akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000001
#define r(i,a,b)    for(i=a;i<b;i++)
#define ra(i,a,b)   for(i=a;i<=b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ss          set<ll int>
using namespace std;
 
#define N 1000000
#define M 100000000

struct unit {
  ll int a[N];  
};

ll fact (ll int x)
{if(x==1 || x==0)return 1;
else return x*fact(x-1);}

ll power(ll int x,ll int n)
{if(n==0)return 1;
else if(n%2 == 0)return power(x*x,n/2);
else return x*power(x*x,(n-1)/2);}

bool cmp (const pii&a,const pii&b)
{ return((a.F-a.S) > (b.F-b.S));
/*if(a.S<=b.S){if(a.S==b.S)return a.F<b.F;else return a.S<b.S;}
else return a.S<b.S;*/}


int main()
{
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
    ll i,j,k,l,m,n;
    string s1="";
    string s2="";
    cin>>s1>>s2;
    k=sz(s1),l=sz(s2);
    char c[k+1],d[l+1];
    for(i=1,j=0;j<k;i++,j++)
    c[i]=s1[j];
    for(i=1,j=0;j<l;j++,i++)
    d[i]=s2[j];
    ll lcs[k+1][l+1];
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=l;j++)
        {
            if(i==0||j==0)
            lcs[i][j]=0;
            else
            if(c[i]==d[j])
            lcs[i][j]=lcs[i-1][j-1]+1;
            else
            lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    vector<char> s;
    for(i=k;i>=0;)
    {
        for(j=l;j>=0;)
        {
            if(lcs[i][j]==lcs[i][j-1])
            j--;
            else
            if(lcs[i][j]==lcs[i-1][j])
            i--;
            else
            {
                s.pb(c[i]);
                i--;
                j--;
            }
            if(lcs[i][j]==0)
            break;
        }
        if(lcs[i][j]==0)
        break;
    }
    reverse(all(s));
    if(sz(s)!=0){
    for(i=0;i<sz(s);i++)
    cout<<s[i];}
    else
    cout<<" ";
}

Measured memory_bytes: 70656
N,K = map(int,input().split())
ab = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([a,b])
ab.sort()
while K > 0:
    for _ab in ab:
        K -= _ab[1]
        if K <= 0:
            print(_ab[0])
            break

Measured memory_bytes: 20104
use std::error::Error;
use std::io::{self, BufReader};
use std::io::prelude::*;
use std::str::{self, FromStr};

fn exec() {
    let mut sc = Scanner::new(io::stdin());
    let (h, w, n): (usize, usize, usize) = (sc.ne(), sc.ne(), sc.ne());
    let a: Vec<usize> = (0..n).map(|_| sc.ne()).collect();
    let mut v = Vec::new();
    for i in 0..n {
        for _ in 0..a[i] {
            v.push(i + 1);
        }
    }
    for i in 0..h {
        let ans = if i % 2 == 0 {
            v[i * w..(i + 1) * w].to_owned()
        } else {
            let mut tmp = v[i * w..(i + 1) * w].to_owned();
            tmp.reverse();
            tmp
        };
        for j in 0..w {
            print!("{} ", ans[j]);
        }
        println!("");
    }
}


fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
pub struct Scanner<R> {
    bufread: BufReader<R>,
    id: usize,
    buf: Vec<u8>,
}
impl<R: Read> Scanner<R> {
    pub fn new(resource: R) -> Scanner<R> {
        Scanner {
            bufread: BufReader::new(resource),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.bufread.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    pub fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.is_empty() {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert_ne!(self.buf[l], b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!(
                    "parse error, {:?}",
                    String::from_utf8(self.buf[l..r].to_owned())
                )
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    pub fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}

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

main(){

  int count;
  cin >> count;
  
  int64_t sum = 1;
  int64_t sum_bk =2;
  int64_t ans;

  if(count == 1){
    ans = 1;
  }
  if(count > 1){
    for(int i = 1; i < count;i++){
  
    sum = sum + sum_bk;
    sum_bk = sum - sum_bk;
    }
    ans = sum;
  }
  cout << ans << endl;
  
  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
using Graph = vector<vector<int>>;
using ll = long long;
const ll INF = 1000000007;
int main(){ 
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans = -1000000000000000000;
  ans = max({a * c,a * d,b * c,b * d});
  cout << ans << endl;
}


Measured memory_bytes: 3544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      StringBuilder cards = new StringBuilder();
      int sTimes = 0;
      int cuts = 0;

      while(true){

        if( (line = br.readLine()).equals("-") ) break;

        cards.append(line);
        sTimes = Integer.parseInt(br.readLine());

        for ( int i = 0; i < sTimes; i++ ) {
          cuts = Integer.parseInt(br.readLine());
          cards.append(cards.substring(0, cuts))
               .delete(0,cuts);
        }

        System.out.println(cards);

        cards.setLength(0);
      }
    }
  }
}


Measured memory_bytes: 24188
import java.util.*;
import static java.lang.Math.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		char[] chars = n.toCharArray();
		for (int i=0; i<3; i++) {
			if (chars[i] == '1') chars[i] = '9';
			else if (chars[i] == '9') chars[i] = '1';
		}
		System.out.println(new String(chars));
	}
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool is_all_even = true;
    REP(i, n) {
        int a;
        cin >> a;
        if (a % 2 == 1) is_all_even = false;
    }
    cout << (is_all_even ? "second" : "first") << ln;
    return 0;
}


