akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int kouyakusuu(int a,int b);
int main(){
    int ans=0,tmp=0,k,b,c;
    scanf("%d",&k);
    for(int a=1;a<=k;a++){
        for(b=1;b<=k;b++){
            for(c=1;c<=k;c++){
                tmp=kouyakusuu(a,b);
                tmp=kouyakusuu(tmp,c);
                ans+=tmp;
            }
            c=1;
        }
        b=1;
    }
        printf("%d\n",ans);
}
int kouyakusuu(int a,int b){
    int tmp,r;
    /* 自然数 a > b を確認・入替 */
     if(a<b){
       tmp = a;
       a = b;
       b = tmp;
     }
     /* ユークリッドの互除法 */
     r = a % b;
     while(r!=0){
       a = b;
       b = r;
       r = a % b;
     }
     /* 最大公約数を出力 */
    return b;
}


Measured memory_bytes: 1736
function Main(input) {
    const lines = input.split('\n')
    const s = lines[0];
    const t = lines[1];

    let result = (s == t.slice(0, t.length - 1)) ? "Yes" : "No";
    // console.log("");
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29548
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '1')
            cout << 9;
        else if(s[i] == '9')
            cout << 1;
        else
            cout << s[i];
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int a[3][3];

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    cin >> a[0][0] >> a[0][1] >> a[1][1];

    int s = 3 * a[1][1];
    a[0][2] = s - a[0][1] - a[0][0];
    a[2][1] = s - a[0][1] - a[1][1];
    a[2][2] = s - a[0][0] - a[1][1];
    a[1][2] = s - a[0][2] - a[2][2];
    a[1][0] = s - a[1][1] - a[1][2];
    a[2][0] = s - a[2][1] - a[2][2];

    forn (i, 3) {
        forn (j, 3)
            cout << a[i][j] << ' ';
        cout << '\n';
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    string s;cin>>s;
    for(int i=0;i<s.length();i++) {
        if(i%2==0) cout<<s[i];
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct card{char suit;int value;};
card c1[100],c2[100];
int n;
void sw(card &x,card &y){
	card t;
	t=x;
	x=y;
	y=t;
}
void bubble(struct card a[],int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>=i+1;j--){
			if(a[j].value<a[j-1].value){
				sw(a[j],a[j-1]);
			}
		}
	}
}
void select(struct card a[], int n){
	for(int i=0;i<n;i++){
		int minj=i;
		for(int j=i;j<n;j++){
			if(a[j].value<a[minj].value){
				minj=j;
			}
	}
		sw(a[i],a[minj]);
	}
}
bool judge(struct card c1[],struct card c2[],int n){
	for(int i=0;i<n;i++){
		if(c1[i].suit!=c2[i].suit){
			return false;
		}
    }
	return true;
}
void print(struct card a[],int n){
	for(int i=0;i<n;i++){
		if(i>0){
			printf(" ");
		}
		printf("%c%d",a[i].suit,a[i].value);
	}
	printf("\n");
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    cin>>c1[i].suit >>c1[i].value ;
	}
	for(int i=0;i<n;i++){
		c2[i]=c1[i];
	}
    bubble(c1,n);
    select(c2,n);
    print(c1,n);
    printf("Stable\n");
    print(c2,n);
    if(judge(c1,c2,n)){
    	printf("Stable\n");
	}
	else{
		printf("Not stable\n");
	}
	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (!i && a[i] != 0 || i && a[i]-a[i-1] > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (i == n-1 || a[i+1]-a[i] < 1)
      ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	string s; 
	string t;
	cin >> s >> t;

 	SORT(s);
 	SORT(t);
	reverse(t.begin(), t.end());

	if(s < t) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;

}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: i32 = read();
    let mut dsum = 0;

    let mut nn = n;
    while nn >= 1 {
        dsum += nn % 10;
        nn /= 10;
    }
    if n % dsum == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int MAX_ROW = 60;   // to be set appropriately
const int MAX_COL = 200;  // to be set appropriately
struct BitMatrix {
  int H, W;
  bitset<MAX_COL> val[MAX_ROW];
  BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
  inline bitset<MAX_COL> &operator[](int i) { return val[i]; }
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
  int rank = 0;
  for(int col = 0; col < A.W; ++col) {
    if(is_extended && col == A.W - 1) break;
    int pivot = -1;
    for(int row = rank; row < A.H; ++row) {
      if(A[row][col]) {
        pivot = row;
        break;
      }
    }
    if(pivot == -1) continue;
    swap(A[pivot], A[rank]);
    for(int row = 0; row < A.H; ++row) {
      if(row != rank && A[row][col]) A[row] ^= A[rank];
    }
    ++rank;
  }
  return rank;
}

