akhauriyash/Code-Regression huggingface dataset:
if __name__ == '__main__':
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    elec = []
    point = 0
    for i in range(k):
        if t[i] == "r":
            point += p
            elec.append("r")
        if t[i] == "s":
            point += r
            elec.append("s")
        if t[i] == "p":
            point += s
            elec.append("p")

    for i in range(k, n):
        if elec[i - k] == t[i]:
            # if i < n - k:
            elec.append(" ")
        else:
            if t[i] == "r":
                point += p
                elec.append("r")
            if t[i] == "s":
                point += r
                elec.append("s")
            if t[i] == "p":
                point += s
                elec.append("p")
    print(point)


Measured memory_bytes: 4212
/*
 * X_Cubic.cpp
 *
 *  Created on: 2014/07/20
 *      Author: WanWan1985
 */
#include <iostream>
#include <math.h>
using namespace std;

int main(void) {
	// 入力値
	int iInput;
	cin >> iInput;

	// 実行
	double dOutput = pow((double)iInput, 3.0);

	// 出力
	cout << (int)dOutput << endl;

	return 0;
}

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

int dp[502][2][10][500][3], m;
char S[2][550];
int solve(int o) {
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0][0] = 1;
	int i;
	for (i = 0; S[o][i]; i++)rep(j, 2)rep(k, 10)rep(l, m)rep(d, 3) {
		if (dp[i][j][k][l][d] == 0)continue;
		int s, g, p = S[o][i] - '0';
		if (d == 1)s = k + 1, g = (j ? 9 : p);
		else if (d == 2)s = 0, g = (j ? k - 1 : min(k - 1, p));
		else s = 0, g = (j ? 9 : p);
		for (int x = s; x <= g; x++) {
			if (x&&k == x)continue;
			int y;
			if (d == 1)y = 2;
			else if (d == 2)y = 1;
			else {
				if (k == 0)y = 0;
				else if (x < k)y = 1;
				else y = 2;
			}
			(dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %= MOD;
		}
	}
	int sum = 0;
	rep(k, 2) {
		if (!k && !o)continue;
		rep(j, 10)rep(t, 3)(sum += dp[i][k][j][0][t]) %= MOD;
	}
	return sum;
}
int main() {
	scanf("%s%s%d", S[0], S[1], &m);
	printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}

Measured memory_bytes: 62044
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

vector<bool> visited;
ll ans = 0;
ll N, M;

void dfs(const Graph &G, ll v, ll depth) {
  if (visited[v]) return;
  if (depth == N - 1) {
    ans++;
  }
  visited[v] = true;

  for (auto next_v : G[v]) {
    if (visited[next_v]) continue;
    dfs(G, next_v, depth + 1);
  }
  visited[v] = false;
}

