akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer n;
  n=nil->next;
  while(n!=nil && n->key!=key){
    n = n->next;
  }
  return n;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
 t->prev->next = t->next;
 t->next->prev = t->prev;
 free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer n=nil->prev;
  if(n==nil) return;
  deleteNode(n);
}

void delete(int key){
  NodePointer x;
  x = listSearch(key);
  if( x == nil ) return;
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next=x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  printList();
  return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;

    string u;
    cin >> u;
    if (u == s) a--;
    if (u == t) b--;

    printf("%d %d\n", a, b);

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int main()
{
	char c;cin>>c;
	cout << char(c+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 const long long mod=1e9+7;

 int main(){
 int N,M;
 cin>>N>>M;
 vector<int>oks(N+1,true);
 for(int i=0;i<M;++i){
 int a;cin>>a;
 oks[a]=false;
 }

 vector<long long int>dp(N+1);
 dp[0]=1;
 for(int now=0;now<N;++now){
 for(int next=now+1;next<=min(N,now+2);++next){
 if(oks[next]){
 dp[next]+=dp[now];
 dp[next]%=mod;
 }
 }
 }

 cout<<dp[N]<<endl;
 return 0;
 }

Measured memory_bytes: 4564
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;
int n;
lint D;
lint ar[200005];
lint br[200005],cr[200005];
bool mark1[200005],mark2[200005];

bool done[200005];
lint pfxbr[200005],sfxcr[200005];
int main(){
  cin>>n>>D;
  REP(i,n){
    cin>>ar[i];
    br[i]=ar[i]-i*D;
    cr[i]=ar[i]+i*D;
  }

  pfxbr[0]=INF;
  REP(i,n){
    if(br[i]<pfxbr[i]){
      mark1[i]=1;
      pfxbr[i+1]=br[i];
    }else{
      pfxbr[i+1]=pfxbr[i];
    }
  }

  sfxcr[n]=INF;
  for(int i=n-1;i>=0;--i){
    if(cr[i]<sfxcr[i+1]){
      mark2[i]=1;
      sfxcr[i]=cr[i];
    }else{
      sfxcr[i]=sfxcr[i+1];
    }
  }
  int prev=-1;
  lint res=0;
  REP(i,n){
    if(mark1[i] && mark2[i]){
      if(~prev){
        res+=D*(i-prev)+ar[i]+ar[prev];
      }
      prev=i;
    }else{
      lint tmp1=pfxbr[i]+ar[i]+i*D;
      lint tmp2=sfxcr[i]+ar[i]-i*D;
      res+=min(tmp1,tmp2);
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 8704
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(void){
    ll n,k,q,a[100010]={0};
    cin>>n>>k>>q;
    ll b;
    for(int i=0;i<q;i++){
        cin>>b;
        a[b]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]+k-q>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 1408
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const alphabets = 'abcdefghijklmnopqrstuvwxyz'.split('');
let num = [];
let tmp = input.toLowerCase();
let str = tmp.split('')
for (let i = 0; i < alphabets.length; i++) {
    let cnt = 0;
    for (let j = 0; j < str.length; j++) {
        if (str[j] === alphabets[i]) {
            cnt++;
        }
    }
    num.push(cnt);
}

for  (i = 0; i < alphabets.length; i++) {
  console.log(alphabets[i] + " : " + num[i]);
}




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

int main(){
  int N,T;
  cin >> N >> T; 
  vector<int> c(N),t(N);
  
  for(int i = 0; i < N; i++){
    cin >> c.at(i) >> t.at(i);
  }
  
  int minc = 10000;
  
  for(int i = 0; i < N; i++){
    if(t.at(i) <= T && c.at(i) < minc){ 
      minc = c.at(i);
    }
  }
  
  if(minc == 10000){
    cout << "TLE";
  }
  else{
    cout << minc;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

const int N = 200500;

int R[N], C[N], A[N];

void die() {
    puts("No");
    exit(0);
}

vector<pair<int, int>> E[N];

typedef long long llong;

struct linear {
    int k;
    llong b;
    linear(int _k, int _b) {
        k = _k, b = _b;
    }
    linear(){}
    friend linear operator +(linear a, linear b) {
        return linear(a.k + b.k, a.b + b.b);
    }
    friend linear operator -(linear a, linear b) {
        return linear(a.k - b.k, a.b - b.b);
    }
};

bool used[N];

vector<int> comp;

linear L[N];

void DFS(int x) {
    used[x] = true;
    comp.push_back(x);
    for (auto pr : E[x]) {
        int s = pr.first;
        int y = pr.second;
        linear there(-L[x].k, s - L[x].b);
        if (used[y]) {
            if (there.k != L[y].k || there.b != L[y].b) {
                die();
            }
        } else {
            L[y] = there;
            DFS(y);
        }
    }
}

llong linf = (llong)1e18;

llong val[N];

int main() {
    int r, c;
    scanf("%d %d", &r, &c);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &R[i], &C[i], &A[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        /*R[i] = (R[i] - R[0] + r) % r;
        C[i] = (C[i] - C[0] + c) % c;*/
        E[C[i]].push_back(make_pair(A[i], c + R[i]));
        E[c + R[i]].push_back(make_pair(A[i], C[i]));
        /* else if (R[i] == 0 && C[i] == 0) {
            continue;
        } else if (R[i] == 0) {
            int v = C[i];
            L[v] = linear(0, A[i]);
        } else if (C[i] == 0) {
            int v = R[i] + c;
            L[v] = linear(0, A[i]);
        }*/
    }
    for (int j = 0; j < r + c; j++) {
        if (used[j]) {
            continue;
        }
        comp.clear();
        L[j] = linear(1, 0);
        DFS(j);
        /*if (L[j].k == 0) {
            for (int v : comp) {
                if (L[v].b < 0)
                    die();
            }
            for (int v : comp)
                val[v] = L[v].b;
        } else*/ {
            llong mn1 = linf, mn2 = linf;
            for (int v : comp) {
                if (L[v].k == 1) {
                    mn1 = min(mn1, L[v].b);
                } else {
                    mn2 = min(mn2, L[v].b);
                }
            }
            if (mn1 + mn2 < 0)
                die();
        }
    }
    puts("Yes");
}


Measured memory_bytes: 17784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class ALDS1_1C
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int primeCount = 0;
            for (int i = 0; i < n; i++)
            {
                if(IsPrime(int.Parse(Console.ReadLine())))
                {
                    primeCount++;
                }
            }

            Console.WriteLine(primeCount);

            Console.ReadLine();
        }

        static bool IsPrime(int _n)
        {
            int sqrt = (int)Math.Sqrt(_n);
            for(int i=2;i<=sqrt;i++)
            {
                if(_n%i==0)
                {
                    return false;
                }
            }
            return true;
        }
    }
}

Measured memory_bytes: 9072
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define sz(v) (int)(v).size()
#define vec(x) vector < x >
using vi = vector < int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';

int main() {
// #ifndef ONLINE_JUDGE
// 	if (fopen("input.txt", "r")) {
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code

	int n;
	cin >> n;
	int64 s = 0;
	map < int, int > mp;
	for0(i, n) {
		int x;
		cin >> x;
		mp[x]++;
		s += (int64)x;
	}
	int q;
	cin >> q;
	for0(i, q) {
		int x, y;
		cin >> x >> y;
		int k = mp[x];
		mp[x] = 0;
		mp[y] += k;
		int64 tmp = (int64)(y - x) * k;
		s += tmp;
		cout << s << nwl;
	}

	return 0;
}

Measured memory_bytes: 8024
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int64 ans=a[0]-1;
  int now=1;
  for(i=1;i<n;i++){
    if(a[i]==now+1){
      now++;
    } else {
      ans+=(a[i]-1)/(now+1);
    }
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < k; i++) {
        ans += p[i];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
using namespace std;
int main()
{
	int n,count=0;
	long long x,y,d,m;	
	cin>>n>>d;
	m=d*d;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		long long temp;		
		temp=x*x+y*y;
		if(temp<=m)
		{
			count++;
		}			
	}
	cout<<count<<endl;
	return 0;	
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int n = sc.nextInt();
		int[][] c = new int[H][W];
		int[] a = new int[n];
		int now = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(a[now] == 0) now++;
				c[i][i%2 == 0 ? j : W-j-1] = now+1;
				a[now]--;
			}

		}
		for(int i = 0 ;i < H; i++) {
			for(int j = 0; j < W; j++) {
				System.out.print(c[i][j]+" ");
			}
			System.out.println("");
		}
		sc.close();
	}
}

Measured memory_bytes: 31940
#include<iostream>
using namespace std;
int a[105];
int main() {
	int n,sum=0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i=1;i<n;i++)
		for (int j = i + 1; j <= n; j++) {
			sum += a[i] * a[j];
		}
	cout << sum;
	return 0;
}

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

bool test(vector<int64_t> &K, int64_t a, int n){
    for(int i=n;i>0;i--){
        K[i-1]-=K[i]*a;
    }
    if(!K[0]){
        for(int i=0;i<n;i++){
            K[i]=K[i+1];
        }
        K.pop_back();
        return true;
    }
    return false;
}

int main(){
    int n;
    cin.ignore();//x
    cin.ignore();//^
    cin>>n;
    vector<int64_t> k(n+1,0);
    k[n]=1;
    string S;
    cin>>S;
    int i=0;
    while(true){
        int d=0;
        int f = (S[i]=='+'?1:-1);
        for(i++;S[i]!='x'&&i<S.size();i++){
            d*=10;
            d+=S[i]-'0';
        }
        if(!d)d=1;
        d*=f;
        if(i==S.size()){
            k[0]=d;
            break;
        }else{
            i++;
            if(i<S.size()&&S[i]=='^'){
                k[S[i+1]-'0']=d;
                i+=2;
            }else{
                k[1]=d;
            }
        }
    }
    // for(auto d:k)cout<<d<<endl;
    vector<int> ans;
    for(int i=n;i>0;i--){
        for(int a=-(k[0]>0?k[0]:-k[0]);a<=(k[0]>0?k[0]:-k[0]);a++){
            if(!a||k[0]%a) continue;
            vector<int64_t> K=k;
            if(test(K,a,i)){
                k=K;
                ans.push_back(a);
                break;
            }
        }
    }
    sort(ans.begin(), ans.end());
    for(auto d:ans){
        cout<<(d>0?"(x+":"(x")<<d<<')';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k; --k;
    vector<int> x(n);
    REP(i,n) cin >> x[i];
    int ans = INT_MAX;
    FOR(i,k,n) {
        int tmp = abs(x[i]-x[i-k]) + min(abs(x[i]),abs(x[i-k]));
        chmin(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<string> s(n);
   f(i,0,n){
      cin >> s[i];
      sort(all(s[i]));
   }
   sort(all(s));
   int c = 1;
   int ans = 0;
   f(i,1,n){
      if(s[i] == s[i-1]){
         c++;
      }else{
         // c = 1;
         ans += ((c*(c-1))/2);
         c = 1;
      }
      if(i==n-1){
         ans += ((c*(c-1))/2);
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 5760
# 想定解法
import itertools

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

indices = [2, 0, 1]
count_color = [[0] * C for i in range(3)]
for i in range(N):
  idx = indices[i%3]
  for j in range(N):
    count_color[idx][c[i][j]-1] += 1
    idx = (idx + 1) % 3

# 色の対応関係をC_P_3通り全て試す
ans = float('inf')
correspondence = list(itertools.permutations(range(C), 3))
# (i+j)%3のマス目をcorr[(i+j)%3]に書き換える
for corr in correspondence:
  cost = 0
  for idx in range(3): # idx : (i+j)%3
    for color in range(C):
      cost += count_color[idx][color] * D[color][corr[idx]]
  ans = min(ans, cost)

print(ans)

Measured memory_bytes: 7540
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll x,y,a,b,fact[2000010];
ll power(ll a,ll b=mod-2)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(ll n)
{
	fact[0]=1;
	for(ll i=1;i<=n;++i)
		fact[i]=fact[i-1]*i%mod;
}
ll C(ll n,ll m)
{
	return fact[n]*power(fact[m])%mod*power(fact[n-m])%mod;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>x>>y;
	b=(2*y-x)/3;
	a=(2*x-y)/3;
	init(a+b);
	if(2*a+b!=x||2*b+a!=y||a<0||b<0)
		cout<<0<<endl;
	else cout<<C(a+b,a)<<endl;
	return 0;
}

Measured memory_bytes: 6400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int maxi = 100005;

vector<int> dp(maxi);

int main()
{
	FASTIO;
	int n,k;
	cin >> n >> k;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
		cin >> arr[i];
	
	for(int i=0;i<arr[0];i++)
		dp[i] = -1;

	for(int L=1;L<=k;L++){
		for(int R=0;R<n;R++){
			if(dp[L]==-1)	break;
			
			if(arr[R]<=L){
				if((L-arr[R]>=0 && dp[L-arr[R]]==-1) || (L-arr[R]>=0 && dp[L-arr[R]]==2)){
					dp[L]=1;
					break;
				}
			}
		}
		if(dp[L]==-1 || dp[L])
			continue;
		else
			dp[L] = (dp[arr[0]]==1)?2:1;
		
	}
	//for(int i=0;i<=k;i++)
		//cout << dp[i] << " ";
	//cout << "\n";
	if(dp[k]==2)
		printf("Second\n");
	else
		printf("First\n");
	return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input1 = br.readLine().split(" ");
        int n = Integer.parseInt(input1[0]);
        int d = Integer.parseInt(input1[1]);
        
        Integer[][] numbers = new Integer[n][2];
        int ans = 0;
        
        for(int i = 0; i < n; i++){
            String[] input2 = br.readLine().split(" ");
            numbers[i][0] = Integer.parseInt(input2[0]);
            numbers[i][1] = Integer.parseInt(input2[1]);
            if(Math.sqrt(Math.pow(numbers[i][0], 2) + Math.pow(numbers[i][1], 2)) <= d){
                ans++;
            }
        }
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 67824
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        string inpt = Reader.ReadLine();
        int num = int.Parse(inpt);
        int div = inpt.Select(a => int.Parse(a.ToString())).Sum();

        string ans = "No";
        if(num%div==0) {
            ans = "Yes";
        }
        Console.WriteLine(ans);

    }



    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"





12


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    int num = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if(a % 2 == 0) {
            num++;
        }
    }
    cout << pow(3, n) - pow(2, num) << endl;
    return 0;
}


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

int main(int argc, char *argv[])
{
	int a, b;
	cin >> a >> b;

	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	} else {
		cout << ":(" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int i,n,sum=0;
	cin>>n;
	int a[n];
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum%10!=0){
		cout<<sum<<endl;
		return 0;
	}
	sort(a,a+n);
	for(i=0;i<n;i++){
		if(a[i]%10!=0){
			sum-=a[i];
			break;
		}
	}
	if(sum%10!=0)cout<<sum<<endl;
	else cout<<0<<endl;
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
n, d = map(int, input().split())
ls = []
for i in range(n):
    s = list(map(int, input().split()))
    #print(s)
    ls.append(s)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += abs(ls[i][k] - ls[j][k])**2
        dist = dist ** (1/2)

        if(dist.is_integer()):
            ans += 1
print(ans)

Measured memory_bytes: 3188
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

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

  static int[][] ofs = {
      {1, 0},
      {0, 1}
  };

  void run() {
    for (; ; ) {
      int w = ni();
      int h = ni();
      if (w == 0) {
        break;
      }
      BigInteger[][] dp = new BigInteger[h][w];
      char[][] field = new char[h][w];
      for (int i = 0; i < h; ++i) {
        String str = sc.next();
        for (int j = 0; j < w; ++j) {
          field[i][j] = str.charAt(j);
          dp[i][j] = BigInteger.ZERO;
        }
      }
      BigInteger ans = BigInteger.ZERO;
      for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
          if ('0' <= field[y][x] && field[y][x] <= '9') {
            dp[y][x] = dp[y][x].multiply(BigInteger.TEN).add(BigInteger.valueOf(field[y][x] - '0'));

            if (dp[y][x].compareTo(ans) > 0) {
              ans = dp[y][x];
            }
            for (int i = 0; i < 2; ++i) {
              int nx = ofs[i][0] + x;
              int ny = ofs[i][1] + y;
              if (nx >= w || ny >= h) {
                continue;
              }
              if (dp[ny][nx].compareTo(dp[y][x]) < 0) {
                dp[ny][nx] = dp[y][x];
              }
            }
          }
        }
      }
      System.out.println(ans.toString());
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

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

using namespace std;
using ll = long long;

#ifdef LOCAL 
    #include "_/debug.h"
#else 
    #define out(...) 69;
#endif

ll dp[10][10];

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int x = s.front() - '0';
        int y = s.back() - '0';
        ++dp[x][y];
    }
    ll ans = 0;
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            ans += 1LL * dp[i][j] * dp[j][i];
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n,a[310000],ans;
signed main(){
  cin>>n;rep(i,3*n)cin>>a[i];
  sort(a,a+3*n,greater<int>());
  rep(i,n){
    ans += a[i*2+1];
  }
  cout <<ans << endl;
}


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

int main() {
    int n;
    cin >> n;
    //vector<string> s(n);
    string s;
    int c0=0;
    int c1=0;
    int c2=0;
    int c3=0;

    for(int i=0; i<n; i++){
        //cin >> s[i];
        cin >> s;
        //cout << s << endl;
        if(s == "AC") c0++;
        else if(s == "WA") c1++;
        else if(s == "TLE") c2++;
        else c3++;
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;

}

Measured memory_bytes: 3628
n = int(input())
num_list =list(map(int, input().split()))
res = 1
INF = int(1e18)
num_list.sort()
if num_list[0] == 0:
    print(0)
    exit()
for i in range(n):
    res *= num_list[i]
    if res > INF:
        print(-1)
        exit()
print(res)


Measured memory_bytes: 21604
L=input()

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

d0 = Mint(1)
d1 = Mint()
for b in L:
    if b == '0':
        d1 *= (1 + 2)
        #d0 *= (1 + 0)
    else:
        d1 = d1 * (1 + 2) + d0
        d0 *= (0 + 2)

print(d0+d1)

Measured memory_bytes: 43496
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var n string
	fmt.Scan(&n)
	var words []string
	var sc = bufio.NewScanner(os.Stdin)

	for sc.Scan() {
		if sc.Text() == "END_OF_TEXT" {
			break
		}
		words = append(words, strings.Split(strings.ToLower(sc.Text()), " ")...)
	}

	var result int
	for _, v := range words {
		if v == n {
			result++
		}
	}
	fmt.Println(result)
}



Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
const ll MOD = 1e9+7;
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    int cnt=0;
    rep(i,n){
        int a; cin >> a;
        if(i%2==0&&a%2==1) cnt++;
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node root;
Node treeSearch(Node, int);
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int r, i, x;
  char com[20];
  scanf("%d", &r);
 
  for ( i = 0; i < r; i++ ){
    scanf("%s", com);
    if (com[0] == 'f'){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if (t != NULL) printf("yes\n");
      else printf("no\n");
    } else if (com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    } else if (com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}

Node treeSearch(Node x, int k){
  while(x!=NULL&&k!=x->key){
    if(k<x->key)
      x=x->left;
    else
      x=x->right;
  }
    return x;
}
void insert(int k){
  Node y = NULL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;
 
  while(x!=NULL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
 
  z->parent=y;
 
  if(y==NULL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else
    y->right=z;
}
 
 
void inorder(Node x){
  if(x!=NULL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
 
void preorder(Node x){
  if(x!=NULL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
   
}


Measured memory_bytes: 20468
#include <stdio.h>
int F[45];
int fibonacci(int n){
  if(n==0||n==1) return F[n]=1;
  if(F[n]!=-1) return F[n];
  return F[n]=fibonacci(n-1)+fibonacci(n-2);
}
int main(){
  int i,n;
  for(i=0;i<45;i++){
    F[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}

Measured memory_bytes: 596
n = int(input())
a = list(map(int, input().split()))

# リストの中身を降順ソートする
# 元のリストを保持したいならsorted()
a.sort(reverse = True)

alice, bob = 0, 0

for i in range(0, len(a)):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice - bob)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int d,sum=0,x=0;
  while(~scanf("%d",&d)){
    while(x<600){
      sum+=((x*x)*d);
      x+=d;
    }
    printf("%d\n",sum);
    x=sum=0;
  }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
using namespace std;

int N, Ma, Mb, ming = 10000;
vector<int> A(40);
vector<int> B(40);
vector<int> C(40);

void f(int g, int a, int b, int n) {
    if(g >= ming) {
        return;
    }
    if(n == N) {
        if(Mb * (a + A[N - 1]) == Ma * (b + B[N - 1]) && g + C[N - 1] < ming) {
                ming = g + C[N - 1];
                return;
        }
        return;
    }
    else if(Mb * (a + A[n - 1]) == Ma * (b + B[n - 1]) && g + C[n - 1] < ming) {
            ming = g + C[n - 1];
    }
        f(g, a, b, n + 1);
        f(g + C[n - 1], a + A[n - 1], b + B[n - 1], n + 1);
    
}

int main() {
    cin >> N >> Ma >> Mb;
    REP(i, N) {
        cin >> A[i] >> B[i] >> C[i];
    }
    f(0, 0, 0, 1);
    if(ming == 10000) cout << -1 << endl;
    else cout << ming << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
using namespace std;

const double pi=4*atan(1.0);

using cEdges=std::vector<std::vector<int>>;

void sort_by_dfs_helper(int root,const cEdges& Edges,vector<bool>& IsVisit,vector<int>& Ans,int& index){
	IsVisit[root]=true;

	for(const auto& val:Edges[root]){
		if(!IsVisit[val]){
			sort_by_dfs_helper(val,Edges,IsVisit,Ans,index);
		}
	}

	Ans[index]=root;
	if(index>0)--index;
}
vector<int> sort_by_dfs(const cEdges& Edges){
	if(Edges.empty())return vector<int>();

	vector<bool> IsVisit(Edges.size(),false);
	vector<int> Ans(Edges.size(),-1);
	int index=Ans.size()-1;
	for(int i=0;i<IsVisit.size();++i){
		if(!IsVisit[i]){
			sort_by_dfs_helper(i,Edges,IsVisit,Ans,index);
		}
	}

	return Ans;
}

int main() {
	int N,M;
	cin>>N>>M;
	cEdges Edges(N);
	for(int i=0;i<M;++i){
		int u,v;
		cin>>u>>v;
		Edges[u].push_back(v);
	}

	auto ans=sort_by_dfs(Edges);

	for(const auto& val:ans){
		cout<<val<<"\n";
	}
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> d(n);
    for(int i = 0; i < n; i++)
    {
        cin >> d[i];
    }

    ll ans = 10000000000;
    for(int i = 0; i < n-k+1; i++)
    {
        ll a1 = abs(d[i]-0) + abs(d[i]-d[i+k-1]);
        ll a2 = abs(d[i+k-1]-0) + abs(d[i]-d[i+k-1]);
        ans = min(ans, min(a1, a2));
    }
    cout << ans << endl;
}




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

int main() {
  while(true) {
    int Z; cin >> Z;
    if(Z == 0) break;
    int k = 0;
    for(int x = 1; x <= Z; ++x) {
      for(int y = 1; y <= Z; ++y) {
        if(x*x*x + y*y*y <= Z*Z*Z) {
          k = max(k, x*x*x + y*y*y);
        }
      }
    }
    cout << Z*Z*Z-k << endl;;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>

using namespace std;

int** gmtrx;
int* d, *f;
int t, n;

class Stack{
public:
	Stack(int num):head(0){
		s = new int [num];
		for(int i=0; i<num; ++i){
			s[i] = 0;
		}
	}
	~Stack(){ delete[] s; }
	void push_back(int vtx){
		s[head++] = vtx;
	}
	int pop_back(){
		--head;
		int tmp = s[head];
		s[head] = 0;
		return tmp;
	}
	int back(){
		if(head<=0) return -1;
		return s[head-1];
	}
private:
	int head;
	int* s;
};


int main()
{
	scanf("%d",&n);

	gmtrx = new int*[n];
	d = new int [n]; //discovery
	f = new int [n]; //finish
	Stack st(n);

	for(int i=0; i<n; ++i){
		gmtrx[i] = new int[n];
		for(int j=0; j<n; ++j){
			gmtrx[i][j] = 0;
		}
		d[i] = 0;
		f[i] = 0;
	}

	for(int i=0; i<n; ++i){
		int v, num, a;
		scanf("%d %d",&v,&num);
		--v;
		for(int j=0; j<num; ++j){
			scanf("%d",&a);
			--a;
			gmtrx[v][a] = 1;
		}
	}

	for(int i=0; i<n; ++i){
		int vtmp=i;
		if( d[vtmp]!= 0) continue;
		st.push_back(vtmp);
		vtmp=0;
		while(st.back()!=-1){
			if(d[st.back()]==0){
				++t;
				d[st.back()] = t;
			}
			else if(f[st.back()]!=0){
				vtmp = st.pop_back();
				++vtmp;
				continue;
			}
			for(int j=vtmp; j<=n; ++j){
				if(j==n){
					++t;
					f[st.back()] = t;
					vtmp = st.pop_back();
					++vtmp;
					break;
				}
				if(gmtrx[st.back()][j]){
					if(d[j]==0) st.push_back(j);
					else continue;
					break;
				}
			}
		}
	}

	for(int i=0; i<n; ++i){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}

	for(int i=0; i<n; ++i){
		delete[] gmtrx[i];
	}
	delete[] gmtrx;
	delete[] d;
	delete[] f;

	return 0;
}



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

const vector<vector<int>> D = {
    {4, 0, 2, 3, 5, 1}, // N
    {2, 1, 5, 0, 4, 3}, // E
    {1, 5, 2, 3, 0, 4}, // S
    {3, 1, 0, 5, 4, 2}  // W
};

struct Dice {
  vector<int> face;

  Dice(vector<int> v) : face(v) {
  }

  void roll(char direction) {
    int dir;
    if (direction == 'N')
      dir = 0;
    if (direction == 'E')
      dir = 1;
    if (direction == 'S')
      dir = 2;
    if (direction == 'W')
      dir = 3;

    vector<int> tmp(6);
    rep(i, tmp.size()) tmp[D[dir][i]] = face[i];
    face = tmp;
  }

  bool compare(Dice& d2) {
    bool res = true;
    rep(i, 6) if (face[i] != d2.face[i]) res = false;
    return res;
  }

  int top() {
    return face.front();
  }
  int bottom() {
    return face.back();
  }
};

int main() {
  vector<int> v1(6), v2(6);
  rep(i, 6) cin >> v1[i];
  rep(i, 6) cin >> v2[i];
  Dice d1(v1), d2(v2);

  bool identical = false;

  string direction1 = "NNNNENNNN";
  string direction2 = "EEEE";
  for (auto dir1 : direction1) {
    d2.roll(dir1);
    for (auto dir2 : direction2) {
      d2.roll(dir2);
      if (d1.compare(d2)) {
        identical = true;
        break;
      }
    }
    if (identical)
      break;
  }

  if (identical)
    puts("Yes");
  else
    puts("No");
}


Measured memory_bytes: 3212
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    return sorted(divisors)

N = int(input())

ans = len(divisors(N-1)) -1

for k in divisors(N)[1:]:
    N_ = N
    while N_ % k == 0:
        N_ = N_//k
    if N_ % k == 1:
        ans += 1

print(ans)



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

using namespace std;

int main()
{
	const int MAX_N = 50;
	const int MAX_V = 1001;

	const float USED = -100.0f;

	int n;
	cin >> n;

	float v[MAX_N];
	for (int i = 0; i < n; i++)
		cin >> v[i];

	float answer = 0;

	// 合成をn-1回行う
	for (int h = 0; h < n - 1; h++)
	{
		// ----- 合成に使うものを選ぶ -----
		int useID[] = { -1, -1 };
		// 価値の小さいものから使っていく
		int minVal = MAX_V;
		int secondMinVal = MAX_V;
		for (int i = 0; i < n; i++)
		{
			if (v[i] == USED)
				continue;

			// 暫定最小価値以下だった時
			if (v[i] < minVal)
			{
				secondMinVal = minVal;
				minVal = v[i];
				useID[1] = useID[0];
				useID[0] = i;
			}
			// 暫定最小以下ではないが2番目よりは小さかった時
			else if (v[i] < secondMinVal)
			{
				secondMinVal = v[i];
				useID[1] = i;
			}
		}

		// ----- 実際に合成をする -----
		// useID[0]番目とuseID[1]番目を組み合わせる
		v[useID[0]] = ((v[useID[0]] + v[useID[1]]) / 2);
		v[useID[1]] = USED;

		answer = v[useID[0]];
	}

	cout << answer;

	return 0;
}



Measured memory_bytes: 256
n=int(input())
li=[input() for i in range(n)]
from collections import Counter 
cnt=[None]*n 
ans=''
for i in range(n):
    cnt[i]=Counter(li[i])
for i in range(97,123):
    ch=chr(i)
    mini=10**9
    for j in range(n):
        mini=min(mini,cnt[j][ch])
    ans+=ch*mini 
print(ans)

Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MAX = 1e9+7;

int main(){
    int n, W; cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i, 0, n) cin >> w[i] >> v[i];

    ll sum_v = accumulate(v.begin(), v.end(), 0LL);

    vector<vector<ll>> dp(n+1, vector<ll>(sum_v+1, MAX));
    dp[0][0] = 0;
        
    rep(i, 0, n){
        rep(j, 0, sum_v+1){
            if(j > v[i]) dp[i+1][j] = min(dp[i][j-v[i]] + w[i], dp[i][j]);
            else dp[i+1][j] = min(dp[i][j], w[i]);
        }
    }

    rem(i, sum_v, 0){
        if(dp[n][i] <= W){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long int a[100500]={0};
const long long int N=1e9+5000;
int main()
{
    long long int n;
    cin>>n;
    long long int min1=N;
    long long int sum=0;
    long long int sum1=0;
    int flag=0;
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
        {
            sum++;
            sum=sum%2;
            sum1=sum1-a[i];
        }
        if(a[i]==0)
        {
            flag=1;
        }
        if(a[i]>=0)
        {
            sum1=sum1+a[i];
        }
        min1=min(min1,abs(a[i]));
    }
    if(sum%2==0)
    {
        cout<<sum1<<endl;
        return 0;
    }
    else if(flag==1)
    {
        cout<<sum1<<endl;
        return 0;
    }
    else
    {
        sum1=sum1-2*min1;
        cout<<sum1<<endl;
        return 0;
    }
    return 0;
}


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

#define rep(i, max) for(int i = 0; i < max; i++)

int main() {
	string s, t;
	map<char, char> cor;
	map<char, char>::iterator ic;
	cin >> s >> t;

	rep(i, s.size()) {
		ic = cor.find(s[i]);
		if (ic == cor.end())
			cor.insert({ s[i],t[i] });
		else if ((*ic).second != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cor.clear();
	rep(i, t.size()) {
		ic = cor.find(t[i]);
		if (ic == cor.end())
			cor.insert({ t[i],s[i] });
		else if ((*ic).second != s[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    if (x < (K - x)) {
      sum += (x * 2);
    }
    else {
      sum += ((K - x) * 2);
    }
  }
  cout << sum << endl;
}

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

const int mod = 1000000007;

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

//const int dx[8] = {};
//const int dy[8] = {};

using namespace std;

template <class myType>
void p(vector<myType>& v)
{
    for(myType i: v) cout<<i<<" ";
    cout<<endl;
}

template <class myType>
void pv(vector<vector<myType>>& vv)
{
    for(auto& v: vv)
        p(v);
}

template <class myType>
void GetInputV(vector<myType>& v, int n)
{
    v.resize(n);
    for(myType& i: v) cin>>i;
}

template <class myType>
void GetInputVV(vector<vector<myType>>& vv, int m, int n)
{
    vv.resize(m);
    for(vector<myType>& v: vv) GetInputV(v, n);
}

int main()
{

    int a, b, t;
    cin>>a>>b>>t;

    int res = (t/a)*b;

    cout<<res<<endl;
    

    return 0;
}

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

#define REP(b,n) for(int b = 0; b < (n); ++b)
#define REP1(b,n) for(int b = 1; b <= (n); ++b)
#define RREP(b, n) for(int b = (n) - 1; b >= 0; --b)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n, s;
	cin >> n >> s;
	if(n == s) {
		cout << n+1 << "\n";
		return 0;
	}
	ll rn = sqrt(n);
	for(ll b = 2; b <= rn; ++b){
		if(f(b, n) == s){
			cout << b << "\n";
			return 0;
		}
	}
	for(ll k = rn; k >= 1; --k){
		ll b = (n - s) / k + 1;
		if(f(b, n) == s){
			cout << b << "\n";
			return 0;
		}
	}
	cout << "-1\n";
	return 0;
}


Measured memory_bytes: 256