Measured memory_bytes: 256
//2017-10-19
//miaomiao
//Island loops deep york
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (200000+5)

char s[N];
int lst[N], nxt[N];

int main(){
	scanf("%s", s+1);

	int n = strlen(s+1);
	For(i, 1, n) lst[i] = i-1, nxt[i] = i+1;
	nxt[n] = 0;
	
	int st = -1;
	For(i, 1, n-1) if(s[i] == 'S' && s[i+1] == 'T'){
		st = i; break;
	}
	
	int ans = n, p;
	while(st != -1){
		ans -= 2;
		if(!lst[st] && !nxt[nxt[st]]) break;

		if(lst[st]) p = lst[st], nxt[p] = nxt[nxt[st]], lst[nxt[nxt[st]]] = p;
		else p = nxt[nxt[st]], lst[p] = 0;

		while(nxt[p] && (s[p]!='S' || s[nxt[p]]!='T')) p = nxt[p];
		st = nxt[p]? p: -1;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 2048
import bisect
import sys
sys.setrecursionlimit(10**7)

def dfs(v):
 #DFSの行き(子ノードに下っていくとき)の処理
 pos=bisect.bisect_left(dp,arr[v]) #最長増加部分列で更新する場所を2分探索により求める
 changes.append((pos,dp[pos])) #更新した要素とその値を記録しておく
 dp[pos]=arr[v]
 ans[v]=bisect.bisect_left(dp,10**18) #1からvまでの最長増加部分列の長さは、最長増加部分列の10**18以外の値の個数に等しい
 for u in g[v]:
   if checked[u]==0:
     checked[u]=1
     dfs(u)
 #DFSの戻り(親ノードに上っていくとき)の処理
 pos,val=changes.pop() #頂点vで更新した最長増加部分列の値を元に戻す
 dp[pos]=val

n=int(input())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(n-1):
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
ans=[0]*(n+1)
checked=[0]*(n+1)
checked[1]=1
dp=[10**18 for _ in range(n+1)] #最長増加部分列を求めるのに、十分大きな値で初期化しておく
changes=[]
dfs(1)
for i in range(1,n+1):
 print(ans[i])

Measured memory_bytes: 374476
/*
 * N M K
 * A1 B1
 * ...
 * AM BM
 * C1 D1
 * ...
 * CK DK
*/

#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <cassert>
#include <set>
#include <functional>

using namespace std;
using Graph = vector< vector< int > >;
using IntSet = set< int >;

vector<bool> seen;

void dfs(const Graph &g, int i, set<int> &s) {
  seen[i] = true;
  s.insert(i);

  for (auto next_v : g[i]) {
    if (seen[next_v]) continue;

    dfs(g, next_v, s);
  }
}

int main() {
  long long N, M, K;
  cin >> N >> M >> K;

  Graph friends(N);
  Graph notfriends(N);

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;

    friends.at(a - 1).push_back(b - 1);
    friends.at(b - 1).push_back(a - 1);
  }

  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;

    notfriends.at(a - 1).push_back(b - 1);
    notfriends.at(b - 1).push_back(a - 1);
  }

  seen.assign(N, false);
  vector<int> answer(N);

  for (int i = 0; i < N; i++) {
    if (seen[i]) {
      continue;
    }

    set<int> s;
    dfs(friends, i, s);

    for (int j : s) {
      int count = 0;
      for (int notfriend : notfriends.at(j)) {
        if (s.count(notfriend) != 0) {
          count++;
        }
      }
      answer.at(j) = s.size() - friends.at(j).size() - count - 1;
    }
  }


  for (int i = 0; i < N; i++) {
    cout << (i == 0 ? "" : " ");
    cout << answer.at(i);
  }
}


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

typedef struct {
    int row;
    int col;
    vector<vector<long>> val;
} matrix;

void init_matrix(matrix &mat, int nrow, int ncol);
void read_matrix(matrix &mat);
void matrix_mult(const matrix &mat_a, const matrix &mat_b, matrix &mat_c);
void print_matrix(const matrix &mat);

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    matrix a, b, c;

    init_matrix(a, n, m);
    init_matrix(b, m, l);
    init_matrix(c, n, l);

    read_matrix(a);
    read_matrix(b);
    matrix_mult(a, b, c);
    print_matrix(c);
}


