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

n, m = list(map(int, input().split()))

submissions = []
for _ in range(m):
    num, result = input().split()
    submissions.append((int(num), result))

score = defaultdict(lambda: {"passed": False, "wa": 0})

for p, s in submissions:
    if score[p]["passed"]:
        pass
    elif s == "AC":
        score[p]["passed"] = True
    elif s == "WA":
        score[p]["wa"] += 1

ans = 0
pena = 0

# print(score)

for v in score.values():
    if v["passed"]:
        ans += 1
        pena += v["wa"]

print(ans, pena)

Measured memory_bytes: 55036
n,m = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(list)
for _ in range(1, m+1):
    a,b = list(map(int, input().split()))
    d[a].append(h[b])
    d[b].append(h[a])

ans=n-len(d)
for k,v in d.items():
    if h[k] > max(v):
        ans+=1
print(ans)

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

long g1(long n, int p) {
  if (n == 0) return 0;
  return n / p + g1(n / p, p);
}

long g2(long n, int p) {
  if (n % 2 == 1) {
    return g1(n, p) - g2(n - 1, p);
  }
  long res = g1(n / 2, p);
  if (p == 2) res += n / 2;
  return res;
}
 
int main() {
  long N;
  cin >> N;
  long ans = min(g2(N, 2), g2(N, 5));
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);

    temp = a;
    a = b;
    b = temp;

    temp = a;
    a = c;
    c = temp;

    printf("%d %d %d\n", a,b,c);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
#include <algorithm>
#include <vector>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

using namespace std;

#define MOD 1000000007

long n;
#define SZ 50

void mult( const ll a[SZ][SZ], const ll b[SZ][SZ], ll c[SZ][SZ] )
{
    long i, j, m;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            c[i][j] = 0;
            for(m=0; m<n; m++) {
                c[i][j] = (c[i][j] + a[i][m]*b[m][j] ) %MOD;
            }
        }
    }
    return;
}

void pow0( const ll a[SZ][SZ], const ll k, ll ans[SZ][SZ] )
{
    long i, j;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            ans[i][j]=(i==j)? 1: 0;
        }
    }
    if(k==0) {
        return;
    }
    else if(k==1) {
        for(i=0; i<n; i++) {
            for(j=0; j<n; j++) {
                ans[i][j]=a[i][j];
            }
        }
        return;
    }

    ll tmp[SZ][SZ];
    pow0( a, 1, tmp );
    
    ll m=k;
    for(i=0; m>0; i++) {
        ll tmp2[SZ][SZ];
        if(i>0) {
            mult( tmp, tmp, tmp2 );
            pow0( tmp2, 1, tmp );
        }        
        if(m & 1) {
            mult( ans, tmp, tmp2 );
            pow0( tmp2, 1, ans ); 
        }
        m=m>>1;
    }

    return;
}

int main(int argc, char* argv[])
{
    ll k;
    scanf("%ld %lld", &n, &k );
    
    ll a[SZ][SZ];
    long i, j;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            scanf("%lld", &(a[i][j]));
        }
    }

    ll ans[SZ][SZ];
    pow0( a, k, ans );

    ll sum = 0;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            sum = (sum + ans[i][j]) %MOD;
        }
    }

    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
