akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a[7];
	rep(i, 7)cin >> a[i];
	long long ans = a[1];
	int x, y, z;
	x = a[0];
	y = a[3];
	z = a[4];

	if (x > 0 && y > 0 && z > 0 && x % 2 + y % 2 + z % 2 >= 2) {
		ans += 3;
		x--; y--; z--;
	}
	ans += (x / 2 + y / 2 + z / 2) * 2LL;

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<50;
int n;
map<ll,int> M;
map<ll,int> cnt;
ll ans;
ll solve(ll x) {
	for (ll i=2;;i++) {
		ll t=i*i*i;
		if (t>x) break;
		while (x%t==0) x/=t;
	}
	return x;
}
ll T(ll x) {
	ll A=1,B=1;
	for (ll i=2;;i++) {
		if (i*i*i>x) break;
		int ss=0;
		while (x%i==0) {
			x/=i; ss++;
		}
		if (ss==1) A*=i; else if (ss==2) B*=i;
	}
	ll tmp=(ll)floor(sqrt(x)+0.5);
	if (tmp*tmp==x) B*=tmp;
	else A*=x;
	ll res=A*B;
	if (res>INF/A+1) res=INF; else res*=A;
	return res;
}

int main() {
	//freopen("2.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		ll x; scanf("%lld",&x);
		x=solve(x);
		//printf("%lld\n",x);
		M[x]++;
	}
	ans=0;
	for (map<ll,int>::iterator it=M.begin();it!=M.end();it++) {
		ll x=it->first;
		if (cnt[x]) continue;
		ll t=T(x);
		if (x!=t) ans+=max(it->second,M[t]);
		else ans++;
		cnt[t]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20864
use std::collections::HashMap;
use std::io;

fn main() {
    let mut input_string = String::new();
    io::stdin().read_line(&mut input_string).expect("Error");
    let s = input_string.trim();
    let mut hash_map = HashMap::new();
    for i in s.chars() {
        let count = hash_map.entry(i).or_insert(0);
        *count += 1;
    }
    for (_, value) in hash_map {
        if value % 2 != 0 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(a>=13){
    printf("%d\n",b);
  }
  else if(a<=5){
    printf("0\n");
  }
  else{
    printf("%d\n",b/2);
  }
}

Measured memory_bytes: 128
#include <stdio.h>

class Dice{
public:
	Dice(){
		number = new int[6];
		work = new int[6];
	};
	~Dice(){
		delete[] number;
		delete[] work;
	};

	void setLabel(int index,int num){
		number[index] = num;
	};

	void roll(char dst){
		for(int i = 0; i < 6; i++) work[i] = number[i];
		switch(dst){
		case 'E':
			setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'N':
			setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'S':
			setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'W':
			setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	int returnPeek(){
		return number[0];
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

private:
	int* number;
	int* work;
};

int main(){
	Dice dice;
	int label;
	char ch;
	for(int i = 0; i < 6; i++){
		scanf("%d",&label);
		dice.setLabel(i,label);
	}
	getchar(); 
	while((ch = getchar()) != '\n'){
		dice.roll(ch);
	}
	printf("%d\n",dice.returnPeek());
}



Measured memory_bytes: 2740
import numpy as np

K, N = map(int, input().split())
A = list(map(int, input().split()))
A_dist = [0]*N

for i in range(N-1):
    A_dist[i] = A[i+1]-A[i]
    
A_dist[N-1] = (K-A[N-1])+A[0]


A_dist_max = max(A_dist)
print(K-A_dist_max)

Measured memory_bytes: 34168
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, j, temp, sum = 0;
    number_n = Integer.parseInt(sc.next());
    int[] number = new int[number_n];
    int[] ball = new int [number_n];
    Arrays.fill(ball, 0);
    for (i = 0; i < number_n; i++) number[i] = Integer.parseInt(sc.next());
    for(i = number_n; i > 0; i--) {
      temp = 0;
      for(j = i; j <= number_n; j += i) {
        if(ball[j-1] == 1) temp++;
      }
      if(temp % 2 != number[i-1]) {
        ball[i-1] = 1;
        sum++;
      }
    }
    System.out.println(sum);
    temp = 0;
    for(i = 0; i < number_n; i++) {
      if(ball[i] == 1) {
        temp++;
        if(temp == sum) System.out.println((i + 1));
        else System.out.print((i + 1) + " ");
      }
    }
  }
}


Measured memory_bytes: 49684
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	char a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a == b && b == c)print("Yes");
	else if (b == c && c == d)print("Yes");
	else print("No");





	return 0;
}

Measured memory_bytes: 256
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll fac[2000+1];
ll power(ll x, ll y, ll p=mod)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p=mod)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll nCrModPFermat(ll n, ll r, ll p=mod)
{
   // Base case
   if (r==0)
      return 1;

    if(n<r)
    {
        return 0;
    }

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r


    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}