void init_matrix(matrix &mat, int nrow, int ncol){
    mat.row = nrow;
    mat.col = ncol;
    mat.val.resize(nrow);
    for(auto &vec: mat.val){
        vec.resize(ncol, 0);
    }
}

void read_matrix(matrix &mat){
    for(int row=0; row!=mat.row; ++row){
        for(int col=0; col!=mat.col; ++col){
            cin >> mat.val[row][col];
        }
    }
}

void matrix_mult(const matrix &a, const matrix &b, matrix &c){
    auto n = a.row;
    auto m = a.col;
    auto l = b.col;
    for(int col=0; col!=n; ++col){
        for(int row=0; row!=l; ++row){
            for(int i=0; i!=m; ++i){
                c.val[col][row] += a.val[col][i] *b.val[i][row];
            }
        }
    }
}

void print_matrix(const matrix &mat){
    for(const auto &row: mat.val){
        int i = 0;
        for(const auto &aij:row){
            cout << aij;
            if(++i != mat.col) cout << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 1404
using System;
using System.Collections.Generic;

public class Hello
{
    public static void Main()
    {
string[] input = Console.ReadLine().Split(' ');
int b = int.Parse(input[0]);
int c = int.Parse(input[1]);
int d = int.Parse(input[2]);

if (b == 7){
    if (c == 5){
        if (d == 5){Console.WriteLine("YES");}else {Console.WriteLine("NO");}
                ;}else {Console.WriteLine("NO");}
            }
                
else if (c == 7){
        if (b == 5){
            if (d == 5){Console.WriteLine("YES");}else {Console.WriteLine("NO");}
                ;}else {Console.WriteLine("NO");}
            }
            
else if (d == 7){
        if (c == 5){
            if (b == 5){Console.WriteLine("YES");}else {Console.WriteLine("NO");}
                ;}else {Console.WriteLine("NO");}
            }
else Console.WriteLine("NO");
    }
}


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

int main()
{
	int a, b, c;
	char d;
	int t=0, h=0;

	while (cin >> a >> d >> b >> d >> c){
		if (c*c == (a*a + b*b))
			t++;
		if (a == b)
			h++;
	}

	cout << t << endl << h << endl;
	return 0;
}

Measured memory_bytes: 1160
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		String c=s.next();
		
		int count=0;
		for(int i=2;i<n;i++)
		{if(c.charAt(i-2)=='A' && c.charAt(i-1)=='B' && c.charAt(i)=='C')
		count++;}
		System.out.println(count);
	}
}

Measured memory_bytes: 23120
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int n , m , h[100005] , a , b , ans;
    bool t[100005] = {};
    
    cin >> n >> m;
    for(int i=1 ;i<=n ;i++ ){
        cin >> h[i];
    }
    
    for(int i=0 ;i<m ;i++ ){
        cin >> a >> b;
        if(h[a] == h[b]){
            t[a] = true , t[b] = true;
        } else if(h[a] > h[b]){
            t[b] = true;
        } else {
            t[a] = true;
        }
    }
    
    ans = n;
    for(int i=1 ;i<=n ;i++ ){
        ans -= t[i];
    }
    
    cout << ans << endl;
    return(0);
}

Measured memory_bytes: 4112
# -*- coding: utf-8 -*-
import copy

# input
N = int(input())
A = list()
for _ in range(N):
    A.append(int(input()))

# solve & output
ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])