int mod = 998244353;
ll fpow(ll x, ll p) {
	if (!p)
		return 1;
	ll sq = fpow(x, p / 2);
	sq *= sq;
	sq %= mod;
	if (p & 1)
		sq *= x;
	return sq % mod;
}
const int N = 2e5 + 9;
ll fact[N];
void preProc() {
	fact[0] = fact[1] = 1;
	for (int i = 2; i < N; i++)
		fact[i] = (fact[i - 1] * i) % mod;
}
ll nCrMod(ll n, ll r) {
	// you must call preProc before using nCr
	// you must modify mod first
	// you must modify N
	if (n < r) return 0;
	return (fact[n] * fpow((fact[n - r] * fact[r]) % mod, mod - 2LL)) % mod;
}
int main() {
	file();
	fast();
	preProc();
	ll n, m, k; cin >> n >> m >> k;
	if (k == n - 1)
		RT(fpow(m, n) << endl);
	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ll num = m * nCrMod(n - 1, i);
		num %= mod;
		num *= fpow(m - 1, n - i - 1);
		num %= mod;
		ans += num;
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
#include <string>
using namespace std;
bool use[10];
string s;
int ans = 200000;
void calc(int idx, bool tight, string ret) {
  //cout << "hello" << endl;
  if(idx == s.size()) {
    ans = min(ans, stoi(ret));
    return;
  }
  int digit = s[idx] - '0';
  int min_digit = 10;

  if(idx == 0) {
    int x = 200;
    for(int i=0;i<10;i++) {
      for(int j=0;j<10;j++) {
        if(use[i] && use[j]) {
          int tmp = i*10 + j;
          if(tmp > digit)
            x = min(x, tmp);
        }
      }
    }
    calc(idx+1, false, ret+to_string(x));
  }

  if(tight) {
    for(int i=9;i>=0;i--) {
      if(min_digit > i && use[i] && digit <= i)
        min_digit = i;
    }
    if(min_digit == 10) {
      return;
    }
    calc(idx+1, tight && digit == min_digit, ret + char(min_digit+'0'));
  } else {
    for(int i=9;i>=0;i--) {
      if(min_digit > i && use[i])
        min_digit = i;
    }
    calc(idx+1, tight, ret+char(min_digit+'0'));
  }
}

int main() {
  cin >> s;
  int k;
  cin >> k;
  for(int i=0;i<10;i++)
    use[i] = true;
  for(int i=0;i<k;i++) {
    int di;
    cin >> di;
    use[di] = false;
  }
  calc(0, true, "");
  cout << ans << endl;



}


Measured memory_bytes: 256
from collections import defaultdict as ddict
d = ddict(int)
d[0] = 0
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
for i in range(n-1):
  for j in range(i+1,n):
    curx = l[j][0] - l[i][0]
    cury = l[j][1] - l[i][1]
    d[(curx,cury)] += 1
print(n-max(d.values()))

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int c[200010],n,m;
vector<int> vec[200010];
void add(int s,int w){while (s<=m) {c[s]+=w;s+=s&(-s);}}
int sum(int s){int ans=0;while (s) {ans+=c[s];s-=s&(-s);}return ans;}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		int l,r;scanf("%d%d",&l,&r);
		vec[r-l+1].push_back(l);
	}
	int now=n;
	for (int i=1;i<=m;i++)
	{
		now-=vec[i-1].size();int ans=now;
		for (int k=0;k<vec[i-1].size();k++)
		{
			add(vec[i-1][k],1);
			add(vec[i-1][k]+i-1,-1);
		}
		for (int j=i;j<=m;j+=i) ans+=sum(j);
		printf("%d\n",ans);
	}
} 

Measured memory_bytes: 9088
#include <algorithm>
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  method(input,set<int>){
    int n = in();
    set<int> s;
    rep(_,n)s.emplace(in());
    return s;
  };
  set<int> x = input();
  set<int> y = input();
  set<int> ans;
  set_symmetric_difference(all(x),
                           all(y),
                           inserter(ans,ans.end()));
  foreach(i,ans){
    cout << i << endl;
  }
}



Measured memory_bytes: 40656
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <string>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc116_b(vector<vector<string>> v) {

    int s = atoi(v[0][0].c_str());

    int cnt = 1;

    if(s==1 || s==2){
        
        s=4;
    }
    
    while (s!=4) {

//        cout << s << " ";
        if (s % 2 == 0) {
            s /= 2;
        } else {
            s = s * 3 + 1;
        }
        
        cnt+=1;

    }

//    cout << endl;
    cout << cnt + 3 << endl;

}

