akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_macros, unused_imports, dead_code)]

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn main() {
    from_line!(N : i64);
    from_line!(A : i64);
    println!("{}",
             if N % 500 <= A {
                "Yes"
             } else {
                "No"
             });
}


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

#define INF 1LL << 60
#define MOD 1000000007;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, b, e) for (int i = b; i <= e; i++)
#define PRINT(x) cout << x << endl

int N, K;
string S;

string solve() {
    char c = S[K - 1];
    REP(i, N) {
        if (S[i] != c) {
            S[i] = '*';
        }
    }
    return S;
}

int main() {
    cin >> N >> S >> K;
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n):
    point = i
    ans = 0
    while point < n-1:
        c, s, f = csf[point][0], csf[point][1], csf[point][2]
        if ans < s:
            ans += s-ans+c
        else:
            if ans%f != 0:
                ans += f-(ans%f)
            ans += c
        point += 1
    print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> h(n);
    REP(i, n) cin >> h[i];

    vector<int> dp(n+5, INF);

    dp[0] = 0;
    REP(i, n) {
        dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1]);
        dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2]);
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for(int i = 0; i < N; i++) {
            String s = scan.next();
            switch (s) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }


        os.println("AC x " + ac);
        os.println("WA x " + wa);
        os.println("TLE x " + tle);
        os.println("RE x " + re);
    }
}

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

int x, y, z;

string doit(int d, int e, int f, string x, string y, string z) {
	//you have d a's, e b's, and f c's
	// cout << d << ' ' << e << ' ' << f << endl;
	if (d == 0) {
		if (e == 0) {
			string t;
			for (int i = 0; i < f; ++i)
				t += 'c';
			return t;
		}

		string s[e+5];
		for (int i = 0; i < e+5; ++i)
			s[i] = "";

		for (int i = 0; i < e; ++i)
			s[i] += 'b';
		int ct = 0;
		for (int i = 0; i < f; ++i) {
			s[ct] += 'c';
			ct++;
			ct %= e;
		}

		int c1 = e;
		for (int i = 1; i < e; ++i)
			if (s[i] != s[i-1])
				c1 = i;

		string t;
		t = doit(0, e-c1, c1, "", s[c1], s[0]);

		string ans = "";
		for (int i = 0; i < t.length(); ++i) {
			if (t[i] == 'b')
				ans += s[c1];
			else
				ans += s[0];
		}

		return ans;
	} else {
		string s[d+5];
		for (int i = 0; i < d+5; ++i)
			s[i] = "";

		for (int i = 0; i < d; ++i)
			s[i] += 'a';
		int ct = 0;
		for (int i = 0; i < f; ++i) {
			s[ct] += 'c';
			ct++;
			ct %= d;
		} 

		int ct1 = ct;
		for (int i = 0; i < e; ++i) {
			s[ct1] += 'b';
			ct1++;
			if (ct1 >= d)
				ct1 = ct;
		}

		int c1 = d, c2 = d;
		for (int i = 1; i < d; ++i) {
			if (s[i] != s[i-1]) {
				if (c1 == d)
					c1 = i;
				else
					c2 = i;
			}
		}

		string t = doit(d-c2, c2-c1, c1, s[c2], s[c1], s[0]);
		string ans = "";
		for (int i = 0; i < t.length(); ++i) {
			if (t[i] == 'a')
				ans += s[c2];
			if (t[i] == 'b')
				ans += s[c1];
			if (t[i] == 'c')
				ans += s[0];
		}

		return ans;
	}
}

int main() {
	cin >> x >> y >> z;
	cout << doit(x, y, z, "a", "b", "c") << endl;
}

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

ans = 0
# ab is higher than a+b, dont buy ab pizza
if a + b <= 2*c:
    ans = a*x + b*y
# a and b pizza is higher than ab*2, dont buy a, b pizza
elif a >= c*2 and b >= c*2:
    ans = c * max(x,y) * 2
elif a < c*2 and b >= c*2:
    ans = c*y*2 + max(0, x-y) * a
elif a >= c*2 and b < c*2:
    ans = c*x*2 + max(0, y-x) * b
else:
    ans = min(x, y) * 2 * c + a * (x-min(x,y)) + b * (y-min(x, y))

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

