akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid;//固定高速

	int a, b, c;
	cin >> a >> b >> c;
	vint v(a);
	vcin(v, a);
	int ans = c;
	int x = 0;
	rep(i, a) {
		ans++;
		rop(j, b) {
			if (j == 1)x = v[i];
			if (j == v[i]+1) {
				ans++;
				v[i] += x;
			}
		}
	}
	cout << ans << rt;

	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD  1000000007

using namespace std;
typedef long long int lli;
typedef long double ld;

int arr[101];
int n,k;

lli power(lli a, lli b){
    if(b==0){
        return 1;
    }
    if(b&1){
        return a*power(a*a,b/2);
    }
    return power(a*a,b/2);
}

void solve(){
    cin>>n>>k;

vector <bool> dp(k+1);
    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    
        for(int i=0;i<=k;i++)
        {
            for(int j=0;j<n;j++)
            if(i>=arr[j] && !dp[i-arr[j]])
            dp[i]=1;
        }
        if(dp[k])
        cout<<"First\n";
        else
        cout<<"Second\n";
}

signed main(){
    /*#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 3620
package main

import "fmt"

func main() {
        var n, m, q int
        fmt.Scan(&n, &m, &q)

        lr := make([][]int, n+1)
        for i := range lr {
                lr[i] = make([]int, n+1)
        }
        sum := make([][]int, n+1)
        for i := range sum {
                sum[i] = make([]int, n+1)
        }

        for i := 0; i < m; i++ {
                var l, r int
                fmt.Scan(&l, &r)
                lr[l][r]++
        }

        for l := 1; l <= n; l++ {
                for r := 1; r <= n; r++ {
                        sum[l][r] = lr[l][r] + sum[l-1][r] + sum[l][r-1] - sum[l-1][r-1]
                }
        }

        for i := 0; i < q; i++ {
                var p, q int
                fmt.Scan(&p, &q)
                fmt.Println(sum[q][q] - sum[p-1][q] - sum[q][p-1] + sum[p-1][p-1])
        }
}

Measured memory_bytes: 11908
#include <cstdio>

int main()
{
  int n;
  char s[10001];
  scanf("%d%s", &n, s);
  for (char *p = s; *p; ++p)
  {
    *p = (*p - 'A' + n) % 26 + 'A';
  }
  puts(s);
  return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

class Main{

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);

        long n = sc.nextInt();
        long k = sc.nextInt();

        long[] arr = new long[(int)n];

        for (int i = 0; i <arr.length ; i++) {
            arr[i]=sc.nextInt();
        }

        Arrays.sort(arr);

        if(k>=n)
        {
            System.out.println(0);
        }
        else
        {
            long monleft = n-k;
            //System.out.println(monleft);
            long sum=0;

            for (int i = 0; i <(monleft) ; i++)
            {
                sum+=arr[i];
            }

            System.out.println(sum);

        }


    }
}


Measured memory_bytes: 94032
#include <bits/stdc++.h>
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int a[305][305],n,m,p[305],f[305],num[305];
int check(int s){
  memset(f,0,sizeof(f));
  memset(num,0,sizeof(num));
  for (int i=1; i<=n; ++i)
    p[i]=1,++num[a[i][1]];
  while(1){
    int bj=1;
    for (int i=1; i<=m; ++i)
      if (num[i]>s)
	{ bj=0; break; }
    if (bj) return 1;
    for (int i=1; i<=m; ++i)
      if (num[i]>s)
	f[i]=1;
    for (int i=1; i<=n; ++i){
      --num[a[i][p[i]]];
      while(f[a[i][p[i]]]) ++p[i];
      if (p[i]>m) return 0;
      ++num[a[i][p[i]]];
    }
  }
  return 0;
}
int main(){
  cin>>n>>m;
  for (int i=1; i<=n; ++i)
    for (int j=1; j<=m; ++j)
      a[i][j]=gi();
  int l=1,r=n,mid,ans;
  while(l<=r){
    mid=(l+r)>>1;
    if (check(mid)) ans=mid,r=mid-1;
    else l=mid+1;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 640
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from functools import reduce

class UnionFind:
    def __init__(self, node: int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]

    def find(self, x: int) -> int:
        if x == self.par[x]:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> bool:
        if self.isSame(x, y):
            # print("x and y has already united")
            return False

        rx = self.find(x)
        ry = self.find(y)

        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = self.par[ry]
        else:
            self.par[ry] = self.par[rx]

            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

        return True

    def isSame(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


n, m = li()
lang = [[] for _ in range(m)]
for person in range(n):
    kl = list(li_())
    for langi in kl[1:]:
        lang[langi].append(person)

uf = UnionFind(n)
for langi in lang:
    if len(langi) < 2:
        continue

    for i in range(len(langi)-1):
        uf.unite(langi[i], langi[i+1])


for i in range(n):
    uf.find(i)

ok = True
for i in range(1, n):
    if uf.isSame(0, i):
        continue

    else:
        ok = False
        break

print("YES" if ok else "NO")

Measured memory_bytes: 19492
N = int(input())
S = input()

l_cnt = 0
res = ''

for s in S:
    if s == '(':
        l_cnt += 1
        res += s
    else:
        if l_cnt == 0:
            res = '(' + res
        else:
            l_cnt -= 1
        res += s

res += ')' * l_cnt

print(res)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = in.nextInt();
		}
		int n = N - 1;
		int k = K - 1;
		System.out.println((n + k - 1) / k);

	}
}

Measured memory_bytes: 51460
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-28 22:12:21
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int x; cin >> x;
  cout << 1000 * (x / 500) + (x % 500) / 5 * 5 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) {
    cin >> p[i];
  }

  int ans = -1;
  int ansv = INF;
  for (int i = 101; i >= -1; --i) {
    bool ok = true;
    rep(j, n) {
      if (i == p[j]) ok = false;
    }

    if (ok && ansv >= abs(x - i)) {
      ansv = abs(x - i);
      ans = i;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
ll s[100010];
ll n,a,b;

bool judge(int x)
{
    ll sum=0;
    ll s1=x*b;
    ll s2=a-b;
    for(int i=0;i<n;i++)
    {
        if(s[i]>s1)
        {
            if(((s[i]-s1)%s2)!=0)
                sum+=(s[i]-s1)/s2+1;
            else
                sum+=(s[i]-s1)/s2;
        }
    }
    if(sum<=x)
        return true;
    else
        return false;
}

int main()
{
    while(~scanf("%lld %lld %lld",&n,&a,&b))
    {
        for(int i=0;i<n;i++)
            scanf("%lld",&s[i]);
        sort(s,s+n);
        ll l=1,r=s[n-1]/b+1;
        while(l<=r)
        {
            ll x=(l+r)>>1;
            if(judge(x))
                r=x-1;
            else
                l=x+1;
        }
        printf("%lld\n",l);
    }
    return 0;
}


Measured memory_bytes: 1024
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let x = (readLine()!.characters.split(" ").map{Int(String($0))!} + [input[1]]).sort()
let d = (0..<input[0]).map{x[$0+1]-x[$0]}
var ans = 0
for i in d {
    var x = i
    while ans > 0 {
        (x, ans) = (ans, x % ans)
    }
    ans = x
}
print(ans)

Measured memory_bytes: 7740
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  if (__builtin_popcount(n) == 1) {
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  if ((n%2) == 0) {
    FOR(i,2,n) {
      cout<<i<<' '<<1<<endl;
      cout<<i<<' '<<(n+(i^1))<<endl;
    }
    cout<<n*2-1<<' '<<n+1<<endl;
    int bit = n & ~(n-1);
    cout<<n<<' '<<(n^bit)<<endl;
    cout<<n*2<<' '<<(bit^1)<<endl;
  } else {
    FOR(i,2,n+1) {
      cout<<i<<' '<<1<<endl;
      cout<<i<<' '<<(n+(i^1))<<endl;
    }
    cout<<n*2<<' '<<n+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 2304
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

def dif(X,Y):
    return sum([(x-y)**2 for x,y in zip(X,Y)])

def judge(n):
    for i in range(1,n+1):
        if i**2 == n:
            return True
    return False

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if judge(dif(X[i],X[j])):
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using P = pair<int,int>;

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y); //-d[x] < -d[y]
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n) {
        int ans = uf.size(i)-1-deg[i];
        for (int u : to[i]) {
            if (uf.same(i,u)) --ans;
        }
        printf("%d%c", ans, i==n-1?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 9120
N = gets.to_i
ans = 'No'
(1..9).each do |n|
  a = N / n if N % n === 0
  b = N / a if a && N % a === 0
  if a.to_s.size == 1 && b.to_s.size == 1
  	ans = 'Yes'
    break
  end
end
puts ans

Measured memory_bytes: 1788
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

N = In.int()

ct = 0
ok = False

for _ in range(N):
    d0, d1 = In.ints()

    if d0==d1:
        ct+=1
        if ct==3:
            ok=True
            break
    else:
        ct=0

if ok:
    Out.str("Yes")
else:
    Out.str("No")

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 69436
n = int(input())
d = []
for j in range(n):
    d.append(list(map(int, input().split())))
    
i = 0
while i < n-2:
  if d[i][0] == d[i][1]:
    if d[i+1][0] == d[i+1][1]:
      if d[i+2][0] == d[i+2][1]:
        print("Yes")
        break
  i += 1
else:
  print("No")

Measured memory_bytes: 9192
import java.util.Scanner;
class Main {
  public static void main(String[] args){
  Scanner scanner = new Scanner(System.in);
  int a = scanner.nextInt();
  int b = scanner.nextInt();
  int c = scanner.nextInt();
  boolean range = a < b && b < c;
  if(range){
      System.out.println("Yes");
  } else {
      System.out.println("No");
  }
  }
}

Measured memory_bytes: 26064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll m = 1000000007;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll i,j,a[n];
    for(i=0;i<n;i++) cin>>a[i];
    ll cnt1=0,cnt2=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i]>a[j]) 
            {
                if(j>i) cnt1++;
                cnt2++;
            }
        }
    }
    ll ans = (k*cnt1)%m;
    if(k%2==0) 
    {
        ll t = k;
        k/=2;
        ll tmp = ((k%m)*((t-1)%m))%m;
        tmp = (tmp*cnt2)%m;
        ans =  (ans + tmp)%m;
    }
    else 
    {
        ll tmp = ((((k-1)/2)%m) * (k%m))%m;
        tmp = (tmp*cnt2)%m;
        ans = (ans + tmp)%m;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;
 
public class Main 
{ 
    
    
    public static void main(String[] args) throws IOException 
    { 
  
       BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in));
                              
                  StringTokenizer s=new StringTokenizer(br.readLine());
                   int n =  Integer.parseInt(s.nextToken());
                    int m =  Integer.parseInt(s.nextToken());
                int sum=0;
                  StringTokenizer sa=new StringTokenizer(br.readLine());
                for(int i=0;i<m;i++){
                  
                     int p =  Integer.parseInt(sa.nextToken());
                sum+=p;
                }
               
             
                 if(sum>n)
                 System.out.println("-1");
                 else
                 System.out.println(n-sum);
                   
                
                     
    }
    }
 

Measured memory_bytes: 33960
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()
	p = inputList()

	p.sort()

	ans = 0
	for i in range(K):
		ans += p[i]

	print(ans)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 76632
def score(tl,sl,cl):
    sat=0
    last=[0]*26
    satl=list()
    for i in range(365):    
        sat+=sl[i*26+tl[i]-1]
        dec=0
        for l in range(26):
            if l+1!=tl[i]:  
                last[l]+=1
                dec+=cl[l]*last[l]
            else:
                last[l]=0
        sat-=dec
        satl.append(sat)
    return(satl)







d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(365):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(365):
    t=int(input())
    tl.append(t)
for i in range(365):
    print(score(tl,sl,cl)[i])


Measured memory_bytes: 69456
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int t,n,x,y,ans=INT_MAX;
  cin>>n>>t;
  for(int i=0; i<n; i++)
  {
    cin>>x>>y;
    if(y<=t)
      ans=min(x,ans);
  }
  if(ans!=INT_MAX)
  cout<<ans;
  else
  cout<<"TLE";
  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

string s;
int a, b, c, mx, mn;

int main()
{
      cin >> s;

      for(int i = 0; i < s.size(); i ++)
      {
            if(s[i] == 'a') a ++;
            if(s[i] == 'b') b ++;
            if(s[i] == 'c') c ++;
      }

      mx = max(a, max(b, c));
      mn = min(a, min(b, c));

      if(mx - mn > 1)
            cout << "NO" << endl;
      else
            cout << "YES" << endl;
}


Measured memory_bytes: 512
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
#define ft first
#define se second

ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

vector<int> ad[100001];
int dist[100001], par[100001], vis[100001];
void bfs(int node, int p){
	vis[node] = 1;
	queue<int> q;
	q.push(node);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int child : ad[x]){
			if(!vis[child]){
				q.push(child);
				vis[child] = true;
				dist[child] = dist[x] + 1;
				par[child] = x;
			}
		}
	}
}

void solve(){
	int n,m; cin>>n>>m;
	int a,b; 
	f(i,m){
		cin>>a>>b;
		ad[a].pb(b);
		ad[b].pb(a);
	}
	for(int i=2;i<=n;i++) dist[i] = INT_MAX;
	bfs(1,0);
	int f = 1;
	for(int i=2;i<=n;i++){
		if(!vis[i]){
			f=0;
			break;
		}
	}
	if(!f) cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++) cout<<par[i]<<endl;
	}
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}


Measured memory_bytes: 11356
#include <stdio.h>

int main(void)
{
	int A,B,C;
	C=0;
	scanf(" %d %d",&A,&B);
	if(A<B){
		C=(B+A-1)/A;
		printf("%d\n",C);
	}
	else if(A>B){
		C=1;
		printf("%d\n",C);
	}
	else{
		printf("%d\n",1);
	}
	return 0;
}


Measured memory_bytes: 2104
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
typedef pair<ll, ll> LLARR;
#define INF 999999999

int n;

bool isSum(int *A, int i, int now)
{
	if (0 == now)
		return true;
	if (i >= n)
		return false;
	return isSum(A, i + 1, now) || isSum(A, i + 1, now + A[i]);
}

int main()
{
	ios::sync_with_stdio(false);

	int A[2001];

	cin >> n;
	REP(i, n)
	{
		cin >> A[i];
	}
	int m;
	cin >> m;

	REP (i,m)
	{
		// mi
		int mi;
		cin >> mi;
		cout << (isSum(A, 0, -mi) ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            for(int i; (i = int.Parse(Console.ReadLine())) != 0;) {
                var data = new int[1000001];
                int f, s, b, l = f = s = b = 0;
                for(int m = 0; m < i; ++m) {
                    var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    var time = 0;
                    for(int n = 1; n <= 8; ++n) {
                        time += input[n] * ((n & 1) == 1 ? 60 : 1);
                    }
                    data[input[0]] = time;
                    if(m <= 1) {
                        if(m == 0) {
                            f = s = b = l = input[0];
                        }
                        else { 
                            if (data[f] > time) {
                                f = b = input[0];
                            }
                            else {
                                s = l = input[0];
                            }
                        }
                    }
                    else {
                        if(time < data[s]) {
                            s = input[0];
                        }
                        if(time < data[f]) {
                            s = f;
                            f = input[0];
                        }
                        if(time > data[b]) {
                            b = input[0];
                        }
                        if(time > data[l]) {
                            b = l;
                            l = input[0];
                        }
                    }
                }
                Console.WriteLine("{0}{3}{1}{3}{2}", f, s, b, System.Environment.NewLine);
            }
        }
    }
}

Measured memory_bytes: 20440
//ΔAGC005F
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 1<<19;
const int MO = 924844033;
int ad(int x,int y){
	x+=y;
	if(x>=MO)
		x-=MO;
	if(x<0)
		x+=MO;
	return x;
}
int mul(int x,int y){
	return (LL)x*y%MO;
}
int fpow(int x,int y=MO-2){
	if(!y)
		return 1;
	int z=fpow(x,y>>1);
	z=mul(z,z);
	if(y&1)
		return mul(z,x);
	return z;
}
void DFT(int C[],int n,int fl){
	int i,j,k,l;
	int u,v,w,cur;
	i=n>>1;
	for(j=1;j<n;j=j+1){
		if(i<j)
			swap(C[i],C[j]);
		for(k=n>>1;i&k;k>>=1)
			i^=k;
		i^=k;
	}
	for(l=2;l<=n;l<<=1){
		w=fpow(5,(MO-1)/l);
		if(fl==-1)
			w=fpow(w);
		for(i=0;i<n;i=i+l){
			cur=1;
			for(j=i;j<i+(l>>1);j=j+1){
				u=C[j],v=mul(C[j+(l>>1)],cur);
				C[j]=ad(u,v),C[j+(l>>1)]=ad(u,-v);
				cur=mul(cur,w);
			}
		}
	}
}
int m,A[N],B[N];
void FFT(){
	int i,l,o;
	for(l=1;l<m+m;l<<=1);
	DFT(A,l,1);
	DFT(B,l,1);
	for(i=0;i<l;i=i+1)
		A[i]=mul(A[i],B[i]);
	DFT(A,l,-1);
	o=fpow(l);
	for(i=0;i<l;i=i+1)
		A[i]=mul(A[i],o);
}
int fac[N],ifac[N];
int n,t[N],s[N];
vector<int> v[N];
void dfs(int u,int fa){
	int i=v[u].size(),x;
	t[u]=1;
	while(i--){
		x=v[u][i];
		if(x!=fa)
			dfs(x,u);
	}
	t[fa]+=t[u];
	if(t[u]<n){
		s[t[u]]++;
		s[n-t[u]]++;
	}
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	fac[0]=1;
	for(i=1;i<=n;i=i+1)
		fac[i]=mul(fac[i-1],i);
	for(i=0;i<=n;i=i+1)
		ifac[i]=fpow(fac[i]);
	for(i=1;i<n;i=i+1){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	m=n+1;
	for(i=1;i<=n;i=i+1)
		A[i]=mul(s[i],fac[i]);
	for(i=0;i<=n;i=i+1)
		B[i]=ifac[n-i];
	FFT();
	for(i=1;i<=n;i=i+1){
		x=mul(mul(n,fac[n]),mul(ifac[i],ifac[n-i]));
		y=mul(A[n+i],ifac[i]);
		printf("%d\n",ad(x,-y));
	}
	return 0;
}

Measured memory_bytes: 43648
sum=0
m,n=map(int,input().split())

array_1 = [[] for i in range(m)]
for i in range(m):
    array_1[i] = list(map(int,input().split()))

array_2 = [[] for i in range(n)]
for i in range(n):
    array_2[i] = int(input())

for row in range(m):
    sum = 0
    for cols in range(n):
        sum += array_1[row][cols]*array_2[cols]
    print(sum)



Measured memory_bytes: 6020
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		int count = 0;
		String str = "";
		String[] line;
		List<String[]> lineArray = new ArrayList() ;
		
      	while (sc.hasNextLine()) {
      		str = sc.nextLine();
      		line = str.split(" ");
      		lineArray.add(line);
        }
      	
      	for (String[] comLine : lineArray) {
      		if (comLine[0].equals(comLine[1])) {
      			count++;
      			if (count == 3) {
      				break;
      			}
      		} else {
      			count = 0;
      		}
      	}

      	if (count == 3) {
      		System.out.println("Yes");
      	} else {
      		System.out.println("No");
      	}
	}
}

Measured memory_bytes: 35768
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    while(n--){
    string chs[10];
    chs[1]=".,!? ";
    chs[2]="abc";
    chs[3]="def";
    chs[4]="ghi";
    chs[5]="jkl";
    chs[6]="mno";
    chs[7]="pqrs";
    chs[8]="tuv";
    chs[9]="wxyz";

    string res;
    string s;
    cin>>s;
    int idx=0;
    int cnt=0;
    for(int i = 0; i < s.size(); i++){
        int num=s[i]-'0';
        if(num==0){
            if(idx!=0){
                res+=chs[idx][cnt];
                idx=0;
                cnt=-1;
            }
        }
        else{
            if(idx==num)
                cnt=(cnt+1)%(chs[idx].size());
            else{
                if(idx!=0)
                    res+=chs[idx][cnt];
                idx=num;
                cnt=0;
            }
        }
    }
    if(idx!=0)
        res+=chs[idx][cnt];
    cout<<res<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3


def solve(a, b, ps):
    easy = mid = hard = 0
    for p in ps:
        if p <= a:
            easy += 1
        elif a + 1 <= p <= b:
            mid += 1
        else:
            hard += 1
    return min(easy, mid, hard)


def main():
    _ = int(input())
    a, b = (int(z) for z in input().split())
    ps = [int(z) for z in input().split()]
    res = solve(a, b, ps)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
# ABC 095
def getIntList(): return [int(x) for x in input().split()]
def getIntLines(n): return [int(input()) for i in range(n)]
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
debug = False
N,X = getIntList()
m = getIntLines(N)
db((N,X,m))
used = sum(m)
m.sort()
cnt = len(m)+(X-used)//m[0]
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

bitset<10010> ok[2010];
int n, k;
string s[2010];
char ans[10010];
vector<int> pts;

int fail[10010];
int self[10010];
int match[10010];

int an;

int main()
{
	cin>>n>>k;
	for(int i=1; i<=n; ++i) cin>>s[i];
	ok[n+1][0]=1;
	for(int i=n; 1<=i; --i) ok[i] = ok[i+1] | (ok[i+1]<<(s[i].length()));
	pts.pb(0);
	for(int i=1; i<=n; ++i){
		const char* p = s[i].c_str();
		int l = s[i].length();
		
		fill(fail, fail+l, 0);
		fill(self, self+l, 0);
		fill(match, match+an+1, 0);
		
		for(int i=1; i<l; ++i){
			int j=fail[i-1];
			while(j && p[j] != p[i]) j=fail[j-1];
			if(p[j] == p[i]) ++j;
			fail[i]=j;
			if(j) self[i-j+1]=max(self[i-j+1], j);
		}
		for(int i=0; i<l; ++i){
			int& m=self[i];
			while(m<l-i && p[m]==p[i+m]) ++m;
			if(m){
				int& t=self[i+m-fail[m-1]];
				t=max(t, fail[m-1]);
			}
		}
		
		for(int i=0, ml=0; i<an; ++i){
			while(ml && p[ml] != ans[i]) ml=fail[ml-1];
			if(p[ml] == ans[i]) ++ml;
			if(ml) match[i-ml+1] = max(match[i-ml+1], ml);
		}
		
		for(int i=0; i<an; ++i){
			int& m=match[i];
			while(m<l && ans[i+m] == p[m]) ++m;
			if(m>=2){
				int& t=match[i+m-fail[m-1]];
				t=max(t, fail[m-1]);
			}
		}
		
		int cmp = -1;
		for(int st:pts){
			if(k<(st+l) || !ok[i+1][k-(st+l)]) continue;
			if(cmp == -1){
				if(match[st]<l && (st+match[st]==an || p[match[st]]<ans[st+match[st]])){
					cmp = st;
				}
			} else if(cmp+l <= st) break;
			else {
				int sa = st-cmp;
				if(match[cmp] >= sa){
					if(self[sa] == l-sa || p[self[sa]]<p[sa+self[sa]]) cmp=st;
				}
			}
		}
		
		int lm = an;
		if(cmp != -1){
			lm = cmp + match[cmp], an = cmp+l;
			for(int i=0; i<l; ++i) ans[cmp+i]=p[i]; ans[an]=0;
		}
		vector<int> nv;
		for(int st:pts){
			if(k<(st+l) || !ok[i+1][k-(st+l)]) continue;
			if((match[st]==l && (cmp==-1 || st+match[st]<=cmp)) || match[st]>=cmp-st && self[cmp-st]==l-(cmp-st)){
				nv.pb(st+l);
			}
		}
		vector<int> fn;
		for(int i=0,j=0; i<pts.size() || j<nv.size();){
			if(j==nv.size() || (i<pts.size() && j<nv.size() && pts[i]<nv[j])){
				if(pts[i]<=lm){
					if(fn.empty() || fn.back() != pts[i])
						fn.pb(pts[i]);
				}
				++i;
			} else {
				if(fn.empty() || fn.back() != nv[j]) fn.pb(nv[j]);
				++j;
			}
		}
		swap(pts, fn);
	}
	puts(ans);
	return 0;
}


Measured memory_bytes: 4096
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <cassert>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
typedef pair<ll, ll> LLARR;
#define INF 999999999

int w[100003];
int n,k;

ll check(ll p)
{
	ll ret = 0;
	ll tmp = 0;
	ll i = 0;
	REP(j, k)
	{
		ll s = 0;
		while (s + w[i] <= p)
		{
			s += w[i];
			i++;
			if (i == n)
				return n;
		}
	}
	return i;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> k;
	REP(i, n)
	{
		cin >> w[i];
	}

	ll ma = 10000 * 100000;
	ll l = 0;
	ll r = ma;
	ll mid = 0;
	while (l + 1 < r)
	{
		mid = (l + r) / 2;
		if (check(mid) >= n)
		{
			r = mid;
		}
		else
		{
			l = mid;
		}
	}
	
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3536
/**
 *    author:  math2do
 *    created: 04.05.2020 03:06:20 IST
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3548
using System;
using System.Collections.Generic;

namespace AOJ.ALDS
{
    public class Dictionary
    {
        public static void Main()
        {
            int cnt = int.Parse(Console.ReadLine());
            var dic = new HashSet<string>();
            for (int i = 0; i < cnt; i++)
            {
                var input = Console.ReadLine().Split(' ');
                if (input[0] == "insert") { dic.Add(input[1]); }
                else { Console.WriteLine(dic.Contains(input[1]) ? "yes" : "no"); }
            }
        }
    }
}

Measured memory_bytes: 35996
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <sstream>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)

using namespace std;

typedef long long ll;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int i;
	for(i = 0; (a - 1) * i + 1 < b; i++)
		;
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 128
from collections import deque

n,q=map(int,input().split())
q = int(q)
queue=deque()
for i in range(n):
  queue.append(list(input().split()))

time=0
while len(queue)>0:
  tmp=queue.popleft()
  if int(tmp[1])<=q:
    print(' '.join([tmp[0], str(time + int(tmp[1]))]))
    time += int(tmp[1])
  else:
    queue.append([tmp[0], int(tmp[1]) - q])
    time +=q


Measured memory_bytes: 14340
#include<bits/stdc++.h>
using namespace std;

struct P{
  int x,y;
  long long z;
  bool operator <(const P &a){
    return x<a.x;
  }
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[2111],o1[777][777];
int l[2111];
int j[3333][3333];
long long x,y,z,mod=1000000007;
string r;
//char r[1];
vector<int> v[4121];
vector<P> v1;
queue<int> q;
stack<int> s;
map<int,int> p;

void f1(int n)
{
  //printf("%d ",n);
  o[n]=1;
  for(int h=0;h<v[n].size();h++)
    if(!o[v[n][h]]) f1(v[n][h]);
  s.push(n);
}

void g(int n,int m)
{
  o[n]=m;
  for(int h=0;h<v[n].size();h++)
    if(!o[v[n][h]]) g(v[n][h],m);
}

int f(int n,int m)
{
  if(n==v1.size()) return m*(m-1)/2+(a-m)*(a-m-1)/2;
  if(j[n][m]) return j[n][m];
  return j[n][m]=min(f(n+1,v1[n].x+m),f(n+1,m+v1[n].y));
}

int main()
{
  scanf("%d %d",&a,&b);
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d",&n,&m);
    o1[n][m]=o1[m][n]=1;
  }
  for(int t=1;t<=a;t++)
    for(int w=t+1;w<=a;w++)
      if(!o1[t][w])
      {
        v[t*2-1].push_back(w*2);
        v[w*2-1].push_back(t*2);
        v[t*2].push_back(w*2-1);
        v[w*2].push_back(t*2-1);
      }
  
  for(int t=1;t<=2*a;t++)
    if(o[t]==0) f1(t);
  memset(o,0,sizeof(o));
  for(;s.size();s.pop())
    if(o[s.top()]==0) g(s.top(),++e);
  for(int t=1;t<=a;t++)
  if(o[t*2-1]==o[t*2])
  {
    puts("-1");
    return 0;
  }
    else if(l[o[t*2-1]]==0&&l[o[t*2]]==0)
  {
    l[o[t*2-1]]=1,l[o[t*2]]=1;
    n=0,m=0;
    for(int w=t;w<=a;w++)
      if(o[t*2-1]==o[w*2-1]) n++;
      else if(o[t*2-1]==o[w*2])m++;
    v1.push_back({n,m});
    //printf("%d %d\n",n,m);
  }
  printf("%d",f(0,0));
}



Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int n;
int v[N];
int dp[N];
int f(int i){
    if(i > n)
        return 1e9;
    if(i == n - 1)
        return 0;
    if(dp[i] != -1)return dp[i];
    int &ans = dp[i];
    ans = 1e9;
    ans = min(ans,f(i + 1) + abs(v[i] - v[i + 1]));
    ans = min(ans,f(i + 2) + abs(v[i] - v[i + 2]));
    return ans;
}

int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    //cls(dp, -1);
    fore(i, 0, N)
        dp[i] = 1e9;
    cin >> n;
    fore(i, 0, n)cin >> v[i];
    dp[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--){
        if(i + 1 <= n - 1)
            dp[i] = min(dp[i],dp[i + 1] + abs(v[i] - v[i + 1]));
        if(i + 2 <= n - 1)
            dp[i] = min(dp[i],dp[i + 2] + abs(v[i] - v[i + 2]));
    }

    cout << dp[0] << '\n';
    return 0;   
}

Measured memory_bytes: 1024
t = int(input())
qs=[list(map(int,input().split())) for i in range(t)]

def computeGCD(x, y):
   while(y):
       x, y = y, x % y
   return x

def aprime(a,b,c,d):
    app = a%b
    return(c+d-b - (c-app)%(d-b))


def ans(a,b,c,d):
    if d < b or a<b or (a%b > c and c<b):
        return('No')
    elif b == d or c > b:
        return('Yes')
    elif aprime(a,b,c,d) < b:
        return('No')
    else: return (ans2(aprime(a,b,c,d),b,c,d))

def ans2(a,b,c,d):
    b2 = b % (d-b)
    gcdbbd = abs(computeGCD(b2,b-d))
    aa = a - ((a-c)//gcdbbd)*gcdbbd
    if aa == c: aa = c+ gcdbbd
    if aa >= b: return('Yes')
    else: return('No')

for q in qs:
    print (ans(*q))



Measured memory_bytes: 3188
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

const int INF=1<<29;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	weighted_graph<int> G(n);
	rep(i,m){
		int u,v,d; scanf("%d%d%d",&u,&v,&d); u--; v--;
		G[u].emplace_back(v,d);
		G[v].emplace_back(u,d);
	}
	vector<int> f(n);
	rep(u,n) scanf("%d",&f[u]);
	int Tmax; scanf("%d",&Tmax);

	// Warshall-Floyd
	vector<vector<int>> d(n,vector<int>(n,INF));
	rep(u,n) d[u][u]=0;
	rep(u,n) for(auto e:G[u]) {
		int v=e.to;
		d[u][v]=min(d[u][v],e.wt);
	}
	rep(w,n) rep(u,n) rep(v,n) d[u][v]=min(d[u][v],d[u][w]+d[w][v]);

	list<pair<int,int>> Wait,Now;
	int phase=0;
	int cur=0,next,edge_pos,goal;
	bool on_edge=false;
	rep(t,Tmax){
		int n_new; scanf("%d",&n_new);
		if(n_new>0){
			int id,dst; scanf("%d%d",&id,&dst); id--; dst--;
			Wait.emplace_back(id,dst);
		}
		int n_put; scanf("%d",&n_put);
		rep(i,n_put) scanf("%*d");

		int res=-1;

		// ******* main part *******
		if(phase%2==0 && cur==0){ // at the shop
			Now.insert(Now.end(),Wait.begin(),Wait.end());
			Wait.clear();
			if(!Now.empty()){
				goal=Now.front().second;
				phase++;
			}
		}
		else if(phase%2==0){ // at customer
			for(auto it=Now.begin();it!=Now.end();++it) if(it->second==goal) {
					it=Now.erase(it);
					--it;
			}
			goal=0;
			for(auto p:Now){
				if(goal==0 || d[cur][p.second]<d[cur][goal]) goal=p.second;
			}
			phase++;
		}

		if(phase%2==1){ // moving
			if(!on_edge){
				next=-1;
				for(auto e:G[cur]){
					if(next==-1 || d[cur][goal]==e.wt+d[e.to][goal]) next=e.to;
				}
				edge_pos=1;
				on_edge=true;
			}
			else{ // on_edge
				edge_pos++;
			}
			res=next;

			if(on_edge && edge_pos==d[cur][next]){
				on_edge=false;
				if(next==goal){
					phase++;
				}
				cur=next;
			}
		}
/*{
	bool ok=false;
	for(auto e:G[cur]) if(e.to==next) ok=true;
	fprintf(stderr,"t=%4d: phase=%d, cur=%d, next=%d, on_edge=%d, edge_pos=%d, goal=%d; edge=%d\n",t,phase,cur,next,on_edge,edge_pos,goal,ok);
}*/
		// *************************

		printf("%d\n",res==-1?-1:res+1);
		fflush(stdout);

		char verdict[8]; scanf("%s",verdict);
		if(string(verdict)=="NG"){
			return 0;
		}
		int n_achieve; scanf("%d",&n_achieve);
		rep(i,n_achieve) scanf("%*d");
	}

	return 0;
}