int main() {

    vector<vector < string>> vec_arr_result;
    //    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata();

    abc116_b(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;
    cin>>N;
    vector<int> p(N);
    cin>>p;
    vector<int> a(N,-1);
    vector<vector<int>> g(N);
    stack<int> s;
    FOR(i,1,N+1){
        int id=N-i;
        g[p[id]-1].pb(id);
    }
    REP(i,N){
        for(auto &it:g[i])s.push(it);
        if(s.size()&&a[i]==-1){
            a[i]=s.top();s.pop();
        }
    }
    REP(i,N){
        if(s.size()&&a[i]==-1){
            a[i]=s.top();s.pop();
        }
    }
    REP(i,N)cout<<a[i]+1<<endl;
    return 0;
}

Measured memory_bytes: 7876
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

const int Maxn = 200010;

int n, x;

int idx[Maxn];

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

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        idx[x] = i;
    }
    set<int> s;
    s.insert(-1), s.insert(n);
    ll ans = 0;
    for (int v = 1; v <= n; ++v) {
        int i = idx[v];
        auto itr = s.upper_bound(i);
        ans += 1LL * v * (*itr - i) * (i - *(--itr));
        s.insert(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 10368
import sys
readline = sys.stdin.readline

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(2341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

def accumulate2d(X2):
    X = X2
    N = len(X)
    M = len(X[0])
    
    for i in range(N):
        for j in range(1, M):
            X[i][j] += X[i][j-1]
    
    for j in range(M):
        for i in range(1, N):
            X[i][j] += X[i-1][j]
    
    return X

r1, c1, r2, c2 = map(int, readline().split())

def calc(R, C):
    if min(R, C) == 0:
        return 1
    res = R
    for i in range(1, C):
        res = (res + comb(R+i, i+1)) % MOD
    return res
r2 += 1
c2 += 1
print((calc(r2, c2)-calc(r2, c1)-calc(r1, c2)+calc(r1, c1))%MOD)

Measured memory_bytes: 116012
def delta(t1,t2):
    h,m = [int(t2[i:i+2]) - int(t1[i:i+2]) for i in [0,3]]
    return 60*h + m
     
n,t = map(int,raw_input().split())
s = [raw_input().split() for i in range(n)]
a = []
for i in range(1,n):
    dt = delta(s[i-1][2],s[i][0])
    if dt >= t:
        a.append([s[i][1],str(dt)])
print len(a)
for i in a:
    print " ".join(i)

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

int main() {
  int a1,a2,a3,a4,a5,a6,a7,a8,a9;
  int N;
  int b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
  cin >> a1 >> a2 >> a3  >> a4 >> a5 >> a6 >> a7 >> a8 >> a9 >> N >>
    b1 >> b2 >> b3 >> b4 >> b5 >> b6 >> b7 >> b8 >> b9 >> b10;
  if (a1 == b1 || a1 == b2 || a1 == b3 || a1 == b4 || a1 == b5 || 
      a1 == b6 || a1 == b7 || a1 == b8 || a1 == b9 || a1 == b10) {
    a1 = 0;
  }
  else {
    a1 = 1;
  }
  if (a2 == b1 || a2 == b2 || a2 == b3 || a2 == b4 || a2 == b5 || 
      a2 == b6 || a2 == b7 || a2 == b8 || a2 == b9 || a2 == b10) {
    a2 = 0;
  }
  else {
    a2 = 2;
  }
   if (a3 == b1 || a3 == b2 || a3 == b3 || a3 == b4 || a3 == b5 || 
      a3 == b6 || a3 == b7 || a3 == b8 || a3 == b9 || a3 == b10) {
    a3 = 0;
  }
  else {
    a3 = 3;
  }
   if (a4 == b1 || a4 == b2 || a4 == b3 || a4 == b4 || a4 == b5 || 
      a4 == b6 || a4 == b7 || a4 == b8 || a4 == b9 || a4 == b10) {
    a4 = 0;
  }
  else {
    a4 = 4;
  }
   if (a5 == b1 || a5 == b2 || a5 == b3 || a5 == b4 || a5 == b5 || 
      a5 == b6 || a5 == b7 || a5 == b8 || a5 == b9 || a5 == b10) {
    a5 = 0;
  }
  else {
    a5 = 5;
  }
   if (a6 == b1 || a6 == b2 || a6 == b3 || a6 == b4 || a6 == b5 || 
      a6 == b6 || a6 == b7 || a6 == b8 || a6 == b9 || a6 == b10) {
    a6 = 0;
  }
  else {
    a6 = 6;
  }
   if (a7 == b1 || a7 == b2 || a7 == b3 || a7 == b4 || a7 == b5 || 
      a7 == b6 || a7 == b7 || a7 == b8 || a7 == b9 || a7 == b10) {
    a7 = 0;
  }
  else {
    a7 = 7;
  }
   if (a8 == b1 || a8 == b2 || a8 == b3 || a8 == b4 || a8 == b5 || 
      a8 == b6 || a8 == b7 || a8 == b8 || a8 == b9 || a8 == b10) {
    a8 = 0;
  }
  else {
    a8 = 8;
  }
   if (a9 == b1 || a9 == b2 || a9 == b3 || a9 == b4 || a9 == b5 || 
      a9 == b6 || a9 == b7 || a9 == b8 || a9 == b9 || a9 == b10) {
    a9 = 0;
  }
  else {
    a9 = 9;
  }
  if ((a1 == a2 && a1 == a3) || 
      (a4 == a5 && a4 == a6) ||
      (a7 == a8 && a7 == a9) ||
      (a1 == a4 && a1 == a7) ||
      (a2 == a5 && a2 == a8) ||
      (a3 == a6 && a3 == a9) ||
      (a1 == a5 && a1 == a9) ||
      (a3 == a5 && a3 == a7)) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" << endl;
  }  
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1e9+7;
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;};
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
int n,q;
int s[100005];

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	int x;
	ll res=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		s[x]++;
		res+=x;
	}
	cin>>q;
	int y;
	while(q--)
	{
		scanf("%d%d",&x,&y);
		res=res-1LL*s[x]*x+1LL*s[x]*y;
		s[y]+=s[x];
		s[x]=0;
		printf("%lld\n",res);
	}
	return 0;
}

