akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int a,b,c,n,i,j,k;
int str[100005],str2[100005];
int main()
{
    string s1,s2;
    while(cin>>s1)
    {
        s2=s1;
        k=j=0;
        for(i=1;i<s1.length();i++)
        {
            if(s1[i]=='1'&&s1[i-1]=='1')
                {s1[i]='0';k++;}
            if(s1[i]=='0'&&s1[i-1]=='0')
            {
                s1[i]='1';k++;
            }
        }
        for(i=s2.length()-2;i>-1;i--)
        {
            if(s2[i]=='1'&&s2[i+1]=='1')
                {s2[i]='0';j++;}
            if(s2[i]=='0'&&s2[i+1]=='0')
            {
                s2[i]='1';j++;
            }
        }
        printf("%d\n",min(k,j));

    }
    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize ("O3", "unroll-loops")
#pragma GCC target ("avx")
#include <stdio.h>

constexpr char* S_OUT[31] = {
    "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n",
    "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "20\n",
    "21\n", "22\n", "23\n", "24\n", "25\n", "26\n", "27\n", "28\n", "29\n", "30\n"
};

constexpr unsigned int InputSize = 1e6;
constexpr unsigned int OutputSize = 1e5;
char Input[InputSize];
char* pointer = Input;
char Output[OutputSize];
char* m_buffer = Output;

inline unsigned int getInt(void){
    unsigned int res = 0;
    do{ res = 10 * res + (*(pointer++) - '0'); } while(*pointer >= '0');
    return res;
}

inline void out(const unsigned int v){
    char* str = S_OUT[v];
    while(*str) *(m_buffer++) = *(str++);
}

unsigned int n;
unsigned int N;
constexpr unsigned int SIZE = (1U << 19) + 1;
unsigned int data[2 * SIZE];

inline void set(void){
    n = getInt(); N = 1U << (31 - __builtin_clz(n)); while(N < n) N <<= 1;
    ++pointer; // \n
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j) data[j] = 1U << (*(pointer++) - 'a');
    for(i = N - 1; i ; --i){
      j = i << 1; data[i] = data[j] | data[j | 1U];
    }
}

inline void query(void){
    pointer += 3;
    if(*(pointer - 2) == '1'){
        unsigned int index = getInt() - 1;
        unsigned char idx = *((++pointer)++) - 'a';
        data[index += N] = 1U << idx;
        for(unsigned int i = index; i >= 2; i >>= 1) data[i >> 1] = data[i] | data[i ^ 1];
    }
    else{
        unsigned int l = getInt() + N - 1; pointer++;
        unsigned int r = getInt() + N;
        unsigned int res = 0;
        while(l < r){
            if(l & 1) res |= data[l++]; l >>= 1;
            if(r & 1) res |= data[--r]; r >>= 1;
        }
        out(__builtin_popcount(res));
    }
}

int main(void){
    fread(Input, sizeof(char), InputSize, stdin);
    set(); ++pointer;
    unsigned int q = getInt();
    while(q--) query();
    setvbuf(stdout, 0, _IONBF, 0);
    fputs(Output, stdout);
    return 0;
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int v=sc.nextInt();
			int e=sc.nextInt();
			long[][] cost=new long[v][v];
			long INF=Long.MAX_VALUE/10;
			for(int i=0; i<v; i++) {
				for(int j=0; j<v; j++) {
					cost[i][j]=(i==j)? 0:INF;
				}
			}
			
			for(int i=0; i<e; i++) {
				int s=sc.nextInt();
				int t=sc.nextInt();
				long d=sc.nextLong();
				cost[s][t]=d;
			}
			boolean minor=false;
			for(int k=0; k<v; k++) {
				for(int i=0; i<v; i++) {
					for(int j=0; j<v; j++) {
						if(cost[i][j]>cost[i][k]+cost[k][j] && cost[i][k]!=INF && cost[k][j]!=INF)
						cost[i][j]=cost[i][k]+cost[k][j];
						//System.out.println("cost["+i+"]["+k+"]="+cost[i][k]+" cost["+k+"]["+j+"]="+cost[k][j]);
						//System.out.println("cost["+i+"]["+j+"]="+cost[i][j]);
					}
					if(cost[i][i]<0) minor=true;
				}
			}
			if(minor) System.out.println("NEGATIVE CYCLE");
			else {
				for(int i=0; i<v; i++) {
					for(int j=0; j<v; j++) {
						if(j>0) System.out.print(" ");
						System.out.print((cost[i][j]>=INF)? "INF":cost[i][j]);
					}
					System.out.println();
				}
			}
			
		}
	}
}


Measured memory_bytes: 59244
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ");cout<<endl;
#define pdd(a,n,m)for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define mp make_pair
#define pb push_back
#define ll long long
#define int ll
//#define __int64 lng long
#define P pair<int,int>
#define PP pair<P,int>