int main() {
	int a, p;
	cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
int mo=1000000007;

//////////

signed main()
{
	fastio;
	// #ifndef ONLINE_JUDGE
	// 	freopen("inputf.in","r",stdin);
	// 	freopen("outputf.in","w",stdout);
	// #endif
	int n;
	cin>>n;
	vector<int> v;
	for(int i=0;i<n;++i)
	{
		int d;
		cin>>d;
		v.push_back(d);
	}
	vector<int> ans;
	while(v.size())
	{
		int j=v.size()-1;
		for(;j>=0;--j)
		{
			if(v[j]==j+1)
				break;
		}
		if(j==-1)
		{
			cout<<"-1";
			return 0;
		}
		vector<int> v2;
		for(int i=0;i<v.size();++i)
			if(i!=j)
			{
				v2.push_back(v[i]);
			}
		ans.push_back(j);
		v=v2;
	}
	reverse(ans.begin(), ans.end());
	for(auto r:ans)
		cout<<r+1<<"\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    int H, W;

    public void Solve()
    {
        var line = Console.ReadLine().Split(' ');
        H = int.Parse(line[0]);
        W = int.Parse(line[1]);
        Console.WriteLine(new string('#', W + 2));
        for (int i = 0; i < H; i++)
        {
            Console.Write("#");
            Console.Write(Console.ReadLine());
            Console.Write("#");
            Console.WriteLine();
        }
        Console.WriteLine(new string('#', W + 2));
    }
}


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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        char[] c=fsc.next().toCharArray();
        fsc.close();
        for(int i=0;i<c.length;i+=2){
            System.out.print(c[i]);
        }
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 29096
#include <iostream>
#include <cmath>
int main(){
  int A, B;
  std::cin >> A;
  std::cin >> B;

  int min_a = std::ceil(12.5 * A);
  int max_a = std::floor(12.5*A + 12.5);
  if(A%2 == 1){
    --max_a;
  }
  int min_b = 10*B;
  int max_b = 10*B + 9;
  if(max_a < min_b){
    std::cout << -1 << std::endl;
  }
  else if(max_b < min_a){
    std::cout << -1 << std::endl;
  }
  else if(min_a <= min_b){
    std::cout << min_b << std::endl;
  }
  else{
    std::cout << min_a << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
def dfs(A):
    global cnt

    if len(A) == n:
        ans = [0 for i in range(m)]
        for i, a in enumerate(A):
            if a:
                for j in range(m):
                    if i+1 in s[j]:
                        ans[j] += 1
        for x, y in zip(p, ans):
            if x != y%2:
                break
        else:
            cnt += 1
        return
    for v in range(2):
        A.append(v)
        dfs(A)
        A.pop()

n, m = map(int, input().split())
s = [list(map(int, sys.stdin.readline().split()))[1:]  for x in range(m)]
p = list(map(int, sys.stdin.readline().split()))
cnt = 0
dfs([])
print(cnt)

Measured memory_bytes: 9152
#include <iostream>
#include <string>
using namespace std;
 
   int main()
   {
       int N;
       int count=0;
       int cmax=0;
       cin >> N;

       int n[N];
       int n2[N];
       
       for (int i=0;i<N;i++){
           cin >> n[i] >> n2[i];
       }
       
       for (int i=0; i<N; i++){
           if (n[i] == n2[i]){
               count+=1;
        
               if (count > cmax){
                   cmax = count;
               }
           }else{
               count = 0;
           }
       }
       
       if(cmax >=3){
           cout << "Yes" << endl;
       }
       else{
           cout << "No" << endl;
       }
       
    }

Measured memory_bytes: 3600
//tokyokaijyo2020_c.cpp
//Sat Jun 27 18:40:37 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,k;
	cin >> n >> k;

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

	int imos[n+1];
	for (int i=0;i<k;i++){
		fill(imos,imos+n+1,0);
		for (int j=0;j<n;j++){
			imos[max(j-a[j],0)]++;
			imos[min(j+a[j]+1,n)]--;
		}
		a[0] = imos[0];
		int flag = 1;
		for (int j=1;j<n;j++){
			imos[j] = imos[j-1]+imos[j];
			a[j] = imos[j];
			if (a[j]!=n){
				flag = 0;
			}
		}
		if (flag){
			for (int j=0;j<n;j++){
				cout << n << " ";
			}
			printf("\n");
			return 0;
		}
	}

	for (int i=0;i<n;i++){
		cout << a[i] << " ";
	}
	printf("\n");

}

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

int main()
{
    int a,b,c;
    int count = 0;
    int i;
    cin >> a >> b >> c;
   
    for(i=0; i<= b-a; i++){
       if(c%(a+i) == 0){
           count+= 1;
       }
    }
    cout << count << endl;
    return 0;
}



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

int dp[3030][3030][2];

int main(){
  int n, t;
  cin >> n >> t;
  vector<P> p;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    p.push_back({a,b});
  }
  //sort(p.begin(), p.end());

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < t; j++) {
      for (int k = 0; k < 2; k++) {
        if (k == 0) dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][0] + p[i].second);
   
        if (j + p[i].first < t) {
            dp[i+1][j+p[i].first][k] = max(dp[i+1][j+p[i].first][k], dp[i][j][k] + p[i].second);
        }

        dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
      }
    } 
  }
  cout << dp[n][t-1][1] << endl;
  return 0;
} 

