akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)

using namespace std;

int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    vl a(n);
    ll gcd;
    forn(i,n)
    {
        scanf("%lld",&a[i]);
//        if(a[i]%2==1)
//        {
//            printf("0\n");
//            return 0;
//        }
        a[i]/=2;
        if(i==0)gcd=a[i];
        else
        {
            gcd=__gcd(gcd,a[i]);
        }
    }
    ll cnt=1;
    while(gcd%2==0) 
    {
        cnt*=2;
        gcd/=2;
    }
    forn(i,n)
    {
        a[i]/=cnt;
        if(a[i]%2==0)
        {
            printf("0\n");
            return 0;
        }
    }
    ll lcm=a[0]*cnt;
    forn(i,n-1)
    {
        a[i+1]*=cnt;   
        lcm=lcm*(a[i+1]/(ll)__gcd(lcm,a[i+1]));
        if(lcm>m||lcm<0)
        {
            printf("0\n");
            return 0;
        }
    }
//    lcm/=gcd;
    printf("%lld\n",(m-lcm)/(2*lcm)+1);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<P> coord(N);
    rep(i, N) cin >> coord.at(i).first >> coord.at(i).second;
    
    vector<int> order(N);
    rep(i, N) order.at(i) = i;
    
    double sum_dist = 0;
    int count = 0;
    do {
        count++;
        double dist = 0;
        rep(i, N-1) dist += sqrt(pow(coord.at(order.at(i)).first - coord.at(order.at(i+1)).first, 2) + pow(coord.at(order.at(i)).second - coord.at(order.at(i+1)).second, 2));
        sum_dist += dist;
    } while (next_permutation(order.begin(), order.end()));
    
    printf("%.10f\n", sum_dist/count);
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

ll a[120000];
int n;

ll gcd(ll a, ll b) {
	while (b) {
		ll q = a % b;
		a = b;
		b = q;
	}
	return a;
}

int solve() {
	int c0 = 0;
	int c1 = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] % 2 == 0)
			++c0;
		else
			++c1;
	}
	if (c0 % 2 == 1)
		return 1;
	if (c0 % 2 == 0 && c1 >= 2)
		return 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] % 2 == 1) {
			if (a[i] == 1)
				return 0;
			--a[i];
		}
	}
	ll g = a[0];
	for (int i = 0; i < n; ++i)
		g = gcd(g, a[i]);
	for (int i = 0; i < n; ++i)
		a[i] /= g;
	return 1 - solve();
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld", a + i);
	if (n == 1) {
		cout << "Second\n";
		return 0;
	}
	int x = solve();
	if (x == 1)
		cout << "First\n";
	else
		cout << "Second\n";
	return 0;
}




Measured memory_bytes: 1152
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int X[N];
  for (int i=0 ; i<N ; i++) scanf("%d", &X[i]);
  int sorted[N];
  memcpy(sorted, X, sizeof(X));
  sort(sorted, sorted+N);
  for (int i=0 ; i<N ; i++) {
    auto it = lower_bound(sorted, sorted+N, X[i]);
    int idx = (int)(it - sorted);
    if (idx < N/2) printf("%d\n", sorted[N/2]);
    else printf("%d\n", sorted[N/2-1]);
  }
}


Measured memory_bytes: 3712
N = int(raw_input())

W = map(int, raw_input().split())

sum_w = list()
sum_val = 0
for w in W:
    sum_val += w
    sum_w.append(sum_val)

min_val = 100000
for w in sum_w:
    val = abs(sum_w[-1] - 2 * w)
    if val < min_val:
        min_val = val

print min_val

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  char b;
  cin >> b;
  if (b == 'A') {
    cout << 'T' << endl;
  } else if (b == 'T') {
    cout << 'A' << endl;
  } else if (b == 'C') {
    cout << 'G' << endl;
  } else {
    cout << 'C' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cassert>
#include <map>
#include <set>
using namespace std;



int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> v(n, vector<char>(m, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  auto print = [&](int left) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (v[i][j] == '#') {
          cout << '#';
        } else {
          if ((left && j == 0) || (!left && j == m - 1)) {
            cout << '#';
          } else {
            if (left && j == m - 1) {
              cout << ".";
            } else {
              if (!left && j == 0) {
                cout << '.';
              } else {
                if (left) {
                  if (i % 2 == 0) {
                    cout << "#";
                  } else {
                    cout << ".";
                  }
                } else {
                  if (i % 2) {
                    cout << "#";
                  } else {
                    cout << ".";
                  }
                }
              }
            }
          }


        }
      }
      cout << "\n";
    }
    cout << "\n";
  };
  print(0);
  print(1);

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;

