akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int R, G, B;
    cin >> R >> G >> B;
    int N;
    cin >> N;
    int count = 0;
    for (int i = 0; i * R <= N; i++) {
        for (int j = 0; j * G + i * R <= N; j++) {
            int sum = N - j * G - i * R;
            if (sum % B == 0) {
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		int m = sc.nextInt();
		
		out.println(24+(24-m));
		
	}
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
#include<iostream>
#include<math.h>
using namespace std;

int main(void)
{
	long long a, b, c, k;
	long long keiA = 1, keiB = 1, keiC = 1;
	long long ansA, ansB;

	cin >> a >> b >> c >>  k;

	if (k % 2 == 1) {
		keiA = keiB = keiC = (pow(2, k) + 1) / 3;

		ansA = (keiA - 1)*a + keiB * b + keiC * c;
		ansB = keiA * a + (keiB - 1)*b + keiC * c;
	}
	else {
		keiA = keiB = keiC = (pow(2, k) - 1) / 3;

		ansA = (keiA + 1)*a + keiB * b + keiC * c;
		ansB = keiA * a + (keiB + 1)*b + keiC * c;
	}

	if (ansA - ansB > pow(10, 18))
		cout << "Unfair" << endl;
	else {
		cout << ansA - ansB << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int ar[4];
  memset(ar,false,sizeof(ar));
  int a, b;
  cin >> a >> b;
  ar[a]=true;
  ar[b]=true;
  for(int i=1;i<=3;i++)
  {
    if(ar[i]==false)
    {
      printf("%d",i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define L first
#define R second
using namespace std;

int qmin(int a, int b){
	return (a < b) ? a : b;
}
int qmax(int a, int b){
	return (a > b) ? a : b;
}

int n;
pair<int, int> seg[100100];

int len(int l, int r){
	return qmax(r-l+1, 0);
}

int main(){
	scanf("%d", &n);
	rep(i, n) scanf("%d%d", &seg[i].L, &seg[i].R);
	int lmax = seg[0].L, lmax_pos = 0, rmin_2nd = seg[0].R;
	int rmin = seg[0].R, rmin_pos = 0;
	rep(i, n){
		if(seg[i].L > lmax){
			lmax = seg[i].L;
			lmax_pos = i;
			rmin_2nd = seg[i].R;
		}
		if(seg[i].L == lmax) lmax_pos = -1;
		if(seg[i].R < rmin){
			rmin = seg[i].R;
			rmin_pos = i;
		}
		if(seg[i].R == rmin) rmin_pos = -1;
	}
	int ans = len(lmax, rmin) + len(seg[0].L, seg[0].R);
	rep(i, n){
		ans = qmax(ans, len(lmax, rmin) + len(seg[i].L, seg[i].R));
	}
	if(lmax_pos < 0 || lmax_pos != rmin_pos){
		sort(seg, seg+n);
		for(int i = n-1; i > 0; i--){
			rmin_2nd = qmin(rmin_2nd, seg[i].R);
			ans = qmax(ans, len(lmax, rmin_2nd) + len(seg[i-1].L, rmin));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  REP(i, 1<<(n-1)){
    ll t = 0;
    REP(j, n-1){
      if(i&1ll<<j){
        ans += stol(s.substr(t, j-t+1));
        t = j+1;
      }
    }
    ans += stol(s.substr(t, n-t+1));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def resolve():
    '''
    code here
    x=一発で通る時間
    y=全てのテストケースが通る時間
    x = 1900M + 100(N-M)
    y = x + (1 - (1/2)**M )y :::ここで失敗してから終わる時間の期待値は終わる時間の期待値そのもの
    →変形すると　y = 2**M x
    よって　y = (1900M + 100(N-M)) * 2 ** M  
    '''
    N, M = [int(item) for item in input().split()]

    print((1900 * M + 100 * (N - M)) * 2 ** M)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    n %= 10;
    
    int hons[] = {2,4,5,7,9};
    int pons[] = {0,1,6,8};
    int bons[] = {3};
    
    for(int i = 0; i< hons.length;i++){
    	if(n == hons[i]) System.out.println("hon");
    }
    
    for(int i = 0; i< pons.length;i++){
    	if(n == pons[i]) System.out.println("pon");
    }
    
    for(int i = 0; i< bons.length;i++){
    	if(n == bons[i]) System.out.println("bon");
    }
    
  }
}


Measured memory_bytes: 35720
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int MAXN=300005;

int n,A[MAXN],B[MAXN];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&A[i]);
        B[i]=A[i];
    }
    sort(B+1,B+n+1);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        A[i]=lower_bound(B+1,B+n+1,A[i])-B;
        ans+=(A[i]&1)!=(i&1);
    }
    ans/=2;
    printf("%d\n",ans);

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<pair<int, pair<int, int>>> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i).first >> p.at(i).second.first >> p.at(i).second.second;
    }

    int tc = 0, xc = 0, yc = 0;
    for (int i = 0; i < N; i++)
    {
        int ti = p.at(i).first, xi = p.at(i).second.first, yi = p.at(i).second.second;
        int t = ti - tc;
        int l = abs(xc - xi) + abs(yc - yi);
        if (t < l || (t - l) % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
        tc = ti;
        xc = xi;
        yc = yi;
    }
    cout << "Yes" << endl;
}

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

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

  vector<vector<int>> a(2, vector<int>(n+1,0));
  a[0][0]=a[1][0]=0;
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= n; j++) {
      int aa;
      cin >> aa;
      a[i][j]=a[i][j-1]+aa;
    }
  }

  int ans=0;
  for (int i = 1; i <= n; i++) {
    ans=max(ans, a[0][i]+a[1][n]-a[1][i-1]);
  }

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

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

typedef long long  L;
typedef pair<L, L> pii;
L a,a1,a2,a3,b,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx,mn,flg,flg1,flg2,id1,id2,id3,id4,lim,id;
L A[Mx],B[Mx];
char str[Mx];

int main()
{
    scanf("%s",str);
    if(str[2]==str[3]&&str[4]==str[5])printf("Yes\n");
    else printf("No\n");
    return 0;
}
/// lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int mod = 1e+9 + 7;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  vector<int> a(N), b(N);
  map<int, int> cnt;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    cnt[a] += 1;
    cnt[b] += 1;
  }

  bool yes = true;
  for( auto p : cnt ) {
    if( p.second % 2 == 1 ) {
      yes = false;
      break;
    }
  }

  cout << (yes ? "YES" : "NO") << "\n";





  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    string s[100];
    for (int i = 0; i < n; i++)
        cin >> s[i];

    sort(s, s+n);
    string res = "";
    for (int i = 0; i < n; i++)
        res = res + s[i];

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []
limit = 0
present = 1
total = 0
for i in range(n+1):
    limit += a[i]
for i in range(n+1):
    limit -= a[i]
    b.append(limit)
for i in range(n+1):
    if present > a[i]:
        total += present
        present = min((present-a[i])*2, b[i])
    elif present == a[i] and i == n:
        total += present
    else:
        total = -1
        break;
print(total)

Measured memory_bytes: 19992
N, W = map(int, input().split())
wv = []
for _ in range(N):
    wv.append(tuple(map(int, input().split())))

dp = [0]*(W+1)

for w, v in wv:
    newdp = dp[:]
    for ww in range(W+1):
        if w+ww > W:
            continue
        newdp[w+ww] = max(dp[ww+w], dp[ww]+v)
    dp = newdp

print(dp[-1])

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

using namespace std;


bool isPal(string &S) {
    int l = 0, r = S.length()-1;
    while(l < r) {
        if(S[l] != S[r]) {
            return false;
        }
        l++; r--;
    } 
    return true;
}

int main() {
    string S; cin >> S;
    bool flag = true;

    int N = S.length();

    string temp = "", temp2 = "";
    for(int i = 1; i <= (N-1)>>1; i++) {
        temp += S[i-1];
    }

    for(int i = (N+3)>>1; i <= N; i++) {
        temp2 += S[i-1];
    }

    flag &= isPal(S);
    flag &= isPal(temp);
    flag &= isPal(temp2);

    if(flag) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

    return 0;   
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> cells(H);
  
  for(int i=0; i<H; i++){
    cin >> cells.at(i);
  }
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int count = 0;
      if(cells.at(i).at(j) == '#'){
        cout << '#';
      }
      
      if(cells.at(i).at(j) == '.'){
        if(i-1 >= 0 && j-1 >= 0){
          if(cells.at(i-1).at(j-1) == '#'){
            count++;
         }
        }
        if(i-1 >= 0){
          if(cells.at(i-1).at(j) == '#'){
            count++;
         }
        }
        if(i-1 >= 0 && j+1 <= W-1){
          if(cells.at(i-1).at(j+1) == '#'){
            count++;
         }
        }
        
        if(j-1 >= 0){
          if(cells.at(i).at(j-1) == '#'){
            count++;
         }
        }
        if(j+1 <= W-1){
          if(cells.at(i).at(j+1) == '#'){
            count++;
         }
        }

        if(i+1 <= H-1 && j-1 >= 0){
          if(cells.at(i+1).at(j-1) == '#'){
            count++;
         }
        }
        if(i+1 <= H-1){
          if(cells.at(i+1).at(j) == '#'){
            count++;
         }
        }
        if(i+1 <= H-1 && j+1 <= W-1){
          if(cells.at(i+1).at(j+1) == '#'){
            count++;
         }
        }
        
        cout << count;
      }
      if(j == W-1){
        cout << endl;
      }
    }
  }

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,i,j,ggg;
	int val[10]={0};
	
	while(scanf("%d",&n))
	{
		if(n==0)
		{
			break;
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&j);
			val[j]++;
		}
		for(i=0;i<10;i++)
		{
			ggg=val[i];
			val[i]=0;
			if(ggg==0)
			{
				printf("-\n");
			}
			else
			{
				for(j=0;j<ggg;j++)
				{
					printf("*");
				}
				printf("\n");
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 572
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    H,W = LI()
    N = I()
    A = LI()
    HW = [[0] * W for _ in range(H)]
    
    a_flag = [1,A[0]]
    for h in range(H):
        if h%2 == 0:
            range_W = range(W)
        else:
            range_W = range(W-1,-1,-1)
        for w in range_W:
            HW[h][w] = a_flag[0]
            if a_flag[1] == 1 and a_flag[0] < len(A):
                a_flag = [a_flag[0]+1,A[a_flag[0]]]
            else:
                a_flag[1] -= 1

    for x in HW:
        print(" ".join(map(str,x)))



            

if __name__ == "__main__":
    main()


Measured memory_bytes: 40688
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
//#define mp make_pair 
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")

const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;

ll pw(ll a, ll b)
{
    if(b == 0) return 1;
    ll x = pw(a,b/2); x = (x*x) % mod;
    if(b & 1) x = (x*a) % mod;
    return x;
}

ll repo(ll x)
{
    return pw(x,mod-2);
}

int n;
int a[maxn], ps[maxn];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin>> n;
    ll fac = 1;
    for(int i = 1; i <= n; i++) (fac *= i) %= mod;
    for(int i = 1; i <= n; i++)
        ps[i] = (ps[i-1] + (fac * repo(i)) % mod) % mod;
    ll ans = 0;
    for(int i = 1, val; i <= n; i++)
    {
        cin>> val;
        ll f = (ps[n-i+1] + ps[i] - fac) % mod;
        (ans += (f * val) % mod) %= mod;
    }
    cout<< (ans + mod) % mod;
}


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

int main()
{
	int N, A, B;

	cin >> N >> A >> B;

	if (A * N <= B)
	{
		cout << A * N << endl;
	}
	else if (A * N >= B)
	{
		cout << B << endl;
	}
	else
	{
		cout << B << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    vector<int> x(3);
    cin>>x[0]>>x[1]>>x[2];
    sort(ALL(x));

    int d1=x[2]-x[0],d2=x[2]-x[1];
    if(d1%2==0 && d2%2==0) cout<<d1/2+d2/2<<endl;
    else if (d1%2 && d2%2) cout<<(d1-1)/2+(d2-1)/2+1<<endl;
    else if(d1%2 && d2%2==0) cout<<(d1+1)/2+d2/2+1<<endl;
    else cout<<(d2+1)/2+d1/2+1<<endl;

	return 0; 
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int D;
	cin >> D;
	vector<int> c(26);
	for (int i = 0 ; i < 26 ; i++) {
		cin >> c[i];
	}
	vector<vector<int>> s(D, vector<int>(26));
	for (int i = 0 ; i < D ; i++) {
		for (int j = 0 ; j < 26 ; j++) {
			cin >> s[i][j];
		}
	}
	vector<int> l(26);
	ll score = 0;
	for (int d = 0 ; d < D ; d++) {
		int choice = 0;
		int best = 0;
		for (int i = 0 ; i < 26 ; i++) {
			int dm = c[i] * (d + 1 - l[i]) - s[d][i];
			if (dm < best) {
				best = dm;
				choice = i;
			}
		}
		l[choice] = d + 1;
		score += s[d][choice];
		for (int i = 0 ; i < 26 ; i++) {
			score -= c[i] * (d + 1 - l[i]);
		}
		cout << choice + 1 << "\n";
	}
	cerr << max(ll(1e6) + score, 0LL) << endl;
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  ll n, X;
  cin >> n >> X;
  lvec x(n);
  REP(i, n) {
    int tmp;
    cin >> tmp;
    x[i] = abs(tmp - X);
  }

  ll ans = x[0];
  FOR(i, 1, n) ans = gcd(ans, x[i]);
  if (n == 1) ans = x[0];
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
n, m = map(int,input().split())
G = [[] for _ in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
SAW = [False] * n

def dfs(v,SAW):
    global res
    end = True
    for i in range(n):
        if not SAW[i] and i != v:
            end = False
    if end:
        res += 1
        return
    SAW[v] = True
    for nv in G[v]:
        if SAW[nv]:
            continue
        dfs(nv,SAW)
    SAW[v] = False
res = 0
dfs(0,SAW)
print(res)


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

int top,S[1000];

void push(int x) { 
  S[++top] = x;
}

int pop() {
   top--;
   return S[top+1];
}

int main() { 
  int a, b;
  top = 0;
  char s[100];

  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }else{
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}


Measured memory_bytes: 2740
#include <cstdio>
#include <algorithm>
#include <unordered_set>
typedef long long ll;
using namespace std;
int h, w, n;
unordered_set<ll> board;
int cur_board[5][5];
ll ans[10];
int main() {
	scanf("%d%d%d", &h, &w, &n);
	ans[0] = (ll)(h - 2) * (w - 2);
	while(n--) {
		ll a;
		int b; scanf("%lld%d", &a, &b);
		if(board.find(a << 30 | b) != board.end()) continue;
		for(int di = -2; di <= 2; di++) for(int dj = -2; dj <= 2; dj++) {
			if(1 <= a + di && a + di <= h && 1 <= b + dj && b + dj <= w)
				cur_board[di + 2][dj + 2] = board.find((a + di) << 30 | (b + dj)) != board.end();
			else
				cur_board[di + 2][dj + 2] = 0;
		}
		for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) {
			if(i > 0) cur_board[i][j] += cur_board[i - 1][j];
			if(j > 0) cur_board[i][j] += cur_board[i][j - 1];
			if(i > 0 && j > 0) cur_board[i][j] -= cur_board[i - 1][j - 1];
		}
		for(int di = -1; di <= 1; di++) for(int dj = -1; dj <= 1; dj++) {
			int a_ = a + di, b_ = b + dj;
			if(2 <= a_ && a_ <= h - 1 && 2 <= b_ && b_ <= w - 1) {
				int c = cur_board[di + 3][dj + 3];
				if(di >= 0) c -= cur_board[di][dj + 3];
				if(dj >= 0) c -= cur_board[di + 3][dj];
				if(di >= 0 && dj >= 0) c += cur_board[di][dj];
				ans[c]--;
				ans[c + 1]++;
			}
		}
		board.insert(a << 30 | b);
	}
	for(int i = 0; i < 10; i++) printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 4388
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from collections import deque

def process_task(task,qua, elapsed_time, complete_task):
	exe_task = task.popleft()
	t = int(exe_task[1])
	q = int(qua)

	if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	return elapsed_time,complete_task

def main():
	n,q = map(int, raw_input().split())
	task = [raw_input().split() for _ in range(n)]
	que = deque(task)
	ela_time = 0
	comp_task = []

	while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	for i in comp_task:
		print i[0], i[1]

#def test():

if __name__ == '__main__':
	main()
	#test()

Measured memory_bytes: 24824
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))    

Measured memory_bytes: 17808
//
// Created by on 2019-04-17.
//
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>

using namespace std;


int main(void){
    int N;
    int H[100010];

    cin>>N;
    vector<long long> dp(N+10,1000000);

    for (int i = 0; i < N; ++i) {
        cin>>H[i];
    }

    dp[1] = abs(H[0] - H[1]);
    dp[2] = abs(H[0] - H[2]);
    for (int j = 1; j < N; ++j) {
        if(j+1 < N){
            dp[j+1] = min(dp[j+1], (dp[j] + abs(H[j] - H[j+1])));
        }

        if(j+2 < N){
            dp[j+2] = dp[j] + abs(H[j]-H[j+2]);
        }
    }

    cout<<dp[N-1]<<endl;

    return 0;
}

Measured memory_bytes: 1408
from sys import stdin,stdout
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline
 
def main():
    n = int(input())
    keys = map(lambda i: map(int,readline().split())+[i], xrange(n))
    keys.sort()

    root = int(math.sqrt(len(keys)))
 
    low = [x for x, y, i in keys[::root]]
    high = [x for x, y, i in keys[root - 1::root]] + [float('inf')]
 
    keys = [sorted(keys[i:i+root], key=itemgetter(1)) for i in range(0,len(keys),root)]
    keys_y = map(lambda k:[y for x,y,i in k], keys)

    q = int(input())
    for i in xrange(q):
        sx,tx,sy,ty = map(int,readline().split())
        
        nums = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            y = keys_y[i]
            for j in range(bisect_left(y, sy), bisect_right(y, ty)):
                if sx <= keys[i][j][0] <= tx:
                    nums.append(keys[i][j][2])
        if nums:
            nums.sort()
            map(lambda n:stdout.write("{}\n".format(n)), nums)
        print("")

if __name__ == "__main__":
    main()

Measured memory_bytes: 98320
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readLong();
      foreach (x; 0 .. N + 1) {
        if (x * 108 / 100 == N) {
          writeln(x);
          goto found;
        }
      }
      writeln(":(");
     found:
    }
  } catch (EOFException e) {
  }
}


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