int main() {
  cin >> N >> M;
  Graph G(N);
  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    a--, b--;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  visited.assign(N, false);
  dfs(G, 0, 0);

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>

typedef long long ll;

using namespace std;

int main(){
    int N,X,Y;
    int ans [2001];
    cin >> N >> X >> Y;
    for(int i = 1 ; i <= N - 1 ; i++){
        ans[i] = 0;
    }
    for(int i = 1 ; i <= N ; i++){
        for(int j = 1 + i ; j <= N; j++){
            int min = j - i ;
            if(min > abs(i-X) + 1 + abs(j-Y)){
                min = abs(i-X) + 1 + abs(j-Y);
            }
            if(min > abs(i-Y) + 1 + abs(j-X)){
                min = abs(i-Y) + 1 + abs(j-X);
            }
            ans[min]++;
        }
    }
    for(int i = 1 ; i <= N-1 ; i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;
	REP(i, INF) {
		if (i*(i + 1) / 2 >= x) {
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>

using namespace std;

int a,b,c;

int main()
{
	scanf("%d%d%d",&a,&b,&c);
	swap(a,b); swap(a,c);
	printf("%d %d %d\n",a,b,c);
	return 0;
}

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;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    int n;
    vector<int> a(n);
    vector<int> b(n-1);
    cin >> n;
    rep(i,n-1) cin >> b[i];
    a[0]=b[0];
    for(int i=1;i<=n-2;i++){
        a[i]=min(b[i],b[i-1]);
    }
    a[n-1]=b[n-2];
    int s=0;
    rep(i,n){
        s+=a[i];
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 2000
#define LL long long
#define INF 1000000000000000000
int n;
LL a[MAXN+5],x;
LL minn[MAXN+5];
LL ans;
int main()
{
	ans=INF;
	scanf("%d%lld",&n,&x);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	memset(minn,0x3f,sizeof(minn));
	for(LL st=0;st<n;st++)
	{
		LL sum=0;
		for(LL j=0;j<=n-1;j++)
		{
			minn[j]=min(minn[j],a[(j-st+n)%n]);
			sum+=minn[j];
		}
		ans=min(ans,sum+st*x);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 504
#include<stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    int a[n+1];
    for ( int i = 1; i <= n; i++ ) {
        scanf("%d", &a[i]);
    }
    int cnt=0;
    for ( int i = 1; i <= n; i++ ) {
        if ( a[i] == i ) {
            int tmp = a[i];
            a[i] = a[i+1];
            a[i+1] = tmp;
            cnt += 1;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int h=fsc.nextInt(), w=fsc.nextInt();
        char[][] ans=new char[h+2][w+2];
        for(int i=0;i<h+2;i++){
            char[] line=null;
            if(i>0 && i<h+1){
                line=fsc.next().toCharArray();
            }
            for(int j=0;j<w+2;j++){
                if(i==0 || i==h+1) {
                    ans[i][j]='#';
                } else if(j==0 || j== w+1) {
                    ans[i][j]='#';
                } else {
                    ans[i][j]=line[j-1];
                }
                System.out.print(ans[i][j]);
            }
            System.out.print("\n");
        }
        fsc.close();
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define lli long long int
#define pii pair<lli,lli>
#define f first
#define sE second
lli n,x,y,t,mod=1e9+7,ans=0; 
int main() { 
    fast
    string s;
    cin>>s;
    if(s[0]!=s[1] || s[1]!=s[2] || s[0]!=s[2])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
        
} 

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int N;
    cin >> N;
    double x[N];
    double y[N];
    long double l[N];
    for (int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    for (int i=0; i<N; i++){
        long double tmp_l = 0;
        for (int j=0; j<N; j++){
            if(i != j){
                tmp_l += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            }
        }
        l[i] = tmp_l;
        //cout << l[i] << endl;
    }
    long double avg = 0;
    for (int i=0; i<N; i++){
        avg += l[i];
    }
    cout.precision(10);
    cout << fixed << avg / N;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define MAPFOR(it,m) for( auto it = (m).begin(); it != (m).end() ; ++it )
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

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

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

void Main()
{
	int a;
	cin >> a;
	if(a <= 599) {
		cout << 8 << endl;
		return;
	} else if(a <= 799) {
		cout << 7 << endl;
		return;
	} else if(a <= 999) {
		cout << 6 << endl;
		return;
	} else if(a <= 1199) {
		cout << 5 << endl;
		return;
	} else if(a <= 1399) {
		cout << 4 << endl;
		return;
	} else if(a <= 1599) {
		cout << 3 << endl;
		return;
	} else if(a <= 1799) {
		cout << 2 << endl;
		return;
	} else if(a <= 1999) {
		cout << 1 << endl;
		return;
	} 
}

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: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  ll N,K;
  cin >> N >> K;
  vector<vector<ll>> s(N);
  for(int i=0; i<N; i++){
    ll t,d;
    cin >> t >> d;
    t--;
    s[t].push_back(d);
  }
  for(auto &v: s){
    sort(v.begin(),v.end(),greater<ll>());
    if(v.empty()) v.push_back(-INF);
  }
  sort(s.begin(),s.end(),[&](vector<ll> a,vector<ll> b){
    return a[0] > b[0];
  });
  ll cur=0;
  priority_queue<ll> que;
  for(int i=0; i<K; i++){
    cur += s[i][0];
    for(int j=1; j<s[i].size(); j++){
      que.push(s[i][j]);
    }
  }
  for(int i=K; i<N; i++){
    for(int j=0; j<s[i].size(); j++){
      que.push(s[i][j]);
    }
  }
  ll res = cur + K*K;
  for(ll x=K-1; x>=1; x--){
    ll v = s[x][0];
    ll w = que.top();
    if(v < w){
      que.pop();
      cur += w;
      cur -= v;
    }else{
      break;
    }
    res = max(res, cur + x*x);
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define index_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIndex find_by_order
#define indexOf order_of_key
#define MOD 1000000007
#define MAX 200005

int dp[MAX];

bool compare(pair<int,int> &x , pair<int,int> &y){
    if(x.second < y.second){
        return true;
    }else if(y.second < x.second){
        return false;
    }else return x.first < y.first;
}

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

    vector<pair<int,int>> data(n);
    for(int i = 0 ; i< n; i++)
        cin>>data[i].first>>data[i].second;

    sort(data.begin() , data.end() , compare);

    int sum = 0;
    bool possible = true;
    for(int i = 0 ; i< n ; i++){
        sum += data[i].first;
        if(sum > data[i].second){
            possible = false;
            break;
        }
    }
    if(possible){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
}

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

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int res = 0;
		if (X == 1) {
			res += 300000;
		} else if (X == 2) {
			res += 200000;
		} else if (X == 3) {
			res += 100000;
		}
		if (Y == 1) {
			res += 300000;
		} else if (Y == 2) {
			res += 200000;
		} else if (Y == 3) {
			res += 100000;
		}
		if (X == 1 && Y == 1) {
			res += 400000;
		}
		System.out.print(res);
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const ll MOD = 1e9+7;

const ll INF = ll(1e18)+1;

int main() {
	ll n, k;
	cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll l = -INF, r = INF;
    while (l+1 < r) {
        ll x = (l+r)/2;
        bool ok = [&]{
            ll tot = 0;
            rep(i,n) {
                if (a[i] < 0) {
                    int l = -1, r = n;
                    while (l+1 < r) {
                        int c = (l+r)/2;
                        if (a[c]*a[i] < x) r = c;
                        else               l = c;
                    }
                    tot += n-r;
                } else {
                    int l = -1, r = n;
                    while (l+1 < r) {
                        int c = (l+r)/2;
                        if (a[c]*a[i] < x) l = c;
                        else               r = c;
                    }
                    tot += r;
                }
                if (a[i]*a[i] < x) tot--;
            }
            tot /= 2;
            return tot < k;
        }();
        if (ok) l = x;
        else    r = x;
    }
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
 
using namespace std;
 
void load(void);
void calc(void);
void output(void);
 
int N, K, res = 0;
vector<int> p(1000, 1001);

int main(){
	load();
	calc();
	output();
	return 0;
}
 
void load(void){
	int i;
	cin >> N >> K;
	for(i = 0;i < N;i++){
		cin >> p[i];
	}
}
 
void calc(void){
	int i;
	sort(p.begin(), p.end());
	for(i = 0;i < K;i++){
		res += p[i];
	}
}
 
void output(void){
	cout << res << endl;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String ans = "No";
    if((n % 10) == 9) ans = "Yes";
    if((n / 10) == 9) ans = "Yes";
    System.out.println(ans);
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i,n){
    cin >> a[i];
    b[i] = a[i] - i - 1;
  }
  sort(b.begin(), b.end());
  ll x = b[n / 2];
  ll ans = 0;
  rep(i,n){
    ans += max(x - b[i], -x + b[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
		
		int num = x/(y+z);
		
		if(x-num*(y+z) >= z) System.out.println(num);
		else System.out.println(num-1);
	}

}


Measured memory_bytes: 23508
n = int(input())
q = []
z = ['M','A','R','C','H']
import sys
from collections import Counter
import itertools

for _ in range(n):
    s = input()
    a = s[0]
    
    if a =='M' or a =='A' or a =='R' or a =='C' or a =='H':
        q.append(a)
        
b = Counter(q)
c = list(b.keys())
m = 0

if len(b) < 3:
    print(0)
    sys.exit()
else:
    p = list(itertools.combinations(c,3))

ans = 0
for f,g,h in p:
    ans += (b[f]*b[g]*b[h])
        
print(ans)

Measured memory_bytes: 52440
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<int, int> P;

int main() {
	FAST;

	int n,k;

	cin >> n >> k;

	int res = 0;

	if (n % k == 0) res = 0;
	else res = 1;

	cout << res << "\n";

	return 0;
}

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

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

typedef long long int ll;
const ll maxn = 1000000000000000000;
int main()
{
	ll x, y;
	scanf("%lld %lld", &x, &y);
	if(x == y) printf("-1\n");
	else 
	{
		for(ll i = 1; i < y; i++)
		{
			ll ans = x * i;
			if(ans > maxn) { printf("-1\n"); return 0; }
			if(ans % y != 0) { printf("%lld\n", ans); return 0; } 
		}
		printf("-1\n");
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, M, Q;
    int sum_v[505][505] = {0};

    cin >> N >> M >> Q;

	while (M--) {
        int l, r;
        cin >> l >> r;
        sum_v[l][r]++;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            sum_v[i][j] += sum_v[i-1][j];
            sum_v[i][j] += sum_v[i][j-1];
            sum_v[i][j] -= sum_v[i-1][j-1];
        }
    }

    while (Q--) {
        int p, q, ans;
        cin >> p >> q;

        ans = sum_v[q][q] - sum_v[q][p-1] - sum_v[p-1][q] + sum_v[p-1][p-1];

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 1001001001
#define MOD 1000000007
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int dp[45][450][450];
int a[45], b[45], c[45];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    int n, ma, mb;
    cin >> n >> ma >> mb;
    rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];
    rep(i, 0, 45) rep(j, 0, 450) rep(k, 0, 450) 
      dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i, 0, n) {
      erep(j, 0, 400) {
        erep(k, 0, 400) {
          if (dp[i][j][k] == INF) continue;
          dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
          dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
        }
      }
    }
    int ans = INF;
    rep(i, 1, 401) {
      rep(j, 1, 401) {
        if (i * mb == j * ma) ans = min(ans, dp[n][i][j]);
      }
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


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

int main(){
  long long ans[8][10];
  int  f=0;
  int sum,n,m;
  vector <int>a;
  string s;

  cin>>n;
  cin>>s;
  cin>>m;
  int b;
  for(int i=0;i<m;i++) {
    cin>>b;
    if(find(a.begin(), a.end(), b) == a.end()){
      a.push_back(b);
    }
  }
  reverse(s.begin(), s.end());
  m=a.size();
  fill(ans[0],ans[8],0);
  ans[0][0]=1;
  sum=0;
  for(int i=0;i<n;i++){
    bool g =i%2;
    if(s[i]=='*'){
      f++;
      for(int j=0;j<m;j++){
	b=a[j];
	if(g) b*=2;
	b=b/10+b%10;
	for(int k=0;k<10;k++)
	  ans[f][(b+k)%10] += ans[f-1][k];
      }
    }
    else {
      b=s[i]-'0';
      if(g) b*=2;
      sum=(sum+b/10+b%10)%10;
    }
  }
  if(sum==0) sum=10;
  cout<<ans[f][10-sum]<<endl;
 
  return 0;
}

Measured memory_bytes: 1352
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int64 n, m;
  cin >> n >> m;
  int64 ret = min(n, m / 2);
  m -= ret * 2;
  ret += m / 4;
  cout << ret << endl;
  return 0;
}


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

n, c = map(int, input().split())
X = [0]*n
V = [0]*n
for i in range(n):
    x, v = map(int, input().split())
    X[i] = x
    V[i] = v

from itertools import accumulate
# clock
A1 = [0]+V
A1 = list(accumulate(A1))
for i, x in enumerate(X):
    A1[i+1] -= x
#print(A1)

# counterclock
B1 = [0]+list(reversed(V))
B1 = list(accumulate(B1))
for i, x in enumerate(reversed(X)):
    B1[i+1] -= c-x
#print(B1)

import copy
MA1 = copy.copy(A1)
for i in range(1, n+1):
    MA1[i] = max(MA1[i-1], A1[i])

MB1 = copy.copy(B1)
for i in range(1, n+1):
    MB1[i] = max(MB1[i-1], B1[i])

#print(MA1)
#print(MB1)

A2 = copy.copy(A1)
for i, x in enumerate(X):
    A2[i+1] -= x
#print(A2)

B2 = copy.copy(B1)
for i, x in enumerate(reversed(X)):
    B2[i+1] -= c-x
#print(B2)

MA2 = copy.copy(A2)
for i in range(1, n+1):
    MA2[i] = max(MA2[i-1], A2[i])

MB2 = copy.copy(B2)
for i in range(1, n+1):
    MB2[i] = max(MB2[i-1], B2[i])

#print(MA2)
#print(MB2)

ans = 0
# clock > counterclock
for i in range(n+1):
    temp = MA2[i]+MB1[n-i]
    ans = max(ans, temp)
# counterclock > clock
for i in range(n+1):
    temp = MB2[i]+MA1[n-i]
    ans = max(ans, temp)
print(ans)


Measured memory_bytes: 94292
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define reg register
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,m,a[N],b[N],cnta,cntb;
ll ans;
inline int read()
{
	int x=0,w=1;
	char c=getchar();
	while (!isdigit(c)&&c!='-') c=getchar();
	if (c=='-') c=getchar(),w=-1;
	while (isdigit(c))
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
int main()
{
	n=read(),m=read();
	memset(a,127/3,sizeof(a));
	memset(b,127/3,sizeof(b));
	for (reg int i=1;i<=n;i++)
	{
		int x=read();
		if (x<0) a[++cnta]=-x;
		else b[++cntb]=x;
	}
	for (reg int i=1;i<=(cnta>>1);i++) swap(a[i],a[cnta-i+1]); 
	ans=min(a[m],b[m]);
	for (reg int i=1;i<=min(m,cnta);i++) ans=min(ans,(ll)a[i]+b[m-i]*2);
	for (reg int i=1;i<=min(m,cntb);i++) ans=min(ans,(ll)b[i]+a[m-i]*2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k)
        cout<<k<<endl;
    else if(k>a+b)
        cout<<(a-(k-(a+b)))<<endl;
    else
        cout<<a<<endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vs s(3);
	cin>>s[0]>>s[1]>>s[2];
	int ans=0;
	rep(i,n){
		if(s[0][i]==s[1][i] and s[1][i]==s[2][i]){
			ans+=0;
		}else if(s[0][i]==s[1][i] or s[0][i]==s[2][i] or s[2][i]==s[1][i]){
			ans+=1;
		}else{
			ans+=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char s[4];
	scanf("%s", s);
	int i;
	for (i = 0; i < 3; i++) {
		if (s[i] == '1') {
			printf("9");
		} else if (s[i] == '9') {
			printf("1");
		} else {
			printf("%c", s[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int N;
  int ansflg=0;
  int tmp;

  cin >> N;

  vector<int> t(N),x(N), y(N);
  for(int i = 0; i < N; i++){
    cin >> t[i] >> x[i] >> y[i];
  }

  for(int i = 0; i < N; i++){
    tmp= x[i] + y[i];

    if(tmp%2 != t[i]%2 || tmp > t[i]){
      ansflg=1;
    }

  }

  if(ansflg==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1408
/*
 * a.cpp
 *
 *  Created on: 2019/06/08
 *      Author: MEIP-users
 */




#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <locale>
#include <queue>
#include <tuple>
#include <map>
#include <fstream>

using namespace std;


#define MOD (long long int)(1e9+7)
#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 INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))




int main() {
	int n;
	cin >> n;
	if(n == 1){
		cout << "Yes" << endl;
		cout << 2 << endl;
		cout << 1 << " "<< 1 << endl;
		cout << 1 << " " << 1 << endl;
		return 0;
	}
	int kk;
	reps(i, 1000){
		int k = (i+1)*(i+2)/2;
		if(n == k){
			kk = i+2;
			break;
		}
		if(n < k){
			cout << "No" <<endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	cout << kk << endl;
	vector<vector<int>> gs;
	int m = 1;
	rep(i, kk){
		cout << kk-1 << " ";
		int cnt = kk-1;
		rep(j,gs.size()){
			cout << gs[j][0] << " ";
			cnt--;
			gs[j].erase(gs[j].begin());
		}
		if(cnt > 0){
			vector<int> g;
			rep(j,cnt){
				cout << m << " ";
				g.push_back(m);
				m++;
			}
			gs.push_back(g);
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	static long[] set;
	static int size;
	
	static void add(long val) {
		long me = Long.highestOneBit(val);
		for (int i = size - 1; i >= 0; i--) {
			long bit = Long.highestOneBit(set[i]);
			if (me == bit) {
				val ^= set[i];
				me = Long.highestOneBit(val);
			}
		}
		if (val != 0) {
			set[size++] = val;
			Arrays.sort(set, 0, size);
		}
	}
	
	static boolean canRemove(long val) {
		long me = Long.highestOneBit(val);
		for (int i = size - 1; i >= 0; i--) {
			long bit = Long.highestOneBit(set[i]);
			if (me == bit) {
				val ^= set[i];
				if (val == 0) {
					return true;
				}
				me = Long.highestOneBit(val);
			}
		}
		return false;
	}
	
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int T = sc.nextInt();
		set = new long[70];
		for (int caze = 0; caze < T; caze++) {
			int N = sc.nextInt();
			long[] vals = new long[N];
			for (int i = 0; i < N; i++) {
				vals[i] = sc.nextLong();
			}
			char[] S = sc.next().toCharArray();
			size = 0;
			
			boolean zero = true;
			for (int i = N - 1; i >= 0; i--) {
				if (S[i] == '0') {
					add(vals[i]);
				} else {
					if (!canRemove(vals[i])) {
						zero = false;
					}
				}
			}
			out.println(zero ? 0 : 1);
		}
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 40012
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define vll vector<ll>
#define here cout<<"I'm here\n";
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele;
}

int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    ll k,n;
    cin>>k>>n;
    vector<ll> v(n);
    for(auto &itr:v) cin>>itr;
    sort(v.begin(),v.end());
    ll ans=100000000;
    for(ll i=1;i<n;i++){
        ans=min(ans,(k-(v[i]-v[i-1])));
    }
    ans=min(ans,v[n-1]-v[0]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    repk(i, n, 1000) {
        string s = to_string(i);
        if (s[0] == s[1] && s[0] == s[2]) {
            cout << s << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a=0,i,c,j;
    string s;char cc;

    vector<long long>b;
       cin>>s;
    for(i=0;i<s.size();i++)
    {

        a+=s[i]-'0';
    }
    //cout<<a<<endl;
    if(a%9==0)
    {
       cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 3656
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>

#define ll long long

using namespace std;

const int maxn=1e5+10;
int k,x;
int main(){
    cin >> k >> x;
    for(int i=x-k+1;i<=x+k-1;i++) cout  << i <<" ";
 //   system("pause");
    return 0;
}

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

int main() {

  string S;

  cin >>S;
    int A;
  A=S.size();
  

  for (int i = 0; i < A; i++) {
   if(S.at(i)=='?'){
    S.at(i)='D'; 
   }
  }

   cout << S << endl;
 return 0;
}

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

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

int main(){
    int k, n; cin >> k >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    vector<int> b(n);
    rep(i,n-1){
        b[i] = a[i+1] - a[i];
    }
    b[n-1] = k - a[n-1] + a[0];

    vector<int>::iterator iter = max_element(b.begin(), b.end());
    b.erase(iter);
    int ans = accumulate(b.begin(), b.end(), 0);
    
    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

	string s, t;
	while (cin >> s >> t) {
        vector<vector<int>> dp(5000, vector<int>(5000));
        FOR(i, 0, s.size()) {
            FOR(j, 0, t.size()) {
                if (s[i] == t[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                }
                else {
                    dp[i + 1][j + 1] = 0;
                }
            }
        }
        int ans = 0;
        FOR(i, 0, dp.size()) {
            FOR(j, 0, dp[0].size()) {
                ans = max(ans, dp[i][j]);
            }
        }
        print(ans);
	}

	return 0;
}


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

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0){break;}
        int table[26];
        char chara[n+1];
        int maxi1=0;
        int maxi2=0;
        char max_chara[2];
        for(int i=0;i<26;i++)
            table[i]=0;
        for(int i=0;i<n;i++)
            cin>>chara[i];
        for(int t=0;t<n;t++){
            table[chara[t]-'A']++;
            if(table[chara[t]-'A']>maxi1){
                maxi1=table[chara[t]-'A'];
                max_chara[0]=chara[t];
            }
            else if(table[chara[t]-'A']>maxi2)maxi2=table[chara[t]-'A'];
            if(maxi1-maxi2 >= n-t){
                cout<<max_chara[0]<<" "<<t+1<<endl;
                break;
            }
            if(t==n-1)
                if(maxi1==maxi2)
                    cout<<"TIE"<<endl;
        }
    }
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define sz(x)       int(x.size())
//#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = 2002;
const int M = 2000 * 2000 + 2;

bitset<M> f;
int s, x, n;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n; f.set(0);
    for(int i = 1; i <= n; ++i) {
        cin >> x; s += x;
        f |= (f << x);
    }
    for(int i = (s + 1) >> 1; i <= s; ++i) {
        if(f[i]) return cout << i, 0;
    }
}


Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var s, t string

	fmt.Scan(&s, &t)

	for i := 0; i < n; i++ {

		fmt.Printf("%c%c", s[i], t[i])
	}
	fmt.Printf("\n")
}

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

int main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<int> row(h), col(w);
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    ++row[x];
    ++col[y];
    mp[{x, y}] = true;
  }
  int maxRow = *max_element(row.begin(), row.end());
  int maxCol = *max_element(col.begin(), col.end());
  vector<int> rows, cols;
  for (int i = 0; i < h; i++) 
    if (row[i] == maxRow)
      rows.push_back(i);
  for (int i = 0; i < w; i++)
    if (col[i] == maxCol)
      cols.push_back(i);
  int res = maxRow + maxCol;
  for (int row : rows) 
    for (int col : cols)
      if (!mp.count({row, col})) // at most 3 * 10 ^ 5!
        return cout << res, 0;
  cout << res - 1 << '\n';
  return 0;
}

Measured memory_bytes: 28540
#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    int a,b=0,n;
    string s,t;
    cin>>n;
    a=n;
    while(a>0){
        b+=a%10;
        a/=10;
    }
    if(n%b==0) cout<<"Yes\n";
    else cout<<"No\n";
    return(0);
}

Measured memory_bytes: 3604
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


m, n = map(int, input().split())
print((m-1)*(n-1))


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

int main()
{
    string s;
    cin >> s;
    int len_s = s.size();

    int answer = -1;
    for (int i = 1; i <= len_s; i++)
    {
        string s2 = s.substr(0, len_s - i);
        if ((s2.size()) % 2 == 0)
        {
            if (s2.substr(0, s2.size() / 2) == s2.substr(s2.size() / 2, s2.size() - 1))
            {
                answer = s2.size();
                break;
            }
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
VI e[SIZE];
int N,K,an;
int dfs(int x,int lt){
 int ma=0;
 REP(i,SZ(e[x])){
  ma=max(ma,dfs(e[x][i],x)+1);
 }
 if(ma==K-1&&x!=1&&lt!=1){an++;ma=-1;}
 return ma;
}
int main(){
 RII(N,K);
 REPP(i,1,N+1){
  DRI(x);
  if(i==1)an+=(x!=1);
  else e[x].PB(i);
 }
 dfs(1,1);
 cout<<an<<endl;
 return 0;
}

Measured memory_bytes: 34560
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

void print_arr(int* arr, int size) {
    for (int i = 0; i < size; i++) {
        cout << arr[i];
        if (i != size - 1) {
            cout << " ";
        }
    }
    cout << "\n";
}

void sort(int* arr, int size) {
    int counter = 0;
    int flag = 1;
    while (flag) {
        flag = 0;
        for (int j = size - 1; j >= 1; --j) {
            if (arr[j] < arr[j - 1]) {
                counter++;
                int tmp = arr[j];
                arr[j] = arr[j - 1];
                arr[j - 1] = tmp;
                flag = 1;
            }
        }
    }
    print_arr(arr, size);
    cout << counter << "\n";
}

int main() {

    int N = 0;
    cin >> N;
    int* arr = (int*)malloc(N * sizeof(int));

    int i = 0;
    while (i < N && scanf("%d", &arr[i]) == 1)
        i++;

    sort(arr, N);
    return 0;
}

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


void solve(){
    ll n;
    cin>>n;
    unordered_map<ll,ll> umap;
    ll sum=0;
    for(ll i=0; i<n; ++i){
        ll in;
        cin>>in;
        umap[in]++;
        sum += in;
    }
    // cout<<sum<<endl;
    
    // cout<<sum<<endl;
    ll q;
    cin>>q;
    while(q--){
        ll x,y;
        cin>>x>>y;
        sum += y*umap[x] - umap[x]*x;
        umap[y] += umap[x];
        umap[x] = 0;
        cout << sum << endl;

    }


}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}

Measured memory_bytes: 7088