akhauriyash/Code-Regression huggingface dataset:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    N,K = LMIIS()
    P = list(map(lambda x: int(x)-1,input().split()))
    C = LMIIS()
    score_sets = []
    used = [False]*N
    tmp = P[0]
    for i in range(N):
        if not used[i]:
            tmp = i
            score_set = []
            while not used[tmp]:
                used[tmp] = True
                tmp = P[tmp]
                score_set.append(C[tmp])
            score_sets.append(score_set)
        
    ans = -INF
    for score_set in score_sets:
        # 合計が最大になる区間を探す
        len_set = len(score_set)
        sum_score_set_real = sum(score_set)
        sum_score_set = max(0,sum_score_set_real)


        
        for i in range(len_set):
            cum_sum_1 = 0
            for j in range(i,min(len_set, i+K)):
                cum_sum_1 += score_set[j]
                num_move = j-i+1
                tmp_max = cum_sum_1 + (K - num_move) // len_set * sum_score_set
                ans = max(ans, tmp_max)

        for i in range(1,len_set-1):
            cum_sum_2 = sum_score_set_real
            for j in range(i,min(len_set-1-(K-i),len_set-1)):
                cum_sum_2 -= score_set[j]
            for j in range(min(max(i,len_set-1-(K-i)),len_set-1),len_set-1):
                cum_sum_2 -= score_set[j]
                num_move = len_set - (j-i+1)
                tmp_max = cum_sum_2 + (K - num_move) // len_set * sum_score_set
                ans = max(ans,tmp_max)






        
                
    print(ans)

    
main()

Measured memory_bytes: 75652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,0,n) {
    cin >> a[i];
  }
  vector<int> s;
  vector<int > ord(n+1,-1);
  int c=1,l=0;
  int v=1;
  while(ord[v]==-1){
    ord[v]=s.size();
    s.push_back(v);
    v=a[v-1];
  }
  c=s.size()-ord[v];
  l=ord[v];
  if (k<l) cout << s[k] << endl;
  else {
    k-=l;
    k%=c;
    cout << s[l+k] << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a, b;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n);
	b.resize(n);
	REP(i, n){
		cin >> a[i] >> b[i];
	}
	sort(ALL(a));
	sort(ALL(b));
	if(n % 2 == 0){
		cout << ((b[n/2-1]+b[n/2]) - (a[n/2-1]+a[n/2])) + 1 << endl;
	}else{
		cout << (b[(n+1)/2-1] - a[(n+1)/2-1])+ 1 << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,n; cin >>a >>b;
  if (b==100) n=a*1000+b;
  else if (b/10 != 0) n=a*100+b;
  else n=a*10+b;
  
  bool ans = false;
  for (int i=1; i<n; i++){
    if (i*i == n){
      ans = true;
      break;
    }
  }
  
  if (ans) cout <<"Yes" <<endl;
  else cout <<"No" <<endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc112/tasks/abc112_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret),greater<ll>()); //降順
  return (ret);
}

