akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second

const ll P = 1000000007;

using namespace std;

int n;
vector<int> g[101010];
ll dp[2][101010];

void dfs(int i, int p){

	dp[0][i] = 1;
	dp[1][i] = 1;
	
	for(int j : g[i]){
		if(j!=p){
			dfs(j, i);
			dp[0][i] = (dp[0][i]*(dp[0][j]+dp[1][j]))%P;
			dp[1][i] = (dp[1][i]*dp[0][j])%P;
		}	
	}

}

int main(){

	cin >> n;
	for(int i=1; i<n; i++){
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dp[0][1]--;
	dp[1][1]--;
	dfs(1, 0);

	cout << (dp[0][1]+dp[1][1])%P << endl;

	return 0;
}


Measured memory_bytes: 14208
# -*- coding: utf-8 -*-

s = int(input())
a = [s]

for i in range(1000):
    if a[i] % 2:
        tmp = 3 * a[i] + 1
    else:
        tmp = a[i] // 2

    if tmp in a:
        print(i + 2)
        exit()
    else:
        a = a + [tmp]

print('Meh')


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(in) in.begin(),in.end()
#define int long long
typedef pair<int,int> pii;
signed main(){
    int n,t,q;
    cin >> n >> t >> q;
    vector<pii> l,r;
    vector<int> in(n),d(n);
    rep(i,n){
        cin >> in[i] >> d[i];
        if(d[i] == 1){
            r.push_back(pii(in[i],i));
        }else{
            l.push_back(pii(in[i],i));
        }
    }
    sort(all(l));
    sort(all(r));
    //rep(i,l.size())cout << " " << l[i].first;cout << endl;
    //rep(i,r.size())cout << " " << r[i].first;cout << endl;
    rep(i,q){
        int qq;
        cin >> qq;
        qq--;
        if(d[qq] == 1){
            //lの中からin[qq]以上の最小ind1をさがす
            int tmp1 = upper_bound(all(l), pii(in[qq],-1)) - l.begin();
            if(tmp1 == l.size()){
                cout << in[qq] + t << endl;
                continue;
            }
            int ind1 = l[tmp1].second;
            //rの中からin[ind1]以下の最大ind2をさがす
            int tmp2 = lower_bound(all(r), pii(in[ind1],-1)) - r.begin() - 1;
            int ind2 = r[tmp2].second;
            int x = (in[ind1] + in[ind2])/2;
            //cout << ind1 << " " << ind2 << " " << x << endl;
            if(in[qq] + t > x){
                cout << x << endl;
            }else{
                cout << in[qq] + t << endl;
            }
        }else{
            int tmp1 = lower_bound(all(r),pii(in[qq],-1)) - r.begin() - 1;
            if(tmp1 < 0){
                cout << in[qq] - t << endl;
                continue;
            }
            int ind1 = r[tmp1].second;
            int tmp2 = upper_bound(all(l), pii(in[ind1],-1)) - l.begin();
            int ind2 = l[tmp2].second;
            int x = (in[ind1] + in[ind2])/2;
            //cout << ind1 << " " << ind2 << " " << x << endl;
            if(x > in[qq] - t){
                cout << x << endl;
            }else{
                cout << in[qq] - t << endl;
            }
        }

    }
}



Measured memory_bytes: 6688
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a*b/2<<endl;
}

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

int isprime(int n);
int isSmallTwinPrime(int n);
int GetMaxTwinPrimeNumber(int argRange);

int main()
{
	int const size = 10000;
	int data[size];	
	
	int i=0;
	while(1) //for(int i=0; data[i]!=0; i++)
	{
		cin >> data[i];
		if(data[i]<=0) break;
		i++;
	}
	
	int outputNum;
	
	for(int i=0; data[i]!=0; i++)
	{
		outputNum = GetMaxTwinPrimeNumber(data[i]);
		if(outputNum!=0)
		{
			cout << outputNum-2 << " " << outputNum << endl;
		}
	}
	
	return 0;
}

int isprime(int n) 
{
	for(int i = 2; i * i <= n; i++) 
	{
		if(n % i == 0) 
		{
			return 0;
		}
	}
	return 1;
}

int isSmallTwinPrime(int n)
{
	for(int i = 2; i * i <= n; i++) 
	{
		if((n-2) % i == 0) 
		{
			return 0;
		}
	}
	return 1;
}

