akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
using namespace __gnu_pbds;

mt19937_64 gen(time(0));

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

//const int mod = 1e9 + 7;
//const int inf = 2e9 + 6555;
const int maxn = 1e4 + 44;

int ans[maxn];


signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    int n;
    cin >> n;
    for(int x = 1; x * x <= n; ++x)
    {
        int g1 = n - x * x;
        for(int y = 1; y * y + x * y <= g1; ++y)
        {
            int g2 = g1 - y * y - x * y;
            for(int z = 1; z * z + x * z + y * z <= g2; ++z)
            {
                ans[x * x + y * y + z * z + x * y + x * z + y * z]++;
            }
        }
    }
    for(int i = 1; i <= n; ++i)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3688
# 鶴亀算
x, y = map(int, input().split())
# 鶴は０匹からx匹いるとして
for a in range(x+1):
    # 亀の個数は全体-鶴a=b　
    b = x - a
    # yがこれに一致したらyesを出力
    if y == a * 2 + b * 4:
        print("Yes")
        exit()

print("No") 

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(m);
	for(int i=0;i<m;i++){
		cin >> a[i];
	}
	int sum = 0;
	for(int i: a){
		sum += i;
	}
	if(n -sum <0){
		cout << "-1" << endl;
	}else{
		cout << n - sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3640
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun <A> countList(a: List<A>): Map<A, Long> {
        val result = mutableMapOf<A, Long>()
        a.forEach {
            result[it] = (result[it] ?: 0L) + 1L
        }
        return result
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val s = Array(N) { sc.next().toCharArray().sorted().toString() }.toList()
        var ans = 0L
        countList(s).forEach {
            val v = it.value
            ans += v * (v - 1) / 2
        }
        pw.println(ans)
    }
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n,m;
    cin >> n >> m;
    if(abs(n-m)>1){
        cout << 0 << endl;
        return 0;
    }
    ll ret=0;
    ll fracn=1,fracm=1;
    for(ll i=1;i<=n;i++){
        (fracn*=i)%=MOD;
    }
    for(ll i = 1; i <= m; i++) {
        (fracm *= i) %= MOD;
    }
    if(n==m){
        cout << (2*fracm*fracn)%MOD << endl;
    }else{
        cout << (fracn * fracm)%MOD << endl;
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	string s;
	cin >> s;
	FOR(i,s.length())
		if(i%2==0)cout << s[i];

	return 0;
}

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


#define fi first
#define se second
#define pb push_back
#define ll long long 
const int MAX = 1e5+5;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(){
	int r;
	cin >> r;
	int area = 3 * r * r;
	cout << area << endl;
}



















Measured memory_bytes: 3592
def resolve():
  n = int(input())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  ans = 0
  for i in range(n):
    if b[i] < a[i]:
      a[i] -= b[i]
      ans += b[i]
    else:
      b[i] -= a[i]
      ans += a[i]
      a[i] = 0
      if b[i] < a[i+1]:
        ans += b[i]
        a[i+1] -= b[i]
      else:
        ans += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 19004
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,c,a[N];
db f[510][1<<7|1];

int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(c);
	for (int i=1; i<=n; i++)
		sc(a[i]);
	sort (a+1,a+n+1);
	int S=1<<(n-1),m=0; db ans=0;
	while (20021206)
	{
		memset (f,0,sizeof (f));
		f[a[n]*n][0]=1;
		for (int i=0; i<=n*c; i++)
		{
			int id=i%n;
			if (id) for (int j=i; j<=n*c; j++)
				for (int s=0; s< S; s++)
					if (!(s>>(id-1)&1))
						f[min (n*c,max (j,i+a[id]*n))][s|1<<(id-1)]+=f[j][s];
		}
		ans+=f[n*c][S-1],++m;
		if (!next_permutation (a+1,a+n)) break;
	}
	printf ("%.15lf\n",ans/m/pow (c,n-1));

    return 0;
}


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