Measured memory_bytes: 71936
def f(a,b):
    for i in range(a):
        print("#"*b)
    print()
L = []
while True:
        a,b = map(int,input().split())
        k = [a,b]
        L.append(k)
        if a == 0 and b == 0 :
            break

for i in range(len(L)-1):
    f(L[i][0],L[i][1])



Measured memory_bytes: 5628
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
s=list(map(int,list(SI())))
pos=[[-1,-1] for i in range(10)]
for i in range(n):
    j=n-i-1
    if pos[s[i]][0]==-1:
        pos[s[i]][0]=i
    if pos[s[j]][1]==-1:
        pos[s[j]][1]=j
#print(pos)
count=0
for i in range(10):
    for j in range(10):
        lis=[0 for i in range(10)]
        if pos[i][0]<0 or pos[j][0]<0:
            continue
        for k in range(pos[i][0]+1,pos[j][1]):
            lis[s[k]]+=1
        for l in range(10):
            if lis[l]>0:
                count+=1
print(count)
            
        
        
            
    
            
            

    
    
            
            



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

class M {
  static void Main(String[] _) {
    var N = int.Parse( Console.ReadLine() );
    var W = Console.ReadLine().Split(' ');
	
    var L = new List<int>();
    foreach ( var T in W ) {
      var E = int.Parse(T);
      if ( L.Count + 1 < E ) {
	    Console.Write( "-1" );    
        return;
      }
      L.Insert( E - 1 , E ) ;
    }
    
    Console.Write( string.Join("\n",L.ToArray()) );    
    
  }
}


Measured memory_bytes: 13268
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef vector<xy_t> polygon;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

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

int memo[sz][6];
P pos[sz][7];
int cnt[7];