using QWORD = unsigned long long;
using SQWORD = long long;
using DWORD = unsigned int;
using SDWORD = int;
using WORD = unsigned short;
using SWORD = short;
using DOUBLE = double;
using FLOAT = float;

#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define ArrayLength(a)  (sizeof(a) / sizeof(a[0]))

static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }

#define BYTE_BITS   (8)
#define WORD_BITS   (16)
#define DWORD_BITS  (32)
#define QWORD_BITS  (64)

using M_BOOL = bool;
#define M_TRUE (true)
#define M_FALSE (false)

static void printMatrix(DWORD **p, DWORD dwSize)
{
    printf("---\n");
    for (DWORD i = 0; i < dwSize; i++) {
        for(DWORD j = 0; j < dwSize; j++) {
            printf("%5d", p[i*dwSize + j]);
        }
        cout << endl;
    }
    printf("---\n");
}

int main()
{
    DWORD dwInput_N, dwInput_M, dwInput_Q;
    char str[6000];

    cin.getline(str, sizeof(str));
    dwInput_N = atoi(strtok(str, " "));
    dwInput_M = atoi(strtok(NULL, " "));
    dwInput_Q = atoi(strtok(NULL, " "));

    /* input train */
    DWORD aadwTrainMap[dwInput_N+1][dwInput_N+1];
    memset(aadwTrainMap, 0, sizeof(aadwTrainMap));
    for (DWORD dwIdx = 0; dwIdx < dwInput_M; dwIdx++) {
        cin.getline(str, sizeof(str));
        WORD wCity_L, wCity_R;

        wCity_L = atoi(strtok(str, " "));
        wCity_R = atoi(strtok(NULL, " "));
        aadwTrainMap[wCity_L][wCity_R]++;
    }

    /* calc camsum(Row) */
    for (DWORD dwRow = 0; dwRow <= dwInput_N; dwRow++) {
        DWORD dwSum = 0;
        for (DWORD dwCol = 0; dwCol <= dwInput_N; dwCol++) {
            dwSum += aadwTrainMap[dwRow][dwCol];
            aadwTrainMap[dwRow][dwCol] = dwSum;
        }
    }

    /* calc camsum(col) */
    for (DWORD dwCol = 0; dwCol <= dwInput_N; dwCol++) {
        DWORD dwSum = 0;
        for (DWORD dwRow = 0; dwRow <= dwInput_N; dwRow++) {
            dwSum += aadwTrainMap[dwRow][dwCol];
            aadwTrainMap[dwRow][dwCol] = dwSum;
        }
    }

    /* input question */
    for (DWORD dwIdx = 0; dwIdx < dwInput_Q; dwIdx++) {
        DWORD dwAnswer;
        cin.getline(str, sizeof(str));
        WORD wBegin = atoi(strtok(str, " "));
        WORD wEnd   = atoi(strtok(NULL, " "));

        dwAnswer= (aadwTrainMap[wEnd][wEnd]
                    - aadwTrainMap[wBegin-1][wEnd]
                    - aadwTrainMap[wEnd][wBegin-1]
                    + aadwTrainMap[wBegin-1][wBegin-1]);
        printf("%d\n", dwAnswer);
    }

    return 0;

}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