Measured memory_bytes: 14560
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<long long> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n,x=1,ans=0;
	cin >> n;
	vec(a,n);
	vec(s,n+1);
	cin >> a[0];
	s[0]= a[0];
	FOR(i,1,n){
		cin >> a[i];
		s[i] = s[i-1] + a[i];
	}
	s[n]=1e18+7;
	sort(s.begin(),s.end());
	REP(j,n){
        if(s[j]== 0){
            ans++;
        }
    }
	REP(i,n){
		if(s[i] == s[i+1]){
			x += 1;
		}
		else{
			ans = ans + x * (x-1) / 2;
			x = 1;
		}
	}
	cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main(void) {

    int N; cin >> N;
    set<string> U;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        U.insert(s);
    }

    int M; cin >> M;
    bool islocked = true;
    for (int i = 0; i < M; i++) {
        string T; cin >> T;

        if (U.find(T) != U.end()) {
            if (islocked) {
                cout << "Opened by " << T << endl;
            } else {
                cout << "Closed by " << T << endl;
            }
            islocked = !islocked;
        } else {
            cout << "Unknown " << T << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3232
import math


def combinations_with_replacement_count(n, r):
    return math.factorial(n + r - 1) // (math.factorial(n - 1) * math.factorial(r))


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
fact = {}
i = 2
while i * i <= m:
    while m % i == 0:
        m = m // i
        if i in fact:
            fact[i] += 1
        else:
            fact[i] = 1
    i += 1
if m > 1:
    fact[m] = 1
j = 2
ans = 1
for k in fact:
    ans = ans * combinations_with_replacement_count(n, fact[k])
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 114396
// abc138_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    int n = 1 << N;
    vector<int> S(n);
    REP(i, n) cin >> S[i];

    multiset<int> T(ALL(S));

    multiset<int> gen;

    auto last = prev(T.end());
    gen.insert(*last);
    T.erase(last);

    REP(i, N){
        auto tmp = gen;
        for (auto gen_it = tmp.rbegin(); gen_it != tmp.rend(); gen_it++){
            int s = *gen_it;
            auto it = T.lower_bound(s);
            if (it == T.begin()) {
                print("No");
                return 0;
            }
            it--;
            gen.insert(*it);
            T.erase(it);
        }
    }

    print("Yes");

    return 0;
}


Measured memory_bytes: 19712
N = int(input())
sp = []
sp2idx = {}
for i in range(N):
    s, p = input().split()
    sp.append([s, int(p)])
    sp2idx[(s, int(p))] = i+1

sp.sort(key=lambda x:x[1], reverse=True)
sp.sort(key=lambda x:x[0], reverse=False)

for a in sp:
    print(sp2idx[tuple(a)])

Measured memory_bytes: 3064
import math
from functools import reduce

def gcd_list(numbers):
  return reduce(math.gcd, numbers)
  
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n=int(input())
a=list(map(int, input().split(" ")))
check = [False for i in range(10 ** 6 + 1)]
pairwise = True
for i in a:
  temp = (factorization(i))
  for j, _ in temp:
    if temp == [[1, 1]]:
      continue
    if check[j] == True:
      pairwise = False
      break
    else:
      check[j] = True
  else:
    continue
  break
if pairwise:
  print("pairwise coprime")
else:
  if gcd_list(a) == 1:
    print("setwise coprime")
  else:
    print("not coprime")

Measured memory_bytes: 205484
program main
  implicit none

  integer :: n, a(100),i
  real :: s = 0.0

  read(*,*)n
  read(*,*)(a(i),i=1, n)

  do i = 1, n
    s = s + 1.d0/real(a(i))
  end do
  write(*,*)1.0/s

end program main

Measured memory_bytes: 384
a, b = map(int, input().split())

def A(n):
    ans = 1
    while(n != 1):
        ans = ans * n % 1000000007
        n -= 1
    return ans

if(a == b):
    t = A(a)
    print(t * t * 2 % 1000000007)
elif(a == b + 1 or b == a + 1):
    print(A(a) *A(b) % 1000000007)
else:
    print(0)

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

int main() {
  string s; cin >> s;
  int n = s.size();
  int ans = n;
  for (int i = 1; i < n; i++) {
    if (s[i-1] != s[i]) {
      ans = min(ans, max(i, n-i));
    }
  }
  cout << ans << endl;
}

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

int main() {
  long N, AC = 0, WA = 0, TLE = 0, RE = 0;
  cin >> N;
  vector<string> item(N);
  for (int i = 0; i < N; i++) cin >> item.at(i);
  
  for (int j = 0; j < N; j++) {
    if (item.at(j) == "AC") AC++;
    if (item.at(j) == "WA") WA++;
    if (item.at(j) == "TLE") TLE++;
    if (item.at(j) == "RE") RE++;
  }
  
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

Measured memory_bytes: 6436
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    unordered_map<ll,ll> Difficulty;
    unordered_map<ll,ll> ProblemSet;
    rep(i,n){
        ll a ;
        cin >> a;
        Difficulty[a]++;
    }
    ll m;
    cin >> m;
    rep(i,m){
        ll a;
        cin >> a;
        ProblemSet[a]++;
    }
    for(auto a : ProblemSet){
        if(Difficulty[a.first] < a.second){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 16712
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn = 1e5+7;
int main(){
	fast_io;
	int n;
	cin>>n;
	ll ans = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				int g1 = __gcd(i,j);
				int g2 = __gcd(g1,k);
				ans += g2;
			}
		}
	}
	cout<<ans;

	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3652
N, L = (int(i) for i in input().split())

if L <= 0 and 0 < L+N-1:
    print(int((N)*(2*L+N-1)/2))
elif L < 0:
    print(int(((N-1)*(2*L+N-2)/2)))
else:
    print(int((N-1)*(2*(L+1)+N-2)/2))


Measured memory_bytes: 38384
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner sc = new Scanner();

    internal static void Main(string[] args) {
        var inp = sc.ArrayInt(4);
        //var x = Math.Abs(inp[0] - inp[2]);
        //var y = Math.Abs(inp[1] - inp[3]);
        var x = inp[2] - inp[0];
        var y = inp[3] - inp[1];
        var ans = new int[4];
        ans[0] = inp[2] - y;
        ans[1] = inp[3] + x;
        ans[2] = inp[0] - y;
        ans[3] = inp[1] + x;
        WriteLine(string.Join(" ", ans));
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13268
n=int(input())
s = list(input())
ans = 0
i=0
j=n-1
while i<j:
	while i<j and s[j]!='R': j-=1
	while i<j and s[i]!='W': i+=1
	if i<j:
		ans+=1
		j-=1
		i+=1
print(ans)


Measured memory_bytes: 10776
n , k = [int(i) for i in input().split()]

l = []
for _ in range(n):
  l.append(int(input()))
  

l = sorted(l)
  

base_d = l[k-1] - l[0]

for i in range(n-k+1):
  d = l[i+k-1] - l[i]
  if base_d >= d:
    base_d = d
    
    
print(base_d)

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

int main() {
  int N; cin >> N;
  vector<tuple<string, int, int>> list(N);
  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    int p; cin >> p;
    int j = i + 1;
    p *= -1;
    list.at(i) = tie(s, p, j);
  }
  sort(list.begin(), list.end());
  for(int i = 0; i < N; i++) {
    cout << get<2>(list.at(i)) << 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);
        // 整数の入力
        int N = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        // 文字列の比較
        int res = 0;
        int i = 0;
        if(s.equals(t)) res = N;
        else {
        	for(i=1; i<=N; i++) {
        		if(s.substring(i).equals(t.substring(0, N-i)))
        			break;
        	}
    		res = N + i;
        }

        // 出力
        System.out.println(res);
        sc.close();
	}

}

Measured memory_bytes: 9684
#include<iostream>
using namespace std;
int main()
{
	int n,m,ans=0;
	cin>>n>>m;
	int a[m+1];
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		ans+=a[i];
	}
	if(ans>n)
	{
		cout<<-1;
	}
	if(ans<n||ans==n)
	{
		cout<<n-ans;
	}
	return 0;
}

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

