akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define  N 100

int main(){
  int bubble[N];
  int flag;
  int i,j,num,temp,cnt=0;

  scanf("%d",&num);
  for(i=0;i<num;i++) scanf("%d",&bubble[i]);

  flag = 1;
  while(flag == 1){
    flag = 0;
    for(j=num-1;j>0;j--){
      if(bubble[j] < bubble[j-1]){
	//bubble[j]とbubble[j-1]を交換
	temp = bubble[j];
	bubble[j] = bubble[j-1];
	bubble[j-1] = temp;
	flag = 1;
	cnt++;
      }
    }
  }

  for(i=0;i<num;i++){
    if (i) printf(" ");
    printf("%d",bubble[i]);
  }
  
  printf("\n%d\n",cnt);
  
  return 0;
}



Measured memory_bytes: 2756
S = input()
length = len(S)
countB = 0
for c in S:
    if c == 'B':
        countB += 1
soko = 1
ans = 0
for i in range(length):
    if S[-i-1] == 'B':
        ans += i + 1  - soko
        soko += 1
print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int main(){
	int K;
	cin>>K;
	if(K==1){
		cout<<1<<endl;
		cout<<1<<endl;
		return 0;
	}
	int N = (K+3)/4*2;
	VV<int> a(N,V<int>(N));
	rep(i,2) rep(j,N) a[i][j] = (j+i*N < K) ? j+i*N : a[i-1][(j+N-1)%N];
	for(int i=2;i<N;i++) rep(j,N) a[i][j] = a[i-2][(j+N-2)%N];
	cout<<N<<endl;
	rep(i,N){
		rep(j,N) cout<<a[i][j]+1<<" ";
		cout<<endl;
	}
	cout<<endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int row,col;
  cin>>row>>col;
  vector<vector<char> > v;
  for(int i=0;i<row;i++)
  {
    vector<char> r;
    for(int j=0;j<col;j++)
    {
      char ch;
      cin>>ch;
      r.push_back(ch);
    }
    v.push_back(r);
  }
  int dp[row][col];
 	for(int i=0;i<row;i++)
    {
      for(int j=0;j<col;j++)
      {
        if(v[i][j]=='.')
        dp[i][j]=0;
        else 
          dp[i][j]=-1;
      }
    }
    dp[0][0]=1;
  for(int i=0;i<row;i++)
  {
    for(int j=0;j<col;j++)
    {
      if(dp[i][j]==-1)
        continue;
      else
      {
        if(j-1>=0 && dp[i][j-1]!=-1)
          dp[i][j]=((dp[i][j])%1000000007+(dp[i][j-1])%1000000007)%1000000007;
        if(i-1>=0 && dp[i-1][j]!=-1)
          dp[i][j]=((dp[i][j])%1000000007+(dp[i-1][j])%1000000007)%1000000007;
      }
    }
  }
  cout<<dp[row-1][col-1];
}


