akhauriyash/Code-Regression huggingface dataset:
from collections import deque

s = deque(list(input()))
#print(s)
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)
# True -> straight, False -> back
order_flag = True

for query in queries:
  if query.startswith("1"):
    order_flag = not order_flag
  elif query.startswith("2"):
    if query[2] == "1":
      if order_flag:
        s.appendleft(query[4])
      else:
        s.append(query[4])
    elif query[2] == "2":
      if order_flag:
        s.append(query[4])
      else:
        s.appendleft(query[4])
        
if order_flag:
  print(''.join(list(s)))
else:
  s.reverse()
  print(''.join(list(s)))

Measured memory_bytes: 21092
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = []

    for i in range(N):
        a, b = map(int, input().split())
        A.append((a, b))

    A = sorted(A, key=lambda x: x[1])

    time = 0

    for a, b in A:
        time += a
        if time > b:
            return 'No'

    return 'Yes'

print(main())

Measured memory_bytes: 33416
from collections import Counter
import itertools
import math
def prime(n):
    ma=int(math.sqrt(n))+1
    li=[i for i in range(2,n+1)]
    primes=[]
    while li[0]<=ma:
        primes.append(li[0])
        tmp=li[0]
        li=[i for i in li if i%tmp!=0]
    primes.extend(li)
    return primes

n=int(input())
if(n<10):
    print(0)
    exit()
primes=prime(n+1)
factor=[]
for i in range(2,n+1):
    tmp=i
    for k in primes:
        while(tmp%k==0):
            tmp//=k
            factor.append(k)
values,counts=zip(*Counter(factor).most_common())
counts=list(counts)
ans=0
for i in counts:
    if(i>=74):
        ans+=1
for k in itertools.combinations(counts,2):
    if(k[0]>=2 and k[1]>=24):
        ans+=1
    if(k[0]>=4 and k[1]>=14):
        ans+=1
    if(k[0]>=24 and k[1]>=2):
        ans+=1
    if(k[0]>=14 and k[1]>=4):
        ans+=1
for k in itertools.combinations(counts,3):
    if(k[0]>=2 and k[1]>=4 and k[2]>=4):
        ans+=1
    if(k[1]>=2 and k[2]>=4 and k[0]>=4):
        ans+=1
    if(k[2]>=2 and k[1]>=4 and k[0]>=4):
        ans+=1
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;


int main()
{


    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);

    int n, k=1000,x=0;
    cin>>n;
    int j=1;
    while(x<n){
        x+=k;

    }
    cout<<x-n<<endl;


}


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