int main()
{
	string s;
	cin>>s;
	if(s[s.length()-1]=='2'||s[s.length()-1]=='4'||s[s.length()-1]=='5'||s[s.length()-1]=='7'||s[s.length()-1]=='9'){
		cout<<"hon"<<endl;	
	}else if(s[s.length()-1]=='0'||s[s.length()-1]=='1'||s[s.length()-1]=='6'||s[s.length()-1]=='8'){
		cout<<"pon"<<endl;
	}else cout<<"bon"<<endl;
 	return 0;
}







Measured memory_bytes: 3596
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let i:Vec<i32> = read_vec();
    if i[0] < i[1] && i[1] < i[2]{
        println!("Yes");
    } else {
        println!("No");
    }
}


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  vector<int> bell(3);
  cin >> bell[0] >> bell[1] >> bell[2];
  sort(bell.begin(), bell.end());
  cout << bell[0] + bell[1] << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - One Card Poker
            var line = ReadLine();
            int a = line[0];
            int b = line[1];

            if (a == b)
            {
                Console.WriteLine("Draw");
            }
            else if (a == 1)
            {
                Console.WriteLine("Alice");
            }
            else if (b == 1)
            {
                Console.WriteLine("Bob");
            }
            else if (a > b)
            {
                Console.WriteLine("Alice");
            }
            else
            {
                Console.WriteLine("Bob");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
a,v = (int(x) for x in input().split())
b,w = (int(x) for x in input().split())
t = int(input())
 
if a < b:
  if a+v*t>=b+w*t:
    print("YES")
  else:
    print("NO")
else:
  if b-(w*t) >= a-(v*t):
    print("YES")
  else:
    print("NO")

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

using namespace std;
const int N = 1000 + 10;
typedef long long ll;
int dp[N][N];
int a[N];
int main()
{
    int n;
    while(cin>>n)
    {
        int sum = 0;
        for(int i = 1; i<=n; i++)
        {
            scanf("%d", &a[i]);
            sum += a[i];
        }
        sort(a+1,a+1+n);
//        memset(dp, 0, sizeof(dp));
//        int ans = 0;
//        for(int i = 1; i<=n; i++)
//        {
//            if(dp[i-1][1] >= dp[i-1][0])
//            {
//                dp[i][1] = dp[i-1][1] + a[i];
//                if(dp[i][1] % 10 == 0)
//                    ans = max(dp[i-1][0] +a[i]%10==0?0:dp[i-1][0] + a[i], ans);
//                ans = max(dp[i][1]%10==0?0:dp[i][1], ans);
//            }
//            dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
//            ans = max(dp[i-1][1]%10==0?0:dp[i-1][1], ans);
//            ans = max(dp[i-1][0]%10==0?0:dp[i-1][0], ans);
//        }
//        cout<<ans<<endl;
        if(sum % 10 == 0)
        {
            for(int i = 1; i<=n; i++)
            {
                if(a[i] % 10 != 0){
                    sum -= a[i];
                    break;
                }
            }
        }
        if(sum %10 == 0)
            cout<<0<<endl;
        else cout<<sum<<endl;
    }
    return 0;
}
/*
5
2 3 1 3 2
3
2
1 3
*/


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

int main() {
	// your code goes here
	long long int a;
	cin>>a;
	string out="";
	while(a>0)
	{
		int rem=a%26;
		a=a/26;
		if(rem==0)
		{
			rem+=26;
			a--;
		}
		out=(char)(rem+96)+out;
	}
	cout<<out<<endl;
	return 0;
}

Measured memory_bytes: 3620
import sys

d = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000
}

for s in sys.stdin:
    c = 0
    for i,j in enumerate(list(s)):
        if j == '\n':
            break
        try:
            if j == 'I' and (s[i+1] == 'V' or s[i+1] == 'X'):
                c -= 1
            elif j == 'X' and (s[i+1] == 'L' or s[i+1] == 'C'):
                c -= 10
            elif j == 'C' and (s[i+1] == 'D' or s[i+1] == 'M'):
                c -= 100
            else:
                c += d[j]
        except:
            c += d[j]
    print(c)