Measured memory_bytes: 4144
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;
const int mod = 1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};



int main()
{
    ll k;
    cin >> k;
    string s;
    cin >> s;
    ll n = s.size();
    ll tmp = 1;
    combination c(n+k);
    mint ans = 0;
    for(int i = 0; i<=k; i++){
        mint now = mint(26).pow(k-i);
        now *= mint(25).pow(i);
        now *= c(i+n-1, n-1);
        ans += now;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 35552
#!/usr/bin/env python3
a, b, c, x, y = map(int, input().split())
print(
    min(
        a * x + b * y,
        max(x, y) * c * 2,
        c * x * 2 + (y - x) * b if y > x else c * y * 2 + (x - y) * a if x > y else 10**9,
    ))


Measured memory_bytes: 61880
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
string s;

int main() {
	cin >> m>> n;
	for (int i = 0; i < 2*m-1; i++)
	{
		cout << n - m + i+1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define P pair<int, int>
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, 0, n) cin >> b[i];
    vector<int> ans(n);
    if(b[0] != 1) {
        cout << -1 << endl;
        return 0;
    }

    ans[0] = b[0];
    rep(i, 1, n) {
        auto itr = ans.begin()+(b[i]-1);
        //cout << "itr: " << *itr  << " " << *ans.begin()<< endl;
        if(b[i]-1 != i && *itr == 0) {
            cout << -1 << endl;
            return 0;
        }
        ans.insert(itr, b[i]);
    }
    rep(i, 0, n) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;


public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var ans1 = a / b;
        var ans2 = a % b;
        var ans3 = (decimal)a / b;
        Console.WriteLine("{0} {1} {2}", ans1, ans2, ans3);

    }
}

Measured memory_bytes: 9216
def main():
  x = input()
  if x == 'RSS' or x == 'SRS' or  x == 'SSR' or  x == 'RSR':
    print(1)
  elif x == 'RRS' or x == 'SRR':
    print(2)
  elif x == 'RRR':
    print(3)
  else:
    print(0)
main()

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

long long cnt;
vector<int> G;

void insertionSort(vector<int>& A, int g) {
  for (int i = g; i < A.size(); i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(vector<int>& A) {
  for (int h = 1; ;) {
    if (h > A.size()) {
      break;
    }
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int  i = G.size() - 1; i >= 0; i--) {
    insertionSort(A, G[i]);
  }
}

int main(){
  vector<int> A;
  A.reserve(100000);

  int N, a;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  cnt = 0;

  shellSort(A);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--) {
    cout << G[i];
    if (i) {
      cout << " ";
    }
  }
  cout << endl;
  cout << cnt << endl;
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 6744
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

//セグメント木を持つグローバル配列
int N;
int dat[2 * 1000010 - 1];

//初期化
void init(int N_) {
    N = 1;
    //簡単のため、要素数を2のべき乗に
    while(N < N_) {
        N *= 2;
    }
    //すべての値をINFに
    for(int i = 0;i < 2 * N - 1;i++) {
        dat[i] = pow(2,31) - 1;
    }
}

//k番目の値(0-indexed)をaに変更
void update(int k,int a) {
    //葉の節点
    k += N - 1;
    dat[k] = a;
    //登りながら更新
    while(k > 0) {
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1],dat[k * 2 + 2]);
    }
}

//[a,b)の最小値を求める
//後ろの方の引数は、計算のための引数。
//kは節点の番号、1,rはその節点が[1,r)に対応づいていることを表す。
//したがって、外からはquery(a,b,0,0,n)として呼ぶ。
int query(int a,int b,int k,int l,int r) {
    //[a,b)と[l,r)が交差しなければ、INF
    if(r <= a || b <= l) {
        return pow(2,31) - 1;
    }

    //[a,b)が[l,r)を完全に含んでいれば、この節点の値
    if(a <= l && r <= b) {
        return dat[k];
    }
    else {
        //そうでなければ、2つの子の最小値
        int vl = query(a,b,k * 2 + 1,l,(l + r) / 2);
        int vr = query(a,b,k * 2 + 2,(l + r) / 2,r);
        return min(vl,vr);
    }
}

signed main() {
    cin >> N;
    int Q;
    cin >> Q;
    init(N);
    for(int i = 0;i < Q;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        if(A == 0) {
            update(B,C);
        }
        else {
            cout << query(B,C + 1,0,0,N) << endl;
        }
    }
}


Measured memory_bytes: 5136
#!/usr/bin/env python
H, W = map(int, input().split())
A = [[s for s in input()] for i in range(H)]

row = [False]*H
col = [False]*W

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(A[i][j], end='')
        print()

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

int main(){
  long long n;
  cin >> n;
  long long s5=0;
  long long a=10;
  
  while(n>=a){
  s5 +=n/a;
  a= a*5;
  }
  
  if(n%2 == 1){cout << 0 << endl;}else{
  cout << s5 << endl;}
}

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

int a[500][500] = {};

//解答用  移動
struct pos {
	int y1, x1, y2, x2;
};
vector<pos> v;

int main() {
	int h, w; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) cin >> a[i][j];

	//１行ずつ右端に1つずつ移動させる
	rep(i, 0, h) rep(j, 0, w - 1) {
		if (a[i][j] & 1) {
			a[i][j + 1]++;
			pos p;
			p.y1 = i + 1;
			p.x1 = j + 1;
			p.y2 = i + 1;
			p.x2 = j + 2;
			v.push_back(p);
		}
	}
	//右端列を上から下にに1つずつ移動させる
	rep(i, 0, h - 1) {
		if (a[i][w - 1] & 1) {
			a[i + 1][w - 1]++;
			pos p;
			p.y1 = i + 1;
			p.x1 = w;
			p.y2 = i + 2;
			p.x2 = w;
			v.push_back(p);
		}
	}

	//解答を出力
	cout << v.size() << endl;
	for (vector<pos>::iterator it = v.begin(); it != v.end(); it++) {
		cout << it->y1 << " " << it->x1 << " " << it->y2 << " " << it->x2 << endl;
	}

	return 0;
}