int cost(const P &p1, const P &p2){
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

void update(int cur, int nxt, int n){
	rep(i, cnt[cur]){
		rep(j, cnt[nxt]){
			memo[j][n+1] = min(memo[j][n+1], memo[i][n] + cost(pos[i][cur], pos[j][nxt]));
		}
	}
}

int main(){
	int X, Y;
	int num;
	char ch;
	while(cin >> X >> Y && (X || Y)){
		memset(cnt, 0, sizeof(cnt));
		rep(i, Y)rep(j, X){
			cin >> ch;
			if(ch == '.') continue;
			if(ch == 'S'){
				pos[cnt[0]++][0] = P(j, i);
			}else if(ch == 'G'){
				pos[cnt[6]++][6] = P(j, i);
			}else{
				num = ch - '0';
				pos[cnt[num]++][num] = P(j, i);
			}
		}
		int res = INF;
		int id = -1;

		rep(type, 5){
			fill(&memo[0][0], &memo[sz-1][5] + 1, INF);
			memo[0][0] = 0;
			rep(i, 5){
				int cur = 0, nx = 0;
				if(i == 0){
					cur = 0;
					nx = 1 + (type + i + 1) % 5;
				}else if(i == 4){
					cur = 1 + (type + i) % 5;
					nx = 6;
				}else{
					cur = 1 + (type + i) % 5;
					nx = 1 + (type + i + 1) % 5;
				}
				update(cur, nx, i);
			}
		
			if(memo[0][5] < res){
				res = memo[0][5];
				id = type;
			}
		}
		if(res == INF) cout << "NA" << endl;
		else cout << id+1 << " " << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x,ans;
  ans=0;
  cin>>n>>x;
  if(n%x==0){
    ans=n/x;
  }else{
    ans=n/x;
    ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 3556
unittest
{
	assert( [ "2 6" ].solve == 4 );
	assert( [ "3 12" ].solve == 18 );
	assert( [ "100000 1000000000" ].solve == 957870001 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	
	const M = 10L ^^ 9 + 7;
	auto ans = ModWorld!M( 1L );
	foreach( p; m.primefactorize.group )
	{
		ans *= ( p[ 1 ] + n - 1 ).combination!M( n - 1 );
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}

// 階乗
auto factorial( long M )( long x )
{
	static memo = [ ModWorld!M( 1L ) ];
	if( memo.length <= x )
	{
		auto i = memo.length.signed;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i;
	}
	return memo[ x ];
}

// 組み合わせ数
auto combination( long M )( long n, long k )
{
	if( n < k ) return ModWorld!M( 0L );
	else        return n.factorial!M / ( k.factorial!M * ( n - k ).factorial!M );
}

// 素数列
auto primes( long x )
{
	Appender!( long[] ) ps;
	if( x < 2 ) return ps.data;
	
	auto cs = new bool[]( x + 1 );
	ps ~= 2L;
	for( auto i = 3L; i * i < cs.length; i += 2 )
	{
		if( cs[ i ] ) continue;
		for( auto j = i; i * j < cs.length; j++ )
		{
			cs[ i * j ] = true;
		}
	}
	for( auto i = 3L; i < cs.length; i += 2 )
	{
		if( !cs[ i ] ) ps ~= i;
	}
	return ps.data;
}

// 素因数分解
auto primefactorize( long x )
{
	Appender!( long[] ) fs;
	if( x < 2 ) return fs.data;
	
	auto s = cast( long ) x ^^ 0.5L;
	foreach( p; s.primes )
	{
		while( x % p == 0 )
		{
			x /= p;
			fs ~= p;
		}
		if( x < 2 ) break;
	}
	if( 2 <= x ) fs ~= x;
	return fs.data;
}


Measured memory_bytes: 3760
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var x = int.Parse(Console.ReadLine());

        var happiness = x / 500 * 1000 + x % 500 / 5 * 5;
        
        Console.WriteLine(happiness);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  int a[N], b = 0;
  vector<vector<bool>> dp1(N+1,vector<bool>(K+1)),dp2(N+1,vector<bool>(K+1));
  dp1[0][0] = true;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i] = min(a[i],K);
    for (int j = 0; j <= K; j++) {
      if (!dp1[i][j]) continue;
      dp1[i+1][j] = true;
      if (j+a[i] <= K) dp1[i+1][j+a[i]] = true;
    }
  }
  dp2[N][0] = true;
  for (int i = N-1; i+1; i--) {
    for (int j = 0; j < K; j++) {
      if (!dp2[i+1][j]) continue;
      dp2[i][j] = true;
      if (j+a[i] <= K) dp2[i][j+a[i]] = true;
    }
  }
  for (int i = 0; i < N; i++) {
    bool ok = false;
    for (int j = 0; j < K; j++) {
      if ((dp1[i][j] || dp2[i+1][j]) && j+a[i] >= K) {
        ok = true;
        break;
      }
    }
    for (int j = 0; j <= K-a[i]; j++) {
      if (dp1[i][j] && dp2[i+1][K-j-a[i]]) {
        ok = true;
        break;
      }
    }
    b += !ok;
  }
  cout << b;
}

Measured memory_bytes: 9880
# input
S = input()

# check
check_one = S[0] == "A"
check_two = S[2:-1].count("C") == 1
check_three = False not in [True if s in ["A", "C"] or s.lower() == s else False for s in list(S)]

if False not in [check_one, check_two, check_three]:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int Q = sc.nextInt();
    int[] l = new int[Q];
    int[] r = new int[Q];
    int max = 0;
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
      max = Math.max(max, r[i]);
    }

    boolean[] prime = new boolean[max+5];
    for (int i = 2; i <= max; i++) {
      boolean isPrime = true;
      for (int j = 2; j*j <= i; j++) {
        if (i%j == 0) {
          isPrime = false;
          break;
        }
      }
      prime[i] = isPrime;
    }
    
    int[] cnt = new int[max+5];
    for (int i = 1; i <= max; i++) {
      if (prime[i] && prime[(i+1)/2]) {
        cnt[i] = cnt[i-1]+1;
      } else {
        cnt[i] = cnt[i-1];
      }
    }
    
    StringBuilder ans = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      ans.append(cnt[r[i]] - cnt[l[i]-1]).append('\n');
    }

    System.out.print(ans.toString());
  }
}

Measured memory_bytes: 87048
#include <bits/stdc++.h>
using namespace std;
int i,j,k,x,y,z,l,m,n,count1=0,count2=0;
int gcd(int,int);
void A(void);
void B(void);
void C(void);
void D(void);
void E(void);
void F(void);

int main(void){
    A();
}