Measured memory_bytes: 5564
#include <stdio.h>
#include <string.h>
typedef struct {
  char value[3]; 
}SCHD;
int main(){
  SCHD card1[36];
  SCHD card2[36];
  SCHD card3[36];
  char str[3];
  int n,i,j;
  int min,sn=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){   
    scanf("%s",card1[i].value);
    strcpy(card2[i].value,card1[i].value);
    strcpy(card3[i].value,card1[i].value);
  }
    for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(card1[j].value[1]<card1[j-1].value[1]){
	strcpy(str,card1[j].value);
	strcpy(card1[j].value,card1[j-1].value);
	strcpy(card1[j-1].value,str);
      }     
    }
  }
  for(i=0;i<n-1;i++){
    printf("%s ",card1[i].value);
  } 
  printf("%s\n",card1[n-1].value);  
  for(i=0;i<n;i++){   
    for(j=0;j<n;j++){
      if((int)card3[i].value[1]==(int)card1[j].value[1]) break;     	
    }    
    if(j!=n){
      sn++;
      if(card3[i].value[0]==card1[j].value[0]){
	sn++;
	break;
      }
      }     
   }  
  if(sn!=2)printf("Not stable\n");
  else printf("Stable\n");   
  for(i=0;i<n-1;i++){
    min=i;
    for(j=i;j<n;j++){
      if(card2[j].value[1]<card2[min].value[1])min=j;
    }
    strcpy(str,card2[i].value);
    strcpy(card2[i].value,card2[min].value);
    strcpy(card2[min].value,str);
  } 
  for(i=0;i<n-1;i++){
    printf("%s ",card2[i].value);
  }
  printf("%s\n",card2[n-1].value);
  sn=0;
   for(i=0;i<n;i++){ 
    for(j=0;j<n;j++){
      if((int)card3[i].value[1]==(int)card2[j].value[1]) break;     	
    }    
    if(j!=n){
      sn++;
      if(card3[i].value[0]==card2[j].value[0]){
	sn++;
	break;
      }
    }          
    }
  if(sn!=2 || n==36) printf("Not stable\n");
  else printf("Stable\n");
  return 0;
}



Measured memory_bytes: 2068
a = input()
b = input()
ret = ""
if len(a) > len(b):
    ret = "GREATER"
elif len(a) < len(b):
    ret = "LESS"
else:
    for (i, c) in enumerate(a):
        if(c > b[i]):
            ret = "GREATER"
            break
        elif(c < b[i]):
            ret = "LESS"
            break
        else:
            pass
if ret == "":
    print("EQUAL")
else:
    print(ret)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>

using namespace std;

int SUNUKE[101] = {0};

int main(int argc, char* argv[]){
	int N, K;

	cin >> N >> K;

	for(int i=1; i<=K*2; i++){
		int d;
		cin >> d;
		for(int j=1; j<=d; j++){
			int a;
			cin >> a;
			SUNUKE[a] = 1;
		}
	}
	int ans = 0;
	for(int i=1; i<=N; i++){
		ans += SUNUKE[i];
	}
	printf("%d\n", N-ans);
	return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

//木はdfsのほうが書くのはやいかなぁ
vector<int> eda[100001];
int kyoriF[100001];
int kyoriS[100001];

void sagasuF(int A, int B) {
	if (!kyoriF[A]) {
		kyoriF[A] = B;
		for (auto itr : eda[A]) sagasuF(itr, B + 1);
	}
}
void sagasuS(int A, int B) {
	if (!kyoriS[A]) {
		kyoriS[A] = B;
		for (auto itr : eda[A]) sagasuS(itr, B + 1);
	}
}

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

	int N;
	cin >> N;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		eda[a].push_back(b);
		eda[b].push_back(a);
	}

	sagasuF(1, 1);
	sagasuS(N, 1);

	int fen = 0;
	rep1(i, N) if (kyoriF[i] <= kyoriS[i]) fen++;

	if (fen > N - fen) co("Fennec");
	else co("Snuke");

	Would you please return 0;
}