using namespace std;
#define int long long
signed main() {
    int n, d;
    cin >> n >> d;
    int ans = 0;
    int i;
    for(i=1;i<=n;i++)
    {
        int x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d)
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<mint> ansbit(60);
    vector<bitset<60>> bs(n);
    rep(i,n) bs[i] = bitset<60>(a[i]);
    rep(i,60) {
        mint num = 0;
        rep(j,n) {
            if(bs[j][i]) num += 1;
        }
        ansbit[i] = num*(mint(n)-num);
    }
    mint ans = 0;
    rep(i,60) {
        ans += ansbit[i]*mint(2).pow(i);
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void)
{
  int month1,month2,day1,day2;
  char str[16];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d %d",&month1,&day1);
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d %d",&month2,&day2);
  
  if(month1 == month2)
  {
    puts("0");
  }else
  {
    puts("1");
  }
  
  return 0;
}

Measured memory_bytes: 128
use std::collections::HashMap;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let itr = s.split_whitespace().map(|e| e.parse::<i64>().unwrap());
    let mut dict = HashMap::new();

    for i in itr {
        *dict.entry(i).or_insert(0) += 1;
    }

    println!(
        "{}",
        if dict[&5] == 2 && dict[&7] == 1 {
            "YES"
        } else {
            "NO"
        }
    );
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <numeric>
using namespace std;


int main()
{
    int a[6];
    for(int i=1;i<6;i++){
        cin>>a[i];
    }
    
    int ans=0;
    
    
    for(int i=1;i<6;i++){
        if(a[i]%10==0){
        ans+=a[i];
        }
        else{
            ans+=((a[i]/10)+1)*10;
        }
    }
    
    vector<int> b;
    
    for(int i=1;i<6;i++){
        if(a[i]%10!=0){
        b.push_back(a[i]%10);
        }
    }
    
    if(b.begin()==b.end()){
        cout<<ans<<endl;
    }
    else{
    sort(b.begin(),b.end());
    
    auto itr=b.begin();
    
    if(*itr!=0){
        ans-=10-*itr;
    }
    
    cout<<ans<<endl;
    }
    
    
    
    }



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi c(n),s(n),f(n);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n){
        int ans=0;
        Rep(j,i,n-1){
            int x=s[j];
            while(ans>x)x+=f[j];
            ans+=x-ans;
            ans+=c[j];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main(void){
   int N,M;
   cin>>N>>M;
   int a[N],b[N];
   for(int i=0;i<N;i++){
       cin>>a[i]>>b[i];
   }
   int c[M],d[M];
   for(int i=0;i<M;i++){
       cin>>c[i]>>d[i];
   }
   int min[N];
   int ans[N];
   int dis;
   for(int i=0;i<N;i++){min[i]=1000000000;
       for(int j=0;j<M;j++){
           dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
           if(dis<min[i]) {min[i]=dis; ans[i]=j+1;}
       }
   }
   for(int i=0;i<N;i++){
       cout<<ans[i]<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,i,j=0,x[50];
    double a;
    scanf("%d",&n);
    for (i=1;i<=n;i++){
        if (i%2!=0){
            x[j]=i;
            j++;
        }
    }
    a=(double)j/n;
    printf("%lf",a);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(int (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(int (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

int main()
{
    int n,k;
    cin >> n >> k;
    double ans = 0;
    rep1(i, n + 1){
        int now = i;
        double count = 1.0 / n;
        while (now < k) {
            now *= 2;
            count /= 2;
        }
        ans += count;
    }
    printf("%.12f\n",ans);
    return 0;
}


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

using namespace std;

main(){
  long long n, e[100][100], a = 0;
  cin >> n;
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin >> e[i][j];
  for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) a += min(e[i][j], e[j][i]);
  cout << a << endl;
}

Measured memory_bytes: 1232
K = int(eval(input()))

# すべての要素に1回ずつ操作を行うことは、すべての要素を-1することと同じ。
# N=50,aiがすべてN-1である状態を最終状態として、逆算する。

N = 50
r = K % N
q = K // N
A = []
for i in range(N):
  A.append(N-1 + q + (i<r)*(N-r+1) - (i>=r)*r)
print(N)
print(*A)

Measured memory_bytes: 38256
import numpy as np

num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = [int(s) for s in input().split()]
A.sort(reverse = True)

dp = np.zeros(N+1, dtype = np.int)
MIN = -10**9
for i in range(1, N+1):
    mx = MIN
    for a in A:
        k = i-num[a]
        if k >= 0:
            mx = max(mx, dp[k] + 1)
    dp[i] = mx

d = dp[N]
n = N
s = []
for i in range(0, d):
    for a in A:
        tmp = n-num[a]
        if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break
print("".join(s))


Measured memory_bytes: 12512
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;

int main(){

  ll h,w,k;
  cin >> h >> w >> k;

  ll sx,sy,gx,gy;
  cin >> sx >> sy >> gx >> gy;

  char e[h+2][w+2];
  for(int i=0;i<w+2;i++){
    e[0][i]='@';
    e[h+1][i]='@';
  }
  for(int i=1;i<h+1;i++){
    e[i][0]='@';
    for(int j=1;j<w+1;j++)cin >> e[i][j];
    e[i][w+1]='@';
  }

  ll dist[h+2][w+2];
  memset(dist,-1,sizeof(dist));

  dist[sx][sy]=0;
  queue<pair<ll,ll>> que;
  que.push(make_pair(sx,sy));

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

  while(!que.empty()){
    ll y=que.front().first;
    ll x=que.front().second;
    que.pop();    

    for(int i=0;i<4;i++){
      for(int j=1;j<=k;j++){
        if(y+dy[i]*j<0 || y+dy[i]*j>h+1 || x+dx[i]*j<0 || x+dx[i]*j>w+1)break;
        if(e[y+dy[i]*j][x+dx[i]*j]=='@')break;
        if(dist[y+dy[i]*j][x+dx[i]*j]!=-1){
          if(dist[y+dy[i]*j][x+dx[i]*j]>dist[y][x]);
          else break;
        }
        if(dist[y+dy[i]*j][x+dx[i]*j]==-1){
          dist[y+dy[i]*j][x+dx[i]*j]=dist[y][x]+1;
          que.push(make_pair(y+dy[i]*j,x+dx[i]*j));
        }
      }
    }

  }


  cout << dist[gx][gy] << endl;

  


}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  a *= n;
  int ans = min(a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	int n;
	while (cin >> str)
	{
		if (str == "-")
		{
			break;
		}
		cin >> n;
		for (int i = 0, h; i < n; i++)
		{
			cin >> h;
			string cut = str.substr(0, h);
			str.erase(0, h);
			str += cut;
		}
		cout << str << endl;
	}
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a==5&&b==5&&c==7)cout<<"YES"<<endl;
    else if(a==5&&b==7&&c==5)cout<<"YES"<<endl;
    else if(a==7&&b==5&&c==5)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100000
int main(void){
    int n,max;
    int cnt[N] = {0};
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        int t;
        scanf("%d", &t);
        if (t-1>=0) cnt[t-1]++;
        if (t+1<N) cnt[t+1]++;
        cnt[t]++;
    }
    max = 0;
    for (int i=0; i<N; i++){
        max = (cnt[i]>max) ? cnt[i] : max;
    }
    
    printf("%d\n", max);
    
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

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

        int H = sc.nextInt();
        int W = sc.nextInt();

        int[][] c = new int[10][10];
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                c[i][j] = sc.nextInt();
            }
        }

        int[][] A = new int[H][W];
        int[] cnt = new int[10];
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                A[i][j] = sc.nextInt();
                if(A[i][j] != -1){
                    cnt[A[i][j]]++;
                }
            }
        }
        
        for(int k = 0; k < 10; k++){
            for(int i = 0; i < 10; i++){
                for(int j = 0; j < 10; j++){
                    c[i][j] = Math.min(c[i][j], c[i][k]+c[k][j]);
                }
            }
        }
        long sum = 0;
        for(int i = 0; i < 10; i++){
            sum += c[i][1]*cnt[i];
        }
        sc.close();

        System.out.println(sum);

    }
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    int t = 0;
    for (const char c : s) {
        if (c == '2') {
            t++;
        }
    }
    cout << t << endl;
}


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

int main()
{
    long long int n,res,ans,p,q;
    cin>>n;
    ans = n;

    for(int i = 1;i<= sqrt(n);i++){
        if(n % i == 0){
            p = i;
            q = n/i;
            res = (p-1)+(q-1);
            if(res < ans){
                ans = res;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator^(const ll& t)const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

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


int main() {
    string s;
    cin >> s;
    ll N = s.size();

    ll ans = 0;
    ll a = 0;
    rep(i, N) {
        if (s[i] == 'A') { a++; }
        else if (i < N - 1 && s[i] == 'B' && s[i+1] == 'C') { ans += a; i++; }
        else { a = 0; }
        //cout << a << ans << endl;
    }
    cout << ans;
	system("PAUSE");
}

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

int main() {
    int N, L; cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; i++) cin >> S.at(i);
    sort(S.begin(), S.end());
    string K;
    for (int i = 0; i < N; i++) {
        K += S.at(i);
    }
    cout << K << endl;
}

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

signed main(){
    int n;
    cin>>n;
    int ans=1;

    for(int i=1;i<=n;i++){
        ans*=i;
    }
    cout<<ans<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string S;	cin>>S;
	string T;	cin>>T;
	T.pop_back();
	if(S==T)	Yes();
	else No();

    return 0;
}




Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int n;cin>>n;
    int tmp = n/1000;
    tmp++;
    tmp*=1000;
    if(n%1000==0)cout<<0;
    else 
    cout<<tmp-n;
 
return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int M, N, D, S[32][32], a[768][768];

bool solve(int n) {
    int h = 0;
    rep(k, n) {
        int ix = -1;
        for(int i=h; i<n; i++) if(a[i][k]) { ix=i; break; }
        if(ix==-1) continue;
        if(h!=ix) rep(i, n+1) swap(a[h][i], a[ix][i]);
        rep(i, n) if(i!=h) if(a[i][k]) {
            for(int j=k; j<=n; j++) a[i][j] ^= a[h][j];
        }
        h++;
    }
    for(int i=h; i<n; i++) if(a[i][n]==1) return false;
    return true;
}

int main() {
    for(;;) {
        scanf("%d%d%d", &M, &N, &D);
        if(M==0 && N==0 && D==0) return 0;
        rep(i, N) rep(j, M) scanf("%d", S[i]+j);
        memset(a, 0, sizeof(a));
        const int n = N*M;
        rep(i, N) rep(j, M) {
            const int ix = i*M+j;
            a[ix][ix] = 1;
            a[ix][n] = S[i][j];
            rep(x, N) rep(y, M) if(abs(i-x)+abs(j-y)==D) a[ix][x*M+y] = 1;
        }
        printf("%d\n", (int)solve(n));
    }
}

Measured memory_bytes: 0
def main():
    _ = input()
    A = tuple(map(int, input().split()))
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 14352
def changeSecond(time)
  splitedTime = time.split(":").map(&:to_i)
  secondTime = 60*60*splitedTime[0] + 60*splitedTime[1] + splitedTime[2]
  return secondTime
end

oneDaySecond = 60*60*24
loop do
  n = gets.chomp.to_i
  break if n == 0

  s = Array.new(oneDaySecond,0)
  (0..n-1).each do |i|
    start, finish = gets.chomp.split(" ").map(&:to_s)
    start = changeSecond(start)
    finish = changeSecond(finish)
    s[start] += 1
    s[finish] += -1
  end 
  (0...oneDaySecond-1).each do |j|
    s[j+1] += s[j]
  end
  p s.max
end



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

int func(int **a, int x, int y, int n, int m)
{
	int c = 1;
	if(a[y][x] == 1){
		return 0;
	}
	a[y][x] = 1;
	
	if(x-1 >= 0){
		c += func(a, x-1, y, n, m);
	}
	if(y-1 >= 0){
		c += func(a, x, y-1, n, m);
	}
	if(x+1 < n){
		c += func(a, x+1, y, n, m);
	}
	if(y+1 < m){
		c += func(a, x, y+1, n, m);
	}
	
	return c;
}

int main(int argc, char **argv)
{
	int **a, n, m, x, y, i, j;
	char *w;
	
	while(1){
		scanf("%d %d", &n, &m);
		if(n == 0){
			break;
		}
		
		a = (int **)calloc(m, sizeof(int));
		for(i = 0; i < m; i++){
			a[i] = (int *)calloc(n, sizeof(int));
			w = (char *)malloc((n+1)*sizeof(char));
			scanf("%s", w);
			for(j = 0; j < n; j++){
				if(w[j] == '@'){
					x = j;
					y = i;
				} else if(w[j] == '#'){
					a[i][j] = 1;
				}
			}
			free(w);
		}
		
		printf("%d\n", func(a, x, y, n, m));
		for(i = 0; i < m; i++){
			free(a[i]);
		}
		free(a);
	}
	
	return 0;
}

Measured memory_bytes: 0
import sys

def dijkstra(v_count: int, edges: list, start: int,
             *, adj_matrix: bool = False, unreachable=float("inf")) -> list:
    """ ダイクストラ法
    :param v_count: 頂点数
    :param edges: 辺のリスト(隣接リストor隣接行列)
    :param start: スタートする頂点
    :param adj_matrix: edgesに渡したリストが隣接行列ならTrue
    :param unreachable: 到達不能を表すコスト値
                        隣接行列の辺の有無の判定および返すリストの初期値に使用
    """
    from heapq import heappush, heappop

    vertices = [unreachable] * v_count
    vertices[start] = 0
    q, rem = [(0, start)], v_count - 1

    while q and rem:
        cost, v = heappop(q)
        if vertices[v] < cost:
            continue
        rem -= 1

        dests = (filter(lambda x: x[1] != unreachable, enumerate(edges[v]))
                 if adj_matrix else edges[v])

        for dest, _cost in dests:
            newcost = cost + _cost
            if vertices[dest] > newcost:
                vertices[dest] = newcost
                heappush(q, (newcost, dest))

    return vertices

n = int(input())
inf = float("inf")
edges = [[inf]*n for _ in [0]*n]
for a in (tuple(map(int, l.split())) for l in sys.stdin):
    _from = a[0]
    for to, cost in zip(a[2::2], a[3::2]):
        edges[_from][to] = cost
vertices = dijkstra(n, edges, 0, adj_matrix=True)
for i, n in enumerate(vertices):
    print(i, n)


Measured memory_bytes: 5988
#include<iostream>
#include<map>
#include<deque>
#include<cstdlib>
#include<cstring>
using namespace std;struct B{int z[2];char s[14];bool operator<(const B&r)const{return strcmp(s,r.s)<0;}};int main(){int a[13][5]={{2,-1},{2,5,-1},{0,1,3,6,-1},{2,7,-1},{5,-1},{1,4,6,9,-1},{2,5,7,10,-1},{3,6,8,11,-1},{7,-1},{5,10,-1},{6,9,11,12,-1},{7,10,-1},{10,-1},},gx[]={2,1,2,3,0,1,2,3,4,1,2,3,2},gy[]={0,1,1,1,2,2,2,2,2,3,3,3,4},v,d,s,i,j;B g={0,0,"0123456789:;0"};for(;;){map<B,int>m;deque<B>q;B b={-1,-1};for(i=0;i<13;i++){cin>>v;if(v==-1)return 0;b.s[i]='0'+v;if(!v)b.z[b.z[0]!=-1]=i;}b.s[13]=0;m[b]=1;for(q.push_back(b);!q.empty();q.pop_front()){B&b=q.front();if(!strcmp(b.s,g.s))break;d=0;for(i=13;i--;){v=b.s[i]-'0';if(v)d+=abs(gx[v]-gx[i])+abs(gy[v]-gy[i]);}s=m[b];if(s+d<22)for(j=2;j--;)for(i=0;~a[b.z[j]][i];i++){B n=b;n.z[j]=a[b.z[j]][i];if(n.z[j]-n.z[1-j]){swap(n.s[b.z[j]],n.s[n.z[j]]);int&t=m[n];if(!t){t=s+1;q.push_back(n);}}}}m[g]?cout<<m[g]-1<<endl:cout<<"NA\n";}}

Measured memory_bytes: 1364
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>

int main()
{
	long long n, t, a, min = 1000000000000000, min_i = 0;

	scanf("%lld%lld%lld", &n, &t, &a);
	t *= 1000;
	a *= 1000;
	for (int i = 0; i < n; i++)
	{
		long long h, ave;
		scanf("%lld", &h);
		ave = t - h * 6;
		if (std::abs(ave - a) < min)
		{
			min_i = i + 1;
			min = std::abs(ave - a);
		}
	}
	printf("%lld\n", min_i);

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll L,R;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>L>>R;
    if(R-L+1>=2019){
        cout<<0<<endl;
    }else{
        ll ans=2018;
        FOR(i,L,R+1){
            FOR(j,i+1,R+1){
                ans=min(i*j%2019,ans);
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int r,c,sum,total_sum = 0;
	scanf("%d %d",&r,&c);
	int table[r+1][c+1];

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			table[i][j] = 0;
		}
	}

	for(int i = 0; i < r; i++){
		sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d",&table[i][j]);
			sum += table[i][j];
			table[r][j] += table[i][j];
		}
		table[i][c] = sum;
		total_sum += sum;
	}
	table[r][c] = total_sum;

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c; j++){
			printf("%d ",table[i][j]);
		}
		printf("%d\n",table[i][c]);
	}
}



Measured memory_bytes: 2684
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	t := scanString()
	if s == t[:len(t)-1] {
		fmt.Fprintln(wr, "Yes")
	} else {
		fmt.Fprintln(wr, "No")
	}
}


Measured memory_bytes: 1760
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

static const int MAX_N = 1000000;
bool isPrime[MAX_N];

class Ticket{
public:
	int mMoney;
	string mNumber;
	Ticket(int _m, string _num){
		mMoney = _m;
		mNumber = _num;
	}
};

int main(){
	int n,m;

	while(~scanf("%d %d",&n,&m)){
		if(n==0) break;
		vector<Ticket> tickets;
		for(int i=0;i<n;i++){
			string number;
			int money;
			cin >> number >> money;
			tickets.push_back(Ticket(money,number));
		}

		int sum = 0;
		for(int i=0;i<m;i++){
			string str;
			cin >> str;		
			int prize = 0;
			for(int j=0;j<tickets.size();j++){		
				bool isok = true;
				for(int k=tickets[j].mNumber.size()-1;k>=0;k--){					
					if(tickets[j].mNumber[k] != str[k]
					&& tickets[j].mNumber[k] != '*'){
						isok = false;
						break;
					}
				}

				if(isok) prize = max(tickets[j].mMoney,prize);
			}

			sum += prize;
		}

		printf("%d\n",sum);
	}
}

Measured memory_bytes: 1264
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IM
import Data.List

type Map = IM.IntMap Int

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

get :: Int -> Map -> Int
get key m = fromMaybe 0 $ IM.lookup key m

solve :: Int -> Int -> Int -> Map -> Int
solve k right prev m
  | left <= 0 = prev
  | otherwise = solve k (right - 1) result m
    where left = right - k + 1
          curr = get right m - get left m
          result = if curr < prev then curr else prev

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  hs <- sort <$> readIntLines
  let d = IM.fromList $ zip [1..] hs
  print $ solve k (length hs) (10 ^ 9) d

Measured memory_bytes: 16764
x = input().split(" ")
if int(x[2]) - int(x[4]) >= 0 and int(x[3]) - int(x[4]) >= 0 and int(x[2]) + int(x[4]) <= int(x[0]) and int(x[3]) + int(x[4]) <= int(x[1]) :
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int G[1001][1001] = {};

int main() {
    int N; cin >> N;
    for(int i=0; i<N; ++i) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        G[x1][y1] += 1;
        G[x1][y2] -= 1;
        G[x2][y1] -= 1;
        G[x2][y2] += 1;
    }
    for(int i=0; i<1000; ++i) {
        for(int j=0; j+1<1000; ++j) {
            G[i][j + 1] += G[i][j];
        }
    }
    for(int i=0; i<1000; ++i) {
        for(int j=0; j+1<1000; ++j) {
            G[j + 1][i] += G[j][i];
        }
    }

    int res = -1;
    for(int i=0; i<=1000; ++i) {
        res = max(res, *max_element(G[i], G[i] + 1001));
    }
    cout << res << endl;
}