int main()
{
fast;

    fac[0] = 1;
    for (ll i=1 ; i<=2000; i++)
        fac[i] = (fac[i-1]*i)%mod;
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=1;i<=k;i++)
    {
        ans=(nCrModPFermat(k-1,i-1)*nCrModPFermat(n-k+1,i))%mod;
        cout<<ans<<endl;
    }

return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

	int n= sc.nextInt(),T=sc.nextInt();
	int min = 1010;


	for(Integer i=0; i<n;i++) {
		int c=sc.nextInt();
		int t=sc.nextInt();

		if(t<=T) {
			if(c<min) {
				min=c;

			}
		}
	}
	System.out.println(min<=1000?min:"TLE");
	}
}

Measured memory_bytes: 23252
solve1 :: Int -> Int -> Int -> Int -> IO()
solve1 x1 y1 x2 y2
  | x1 == x2 = if(y1 < y2)
               then putStrLn $ unwords (map show [x2 - diff, y2, x2 - diff, y1])
               else putStrLn $ unwords (map show [(x2 + diff), y2, (x2 + diff), y1])
  | otherwise = if(x1 < x2)
                then putStrLn $ unwords (map show [x2, (y2 + diff), x1, (y2 + diff)])
                else putStrLn $ unwords (map show [x2, (y2 - diff), x1, (y2 - diff)])
  where
    diff = max (abs (x1 - x2)) (abs (y1 - y2))

solve2 :: Int -> Int -> Int -> Int -> IO()
solve2 x1 y1 x2 y2
  | x1 < x2 && y2 < y1 = putStrLn $ unwords (map show [(x2 + diff2), (y2 + diff1), (x2 + diff2 - diff1), (y2 + diff1 + diff2)])
  | x1 < x2 && y1 < y2 = putStrLn $ unwords (map show [(x2 - diff2), (y2 + diff1), (x2 - diff2 - diff1), (y2 + diff1 - diff2)])
  | x2 < x1 && y1 < y2 = putStrLn $ unwords (map show [(x2 - diff2), (y2 - diff1), (x2 - diff2 + diff1), (y2 - diff1 - diff2)])
  | otherwise = putStrLn $ unwords (map show [(x2 + diff2), (y2 - diff1), (x2 + diff2 + diff1), (y2 - diff1 + diff2)])
  where
    diff1 = abs (x1 - x2)
    diff2 = abs (y1 - y2)

main = do
  [x1, y1, x2, y2] <- (map read . words) <$> getLine
  if(x1 == x2 || y1 == y2)
  then solve1 x1 y1 x2 y2
  else solve2 x1 y1 x2 y2

Measured memory_bytes: 508
#include<stdio.h>
#include<string.h>