int GetMaxTwinPrimeNumber(int argRange)
{
	int maxTwinPrimeNum = 0;
	
	for(int i=0; ; i++)
	{
		int Num = argRange - i;
		
		if(isprime(Num)==1 && isSmallTwinPrime(Num)==1)
		{
			maxTwinPrimeNum = Num;
			return maxTwinPrimeNum;
		}
		
		if(Num==0)
		{
			return 0;
		}
	}
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    string ch;
    cin>>ch;
    int mx=0;
    int n=ch.size();
    for(int i=0;i<ch.size();i++)
    {
        int ase=0;
        if((ch[i]=='R'))
        {
            ase=1;
            while((i+1)<n && ch[i+1]=='R')
            {
                i++;ase++;
            }
            mx=max(mx,ase);
        }
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 3632
let n = int (stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.map int
let count = ref 0
for i in 0..n - 1 do
    while a.[i] % 2 = 0 do
        a.[i] <- a.[i] / 2
        count := !count + 1
printfn "%d" !count

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];

	set<int> s;
	rep(i, n){
		if(s.find(a[i]) == s.end()){
			s.insert(a[i]);
		} else {
			s.erase(a[i]);
		}
	}

	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 5376
import java.util.*;
class Main{
	public static void main(String[] args)throws Exception{
		int a,b,c;
		Scanner sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		if(a<=c&&b>=c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main() {
  int n,m,c;
  scanf("%d %d %d", &n, &m, &c);
  int a[n][m],b[m];
  int i,j;
  for(i=0;i<m;i++){
    scanf("%d", &b[i]);
  }
  
  int count=0;
  
  for(i=0;i<n;i++){
  int sum = c;
  for(j=0;j<m;j++){
    scanf("%d", &a[i][j]);
    sum += a[i][j]*b[j];
  }
  if(sum>0) count++;
  }

  printf("%d", count);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    string s;
    cin>>s;
    int idx=0;
    string ans;
    while(idx<=s.length()){
        if(s[idx]=='0'){
            ans.push_back('0');
        }
        else if(s[idx]=='1'){
            ans.push_back('1');
        }
        else if(s[idx]=='B'){
            if(ans.size()>=1) ans.pop_back();
        }
        idx++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint A[3];
    rep(i,3) cin >> A[i];
    sort(A,A+3);
    int ans=0;
    rep(i,100000){
        bool check=true;
        rep(j,3) if(A[j]%2) check=false;
        if(!check) break;
        ans++;
        lint move[3]={};
        rep(j,3) rep(k,3) if(j!=k) move[j]+=A[k]/2;
        rep(j,3) A[j]=move[j];
    }
    if(ans==100000) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main(){
  int n;
  cin>>n;
  long long int sum = 0;
  for(int i = 1;i <= n;i++){
    if(i % 5 == 0 || i %  3 == 0);
    else
      sum+=i;
  }
  
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 3608
import sys
sys.setrecursionlimit(10**6)

N,u,v = map(int,input().split())
edges = [list(map(int,input().split())) for _ in range(N-1)]
E = [[] for _ in range(N+1)]
for a,b in edges:
    E[a].append(b)
    E[b].append(a)

depth = [[-1,-1] for _ in range(N+1)] 
depth[v][0] = 0
depth[u][1] = 0
def dfs1(E,v):
    vv = E[v]
    for vvv in vv:
        if depth[vvv][0] == -1:
            depth[vvv][0] = depth[v][0] + 1
            dfs1(E,vvv)

def dfs2(E,v):
    vv = E[v]
    for vvv in vv:
        if depth[vvv][1] == -1:
            depth[vvv][1] = depth[v][1] + 1
            dfs2(E,vvv)
dfs1(E,v)
dfs2(E,u)
depth = sorted(depth, reverse=True)
idx = 0
while True:
    if depth[idx][0] - depth[idx][1] >= 1:
        print(depth[idx][0]-1)
        exit()
    else:
        idx += 1



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

public class Main{

	public static void main(String[] args){
		solve();
	}

	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] counter = new int[26];
		String[] a = new String[h];
		for(int i=0;i<h;i++){
			a[i] = sc.next();
			for(int j=0;j<w;j++){
				counter[(int)a[i].charAt(j)-(int)'a']++;
			}
		}
		int one = 0;
		int two = 0;
		if(h%2==1 && w%2==1){
			one = 1;
			two = h + w - 2;
		}
		else if(h%2==1){
			two = w;
		}
		else if(w%2==1){
			two = h;
		}
		
		int four = h*w-two-one;
		//System.out.println(four+" "+two+" "+one);
		for(int i=0;i<26;i++){
			if(four==0){
				break;
			}
			if(counter[i]>=4){
				counter[i] -= 4;
				i--;
				four-=4;
			}
		}
		for(int i=0;i<26;i++){
			if(two==0){
				break;
			}
			if(counter[i]>=2){
				counter[i] -= 2;
				i--;
				two-=2;
			}
		}
		for(int i=0;i<26;i++){
			if(one==0){
				break;
			}
			if(counter[i]>=1){
				counter[i] -= 1;
				i--;
				one--;
			}
		}
		if(four==0 && two==0 && one==0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 23764
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map(fun x -> int x)
let char2String(value) = List.ofSeq value |> List.toArray |> System.String

let s = List.ofArray(readString().ToCharArray())

let rec solve str acc result =
    match str with 
    | h :: t ->     
        if List.contains h ['A'; 'C'; 'G'; 'T'] then 
            solve t (acc + 1) (max (acc + 1) result)
        else 
            solve t 0 result
    | _ -> result

solve s 0 0
|> printfn "%d"

Measured memory_bytes: 12764
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<Character,Integer> alphabet = new HashMap<Character,Integer>();
        for(char i = 'a'; i <= 'z' ;i++){
            alphabet.put(i,0);
        }
        while(sc.hasNext()) {
        String str = sc.next();
         str = str.toLowerCase();
        for(int i = 0; i < str.length();i++){
            char c = str.charAt(i);
            if(alphabet.containsKey(c)){
                int count = alphabet.get(c) + 1;
                alphabet.put(c,count);
            }
        }
    }
        sc.close();
        for(char i:alphabet.keySet()){
            System.out.println(i + " : " + alphabet.get(i));
        }
    }
}


Measured memory_bytes: 26368
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> board(h);
    rep(i, h) {
        string s;
        cin >> s;
        board[i] = s;
    }

    vector<vector<ll>> dp(h, vector<ll>(w));  // dp[i][j] : (i,j)に行く経路数のmodでの剰余

    rep(j, w) {
        if(board[0][j] == '#') {
            break;
        }
        dp[0][j] = 1LL;
    }
    rep(i, h) {
        if(board[i][0] == '#') {
            break;
        }
        dp[i][0] = 1LL;
    }

    for(int i = 1; i < h; i++) {
        for(int j = 1; j < w; j++) {
            if(board[i][j] == '#') {
                continue;
            }

            dp[i][j] = dp[i-1][j] + dp[i][j-1];
            dp[i][j] %= mod;
        }
    }

    cout << dp[h-1][w-1] <<  endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;
    int count = 0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]&&b[i]==c[i]) continue;
        else if(a[i]!=b[i]&&b[i]!=c[i]&&a[i]!=c[i]) count+=2;
        else count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    multiset<int> mst;
    for(int i = 0; i < q; i++)
    {
        int com, x;
        cin >> com >> x;
        if(com == 0)
        {
            mst.insert(x);
            cout << mst.size() << endl;
        }
        else if(com == 1)
        {
            cout << mst.count(x) << endl;
        }
        else if(com == 2)
        {
            mst.erase(x);
        }
        else if(com == 3)
        {
            int y;
            cin >> y;
            auto it = mst.lower_bound(x);
            auto last = mst.upper_bound(y);
            while(it != last)
            {
                cout << *it << endl;
                it++;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 12404
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int INF = 1001001001;
	int N, W; cin >> N >> W;
	vector<ll> w(N + 1), v(N + 1);
	rep(i, 1, N)cin >> w[i] >> v[i];
	vector<vector<ll>> dp(N + 1, vector<ll>(101001, INF));
	dp[0][0] = 0;
	rep(i, 0, N - 1)rep(j, 0, 100001)
	{
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		dp[i + 1][j + v[i + 1]] = dp[i][j] + w[i + 1];
	}
	ll ans = 0;
	rep(i, 0, 100001)
	{
		ll now = i;
		if (dp[N][i] <= W)ans = max(ans, now);
	}
	cout << ans << endl;
}

Measured memory_bytes: 81024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1, i64); m]
    }
    let es2 = es.iter().map(|&(a, b, c)| (a, b, -c)).collect();
    if let Some(d) = bellman_ford(0, n - 1, n, &es2) {
        println!("{}", - d);
    } else {
        println!("inf");
    }
}

fn bellman_ford(s: usize, t: usize, n: usize, es: &Vec<(usize, usize, i64)>) -> Option<i64> {
    let mut d = vec![1 << 60; n];
    let mut forward = vec![false; n];
    let mut back = vec![false; n];
    d[s] = 0;
    forward[s] = true;
    back[t] = true;
    for _ in 0..n - 1 {
        for &(a, b, c) in es {
            if !forward[a] {
                continue;
            }
            d[b] = min(d[b], d[a] + c);
            forward[b] = true;
            back[a]|= back[b];
        }
    }
    for &(a, b, c) in es {
        if d[b] > d[a] + c && forward[a] && back[b] {
            return None;
        }
    }
    Some(d[t])
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int n, k;
int main(){
    while(cin >> n, n){
        int res=0;
        int rest=1000-n;
        while(rest){
            if(rest-500>=0){
                res++;
                rest-=500;
                continue;
            }
            if(rest-100>=0){
                res++;
                rest -=100;
                continue;
            }
            if(rest-50>=0){
                res++;
                rest -=50;
                continue;
            }
            if(rest-10>=0){
                res++;
                rest -=10;
                continue;
            }
            if(rest-5>=0){
                res++;
                rest -=5;
                continue;
            }
            if(rest-1>=0){
                res++;
                rest -=1;
                continue;
            }
        }
        cout << res << endl;
    }
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  set<char> s;
  for(int i=0;i<S.size();i++){
    s.insert(S.at(i));
  }
  if(s.size()==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

const int MAX = 100000;
int n, pa[MAX], le[MAX], ri[MAX], cnt;

void dfs_h(int a, int res){
  cnt = max(cnt,res);
  if(le[a] != -1) dfs_h(le[a], res+1);
  if(ri[a] != -1) dfs_h(ri[a], res+1);
}

void solve(){
  for(int i=0;i<n;i++){
    cout << "node " << i << ": parent = " << pa[i] << flush;

    if(pa[i] == -1) cout << ", sibling = " << -1 << flush;
    else if(le[pa[i]] != i) cout << ", sibling = " << le[pa[i]] << flush;
    else cout << ", sibling = " << ri[pa[i]] << flush;

    cnt = 0;
    if(le[i] != -1) cnt++;
    if(ri[i] != -1) cnt++;
    cout << ", degree = " << cnt << flush;

    cnt = 0;
    for(int j=pa[i]; j!=-1; j=pa[j]) cnt++;
    cout << ", depth = " << cnt << flush;

    cnt = 0;
    dfs_h(i,0);
    cout << ", height = " << cnt << flush;

    if(pa[i] == -1) cout << ", root" << endl;
    else if(le[i] == -1 && ri[i] == -1) cout << ", leaf" << endl;
    else cout << ", internal node" << endl;
  }

}

int main(){
  cin >> n;
  fill(pa,pa+MAX,-1);
  fill(le,le+MAX,-1);
  fill(ri,ri+MAX,-1);
  for(int i=0;i<n;i++){
    int a,b,c;
    cin >> a >> b >> c;
    le[a] = b;
    ri[a] = c;
    pa[b] = a;
    pa[c] = a;
  }
  solve();
}

Measured memory_bytes: 2336
n=int(input())
a=list(map(lambda x:int(x)-1,list(input())))
memo=[-1]*(n+1)
def log(x):
    if memo[x]!=-1:return memo[x]
    ret=0
    xx=x
    while x and x%2==0:
        x//=2
        ret+=1
    memo[xx]=ret
    return ret

def slv(n,a):
    v=a[0]
    if all(v==x for x in a):return 0
    # 答えの偶奇を求める
    chk=0
    tmppl=0
    tmpmi=0
    for i in range(n):
        x=a[i]%2
        if tmppl>tmpmi:
            pass
        else:
            chk+=a[i]
            chk%=2
        tmppl+=log(n-i-1)
        tmpmi+=log(i+1)
    if chk:return 1
    if 1 in a:return 0
    a=[x//2 for x in a]
    return slv(n,a)*2
print(slv(n,a))


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

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define	inf (ll)1e15
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=100100;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
	ll n;
	while(~sf("%lld",&n))
	{
		ll A[n+5],B[n+5];
		for(int i=1;i<=n;i++)
		{
			sf("%lld %lld",&A[i],&B[i]);
		}

		sort(A+1,A+n+1);
		sort(B+1,B+n+1);

		if(n%2==0)
		{
			ll X=A[n/2]+A[n/2+1];
			ll Y=B[n/2]+B[n/2+1];
			pf("%lld\n",Y-X+1);
		}
		else 
		{
			ll X=A[(n+1)/2];
			ll Y=B[(n+1)/2];
			pf("%lld\n",Y-X+1);
		}
	}
    return 0;
}




































Measured memory_bytes: 6952
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)

h = Hash.new(0)
n.times do |i|
  h[a[i]] += 1
end

h2 = {}
h.each_key do |i|
  h2[i] = h[i] * (h[i]-1) / 2
end

sum = h2.values.inject(:+)
h.each_key do |i|
  h2[i] = sum - h2[i] + (h[i]-1) * (h[i]-2) / 2
end
n.times do |i|
  puts h2[a[i]]
end

Measured memory_bytes: 39172
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include<iostream>
#include <set>

using namespace std;

int main() {
  int n,max=0;
  string s;
  // set <srting> se;
  map <string, int> x;
  map<string, int>::iterator it;
  set<string> ret;
  set<string>::iterator that;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    // scanf("%s", s);
    cin >> s;
    if(x.find(s)!=x.end()){
      x[s]++;
    }else{
      x.insert(make_pair(s,1));
    }
  }

  for(it=x.begin();it!=x.end();it++){
    pair<string,int> com=*it;
    if(com.second>max){
      max=com.second;
      ret.clear();
      ret.insert(com.first);
    }else if(com.second==max){
      ret.insert(com.first);
    }else{
      continue;
    }
  }
  for(that=ret.begin();that!=ret.end();that++){
    string aa;
    aa=*that;
    printf("%s\n",aa.c_str());
  }
}


Measured memory_bytes: 34560
/*
 * Shubham Jain
 */
using namespace std;
#include <bits/stdc++.h>
#define ll long long int
#define rep(i,n) for(ll i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define inf (1<<30)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000000000000
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
#define mx 0
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


int main() {
    FAST_IO
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    //cout<<s<<'\n';
    sort(t.begin(),t.end());
    //cout<<t<<'\n';
    sort(t.rbegin(),t.rend());
    //cout<<t<<'\n';
    if(s<t)
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <int,string> PIS;
typedef vector <int> vec;
#define pi 3.141592653589793
#define fori(z,n) for(int i=z;i<n;i++)
#define forii(z,n) for(int i=z;i<=n;i++)
int main() 
{ 
    string str;
    cin>>str;
    int c=0;
    for(int i=0;i<3;i++)
    {
        if(str[i]==str[i+1])
        {
            c++;
            break;
        }
    }
    if(c==0)
    {
        cout<<"Good";
    }
    else 
        cout<<"Bad";
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] h = new int[N][3];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 3; j++) {
                h[i][j] = sc.nextInt();
            }
        }

        int[][] dp = new int[N + 1][3];
        //for (int i = 0; i < N + 1; i++) {
        //    Arrays.fill(dp[i], Integer.MIN_VALUE);
        //}

        for (int i = 0; i < N; i++) {
            // j : from.
            // k : to.
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (j != k) {
                        dp[i + 1][k] = Math.max(dp[i + 1][k],  dp[i][j] + h[i][k]);
                    }
                }
            }
        }

        int max = Math.max(dp[N][0], dp[N][1]);
        max = Math.max(max, dp[N][2]);
        System.out.println(max);
    }
}


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