Measured memory_bytes: 7032
//ΔAGC023A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
map<LL,int> M;
map<LL,int>::iterator it;
int main()
{
	int n,x;
	LL s=0;
	cin>>n;
	M[0]=1;
	while(n--){
		cin>>x;
		s+=x;
		M[s]++;
	}
	s=0;
	for(it=M.begin();it!=M.end();it++){
		x=(*it).second;
		s+=(LL)x*(x-1);
	}
	cout<<s/2;
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    
    x=x-z;
    printf("%d",(x/(y+z)));
	return 0;
}

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

int main() {

  int N, last = 101,ans;
  cin >> N;
  
  vector<int> d(N);
  
  for (int i = 0 ; i < N ; i++)
    cin >> d.at(i);
  
  sort(d.begin(),d.end());  
    
  for (int i = N - 1 ; i >= 0 ; i--){
    if (d.at(i) < last){
      ans ++;
      last = d.at(i);
    }
  }
  
  cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MB 1000000007
#define NB 1000000000
#define N5 100007
#define ll long long int
int N,K;
int H[N5],dp[N5];

int main()
{

	cin >>N >> K;
	REP(i,N){
		cin >> H[i];
	}
	dp[0] = 0;
	dp[1] = abs(H[1] - H[0]);
	FOR(i,2,N){
		int mi = NB;
		FOR(j,1,min(K,i)+1){
			mi = min(mi,dp[i-j]+abs(H[i]-H[i-j]));
		}
		dp[i] = mi;
	}

	cout << dp[N-1];
}





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

int main(){
    int N;
    cin >> N;
    int A[N] = {0};
    for ( int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int ans = 0;
    bool div_2 = true;
    while (div_2){
        for(int j= 0; j<N; j++){
            if (A[j]%2 == 1){
                div_2 = false;
                break;
            }
            else A[j] /= 2;
        }
        if(div_2){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll n;
char s[300010];
ll a[300010];
ll ans=INF;
int main(){
	scanf("%lld\n%s",&n,s);
	rep(i,0,n)a[i+1]=a[i]+(s[i]=='E');
	rep(i,0,n)ans=min(ans,(i-a[i])+(a[n]-a[i+1]));
	printf("%lld\n",ans);
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<int> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool check(VI arr){
    fore1(i,1,arr.size()){
        if(arr[i]<arr.size()-1)return false;
    }
    return true;
}
int main()
 {  fast();
 VI arr(5,0);
 fore(i,5)cin>>arr[i];
 
fore(i,5){
    if(arr[i]==0){
        cout<<i+1<<endl;
        break;}
}
}

Measured memory_bytes: 3588
N = input()

num_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(num_list[int(N)-1])

Measured memory_bytes: 3060
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int t; cin >> t;
	while (t--) {
		int C, A, N; cin >> C >> A >> N;

		int ans = min({ C,A,N });
		C -= ans;
		A -= ans;
		N -= ans;
		int tmp = min(A, C / 2);
		ans += tmp;
		C -= tmp * 2;
		ans += C / 3;


		cout << ans << endl;
	}

	return 0;
}




Measured memory_bytes: 3164
import sys
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
    sys.exit()

if N == 1:
    print(M - 2)
    sys.exit()
if M == 1:
    print(N - 2)
    sys.exit()
if N >= 2 and M >= 2:
    print((N - 2) * (M - 2))
    sys.exit()

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end()); // {1, 2, 2, 5}
  reverse(vec.begin(), vec.end());
	  
  int a_score = 0;
  int b_score = 0;
  for (int i = 0; i < (N + 1)/2 ; i++) {
    a_score += vec.at(2*i);
  }
  for (int i = 0; i < N/2; i++) {
    b_score += vec.at(2*i + 1);
  }
  
  cout << a_score - b_score << endl;
  
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
using namespace std;
int main()
{

	int n, sum, dice[6];
	string sup;

	cin >> n;

	while (n != 0){

		sum = 1;
		for (int i = 0; i < 6; i++)	dice[i] = i + 1;


		for (int i = 0; i < n; i++){
			cin >> sup;
			switch (sup[0])
			{
				int temp;
			case 'N':
				temp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = temp;
				sum += dice[0];
				break;
			case 'E':
				temp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = temp;
				sum += dice[0];
				break;
			case 'W':
				temp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = temp;
				sum += dice[0];
				break;
			case 'S':
				temp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = temp;
				sum += dice[0];
				break;
			case 'R':
				temp = dice[1];
				dice[1] = dice[2];
				dice[2] = dice[4];
				dice[4] = dice[3];
				dice[3] = temp;
				sum += dice[0];
				break;
			case 'L':
				temp = dice[1];
				dice[1] = dice[3];
				dice[3] = dice[4];
				dice[4] = dice[2];
				dice[2] = temp;
				sum += dice[0];
				break;
			default:
				break;
			}
		}

		cout << sum << endl;

		cin >> n;

	}

}

Measured memory_bytes: 1204
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  int ans = 0;
  rep(i,N) {
    if (i%2==0 && A[i]%2==1) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define X first
#define Y second
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

int compress ( VI &va, VI &vb, int wh )
{
	int n = va.size();
	VI vc;
	for (int i = 0; i < n; ++i) {
		for (int d = -1; d <= 1; ++d) {
			int ta = va[i] + d, tb = vb[i] + d;
			if (0 <= ta && ta <= wh) { vc.push_back(ta); }
			if (0 <= tb && tb <= wh) { vc.push_back(tb); }
		}
	}
	sort(all(vc));
	vc.erase(unique(all(vc)), vc.end());
	for (int i = 0; i < n; ++i) {
		va[i] = lower_bound(all(vc), va[i]) - vc.begin();
		vb[i] = lower_bound(all(vc), vb[i]) - vc.begin();
	}
	return vc.size();
}

int main ( void )
{
	int dx[] = { 0, 0, -1, 1 }, dy[] = { -1, 1, 0, 0 };
	int w, h, n;
	while (cin >> w >> h, w|h) {
		cin >> n;
		VI xa(n), xb(n), ya(n), yb(n);
		for (int i = 0; i < n; ++i) {
			cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
		}
		w = compress(xa, xb, w) - 1;
		h = compress(ya, yb, h) - 1;

		vector<vector<bool> > fld(h, vector<bool>(w, false));
		for (int i = 0; i < n; ++i) {
			for (int y = ya[i]; y < yb[i]; ++y) {
				for (int x = xa[i]; x < xb[i]; ++x) {
					fld[y][x] = true;
				}
			}
		}

		int ans = 0;
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				if (fld[y][x]) { continue; }
				++ans;

				queue<PII> que;
				que.push(PII(x, y));
				while (!que.empty()) {
					PII p = que.front(); que.pop();

					for (int d = 0; d < 4; ++d) {
						PII t(p.X + dx[d], p.Y + dy[d]);
						if (t.X < 0 || t.X >= w || t.Y < 0 || t.Y >= h) { continue; }
						if (fld[t.Y][t.X]) { continue; }
						que.push(t);
						fld[t.Y][t.X] = true;
					}
				}
			}
		}

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

Measured memory_bytes: 1400
#include<bits/stdc++.h>
const int N = 524288, P = 924844033;
int ri() {
	char c = getchar(); int x = 0, f = 1; for(;c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
	for(;c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) - '0' + c; return x * f;
}
int w[N], R[N], a[N], b[N], sz[N], to[N << 1], nx[N << 1], pr[N], f[N], g[N], tp, L, InvL, n;
int fix(int x) {return (x >> 31 & P) + x;}
int add(int a, int b) {return a += b, a >= P ? a - P : a;}
int mul(int a, int b) {return 1LL * a * b % P;}
void ins(int u, int v) {to[++tp] = v; nx[tp] = pr[u]; pr[u] = tp;}
void adds(int u, int v) {ins(u, v); ins(v, u);}
int Pow(int x, int k) {
	int r = 1;
	for(;k; x = mul(x, x), k >>= 1)
		if(k & 1)
			r = mul(r, x);
	return r;
}
int Inv(int x) {return Pow(x, P - 2);}
void Pre(int m) {
	L = 1; int x = 0;
	for(;(L <<= 1) < m; ++x) ;
	for(int i = 1;i < L; ++i)
		R[i] = R[i >> 1] >> 1 | (i & 1) << x;
	w[0] = 1; int wn = Pow(5, (P - 1) / L);
	for(int i = 1;i < L; ++i)
		w[i] = mul(w[i - 1], wn);
	InvL = Inv(L);
}
void DFT(int *F) {
	for(int i = 0;i < L; ++i)
		if(i < R[i])
			std::swap(F[i], F[R[i]]);
	for(int i = 1, d = L >> 1; i < L; i <<= 1, d >>= 1)
		for(int j = 0;j < L; j += i << 1) {
			int *l = F + j, *r = F + j + i, *p = w, tp;
			for(int k = i; k--; ++l, ++r, p += d)
				tp = mul(*r, *p), *r = fix(*l - tp), *l = add(*l, tp);
		}
}
void Dfs(int u, int f) {
	sz[u] = 1;
	for(int i = pr[u]; i; i = nx[i])
		if(to[i] != f)
			Dfs(to[i], u),
			sz[u] += sz[to[i]],
			--a[sz[to[i]]];
	--a[n - sz[u]];
}
int main() {
	n = ri();
	f[0] = 1; for(int i = 1;i <= n; ++i) f[i] = mul(f[i - 1], i);
	g[n] = Inv(f[n]); for(int i = n;i; --i) g[i - 1] = mul(g[i], i);
	for(int i = 1;i < n; ++i)
		adds(ri(), ri());
	Dfs(1, 0); a[n] = n;
	for(int i = 1;i <= n; ++i)
		a[i] = mul(fix(a[i]), f[i]);
	for(int i = 0;i <= n; ++i)
		b[n - i] = g[i];
	Pre((n << 1) + 1);
	DFT(a); DFT(b);
	for(int i = 0;i < L; ++i)
		a[i] = mul(a[i], b[i]);
	DFT(a);
	for(int i = 1;i <= n; ++i) 
		printf("%d\n", mul(mul(a[L - n - i & L - 1], InvL), g[i]));
	return 0;
}


Measured memory_bytes: 29312