int main() {
    ll N,M; cin>>N>>M;

    auto divs = divisor(M); //約数,降順
    for(auto v:divs){
        if(N*v<=M) {
            cout<<v<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()

area = h * w / 3
min_diff = min(h, w)

for h1 in range(1, h):
    if area // h1 > w:
        continue
    else:
        w1s = [int(area // h1), int(area // h1) + 1]

    for w1 in w1s:
        if w1 == w:
            continue
        else:
            h2 = h - h1
            w2s = [w1, w]

        for w2 in w2s:
            w3 = w - w1
            if w2 == w1:
                h3 = h
            else:
                h3 = h1

            areas = [h1 * w1, h2 * w2, h3 * w3]
            if max(areas) - min(areas) < min_diff:
                min_diff = max(areas) - min(areas)

print(min_diff)

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

namespace ABC107B
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            string[] input1 = Console.ReadLine().Split(' ');
            int H = int.Parse(input1[0]);
            int W = int.Parse(input1[1]);
            List<int> line = new List<int>();
            List<int> raw = new List<int>();

            string input2;
            char[,] A = new char[H, W];
            char[] charr = new char[W];
            for (int i = 0; i < H; i++)
            {
                input2 = Console.ReadLine();
                charr = input2.ToCharArray();
                for (int j = 0; j < W; j++)
                {
                    A[i, j] = charr[j];
                }
            }

            bool linewhite = true;
            for (int i = 0; i < H;i++){
                linewhite = true;
                for (int j = 0; j < W;j++){
                    if(A[i,j]=='#'){
                        linewhite = false;
                        break;
                    }
                }
                if(!linewhite){
                    line.Add(i);
                }
            }

  
            bool rawwhite = true;
            for (int j = 0; j < W; j++)
            {
                rawwhite = true;
                for (int i = 0; i < H; i++)
                {
                    if (A[i, j] == '#')
                    {
                        rawwhite = false;
                        break;
                    }
                }
                if (!rawwhite)
                {
                    raw.Add(j);

                }
            }

            foreach(int lineno in line)
            {
                foreach (int rawno in raw){
                    Console.Write(A[lineno, rawno]);
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 11220
from math import gcd
from functools import reduce
from collections import Counter


class Osa_k:
    def __init__(self, maximum):
        self.table = [-1] * (maximum+1)
        for i in range(2, maximum+1):
            if self.table[i] != -1:
                continue
            for j in range(2, int(i**0.5)+1):
                if i%j == 0:
                    self.table[i] = j
                    for k in range(2*i, maximum+1, i):
                        if self.table[k] != -1:
                            self.table[k] = j
                    break

    def factorize(self, n):
        res = Counter()
        b = n
        while 1:
            if self.table[b] == -1:
                break
            res[self.table[b]] += 1
            b //= self.table[b]
        res[b] += 1
        return res


N = int(input())
*A, = map(int, input().split())
def f():
    cnt = Counter()
    ins = Osa_k(10**6)
    for i in A:
        res = ins.factorize(i) if i!=1 else {}
        for j in res.keys():
            cnt[j] += 1
            if cnt[j] >= 2:
                return False
    return True

cond1 = f()
cond2 = (reduce(gcd, A)==1)

if cond1:
    print("pairwise coprime")
elif cond2:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 230256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

string shuffle(int num, string str)
{
	int i, j, length = str.length();
	for (i = 0; i < num; i++)
	{
		cin >> j;
		str = str.substr(j, length) + str.substr(0, j);
	}
	return str;
}

int main()
{
	int num;
	string str;
	while (true)
	{
		cin >> str;
		if (str == "-") break;
		cin >> num;
		str = shuffle(num, str);
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int c[n],w[n];
  int l[n],r[n];
  int s[n+1];
  int i,j,k;
  for(i=0;i<n;i++) cin >> c[i] >> w[i];
  s[0]=c[0];
  for(i=0;i<n;i++) s[i+1]=s[i]+w[i]; 
  for(i=0;i<n;i++){
    l[i]=0;r[i]=0;
    for(j=i-1;j>=0;j--){
      if(s[i]-s[j]<=c[i]) l[i]++;
      else break;
    }
    for(j=i+2;j<=n;j++){
      if(s[j]-s[i+1]<=c[i]) r[i]++;
      else break;
    }
    //cout << i << ":" << l[i] << "/" << r[i] << endl;
  }
  bool p[1005][1005]={{}};
  for(j=0;j<n;j++) p[1][j]=true;
  for(i=1;i<=n;i++){
    for(j=0;j<n;j++){
      if(j-i>=0){
	if(l[j]>=i&&p[i][j-i]) p[i+1][j-i]=true;
      }
      if(j+i<n){
	if(r[j]>=i&&p[i][j+1]) p[i+1][j]=true;
      }
    }
  }
  /*
  for(i=0;i<n;i++){
    cout << i << ":";
    for(j=1;i+j<=n;j++){
      cout << (p[j][i]?1:0) << " ";
    }
    cout << endl;
  }
  */
  int dp[1005];
  fill(dp,dp+1005,n);
  dp[0]=0;
  for(i=0;i<n;i++){
    for(j=1;i+j<=n;j++){
      if(p[j][i]) dp[i+j]=min(dp[i+j],dp[i]+1);
    }
  }
  
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();
    int ans = 0;
    int[][] c = new int[h][w];
    for(int i = 0; i < h; i++) {
      String s = sc.next();
      for(int j = 0; j < w; j++) {
        if(s.charAt(j) == '#') c[i][j] = 1;
      }
    }
    for(int i = 0; i < (int)Math.pow(2, h); i++) {
      for(int j = 0; j < (int)Math.pow(2, w); j++) {
        int t = 0;
        for(int a = 0; a < h; a++) {
          for(int b = 0; b < w; b++) {
            if((c[a][b] == 1) && ((i & (1 << a)) == 0) && ((j & (1 << b)) == 0)) t++;
          }
        }
        if(t == k) ans++; 
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35856
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        while (true){
            int a = sc.nextInt();
            int sum=0;
            if (a==0)break;
            for (int i=0;i<a/4;i++){
                sum+=sc.nextInt();

            }
                System.out.println(sum);
        }

    }
}

Measured memory_bytes: 18180
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1e5;
VI e[N];
int reach[N][2];

void dfs(int now, int d){
	reach[now][d] = 1;
	for (int next : e[now]){
		if (reach[next][d^1]) continue;
		dfs(next, d^1);
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	while (m--){
		int a, b;
		scanf("%d %d", &a, &b);
		a--;
		b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	dfs(0, 0);

	int even = 0, odd = 0;
	REP(i,n){
		even += reach[i][0];
		odd += reach[i][1];
	}

	ll ans = 0;
	REP(i,n){
		if (reach[i][0] && reach[i][1]){
			ans += (n - e[i].size() - 1);
		}else if (reach[i][0]){
			ans += (odd - e[i].size());
		}else{
			ans += (even - e[i].size());
		}
		// cout << ans << endl;
	}

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

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

int main() {
  int n,x = 0,maxi = 0;
  string s;
  cin >> n >> s;
  for(int i = 0; i < n; i++){
    if(s.at(i) == 'I'){
      x++;
      maxi = max(maxi,x);
    }else{
      x--;
    }
  }
  cout << maxi << endl;
}


Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = [el for el in map(int,input().split())]
A = [[] for _ in range(N)]
for i in range(N):
    new = [el for el in map(int,input().split())]
    A[i] = new
ans = 0
for i in range(N):
    cand = 0
    for j in range(M):
        cand += A[i][j]*B[j]
    if cand + C >0:
        ans += 1
print(ans)
    

Measured memory_bytes: 3064
#!/usr/bin/env python3
#ABC99 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,c = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(c)]
g = [list(map(int,input().split())) for _ in range(n)]

cnt0 = [0]*30
cnt1 = [0]*30
cnt2 = [0]*30

for y in range(1,n+1):
    for x in range(1,n+1):
        if (x+y) % 3 == 0:
            cnt0[g[y-1][x-1]-1] += 1
        elif (x+y) % 3 == 1:
            cnt1[g[y-1][x-1]-1] += 1
        else:
            cnt2[g[y-1][x-1]-1] += 1

l = list(permutations(range(c),3))
ans = float('inf')
for c0,c1,c2 in l:
    preans = 0
    for i in range(c):
        preans += d[i][c0] * cnt0[i]
        preans += d[i][c1] * cnt1[i]
        preans += d[i][c2] * cnt2[i]
    ans = min(ans,preans)
print(ans)


Measured memory_bytes: 46812
#include<bits/stdc++.h>
using namespace std;
main(){
	string str;
	cin>>str;
	int n = str.length();
	int flag = 0;
	if(str[0] != 'A'){
		flag = 1;
	}
	else{
		int count = 0;
		for(int i=2;i<n-1;i++){
			if(str[i] == 'C'){
				count++;
			}
		}
		if(count != 1){
			flag = 1;
		}
		count = 0;
		for(int i=1;i<n;i++){
			if(islower(str[i])){
				count++;
			}
		}
		if(count != n-2){
			flag = 1;
		}
	}
	if(flag == 0){
		cout<<"AC"<<endl;
	}
	else{
		cout<<"WA"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define M 30
using namespace std;
int n,k,c,depth[N],parent[N][M];
vector<int> e[N];

void dfs(int x,int d){
  depth[x]=d;
  for(int i=0;i<(int)e[x].size();i++)
    dfs(e[x][i],d+1);
}

int lca(int u,int v){
  if(depth[u]<depth[v])swap(u,v);
  int K=depth[u]-depth[v];
  for(int i=0;i<M;i++)
    if(K>>i&1)u=parent[u][i];
  if(u==v)return u;
  for(int j=M-1;j>=0;j--){
    if(parent[u][j]==parent[v][j])continue;
    u=parent[u][j];
    v=parent[v][j];
  }
  return parent[u][0];
}

int main(){
  cin>>n;
  memset(parent,-1,sizeof(parent));
  for(int i=0;i<n;i++){
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      scanf("%d",&c);
      e[i].push_back(c);
      parent[c][0]=i;
    }
  }
  for(int j=1;j<M;j++)
    for(int i=0;i<n;i++)
      if(parent[i][j-1]==-1)parent[i][j]=-1;
      else parent[i][j]=parent[ parent[i][j-1] ][j-1];

  dfs(0,0);
  int q,u,v;
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>u>>v;
    printf("%d\n",lca(u,v));
  }
  return 0;
}

Measured memory_bytes: 23500
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, K;
long long a[100005];
//leftsum[i] = (0, 1,,, , i-1)
long long leftsum[100005];
//righhsum[i] = (i, i+1, i+2, i+3,,)
long long rightsum[100005];
//sumi[i] = (0, 1,,, , i-1)
long long sumi[100005];

int main(){
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}

	leftsum[0] = 0;
	sumi[0] = 0;
	for(int i = 0; i < N; i++){
		leftsum[i+1] = leftsum[i] + max((long long)0, a[i]);
		sumi[i+1] = sumi[i] + a[i];
	}

	for(int i = N-1; i >= 0 ; i--){
		rightsum[i] = rightsum[i+1] + max((long long)0, a[i]);
	}

	long long ans = 0;
	for(int i = 0; i <= N - K; i++){
		//cout << " i = " << i << endl;
		//[i,,,,i+K-1]
		long long tmpsum;
		tmpsum = max((long long) 0, sumi[i+K] - sumi[i]);
		//cout << i << " - " << i + K - 1 << " : " << tmpsum << endl;

		//cout << "left sum = " << leftsum[i] << endl;
		//cout << "right sum = " << rightsum[i+K] << endl;
		ans = max(ans, tmpsum + leftsum[i] + rightsum[i+K]);
	}
	cout << ans << endl;
}


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

struct zahyou{
  int hyoukou;
  int x;
  int y;
};

struct motoz{
  int hyoukou;
  int point;
  int ok;
};

class LessHyoukou{
public:
  bool operator()(const struct zahyou & riLeft, const struct zahyou & riRight) const{
    return riLeft.hyoukou < riRight.hyoukou;
  };
};

struct zahyou z[1000000];
struct motoz zz[1002][1002];

int main(){
  int h,w;
  cin >> h >> w;
  for(int i=0;i<1002;i++){
    for(int j=0;j<1002;j++){
      zz[i][j].hyoukou=10000000;
      zz[i][j].point = 0;
      zz[i][j].ok=0;
    }
  }
  int m;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> m;
      z[i*w+j].hyoukou = m;
      z[i*w+j].x = j+1;
      z[i*w+j].y = i+1;
      zz[j+1][i+1].hyoukou = m;
    }
  }

  sort(z,z+h*w,LessHyoukou());

  int ans = 0;
  int vect[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
  int isHekomi;
  for(int i=0;i<h*w;i++){
    isHekomi=1;
    for(int j=0;j<4;j++){
      if(z[i].hyoukou>zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].hyoukou)
        isHekomi=0;
    }
    if(isHekomi){
      for(int j=0;j<4;j++){
        if(zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].point*(zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].point!=z[i].hyoukou)){
          zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].ok=1;
        }else{
          zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].point=z[i].hyoukou;
        }
      }
    }else if(zz[z[i].x][z[i].y].ok){
      for(int j=0;j<4;j++){
          zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].ok=1;
      }
    }else{
      for(int j=0;j<4;j++){
        if(z[i].hyoukou<zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].hyoukou)
          if(zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].point*(zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].point!=zz[z[i].x][z[i].y].point)){
            zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].ok=1;
          }else{
            zz[z[i].x+vect[j][0]][z[i].y+vect[j][1]].point=zz[z[i].x][z[i].y].point;
          }
      }
    }
    if( zz[z[i].x][z[i].y].ok ){
      ans++;
    }
  }

  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 26628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll MAX_N = ll(1e5 + 5);
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i,n) for (int i = n; i >=0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    while(1){
    ll D, n, m, ans = 0;
    vector<ll> d;
    cin >> D;
    if(D==0)break;
    cin >> n >> m;
    d.push_back(0);
    for(int i = 1;i<n;i++){
        ll a;
        cin >> a;
        d.push_back(a);
    }
    d.push_back(D);
    SORT(d);
    //for(auto i : d)cout << ">" << i << endl;
    for(int i = 0;i<m;i++){
        ll k, num;
        cin >> k;
        num = upper_bound(ALL(d),k)- d.begin() - 1;
        ans += min(abs(d[num]-k),abs(d[num+1]-k));
    }
    
    cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3776
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll A,B,C;
  cin >> A >> B >> C ;
  ll N=A+B+C;
  ll K=0;
  while(A%2==0 && (B%2==0 && C%2==0)){
    A=(N-A)/2;B=(N-B)/2;C=(N-C)/2;
    if(K>10000000){
      cout << -1 << endl;
      return 0;
    }
    K++;
  }
  cout << K << endl;
}


Measured memory_bytes: 256
N,D=gets.split.map(&:to_i)
X=N.times.map{gets.split.map(&:to_i)}
ans = 0
(0..N-2).each do |i|
  (i+1..N-1).each do |j|
    sum = 0
    D.times do |k|
      sum += (X[i][k] - X[j][k])**2
    end
    sum = Math.sqrt(sum)
    if sum.to_i == sum
      ans += 1
    end
  end
end
puts ans

Measured memory_bytes: 1788
hand = None

def find(trg, start = 0):
    count = 0
    m = -1 
    mm = 0
    for i in range(start, 5):
        if m == hand[i]:
            count += 1
        else:
            if count == trg:
                mm = i
                break
            m = hand[i]
            count = 1
    if count == trg:
        mm = i
    return mm

while True:
    try:
        hand = map( int, raw_input().split(',') ) 
    except EOFError:
        break
    hand.sort()
    if find(4): 
        print "four card"
    elif find(3) and find(2) and find(3) != find(2): 
        print "full house"
    elif (hand[1] - hand[0]) * (hand[2] - hand[1]) * (hand[3] - hand[2]) * (hand[4] - hand[3]) == 1 or (hand[0] == 1 and hand[1] == 10 and hand[2] == 11 and hand[3] == 12 and hand[4] == 13):
        print "straight"
    elif find(3):
        print "three card"
    elif find(2)*find(2,2) and find(2) != find(2, 2):
        print "two pair"
    elif find(2):
        print "one pair"
    else:
        print "null"

Measured memory_bytes: 4284
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

// Union-Find
vector<int> parent(100001);

void init(int n)
{
  for (int i = 0; i < n; i++)
    parent[i] = i;
}

int root(int x)
{
  if (parent[x] == x)
    return x;
  else
    return parent[x] = root(parent[x]);
}

bool same(int x, int y)
{
  return root(x) == root(y);
}

void unite(int x, int y)
{
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  parent[x] = y;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  REP(i, N)
  {
    cin >> p[i];
    p[i]--;
  }
  vector<int> x(M), y(M);
  REP(i, M)
  {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
  }
  init(N);
  REP(i, M)
  unite(p[x[i]], p[y[i]]);
  int ans = 0;
  REP(i, N)
  {
    if (same(i, p[i]))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    val sp = (1..N).map {
        val input = readLine()!!.split(" ")
        Pair(input[0], input[1].toInt())
    }
    var map = mutableMapOf<String,MutableList<Pair<Int,Int>>>()
    var index = 0
    for((s,p) in sp) {
        if(!map.contains(s)) {
            map.set(s, mutableListOf<Pair<Int,Int>>())
        } else {
            
        }
        map[s]!!.add(Pair(p,index))
        index += 1
    }

    map.keys.sorted().map{
        map[it]!!.sortedByDescending() {
            it.first
        }
    }.flatMap{it}.map {it.second + 1}.forEach(::println)
}
 

Measured memory_bytes: 37996
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>x(N);
	vector<int>y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	int ans = MOD;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j)continue;
			int cx = x[j] - x[i];
			int cy = y[j] - y[i];
			int cnt = 0;
			for (int k = 0; k < N; k++) {
				for (int l = 0; l < N; l++) {
					if (cx == x[l] - x[k] && cy == y[l] - y[k])cnt++;
				}
			}
			ans = min(ans, N - cnt);
		}
	}
	cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    for (int i = 0; i < N+1; i++) cin >> A.at(i);
    for (int i = 0; i < N; i++) cin >> B.at(i);
    ll res = 0;
    for (int i = 0; i < N; i++){
        ll battle = min(A.at(i), B.at(i));
        res += battle;
        A.at(i) -= battle;
        B.at(i) -= battle;
        battle = min(A.at(i+1), B.at(i));
        res += battle;
        A.at(i+1) -= battle;
        B.at(i) -= battle;
    }
    cout << res << endl;
}

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