int main(void)
{
  int n;
  char s[128];
  scanf("%d",&n);
  scanf("%s",s);
  int max=0;

  for(int i=1;i<n;i++){
    int count=0;
    for(char c='a';c<='z';c++){
      int flag1=0,flag2=0;
      for(int j=0;j<i;j++){
        if(s[j]==c){
          flag1=1;
        }
      }
      for(int k=i;k<n;k++){
        if(s[k]==c){
          flag2=1;
        }
      }
      if(flag1==1&&flag2==1){
        count++;
      }
    }
    if(count>max){
      max=count;
    }
  }


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


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

int n,x;
int a[100002];
int main(){
    while(cin>>n>>x){
        long long ans=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=1;i<n;i++){
            long long sum=a[i]+a[i-1];
            if(sum>x){
                long long temp=sum-x;
                if(temp<=a[i]){
                    a[i]-=temp;
                }else{
                    a[i]=0;
                    a[i-1]-=(temp-a[i]);
                }
                ans+=temp;
            }
        }
        cout<<ans<<endl;

    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e5+20;

int n,A[maxn],B[maxn];
vector<int>ea[maxn],eb[maxn];
int ra,rb;

inline void init()
{
	n=read();
	REP(i,1,n)
	{
		A[i]=read();
		if(~A[i])ea[A[i]].push_back(i);
		else ra=i;
	}
	
	REP(i,1,n)
	{
		B[i]=read();
		if(~B[i])eb[B[i]].push_back(i);
		else rb=i;
	}
}

int vis[maxn];

vector<int>ed[maxn];

int dfa(int u)
{
	int t=0;
	for(int v:ea[u])
	{
		int s=dfa(v);
		if(t)ed[s].push_back(t),ed[t].push_back(s),t=0;
		else t=s;
	}
	return t?t:(vis[u]|=1,u);
}


int dfb(int u)
{
	int t=0;
	for(int v:eb[u])
	{
		int s=dfb(v);
		if(t)ed[s].push_back(t),ed[t].push_back(s),t=0;
		else t=s;
	}
	return t?t:(vis[u]|=2,u);
}

int dis[maxn];

void dfs(int u)
{
	for(int v:ed[u])
	{
		if(!dis[v])dis[v]=dis[u]*-1,dfs(v);
	}
}

inline void doing()
{
	dfa(ra);
	dfb(rb);
	REP(i,1,n)if(vis[i]==1 || vis[i]==2)puts("IMPOSSIBLE"),exit(0);
	puts("POSSIBLE");
	REP(i,1,n)if(!dis[i] && vis[i]==3)dis[i]=1,dfs(i);
	REP(i,1,n)printf("%d ",dis[i]);
}

int main()
{
	init();
	doing();
	return 0;
}


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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

struct Edge {int to, cost; };
typedef pair<int, int> pint;

#define INF (1000L * 1000L * 1000L * 1000L)

class Dikstra {
private:
    int N;
    vector<vector<Edge>> edge_list;

public:
    Dikstra(vector< vector<Edge>> &edge_list) {
        this->edge_list = edge_list;
        this->N = edge_list.size();
    }

    Dikstra(int N) {
        this->edge_list = vector< vector< Edge>>(N, vector<Edge>());
        this->N = N;
    }

    void addEdge(int i, Edge e) {
        this->edge_list[i].pb(e);
    }

    vector<int> search(int s) {
        priority_queue<pint, vector<pint>, greater<pint> > que;
        vector<int> d(N, INF);
        d[s] = 0;
        que.push(make_pair(0, s));

        while (!que.empty()) {
            pint p = que.top();
            que.pop();

            int v = p.second;
            if (d[v] < p.first) continue;

            for (Edge e: edge_list[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }

        return d;
    }
};

signed main() {
    int N, M, L;
    cin >> N >> M >> L;

    Dikstra d(N);
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        d.addEdge(a, {b, c});
        d.addEdge(b, {a, c});
    }

    Dikstra d2(N);
    REP(i, N) {
        vector<int> dist = d.search(i);
        REP(j, N) {
            if (i == j) continue;

            if (dist[j] <= L) {
                d2.addEdge(i, {j, 1});
            }
        }
    }

    vector<vector <int>> ans(N, vector<int>(N, -1));
    REP(i, N) {
        vector<int> dist = d2.search(i);

        REP(j, N) {
            ans[i][j] = (dist[j] == INF) ? -1 : dist[j] - 1;
        }
    }

    int Q;
    cin >> Q;

    REP(i, Q) {
        int s, t;
        cin >> s >> t;
        s--; t--;

        cout << ans[s][t] << endl;
    }

    return 0;
}

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

int main()
{
  int n;
  cin >> n;

  for(int i = 0; i <= 100; i++){
    if(i*4 > n) break;

    for(int j = 0; j <= 100; j++){
      if(i*4 + j*7 > n) break;

      if(i*4 + j*7 == n){
        cout << "Yes" << endl;
        return 0;
      }

    }
  }

  cout << "No" << endl;

  return 0;

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	set<string> V;
	string T;
	string P="";
	int ret=0;
	FORR(c,S) {
		T+=c;
		if(T!=P) {
			P=T;
			T="";
			ret++;
		}
	}
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 720
def main():
  N=int(input())
  A=[int(a) for a in input().split()]
  cnt={}
  for a in A:
    cnt[a] = cnt.get(a, 0) + 1
  prob=0
  for a in cnt.values():
    prob+=a*(a-1)//2
    
  for a in A:
    print(prob-(cnt[a]-1))
  
main()



Measured memory_bytes: 32180
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long

int main()
{
	int ans;
	std::vector<int> v(4);

	REP(i,3){
	cin >> v[i];
	}

	sort(v.begin(),v.end(),greater<int>());

	ans = v[0]*10 + v[1] + v[2];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#   C

import numpy as np

N, K = map(int, input().split())

sum_poss = 0
for n in range(1, N+1):
    m0 = 0
    if n >= K:
        m0 = 0
    else:
        m0 = int(np.log2(K/n))
        if np.log2(K/n) - int(np.log2(K/n)) != 0:
            m0 += 1
#    print(m0, 1/(2**m0))
    sum_poss += 1/((2**m0)*N)
    
#sum_poss /= N


print(sum_poss)

Measured memory_bytes: 21376
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <cstdlib>
#define INF 998244353

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

const ll MOD = 1e9+7;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
/*
long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}*/

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

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

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

    // 素数である
    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int bubblesort(vector<int> array,int size){//バブルソート　転倒数
    int kaisu = 0;
    for(int i = 0; i < size; i++){
        for(int j = i + 1; j < size; j++){
            if(array[i] > array[j]){
                int number = array[i];
                array[i] = array[j];
                array[j] = number;
                kaisu++;
            }
        }
    }
    return kaisu;
}

ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = (sum * i)%MOD;
    }
    return sum;
}

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






Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        mut ab: [[usize; 2]; n],
    }
    ab.sort();
    debug!(ab);
    let mut end = 0;
    for i in 0..n {
        end += ab[i][1];
        if k <= end {
            println!("{}", ab[i][0]);
            return;
        }
    }

}


Measured memory_bytes: 9748
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int menu[m+10] = {0};
  for(int i = 1; i <= n; i++){
    int k;
    cin >> k;
    for(int j = 1; j <= k; j++){
      int k_i;
      cin >> k_i;
      menu[k_i] += 1;
    }
  }
  int ans = 0;
  for(int i = 1; i <= m; i++){
    if(menu[i] == n)ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	//#endif
 
	int x;
	cin>>x;
	int full = (x/500)*1000;
	int left = (x- (x/500)*500);
	int other = (left/5)*5;
	cout<<full+other;
}

Measured memory_bytes: 256
// CODE FESTIVAL 2016 qual C
// B - K個のケーキ / K Cakes

#include <cstdio>
#include <algorithm>
using namespace std;


int K, T;

int main() {

  int a, max_a;

  scanf("%d%d", &K, &T);
  max_a = 0;
  for (int i = 0; i < T; i++) {
    scanf("%d", &a);
    max_a = max(max_a, a);
  }

  printf("%d\n", max(max_a - (K - max_a) - 1, 0));

  return 0;

}




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

typedef long long LL;

const int N = 1e6+7;
int a[N];
int nxt[N], last[N];
int n;
LL k;

int f(int x, LL &sum) {
    sum += nxt[x];
    return (x+nxt[x])%n;
}

pair<LL, LL> floyd() {
    int h=0, t=0;
    LL hs=0, ts = 0;

    do {
        h = f(h, hs);
        h = f(h, hs);
        t = f(t, ts);
    } while (h!=t);

    LL pre = 0;
    t = 0;
    while (t!=h)    t = f(t, pre);

    return make_pair(pre, ts-pre);
}

bool is[N];

void simulate(vector<int> &v) {
    vector<int> ans;
    for (int x: v) {
        if (!is[x]) {
            is[x] = 1;
            ans.push_back(x);
        }
        else {
            while (ans.back()!=x) {
                is[ans.back()] = 0;
                ans.pop_back();
            }
            assert(ans.back() == x);
            is[ans.back()] = 0;
            ans.pop_back();
        }
    }
    v = ans;
}

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

    cin>>n>>k;

    for (int i=0; i<n; i++)        cin>>a[i];
    for (int i=n; i<2*n; i++)    a[i] = a[i-n];

    for (int i=2*n-1; i>=0; i--) {
        nxt[i] = last[a[i]]-i+1;
        last[a[i]] = i;
    }

    pair<LL, LL> ans = floyd();
    assert(ans.first == 0);
    assert(ans.second%n==0);

    LL len = (n*k)%ans.second;

    int cur = 0;
    LL sum = 0;

    while (true) {
        LL prv = sum;
        cur = f(cur, sum);
        if (sum > len) {
            sum = prv;
            break;
        }
    }
    LL rem = len - sum;
    assert(rem <= n);
//    cout<<":: "<<rem<<endl;

    vector<int> out;
    for (int i=0; i<rem; i++)
        out.push_back(a[n-1-i]);

    reverse(out.begin(), out.end());

//    for (int x: out)    cout<<x<<" "; cout<<endl;

    simulate(out);

    for (int x: out)    cout<<x<<" ";
}


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

