akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int n, m;
  cin >> n >> m;
  long long x[n], y[n], z[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  vector<long long> sum(n);
  for (int i = 0; i < n; i++) {
    sum[i] = x[i] + y[i] + z[i];
  }
  sort(sum.rbegin(), sum.rend());
  long long ans = 0;
  long long tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = x[i] + y[i] - z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = x[i] - y[i] + z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = x[i] - y[i] - z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = -x[i] + y[i] + z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = -x[i] + y[i] - z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = -x[i] - y[i] + z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  for (int i = 0; i < n; i++) {
    sum[i] = -x[i] - y[i] - z[i];
  }
  sort(sum.rbegin(), sum.rend());
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += sum[i];
  }
  ans = max(ans, tmp);

  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int L, R;
    int mod = 2019;
    cin >> L >> R;
    int upperL = (L / mod + 1) * mod;
    if(R >= upperL){
        cout << 0;
        return 0;
    } else{
        R %= mod;
        L %= mod;
        int ans = 2018;
        for (int i = L; i < R; ++i) {
            for (int j = i + 1; j <= R; ++j) {
                ans = min(ans, i*j % mod);
            }
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  int A[N][20];
  for(int i=0; i<N; i++){
    ll in;
    cin >> in;
    for(int j=0; j<20; j++){
      A[i][j] = in % 2;
      in /= 2;
    }
  }

  int ones[N+1][20];
  for(int j=0; j<20; j++)
    ones[0][j] = 0;
  for(int i=1; i<N+1; i++){
    for(int j=0; j<20; j++){
      ones[i][j] = ones[i-1][j];
      if(A[i-1][j] == 1)
	ones[i][j]++;
    }
  }

  ll ret = 0;
  int prev_r = 0;
  for(int l=0; l<N+1; l++){
    for(int r=prev_r; r<N+1; r++){
      bool ok = true;
      for(int i=0; i<20; i++){
	if(ones[r][i] - ones[l][i] >= 2){
	  ok = false;
	  break;
	}
      }
      if(!ok){
	ret += r - l - 1;
	prev_r = r - 1;
	break;
      } else if(r == N){
	ret += r - l;
	prev_r = r;
	break;
      }
    }
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
string s[]={"afkpuz","bglqv.","chmrw?","dinsx!","ejoty "};
int main(){string ss;while(cin>>ss){
if(ss.size()%2==1){cout<<"NA"<<endl;continue;}
bool b=1;string ans="";for(int i=0;i<ss.size()-1;i+=2){
if(!('1'<=ss[i+1]&&ss[i+1]<='5')||!('1'<=ss[i]&&ss[i]<='6')){b=0; break;}
ans+=s[ss[i+1]-'0'-1][ss[i]-'0'-1];}
if(b)cout<<ans<<endl;else cout<<"NA"<<endl;
}}

Measured memory_bytes: 3144
n, m = [int(s) for s in raw_input().split(" ")]
routes = []
for i in xrange(m):
    routes.append([int(s) for s in raw_input().split(" ")])
x = set([r[1] for r in routes if r[0] == 1])
y = set([r[0] for r in routes if r[1] == n])
print "POSSIBLE" if x & y else "IMPOSSIBLE"


Measured memory_bytes: 46704
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set()
for i in range(n):
     su=0
     for j in range(i,n):
          su+=a[j]
          s.add(su)
s=list(s)
x=0
for i in range(40):
     x_=x+2**(39-i)
     cnt=0
     for a in s:
          if x_&a==x_:
               cnt+=1
     if cnt>=k:
          x=x_
print(x)

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;
const LL INF = 1e18;

int n, m, k;
LL a[N], b[N];

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i ++ ) scanf("%lld", &a[i]);
	for (int i = 1; i <= m; i ++ ) scanf("%lld", &b[i]);
	a[0] = b[0] = -INF;
	a[n + 1] = b[m + 1] = INF;
	
	while (k -- )
	{
		LL x;
		scanf("%lld", &x);
		
		LL ls, lt, rs, rt;
		rs = a[lower_bound(a, a + n + 2, x) - a];
		rt = b[lower_bound(b, b + m + 2, x) - b];
		ls = a[upper_bound(a, a + n + 2, x) - a - 1];
		lt = b[upper_bound(b, b + m + 2, x) - b - 1];
		
		LL res = INF;
		res = min(res, max(rs, rt) - x);
		res = min(res, x - min(ls, lt));
		res = min(res, 2LL * min(rs - x, x - lt) +  max(rs - x, x - lt));
		res = min(res, 2LL * min(rt - x, x - ls) +  max(rt - x, x - ls));
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 2816
h, w, d = [int(item) for item in input().split()]
a = [[int(item) for item in input().split()] for _ in range(h)]
q = int(input())
lr = [[int(item) for item in input().split()] for _ in range(q)]

size = h * w
dist = [[0] * ((size)//d + 1) for _ in range(d)]
ilist = [0] * (size+1)
jlist = [0] * (size+1)

for i in range(h):
  for j in range(w):
    ilist[a[i][j]] = i
    jlist[a[i][j]] = j

def get_dist(x, y):
  distance = abs(ilist[x] - ilist[y]) + abs(jlist[x] - jlist[y])
  return distance

for i in range(d):
  for j in range((size)//d + 1):
    if (j-1)*d+i <= 0 or j*d + i > size:
      continue
    dist[i][j] = dist[i][j-1] + get_dist(j*d+i, (j-1)*d+i)

for l, r in lr:
  print(dist[r%d][r//d] - dist[l%d][l//d])
    

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

int main() {
    long long n;
    cin>>n;
    long long a[n],c=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i+=2){
        if(a[i]%2==1) c++;
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 3620
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    x, y = map(int, readline().split())
    sx, sy = 0, 0

    for i in range(len(s)):
        if s[i] == "F":
            sx += 1
        else:
            break

    is_x = False
    cur = 0

    x_list = []
    y_list = []

    for i in range(sx + 1, len(s)):
        if s[i] == "F":
            cur += 1
        if s[i] == "T" or i == len(s) - 1:
            if is_x:
                x_list.append(cur)
            else:
                y_list.append(cur)
            cur = 0
            is_x = not is_x

    x_possible = set()
    x_possible.add(0)

    while x_list:
        x_possible_new = set()
        cx = x_list.pop()
        for px in x_possible:
            x_possible_new.add(px + cx)
            x_possible_new.add(px - cx)
        x_possible = x_possible_new

    y_possible = set()
    y_possible.add(0)

    while y_list:
        y_possible_new = set()
        cy = y_list.pop()
        for py in y_possible:
            y_possible_new.add(py + cy)
            y_possible_new.add(py - cy)
        y_possible = y_possible_new

    nx = x - sx
    ny = y

    if (nx in x_possible) and (ny in y_possible):
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()


Measured memory_bytes: 47580
n = int(input())
l = list(map(int,input().split()))

budget = 1000
stock = 0
for i in range(n-1):
    if l[i] < l[i+1]:
        budget = budget + stock * l[i]
        stock = budget // l[i]
        budget = budget % l[i]
    elif l[i] > l[i+1]:
        budget = budget + stock * l[i]
        stock = 0
else:
    budget += stock*l[-1]
    stock = 0

print(budget)


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

int main() {
  int n;
  string ans = "No";

  cin >> n;

  for(int i=1;i<=9;i++) {
    for(int j=1;j<=9;j++) {
      if(n == i*j) ans = "Yes";
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <string>
# include <vector>


using namespace std;


const int MOD = 1e9+7;


int main() {
    string s; cin >> s;

    int n_digits = s.size();

    vector<vector<long long>> dp(n_digits+1, vector<long long>(13, 0));
    dp[0][0] = 1;  // 0 (mod 13) \equiv 0

    long long digit = 1;
    for (int i=0; i<n_digits; i++) {

        char c = s[i];

        // update dp[i+1][k]
        if (c != '?') {
            int k = c - '0';
            for (int j=0; j<13; j++) {
                int l = (10 * j + k) % 13;
                dp[i+1][l] = dp[i][j];
            }
        }

        else {
            for (int k=0; k<10; k++) {
                for (int j=0; j<13; j++) {
                    int l = (10 * j + k) % 13;
                    dp[i+1][l] += dp[i][j];
                    dp[i+1][l] %= MOD;
                }
            }
        }

        digit *= 10;
        digit %= MOD;

        // cerr << (i+1) << " : ";
        // for (int k=0;k<13;++k)cerr << dp[i+1][k] << ' ';
        // cerr << endl;
        // cerr << "digit " << digit << endl;
    }

    cout << dp[n_digits][5] << endl;
    return 0;
}



Measured memory_bytes: 13696
from bisect import bisect

s = input()
t = input()

indices = {}
N = len(s)
for i in range(N):
  try:
    indices[s[i]].append(i)
  except:
    indices[s[i]] = [i]

min_i = 0
cur = -1
for i in range(len(t)):
  try:
    idx = bisect(indices[t[i]], cur)
    try:
      n = indices[t[i]][idx]
    except:
      n = indices[t[i]][0]

    if n <= cur:
      min_i += (N - cur) + n
    else:
      if cur == -1:
        cur = 0
      min_i += (n - cur)
    cur = n
  except:
    print(-1)
    break
else:
  print(min_i + 1)

Measured memory_bytes: 7668
#include <stdio.h>

#define MAX 50000000

int parent(int i) {return i / 2;}
int left(int i) {return 2*i;}
int right(int i){return 2*i + 1;}
int H;
int A[MAX];

void maxHeap(int idx){
    int l = left(idx);
    int r = right(idx);
    int large;
    if(l <= H && A[idx] < A[l]){
        large = l;
    } else {
        large = idx;
    }

    if(r <= H && A[large] < A[r]){
        large = r;
    }

    if(large != idx){
        int tmp = A[idx];
        A[idx] = A[large];
        A[large] = tmp;
        maxHeap(large);
    }

}

void exec(){
    for(int i = H/2; i >= 1; i--) maxHeap(i);
}

int main(){
    int i;
    scanf("%d", &H);
    for(i = 1; i <= H; i++){
        scanf("%d", &A[i]);
    }

    exec();

    for(i = 1; i <= H; i++){
        printf(" %d", A[i]);
    }

    printf("\n");

    return 0;
}



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

#define rep(i,s,t) for(int i=s,i##end=t;i<=i##end;++i)
#define per(i,s,t) for(int i=t,i##end=s;i>=i##end;--i)
#define repo(i,s,t) for(int i=s,i##end=t;i<i##end;++i)
#define debug(x) cerr<<#x<<" : "<<x<<" "<<__FUNCTION__<<__LINE__<<endl

const int MAXN = 105;

int n, A, B;


int main() {
	cin >> n >> A >> B;
	int d = B - A;
	if (d & 1) cout << "Borys" << endl;
	else cout << "Alice" << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
links=[set() for _ in [0]*N]
for i in range(1,N):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  links[u].add((v,w))
  links[v].add((u,w))
ans=[-1]*N
q=[(0,0,-1)]
while q:
  v,d,p=q.pop()
  if d%2==0:
    ans[v]=0
  else:
    ans[v]=1
  for u,w in links[v]:
    if u==p:
      continue
    q.append((u,w+d,v))
print('\n'.join(map(str,ans)))

Measured memory_bytes: 56480
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
const int DY[] = { -1,0,1,0 };
const int DX[] = { 0,1,0,-1 };

int H, W, d[101][101];
char S[101][101];

void f(int y, int x) {
    queue<tuple<int,int,int> > Q;
    Q.push(MT(y, x, 0));
    MEM(d, -1);
    while (sz(Q)) {
        int dis;
        tie(y, x, dis) = Q.front(); Q.pop();
        if (y < 0 || x < 0 || y >= H || x >= W || d[y][x]!=-1 || S[y][x]=='#')continue;
        d[y][x] = dis;
        rep(i, 4) {
            int ny = y + DY[i], nx = x + DX[i];
            Q.push(MT(ny, nx, dis + 1));
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> H >> W;
    int b = 0;
    rep(y, H) {
        cin >> S[y];
        rep(x, W) {
            if (S[y][x] == '#')b++;
        }
    }
    f(0, 0);
    if (d[H-1][W-1]!=-1) {
        cout << (H*W - d[H - 1][W - 1] - 1 - b) << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int N = sc.nextInt();
		int H[] = new int[N];

		int max = 0;

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

		int tmp = 0;

		for (int i = 0; i < N-1; i++) {
			if (H[i] >= H[i+1]) {
				for (int j = i; j < N; j++) {
					if (j == N-1) {
						max = Math.max(tmp,max);
						tmp = 0;
						i = j;
						break;
					}

					if (H[j] >= H[j+1]) {
						tmp++;
					} else {
						max = Math.max(tmp,max);
						tmp = 0;
						i = j;
						break;
					}
				}
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 50176
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> List = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            int j = sc.nextInt();
            List.add(j);
        }
        int k = sc.nextInt();
        int num = 0;
        for (int i = 0; i < 4; i++) {
            for(int j=i+1;j<5;j++){
                if (List.get(j) - List.get(i) > k) num++;
            }
        }
        if (num == 0) System.out.println("Yay!");
        else System.out.println(":(");
    }
}

Measured memory_bytes: 21716
def solve():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    # least
    ans = 0
    cnt = 0
    for i in range(A+1):
        for j in range(B+1):
            for k in range(C+1):
                if (500*i+100*j+50*k) == X:
                    ans += 1
    print(ans)
    return

solve()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
  string a,b,c;
  cin >> a >> b >> c;

  string card[] = {a,b,c};
  size_t card_num[] = {a.size(),b.size(),c.size()};
  int turn = 0;
  int next_turn;
  while(true){
    if (card_num[turn] == 0) {
      break;
    }
    switch(card[turn][card[turn].size() - card_num[turn]]){
      case 'a':
        next_turn = 0;
        break;
      case 'b':
        next_turn = 1;
        break;
      case 'c':
        next_turn = 2;
        break;
    }
    card_num[turn]--;
    turn = next_turn;
  }

  switch(turn){
    case 0:
      cout << "A" << endl;
      break;
    case 1:
      cout << "B" << endl;
      break;
    case 2:
      cout << "C" << endl;
      break;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n,k,x,sum;

int main ()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>x;
		if(k-x<x)
			sum=sum+(k-x)*2;
		else
			sum=sum+x*2;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){

	while(true) {
		auto n = readInt();
		if(n == 0) return;
		int ans;
		for(int i = 1; i*i <= n; ++i) {
			if(i*i == n) {
				++ans;
				break;
			}
			for(int j = i; i*i+j*j <= n; ++j) {
				if(i*i+j*j == n) {
					++ans;
					break;
				}
				for(int k = j; i*i+j*j+k*k <= n; ++k) {
					if(i*i+j*j+k*k == n) {
						++ans;
						break;
					}
					auto m = n-(i*i+j*j+k*k);
					auto l = 1;
					auto u = m;
					while(l < u) {
						auto x = (l+u)/2;
						if(x*x == m) {
							if(x >= k) {
								++ans;
							}
							break;
						}
						if(x*x < m) {
							l = x+1;
						} else {
							u = x;
						}
					}
				}
			}
		}
		writeln(ans);
	}
}

Measured memory_bytes: 2504
#include <iostream>
#include <cmath>
#include <set>
using namespace std;

const int MAX_N = 2 * 100000;
int N, A[MAX_N];
set<int> s;

bool isPrime(int x) {
  if (x % 2 == 0) {
    return false;
  }
  for (int i=3; i*i<=x; i += 2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int solve() {
	std::sort(A, A+N);
	int cnt = 0;
	// for (int i=0; i<N; i++) {
	// 	printf("%d ", A[i]);
	// }
	bool isFirst = A[0] == 1;
	for (int i=0; i<N; i++) {
		if (i >= 1 && A[i-1] == A[i]) {
			continue;
		}
		if (i <= N-2 && A[i+1] == A[i]) {
			continue;
		}
		if (A[i] == 1) {
			isFirst = true;
		}

		if (!isFirst && A[i] > 3 && isPrime(A[i])) {
			cnt++;
			continue;
		}

		bool chek = false;
		for (int j=0; A[j]<=A[i]/12; j++) {
			if (A[i] % A[j] == 0) {
				chek = true;
				break;
			}
		}

		if (!chek) {
			if (A[i] % 2 == 0) {
				if (s.find(A[i]/2) != s.end()) {
					continue;
				}
			}
			if (A[i] % 3 == 0) {
				if (s.find(A[i]/3) != s.end()) {
					continue;
				}
			}
			if (A[i] % 4 == 0) {
				if (s.find(A[i]/4) != s.end()) {
					continue;
				}
			}
			if (A[i] % 5 == 0) {
				if (s.find(A[i]/5) != s.end()) {
					continue;
				}
			}
			if (A[i] % 6 == 0) {
				if (s.find(A[i]/6) != s.end()) {
					continue;
				}
			}
			if (A[i] % 7 == 0) {
				if (s.find(A[i]/7) != s.end()) {
					continue;
				}
			}
			if (A[i] % 8 == 0) {
				if (s.find(A[i]/8) != s.end()) {
					continue;
				}
			}
			if (A[i] % 9 == 0) {
				if (s.find(A[i]/9) != s.end()) {
					continue;
				}
			}
			if (A[i] % 10 == 0) {
				if (s.find(A[i]/10) != s.end()) {
					continue;
				}
			}
			if (A[i] % 11 == 0) {
				if (s.find(A[i]/11) != s.end()) {
					continue;
				}
			}
			cnt++;
		}
	}
	return cnt;
}

int main() {
	scanf("%d", &N);
	for (int i=0; i<N; i++) {
		scanf("%d", &A[i]);
		s.insert(A[i]);
  }
	printf("\n%d", 	solve());
	return 0;
}

Measured memory_bytes: 13384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int S = Integer.parseInt(line);

		int h = S / 3600;
		int m = S % 3600 / 60;
		int s = S % 3600 % 60;

		System.out.println(h + ":" + m + ":" + s);
	}
}



Measured memory_bytes: 26176
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let nk = lines.shift().split(/\s/).map((v) => v - 0);
    let N = nk[0], K = nk[1];
    let Hs = lines.shift().split(/\s/).map((v) => v - 0);
    Hs.unshift(0);
    let dp = new Array(N+K).fill(Number.MAX_SAFE_INTEGER);
    dp[1] = 0;
    for (let n = 0; n <= N; n++) {
        for (let m = 1; m <= K; m++) {
            dp[n + m] = Math.min(dp[n + m], dp[n] + Math.abs(Hs[n + m] - Hs[n]));
        }
    }
    console.log(dp[N]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 28620
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,g[2000][2000]={},x,y,ans=0,sum[2001][2001]={};
    char c;
int main(){
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d %d %c",&x,&y,&c);
        if(c=='B'){
            x+=k;
        }
        x%=2*k;
        y%=2*k;
        g[x][y]++;
        g[(x+k)%(2*k)][(y+k)%(2*k)]++;
        if(x+k<2*k&&y+k<2*k){
            g[x+k][y+k]++;
            g[x+k][y]--;
            g[x][y+k]--;
        }
        else if(x+k<2*k){
            g[x+k][y]--;
            g[x][0]++;
            g[x][(y+k)%(2*k)]--;
            g[x+k][0]--;
            g[x+k][(y+k)%(2*k)]++;
        }
        else if(y+k<2*k){
            g[x][y+k]--;
            g[0][y]++;
            g[(x+k)%(2*k)][y]--;
            g[(x+k)%(2*k)][y+k]++;
            g[0][y+k]--;
        }
        else{
            g[0][0]++;
            g[(x+k)%(2*k)][(y+k)%(2*k)]++;
            g[0][(y+k)%(2*k)]--;
            g[(x+k)%(2*k)][0]--;
            g[0][y]++;
            g[x][0]++;
            g[(x+k)%(2*k)][y]--;
            g[x][(y+k)%(2*k)]--;
        }
        if((x+k)%(2*k)+k<2*k&&(y+k)%(2*k)+k<2*k){
            g[(x+k)%(2*k)+k][(y+k)%(2*k)+k]++;
            g[(x+k)%(2*k)+k][(y+k)%(2*k)]--;
            g[(x+k)%(2*k)][(y+k)%(2*k)+k]--;
        }
        else if((x+k)%(2*k)+k<2*k){
            g[(x+k)%(2*k)+k][(y+k)%(2*k)]--;
            g[(x+k)%(2*k)][0]++;
            g[(x+k)%(2*k)][((y+k)%(2*k)+k)%(2*k)]--;
            g[(x+k)%(2*k)+k][0]--;
            g[(x+k)%(2*k)+k][((y+k)%(2*k)+k)%(2*k)]++;
        }
        else if((y+k)%(2*k)+k<2*k){
            g[(x+k)%(2*k)][(y+k)%(2*k)+k]--;
            g[0][(y+k)%(2*k)]++;
            g[((x+k)%(2*k)+k)%(2*k)][(y+k)%(2*k)]--;
            g[0][(y+k)%(2*k)+k]--;
            g[((x+k)%(2*k)+k)%(2*k)][(y+k)%(2*k)+k]++;
        }
        else{
            g[0][0]++;
            g[((x+k)%(2*k)+k)%(2*k)][((y+k)%(2*k)+k)%(2*k)]++;
            g[0][((y+k)%(2*k)+k)%(2*k)]--;
            g[((x+k)%(2*k)+k)%(2*k)][0]--;
            g[0][(y+k)%(2*k)]++;
            g[(x+k)%(2*k)][0]++;
            g[x][(y+k)%(2*k)]--;
            g[(x+k)%(2*k)][y]--;
        }
    }
    for(int i=0;i<2*k;i++){
        for(int j=0;j<2*k;j++){
            sum[i+1][j+1]=sum[i+1][j]+g[i][j];
        }
    }
    for(int i=0;i<k*2;i++){
        for(int j=0;j<2*k;j++){
            sum[i+1][j+1]=sum[i+1][j+1]+sum[i][j+1];
        }
    }
    for(int i=0;i<2*k;i++){
        for(int j=0;j<2*k;j++){
            ans=max(ans,sum[i+1][j+1]);
            //printf("%d ",sum[i+1][j+1]);
        }//printf("\n");
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 31360
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */


int main() {
    int n;
    cin >> n;
    vector<P> A(n); 
    rep(i, n) {
        int a;
        cin >> a;
        A[i].first = a;
        A[i].second = i; 
    }
    sort(ALL(A));
    rep(i, n) cout << A[i].second + 1 << " ";
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int32_t main(){
    string s;
    int k;
    cin >> s >> k;

    for(int i=0; ; i++){
        if(i+1==k){
            cout << s[i] << endl;
            return 0;
        }
        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

struct edge
{
  ll to;
  ll cost;
  edge(ll t, ll c): to(t), cost(c){}
};

bool
dfs(const vector<vector<edge>> &G, int node, vector<int> &dist)
{
  for(auto nxt : G[node]){
    if(dist[nxt.to] != -iINF){
      if(dist[nxt.to] != nxt.cost + dist[node]) return false;
      else continue;
    } else {
      dist[nxt.to] = dist[node] + nxt.cost;
    }
    if(!dfs(G, nxt.to, dist)) return false;
  }

  return true;
}


int main()
{
  int N, M; cin >> N >> M;
  vector<vector<edge>> G(N);
  rep(i, 0, M){
    int l, r, d; cin >> l >> r >> d;
    --l, --r;
    G[l].push_back(edge(r, d));
    G[r].push_back(edge(l, -d));
  }

  vector<int> dist(N, -iINF);
  rep(i, 0, N){
    if(dist[i] != -iINF) continue;
    dist[i] = 0;
    if(dfs(G, i, dist)) continue;
    else{cout << "No" << endl; return 0;}
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 18916
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-10, PI = acos(-1);
const int N = 2e5 + 9, M = 1e5 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int n, mod;
vector<int> adj[N];
ll up[N], down[N];

ll mul(ll a, ll b) {
  return (a * b) % mod;
}

void dfsDown(int node, int par) {
  ll ret = 1;
  for(int it: adj[node]) {
    if(it == par) continue;
    dfsDown(it, node);
    ret = mul(ret, down[it] + 1);
  }
  down[node] = ret;
}

void dfsUp(int node, int par, ll cur) {
  up[node] = cur;
  vector<ll> suf(adj[node].size(), 1);
  ll ret = 1;
  for (int i = ((int)adj[node].size()) - 1; i >= 0; --i) {
    suf[i] = ret;
    int child = adj[node][i];
    if(par == child) continue;
    ret = mul(ret, (down[child] + 1));
  }
  ret = 1;
  for (int i = 0; i < (int)adj[node].size(); ++i) {
    int child = adj[node][i];
    if(par == child) continue;

    dfsUp(child, node, mul(mul(ret, suf[i]), cur) + 1); // . . .   if you want to calc for mid(.) so you need val of suf ( (x + 1) to n ) and all before you (1 to (x-1))

    ret = mul(ret, down[child] + 1);
  }
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif

  cin >> n >> mod;
  int u, v;
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfsDown(1, -1);
  dfsUp(1, -1, 1);
  for (int i = 1; i <= n; ++i) {
//    cerr << down[i] << ' ' << up[i] << endl;
    cout << mul(up[i], down[i]) << '\n';
  }
  return 0;
}


Measured memory_bytes: 20352
#include<stdio.h>
int main(void)
{
int h,r,a;
scanf("%d",&h);
scanf("%d",&r);
a=h+r;
if(a>0)
  printf("1\n");
else if(a==0)
    printf("0\n");
  else
    printf("-1\n");
return 0;
}


Measured memory_bytes: 2112
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline


n,m = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

#a.sort(reverse=True)

a.sort()



def check(mid):
    num = 0
    p = 0
    for i in range(n-1,-1,-1):
        c = 0
        while p<n and a[p]+a[i] < mid:
            p += 1
        num += n-p
    #print(mid,num,"mn")
    return num


ok = a[0]*2-1
ng = a[-1]*2+1

while ng - ok > 1:
    mid = (ng+ok)//2
    c = check(mid)
    if c<m:
        ng = mid
    else:
        ok = mid
    
    #print(ok,ng)
    
#print(ok)
    



ans = 0
p = n-1
num = 0

res = [0]*n
for i in range(n):
    c = 0
    while p>=0 and a[p]+a[i] >= ng:
        p -= 1
    res[i] = n-1-p
    num += n-1-p

for i in range(n):
    ans += res[i]*a[i]
ans *= 2
#print(ans,num)
print(ans+ok*(m-num))




















Measured memory_bytes: 57308
n, m = map(int, input().split())
height = list(map(int, input().split()))
observetry = list(range(1, n+1))
lose = []

for i in range(m):
    a, b = map(int, input().split())
    if height[a-1] == height[b-1]:
        lose.append(a)
        lose.append(b)
    elif height[a-1] > height[b-1]:
        lose.append(b)
    else:
        lose.append(a)

ans = list(set(observetry) - set(lose))
print(len(ans))

Measured memory_bytes: 29804
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.B
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			int d = cin.nextInt();
			var v = new int[n, d];
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < d; j++)
				{
					v[i, j] = cin.nextInt();
				}
			}
			int ans = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					double a = 0;
					for (int k = 0; k < d; k++)
					{
						a += Math.Pow((v[i,k] - v[j,k]), 2);
					}
					if (Math.Sqrt(a + 0.0) % 1 == 0) ans++;
				}
			}
			Console.WriteLine(ans);
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
N, L = [int(i) for i in input().split()]

def getMin(arr):
    idx = 0
    curr = abs(arr[0])
    for i in range(1, len(arr)):
        if abs(arr[i]) < curr:
            curr = abs(arr[i])
            idx = i
    return (idx, curr)

f = [(L + i) for i in range(N)]
idx, m = getMin(f)
print(sum([i if i != f[idx] else 0 for i in f]))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			String n = in.nextString();
			int k = in.nextInt();
			Set<String> strs = new HashSet<>();
			for (int i = 0; i < 10; i++) {
				strs.add(String.valueOf(i));
			}
			for (int i = 0; i < k; i++) {
				strs.remove(in.nextString());
			}

			Queue<String> q = new ArrayDeque<>();
			for (String str : strs) {
				q.add(str);
			}

			int ans = Integer.MAX_VALUE;
			while (!q.isEmpty()) {
				String s = q.remove();
				if (s.length() > n.length()+1) {
					break;
				}
				int t = Integer.parseInt(s);
				if (t >= Integer.parseInt(n) && t <= ans) {
					ans = t;
				}

				for (String str : strs) {
					q.add(s+str);
				}

			}

			out.println(ans);

		}

	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 82640
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define rep(i, n) for (int i{ 0 }; i < n; ++i)

using namespace std;

int main() {
    int N;
    cin >> N;

    vector<uint64_t> l(N + 1);
    l.at(0) = 2;
    l.at(1) = 1;

    for (int i{ 2 }; i <= N; ++i) l.at(i) = l.at(i - 1) + l.at(i - 2);

    cout << l.at(N) << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

int main() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s;
    return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int s1 = h1 * 60 + m1;
    int s2 = h2 * 60 + m2;
    cout << s2 - s1 - k << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int n, k, a, one;
    cin >> n >> k;
    for(int i=0; i<n; i++) {
        cin >> a;
        if(a==1) one = i;
    }
    int ans;
    if((n-1)%(k-1)==0) ans = (n-1)/(k-1);
    else ans = (n-1)/(k-1)+1;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define MAX 2000010
int heap[MAX];
int heap_size=0;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l,r,largest,tmp;
  l=left(i);
  r=right(i);
  if(l<=heap_size && heap[l]>heap[i]) largest=l;
  else largest=i;

  if(r<=heap_size && heap[r]>heap[largest])  largest=r;
  
  if(largest!=i){
    tmp=heap[i];
    heap[i]=heap[largest];
    heap[largest]=tmp;
    maxHeapify(largest);
  }
}

void builtMaxHeap(void){
  int i;
  for(i=heap_size/2;i>0;i--){
    maxHeapify(i);
  }
}

void heapIncreaseKey(i, key){
  int tmp;
  if(key<heap[i]) return;
  
  heap[i]=key;
     
  while(i>1 && heap[parent(i)]<heap[i]){
    tmp=heap[i];
    heap[i]=heap[parent(i)];
    heap[parent(i)]=tmp;
    i=parent(i);
  }
}

void maxHeapInsert(int key){
  heap_size+=1;
  heap[heap_size]= -INT_MAX;
  heapIncreaseKey(heap_size,key);
}

int heapExtractMax(){
  int max;
  if(heap_size<1) return;
  max=heap[1];
  heap[1]=heap[heap_size];
  heap_size-=1;
  maxHeapify(1);
  return max;
}

int main(){
  int i=1,n,pri;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&heap[i]);
      maxHeapInsert(heap[i]);
      i++;
    }
    else if(com[1]=='x'){
      pri=heapExtractMax();
      if(pri!=-1) printf("%d\n",pri);
    }
    else break;
  }
  return 0;
}

Measured memory_bytes: 6744
#A
"""
a,b = map(int, input().split())
if b % a == 0:
    print(b + a)
else:
    print(b-a)
"""

#B
"""
n, m = map(int, input().split())
ans = input().split()
del ans[0]
for i in range(n-1):
    a = input().split()
    del a[0]
    for k in ans:
        if k in a:
            continue
        else:
            ans.remove(k)
    if len(ans) == 0:
        break
print(len(ans))
"""
#C
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))
print(gcd_list(a))

Measured memory_bytes: 16268
#include<stdio.h>
#include<stdlib.h>
static const int MAX_N = 1000;

struct Node{
	int data;
	struct Node *prev;
	struct Node *next;
};
struct Queue{
	struct Node *front;
	struct Node *rear;
};

struct Queue *createQueue(){
	struct Queue *Q = (struct Queue *)malloc(sizeof(struct Queue));
	Q->front = NULL;
	Q->rear = NULL;
	return Q;
}
void enqueue(struct Queue *Q, int x){
	struct Node *t = (struct Node *)malloc(sizeof(struct Node));
	t->data = x;
	if(Q->front == NULL && Q->rear == NULL){
		t->prev = NULL;
		t->next = NULL;
		Q->front = t;
		Q->rear = t;
	}else{
		Q->rear->next = t;
		t->prev = Q->rear;
		t->next = NULL;
		Q->rear = t;
	}
}
void front(struct Queue *Q){
	if(Q->front == NULL) return;
	printf("%d\n", Q->front->data);
}
void dequeue(struct Queue *Q){
	if(Q->front == NULL) return;
	if(Q->front == Q->rear){
		free(Q->front);
		Q->front = NULL;
		Q->rear = NULL;
		return;
	}
	struct Node *bf = Q->front->next;
	free(Q->front);
	Q->front = bf;
	if(Q->front == Q->rear){
		Q->front->prev = NULL;
		Q->front->next = NULL;
		Q->rear->prev = NULL;
	}else{
		Q->front->prev = NULL;
	}
}
void deleteQueue(struct Queue *Q){
	struct Node *cur = Q->front;
	for(;;){
		if(cur == Q->rear){
			free(cur);
			break;
		}
		free(cur);
		cur = cur->next;
	}
	free(Q);
}

int main(){
	int n, q;
	scanf("%d %d", &n, &q);
	struct Queue *Q[MAX_N];
	for(int i = 0; i < n; i++) Q[i] = createQueue();
	for(int i = 0; i < q; i++){
		int op, t;
		scanf("%d %d", &op, &t);
		if(op == 0){
			int x;
			scanf("%d", &x);
			enqueue(Q[t], x);
		}else if(op == 1){
			front(Q[t]);
		}else{
			dequeue(Q[t]);
		}
	}
	for(int i = 0; i < n; i++) deleteQueue(Q[i]);
	return 0;
}



Measured memory_bytes: 8008
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    ll x;
    cin >> n >> x;
    ll a[2001];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    ll mini[2001][2001];
    for(int i = 1; i <= n; i++){
        mini[i][i] = a[i];
        for(int j = 0; j < n - 1; j++){
            int k = (i + j) % n;
            if(k <= 0){
                k += n;
            }
            mini[i][(i + j) % n + 1] = min(mini[i][k], a[(i + j) % n + 1]);
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            //cout << "from " << i << " to " << j << " " << mini[i][j] << endl;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += a[i];
    }
    for(int i = 1; i <= n - 1; i++){
        ll sub = i * x;
        for(int j = 1; j <= n; j++){
            int k = j - i;
            if(k <= 0){
                k += n;
            }
            sub += mini[k][j];
        }
        ans = min(ans, sub);
    }
    cout << ans << endl;
        return 0;
}

Measured memory_bytes: 31488
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

using modulo = modint<1000000007>;

#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	string S; int D;
	cin >> S >> D;
	int N = S.size();
	vector<vector<modulo> > dp(N, vector<modulo>(D, modulo(0)));
	dp[0][0] = modulo(1);
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < D; ++j) {
			for (int k = 0; k < 10; ++k) {
				dp[i][(j + k) % D] += dp[i - 1][j];
			}
		}
	}
	modulo ans = 0;
	int digitsum = 0;
	for (int i = N - 1; i >= 0; --i) {
		int digit = int(S[N - i - 1] - '0');
		for (int j = 0; j < digit + (i == 0 ? 1 : 0); ++j) {
			ans += dp[i][(D - (digitsum + j) % D) % D];
		}
		digitsum += digit;
	}
	cout << (ans - modulo(1)).get() << '\n';
	return 0;
}

Measured memory_bytes: 4608
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N, X, D;
  cin >> N >> X >> D;

  if (D < 0) {
    X *= -1;
    D *= -1;
  } else if (D == 0) {
    cout << (X == 0 ? 1 : N + 1) << endl;
    return 0;
  }
  X *= 2;
  D *= 2;

  vector<int64_t> p;
  irep(i, N) { p.push_back((i * X % D + D) % D); }
  sort(p.begin(), p.end());
  p.erase(unique(p.begin(), p.end()), p.end());

  using S = pair<int64_t, int64_t>;
  vector<vector<S>> m(p.size());
  irep(i, N) {
    int64_t L = i * (2L * X + (i - 1L) * D) / 2;
    int64_t R = i * (2L * X + (2L * N - i - 1) * D) / 2;
    int64_t rem = (L % D + D) % D;
    int j = lower_bound(p.begin(), p.end(), rem) - p.begin();

    m[j].push_back(S(L, R));
  }

  int64_t result = 0;
  rep(i, m.size()) {
    vector<S>& s = m[i];
    sort(s.begin(), s.end());

    int64_t INF = 2'00'000 * 1'000'000'000L;
    int64_t L = -INF + D;
    int64_t R = -INF;

    rep(i, s.size()) {
      int64_t l, r;
      tie(l, r) = s[i];
      if (R < l) {
        result += (R + D - L) / D;
        L = l;
        R = r;
      } else {
        R = max(R, r);
      }
    }
    result += (R + D - L) / D;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX = 2005;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N, K; cin >> N >> K;
    COMinit();
    ll n = N-K;
    for(int i = 1; i <= K; i++){
        ll ans = 0;
        ll co = COM(K-1, i-1);
        ll need = i+1-2; //入れなきゃいけないとこ
        ll rest = n-need; //残り
        if(rest < 0){
            cout << 0 << endl;
            continue;
        }
        ll hole = i+1; //穴の数
        //ll uva = hole-need;
        ll mul = COM(rest+hole-1, rest);
        //cout << " " << mul << " " << co << endl;
        ans += co*mul;
        ans %= MOD;
        cout << ans << endl;
        
    }
    //cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, d; cin >> n >> d;
  vector<vector<int> > v;
  for (int i = 0; i < n; i++)
  {
    vector<int> p;
    for (int j = 0; j < d; j++)
    {
      int t; cin >> t;
      p.push_back(t);
    }
    v.push_back(p);
  }
  int cnt = 0;
  for (int i = 0; i < n - 1; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      long long sum = 0;
      for (int k = 0; k < d; k++)
      {
        sum += pow((v[i][k] - v[j][k]), 2);
      }
      long long f = (long long)(sqrt(sum));
      if (sum == f * f) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

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

    int sz;
    cin >> sz;
    vector<int> xs(sz, 0);
    for (auto &x : xs) cin >> x;

    int ans = 0;

    for (int i = 0; i < sz; ++i) {
        const int pos = i + 1;
        const int x = xs[i];

        if (x % 2 && pos % 2) ++ans;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3636
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define __ %=Mod
using namespace std;

const ll Mod = 1e9+7;
const int maxn = 305;

int n,m;
struct node{int l,r,x;}a[maxn];
inline bool cmp(const node x,const node y){return x.r<y.r;}
ll f[maxn][maxn][maxn];

void trans(const int i,const int x,const int y,const int z)
{
	ll &tmp=f[x][y][z];
	(f[i][y][z]+=tmp)__;
	(f[x][i][z]+=tmp)__;
	(f[x][y][i]+=tmp)__;
	tmp=0;
}
int cal(const int x,const int y,const int z,const int l)
{
	int re=0;
	if(x>=l) re++;
	if(y>=l) re++;
	if(z>=l) re++;
	return re;
}
void judge(const int x,const int y,const int z,int l,int r)
{
	bool flag=true;
	for(int i=l;i<=r;i++)
	{
		if(a[i].x!=cal(x,y,z,a[i].l)){ flag=false; break; }
	}
	if(!flag) f[x][y][z]=0;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].x);
	sort(a+1,a+m+1,cmp);
	
	f[0][0][0]=1ll; int pos=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=i-1;j>=0;j--) for(int k=i-1;k>=0;k--)
		{
			if(f[i-1][j][k]) trans(i,i-1,j,k);
			if(f[j][i-1][k]) trans(i,j,i-1,k);
			if(f[j][k][i-1]) trans(i,j,k,i-1);
		}
		int np=pos; while(np<=m&&a[np].r==i) np++; np--;
		if(pos>np) continue;
		
		for(int j=i-1;j>=0;j--) for(int k=i-1;k>=0;k--)
		{
			if(f[i][j][k]) judge(i,j,k,pos,np);
			if(f[j][i][k]) judge(j,i,k,pos,np);
			if(f[j][k][i]) judge(j,k,i,pos,np);
		}
		pos=np+1;
	}
	ll re=0;
	for(int j=n-1;j>=0;j--) for(int k=n-1;k>=0;k--)
	{
		if(f[n][j][k]) (re+=f[n][j][k])__;
		if(f[j][n][k]) (re+=f[j][n][k])__;
		if(f[j][k][n]) (re+=f[j][k][n])__;
	}
	printf("%lld\n",re);
	
	return 0;
}


Measured memory_bytes: 219392