Measured memory_bytes: 2004
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] W = new int[N];
        for (int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
        }

        int leftSum = W[0];
        int rightSum = 0;
        for (int i = 1; i < N; i++) {
            rightSum += W[i];
        }

        int ans = Math.abs(leftSum - rightSum);

        for (int i = 1; i < N-1; i++) {
            leftSum += W[i];
            rightSum -= W[i];
            ans = Math.min(ans, Math.abs(leftSum - rightSum));
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int n; cin >> n;
    int a[n];
    map<int, int> mp;
    for(int i = 1; i < 10; i++){
        mp[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] < 400 && a[i] > 0) mp[1]++;
        else if(a[i] < 800) mp[2]++;
        else if(a[i] < 1200) mp[3]++;
        else if(a[i] < 1600) mp[4]++;
        else if(a[i] < 2000) mp[5]++;
        else if(a[i] < 2400) mp[6]++;
        else if(a[i] < 2800) mp[7]++;
        else if(a[i] < 3200) mp[8]++;
        else mp[9]++;
    }
    int cnt = 0;
    for(int i = 1; i < 9; i++){
        if(mp[i] > 0){
            cnt++;
        }
    }
    if(cnt == 0){
        cout << 1 << " " << cnt + mp[9] << endl;
    } else {
        cout << cnt << " " << cnt + mp[9] << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

//Card Game II
public class Main{

	int[] res, t;
	
	void add(int D){
		t[0] = 1/D;
		int R = 1%D, id = 1;
		while(id<t.length){
			R*=10;
			t[id++] = R/D;
			R%=D;
		}
		for(int i=t.length-1;i>0;i--){
			res[i]+=t[i];
			res[i-1]+=res[i]/10;
			res[i]%=10;
		}
		res[0]+=t[0];
	}
	
	void div(int n){
		t[0] = res[0]/n;
		int R = res[0]%n, id = 1;
		while(id<t.length){
			R = R*10 + res[id];
			t[id++] = R/n;
			R%=n;
		}
		for(int i=0;i<t.length;i++)res[i] = t[i];
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), k = sc.nextInt(), m = sc.nextInt(), r = sc.nextInt();
			if((n|k|m|r)==0)break;
			res = new int[r+10];
			t = new int[r+10];
			if(m==0){
				add(n);
			}
			else{
				for(int i=1;i<n;i++)add(i);
				div(n);
				add(n);
			}
			System.out.print(res[0]+".");
			for(int i=1;i<=r;i++)System.out.print(res[i]+(i==r?"\n":""));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000