akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,m;cin>>n>>m;
  vpii v(n);
  rep(i,n){
    int a,b;cin>>a>>b;
    v[i]=mp(a,b);
  }
  vsort(v);
  int counter=0;
  ll ans=0;
  rep(i,n){
    rep(j,v[i].second){
      ans+=v[i].first;
      counter++;
      if(counter==m){
        cout<<ans<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
using namespace std;
int n,h,a[100020],b[100020],ma,ans;
int main()
{
    cin>>n>>h;
    for (int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    ma=a[n-1];
    sort(b,b+n);
    for (int j=n-1;j>=0;j--)
    {
        if (b[j]>ma && h>0)
        {h-=b[j]; ans++;}
    }
    if (h>0)
        ans+=(h+ma-1)/ma;
    cout<<ans<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 1272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			String t = sc.next();
			char[] sArr = s.toCharArray();
			char[] tArr = t.toCharArray();

			int result = Integer.MAX_VALUE;
			for (int i = 0; i < s.length() - t.length() + 1; i++) {
				int tmp = 0;
				for (int j = 0; j < t.length(); j++) {
					if(sArr[i + j] != tArr[j]) {
						tmp++;
					}
				}
				if (tmp < result) {
					result = tmp;
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 35764
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        s: String,
    };

    let pt = ["eraser", "erase", "dreamer", "dream"];
    println!(
        "{}",
        if pt.iter().fold(s, |s, x| s.replace(x, "")).is_empty() {
            "YES"
        } else {
            "NO"
        }
    );
}


Measured memory_bytes: 4352
import collections
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
c = collections.Counter(D)
if c[0] != 1:
    print(0)
    exit()
##print(c)
ans = 1
##print(max(D))
for i in range(1, max(D)+1):
    if c[i] == 0:
        ans = 0
        break
    ans *= c[i-1] ** c[i]
    ans = ans % mod
    ##print(ans)
print(ans)

Measured memory_bytes: 19936
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] a = getIntArr(in, n);
		double r = solve(n, a);
		System.out.println(r);
		in.close();
	}

	private static double solve(int m, int[] a) {
		int[] n = new int[3];
		for (int i = 0; i < a.length; i++) {
			n[a[i] - 1]++;
		}
		double[][][] dp = new double[m + 1][m + 1][m + 1];
		for (int i = 0; i <= m; i++) {
			for (int j = 0; j <= m; j++) {
				for (int k = 0; k <= m; k++) {
					int total = i + j + k;
					if (total == 0 || total > m) {
						continue;
					}
					if (i > 0) {
						dp[i][j][k] += 1.0 * dp[i - 1][j + 1][k] * i / total;
					}
					if (j > 0) {
						dp[i][j][k] += 1.0 * dp[i][j - 1][k + 1] * j / total;
					}
					if (k > 0) {
						dp[i][j][k] += 1.0 * dp[i][j][k - 1] * k / total;
					}
					dp[i][j][k] += 1.0 * m / total;
				}
			}
		}
		return dp[n[2]][n[1]][n[0]];
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


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

string S;
int main (){
    cin >> S;
    int flag = 1;
    int cnt = 0;
    if( S[0] != 'A' ) flag = 0;
    for(int i=1, l = S.length(); i<l; i++){
        if( S[i] == 'C') {
            if( i >= 2 && i<= l - 2) cnt++;
        } else if( S[i] - 0 < 97) flag = 0;
    }
    if( cnt != 1) flag = 0;
    cout << ( flag ? "AC": "WA") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

N = int(input())

jpy = 0
btc = 0

for i in range(N):
    x, u = input().split()

    if u == "JPY":
        jpy += int(x)
    else:
        btc += float(x)

print(jpy + btc * 380000)


Measured memory_bytes: 3060
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> [Int] -> Int
solve n as = 2 * s - abs(e2-e1)
  where
    (e1, e2) = findMiddle n (sort as)
    s = sum [abs(a - e1)| a <- as]

findMiddle n bs = sub (divMod n 2)
  where
    sub (k,0) = let x:y:_ = drop (k-1) bs
                in (x, y)
    sub (k,1) = let x:y:z:_ = drop (k-1) bs
                in if y-x < z-y then (y, x) else (y, z)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      as = map (\[x] -> readBInt x) remLines1
  in solve n as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


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

int main()
{
  string n;

  cin >> n;

  rep(i,3){
    if(n.at(i) == '1')
      n.at(i) = '9';
    else{
      n.at(i) = '1';
    }
  }

  cout << n;
}


Measured memory_bytes: 3568
#include<complex>
#include<stdio.h>
#include<cmath>
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){
	typedef double D;
	int n;D d,e,f,g,h,i;
	for(scanf("%d",&n);n--;){
		scanf("%lf%lf%lf%lf%lf%lf",&d,&g,&e,&h,&f,&i);
		std::complex<D> a(d,g),b(e,h),c(f,i);
		D A=abs(b-c),B=abs(c-a),C=abs(a-b),
		s=sin(2*F(A,B,C)),t=sin(2*F(B,C,A)),u=sin(2*F(C,A,B)),v=s+t+u;
		printf("%.3f %.3f %.3f\n",(d*s+e*t+f*u)/v,(g*s+h*t+i*u)/v,A/sin(F(A,B,C))/2);
	}
}

Measured memory_bytes: 0
while True:
    m,f,r=map(int,input().split())
    if m==-1 or f==-1:
        if m==-1 and f==-1 and r==-1:
          break
        else:
          print('F')  
    elif m+f>=80:
        print('A')
    elif m+f>=65:
        print('B')
    elif m+f>=50:
        print('C')
    elif m+f>=30 and r>=50:
        print('C')
    elif m+f>=30:
        print('D')
    else:
        print('F')
    


Measured memory_bytes: 5596
#include <iostream>

using namespace std;

int n;
int a[500005];
int count = 0;

void merge(int l, int mid, int r) {
    int n1 = mid - l;
    int n2 = r - mid;
    int *lf = new int[n1];
    int *rt = new int[n2];
    for (int i = 0; i < n1; i++) {
        lf[i] = a[l + i];
    }
    for (int i = 0; i < n2; i++) {
        rt[i] = a[mid + i];
    }
    int i = 0;
    int j = 0;
    for (int k = l; k < r; k++) {
        count++;
        if ((lf[i] <= rt[j] && i != n1) || (j == n2)) {
            a[k] = lf[i];
            i++;
        } else {
            a[k] = rt[j];
            j++;
        }
    }
    delete(lf);
    delete(rt);
}

void mergeSort(int l, int r) {
    if (l + 1 < r) {
        int mid = (l + r) / 2;
        mergeSort(l, mid);
        mergeSort(mid, r);
        merge(l, mid, r);
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    mergeSort(0, n);
    for (int i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 6888
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
T mypow(T a, T p) {
	T ret = 1;
	while( p ) {
		if( p & 1 ) {
			ret *= a;
		}
		
		a *= a;
		p >>= 1;
	}
	
	return ret;
}

int main(void) {
	ll h;
	cin >> h;
	
	ll cnt = 0LL;
	ll tmp = h;
	while( tmp ) {
		tmp /= 2LL;
		cnt++;
	}
	
	ll ans = 0LL;
	for(ll i = 0; i < cnt; ++i) {
		ans += mypow(2LL, i);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
  bool judge = true;
  int x, y;
  int n	= 0;
  while (judge) {
    cin >> x >> y;
    if ((x == 0) && (y == 0)) {
      judge =	false;
    } else {
      if (x > y) {
	cout <<	y << " " << x << endl;
      }	else {
	cout <<	x << " " << y << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,m,a[1000]={};
  cin>>n;
  vector<pair<int,int> > pp(n+1);
  for(int i=n;i>=0;i--){
    m = i;
     while(m%2==0 && m>0){
       m = m / 2;
       a[i]++;
     }
     pp[i] = make_pair(a[i],i);
  }
  sort(pp.begin(),pp.end());
  cout<<pp[n].second<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    int A;
    vector<int> P(N+1);
    rep(i,Q){
        cin >> A;
        P[A]++;
    }
    for(int i=1;i<=N;i++){
        if(K-Q+P[i]<=0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    unsigned long long a[5000]={0},c=0,p,o,u;
    rep(i,n){
      cin>>p>>o>>u;
      a[p]+=o*u;
      if(a[p]>=1000000){cout<<p<<endl;c++;}
    }
    if(!c)cout<<"NA"<<endl;
  }
}

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


int main() {
    int A,B,M;
    cin>>A>>B>>M;
    vector<int>a(A);
    vector<int>b(B);
      rep(i,A)cin>>a[i];
    rep(i,B)cin>>b[i];
    vector<int>aa=a;
    sort(aa.begin(),aa.end());
    vector<int>bb=b;
    sort(bb.begin(),bb.end());
    int p=aa[0]+bb[0];
      ;
    vector<pair<pair<int,int>,int>>data(M);

    int mn =1000000;
    rep(i,M){
        cin>>data[i].first.first>>data[i].first.second>>data[i].second;
        int q=a[data[i].first.first-1]+b[data[i].first.second-1]-data[i].second;
        mn =min(mn,min(p,q));
    }
    cout<<mn<<endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <climits>

int main()
{
  int n, x;
  int m[120];
  int ans = 0;

  std::cin >> n >> x;

  for (int i = 0; i < n; ++i) {
    std::cin >> m[i];
    ans += m[i];
  }

  int min = INT_MAX;
  for (int i = 0; i < n; ++i) {
    if (min > m[i]) {
      min = m[i];
    }
  }
  int ansx = n;
  for (; ans < x;) {
    ans += min;
    if (ans <= x) {
      ansx++;
    }
  }

  std::cout << ansx << std::endl;

  return 0;
}


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

int main(){
	int n , m , x;
	cin >> n >> m >> x;
	vector<vector<int> > a(n , vector<int> (m));
	vector<int> c(n);


	for(int i = 0 ; i < n ; i++){
		cin >> c[i];

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

	int all = 1 << n;
	int ans = INT_MAX;

	for(int i = 0 ; i < all ; i++){
		vector<int> level(m , 0);
		int price = 0;

		for(int j = 0 ; j < n ; j++){
			if((i >> j) & 1){
				price += c[j];
				for(int k = 0 ; k < m ; k++){
					level[k] += a[j][k];
				}
			}
		}

		bool can = true;
		for(int j = 0 ; j < m ; j++){
			if (level[j] < x){
				can = false;
			}
		}

		if (can){
			ans = min(ans , price);
		}
	}

	if(ans == INT_MAX){
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}


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


int main() {
    int n;
    cin >>n;
    vector<int> a(n);
    
    for(int x = 1;x <= sqrt(n);x++){
        for(int y = 1;y <= sqrt(n);y++){
            for(int z = 1;z <= sqrt(n);z++){
                int value = x*x + y*y + z*z + z*x + z*y + x*y;
                if(value <= n) a[value]++;
            }
        }
    }

    for(int i = 1;i<=n;i++) cout << a[i] << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int board[510][510];

int main(){
  int h, w; cin >> h >> w;
  rep(i,h)rep(j,w){
    int tmp; cin >> tmp;
    board[i][j] = tmp;
  }
  
  vector<tuple<int,int,int,int>> v;
  rep(i,h)rep(j,w){
    if(i==h-1&&j==w-1){//最終地点だったら何もしない
    }else if(j==w-1){//もし現在地が右端だったら
      if(board[i][j]%2){//奇数だったら
        board[i][j]--; board[i+1][j]++;//下に移動させる
        //vに格納(1-indexedに注意)
        v.push_back(make_tuple(i+1,j+1,i+2,j+1));
      }
    }else{//それ以外
      if(board[i][j]%2){//奇数だったら
        board[i][j]--; board[i][j+1]++;//右に移動させる
        //vに格納(1-indexedに注意)
        v.push_back(make_tuple(i+1,j+1,i+1,j+2));
      }
    }
  }
  
  //出力
  printf("%d\n",v.size());
  for(auto v1:v){
    int x1,y1,x2,y2;
    tie(x1,y1,x2,y2) = v1;
    printf("%d %d %d %d\n",x1,y1,x2,y2);
  }
  return 0;
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    vector <int> x(n);
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    int dist = 0;
    for(int i=0;i<n;i++)
    {
        int dist_part= min(x[i],abs(k-x[i]));
        dist+=dist_part*2;
    }
    cout<<dist<<endl;
    return 0;
}

Measured memory_bytes: 256
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define debug cout << "here!"
#define pii pair<int , int>
#define pdd pair<double , double>
#define F first
#define S second
const int maxn = 1e5 * 5 + 10 , inf = 1e9 , pi = 3.14159265;
bool check(int x){
    for (int i = 2; i <= sqrt(x); i ++){
        if (x % i == 0){
            int j = 2;
            while (pow(i , j) < x){
            //    cout << i << " " << endl;
                j ++;
            }
            if (pow(i , j) == x){
                return 1;
            }
        }
      //  cout << "salam" << endl;
    }
    return 0;
}
void solve(){
    
}
void in(){
    int x; cin >> x; int ans = 1;
    for (int i = 1; i <= x; i ++){
        if (check(i) == 1){
            ans = i;
        }
        //cout << ans << endl;
    }
    cout << ans;
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    in();
    return 0;
}


Measured memory_bytes: 4076
#include <stdio.h>
#include <string.h>

char X[1001];
char Y[1001];



//int i,j;

/*void print(int k){
    
    printf("%d\n",k);
    
}*/



/*int lcs(int i,int j){
    int len1,len2;
    
  //  i=strlen(X)-1;
  //  j=strlen(Y)-1;
    
    if(i<0||j<0)return 0;
    
    if(L[i][j] !=-1)return(L[i][j]);
    
    if(X[i]==Y[j]){
        L[i][j]=lcs(i-1,j-1)+1;
        return L[i][j];
    }else{
        len1=lcs(i-1,j);
        len2=lcs(i,j-1);
        if(len1>=len2)L[i][j]=len1;
         else  L[i][j]=len2;
        return L[i][j];
    }

    
}*/


void lcs(int m,int n){
    int i,j;
    int L[1001][1001];
    
    for(i=0;i<=m;i++){
        for(j=0;j<=n;j++){
            L[i][j]=0;
        }
    }
    
    
    
    
    for(i=1;i<=m;i++){
        for(j=1;j<=n;j++){
            if(X[i-1]==Y[j-1]){
                L[i][j]=L[i-1][j-1]+1;
            }
            else if(L[i-1][j]>=L[i][j-1])L[i][j]=L[i-1][j];
            else L[i][j]=L[i][j-1];
        }
    }
    
    printf("%d\n",L[m][n]);
}



int main(void){
    int s,p,set;
    int i,j;
    
    
  /*  for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            L[i][j]=0;
        }
    }
    */
    
    
    scanf("%d",&set);
    
    for(i=0;i<set;i++){
    scanf("%s",X);
    scanf("%s",Y);
    lcs(strlen(X),strlen(Y));
    //printf("%d",L[i][j]);
       // printf("%d\n",lcs(/*m-1,n-1*/));
       
    }
    
    return 0;
    
    
}

Measured memory_bytes: 4512
h,w=map(int,input().split())
m=h*w
d=lambda a,b,c:max(abs(a-b),abs(b-c),abs(a-c))
def c(h,w):
 a=m
 for i in range(1,h):
  l=i*w
  y=(h-i)//2*w
  t=(h-i)*(w//2)
  a=min(a,d(l,y,m-l-y),d(l,t,m-l-t))
 return a
print(min(c(h,w),c(w,h)))

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


vector<vector<ll>>w(110000);
priority_queue<ll> que;

int main() {
    ll n, m, ans = 0; cin >> n >> m;
    for(ll i = ll(0); i < ll(n); i++){
        ll a, b;
        cin >> a >> b;
        w[a].push_back(b);
    }
    for(ll i = ll(1); i < ll(m+1); i++){
        for(ll j = ll(0); j < ll(w[i].size()); j++){
            if(w[i][j] != 0) que.push(w[i][j]);
        }
        if(que.size() != 0){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5888
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>

typedef long long ll;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,a,b) for(int i=b-1;i>=a;i--)

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
int main() {
  int n;
  stringstream ss;
  cin >> n;
  if(n%2==0) cout << n << endl;
  else cout << n*2 << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const int INF=100000000LL;
int main() {
	int n;
	double t[102],v[102];
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>t[i];
		t[i]+=t[i-1];
	}
	for(int i=1;i<=n;++i)cin>>v[i];
	t[n+1]=t[n];
	t[n+2]=t[n];
	v[n+1]=0;
	double a[40000];
	a[0]=0;
	double ans=0;
	for(int i=1;i<=t[n+1]*2;++i){
		double k=(double)i/2;
		a[i]=min(k,t[n+1]-k);
		for(int j=1;j<=n;++j){
			double l=t[j-1],r=t[j];
			if(k<l)a[i]=min(a[i],v[j]+(l-k));
			if(k>r)a[i]=min(a[i],v[j]+(k-r));
			if(k>=l&&k<=r)a[i]=min(a[i],v[j]);

		}
//		cout<<i<<" "<<a[i]<<endl;
		ans+=(a[i-1]+a[i])/4;
	}
	printf("%f\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int i, n, a, b, c;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &a, &b, &c);
		a *= a; b *= b; c *= c;
		if (a + b == c || a + c == b || b + c == a) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string k,s,t;
	cin>>s>>t;
	int n;
	n=s.size();
	int x=n,i,j;
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(s.substr(i)+s.substr(0,i)==t)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 3568
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn main() {
    let n = read::<usize>();
    let mut cnt_map = HashMap::<usize, usize>::new();
    for _i in 0..n {
        let v = read::<usize>();
        let entry = cnt_map.entry(v).or_insert(0);
        *entry += 1;
    }
    let mut cnts = vec![];
    for (_v, &cnt) in cnt_map.iter() {
        cnts.push(cnt);
    }
    cnts.sort();
    let mut ans = 0;
    let mut anss = vec![0; n];
    let mut index = 0;
    let mut rest = 0;
    for i in 0..cnts.len() {
        let w = cnts.len() - i;
        while ans < cnts[i] {
            ans += 1;
        }
        loop {
            while index < cnts.len() && cnts[index] == ans {
                index += 1;
            }
            let lw = index - i;
            assert!(lw > 0);
            if rest >= lw {
                ans += 1;
                rest -= lw;
            } else {
                break;
            }
        }
        anss[w - 1] = ans;
        rest += ans;
    }
    for i in 0..n {
        println!("{}", anss[i]);
    }
}


Measured memory_bytes: 15092
class Dice(object):

    def __init__(self, num):
        self.num = num

    def rotate_S(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rotate_N(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rotate_W(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]

    def rotate_E(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rotate_M(self):
        self.num = [self.num[0], self.num[2], self.num[4], self.num[1], self.num[3], self.num[5]]

dice1 = Dice(map(int, raw_input().split()))
dice2 = Dice(map(int, raw_input().split()))
yes_flg = False
if len(set(dice1.num) - set(dice2.num)) != 0:
    print 'No'
else:
    num = []
    for i in range(6):
        if dice1.num[0] == dice2.num[i]:
            num.append(i)
    for j in num:
        if j == 1:
            dice2.rotate_N()
        elif j == 2:
            dice2.rotate_W()
        elif j == 3:
            dice2.rotate_E()
        elif j == 4:
            dice2.rotate_S()
        elif j == 5:
            dice2.rotate_S()
            dice2.rotate_S()

        if dice1.num[5] == dice2.num[5]:
            for i in range(4):
                if (dice1.num[1] == dice2.num[1]) & (dice1.num[2] == dice2.num[2]) & (dice1.num[3] == dice2.num[3]):
                    yes_flg = True
                    break
                dice1.rotate_M()
            if yes_flg:
                break
    if yes_flg:
        print 'Yes'
    else:
        print 'No'

Measured memory_bytes: 6556
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    else
        return gcd(b % a, a);
 }

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

ll fact(ll n){
    if(n==0)
        return 1;
    else
        return n*fact(n-1);
}

void solve(){

    ll N,M;
    cin>>N>>M;
    ll A[N][M],i,j;
    char c;
    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            cin>>c;
            if(c=='.')
                A[i][j] = 0;
            else
                A[i][j] = -1;
        }
    }

    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            if(A[i][j]%mod==-1)
                continue;
            if(i==0 && j==0){
                A[i][j] = 1;
            }
            else if(i==0){
                A[i][j] = A[i][j-1]%mod;
            }
            else if(j==0){
                A[i][j] = A[i-1][j]%mod;
            }
            else{
                if(A[i-1][j]%mod==-1)
                    A[i][j] = A[i][j-1]%mod;
                else if(A[i][j-1]%mod==-1)
                    A[i][j] = A[i-1][j]%mod;
                else
                    A[i][j] = (A[i-1][j]%mod + A[i][j-1]%mod)%mod;
            }
        }
    }
    /*for(i=0;i<N;i++){
        for(j=0;j<M;j++)
            cout<<A[i][j]<<" ";
        cout<<"\n";
    }*/
    ll k = A[N-1][M-1]%mod;
    if(k<0)
        cout<<0;
    else
        cout<<k%mod;

}

int main(){
    //freopen("D:\\codes\\1input.txt","r",stdin);
    //freopen("D:\\codes\\1output.txt","w",stdout);
    ll T=1;
    //cin>>T;
    for(ll t=1;t<=T;t++){

        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 11364
n = int(input())
list01 = input().split()
x = 0
for i in list01:
    if int(i) % 2 != 0:
        pass
    elif int(i) % 3 == 0:
        pass
    elif int(i) % 5 == 0:
        pass
    else:
        x += 1
        break

if x == 1:
    print('DENIED')
else:
    print('APPROVED')

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    if(n == 1) cout << "Hello World" << endl;
    else{
        int a, b; cin>>a>>b;
        cout << a+b << endl;
    }
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int buf = 0;
            for(int i = 0; i < s.Length; i++)
            {
                if(s[i] == '+')
                {
                    buf++;
                }
                else
                {
                    buf--;
                }
            }
            Console.WriteLine(buf);
        }
    }
}

Measured memory_bytes: 13140
s = input()
t = input()
n = len(s)
m = len(t)

# dp[i][j]:s[i],t[j]までで、最長の部分列の長さ
dp = [[0]*(m+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,m+1):
        # s[i]とt[j]が等しいとき
        # dp[i][j]=s[i-1],t[j-1]までの最長部分列にs[i],t[j]を加えればよい
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]  + 1
        # s[i]とt[j]が等しくないとき
        # dp[i][j]=(s[i-1],t[j]までの最長部分列)or(s[i],t[j-1]までの最長部分列)
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

res = ''
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        res = s[n] + res
print(res)

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

int main() {
	
	int m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1 != m2) cout << 1 << endl;
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[10];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    scanf("%s",ss+1);int len=strlen(ss+1);
    bool bk=true;
    for(int i=2;i<=len;i++)if(ss[i]==ss[i-1]){bk=false;break;}
    if(bk==true)puts("Good");
    else puts("Bad");
   	return 0;
}

Measured memory_bytes: 128
N = int(input())
H = list(map(int, input().split()))
f = True
now = H[0]
for i in range(0,N - 1):
  #print(i, now)
  #次が1以上小さい
  if now - H[i + 1] >= 1:
    f = not f
    break
  #次の方が1以上大きい
  elif H[i + 1] - now >= 1:
    now = H[i + 1] - 1

if f:
  print("Yes")
else:
  print("No")

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

int main() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  rep(i,d) cin >> p.at(i) >> c.at(i);
  
  int ans = 1e9;
  rep(bit,1<<d) {
    int sum = 0, num = 0, rest = 0;
    rep(i,d) {
      if (bit & (1 << i)) {
        sum += 100 * (i+1) * p.at(i) + c.at(i);
        num += p.at(i);
      }
      else rest = i;
    }
    
    if (sum < g) {
      int tmp = 100 * (rest+1);
      int need = (g - sum + tmp - 1) / tmp;
      if (need >= p.at(rest)) continue;
      num += need;
    }
    
    ans = min(ans, num);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, s, g) for(int i = s; i < g; i++)
#define FORR(i, s, g) for(int i = s - 1; i >= g; i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define DMP(a) std::cerr << #a << " = " << std::a << "\n"
using namespace std;
typedef long long ll;
struct aaa{
    aaa(){
        std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout<<std::fixed<<std::setprecision(20);
    };
}aaaaaaa;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a >= 13 ? b : a >= 6 ? b / 2 : 0) << "\n";

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

def paint():
	while len(stack) > 0:
		node = stack.pop()
		for n in adj_list[node]:
			if color_list[n[0]] != "-1":
				continue

			stack.append(n[0])

			if n[1] % 2 == 0:
				color_list[n[0]] = color_list[node]
			else:
				if color_list[node] == "0":
					color_list[n[0]] = "1"
				else:
					color_list[n[0]] = "0"

N = int(input())
adj_list = [[] for i in range(N)]

for i in range(N - 1):
	elm = [int(x) for x in input().split()]
	adj_list[elm[0] - 1].append([elm[1] - 1, elm[2]])
	adj_list[elm[1] - 1].append([elm[0] - 1, elm[2]])

color_list = ["-1"] * N
color_list[0] = "0"

import sys
sys.setrecursionlimit(10000)

stack = [0]
paint()

for c in color_list:
	print(c)

Measured memory_bytes: 44972
import java.util.Scanner;
class Main{
  public static void main(String[] args){

      Scanner sc = new Scanner(System.in);

      int ans = 0;

      String[] sa;
      String inputa = sc.next();
      sa = inputa.split("");
      int lena = sa.length;

      String[] sb;
      String inputb = sc.next();
      sb = inputb.split("");
      int lenb = sb.length;

      int[][] DP;
      DP = new int[lena+1][lenb+1];

      for(int i=0; i<=lena; i++){
        for(int j=0; j<=lenb; j++){
          DP[i][j] = 0;
        }
      }

      for(int i=0; i <= lena; i++){
          DP[i][0] = i;
      }

      for(int i=0; i <= lenb; i++){
         DP[0][i] = i;
      }

      for(int i=1; i<=lena; i++){
        for(int j=1; j<=lenb; j++){
          if(sb[j-1].equals(sa[i-1])){
              DP[i][j] = DP[i-1][j-1];
          }
          else{
              int m = Math.min(DP[i][j-1],DP[i-1][j]);
              DP[i][j] = Math.min(m,DP[i-1][j-1])+1;
          }
        }
      }
      ans = DP[lena][lenb];

      System.out.println(ans);
    }
}



Measured memory_bytes: 34156
#include <stdio.h>
int main (void)
{
	int sum[1000];
	int i;
	int j;
	int k=0;
	char array[1000];
	char n[10]={'0','1','2','3','4','5','6','7','8','9'};
		for(i=0;i<1000;i++){
	sum[i]=0;
	}
	while(1){
		for(i=0;i<1000;i++){
	array[i]='0';
	}
	scanf("%s",array);
		if(array[0]=='0'){
			break;
		}
	for(i=0;i<1000;i++){
		for(j=0;j<10;j++){
			if(n[j]==array[i]){
				sum[k]+=j;
			}
		}
	}
	k++;
	}
	
	for(i=0;i<=k;i++){
		if(sum[i]==0){
			break;
		}
	printf("%d\n",sum[i]);
	}
	return 0;
        } 

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


void solve(long long N){
    cout << (N % 2 == 0 ? N / 2 : (N / 2 + 1)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

int main(){
    int a[300], n, x=-1;
    cin >> n;
    for (int i = 0; i != 1;){

        for (int j = 0; j < n;j++){
            if(x==-1){
                cin >> a[j];
                }
            if(a[j]%2==1){
                i = 1;
                break;
            }
            a[j] = a[j] / 2;
        }
        x++;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

struct UnionFind{
	vector<int> data;
	
	UnionFind(int sz){
		data.assign(sz,-1);
	}
	
	bool unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return(false);
		if(data[x]>data[y]) swap(x,y);
		data[x]+=data[y];
		data[y]=x;
		return(true);
	}
	
	int find(int k){
		if(data[k]<0) return(k);
		return(data[k]=find(data[k]));
	}
	
	int size(int k){
		return(-data[find(k)]);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;cin >> n >> m;
	vector<int> a(m),b(m);
	rep(i,m){
		cin >> a.at(i) >> b.at(i);
		a.at(i)--;b.at(i)--;
	}
	vector<ll> ans(m);
	ans.at(m-1)=n*(n-1)/2;
	UnionFind uf=UnionFind(n);
	for(int i=m-1;i>0;--i){
		ll x=uf.size(a.at(i)),y=uf.size(b.at(i));
		if(uf.unite(a.at(i),b.at(i))){
			ll z=uf.size(a.at(i));
			ans.at(i-1)=ans.at(i)+x*(x-1)/2+y*(y-1)/2-z*(z-1)/2;
		}
		else{
			ans.at(i-1)=ans.at(i);
		}
	}
	rep(i,m) cout << ans.at(i) << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] != t[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  string A, B, C;
  cin >> A >> B >> C;
  int a=A.size(), b=B.size(), c=C.size();
  if(A.at(a-1)==B.at(0) && B.at(b-1)==C.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

typedef long long ll;

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector< std::pair< ll , ll > > vp(M, std::make_pair< ll, ll >(0, 0));

  std::vector< ll > v_cnt(N, 0);

  for (int i = 0; i < M; i++) {
    std::cin >> vp[i].first >> vp[i].second;
  }

  std::vector< std::pair< ll, ll > >::iterator it;
  for (it = vp.begin(); it != vp.end(); it++) {
    v_cnt[it->first  - 1]++;
    v_cnt[it->second - 1]++;
  }

  std::vector< ll >::iterator itc;
  for (itc = v_cnt.begin(); itc != v_cnt.end(); itc++) {
    std::cout << *itc << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int s=sc.nextInt();
			if(n==0&&s==0){
				break;
			}
			System.out.println(sum(n,s,0,0));
		}
	}
	static int sum(int n,int s,int i,int sum){
		if(n==0){
			return s==sum?1:0;
		}else{
			int count=0;
			for(;i<10;i++){
				count+=sum(n-1,s,i+1,sum+i);
			}
			return count;
		}
	}
}

Measured memory_bytes: 16464
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	int cnt = 0;
	while (a >= b) {
		b *= 2;
		cnt++;
	}

	while (c <= b) {
		c *= 2;
		cnt++;
	}

	if(cnt<=k){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	vector<Int> num(K);
	for (Int i = 1; i <= N; i++) {
		num[i % K]++;
	}


	Int ans = 0;
	for (Int a = 0; a < K; a++) {
		Int b = (K - a) % K;
		Int c = (K - a) % K;
		if ((b + c) % K)continue;
		ans += num[a] * num[b] * num[c];
	}

	cout << ans << endl;

}

Measured memory_bytes: 1792
N, K = list(map(int, input().split()))

aa = []
for _ in range(N):
    a = int(input())
    aa.append(a - K)

raa = [0]
for a in aa:
    raa.append(raa[-1] + a)


class Searchable_BIT():
    def __init__(self, N):
        self.N = N
        self.node = [0] * (self.N + 1)
        self.cnt = 0

    def add(self, a):  # 要素 x を追加
        x = a
        self.cnt += 1
        while x <= self.N:
            self.node[x] += 1
            x += x & -x

    def delete(self, x):  # 要素 x を削除
        self.cnt -= 1
        while x <= self.N:
            self.node[x] -= 1
            x += x & -x

    def count(self, x):  # x以下の要素数
        tmp = 0
        while x > 0:
            tmp += self.node[x]
            x -= x & -x
        return tmp

    def get_maxval(self):
        return self.get_lower_i(self.cnt)

    def get_lower_i(self, i):  # i 番目に小さい要素を取得
        NG = -1
        OK = self.N
        while OK - NG > 1:
            mid = (OK + NG) // 2
            # print(OK,NG,self.count(mid))
            if self.count(mid) >= i:
                OK = mid
            else:
                NG = mid
        return OK


a2i = {a: i + 1 for i, a in enumerate(sorted(list(set(raa))))}
BIT = Searchable_BIT(len(a2i) + 5)

ans = 0
for i, a in enumerate(raa):
    ans += BIT.count(a2i[a])

    BIT.add(a2i[a])

print(ans)


Measured memory_bytes: 54740
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  string s; cin >>s;
  int res = 0;
  rep(i, s.size()) if (s[i] == '2') res++;
  cout <<res <<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	keys = []string{"AC", "WA", "TLE", "RE"}
	m    = make(map[string]int)
)

func main() {
	defer writer.Flush()
	readVariables()
	for _, k := range keys {
		fmt.Printf("%s x %v\n", k, m[k])
	}
}

func readVariables() {
	N := nextInt()
	for i := 0; i < N; i++ {
		key := nextStr()
		m[key]++
	}
}

/* Template */

var (
	scanner *bufio.Scanner
	writer  *bufio.Writer
)

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
	writer = bufio.NewWriterSize(os.Stdout, Max)
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 2524