int main(void){
    int h, w;
    int min = 10000000;
    int sum;
    cin >> h >> w;
    vector<vector<int> > a(h,vector<int>(w));

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < h; k++){
                for(int l = 0; l < w; l++){
                    if(abs(i - k) < abs(j - l)){
                        sum += abs(i - k) * a[k][l];
                    }else{
                        sum += abs(j - l) * a[k][l];
                    }
                }
            }
            if(min > sum){
                min = sum;
            }
            sum = 0;
        }
    }

    cout << min << endl;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
ll n,a,x[55],dp[55][55][2505]={};
bool vis[55][55][2505]={};

ll rec(int i,int j,int k){
  if(i<j||k<0||j<0) return 0;
  if(vis[i][j][k]) return dp[i][j][k];
  if(i==0) return 0;
  vis[i][j][k]=1;
  dp[i][j][k]=rec(i-1,j,k)+rec(i-1,j-1,k-x[i]);
  return dp[i][j][k];
}

int main(){
  cin>>n>>a;
  Fr(i,n) cin>>x[i];
  ll ans=0;
  dp[0][0][0]=1;
  vis[0][0][0]=1;
  Fr(i,n) ans+=rec(n,i,i*a);
  cout<<ans<<endl;
}

Measured memory_bytes: 62080
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, k, a[N], cnt[N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	fw (i, 0, n) cin >> a[i];
//	fw (i, 0, n) cout << a[i] << " "; cout << "\n";
	int steps = 0;
	fw (i, 0, k) {
		fw (j, 0, n) cnt[j] = 0;
		fw (j, 0, n) {
			cnt[max(0, j - a[j])]++;
			cnt[min(n, j + a[j] + 1)]--;
		}
		int tmp = 0;
		fw (j, 0, n) {
			tmp += cnt[j];
			a[j] = tmp;
		}
		
		bool done = 1;
		fw (j, 0, n) if (a[j] != n) done = 0;
		if (done) break;
	}
	fw (i, 0, n) cout << a[i] << " ";
	return 0;
}