long long N, K;
long long a[100005];

long long positivesum[100005];
long long allsum[100005];


long long maxi(long long left, long long right){
	return positivesum[right+1] - positivesum[left];
}

long long getsum(long long left, long long right){
	return allsum[right+1] - allsum[left];
}

int main(){
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}

	for(int i = 0; i < N; i++){
		allsum[i+1] = allsum[i] + a[i];
		positivesum[i+1] = positivesum[i] + max((long long)0, a[i]);
	}

	long long ans = -1 * INT_MAX;

	for(int start = 0; start <= N- K; start++){
		long long sumi = 0;
		sumi = max(sumi, getsum(start, start + K - 1));
		sumi += maxi(0, start - 1);
		sumi += maxi(start + K, N-1);
		ans = max(ans, sumi);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};


int main(){
  int n,m,q;
  cin >> n >> m >> q;
  vector<vector<int>> lr(m,vector<int>(2));
  for(int i=0;i<m;i++){
    cin >> lr.at(i).at(0) >> lr.at(i).at(1);
    lr.at(i).at(0)--;lr.at(i).at(1)--;
  }
  vector<vector<int>> pq(q,vector<int>(2));
  for(int i=0;i<q;i++){
    cin >> pq.at(i).at(0) >> pq.at(i).at(1);
    pq.at(i).at(0)--;pq.at(i).at(1)--;
  }
  vector<vector<int>> table(n,vector<int>(n,0));
  for(int i=0;i<m;i++){
    table.at(lr.at(i).at(0)).at(lr.at(i).at(1))++;
  }
  vector<vector<int>> s(n,vector<int>(n));
  s[0][0] = table[0][0];
  for(int i=1;i<n;i++){
    s[i][0] = s[i-1][0] + table[i][0];
    s[0][i] = s[0][i-1] + table[0][i];
  }
  for(int i=1;i<n;i++){
    for(int j=1;j<n;j++){
      s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + table[i][j];
    }
  }
  for(int i=0;i<q;i++){
    int pp = pq.at(i).at(0),qq = pq.at(i).at(1);
    if(pp == 0)cout << s[qq][qq] << endl;
    else{
      cout << s[qq][qq] - s[qq][pp-1] - s[pp-1][qq] + s[pp-1][pp-1] << endl;
    }
  }
}