Measured memory_bytes: 9600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

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

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int ans = 0;
			for(int i = 1; i <= N; i++) {
				if(i == 1 || i == 2 || i == 4 || i == 8 || i == 16 || i == 32 || i == 64) {
					ans = i;
				}
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		int res=0;
		for(int i=1;i*i<=n;i++) for(int j=i;i*i+j*j<=n;j++) for(int k=j;i*i+j*j+k*k<=n;k++){
			int sq=(int)(sqrt(n-i*i-j*j-k*k)+eps);
			if(sq*sq==n-i*i-j*j-k*k&&sq>=k) res++;
		}
		for(int i=1;i*i<=n;i++) for(int j=i;i*i+j*j<=n;j++){
			int sq=(int)(sqrt(n-i*i-j*j)+eps);
			if(sq*sq==n-i*i-j*j&&sq>=j) res++;
		}
		for(int i=1;i*i<=n;i++){
			int sq=(int)(sqrt(n-i*i)+eps);
			if(sq*sq==n-i*i&&sq>=i) res++;
		}
		int sq=(int)(sqrt(n)+eps);
		if(sq*sq==n) res++;
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3116
#include <stdio.h>

int main(void){

    int N = 0;
    char X[100];
    int flag = 0;
    int sum = 0;

    scanf("%d", &N);

    char s[N][100];
    int t[N];

    for (int i = 0; i < N; i++){ 

        scanf("%s %d", s[i], &t[i]);
    }

    scanf("%s", X);

    for (int j = 0; j < N; j++){ 

        if (flag == 1){
            sum = sum + t[j];
        }
        if ( strcmp(s[j], X) == 0){
            flag = 1;
        }
    }
    printf("%d\n", sum);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define eb emplace_back

int in(){int x;cin>>x;return x;}


    
#define ll long long

int n;
vector<vector<int>> g;
vector<int> p;
int ma;
void dfs(vector<int> &used,int x,int r){
    while(r<n and used[r]) r++;
    if(r == n){
        ma = max(ma,x); return ;
    }
    vector<int> mem{r};
    for(auto e:g[r])if(!used[e])mem.push_back(e);
    for(auto e:mem){
        vector<int> use{e};
        for(auto f:g[e]){
            if(!used[f])use.push_back(f);
        }
        for(auto f:use)used[f]=1;
        dfs(used,x+p[e],r+1);
        for(auto f:use)used[f]=0;
    }
}
            

main(){
    while(1){
        n=in();
        if(!n)return 0;
        map<string,int> mp;
        g=vector<vector<int>>(n);
        p=vector<int>(n);
        int cnt = 0;
        rep(i,n){
            string s;cin>>s;
            int now ;
            if(!mp.count(s))mp[s] = cnt++;
            now = mp[s];
            cin>>p[now];
            int k=in();
            rep(j,k){
                cin>>s;
                if(!mp.count(s))mp[s] = cnt++;
                g[now].pb(mp[s]);
            }
        }
        vector<int> used(n);
        int ans = 0;
        rep(i,n){
            if(g[i].empty()){
                used[i] = 1;
                ans+=p[i];
            }
        }
        if(!used[0]){
            ans+=p[0];
            for(auto e:g[0])used[e]=1;
            used[0]=1;
        }
        ma = 0;
        dfs(used,ans,0);
        cout << ma  << endl;
    }
}

        


Measured memory_bytes: 3188
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    for(int i=0;i<5;++i)
    {
        int x;
        cin>>x;

        if(x==0)
        {
            cout<<i+1;
            return;
        }
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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

struct UnionFind {
    vector<int> Parent;
    vector<int> Size;

    UnionFind(int N) : Parent(N), Size(N,1){
        for(int i = 0; i < N; i++) Parent[i] = i;
    }

    int root(int A) {
        if (Parent[A] == A) return A;
        return Parent[A] = root(Parent[A]);
    }

    bool merge(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) return false;

        if (Size[A] < Size[B]) swap(A, B);

        Size[A] += Size[B];
        Parent[B] = A;
        return true;
    }

    bool issame(int A, int B) { //
        return root(A) == root(B);
    }

    int findsize(int A) {
        return Size[root(A)];
    }
};

signed main() {
  int n, m;
  cin >> n >> m;

  UnionFind Tree(n);
  vector<int> a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    Tree.merge(a[i], b[i]);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int s = Tree.findsize(i);
    ans = max(ans, s);
  }

  cout << ans << '\n';

}


Measured memory_bytes: 6416
package main

import "fmt"

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if a - b >= 0 {
		fmt.Println("delicious")
	} else if x + a - b >= 0 {
		fmt.Println("safe")
	} else {
		fmt.Println("dangerous")
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
#define rep(i,s,t )for(register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
    char cc = getchar() ; int cn = 0, flus = 1 ;
    while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
    while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
    return cn * flus ;
}
const int P = 998244353 ; 
const int N = 1e7 + 5 ;
int n, inv[N], fac[N], fp[N], Ans ;
int fpow( int x, int k ) {
    int ans = 1, base = x ;
    while( k ) {
        if( k & 1 ) ans = ans * base % P ;
        base = base * base % P, k >>= 1 ;
    } return ans ; 
}
void inc( int &x, int y ) {
    ( ( x += y ) >= P ) && ( x -= P ) ;
}
int C( int x, int y ) {
    if( y > x ) return 0 ;
    return fac[x] * inv[y] % P * inv[x - y] % P ;
}
signed main()
{
    n = gi(), fp[0] = inv[0] = fac[0] = 1 ;
    rep( i, 1, n ) fac[i] = fac[i - 1] * i % P, fp[i] = fp[i - 1] * 2 % P ; 
    inv[n] = fpow( fac[n], P - 2 ) ;
    for( re int i = n; i >= 1; -- i ) inv[i - 1] = inv[i] * i % P ;
    int m = ( n / 2 ) + 1, num = 0 ;
    Ans = fpow( 3, n ) ;
    for( re int i = m; i <= n; ++ i ) {
        int dec = C( n, i ) ;
        dec = dec * fp[n - i] % P ;
        inc( num, dec ) ;
    }
    Ans = ( Ans - num * 2ll % P + P ) % P ;
    printf("%lld\n", Ans ) ;
    return 0 ;
}

Measured memory_bytes: 234624
#include<bits/stdc++.h>
#define N 505
using namespace std;
int k,n,a[N][N];

int main()
{
	cin>>k;
	n = min(k,500);
	for(int i=1;i<=n;++i)
	{
		int x = 1,y = i;
		for(int j=1;j<=n;++j)
		{
			a[x][y] = i;
			if(i + n <= k && (j & 1)) a[x][y] = i + n;
			x = x % n + 1,y = y % n + 1;
		}
	}
	printf("%d\n",n);
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j) printf("%d ",a[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2176
# Great Ocean View
import numpy as np

# input
N = int(input())
H = np.array(list(map(int, input().split())))

# solve
res = 1
for i in range(1, len(H)):
    if sum(H[:i] - H[i] > 0) == 0:
        res += 1

# output
print(res)

Measured memory_bytes: 12488
program not_found
  implicit none
  character(100000) :: s
  integer           :: n, i, a(26), c
  a = 0
  read(*,*) s
  s = adjustl(s)
  n = len_trim(s)
  do i = 1, n
    c = ichar(s(i:i)) - 96
    a(c) = a(c) + 1
  end do
  do i = 1, 26
    if (a(i).eq.0) then
      write(*,'(a)') achar(i+96)
      stop
    end if
  end do
  write(*,'(a)') "None"
  stop
end program not_found

Measured memory_bytes: 2724
#include <cstdio>
using namespace std;

int X[60], Y[60];
int main() {
    int N; scanf("%d", &N);
    for(int i=0; i<N; i++) {
        scanf("%d%d", &X[i], &Y[i]);
    }

    if(N % 2) {
        printf("NA\n");
    }
    else {
        int px = X[0] + X[N/2], py = Y[0] + Y[N/2];
        bool ok = true;
        for(int i=0; i<N; i++) {
            int tx = X[i] + X[(i+N/2)%N];
            int ty = Y[i] + Y[(i+N/2)%N];
            ok &= (px == tx && py == ty);
        }
        if(!ok) printf("NA\n");
        else {
            double ans_x = px / 2.0, ans_y = py / 2.0;
            printf("%.12f %.12f\n", ans_x, ans_y);
        }
    }
    return 0;
}


Measured memory_bytes: 2732
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			String S = scn.next();
			String T = scn.next();
 
			if(S.equals(T.substring(0, S.length()))) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
 
		}
	}
}