Measured memory_bytes: 5236
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int a;
		char n[10];
		while(~scanf("%s",n))
		{
			a=0;
			for(int i=0;i<3;i++)
			{
				for(int j=i+1;j<4;j++)
				if(n[i]==n[j])
				a+=1;
			}
			if(a==2)
			printf("Yes\n");
			else
			printf("No\n");
			
		}
}

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

long long int a, b;
long long int res;

long long int euc(long long int a, long long int b){//順不同
  if(a > b) swap(a, b);
  while(true){
    int tmp = b;
    b = a % b;
    a = tmp;
    //cout << a <<" "<< b << endl;
    if(b == 0) break;
  }
  return a;
}


int main(){
  cin >> a >> b;
  res = (a * b); 
  res /=  euc(a, b);
  cout << res << endl;
  return 0;
}

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

int N,X;
string A;

int main(){
  cin >> N >> X;
  cin >> A;
  
  if(A[X-1] == 'A'){
    A[X-1] = 'a';
    cout << A << endl;
  }else if(A[X-1] == 'B'){
    A[X-1] = 'b';
    cout << A << endl;
  }else{
    A[X-1] = 'c';
    cout << A << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
counter = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0
}
for i in range(N):
    counter[input()] += 1

for judge in ['AC', 'WA', 'TLE', 'RE']:
    print(judge + ' x ' + str(counter[judge]))

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

int main(){
	int n;
	int ans=0;
	int hi=0;
	int h;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>h;
		if(hi<h){
			ans+=h-hi;
		}
		hi=h;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect

N = int(input())
one = list(map(int, input().split()))
second = list(map(int, input().split()))
third = list(map(int, input().split()))

one.sort()
second.sort()
third.sort()

c = 0
for second_v in second:
    one_n = bisect.bisect_left(one, second_v)
    third_n = len(third) - bisect.bisect_right(third, second_v)
    c += one_n * third_n
print(c)


Measured memory_bytes: 22720
#include <stdio.h>

int main(void) {
	int a, b, c;
	for (a=1; a<=9; a++) {
		for (b=1; b<=9; b++) {
			c=a*b;
			printf("%dx%d=%d\n",a,b,c);
		}
	}
return 0;
}

Measured memory_bytes: 524
#include<stdio.h>


int main(void)
{
   
	int w,h,x,y,r;
   

	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
   

	if(0<=x-r && 0<=y-r && x+r<=w && y+r<=h)
 
 		printf("Yes\n");
  
	 else
    
		 printf("No\n");
  

	 return 0;

}



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

template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
        P p=[](E a,size_t b){return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
        update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};

int MAX=2e5+9;

signed main(){
  int n,q;
  cin>>n;
  SegmentTree<int,int> ch(MAX,
        [](int a,int b){return a+b;},
        [](int a,int b){return a+b;},
        [](int a,int b){return a+b;},
        0,0,
        [](int a,int b){return a*b;});
  ch.build(n,vector<int>(MAX,0));
  int ans=0,a[n],b[n];
  r(i,n)cin>>a[i],b[i]=a[i];
  sort(b,b+n);
  int c=1;
  map<int,int>M;
  r(i,n){
    M[b[i]]=c++;
  }
  for(int i=0;i<n;i++){
    int q=M[a[i]];
    ch.update(q-1,q,1);
    ans+=ch.query(q,MAX);
    //cout<<ch.query(q,MAX)<<endl;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 26816
#include <stdio.h>
#include <stdlib.h>

int main(){
	char key[5];
	fgets(key,5,stdin);
	int i,j;
	char f = 1;
	for(i = 0; i <= 3;i++){
		if(key[i] == key[i+1]){
			f = 0;
		}
	}
	if(f){
		printf("Good\n");
	}else{
		printf("Bad\n");
	}
	return 0;
}

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

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

  vector<vector<int>> x(N, vector<int>(D));
  rep(i, N) {
    rep(j, D) {
      cin >> x[i][j];
    }
  }

  int ans = 0;
  rep(i, N - 1) {
    for(int j = i + 1; j < N; ++j) {
      int d = 0;
      rep(k, D) {
        d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      double dist = sqrt(d);
      if (floor(dist) == dist) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define REP(i, a, b) for(int i = a; i < b; i++)
#define PER(i, a, b) for(int i = b - 1; i >= a; i--)

const int maxn = 55;

char s[maxn], S[maxn], T[maxn], ans[maxn];

int main() {
	scanf("%s\n%s", s, T);
	int n = strlen(s), m = strlen(T);
	REP(i, 0, n) ans[i] = 'z';

	bool find = false;
	REP(i, 0, n - m + 1) {
		strcpy(S, s);
		bool ok = true;
		REP(j, 0, m) {
			if(S[i+j] != '?' && S[i+j] != T[j]) {
				ok = false;
				break;
			}
			if(S[i+j] == '?') S[i+j] = T[j];
		}
		if(!ok) continue;
		find = true;
		REP(i, 0, n) if(S[i] == '?') S[i] = 'a';
		if(strcmp(S, ans) < 0) strcpy(ans, S);
	}

	if(find) printf("%s\n", ans);
	else printf("UNRESTORABLE\n");

	return 0;
}


Measured memory_bytes: 128
s = list(input())

if 5 <= len(s) <= 9:
    if s[0] != 'A':
        s.insert(0, 'A')
    if s[4] != 'A':
        s.insert(4, 'A')
    if s[6] != 'A':
        s.insert(6, 'A')
    if len(s) == 8:
        s.append('A')

    if s == ['A','K','I','H','A','B','A','R','A']:
        print('YES')
    else:
        print('NO')

else:
    print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> mp;
    ll s = 0;
    rep(i, n) {
        mp[a[i]]++;
        s += a[i];
    }
    int q;
    cin >> q;
    rep(_, q) {
        ll b, c;
        cin >> b >> c;
        ll k = mp[b];
        s -= k*b;
        s += k*c;
        mp[b] = 0;
        mp[c] += k;
        cout << s << '\n';
    }
    return 0;
}

Measured memory_bytes: 10100
n=int(input())
d={}
for k in range(2,10**6):
  while n%k<1: n//=k; d[k]=d.get(k,0)+1
a=0
for i in d.values():
  t=c=0
  while t+c<i: c+=1; t+=c
  a+=c
print(a+(n>1))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  string T = "CODEFESTIVAL2016";
  
  int ans = 0;
  for (int i = 0; i < 16; i++)
  {
    char c;
    cin >> c;
    if (c != T.at(i)) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  vector<int> a(N+1);
  
  for(int i=1; i<=N; i++){
    cin >> a.at(i);
  }
  
  int n = 1, count = 1;
  while(a.at(n)!=2){
    if(a.at(n)==-1) break;
    int temp;
    temp = n;
    n = a.at(n);
    a.at(temp) = -1;
    count++;
  }
  if(a.at(n)==-1) cout << -1 << endl;
  else cout << count << endl;
}

    
    


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf =0x3f3f3f3f;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define maxn 1000010
const int S=20;
ll gcd(ll a,ll b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}
ll qmul(ll a,ll b,ll p){
     ll d=0,t=a;
    while(b>0)
    {
        if(b&1) d=(d+t)%p;
        b=b/2;
        t=(t+t)%p;
    }
    return d;

}

ll qmod(ll a,ll b,ll p)//快速幂
{
    ll d=1,t=a;
    while(b)
    {
        if(b&1)
            d=qmul(d,t,p)%p;
        t=qmul(t,t,p)%p;
        b>>=1;
    }return d;
}
int exgcd(int a,int b,int& x,int& y)
{
	if(!b){
		x=1;y=0;
		return a;
	}
	int d=exgcd(b,a%b,y,x);
	y-=(a/b)*x;
	return d;
}

int del[105];
//int a[105];
int main(){
    
    int a,b;
    scn(a);scn(b);
    int ans=a*b;
    ptf(ans);  
    return 0;
}


Measured memory_bytes: 3720
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,k,ans=0,sum;
	cin>>a>>b>>c>>sum;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int f=0;f<=c;f++)
			{
			k=500*i+100*j+50*f;
			if(k==sum)
			{
			ans++;}
			}
	
	
	cout<<ans;
	
}

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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  string s;
  cin >> s;
  Rep(i, s.size()-8) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

ans=[[0]*w for _ in range(h)]
i=0
j=0
jugh=0


if w==1:
    for i in range(n):
        for j in range(a[i]):
            print(i+1)
    exit()



for z in range(n):
    count=0
    while count<a[z]:
       # print(i,j,z+1)
        if jugh==0:
            ans[i][j]=z+1
            j+=1
            c=0
        elif jugh==2:
            if j==0:
                jugh=0
                c=1
                ans[i][j]=z+1
                j+=1
            else:
                
                jugh=1
                c=1
                
                ans[i][j]=z+1
                j-=1
        else:
            ans[i][j]=z+1
            j-=1
            c=0

        if j==w and c==0:
            i+=1
            j-=1
            jugh=2
        if j==-1 and c==0:
            i+=1
            j+=1
            jugh=2
            
        count+=1

for i in range(h):
    for j in range(w):
        print(ans[i][j],end=" ")
    print()


Measured memory_bytes: 3920
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define OrderSetTree tree<ll,null_type/*mapped_type*/,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    //OrderSetTree ost;
    ll i,x,y,n,p,sum=0,ans=0,ans2=0;
    vector<ll>v;

    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>p;
        v.pb(p);
        sum+=p;
    }

    x=floor(sum/n);
    y=ceil(((double)sum)/n);

    for(i=0;i<n;i++)
    {
        ans+=(v[i]-x)*(v[i]-x);
        ans2+=(v[i]-y)*(v[i]-y);
    }

    cout<<min(ans,ans2);
    cout<<"\n";
    return 0;   //:D
}




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

using namespace std;
int g[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&g[i]);
    sort(g,g+n);
    int maxn=0;
    for (int i=0;i<n-1;i++)
    {
        if (abs((g[n-1]-g[i])-g[i])<abs((g[n-1]-maxn)-maxn))
            maxn=g[i];
    }
    printf("%d %d\n",g[n-1],maxn);
    return 0;
}


Measured memory_bytes: 640
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(n)]
e=0
for i in range(n):
    d=0
    for j in range(m):
        d+=a[i][j]*b[j]
    if d+c>0:
        e+=1
