akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
struct node
{
	int a,b,id;
	bool operator < (const node x) const&
	{
		return 1LL*a*x.b<1LL*b*x.a;
	}
}a[200010];
int n,fa[200010],p[200010];
long long ans;
priority_queue<node> q;
int find(int x)
{
	if (fa[x]!=x)
	{
		fa[x]=find(fa[x]);
	}
	return fa[x];
}
int main()
{
	scanf("%d",&n);
	for (int i=2;i<=n;i++)
	{
		scanf("%d",&p[i]);
	}
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if (x==0)
		{
			a[i].a++;
		}
		else
		{
			a[i].b++;
		}
		a[i].id=i;
		fa[i]=i;
		q.push(a[i]);
	}
	while (!q.empty())
	{
		int x=q.top().id;
		if (x==1 || a[x].a!=q.top().a || a[x].b!=q.top().b)
		{
			q.pop();
			continue;
		}
		q.pop();
		int f=find(p[x]);
		fa[x]=f;
		ans+=1LL*a[f].b*a[x].a;
		a[f].a+=a[x].a;
		a[f].b+=a[x].b;
		a[x].a=a[x].b=0;
		q.push(a[f]);
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7796
def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #数字リストをstrで

S, W = inpl()
print("unsafe") if S <= W else print("safe")

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

int main(){

  int n;
  cin>>n;
  int a[200],b[200];  
  
  for(int i=0;i<n;i++){
   cin>>a[i];
   cin>>b[i];
  }
  
  for(int i=n;i>0;i--){
    if(a[i]==b[i] && a[i-1]==b[i-1] && a[i-2]==b[i-2]){
      cout<<"Yes"<<endl;return 0;}
    else continue;
  }
  cout<<"No"<<endl;
 
 return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

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



int main()
{
    char c;
    cin >> c;
    if(c>='a'){
        cout << "a" << endl;
    }else{
        cout << "A" << endl;
    }




    return 0;
}

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

const int MAX= 12800;
const int INF = 1E8;
const int MAXN=82;

bool f[MAXN][2*MAX+5];
bool nf[MAXN][2*MAX+5];
int h, w;
int a[MAXN][MAXN][2];

signed main(){
	cin >> h >> w;
	for(int t=0;t <= 1; ++t)
		for(int i=1; i<= h; ++i)
			for(int j=1; j<= w; ++j)
				cin >> a[i][j][t];

	//dp for first row
	f[1][MAX+(a[1][1][0]-a[1][1][1])] = f[1][MAX - (a[1][1][0] - a[1][1][1])] = 1;
	for(int j=2; j<= w; ++j)
		for(int t=0;t<= 2*MAX; ++t){
			int u =a[1][j][0] - a[1][j][1];
			if(t-u >= 0 && t-u <= 2*MAX) f[j][t] |= f[j-1][t-u];
			if(t+u >=0 && t+u <= 2*MAX) f[j][t] |= f[j-1][t+u];
		}
	//other row
	for(int i=2; i<= h; ++i){
		memcpy(nf, f, sizeof f);
		memset(f, 0, sizeof f);
		//for first cell
		for(int t=0;t<= 2*MAX; ++t){
			int u =a[i][1][0] - a[i][1][1];
			if(t-u >= 0 && t-u <= 2*MAX) f[1][t] |= nf[1][t-u];
			if(t+u >=0 && t+u <= 2*MAX) f[1][t] |= nf[1][t+u];
		}
		//other cell
		for(int j=2; j<= w; ++j)
			for(int t=0;t<= 2*MAX; ++t){
				int u =a[i][j][0] - a[i][j][1];
				if(t-u >=0 && t-u <= 2*MAX) f[j][t]|= (f[j-1][t-u] || nf[j][t-u]);
				if(t+u >=0 && t+u <= 2*MAX) f[j][t]|= (f[j-1][t+u] || nf[j][t+u]);
			}
	}
	int ans= MAX;
	for(int t=0; t<= 2*MAX; ++t){
			if(f[w][t] == 1) ans=min(ans, abs(t-MAX));
	}
	cout << ans;
}

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

int main(){
    ll x;
    cin >> x;
    ll ans=0;
    ll sum=100;
    while(sum<x){
        sum*=1.01;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

void West(int surface[]);
void East(int surface[]);
void North(int surface[]);
void South(int surface[]);

typedef struct dice {

	int surface[6];
	string str;

} Dice;

Dice memory;

int main() {

	Dice dice;

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

		cin >> dice.surface[i];

	}

	cin >> dice.str;
	memory = dice;

	for (int i = 0; i < dice.str.size(); i++) {

		switch (dice.str[i]) {

		case 'W':
			West(dice.surface);
			break;
		case 'E':
			East(dice.surface);
			break;
		case 'N':
			North(dice.surface);
			break;
		case 'S':
			South(dice.surface);
			break;

		}

		dice = memory;

	}

	cout << dice.surface[0] << endl;

}

void West(int surface[]) {

	memory.surface[0] = surface[2];
	memory.surface[2] = surface[5];
	memory.surface[5] = surface[3];
	memory.surface[3] = surface[0];

	return;

}

void East(int surface[]) {

	memory.surface[0] = surface[3];
	memory.surface[3] = surface[5];
	memory.surface[5] = surface[2];
	memory.surface[2] = surface[0];

	return;

}

void North(int surface[]) {

	memory.surface[0] = surface[1];
	memory.surface[1] = surface[5];
	memory.surface[5] = surface[4];
	memory.surface[4] = surface[0];

	return;

}

void South(int surface[]) {

	memory.surface[0] = surface[4];
	memory.surface[4] = surface[5];
	memory.surface[5] = surface[1];
	memory.surface[1] = surface[0];

	return;

}


Measured memory_bytes: 3176
#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 PI = 3.1415926535897932;   // acos(-1)
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)
#define chadd(x, y) x = (x + y) % mod

vector<ll> divisor(ll x){
    vector<ll> res;
    for(ll i = 1; i * i <= x; ++i){
        if(x % i == 0){
            res.push_back(i);
            if(i * i != x)  res.push_back(x / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

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

    ll n, s;
    cin >> n >> s;
    if(n == s){
        cout << n + 1 << endl;
        return 0;
    }
    if(n < s){
        cout << -1 << endl;
        return 0;
    }

    for(int i = 2; (ll)i * i <= n; ++i){
        ll sum = 0;
        ll foo = n;
        while(foo){
            sum += foo % i;
            foo /= i;
        }
        if(sum == s){
            cout << i << endl;
            return 0;
        }
    }

    vector<ll> div = divisor(n - s);
    int sz = div.size();
    for(int i = 0; i < sz; ++i){
        ll base = div[i] + 1;
        ll foo = n;
        ll sum = 0;
        while(foo){
            sum += foo % base;
            foo /= base;
        }
        if(sum == s){
            cout << base << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

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

int main() {
  int n, a, b;
  //string s;
  cin >> n >> a >> b;
  //char a;
  //char b = 'a';
  //int count_a = 1;
  //int count_b = 0;

  if(n*a >= b) {
    cout << b << endl;
  }
  else {
    cout << n*a << endl;
  }
  /*
  a = s.at(0);
  for(int i = 1; i < 4; i++) {
    if(s.at(i) == a) {
      count_a++;
    } else if(b == 'a'){
      b = s.at(i);
      count_b++;
    } else if(s.at(i) == b) {
      count_b ++;
    } else {
      cout << "No" << endl;
      return 0;
    }
    //cout << a << endl;
    //cout << b << endl;
  }

  if(count_a == 2 && count_b == 2) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    */
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int A = 0;
        for (int i = 0 ; i < M ; i++) {
            A += scanner.nextInt();
        }

        System.out.println(Math.max(N - A, -1));
    }
}


Measured memory_bytes: 46200
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        if(x<y||x==y){
            cout<<x<< " "<<y<<endl;
        }else if(x>y){
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


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

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

using namespace std;

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

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

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

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

int main(){
fast_io
int r,g; cin>>r>>g;
cout<<(2*g-r);
return 0;
}

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

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

const ll MOD0 = 1e9+7;
const ll MOD1 = 1e9+9;
//const ll base = 4007;
const ll base = 7;

ll modpow(ll a, int n, ll q){
	ll ret = 1, k = a;
	for(int i=0; (1<<i)<=n; i++){
		if( (1<<i)&n ) ret = ret * k % q;
		k = k*k % q;
	}
	return ret;
}

int main(){

//	ll p=0;
//	{
//		bool f[10000]={};
//		for(int i=2; i<10000; i++){
//			if( !f[i] ){
//				if( i>4005 ){
//					p = i;
//					break;
//				}
//				for(int j=i; j<10000; j+=i) f[j] = true;
//			}
//		}
//	}

	string s[2];
	rep(i,2) cin >> s[i];

	int ans = 0;
	ll hs[2][2][4005]={};
	rep(l,min(s[0].length(),s[1].length()) ){
		//cout << l << endl;
		set<pii> st;
		rep(k,2){
			rep(i,s[k].length()-l){
				int c = s[k][i+l] - 'a' + 1;
				hs[k][0][i] += modpow(base, c, MOD0);
				hs[k][0][i] %= MOD0;
				hs[k][1][i] += modpow(base, c, MOD1);
				hs[k][1][i] %= MOD1;
				auto key = pii(hs[k][0][i], hs[k][1][i]);
				if( k == 0 ){
					//cout << "insert " << i << " " << l+1 << " " << key << endl;
					st.insert( key );
				}else{
					//cout << "count  " << i << " " << l+1 << " " << key << endl;
					if( st.count(key) ){
						ans = max(ans, l+1);
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
int len[250];
int main()
{
	int n,sum=0;
	cin >>n;
	for (int i=1;i<=2*n;i++)
	cin >>len[i];
	sort(len+1,len+n*2+1);
	for (int i=1;i<=n;i++)
	sum=sum+len[2*i-1];
	cout<<sum;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <stdint.h>

std::vector<int64_t> edges[100005];

int64_t as[100005];

void fail(){
  printf("NO\n");
  exit(0);
}

int64_t dfs(int64_t node,int64_t parent){
  if(edges[node].size()==1&&node!=parent) return as[node];//leaf
  int64_t ac=0;
  int64_t max=0;
  for(int64_t child:edges[node]){
    if(child==parent) continue;
    int64_t tmp=dfs(child,node);
    ac+=tmp;
    max=std::max(max,tmp);
  }
  if(max>as[node]||as[node]>ac||2*as[node]<ac) fail();
  if(edges[node].size()==1) return 0;
  //printf("%ld: %ld\n",node,2*as[node]-ac);
  return 2*as[node]-ac;
}

int main(){
  int64_t N;
  scanf("%ld",&N);
  for(int64_t i=0;i<N;i++){
    scanf("%ld",&as[i]);
  }
  for(int64_t i=0;i<N-1;i++){
    int64_t A,B;
    scanf("%ld %ld",&A,&B);
    A--,B--;
    edges[A].push_back(B);
    edges[B].push_back(A);
  }
  if(dfs(0,0)) fail();
  printf("YES\n");
  return 0;
}


Measured memory_bytes: 11776
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] t = new long[n];
        for (int i = 0 ; i < n ; i++) {
            t[i] = sc.nextLong();
        }
        long ans = 1;
        for (int i = 0 ; i < n ; i++) {
            ans = LCM(ans, t[i]);
        }
        System.out.println(ans);

    }
    //ユーグリッド互除法により最大公約数を求める
    private static long GCD(long a, long b) {
        if (a < b) {
            return GCD(b, a);
        }
        if (b == 0) {
            return a;
        }
        return GCD(b, a % b);
    }
    //最小公倍数を求める。
    private static long LCM(long a, long b) {
        long temp = a / GCD(a, b);
        return temp * b;
    }

}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define N 100005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rev(a,n) reverse(a,a+n)
using namespace std;
int n,k,a[N],ans;
int main() {
	cin>>n>>k;
	rep(i,0,n) cin>>a[i];
	//数组中肯定有1，所以最后结果肯定是n个1，1在x位，左边为（a-1）/（k-1），右边为 （n-x）/（k-1）
	//加起来得(n-1)/(k-1) 
	ans=(n-1)/(k-1);
	if((n-1)%(k-1)!=0)ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3964
from collections import defaultdict
cards = defaultdict(int)
n = int(input())
for i in range(n):
  s = input()
  cards[s] += 1

m = int(input())
for i in range(m):
  t = input()
  cards[t] -= 1

max_c = -float('inf')
for v in cards.values():
  max_c = max(max_c, v)
print(max(0, max_c))

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u == s) cout << --a << " " << b << endl;
    else cout << a << " " << --b << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

def pr(A):
    N = len(A)
    for i in range(N):
        if i != 0:
            print(" ",end = "")
        print(A[i], end = "")
    print("")

def insertionSort(A):
    N =len(A)
    for i in range(1,N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        pr(A)

pr(A)
insertionSort(A)



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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  
  if ((a+b) == (c+d)){
    cout << "Balanced" << endl;
  }else if ((a+b) < (c+d)) {
    cout << "Right";
  }else if ((a+b) > (c+d)) {
    cout << "Left";
  }
      
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main(){
    fast_io
   
    int n, m;
    cin>>n>>m;
    UnionFind tree(n);
    rep(i,m){
      int x, y;
      cin>>x>>y;
      if(!tree.findSet(x, y)){
        tree.unionSet(x, y);
      }
    }
    int ans =0;
    rep(i,n){
      ans = max(ans, tree.size(i));
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    long long a,b,c,d,e,i,j;
    cin >> a;
    vector<int>vec;
   while(a--)
   {
       cin >> b;
       vec.push_back(b);





   }
   int sum=vec[0];
   for(j=1;j<vec.size();j++)
   {
       sum^=vec[j];


   }

   for(j=0;j<vec.size();j++)
   {
       int x=vec[j]^sum;
       cout << x << " ";


   }








}



Measured memory_bytes: 4320
#include <iostream>
#include <vector>

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

    std::vector<int64_t> L(86);

    L[0] = 2;
    L[1] = 1;

    if (N >= 2)
    {
        for (auto i = 2; i <= N; i++)
        {
            L[i] = L[i - 1] + L[i - 2];
        }
    }

    std::cout << L[N] << std::endl;
}


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

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

    int ans=0;
    for(int i=0;i<s.length();i++){
        int cnt=0;
        for(int j=i;j<s.length();j++){
            if(s[j]=='A'||s[j]=='T'||s[j]=='C'||s[j]=='G') cnt++;
            else break;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 054c

int n, m;
vector<int> adj[10];
int ans=0;

void dfs(int v, vector<bool> visited){
    bool flag = true;
    visited[v] = true;
    rep(i, n){
        flag = false;
        if(!visited[i]){
            flag = true;
            break;
        }
    }

    if (flag){
        rep(i, adj[v].size()){
            int nv = adj[v][i];
            if (visited[nv]) continue;
            dfs(nv, visited);
        }
    }else{
        ans++;
    }
}

int main(){
    cin >> n >> m;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<bool> visited(n);
    rep(i, n) visited[i] = false;
    dfs(0, visited);

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


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


bool is_prime(const unsigned n) {
    switch(n) {
        case 0:
        case 1: return false;
        case 2: return true;
    }
    if(n % 2 == 0) return false;
    for(unsigned i=3; i*i <= n; i+=2) {
        if(n % i == 0) return false;
    }
    return true;
}

int main(){
    int X, num;
    cin >> X;
    for(int i=X; i<=1000000; i++) {
        if(is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
bool used[10][10];
int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int dfs(vector<vector<int> > &grid, int bef, int aft, int x = 0, int y = 0){
  int res = 0;
  used[y][x] = true;
  grid[y][x] = aft; 
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if(not (0 <= nx and nx < grid[0].size() and 
            0 <= ny and ny < grid.size()))continue;
    if(used[ny][nx] or grid[ny][nx] != bef)continue;
    res += dfs(grid, bef, aft, nx, ny) + 1;
  }
  return res;
}

int check(vector<vector<int> > grid, vector<int> &perm){
  for (int i = 0; i < perm.size(); i++) {
    memset(used, false, sizeof(used));
    dfs(grid, grid[0][0], perm[i]);
  }
  memset(used, false, sizeof(used));
  return dfs(grid, perm.back(), perm.back()) + 1;
}

int solve(vector<vector<int> > &grid, vector<int> &perm, int d=0){
  int res = 0;
  if(d == 4)return check(grid, perm); 
  for (int i = 0; i < 6; i++){
    perm[d] = i;
    res = max(res ,solve(grid, perm, d + 1));
  } 
  return res;
}
          

int main(){
  int h, w, c;
  while(std::cin >> h >> w >> c, h){
    c--;
    vector<vector<int> > grid(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        std::cin >> grid[i][j];
        grid[i][j]--;
      }
    }
    vector<int> perm(5);
    perm[4] = c;
    std::cout << solve(grid, perm) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3064
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;

void mymain(){
    string s;
    cin >> s;

    int ans=1,n=s.size();
    char lst=s[0];
    for(int i=1;i<n;i++){
        if(s[i]!=lst){
            ans++;
            lst = s[i];
        }

        else{
            if(i!=n-1)
                ans++;
            i++;
            lst='1';
        }

    }
    cout << ans <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t;
t=1;
///cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = 0;

    double tate = min(H-y, y);
    double yoko = min(W-x, x);

    bool tt = false;
    bool yy = false;
    if(H % 2 == 0)
        tt = y == H/2;
    if(W % 2 == 0)
        yy = x == W/2;
    double t = tate * W;
    double s = yoko * H;

    //chmax(ans, t);
    //chmax(ans, s);

    //bool ok = false;
    //if(H/y == W/x && H%y == W%x){
    //    //chmax(ans, tate*yoko/2);
    //    ok = true;
    //}
    ans = (double)H * W / 2.0;

    //if(tate * W == yoko * H){
    //    printf("%.15lf %d\n", ans, 1);
    //}
    if(tt && yy){
        printf("%.15lf %d\n", ans, 1);
    }
    //else if(ok){
    //    printf("%.15lf %d\n", ans, 1);
    //}
    else{
        printf("%.15lf %d\n", ans, 0);
    }
    //else if(t > s){
    //    if(tt){
    //        printf("%.15lf %d\n", ans, 1);
    //    }
    //    else{
    //        printf("%.15lf %d\n", ans, 0);
    //    }
    //}
    //else{
    //    if(yy){
    //        printf("%.15lf %d\n", ans, 1);
    //    }
    //    else{
    //        printf("%.15lf %d\n", ans, 0);
    //    }
    //}
    return 0;
}


Measured memory_bytes: 256
#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  
#define pause system("pause")  
  
using namespace std;  
  
inline ll read()  
{  
    long long 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;  
}  
int main()  
{  
    ll l=read(),r=read();  
    int ans=0;  
    while (r>=l) l*=2,ans++;   
    cout<<ans;  
    return 0;  
}  

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

int c[2][600][600];
int D[2];
int N;
vector<P> ds;
void dfs(int t[600][600],int i, int j, int v){
	if(t[i][j]>=0)return;
	t[i][j]=v;
	for(P d:ds){
		int x=i+d.first;
		int y=j+d.second;
		if(0<=x&&x<2*N&&
			0<=y&&y<2*N){
			dfs(t,x,y,v^1);
		}
	}
}
int main() {
	cin >> N >> D[0] >> D[1];
	memset(c,-1,sizeof(c));
	for(int i=0;i<2;i++){
		ds.clear();
		for(int k=0;k*k<=D[i];k++){
			int v=(int)(sqrt(D[i]-k*k)+0.5);
			if(v*v+k*k==D[i]){
				//cerr << k << ", " << v << endl;
				ds.push_back(P(k,v));
				ds.push_back(P(k,-v));
				ds.push_back(P(-k,v));
				ds.push_back(P(-k,-v));
			}
		}
		for(int x=0;x<2*N;x++){
			for(int y=0;y<2*N;y++){
				if(c[i][x][y]==-1){
					dfs(c[i],x,y,0);
				}
				//cerr << c[i][x][y];
			}
			//cerr << endl;
		}
		//cerr << endl;
	}
	vector<P> ret[2][2];
	for(int x=0;x<2*N;x++){
		for(int y=0;y<2*N;y++){
			auto& r=ret[c[0][x][y]][c[1][x][y]];
			r.push_back(P(x,y));
			if(r.size()==N*N){
				for(auto p:r){
					cout << p.first << " " << p.second << endl;
				}
				return 0;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 29144
import sys
from math import sqrt

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


a, b, c = MI()
if c - b - a <= 0:
    print('No')
    exit(0)
r = (c - b - a) ** 2
l = 4 * a * b
if l < r:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
const std::string yes = "Yes";
const std::string no  = "No";

int main(){
    int n,m;
    std::cin >> n;
    std::set<std::string> st;
    std::multiset<std::string> s,t;
    rep(i,n){
        std::string si;
        std::cin >> si;
        s.insert(si);
        st.insert(si);
    }
    std::cin >> m;
    rep(i,m){
        std::string ti;
        std::cin >> ti;
        t.insert(ti);
        st.insert(ti);
    }

    int ans = 0;
    for(auto itr=st.begin(); itr!=st.end(); itr++){
        int buf = s.count(*itr);
        buf -= t.count(*itr);
        ans = std::max(ans, buf);
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3604
x,k,d=map(int,input().split())
x=abs(x)
first_move=x//d
if first_move>k:
  x-=k*d
  x=abs(x)
  print(x)
  exit()

x-=first_move*d
x=abs(x)
k-=first_move
print(abs(x-d) if k&1 else x)

Measured memory_bytes: 9160
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

bool solve(void){
    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    SORT(a);

    if(n % 3 == 0){
        rep(i, n / 3){
            if(a[i] != a[0]){
                return false;
            }
        }
        REP(i, n / 3, (n * 2) / 3){
            if(a[i] != a[n / 3]){
                return false;
            }
        }
        REP(i, (n * 2) / 3, n){
            if(a[i] != a[n - 1]){
                return false;
            }
        }
        vector<int> v = {a[0], a[n / 3], a[n - 1]};
        SORT(v);
        do{
            if((v[0] ^ v[1]) == v[2] && (v[1] ^ v[2]) == v[0] && (v[2] ^ v[0]) == v[1]){
                return true;
            }
        }while(next_permutation(v.begin(), v.end()));
        return false;
    }else{
        rep(i, n){
            if(a[i] != a[0]){
                return false;
            }
        }
        if(a[0] != 0){
            return false;
        }
    }

    return true;
}

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

    if(solve()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long n,i,c,a[300000];
bool res=true;
int main(){
  for(cin>>n;i<n*3;i++)cin>>a[i];
  sort(a,a+3*n,greater<int>());
  for(i=0;i<n;i++){
    c+=a[1+i*2];
  }
  cout<<c;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A[30];
int xs[30][30], ys[30][30];

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> A[i];
      
      for(int j=0;j<A[i];++j){
          std::cin >> xs[i][j] >> ys[i][j];

          xs[i][j] -= 1;
      }
  }

  int res = 0;

  for(int i=0;i<(1<<N);++i){
      bool ok = true;

      for(int j=0;j<N;++j){
          unless(i >> j & 1){
              continue;
          }

          for(int k=0;k<A[j];++k){
              int x = xs[j][k], y = ys[j][k];

              if(y == 1 && (i >> x & 1) == 0){
                  ok = false;
              }

              if(y == 0 && (i >> x & 1) == 1){
                  ok = false;
              }
          }
      }

      if(ok){
          res = std::max(res, __builtin_popcount(i));
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    int k;
    scanf("%d %d", &n, &k);
    int h[n];
    int count = 0;
    for(int i = 0;i < n;i++){
        scanf("%d",&h[i]);
    }
    for(int i = 0;i<n;i++){
        if(h[i] >= k){
            count++;
        } 
    }
    printf("%d",count);
    return 0;
}

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

using namespace std;
const int N = 106, mod = 1e9 + 7;
char s[2][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 2; i++)
    scanf("%s", s[i]);
  long long ans = 1;
  if (s[0][0] == s[1][0])
    ans = 3;
  else
    ans = 6;
  for (int i = 1 + (s[0][0] != s[1][0]); i < n; i++) {
    if (s[0][i] == s[1][i]) {
      if (s[0][i-1] == s[1][i-1])
        ans = (ans * 2) % mod;
    }
    else {
      if (s[0][i-1] == s[1][i-1])
        ans = ans * 2 % mod;
      else
        ans = ans * 3 % mod;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
a = int(input())
list2 = list(map(int,input().split()))
list1 = list(range(1,a+1,1))
b = 0
for i in range(a):
    if list1[i] == list2[i]:
        continue
    else:
        if b == 0:
            for j in range(i+1,a):
                if list1[i] == list2[j]:
                    list2[j] = list2[i]
                    list2[i] = list1[i]
                    b += 1
        else:
            print("NO")
            break
else:
    print("YES")

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

using namespace std;

vector<int> neighbor[100'000];
bool isVisited[100'000];
int color[100'000];

bool dfs(int node, int col)
{
    isVisited[node] = true;
    color[node] = col;

    bool result = true;

    for (const int c : neighbor[node]) {
        if (isVisited[c]) {
            result = result && color[node] != color[c];
        } else {
            result = result && dfs(c, 1 - col);
        }
    }

    return result;
}

int main()
{
    int64_t n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        neighbor[a].push_back(b);
        neighbor[b].push_back(a);
    }

    fill(isVisited, isVisited + n, false);
    if (dfs(0, 0)) {
        int64_t cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += color[i] == 0 ? 1 : 0;
        }
        int64_t result = cnt * (n - cnt) - m;
        cout << result << endl;
    } else {
        cout << n * (n - 1) / 2 - m << endl;
    }

    return 0;
}

Measured memory_bytes: 6656
_=gets.to_i
s=gets.chomp
if s.index('#.').nil?
  puts 0
  exit 0
end
rc = '#'
b = 0
aw = s.count('.')

map = s.split('').map.with_index(1) do |c, mapi|
  b += 1 if c == '#'
  if rc == '.' && c == '#'
    rc = c
    b-1 + (aw - (mapi - b) )
  else
    rc = c
    nil
  end
end

puts (map.compact << s.count('.') << s.count('#')).min


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

int main() {
	int n, k, l[50];
	cin >> n >> k;
	for (int i = 0;i < n;i++)cin >> l[i];
	sort(l, l + n);
	reverse(l, l + n);
	int sum = 0;
	for (int i = 0;i < k;i++)sum += l[i];
	cout << sum << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
typedef pair<long long , long long> P;
int main() {
	int N, M; cin >> N >> M;
	vector<P>A(N);
	rep(i, N) {
		cin >> A.at(i).first >> A.at(i).second;
	}
	sort(A.begin(), A.end());
	long long ans = 0, num = 0;
	int i = 0;
	while (num < M && i < N) {
		if (M - num <= A.at(i).second) {
			ans += (M - num) * A.at(i).first;
			num = 10000000;
		}
		else {
			ans += (A.at(i).first * A.at(i).second);
			num += A.at(i).second;
		}
		i++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>

int main(void){
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a+b+c >= 22){
        printf("bust\n");
    }else{
        printf("win\n");
    }
  
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define MAX 10000
int main(){

  int n,q,s[MAX],t[MAX],i,j,count=0;

  //in
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    scanf("%d",&s[i]);
  
  //in
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
  
  //Search
  for(i=0;i<q;i++){
    j=0;
    s[n]=t[i];
    while(s[j]!=t[i]){
      j++;
    }
    if(j!=n) count++;
  }
  
  //out
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v((1<<n)+1), ans(1<<n);
    for(int i = 0; i < (1<<n); ++i) scanf("%d", &v[i]);
    vector<pair<int, int>> u(1<<n);
    auto f = [&](int a, int b){ return v[a] > v[b]; };
    for (int i = 0; i < (1<<n); ++i) {
        u[i] = make_pair(i, (1<<n));
        vector<int> x{u[i].first, u[i].second};
        for (int j = 0; j < n; ++j) {
            if(i&(1<<j)){
                int k = (i^(1<<j));
                x.emplace_back(u[k].first);
                x.emplace_back(u[k].second);
            }
        }
        sort(x.begin(), x.end(), f);
        x.erase(unique(x.begin(), x.end()), x.end());
        u[i] = make_pair(x[0], x[1]);
        ans[i] = v[u[i].first] + v[u[i].second];
    }
    for (int i = 1; i < (1 << n); ++i) {
        ans[i] = max(ans[i], ans[i-1]);
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 7168
import sys, collections
def input():
	return sys.stdin.readline()[:-1]

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

def calc(s):#s: 開催しないスポーツ番号のset
	c = collections.Counter()
	for i in range(n):
		for j in range(m):
			if a[i][j] not in s:
				c[a[i][j]] += 1
				break
	tmp = [-1, -1]
	for k, v in c.items():
		if v > tmp[1]:
			tmp = [k, v]
	del c
	return tmp

ans, boycott = n, set()

for _ in range(m-1):
	res = calc(boycott)
	ans = min(ans, res[1])
	boycott.add(res[0])

print(ans)

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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=5000000;
char a[N];
int main()
{
    string s;
    scanf("%s",a);
    s=a;
    int sum=0;
    for(int i=0;i<s.size();i++){
        sum+=(s[i]-'0');
    }
    if(sum%9){
        printf("No");
    }
    else{
        printf("Yes");
    }

}


Measured memory_bytes: 3908
#include <stdio.h>
#include <string.h>
int main(){
  int stk[100];
  char buf[100];
  int i;
  for(i = 0; scanf("%s", buf) != EOF; i++){
    if(i < 100 & buf[0] >= '0' & buf[0] <= '9'){
      stk[i] = atoi(buf);
    }
    else{
      i--;
      switch(buf[0]){
        case '+':
	  stk[i - 1] += stk[i];
	  break;
        case '-':
	  stk[i - 1] -= stk[i];
	  break;
        case '*':
	  stk[i - 1] *= stk[i];
	  break;
        default:
	  break;
      }
      i--;
    }
  }
  printf("%d\n", stk[0]);
  return 0;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,mod=1e9+7;
int n,m;
long long dp[N];
bool vis[N];
int main()
{
    dp[0]=1;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x;
        scanf("%d",&x);
        vis[x]=true;
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i-1]) dp[i]+=dp[i-1];
        if(!vis[i-2]&&i-2>=0) dp[i]+=dp[i-2];
        dp[i]%=mod;
    }
    printf("%lld\n",dp[n]);
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> A(N+1); rep(i, N+1) cin >> A[i];
  vector<ll> B(N); rep(i, N) cin >> B[i];
  ll ans = 0;
  rep(i, N) {
    ll x = min(A[i], B[i]);
    B[i] -= x;
    ll y = min(A[i+1], B[i]);
    A[i+1] -= y;
    ans += x + y;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
list=[]
for j in range(3):
   D=0
   for i in range(n):
      if x[i]<y[i]:
         d = (y[i]-x[i])
      else:
         d = (x[i]-y[i])
      list.append(d)
      D += (d**(j+1))
   print(f"{D**(1/(j+1)):.6f}") 
print(f"{max(list):.6f}")



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

int main() {
	int N;
	static long long A[100000];
	set<long long> S;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] = A[i] * 1000000 + 500000 - i;
	}
	S.insert(-1);
	for (int i = 0; i < N; i++) {
		if (*S.begin() >= A[i]) S.insert(A[i]);
		else {
			auto it = S.lower_bound(A[i]);
			it--;
			S.erase(*it);
			S.insert(A[i]);
		}
	}
	cout << S.size() << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

std::string n;
int f[1010][10];
int dig[1010];
int k, len;

int dfs(int dep, bool isLimit, int status)
{
    if (status > k) return 0;
    if (!dep)   return status == k;
    if (!isLimit && ~f[dep][status])   return f[dep][status];
    int ans = 0, bit = isLimit ? dig[dep] : 9;
    for (int i = 0; i <= bit; ++i)
    {
        if (i) ans += dfs(dep - 1, isLimit && i == bit, status + 1);
        else    ans += dfs(dep - 1, isLimit && i == bit, status);
    }
    if (!isLimit)   f[dep][status] = ans;
    return ans;
}

int main()
{
    memset(f, -1, sizeof(f));
    std::cin >> n;
    read(k);
    len = n.size();
    for (int i = 0; i < len; ++i)   dig[len - i] = n[i] - 48;
    printf("%d\n", dfs(len, true, 0));
    return 0;
}

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

int strnum(char* s1, char* s2) {
  int i = 0;
  while (1) {
    if (*(s1+i) == *(s2+i)) {
      i++;
    } else {
      break;
    }
  }
  return i;
}

int main() {
  char* buff = (char*)malloc(sizeof(char) * 100001);
  scanf("%s", buff);
  while (strcmp(buff, "\0") != 0 && strcmp(buff, "\n") != 0) {
    char* sd = "dreameraseX";
    int num = strnum(buff, sd);
    if (num == 5 || num == 10) {
      buff += 5;
      continue;
    } else if (num == 7) {
      buff += 7;
      continue;
    }
    char* se = "eraseraseX";
    num = strnum(buff, se);
    if (num == 5 || num == 9) {
      buff += 5;
      continue;
    } else if (num == 6) {
      buff += 6;
      continue;
    }
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Control.Monad.Trans.Except
import Data.Either

main :: IO ()
main = do
  [n] <- readInts
  putStrLn $ solve n

solve n = if isLeft $ runExcept $ foldM (\a x -> when (x == n) $ throwE ()) () [x * y | x <- [1 .. 9], y <- [1 .. 9]]
  then "Yes"
  else "No"

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 380
#include<stdio.h>
#include<string.h>
#define N 10

int main()
{
    char weather[N];
    scanf("%s", weather);
    if(strcmp(weather,"Sunny")==0){
        printf("Cloudy\n");
    }
    else if (strcmp(weather, "Cloudy") == 0){
        printf("Rainy\n");
    }
    else if (strcmp(weather, "Rainy") == 0){
        printf("Sunny\n");
    }

    return 0;
}

Measured memory_bytes: 128
s = input()

ans = 'keyence'
ret = 'NO'
if s[:7] == ans:
    ret = 'YES'
elif s[-7:] == ans:
    ret = 'YES'
else:
    for i in range(7):
        j = 7-i
        if s[:i] == ans[:i] and s[-j:] == ans[-j:]:
            ret = 'YES'
print(ret)


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

typedef vector<vector<int> > Graph;

const int MAXN = 100;

void rec(int v, int &k, int &time,
         vector<int> &node, vector<int> &num, Graph &g) {
  node[time] = v;
  for(int r; num[v] && cin >> r && r; --num[v]) {
    int to = -1;
    if(r > 0) {
      to = k++;
      num[to] = r - 1;
      ++time;
      rec(to, k, time, node, num, g);
      --time;
    } else {
      to = node[r + time];
      num[to] -= 1;
    }
    g[v].push_back(to);
    g[to].push_back(v);
  }
}

int main() {
  for(int tc = (cin >> tc, tc); tc--; ) {
    int time = 0;
    Graph g(MAXN);
    int k = 1;
    vector<int> num(MAXN), node(MAXN, -1);
    int r = (cin >> r, r);
    num[0] = r;
    rec(0, k, time, node, num, g);
    assert(cin >> r && r == 0);
    for(int i = 0; i < k; ++i) {
      cout << i+1;
      sort(g[i].begin(), g[i].end());
      for(int j = 0; j < g[i].size(); ++j) {
        cout << " " << g[i][j]+1;
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

uint64_t from_zero(uint64_t data)
{
	if (data == 1)
		return 1;

	if (data % 2 == 0)
		return ((data / 2) % 2) ^ data;
	else
		return (((data + 1) / 2) % 2);
}

int main()
{
	uint64_t A, B;
	cin >> A >> B;
	
	uint64_t result = from_zero(A - 1) ^ from_zero(B);

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


Measured memory_bytes: 256
f=lambda:input().split()
n,m=map(int,f())
n+=1
a,w=[0]*n,[0]*n
for _ in range(m):
  p,s=f()
  p=int(p)
  if s=='AC': a[p]=1
  elif a[p]<1: w[p]+=1
print(sum(a),sum(i*j for i,j in zip(a,w)))

Measured memory_bytes: 10436
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());

		boolean flag = false;

		for(int i = 1; i < 10; i++) {

			if(n % i == 0) {

				double temp = n / i;

				for(int j = 1; j < 10; j++) {

					if(temp / j == 1) {

						flag = true;
						break;

					}
				}
			}
		}


		if(flag) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pairll=pair<ll,ll>;
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll npr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

bool IsPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int n; cin>>n;
	int doing[3][n];
	for(int i=0; i<n; i++) cin>>doing[0][i]>>doing[1][i]>>doing[2][i];
	ll happy[3][n+1];
	for(int i=0; i<3; i++) {
		for(ll &hpy: happy[i]) hpy=0LL;
	}

	for(int i=0; i<n; i++) {
		for(int j=0; j<3; j++) {
			for(int k=0; k<3;k++) {
				if(j==k) continue;
				happy[j][i+1] = max(happy[j][i+1],happy[k][i]+doing[j][i]);
			}
		}
	}


	ll result=0LL;
	for(int i=0;i<3;i++) result = max(result,happy[i][n]);
	cout << result << endl;
}

Measured memory_bytes: 3712