int main()
{
    long long N, K, Q;
    cin >> N >> K >> Q;
    vector<long long> points(N);
    vector<long long> ans(N, 0);

    long long a;
    for(int i=0;i<Q;i++){
        cin >> a;
        --a;
        ++ans[a];
    }

    for(int i=0;i<N;i++){
        if(K - Q + ans[i] > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}

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

int main() {
    int64_t N;
    vector<int64_t> num(3);
    cin >> N >> num[0] >> num[1] >> num[2];

    vector<string> s(N);
    for (string& S : s) {
        cin >> S;
    }

    vector<char> ans;

    for (int64_t i = 0; i < N; i++) {
        int64_t i0 = s[i][0] - 'A';
        int64_t i1 = s[i][1] - 'A';
        if (i0 > i1) {
            swap(i0, i1);
        }
        if (num[i0] == 0 && num[i1] == 0) {
            cout << "No" << endl;
            return 0;
        }

        if (num[i0] > num[i1]) {
            ans.push_back('A' + i1);
            num[i0]--;
            num[i1]++;
        } else if (num[i0] < num[i1]) {
            ans.push_back('A' + i0);
            num[i0]++;
            num[i1]--;
        } else {
            if (i == N - 1) {
                ans.push_back('A' + i1);
                num[i0]--;
                num[i1]++;
                break;
            }

            int64_t ni0 = s[i + 1][0] - 'A';
            int64_t ni1 = s[i + 1][1] - 'A';
            
            if (i1 == ni0 || i1 == ni1) {
                ans.push_back('A' + i1);
                num[i0]--;
                num[i1]++;
            } else {
                ans.push_back('A' + i0);
                num[i0]++;
                num[i1]--;
            }
        }

        assert(num[0] >= 0 && num[1] >= 0 && num[2] >= 0);
    }

    assert(ans.size() == N);

    cout << "Yes" << endl;
    for (char c : ans) {
        cout << c << endl;
    }
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int sum,n,s[200];
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i]; sum+=s[i];
    }
    sort(s+1,s+1+n);

    if(sum%10==0){
        for(int i=1;i<=n;i++){
            if(s[i]%10){sum-=s[i];break;}
        }
    }

    if(sum%10==0) cout<<0<<newl;
    else cout<<sum<<newl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


void f(int h, int w) {
  vector<vector<int>> g(h * 2 + 1, vector<int>(w * 2 + 1, -1));
  queue<pair<int, int>> que;
  vector<int> vy = {0, 1, 0, -1};
  vector<int> vx = {1, 0, -1, 0};
  for (int i=1; i<h*2; ++i) {
    if (i%2 == 1) for (int j=2; j<w*2; j+=2) cin >> g[i][j];
    else for (int j=1; j<w*2+1; j+=2) cin >> g[i][j];
  }
  g[1][1] = 1;

  rep (i, 4) if (g[1+vy[i]][1+vx[i]] == 0) {
    que.push(make_pair(1+vy[i]*2, 1+vx[i]*2));
    g[1+vy[i]*2][1+vx[i]*2] = 2;
  }
  while (!que.empty()) {
    int y, x;
    tie(y, x) = que.front();  que.pop();

    rep (i, 4) if (g[y+vy[i]][x+vx[i]] == 0) {
      if (y+vy[i]*2 == h*2-1 && x+vx[i]*2 == w*2-1) {
        cout << g[y][x] + 1 << endl;
        return;
      }

      if (g[y+vy[i]*2][x+vx[i]*2] == -1) {
        que.push(make_pair(y+vy[i]*2, x+vx[i]*2));
        g[y+vy[i]*2][x+vx[i]*2] = g[y][x] + 1;
      }
    }
  }

  cout << 0 << endl;
  return;
}


int main() {
  int w, h;
  cin >> w >> h;
  while (!(w == 0 && h == 0)) {
    f (h, w);
    cin >> w >> h;
  }
}


Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(void){
  int n;
  int cases=1;

  while(cin >> n && n){
    int lines = n*2-1;
    int mid = lines/2;
    int f[n][n];
    int num;
    int val=1;
    for(int i=0;i<lines;i++){
      if(i<mid){
	num = i+1;
      }else if(i==mid){
	num = n;
      }else{
	num = n-(i-mid);
      }
      bool order;
      i%2?order=true:order=false;
      for(int j=0;j<num;j++){
	if(i <= mid){
	  if(order){
	    f[j][i-j] = val++;
	  }else{
	    f[i-j][j] = val++;
	  }
	}else{
	  if(!order){
	    f[n-j-1][i-n+1+j] = val++;
	  }else{
	    f[i-n+1+j][n-j-1] = val++;
	  }
	}
      }
    }

    printf("Case %d:\n", cases++);
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	printf("%3d", f[i][j]);
      }
      printf("\n");
    }
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final long N = sc.nextLong();
		
		long count = 0;
		
		count = 2 * (N/11);
		int rest = (int) (N%11);
//		System.out.println(count);
		if(rest ==0) {
			count +=0;
		}else if(rest<=6) {
			count +=1;
		}else {
			count +=2;
		}
		
		System.out.println(count);
		sc.close();
	}
}


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

int main(void){
char x[11];
int minval = 1000;

  
cin >> x;
for (int i=0;i<11;i++){
 int v = (int)(x[i]-0x30)*100+(int)(x[i+1]-0x30)*10+(int)(x[i+2]-0x30)*1;
 //cout << v << endl;
 int a = 0;
 if (v>=753) a = v-753; else a = 753-v;
 if (minval>a)minval=a;
 //cout << a << endl;
 if (x[i+3]==0){
   break;
 }
}
cout << minval << endl;

};

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int x, y, gcd, box;
  scanf("%d %d", &x, &y); 
  box = 0;
  while(1){
    if (x < y){
      box = x;
      x = y;
      y = box;
    }
    x %= y;
    if (x == 0){
      break;
    }
  }
  printf("%d\n", y);
}
    

Measured memory_bytes: 1796
#include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    double r;
    cin >> r;
    double s, l;
    s = M_PI*r*r;
    l = 2*r*M_PI;
    printf("%.7f %.7f\n", s, l);
    return 0;
}