int main(){
    int h, w, i, j, k;

    for(k = 0; ;k++){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) break;
        for(i = 0; i < h; i++){
            for(j = 0;j < w; j++){
                if(i % 2 == j % 2) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  ll cnt = 0;
  ll s = 0;
  for (int i = 0; i < N; i++) {
    ll a; cin >> a;
    if (a == 0) {
      cnt += s / 2;
      s = 0;
    }else {
      s += a;
    }
  }
  cnt += s / 2;
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define mod(i) (i%(ll)(1e9 + 7))


int main(){
	string s,ans = "";
	cin >> s;

	for(int i = 0;i < s.size(); i++){
		if(s[i] == 'B'){
			if(ans.size() > 0)ans.erase(ans.size()-1);    
		
		}else{
			ans+=s[i];
		}
	}     

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;


void func()
{
	int K;
	int ai;
	int ans = 1;

	cin >> K;
	ai = 7 % K;

	for (; ans <= K; ++ans)
	{
		if (ai == 0)
		{
			cout << ans << endl;
			return;
		}
		ai = (10 * ai + 7) % K;
	}
	cout << -1 << endl;
}

int main() {

	func();
	return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,y;
    cin>>x>>y;
    if (x == 0) {
    if (y > 0) cout << y;
    else cout << -y + 1;
    return 0;
  }
  if (y == 0) {
    if (x > 0) cout << x + 1;
    else cout << -x;
    return 0;
  }
  
  if(abs(x - y) > abs(x + y)) {
    if (x + y > 0) cout << x + y + 1;
    else cout << -(x + y) + 1;
  } else {
    if (x - y > 0) cout << x - y + 2;
    else cout << -(x - y);
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
  
int main()
{
    int H, W;
    int i, j;
  
    do{
        cin >> H >> W;
        if((H == 0) && (W == 0)) break;
  
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                if((i + j) % 2 == 0){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
	    cout << endl;
        }
 
        cout << endl;
  
    }while(1);
  
    return 0;
}

Measured memory_bytes: 1152
L, R = gets.split.map(&:to_i)

min_mod = 2019

for i in L..R-1
  for j in i+1..R
    if min_mod > i*j % 2019
      min_mod = i*j % 2019
    end
    if min_mod == 0
      puts 0
      exit
    end
  end
end

puts min_mod

Measured memory_bytes: 1788
#include <iostream>

using namespace std;
typedef long long ll;

int n, maxw;
int weight[105], value[105];

ll dp[105][100005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> maxw;
	for (int i = 1; i <= n; ++i) {
		cin >> weight[i] >> value[i];
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= maxw; ++j) {
			int prev_weight = j+weight[i];
			dp[i][j] = dp[i-1][j];
			if (prev_weight <= maxw) {
				dp[i][j] = max(dp[i][j], dp[i-1][prev_weight]+value[i]);
			}
		}
	}
	ll res = 0;
	for (int j = 0; j <= maxw; ++j) {
		res = max(res, dp[n][j]);
	}
	cout << res << "\n";
	return 0;
}

/*
	dp[i][j] = max value with item prefix 1..i with free space of j
	dp[i][j] = max(dp[i-1][j], dp[i-1][j+weight[i]] + value[i])

	res = max(dp[n][j]) over all j
*/


Measured memory_bytes: 79360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < 1 || b > 100) {
			throw new IllegalArgumentException("Input Number Error");
		}
		int area = a * b;
		int circumference = (a * 2) + (b * 2);
		System.out.println(area + " " + circumference);
	}
}


Measured memory_bytes: 26032
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 1000 * 1000 * 1000
using namespace std;
ll x , y;
int ans = 0;
int main()
{
	cin >> x >> y;
	while(x <= y)
	{
		ans ++;
		x *= 2;
	}
	cout << ans;

}


Measured memory_bytes: 256
#include<bitset>
#include<cstdio>

static char ibuf[1<<20|1], obuf[1<<20|1], *p1 = ibuf, *p2 = ibuf, *p3 = obuf;

struct IO {
	inline char gc() {
		return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20 | 1, stdin), p1 == p2) ? EOF : *p1++;
	}

	inline void flush() {
		fwrite(obuf, 1, p3 - obuf, stdout);
	}

	inline IO operator<<(char n) {
		if (p3 - obuf == (1 << 20 | 1)) fwrite(obuf, 1, 1 << 20 | 1, stdout), p3 = obuf;
		*p3++ = n;
		return *this;
	}

	inline bool get() {
		char n;
		do n = gc(); while (n < '#');
		return n == '#';
	}
} cin, cout;