Measured memory_bytes: 21680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,q,ans,a[100005];
int main(){
	n=read();
	for(int i=0;i<n;i++){
		ll x=read();
		a[x]++,ans+=x;
	}
	q=read();
	while(q--){
		ll x=read(),y=read();
		ans+=(y-x)*a[x];
		a[y]+=a[x],a[x]=0;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4528
#include<iostream>
#include<string>
using namespace std;
using ll = long long;

int main() {
	string s;
	ll k;
	cin >> s >> k;
	char ans = '1';
	for (int i = 0;i < k;i++) {
		if (s[i] != '1') {
			ans = s[i];
			break;
		}
	}
	cout << ans << endl;
}

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

int main() {
  int x;
  cin >> x;
  int s1 = x / 100;
  int s2 = (x - 100 * s1) / 10;
  int s3 = x - 100 * s1 - 10 * s2;
  cout << s1 + s2 + s3 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string ans = "";
    while(n > 0){
        n--;
        ans += 'a'+n%26;
        n /= 26;
    }
    reverse(all(ans));
    PRINT(ans);
}


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

int main(){
 int a,b;
 cin>>a>>b;
 int n;
 cin>>n;
 int s[n];
 int f[n];
 for(int i=0;i<n;i++){
     cin>>s[i]>>f[i];
 }
 int cnt=0;
 for(int i=0;i<n;i++){
     if(!(a>=f[i]||b<=s[i])){
         cnt++;
         break;
     }
 }
 if(cnt){
     cout<<1<<endl;
 }else{
     cout<<0<<endl;
 }
 return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列以外を出力する
    void write(){

    }
    template<typename First, typename... Rest>
    void write(First first, Rest... rest){
        cout << first << " ";
        write(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    string S;
    io.read(S);
    int a = 1;
    int b = 0;
    int sum1 = 0;
    int sum2 = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] - '0' != a) {
            sum1++;
        }
        else {
            sum2++;
        }
        swap(a, b);
    }
    io.write(min(sum1, sum2));
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int R, G, B, N, r = 0, rg, ans;
    R = read(); G = read(); B = read(); N = read();
    for (int i = 0; i<=N; i++) {
        if(i != 0) r += R;
        if (r > N) break;
        for (int j = 0; j<=N; j++) {
            if (j == 0) rg = r;
            else rg += G;
            if (rg > N) break;
            if ((N-rg)%B == 0) ans++;
        }
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      ll a[n],sum=0;
      for(int i=0;i<n;i++) cin>>a[i];
      for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
          sum+=a[i]*a[j];
        }
      }
      cout<<sum;
}

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

typedef long long ll;
const ll INF = -1000000000000;
ll n, m, x[1000], y[1000], z[1000];

ll dp[1001][1001];

ll check() {
  for (ll i = 0; i <= n; i++)
    for (ll j = 0; j <= m; j++) dp[i][j] = INF;
  ll ans = 0;
  for (ll j = 0; j <= n; j++) dp[j][0] = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      dp[i+1][j+1] = dp[i][j+1];
      if (dp[i][j] != INF && dp[i+1][j+1] < dp[i][j] + x[i] + y[i] + z[i]) dp[i+1][j+1] = dp[i][j] + x[i] + y[i] + z[i];
    }
  }
  for (ll i = 0; i <= n; i++)
    ans = max(ans, dp[i][m]);
  return ans;
}

void change(ll* p) {
  for (ll i = 0; i < n; i++) p[i] = -p[i];
}

int main() {
  scanf("%lld%lld", &n, &m);
  for (ll i = 0; i < n; i++) scanf("%lld%lld%lld", &x[i], &y[i], &z[i]);
  ll ans = 0;
  ans = max(ans, check()); // +++
  change(x);
  ans = max(ans, check()); // -++
  change(y);
  ans = max(ans, check()); // --+
  change(z);
  ans = max(ans, check()); // ---
  change(y);
  ans = max(ans, check()); // -+-
  change(x);
  ans = max(ans, check()); // ++-
  change(y);
  ans = max(ans, check()); // +--
  change(z);
  ans = max(ans, check()); // +-+
  printf("%lld\n", ans);
}


Measured memory_bytes: 8064
#include <iostream>
int main(){
	int a,b;
	for(int i=0;i<4;++i){
		std::cin>>a>>b;
		int m=0;
		if(a==1)m=6000;
		else if(a==2)m=4000;
		else if(a==3)m=3000;
		else m=2000;
		std::cout<<b*m<<std::endl;
	}
}