double a,b;
double x;

double f(double tan) {
    if (tan > a / b) {
        return (b - a/tan) * a * a + a * a * a / (2 * tan);
    }
    else {
        return a * (b * tan) * b /2;
    }
}

int main() {
    const double PI = 3.141592653;
    cin >> a >> b >> x;
    double l = 0, r = 90;
    for(int i = 0; i < 1000; i++) {
        double mid = (l + r) / 2;
        if (f(tan(mid / 360 * 2 * PI)) > x) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%.10f\n",90 - r);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
SPN = []
for i in range(n):
    s,p = input().split()
    SPN.append([s,int(p),i+1])
SPN.sort(key = lambda x:x[1],reverse=True)
SPN.sort(key = lambda x:x[0])
for s,p,n in SPN:
    print(n)


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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

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

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    if( N >= 1000 ) cout << "ABD" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

X=[]
Y=[]
C=[]
for m in range(M):
  x,y,c=map(int,input().split())
  X.append(x)
  Y.append(y)
  C.append(c)
no_coupon=min(a)+min(b)

sum=[]
for i in range(M):
  sum.append(a[X[i]-1]+b[Y[i]-1]-C[i])

with_coupon=min(sum)
print(min(no_coupon,with_coupon))

Measured memory_bytes: 28844
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a[4];
	int b[4];
	int hit,blow;

	while(scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) != EOF){
		hit = 0;
		blow = 0;
		for(int i = 0;i < 4;i++){
			for(int j = 0;j < 4;j++){
				if(a[i] == b[j] && i == j){
					hit++;
				}
				if(a[i] == b[j] && j != i){
					blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
}

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
int main()
{
    long long int t,i,r,l,c,j;
    while(cin>>t)
    {  c=0;
        for(i=1;i<=t;i++)
        {
            cin>>l>>r;
            for(j=l;j<=r;j++)
            {
                c++;
            }
        }
        cout<<c<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  char op;
  
  cin >> A >> op >> B;
  
  if (op == '+') {
    cout << A + B << endl; 
  }
  else if (op == '-') {
    cout << A - B << endl;
  }
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, k) = i.read2::<usize, usize>();
    let a = i.read_vec::<usize>(n);

    writeln!(o, "{}", solve(&a, k)).unwrap();
}
fn solve(a: &[usize], k: usize) -> usize {
    let l = a.iter().position(|&x| x == 1).unwrap();
    let r = a.len() - l - 1;

    let lc = l / (k - 1);
    let rc = r / (k - 1);
    let l = l - lc * (k - 1);
    let r = r - rc * (k - 1);
    lc + rc + if l + r > k {
        2
    } else if l + r > 0 {
        1
    } else {
        0
    }
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        {$f:ident($($v:ident: $t:ident),*)} => {
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                $(
                    let $v = i.next().unwrap().parse().ok().unwrap();
                )*
                ($($v),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(v1: T1, v2: T2) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
}


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

int main() {
  int n, p, t = 0, o = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &p);
    if(i + 1 == p)
      t++;
    else if(t) {
      if(t == 1)
        o++;
      else
        o += (t + 1) / 2;
      t = 0;
    }
  }
  if(t == 1)
    o++;
  else
    o += (t + 1) / 2;
  printf("%d\n", o);
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;
ll rec(ll n);

int main(void) {
    ll n, i, j;
    cin >> n;
    
    for(i=0; i<=100; i+=4) {
        for(j=0; j<=100; j+=7) {
            if(n==i+j) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    ll a[n],c[n+1];
    rep(0,i,n+1)c[i]=0;
    rep(0,i,n){
        cin>>a[i];
        ++c[a[i]];
    }
    ll sum=0;
    rep(0,i,n+1){
        sum+=c[i]*(c[i]-1)/2;
    }
    rep(0,i,n){
        cout<<sum-(c[a[i]]-1)<<endl;
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define pii pair<int,int>
#define unmap unordered_map<int,int>
#define ll long long int
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    int a[m];
    int sum = 0;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (n >= sum)
        cout << n - sum << "\n";

    else
        cout << "-1" << "\n";


}





int main()
{


    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=105;

int N,M,X,Y;
char mp[MAXN][MAXN];
short dp[MAXN][MAXN][MAXN][MAXN];
short sum[MAXN][MAXN];

short CountRect(int u,int l,int d,int r)
{
	return sum[d][r]-sum[d][l-1]-sum[u-1][r]+sum[u-1][l-1];
}

int main()
{
    scanf("%d%d",&N,&M);
    for(int i=1;i<=N;i++)
	{
		scanf("%s",mp[i]+1);
		for(int j=1;j<=M;j++)
			if(mp[i][j]=='E')
				X=i,Y=j;
	}
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(mp[i][j]=='o');
	int ans=0;
	for(int u=X;u>0;u--)
		for(int l=Y;l>0;l--)
			for(int d=X;d<=N;d++)
				for(int r=Y;r<=M;r++)
				{
					ans=max(ans,(int)dp[u][l][d][r]);
					int U=d-X+1,L=r-Y+1,D=N-(X-u),R=M-(Y-l);
					if(u>U)
						dp[u-1][l][d][r]=max((int)dp[u-1][l][d][r],dp[u][l][d][r]+CountRect(u-1,max(L,l),u-1,min(R,r)));
					if(l>L)
						dp[u][l-1][d][r]=max((int)dp[u][l-1][d][r],dp[u][l][d][r]+CountRect(max(U,u),l-1,min(D,d),l-1));
					if(d<D)
						dp[u][l][d+1][r]=max((int)dp[u][l][d+1][r],dp[u][l][d][r]+CountRect(d+1,max(L,l),d+1,min(R,r)));
					if(r<R)
						dp[u][l][d][r+1]=max((int)dp[u][l][d][r+1],dp[u][l][d][r]+CountRect(max(U,u),r+1,min(D,d),r+1));
				}
	printf("%d\n",ans);

    return 0;
}


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

using namespace std;
int main(){
    int n;
    int ans=0;
    cin >> n;
    vector<pair<int,int>> tasc(n);
    for (int i=0; i<n; i++){
        cin >> tasc[i].second >> tasc[i].first;
    }
    sort(tasc.begin(), tasc.end());
    for(int i=0; i<n; i++){
        ans += tasc[i].second;
        // 時間を過ぎたら終了
        if(ans>tasc[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

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

	if (a > 9 || b > 9) {
		cout << -1 << endl;
	} else {
		cout << a * b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    ll n; cin >> n;
    vl a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    priority_queue<ll> pq;
    vl v;
    ll ans = 0;
    rep(i,n){
        if(a[i]>=b[i]) pq.push(a[i]-b[i]);
        else{
            v.push_back(b[i]-a[i]);
            ans++;
        }
    }
    while(!pq.empty()){
        if(v.empty()){
            cout << ans << endl;
            return 0;
        }
        ll s = pq.top(); pq.pop(); ans++;
        ll t = v.back(); v.pop_back();
        while(s>=t){
            s -= t;
            if(v.empty()){
                cout << ans << endl;
                return 0;
            }
            t = v.back(); v.pop_back();
        }
        t -= s;
        v.push_back(t);
    }
    if(v.empty()) cout << ans << endl;
    else puts("-1");
}

Measured memory_bytes: 2936
#include <stdio.h>
void aprint(int[],int);
void insertionSort(int[],int);
int main(){
  int N;
  int i;
  int A[100];

  scanf("%d",&N);
  while(N<0&&N>100){
    scanf("%d",&N);
  }
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  aprint(A,N);
  insertionSort(A,N);
  return 0;
}

void insertionSort(int A[],int N){
  int i,j,v;

  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    aprint(A,N);
  }
}

void aprint(int A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}



Measured memory_bytes: 2084
n=int(input())
t,a=[0]*n,[0]*n
for i in range(n):
  t[i],a[i]=map(int,input().split())
tt,aa=t[0],a[0]
for i in range(1,n):
  tt=t[i]*max((tt+t[i]-1)//t[i],(aa+a[i]-1)//a[i])
  aa=a[i]*max((tt+t[i]-1)//t[i],(aa+a[i]-1)//a[i])
print(aa+tt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
int k;
int main(){
	ios::sync_with_stdio(0);
	cin>>k;
	rep(i,k)
	cout<<"ACL";
	re 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args){
    		Scanner sc = new Scanner(System.in);
    			
    			long x = sc.nextLong();
     
    			for(int a = 0 ; a < 300 ; a++ ) {
    				for(int b = -300 ; b < 300 ; b++ ) {
    					
    					long p = (long)(Math.pow(a, 5) - Math.pow(b, 5));
    					
    					if ( x == p ) {
    						System.out.println(a + " " + b);
    						return;
    					}
    				}
    			}
    		
    	}
     
    }

Measured memory_bytes: 38672
#include <bits/stdc++.h>
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;

  if (s[2]==s[3] && s[4]==s[5]) yn;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<numeric>
#define ll long long
#define PI 3.14159265359

using namespace std;

int main() {
  ll n;
  cin >> n;
  map<int,int> mp;
  ll num=1;
  ll ans=0;
  for(int i=0;i<n-1;++i){
    int a;
    cin >> a;
    mp[a-1]++;
  }

  vector<int> vc(n,0);
  for(int i=0;i<mp.size();++i){
    vc[i] = mp[i];
  }

  for(int i=0;i<n;i++){
    cout << vc[i] << endl;
  }
}

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

int main(){
    int m, n, l;
    int a[100][100];
    int b[100][100];
    long int c[100][100] = {0};
    
    cin >> m >> n >> l;
    
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            cin >> b[i][j];
        }
    }
    
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < n; k++){
                c[i][j] += a[i][k] * b[k][j];
            }
            
            cout << c[i][j];
            if(j == l - 1) cout << endl;
            else cout << " ";
        }
    }
}


Measured memory_bytes: 3252
import bisect
N, M = map(int,input().split())
A = []
for _ in range(M):
    A.append(int(input()))

dp = [ 0 for _ in range(N+5)]

def check(n):
    i = bisect.bisect_left(A, n)
    if i != M and A[i] == n:
        return False
    else:
        return True

dp[0] = 1
for i in range(N):
    if check(i+1):
        dp[i+1] += dp[i]
        dp[i] %= 1000000007
    if check(i+2):
        dp[i+2] += dp[i]
        dp[i] %= 1000000007

print(dp[N] % 1000000007)


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

int ans = 0x3f3f3f3f;
int Count(int x) {
	int ret = 0;
	while(x) {
		ret += x % 10;
		x /= 10;
	}
	return ret;
}

int main(void) {
	int n;
	cin >> n;
	for(int i = 1; i <= n/2+1; ++i) {
		ans = min(ans, Count(i) + Count(n-i));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        long sum = 0;

        for (int i = 1; i <= n; i++) {
            sum += i;
            if (sum >= n) {
                long gap = sum - n;
                for (int j = 1; j <= i; j++) {
                    if (gap == j) {
                        continue;
                    }
                    System.out.println(j);
                }
                return;
            }
        }
    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())


int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N),sum(N+1,0);
	FOR(i,0,N) cin >> A[i];
	sort(A.begin(),A.end());
	FOR(i,1,N+1)sum[i] = sum[i-1] + A[i-1];

	// 幸福度が ok 以上になる握手がM回以上ある
	ll ok=0,ng=300000,ans=0;
	while(ng-ok>1){
		ll mid = (ng+ok)/2;
		ll num = 0;
		FOR(i,0,N){
			ll ind = POSL(A,mid-A[i]);
			num += N - ind;
		}
		if(num >= M){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	FORR(i,0,N){
		ll ind = POSL(A,ok-A[i]);
		// A[ind] ~ A[N-1]　まで　できる
		M -= N - ind;
		ans += (sum[N]-sum[ind])+A[i]*(N-ind); 
	}
	if(M<0) ans += M * ok;//足しすぎ分を引く
	cout << ans << endl;
}


Measured memory_bytes: 1792
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import numpy as np

import math

if __name__ == '__main__':
    n = int(input())
    b, c = map(int, input().split())
    list = []
    min = 10000000000
    d = [int(i) for i in input().split()]
    c = c * 1000

    for i in d:
        a = b *1000 - i * 6
        diff = 0
        if (a > 0 and c > 0) or (a < 0 and c < 0):
            diff = abs(c - a)
        else:
            diff = abs( a) +abs(c)
        list.append(diff)
        if min > diff:
            min = diff
    print(list.index(min) + 1)

Measured memory_bytes: 15504