akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/agc009/tasks/agc009_a
# 普通にBの倍数かつAより大きいものの中で最小の数を高速に求めれば良い
# いや[0,i)を+1増やすらしい。めちゃくちゃめんどくさいやつだ

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


N = a_int()
A, B = read_col(N)
# 後ろから決定していく
n_pushed = 0  # すでに何回押されたか(a+n_pushedがその時点での数字の大きさに成る)
for a, b in zip(reversed(A), reversed(B)):
    a += n_pushed
    # x = (ceil(a / b)) * b
    x = ((a - 1) // b + 1) * b
    # print(x)
    n_pushed += x - a

print(n_pushed)


Measured memory_bytes: 92820
<?php
fscanf(STDIN, "%d%d", $w, $b);
$w--;
$b--;
$size = 100;
for($i = 0; $i < $size/2; $i++){
  $map[$i] = array_fill(0, $size, "#");
  $map[$i+$size/2] = array_fill(0, $size, ".");
}
for($i = 0; $i < $w; $i++)$map[intdiv($i*2,$size)*2][$i*2%$size] = ".";
for($i = 0; $i < $b; $i++)$map[$size - 1 - intdiv($i*2,$size)*2][$i*2%$size] = "#";
echo "$size $size\n";
for($i = 0; $i < $size; $i++){
  echo implode("", $map[$i]),"\n";
}


Measured memory_bytes: 4856
<?php
$n = intval(trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    $a[] = intval(trim(fgets(STDIN)));
}

$ans = -1;
$push = 1;
$cnt = 0;
for($i = 0; $i < $n; $i++){
    $push = $a[$push-1];
    $cnt++;
    if($push == 2){
        $ans = $cnt;
        break;
    }
}
echo $ans;

Measured memory_bytes: 10744
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  lint N,K;
  cin>>N>>K;
  lint ans=0;
  ans+=(N/K)*(N/K)*(N/K);
  if(K%2==0)ans+=((N+K/2)/K)*((N+K/2)/K)*((N+K/2)/K);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long data[2][4000],n,i,f,id,a,b;
  while(1){
    cin>>n;
    if(n==0) break;
    for(i=0; i<4000; i++) data[0][i]=-1,data[1][i]=0;
    for(i=0;i<n;i++){
      cin>>id>>a>>b;
      for(f=0;f<i+1;f++){
	if(data[0][f]==id){
	  (a*b<1000000)? (data[1][f]+=(a*b)) : (data[1][f]=1000000);
	  break;
	}else if(data[0][f]==-1){
	  data[0][f]=id;
	  (a*b<1000000)? (data[1][f]=(a*b)) : (data[1][f]=1000000);
	  break;
	}
      }
    }
    for(i=0,f=0;i<n;i++){
      if(data[1][i]>=1000000)cout<<data[0][i]<<"\n",f=1;
      if(data[0][i]==-1)break;
      //cout<<"id : "<<data[0][i]<<" sale: "<<data[1][i]<<endl;
    }
    if(f==0)cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
 
#define tate 3
#define yoko 3
#define Total (tate*yoko)
#define TryCnt 45

extern inline void down_0(void);    // 0 を下に移動
extern inline void up_0(void);      // 0 を上に移動
extern inline void right_0(void);   // 0 を右に移動
extern inline void left_0(void);    // 0 を左に移動

extern int  serch(int x, int y, int MaxCnt, int pre);

int num = 0;        // 0 の位置を示す
int val[Total] ={}; // 数値配列


int main( void )
{
    int i = 0;
    int x,y = 0;
    
    // 文字列の取り込み
    for(i=0; i<Total; i++)
    {
        scanf("%d",&val[i]);
        
        if(val[i] == 0)
        {
            num = i;
        }
    }
    
    // 右下に行くために 0 を何回動かせばいいか。
    x = tate - (num/yoko) -1;
    y = yoko - (num%yoko) -1;
    
    for(i=0; i<TryCnt; i++)
    {
        if( serch(x,y,i,4) == 1 )
        {
            printf("%d\n",i);
            break;
        }
    }     
    
    return 0;
}

int serch(int x, int y, int MaxCnt, int pre)
{
    int result;
    int i=0;
    
    if(MaxCnt < (x + y) )
    {
        return 0;
    }
    
    // 最大数でゴールと一致しているか確認
    if(MaxCnt==0)
    {
        for(i=0; i<Total-1; i++)
        {
            if(val[i] != (i+1))
            {
                // ゴールと不一致
                return 0;
            }
        }
        // ゴールと一致！！
        return 1;
    }
    
    
    // 0 の移動
    for(i=0; i<4; i++)
    {
        result = 0;
        
        switch(i)
        {
            case 0:
                if( (x > 0) && (pre != 3) )
                {
                    down_0();
                    
                    result = serch(x-1, y, MaxCnt-1, 0);
                    
                    up_0();
                }
                break;
                
            case 1:
                if( (y > 0) && (pre != 2) )
                {
                    right_0();
                    
                    result = serch(x, y-1, MaxCnt-1, 1);
                    
                    left_0();
                }
                break;
                
            case 2:
                if( (y < yoko -1 ) && (pre != 1) )
                {
                    left_0();
                    
                    result = serch(x, y+1, MaxCnt-1, 2);
                    
                    right_0();
                }
                break;
                
            case 3:
                if( (x < tate -1 ) && (pre != 0) )
                {
                    up_0();
                    
                    result = serch(x+1, y, MaxCnt-1, 3);
                    
                    down_0();
                }
                break;
                
            default:
                // 何もしない。
                break;
        }
        
        if(result)
        {
            return 1;
        }
    }
    
    return 0;
}


inline void down_0()
{
    val[num] = val[num + yoko];
    num = num + yoko;
}
 
inline void up_0()
{
    val[num] = val[num - yoko];
    num = num - yoko;
}
 
inline void right_0()
{
    val[num] = val[num +1];
    num = num + 1;
}
 
inline void left_0()
{
    val[num] = val[num -1];
    num = num - 1;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, m;
int a[310][310];
int rnk[310][310];

bool sel[310];
int cnt[310];

int main()
{
	read(n, m);
	for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) read(a[i][j]), rnk[i][a[i][j]]=j;
	int ans=2e9;
	fill(sel+1, sel+m+1, true);
	for(int step=1; step<=m; ++step){
		fill(cnt+1, cnt+m+1, 0);
		for(int i=1; i<=n; ++i){
			for(int j=1; j<=m; ++j){
				if(sel[a[i][j]]){
					++cnt[a[i][j]];
					break;
				}
			}
		}
		int mi = max_element(cnt+1, cnt+m+1) - cnt;
		ans = min(ans, cnt[mi]);
		sel[mi] = 0;
	}
	printf("%d\n", ans);
	return 0;
}


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

int main(){
    int D[13]{0};
    int S[13]{0};
    int H[13]{0};
    int C[13]{0};
    int n, num;
    char suit;
    cin >> n;

    for(int i=0; i<n; i++){
        cin >> suit >> num;
        switch (suit) {
            case 'D':
                D[num-1] = 1;
                break;
            case 'S':
                S[num-1] = 1;
                break;
            case 'H':
                H[num-1] = 1;
                break;
            case 'C':
                C[num-1] = 1;
                break;
        }
    }
    for(int i=0; i<13;i++){
        if (S[i]!=1){
            cout << 'S' << ' ' << i+1 << endl;
        }
    }
    for(int i=0; i<13;i++){
        if (H[i]!=1){
            cout << 'H' << ' ' << i+1 << endl;
        }
    }
    for(int i=0; i<13;i++){
        if (C[i]!=1){
            cout << 'C' << ' ' << i+1 << endl;
        }
    }
    for(int i=0; i<13;i++){
        if (D[i]!=1){
            cout << 'D' << ' ' << i+1 << endl;
        }
    }
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
const ll mod=1e9+7;
int main(){
    ll n,q;cin>>n>>q;
    string s;cin>>s;
    vector<char>t(q),d(q);
    rep(i,q)cin>>t[i]>>d[i];
    ll ans=n;
    ll now=0;
    rep(i,q){
        if(t[i]==s[now]){
            if(d[i]=='R')now++;
            else now--;
        }
        if(now<0)break;
        if(now>=n)break;
    }
    if(now<0){
        ll l=0,r=n;
        while(r-l>1){
            ll k=(r+l)/2;
            ll im=k;
            rep(i,q){
                if(t[i]==s[im]){
                    if(d[i]=='R')im++;
                    else im--;
                }
                if(im<0)break;
                if(im>=n)break;
            }
            if(im<0)l=k;
            else r=k;
        }
        ans-=l+1;
    }
    now=n-1;
    rep(i,q){
        if(t[i]==s[now]){
            if(d[i]=='R')now++;
            else now--;
        }
        if(now<0)break;
        if(now>=n)break;
    }
    if(now>=n){
        ll l=-1,r=n-1;
        while(r-l>1){
            ll k=(r+l)/2;
            ll im=k;
            rep(i,q){
                if(t[i]==s[im]){
                    if(d[i]=='R')im++;
                    else im--;
                }
                if(im<0)break;
                if(im>=n)break;
            }
            if(im>=n)r=k;
            else l=k;
        }
        ans-=n-r;
    }
    cout<<ans<<endl;
}


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    set <int> x;
    x.insert(a);
    x.insert(b);
    x.insert(c);
    cout<<x.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>

#define MEMZERO(x) memset(x, 0, sizeof(x))
#define MEMSET(x, y) memset(x, y, sizeof(x))

using namespace std;

const int SIZE = 101200;
bool isPrime[SIZE];
int prime[SIZE/2], pSize;
int table[5100];

int memo[10000][100];

void setPrime( void )
{
	pSize = 0;
	for(int i=2; i < SIZE; ++i) isPrime[i] = true;
	isPrime[0] = isPrime[1] = false;
	for(int i=2; i < SIZE; ++i) {
		if(!isPrime[i]) continue;
		prime[pSize++] = i;
		for(int j=i+i; j < SIZE; j+=i) {
			isPrime[j] = false;
		}
	}
}

int search_index( int num )
{
	int l=0, h = pSize;
	while(l < h) {
		int m = (l + h) / 2;
		if(prime[m] < num) l = m + 1;
		else if(prime[m] > num) h = m;
		else return (m+1);
	}
	return l;
}

int main( void )
{
	setPrime();
	for(int i=0; i < 10000; ++i) for(int j=0; j < 100; ++j) memo[i][j] = -1;
	int m, p;
	while(cin >> m >> p, m != -1 || p != -1) {
		MEMZERO(table);
		int ii = search_index(m);
		if(memo[ii][p-1] != -1) {
			cout << memo[ii][p-1] << endl;
			continue;
		}
		int count = 0;
		for(int i=0; i < 100; ++i)
			for(int j=i; j < 100; ++j) {
				table[count++] = prime[i+ii] + prime[j+ii];
			}
		sort(table, table+count);
		cout << table[p-1] << endl;
		for(int i=0; i < 100; ++i) memo[ii][i] = table[i];
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using ld= long double;
using vi= vector<int>;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvi= vector<vector<int>>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

template <class T>
inline void chmin(T &a, T b) {
    if(a > b) { a= b; }
}

template <class T>
inline void chmax(T &a, T b) {
    if(a < b) { a= b; }
}

/* 最大公約数 */
ll gcdx(ll a, ll b) {
    return b ? gcdx(b, a % b) : a;
}

/* 最小公倍数 */
ll lcmx(ll a, ll b) {
    return a / gcdx(a, b) * b;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll N;
    cin >> N;
    vl T(N);
    REP(i,N)cin >> T[i];
    ll lcm = 1;
    REP(i,N)lcm = lcmx(lcm,T[i]);
    cout << lcm << "\n";
}

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

count_dict={}

for i in range(n):
    new=int(input())
    if new in count_dict:
        count_dict[new]+=1
    else:
        count_dict[new]=1
ans=0
for i in count_dict.values():
    if i%2==1:
        ans+=1
print(ans)

Measured memory_bytes: 19312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> b_l(n, 0), b_r(n, 0), w_l(n, 0), w_r(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '#')
            b_l[i] += 1;
        else if (s[i] == '.')
            w_l[i] += 1;
        if (s[n - 1 - i] == '.')
            w_r[n - 1 - i] += 1;

        b_l[i] += (i > 0 ? b_l[i - 1] : 0);
        w_l[i] += (i > 0 ? w_l[i - 1] : 0);
        w_r[n - 1 - i] += (i > 0 ? w_r[n - 1 - i + 1] : 0);
    }
    int ans = INT_MAX;
    for (int i = 0; i <= n; i++)
    {
        if (i == 0)
            ans = min(ans, w_l[n - 1]);
        else if (i == n)
            ans = min(ans, b_l[n - 1]);
        else
        {
            ans = min(ans, b_l[i - 1] + w_r[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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; }

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

ll dp[3001][3001][4];

int main(){
  int r,c,k;
  cin >> r >> c >> k;
  
  map<P, int> mp;

  REP(i,k){
    int rr,cc,v;
    cin >> rr >> cc >> v;
    mp[make_pair(rr,cc)]=v;
  }

  FOR(i,1,r+1)FOR(j,1,c+1){
    if(mp.end() != mp.find(make_pair(i,j))){
      ll v = mp[make_pair(i,j)];
      FOR(k,1,4){
        dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1]+v);        
      }
      //FOR(k,1,4){
        REP(l,4){
          dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][l]+v);        
        }
      //}
      REP(k,4){
        dp[i][j][k] = max(dp[i][j][k], max(dp[i-1][j][k], dp[i][j-1][k]));        
      }
    }else{
      REP(k,4){
        dp[i][j][k] = max(dp[i][j][k], max(dp[i-1][j][k], dp[i][j-1][k]));        
      }
    }
  }

  ll ans = 0;
  REP(i,4)chmax(ans, dp[r][c][i]);

  // REP(i,r+1)REP(j,c+1)REP(k,4){
  //   cout << dp[i][j][k] << endl;
  // }

  cout << ans << endl;

}



Measured memory_bytes: 297292
// finish date: 2018/03/10

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    string X;
    cin >> X;
    int numS = 0;
    int extraT = 0;
    rep(i, X.size()) {
        if (X[i] == 'S') {
            numS++;
        } else {
            if (numS == 0) {
                extraT++;
            } else {
                numS--;
            }
        }
    }
    cout << numS + extraT << endl;


    return 0;
}

Measured memory_bytes: 640
import heapq
def Dsa(n):
    inf = 10 ** 6 + 1
    dt = [0] + [inf] * (n - 1)
    q = [(0, 0)]
    while q:
        u = heapq.heappop(q)[1]
        for (v, c) in ed[u]:
            alt = dt[u] + c
            if dt[v] > alt:
                dt[v] = alt
                heapq.heappush(q, (alt, v))
    return dt
 
n = int(input())
ed = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    ed[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(Dsa(n)):
    print(i, c)

Measured memory_bytes: 42308
# encoding:utf-8

def main():
	n, m = list(map(int, input().split()))
	ships = [list(map(int, input().split())) for _ in range(m)]
	frm1 = [x[1] for x in ships if x[0] == 1]
	toN = [x[0] for x in ships if x[1] == n]
	out = set(frm1).intersection(set(toN))
	if len(out) >= 1:
		print("POSSIBLE")
	else:
		print("IMPOSSIBLE")
		
if __name__ == '__main__':
	main()

Measured memory_bytes: 61068
def main():
    import sys
    input = sys.stdin.readline

    H, W, K = map(int, input().split())

    G = [[0] * W for _ in range(H)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        G[r - 1][c - 1] = v

    pdp = [[0] * 4 for _ in range(W)]
    for r in range(H):
        dp = [[0] * 4 for _ in range(W)]
        left = [0] * 4
        for c in range(W):
            cell = dp[c]

            for k in range(4):
                cell[k] = left[k]

            up = max(pdp[c])
            if cell[0] < up:
                cell[0] = up

            for k in range(2, -1, -1):
                cell[k + 1] = max(
                    cell[k + 1],
                    cell[k] + G[r][c])
            left = cell
        pdp = dp

    # for k in range(4):
    #     for row in range(H):
    #         for col in range(W):
    #             print(dp[row][col][k], end=' ')
    #         print()
    #     print()

    # print(*G, sep='\n')

    ans = max(dp[-1])
    print(ans)


if __name__ == '__main__':
    main()


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

int main(void) {
    int m,f,r;
    char result;
    while(true) {
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) return 0;
        else if(m == -1 || f == -1 || m + f < 30) result = 'F';
        else if(m + f >= 80) result = 'A';
        else if(m + f >= 65 && m + f < 80) result = 'B';
        else if(m + f >= 50 && m + f < 65) result = 'C';
        else if(m + f >= 30 && m + f < 50){
            if(r >= 50) result = 'C';
            else result = 'D';
        }
        cout << result << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
    int n,m;
    cin >> n >> m;
    ll h[n+1];
    for (int i = 1; i<= n; i++){
        cin >> h[i];
    }
    bool good[n+1];
    for (int i = 1; i<=n; i++){
        good[i] = true;
    }
    for (int i = 1; i <=m; i++){
        int a,b;
        cin >> a >> b;
        if (h[a] > h[b]){
            good[b]=false;
        }
        else if (h[a] < h[b]){
            good[a]=false;
        }
        else {
            good[a]=false;
            good[b]=false;
        }
    }
    int ret = 0;
    for (int i = 1; i<= n; i++){
        if (good[i]){
            ret++;
        }
    }
    cout << ret;
    return 0;
}

Measured memory_bytes: 4512
s = gets.chomp
n = s.to_i
list = [2,1,0]

finish = false
if(n == 1)
  print "1\n"
else
  (n-1).times do |i|
    list[2] = list[0] + list[1]
    list[0] = list[1]
    list[1] = list[2]
  end
  print "#{list[2]}\n"
end


Measured memory_bytes: 1916
#include <iostream>

using namespace std;

int main()
{
    int n,sum=0,a;
    cin>>n;
    int mas[20000],mas1[20000];
    for(int i=0; i<n; i++){
        cin>>mas[i];
    }
    for(int i=0; i<n; i++){
        cin>>a;
        sum+=a;
    }
    for(int i=1; i<n; i++){
        cin>>mas1[i];
    }
    for(int i=1; i<n; i++){
        if(mas[i]==mas[i-1]+1){
            sum+=mas1[mas[i]-1];
        }
    }
    cout<<sum;
}


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

void init(int n_){
	n = 1;
	while(n < n_) n *= 2;
	node.resize(2*n-1, INT_MAX);
}

void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while(x > 0) {
        x = (x - 1) / 2;
        node[x] = min(node[2*x+1], node[2*x+2]);
    }
}

int getmin(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    if(r <= a || b <= l) return INT_MAX;
    if(a <= l && r <= b) return node[k];
    int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
    int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
}

int main(){
	int N, q; cin >> N >> q;
	init(N);
	rep(i, q){
		int c; cin >> c;
		int x, y; cin >> x >> y;
		if(c==0) update(x, y);
		else cout << getmin(x, y+1) << endl;
	}
}


Measured memory_bytes: 3816
import cmath
EPS = 1e-10

#外積
def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

#3点が反時計回りか
#一直線上のときの例外処理できていない→とりあえずT
def CCW(p, q, r):
	one, two = q-p, r-q
	if OuterProduct(one, two) > -EPS:
		return True
	else:
		return False

#凸包リストを返す
def ConvexHull(dots):
	dots.sort(key=lambda x: (x.real, x.imag))
	res1 = [dots[0]]
	for d in dots[1:]:
		if len(res1) == 1:
			res1.append(d)
		else:
			while len(res1) > 1 and not CCW(res1[-2], res1[-1], d):
				res1.pop()
			res1.append(d)
	dots.reverse()
	res2 = [dots[0]]
	for d in dots[1:]:
		if len(res2) == 1:
			res2.append(d)
		else:
			while len(res2) > 1 and not CCW(res2[-2], res2[-1], d):
				res2.pop()
			res2.append(d)
	return res1[:-1] + res2[:-1]

n = int(input())
dots = []
for _ in range(n):
	x, y = map(int, input().split())
	dots.append(complex(x, y))

if len(dots) == 3:
	print(1)
elif len(ConvexHull(dots)) == n:
	print(1)
else:
	print(0)


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

int n;
vector<int>E[200000];
int sz[200000];
ll ans=0;

void dfs(int v,int p){
	sz[v]=1;
	ll all=ppow(2,n-1);
	ll U=0;
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
		sz[v]+=sz[u];
	}
	for(int u:E[v]){
		if(u==p)continue;
		(U+=(ppow(2,sz[u])+MOD-1))%=MOD;
	}
	(U+=(ppow(2,n-sz[v])+MOD-1))%=MOD;
	(U+=1)%=MOD;
	(all+=MOD-U)%=MOD;
	(ans+=all)%=MOD;
}

int main(){
	cin>>n;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs(0,-1);
	ll d=ppow(2,n);
	cout<<ans*ppow(d,MOD-2)%MOD<<endl;
}

Measured memory_bytes: 25344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var n = RI;
			var a = RIs;
			long count = 0;
			long cc = 0;
			int max = (int)Math.Pow(2, Math.Ceiling(Math.Log(a.Max(), 2) + 0.01));
			for(int i = n-1;i >= 0;i--)
			{
				long x = a[i];
				long s = a[i];
				if(a[i] == 0)
				{
					cc++;
					count += cc;
					continue;
				}
				cc = 1;
				for(int j = i + 1;j < n;j++)
				{
					x ^= a[j];
					s += a[j];
					if (x == s)
					{
						cc++;
					}
					if (s > max) break;
				}
				count += cc;
			}
			Out(count);
		}		
	}
}