Measured memory_bytes: 26936
import math

n,k = map(int,input().split())
coin_count = 0
dice_count = 0
def func(point,cointoss):
	if point >= k:
		return cointoss
	return func(point*2,cointoss+1)

for i in range(1,n+1):
	if not i >= k:
		coin_count += (1/2)**func(i,0)
	else:
		coin_count += 1

print(coin_count/n)

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

using namespace std;
using ll = long long;


int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  
  
  for(int i=0; i<n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  
  int p = x[0];
  ll sum = 1e11;
  while(p<=x[n-1]){
    ll tmp = 0;
    for(int i=0; i<n; i++){
      tmp += (x[i]-p)*(x[i]-p);
    }
    sum = min(sum, tmp);
    p++;
  }
  
  cout << sum << endl;
  
  
  return 0;
}

Measured memory_bytes: 3600
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int hoge = 0;
		int tea = i;
		while (tea != 0) {
			hoge++;
			tea /= 10;
		}
		ans += hoge % 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N,A,B,C,D;
int main(){
  cin>>N>>A>>B>>C>>D;
  ll max=A+(N-1)*D;
  ll mod=C+D;
  ll x=max%mod;
  ll y=(D-C)*(N-1);
  ll z=B%mod;
  bool f;
  if(B>max) f=false;
  else{
    if(x>=y){
      if(x-y<=z&&z<=x) f=true;
      else f=false;
    }
    else{
      if((0<=z&&z<=x)||(mod-y+x<=z&&z<=mod)) f=true;
      else f=false;
    }
  }
  if(f) prin("YES");
  else prin("NO");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){
  vector <int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());
  if(A[0] != A[1]) cout << A[0] << endl;
  else cout << A[2] << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(N) for (int i = 0; i < N; i++)

int main(){
    int N, Y;
    int x, y, z;
    int end_flag = false;
    cin >> N >> Y;

    for (x = 0; x <= N; x++){
        for (y = 0; y <= N - x; y++){
            z = N - x - y;
            if (10000 * x + 5000 * y + 1000 * z == Y){
                end_flag = true;
                break;
            }
        }
        if (end_flag == true) break;
    }

    if (end_flag == true){
        cout << x << " " << y << " " << z << endl;
    }else{
        cout << "-1 -1 -1" << endl;
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();

		if (a > x || (a + b) < x) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}

		sc.close();
	}
}

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



// Problem https://atcoder.jp/contests/arc089/tasks/arc089_a
// Ref https://qiita.com/drken/items/fd4e5e3630d0f5859067#%E7%AC%AC-10-%E5%95%8F--abc-086-c---traveling-300-%E7%82%B9
//     https://atcoder.jp/contests/arc089/submissions/2005254