int n, ans, a[200005], f[1000005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        f[a[i]]++;
    }

    for (int i = 0; i < n; i++) {
        f[a[i]]--;
        for (int j = 1; j*j <= a[i]; j++) {
            if (a[i]%j == 0) {
                if (f[j] > 0 || (f[a[i]/j]) > 0) {
                    ans++;
                    break;
                }
            }
        }
        f[a[i]]++;
    }
    cout << n-ans << '\n';

    return 0;
}

Measured memory_bytes: 8304
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;

inline int read() {
	int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
}

const int N = 300005, mod = 1e9 + 7;
int f[N], g[N], a[N];

int main() {
//	freopen("a.in", "r", stdin);
	int n = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	for (int i = 1; i <= n; ++i) f[i] = 1;
	for (int i = 1; i <= n; ++i) {
		f[i] = max(f[i], f[i - 1]);
		if (g[a[i]]) {
			f[i] = f[g[a[i]]];
			if (g[a[i]] != i - 1) f[i] = (f[i] + f[i - 1]) % mod;
		}
		g[a[i]] = i;
	}
	cout << f[n];
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*int s;
	scanf("%d", &s);
	if (s % 10 == s % 100 / 10 || s % 100 / 10 == s % 1000 / 100 || s / 1000 == s % 1000 / 100) {
		printf("Bad\n");
	}
	else {
		printf("Good\n");
	}*/

	int n, l;
	scanf("%d %d", &n, &l);
	int absmin = 99999999;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += l + i;
		if (abs(absmin) > abs(l + i)) {
			absmin = l + i;
		}
	}
	sum -= absmin;
	printf("%d\n", sum);
	return 0;
}

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