Measured memory_bytes: 33884
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A___Remaining_Balls
{
    class Program
    {
        static void Main(string[] args)
        {
            //一行読み込むところ
            var one = Console.ReadLine();
            string[] arrone = one.Split(' ');

            string S = arrone[0];
            string T = arrone[1];


            //一行読み込むところ
            var two = Console.ReadLine();
            //sprit掛けるところ
            string[] arrtwo = two.Split(' ');

            int A = int.Parse(arrtwo[0]);
            int B = int.Parse(arrtwo[1]);


            //一行読み込むところ
            var three = Console.ReadLine();
            //sprit掛けるところ
            string[] arrthree = three.Split(' ');

            string U = arrthree[0];

            //配列の要素数を数える
            if (S.Equals(U))
            {
                A = A - 1;
            } else if (T.Equals(U)) {
                B = B - 1;
            }
            string stra = A.ToString();
            string strb = B.ToString(); 
            Console.WriteLine(stra + " "+ strb);


        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	double a, b, x, t;
	cin >> a >> b >> x;
	t = 2 * x / (a * b);
	if (t <= a) {
		printf("%0.8lf", atan(b / t) / (atan(1) * 4) * 180);
	}
	else {
		double leave;
		leave = a * a * b - x;
		printf("%0.8lf", atan(leave * 2 / (a * a) / a) / (atan(1) * 4) * 180);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define FIR first
#define SEC second
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<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll DP[10001];




int main() {
  IN(ll,H);
  IN(ll,N);
  A2IN(ll, A, ll, B ,N);
  Fill(DP,INF);
  DP[0] = 0;
  REP(i, N){
    for(ll j = 0; j <= H; j++){
      chmin(DP[j],DP[max(j - A[i], 0LL)] + B[i]);
    }
  }
  OUT(DP[H]);
}



Measured memory_bytes: 384
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

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

	vector<int> rc(n, 0);
	if (sc[0] == 'R') {
		rc[0] = 1;
	}

	for (int i = 1; i < n; ++i) {
		rc[i] = rc[i - 1];
		if (sc[i] == 'R') {
			++rc[i];
		}
	}

	cout << rc[n - 1] - rc[rc[n - 1] - 1] << endl;


	return 0;
}

Measured memory_bytes: 4448
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define inf 2147483647
typedef long long ll;
using namespace std;
#define N 1<<18
#define M 1<<17
int rua[N],rma[N];
void eval(int l,int r,int k){
    if(rua[k]==-1)return;
    rma[k]=rua[k];
    if(l+1<r){
    rua[k*2+1]=rua[k];
    rua[k*2+2]=rua[k];
    }
    rua[k]=-1;
}
void update(int a,int b,int l,int r,int k,int x){
    eval(l,r,k);
    if(a<=l&&r<=b){
    rua[k]=x;
    eval(l,r,k);
    return;
    }
    if(a>=r||l>=b){return;}
    update(a,b,l,(l+r)/2,k*2+1,x);
    update(a,b,(l+r)/2,r,k*2+2,x);
    rma[k]=min(rma[k*2+1],rma[k*2+2]);
}
int rmq(int a,int b,int l,int r,int k){
    eval(l,r,k);
    if(a<=l&&r<=b)return rma[k];
    if(a>=r||l>=b)return inf;
    int vl=rmq(a,b,l,(l+r)/2,k*2+1);
    int vr=rmq(a,b,(l+r)/2,r,k*2+2);
    return min(vl,vr);
}
 
int main(){
    lol(i,N)rma[i]=inf,rua[i]=-1;
    int n,q;cin>>n>>q;
    lol(i,q){
    int flag;cin>>flag;
    if(flag==0){
        int a,b,c;cin>>a>>b>>c;
        update(a,b+1,0,M,0,c);
    }
    if(flag==1){
        int a,b;cin>>a>>b;
        cout<<rmq(a,b+1,0,M,0)<<endl;
    }
    }
     
    return 0;
}



Measured memory_bytes: 5164
#include<bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<ll,ll> pi;

int dp[11][1001];

int sum(int x1,int y1,int x2,int y2){
    int ans = dp[x2][y2];
    if(y1 > 0) ans -= dp[x2][y1-1];
    if(x1 > 0) ans -= dp[x1-1][y2];
    if(y1 > 0 && x1 > 0) ans += dp[x1-1][y1-1];
    return ans;
}
int h,w,k;

int howMany(vector<int> &lines){
    int last = w-1;
    int ans = 0;
    for(int j = last; j > -1;--j){
        int su = sum(0,j,lines[0],last);
        su = max(sum(lines.back()+1,j,h-1,last),su);
        for(int i = 0; i < lines.size()-1;++i)
            su = max(sum(lines[i]+1,j,lines[i+1],last),su);
        if(su > k){
            if(last == j)return 100000000;
            last = j;
            ++j;
            ++ans;
        }
    }
    return ans;
}

int main(){
    scanf(" %d %d %d",&h,&w,&k);
    int matrix[h][w];
    for(int i = 0; i < h;++i){
        char temp;
        for(int j = 0; j < w;++j){
            scanf(" %c",&temp);
            if(temp == '1')
                matrix[i][j] = 1;
            else matrix[i][j] = 0;
        }
    }
    for(int i = 0; i < w;++i){
        for(int j = 0; j < h;++j){
            dp[j][i] = matrix[j][i];
            if(i > 0) dp[j][i] += dp[j][i-1];
            if(j > 0) dp[j][i] += dp[j-1][i];
            if(i > 0 && j > 0) dp[j][i] -= dp[j-1][i-1];
        }
    }
    if(dp[h-1][w-1] <= k){
        puts("0");
        return 0;
    }
    int ans = 1000000;
    for(int i = 1; i < (1<<(h-1));++i){
        int co = i;
        int j = 0;
        vector<int> send;
        while(co){
            if(co&1)send.push_back(j);
            co = co >> 1;
            ++j;
        }
        ans = min(ans,howMany(send)+(int)send.size());
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(){
    ll N, K;
    cin >> N >> K;
    vector<bool> s(N+1, false);
    rep(i, 0, K){
        ll d;
        cin >> d;
        rep(j, 0, d){
            ll a;
            cin >> a;
            s[a] = true;
        }
    }
    ll ans = 0;
    rep(i, 1, N+1){
        if(!s[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.HashSet;
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			long[] a = new long[n];
			HashSet<Long> h = new HashSet<Long>();
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextLong();
			}
			
			for(int i=0;i<n;i++) {
				if(h.contains(a[i])) {
					h.remove(a[i]);
				}else {
					h.add(a[i]);
				}
			}
			
			System.out.println(h.size());
			
	    }
		
		
	}


Measured memory_bytes: 54408
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  s <- getLine
  t <- getLine

  let solve _ _ Nothing _ = False
      solve _ _ _ Nothing = False
      solve [] [] _ _     = True
      solve (c:cs) (x:xs) (Just m1) (Just m2) = let m1' = case Map.lookup c m1 of
                                                      Just x' | x == x'   -> Just m1
                                                              | otherwise -> Nothing
                                                      Nothing -> Just (Map.insert c x m1)
                                                    m2' = case Map.lookup x m2 of
                                                      Just c' | c == c'   -> Just m2
                                                              | otherwise -> Nothing
                                                      Nothing -> Just (Map.insert x c m2)
                                                in solve cs xs m1' m2'

      ans = if solve s t (Just Map.empty) (Just Map.empty) then "Yes" else "No"

  putStrLn ans


Measured memory_bytes: 18812
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val H, W = in.nextInt
  val grid = Array.fill(H)(in.next)
  def removeAndRotate(a: Array[String]): Array[String] =
     a.filter(_.exists(_ == '#')).map(_.toArray).transpose.map(_.mkString)

  println(removeAndRotate(removeAndRotate(grid)).mkString("\n"))
}

Measured memory_bytes: 32768
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var S = cin.Scan.Select(i => i.ToUpper()).ToArray();
        WriteLine($"{S[0][0]}{S[1][0]}{S[2][0]}");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11472
X, Y = map(int, input().split())
ans = 'No'
if Y % 2 != 0:
    ans = 'No'
else:
    for i in range(X+1):
        a = X - i
        if a * 2 + i * 4 == Y:
            ans = 'Yes'
            break
print(ans)

Measured memory_bytes: 9164
#include<stdio.h>
typedef long long ll;
#define min(a, b) ((a)>(b)?(b):(a))
#define max(a, b) ((a)>(b)?(a):(b))
#define MAX 500500
const ll mod = 1000000007ll;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[0] = inv[1] = 1;
	for(int i=2; i<MAX; i++){
		fac[i] = fac[i-1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}
ll COM(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}
ll PER(int n, int k){
	if(n < k || n < 0 || k < 0) return 0;
	return fac[n] * finv[n-k] % mod;
}
int main(){
	COMinit();
	ll N, M, ans=0, t=1;
	scanf("%lld%lld",&N,&M);
	for(int i=0; i<=N; i++){
		ans += COM(N, i) * PER(M, i) % mod * (PER(M-i, N-i) * PER(M-i, N-i) % mod) % mod * t;
		ans = (ans + mod) % mod;
		t *= -1;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    map<char,int> dict;
    rep(i,s.size()) dict[s[i]]++;
    int minv=100005;
    for(auto itr=dict.begin();itr!=dict.end();itr++){
        if(itr->second==s.size()) minv=0;
        else minv=min(minv,itr->second);
    }
    cout<<minv*2<<"\n";
    return 0;
}

Measured memory_bytes: 3728
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k]) ** 2
        if int(math.sqrt(tmp)) ** 2 == tmp:
            ans += 1

print(ans)

Measured memory_bytes: 3064
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	fastio;
	int n,m,s,c;
	cin >> n >> m;
	vector<int> num(n,-1);
	bool ok = true;
	REP(i,0,m){
		cin >> s >> c;
		s--;
		if(num[s] == -1) num[s] = c;
		else ok = ok && num[s] == c;
	}

	if(n > 1 && num[0] == 0) ok = false;

	if(!ok){ cout << -1 << endl; exit(0); }

	if(n == 1){
		if(num[0] == -1) num[0] = 0;
	}else{
		if(num[0] == -1) num[0] = 1;
		REP(i,1,n) if(num[i] == -1) num[i] = 0;
	}

	REP(i,0,n) cout << num[i]; cout << endl;

	return 0;
}


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

int main()
{
		int m[10000], f[10000], r[10000], i, n;
		while (1) {
				cin >> m[n] >> f[n] >> r[n];
				if (m[n]==-1 && f[n]==-1 && r[n]==-1) break;
				n++;
		}

		for (i=0; i<n; i++) {
				if (m[i]==-1 || f[i]==-1) cout << "F\n";
				else if (m[i]+f[i]>=80) cout << "A\n";
				else if (m[i]+f[i]>=65 && m[i]+f[i]<80) cout << "B\n";
				else if (m[i]+f[i]>=50 && m[i]+f[i]<65) cout << "C\n";
				else if (m[i]+f[i]>=30 && m[i]+f[i]<50) {
						if (r[i]>=50) cout << "C\n";
						else cout << "D\n";
				} else cout << "F\n";
		}
}

Measured memory_bytes: 3076
def main():
    s = input()
    N = len(s)

    dp = [[-1]*4 for n in range(N)]
    for i in reversed(list(range(N))):
        for j in range(4):
            if i == N-1:
                if j == 3:
                    dp[i][j] = 3 if s[i] == "?" else 1
                elif j == 2:
                    dp[i][j] = 1 if s[i] in ("?", "C") else 0
                else:
                    dp[i][j] = 0
            else:
                if j == 3:
                    dp[i][j] = (3 if s[i] == "?" else 1) * dp[i+1][j]
                elif s[i] == "?":
                    dp[i][j] = 3 * dp[i+1][j] + dp[i+1][j+1]
                elif s[i] == "ABC"[j]:
                    dp[i][j] = dp[i+1][j+1] + dp[i+1][j]
                else:
                    dp[i][j] = dp[i+1][j]
            dp[i][j] %= 10 ** 9 + 7
    print(dp[0][0])


if __name__ == "__main__":
    main()

Measured memory_bytes: 55020
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main()
{
	int d,g;
	int i,j;
	int p[11],c[11];
	scanf("%d%d",&d,&g);
	for(i=0;i<d;i++)
		scanf("%d%d",&p[i],&c[i]);
	int ans = INF;
	for(i=0;i<(1<<d);i++)
	{
		ll sum=0;
		int ss=0;
		for(j=0;j<d;j++)
		{
			if((i>>j)&1)
			{
				sum += p[j]*(j+1)*100+c[j];
				ss += p[j];
			}
		}
		for(j=d-1;j>=0;j--)
		{
			if((i>>j)&1)	continue;
			if(sum >= g)	continue;
			int s;
			s = (g-sum)/((j+1)*100);
			s = min(s,p[j]);
			ss += s;
			sum += (j+1)*100*s;
		}
		if(g <= sum)
			ans = min(ans,ss);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int N,A;
  cin >> N;
  cin >> A;
  
  int x = N % 500;
  
  if(x > A)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }  
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> P;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define abs(x) ((x)>0?(x):-(x))
const int maxn = 10006, inf = 0x3f3f3f3f;
int n;
int a[maxn];
int gcd(int a,int b){
	if(a<b) swap(a,b);
	if(!b) return a;
	return gcd(b,a%b);
}
vector<int> isp(maxn,-1);
void init(){
	isp[0]=isp[1]=0;
	for(int i=2;i<maxn;i++){
		if(isp[i]){
			for(int j=2;j*i<maxn;j++) isp[i*j]=0;
		}
	}
}
set<int> ans;
ll cal(ll i,ll p){
	ll ans=0;
	for(int j=0;j<=n;j++){
		ans = 1LL * ans * i % p + a[j];
		ans %= p;
	}
	return ans;
}
void div(int p){
	int b[maxn];
	for(int i=0;i<n;i++){
		b[i]=a[i];
		a[i+1]+=a[i]*p;
	}
	for(int i=0;i<n;i++) a[i]=b[i];
	n--;
}
int main(){
	init();
	cin>>n;
	for(int i=0;i<=n;i++) cin>>a[i];
	int d=abs(a[0]);
	for(int i=1;i<=n;i++) d=gcd(d,abs(a[i]));
	int dd=d;
	for(int i=2;i<=d&&i<maxn;i++){
		if(isp[i]&&!ans.count(i)&&d%i==0) {
			ans.insert(i);
			d/=i;
		}
	}
	if(d>1) ans.insert(d);
	for(int i=0;i<=n;i++) a[i]/=dd;
	int tot=1;
	for(int i=0;i<isp.size();i++){if(!isp[i]) continue;
		int p=i;
		int fl=0;
		if(p>100){
			for(int j=0;j<100;j++){
				int k=rand()%p;
				if(cal(k,p)){
					fl=1;
					break;
				}
			}
		}else{
			for(int j=0;j<p;j++){
				if(cal(j,p))
				{
					fl=1;
					break;
				}
			}
		}
		if(!fl && !ans.count(p)) {
			ans.insert(p);
			//div(p);
//			for(int i=0;i<=n;i++){
//				cout<<a[i]<<' ';
//			}
//			cout<<endl;
		}
	}
	for(auto p:ans) cout<<p<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
std::string S;
int main() {
	std::cin >> S;
	int size = S.size();
	for (int i = 0; i < size - 1; i++) {
		if (S[i] == 'A') {
			if (S[i + 1] == 'C') {
				std::cout << "Yes" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool f = true;
    if(n%2==1){
        f=false;
    }else{
        REP(i,n/2){
            if(s[i]!=s[n/2+i]){
                f=false;
                break;
            }
        }
    }
    if(f){
        cout <<"Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

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

long long num[100000];

int main(){
	int n;
	long long sum =0;
	cin >> n;
	while(n--){
		int x;
		cin >> x;
		num[x-1]++;
		sum+=x;
	}
	int q;
	cin >> q;
	while(q--){
		int b,c;
		cin >> b >> c;
		num[c-1]+=num[b-1];
		sum -= (b*num[b-1]);
		sum += (c*num[b-1]);
		num[b-1]=0;
		cout << sum << '\n';
	}

}

Measured memory_bytes: 4372
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	priority_queue<int> q;
	rep(i, n) {
		int a;
		cin >> a;
		q.push(a);
	}
	rep(i, m) {
		int a = q.top(); q.pop();
		q.push(a / 2);
	}
	ll count = 0;
	rep(i, n) {
		count+= q.top(); q.pop();
	}
	cout << count << endl;
}

Measured memory_bytes: 892
#include <stdio.h>

int key[500001];
int left[500001];
int right[500001];
int root;
int head;

void printpre(int i){
    if(i == -1) return;
    printf(" %d", key[i]);
    printpre(left[i]);
    printpre(right[i]);
}

void printin(int i){
    if(i == -1) return;
    printin(left[i]);
    printf(" %d", key[i]);
    printin(right[i]);
}

int find(int r, int v){
    if(r == -1)
        return -1;
    if(v < key[r])
        return find(left[r], v);
    else if(v == key[r])
        return r;
    else
        return find(right[r], v);
}

void insert(int z){
    int y = -1;
    int x = root;
    while(x != -1){
        y = x;
        if(z < key[x])
            x = left[x];
        else
            x = right[x];
    }

    if(y == -1) {
        root = head;
    } else if(z < key[y]) {
        left[y] = head;
    } else {
        right[y] = head;
    }
    key[head] = z;
    left[head] = -1;
    right[head] = -1;
    head++;
}

int main(void){
    int n;
    scanf("%d", &n);
    root = -1;
    while(n--){
        char cmd[8];
        scanf("%s", cmd);
        if(cmd[0] == 'i'){
            int z;
            scanf("%d", &z);
            insert(z);
        } else if(cmd[0] == 'f') {
            int z;
            scanf("%d", &z);
            printf("%s\n", find(root, z) == -1 ? "no" : "yes");
        } else {
            printin(root);
            puts("");
            printpre(root);
            puts("");
        }
    }
}



Measured memory_bytes: 6492