Measured memory_bytes: 3108
const main = (input) => {
  input = input.trim().split('\n')

  const n = input[1].split(' ').map(Number).sort((a, b) => a - b)
  const biggest = n[n.length-1]
  const arr = new Array(biggest+1).fill(0)

  for (let i=0; i<n.length; i++) {
    for (let v=n[i]; v<=biggest; v+=n[i]) {
      arr[v]++
    }
  }

  let ans = 0
  for (let i=0; i<n.length; i++) {
    if (arr[n[i]] === 1) ans++
  }

  return console.log(ans)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

vector<long long> nums;
long long dp[100010];

long long ans(int k){
    if(dp[k]!=-1) return dp[k];
    if(k==1) return dp[1]=0;
    if(k==2) return dp[2]=abs(nums[k]-nums[k-1]);
    if(k==3) return dp[3]=min(ans(2)+abs(nums[3]-nums[2]), abs(nums[3]-nums[1]));
    return dp[k]=min(ans(k-1)+abs(nums[k]-nums[k-1]), ans(k-2)+abs(nums[k]-nums[k-2]));
}

int main(){
    int n;
    memset(dp, -1, sizeof dp);
    long long aux;
    cin>>n;
    nums.push_back(0);
    for(int i=1; i<=n; i++){
        cin>>aux;
        nums.push_back(aux);
    }
    cout<<ans(n)<<endl;
}


Measured memory_bytes: 4340
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

struct BIT
{
	//[0,mn]
	vector<int> node;
	int mn;

	BIT(int mn)
	{
		this->mn = mn;
		node.resize(mn + 1, 0);
	}

	void add(int i, int x)
	{
		while (i <= mn)
		{
			node[i] += x;
			i += (i&-i);
		}
	}

	int sum(int i)
	{
		int res = 0;
		while (i > 0)
		{
			res += node[i];
			i -= (i&-i);
		}
		return res;
	}
};

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

	int N;
	cin >> N;
	vector<pii> A(N);
	vector<vector<int>> DP(N+1, vector<int>(N+1, 0));

	rep(i, 0, N)
	{
		cin >> A[i].first;
		A[i].second = i;
	}

	sort(all(A), greater<pii>());

	int ans = 0;
	rep(i, 0, N)
	{
		rep(j, 0, i + 1)
		{
			chmax(DP[j + 1][i - j], DP[j][i - j] + A[i].first*abs(A[i].second - j));
			chmax(DP[j][i - j + 1], DP[j][i - j] + A[i].first*abs(A[i].second - (N - 1 - (i - j))));
			chmax(ans, DP[j + 1][i - j]);
			chmax(ans, DP[j][i - j + 1]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 34600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var dct = Primefactrize(N);
            var ans = 0L;
            foreach (var v in dct.Values)
            {
                var i = 1;
                while (i * i + i <= 2 * v) ++i;
                ans += i - 1;
            }
            WriteLine(ans);

        }
        static Dictionary<long, long> Primefactrize(long n)
        {
            var primes = new Dictionary<long, long>();
            for (var i = 2L; i * i <= n; ++i)
            {
                while (n % i == 0)
                {
                    if (!primes.ContainsKey(i)) primes[i] = 0;
                    ++primes[i];
                    n /= i;
                }
            }
            if (n != 1) primes[n] = 1;
            return primes;
        }
    }
}

Measured memory_bytes: 28288
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    ll i,ans=1;
    if(abs(m-n)>1){
    	cout<<0<<endl;
    	return 0;
    }
    
    if(m!=n){
    	f(i,1,n+1){
    		ans*=i;
    		ans%=mod;
    	}
    	f(i,1,m+1){
    		ans*=i;
    		ans%=mod;
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    else{
    	f(i,1,n+1){
    		ans*=i;
    		ans%=mod;
    	}
    	ans*=ans;
    	ans%=mod;
    	ans*=2;
    	ans%=mod;
    	cout<<ans<<endl;
    	return 0;

    }

    
}



Measured memory_bytes: 256
import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())

    J = [[] for _ in range(M)]
    for a, b in zip(*[iter(AB)] * 2):
        if a > M:
            continue
        J[a - 1].append(b)

    hq = []
    ans = 0
    for i in range(M):
        for b in J[i]:
            heappush(hq, -b)
        if hq:
            ans += -heappop(hq)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 101324
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>
#include <stack>
#include <vector>
#include <array>


int main(){

    //stack<int> s;
  int A,B;
  cin >>A >>B;
  int m;
  m=max(A+B,A*B);
  m=max(m,A-B);
  cout<<m;


  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> path(n);
    vector<int> d(n,inf),ans(n,-1);

    d[0]=0;

    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }

    priority_queue<pp, vector<pp>, greater<pp>> pq;
    pq.push(mk(0,0));

    int cost,s,md=0,mp;
    while(!(pq.empty())){
            tie(cost,s)=pq.top(); pq.pop();
            if(cost!=d[s]) continue;
            for(auto p : path[s]){
                if(d[p]>cost+1){
                    d[p]=cost+1;
                    pq.push(mk(d[p],p));
                    if(md<=d[p]){
                        md=d[p];
                        mp=p;
                    }
                }
            }
    }
    queue<int> que;
    que.push(0);
    while(!(que.empty())){
        s=que.front(); que.pop();
        for(auto to:path[s]){
            if(d[s]==d[to]-1 && ans[to]==-1){
                ans[to]=s+1;
                que.push(to);
            }
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 11304
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

#define N 200

int stack[N];
int sp = 0;

void push(int v)
{
  stack[sp++] = v;
}

int pop(void)
{
  return stack[--sp];
}

int main(void)
{
  char c[200];
  int x, v1, v2;
  while( scanf("%s", c) != EOF ){
    if ( c[0] == '+' ){
      v1 = pop();
      v2 = pop();
      push(v2+v1);
    } else if ( c[0] == '-' ){
      v1 = pop();
      v2 = pop();
      push(v2-v1);
    } else if ( c[0] == '*' ){
      v1 = pop();
      v2 = pop();
      push(v2*v1);
    } else {
      x = atoi(c);
      push(x);
    }
  }

  cout << stack[0] << endl;

  return 0;
}


Measured memory_bytes: 3244
//#include "/Users/the_sun/stdc++.h"
#include <bits/stdc++.h>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

#define pub push_back
#define pob pop_back
#define F first
#define S second
#define PI acos(-1)

typedef long long ll;

const int MAXN = 1e5 + 7;
const ll MAXL = 1e18;
const int N = 1e7;
const long double eps = 1e-11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    if ((a - b - 1) % 2) {
        cout << "Alice\n";
    }
    else {
        cout << "Borys\n";
    }
    return 0;
}


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

using namespace std;

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

    int cnt = 0;
    int ok = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'b') cnt++;

        if (s[i] == 'a' and ok < a + b) {
            ok++;
            cout << "Yes" << endl;
        } else if (s[i] == 'b' and ok < a + b and cnt <= b) {
            ok++;
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 896
while True:

    N = int(input())

    if N == 0:
        break

    ans = 0

    lis = [0]

    for i in range(1000):

        lis.append(lis[-1] + i+1)

    for i in range(1001):

        for j in range(i-1):

            if lis[i] - lis[j] == N:
                ans += 1

    print (ans)



Measured memory_bytes: 5600
n = int(input())
l = []
if n%2==1:
    for i in range((n-1)//2):
        l.append([i+1,n-1-i])
    l.append([n,n])
else:
    for i in range(n//2):
        l.append([i+1,n-i])
ans = []
for i in range(len(l)):
    for j in range(len(l)):
        if i==j:
            continue
        ret1 = [l[i][0],l[j][0]]
        ret2 = [l[i][0],l[j][1]]
        ret3 = [l[i][1],l[j][0]]
        ret4 = [l[i][1],l[j][1]]
        ret1.sort()
        ret2.sort()
        ret3.sort()
        ret4.sort()
        ret = [ret1,ret2,ret3,ret4]
        for ret_ in ret:
            if not ret_ in ans:
                ans.append(ret_)
print(len(ans))
for ans_ in ans:
    print(ans_[0],ans_[1])

Measured memory_bytes: 4132
#include <stdio.h>
int r[1005],c[1005];
int main()
{
    int row,col;
    scanf("%d%d",&row,&col);
    int i,j;
    char matrix[row][col];
    for(i=0;i<row;i++)
        scanf("%s",matrix[i]);
        if(row==1)
        {
            for(j=0;j<col;j++)
                if(matrix[0][j]=='#') printf("#");
            printf("\n");
            return 0;
        }
        if(col==1)
        {
            for(i=0;i<row;i++)
                if(matrix[i][0]=='#') printf("#\n");
            return 0;
        }
    for(j=0;j<col;j++)
    {
        for(i=1;i<row;i++)
        {
            if(matrix[i][j]=='#'||matrix[i-1][j]=='#') break;
        }
        if(i==row) c[j]=-1;
    }
    for(i=0;i<row;i++)
    {
        for(j=1;j<col;j++)
        {
            if(matrix[i][j]=='#'||matrix[i][j-1]=='#') break;
        }
        if(j==col) r[i]=-1;
    }
    for(i=0;i<row;i++)
    {
        if(r[i]!=-1)
            for(j=0;j<col;j++)
            {
                if(c[j]==0) printf("%c",matrix[i][j]);
            }
        if(r[i]!=-1) printf("\n");
    }
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>

const int vertical = 2;  //今回も　2×3　以外のパターンもできるように
const int side = 3;      //ここの変数を変えれば一応どんな行列にも対応できるようにしたい　//2×3以外で試してないけど…

int main() {
	int count = 0,a;
	bool flag;
	std::vector<std::string> v;
	std::vector<std::vector<std::string>> vv;
	
	v.resize(vertical);
	vv = std::vector<std::vector<std::string>>(vertical, std::vector<std::string>(side));

	for (int i = 0; i < vertical; i++) {
		std::cin >> v[i];
		for (int j = 0; j < side; j++) {
			vv[i][j] = v[i].substr(j, 1);
		}
	}


	for (int i = 0; i <vertical/2; i++) {
		for (int j = 0; j <side; j++) {
			count += vv[i][j] == vv[vertical - 1 - i][side - 1 - j] ? 1 : 0;
		}
	}

	flag=count == side;
	std::cout <<( flag ? "YES" : "NO") << std::endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0

    for i in range(N):
        if a[i] >= b[i]:
            ans += b[i]
        else:
            if a[i+1] >= (b[i] - a[i]):
                ans += b[i]
                a[i+1] = a[i+1] - (b[i] - a[i])
            else:
                ans += (a[i+1]+a[i])
                a[i+1] = 0
    return int(ans)
if __name__ == '__main__':
    print(main())

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

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

const int N = 1e5+34;

pair<int, int> a[N];

void solve() {
	int n, h; scanf("%d%d", &n, &h);
	int m = -1;
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &a[i].second, &a[i].first);
		m = max(m, a[i].second);
	}
	sort(a, a+n, greater<pair<int, int>>());
	long long tot = 0;
	int ans = 2e9;
	for (int i = 0; i <= n; ++i) {
		int x = max(0LL, h-tot);
		ans = min(ans, i+(x+m-1)/m);
		if (i == n) break;
		tot += a[i].first;
	}
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

long fct(long a,long b){
    a=long((a+b-1)/b)*b;
    return a;
}

int main(){
    int N;cin>>N;
    long T,A;cin>>T>>A;
    long p=T,q=A,nextp,nextq;
    for(int i=1;i<N;i++){
        cin>>T>>A;
        nextp=fct(p,T);
        nextq=fct(q,A);
        if(nextp/T*A-q<0){
            q=nextq;
            p=nextq/A*T;
        }
        else if(nextq/A*T-p<0){
            p=nextp;
            q=nextp/T*A;
        }
        else if(nextp>=nextq){
            p=nextp;
            q=nextp/T*A;
        }
        else{
            q=nextq;
            p=nextq/A*T;
        }
    }

    cout<<p+q<<endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
D - Walk and Teleport
https://atcoder.jp/contests/arc067/tasks/arc067_b

"""
import sys


def solve(N, A, B, X):
    gaps = [z-y  for y, z in zip(X, X[1:])]
    ans = 0
    for g in gaps:
        if g*A <= B:
            ans += g*A
        else:
            ans += B
    return ans


def main(args):
    N, A, B = map(int, input().split())
    X = [int(x) for x in input().split()]
    ans = solve(N, A, B, X)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 14228
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<pair<int, int>>  a(3);
    for(int i=0;i<3;i++) {
        int pre, back;
        cin >> pre >> back;
        if(pre > back) {
            a[i] = make_pair(back, pre);
        } else{
            a[i] = make_pair(pre, back);
        }
    }
    sort(a.begin(), a.end(), [](auto &left, auto &right) {return left.first < right.first;});
    for(int i=0;i<3;i++){
    //    cout << a[i].first << a[i].second << endl;
    }
    int posi = 1;
    int gone[4] = {0};
    gone[0] = 1;
    for(int i=0;i<3;i++) {
//        cout << posi << endl;
//        for (auto itr=a.begin();itr!=a.end();++itr){
//            cout << (*itr).first <<(*itr).second << endl;
//        }
        for(auto itr=a.begin();itr!=a.end();itr++) {
            if (posi == (*itr).first) {
                posi = (*itr).second;
                gone[posi-1] = 1;
                a.erase(itr);
                break;
            } else if(posi == (*itr).second) {
                posi = (*itr).first;
                gone[posi-1]=1;
                a.erase(itr);
                break;
            }
        }
    }
//    for (int i=0;i<4;i++){
//        cout << gone[i];
//    }
    int sol[4] = {1,1,1,1};
    if(posi == 4){
        if(equal(gone, gone+4, sol)){
            cout << "YES";
        }else{
            cout << "NO";
        }
    } else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 384
solve ss = (show hour) ++ ":" ++ (show minute) ++ ":" ++ (show second)
  where
    hour = ss `div` 3600
    minute' = ss `mod` 3600
    minute = minute' `div` 60
    second = minute' `mod` 60

main = do
  s <- readLn :: IO Int
  putStrLn $ solve s



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A + B + C >= 22)cout << "bust" << endl;
    else cout << "win" << endl;
}

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

int main(){
    int n, x;
    cin >> n;
    vector<int> d(n,200);
    for(int i = 0;i<n;i++){
        cin >> x;
        for(int j = 0;j<n;j++){
            if(x == 200) break;
            if(d[j]>x){
                int temp = d[j];
                d[j] = x;
                x = temp;
            }
            if(d[j] == x) break;
        }
    }
    int sum = 0;
    for(int i = 0;i<n;i++){
        if(d[i] != 200) sum++;
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
    int64_t h;
    cin >> h;

    int64_t ans = 0;
    for (int64_t i = 1; h != 0; i <<= 1) {
        h /= 2;
        ans += i;
    }

    cout << ans << endl;
}

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

int main(){
    double n,x,t;
    int aaa;

    cin >> n >> x >> t;

    aaa=(int)ceil(n/x);

    cout << (int)(aaa*t) << endl;

    return(0);
}


Measured memory_bytes: 3716
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=2e5+100;
const double eps=1e-10;
bool vis[MAXN];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF){
        int u,v;
        bool flag=false;
        for(int i=1;i<=n;i++)
            vis[i]=false;
        for(int i=1;i<=m;i++){
            scanf("%d%d",&u,&v);
            if(flag) continue;
            if(u==1){
                if(vis[v]){
                    flag=true;
                }
                vis[v]=true;
            }else if(v==n){
                if(vis[u]){
                    flag=true;
                }
                vis[u]=true;
            }
        }
        if(flag) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		String N=scan.next();
    		if (N.charAt(0)==N.charAt(2)) {
    			System.out.print("Yes");
    		}else {
    			System.out.print("No");
    		}

    		
    	
  
    				
 
     
    }
    }

Measured memory_bytes: 23124
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;


int main() {
    string s;
    cin >> s;
    for(auto c: s) {
        if (c == '1') cout << '9';
        else if (c == '9') cout << '1';
        else return 1;
    }
    cout << endl;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def f(n, x):
    if n == -1:
        return 0
    else:
        return n // x + 1


def main():
    a, b, x = map(int, input().split())

    ans = f(b, x) - f(a - 1, x)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
#define MOD 1000000007
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = 2147493647;
const double pi = acos(-1);
const double EPS = 1e-9;

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


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int arr[N];
  int cntr = 0;
  for(int i = 0; i < N; i++){
  	cin >> arr[i];
    if((i+1) % 2 == 1 && arr[i] % 2 == 1)
      cntr++;
  }
  cout << cntr;
}

Measured memory_bytes: 3588
#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>;

vector<set<int>> to;
vector<bool> seen;
int cnt;

void dfs(int i) {
  cnt++;
  seen[i] = true;
  for (auto d : to[i]) {
    if (seen[d]) continue;
    dfs(d);
  }
}

int main(){
  int n, m;
  cin >> n >> m;
  to.resize(n);
  int ans = 0;
  seen.assign(n,false);
  vector<int> size(n);
  size.resize(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].insert(b);
    to[b].insert(a);
  }
  cnt = 0;
  rep(i,n) {
    if (seen[i]) continue;
    dfs(i);
    size[i] = cnt;
    cnt = 0;
  }
  rep(i,n) ans = max(ans, size[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 38156
/*5_3 hightierra*/
#include <stdio.h>
#define LIMIT 100

int main(void){
    int row,col,i,j,rowjudge[LIMIT]={0},coljudge[LIMIT]={0};
    char matrix[LIMIT][LIMIT];
    scanf("%d %d",&row,&col);

    // 初期化
    for(i=0; i<LIMIT; i++){
        for(j=0; j<LIMIT; j++){
            matrix[i][j]=0;
        }
    }

    // 入力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            scanf(" %c",&matrix[i][j]);
        }
    }

    // 各行、各列に黒が１つでもあるかを判別
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(matrix[i][j]=='#'){
                rowjudge[i]=1;
            }
        }
    }
    for(j=0; j<col; j++){
        for(i=0; i<row; i++){
            if(matrix[i][j]=='#'){
                coljudge[j]=1;
            }
        }
    }

    // 黒が１つでもある行と列の重なる要素のみを出力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(rowjudge[i]==1 && coljudge[j]==1){
                printf("%c",matrix[i][j]);
            }
        }
        if(rowjudge[i]==1){
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(){
    char s[4]={0};
    int  ans=0;
    scanf("%s", s);
    if     ( strcmp(s, "RRR")==0 ){ ans=3; }
    else if( strcmp(s, "SSS")==0 ){ ans=0; }
    else if( strcmp(s, "RRS")==0 ){ ans=2; }
    else if( strcmp(s, "SRR")==0 ){ ans=2; }
    else                          { ans=1; }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
using ll = long long;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repp(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)


int main() {
  int x;  cin >> x;
  if (x == 1) cout << 0;
  else cout << 1;
  cout << endl;
}

Measured memory_bytes: 3592
w, h, n = map(int, input().split())
u, d = 0, h
l, r = 0, w

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        l = max(l, x)
    if a == 2:
        r = min(r, x)
    if a == 3:
        u = max(u, y)
    if a == 4:
        d = min(d, y)
print(max(0, (d-u)) * max(0, (r-l)))

Measured memory_bytes: 3064
#include <cstdio>
#include <math.h>
using namespace std;


int main(){
	double x1, x2, y1, y2;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	double ans = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	printf("%.8f\n", ans);

	return 0;
}

Measured memory_bytes: 2708
package main

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

var (
  A string
  
)

func main(){
  var sc = bufio.NewScanner(os.Stdin)
  sc.Scan()
  A = sc.Text()//string
  B := strings.Split(A, " ")
  a, _ := strconv.Atoi(B[0])
  b, _ := strconv.Atoi(B[1])
  c, _ := strconv.Atoi(B[2])
  total := a+b+c
  
  if total == 17 {
    fmt.Println("YES")
  }else{
    fmt.Println("NO")
  }
}

Measured memory_bytes: 640
import std.stdio;
import std.string;
import std.conv;
import std.array;

void main()
{
    int num;
    num = chomp(readln()).to!int;
    string[][4] card;
    
    for(int i = 0; i < num; ++i){
        string[] tmp = split(chomp(readln()));
        if(tmp[0] == "S")
            card[0] ~= tmp[1];
        else if(tmp[0] == "H")
            card[1] ~= tmp[1];
        else if(tmp[0] == "C")
            card[2] ~= tmp[1];
        else if(tmp[0] == "D")
            card[3] ~= tmp[1];
    }
    
    bool[13][4] flag = false;
    for(int i = 0; i < 4; ++i){
        for(int j = 0; j < card[i].length; ++j){
            flag[i][(card[i][j].to!int)-1] = true;
        }
    }
    
    for(int i = 0; i < 4; ++i){
        for(int j = 0; j < 13; ++j){
            if(!flag[i][j]){
                if(i == 0)
                    writeln("S ", j+1);
                else if(i == 1)
                    writeln("H ", j+1);
                else if(i == 2)
                    writeln("C ", j+1);
                else if(i == 3)
                    writeln("D ", j+1);
            }
        }
    }
} 

Measured memory_bytes: 2444
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();
		if(a<=8&&b<=8){
			System.out.println("Yay!");
		}else{
			System.out.println(":(");
		}
		return;
	}
}

Measured memory_bytes: 22868
/*
  Very Nice question of DP on Trees.

  Here we are required to find the possible ways to paint it with given conditions.
  So what we can do is:- 
  take every node and visit its children.
  If that node was painted black then we are bound to color its childs as white, so just recur for every
  child by giving white color and multiply the result for every child branch

  If that node was painted white then we have two choice for every child to be painted, so in addition to above 
  calculation do the calculation by assuming the childs to be white also.
  Then finally add the above two answers.

  So here dp array is dp[total_number_of_nodes][colors_possible]

  then answer is just sum of both possible colors for root node.

  created by sanyam singhal
*/

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

#define pb push_back
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define w(t) int t;	cin>>t while(t--)
#define triplet pair<int,pair<int,int>>
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define loop(i, k, n) for(ll i=k; i<n; i+=1)
#define loop2(i, k, n) for(ll i=k; i>=n; i--)

const ll inf = 1e18;
ll dp[100001][2];
bool vis[100001];

void take_fileIO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  return;
}

ll solve_by_dp(vector<vector<int>> &adj, int node, int parent_color){
  if(dp[node][parent_color]!=-1)
    return dp[node][parent_color];

  vis[node] = true;
  ll ans = 1;
  for(int neigh : adj[node]){
    if(vis[neigh]==false){

      if(parent_color==0){  // 0 here for white
        ll op1 = solve_by_dp(adj, neigh, parent_color)%mod;

        ll op2 = solve_by_dp(adj, neigh,1-parent_color)%mod;
      
        ans = (ans%mod * (op1 + op2)%mod)%mod;

        // cout<<"neigh and node are "<<neigh<<" "<<node<<"color "<<parent_color<<" "<<ans<<endl;
      }
      else{ // 1 for black
        ans = (ans%mod * solve_by_dp(adj, neigh, 1-parent_color)%mod)%mod;
        // cout<<"neigh and node are "<<neigh<<" "<<node<<"color "<<parent_color<<" "<<ans<<endl;
      }
      
    }
  }

  vis[node]=false;
  dp[node][parent_color] = ans;
  return ans;
}

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

  vector<vector<int>>adj(n+1);
  loop(i, 0, n-1){
    int u, v;
    cin>>u>>v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  memset(dp, -1, sizeof(dp));
  memset(vis, false, sizeof(vis));

  ll ans = solve_by_dp(adj, 1, 0)%mod;  //by taking root as white
  ll ans2 = solve_by_dp(adj, 1, 1)%mod; //by taking root as black

  ll f_ans = (ans%mod + ans2%mod)%mod;
  cout<<f_ans<<endl;
  return;
}

int main(){

  fastIO;
  //take_fileIO();
  solve();
  return 0;
}

Measured memory_bytes: 15744
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N;
  cin >> N;
  vector<vector<int>> F = vector<vector<int>>(N, vector<int>(10));
  vector<vector<int>> P = vector<vector<int>>(N, vector<int>(11));
  for(int i = 0; i < N; i ++)for(int j = 0; j < 10; j++) cin >> F[i][j];
  for(int i = 0; i < N; i ++)for(int j = 0; j < 11; j++) cin >> P[i][j];

  int ans = INT_MIN;
  for(int i = 1; i < (1 << 10); i++){
    int c = 0;
    for(int j = 0; j < N; j++){
      int cnt = 0;
      for(int k = 0; k < 10; k++){
	if((i & (1 << k)) && F[j][k])cnt++;
      }
      c += P[j][cnt]; 
    }
    ans = max(ans, c);
  }
  
  cout << ans <<endl;
  return 0;
}


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

int main(){

	int n, m, low;
	
	while(cin >> n >> m){
		low = min(n, m);
		for(int i=low; i>0; i--){
			if(n % i == 0 && m % i == 0){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
    ll n;
    cin >> n;
    ll a[100001] = {};
    ll b[100001] = {};

    REP(i,n){
        ll x;
        cin >> x;
        if(i%2 == 0)
            a[x]++;
        else
            b[x]++;
    }
    ll amax = 0, bmax = 0;
    ll aa,bb;
    REP(i,100001){
        if(amax < a[i])
            aa = i;
            
        if(bmax < b[i])
            bb = i;
            
        amax = max(amax, a[i]);
        bmax = max(bmax, b[i]);
    }
    ll res = 0;
    if(aa == bb){
        a[aa] = -1;
        ll aaa = amax;
        amax = 0;
        REP(i,100001){
            amax = max(amax, a[i]);
        }
        //cout << amax << endl;
        ll r = (n/2 - amax) + (n/2 - bmax);
        //cout << r << endl;
        amax = aaa;
        b[bb] = -1;
        bmax = 0;
        REP(i,100001){
            bmax = max(bmax, b[i]);
        }
        ll rr = (n/2 - amax) + (n/2 - bmax);
        //cout << rr << endl;
        res = min(r,rr);
    }
    else{
         res = (n/2 - amax) + (n/2 - bmax);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int m = sc.nextInt();

        // 配列
        int[] x = new int[m];
        int[] y = new int[m];
        for(int i=0;i<m;i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        boolean[] prob = new boolean[n+1];
        Arrays.fill(prob, false);
        prob[1] = true;

        int[] ball = new int[n+1];
        Arrays.fill(ball, 1);
        ball[0] = 0;

        for(int i=0;i<m;i++){
            ball[x[i]]--;
            ball[y[i]]++;
            if(prob[x[i]]) {
                prob[y[i]] = true;
            }
            if(ball[x[i]] == 0) {
                prob[x[i]] = false;
            }
        }

        int ans = 0;
        for (int i =1;i<=n;i++) {
            if(prob[i]) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 82868
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int A, B, C;  cin >> A >> B >> C;

    int ans = min(B/A, C);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void){
    int p, q; cin >> p >> q;

    q /= __gcd(p, q);

    int res = 1, qq = q;
    for(int i = 2; i * i <= q; i++){
        if(qq % i == 0){
            res *= i;

            while(qq % i == 0) qq /= i;
        }
    }

    res *= qq;

    cout << res << endl;

	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int c = 0;
  for (int i = 0; i < N - 2; i++) {
    //cout << S.substr(i, 3);
    if (S.substr(i, 3) == "ABC") {
      c++;
    }
  }
  cout << c;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

int main(){
	ll n,d;
	cin >> n >> d;
	int cnt = 0;
	for(int i=0;i<n;i++){
		ll x,y;
		cin >> x >> y;
		if(x*x + y*y <= d*d){
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3184