Measured memory_bytes: 5120
/*input

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

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#define F first
#define S second
#define mp make_pair
#define append push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define pb push_back
#define print(a) cout<<a<<endl
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define all(x) x.begin(), x.end()
#define loop(i,n) for(int i = 0; i < n; i++)
//#define int long long int
 
const int MOD = 1e9 + 7;

int fastexpo(int x, int y) 
{ 
    int res = 1;
    x = x % MOD;
    while (y) 
    { 
        if (y & 1) res = (res*x) % MOD; 
        y = y>>1;
        x = (x*x) % MOD;   
    } 
    return res; 
}

int mod(int x, int y){
    return (x%y + y)%y;
}

void solve();

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

    int t = 1;
    //cin>> t;
    while(t--){
        solve();
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

void solve(){
    int n, m;
    cin>> n >> m;
    priority_queue<int> pq;
    for(int i = 0; i < n; i++){
        int x;
        cin>> x;
        pq.push(-x);
    }
    vector<pair<int, int> > que;
    for(int i = 0; i < m; i++){
        int b, c;
        cin>> b >> c;
        que.append(mp(c, b));
    }
    sort(all(que));
    reverse(all(que));
    for(auto u : que){
        for(int i = 0; i < u.S and -pq.top() < u.F; i++){
            pq.pop();
            pq.push(-u.F);
        }
    }
    long long int ans = 0;
    while(!pq.empty()){
        ans +=-pq.top();
        pq.pop();
    }
    print(ans);
}

Measured memory_bytes: 1912
def d_checker(N, K, Q):
    # マス(x,y)が白⇔マス(x,y+K)が黒なので、希望の色がすべて黒になるようにする
    # 市松模様の周期は2Kなので、x,y座標をそれぞれ2Kで剰余を取った座標と同一視できる
    mat = [[0]*(2*K+2) for _ in range(2*K+2)]
    total = [[0]*(4*K+2) for _ in range(4*K+2)]
    for x, y, c in Q:
        if c == 'W':
            y += K
        mat[(x % (2*K)) + 1][(y % (2*K)) + 1] += 1

    # 事前に累積和を取る
    for x in range(1, 4*K+1):
        for y in range(1, 4*K+1):
            total[x][y] = total[x][y-1] + \
                mat[((x-1) % (2*K)) + 1][((y-1) % (2*K)) + 1]
    for y in range(1, 4*K+1):
        for x in range(1, 4*K+1):
            total[x][y] += total[x-1][y]

    def get(x, y):
        # 市松模様の橋の黒の座標を決めたときに実現できる希望の数
        return total[x+K-1][y+K-1] + total[x-1][y-1] - total[x-1][y+K-1] - total[x+K-1][y-1]

    ans = 0
    for x in range(1, 2*K+1):
        for y in range(1, 2*K+1):
            ans = max(ans, get(x, y)+get(x+K, y+K))
    return ans

N, K = [int(i) for i in input().split()]
Q = [(int(x), int(y), c)
    for x, y, c in [input().split() for i in range(N)]]
print(d_checker(N, K, Q))


Measured memory_bytes: 232196
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int h, w;
	while(1){
		cin >> h >> w;
		if(h == 0 && w == 0) break;
		int i, j;
		int h1 = 0, w1 = 0, s1 = 0, s2 = 0, s3 = 0, count = 0;
		bool hantei = false;
		for(i = 1;i <= 150;i++){
			for(j = i+1;j <= 150;j++){
				//cout << i << " " << j << endl;
				if(i > h && j != w && (h*h + w*w == i*i + j*j)){
					h1 = i;
					w1 = j;
					hantei = true;
					break;
					//cout << "h1 = " << h1 << " w1 = " << w1 << endl;
				}
			}
			if(hantei) break;
		}
		if(!hantei){
			for(i = 1;i < 150;i++){
				for(j = i+1;j < 150;j++){
					if((h*h + w*w < i*i + j*j) && count == 0){
						s1 = i*i +j*j;
						h1 = i;
						w1 = j;
						//cout << "h1 = " << h1 << " w1 = " << w1 << " s1 = " << s1 << endl;
						count++;
						break;
					}
					else if((h*h + w*w < i*i + j*j) && count != 0){
						s2 = i*i + j*j;
						if(s2 < s1){
							s1 = s2;
							h1 = i;
							w1 = j;
						}
					}
				}
			}
		}


		cout << h1 << " " << w1 << endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=1;i<=(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<=(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int min_weight[101][100001];
int weight[101]; 
int value[101]; 
int n,w; 
int ans =0;

void solve(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=100000;j++){
            if(value[i]==j){
                int temp = weight[i];
                min_weight[i][j] = min(temp,min_weight[i-1][j]);
            }
            else if(value[i]<j){
                int temp = weight[i]+min_weight[i-1][j-value[i]];
                // if(j==80)cout<<weight[i]<<" "<<min_weight[i-1][j-value[i]]<<endl;
                min_weight[i][j]  = min(min_weight[i-1][j],temp);
            }
            else{
                min_weight[i][j] = min_weight[i-1][j];
            }
            if(min_weight[i][j]<=w){
                // cout<<i<<" "<<j<<" "<<min_weight[i][j]<<endl;
                ans =max(ans,j);
            }
            
        }
    }
    cout<<ans;
}
 
int32_t main()
{
    
    from_j(i,0,100)from_j(j,0,100000)min_weight[i][j]=inf;
    c_p_c();
    cin>>n>>w;
    from(i,n)cin>>weight[i]>>value[i];
    solve();
    // cout<<max_value[n][w];
    
    
    
    return 0;
}


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

#define is_uruu leapyear
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)

int stack[3], top;
    
void push(int x){
	stack[++top] = x;
}

int  pop(){
	return stack[top--];
}
    
int main() {
	int a, b;
	string c;
	top = -1;
	while(cin >> c){
		if(c == "+"){
			a = pop();
			b = pop();
			push(a+b);
			continue;
		}
		if(c == "-"){
			a = pop();
			b = pop();
			push(b-a);
			continue;
		}
		if(c == "*"){
			a = pop();
			b = pop();
			push(a*b);
			continue;
		}
		push(atoi(c.c_str()));
	}
	cout << pop() << endl;
    return 0;
}


Measured memory_bytes: 3240
'''A - Curtain
https://atcoder.jp/contests/abc143/tasks/abc143_a

>>> main(12, 4)
4
>>> main(20, 15)
0
>>> main(20, 30)
0

'''


def main(a, b):
    print(max(0, a - b*2))


if __name__ == "__main__":
    a, b = map(int, input().split(' '))
    main(a, b)


Measured memory_bytes: 2940
//#include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef int64_t ll;

#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+6;

ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

// using namespace __gnu_pbds;
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set


int32_t main()
{
IOS

    
    int n,m;
    cin>>n>>m;
    int a[n+1];
    for(int i=1;i<=n;++i)
        cin>>a[i],a[i]/=2;
    sort(a+1,a+n+1);
    // for(int i=1;i<=n;++i)
    // {
    //     if(a[i]%2==0)
    //     {
    //         cout<<0;
    //         return 0;
    //     }
    // }
    int te=a[1],l=a[1];
    for(int i=2;i<=n;++i)
    {
        te=__gcd(l,a[i]);

        l=(l*a[i])/te;
        //cout<<l<<" "<<a[i]<<endl;
        if(l>m)
        {
            cout<<0;
            return 0;
        }
    }
    if(l%2==0)
    {
        int x=0;
        for(int i=1;i<=n;++i)
            x=__gcd(x,a[i]);
        for(int i=1;i<=n;++i)
        {
            a[i]/=x;
            if(a[i]%2==0)
            {
                cout<<0<<endl;
                return 0;
            }
        }
        cout<<(m/l+1)/2<<endl;
        return 0;
        
    }


   // cout<<l<<endl;
    cout<<(m/l+1)/2<<endl;

}    

Measured memory_bytes: 1024
n = int(input())

deg = [0 for i in range(n)]

from collections import defaultdict
G = defaultdict(list)


abl = []
for _ in range(n-1):
    a,b = map(int,input().split())
    deg[a-1] += 1
    deg[b-1] += 1
    abl.append((a-1, b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)

cl = list(map(int,input().split()))
cl = sorted(cl)
ansl = [0 for _ in range(n)]
for c in cl:
    for idx, d in enumerate(deg):
        if d == 1:
            ansl[idx] = c
            deg[idx] -= 1
            for j in G[idx]:
                deg[j] -= 1
            break
for idx, a in enumerate(ansl):
    if a == 0:
        ansl[idx] = cl[-1]

print(sum(cl[:-1]))
print(*ansl)




Measured memory_bytes: 55768
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define RREP(i, n) for(int i=0; i>(int)(n); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
typedef long long ll;
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;}

using namespace std;

int N;
ll a[3333];
ll dp[3333][3333];
bool flag[3333][3333];

ll f(int x, int y)
{
	if(flag[x][y]){
		return dp[x][y];
	}
	flag[x][y] = true;
	if(x==y){
		return dp[x][y] = a[x];
	}
	return dp[x][y] = max(a[x]-f(x+1, y), a[y]-f(x, y-1));
}

int main(void)
{
	cin >> N;
	REP(i, N){
		cin >> a[i];
	}
	REP(i, N){
		REP(k, N){
			flag[i][k] = false;
		}
	}
	cout << f(0, N-1) << "\n";
	return 0;
}


Measured memory_bytes: 90624
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<cmath>
using namespace std;
const int maxn=2e5+10;
typedef long long LL;
const LL mod=1e9+7;
const double pi=acos(-1.0);
int main()
{
    double r;
    scanf("%lf",&r);
    printf("%.6f\n",2.0*r*pi);
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

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

    int cnt_r=0,cnt_w=0;

    for(int i=0;i<n;i++)
    {
        if(s[i]=='W') cnt_w++;
        else cnt_r++;
    }
    int l=min(cnt_r,cnt_w);
    if(l==0) {
        cout<<0<<endl;
        return 0;
    }

    int ans=l;
    int swaps=0;

    for(int i=0;i<cnt_r;i++)
    {
        if(s[i]=='W') swaps++;
    }
    ans=min(ans,swaps);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3748
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


def floor_sum(n,m,a,b):  # sum((A*i+B)//M for i in range(N))
    res = 0
    if a >= m:
        res += (a//m)*n*(n-1)//2
        a %= m
    if b >= m:
        res += (b//m)*n
        b %= m
    y_max = (a*n+b)//m
    if y_max == 0:
        return res
    x_max = m*y_max-b
    res += (n+(-x_max)//a)*y_max
    res += floor_sum(y_max,a,m,(-x_max) % a)
    return res


T = I()
for i in range(T):
    n,m,a,b = MI()
    print(floor_sum(n,m,a,b))


Measured memory_bytes: 80152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main
{
	
	public static ArrayList<String> AL = new ArrayList<String>();
	
	
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n = fs.nextInt();
		int x = fs.nextInt();
		int t = fs.nextInt();
		int count =t;
		int c1 = x;
		while(n>c1) {
			c1+=x;
			count+=t;
		}
		System.out.println(count);
		
	}
	
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 32748
N = int(input())
pi = list(map(int, input().split()))
pi_sort = sorted(pi)
count = 0
for p, p_s in zip(pi, pi_sort):
    if p != p_s:
        count += 1

if count == 0 or count == 2:
    print('YES')
else:
    print('NO')

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,cs;
  cin >> n >> m;
  vector<int> c(m);
  vector<vector<int>> dp(50001,vector<int>(m+1,0));
  vector<int> dp2(50001,inf);
  rep(i,m){
    cin >> c[i];
  }
  dp[1][1] = 1;
  dp2[1] = 1;
  dp2[0] = 0;
  rep(i,n+1){
    for(int j = m-1; j >= 0; --j){
      if(i >= c[j]){
        dp2[i] = min(dp2[i],dp2[i-c[j]] + 1);
      }
    }
  }
//   rep(i,n+1){
//     cout << dp2[i] << " ";
//   }
//   cout << endl;
  cout << dp2[n]<<endl;
  return 0;
}

Measured memory_bytes: 8940
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

typedef Point Vector;


double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x*b.y - a.y*b.x;
}

int isContained(Point p, vector<Point> polygon);

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    int n, q;
    cin >> n;

    std::vector<Point> polygon(n);
    for(int i=0; i<n; i++){
        cin >> polygon[i].x >> polygon[i].y;
    }

    cin >> q;
    for(int j=0; j<q; j++){
        Point p;
        cin >> p.x >> p.y;
        cout << isContained(p, polygon) << "\n";
    }

    return 0;
}

//Is point p contained in polygon?
int isContained(Point p, vector<Point> polygon){
    int n = polygon.size();
    bool out = false;
    for(int i=0; i < n; i++){
        Vector a = polygon[i] - p;
        Vector b = polygon[(i+1)%n] - p;

        if(cross(a,b)==0 && dot(a,b)<=0){ //辺上にある場合
            return 1;
        }
        else {
            Vector big = ( (b.y > a.y)? b : a ) ;
            Vector small = ( (b.y > a.y)? a : b ) ;
            if(big.y > 0 && small.y <= 0 && cross(small,big) > 0){ //small.yだけ不等号なのが肝
                out = !out;
            }
        }
    }
    return (out? 2 : 0);
}



Measured memory_bytes: 3236
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
  int n = s.size();
  int ans = 0;
  rep(i,n/2){
    if(s[i]!=s[n-1-i]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if (A < C){
		if (C < B){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	if (A > C){
		if (C > B){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
}

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

int main(){
    string S;
    cin>>S;
    if(S.size()==1){
        cout<<0<<endl;
        return 0;
    }
    int ans=0;
    for(int i=1;i<S.size();i++){
        if(S[i]==S[i-1]){
            ans++;
            S[i]=(S[i]-'0'?'0':'1');
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
string s;
int A[5<<17];
main()
{
	cin>>s;
	int pre=0;
	int id=0;
	while(id<s.size())
	{
		while(id<s.size()&&s[id]=='<')id++;
		int x=id;
		while(id<s.size()&&s[id]=='>')id++;
		int y=id;
		for(int i=pre;i<=x;i++)
		{
			A[i]=i-pre;
		}
		int k=0;
		for(int j=y;j>=x;j--)
		{
			A[j]=max(A[j],k);
			k++;
		}
		pre=y;
	}
	long ans=0;
	for(int i=0;i<=s.size();i++)
	{
		//cout<<A[i]<<" ";
		ans+=A[i];
	}
	//cout<<endl;
	cout<<ans<<endl;
}


Measured memory_bytes: 2820
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>

using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
typedef long long ll;

ll n, k;
int main(){
	cin >> n >> k;
	n %= k;
	cout << min(n, k - n) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
def solve(R: int):
    ans = ["ABC", "ARC", "AGC"]
    if R < 1200:
        print(ans[0])
    elif 1200 <= R < 2800:
        print(ans[1])
    else:
        print(ans[2])

def main():
    R = int(input())
    solve(R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    vector<int> v(3);
    for (int i = 0; i < 3; i++) cin >> v[i];
    sort(v.begin(), v.end());
    cout << (v[0] + v[1] + v[2]*10) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

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

#define ll long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_in_out;
    int d,t,s;
    cin >> d >> t >> s;
    if((t * s) >= d)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No\n";
    }
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    ll n, k, q; cin >> n >> k >> q;
    V<ll> v(q);
    for(ll i = 0; i < q; i++){
        ll a; cin >> a;
        a--;
        v[i] = a;
    }

    V<ll> ans(n, k);
    for(int i = 0; i < q; i++){
        ans[v[i]]++;
    }

    for(int i = 0; i < n; i++){
        if(ans[i] - q <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    int A[101]={0};
    int B[101]={0};
    int i;
    for(i=a;i<b;i++){
        A[i]=1;
    }
    for(i=c;i<d;i++){
        B[i]=1;
    }
    int v=0;
    for(i=0;i<101;i++){
        if((A[i]==1)&&(B[i]==1)){
            v++;
        }
    }
    cout << v << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b =sc.nextInt();
    System.out.println((a-1)*(b-1));
  }
}

Measured memory_bytes: 21716
#include <iostream>

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

int main() {
    int N;
    scanf("%d", &N);
    REP(i, 14){
        REP(j, 25){
            if (N == 7*i+4*j) {
                printf("%s\n", "Yes");
                return 0;
            }
        }
    }
    printf("%s\n", "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int a[100010];
int main(){
    int n;
    cin>>n;
    REP(i,n) cin>>a[i];
    int cnt=0;
    if(n==1 || n==2) {
        cout<<1<<endl;
        return 0;
    }
    bool flag1=false,flag2=false;
    for (int i = 0; i < n-1; i++)
    {
        if(!flag2&&a[i]<a[i+1]){
            flag1=true;
        }
        if(flag1){
            if(a[i]>a[i+1]){
                cnt++;
                flag1=false;
               // cerr<<i<<endl;
                continue;
            }
        }
          if( !flag1 && a[i]>a[i+1]){
            flag2=true;
        }
        if(flag2){
            if(a[i]<a[i+1]){
                cnt++;
                flag2=false;
              //  cerr<<i<<endl;
                continue;
            }
        }
    }
    cout<<cnt+1<<endl;
    

    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

public class Main {
    static int maxturn;
    static int maxval = 10000007;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        /*int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int n = a*a*b*b*c;
        n = n*n;*/
        int n = sc.nextInt();
        boolean[] pri = new boolean[n+1];
        Arrays.fill(pri,true);
        ArrayList<Integer> prime = new ArrayList<>();
        for(int i=2;i<=n;i++){
            if(!pri[i]) continue;
            prime.add(i);
            for(int j=i;j<=n;j+=i) pri[j]=false;
        }
        HashMap<Integer,Integer> priIdx = new HashMap<>();
        for(int i=0;i<prime.size();i++) priIdx.put(prime.get(i),i);
        int[] cnt = new int[prime.size()];
        for(int i=2;i<=n;i++){
            int cur = i;
            for(int j=2;j<=cur;j++){
                while(cur%j==0){
                    int idx = priIdx.get(j);
                    cnt[idx]++;
                    cur /= j;
                }
            }
        }
        int c2=0,c4=0,c14=0,c24=0,c74=0;

        for(int i=0;i<cnt.length;i++){
            if(cnt[i]>=2) c2++;
            if(cnt[i]>=4) c4++;
            if(cnt[i]>=14) c14++;
            if(cnt[i]>=24) c24++;
            if(cnt[i]>=74) c74++;
        }
        int ans = c4*(c4-1)*(c2-2)/2+c24*(c2-1)+c14*(c4-1)+c74;
        System.out.println(ans);
    }
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int a = 0; a <= A; ++a){
    for (int b = 0; b <= B; ++b){
      for (int c = 0; c <= C; ++c){
        int TOTAL = 500*a + 100*b + 50*c;
        if (TOTAL == X) ++cnt;
      }
    }  
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int f(int x) {
  int cnt = 0;
  while (x % 2 == 0) {
    cnt++;
    x /= 2;
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += f(v[i]);
  }
  cout << res << endl;
}


Measured memory_bytes: 384
class Func
	def initialize()
		@list = Hash.new
	end

def insert(str)
  @list[str] = true
end


def find(str)
	if @list.has_key?(str)
		return "yes"
	else
		return "no"
	end
end


end

n = gets.to_i
f = Func.new
ans = []
n.times do
	command,str = gets.split.map(&:to_s)
	if command == "insert"
		f.insert(str)
	else
		ans << f.find(str)
	end
end

ans.each do |s|
	puts s
end

Measured memory_bytes: 74660
#include <bits/stdc++.h>
#define MAXN 50

using namespace std;

long long dp[MAXN + 1][2];

int main() {
   // fstream cin("A.in");
   // ofstream cout("A.out");
    int i, n, x, p;
    ios::sync_with_stdio(false);
    dp[0][0] = 1;
    cin >> n >> p;
    for(i = 1; i <= n; i++) {
        cin >> x;
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = dp[i - 1][1];
        if(x % 2 == 1) {
            dp[i][0] += dp[i - 1][1];
            dp[i][1] += dp[i - 1][0];
        }
        else {
            dp[i][0] += dp[i - 1][0];
            dp[i][1] += dp[i - 1][1];
        }
    }
    cout << dp[n][p];
   // cin.close();
   // cout.close();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;

string a, b;

int main(){
    AC
    cin>>a;
    cin>>b;
    int ans=0;
    for(int i=0; i<a.size(); i++){
        if(a[i]!=b[i])
            ans++;
    } 
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String S = sc.next();
    char[]ss = S.toCharArray();

    int cou = 0;
    for(int i=0; i<a; i++) {
    	if(ss[i] == '-') {
    		cou++;
    	}
    }
    for(int i=a+1; i<a+b+1; i++) {
    	if(ss[i] == '-') {
    		cou++;
    	}
    }
    if(ss[a] == '-') {
    	if(cou==0) {
    		System.out.println("Yes");    
        }else{
            System.out.println("No");
        }
    }else{
        System.out.println("No");

    	}
    }
}
    
    

Measured memory_bytes: 35832
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

static const int N = 1000;

int lcs(string X, string Y){
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X; //X[0]?????????????????\
    Y = ' ' + Y; //Y[0]?????????????????\
    for ( int i = 1; i <= m; i++) c[i][0] = 0;
    for ( int j = 1; j <= n; j++) c[0][j] = 0;
    
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if (X[i] == Y[j]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }else{
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main(){
    string s1, s2;
    int n; cin >> n;
    for( int i = 0; i < n; i++){
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}

Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a,sum;
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a;
        sum+=a;
    }
    if(n-sum>=0) cout<<n-sum;
    else cout<<"-1";
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t = "";
    int w;
    cin >> s >> w;
    int n = s.size();
    int idx = 0;
    while(idx < n){
        t += s[idx];
        idx += w;
    }
    cout << t << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  if (a <= b)
    cout << a << endl;
  else
    cout << a - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
       #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
int n,m;
int l;
signed main(){
string s[105];
cin>>n>>l;
	
	for(int i=0;i<n;i++) cin>>s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++) cout<<s[i];
	cout<<endl;
	return 0;
        }


Measured memory_bytes: 256
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a


a, b = map(int, input().split())
print(a*b//xgcd(a,b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n, m, len, sx, sy;
  cin >> n >> m >> len;
  cin >> sx >> sy;
  string S, T;
  cin >> S >> T;
  int lx = 1, rx = n, ly = 1, ry = m;
  for (int i = len - 1; i >= 0; i--) {
    if (T[i] == 'D') {
      lx = max(1, lx - 1);
    } else if (T[i] == 'U') {
      rx = min(n, rx + 1);
    } else if (T[i] == 'R') {
      ly = max(1, ly - 1);
    } else {
      ry = min(m, ry + 1);
    }
    if (S[i] == 'D') {
      rx--;
    } else if (S[i] == 'U') {
      lx++;
    } else if (S[i] == 'R') {
      ry--;
    } else {
      ly++;
    }
    if (lx > rx || ly > ry) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << (lx <= sx && sx <= rx && ly <= sy && sy <= ry ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 920
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
signed main()
{
  string c;
  int a,b;
  while(1){
  cin>>a>>c>>b;
  if(c=="+"){
    cout<<a+b<<"\n";
  }
  if(c=="-"){
    cout<<a-b<<"\n";
  }
  if(c=="*"){
    cout<<a*b<<"\n";
  }
  if(c=="/"){
    cout<<a/b<<"\n";
  }
  if(c=="?"){
    break;
  }
  }
  return(0);
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int n, ma, mb, dp[45][405][405], ans = IINF;

int main() {
    cin >> n >> ma >> mb;
    REP(i,45)REP(j,405)fill(dp[i][j],dp[i][j]+405,IINF/2);
    dp[0][0][0] = 0;
    REP(i,n){
        int a, b, c;
        cin >> a >> b >> c;
        REP(j,401){
            REP(k, 401){
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                if(j>=a && k>=b) dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j-a][k-b]+c);
            }
        }
    }
    for(int i=1;i<=(400/max(ma,mb));i++){
        ans = min(ans, dp[n][ma*i][mb*i]);
    }
    cout << (ans!=IINF/2?ans:-1) << endl;
    return 0;
}


Measured memory_bytes: 29056
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
ways = [[] for _ in range(N)]
for ab in AB:
    ways[ab[0] - 1].append(ab[1] - 1)
    ways[ab[1] - 1].append(ab[0] - 1)
c = 0
for i in range(N):
    if len(ways[i]) == 0:
        c += 1
        continue
    t = 0
    for j in ways[i]:
        if H[i] <= H[j]:
            break
    else:
        c += 1
print(c)


Measured memory_bytes: 47616
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        s = input()
        d[s[0]] += 1
    print(sum([d[c1] * d[c2] * d[c3] for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()


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

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

	vector<vector<int>> c(N, vector<int>(D));
	rep(i, N){
		rep(n, D) cin >> c.at(i).at(n);
	}
	int count = 0;
	rep(i, N){
		int n = i + 1;
		for(; n < N; n++){
			int sum = 0;
			rep(k, D){
				int a = max(c.at(i).at(k), c.at(n).at(k));
				int b = min(c.at(i).at(k), c.at(n).at(k));
				// cout << "i:" << i << " n:" << n << " " << a << "," << b << endl;
				sum += (a - b) * (a - b);
			}
			// cout << "sum = " << sum << endl;
			// cout << sqrt(sum) << " " << floor(sqrt(sum)) << endl;
			if (sqrt(sum) == floor(sqrt(sum))) count++;
		}
	}
	cout << count << endl;
}

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

int main(){
	
	int a,b,c;
	cin >> a >> b >> c;
    int ans;
    ans = c-(a-b);
    if( ans < 0 ) ans = 0;
	cout << ans << endl;
	return 0;
}

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

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d);
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
const int MAX_H = 11100;
const long long INF = 1e18;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    
    long long dp[MAX_H];
    fill(dp, dp+MAX_H, INF);
    dp[0] = 0;
    
    for (int i = 0; i < N; i++) {
        for (int j = A[i]; j < MAX_H; j++) {
            chmin(dp[j], dp[j - A[i]] + B[i]);
        }
    }
    
    long long ans = INF;
    for (int i = H; i < MAX_H; i++) chmin(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

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

#define MAX_INT 10100
int A[2000100];
int C[MAX_INT];
int B[2000100];

int main()
{
    int n;cin >>n;
    memset(A,sizeof(A),0);
    memset(B,sizeof(B),0);
    for(int i=1;i<=n;++i)
    {
        cin >> A[i];
    }
    memset(C,sizeof(C),0);
    for(int i =1;i<=n;++i)
    {
        C[A[i]]++;
    }
    for(int j=1;j<MAX_INT;++j)
    {
        C[j] = C[j] + C[j-1];
    }

    for(int k =1;k<=n;++k)
    {
        B[C[A[k]]] = A[k];
        C[A[k]]--;
    }
    for(int i=1;i<=n;++i)
    {
        if(i==1)cout << B[i];
        else
        {
            cout << " " << B[i];
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 18732
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9;

int main() {
    vector<int> A(5);
    cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
    vector<int> P = {0, 1, 2, 3, 4};
    int final_ans = INF;

    do {
        int ans = 0;
        for (int i = 0; i < 5; ++i) {
            while (ans % 10 != 0) ans += 1;
            ans += A[P[i]];
        }
        final_ans = min(final_ans, ans);
    } while (next_permutation(P.begin(), P.end()));
    cout << final_ans << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int main()
{
	long n, k, x, y;
	long res;

	cin >> n >> k >> x >> y;

	if (n <= k)
	{
		res = n * x;
	}
	else
	{
		res = k * x + (n - k) * y;
	}

	cout << res << endl;

	return 0;
}

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

int N; long long L;
struct Node
{
  bool p;
  Node* L;
  Node* R;
}; Node* root;

long long calc(Node* r, long long h)
{
  if(!r) return h&(-h);
  if(r->p) return 0;
  return calc(r->L, h-1)^calc(r->R, h-1);
}
void ins(Node* r, char* s)
{
  if(*s == 0){r->p = true; return;}
  if(*s == '0')
  {
    if(!(r->L))
    {
      r->L = new Node();
    }
    ins(r->L, s+1);
  }
  else
  {
    if(!(r->R))
    {
      r->R = new Node();
    }
    ins(r->R, s+1);
  }
}

char s[101010];
int main()
{
  root = new Node();
  scanf("%d%lld", &N, &L);
  for(int i=0; i<N; ++i)
  {
    scanf("%s", s);
    ins(root, s);
  }
  puts(calc(root, L+1)?"Alice":"Bob");
  return 0;
}

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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    int n, l;
    cin >> n >> l;
    string s[n];
    for(int i = 0; i < n; ++i) {
        cin >> s[i];
    }

    sort(s, s+n);
    for(auto ss : s)
        cout << ss;
    cout << '\n';
    return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <vector>

using namespace std;

int solve(int, int, int, int, int);

int main()
{
    int n, x, y, index;
    cin >> n >> x >> y;
    vector<int> ans(n, 0);

    for (int i = 1; i < n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            index = solve(n, x, y, i, j);
            ans[index] += 1;
        }
    }

    for (int i = 1; i < n; i++)
        cout << ans[i] << endl;
}

int solve(int n, int x, int y, int start, int end)
{
    int l = 0;
    l = min(min(abs(end - start), abs(x - start) + 1 + abs(end - y)), abs(y - start) + 1 + abs(end - x));
    return l;
}

Measured memory_bytes: 256
#include <map>
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>

int main() {

	int n;
	std::cin >> n;
	std::map<std::string, int> m;

	for (int i = 0; i < n; i++)
	{

		std::string s;
		std::cin >> s;
		std::sort(s.begin(), s.end());

		auto itr = m.find(s);
		if (itr != m.end()) (itr->second)++;
		else m.insert(make_pair(s, 1));
		
	}

	long long int ans = 0;

	for (auto itr = m.begin(); itr != m.end(); itr++)
	{
		long long int x = (itr->second);
		ans += x * (x - 1) / 2;
	}

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


Measured memory_bytes: 11136