print(e)

Measured memory_bytes: 3060
n,m=map(int,input().split())
d=[int(input()) for _ in range(n)]
c=[int(input()) for _ in range(m)]
dp=[[0]*m for _ in range(n)]
for i in range(n):
    for j in range(i,m):
        if i==j:
            dp[i][j]=dp[i-1][j-1]+c[j]*d[i]
        else:    
            dp[i][j]=min(dp[i-1][j-1]+c[j]*d[i],dp[i][j-1])
print(min(dp[n-1][n:m]))


Measured memory_bytes: 18852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = new StringBuffer(sc.next()).reverse().toString();

		System.out.println(a.equals(b) ? "YES" : "NO");

		sc.close();

	}

}


Measured memory_bytes: 35744
# -*- coding: utf-8 -*-
num = [0,2,5,5,4,5,6,3,7,6]
#      0,1,2,3,4,5,6,7,8,9

def f(n,al):
    INF = 10**18
    dp = [-INF for _ in range(n+1)]
    dp[0] = 0

    for i in range(1,n+1):
        for a in al:
            if i-num[a]>=0:
                dp[i] = max(dp[i], dp[i-num[a]]+1)

    res = []
    al.sort(reverse=True)

    while n>0:
        for a in al:
            if n-num[a]>=0 and dp[n-num[a]]==dp[n]-1:
                res.append(str(a))
                n -= num[a]
                break

    return "".join(res)