Measured memory_bytes: 5104
class Dice:
    def __init__(self,numbers):
        self.surface=numbers

    def inspection(self,other):
        string=''
        a=self.surface[0]
        b=self.surface[1]
        c=self.surface[2]
        d=self.surface[3]
        e=self.surface[4]
        f=self.surface[5]
        match1=a+b+c+d+e+f
        match2=b+f+c+d+a+e
        match3=c+b+f+a+e+d
        match4=d+b+a+f+e+c
        match5=e+a+c+d+f+b
        match6=f+e+c+d+b+a
        match7=f+b+d+c+e+a
        match8=a+d+b+e+c+f
        match9=d+f+b+e+a+c
        match10=b+d+f+a+c+e
        match11=e+d+a+f+c+b
        match12=c+a+b+e+f+d
        match13=f+c+b+e+d+a
        match14=f+d+e+b+c+a
        match15=a+e+d+c+b+f
        match16=e+f+d+c+a+b
        match17=d+e+f+a+b+c
        match18=c+e+a+f+b+d
        match19=b+a+d+c+f+e
        match20=a+c+e+b+d+f
        match21=c+f+e+b+a+d
        match22=e+c+f+a+d+b
        match23=b+c+a+f+d+e
        match24=d+a+e+b+f+c
        for i in other.surface:
            string+=i
        if string==match1 or string==match2 or string==match3 or string==match4 or string==match5 or string==match6 or string==match7 or string==match8 or string==match9 or string==match10 or string==match11 or string==match12 or string==match13 or string==match14 or string==match15 or string==match16 or string==match17 or string==match18 or string==match19 or string==match20 or string==match21 or string==match22 or string==match23 or string==match24:
            return 'Yes'
        return 'No'

dice1=Dice(input().split())
dice2=Dice(input().split())
result=dice1.inspection(dice2)
print(result)


Measured memory_bytes: 5596
#!/usr/bin/env python3
from collections import deque

# input
n, m = map(int, input().split())
a = [-1 for _ in range(m)]
b = [-1 for _ in range(m)]
to = [[] for _ in range(n+1)]
for i in range(m):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    to[a[i]].append(b[i])
    to[b[i]].append(a[i])

# calc
inf = 1001001001
dist = [inf for _ in range(n)]
pre = [-1 for _ in range(n)]
dist[0] = 0 
q = deque()
q.append(0)

while q:
    v = q.popleft()
    for u in to[v]:
        if dist[u] == inf:
            dist[u] = dist[v] + 1 
            pre[u] = v 
            q.append(u)

print('Yes')
for i in range(n):
    if i == 0:
        continue
    else:
        ans = pre[i]
        ans += 1
        print(ans)


Measured memory_bytes: 38228
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	ll x,sum = 0,y,l;cin >> x;
	int u = floor(log(x) / log(2));
	sum =  2 * pow(2, u);
	cout << sum - 1  << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