std::bitset<503> r[503], b[503];

int main() {
	int N, M;

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

	for (int i = 1; i <= N; ++i) {
		r[i].set(1), b[i].set(M);
		i & 1 ? r[i].set() : b[i].set();
		r[i].reset(M), b[i].reset(1);
	}

	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
			if (cin.get()) r[i].set(j), b[i].set(j);

	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j)
			cout << (r[i][j] ? '#' : '.');
		cout << '\n';
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j)
			cout << (b[i][j] ? '#' : '.');
		cout << '\n';
	}
	cout.flush();
	return 0;
}



Measured memory_bytes: 1536
//06
#include<iostream>
#include<cstdlib>
#include<algorithm>

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  while(k--){
    int a,b;
    cin>>a>>b;
    cout<<min(min(a-1,n-a),min(b-1,n-b))%3+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
from collections import deque


def wfs(start):
    reached = [None] + [0] * N
    exit = [None] + [-1] * N
    q = deque()

    q.append(start)
    reached[start] = 1
    while q:
        p = q.popleft()
        for r in V[p]:
            if reached[r]:
                continue
            reached[r] = 1
            exit[r] = p
            q.append(r)

    return exit


N, M = map(int, input().split())
V = [None] + [[] for _ in range(N)]
for _ in range(M):
    A, B = list(map(int, input().split()))
    V[A].append(B)
    V[B].append(A)

exit = wfs(1)[2:]
if min(exit) == -1:
    print('No')
else:
    print('Yes')
    for e in exit:
        print(e)

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

using namespace std;

#define int long long

const int MAXN = 5e5 + 25;

int dp[MAXN][3];
int a[MAXN];

const int INF = 1e18 + 1188;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i <= n; ++i)
    {
        dp[i][0] = -INF;
        dp[i][1] = -INF;
        dp[i][2] = -INF;
    }
    dp[1][0] = a[0];
    dp[2][1] = a[1];
    dp[3][2] = a[2];
    dp[3][0] = a[2] + a[0];
    for (int i = 3; i < n; ++i)
    {
        dp[i + 1][0] = dp[i - 1][0] + a[i];
        dp[i + 1][1] = max(dp[i - 2][0], dp[i - 1][1]) + a[i];
        int c = max(dp[i - 2][1], dp[i - 1][2]);
        c = max(c, dp[i - 3][0]);
        dp[i + 1][2] = c + a[i];
    }
    if (n % 2)
    {
        int mx = dp[n][2];
        mx = max(mx, dp[n - 1][1]);
        mx = max(mx, dp[n - 2][0]);
        cout << mx << endl;
    }
    else
    {
        int mx = dp[n][1];
        mx = max(mx, dp[n - 1][0]);
        cout << mx << endl;
    }
    return 0;
}