Measured memory_bytes: 1160
s = input()
n = len(s)
mod = 10**9+7
dp = [[0]*4 for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
  l = s[i]
  for j in range(4):
    if l == "?":
      dp[i+1][j] = (dp[i][j]*3)%mod
    else:
      dp[i+1][j] = dp[i][j] % mod
  if l == "A" or l == "?":
    dp[i+1][1] += dp[i][0] % mod
  if l == "B" or l == "?":
    dp[i+1][2] += dp[i][1] % mod
  if l == "C" or l == "?":
    dp[i+1][3] += dp[i][2] % mod
print(dp[n][3]%mod)

Measured memory_bytes: 27508
import sys

w = input()
dict = {}
keys = []
value = []
for i in range(len(w)):
  if(w[i] not in keys):
    keys.append(w[i])

for i in range(len(keys)):
  value.append(w.count(keys[i]))
  if(value[i] % 2 != 0):
    print('No')
    sys.exit()

print('Yes')


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	
	static int h;
	static int w;
	static int cnt = 0;
	static char[][] g;
	static boolean[][] v;
	static boolean wbool;
	static boolean bbool;
	
	static void dfs(int i, int j) {
		if(v[i][j]) return;
		if(g[i][j] == 'W') {
			wbool = true;
			return;
		}
		if(g[i][j] == 'B') {
			bbool = true;
			return;
		}
		if(g[i][j] != '.') return;
		v[i][j] = true;
		cnt++;
		if(i > 0) dfs(i-1, j);
		if(i < h-1) dfs(i+1, j);
		if(j > 0) dfs(i, j-1);
		if(j < w-1) dfs(i, j+1);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			w = sc.nextInt();
			h = sc.nextInt();
			if(w + h == 0) break;
			g = new char[h+1][w+1];
			v = new boolean[h+1][w+1];
			for(int i = 0; i < h; i++) {
				g[i] = sc.next().toCharArray();
			}
			
			int hcnt = 0;
			int bcnt = 0;
			for(int i = 0; i < h; i++) {
				for(int j = 0; j < w; j++) {
					if(g[i][j] == '.' && v[i][j] == false) {
						wbool =false;
						bbool = false;
						cnt = 0;
						dfs(i, j);
						if(wbool && !bbool) {
							hcnt += cnt;
						}
						if(bbool && !wbool) {
							bcnt += cnt;
						}
					}
				}
			}
			System.out.println(bcnt + " " + hcnt);
		}

	}

}



Measured memory_bytes: 36584
import itertools
h,w,f=map(int, input().split())
box=[]
cnt=0
for i in range(h):
  box.append(list(str(input())))
htarget=list(itertools.product([0,1], repeat=h))
wtarget=list(itertools.product([0,1], repeat=w))
for j in range(len(htarget)):
  boxtemp=[["0"] * w for i in range(h)]
  for k in range(len(wtarget)):
    cnttemp=0
    for p in range(h):
      for q in range(w):
        if htarget[j][p]==1 or wtarget[k][q]==1:
          boxtemp[p][q]="?"
        else:
          boxtemp[p][q]=box[p][q]
    for s in range(h):
      for t in range(w):
        if boxtemp[s][t]=="#":
          cnttemp+=1
    if cnttemp==f:
      cnt+=1
print(cnt)

Measured memory_bytes: 9256
def egcd(a, b):
    x,y, u,v = 0,1, 1,0
    while a != 0:
        q, r = b//a, b%a
        m, n = x-u*q, y-v*q
        b,a, x,y, u,v = a,r, u,v, m,n
    gcd = b
    return gcd,x,y

a,b = (int(_) for _ in input().split(" "))
gcd,x,y = egcd(a,b)

if y * a + x * b == gcd:
    tmp = x
    x = y
    y = tmp

print(x,y)


Measured memory_bytes: 5604
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  intmax_t W;
  scanf("%zu %jd", &N, &W);

  std::vector<std::vector<intmax_t>> v(4);
  intmax_t w1;
  {
    intmax_t v1;
    scanf("%jd %jd", &w1, &v1);
    v[0].push_back(v1);
  }

  for (size_t i = 1; i < N; ++i) {
    intmax_t wi, vi;
    scanf("%jd %jd", &wi, &vi);
    v[wi-w1].push_back(vi);
  }

  std::vector<std::vector<intmax_t>> vv(4);
  for (size_t i = 0; i < 4; ++i) {
    std::sort(v[i].rbegin(), v[i].rend());
    vv[i].push_back(0);
    for (size_t j = 0; j < v[i].size(); ++j)
      vv[i].push_back(vv[i][j]+v[i][j]);
  }

  intmax_t res = 0;
  for (size_t i = 0; i < vv[0].size(); ++i) {
    for (size_t j = 0; j < vv[1].size(); ++j) {
      for (size_t k = 0; k < vv[2].size(); ++k) {
        for (size_t l = 0; l < vv[3].size(); ++l) {
          intmax_t w = w1*i + (w1+1)*j + (w1+2)*k + (w1+3)*l;
          if (w > W) break;
          res = std::max(res, vv[0][i]+vv[1][j]+vv[2][k]+vv[3][l]);
        }
      }
    }
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: int, K: int):
    for i, s in enumerate(str(S)[:K]):
        if s != '1':
            return s
    return 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(S, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

int main() {
  string S;
  cin >> S;

  int index = 0;
  bool isHitachi = true;
  while (index < S.length()) {
    string str = S.substr(index, 2);
    if (str != "hi") isHitachi = false;
    index += 2;
  }

  if (isHitachi) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
        }
        Arrays.sort(p);
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i <= n - k; i++){
            ans = Math.min(p[i + k - 1] - p[i], ans);
        }
        System.out.println(ans);
    }
}

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