int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
  int m = A.H, n = A.W;
  BitMatrix M(m, n + 1);
  for(int i = 0; i < m; ++i) {
    for(int j = 0; j < n; ++j) M[i][j] = A[i][j];
    M[i][n] = b[i];
  }
  int rank = GaussJordan(M, true);

  // check if it has no solution
  for(int row = rank; row < m; ++row)
    if(M[row][n]) return -1;

  // answer
  res.assign(n, 0);
  for(int i = 0; i < rank; ++i) res[i] = M[i][n];
  return rank;
}

int main() {
  ll t;
  cin >> t;
  rep(_, t) {
    ll n;
    cin >> n;
    vl a(n);
    string s;
    rep(i, n) cin >> a[i];
    cin >> s;
    vl dp;
    bool ans = false;
    for(int i = n - 1; i >= 0; i--) {
      ll m = dp.size();
      if(s[i] == '0')
        dp.push_back(a[i]);
      else {
        if(m == 0)
          ans = true;
        else {
          BitMatrix bm(MAX_ROW, m);
          vi b(MAX_ROW), res;
          rep(j, m) rep(k, MAX_ROW) bm[k][j] = (dp[j] >> k & 1);
          rep(k, MAX_ROW) b[k] = (a[i] >> k & 1);
          int rank = linear_equation(bm, b, res);
          if(rank == -1) ans = true;
        }
      }
    }
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3664
nlist=list(map(int,input().split()))
count=0
while max(nlist)-min(nlist)!=0:
    if max(nlist)-min(nlist)>=2:
        #最小値のindexを取得して、+2する
        minindex=nlist.index(min(nlist))
        nlist[minindex]+=2
        #print("first")
        #print(nlist)
        count+=1
        
    else:
        #665,655のような状態。同種を+1ずつする。
        nlist.sort()
        if nlist[0]==nlist[1]:
            nlist[0]+=1
            nlist[1]+=1
            
        else:
            nlist[1]+=1
            nlist[2]+=1
            
        #print("second")
        #print(nlist)
        count+=1
        
#print(nlist)
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
   ll n;
   cin>>n;
   if(n>=30)
    cout<<"Yes"<<endl;
   else cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 3588
N = int(input())

A = []
B = []
for i in range(N):
    x,y = list(map(int,input().split()))
    A.append(x+y)
    B.append(-x+y)


A.sort()
B.sort()

print(max(abs(A[0]-A[-1]),abs(B[0]-B[-1])))

Measured memory_bytes: 100148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int l , r;

int main()
{   

      ios_base::sync_with_stdio(0);
      cin.tie(0);cout.tie(0);


      cin>>l>>r;

      int end = min(r,l+2019);
      int ans = 2019;
      for (int i=l; i < end ; i++)
            for (int j= i+1;j <= end ; j++)
                  ans=min(ans,i%2019*(j%2019)%2019);
                  
      cout << ans << endl;


      return 0;
}

Measured memory_bytes: 256
def binary_search_list(beSearched,wanted) :
    l = 0
    r = len(beSearched)

    #print("condition = {}".format(r-l))

    while r - l >= 1 :
        s = (l + r) // 2
        #print("l={} r={} s={}".format(l,r,s))
        if beSearched[s] == wanted :
            return True
        if beSearched[s] > wanted :
            r = s
        else :
            l = s + 1

    return False

K,S = (int(_) for _ in input().split())
num = [_ for _ in range(K+1)]
out = 0
for i in range(K+1):
    for j in range(i+1):
        if 0 <= S - i - j <= j :
            if i == j and j == S - i - j:
                out += 1
            elif i == j or j == S - i - j or S -i - j == i:
                out += 3
            else :
                out += 6
        #print(num[:j+1])
        #b = binary_search_list(num[:j+1],S - i - j)
        #print("b={} i={} j={} k = {}".format(b,i,j, S- i -j))
        #if b :
            #if i == j and j == S - i - j:
                #out += 1
            #elif i == j or j == S - i - j or S -i - j == i:
                #out += 3
            #else :
                #out += 6

print(out)


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int h, w, res, bc = 0;
	char s[50][51];

	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++) {
		scanf("%s", s[i]);
		for (int j = 0; j < w; j++)
			if (s[i][j] == '.')
				bc++;
	}

	class Int2 {
	public:
		int cost, a, b;
		Int2(int cost = 0, int a = 0, int b = 0) :cost(cost), a(a), b(b) {};
	};

	queue<Int2> q;
	q.emplace(1, 0, 0);
	s[0][0] = 'o';
	while (!q.empty()) {
		Int2 cur(q.front());
		q.pop();

		if (1 <= cur.a && s[cur.a - 1][cur.b] == '.') {
			q.emplace(cur.cost + 1, cur.a - 1, cur.b);
			s[cur.a - 1][cur.b] = 'o';
		}
		if (1 <= cur.b && s[cur.a][cur.b - 1] == '.') {
			q.emplace(cur.cost + 1, cur.a, cur.b - 1);
			s[cur.a][cur.b - 1] = 'o';
		}
		if (cur.a + 1 < h && s[cur.a + 1][cur.b] == '.') {
			q.emplace(cur.cost + 1, cur.a + 1, cur.b);
			s[cur.a + 1][cur.b] = 'o';
		}
		if (cur.b + 1 < w && s[cur.a][cur.b + 1] == '.') {
			q.emplace(cur.cost + 1, cur.a, cur.b + 1);
			s[cur.a][cur.b + 1] = 'o';
		}
		if (cur.a == h - 1 && cur.b == w - 1)
			res = cur.cost;
	}

	if (s[h - 1][w - 1] != 'o')
		printf("-1\n");
	else
		printf("%d\n", bc - res);
}

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