void A(){
    string s,t;
    cin>>s>>t;
    int ans=1;
    for(i=0;i<s.length();i++){
        if(s[i]!=t[i])ans=0;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main(){
    int N,X;

    cin >> N >> X;

    int L[N];

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

    int count = 1;
    int sum_x = 0;

    for(int i = 0; i < N; i++){
        sum_x += L[i];
        if(sum_x > X){
            break;
        }
        count++;
    }

    cout << count << endl;

    return 0;
}

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

int main() {
  int N,i,k=0;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<a.size();++i){
    cin >> a.at(i);
    --a.at(i);
  }
  i=0;
  do{
    ++k;
    i=a.at(i);
    if(i==1)
      break;
  }while(--N);
  if(N)
    cout << k << endl;
  else
    cout << -1 << endl;
    
}


Measured memory_bytes: 3784
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    else:
        #高さHの分だけループ
        for j in range(H) :
            #１行目, 最終行は全て＃で出力
            if j == 0 or j == H-1 :
                for i in range(W) :
                    print("#", end="")
                print()
            #2行目以降は間を.で出力
            else :
                #横の長さを出力
                for i in range(W) :
                    # 行の始めと終わりは＃を出力
                    if i == 0 or i == W-1  :
                        print("#", end="")
                    # 始めと終わり以外は.を出力
                    else :
                        print(".", end="")
                # 横の長さWを出力が終わったら改行
                print()
        #縦の長さHの出力が終わったら空行を出力
        print()



Measured memory_bytes: 7004
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1100010;
char cn[cm], * ci = cn, ct;

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

	fread(cn, 1, cm, stdin);
	int N = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';

	int kotae = 0;
	rep(i, N) {
		while (*ci++ >= '0');
		kotae ^= *(ci - 2);
	}
	if (kotae & 1) printf("NO\n");
	else printf("YES\n");


	Would you please return 0;
}

Measured memory_bytes: 1152
import scala.collection.mutable.PriorityQueue


object Main {

  def main(args: Array[String]): Unit = {

    val Array(n,m) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val leftJobs = PriorityQueue.empty[(Int,Int)](Ordering.by[(Int,Int),Int](t => -t._1))
    val availables = PriorityQueue.empty[Int]

    (0 until n)
      .foreach(_ => {
        val Array(days,reward) = readLine().split(" ").map(_.toInt)
        leftJobs.enqueue(days -> reward)
      })

    val totalReward = (for { 
      leftDays <- 0 to m
    } yield {
      while(leftJobs.size > 0 && leftJobs.head._1 <= leftDays) {
        val v = leftJobs.dequeue()
        availables.enqueue(v._2)
      }

      if(availables.size == 0) {
        0
      } else {
        availables.dequeue()
      }
    }).sum

    println(totalReward)
  }

}

Measured memory_bytes: 118344
import heapq as hq
N,M,S = list(map(int, input().split()))
#Edge
E = [[] for _ in range(N)]
  
for _ in range(M):
  # U <-> V, A coins, B mins
  u,v,a,b = list(map(int, input().split()))
  # 0-indexed
  E[u-1].append([v-1, a, b])
  E[v-1].append([u-1, a, b])

# City
C = []
for _ in range(N):
  # C coins, D mins
  C.append(list(map(int, input().split())))
  
# dp[p][i] 点Pにたどり着いた時、i円持っている時の最小時間
MAXYEN = 50 * N
dp = [[ 1e18 for i in range(MAXYEN + 5) ] for _ in range(N)]
S = min(MAXYEN, S)
dp[0][S] = 0

# 状態は点とお金と時間. time, pointindex, money
Q = []
hq.heapify(Q)
hq.heappush(Q, [0,0,S])

while len(Q) > 0:
  nowt, nowi, nowm = hq.heappop(Q)
  #print("Pop :", nowt, nowi, nowm)
  # Edgeをわたる。a yen払ってB時間かけて、Vに移動する。
  for e in E[nowi]:
    to_i, costm, costt = e
    #print("Edge:", to_i, costm, costt)
    if nowm - costm < 0:
      # unreachable 
      continue
    if dp[to_i][nowm-costm] > dp[nowi][nowm] + costt:
      dp[to_i][nowm-costm] = dp[nowi][nowm] + costt
      hq.heappush(Q, [dp[nowi][nowm] + costt, to_i, nowm-costm])
      
  # その場でお金を1回買う。移動せず、CYenGetして、D時間かける
  getm, costt = C[nowi]
  targetm = min(MAXYEN, nowm + getm)
  #print("Buy :", getm, targetm, costt)
  if dp[nowi][targetm] > dp[nowi][nowm] + costt:
    dp[nowi][targetm] = dp[nowi][nowm] + costt
    hq.heappush(Q, [dp[nowi][targetm], nowi, targetm])
  