l = []
l.append(n)

ans = 2
while True :

    if n % 2 == 0:
        n = n / 2
    else:
        n = n * 3 + 1
    
    if n in l:
        break
    else:
        l.append(n)

    ans += 1

print(ans)

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

typedef struct node{
  int num;
  struct node *next;
  struct node *back;
}Node;

Node *nil;

void insert(int x){
  Node *newNode;
  newNode = (Node *)malloc(sizeof(Node));
  newNode->num = x;

  newNode->next = nil->next;
  newNode->back = nil;
  newNode->next->back = newNode;
  nil->next = newNode;
  if(nil->back == nil) nil->back = newNode;
}

void delete(int x){
  Node *del;
  del = nil;

  while(1){
    if(del->next->num == x) break;
    else del = del->next;

    if(del == nil) return;
  }

  del->next = del->next->next;
  del->next->back = del;
}

void deleteFirst(){
  nil->next = nil->next->next;
  nil->next->back = nil;
}

void deleteLast(){
  Node *del;
  del = nil->back;
  del->back->next = nil;
  nil->back = del->back;
}

int main(){
  int i,j,exist=0;

  char c[7];
  int x;

  nil = (Node *)malloc(sizeof(Node));

  nil->num = -1;
  nil->next = nil;
  nil->back = nil;

  int n;
  scanf("%d",&n);


  for(i=0;i<n;i++){
    //printf("%d\n",i);
    for(j=0;j<8;j++){
      if(j==0){
         scanf("%c",&c[j]);
         continue;
      }
      scanf("%c",&c[j-1]);
      // if(c[j-1]=='\0'){
      // printf("sjsjs\n");
      // c[j-1]=' ';
      // }
    }
    /*for(j=0;j<7;j++){
      printf("%c",c[j]);
    }*/
    if(c[0]=='i'){
      scanf("%d",&x);
    //  printf("%d\n",x);

      insert(x);
    }else if(c[0]=='d'){
      if(c[6]==' '){
        scanf("%d",&x);
      //  printf("%d\n",x);

        delete(x);
      }else if(c[6]=='F'){
      //  printf("first\n");
        for(j=0;j<4;j++){
          scanf("%c",&c[0]);
        }

        deleteFirst();
      }else if(c[6]=='L'){
      //  printf("Last\n");
        for(j=0;j<3;j++){
          scanf("%c",&c[0]);
        }

        deleteLast();
      }
    }
      //printf("%d\n",nil->back->num);
  }

  Node *mark;
  mark = nil;

  //printf("%d\n",mark->next->num);

  while(1){
    if(mark->next != nil){
      if(exist) printf(" ");
      printf("%d",mark->next->num);
      mark = mark->next;
      exist = 1;
    }
    else break;
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 36092
# coding: utf-8
import math

n = input()
xs = map(int, raw_input().split())

#avg = 1.0 * sum(xs) / n
#mindist = math.ceil(sum((x - avg) ** 2 for x in xs))

p = round(1.0 * sum(xs) / n)
mindist = math.ceil(sum((x - p) ** 2 for x in xs))

print int(mindist)


Measured memory_bytes: 2568
#!/usr/bin/env python3

import math
def main():
    N = int(input())
    left = 0
    right = 0
    
    if is_prime(N):
        print(N-1)
        return
    
    minimum_distance = 10 ** 12
    for i in range(1, int(N**0.5)+1):
        right = 0
        left = 0
        if N % i == 0:
            right = i
            left = math.floor(N/i)
            distance = (left - 1) + (right - 1)
            if minimum_distance > distance:
                minimum_distance = distance
        
    print(minimum_distance)
        
    
    

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,s,x;
int main(){
bitset<N*N> f;
f[0]=1;
scanf("%d",&n); 
	for (register int i=1; i<=n; ++i)
	{
	scanf("%d",&x);
	f|=f<<x;
	s+=x;
	}
for (register int i=(s+1)/2; i<=s; ++i)
if (f[i]) {printf("%d\n",i); return 0;}
}

Measured memory_bytes: 1664
n = int(input())
a = []
b = []

for i in range(n):
    a_temp, b_temp = map(int, input().split())
    a.append(a_temp)
    b.append(b_temp)

ans = 0
a = a[::-1]
b = b[::-1]
for i in range(n):
    ans += (-(a[i] + ans)) % b[i]
print(ans)


Measured memory_bytes: 17632