akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

char B[3][3];

bool isbw(char c) {
	return c == 'b' || c == 'w';
}

char check() {
	bool ok = false;
	rep(i,3) {
		if(!isbw(B[i][0])) continue;
		ok = true;
		rep(j,3) {
			if(B[i][0] != B[i][j]) {
				ok = false;
				break;
			}
		}
		if(ok) return B[i][0];
	}

	rep(i,3) {
		if(!isbw(B[0][i])) continue;
		ok = true;
		rep(j,3) {
			if(B[0][i] != B[j][i]) {
				ok = false;
				break;
			}
		}
		if(ok) return B[0][i];
	}

	ok = true;
	rep(i,3) {
		if(B[1][1] != B[i][i]) {
			ok = false;
			break;
		}
	}
	if(ok && isbw(B[1][1])) return B[1][1];

	ok = true;
	rep(i,3) {
		if(B[1][1] != B[i][2-i]) {
			ok = false;
			break;
		}
	}
	if(ok && isbw(B[1][1])) return B[1][1];
	
	return '+';
}

int main() {
	while( 1 ) {
		rep(i,3) {
			rep(j,3) {
				cin >> B[i][j];
				if(i==0 && j==0 && B[i][j] == '0') return 0;
			}
		}

		char a = check();
		if(a != 'b' && a != 'w') printf("NA\n");
		else printf("%c\n", a);
	}
}

Measured memory_bytes: 1128
N = int(input())

def check(a, b):
    return max(len(str(a)), len(str(b)))

n = int(N ** (1/2))
#arr =[]
res = check(1, N)