for i in range(1,N):
  print(min(dp[i]))
  


Measured memory_bytes: 100376
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scane = new Scanner(System.in);

		int a = scane.nextInt();
		int b = scane.nextInt();

		String s = String.format("%.5f", (double)a/(double)b);

		System.out.println(a/b+" "+a%b+" "+s);



	}
}

Measured memory_bytes: 26328
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;
double t[110];
double v[110];
double t_sum[110] = {};
double vmin[50000] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    rep(i,0,N){
        cin >> t[i];
    }
    rep(i,0,N){
        cin >> v[i];
    }
    rep(i,1,N+1){
        t_sum[i] = t_sum[i-1] + t[i-1];
    }
    rep(i,0,t_sum[N] * 2 + 1){
        double vmin_tmp = 1e9;
        double tt = double(i)/2;
        rep(j,0,N){
            if(tt < t_sum[j]){
                vmin_tmp = min(vmin_tmp, v[j] + t_sum[j] - tt);
            }else if(tt >= t_sum[j] && tt <= t_sum[j+1]){
                vmin_tmp = min(vmin_tmp, v[j]);
            }else{
                vmin_tmp = min(vmin_tmp, v[j] + tt - t_sum[j+1]);
            }
        }
        vmin_tmp = min(vmin_tmp, tt);
        vmin_tmp = min(vmin_tmp, t_sum[N] - tt);
        vmin[i] = vmin_tmp;
    }
    double ans = 0;

    rep(i,0,t_sum[N] * 2){
        ans += 0.25 * (vmin[i] + vmin[i+1]);
    }
    cout << setprecision(10) << ans << endl;


}


Measured memory_bytes: 640
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

def score_p(t):
    if t == 'r':
        return P
    if t == 's':
        return R
    if t == 'p':
        return S

A = [None] * N
for k in range(K):
    for i in range(k, N, K):
        if i == k:
            A[i] = score_p(T[i])
        else:
            if T[i] == T[i-K]:
                if A[i-K] > 0:
                    A[i] = 0
                else:
                    A[i] = score_p(T[i])
            else:
                A[i] = score_p(T[i])

print(sum(A))


Measured memory_bytes: 4084
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int field[5][5];

bool ok(int h, int w){
	h--, w--;
	for(int i = 0; i + h < 5; i++){
		for(int j = 0; j + w < 5; j++){
			bool f = true;
			for(int l = 0; l <= h; l++){
				for(int k = 0; k <= w; k++){
					if(field[i+l][j+k] == 0) f = false;
				}
			}
			if(f){
				return true;
			}
		}
	}
	return false;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 5; j++){
			for(int k = 0; k < 5; k++){
				cin >> field[j][k];
			}
		}
		int res = 0;
		for(int j = 1; j <= 5; j++){
			for(int k = 1; k <= 5; k++){
				if(ok(j, k)) res = max(res, j * k);
			}
		}
		cout << res << endl;
	}
	return 0;
}
		

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

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  
  int k=0;
  
  for(int i=1;i<=N;i++){
    int x=i%10+i/10%10+i/100%10+i/1000%10+i/10000;
    if(A<=x&&x<=B){
      k+=i;
    }
  }
  cout << k << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=1; i<N; i++) {
    cin >> A.at(i);
  }
  
  vector<int> children(N);
  
  for (int i = 1; i < N; i++) {
    int parent = A.at(i) - 1;  // i番の親組織の番号
    children.at(parent) += 1;  // parentの子組織一覧にi番を追加
  }
  
  for (int i; i < N; i++) {
    cout << children.at(i) << endl;
  }
}

Measured memory_bytes: 4756
#include<iostream>
using namespace std;
int main()
{
    int X,Y,Z,A,B,C,T,E;
    cin>>X>>Y>>Z;
    A=X;
    B=Y;
    C=Z;
    T=A;
    A=B;
    B=T;
    E=A;
    A=C;
    C=E;
    cout<<A<<" "<<B<<" "<<C;

}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

//aとbの最大公約数を返す
long long gcd(long long a, long long b){
    while (a != 0 && b != 0){
        if (a >= b) a %= b;
        else b %= a;
    }
    return a + b;
}

int N;
ll A[200010], B[200010];
ll P[200010];