int main()
{
  int H,W;
  cin>>H>>W;
  char a[H+2][W+2];
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>a[i][j];
    }
  }
  
  for(int i=0;i<=W+1;i++){
    a[0][i]='#';
    a[H+1][i]='#';
  }
  for(int i=0;i<=H+1;i++){
    a[i][0]='#';
    a[i][W+1]='#';
  }
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout<<a[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
//const long mod=(long)1e9+7;
inline void solve(void){
  int H,N;in(H,N);
  vector<int>A(N);ins(A);
  sort(rall(A));
  for(auto e:A){
    H-=e;
    if(H<=0){
      out("Yes");
      return;
    }
  }
  out("No");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 640
use itertools::Itertools;
use proconio::input;

fn main() {
    input!(len: [u64]);
    let ans = len
        .into_iter()
        .sorted()
        .tuple_combinations()
        .filter(|&(a, b, c)| a + b > c && a != b && b != c)
        .count();
    println!("{}", ans);
}


Measured memory_bytes: 2192
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define INT_INF 2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));

bool binarySearch(vector<int> S, int N, int key){
    int left = 0, right = N;
    while(abs(right - left > 1)){
        int mid = (left + right) / 2;
        if(S[mid] == key) return true; 
        else if(S[mid] > key) right = mid;
        else left = mid;
    }
    return false;
}

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

   int N;
   cin >> N;
   vector<int> S(N);
   for(int i = 0; i < N; i++) cin >> S[i];
   int Q;
   cin >> Q;
   vector<int> T(Q);
   for(int i = 0; i < Q; i++) cin >> T[i];

   int cnt = 0;
   for(int t : T){
       if(binarySearch(S, N, t)) cnt++;
   }
   cout << cnt << endl;
}