//#define debug
#define MP make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
const int le5=1e5;
int x,y;
int A,B,C;
int a[le5+10],b[le5+10],c[le5*3+10];
bool cmp(int a,int b){return a>b;}
int main()
{
	scanf("%d%d",&x,&y);
	scanf("%d%d%d",&A,&B,&C);
	
	for(int i=1; i<=A; i++)
		scanf("%d",&a[i]);
	for(int i=1; i<=B; i++)
		scanf("%d",&b[i]);
	for(int i=1; i<=C; i++)
		scanf("%d",&c[i]);
	
	sort(a+1,a+1+A,cmp);
	sort(b+1,b+1+B,cmp);

	for(int i=1; i<=x; i++)
		c[C+i]=a[i];
	for(int i=1; i<=y; i++)
		c[C+x+i]=b[i];
		
	sort(c+1,c+1+C+x+y,cmp);
	
	#ifdef debug
	//一维数组打表
	printf("A:\n");
	for(int i=1; i<=C+x+y; i++)
		printf("%3d",i);
	printf("\n");
	for(int i=1; i<=C+x+y; i++)
		printf("%3d",c[i]);
	printf("\n");
	#endif
	ll sum=0;
	for(int i=1; i<=x+y; i++)
		sum+=c[i];
	printf("%lld\n",sum);
	
//	#ifdef debug
//	//一维数组打表
//	printf("A:\n");
//	for(int i=1; i<=A; i++)
//		printf("%3d",i);
//	printf("\n");
//	for(int i=1; i<=A; i++)
//		printf("%3d",a[i]);
//	printf("\n");
//	#endif
//	
//	int pa=1,pb=1,pc=1;
//	ll sum=0;
////	while(pa<=A&&pb<=B&&pa+pb+pc<=A+B)
//	while(pa+pb+pc<=x+y+2)
//	{
//		if(pa<=x
//		&&a[pa]>=b[pb]&&a[pa]>=c[pc]
//		)
//		{
//			
//			sum+=a[pa];
//			pa++;
//		}
//		else
//		{
//			if(pb<=y
//			&&b[pb]>=a[pa] && b[pb]>=c[pc])
//			{
//				sum+=b[pb];
//				pb++;
//			}
//			else
//			{
//				
//				if(c[pc]>=a[pa] && c[pc]>=b[pb])
//				{
//					sum+=c[pc];
//					pc++;
//				}
//				else
//				{//有不足的
//					if(pa>x)
//					{
//						if(b[pb]<=c[pc])
//						{
//							sum+=c[pc];
//							pc++;
//						}
//						else
//						{
//							sum+=b[pb];
//							pb++;
//						}
//					}
//					else
//					{
//						if(pb>y)
//						{
//							if(a[pa]<=c[pc])
//							{
//								sum+=c[pc];
//								pc++;
//							}
//							else
//							{
//								sum+=a[pa];
//								pa++;
//							}
//						}
//					}
//				}
//			}
//		}
//	}
//	
//	
//	printf("%lld\n",sum);
	return 0;
}
/*

*/

Measured memory_bytes: 5700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include<queue>
#include<stack>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1()
{
    int h, w; cin >> h >> w;

    vector<vector<char>> c(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> c[i][j]; 
        }
    }

    rep(i, h)
    {
        rep(j, w)
        {
            cout << c[i][j];
        }
        cout << endl;
        rep(j, w)
        {
            cout << c[i][j];
        }
        cout << endl;
    
    }

   
}

int main()
{
    solve1();
}

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

#define int int_fast64_t

bool is_pali(string s) {
  return s == string(s.rbegin(), s.rend());
}

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

  string s; cin >> s;
  if (is_pali(s) &&
      is_pali(s.substr(0, s.size()/2)) &&
      is_pali(s.substr(s.size()/2+1, s.size()/2)))
    cout << "Yes\n";
  else
    cout << "No\n";
      
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	long long a,b;
	int judge,count=0;
	string temp;

	cin >>a >>b;
	for(int i=a;i<=b;i++){
		judge=0;
		temp=to_string(i);
		for(int j=0;j<((int)temp.size()-1)/2;j++){
			if(temp[j]!=temp[(int)temp.size()-1-j]){
				judge=1;
				break;
			}
		}
		if(judge==0)count++;
	}
	cout<<count<<endl;
	return 0;	
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
sum = a.inject(:+)
t = sum / (n * (n+1)/2)
if n == 1
  puts "YES"
  exit
end
unless sum % (n * (n+1)/2) == 0
  puts "NO"
  exit
end
a.map!{|a|a - t}
sum = a.inject(:+)
deno = ((n * (n - 1) * n / 2))
left = (n - 2) * (n + 1) / 2
n.times do |row|
  s = sum + a[(n - 1 - row) % n] * (left + 1) - a[(n - row) % n] * (left + 1)
  if s % deno != 0 || s < 0
    puts "NO"
    exit
  end