int n;
int sum;
signed main(){
  cin>>n;
  rep(i,n){
    int now=i+1;
    if(now%3!=0&&now%5!=0)
      sum+=now;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3632
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

a_mini = a-t*v
a_maxi = a+t*v
b_mini = b-t*w
b_maxi = b+t*w
if (a_mini <= b_mini <= a_maxi) and (a_mini <= b_maxi <= a_maxi):
    print('YES')
    
else:
    print('NO')

Measured memory_bytes: 9188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define MOD 1000000007 //10^9+7
#define INF 1000000000 //10^9

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


int main ()
{
    ll a,b;
    while (cin>>a>>b) {
        ll g=gcd(a, b);
        cout<<g<<' '<<a/g*b<<endl;
    }
    return 0;
}

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

using namespace std;

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

typedef long long ll;


void dfs(vector<pair<vector<ll>,ll>> &g, ll v, vector<bool> &flag){
 flag[v]=true;
 for(auto next_v:g[v].first){
  if(flag[next_v]) continue;
   g[next_v].second+=g[v].second;
  dfs(g,next_v,flag);
}
}


int main(){
 ll n,q;
  cin >> n >> q;
  vector<pair<vector<ll>,ll>> v(n);
  rep(i,0,n) v[i].second=0;
  rep(i,0,n-1){
   ll a,b;
   cin >> a >> b;
    a--;
    b--;
   v[a].first.push_back(b);
   v[b].first.push_back(a);
  }
vector<bool> flag(n,false);
  rep(i,0,q){
   ll p,x;
    cin >> p >> x;
    p--;
   v[p].second+=x;
  }
  
dfs(v,0,flag);
  
  rep(i,0,n-1) cout << v[i].second << " ";
    cout << v[n-1].second << endl;
}

Measured memory_bytes: 27392
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws Exception
	{
		int m=nextInt();
		int k=nextInt();
		int bigmask=(1<<m)-1;
		if(k>bigmask)
			out.println(-1);
		else if(m==0)
			out.println("0 0");
		else if(m==1 && k==0)
			out.println("0 0 1 1");
		else if(m==1 && k==1)
			out.println(-1);
		else
		{
			//xor[0..bigmask]=0 because bigmask%4=0
			for(int i=0;i<=bigmask;i++)
				if(i!=k)
					out.print(i+" ");
			out.print(k+" ");
			for(int i=bigmask;i>=0;i--)
				if(i!=k)
					out.print(i+" ");
			out.println(k);
		}
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 49628
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, d[51];
  scanf("%d", &n);
  rep(i, n)
  {
    scanf("%d", &d[i]);
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      ans += d[i] * d[j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <vector>

using namespace std;

const int N = 1e6+10;

int primes[N];
bool st[N] ;
int cnt ;

void isPrime(int n ){//线性素数筛：原理，每次筛掉以i为最大因数的合数
    memset(st , false , sizeof st);
    cnt = 0 ;
    for(int i = 2 ; i <= n ; i++ )
    {
        if( !st[i] )    primes[cnt++] = i ;//如果此数在之前没被筛掉，则说明这个数是素数
        for(int j = 0 ; j <= cnt && primes[j]*i <= n ; j++)
        {
            st[primes[j]*i] = true; //将【小于等于【【i的最小素因子】的数】】*i所得到的【合数】筛掉
            if(i%primes[j] == 0)    //找到小于等于【【i的最小素因子】的数】，结束此轮筛选
                break;
        }

    }
    return ;
}


int main()
{
    int n;
    isPrime(N);

    cin >> n ;

    while( st[n] ) n++ ;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
   string s;
   cin >> s;
   if(s == "Sunny"){
      cout << "Cloudy" <<endl;
   }else if(s == "Rainy"){
      cout << "Sunny" << endl;
   }else{
      cout << "Rainy" << endl;
   }
   return 0;
}

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

int main(){
  int cnt=0;
  vector<int> x(3000), y(3000);
  rep(i, 3000){
    cin >> x[i] >> y[i];
    if(x[i]==0 && y[i]==0){
      break;
    }
    cnt++;
  }

  rep(i, cnt){
    if(x[i]<=y[i]){
      cout << x[i] << " " << y[i] << endl;
    }
    else{
      cout << y[i] << " " << x[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(10);
  ll n;
  cin >> n;
  double a,ans = 0;
  for(ll i = 0; i < n; ++i){
    cin >> a;
    ans += 1/a;
  }
  cout << 1/ans;
  return 0;
}

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


int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    
    vector<pair<ll,int>> p(a+b+c);
    rep(i,a+b+c){
        cin>>p[i].first;
        if(i<a)
            p[i].second = 0;
        else if(i<a+b)
            p[i].second = 1;
        else
            p[i].second = 2;
    }
    
    sort(p.rbegin(), p.rend());
    
    ll ans = 0;
    
    vector<int> count(3,0), lim(3);
    lim[0] = x;
    lim[1] = y;
    lim[2] = x+y;
    
    rep(i,a+b+c){
        int t = p[i].second;
        if(count[t]>=lim[t] || count[2]>=lim[2])continue;
        ans += p[i].first;
        if(t!=2)count[t]++;
        count[2]++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll n;
   cin>>n;
   ll a[n],p=1,i;
   map<int,int>m;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
       m[a[i]]++;
   }
   map<int,int>::iterator itr;
   for(itr=m.begin();itr!=m.end();itr++)
   {
       if(itr->second>1)
       {p=0;
        break;
       }
   }
   if(p)
    cout<<"YES"<<endl;
   else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;

typedef long long ll;

int dx[4] = { 0, -1, 1, 0 };
int dy[4] = { -1, 0, 0, 1 };

int main() {
  string s;
  cin >> s;
  vector<char> ss = {'a', 'b', 'c'};
  int res = 0;
  for (int i = 0; i < 3; ++i) {
    auto result = find(ss.begin(), ss.end(), s[i]);
    if (result != ss.end()) {
      ++res;
      ss.erase(result);
    }
  }
  if (res == 3) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

vector<vector<int>> g;
vector<int> children;

void dfs1(int v, int p = -1) {
    for (int ngb : g[v]) {
        if (ngb == p) {
            continue;
        }
        dfs1(ngb, v);
        ++children[v];
    }
}

int64_t n_perm(int64_t n, int64_t k) {
    if (k > n) {
        return 0;
    }
    int64_t res = 1;
    for (int64_t i = n - k + 1; i <= n; ++i) {
        res = (res * i) % INF;
    }
    return res;
}

void solve() {
    int64_t n, k;
    cin >> n >> k;
    g.resize(n);
    children.assign(n, 0);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs1(0);
    int64_t res = (k * n_perm(k - 1, children[0])) % INF;
    for (int i = 1; i < n; ++i) {
        if (g[i].size() == 1) {
            continue;
        } else {
            res = (res * n_perm(k - 2, children[i])) % INF;
        }
    }
    cout << res;
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    string S;
    cin >> S;
    for(int i = 0; i < (int)S.size()-1; i++) {
        if(S[i] == S[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(int i = 0; i < (int)S.size()-2; i+=2) {
        if(S[i] == S[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    for(int i = 1; i < (int)S.size()-2; i+=2) {
        if(S[i] == S[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 3712
// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const int M = 1e9 + 7, N = 1e6 + 5;

int parent[N], sz[N], vis[N];

void make_set(int v)
{
    parent[v] = v;
    sz[v] = 1;
}

int find_set(int v)
{
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b)
{
    a = find_set(a);
    b = find_set(b);
    if (a != b)
    {
        if (sz[a] < sz[b]) swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) make_set(i);
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        union_sets(x, y);
    }
    for (int i = 1; i <= n; i++) vis[find_set(i)]++;
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, vis[i]);
    cout << ans;
}

Measured memory_bytes: 5952
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline int read()
{
	int f=1,sum=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-')	f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*f;
}
const int MAXN=200010;
struct edge
{
	int next,to;
};
edge e[MAXN];
int head[MAXN],cnt;
void addedge(int u,int v)
{
	e[++cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
int ans,k,to[MAXN],dep[MAXN];
bool visit[MAXN];
void dfs(int x)
{
	visit[x]=1;
	dep[x]=1;
	for (int i=head[x];i;i=e[i].next)
	{
		int v=e[i].to;
		if (visit[v]) continue;
		dfs(v);
		dep[x]=max(dep[x],dep[v]+1);
	}
	if (dep[x]==k && to[x]>1) ans++,dep[x]=0;
}
int main()
{
	int n;
	scanf("%d%d",&n,&k);
	to[1]=read();
	if (to[1]>1) ans++;
	to[1]=1;
	for (int i=2;i<=n;i++)
		to[i]=read(),addedge(to[i],i);
	dfs(1);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>X(N);
	vector<int>Y(N);
	for (int n = 0;n<N;++n) {
		cin >> X[n] >> Y[n];
	}
	double ans = 0;
	for (int n = 0;n<N;++n) {
		for (int m = n + 1;m<N;++m) {
			ans += 2.0 * sqrt((X[n]-X[m])*(X[n]-X[m])+(Y[n]-Y[m])*(Y[n]-Y[m])) / N;
		}
	}
	printf("%.10f\n", ans);
	return 0;
}


Measured memory_bytes: 3816
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 0
tmp = 0
for i in range(n):
    if a[tmp]==2:
        print(cnt+1)
        exit()
    else:
        tmp =a[tmp]-1
        cnt += 1
else:
    print(-1)
    exit()

Measured memory_bytes: 7084
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e15
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll N, K;
	cin >> N >> K;

	ll totalNum = (N - 1) * (N - 2) / 2;
	
	if (totalNum < K) {
		cout << -1 << endl;
		return 0;
	}
	
	vector<P> G;
	REPN(i, 1, N) {
		G.emplace_back(0, i);
	}

	REPN(i, 1, N) {
		REPN(j, i + 1, N) {
			if (totalNum != K) {
				G.emplace_back(i, j);
				totalNum--;
			}
			if (totalNum == K) {
				goto EXIT;
			}
		}
	}

EXIT:
	cout << G.size() << endl;
	for (auto one : G) {
		cout << one.first + 1 << " " << one.second + 1<< endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){


  int num,i,j,R[200000],minv=0,maxv;

  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&R[i]);
  }

  maxv =R[1]-R[0];
  minv = R[0];

  for(j=1;j<=num-1;j++){

    if(maxv > R[j]-minv)maxv = maxv;
    else maxv = R[j]- minv;

    if(minv < R[j])minv=minv;
    else minv = R[j];

  }

  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 1376
n, m, x=map(int, input().split())
c=[]
a=[]
for i in range(n):
  l=list(map(int, input().split()))
  c.append(l[0])
  a.append(l[1:])
import numpy as np
ab=np.array(a).T

ans=[]
#print(c)
#print(ab)
from itertools import product
s = [0,1]
for i in sorted(list(product(s, repeat=n))):
  for t in ab:
    if sum(np.array(t)*np.array(i))<x:
      break
  else:
    ans.append(sum(np.array(i)*np.array(c)))
    continue
if ans==[]:
  print(-1)
else:
  print(min(ans))

Measured memory_bytes: 27688
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define maxn 100005
#define maxm 100005
#define eps 1e-6
typedef long long ll;
using namespace std; 
const ll mod = 1e9 + 7;
inline int read(){
	int x = 0, f = 1;char ch = getchar();
	while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
	return x * f;
}

int n, m, y, ans = 10000;
char s[1005],t[1006];
int main(){
	int i, j, x;
	scanf("%s",s+1);scanf("%s",t+1);
	n = strlen(s+1),m= strlen(t+1);
	for(i = 1;i <=n - m +1;i++){
		int now = 0;
		for(j = 1;j <= m;j++){
			if(s[i + j - 1] != t[j]) now++;
		}
		ans = min(ans,now);
	}
	cout<<ans;
}
//

Measured memory_bytes: 3760
import sys
from queue import Queue

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
g = []
for i in range(n):
    g.append([])
for i in range(m):
    u, v = na()
    g[u-1].append(v-1)

s, t = na()
s -= 1;
t -= 1

ds = [[9999999999] * n for i in range(3)]
ds[0][s] = 0

q = Queue()
q.put((0, s))
while not q.empty():
    r, cur = q.get_nowait()
    nr = (r+1) % 3
    for e in g[cur]:
        # print(nr, e)
        if ds[nr][e] > ds[r][cur] + 1:
            ds[nr][e] = ds[r][cur] + 1
            q.put((nr, e))
if ds[0][t] < 99999999:
    print(ds[0][t]//3)
else:
    print(-1)


Measured memory_bytes: 68088
object Main extends App {
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  	val lines = readInt;
  	val k = readInt;
  	val balls = readLine.split(" ").map(_.toInt).toList
  
  	println(balls.map(x => List(x,scala.math.abs(k-x)).min.*(2)).sum.toString)   
}

Measured memory_bytes: 54800
#include <string>
#include <iostream>

using namespace std;
int main() {
    // freopen("in.txt","r",stdin);
    string s, t;
    cin >> s >> t;
    bool flag = true;
    if(s.size()+1!=t.size()) flag = false;
    if(flag) {
      for (int i = 0; i < s.size(); i++) {
          if (s[i] != t[i]) {
              flag = false;
              break;
          }
      }
    }
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3160
import sys, math
input = sys.stdin.readline
N = int(input())

dic = 'abcdefghijklmnopqrstuvwxyz'

def f(n, i, s):
  if n == 1:
    print(s)
    return
  for j in range(i+1):
    f(n-1, i, s + dic[j])
  if i+1 < 25:
  	f(n-1, i+1, s + dic[i+1])

f(N, 0, 'a')

Measured memory_bytes: 4412
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

struct Item {
    string name;
    int score;
    int index;

    bool operator<(const Item& other) const {
        return make_pair(name, -score) < make_pair(other.name, -other.score);
    }
};

int main() {
    int N;
    while (cin >> N) {
        vector<Item> rs;
        for (int i = 0; i < N; ++i) {
            string name;
            int score;
            cin >> name >> score;
            rs.push_back({ name, score, i });
        }
        sort(rs.begin(), rs.end());
        for (int i = 0; i < N; ++i) {
            cout << rs[i].index + 1 << '\n';
        }
    }
}

Measured memory_bytes: 256
s = input()

ans = 0
if s == 'SUN':
    ans = 7
elif s == 'MON':
    ans = 6
elif s == 'TUE':
    ans = 5
elif s == 'WED':
    ans = 4
elif s == 'THU':
    ans = 3
elif s == 'FRI':
    ans = 2
elif s == 'SAT':
    ans = 1

print(ans)

Measured memory_bytes: 2940
from fractions import gcd

N, K = map(int, input().split())
As = list(map(int, input().split()))
if len(As) == 1:
    possible = (As[0] == K)
else:
    g = max(abs(As[1] - As[0]), 1)
    for A in As[2:]:
        g = gcd(g, A - As[0])

    possible = ((K-As[0]) % g == 0) and (min(As) <= K <= max(As))

if possible:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
string s,t="keyence";
int n,m,i,j;
int main()
{
	cin>>s;
	for (i=0;i<=7;i++)
	{
		//cerr<<s.substr(0,i)<<' '<<s.substr(s.length()-(7-i))<<endl;
		if (s.substr(0,i)+s.substr(s.length()-(7-i))==t)
		{
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>


using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

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

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

inline void Main() {
	int r;

	cin >> r;

	cout << r * r;
}

Measured memory_bytes: 256
n = int(input())
mod = 10**9+7
dp = [[0]*4 for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    dp[i+1][3] = (dp[i][3]*10 + dp[i][1] + dp[i][2]) % mod
    dp[i+1][2] = (dp[i][2]*9 + dp[i][0]) % mod
    dp[i+1][1] = (dp[i][1]*9 + dp[i][0]) % mod
    dp[i+1][0] = (dp[i][0]*8) % mod

print(dp[n][3])


Measured memory_bytes: 191484
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define zrep(i, a, b, c) for (int i = int(a); i < int(b); i+=int(c))
using ll = long long;
const int INF = 1001001001;

void InsertSort(vector<int> &A) {
    int N = A.size();
    print(A);
    xrep(i, 1, N) {
        int v = A[i];
        int j = i-1;
        while(v<A[j]) {
            swap(A[j], A[j+1]);
            j--;
        }
    print(A);
    }
}



int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    InsertSort(A);
    return 0;
}


Measured memory_bytes: 3092
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N,nL) = rd.readListInt()
    val L = nL.toLong()
    val A = rd.readListLong()

    var pos = -1
    for (i in 0 until N-1) {
        if (A[i] + A[i+1] >= L) {
            pos = i
            break
        }
    }
    if (pos < 0) {
        println("Impossible")
        return
    }

    val ord = ArrayList<Int>()
    for (i in 0 until pos) {
        ord.add(i+1)
    }
    for (i in N-1 downTo pos+2) {
        ord.add(i)
    }
    ord.add(pos+1)

    println("Possible")
    val ans = ord.joinToString("\n")
    println(ans)
}


//val rd = debug.Reader("agc", "002", "c", "sample-3")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readDouble: () -> Double = { br.readLine().toDouble() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readIntArray: () -> IntArray = { readListInt().toIntArray() }
    val readLongArray: () -> LongArray = { readListLong().toLongArray() }
    val readListStringCol: (Int) -> List<String> = { N -> (0 until N).map { readString() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { readListInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { readListLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 62060
#include <bits/stdc++.h>
using namespace std;
long long k, ans=0, cnt=0, x[100100]={0};
int dfs(long long s, long long tmp){
    if(s<=3234566667 && tmp!=-1){
        x[cnt-1]=s;
    }
    else if(s>3234566667) return 0;
    if(cnt==100000){
        return 0;
    }
    if(cnt>100000) return 0;
    long long a, b, c;
    if(cnt==0){
        cnt++;
        dfs(1,1);
        cnt++;
        dfs(2, 2);
        cnt++;
        dfs(3, 3);
        cnt++;
        dfs(4, 4);
        cnt++;
        dfs(5, 5);
        cnt++;
        dfs(6, 6);
        cnt++;
        dfs(7, 7);
        cnt++;
        dfs(8, 8);
        cnt++;
        dfs(9, 9);
    }
    else if(tmp==0){
        a=s*10;b=s*10+1;
        if(a<=3234566667){
            cnt++;
            dfs(a, 0);
        }
        else return 0;
        if(b<=3234566667){
            cnt++;
            dfs(b, 1);
        }
        else return 0;
    }
    else if(tmp==9){
        a=s*10+8;b=s*10+9;
        if(a<=3234566667){
        cnt++;
        dfs(a, 8);
        }
        if(b<=3234566667){
        cnt++;
        dfs(b, 9);
        }
    }
    else{
        a=s*10+(tmp-1);b=s*10+tmp;c=s*10+(tmp+1);
        if(a<=3234566667){
            cnt++;
            dfs(a, tmp-1);
        }
        else return 0;
        if(b<=3234566667){
            cnt++;
            dfs(b, tmp);
        }
        else return 0;
        if(c<=3234566667){
            cnt++;
            dfs(c, tmp+1);
        }
        else return 0;
    }
}
int main(){
    long long i;
    cin >> k;
    dfs(0, -1);
    sort(x, x+100000);
    ans=x[k-1];
    
    cout << ans <<endl;
    return 0;
}

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

using namespace std;

vector<vector<int>> dp;

const int MOD = 1e9 + 7;

int main(){
    int h, w;
    cin>>h>>w;
    string s;
    int tmp = h;
    vector<string> arr;
    while(tmp--){
        cin>>s;
        arr.push_back(s);
    }
    dp.assign(h, vector<int>(w, 0));
    for(int i = 0; i < w; i++) if(arr[0][i] != '#') dp[0][i] = 1; else break;
    for(int i = 0; i < h; i++) if(arr[i][0] != '#') dp[i][0] = 1; else break;
    for(int i = 1; i < h; i++){
        for(int j = 1; j < w; j++){
            if(arr[i][j] == '#') continue;
            dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
        }
    }
    int res = dp[h-1][w-1];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
typedef long long ll;
ll max(ll a,ll b){return a<b?b:a;}
ll w[100005],bit[(1<<17)+5];
int a[100005],n;
int f(int x){ return x&-x;}
void update(int i,ll x){ for(int s=i;s<=(1<<17);s+=f(s)) bit[s]=max(bit[s],x);}
ll get(int i){ ll ret=0LL; for(int s=i;s>0;s-=f(s)) ret=max(ret,bit[s]); return ret;}
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++) w[i]=i;
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  ll sum=0;
  for(int i=1;i<=n;i++)
    {
      ll got=get(a[i]-1);
      update(a[i],got+w[a[i]]); sum+=w[i];
    }
  printf("%lld\n",(sum-get((1<<17))));
}

Measured memory_bytes: 4700
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


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

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


const long long INF = 1LL<<60;

void solve() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    vector<vector<long long>> dp(N+1, vector<long long>(H+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= H; j++) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
        }

        // for (int k = 0; k <= N; k++) {
        //     for (int l = 0; l <= H; l++) {
        //         if (dp[k][l] == INF) cout << -1 << " ";
        //         else cout << " " << dp[k][l] << " ";
        //     }
        //     cout << endl;
        // }
        // cout << endl;
    }

    cout << dp[N][H] << endl;

    
}


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

Measured memory_bytes: 78592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int q = in.nextInt();

		for (int l = 0; l < q; l++) {

			char[] x = (" "+in.next()).toCharArray();
			char[] y = (" "+in.next()).toCharArray();
			int[][] c = new int[x.length][y.length];

			for (int i = 1; i < x.length; i++) {
				for (int j = 1; j < y.length; j++) {
					if (x[i] == y[j]) {
						c[i][j] = c[i-1][j-1] + 1;
					} else if (x[i] != y[j]) {
						c[i][j] = Math.max(c[i][j-1], c[i-1][j]);
					}
				}
			}
			System.out.println(c[x.length-1][y.length-1]);
		}
		in.close();
	}
}



Measured memory_bytes: 63940
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

int n, m, k, s, p, q;
vector<vector<int> > G;
vector<int> c, d, cost;

const int INF = 1e16;

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > q;
    rep(i, 0, n) d[i] = INF;
    d[s] = 0;
    q. push(P(0, s));

    while(!q.empty()){
        P p = q.top(); q.pop();
        int v = p.second;
        if(p.first > d[v]) continue;
        rep(i, 0, G[v].size()){
            int next = G[v][i];
            if(d[next] > d[v] + cost[next]){
                d[next] = d[v] + cost[next];
                q. push(P(d[next], next));
            }
        }
    }
}


signed main(){
    cin >> n >> m >> k >> s >> p >> q;
    c.resize(k);
    G.resize(n, vector<int>());
    d.resize(n, 1e16);
    cost.resize(n, 1);
    vector<int> f(n, 0);
    rep(i, 0, k){
        cin >> c[i];
        c[i]--;
    }
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a]. push_back(b);
        G[b]. push_back(a);
    }
    rep(i, 0, k){
        dijkstra(c[i]);
        rep(j, 0, n){
            if(d[j] <= s) f[j] = 1;
        }
    }
    rep(i, 0, n){
        if(f[i]){
            cost[i] = q;
            // cout << i + 1 << endl;
        }
        else cost[i] = p;
    }
    rep(i, 0, k){
        cost[c[i]] = 1e16;
    }
    cost[0] = cost[n - 1] = 0;
    dijkstra(0);
    cout << d[n - 1] << endl;
}

Measured memory_bytes: 12364
import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())

edge = [[0 for j in range(N)] for i in range(N)]

room1 = []
for i in range(N):
	room1.append(i)
room1.append(1)
room = [room1]

while len(room) > 0:
	now = room.pop()
	num = now.pop()
	now1 = now[0:len(now)//2]
	now2 = now[len(now)//2:len(now)]
	for i in now1:
		for j in now2:
			edge[i][j] = num
	if len(now1) > 1:
		now1.append(num + 1)
		room.append(now1)
	if len(now2) > 1:
		now2.append(num + 1)
		room.append(now2)
for i in range(N - 1):
	for j in range(i + 1, N - 1):
		print(edge[i][j], end="")
		print(" ", end="")
	print(edge[i][N - 1])

Measured memory_bytes: 72920
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int a,b,k; cin>>a>>b>>k;
    if(a>b) swap(a,b);
    vint v;
    for(int i=1;i<=a;i++){
        if(a%i==0 and b%i==0){
            v.push_back(i);
        }
    }
    sort(ALL(v),greater<int>());
    cout<<v[k-1]<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>


void kitamuraeri(int mimorisuzuko[30], int tokuisora) {
	static const int asumikana[4][10] = {
		{ 1,  4,  7, 10, 16, 24, 27, 30, 21, 18},
		{ 7,  8,  9, 13, 10, 22, 23, 24, 18, 12},
		{ 9,  6,  3, 19, 13, 28, 25, 22, 12, 15},
		{ 3,  2,  1, 16, 19, 30, 29, 28, 15, 21}
	};
	int kugimiyarie;
	for (kugimiyarie = 0; kugimiyarie < 5; kugimiyarie++) {
		int matukimiyu, araisatomi;
		matukimiyu = mimorisuzuko[asumikana[tokuisora][kugimiyarie] - 1];
		araisatomi = mimorisuzuko[asumikana[tokuisora][kugimiyarie + 5] - 1];
		mimorisuzuko[asumikana[tokuisora][kugimiyarie] - 1] = araisatomi;
		mimorisuzuko[asumikana[tokuisora][kugimiyarie + 5] - 1] = matukimiyu;
	}
}

int hanazawakana(const int utidamaaya[30]) {
	int sakuraayane, minaseinori;
	for (sakuraayane = 1; sakuraayane < 9; sakuraayane++) {
		if (utidamaaya[0] != utidamaaya[sakuraayane]) return 0;
		if (utidamaaya[21] != utidamaaya[21 + sakuraayane]) return 0;
	}
	for (minaseinori = 9; minaseinori < 21; minaseinori += 3) {
		for (sakuraayane = 1; sakuraayane < 3; sakuraayane++) {
			if (utidamaaya[minaseinori] != utidamaaya[minaseinori + sakuraayane]) return 0;
		}
	}
	return 1;
}

int solve(void) {
	int nakamurayuuichi = 8;
	int sakagutidaisuke;
	int fukuennmisato;
	int tatenokanako[30];
	int katouemiri[30];
	for (sakagutidaisuke = 0; sakagutidaisuke < 30; sakagutidaisuke++) {
		if (scanf("%d", &tatenokanako[sakagutidaisuke]) != 1) return 0;
	}
	if (hanazawakana(tatenokanako)) {
		nakamurayuuichi = 0;
	} else {
		for (sakagutidaisuke = 0; sakagutidaisuke < 0x10000; sakagutidaisuke++) {
			for (fukuennmisato = 0; fukuennmisato < 30; fukuennmisato++) {
				katouemiri[fukuennmisato] = tatenokanako[fukuennmisato];
			}
			for (fukuennmisato = 0; fukuennmisato < nakamurayuuichi; fukuennmisato++) {
				kitamuraeri(katouemiri, (sakagutidaisuke >> (2 * fukuennmisato)) & 3);
				if (hanazawakana(katouemiri)) nakamurayuuichi = fukuennmisato + 1;
			}
		}
	}
	printf("%d\n", nakamurayuuichi);
	return 1;
}

int main(void) {
	int oogameasuka;
	int satourina;
	if (scanf("%d", &oogameasuka) != 1) return 1;
	for (satourina = 0; satourina < oogameasuka; satourina++) {
		if (!solve()) return 1;
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    String ans = "NO";
    if((100 * r + 10 * g + b) % 4 == 0) ans = "YES";
    System.out.println(ans);
  }
}

Measured memory_bytes: 22996
# ABC153 E - Crested Ibis vs Monster
h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
    aa,bb=map(int,input().split())
    a.append(aa)
    b.append(bb)

dp=[[float("inf")]*(h+1) for i in range(n+1)]
dp[0][0]=0

for i in range(n):
    for j in range(h+1):
        # i番目の魔法を使わない場合
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        # i番目の魔法を使う場合
        dp[i+1][min(j+a[i],h)]=min(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i])    
        
print(dp[n][h])

Measured memory_bytes: 286856
#include <cassert>
#include <limits>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n),b(n);
  rep(i,0,n)std::cin>>a[i];
  rep(i,0,n)std::cin>>b[i];

  ll ans=0;

  rep(i,0,29){
    std::vector<ll> temp(n);
    rep(j,0,n)temp[j]=b[j]%(1ll<<(i+1));
    std::sort(all(temp));

    ll cnt=0;
    ll t=(1ll<<i);
    rep(j,0,n){
      cnt+=(ll)(std::lower_bound(all(temp),2*t-(a[j]%(2*t)))-std::lower_bound(all(temp),t-(a[j]%(2*t))));
      cnt+=(ll)(std::lower_bound(all(temp),4*t-(a[j]%(2*t)))-std::lower_bound(all(temp),3*t-(a[j]%(2*t))));
    }

    if(cnt%2)ans+=t;
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#define INF 10000000

int matrixChainOrder(int *p, int n){
  int i, j, k, l,  m[100][100], q;
  for(i = 1; i <= n; i++)
    m[i][i] = 0;
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k < j; k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	if(m[i][j] > q) m[i][j] = q;
      }
    }
  }
  return m[i-1][j];
}

int main(){
  int i, n, p[100];
  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d %d",&p[i], &p[i+1]);
  printf("%d\n",matrixChainOrder(p,n));
  return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int dp[3005][6005];

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

    int n, t;
    cin >> n >> t;
    vector<P> table(n);
    int maxe = 0;
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        table[i] = P(a, b);
        chmax(maxe, a);
    }
    sort(table.begin(), table.end());
    
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= t + maxe; ++j){
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < t; ++j){
            if(dp[i][j] == -1)  continue;
            chmax(dp[i + 1][j], dp[i][j]);
            int a = table[i].first, b = table[i].second;
            chmax(dp[i + 1][j + a], dp[i][j] + b);
            chmax(ans, dp[i + 1][j + a]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;

lli n;
lli a[3003];
lli dp[2][3003][3003];

lli func(int t,lli l,lli r){
    if(r<l) return 0;
    if(dp[t][l][r]!=-1) return dp[t][l][r];
    
    if(t==0){
        return dp[t][l][r]=max(a[l]-func(1,l+1,r) , a[r]-func(1,l,r-1));
    }
    else{
        return dp[t][l][r]=max(a[l]-func(0,l+1,r) , a[r]-func(0,l,r-1));
    }
}

int main(){
    memset(dp,-1,sizeof(dp));
    cin>>n;
    lli i,j,l;
    for(i=0;i<n;i++) cin>>a[i];
    
    lli ans=max(a[0]-func(1,1,n-1) , a[n-1] - func(1,0,n-2));
    cout<<ans<<endl;
}


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

#define ankit_2305 cerr<<"\nTime taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<" sec\n";
#define START clock_t
#define TIMER time_p=clock();
#define ll long long

#define MOD 1000000007

using namespace std;

int main(){
    START TIMER
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin>>n;
	ll a, ans = 1;
	double checker = 0;
	for(int i=0;i<n;i++){
		cin>>a;
		ans *= a;
		checker += log10(a);
	}
	if(checker > 18 || ans > 1000000000000000000)
		cout<<"-1";
	else
		cout<<ans;
    ankit_2305
    return 0;
}


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

using namespace std;

#define dbg(a) cout<<#a<<" = "<<a<<endl
#define dbg2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define dbg3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define dbg4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int x;
	double z;
	cin>>x;
	z = floor((x+1)/2);
	z = z/x;
	cout.precision(10);
	std::cout.setf( std::ios::fixed, std:: ios::floatfield );
	cout<<z;
	return 0;
}


Measured memory_bytes: 256
import java.math.*;
import java.text.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		in.useDelimiter("\\s*[,\\n]\\s*");
		double cx = 0, cy = 0, ct=Math.toRadians(90);
		while(in.hasNextInt()){
			int r = in.nextInt();
			cx += r*Math.cos(ct);
			cy += r*Math.sin(ct);
			int t = in.nextInt();
			ct -= Math.toRadians(t);
			if(r==0 && t==0) break;
		}
		System.out.println((int)cx);
		System.out.println((int)cy);
	}

}

Measured memory_bytes: 12000