Measured memory_bytes: 9892
from collections import Counter

n = int(input())
l = list(map(int, input().split()))
d = Counter(l)
if n%2 == 0 and 0 in l:
    print(0)
elif n%2 == 1 and d[0] != 1:
    print(0)
else:
    ans = 1
    for key, val in d.items():
        if key != 0 and val != 2:
            print(0)
            exit()
        if key == 0:
            continue
        ans*=2
        ans %= 1000000007
    print(ans)



Measured memory_bytes: 93388
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <string.h>

using namespace std;

void init() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}

long long sumSums(int a[], int b, int e) {

    long long sum = 0;
    for (int i = b; i <= e; i++) {
        sum += a[i];
    }
    return sum;

}

string removeZeros(string &s) {
    int c = 0;
    for (int i = 0; i < s.length(); i++) {

        if (s[i] == '0')
            c++;
    }
    for (int i = 0; i < c; i++) {
        s.erase(s.find('0'), 1);
    }
    return s;

}

bool isPrime(int a) {

    if (a == 1 || a == 0)
        return false;
    bool is = true;
    for (int i = sqrt(a); i >= 2; i--) {
        if ((a) % i == 0) {
            is = false;
            break;
        }
    }
    if (is)
        return true;
    else
        return false;

}

string intToString(int &a) {
    string s = "";
    while (a != 0) {
        char c = a % 10 + '0';
        a = a / 10;
        s = c + s;
    }
    return s;

}

int stringToInt(string &s) {
    int a = 0;
    int j = s.length() - 1;
    for (int i = 0; i < s.length(); i++) {
        int x = s[i] - '0';
        a += x * pow(10, j--);
    }
    return a;
}

int charToInt(char s) {

    return s - '0';
}

bool isPalindrome(int a) {

}

void print(int n) {
    for (int i = 1; i < n; i++) {
        cout << i << " ";
    }
    cout << n;
}

int sum(int a, int b) {

    return a + b;

}

int lenthOfInt(int a) {

    int c = 1;
    while (a != 0) {

        c++;
        a = a / 10;

    }
    return c;
}

int lengthfunction(int number) {
    int counter = 0;
    while (number) {
        number = number / 10;
        counter++;
    }
    return (counter);
}

/*bool isLuky(int a) {
    string s = intToString(a);
    for (int i = 0; i < s.length(); i++) {
        for (int j = i + 1; j < s.length(); j++) {
            if (i == j)
                continue;
            else if (s[i] == s[j]) {
                return false;
            }
        }
    }
    return true;

}*/

bool found(string s, int a) {

    for (int i = 0; i < a; i++) {
        if (s[a] == s[i])return true;
    }
    return false;
}

int nFound(string s[], int a) {

    int c = 0;
    for (int i = 0; i < a; i++) {
        if (s[a] == s[i])c++;
    }
    return c;
}

bool isLuky(int n) {
    string s = intToString(n);
    int is = true;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != '4' && s[i] != '7') {
            return false;

        }
    }

    return true;
}

bool isPalindrome(string str) {
    int l = 0;
    int h = str.length() - 1;

    while (h > l) {
        if (str[l++] != str[h--]) {

            return false;
        }
    }
    return true;
}

void swap(int &a, int &b) {
    int t = a;
    a = b;
    b = t;

}

int main() {

    init();
    int l;
    cin >> l;
    string s;
    cin >> s;
    if (s.length() > l)cout << s.substr(0, l ) << "...";
    else cout << s;
    return 0;

}

Measured memory_bytes: 3624
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	vector<ll>arr(n);
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			ans+=(arr[i]*arr[j]);
		}
	}
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