end
puts "YES"


Measured memory_bytes: 10900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int M=13000;
bool dp[81][81][M] {false};

int main(){
  int h,w;cin >> h >> w;
  Graph a(h, vector<int>(w));
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      int b;cin >> b;
      a[i][j]= abs(a[i][j]-b);
    }
  }
  
  dp[0][0][0]=true;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      for(int k = 0; k < M-80; ++k){
        dp[i][j+1][k+a[i][j]] |= dp[i][j][k];
        dp[i][j+1][abs(k-a[i][j])] |= dp[i][j][k];
      }
      for(int k = 0; k < M-80; ++k){
        if(i==h-1)break;
        dp[i+1][j+1][k+a[i+1][j]] |= dp[i][j+1][k];
        dp[i+1][j+1][abs(k-a[i+1][j])] |= dp[i][j+1][k];
      }
    }
  }
  for(int i = 0; i < M; ++i){
    if(dp[h-1][w][i]){
      cout << i << endl;
      break;
    }
  }
}


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

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

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

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

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

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

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

    sort(all(a));
    int l = 0, r = t-1;
    for(; l < r;){
        a[r]--; a[l]--;
        if(a[r] == 0) r--;
        if(a[l] == 0) l++;
    }
    cout << max(a[l] - 1, 0) << endl;
}


Measured memory_bytes: 256
a = list(map(int,list(input())))

for i in range(2<<3):
    ans = a[0]
    st = str(a[0])
    for j in range(3):
        if (i>>j)&1 == 1:
            ans += a[j+1]
            st += "+"+str(a[j+1])
        else:
            ans += -a[j+1]
            st += "-"+str(a[j+1])
    if ans == 7:
        print(st+"=7")
        break


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
ttl1, ttl2, ttl3 = 0, 0, 0
avarage1 = -(-sum(A) // N)
avarage2 = sum(A) // N
avarage3 = round(sum(A) / N)
for i in A:
    ttl1 += (i - avarage1) ** 2
    ttl2 += (i - avarage2) ** 2
    ttl3 += (i - avarage3) ** 2
print(min(ttl1, ttl2, ttl3))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>

using namespace std;

int X, Y, Z;

void solve()
{
	int res = 1;
	X -= Y + 2 * Z;
	res += X / (Y + Z);
	cout << res << endl;
}


int main()
{
	cin >> X >> Y >> Z;
	solve();
	return 0;
}

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

const int INF = 1e9;

int main() {
  int a,b,k;
  cin>>a>>b>>k;

  for(int i=0;i<k;i++){
    if(i%2==0){
      if(a%2==1){
        a=a-1;
      }
      int tmp=a/2;
      a=a-tmp;
      b=b+tmp;
    }else{
      if(b%2==1){
        b=b-1;
      }
      int tmp=b/2;
      b=b-tmp;
      a=a+tmp;
    }
  }
  cout<<a<<" "<<b<<endl;
}

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

int main() {
	int A, B, C, X;
	int res = 0;
	cin >> A >> B >> C >> X;

	for (int i = 0; i <= A; ++i) {
		for (int j = 0; j <= B; ++j) {
			for (int k = 0; k <= C; ++k) {
				int total = 500 * i + 100 * j + 50 * k;
				if (total == X) ++res;
			}
		}
	}

	cout << res << endl;
}

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

int main(){
    int N;
    cin>>N;
    int x[N],y[N],h[N];
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>h[i];
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            int f=-1;
            for(int k=0;k<N;k++){
            if(f<0) f=h[k]+abs(x[k]-i)+abs(j-y[k]);
            else f=min(f,h[k]+abs(x[k]-i)+abs(j-y[k]));
            }
            for(int k=0;k<N;k++){
                if (max(0,f-abs(x[k]-i)-abs(j-y[k]))!=h[k]){
                    break;
                }
                if(k==N-1) cout<<i<<" "<<j<<" "<<f<<endl;
            }
        }
    }
}

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
t = []
res = 0
for c in s:
    t.append(c[0] + c[-1])
    res += c.count('AB')

a,b,ba = 0,0,0
for c in t:
    if c == 'BA':
        ba += 1
    elif c[0] == 'B':
        b += 1
    elif c[-1] == 'A':
        a += 1

if ba > 0:
    res += ba - 1
    if a > 0:
        res += 1
        a -= 1
    if b > 0:
        res += 1
        b -= 1

res += min(a, b)