Measured memory_bytes: 3868
s = input()
mod = 10**9 + 7
n = len(s)
dp = [[0] * 13 for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    ss = s[i]
    for j in range(13):
        if ss == '?':
            for k in range(10):
                dp[i+1][(j*10+k)%13] += dp[i][j]
        else:
            dp[i+1][(j*10+int(ss))%13] += dp[i][j]
        dp[i+1][j] %= mod
print(dp[n][5]%mod)

Measured memory_bytes: 61916
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

max_a = max(A)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    s = 0
    for i in range(len(filtered)):
        s += filtered[i]
        if s >= H:
            print(i + 1)
            break


Measured memory_bytes: 11748
import sys

def main(N,M,A):
    ans = []
    for i in range(N-1):
        for j in range(i+1,N):
            if A[i]+A[j] <= M:
                ans.append(A[i]+A[j])
    return max(ans) if ans else 'NONE'

while 1:
    N,M = [int(x) for x in sys.stdin.readline().split()]
    if N==M==0:
        break
    A = [int(x) for x in sys.stdin.readline().split()]
    print(main(N,M,A))


Measured memory_bytes: 26928
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	string s; cin>>s;
	repp(i,1,s.size()){
		if(s[i]==s[i-1]){
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ff first
#define ss second
 
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif
 
const int inf = 2e18;
const int mod = 1e9 + 7;

signed main(){
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif
 
	int n, k; cin>>n>>k;
	vector<int> arr(n);
	vector<int> ans(k+1);
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	for(int i=0; i<=k; i++){
		bool flag = true;
		for(int j=0; j<n; j++){
			if(i-arr[j]>=0){
				if(ans[i-arr[j]]==2){
					ans[i] = 1;
					flag = false;
					break;
				}
			}
		if(flag) ans[i] = 2;
		}
	}
	if(ans[k]==1) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int n, m; cin >> n >> m;
   V<V<int>> A(n, V<int>(n, INF));
   REP(i, m) {
      int s, t, d; cin >> s >> t >> d;
      A[s][t] = d;
   }

   V<V<V<int>>> dp(n, V<V<int>>(1<<n, V<int>(n, INF)));
   REP(k, n) {
      dp[k][0][k] = 0;
      REP(s, 1<<n) {
         REP(i, n) {
            REP(j, n) if (!(s >> j & 1)) {
               chmin(dp[k][s | 1<<j][j], dp[k][s][i] + A[i][j]);
            }
         }
      }
   }
   int ans = INF;
   REP(k, n) {
      chmin(ans, dp[k][(1<<n)-1][k]);
   }
   cout << (ans == INF ? -1 : ans) << endl;

   return 0;
}



Measured memory_bytes: 80640
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans = INT_MAX;
void f(string a, string b, string c) {
	vector<string> v;
	for(int i=0; i<=a.size(); i++) {
		string acp = a;
		bool ok = 1;
		for(int j=0; j<b.size(); j++) {
			if(i+j >= acp.size()) {
				acp.push_back(b[j]);
			} else if(acp[i+j] == '?') {
				if(b[j] == '?') {
					continue;
				} else {
					acp[i+j] = b[j];
				}
			} else {
				if(b[j] == '?' || acp[i+j] == b[j])
					continue;
				else {
					ok = 0;
					break;
				}
			}
		}
		if(!ok || acp.size() >= ans)
			continue;
		for(int j=0; j<=acp.size(); j++) {
			int nxtans = max((int)acp.size(),j+(int)c.size());
			if(nxtans >= ans)
				continue;
			bool tok = 1;
			for(int k=0; k<c.size() && j+k<acp.size(); k++) {
				if(acp[j+k] == '?' || c[k] == '?' || acp[j+k] == c[k]) {
					continue;
				} else {
					tok = 0;
					break;
				}
			}
			if(tok) {
				ans = min(ans, nxtans);
				break;
			}
		}
	}
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;
	f(a, b, c);
	f(a, c, b);
	f(b, a, c);
	f(b, c, a);
	f(c, a, b);
	f(c, b, a);
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
int main() {
	int r, d, x;
	scanf("%d %d %d", &r, &d, &x);
	for(int i=1;i<=10;++i) {
		x = r*x - d;
		printf("%d\n", x);
	}
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int maxn = 55;

ll f[maxn][maxn],g[maxn][maxn];
int n,a,b;
ll v[maxn];

ll gcd(ll x,ll y){
  return y==0?x:gcd(y,x%y);
}

int main() {
  //freopen("in.cpp","r",stdin);
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++)cin>>v[i];
  memset(f,-1LL,sizeof(f));
  f[0][0]=0,g[0][0]=1;
  for(int i=0;i<n;i++)
  for(int j=0;j<=i;j++){
    if(f[i][j]==-1)continue;
    if(f[i][j]>f[i+1][j]){
      f[i+1][j]=f[i][j];
      g[i+1][j]=g[i][j];
    } else if(f[i][j]==f[i+1][j]){
      g[i+1][j]+=g[i][j];
    }
    ll tmp=f[i][j]+v[i+1];
    if(tmp>f[i+1][j+1]){
      f[i+1][j+1]=tmp;
      g[i+1][j+1]=g[i][j];
    } else if(tmp==f[i+1][j+1]){
      g[i+1][j+1]+=g[i][j];
    }
  }
  ll mx=0,mxx=1;
  ll ret=0;
  for(int i=a;i<=b;i++){
    ll tmx=f[n][i];
    ll tmxx=i;
    ll tmp=gcd(tmx,tmxx);
    tmx/=tmp,tmxx/=tmp;
    if(mx*tmxx<mxx*tmx){
      ret=g[n][i];
      mx=tmx,mxx=tmxx;
    } else if(mx*tmxx==mxx*tmx){
      ret+=g[n][i];
    }
  }
  printf("%.10f\n",mx*1.0/mxx);
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

template<int Mod> class ModInt {
  int v;
public:
  constexpr ModInt(const long long x = 0) noexcept : v((x % Mod + Mod) % Mod) {}
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    v += rhs.v;
    if (v >= Mod)
      v -= Mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (v < rhs.v)
      v += Mod;
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    v = int(1LL * v * rhs.v % Mod);
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1)
        *this *= rhs;
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  constexpr ModInt operator-() const noexcept { return ModInt(-v); }
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr bool operator==(const ModInt rhs) const noexcept {
    return v == rhs.v;
  }
  constexpr bool operator!=(const ModInt rhs) const noexcept {
    return v != rhs.v;
  }
  constexpr ModInt pow(long long exp) const noexcept {
    ModInt res(1), mul(v);
    while (exp) {
      if (exp & 1)
        res *= mul;
      mul *= mul;
      exp >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt obj) noexcept {
    return os << obj.v;
  }
  friend istream &operator>>(istream &is, ModInt &obj) noexcept {
    long long tmp;
    is >> tmp;
    obj = ModInt<Mod>(tmp);
    return is;
  }
};
constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  mint oth = (mint(9).pow(n)-mint(8).pow(n))*2+mint(8).pow(n);
  mint ans = mint(10).pow(n)-oth;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A,B,count=0;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
    if( (i%10==i/10000) && ((i/10)%10==(i/1000)%10) )
      count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256