ll dp[1100][1100];

int main() {
    COMinit();
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;

    ll ans = 0;

    rep(i,1100)dp[i][0] = 1;

    srep(i,a,b+1){
        rep(j,n+1)dp[i][j] = dp[i-1][j];
        rep(j,n+1){
            if(dp[i-1][j] == 0)continue;
            if(j + i * c > n)break;
            ll invv = 1;
            rep(k,c){
                invv = invv * finv[i] % MOD;
            }
            srep(k,c,d+1){
                if(j + i * k > n)break;
                dp[i][j+i*k] += dp[i-1][j] * COM(n-j, i*k) % MOD * FINV(k) % MOD * fac[i*k] % MOD * invv % MOD;
                dp[i][j+i*k] %= MOD;
                invv = invv * finv[i] % MOD;
            }
        }
    }

    srep(i,a,b+1){
        ans += dp[i][n];
        ans %= MOD;
        // cout << dp[i][n] << endl;
    }

    cout << dp[b][n] << endl;
    return 0;
}



Measured memory_bytes: 21632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

string str;
ll w[M],e[M];

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

	ll n,i,mn;

	cin >> n;
	cin >> str;
	for(i=1;i<=n;++i)
	{
		w[i] = w[i-1];
		e[i] = e[i-1];
		if(str[i-1] == 'W')
			w[i]++;
		else
			e[i]++;
	}

	mn = n;
	for(i=1;i<=n;++i)
	{
		mn = min(mn,w[i-1]+e[n]-e[i]);
	}

	cout << mn << "\n";
}

Measured memory_bytes: 8464
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double s = r*r*pi;
        double c = r*2*pi;
        System.out.printf("%f %f\n", s, c);
        sc.close();
    }
}



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

typedef long long ll;
ll MOD = 1e9+7;
ll h[100000];
int main()
{
	int n,k;
	ll ans=1e11-1;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>h[i];
	
	sort(h,h+n);
	for(int i=k-1;i<n;i++)
		ans=min(h[i]-h[i-(k-1)],ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  int i,n=0;
  string a,b;
  
  cin>>a>>b;
  
  for(i=0;i<3;i++){
    if(a.at(i)==b.at(i))
      n++;
  }
  
  cout<<n;
  
  return 0;
}


Measured memory_bytes: 3192
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        int m = sc.nextInt();
        double ans = 0;
        double hh = h * 30 + 0.5 * m;
        double mm = 6 * m;
        double hm = (double)Math.abs(hh - mm);
        double cos = (double)Math.cos(Math.toRadians(hm));
        ans = Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * cos;
        System.out.println(Math.sqrt(ans));
    }
}

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

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    ll a1,a2;
    char c;
    while(1)
    {
        scanf("%lld %c %lld",&a1,&c,&a2);
        if(c=='?')
            break;
        if(c=='+')
            a1=a1+a2;
        if(c=='-')
            a1=a1-a2;
        if(c=='*')
            a1=a1*a2;
        if(c=='/'&&a2!=0)
            a1=a1/a2;
          printf("%lld\n",a1);
    }
    return 0;
}




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

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    int p[n];
    fill(p,p+n,k);
    for(int i=0; i<q; i++){
        int a;
        cin >> a;
        p[a-1]++;
    }
    for(int i=0; i<n; i++){
        if(p[i]-q > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int i;
  int n;
  int tmp;
  double gyakusu=0;
  double ans;

  scanf("%d", &n);

  for(i=1; i<=n; i++){
    scanf("%d", &tmp);
    gyakusu+=(double)1.0/tmp;
  }

  ans=1/gyakusu;

  printf("%lf\n", ans);

  return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	ll a, v;
	cin >> a >> v;
	ll b, w;
	cin >> b >> w;
	ll t;
	cin >> t;

	ll one = v - w;
	ll diff = abs(a - b);

	if(w >= v){
		cout << "NO" << endl;
		return 0;
	}
	ll A = v * t; // 二人野動ける距離。
	ll B = w * t;
	if(A - B >= diff){
		puts("YES");
	} else {
		puts("NO");
	}
}


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

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

    //good luck kittu!
    int n, l; cin>>n>>l;
    vector<string> s(n);
    for(int i = 0; i<n; i++) cin>>s[i];
    sort(s.begin(), s.end());
    for(string x : s) cout<<x;
    return 0;
}