if __name__ == '__main__':
    n,m = map(int, input().split())
    al = list(map(int, input().split()))
    print(f(n,al))

    # from random import shuffle
    # for _ in range(1000):
    #     n = 10000
    #     m = 5
    #     al = list(range(1,10))
    #     shuffle(al)
    #     al = al[:m]
    #     f(n,al)


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

string s;

int main()
{
	cin >> s;

	char base = s[0];
	int stack = 1;
	int cnt = 0;
	for (int i = 1; i < s.size(); ++i) {
		if (s[i] == base) {
			stack++;
		}
		else {
			if (stack == 0) {
				stack = 1;
				base = s[i];
			}
			else {
				cnt++;
				stack--;
			}
		}
	}

	cout << cnt * 2 << endl;

	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<set>
#include<utility>
#include<algorithm>
#include<cmath>
using namespace std;

#define fo(i,n) for (int i = 0; i < n; ++i)
#define tr(i,n) for(auto i=n.begin();i!=n.end();i++)
#define w(t) while(t--)
#define ll long long int
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fst ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define all(x) (x).begin(), (x).end()

int main()
{
	fst;
	long int a,b,c,k;
	cin>>a>>b>>c>>k;
	long int sum=0;
	if(k>=a)
	{
		sum+=a;
		k-=a;
	}
	else
	{
		sum+=k;
		k=0;
	}
	if(k>=b)
	{
		sum+=0;
		k-=b;
	}
	else
	{
		sum+=0;
		k=0;
	}

	if(k>=c)
	{
		sum-=c;
	}
	else
	{
		sum-=k;
	}

	cout<<sum;
}


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

using namespace std;

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

      int n,ans;cin>>n;
    
      ans=n%1000;
    
      if(ans!=0)
      ans=1000-ans;
    
      cout<<ans;
 
      
   
    
     
      return 0;
}

Measured memory_bytes: 3636