// ところでlongの適応範囲はどれくらいか->2^32保証、signedは適用出来るのか->無理して使わない
// もしかしたら100010ならばintが使えるかもしれないのか->使えるが32bit以上前提
bool solver(long visitPosition,vector<long> t,vector<long> x,vector<long> y){
    bool result;
    result = true;
    /**  for(long j=0;j<=visitPosition;j++)
    {
        cout << t.at(j) << " " << x.at(j) << " " << y.at(j) << endl;
    }**/
    for(long j=1;j<=visitPosition;j++){
        // (1) 距離が適当か
        long int dist=0;
        long int timelag=0;
        dist=abs(x.at(j)-x.at(j-1))+abs(y.at(j)-y.at(j-1));
        timelag=t.at(j)-t.at(j-1);
        if(timelag < dist){
            result=false;
            break;
        }
        // EOO = EvenOrOdd 偶数か奇数か
        // 偶数時間後には偶数位置へ移動、奇数時間後には貴数時間後に移動していなければならない
        int distEOO=0;
        int timelagEOO=0;
        distEOO = dist % 2;
        timelagEOO = timelag % 2;
        if(distEOO != timelagEOO){ // 偶数奇数が1カ所でも異なっていたらNG
            result=false;
            break;
        }
        // それ以外なら継続。最後まで行ったら最初に定義したtrueで終了
    }
    
    return result;
}