Measured memory_bytes: 256
import java.util.BitSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static int n;
	public static int[][] map;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			n = in.nextInt();
			if(n == 0) return;
			map = new int[n][n+1];
			int bitmax = 1<<n;
			for(int i=0; i<n; i++){
				for(int j=0; j<=n; j++){
					map[i][j] = in.nextInt();
				}
			}
			BitSet used = new BitSet(bitmax);
			Queue<State> qu = new PriorityQueue<State>();
			qu.add(new State(0, 0));
			while(!qu.isEmpty()){
				State s = qu.poll();
				if(used.get(s.bit)) continue;
				if(s.bit == bitmax-1){
					System.out.println(s.time);
					break;
				}
				used.set(s.bit);
				for(int i=0; i<n; i++){
					if((s.bit & 1<<i) > 0) continue;
					qu.add(new State(s.bit | 1<<i
							, s.time + best(s.bit, i)));
				}
			}
		}
	}
	
	public static int best(int used, int idx){
		int res = map[idx][0];
		for(int i=0; i<n; i++){
			if((used & 1<<i) == 0) continue;
			res = Math.min(res, map[idx][i+1]);
		}
		return res;
	}
}

class State implements Comparable<State>{
	int bit;
	int time;
//	int bc;
	public State(int bit, int time){
		this.bit = bit;
		this.time = time;
//		bc = Integer.bitCount(bit);
	}
	
	@Override
	public int compareTo(State o) {
//		if(bc != o.bc) return bc-o.bc;  
		return time-o.time;
	}
}

Measured memory_bytes: 99508
//abc101_b.cpp
//Sat Jun 23 20:52:56 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
using ll=long long;

int main(){
	int n;
	cin >> n;

	int m = n;

	int s = 0;
	while (m>0){
		s += m%10;
		m = floor(m/10);
	}

	if (n%s == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N, K, X, Y;
	int ans = 0;
	int i = 1;
	cin >> N >> K >> X >> Y;
	
	while(i <= K && i <= N){
		ans += X;
		i++;	
	}
	
	while(i <= N){
		ans += Y;	
		i++;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

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

    int p = pow(2, M);

    int result;
    result = p*((1900*M)+(N-M)*100);

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 384
#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(){
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(10) << W * H / 2.0 << endl;
  if(2 * x == W && 2 * y == H){
    cout << 1 << endl;
    return 0;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n,r,i;
	char s[256],t[256],c;
	string p;
	while(scanf("%d",&n),n)
	{
		map<string,vector<string> >m;
		queue<string>q;
		while(n--)
		{
			scanf(" %[a-z]:",s);
			if(q.empty())q.push(s);
			for(;;)
			{
				scanf(" %[a-z]%c",t,&c);
				m[s].push_back(t);
				if(c=='.')break;
			}
		}
		r=0;
		map<string,bool>c;
		while(q.size())
		{
			p=q.front();q.pop();
			if(c[p])continue;
			c[p]=1;
			if(m.find(p)!=m.end())
				for(i=0;i<m[p].size();++i)q.push(m[p][i]);
			else ++r;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**8)

N = int(input())
X = str(input())
ones = X.count('1')
intX = int(X, 2)
def check(n, r):
    if n == 0:
        return print(r)
    d = str(bin(n)).count('1')
    check(n%d, r+1)

if ones > 1:
    Xplus = intX % (ones + 1)
    Xminus = intX % (ones - 1)
else:
    Xplus = intX % (ones + 1)
    Xminus = intX

for i in range(N):
    e = 1
    if X[i] == '0':
        num = (Xplus + pow(2, N-1-i, ones + 1)) % (ones + 1)
    elif X[i] == '1' and ones > 1:
        num = (Xminus - pow(2, N-1-i, ones - 1)) % (ones - 1)
    else:
        num = (Xminus - pow(2, N-1-i))
        e = 0
    check(num, e)

Measured memory_bytes: 9552
#include <stdio.h>
#include <string.h>
#define N 200000000
#define INF 2000000001

int size;
int heap[N];

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= size && heap[l] > heap[i]) valM = l;
  else valM = i;
  if(r <= size && heap[r] > heap[valM]) valM = r;
  if(valM != i){
    swap(&heap[i], &heap[valM]);
    maxHeapify(valM);
  }
}

void heapIncreaseKey(int i, int key){
  if(key < heap[i]) return;
  heap[i] = key;
  while(i>1 && heap[i/2]<heap[i]){
    swap(&heap[i], &heap[i/2]);
    i = i/2;
  }
}

void maxHeapInsert(int key){
  size++;
  heap[size] = -INF;
  heapIncreaseKey(size, key);
}

int heapExtractMax(){
  int valM;
  if(size < 1) return 0;
  valM = heap[1];
  heap[1] = heap[size--];
  maxHeapify(1);
  return valM;
}

main(){
  char input[20];
  size = 0;
  while(scanf("%s", input)){
    if(!strcmp(input, "end")) break;
    if(!strcmp(input, "extract")) printf("%d\n", heapExtractMax());
    else{
      char val[20];
      scanf("%s", val);
      maxHeapInsert(atoi(val));
    }
  }
  return 0;
}

Measured memory_bytes: 4328