print(res)


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,ans=0;
  cin>>N;
  rep(i,N+1){
    string S=to_string(i);
    if(S.size()%2==1){
      ans+=1;
    }
  }
  cout<<ans-1<<endl;
}

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

const int inf = 1e9;
const ll linf = 1e18;

struct edge { int from, to, cost; };

int bellman_ford(int v, const vector<edge> &es, int s, int g)
{
    vector<int> d(v, inf);
    d[s] = 0;

    for (int i = 0; i < 2 * v; i++) {
        for (auto &e: es) {
            if (d[e.from] < inf && d[e.from] + e.cost < d[e.to]) {
                if (i < v - 1) {
                    d[e.to] = d[e.from] + e.cost;
                } else { // v回目以降の更新->負の閉路
                    d[e.to] = -inf;
                }
            }
        }
    }

    return d[g];
}

int main()
{
    int n, m, p; cin >> n >> m >> p;
    vector<edge> es(m);
    for (int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        es[i] = {a, b, p - c};
    }
    int d = bellman_ford(n, es, 0, n - 1);
    cout << (d <= -inf ? -1 : max(0, -d)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	string s;
	int cnt=0;
	cin >> s;
	if(s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define mem(arr,x) memset(arr, x, sizeof arr)
#define db(arr) for(auto x : arr) cout << x << " "; cout << "\n";
using namespace std;

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll power(ll n,ll m){
	if(m==0) return 1;
	ll val=power(n,m/2);
	if(m%2==0) return (val*val); else return ((val*val)*n);
}

ll powermod(ll n,ll m,ll MOD){
	if(m==0) return 1;
	ll val=powermod(n,m/2,MOD);
	val %= MOD;
	if(m%2==0) return (val*val) % MOD; else return (((val*val) % MOD) * n) % MOD;
}

int h, w, m;

void solve(){
	cin >> h >> w >> m;
	set<pair < int , int > > all;
	vector < pair < int , int > > row(h + 1), col(w + 1);

	for(int i = 0; i < h + 1; i++) row[i].second = i;
	for(int i = 0; i < w + 1; i++) col[i].second = i;

	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		row[x].first++;
		col[y].first++;
		all.insert(make_pair(x, y));
	}

	sort(all(row));
	reverse(all(row));
	sort(all(col));
	reverse(all(col));

	for(int r = 0; row[r].first == row[0].first; r++){
		for(int c = 0; col[c].first == col[0].first; c++){
			if(!all.count(make_pair(row[r].second, col[c].second))) {
				cout << col[c].first + row[r].first << endl;
				return;
			}
		}
	}
	int ans = max(0, col[0].first + row[0].first - 1);
	cout << ans << endl;
	
}

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);	
	#endif

	int t = 1;
	// cin >> t;

	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solve();
	}

	return 0;
}

Measured memory_bytes: 21932
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n ;
#define int long long
const double eps = 1e-9 , PI = acos(-1) ;
const int N = 1e3 + 3 , oo = 1e9 , M = 30;


int32_t main(){
  int xx , y;
  cin >> xx >> y ;
  for(int x = 0 ;x <= 100 ; x++){
    for(int z = 0 ; z <= 100 ;z++){
        if(2 * x + 4 * z == y && x + z == xx){
            cout << "Yes";
            return 0 ;
        }
    }
  }

  cout << "No";

    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,x,a[2222]={},m[2222]={},m2[2222]={};
	cin>>n>>x;
	FOR(i,0,n){
		cin>>a[i];
		m[i]=a[i];
	}

	LL ans=1LL*mod*mod;
	FOR(nx,0,n){
		LL tmp=nx*x;
		FOR(j,0,n){
			m[j]=min(m[j],a[(j+n-nx)%n]);
			tmp+=m[j];
		}
		ans=min(ans,tmp);
	}
	cout<<ans;

    return 0;
}


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

int main() {   
    vector<int> v;
    int i;
    while (true) {
        cin >> i;
        if (i == 0) break;
        v.push_back(i);
    }

    for (int i = 0; i < v.size(); i++) {
        cout << "Case " << i+1 << ": " << v.at(i) << endl;
    }
}


Measured memory_bytes: 3156
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



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

	long long int y = 1900 * m + (n - m) * 100;
	y *= pow(2, m);
	cout << y << endl;


	return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<(ull)n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

bool ok(string s) {
    for (auto &e:s) {
        bool t = false;
        for (auto &f:"ACGT")if (e == f)t = true;
        if (!t)return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    int r = 0;
    for (int i = 0; i < s.length(); i++)for (int j = 0; i + j <= s.length(); j++)if (ok(s.substr(i, j)))r = max(r, j);
    cout << r << endl;
}

Measured memory_bytes: 256