i = 1
while i <= n:
  if N % i == 0:
    res = min(res, check(i,int(N / i)))
  i += 1

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  string s, t;
  cin >> s >> t;
  Sort(s);
  Sort(t);
  Reverse(t);
  string ans = "No";
  if (s < t) {
    ans = "Yes";
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3636
#include <stdio.h>
int main() {
    int N,i,v,j,k;
    scanf("%d",&N);
    int A[N]; 
    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
    }
    for(i=0; i<N; i++){
        v = A[i];
        j = i-1;
        while( j>= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(k=0; k<N; k++){
            printf("%d",A[k]);
            if(k<N-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2040
loop do
  l = (1..8).map{gets.chomp}.join
  puts "A" if l =~ /1100000011/
  puts "B" if l =~ /1000000010000000100000001/
  puts "C" if l =~ /1111/
  puts "D" if l =~ /1000000110000001/
  puts "E" if l =~ /11000000011/
  puts "F" if l =~ /100000001100000001/
  puts "G" if l =~ /110000011/
  break unless gets
end

Measured memory_bytes: 8596
import collections

n=int(input())
arr=[input() for _ in range(n)]
dic={}
for s in arr:
  count=[0]*26
  tmp=collections.Counter(s)
  for char in tmp.keys():
    count[ord(char)-ord('a')]+=tmp[char]
  count=tuple(count)
  if count not in dic:
    dic[count]=1
  else:
    dic[count]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

Measured memory_bytes: 43376
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var power = 1
	var a = int(math.Pow10(9)) + 7

	fmt.Scanf("%d\n", &n)

	for i := 1; i <= n; i++ {
		power *= i
		power = power % a
	}

	fmt.Println(power)

}


Measured memory_bytes: 1836
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); i++)

using namespace std;
using ll = int64_t;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, a, b;
  cin >> n >> a >> b;
  ll x = abs(a - b);
  if (x & 1) {
    cout << min(min(a, b) + x / 2, n - max(a, b) + 1 + x / 2) << endl;
  } else {
    cout << (x >> 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
k,n=map(int,input().split())
import collections
ans=[]
a=list(map(int,input().split()))
c=collections.Counter(a)
for i in list(set(a)):
    ans.append(c[i])
ans.sort()
ANS=0
for i in range(len(set(a))-n):
    ANS+=ans[i]
print(ANS)

Measured memory_bytes: 117308
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_C

n = gets.to_i

hash = {}

for b in 1..4
for f in 1..3
for r in 1..10
    key = b.to_s + "," + f.to_s + "," + r.to_s
    hash[key]=0
end
end
end

n.times do
    b,f,r,v = gets.split.map(&:to_i)
    key = b.to_s + "," + f.to_s + "," + r.to_s
    hash[key]+=v
end

for b in 1..4
for f in 1..3
for r in 1..10
    key = b.to_s + "," + f.to_s + "," + r.to_s
    v = hash[key]
    print " " + v.to_s
end
puts
end
puts "#"*20 if b < 4
end

Measured memory_bytes: 6112
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
char a[N];
int main() {
    ios::sync_with_stdio(false);
    cin>>a+1;
    int len=strlen(a+1);
    int l=0;
    for(int i=1;i<=len/2;i++){
        if(a[i]!=a[len-i+1])l++;
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;
int n, m;
const int maxN = 1e3 + 5;
int MOD = 1e9 + 7;
int dp[maxN][maxN];

void add_self(int & a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

int main(int argc, char *argv[]) {
    cin >> n >> m;
    vector<string> g(n, string(m, '.'));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> g[i][j];
        }
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int ni: {i, i + 1}) {
                int nj = j;
                if (ni == i)
                    nj++;
                if (ni < n && nj < m && g[ni][nj] == '.') {
                    add_self(dp[ni][nj], dp[i][j]);
                }
            }
        }
    }
    cout << dp[n-1][m-1] << endl;
    return 0;
}

Measured memory_bytes: 5248
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int dp[111111];
vector<vint> g;

int f(int x){
	if(dp[x]!=-1)return dp[x];
	int t=0;
	for(auto aa:g[x])chmax(t,f(aa)+1);
	return dp[x]=t;
}

main(){
	int n,m;cin>>n>>m;
	g.assign(n,vint());
	rep(i,m){
		int x,y;cin>>x>>y;x--;y--;
		g[x].pb(y);
	}
	rep(i,n)dp[i]=-1;
	int ans=0;
	rep(i,n)ans=max(ans,f(i));
	dans;
}






Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
 
using namespace std;
using LL = long long;
 
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<int> v(n+1);
  REP(i,m) {
    int x;
    cin >> x;
    ++v[x];
    cin >> x;
    ++v[x];
  }
  for(auto x:v) {
    if(x%2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ll x ,k ,d ; 
	cin >> x >> k >> d ; 
	x = abs(x);
	ll r = x%d ; 
	ll q = x/d  ;
	if(q >= k )
		cout << x - k*d ; 
	else {
		ll rem =  k - q ; 
		if(rem%2 == 0 )
			cout << r  ;
		else 
			cout << abs(r - d) ; 
	}
	return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
map<long,long>mp;
int main()
{
    long i,j,t,a,b,n,c,y,m,prev,sum,ans=1,count,k;
    t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        if(n%10==9 || n/10==9)cout<<"Yes";
        else cout<<"No";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
    int n;
    cin>>n;
    map<string,int> h;
    vector<string> s(n);
    for(int i=0;i<n;i++)
        cin>>s[i],h[s[i]]++;
    cout<<h.size();
    return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int A, P;

int main(int argc, const char * argv[]) {
    cin >> A >> P;
    int appfr = A * 3 + P;
    int pie = appfr / 2;

    output(pie);

    return 0;
}

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

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();

        int[] arr = new int[100001];

        for (int i = 0; i < N; i++)
        {
            int a = cin.nextInt();
            arr[a]++;
        }

        int ans = 0;
        int even_cnt = 0;
       
        for(int i = 0;i<arr.Length;i++)
        {
            if (arr[i] == 0) continue;
            ans++;
            if (arr[i] % 2 == 0) even_cnt++;
        }

        if (even_cnt % 2 == 1) ans--;
        
        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}


Measured memory_bytes: 9816
//
//  main.cpp
//  ABC164
//
//  Created by 安藤光希 on 2020/04/26.
//  Copyright © 2020 安藤光希. All rights reserved.
//

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define rep(i, n) for (int i = 0; i<n; i++)
using namespace std;
// https://atcoder.jp/contests/abc163/tasks/abc163_c
typedef long long ll;


int main() {
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    
    for (int i = 0; i < 10000000; i++){
        C -= B;
        if (C <= 0){
            cout << "Yes" << endl;
            break;
        }

        
        A -= D;
        if (A <= 0){
            cout << "No" << endl;
            break;
        }
        
    }


}

/* A
 int main() {
     ll S, W;
     cin >> S >> W;
     
     if (S > W) cout << "safe" << endl;
     else cout << "unsafe" << endl;

 }
 */


Measured memory_bytes: 3624
#include<iostream>

using namespace std;
typedef long long ll;

const int MAX = 100;

static int u[MAX][MAX];
static int d[MAX];
static int f[MAX];
static int v[MAX];


void seekNode(int n, int& elp) {

	d[n] = elp;
	elp++;
	v[n] = 1;

	for (int i = 0;i < MAX;i++) {
		if (u[n][i] > 0 && v[i] == 0) {
			seekNode(i, elp);
		}
	}


	f[n] = elp;
	elp++;
	return;
}


int main() {

	int n, uid, ap, tmp, elp;
	cin >> n;


	for (int i = 0;i < n;i++) {
		cin >> uid >> ap;
		for (int k = 0;k < ap;k++) {
			cin >> tmp;
			u[uid - 1][tmp - 1] = 1;
		}
	}
	elp = 1;
	for (int i = 0;i < n;i++) {
		if (v[i] == 0)	seekNode(i, elp);
	}

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


	return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int T, X; cin >> T >> X;
    cout.precision(10);
    cout << fixed << 1.0 * T / X << endl;

    return 0;
}


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

int main() {
	//cout<<"GfG!";
    char o[50] , e[50];
	char str[10000];
	int l = 0, m = 0;
	cin>>o>>e;
	for (int i = 0; i < (strlen(o) + strlen(e)); i++)
	{
	   	 if (i % 2 == 0)
	   	 {
	   	     str[i] = o[l]; l++;
	   	 }
	   	 else
	   	 {
	   	     str[i] = e[m]; m++;
	   	 }
	}
	cout<<str;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }

int main() {

	string res = "Yes";
	string S; cin >> S;

	long slen = S.length();

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

		if (i % 2 == 0 && S[i] == 'L') res = "No";
		if (i % 2 == 1 && S[i] == 'R') res = "No";
	}

	cout << res << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int e,y;cin >>e >>y;
    cin >>e >>y;
    if(e==0){
        if(y<=1911) cout << "M" << y - 1867<<endl;
        else if(y <=1925) cout << "T" << y-1911<<endl;
        else if(y<=1988) cout << "S" << y-1925<<endl;
        else cout<<"H"<<y-1988<<endl;
    }else if(e==1){
        cout << 1867+y<<endl;
    }else if(e==2){
        cout << 1911 +y<<endl;
    }else if(e==3){
        cout << 1925+y<<endl;
    }else{
        cout << 1988+y<<endl;
    }
}


Measured memory_bytes: 3128
// C - Takahashi's Information

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int a[3];
int b[3];
int c[3][3];

int main() {
	for (int i=0; i<3; i++) {
		for (int j=0; j<3; j++) {
			cin >> c[i][j];
		}
	}

	a[0] = 0;
	a[1] = c[1][0] - c[0][0];
	a[2] = c[2][0] - c[0][0];
	b[0] = c[0][0];
	b[1] = c[0][1];
	b[2] = c[0][2];

	string ans = "Yes";

	for (int i=0; i<3; i++) {
		for (int j=0; j<3; j++) {
			if (a[i] + b[j] != c[i][j]) ans = "No";
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); 
#define test ll t; cin>>t; while(t--)
//103715602
ll mod=1000000007;
ll sum(ll a[],ll n) 
{ 
    ll s=0,i;
    for ( i = 0; i < 64; i++)  
    {
        ll su,e=0,o=0;  
        for (int j = 0; j < n; j++) 
        { 
            if (a[j]%2==0) 
                e++;
            else
                o++; 
            a[j]/= 2; 
        } 
        ll y=e*o;
        ll x=pow(2,i);
        su=((y%mod)*(x%mod))%mod; 
        //cout<<su<<"\n";
        s+=su;  
    } 
    return s; 
}
int main() {
	fast;
	ll n,i,x;
	cin>>n;
	ll a[n+1];
	for(i=0;i<n;i++)cin>>a[i];
	x=sum(a,n);
	cout<<x%mod;
	return 0;
}

Measured memory_bytes: 2560
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define mp make_pair
#define pb push_back
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int N = 4010;
int n, a[N], b[N];
int fa[N][N], fb[N][N], g[N][N];

namespace BIT {
  int c[N];

  inline int lowbit(int x) { return x & -x; }
  void Add(int x, int val) {
    for (; x <= n * 2 + 1; x += lowbit(x))
      c[x] += val;
  }
  int Query(int x) {
    int res = 0;
    for (; x; x -= lowbit(x))
      res += c[x];
    return res;
  }
}

int main(void) {
  read(n);
  for (int i = 1, x; i <= n << 1; ++i) {
    char s[10];
    scanf("%s", s);
    read(x);
    if (s[0] == 'B') a[x] = i;
    else b[x] = i;
  }
  
  for (int i = 0; i <= n; ++i) {
    if (i) BIT::Add(a[i], 1);
    for (int j = 0; j <= n; ++j) {
      if (j) BIT::Add(b[j], 1);
      if (i < n) fa[i][j] = BIT::Query(2 * n + 1) - BIT::Query(a[i + 1]);
      if (j < n) fb[i][j] = BIT::Query(2 * n + 1) - BIT::Query(b[j + 1]);
    }
    for (int j = 1; j <= n; ++j) BIT::Add(b[j], -1);
  }

  memset(g, 0x3f, sizeof g);
  g[0][0] = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) {
      if (i < n) Min(g[i + 1][j], g[i][j] + fa[i][j]);
      if (j < n) Min(g[i][j + 1], g[i][j] + fb[i][j]);
    }
  printf("%d\n", g[n][n]);

  return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
int k;
int c[4];

int f(int val) {
    int cnt = 0;
    int values[] = {500,100,50,10};
    rep(i,4) {
        int t = val/values[i];

        val -= (t*values[i]);
        cnt += t;
    }
    return cnt;
    
}

void solve() {
    int sum=0;
    rep(i,4) cin>>c[i],sum+=c[i];
    int mini = 10000;
    int ans[4] = {};
    
    rep(i1,c[0]+1) rep(i2,c[1]+1) rep(i3,c[2]+1) rep(i4,c[3]+1) {
        int t = i1*10+i2*50+i3*100+i4*500;
        t-=k;

        if(t<0) continue;
        
        int tt = sum + f(t) - i1 - i2 - i3 - i4;
        if(tt < mini) {
            mini = tt;
            ans[0] = i1;
            ans[1] = i2;
            ans[2] = i3;
            ans[3] = i4;
        }
       
    }

    if(ans[0]!=0) cout<<"10 "<<ans[0]<<endl;
    if(ans[1]!=0) cout<<"50 "<<ans[1]<<endl;
    if(ans[2]!=0) cout<<"100 "<<ans[2]<<endl;
    if(ans[3]!=0) cout<<"500 "<<ans[3]<<endl;

}

int main() {
    int f=1;
    while(cin>>k) {
        if(k==0) return 0;
        if(f) {
            f=0;
        }
        else cout<<endl;
        solve();
    }

    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std ;

struct Node
{
	int P ;
	int C ;
	Node ( ) { }
	Node ( int a , int b )
	{
		P = a ;
		C = b ;
	}
	bool operator < ( const Node &a ) const
	{
		return C > a.C ;
	}
} ;

vector < int > ListofRoad [110] ;
vector < int > ListofTime [110] ;
vector < int > ListofCost [110] ;

int CostAns[110][110] ;
int TimeAns[110][110] ;
bool vis[110] ;

void init ( ) ;
void Dijkstra ( int , int , int ) ;

int main ( )
{
	int n ;
	int m ;
	while ( scanf ( "%d %d" , &n , &m ) == 2 && ( n || m ) )
	{
		init ( ) ;
		for ( int i = 0 ; i < n ; i++ )
		{
			int a ;
			int b ;
			int c ;
			int d ;
			scanf ( "%d %d %d %d" , &a , &b , &c , &d ) ;
			ListofRoad[a].push_back ( b ) ;
			ListofCost[a].push_back ( c ) ;
			ListofTime[a].push_back ( d ) ;
			ListofRoad[b].push_back ( a ) ;
			ListofCost[b].push_back ( c ) ;
			ListofTime[b].push_back ( d ) ;
		}
		int Q ;
		scanf ( "%d" , &Q ) ;
		while ( Q-- )
		{
			int p ;
			int q ;
			int r ;
			scanf ( "%d %d %d" , &p , &q , &r ) ;
			if ( r == 0 )
			{
				if ( CostAns[p][q] == -1 )
				{
					Dijkstra ( p , m , 1 ) ;
				}
				printf ( "%d\n" , CostAns[p][q] ) ;
			}
			else
			{
				if ( TimeAns[p][q] == -1 )
				{
					Dijkstra ( p , m , 0 ) ;
				}
				printf ( "%d\n" , TimeAns[p][q] ) ;
			}
		}
	}
	return 0 ;
}

void init ( )
{
	for ( int i = 0 ; i < 110 ; i++ )
	{
		ListofRoad[i].clear ( ) ;
		ListofTime[i].clear ( ) ;
		ListofCost[i].clear ( ) ;
	}
	memset ( CostAns , -1 , 110 * 110 * sizeof ( int ) ) ;
	memset ( TimeAns , -1 , 110 * 110 * sizeof ( int ) ) ;
}

void Dijkstra ( int source , int m , int type )
{
	memset ( vis , false , 110 * sizeof ( bool ) ) ;
	priority_queue < struct Node > pQ ;
	if ( type == 0 )
	{
		TimeAns[source][source] = 0 ;
	}
	else
	{
		CostAns[source][source] = 0 ;
	}
	pQ.push ( Node ( source , 0 ) ) ;
	for ( int i = 1 ; i <= m ; i++ )
	{
		struct Node var = ( struct Node ) { -1 , -1 } ;
		while ( pQ.empty ( ) == false && vis[( var = pQ.top ( ) ).P] == true )
		{
			pQ.pop ( ) ;
		}
		if ( var.P == -1 )
		{
			break ;
		}
		vis[var.P] = true ;
		if ( type == 0 )
		{
			vector < int > :: iterator iu = ListofTime[var.P].begin ( ) ;
			for ( vector < int > :: iterator it = ListofRoad[var.P].begin ( ) ;
				it != ListofRoad[var.P].end ( ) ;
				it++ , iu++ )
			{
				if ( vis[*it] == false )
				{
					if ( TimeAns[source][*it] == -1 || ( TimeAns[source][*it] > var.C + *( iu ) ) )
					{
						TimeAns[source][*it] = var.C + *( iu ) ;
						pQ.push ( Node ( *it , TimeAns[source][*it] ) ) ;
					}
				}
			}
		}
		else
		{
			vector < int > :: iterator iu = ListofCost[var.P].begin ( ) ;
			for ( vector < int > :: iterator it = ListofRoad[var.P].begin ( ) ;
				it != ListofRoad[var.P].end ( ) ;
				it++ , iu++ )
			{
				if ( vis[*it] == false )
				{
					if ( CostAns[source][*it] == -1 || ( CostAns[source][*it] > var.C + *( iu ) ) )
					{
						CostAns[source][*it] = var.C + *( iu ) ;
						pQ.push ( Node ( *it , CostAns[source][*it] ) ) ;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1256
#include <iostream>

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I < END; I--)

using namespace std;

/* greatest common divisor */
int gcd(int a, int b){
    int r;
    if((r = a % b) != 0){
        gcd(b, r);
    }else{
        return b;
    }
}

int sort(int a, int b){
    int c;
    if(a < b){
        c = a;
        a = b;
        b = c;
    }
    return gcd(a, b);
}

int main(){
    int N;
    cin >> N;
    int A[N];
    Fp(i, 0, N) cin >> A[i];
    int L[N-1] = {}, R[N-1] = {};

    L[1] = A[0];
    Fp(i, 2, N) L[i] = sort(A[i - 1], L[i - 1]); 

    R[N - 2] = A[N - 1];
    Fp(i, 2, N) R[N - 1 - i] = sort(R[N - i], A[N - i]);

    int result[N];
    result[0] = R[0];
    result[N - 1] = L[N - 1];
    Fp(i, 1, N - 1){
        result[i] = sort(L[i], R[i]);
    }

    int temp = 0;
    Fp(i, 0, N) if(temp < result[i]) temp = result[i];
    cout << temp << endl;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            if(S == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 17312
fun main(){
    val n = readLine()!!.split(" ")[0].toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }.sortedDescending()
    var ans = 0L
    var min = mutableListOf<Long>()
    for (i in 0 until n){
        if (i != 0){
            ans += min[i-1]
            min.add(a[i])
        }
        min.add(a[i])
    }
    println(ans)
}

Measured memory_bytes: 73656
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int x, a, b;
  cin >> x >> a >> b;

  if (abs(x - a) <= abs(x - b)){
    cout << 'A' << endl;
  }else{
    cout << 'B' << endl;
  }
}


Measured memory_bytes: 3612
N = int(input())
s = []
for i in range(N):
    s.append((input()))

count = 0
count_BA = 0
count_A = 0
count_B = 0
for i in range(N):
    count += s[i].count('AB')
    if s[i][0] == 'B' and s[i][-1] == 'A':
        count_BA += 1
    elif s[i][0] == 'B':
        count_B += 1
    elif s[i][-1] == 'A':
        count_A += 1

if count_B != 0 and count_A != 0:
    print(count + count_BA - 1 + 1 + 1 + min(count_A, count_B) - 1)
elif count_B != 0 or count_A != 0:
    print(count + count_BA - 1 + 1)
elif count_BA != 0:
    print(count + count_BA - 1)
else:
    print(count)


Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int a,b,c,d,e,f,g,h,i;
  cin>>a>>b>>e;
  g=a+b-e;
  f=a+g-e;
  c=a+e-f;
  d=b+c-g;
  h=f+c-g;
  i=b+c-e;
  printf("%d %d %d\n",a,b,c);
  printf("%d %d %d\n",d,e,f);
  printf("%d %d %d\n",g,h,i);
}


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

int main() {
    int n;
    cin >> n;
    vector<int> R(n);
    for (int i=0; i<n; i++) {
        cin >> R[i];
    }
    int maxv=R[1]-R[0];
    int minv=R[0];
    for (int t=1; t<n; t++) {
        maxv=max(maxv,R[t]-minv);
        minv=min(minv,R[t]);
    }
    printf("%d\n",maxv);
    return 0;
}

Measured memory_bytes: 3636
#include "stdio.h"

int res;
long long int W, H, x, y;
long double S;

int main(void){
  scanf("%Ld %Ld %Ld %Ld", &W, &H, &x, &y);
  S = (long double)(W * H) / 2;
  if(W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2){
    res = 1;
  }else{
    res = 0;
  }
  printf("%Lf %d", S, res);
}

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

const int MAXN = 55;

bool check(const string &s) {
  return s.empty() || s == "0" || s[0] != '0';
}

class BigNum {
private:
  string s;
public:
  BigNum() {
    s = "";
  }
  BigNum(const string &s) {
    if (!check(s)) this->s = "";
    else this->s = s;
  }
  bool operator < (const BigNum &x) const {
    if (s.size() != x.s.size()) return s.size() < x.s.size();
    return s < x.s;
  }
  bool operator > (const BigNum &x) const {
    return x < *this;
  }
  bool operator != (const BigNum &x) const {
    return s != x.s;
  }
  bool operator == (const BigNum &x) const {
    return s == x.s;
  }
  bool operator <= (const BigNum &x) const {
    return *this == x || *this < x;
  }
  bool operator >= (const BigNum &x) const {
    return *this == x || x < *this;
  }
  string getString() const {
    return s;
  }
};

int N;
string S;
bool vis[MAXN][MAXN];
BigNum mem[MAXN][MAXN];

BigNum rec(int l, int r) {
  BigNum &res = mem[l][r];
  if (vis[l][r]) {
    return res;
  }
  res = BigNum();
  vis[l][r] = true;
  if ((S[l] == '?' || S[l] == 'L' || S[l] == 'R') &&
      (S[l+1] == '?' || S[l+1] == '(') &&
      (S[r-1] == '?' || S[r-1] == ')')) {
    for (int i = l+3; i < r-2; ++i) {
      if (S[i] != '?' && S[i] != ',') continue;
      BigNum a = rec(l+2, i);
      BigNum b = rec(i+1, r-1);
      if (a != BigNum() && b != BigNum()) {
        if (S[l] == '?' || S[l] == 'L') {
          res = max(res, a);
        }
        if (S[l] == '?' || S[l] == 'R') {
          res = max(res, b);
        }
      }
    }
  }
  {
    string x = "";
    for (int i = l; i < r; ++i) {
      if (S[i] == '?') {
        x += "9";
      } else if (isdigit(S[i])) {
        x += S[i];
      } else {
        x = "";
        break;
      }
    }
    res = max(res, BigNum(x));
  }
  return res;
}

int main() {
  while (cin >> S) {
    N = S.size();
    S += "$";
    memset(vis, 0, sizeof(vis));
    string ans = rec(0, N).getString();
    if (ans == "") ans = "invalid";
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int A[8][8] = {};
int main(){
    int N,M,a,b;
    int ans = 0;
    bool flag;
    vector<int> list;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        A[a-1][b-1] = 1;
        A[b-1][a-1] = 1;
    }
    for(int i=1;i<N;i++) list.push_back(i);
    do{
        flag = true;
        if(A[0][list[0]] == 0) continue;
        for(int i=0;i<N-2;i++){
            if(A[list[i]][list[i+1]] == 0){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }while(next_permutation(list.begin(),list.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
numArray = list(map(int,input().split()))

numArraySorted = sorted(numArray,reverse=True) #soted method cannot change raw data

alice = 0
bob = 0

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

print(alice-bob)



Measured memory_bytes: 3060
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
pos = []
flag1 = flag2 = False

for i in range(N):
    X, Y = map(int, raw_input().split())
    if (X + Y) % 2:
        flag1 = True
    else:
        flag2 = True
    pos += [(X, Y)]

if flag1 and flag2:
    print -1
    exit()

arms = [2 ** i for i in range(37)][::-1]
if flag2:
    arms += [1]

print len(arms)
print " ".join(map(str, arms))

dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
S = "LRDU"

for gx, gy in pos:
    x, y = 0, 0
    ans = ""
    for d in arms:
        x2, y2 = INF, INF
        for i in range(4):
            dx, dy = dir[i]
            x1, y1 = x + dx * d, y + dy * d
            if abs(x2 - gx) + abs(y2 - gy) > abs(x1 - gx) + abs(y1 - gy):
                x2, y2 = x1, y1
                c = S[i]
        ans += c
        x, y = x2, y2
    print ans


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

// macros
#define overload_rep(va_0, va_1, va_2, va_3, name, ...) name
#define rep_0_(i, n) for(int i = 0; i < (n); ++i)
#define rep_1_(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep_2_(i, x, y, z) for(int i = (x); i >= (y); --i)
#define rep(...) overload_rep(__VA_ARGS__, rep_2_, rep_1_, rep_0_)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries
template<class Monoid>
struct SegmentTree{
private:

    int sz; 
    vector<Monoid> node;
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func operate; 
    const Monoid unit;

public:

    SegmentTree(){}
    SegmentTree(const Func f, const Monoid m) : operate(f), unit(m) {}
    SegmentTree(const vector<Monoid>& vec, const Func f, const Monoid m)
        : operate(f), unit(m) { bulid(vec); }
    ~SegmentTree(){}

    inline void init(){
        fill(node.begin(), node.end(), unit);
    }

    inline void bulid(const vector<Monoid> &vec){
        for(sz = 1; sz < (int)vec.size(); sz <<= 1);
        node.assign(sz << 1, unit);
        for(int i = 0; i < (int)vec.size(); i++)
            node[i + sz] = vec[i];
        for(int i = sz - 1; i > 0; i--)
            node[i] = operate(node[i << 1], node[i << 1 | 1]);
    }

    inline void set(int i, Monoid v){
        for(node[i += sz] = v; i >>= 1;)
            node[i] = operate(node[i << 1], node[i << 1 | 1]);
    }

    inline void add(int i, Monoid v){
        set(i, node[i + sz] + v);
    }

    inline Monoid fold(int l, int r){
        Monoid vl = unit, vr = unit;
        for((l += sz), (r += sz); l < r; l >>= 1, r >>= 1){
            if(l & 1)vl = operate(vl, node[l++]);
            if(r & 1)vr = operate(node[--r], vr);
        }
        return operate(vl, vr);
    }

    inline Monoid operator [] (int i){
        return node[i + sz];
    }

};

// declarations
typedef long long lint;
constexpr lint inf = 1ll << 60;

// solve
int main(){

    int N;
    scanf("%d", &N);

    int h[200000], a[200000];
    rep(i, N)scanf("%d", &h[i]);
    rep(i, N)scanf("%d", &a[i]);

    SegmentTree<lint> seg(vector<lint>(N + 1, -inf), [](lint x, lint y){ return max(x, y); }, -inf);
    seg.set(0, 0);
    rep(i, N)seg.set(h[i], seg.fold(0, h[i] + 1) + a[i]);

    printf("%lld\n", seg.fold(0, N + 1));
    return 0;

}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

const int N = 405;
int n;
vector<int> v, pre;
int dp[N][N];

int getsum(int l, int r)
{
    if(l == r) return 0;
    int ans = pre[r];
    if(l) ans -= pre[l-1];
    return ans;
}

int f(int l, int r)
{
    if(l == r) return v[l];
    if(dp[l][r]) return dp[l][r];
    int ans = 1e18;
    for(int i=l+1;i<r;i++)
        ans = min(ans, f(l, i) + f(i+1, r) + getsum(l, i) + getsum(i+1, r));
    ans = min(v[l] + f(l+1, r) +  getsum(l+1, r), ans);
    ans = min(v[r] + f(l, r-1) + getsum(l, r-1), ans);
    dp[l][r] = ans;
    return ans;

}

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    cin >> n;
    v.resize(n);
    pre.resize(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        pre[i] = v[i];
        if(i) pre[i] += pre[i-1];
    }
    cout << f(0, n-1);
    return 0;
}



Measured memory_bytes: 1536
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    vector<int> isprime(N + 5, 1);
    vector<int> primes;
    vector<int> SPF(N + 5);
    isprime[0] = isprime[1] = 0;
    for (int i = 2; i < N; i++)
    {
        if (isprime[i])
            primes.push_back(i), SPF[i] = i;
        for (int j = 0; j < primes.size() && i * primes[j] < N && primes[j] <= SPF[i]; j++)
            isprime[i * primes[j]] = 0, SPF[i * primes[j]] = primes[j];
    }
    ll a, b, c = 1;
    cin >> a >> b;
    while (b)
        a %= b, swap(a, b);
    for (int prime : primes)
    {
        c += !(a % prime);
        while (!(a % prime))
            a /= prime;
    }
    if (a > 1)
        c++;
    cout << c;
    return 0;
}

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



int main(){
    string S,T;
    cin>>S>>T;
    int cou=0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)!=T.at(i)){
            cou++;
        }
    }
        
cout<<cou<<endl;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1000000007;
const int INF=1001001001;

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>P(N),C(N);
  for(int i=0;i<N;i++){cin>>P[i];P[i]--;}
  for(int i=0;i<N;i++){cin>>C[i];}
  int64_t ans=-INF;
  for(int i=0;i<N;i++){
    int x=i;
    vector<int>s;
    int64_t tot=0;
    while(true){
      x=P[x];
      s.push_back(C[x]);
      tot+=C[x];
      if(x==i){break;}
    }
    int l=s.size();
    int64_t t=0;
    for(int j=0;j<l;j++){
      t+=s[j];
      int64_t now=t;
      if(j+1>K){break;}
      if(tot>0){
        int r=(K-(j+1))/l;
        now+=tot*r;
      }
      chmax(ans,now);
    }
  }
  cout<<ans<<endl;
  return 0;  
}

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

#define ff first
#define ss second

template <class T>
inline void read(T &x) {
	x = 0;
	char c = getchar();
	bool f = 0;
	for (; !isdigit(c); c = getchar()) f ^= c == '-';
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	x = f ? -x : x;
}

template <class T>
inline void write(T x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	T y = 1;
	int len = 1;
	for (; y <= x / 10; y *= 10) ++len;
	for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

template <class T>
inline void writeL(T x) {
	write(x);
	putchar('\n');
}

template <class T>
inline void writeS(T x) {
	write(x);
	putchar(' ');
}

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

	int total = ((N - 1) * (N - 2)) / 2;
	if (K > total) {
		cout << -1 << endl;
		return 0;
	}

	vector<pair<int, int> > edges;
	for (int i = 2; i <= N; ++i) {
		edges.push_back({1, i});
	}

	for (int i = 2; i < N && total > K; ++i) {
		for (int j = i+1; j <= N && total > K; ++j, --total) {
			edges.push_back({i, j});
		}
	}

	cout << edges.size() << endl;
	for (const auto& p : edges) {
		writeS(p.ff); writeL(p.ss);
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int q;
    ll a, b;
    cin >> q;
    while (q--) {
        cin >> a >> b;
        ll c = (ll)sqrtl(a * b - 1), z = c + c;
        if (a <= c) z--;
        if (b <= c) z--;
        if (c * (c + 1) >= a * b) z--;
        cout << z << '\n';
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;cin>>a;
    string s;
    while(a!=0){
	switch(a%3){
	    case 0:s+="0";break;
	    case 1:s+="+";break;
	    case 2:s+="-";a++;
	    }
	a/=3;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
    }

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll dp[3001][3001];

int main()
{
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    // bit = r - l としています。
    for (int bit = 0; bit < n; bit++)
    {
        for (int l = 0; l + bit < n; l++)
        {
            int r = l + bit;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }

    cout << dp[0][n - 1] << endl;

    return 0;
}

Measured memory_bytes: 70016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

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

  int n;
  cin >> n;

  vector<long> a(n);
  fillLong(a, n);
  sortv(a);

  bool allGuu = true;
  rep(i, n) {
    if (a[i]%2) allGuu = false;
  }

  cout << (allGuu?"second":"first") << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch; ++i) {
        if (ch == '\\') S1.push(i);
        else if (ch == '/' && S1.size() > 0) {
            int j = S1.top();
            S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while (S2.size() > 0) {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); ++i) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3168
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);
        int mod = 10007;

        int n = sc.nextInt();
        int[] tanto = new int[n];
        char[] line = sc.next().toCharArray();
        for(int i=0; i<n; i++){
            if(line[i]=='J') tanto[i] = 0;
            if(line[i]=='O') tanto[i] = 1;
            if(line[i]=='I') tanto[i] = 2;
        }

        int[][] dp = new int[2][1<<3];
        dp[0][0] = 1;
        int idx = 1;
        int cnt = 0;
        for(int i=0; i<n; i++){
            for(int bit=0; bit<(1<<3); bit++){
                if((bit&(1<<tanto[i]))==0) continue;
                if(i==0){
                    if((bit&1)>0) dp[idx][bit] = 1;
                    continue;
                }
                for(int bit2=0; bit2<(1<<3); bit2++){
                    if((bit&bit2)>0){
                        dp[idx][bit] += dp[1-idx][bit2];
                        dp[idx][bit] %= mod;
                    }
                }
                if(i==n-1){
                    cnt += dp[idx][bit];
                    cnt %= mod;
                }
            }
            idx = 1-idx;
            dp[idx] = new int[1<<3];
        }
        System.out.println(cnt);
    }

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

Measured memory_bytes: 18200