akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

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

  vector<Pi> Ans1;
  vector<Pi> Ans2;
  Graph G(N);


  rep(i, N) {
    int carry = 0;
    rep(j, M) {
      int x; cin >> x;
      if (j == M -1) {
        G[i].push_back(x + carry);
      } else {
        if ((x + carry) % 2 == 1) {
          Ans1.push_back(make_pair(i, j));
          x = x + carry - 1;
          carry = 1;
        } else {
          x = x + carry;
          carry = 0;
        }
        G[i].push_back(x);

      }
    } 
  }

  // rep(i, N) {
  //   rep(j, M) {
  //     cout << G[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  // cout << endl;
  // for (auto x: Ans1) {
  //   cout << x.first << " " << x.second << endl;
  // }

  int carry = 0;
  rep(i, N) {
    if (i == N - 1) {
      G[i][M-1] = G[i][M-1] + carry;
    } else {
      if ((G[i][M-1] + carry) % 2 == 1) {
        Ans2.push_back(make_pair(i, M-1));
        G[i][M-1] = G[i][M-1] + carry - 1;
        carry = 1;
      } else {
        G[i][M-1] = G[i][M-1] + carry;
        carry = 0;
      }
    }
  }

  // cout << endl;
  // rep(i, N) {
  //   rep(j, M) {
  //     cout << G[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  cout << Ans1.size() + Ans2.size() << endl;
  for (auto x: Ans1) {
    cout << x.first+1 << " " << x.second+1 << " " << x.first+1 << " " << x.second+2<< endl;
  }
  for (auto x: Ans2) {
    cout << x.first+1 << " " << x.second+1 << " " << x.first +2 << " " <<  x.second+1 << endl;
  }
}


Measured memory_bytes: 4088
import sys, math
#import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.buffer.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
#from decimal import Decimal

n=int(data())
A=mdata()
d=dd(int)
for i in range(n):
    d[A[i]]+=1
cnt=0
m=max(A)
P=[0]*(m+1)
for i in range(1,m+1):
    if d[i]>0:
        if P[i]==0:
            for j in range(2*i,m+1,i):
                P[j]=1
            if d[i]==1:
                cnt+=1
out(cnt)


Measured memory_bytes: 177616
/*2019/07/29 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
/*
int asc_t(const void *a,const void *b){return ((user_t*)a)->score - ((user_t*)b)->score;}
int desc_t(const void *a,const void *b){return ((user_t*)b)->score - ((user_t*)a)->score;}
*/