vector<int> vr,vg,vb;

int main(){
	string s;
	int n;
	long long ans=0;
	cin>>n>>s;
	
	for(int i=0;i<n;i++){
		if(s[i]=='R') vr.push_back(i);
		else if(s[i]=='G') vg.push_back(i);
		else vb.push_back(i);
	}
	
	int a=vr.size(),b=vg.size(),c=vb.size();
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			ans+=c;
			
			int d=abs(vr[i]-vg[j]);
			int mi=min(vr[i],vg[j]),ma=max(vr[i],vg[j]);
			
			if(mi-d>=0&&s[mi-d]=='B') ans--;
			if(ma+d<n&&s[ma+d]=='B') ans--;
			if((vr[i]+vg[j])%2==0&&s[mi+d/2]=='B') ans--;
		}
	}
	
	cout<<ans;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  if ( s == "Sunny"){
    cout << "Cloudy" << endl;
  } else if ( s == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
map{*I=-$_;<>=~$",vec($I,$`-1,8)=$'+49for 1..<>;$Z.='{0,2}'}1..<>;
printf sort{$b-$a}map{
	map{$i=0;for$c(/./g){$i--;$c-2or$_|=$$i}}($_)x5;
	!/3/*y/2//
}glob$Z

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =5e5;
const ld SADAT = 7.84e-17;
const ll INF = 1e18;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define all(x) x.begin() , x.end()
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ms(x , y) memset(x , y , sizeof x);
#define prnt(x)  for(int i = 0 ; i < x.size() ; i ++) cout << x[i] << ' ';
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n;
int p[10] , q[10] , ans[10];

bool ok(int x[]){
    for (int i  = 1 ; i <= n ; i ++){
        if(ans[i]!=x[i]) return(0);
    }
    return(1);
}

int main(){
    migmig
    cin >> n;
    for (int i  = 1 ; i <= n ; i  ++){
        cin >> p[i];
    }

    for (int i  = 1 ; i <= n ; i  ++){
        cin >> q[i];
    }

    for (int i  = 1 ; i <= n ; i  ++){
        ans[i]  =i;
    }
    int cnt = 1  , i = -1 , j = -1;
    while(1){
        if(ok(p)){
            i = cnt;
        }
        if(ok(q)){
            j = cnt;
        }
        if(i > 0 and j > 0){
            dokme(abs(i - j));
        }
        next_permutation(ans + 1 , ans + n + 1);
        cnt++;
    }
    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#define N 200001
using namespace std;
long long a[N],n,sum[N][19];
long long fuckljx;
struct hh{
	int x,y;
}cnt[N];
bool operator<(hh a,hh b){
	if(a.x!=b.x)return a.x>b.x;
	else return a.y>b.y;
}
int main(){
//	freopen("b.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		double x;
		scanf("%lf",&x);
		a[i]=(llround)(x*(long long)1e9);
//		cout<<a[i]<<endl;
		while(a[i]%2==0)a[i]/=2,cnt[i].x++;
		while(a[i]%5==0)a[i]/=5,cnt[i].y++;
		if(cnt[i].y>18)cnt[i].y=18;
//		cout<<i<<" "<<cnt[i].x<<" "<<cnt[i].y<<endl;
	}
	sort(cnt+1,cnt+1+n);
	cnt[0].x=1e8;
//	for(int i=1;i<=n;i++)cout<<cnt[i].x<<' '<<cnt[i].y<<endl;
	for(int i=1;i<=n;i++){
		int l=0,r=i-1,ans=0;
		while(l<=r){
			int mid=(l+r)/2;
			if(cnt[i].x+cnt[mid].x>=18)l=mid+1,ans=mid;
			else r=mid-1;
		}
//		cout<<"check "<<ans<<endl;
		for(int j=0;j<=18;j++){
			if(j+cnt[i].y>=18)fuckljx+=sum[ans][j];
			sum[i][j]=sum[i-1][j];
		}
//		cout<<fuckljx<<endl;
		sum[i][cnt[i].y]++;
//		cout<<fuckljx<<endl;
	}
//	for(int i=1;i<=n;i++){
//		for(int j=0;j<=18;j++)cout<<sum[i][j]<<' ';
//		cout<<endl;
//	}
	cout<<fuckljx;
}

Measured memory_bytes: 36472
#include<iostream>
using namespace std;
long long n,m,x,sum,flg;
string str;
int t[100001],u[100001];
int dfs(int x){
  if(u[x]==1)return x;
  return dfs(t[x]);
}
int main(){
  while(cin>>n>>m,n){
    for(int i=0;i<100001;i++)u[i]=0;
    t[1]=u[1]=1;
    sum=0;
    for(int i=0;i<n-1;i++)cin>>t[i+2];
    for(int i=0;i<m;i++){
      cin>>str>>x;
      if(str=="Q"){
    sum+=dfs(x);
      }else{
    u[x]=1;
      }
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1988
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.PrintWriter

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val (x, a, b) = br.readLine().split(" ").map { it.toInt() }

  val ans = if(Math.abs(a - x) < Math.abs(b - x)) "A" else "B"

  println(ans)
}

Measured memory_bytes: 35528
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 3e3 + 5;
int n , m , k , a[N][N];
ll memo[N][N][4];
ll solve(int i , int j , int cnt) {
    if(i >= n || j >= m || cnt > 3)
        return -1e15;
    if(i == n - 1 && j == m - 1)
        return cnt < 3 ? a[i][j] : 0;
    ll &ans = memo[i][j][cnt];
    if(~ans)
        return ans;
    ans = solve(i + 1 , j , 0);
    if(cnt < 3)
        ans = solve(i + 1 , j , 0) + a[i][j];
    ans = max(ans , solve(i , j + 1 , cnt + (a[i][j] > 0)) + a[i][j]);
    ans = max(ans , solve(i , j + 1 , cnt));
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m >> k;
    for(int i = 0;i < k;i++) {
        int r , c , v;
        cin >> r >> c >> v;
        a[r - 1][c - 1] = v;
    }
    memset(memo , -1 , sizeof memo);
    cout << solve(0 , 0 , 0);
    return 0;
}

Measured memory_bytes: 321472
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n; vector <pair <int, int>> a;
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++)
		if (i + j != n + (n + 1) % 2) a.emplace_back(i, j);
	writeln(a.size());
	for (auto x : a)
		printf("%d %d\n", x.first, x.second);
	return 0;
}

Measured memory_bytes: 384
def fibo(n1,n2)
    return n1+n2
end
 
list = []
 
list << 1
list << 1
 
n = gets.to_i
 
2.upto(n) do |i|
    list << fibo(list[i-2], list[i-1])
end
 
puts list[n]


Measured memory_bytes: 6860
import 'dart:io';

main(List<String> args){
  final int k = int.parse(stdin.readLineSync());
  List<int> A =
      stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  bool c=false;
  for(int i=A[0];i<=A[1];i++){
    if(i%k==0){
      c=true;
      break;
    }
  }
  print(c?"OK":"NG");
}

Measured memory_bytes: 13108
import collections

N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


primes = collections.Counter(prime_factorize(N))
ans = 0
for prime, num in primes.items():
    n = 1
    while (n + 1) * (n + 2) / 2 <= num:
        n += 1
    ans += n

print(ans)

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

bool vis[200001];
int l[100001],r[100001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int> > v;
	long long int ans, tot = 0,totl = 0, totr = 0;
	for(int i=0;i<n;i++){
		cin>>l[i]>>r[i];totl+=l[i],totr+=r[i];
		v.emplace_back(l[i],i<<1);
		v.emplace_back(r[i],i<<1|1);
	}
	ans = min(totl,totr);
	sort(v.begin(),v.end());
	for(int i=0;i<n-2;i++)
		vis[v[i].second] = true, tot += v[i].first;
	for(int i=0;i<n;i++){
		int stp = n-2;
		long long int cur = tot;
		if(vis[i<<1]){
			while((v[stp].second>>1) == i)	stp++;
			cur += v[stp++].first;
		}
		else
			cur += l[i];
		if(vis[i<<1|1]){
			while((v[stp].second>>1) == i)	stp++;
			cur += v[stp++].first;
		}
		else
			cur += r[i];
		ans = min(ans,cur);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2932
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define mp make_pair
#define F first
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y)
#define S second
#define ll long long int
#define inf 1000000014
#define infl (ll)(3e18+250)
#define MOD 1000000007
#define sz(x) (int) x.size()
#define pi pair< int , int >
#define pii pair<pi,int>
#define nax 201010
#define pu push
#define trace1(x)  cerr << #x << ": " << x << endl
#define trace2(x, y)  cerr << #x << ": " << x << " | " << #y << ": " << y << endl
using namespace std;
vector < pi > v;
vector< int > nz,z;
int ans[nax];
int main(int argc, char const *argv[])
{
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   int n,x;
   sd(n);
   for(int i = 1; i <= n; i++)
   {
     sd(x);
     if(x)
     {
       v.pb(mp(x,i));
       nz.pb(i);
     }
     else
      z.pb(i);
   } 
   v.pb(mp( (1 << 24) - 1, n + 1));
   int siz = sz(v);
   ll fans = 0;
   for(int i = 0; i < siz; i++)
   {
      int ff = v[i].F;
      int ss = v[i].S;
      for(int j = i + 1; j < siz; j++)
      {
         if(ff + v[j].F != (ff ^ v[j].F))
         {
           fans += v[j].S - ss;
           ans[ss] = v[j].S;
           break;
         }
         else
            ff += v[j].F;
      }
   }
   siz = sz(z);
   for(int i = 0; i < siz; i++)
   {
      int idx = lower_bound(nz.begin(), nz.end(), z[i]) - nz.begin();
      if(idx < sz(nz))
        fans += ans[v[idx].S] - z[i];
      else
        fans += n + 1 - z[i];
   }
   printf("%lld\n",fans);
   return 0;
}


Measured memory_bytes: 4464
n = int(raw_input())

for i in range(n):
    a = raw_input()
    b = raw_input()

    if len(a) > 80 or len(b) > 80:
        print 'overflow'
    else:
        a, b = int(a), int(b)
        c = a + b
        if len(str(c)) > 80:
            print 'overflow'
        else:
            print c

Measured memory_bytes: 4236
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		boolean first = true;
		for (;sc.hasNext();) {
			int n = sc.nextInt();
			if (n == 0) break;
			if (first) first = false; else System.out.println(); 
			T[] ts = new T[n];
			for (int i = 0; i < n; i++) {
				T t = new T();
				t.id = i;
				t.name = sc.next();
				int win = sc.nextInt();
				int lose = sc.nextInt();
				int draw = sc.nextInt();
				t.point = win * 3 + draw * 1;
				ts[i] = t;
			}
			Arrays.sort(ts);
			for (T t : ts) {
				System.out.println(t.name+","+t.point);
			}
			
		}
	}
	
	class T implements Comparable<T> {
		String name;
		int id;
		int point;
		@Override
		public int compareTo(T o) {
			if (point != o.point) return -(point - o.point);
			return (id - o.id);
		}
	}
}

Measured memory_bytes: 20568
#include<iostream>
#include<map>

int main() {
  int N;
  std::cin >> N;
  std::map<int, int> num;
  for (int i=0; i<N; i++) {
    int temp_num;
    std::cin >> temp_num;
    num[temp_num] = 1;
  }
  std::cout << num.size() << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,b,a) for(int i = (b); i --> int(a);)
#define trav(i,v) for(auto&i:v)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define vcr(v,n) vi v(n); trav(var,v) cin >> var;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	int n;
	cin >> n;
	int c[100100] = {};
	deque<int> dq;
	rep(_,0,n){
		int a;
		cin >> a;
		if(++c[a] == 2) dq.push_back(a);
	}
	sort(all(dq));
	while(!dq.empty()){
		int i = dq.front();
		dq.pop_front();
		while(c[i] > 1 && !dq.empty()){
			int j = dq.front();
			if(--c[j] == 1) dq.pop_front();
			--c[i], n -= 2;
		}
		n -= c[i]-1;
		if(~c[i]&1) --n;
	}
	cout << n << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	if (a > b)
	{
		swap(a, b);
	}

	if (a <= c && c <= b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	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++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
  int n;
  cin >> n;
  vector<int> v(n),c(n);
  rep(i,0,n) cin >> v.at(i);
  rep(i,0,n) cin >> c.at(i);
  int ans=0;
  rep(i,0,n){
      if(v.at(i)-c.at(i)>0) ans+=v.at(i)-c.at(i);
  }
  cout << ans << endl;
}

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

using namespace std;

const int MN = 100010;
int n;
int freq[MN];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        freq[a]++;
    }
    int ans = n, ev = 0;
    for (int x = 0; x < MN; x++) {
        if (!freq[x]) continue;
        ans -= freq[x] - 1;
        if (freq[x] % 2 == 0) {
            ev++;
        }
    }
    if (ev % 2 == 1) {
        ans--;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
	int n, i = 0;
	map<int, vector<int> > tmp;
	while (cin >> n) {
		tmp[n].push_back(i);
		i++;
	}

	if (tmp[5].size() == 2 && tmp[7].size() == 1)
		puts("YES");
	else
		puts("NO");

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long 
const int maxn = 1e6 + 5;
int a[maxn];
int main()
{
	int a;
	cin >> a;
	int t = a / 1000;
	if (a % 1000)t++;
	cout << t * 1000 - a << endl;
}


Measured memory_bytes: 3632
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N, Y;

  cin >> N >> Y;

  bool flag = false;
  ll a, b, c;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        flag = true;
        a = i;
        b = j;
        c = N - i - j;
      }
    } //j
  } //i

  if(!flag){
    a = -1; 
    b = -1; 
    c = -1; 
  }

  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
import time
startTimeProblem=time.time()

import fileinput, sys, itertools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

r = In.int()





print(2*pi*r)


######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 67380
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::cmp::{max, min, Ordering};

macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

// N M => let (N, M) = get!(usize, usize)
// A1 B1
// ...
// AQ BQ => let A = get!(usize, usize; Q)

const MOD: u64 = 1000000007;

fn main() {
    let (N1, N2, N3, N4) = get!(usize, usize, usize, usize);
    let mut A = [N1, N2, N3, N4];
    A.sort();

    if A == [1, 4, 7, 9] {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

long long gcd(long long, long long);

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

	long long g = gcd(max(a, b), min(a, b));

	long long count = 1;
	long long p = 2;
	while (g >= p * p) {
		if (g % p == 0) {
			++count;
		}

		while (g % p == 0) {
			g /= p;
		}

		++p;
	}

	if (g != 1) {
		++count;
	}

	cout << count;
}

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


Measured memory_bytes: 256
a, b, c, k = map(int,input().split())

count = 0


if a > 0 and a <= k and k > 0:
  count = count + a
  k = k - a
elif a > 0 and a > k and k > 0:
  count = k
  k = 0

if b > 0 and b <= k and k > 0:
  k = k - b
elif b > 0 and b > k and k > 0:
  k = 0
  
if c > 0 and c <= k and k > 0:
  count = count - c
  k = k - c
elif c > 0 and c > k and k > 0:
  count = count - k
  k = 0
    
print(count)

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

int main (){
  int x,y,z,a,X;
  cin >> x;

  z = 0;
  a = 0;
  X = x;

  for (int i = 100000000 ; i!=0 ; i /=10){
    X -= a; 
    y = X / i;
    a = y * i;
    z += y;//各位の和
    //cout <<X<<y<<z<<endl;
        }
  
  if (x % z ==0)
  cout << "Yes" <<endl;
  else
  cout << "No" <<endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a[ohara], b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> k;
    rep(i, n) cin >> a[i];
    pos = __gcd(a[0], a[1]);
    rrep(i, 2, n) pos = __gcd(pos, a[i]);
    if (k % pos == 0)
    {
        if (*min_element(a, a + n) > k || *max_element(a, a + n) < k)
            Cout("IMPOSSIBLE");
        else
            Cout("POSSIBLE");
    }
    else
        Cout("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 1024
N=int(input())
l=[]
dp=[[0 for i in range(3)]for j in range(N+2)]
for i in range(N):
    a,b,c=[int(x) for x in input().rstrip().split()]
    l.append([a,b,c])


for i in range(1,N+1):
    now=l[i-1]
    for j in range(3):
        if j==0:
            dp[i][0]=max(dp[i-1][1]+now[0],dp[i-1][2]+now[0])
        elif j==1:
            dp[i][1]=max(dp[i-1][2]+now[1],dp[i-1][0]+now[1])
        else:
            dp[i][2]=max(dp[i-1][0]+now[2],dp[i-1][1]+now[2])
print(max(dp[N]))


Measured memory_bytes: 44108
#include <iostream>
#include <string>
#include <vector>

using namespace std;

static int count_digit(const int a, const int b) {
	return to_string(a + b).length();
}

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



Measured memory_bytes: 3252
s=input()
s=list(s)
if s[1]==s[2] and s[0]==s[1] and s[0] == "R":
	print(3)
elif s[1]==s[2] and s[0]==s[1] and s[0] != "R":
	print(0)
elif (s[1]==s[2] or s[0]==s[1])and s[1]=="R":
	print(2)
else:
	print(1)


Measured memory_bytes: 9056
import java.util.Scanner;

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

        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int coins = 0;

        for (int i = 0; i < 2; i++) {
            coins += Math.max(A, B);
            if (A > B) {
                A--;
            } else {
                B--;
            }
        }
        System.out.print(coins);
    }
}

Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;
int n, m;
vector<vector<int>> graph;

int dfs(int v, int s) {
  bool ok = true;
  rep(i, n) {
    int t = s>>i&1;
    if(t == 0) ok = false;
  }
  if(ok) return 1;

  int res = 0;
  for (int u: graph[v]) {
    int nexts = (1<<u)|s;
    if((s>>u&1) == 0) {
      res += dfs(u, nexts);
    }
  }
  return res;
}

int main() {
  cin >> n >> m;
  graph.resize(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int ans = dfs(0, 1);
  cout << ans << endl;
}


Measured memory_bytes: 256
n,x = map(int, input().split())

l = [int(iz) for iz in input().split()]

bond = [0]
last = 0

for i in range(n):
    last = l[i] + last
    bond.append(last)

#print(bond)

count = 0 
for i in bond:
    if i <= x:
        count +=1

print(count)

#print(l)

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

using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	if (a%3==0 || b%3==0 || (a+b)%3==0) {
		cout << "Possible" << endl;
		return 0;
	}
	cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define m 1000001
#define L 12
char H[m][L]={};
long long X[m]={};
int getchar(char ch){
    if(ch=='A') return 1;
    else if(ch=='C') return 2;
    else if(ch=='G') return 3;
    else if(ch=='T') return 4;
}
long long getkey(char str[]){
    long long sum=0,p=1;
    for(int i=0;i<strlen(str);i++){
        sum+=p*getchar(str[i]);
        p*=4;
    }
    return sum;
    
}
int h1(int key){
    return key%m;
}
int h2(int key){
    return 1+(key%(m-1));
}
int h3(long long key,long long i){
    return (h1(key)+i*h2(key))%m;
}

int main(){
    int n;
    char command[6]={},str[12]={};
    scanf("%d",&n);
    for(long long i=0;i<n;i++){
        scanf("%s %s",command,str);
        if(command[0]=='i'){
            long long i=0,key;
            key=getkey(str);
            while(true){
                long long j=h3(key,i);
                if(X[j]==0){
                    X[j]=key;
                    break;
                }
                else i+=1;
            }
        }
            
        else{
            long long key,i=0;
            key=getkey(str);
            while(true){
                long long a=h3(key,i);
                if(X[a]==key){
                    printf("yes\n");
                    break;
                }
                else if(X[a]==0 || i>m){
                    printf("no\n");
                    break;
                }
                else i+=1;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 10944
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 2050
struct edge{int t,next,v,c;}ed[N*30];
int n,a,b,c,head[N],ct,cnt,vis2[N],vis3[N],vis[N];
long long dis[N],as;
void adde(int f,int t,int w,int c){ed[++cnt]=(edge){t,head[f],w,c};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0,-c};head[t]=cnt;}
void bfs2(int t)
{
	memset(vis2,0,sizeof(vis2));
	queue<int> tp;
	tp.push(t);
	vis2[t]=1;
	while(!tp.empty())
	{
		int x=tp.front();tp.pop();
		for(int i=head[x];i;i=ed[i].next)
		if(ed[i^1].v)
		if(!vis2[ed[i].t])vis2[ed[i].t]=1,tp.push(ed[i].t);
	}
}
bool spfa_is_dead(int s,int t)
{
	bfs2(t);
	memset(vis,0,sizeof(vis));
	memset(vis3,0,sizeof(vis3));
	memset(dis,0x3f,sizeof(dis));
	queue<int> tp;
	tp.push(s);
	dis[s]=0;vis[s]=1;
	while(!tp.empty())
	{
		int x=tp.front();tp.pop();
		vis[x]=0;
		for(int i=head[x];i;i=ed[i].next)
		if(ed[i].v&&vis2[ed[i].t])
		if(dis[ed[i].t]>dis[x]+ed[i].c)
		{
			dis[ed[i].t]=dis[x]+ed[i].c;
			if(!vis[ed[i].t])vis[ed[i].t]=1,tp.push(ed[i].t);
		}
	}
	return dis[t]<=1e15;
}
int dfs(int u,int t,int f)
{
	if(u==t||!f)return f;
	vis3[u]=1;
	int as1=0,tp;
	for(int i=head[u];i;i=ed[i].next)
	if(!vis3[ed[i].t]&&vis2[ed[i].t]&&ed[i].v&&dis[ed[i].t]==dis[u]+ed[i].c&&(tp=dfs(ed[i].t,t,min(ed[i].v,f))))
	{
		as1+=tp,f-=tp;
		ed[i].v-=tp,ed[i^1].v+=tp;
		as+=1ll*ed[i].c*tp;
		if(!f)return as1;
	}
	return as1;
}
long long dinic(int s,int t)
{
	while(spfa_is_dead(s,t))
	dfs(s,t,1e8);
	return as;
}
int main()
{
	scanf("%d",&n);
	ct=6;cnt=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		++ct;
		adde(1,ct,c,0);
		adde(ct,3,c,a+b);
		adde(ct,4,c,a-b);
		adde(ct,5,c,-a+b);
		adde(ct,6,c,-a-b);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		++ct;
		adde(ct,2,c,0);
		adde(3,ct,c,-a-b);
		adde(4,ct,c,-a+b);
		adde(5,ct,c,a-b);
		adde(6,ct,c,a+b);
	}
	printf("%lld\n",-dinic(1,2));
}//12

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <random>
/* All our base are belong to AC */
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;};
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll adad(ll x) {return x*(x+1)/2;} // 1～xの総和

namespace r {
    random_device rd;
    mt19937 mt(rd());
    //mt19937 mt(time(NULL));
    int nd(int max) {return mt() % max + 1;}
    int nd2(int min, int max) {return mt() % (max - min + 1) + min;}
}

int d;
ll c[26], s[365][26], t[365];
set<int> v[26];
ll an;

void solve0() {
  an=0;
  for(int i=0;i<d;i++) {
    an+=s[i][t[i]];
  }
  for(int i=0;i<26;i++) {
    int bf = -2;
    ll su = 0;
    for(int x : v[i]) {
      su+=adad(x-bf-1);
      bf=x;
    }
    an-=su*c[i];
  }
}

void solve1(int h, int k) {
  int bf = t[h];
  an-=s[h][bf];
  an+=s[h][k];

  auto s1 = v[bf].lower_bound(h);
  auto s2 = v[bf].upper_bound(h);
  s1--;
  //cout<<*s1<<" "<<h<<" "<<*s2<<endl;

  an+=adad((*s2) - h - 1) * c[bf];
  an+=adad(h - (*s1) - 1) * c[bf];
  an-=adad((*s2) - (*s1) - 1) * c[bf];
  v[bf].erase(h);
  
  auto t1 = v[k].lower_bound(h);
  auto t2 = v[k].upper_bound(h);
  t1--;
  //cout<<*t1<<" "<<h<<" "<<*t2<<endl;

  an-=adad((*t2) - h - 1) * c[k];
  an-=adad(h - (*t1) - 1) * c[k];
  an+=adad((*t2) - (*t1) - 1) * c[k];
  v[k].insert(h);
  t[h]=k;
}

int main() {
  cin>>d;
  for(int i=0;i<26;i++) {
    cin>>c[i];
  }
  for(int i=0;i<d;i++) {
    for(int j=0;j<26;j++) {
      cin>>s[i][j];
    }
  }
  for(int i=0;i<26;i++) {
    v[i].insert(-1);
    v[i].insert(d);
  }
  for(int i=0;i<d;i++) {
    //cin>>t[i]; t[i]--;
    t[i] = r::nd(26)-1;
    v[t[i]].insert(i);
  }
  solve0();
  for(int i=0;i<5500000;i++) {
    int f = r::nd(d)-1;
    int g = r::nd(26)-1;
    ll ba = an;
    int undo = t[f];
    solve1(f,g);
    if (ba > an) solve1(f,undo);
  }
  for(int i=0;i<d;i++) {
    cout<<t[i]+1<<endl;
  }
}

Measured memory_bytes: 3732
#include<iostream>
#include<vector>
using namespace std;
int main(){
  long n,num,cnt,min,sum;
  vector<int> a;
  cin >>n;
  for(int i=0;i<n;i++){
    cin >> num;
    a.push_back(num);
  }
  cnt = sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
    if(i%2==0){
      if(sum<=0){
        cnt+=1-sum;
        sum=1;
      }
    }else{
      if(sum>=0){
        cnt+=1+sum;
        sum=-1;
      }
    }
  }
  min = cnt;
  cnt = sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
    if(i%2!=0){
      if(sum<=0){
        cnt+=1-sum;
        sum=1;
      }
    }else{
      if(sum>=0){
        cnt+=1+sum;
        sum=-1;
      }
    }
  }
  min = (min<cnt)?min:cnt;
  cout << min << endl;
}


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

int main(){
  int A, B, C;
  int tmp;
  cin >> A >> B >> C;
  while(A!=B){
    tmp = abs(A-B);
    A = min(A, B);
    B = tmp;
  }
  if (C%A == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256