int main(void){
    long N;
    bool answer=true;
    cin >> N;
    vector<long> xi(100010,0);
    vector<long> yi(100010,0);
    vector<long> ti(100010,0);
    for(int j=0;j<N;j++){
        cin >> ti.at(j+1) >> xi.at(j+1) >> yi.at(j+1);
    }
    answer = solver(N,ti,xi,yi);
    if(answer){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define DEBUG true
#define coutd if(DEBUG) cout
#define ff first
#define ss second
#define len(x) int(x.size())
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios_base::sync_with_stdio(0);
	int a, b;
	cin >> a >> b;
	int ans = 3*a+b;
	cout << ans/2 << endl;
}



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

int main(){
    string str;
    cin >> str;
    
    string::size_type position;
    position = str.find("7");
    if (position != str.npos)
        cout << "Yes" << "\n";
    else
        cout << "No" << "\n";
   
    return 0;
}

Measured memory_bytes: 3592
def main():
    K = int(input())
    l = [False] * K
    ans = 1
    now = 0
    while True:
        now = now * 10 + 7
        now %= K
        if now == 0:
            print(ans)
            break

        if l[now]:
            print(-1)
            break
        
        l[now] = True
        ans += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 16748
#include<stdio.h>
int main (void)
{

int a,b,k,i,n=0;
scanf("%d %d %d",&a,&b,&k);
for(i=1;i<=b;i++)
if((i>=a&&i<a+k&&i<=b)||(i>=a&&i>b-k&&i<=b))
printf("%d\n",i);

return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;

constexpr ll INF = 1e18;

ll f(ll b, ll n) {
    if (n < b) {
        return n;
    } else {
        return f(b, n / b) + n % b;
    }
}

int main(void) {
    ll n, s;
    cin >> n;
    cin >> s;

    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    for (ll b = 2; b * b <= n; b++) {
        ll ans = f(b, n);
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    ll ans = INF;
    for (ll c = 1; c * c <= n; c++) {
        if ((n - s) % c != 0) {
            continue;
        }
        ll b = (n - s) / c + 1;
        if (b <= sqrt(n)) {
            continue;
        }

        if (f(b, n) == s) {
            ans = min(ans, b);
        }
    }

    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize ("Ofast")
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __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...);
}

#define ll long long
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(it,vv) for(auto &it : vv)
#define prep(it,vv) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, K; cin >> n >> K;
	std::vector<int> vv(n + 5);
	std::vector<int> dp(n + 5);

	rep(i, n) cin >> vv[i];

	dp[n] = 0;

	for (int i = n - 1; i >= 1; i--)
	{
		dp[i] = INT_MAX;
		for (int k = 1; k <= K; k++) {

			if (i + k <= n) dp[i] = min(dp[i], dp[i + k] + abs(vv[i] - vv[i + k]));

		}
	}
	cout << dp[1] << endll;

}

Measured memory_bytes: 4792
s=str(input())

s1,s2 = int(s[:2]),int(s[2:])

flag1,flag2 = False,False

if   1 <= s2 <= 12:
      flag1 = True

if 1 <= s1 <= 12:
      flag2 = True

if flag1 == True:
      if flag2 == True:
            print("AMBIGUOUS")
      else:
            print("YYMM")
elif flag2 == True:
      print("MMYY")
else:
      print("NA")


Measured memory_bytes: 3060
from sys import stdin

N = int(stdin.readline().rstrip())
A = [0] * N
l = [[int(x) for x in stdin.readline().rstrip().split()] for _ in A]
d = 1
k = N * (N - 1)

while sum(A) < k and d < 10 ** 4:
    L = [1] * N
    y = 0
    d += 1
    for i in range(N):
        if A[i] < N - 1:
            x = l[i][A[i]] - 1
            if l[x][A[x]] * L[x] * L[i] == i + 1:
                A[i] += 1
                A[x] += 1
                L[i] = L[x] = 0
                y = 1

print([k // 2, d * y - 1][d * y < 9999])


Measured memory_bytes: 53212
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll ten[20];

ll solve(ll val,int digit,bool first){
    if(digit==0){
        if(val==0) return 1;
        else return 0;
    }
    if(digit==1){
        if(val==0) return 10;
        else return 0;
    }
    //if(digit<=10&&abs(val)>=ten[digit+1]) return 0;

    if(abs(val)%10==0){
        ll c=10;
        if(first) c--;
        return c*solve(val/10,digit-2,false);
    }

    ll res=0;

    ll tar=abs(val)%10;
    ll d=10-tar;
    if(val<0) tar*=(-1);
    ll minus=tar-tar*ten[digit-1];
    res+=d*solve((val-minus)/10,digit-2,false);

    tar=10-abs(val)%10;
    ll e=10-tar;
    if(val<0) tar*=(-1);
    ll plus=tar-tar*ten[digit-1];
    if(first) e--;
    res+=e*solve((val+plus)/10,digit-2,false);

    return res;
}

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

  ll D;
  cin>>D;

  ten[0]=1;
  for(int i=1;i<19;i++) ten[i]=ten[i-1]*10ll;

  ll ans=0;
  for(ll i=1;i<=18;i++){
      ans+=solve(D,i,true);
      //cout<<i<<" "<<ans<<endl;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;

string op, s, t;
int ps, pt;

void rec(string &s, int &p, bool print = false) {
  if(print) cout << "(";
  ++p;
  if(s[p] == '(') {
    rec(s, p, print);
  }
  if(print) cout << ",";
  ++p;
  if(s[p] == '(') {
    rec(s, p, print);
  }
  if(print) cout << ")";
  ++p;
}

int rec_i() {
  cout << "(";
  ++ps; ++pt;
  if(s[ps] == '(' && t[pt] == '(') {
    rec_i();
  } else {
    if(s[ps] == '(') rec(s, ps);
    if(t[pt] == '(') rec(t, pt);
  }
  cout << ",";
  ++ps; ++pt;
  if(s[ps] == '(' && t[pt] == '(') {
    rec_i();
  } else {
    if(s[ps] == '(') rec(s, ps);
    if(t[pt] == '(') rec(t, pt);
  }
  cout << ")";
  ++ps; ++pt;
}

int rec_u() {
  cout << "(";
  ++ps; ++pt;
  if(s[ps] != '(' && t[pt] != '(') {
    // none
  } else if(s[ps] != '(') {
    rec(t, pt, true);
  } else if(t[pt] != '(') {
    rec(s, ps, true);
  } else {
    rec_u();
  }
  cout << ",";
  ++ps; ++pt;
  if(s[ps] != '(' && t[pt] != '(') {
    // none
  } else if(s[ps] != '(') {
    rec(t, pt, true);
  } else if(t[pt] != '(') {
    rec(s, ps, true);
  } else {
    rec_u();
  }
  cout << ")";
  ++ps; ++pt;
}

int main() {
  while(cin >> op >> s >> t) {
    ps = pt = 0;
    if(op == "i") rec_i();
    else rec_u();
    cout << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e4;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,p;
    string s;
    cin >> n >> p >> s;
    vector<int> digits(n);
    fori(i,n) digits[i] = s[i]-'0';

    LL ans = 0;
    if(p == 2) {
        fori(i,n) if(digits[i]%2 == 0) ans += i+1;
    } else if(p == 5) {
        fori(i,n) if(digits[i]%5 == 0) ans += i+1;
    } else {
        vector<int> remain(p);
        vector<LL> dp(n);
        remain[0] = 1;
        LL c = 1;
        ford(i,n-1,0) {
            LL& r = dp[i];
            if(i != n-1) {
                c = (c*10)%p;
                r = (digits[i]*c+dp[i+1])%p;
            } else {
                r = digits[i]%p;
            }

            ans += remain[r];
            remain[r]++;
        }
    }

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


Measured memory_bytes: 2964
N, x=map(int, input().split())
list_=list(map(int, input().split()))

m_list=sorted(list_)

if sum(m_list)==x:
    print(N)
elif sum(m_list)<x:
    print(N-1)
else:
    ans=0
    for i in m_list:
        x-=i
        if x>=0:
            ans+=1
        else:
            break

    print(ans)

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

#define fi first
#define se second

const int N = (1 << 18);
const int mod = 1e9 + 7;

using namespace std;

void add(int &x, int y)
{
        x += y;
        if(x >= mod){
                x -= mod;
        } else if(x < 0){
                x += mod;
        }
}

int H, L;
int p[N];
int A[N], a[N][18], b[N][18], f[N];
int c1[N], c2[N];
int res;

void solve(int X, int Y)
{
        int bx = (1 << X), by = (1 << Y);
        for(int i = 0, j = 0; i < L; i += bx, j += 2){
                for(int h = 0; h < bx / 2; h++){
                        c1[i + h] = j;
                }
                for(int h = bx / 2; h < bx; h++){
                        c1[i + h] = j + 1;
                }
        }
        for(int i = 0, j = 0; i < L; i += by, j += 2){
                for(int h = 0; h < by / 2; h++){
                        c2[i + h] = j;
                }
                for(int h = by / 2; h < by; h++){
                        c2[i + h] = j + 1;
                }
        }

        for(int i = 0; i < L; i++){
                A[i] = 1;
                if(c1[i] & 1){
                        A[i] = 1ll * A[i] * b[i][X] % mod;
                } else{
                        A[i] = 1ll * A[i] * a[i][X] % mod;
                }
                if(c2[p[i]] & 1){
                        A[i] = 1ll * A[i] * b[p[i]][Y] % mod;
                } else{
                        A[i] = 1ll * A[i] * a[p[i]][Y] % mod;
                }
        }

        for(int i = 0; i < L; i += bx){
                for(int j = 0; j < bx / 2; j++){
                        add(f[c2[p[i + j]]], A[i + j]);
                }
                for(int j = bx / 2; j < bx; j++){
                        add(res, 1ll * A[i + j] * f[c2[p[i + j]] ^ 1] % mod);
                }
                for(int j = 0; j < bx / 2; j++){
                        add(f[c2[p[i + j]]], - A[i + j]);
                }
        }
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> H;
        L = (1 << H - 1);
        for(int i = 0; i < L; i++){
                cin >> p[i];
                p[i] -= 1;
        }

        for(int i = 1; i < H; i++){
                for(int j = 0, x; j < L; j++){
                        x = L + j;
                        a[j][i] = 1;
                        for(int h = 0; h < i; h++){
                                a[j][i] = 1ll * a[j][i] * x % mod;
                                x /= 2;
                        }
                        b[j][i] = 1ll * a[j][i] * x % mod;
                }
        }

        for(int i = 1; i < H; i++){
                for(int j = 1; j < H; j++){
                        solve(i, j);
                }
        }

        cout << res << "\n";
}


Measured memory_bytes: 24624
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	char s[5];
	int www;
	//データの読み込み
	
	scanf("%s",&s);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	www=0;
	if(s[0]=='o'){	
		www=www+1;
	}
	if(s[1]=='o'){	
		www=www+1;
	}
	if(s[2]=='o'){	
		www=www+1;
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",www*100+700);
	
	//('・ω・'）
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
bool prime(int X) {
	for (int i = 2; i < sqrt(X); i++) {
		if (X % i == 0)  return false;
	}
	return true;
}

int main() {
	int X;
	cin >> X;
	while (!prime(X)) {
		X++;
	}
	cout << X << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int, int);

int main(){
    int K;
    long sum = 0;
    int ans_1;
    scanf("%d", &K);

    for(int a = 1; a <= K; a++){
        for(int b = 1; b <= K; b++){
            ans_1 = gcd(a, b);

            for(int c = 1; c <= K; c++){
                sum += gcd( ans_1, c );
            }
        }
    }
    printf("%ld", sum);

    return 0;
}

int gcd(int a, int b){
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

Measured memory_bytes: 1728
import collections

def solve(N, A):
    c = collections.Counter(A)
    originals = [0 for i in range(N + 1)]
    minus = [0 for i in range(N + 1)]
    for (k, v) in c.items():
        originals[k] = v * (v-1) // 2
        minus[k] = ((v * (v-1)) - (v-1) * (v-2)) // 2
    S = sum(originals)

    ans = []
    for a in A:
        ans.append(str(S - minus[a]))
    return "\n".join(ans)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split(" ")))
    print(solve(N, A))


Measured memory_bytes: 34588
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    ma = 10 ** 20
    for i in range(3, len(s) + 1):
        n = int(s[i-3:i])
        ma = min(ma, abs(n - 753))
    print(ma)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main(){
	int H =0 ;
	int W =  0;
	while(1){
		cin >> H >> W;
		if (H == 0 && W == 0){
			break;
		}
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cout << "#" ;
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3084