signed main(){
    cin >> N;
    REP(i, N){
        cin >> A[i] >> B[i];
    }
    P[0] = 1;
    REP(i, N) P[i + 1] = 2 * P[i] % MOD;
    map<pll, pll> mp;
    ll z = MOD - 1;
    REP(i, N){
        if(A[i] == 0 && B[i] == 0){
            z++;
            continue;
        }
        if(pll(A[i], B[i]) < pll(0LL, 0LL)){
            A[i] *= -1; B[i] *= -1;
        }
        ll g = gcd(abs(A[i]), abs(B[i]));
        if(g != 0) A[i] /= g; B[i] /= g;
        if(B[i] > 0) mp[pll(A[i], B[i])].first++;
        else mp[pll(-B[i], A[i])].second++;
    }
    ll ans = 1;
    for(auto p : mp){
        int a = p.second.first, b = p.second.second;
        ans = ans * (P[a] + P[b] - 1) % MOD;
    }
    PRINT((z + ans) % MOD);
    return 0;
}

Measured memory_bytes: 23920
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
int N;
int A[3][200];
int dp[3][200];

int main() {
  cin >> N;
  repe(i, 1, 2) {
    repe(j, 1, N) { cin >> A[i][j]; }
  }

  dp[1][1] = A[1][1];
  dp[2][1] = dp[1][1] + A[2][1];
  repe(j, 2, N) {
    dp[1][j] = dp[1][j - 1] + A[1][j];
    dp[2][j] = max(dp[2][j - 1], dp[1][j]) + A[2][j];
  }
  cout << dp[2][N] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, Q, l[100001], r[100001];
	char S[100001];
	scanf("%d %d", &N, &Q);
	scanf("%s", S);
	for (i = 1; i <= Q; i++) scanf("%d %d", &(l[i]), &(r[i]));
	
	int count[100001] = {};
	for (i = 1; S[i] != 0; i++) {
		if (S[i-1] == 'A' && S[i] == 'C') count[i] = count[i-1] + 1;
		else count[i] = count[i-1];
	}
	
	for (i = 1; i <= Q; i++) printf("%d\n", count[r[i]-1] - count[l[i]-1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int N = 550, M = 5500, p = 1e9 + 7;
int n, m, k, ans = 1, dclk, dfn[N], fac[M], inv[M], fa[N];
int cnt, rt[N], si[N], cn[N], col[N];
int tot, fi[N], a[M], ne[M];
inline int Qmi(int x, int y) {
	int ans = 1;
	for (; y; x = 1ll * x * x % p, y >>= 1) if (y & 1) ans = 1ll * ans * x % p;
	return ans;
}
inline void Add(int x, int y) {
	a[++tot] = y; ne[tot] = fi[x]; fi[x] = tot;
}
inline int Ask(int x) {
	return rt[x] == x ? x : rt[x] = Ask(rt[x]);
}
inline void A(int &x, int y) { x += y; if (x >= p) x -= p; }
inline int C(int x, int y) {
	return 1ll * fac[x] * inv[y] % p * inv[x - y] % p;
}
inline void Dfs(int x) {
	dfn[x] = ++dclk;
	for (int i = fi[x]; i; i = ne[i])
	   	if (!dfn[a[i]]) {
			fa[a[i]] = x; Dfs(a[i]);
		} else {
			if (a[i] == fa[x] || dfn[a[i]] > dfn[x]) continue;
			++cnt; rt[cnt] = cnt; si[cnt] = 1;
			for (int t = x; t != a[i]; t = fa[t]) 
				if (col[t]) {
					int u = Ask(col[t]), v = Ask(cnt);
					if (u == v) continue;
					rt[u] = v; si[v] += si[u];
				} else col[t] = cnt, ++si[Ask(cnt)];
		}
}
int main() {
	fac[0] = 1; for (int i = 1; i < M; ++i) fac[i] = 1ll * fac[i - 1] * i % p;
	inv[0] = inv[1] = 1; for (int i = 2; i < M; ++i) inv[i] = 1ll * inv[p % i] * (p - p / i) % p;
	for (int i = 2; i < M; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % p;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1, x, y; i <= m; ++i) scanf("%d%d", &x, &y), Add(x, y), Add(y, x);
	for (int i = 1; i <= n; ++i) if (!dfn[i]) Dfs(i), col[i] = -1;
	for (int i = 1; i <= cnt; ++i) ++cn[Ask(i)];
	for (int i = 1; i <= n; ++i) if (!col[i]) ans = 1ll * ans * k % p;
	for (int i = 1; i <= cnt; ++i) if (cn[i] == 1) {
		int sm = 0;
		for (int j = 0; j < si[i]; ++j) A(sm, Qmi(k, __gcd(j, si[i])));
		sm = 1ll * sm * Qmi(si[i], p - 2) % p;
		ans = 1ll * ans * sm % p;
	} else if (cn[i] > 1) {
		ans = 1ll * ans * C(si[i] + k - 1, k - 1) % p;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define COUT(a) cout << a << endl;

Vll v(100000);

int main(){
    ll n;
    cin >> n;
    map<ll, ll> m0;
    map<ll, ll> m1;
    ll res = 0, num = 0, max_num = 0, max_num1 = 0;
    ll max2_num=0, max2_num1=0;
    ll max_num_index = 0;
    ll max2_num_index = 0;
    ll max_num_index1 = 0;
    ll max2_num_index1 = 0;
    v.rs(n);

    rep(i,0,n) cin >> v[i];
    rep(i,0,n){
        if(i%2==1){
            if(m1[v[i]]==0) m1[v[i]] = 0;
            m1[v[i]]++;
        }else{
            if(m0[v[i]]==0) m0[v[i]] = 0;
            m0[v[i]]++;
        }
    }

    for(auto &elem : m0){
        ll num = elem.second;
        if(num < max_num){
            res += num;
            if(max2_num < num){
                max2_num = num;
                max2_num_index = elem.first;
            }
        }else{
            res += max_num;
            max2_num = max_num;
            max_num = num;
            max2_num_index = max_num_index1;
            max_num_index = elem.first;     
        }
    }
    
    for(auto &elem : m1){
        ll num = elem.second;
        if(num < max_num1){
            res += num;
            if(max2_num1 < num){
                max2_num1 = num;
                max2_num_index1 = elem.first;
            }
        }else{
            res += max_num1;
            max2_num1 = max_num1;
            max_num1 = num;
            max2_num_index1 = max_num_index1;
            max_num_index1 = elem.first;     
        }
    }
    
    
    if(max_num_index == max_num_index1){
        res += max_num;
        ll tmp = max(max2_num1, max2_num);
        res -= tmp;
    }
    cout << res << endl;

}





Measured memory_bytes: 7296
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-07 20:22:18
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for (int i = 0; i < m; i++)
        cin >> a[i];

    int p, q;
    p = 0;
    for (int i = 0; a[i] < x; i++) {
        p++;
    }
    q = m - p;

    cout << min(p, q) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = (int)4e6 + 3;
bitset<N> a;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n;
	int S = 0;
	a.set(0);
	scanf("%d", &n);
	while(n--) {
		int x;
		scanf("%d", &x);
		S += x;
		a |= a << x;
	}
	S = (S + 1) / 2;
	for (int x = S;; x++) {
		if (a[x]) {
			printf("%d\n", x);
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 1792
//Yazar: Mehmet Kutay Bozkurt
//Auther: Mehmet Kutay bozkurt
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long int lo;
#define pb push_back
#define st first
#define nd second
lo a,b,c,d,e,n,m,x,y,z,a1[100005],a2[100005],k,t;
char c1,c2,c3,c4;
string s1,s2,s3,s4,den[3];
bool av=false;
map <char,lo> mp;
vector <lo> v;
vector <lo> v1;
int main() {
    // freopen("gir.gir","r",stdin);
	// freopen("cik.cik","w",stdout);
	cin>>a>>b;
    if(a%b==0){
        cout<<a/b<<endl;
    }
    else{
        cout<<a/b+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> v(1, 1);
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            v.back()++;
        } else {
            v.push_back(1);
        }
    }
    int ans = 0; 
    for (auto &el : v) {
        ans += el / 2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<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;
    vector<ll> a(4, 0);
    REP(i, n){
        string res;
        cin >> res;
        if(res == "AC"){
            a[0] += 1;
        } else if (res == "WA"){
            a[1] += 1;
        } else if (res == "TLE"){
            a[2] += 1;
        } else {
            a[3] += 1;
        }
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
}



Measured memory_bytes: 3628
#include <stdio.h>

#define N_MAX 10
int stack[N_MAX];
int stack_p=0; //first points the head

void push(int n)
{
    stack[stack_p++]=n;
}
int pop(void)
{
    if(stack_p==0){ return -1; }
    return stack[--stack_p];
}

//#define DEBUG
int main(void)
{
    FILE *fp;
#ifdef DEBUG
    fp=fopen("input.txt","r");
#else
    fp=stdin;
#endif

    while(feof(fp)==0){
        int n; //n-th car (starts from 1)
        fscanf(fp,"%d\n", &n);
        //cars out
        if(n==0){
            printf("%d\n",pop());
        }
        //cars in
        else{
            push(n);
        }
    }
    return 0;
}

Measured memory_bytes: 0