int main(){
    int a,b;
    char str[200];

    scanf("%d %d",&a,&b);
    scanf("%s",str);

    int cnt=0;
    for(int i=0;i<a+b+1;i++){
        if(str[i]=='-'){
            cnt++;
        }
    }
    
    if(cnt==1&&str[a]=='-'){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[3001];
ll dp[3001][3001];
ll s[3001];
ll calc(ll i,ll j){
	if(i==j){
		dp[i][j]=a[i];
		return dp[i][j];
	}
	if(dp[i][j]!=-1)
	return dp[i][j];
	dp[i][j]=max(a[i]+s[j]-s[i]-calc(i+1,j),a[j]+s[j-1]-s[i-1]-calc(i,j-1));
	return dp[i][j];
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=s[i-1]+a[i];
	}
	memset(dp,-1,sizeof(dp));
	calc(1,n);
	cout<<(dp[1][n]-(s[n]-s[0]-dp[1][n]));
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
using namespace std;
int n, m, p, x, s, t[105];
int main() {
	cin>>n;
	for(int i=1; i<=n; i++) cin>>t[i], s += t[i];
	cin>>m;
	while(m--) {
		cin>>p>>x;
		cout<<s + x - t[p]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
    int main(){
    string a,b,c;
    cin >> a >> b >> c;
    char dif='A'-'a';
    printf("%c%c%c\n", a[0] + dif, b[0] + dif, c[0] + dif);
    }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			char c;
			cin >> c;
			if (i == j) {
				cout << c;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		final int r = sc.nextInt();
		final int c = sc.nextInt();
	
		final int a1 = sc.nextInt();
		final int a2 = sc.nextInt();
		final int b1 = sc.nextInt();
		final int b2 = sc.nextInt();
		
		int b1_ = Math.abs(b1 - a1);
		int b2_ = Math.abs(b2 - a2);
		
		long pow = 1;
		if(b1_ == r - b1_){
			pow *= 2;
		}
		if(b2_ == c - b2_){
			pow *= 2;
		}
		
		b1_ = Math.min(b1_, r - b1_);
		b2_ = Math.min(b2_, c - b2_);
		
		
		long dp[][] = new long[r][c];
		
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				if(i == 0 && j == 0){
					dp[i][j] = 1;
				}else if(i == 0){
					dp[i][j] = dp[i][j-1];
				}else if(j == 0){
					dp[i][j] = dp[i-1][j];
				}else{
					dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 100000007;
				}
			}
		}
		
		System.out.println((dp[b1_][b2_] * pow) % 100000007);
	}

}

Measured memory_bytes: 28484
N = int(input())
T,A = 1,1
for _ in range(N):
    t,a = map(int,input().split())
    k1 = (T+t-1)//t
    k2 = (A+a-1)//a
    k = max(k1,k2)
    T = k*t
    A = k*a
print(T+A)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;

  cout<<(n-1) / 2<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll n;
vector<ll> g[100000];
ll dp[100000][2];
ll MOD = 1e9 + 7;

void dfs(ll idx, ll par) {
    ll latte = 1, malta = 1;
    for(auto &to : g[idx]) {
        if (to == par) continue;
        dfs(to, idx);
        (latte *= (dp[to][0] + dp[to][1]) % MOD) %= MOD;
        (malta *= dp[to][0]) %= MOD;
    }
    dp[idx][0] = latte;
    dp[idx][1] = malta;
}
int main() {
    cin >> n;
    rep(i, n-1) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    dfs(0, -1);
    cout << (dp[0][0] + dp[0][1]) % MOD << endl;
}

Measured memory_bytes: 12800
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    n=len(S)

    # 同じ文字が連続していたらOK
    for i in range(n-1):
        if(S[i]==S[i+1]):
            print(i+1,i+2)
            return

    # 1つ飛ばしで同じならOK
    for i in range(n-2):
        if(S[i]==S[i+2]):
            print(i+1,i+3)
            return

    # そうでなければ存在しない
    print(-1,-1)
resolve()

Measured memory_bytes: 39280
// AOJ 0283: Study Session
// 2018.1.29 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MAX(a,b) ((a)>=(b)?(a):(b))

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int N;
int s[1000002], t[1000002];
int leader[102], lsz;
int group[102],  gsz;

int bsch(int x)
{
	int m, l = 0, r = N;

    while (l < r) {
        m = (l+r) >> 1;
        if (t[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int check(int v)
{
	int i, s;

	if (!lsz) return 0;
	s = bsch(group[0]+1) - bsch(group[0]-v);
    for (i = 1; i < lsz; i++) {
		s += bsch(group[i]+1) - bsch(MAX(group[i-1]+1, group[i]-v));
	}
	return s;
}

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int Q, i, a, lo, hi, m, f, max;
	char buf[20], *p;
	
	N = in(), Q = in();
    for (i = 0; i < N; i++) s[i] = t[i] = in();
	qsort(t, N, sizeof(int), cmp);
	max = t[N-1]+1;

	lsz = 0, f = 1;
    while (Q--) {
		fgets(p=buf, 20, stdin);
		while (*p > ' ') p++;
		a = atoi(p+1);
		if (*buf == 'A') leader[lsz++] = a-1, f = 1;
		else if (*buf == 'R') {
			f = 1, a--;
            for (i = 0; leader[i] != a; i++);
			while (i < lsz) leader[i] = leader[i+1], i++;
			lsz--;
        } else if (*buf == 'C') {
			if (f) {
				gsz = 0;
				for (i = 0; i < lsz; i++) group[gsz++] = s[leader[i]];
				qsort(group, gsz, sizeof(int), cmp);
			}
			f = 0;

			lo = -1, hi = max;
            while (hi - lo > 1) {
                m = (lo+hi) >> 1;
                if (check(m) >= N-a) hi = m; else lo = m;
            }
            if (hi == max) printf("NA\n");
            else printf("%d\n", hi);
        }
    }
    return 0;
}


Measured memory_bytes: 13244
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s,a,b,c,d;
	scanf("%d",&s);
	a=s/1000;
	b=s/100%10;
	c=s/10%10;
	d=s%10;
	if(a==b||b==c||c==d)
	{
		printf("Bad");
	}
	else
	{
		printf("Good"); 
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

//vector<pair<int, int>> v[19803];

int main() {
    vector<pair<int, int>> v;
    while (true) {
        int h ,w;
        cin >> h >> w;
        if (h == 0) break;
        int n = h * h + w * w;
        int mi = 1e9;
        pair<int , int> p;
        for (Int i = 150; i >= 1; i--) {
            for (Int j = 150; j > i; j--) {
                int x = i * i + j * j;
                if (x > n && mi >= x) {
                    mi = x;
                    p = {i, j};
                }
                else if (x == n && i > h) {
                    mi = x;
                    p = {i, j};
                }
            }
        }
        v.emplace_back(p);
    }
    //cout << endl;
    for (auto x : v) cout << x.first << " " << x.second << endl;
    return 0;
} 



Measured memory_bytes: 3084
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long

int n;
int a[100005];

int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;++i)
            scanf("%d",&a[i]);
        sort(a,a+n);
        int ans=1;
        LL sum=0;
        for(int i=0;i<n-1;++i)
        {
            sum+=a[i];
            if(2*sum>=a[i+1])
                ans++;
            else ans=1;
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 640
X, Y = map(int, input().split())
total = 0

if X == 1:
    total += 300000
elif X == 2:
    total += 200000
elif X == 3:
    total += 100000

if Y == 1:
    total += 300000
elif Y == 2:
    total += 200000
elif Y == 3:
    total += 100000

if X == 1 and Y == 1:
    total += 400000

print(total)

Measured memory_bytes: 3064
#include <stdio.h>
char RB[13][13];int f[4][2]={1,0,-1,0,0,1,0,-1};void dfs(int x, int y) {RB[x][y]='0';for (int k=0;k<4;k++) {int a=x+f[k][0],b=y+f[k][1];if (a>=0 && a<12 && b>=0 && b<12 && RB[a][b]=='1') dfs(a,b);}}
int main() {int i,j,k;while (scanf("%s",&RB[0])!=EOF) {for (i=1;i<12;scanf("%s",&RB[i++]));k=0;for (i=0;i<12;i++) for (j=0;j<12;j++) if (RB[i][j]=='1') k++,dfs(i,j);printf("%d\n",k);}return 0;}

Measured memory_bytes: 968
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	if(k==1){
		cout<<"0"<<endl;
		return 0;
	}
	n-=(k-1)*1;
	int sum=n-1;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool fpWins[100010];

int main() {
	int n, k; scanf("%d %d", &n, &k);
	vector<int> s(n);
	for (int i = 0; i < n; ++i) scanf("%d", &s[i]);
	for (int i = 1; i <= k; ++i) for (int p : s) if (p <= i && !fpWins[i-p]) fpWins[i] = true;
	if (fpWins[k]) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
h_list = [None] * N
for n in range(N):
    h_list[n] = int(input())

h_list = list(sorted(h_list))

print(min(h_list[K - 1 + i] - h_list[i] for i in range(N - K + 1)))

Measured memory_bytes: 8616
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  cout << *max_element(a, a + n) - *min_element(a, a + n) << endl;

  return 0;
}


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

string s;

signed main(){
  
  cin>>s;
  
  int N = (int)s.size();
  
  s = 'x' + s;
  
  if( s[N] == '1' ){
    cout<<-1<<endl;
    return 0;
  }
  
  if( s[1] == '0' || s[N-1] == '0' ){
    cout<<-1<<endl;
    return 0;
  }
  
  for(int i=1;i<=N-1;i++){
    if( s[i] != s[N-i] ){
      cout<<-1<<endl;
      return 0;
    }
  }
  
  s[N] = '1';
  
  int idx = N;
  
  for(int i=N-1;i>=1;i--){
    
    cout<<i<<' '<<idx<<endl;
    
    if( s[i] == '1' ) idx = i;
    
  }
    
  return 0;
}


Measured memory_bytes: 1660
import java.io.*;
import java.util.*;

public class Main {
  static int MOD = 1000000007;
  static double EPS = 1e-9;

  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    StringTokenizer st = new StringTokenizer(in.readLine());

    String N = st.nextToken();
    int length = N.length();
    int K = Integer.parseInt(st.nextToken());

    TreeSet<Integer> set = new TreeSet<Integer>();

    st = new StringTokenizer(in.readLine());

    for (int i = 0; i < K; i++) {
      set.add(Integer.parseInt(st.nextToken()));
    }

    int[] valid = new int[10 - K];
    int index = 0;

    for (int i = 0; i < 10; i++) {
      if (!set.contains(i)) {
        valid[index] = i;
        index++;
      }
    }

    int res = 0;
    boolean b = true;
    boolean large = false;

    for (int i = 0; i < length; i++) {
      int d = N.charAt(i) - '0';
      boolean done = false;
      if (large) {
        res = res * 10 + valid[0];
        continue;
      }
      for (int j = 0; j < valid.length; j++) {
        if (valid[j] >= d) {
          if (i == 0 && valid[j] > d)
            large = true;
          res = res * 10 + valid[j];
          done = true;
          break;
        }
      }
      if (!done) {
        b = false;
        break;
      }
    }

    if (!b) {
      if (valid[0] == 0)
        res = valid[1];
      else
        res = valid[0];
      for (int i = 0; i < length; i++) {
        res = res * 10 + valid[0];
      }
    }

    System.out.println(res);

    in.close();
  }
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    ll N; cin >> N;
    vector<ll> arr(N);
    for (int i = 0; i < N; i++) {
        ll a; cin >> a;
        arr[i] = a;
    }
    ll sum = accumulate(arr.begin(), arr.end(), 0);

    cout << sum - N << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC_172_D
//
//  Created by Joe Mori on 2020/06/27.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include<bits/stdc++.h>/*
std::vector<bool>is_prime(10001001, true);
void prime_number(long long int a,long long int N){
    if(is_prime[a]){
        for(long long int i=a*2;i<=N;i+=a){
            is_prime[i]=false;
        }
    }
}*/
int main() {
    // insert code here...
//    std::vector<long long int>prime(1000001,1);
//    std::vector<std::vector<long long int> >count(10000001,std::vector<long long int>(10000001,0));
    /*for(int i=2;i<10000000;i++){
        if(is_prime[i]){
            for(int j=i*2;j<10000000;j+=i){
                is_prime[j]=false;
            }
        }
    }*/
//    prime[1]=1;
    /*
    long long int sub,yaku=1;
    for(int i=2;i<10000000;i++){
        sub=i;
        for(int j=2;j<=i;j++){
            if(!is_prime[j])break;
            while(sub%j==0){
                sub/=j;
                count[i][j]++;
            }
            yaku=yaku*(count[i][j]+1);
        }
        std::cout<<"yaku:"<<yaku<<std::endl;
        prime[i]=yaku;
        yaku=1;
    }*/
    long long int N,ans=0,sub,count=0,sub_ans=0;
    std::vector<long long int>a(10000010,0);
    std::cin>>N;
    /*for(int i=2;i<N+1;i++){
        prime_number(i,N);
//        std::cout<<"i=="<<i<<std::endl;
        if(is_prime[i]){
            ans=ans+i*2;
        }else{
            sub=i;
            sub_ans=1;
            for(int j=2;j<=i;j++){
                count=0;
//                std::cout<<"j:"<<j<<std::endl;
                if(!is_prime[j])continue;
//                std::cout<<"j:"<<j<<std::endl;
                while(sub%j==0){
//                    std::cout<<"sub:"<<sub<<std::endl;
                    sub=sub/j;
                    count++;
                }
//                std::cout<<"i:"<<i<<" "<<count<<" j:"<<j<<" sub:"<<sub<<std::endl;
                sub_ans=(1+count)*sub_ans;
                if(sub==1)break;
//                std::cout<<"j:"<<j<<" sub_ans:"<<sub_ans<<std::endl;
            }
//            std::cout<<"i:"<<i<<" sub_ans:"<<i*sub_ans<<std::endl;
            ans=ans+sub_ans*i;
        }
    }
//    DWORD start = timeGetTime();
    //    std::cout<<is_prime[5]<<std::endl;
    
    std::cout<<ans<<std::endl;*/
    for(int i=1;i<=N;i++){
        for(int j=i;j<=N;j+=i){
            a[j]++;
        }
    }
    for(int i=1;i<=N;i++){
        ans=ans+a[i]*i;
    }
    std::cout<<ans<<std::endl;
    return 0;
}


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

int main(){
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> cnt(n);
    rep(i,q){
        int a;
        cin>>a;
        a--;
        cnt[a]++;
    }
    rep(i,n){
        if(k-q+cnt[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  LL n;cin>>n;
  LL ans=1;
  LL a[100010];
  LL po=1000000000000000000;
  for(LL i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==0){
      cout<<0<<endl;
      return 0;
    }
  }
  for(LL i=0;i<n;i++){
    LL x=a[i];
    if(po/ans<x){
      cout<<-1<<endl;
      return 0;
    }
    ans*=x;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4372
import java.util.*;
public class Main {
  
  private static long X = 1000000007;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    long[][] memo = new long[N+1][N+1];
    for (int i = 1; i <= K; i++) {
      if (N-K+1 >= i) {
        long count = (comb(N-K+1, i, memo) * comb(K-1, i-1, memo)) % X;
        System.out.println(count);
      } else {
        System.out.println(0);
      }
    }
  }
  
  private static long comb(int n, int r, long[][] memo) {

    if (r == n || r == 0) {
      return 1;
    }

    if (memo[n][r] != 0) {
      return memo[n][r];
    }

    memo[n][r] = (comb(n-1, r-1, memo) + comb(n-1, r, memo)) % X;
    
    return memo[n][r];
  }
}


Measured memory_bytes: 83156
import sys
input = sys.stdin.readline

n, m = map(int,input().split())
nei =[[i] for i in range(n)]

for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    nei[a].append(b)
    nei[b].append(a)

color = [0 for i in range(n)]
depth = [-1 for i in range(n)]

def paint(v,d,c,pre):
    if d <= depth[v]:
        return
    depth[v] = d
    if color[v] == 0:
        color[v] = c
    if d == 0:
        return
    for next in nei[v]:
        if next == pre:
            continue
        paint(next,d-1,c,v)

q = int(input())
vbc = [list(map(int,input().split())) for i in range(q)][::-1]

for i in range(q):
    paint(vbc[i][0]-1,vbc[i][1],vbc[i][2],-1)
    #print(color)


for co in color:
    print(co)

Measured memory_bytes: 88624
#include<bits/stdc++.h>
using namespace std;
using u64 = uint_fast64_t;
using i64 = int_fast64_t;
#define rep(i, n) for(u64 i = 0; i < n; ++i)

int main(){
  u64 n;
  cin >> n;
  vector<u64> a(n);
  for(auto & e : a) cin >> e;
  vector<u64> p(n);
  rep(i, n) p[a[i] - 1] = i;
  rep(i, n) cout << p[i] + 1 << " \n"[i + 1 == n];
}


Measured memory_bytes: 2432
#include<iostream>
#include<vector>
using namespace std;

int main() {
    int n, l=0;
    cin >> n;
    vector<int> a(n), count(n);
    for(int i=0; i<n; i++) cin>>a[i];

    for(int i=0; i<n-1; i++) {
        if(a[i]==a[i+1]) {
            count[l]++;
        } else if(count[l]!=0) {
            l++;
        }
    }
    int co=0;
    for(int i=0; i<n; i++) {
        if(count[i]==0) continue;
        co += (count[i]+1)/2;
    }
    cout<<co<<endl;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s;
    cin >> s;
    if(s.at(0) == s.at(2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc109/tasks/abc109_d

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int H_MAX = 500;
const int W_MAX = 500;
const int A_IJ_MAX = 9;

struct mv { int i1, j1, i2, j2; };

int H, W;
int a[H_MAX][W_MAX];
vector<mv> ms;

void solve() {
  int ans = 0;
  REP(i, H) REP(j, W - 1) {
    if (a[i][j] % 2) {
      ms.push_back({ i, j, i, j + 1});
      a[i][j]--;
      a[i][j + 1]++;
    }
  }
  REP(i, H - 1) {
    if (a[i][W - 1] % 2) {
      ms.push_back({ i, W - 1, i + 1, W - 1});
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
    }
  }
  // DUMP2D(a, H, W);
  printf("%d\n", ms.size());
  for (auto m : ms) printf("%d %d %d %d\n", m.i1 + 1, m.j1 + 1, m.i2 + 1, m.j2 + 1);
}

void input() {
  scanf("%d%d", &H, &W);
  REP(i, H) REP(j, W) scanf("%d", &a[i][j]);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 5104
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[][] a = new long[n][2];

		for (int i = 0; i < n; ++i) {
			a[i][0] = sc.nextLong();
			a[i][1] = i;
		}
		// 値の降順にソート
		Arrays.sort(a, new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				if (o1[0] != o2[0]) {
					return -Long.compare(o1[0], o2[0]);
				} else {
					return Long.compare(o1[1], o2[1]);
				}
			}
		});
		long[] cnt = new long[n];
		int s = 0, t = 0;
		while (true) {
			if (s == n)
				break;
			while (t != n && a[s][1] <= a[t][1]) {
				++t;
			}
			cnt[(int) a[s][1]] += (a[s][0] - (t == n ? 0 : a[t][0])) * s;
			// [s:t-1]の範囲だけ考えれば良い
			for (int i = t - 1; i >= s; --i) {
				cnt[(int) a[s][1]] += (a[i][0] - (t == n ? 0 : a[t][0]));
			}
			s = t;
		}
		for(int i=0;i<cnt.length;++i){
			System.out.println(cnt[i]);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 73260
#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 < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (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--)

using P = tuple<int, int>;
bool cmp(const P& lh, const P& rh)
{
    int lhl, lhr, rhl, rhr;
    tie(lhl, lhr) = lh;
    tie(rhl, rhr) = rh;

    if (lhr < rhr) {
        return true;
    } else if (lhr > rhr) {
        return false;
    } else {
        return lhl < rhl;
    }
}

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

    vector<P> p;
    int lm = 0, rm;
    rep(i, n)
    {
        int l, r;
        cin >> l >> r;
        p.push_back(P(l, r));

        if (lm < l) {
            lm = l;
            rm = r;
        }
    }
    p.erase(find(p.begin(), p.end(), P(lm, rm)));
    sort(p.begin(), p.end(), cmp);

    n = p.size();
    vector<P> q(n + 1), q2(n + 1);
    irep(i, n)
    {
        if (i == 0) {
            q[i] = P(1, 1e9);
            q2[n - i] = P(1, 1e9);
        } else {
            int lprev, rprev;
            tie(lprev, rprev) = q[i - 1];
            int lp, rp;
            tie(lp, rp) = p[i - 1];

            //cout << "(" << lprev << ", " << rprev << ") (" << lp << ", " << rp << ")" << endl;
            q[i] = P(max(lp, lprev), min(rp, rprev));

            int lprev2, rprev2;
            tie(lprev2, rprev2) = q2[n - (i - 1)];
            int lp2, rp2;
            tie(lp2, rp2) = p[n - 1 - (i - 1)];

            q2[n - i] = P(max(lp2, lprev2), min(rp2, rprev2));
        }
    }

    irep(i, n)
    {
        int l, r;
        tie(l, r) = q2[i];
        //cout << "l=" << l << " r=" << r << endl;
    }

    int result = 0;
    rep(i, n)
    {
        int l1, r1;
        tie(l1, r1) = q[n - i];
        int l2, r2;
        tie(l2, r2) = q2[n - i];
        int l0 = max(l2, lm), r0 = min(r2, rm);

        int score1 = max(r1 - l1 + 1, 0);
        int score2 = max(r0 - l0 + 1, 0);

        //cout << "i=" << i << " score=" << score1 + score2 << "\t" << l0 << " " << r0 << endl;

        result = max(result, score1 + score2);
    }

    rep(i, n)
    {
        int l1, r1;
        tie(l1, r1) = q[i];
        int l2, r2;
        tie(l2, r2) = q2[i + 1];
        int l3, r3;
        tie(l3, r3) = p[i];

        int l0 = max(lm, max(l1, l2)), r0 = min(rm, min(r1, r2));
        int score1 = max(0, r0 - l0 + 1);
        int score2 = max(0, r3 - l3 + 1);

        result = max(result, score1 + score2);
    }

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

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
char s[33];
int main(){
	scanf("%s",s);
	map<char, int> mp;
	for(int i=0; i<3; ++i){
		++mp[s[i]];
	}
	if(mp['S']==1){
		if(s[1]=='R'){
			cout<<2<<endl;
		}
		else{
			cout<<1<<endl;
		}
	}
	else if(mp['S']==2){
		cout<<1<<endl;
	}
	else if(mp['S']==0){
		cout<<3<<endl;
	}
	else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3692
/*
 * Shuffle.cpp
 *
 *  Created on: 2014/08/03
 *      Author: WanWan1985
 */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

// for util
#define FOR(i, a, b) 	for(int i = (a); i < (b); i++)
#define REP(i, n)		FOR(i, 0, n)
#define PB				push_back
#define MP				make_pair
#define CL				clear
#define EXIT			(0)

typedef unsigned int u_int;
typedef long long ll;

void shuffle(vector<int> a_vecShuffle, string& a_rstrTargetCards);

int main(void) {

	vector<string> vecResult;
	while(1) {
		string strTargetCards;
		cin >> strTargetCards;
		if ("-" == strTargetCards) {
			break;
		}

		int iShuffleNum = 0;
		cin >> iShuffleNum;
		vector<int> vecShuffle;
		REP(i, iShuffleNum) {
			int iNum;
			cin >> iNum;
			vecShuffle.PB(iNum);
		}

		shuffle(vecShuffle, strTargetCards);

		vecResult.PB(strTargetCards);
	}

	REP(i, vecResult.size()) {
		cout << vecResult.at(i) << endl;
	}

	return EXIT;
}

void shuffle(vector<int> a_vecShuffle, string& a_rstrTargetCards) {
	REP(i, a_vecShuffle.size()) {
		int iNum = a_vecShuffle.at(i);
		string strTmp = a_rstrTargetCards;
		string strLeft	= strTmp.substr(0, iNum);
		string strRight	= strTmp.substr(iNum, a_rstrTargetCards.size() - 1);
		a_rstrTargetCards = strRight + strLeft;
	}
}

Measured memory_bytes: 1232
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

    string a=string(s.length(), 'x'); 
    cout << a;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #pragma GCC diagnostic warning "-std=c++11"

#define ll long long
#define pb  push_back
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define slc(n) scanf("%lld", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()

using namespace std;

ll n, a[maxn], ans = inf, dp[maxn];

ll rec(ll from, ll to)
{
	// cout << from << " " << to << " " << dp[to] << endl;
	if(to>n)
		return inf;
	if(to==n)
		return abs(a[to]-a[from]);
	if(dp[to]==-1)
		dp[to] = min(rec(to, to+1), rec(to, to+2));
	return dp[to] + abs(a[to]-a[from]);
}

int main()
{
	memset(dp,-1, sizeof dp);
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		slc(a[i]);
	}
	ll ans = rec(1,1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12032
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int w = sc.nextInt();
			int h = sc.nextInt();
			int x, y;
			int[][] map = new int[h][w];
			for(int i=0;i<n;i++){
				x = sc.nextInt();
				y = sc.nextInt();
				map[y-1][x-1] = 1;
			}
			int s = sc.nextInt();
			int t = sc.nextInt();
			
			int max = 0;
			int sum;
			for(int i=0;i<=h-t;i++){
				for(int j=0;j<=w-s;j++){
					sum = 0;
					for(int p=0;p<t;p++){
						for(int q=0;q<s;q++) sum+=map[p+i][q+j];
					}
					max = Math.max(max,sum);
				}
			}
			System.out.println(max);
		}	
	}	
}

Measured memory_bytes: 34120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

/*
6 4
a b c d e f
af -> 4c2
ae,bf -> 3c2
ad,be,cf -> 2c2
*/

/*
Log order calcuration of power
*/
ll bi_pow(ll x, ll n){
  ll res = 1;
  while (n>0){
    if (n%2==1) {res = res * x % MOD;}
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

/*
Inverse element of MOD = 1e9+7
*/
ll inv_MOD(ll x){
  return bi_pow(x, MOD-2);
}

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

  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i,N) { cin >> A[i]; }

  sort(A.begin(), A.end());

  vector<ll> fact(N+1,1);
  vector<ll> inv_fact(N+1,1);
  REP3(i,1,N+1){
    fact[i] = fact[i-1]*i%MOD;
    inv_fact[i] = inv_MOD(fact[i]);
  }


  ll sum_mi = 0;
  // calc min sum
  REP3(mi,0,N-K+1){
    sum_mi += ((A[mi] * fact[N-mi-1] % MOD) * inv_fact[N-mi-K] % MOD) * inv_fact[K-1] % MOD;
    sum_mi %= MOD;
  }

  ll sum_ma = 0;
  // calc max sum
  REP3(ma,K-1,N){
    sum_ma += ((A[ma] * fact[ma] % MOD) * inv_fact[ma-K+1] % MOD) * inv_fact[K-1] % MOD;
    sum_ma %= MOD;
  }

  ll ans = (sum_ma - sum_mi + MOD) % MOD;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 2560
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
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;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
int n;
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}

void Solve() {
	int n;
	cin >> n;
	ll d[200010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> d[i];
	}

	int m;
	cin >> m;
	ll t[200010];
	for (size_t i = 0; i < m; i++)
	{
		cin >> t[i];
	}

	sort(d, d + n);
	sort(t, t + m);
	size_t i = 0, j = 0;
	for (; i < m && j < n; i++,j++)
	{
		while (t[i] > d[j] && j < n)
		{
			j++;
		}
		if (j >= n) {
			cout << "NO" << endl;
			return;
		}

		if (t[i] != d[j]) {
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
} 


int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
const int maxn=5001;
int a[maxn],b[maxn],c[maxn];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];ans+=b[i];
	}
	for(int i=1;i<n;i++)
	{
		cin>>c[i];
	}
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[i+1]-1) ans+=c[a[i]];
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin>>N;
  set<string> S;
  for(int i=0;i<N;i++)
  {
   string s;
   cin>>s;
   S.insert(s);
   }
    
    cout<<S.size();
    return 0;
    }


Measured memory_bytes: 19268
from operator import itemgetter

N = int(input())
C = []
for i in range(N):
    C.append(list(map(int, input().split())))

C.sort(key=itemgetter(1))

elapsed = 0
for i in range(N):
    elapsed += C[i][0]
    if elapsed > C[i][1] :
        print("No")
        exit(0)

print("Yes")


Measured memory_bytes: 47064
program A819B
    implicit none
    integer(8)::i,j,ans,Nlen,calc
    character(17)::N
    integer(8),allocatable,dimension(:)::A
    read*,N
    Nlen=len_trim(N)
    ans=0
    allocate(A(Nlen))
    do i=1,Nlen
        A(i)=ichar(N(i:i))-48
        ans=ans+A(i)
    end do

    do i=1,Nlen
        calc=0
        do j=1,Nlen
            if(j<i)calc=calc+A(j)
            if(j==i)calc=calc+A(j)-1
            if(j>i)calc=calc+9
        end do
        ans=max(ans,calc)
    end do

    print'(i0)',ans
end program A819B

Measured memory_bytes: 256
from itertools import combinations
dist = lambda p1, p2: ((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2) ** (1 / 2)

N = int(input())
P = (tuple(map(int, input().split())) for _ in range(N))

distances = (dist(*combination) for combination in combinations(P, 2))
total_distance = tuple(sum(distance) for distance in combinations(distances, N - 1))
print(sum(total_distance) / len(total_distance))

Measured memory_bytes: 126428
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s,t;
  cin>>s>>t;
  ll ans=INF;
  rep(i,sz(s)-sz(t)+1){
    ll cu=0;
    rep(j,sz(t)){
      if(t[j]!=s[i+j]) cu++;
    }
    chmin(ans,cu);
  }
  COUT(ans);
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

template<class T> inline bool chmin(T& a, T b) 
{ if (a > b) { a = b; return true; } return false; }

template<class T> inline bool chmax(T& a, T b) 
{ if (a < b) { a = b; return true; } return false; }

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }


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

    vector<int> right(S.size(), 0);
    vector<int> left(S.size(), 0);

    int rcnt = 0;
    rep(i, S.size()) {
        if (S[i] == 'R') {
            rcnt++;
            right[i] = rcnt;
        } else {
            rcnt = 0;
        }
    }
    int lcnt = 0;
    rep(i, S.size()) {
        if (S[S.size() - i - 1] == 'L') {
            lcnt++;
            left[S.size() - i - 1] = lcnt;
        } else{ 
            lcnt = 0;
        }
    }

    vector<int> vrcnt(S.size(), 0);
    vector<int> vlcnt(S.size(), 0);

    rep(i, S.size()-1) {
        if (right[i+1] == 0) {
            vrcnt[i] = right[i];
        }
        if (left[S.size() - i - 2] == 0) {
            vlcnt[S.size() - i - 1] = left[S.size() - i - 1];
        }
    }
    
    vector<int> cnt(S.size(), 0);
    rep(i, S.size()) {
        cnt[i] = vrcnt[i] + vlcnt[i];
    }

    vector<int> vec(S.size(), 0);
    rep(i, S.size()) {
        if (cnt[i] != 0) {
            vec[i] = max(cnt[i], cnt[i+1]);
            //print(i << ' ' << cnt[i] << ' ' << vec[i]);
            ++i;
        }
    }

    vector<int> res(S.size(), 0);
    rep(i, S.size()) {
        if (cnt[i] != 0) {
            int sum = cnt[i] + cnt[i+1];
            if (sum %2 != 0 && cnt[i] > cnt[i+1]) {
                res[i] = sum/2 + 1;
                res[i+1] = sum/2;
            } else if (sum % 2 != 0 && cnt[i] < cnt[i+1]) {
                res[i] = sum/2;
                res[i+1] = sum/2 + 1;
            } else {
                res[i] = sum/2;
                res[i+1] = sum/2;
            }
            ++i;
        }
    }

    rep(i, S.size()) {
        if (vec[i] == 0) cout << 0;
        else if (vec[i] % 2 == 1) {
            cout << res[i] << ' ' << res[i+1];
            i++;
        } else {
            cout << res[i+1] << ' ' << res[i];
            i++;
        }
        cout << ' ';
    }

    cout << endl;

    rep(i, S.size()) {
        //print(cnt[i] << ' ' << vec[i]);
    }

    return 0;
}



Measured memory_bytes: 3456
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int w[] = new int[N];
		long v[] = new long[N];
		for(int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextLong();
		}
		
		long dp[][] = new long[N + 1][W + 1];
		Arrays.fill(dp[0], 0);
		//dp[0][0] = 0;
		long ans = 0;
		for(int i = 1; i <= N; i++) {
			for(int j = 0; j <= W; j++) {
				if(j - w[i - 1] >= 0) {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
				} else {
					dp[i][j] = dp[i - 1][j];
				}
				if(i == N) {
					ans = Math.max(ans, dp[i][j]);
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 129104
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n, k;
    cin >> n >> k;
    vi p(n);
    cin >> p;
    vi c(n);
    cin >> c;
    rep(i, 0, n) --p[i];
    int ans = -1e17;
    rep(st, 0, n) {
        int cur = p[st];
        int an = 0;
        int cnt = 0;
        vi route;
        while (cur != st && cnt < k) {
            route.push_back(c[cur]);
            cur = p[cur];
            ++cnt;
        }
        if (cnt != k)
        route.push_back(c[st]);
        int sum_cir = 0;
        rep(i, 0, route.size()) {
            sum_cir += route[i];
        }
        an = 0;
        rep(i, 0, route.size()) {
            an += route[i];
            chkmax(ans, an + max(0ll, (int)(k - i - 1) / (int)route.size() * sum_cir));
        }

    }
    put(ans);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 3388
n, k, q = map(int, input().split())
l = [0] * n
katen = []

my_append = katen.append # appendを(間接的に)直接呼び出す
for i in range(q):
    my_append(int(input()))

for j in katen: # pop、insertを使わない、重要！
    l[j-1] += 1 

for y in range(n):
    if l[y] > q-k:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N;
	cin >> N;
	if (N < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}

Measured memory_bytes: 3632