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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const int MAX_V_flow = 2010;
struct FLOW{
	vector<P1> G[MAX_V_flow];
	bool used[MAX_V_flow];
	
	void init(){
		rep(i,MAX_V_flow)G[i].clear();
	}
	
	void add_edge(int from,int to,int flow){
		G[from].pb( mp1 ( to , flow , G[to].size() ) );
		G[to].pb( mp1 ( from , 0 , G[from].size()-1 ) );
	}
	
	int dfs(int v,int t,int f){
		if(v == t)return f;
		used[v] = true;
		rep(i,G[v].size()){
			if(!used[G[v][i].fr] && G[v][i].sc.fr > 0){
				int d = dfs(G[v][i].fr,t,min(f,G[v][i].sc.fr));
				if(d > 0){
					G[v][i].sc.fr -= d;
					G[G[v][i].fr][G[v][i].sc.sc].sc.fr += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	int flow(int s,int t){
		int ret = 0,d = 1;
		while(d > 0){
			rep(i,MAX_V_flow)used[i] = false;
			d = dfs(s,t,INF);
			ret += d;
		}
		return ret;
	}
}flow;

int n,m,l;
int u[1002],v[1002],d[1002];
int p[1002],t[1002];
int dist[102][102];

void init(){
	flow.init();
	rep(i,102)rep(j,102)dist[i][j] = INF;
	rep(i,102)dist[i][i] = 0;
}

int main(){
	while(1){
		init();
		
		scanf("%d%d%d",&n,&m,&l);
		if(n == 0)break;
		rep(i,m)scanf("%d%d%d",&u[i],&v[i],&d[i]);
		rep(i,l)scanf("%d%d",&p[i],&t[i]);
		
		rep(i,m){
			dist[u[i]][v[i]] = d[i];
			dist[v[i]][u[i]] = d[i];
		}
		rep(k,n)rep(i,n)rep(j,n)dist[i][j] = min ( dist[i][j] , dist[i][k] + dist[k][j] );
		
		rep(i,l){
			flow.add_edge( 2*l+1 , 2*i , 1 );
			flow.add_edge( 2*i+1 , 2*l , 1 );
			rep(j,l){
				if(i == j)continue;
				if(dist[p[i]][p[j]] <= t[j]-t[i]){
					//printf("%d %d\n",i,j);
					flow.add_edge( 2*i , 2*j+1 , 1 );
				}
			}
		}
		
		cout << l - flow.flow( 2*l+1 , 2*l ) << endl;
	}
}

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

bool binarySearch(int *numArray,int target,int indexL,int indexR){
	if( target > numArray[indexR] || target < numArray[indexL]) return false;
	if(target == numArray[indexR] || target == numArray[indexL]) return true;
	if( indexL == (indexR - 1)) return false;

	int index = (indexL  + indexR) / 2;
	if( numArray[index] == target){
		return true;
	}else if( numArray[index] < target){
		indexL = index;
	}else if( numArray[index] > target){
		indexR = index;
	}
	return binarySearch(numArray,target,indexL,indexR);
}

int main()
{

	//1. 入力を変数に格納
	int numS,numT;
	cin >> numS;
	int *arrayS = new int[numS];
	for(int i = 0; i < numS; i++){
		cin>> arrayS[i];
	}
	cin >> numT;
	int *arrayT = new int[numT];
	for(int i = 0; i < numT; i++){
		cin>> arrayT[i];
	}
	
	//2. arrayTのそれぞれの数字がarraySに含まれているかどうか。
	//含まれている場合、sumOfIncludedNumberをインクリメントする
	int sumOfIncludedNumber = 0;
	for(int i = 0; i < numT; i++){
		if( binarySearch(arrayS,arrayT[i],0,numS-1) == true ){
			sumOfIncludedNumber++;
			//cout<< arrayT[i]<<"foud !"<<endl;
		}
		
	}
	cout << sumOfIncludedNumber << endl;
	return 0;
}





Measured memory_bytes: 3640
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{

    int t,m,l,i,n,k;
    string s,sub,sd;
    cin>>k>>s;
    if( k>=s.size()){
       cout<<s<<endl;
    }
    else{
    sub=s.substr(0,k);
    cout<<sub<<"..."<<endl;
    }



    return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int A[110000], B[110000];
int C[110000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> A[i] >> B[i]; }
    int ans = 0;
    rep(i, N) {
        C[i] = A[i] + B[i];
        ans += A[i] - B[i];
    }
    sort(C, C + N), reverse(C, C + N);
    rep(i, N) {
        ans += C[i] * (1 - (i & 1) * 2);
    }
    ans /= 2;
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <functional>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <cstdio>

using namespace std;

int main(){
    int x,y, n, k;
    cin >> n >> k;
    
    for (x = 0; x <= k / 10000; x++){
        for (y = 0; y <= (k - 10000 * x) / 5000; y++){
            if (10000 * x + 5000 * y + 1000 * (n - y - x) == k){
                cout << x << ' '<< y << ' '<< n - y - x << endl;
                return 0;
            }
                
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
    
    
    
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int h,w;
bool done[1010][1010];
ll memo[1010][1010];
string s[1010];

ll solve(int i, int j){
	if(done[i][j]){
		return memo[i][j];
	}
	done[i][j] = true;
	if(i>=h || j>=w){
		memo[i][j] = 0ll;
		return 0ll;
	}else if(s[i][j]=='#'){
		memo[i][j] = 0ll;
		return memo[i][j];
	}else if(i==(h-1) && j==(w-1)){
		memo[i][j] = 1ll;
		return memo[i][j];
	}
	memo[i][j] = (solve(i,j+1)+solve(i+1,j))%MOD;
	return memo[i][j];
}

int main(void){
	int i,j;
	fill(done[0],done[1010],false);
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> s[i];
	}
	cout << (solve(0,0)) << endl;
	return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n;
int x[110][110],y[110][110];
int visited[110][110];

int main(void){
	while(cin >> n,n){
		int ans=0;
		rep(i,n)rep(j,n)  visited[i][j]=0;
		rep(i,n)rep(j,n) cin >> x[i][j] >> y[i][j];
		rep(yy,n)rep(xx,n){
			if(visited[yy][xx]) continue;
			visited[yy][xx]=-1;
			int cx=x[yy][xx],cy=y[yy][xx];
			while(visited[cy][cx]==0){
				visited[cy][cx]=-1;
				int nx=x[cy][cx],ny=y[cy][cx];
				swap(cx,nx),swap(cy,ny);
			}

			int cur=visited[cy][cx];
			if(cur==-1) cur=++ans;
			cx=xx,cy=yy;
			while(visited[cy][cx]==-1){
				visited[cy][cx]=cur;
				int nx=x[cy][cx],ny=y[cy][cx];
				swap(cx,nx),swap(cy,ny);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
#include<stdio.h>
int main(){
  int x[3000],y[3000];
  int i=0;
  int ians,tmp;
  while(1){
    scanf("%d %d",&x[i],&y[i]);
    if(x[i]==0&&y[i]==0)   break;
    i++;
  }
  for(ians=0;ians<i;ians++){
    if(x[ians]>y[ians]){
      tmp=x[ians];
      x[ians]=y[ians];
      y[ians]=tmp;
    }
    printf("%d %d\n",x[ians],y[ians]);
  }
  return 0;
}

Measured memory_bytes: 620
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> ct(N);
  FOR(i, Q) {
    int A;
    cin >> A;
    ct[A - 1]++;
  }
  FOR(i, N) {
    if (Q - ct[i] < K) {
      print("Yes");
    } else {
      print("No");
    }
  }
  return 0;
}

Measured memory_bytes: 1024
using System;

namespace C___Back_and_Forth
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var sx = read[0];
            var sy = read[1];
            var tx = read[2];
            var ty = read[3];

            int x = sx;
            int y = sy;

            string answer = "";

            for(; x < tx ; x++) answer += "R";
            for(; y < ty ; y++) answer += "U";
            for(; x > sx ; x--) answer += "L";
            for(; y > sy ; y--) answer += "D";
            answer += "D"; y--;
            for(; x < tx + 1 ; x++) answer += "R";
            for(; y < ty ; y++) answer += "U";
            answer += "L"; x--;
            answer += "U"; y++;
            for(;x > sx-1 ; x--) answer += "L";
            for(;y > sy ; y--) answer += "D";
            answer += "R"; x++;


            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 32724
import sys
def input(): return sys.stdin.readline().rstrip()
from fractions import gcd
def prime_fact(m):
    pf={}
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    return list(pf)
def main():
    a,b=map(int,input().split())
    print(1+len(prime_fact(gcd(a,b))))

if __name__=='__main__':
    main()

Measured memory_bytes: 64724
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,a1,bb[100000+5];
int main()
{
	cin>>a>>b>>c;
	a=a%b;a1=a;
	if (a==0&&c==0) {cout<<"YES"<<endl;return 0;}
	if (a==0&&c!=0) {cout<<"NO"<<endl;return 0;}
	while (1)
	{
		if (a==c) {cout<<"YES"<<endl;return 0;}
		a+=a1;
		a=a%b;
		if (bb[a]==1) break;
		bb[a]++;
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,i,j,sum=0;
	cin>>n;
	int a[105]={0};
	for(i=1;i<=n;i++)
	{
	 cin>>j;
	 a[j]++;
    }
    for(i=1;i<=104;i++)
    {
    	if(a[i]!=0) sum++;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.buffer.readline

def main():
    H,W,A,B = map(int,input().split())
    u = ["0" for _ in range(A)] + ["1" for _ in range(W-A)]
    _u = ["1" for _ in range(A)] + ["0" for _ in range(W-A)]
    
    for _ in range(B):
        print("".join(u))
    for _ in range(H-B):
        print("".join(_u))

if __name__ == "__main__":
    main()


Measured memory_bytes: 4084
class Stack:
    def __init__(self, n):
        self.top = 0
        self.A = [0 for i in range(n)]
        self.n = n

    def init(self):
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top == self.n - 1

    def push(self, x):
        if not self.is_full():
            self.top += 1
            self.A[self.top] = x

    def pop(self):
        if not self.is_empty():
            x = self.A[self.top]
            self.top -= 1
            return x


if __name__ == '__main__':
    S = Stack(110)
    for ch in raw_input().split():
        if ch == '+':
            b = S.pop()
            a = S.pop()
            S.push(a + b)
        elif ch == '-':
            b = S.pop()
            a = S.pop()
            S.push(a - b)
        elif ch == '*':
            b = S.pop()
            a = S.pop()
            S.push(a * b)
        else:
            S.push(int(ch))
    print S.pop()


Measured memory_bytes: 4688
def isPrime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

N = int(input())
cnt = []

for i in range(2, N+1):
    if not isPrime(i):
        continue
    c = 0
    x = i
    while N // x > 0:
        c += N // x
        x *= i
    cnt.append(c)

ans = 0
for x in cnt:
    if x >= 74:
        ans += 1

for i in range(len(cnt)):
    for j in range(i+1, len(cnt)):
        if cnt[i]>=2 and cnt[j]>=24:
            ans += 1
        if cnt[i]>=24 and cnt[j]>=2:
            ans += 1
        if cnt[i]>=4 and cnt[j]>=14:
            ans += 1
        if cnt[i]>= 14 and cnt[j]>=4:
            ans += 1

for i in range(len(cnt)):
    for j in range(i+1, len(cnt)):
        for k in range(j+1, len(cnt)):
            if cnt[i]>=2 and cnt[j]>=4 and cnt[k]>=4:
                ans += 1
            if cnt[i]>=4 and cnt[j]>=2 and cnt[k]>=4:
                ans += 1
            if cnt[i]>=4 and cnt[j]>=4 and cnt[k]>=2:
                ans += 1

print(ans)

Measured memory_bytes: 3064
n= int(input())
arr = [int(x) for x in input().strip().split()]


def Greedy(arr):
    
    curr = 1000
    for i in range(len(arr)-1):
        if arr[i+1]>arr[i]:
            stocks = curr // arr[i]
            curr += (arr[i+1] - arr[i])*stocks
    return curr

print(Greedy(arr))

        
# mem = {}
# def helper(i, mon, stk):
#     key = (i, mon, stk)
#     if key in mem:
#         return mem[key]
    
#     if i==len(arr):
#         return mon
    
#     ans = helper(i+1, mon, stk)
#     buy = 1
#     while True:
#         if arr[i]*buy<=mon:
#             ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy))
#         else:
#             break
        
#         buy += 1
    
#     for s in range(1, stk+1):
#         ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s))
    
#     mem[key] = ans
#     return ans

    
# print(helper(0, 1000, 0))

Measured memory_bytes: 9212
#include <iostream>

int main() {
    int K,X;
 
    std::cin >> K >>X;
 
    if(K*500>=X){
        std::cout << "Yes" << std::endl;
        return 0;
    }
 
    std::cout << "No" << std::endl;
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k, t=0;
	cin >> n >> k;
	int a[n+1];
	for (int i=1; i<=n; i++) cin >> a[i];
	sort (a+1, a+n+1);
	for (int i=1; i<=k; i++) t+=a[i];
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

ll dp[2010][2010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    VI s(n), t(m);
    dp[0][0] = 1;
    FOR(i, 0, n) {
        cin >> s[i];
        dp[i + 1][0] += dp[i][0];
    }
    FOR(i, 0, m) {
        cin >> t[i];
        dp[0][i + 1] += dp[0][i];
    }

    FOR(i, 0, n)FOR(j, 0, m) {
        if (s[i] != t[j])dp[i + 1][j + 1] -= dp[i][j];
        dp[i + 1][j + 1] += dp[i][j + 1];
        dp[i + 1][j + 1] += dp[i + 1][j];
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + mod) % mod;
    }

    cout << dp[n][m] << "\n";
}

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

#define endl '\n'

void solve(){
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() > k) cout << s.substr(0, k) << "...\n";
    else cout << s << endl;
}

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

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int P[6]={a,b,c,a,b,c};
    int max=0;
    int A,B,C;
    for(int i=0;i<3;i++){
        if(P[i]>=max){
            max=P[i];
            A=i;
            B=i+1;
            C=i+2;
        }
    }
    cout<<max*10+P[B]+P[C]<<endl;
}


Measured memory_bytes: 256
a, b, ab, x, y = map(int, input().split())

ans = 0

if a + b < 2 * ab:
    ans = a * x + b * y
else:
    if x > y:
        if a < 2 * ab:
            ans = 2 * ab * y + a * (x-y)
        else:
            ans = 2 * ab * x
    elif x == y:
        ans = 2 * ab * x
    else:
        if b < 2 * ab:
            ans = 2 * ab * x + b * (y-x)
        else:
            ans = 2 * ab * y

print(ans)


Measured memory_bytes: 3060
D = int(input())
c = list(map(int, input().split()))
sdi = [list(map(int, input().split())) for i in range(D)]

lastdi = [0 for i in range(26)]
ans_c = []
for d in range(D):
  
  day_s = sdi[d]
  
  sloss = [day_s[i] + c[i]*(d - lastdi[i]) for i in range(26) ]
  ans = sloss.index(max(sloss))
  ans_c.append( ans+1 )
  
  for i in range(26):
    if i != ans:
      lastdi[i] += 1
  lastdi[ans] = d

for i in range(D):
  print(ans_c[i])

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << ' ' << max(0, A + B - N) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
S = l()
sa = 1000000000

for i in range(1,N):
    sa = min(sa,abs(sum(S[:i])-sum(S[i:])))

print(sa)


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

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

// [debug]

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

void Main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  ll ans = 0;
  REP(i, 0, n-1) REP(j, i+1, n) ans += d[i] * d[j];
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int price = 700;
  
  for (int i=0; i<3; ++i) {
    if (s[i]=='o') {
      price += 100;
    }
  }
  
  cout << price << endl;
}

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

using namespace std;

const int N = (int) 3e5 + 5;
const int M = (int) 998244353;

typedef long long ll;

int n, x, s, res;

int main() {

    cin >> n;
    s = n + 1;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x < s) res++;
        s = min(s, x);
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;
int main()
{
    int x;
    cin >> x;
    if(x%7==1){
        cout << "fri" << endl;
    }else if(x%7==2){
        cout << "sat" << endl;
    }else if(x%7==3){
        cout << "sun" << endl;
    }else if(x%7==4){
        cout << "mon" << endl;
    }else if(x%7==5){
        cout << "tue" << endl;
    }else if(x%7==6){
        cout << "wed" << endl;
    }else{
        cout << "thu" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define mkp make_pair
const int maxn = 1e5 + 5;
map < int, map < int, int > > cnt;
map < int, map < int, int > > :: iterator X;
map < int, int > :: iterator Y;
int dir[9][2] = {
	0, 0, 0, 1, 0, 2,
	1, 0, 1, 1, 1, 2,
	2, 0, 2, 1, 2, 2,
};
LL ans[10];

int main(){
	int H, W, N, x, y;
	scanf("%d%d%d", &H, &W, &N);
	for(int i = 1; i <= N; i++){
		scanf("%d%d", &x, &y);
		for(int k = 0; k < 9; k++){
			int nx = x - dir[k][0];
			int ny = y - dir[k][1];
			if(1 <= nx && nx + 2 <= H && 1 <= ny && ny + 2 <= W)
				cnt[nx][ny]++;
		}
	}
	for(X = cnt.begin(); X != cnt.end(); X++){
		for(Y = X->second.begin(); Y != X->second.end(); Y++){
			ans[Y->second]++;
		}
	}
	ans[0] = (LL)H * W - 2LL * (H + W) + 4LL;
	for(int i = 1; i < 10; i++){
		ans[0] -= ans[i];
	}
	for(int i = 0; i < 10; i++){
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 70528
#include<stdio.h>
#include<algorithm>
using namespace std;
#define INFTY 2000000000
struct Card{
    char mark;
    int value;
};

Card L[100000/2+2], R[100000/2+2];

void merge(Card* A, int left, int mid, int right){

    int n1 = mid - left;
    int n2 = right - mid;
    for(int i=0; i<n1; i++) L[i] = A[left + i];
    for(int i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = INFTY;
    int i=0; int j = 0;
    for(int k=left; k<right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }
        else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card* A, int left, int right){
    int mid;
    if(left + 1<right){
        mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }

}

int partition(Card* A, int p, int r){
    int x = A[r].value;
    int i=p-1;
    for(int j=p; j<r; j++){
        if(A[j].value <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void quickSort(Card* A, int p, int r){
    int q;
    if(p<r){
        q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

int main(){

    int n;
    scanf("%d", &n);
    Card A[100000], B[100000];
    char S[10];
    for(int i=0; i<n; i++){
        int x;
        scanf("%s %d", S, &x);
        A[i].mark = B[i].mark =  S[0];
        A[i].value = B[i].value = x;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n-1);

    int flag = 0;
    for(int i=0; i<n; i++){
        if(A[i].mark != B[i].mark) flag = 1;
    }

    if(flag==1) printf("Not stable\n");
    else printf("Stable\n");
    for(int i=0; i<n; i++){
        printf("%c %d\n", B[i].mark, B[i].value);
    }
    return 0;

}


Measured memory_bytes: 4924
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  ll n, x;
  cin >> n >> x;

  vector<ll> all(51), p(51);
  all[0] = p[0] = 1;
  rep(i, 1, 51) {
    all[i] = all[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }

  ll ans = 0;
  int now = n;
  while (now > 1) {
    //真ん中より左にある場合(真ん中を含む)
    if ((all[now] + 1) / 2 <= x) {
      ans += p[now - 1] + 1;
      // bとpが1個ずつ余分についてるから引いておく
      x -= all[now - 1] + 2;
    } else {
      //真ん中より右にある場合(真ん中は含まない)
      //一番下のbを引いておく
      x--;
    }

    // 1個下の階層のバーガーを調べるためデクリメントする
    now--;
  }

  vector<ll> l1 = {0, 1, 2, 3, 3};
  ans += l1[min(4LL, max(0LL, x - 1))];

  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <cstdio>

using namespace std;

int getDigSum(int n){
  int sum=0;
  while (n){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(void){
  int n;
  int a,b;
  int ans = 0;
  
  scanf("%d%d%d", &n, &a, &b);
  for (int i=1; i<=n; i++){
    int s;
    s = getDigSum(i);
    ans += (s>=a && s <= b)?i:0;
  }
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())





N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)
x=uf.group_count()
print(x-1)





Measured memory_bytes: 79076
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20

class Counting():
    def __init__(self,maxim,mod):
        maxim += 1

        self.mod = mod
        self.fact = [0]*maxim
        self.fact[0] = 1
        for i in range(1,maxim):
            self.fact[i] = self.fact[i-1] * i % mod

        self.invfact = [0]*maxim
        self.invfact[maxim-1] = pow(self.fact[maxim-1],mod-2,mod)
        for i in reversed(range(maxim-1)):
            self.invfact[i] = self.invfact[i+1] * (i+1) % mod
        


    def nCk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[r] * self.invfact[n-r] % self.mod

    def nPk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[n-r] % self.mod

        
def main():
    X,Y=mi()
    MOD = 10**9+7
    C = Counting(10**6+10,MOD)
    ans = 0
    for a in range(X+1):
        if (X-a) %2 == 1: continue
        b = (X-a)//2

        if 2*a+b == Y:
            ans += C.nCk(a+b,a)
    
    print(ans)






if __name__ == "__main__":
    main()

Measured memory_bytes: 88932
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    char[] data = new char[n];
    String s = sc.next();
    int count = 1;

    for(int i = 0;i < n;i++) {
      data[i] = s.charAt(i);
    }

    for(int i = 0;i < n-1;i++) {
      if(data[i] == data[i+1]) {
        continue;
      } else {
        count++;
      }
    }

    System.out.println(count);

  }

}


Measured memory_bytes: 25940
#include <stdio.h>
int main()
{
    int a, b, c, ax, ac, bc;
    scanf("%d %d %d", &a, &b, &c);
    ax = a+b;
    ac = a+c;
    bc = b+c;
    if(ax<ac && ax<bc)
    {
        printf("%d", ax);
    }
    else if(ac<ax && ac<bc)
    {
        printf("%d", ac);
    }
    else
    {
        printf("%d", bc);
    }
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n];int mx=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];
        mx=max(mx,a[i]);
    }
    vector<int> f[n];int ans=1;
    for(int i=0;i<n;i++)
    {
        f[a[i]].pb(i);
    }
    for(int i=mx;i>0;i--)
    {
        vi in1;
        in1=f[i];
        sort(in1.begin(),in1.end());
        if(in1.size()>3)
            ans=0;
        vi in2;
        in2=f[i-1];
        sort(in2.begin(),in2.end());int taken=0;
        for(int j=0;j<in1.size();j++)
        {
            int cnt=0;
            for(int k=0;k<in2.size();k++)
                if(in2[k]<in1[j])
                    cnt++;
            
            ans=(ans%hell*(cnt-taken))%hell;
            taken++;
        }
    }
    if(f[0].size()==3||f[0].size()==2)
        ans=(ans%hell*6)%hell;
    else if(f[0].size()==1)
        ans=(ans%hell*3)%hell;
                 else
                 ans=0;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6528
n = input()
a = input()
a = list(map(int, a.split()))

def merge(l) :
  length = len(l)
  
  if(length <= 1) :
    return 0, l
  
  flag, left = merge(l[0:int(length/2)])
  if(flag == 1) :
    return 1, l
  flag, right = merge(l[int(length/2):length])
  if(flag == 1) :
    return 1, l
  
  total = []
  while(True) :
    if(len(left) == 0) :
      total.extend(right)
      return 0, total
    if(len(right) == 0) :
      total.extend(left)
      return 0, total
    if(left[0] == right[0]) :
      return 1, l
    if(left[0] < right[0]) :
      total.append(left.pop(0))
    else :
      total.append(right.pop(0))
        
a.sort()
for i in range(0, len(a)-1) :
  if(a[i] == a[i+1]) :
    print("NO")
    exit()

print("YES")

Measured memory_bytes: 27096
x0, y0, x1, y1 = map(int, input().split())
print(
    "R" * (x1 - x0)
    + "U" * (y1 - y0)
    + "L" * (x1 - x0)
    + "D" * (y1 - y0)
    + "D"
    + "R" * (x1 - x0)
    + "R"
    + "U"
    + "U" * (y1 - y0)
    + "L"
    + "U"
    + "L" * (x1 - x0)
    + "L"
    + "D"
    + "D" * (y1 - y0)
    + "R"
)


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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 3e3 + 10;

ll dp[maxn][maxn][3];
int n, s;

int a[maxn];

ll solve(int pos, int sum, int state)
{
  if(sum > s)
    return 0;

  if(pos == n || state == 2)
    return sum == s;
  
  ll &ans = dp[pos][sum][state];
  if(ans != -1)
    return ans;
  ans = 0;
  if(state == 0)
    ans += solve(pos + 1, 0, 0) + solve(pos, 0, 1);
  else if(state == 1)
    ans += solve(pos + 1, sum + a[pos], 1) + solve(pos + 1, sum, 1) 
         + solve(pos + 1, sum, 2);
  ans %= mod;
  return ans;
}

int main()
{
  ios::sync_with_stdio(false);
  MSET(dp, -1);
  cin >> n >> s;
  for(int i = 0 ; i < n ; i++)
    cin >> a[i];
  cout << solve(0, 0, 0) << endl;
  
  return 0;
}

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

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int sum = 0;
    REP(i, n){
        sum += a[i];
    }
    int ans = 0;
    double num = INF;
    REP(i, n){
        if(num > abs((double)sum / n - a[i])){
            ans = i;
            num = abs((double)sum / n - a[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE

ll n;
cin>>n;
ve <ll> v1(n),v2(n);
FOR(i,0,n)cin>>v1[i];
FOR(i,0,n)cin>>v2[i];
ll c=0;
ve <ll> st;

FOR(i,0,n)
st.pb(i+1);

ll c1=0,c2=0;
do{
if(v1==st)c1=c;
if(v2==st)c2=c;
c++;
}while(next_permutation(st.begin(),st.end()));

cout<<abs(c1-c2);


return 0;
 }


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

int table[15][15];

int main(void){
	int n;
	while(cin >> n,n){
		rep(i,n)rep(j,n) table[i][j]=-1;

		int ci=n/2+1,cj=n/2;
		int num=1;
		while(num<=n*n){
			if(table[ci][cj]!=-1){
				ci=(ci+1)%n;
				cj=(cj+n-1)%n;
			}
			table[ci][cj]=num++;
			ci=(ci+1)%n;
			cj=(cj+1)%n;
		}
		rep(i,n){
			rep(j,n) printf("%4d",table[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1140
import collections
s = [input() for i in range(int(input()))]
t = [input() for i in range(int(input()))]
s = list(collections.Counter(s).items())
ans = [0]
for i in range(len(s)):
  ans.append(s[i][1]-t.count(s[i][0]))
ans.sort(reverse = True)
print(ans[0])

Measured memory_bytes: 3316
import java.util.Scanner;

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

        while(true){
        	String str = sc.next();
        	if(str.equals("-")){
        		break;
        	}
        	int x = sc.nextInt();
        	StringBuilder sb = new StringBuilder();
        	sb.append(str);
        	for(int i=0; i<x; i++){
        		String t = sb.toString();
        		int y = sc.nextInt();
            	String tmp = t.substring(0, y);
            	sb.delete(0, y);
            	sb.append(tmp);
        	}
        	System.out.println(new String(sb));
        }
    }
}



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

int main(){
    long a,b,c,d;
    cin >> a >> b >> c >> d;
    long e = c*d/gcd(c,d);
    a--;
    cout << b-b/c-b/d+b/e-(a-a/c-a/d+a/e) << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    set<int> s;
    for(auto e:S){
        s.insert(e - 'a');
    }

    for(int i=0;i<=25;++i){
        if(s.count(i) != 1){
            cout << (char)(i+'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 3728
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
	
    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        long a[]=sc.nextLongArray(n),r=0;
        long s,w,v,sb,bt;
        for (int i = 0; i < 61; i++) {
        	s=(a[n-1]>>i)%2;
        	w=1;
        	sb=0;
			for (int j = n-2; 0 <= j; j--) {
	        	v=(a[j]>>i)%2;
	        	if(v==1) {	        		
	        		sb+=w-s;
	        		s++;
	        	} else {
	        		sb+=s;
	        	}
	        	sb%=mod;
	        	w++;
			}
			bt=1L<<i;bt%=mod;
			r+=bt*sb%mod;
			r%=mod;
		}

        out.println(r);
     	out.flush();
    }


    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//
//class P {
//	int x, y, d;
//	P(int  x, int y, int d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return -p.a+a;//as
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 80136
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

const int yazawa = 2521;
struct edge{
  int from,to,cost;
};
vector<int> to[yazawa];
vector<int> from[yazawa];
bool toN[yazawa];
bool from1[yazawa];
bool ok[yazawa];

void dfs(int v){
  if(from1[v]) return;
  from1[v] = 1;
  for(int u : to[v]){
    dfs(u);
  }
}
void redfs(int v){
  if(toN[v]) return;
  toN[v] = 1;
  for(int u : from[v]){
    redfs(u);
  }
}
int main(){
  int n,m,p;
  cin >> n >> m >> p;
  vector<edge> G;
  rep(i,m){
    int a,b,c;
     cin >> a >> b >> c;
     a--; b--; 
     c -= p; c = -c;
     G.push_back({a,b,c});
     to[a].push_back(b);
     from[b].push_back(a);
  }
  dfs(0);
  redfs(n-1);
  rep(i,n) ok[i] = from1[i] & toN[i];
  //Bellman-Ford
  vector<int> d(n,1001001001);
  d[0] = 0;
  bool upd = 1;
  int step = 0;
  while(upd){
    upd = 0;
    rep(i,m){
      int a,b,c;
      a = G[i].from;
      b = G[i].to;
      c = G[i].cost;
      if(!ok[a]) continue;
      if(!ok[b]) continue;
      int new_d = d[a] + c;
      if(new_d < d[b]){
        upd = true;
        d[b] = new_d;
      }
    }
    step++;
    if(step > n){
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = -d[n-1];
  ans = max(ans,0);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

long long gcd(long long a, long long b) {
    return (b == 0) ? a : gcd(b, a%b);
}

long long a, b;

int main() {
    cin >> a >> b;
    long long c = gcd(a, b);

    vector<long long> d;

    d.push_back(1);
    for(int i = 2; 1LL*i*i <= c; ++i) {
        if (c % i == 0) {
            d.push_back(i);
            while (c % i == 0)
                c /= i;
        }
    }

    if (c > 1)
        d.push_back(c);

    printf("%d\n", d.size());

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define CID(a) (a-'a')
 
int main(void){
    int str=1;
    int ary[26]={},n=0,i,f=0;
 
    while((str=getchar())!=EOF){
        if (str >= 'a' && str <= 'z') ary[CID(str)]++;
        else if (str >= 'A' && str <= 'Z') ary[CID(str)+('a'-'A')]++;
    }
    for(i=0;i<26;i++) printf("%c : %d\n",'a'+i,ary[i]);
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    deque<int> d;
    int nn = n % 2;
    for (int i = 0; i < n; i++){
        if (i % 2 != nn) d.push_front(a[i]);
        else d.push_back(a[i]);
    }
    for (int i = 0; i < n; i++){
        cout << d.front() << " ";
        d.pop_front();
    }
    cout << endl;
}

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

map<long long, long long> m;
long long f(long long h) {
  if (h == 1) {
    return 1;
  }
  if (m.find(h) != m.end()) {
    return m[h];
  } else if (m.find(h/2) != m.end()) {
    return m[h/2] * 2 + 1;
  } else {
    long long a = f(h / 2);
    m[h] = a * 2 + 1;
    return a * 2 + 1;
  }
}

int main() {
  long long h;
  cin>>h;
  cout<<f(h)<<endl;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())
import fractions
start = fractions.gcd(A, B)
count = 0
for i in range(start, 0, -1):
  if A % i == 0 and B % i == 0:
    count += 1
    if count == K:
      print(i)
      exit()

Measured memory_bytes: 5560
#include<cstdio>
int main(){
	int k;
	scanf("%d",&k);
	if(k<=1){
		printf("%d\n",k);
		for(int i=1;i<=k;i++)
			for(int j=1;j<=k;j++){
				printf("%d",i);
				if(j==k)puts("");
				else printf(" ");
			}
		return 0;
	}
	int n=(k+3)/4*2;
	printf("%d\n",n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			int x=(i+j)%n+1;
			if(i%2==0&&x+n<=k)x+=n;
			printf("%d",x);
			if(j==n)puts("");
			else printf(" ");
		}
}

Measured memory_bytes: 1152