akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 600

// 700, 1h で解けず解説を見る

int H, W;
string A[MAX_N];
bool R[MAX_N][MAX_N];
bool B[MAX_N][MAX_N];

int main()
{
    cin >> H >> W;
    REP(i, H) { cin >> A[i]; }
    // 赤を作成
    ZERO(R);
    for(int i = 0; i < H; ++i) {
        if(i % 2 == 0) { for(int j = 0; j < W-1; ++j) { R[i][j] = true; } }
        else { R[i][0] = true; }
        for(int j = 0; j < W-1; ++j) { if(A[i][j] == '#') { R[i][j] = true; } }
    }
    // 青を作成
    ZERO(B);
    for(int i = 0; i < H; ++i) {
        if(i % 2 == 0) { B[i][W-1] = true; }
        else { for(int j = 1; j < W; ++j) { B[i][j] = true; } }
        for(int j = 0; j < W-1; ++j) { if(A[i][j] == '#') { B[i][j] = true; } }
    }
    // 出力
    REP(i, H) {
        REP(j, W) {
            printf("%c", (R[i][j]) ? '#' : '.');
        }
        printf("\n");
    }
    printf("\n");
    REP(i, H) {
        REP(j, W) {
            printf("%c", (B[i][j]) ? '#' : '.');
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 1664
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

void solve() {
    string s;
    cin >> s;
    lli pos = 0, ans = 0;
    vlli v;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'W') {
            v.push_back(i);
        }
    }
    for (auto i : v) {
        ans += (i - pos);
        pos++;
    }
    cout << ans << endl;
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}


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

int main() {
    string s;cin >> s;
    int su = 0;
    int lo = s.size();
    int num = atoi(s.c_str());

    for(int i=0;i<lo;i++){
        su += (s[i] - '0');
    }

    if(num%su==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
long long gcdf(long long a,long long b){
  long long p = a;
  long long q = b;
  long long c = 0;
  c = p%q;
  while(c != 0){
    p = q;
    q = c;
    c = p%q;
  }
  return q;
}

int main(){
  int n = 0;
  int i = 0;
  long long t[100] = {};
  long long gcd = 0;
  long long lcm = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&t[i]);
  }
  lcm = t[0];
  gcd = t[0];
  for(i=1;i<n;i++){
    gcd = gcdf(lcm,t[i]);
    lcm = lcm / gcd * t[i] ;
  }
  printf("%lld",lcm);
  return 0;
}
  
          
  
  

Measured memory_bytes: 128
$N = gets.to_i
$S = gets.chomp
$ans = 0
def solve()
    l = $S.size
    (l-1).times{|i|
        tmp = 0
        a = $S[0..i]
        b = $S[(i+1)..l]
        table = {}
        a.each_char{|s|
            table[s] = 1 if table[s] == nil
        }
        b.each_char{|s|
            tmp = tmp + 1 if table[s] == 1
            table[s] = 0
        }
        $ans = [$ans,tmp].max
    }
end

solve
puts $ans


Measured memory_bytes: 1788
n=int(input())
txy=[list(map(int,input().split())) for _ in range(n)]
if abs(txy[0][1])+abs(txy[0][2])>abs(txy[0][0]) or (txy[0][0]+txy[0][1]-txy[0][2])%2!=0:
  print('No')
  exit()
for i in range(1,n):
  dx,dy,dt=txy[i][1]-txy[i-1][1],txy[i][2]-txy[i-1][2],txy[i][0]-txy[i-1][0]
  if abs(dx)+abs(dy)>abs(dt) or (dx+dy-dt)%2!=0:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 27380
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int[] B = new int[M];
        for (int i = 0; i < M; i++) {
            B[i] = sc.nextInt();
        }
        long sum = 0;
        int i = 0;
        while (i < N && sum+A[i] <= K) {
            sum += A[i];
            i++;
        }
        int j = 0;
        while (j < M && sum+B[j] <= K) {
            sum += B[j];
            j++;
        }
        int ans = i+j;
        while (i > 0) {
            sum -= A[--i];
            while (j < M && sum+B[j] <= K) {
                sum += B[j];
                j++;
            }
            ans = Math.max(ans,i+j);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 60600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        String S = in.next();

        int c0 = 0;
        int c1 = 0;
        for(int i = 0; i < S.length(); i++){
            if(S.charAt(i) - '0' == 0){
                c0++;
            } else {
                c1++;
            }
        }
        out.println(2 * Math.min(c0, c1));
    }
}
}



Measured memory_bytes: 24672
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

const int MAX_N = 1010;
ll dp[MAX_N][10];
void output(int i, int j, int k) {
    if(i == 0) {return;}
    cout << j;
    //cout << i << " " << j << " " << k << endl;
    if(j > 0) {
        if(k > dp[i - 1][j - 1]) {
            k -= dp[i - 1][j - 1];
        } else {
            output(i - 1, j - 1, k);
            return;
        }
    }
    if(k > dp[i - 1][j]) {
        k -= dp[i - 1][j];
    } else {
        output(i - 1, j, k);
        return;
    }
    if(j < 9) {
        if(k > dp[i - 1][j + 1]) {
            k -= dp[i - 1][j + 1];
        } else {
            output(i - 1, j + 1, k);
            return;
        }
    }
}


signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int k;
    cin >> k;
    ll cnt = 0;
    for(int i = 0; i < 10; i ++) {
        dp[1][i] = 1;
    }
    if(k < 10) {cout << k << endl; return 0;}
    k -= 9;
    for(int i = 2; true; i ++) {
        for(int j = 0; j < 10; j ++) {
            if(j > 0) {
                dp[i][j] = dp[i - 1][j - 1];
            }
            dp[i][j] += dp[i - 1][j];
            if(j < 9) {
                dp[i][j] += dp[i - 1][j + 1];
            }
            if(j != 0) {
                if(k > dp[i][j]) {
                    k -= dp[i][j];
                } else {
                    output(i, j, k);
                    return 0;
                }
            }
            //cout << dp[i][j] << " " << k << endl;;
        }
        //-cout << endl;
    }
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        boolean ok = false;
        int index = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] + a[i - 1] >= l) {
                ok = true;
                index = i;
                break;
            }
        }
        if (!ok) {
            System.out.println("Impossible");
            return;
        }
        System.out.println("Possible");
        for (int i = 1; i < index; i++) {
            System.out.println(i);
        }
        for (int i = n - 1; i > index; i--) {
            System.out.println(i);
        }
        System.out.println(index);
    }
}


Measured memory_bytes: 63268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int n = sc.nextInt();

		int[] arr = new int[102];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = i;
		}

		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < p.length; i++) {
			for (int j = 0; j < arr.length; j++) {
				if(p[i]==arr[j]) {
					arr[j]=-1;
				}
			}
		}

		int leftIdx=0;
		for (int i = x; i >= 0; i--) {
			if(arr[i] >= 0) {
				leftIdx =i;
				break;
			}
		}
		int rightIdx=0;
		for (int i = x; i < arr.length ; i++) {
			if(arr[i] >= 0) {
				rightIdx =i;
				break;
			}
		}

		if(x-leftIdx <= rightIdx-x) {
			System.out.println(arr[leftIdx]);
		} else {
			System.out.println(arr[rightIdx]);

		}
	}
}

Measured memory_bytes: 27192
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	long long h,w,a,b,sum = 0;
	scanf("%d%lld%lld",&n,&h,&w);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&a,&b);
		if(a>=h && b>=w)
			sum++;
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  string s;
  cin>>s;
  int ans = 0;
  int now = 0;
  REP(i, 3){
    if(s[i] == 'S'){
      now = 0;
    }else{
      now++;
    }
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    cin>>N;
    int count=0;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        if((i-count+1)!=A[i]){
            count++;
        }
    }
    if(count==N){
        cout << -1 << endl;
    }
    else{
        cout<<count<<endl;
    }
}

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

void Main() {
    // input
    int N, M;
    cin >> N >> M;


    // translate
    int ans = 0;
    ans += (N * (N - 1)) / 2;
    ans += (M * (M - 1)) / 2;


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3616
#include<string>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	string c=a+b;
	int z=1,d=0;
	for (int i=0;i<c.size();i++)
	{
		d=d*10+(c[i]-'0');
	}
	int j=sqrt(d);
	j*=j;
	//cout<<d<<endl;
	if (j==d)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a<b:
    if b<c:
        print(a,b,c)
    elif c<a:
        print(c,a,b)
    else:
        print(a,c,b)
else:
    if a<c:
        print(b,a,c)
    elif c<b:
        print(c,b,a)
    else:
        print(b,c,a)


Measured memory_bytes: 5596
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		char[] c = new char[4];
		for(int i=0;i<4;i++) {
			c[i] = s.charAt(i);
		}
		Arrays.sort(c);
		if(c[0]==c[1] && c[2]==c[3] && c[1]!=c[2]) System.out.println("Yes");
		else System.out.println("No");
		
		in.close();

	}

}


Measured memory_bytes: 21844
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	void BFS() {
		
		int currNode = 0;
		boolean[] visited = new boolean[totalVertex];
		LinkedList<Integer> queue = new LinkedList<Integer>(); 
        visited[currNode]=true; 
        queue.add(currNode); 
        int[] numSteps = new int[totalVertex];
    	int x = 0;
        
        while (queue.size() != 0) 
        { 	
            currNode = queue.poll(); 
            //System.out.print(currNode+" "); 
  
            Iterator<Integer> i = adjList.get(currNode).listIterator(); 
            while (i.hasNext()) 
            { 
                int n = i.next(); 
                if (!visited[n]) 
                { 
                    visited[n] = true; 
                    queue.add(n); 
                    numSteps[n] = numSteps[currNode] + 1;
                } 
            }
        }
        for(int i = 0; i < numSteps.length; i++) {
        	if(numSteps[i] == 0 && i != 0) System.out.println(i+1 + " " + -1);
        	else System.out.println(i+1 + " " + numSteps[i]);
        	
        }
		
	}
	
}


public class Main {
	public static void main(String args[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.BFS();
	}
}


Measured memory_bytes: 27960
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{

 
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans = double(w*h)/2;
  cout<<ans<<" ";
  if(w == 2*x && h == 2*y) cout << 1 << endl;
  else cout << 0 << endl;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int translateChar(char ch){
	int ret;
	switch(ch){
	case 'A':
		ret = 1;
		break;
	case 'C':
		ret = 2;
		break;
	case 'G':
		ret = 3;
		break;
	case 'T':
		ret = 4;
		break;
	}
	return ret;
}


int translateStr(char buf[]){
	int sum = 0;
	int mult = 1;
	for(int i = 0; buf[i] != '\0'; i++){
		sum += translateChar(buf[i])*mult;
		mult *= 4;
	}
	return sum - 1;
}

int main(){

	int n;
	scanf("%d",&n);
	char order[ORDER_LENGTH],str[STR_LENGTH];

	char* check_table = new char[TABLE_SIZE];

	for(int i = 0; i < n; i++){
		scanf("%s %s",order,str);
		if(strcmp(order,"insert") == 0){
			check_table[translateStr(str)] = 'Y';
		}else{
			if(check_table[translateStr(str)] == 'Y'){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}

	//delete[] check_table;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define pb push_back
#define pc __builtin_popcount
#define pcll __builtin_popcountll
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
using namespace std;
ll n, k, up[200005][62];
int main() {
  speed;
  oprecision;
  // code
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> up[i][0];
  for (int j = 1; j <= 61; j++)
    for (int i = 1; i <= n; i++) up[i][j] = up[up[i][j - 1]][j - 1];
  int v = 1;
  while (k > 0) v = up[v][__lg(k & -k)], k &= (k - 1);
  cout << v;
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 100560
import java.util.Arrays;

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

			int n = scan.nextInt();
			int k = scan.nextInt();
			Integer[] a = new Integer [n];
			int iii = 0;
			int sum = 0;
			
			for (int i = 0 ; i < k ; i++) {
				int m = scan.nextInt();
				for(int ii = 0; ii < m ; ii++) {
					int b = scan.nextInt();
					if(Arrays.asList(a).contains(b)) {
						
					} else {
						a[iii] = b;
						iii++;
					}
				}
			}
		for (int i = 1; i <= n ; i++ ) {
			for (int ii = 0 ; ii < iii; ii++) {
				if(a[ii] == i) {
					break;
				} else if (ii == iii-1) {
					sum ++;
				}
			}
		}
		
		
		System.out.println(sum);
		
		
		}
	 
	}


Measured memory_bytes: 47344
n=int(input())
hoge=[]
for i in range(n):
  a,b=map(str,input().split())
  c=int(b)
  hoge.append([a,c,i+1])
hoge=sorted(hoge,key=lambda x:(x[1]),reverse=True)
hoge=sorted(hoge,key=lambda x:(x[0]),reverse=False)
for i in range(n):
  print(hoge[i][2])

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>

#define MAX 100005
int n;

// 1: ookami
int animal[MAX];

void answer(int pre,int next){
	cout<<(pre==0?'S':'W');
	cout<<(next==0?'S':'W');
	for(int i=1; i<n-1; i++){
		int tmp=next;
		if(next) next=animal[i]==1?pre:1-pre;
		else next=animal[i]==1?1-pre:pre;
		pre=tmp;
		cout<<(next==0?'S':'W');
	}
	cout<<en;
}

bool solve(int pre,int next){
	bool ok=true;
	int fir=pre,sec=next;
	for(int i=1; i<n; i++){
		int tmp=next;
		if(next) next=animal[i]==1?pre:1-pre;
		else next=animal[i]==1?1-pre:pre;
		pre=tmp;
		if(i==n-1){
			if(next!=fir) ok=false;
			int a=abs(pre-sec);
			if(fir) {if(animal[0]-a==0) ok=false;}
			else if(abs(animal[0]-a)==1) ok=false;
		}
	}
	if(ok){
		answer(fir, sec);
		return true;
	}else{
		return false;
	}
}

signed main(){
	cin>>n;
	for(int i=0; i<n; i++){
		char ch; cin>>ch;
		if(ch=='x') animal[i]=1;
	}
	for(int i=0; i<2; i++) for(int j=0; j<2; j++){
		if(solve(i, j)) return 0;
	}
	cout<<-1<<en;
}



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

 

int main()
{
   int a, b;     
   cin >> a >> b;
   
   if (a == b)
      cout << "a == b" << endl;
   else if(a > b)
      cout << "a > b" << endl;
   else
      cout << "a < b" << endl;
   
   return 0;
}


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

const double PI=acos(-1.0);

int main() {
    int n;
    int t[110000], x[110000], y[110000];
    cin >> n;
    t[0] = x[0] = y[0] = 0;
    rep(i, n) cin >> t[i + 1] >> x[i + 1] >> y[i + 1];

    bool can = true;
    rep(i, n) {
        int dt = t[i + 1] - t[i];
        int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        if(dt < dist) can = false;
        if(dist % 2 != dt % 2) can = false;
    }

    cout << (can ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
long long a[100010]={0,1,2,3,4,5,6,7,8,9}; 
int main()
{
	int k,id=1;scanf("%d",&k);
	for(int i=10; i<=k; )
	{
		long long x=a[id]*10,y=a[id++]%10;
		if(y==0) a[i++]=x,a[i++]=x+1;
		else if(y==9) a[i++]=x+8,a[i++]=x+9;
		else a[i++]=x+y-1,a[i++]=x+y,a[i++]=x+y+1;
	}
	printf("%lld\n",a[k]);
	return 0;
}


Measured memory_bytes: 2448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// 最大公約数を求める(ユークリッドの互除法).
long long gcd (long long x, long long y) {
  if (y > x) swap(x,y);
  if (y == 0) return x;
  return gcd(x%y,y);
}

int main() {
  int k;
  cin >> k;
  ll sum = 0;
  k ++;

  repr(i, k, 1) repr(j, k, 1) repr(l, k, 1) {

    sum += gcd(i, gcd(j, l));

  }

  cout << sum << endl;
}

Measured memory_bytes: 3636
N = gets.to_i
Ss = readlines.map(&:chomp)

a = %w(M A R C H).map{|c| Ss.count{|s| s[0] == c}}
puts [*0 .. 4].combination(3).inject(0){|s, c| s + c.map{|i| a[i]}.inject(:*)}

Measured memory_bytes: 16636
//
//  main.c
//  aoj_02
//
//  Created by k16031kk on 2018/05/17.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x;
    scanf("%d",&x);
    x=x*x*x;
    printf("%d\n", x);
    return 0;
}



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

using namespace std;
const int MAX = 100003;

int dp[MAX], h[MAX];

int main() {

    fill_n(dp, MAX, 1000000000);
    fill_n(h, MAX, 100000);

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n, k, i, j, lim, val;
    
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> h[i];
        
    dp[n] = 0;

    for(i = n; i > 0; --i){
        lim = i + k < n ? i + k : n;
        for(j = i + 1; j <= lim; ++j){
            val = dp[j] + abs(h[i] - h[j]);
            if(dp[i] > val)
                dp[i] = val;
        }
    }

    cout << dp[1] << "\n";

    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int a[40]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
void solve(){
	cin >> n;
	cout << a[n-1] << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< int > T(N + 2, 0);
	vector< int > V(N + 2);
	for (int i = 1; i <= N; i++) {
		cin >> T[i];
		T[i] += T[i - 1];
	}
	for (int i = 1; i <= N; i++)
		cin >> V[i];
	V[0] = V[N + 1] = 0;
	T[0] = 0;
	T[N + 1] = T[N] + 1;
	int TMAX2 = T[N] * 2;
	vector< double > minv(TMAX2 + 1, 1000);
	for (int i = 0; i <= N + 1; i++) {
		rep(t, minv.size()) {
			if (i == 0) {
				chmin(minv[t], t * 0.5);
			} else if (i == N + 1) {
				chmin(minv[t], (TMAX2 - t) * 0.5);
			} else {
				if (t * 0.5 < T[i - 1]) {
					chmin(minv[t], (double)T[i - 1] - (double)t * 0.5 + V[i]);
				} else if (t * 0.5 > T[i]) {
					chmin(minv[t], t * 0.5 - T[i] + V[i]);
				} else {
					chmin(minv[t], V[i]);
				}
			}
		}
	}
	double ans = 0.0;
	for (double t = 0; t < TMAX2; t += 1.0) {
		ans += (minv[t] + minv[t + 1]) * 0.25;
	}
	//cout << minv << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	ld r;
	cin>>r;
	
	cout<< fixed<< setprecision(20)<<2*PI*r;
	
}


signed main() 
{
	speed		
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 3800
//abc126_a.cpp
//Sat May 25 18:42:45 2019

#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
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	k--;
	for (int i=0;i<s.length();i++){
		if (i==k){
			if (s[i]=='A'){
				s[i] = 'a';
			} else if (s[i]=='B'){
				s[i] = 'b';
			}else if (s[i]=='C'){
				s[i] = 'c';
			}else if (s[i]=='a'){
				s[i] = 'A';
			}else if (s[i]=='b'){
				s[i] = 'B';
			}else if (s[i]=='c'){
				s[i] = 'C';
			}
		}
	}

	cout << s << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int N,A,i;
  int f=0;
  scanf("%d",&N);
  scanf("%d",&A);
  if(N%500<=A){
   printf("Yes\n");
   f=1;	 
  }
  
  if(f==0) printf("No\n");
  return 0;
}

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

class Program
{
    public static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }

    public void Exe()
    {
        int n = int.Parse(Console.ReadLine());
        int pay = 1000;
        int ans = n % pay == 0 ? 0 : pay - (n % pay);
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 27540
// ProblemURL : https://atcoder.jp/contests/abc072/tasks/abc072_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var x, t int
	fmt.Scan(&x, &t)
	rest := x-t
	if rest <0 {
		rest = 0
	}
	fmt.Println(rest)
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    cout << 180 * ( n - 2 ) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define resort(v) sort((v).rbegin(), (v).rend())
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
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 fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int modpow(int a, int n, int mod) {
    int hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

/*signed*/int main(void) {
    ll h, ans = 1;
    cin >> h;
    while (ans <= h) ans *= 2;
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;



int main() {
    ll n, u, v; cin >> n >> u >> v;
    vector<vector<ll> > G(n);
    ll a, b;
    for (ll i = 0; i < n-1; i++) {
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    queue<ll> q;
    ll *du = new ll[n];
    for (ll i = 0; i < n; i++)
        du[i] = -1;
    du[u-1] = 0;

    bool *check = new bool[n];
    check[v-1] = true;
    q.push(u-1);
    while (!q.empty()) {
        ll x = q.front();
        for (ll i = 0; i < G[x].size(); i++) {
            ll p = G[x][i];
            if (du[p] >= 0)
                continue;
            du[p] = du[x] + 1;
            q.push(p);
        }
        q.pop();
    }

    ll *dv = new ll[n];
    for (ll i = 0; i < n; i++)
        dv[i] = -1;
    dv[v-1] = 0;

    check[v-1] = true;
    q.push(v-1);
    while (!q.empty()) {
        ll x = q.front();
        for (ll i = 0; i < G[x].size(); i++) {
            ll p = G[x][i];
            if (dv[p] >= 0)
                continue;
            dv[p] = dv[x] + 1;
            q.push(p);
        }
        q.pop();
    }


    ll g = u-1;
    for (ll i = 0; i < n; i++) {
        if (G[i].size() == 1 && du[i] <= dv[i] && dv[i] > dv[g])
            g = i;
    }

    cout << dv[g] - 1 << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> p(26, 100);
    for (int i = 0; i < n; ++i) {
        vector<int> t(26);
        string s;
        cin >> s;
        for (char c : s) {
            ++t[c - 'a'];
        }
        for (int j = 0; j < 26; ++j) {
            p[j] = min(p[j], t[j]);
        }
    }
    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < p[i]; ++j) {
            cout << char('a' + i);
        }
    }
    return 0;
}

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

using namespace std;

int n, m;
vector<int> rst;
vector<vector<int>> mat;

int dfs(int s, int t) {
  if (s == n) return 1;
  if (t == n) return dfs(s + 1, 0);
  if (~mat[s][t]) return dfs(s, t + 1);

  int res = 0;
  if (rst[s] > 0) {
    rst[s]--;
    mat[s][t] = 1;
    mat[t][s] = 0;
    res += dfs(s, t + 1);
    mat[s][t] = -1;
    mat[t][s] = -1;
    rst[s]++;
  }
  if (rst[t] > 0) {
    rst[t]--;
    mat[t][s] = 1;
    mat[s][t] = 0;
    res += dfs(s, t + 1);
    mat[s][t] = -1;
    mat[t][s] = -1;
    rst[t]++;
  }
  return res;
}

int main() {
  while (cin >> n, n) {
    mat.assign(n, vector<int>(n, -1));
    cin >> m;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y, x--, y--;
      mat[x][y] = 1;
      mat[y][x] = 0;
    }
    for (int i = 0; i < n; i++) {
      mat[i][i] = -2;
    }

    bool ok = true;
    rst.assign(n, n / 2);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (mat[i][j] == 1) rst[i]--; 
      }
      if (rst[i] < 0) ok = false;
    }

    if (ok) {
      cout << dfs(0, 0) << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = static_cast<int>(1e5);
signed main()
{
  int n;
  cin >> n;
  vector<int> OC(MAX + 1), EC(MAX + 1);
  pair<int, int> o_max, o_sec_max, e_max, e_sec_max;
  o_max = o_sec_max = e_max = e_sec_max = make_pair(0, 0);
  for (int i = 0; i < n; ++i)
  {
    int tmpin;
    cin >> tmpin;
    if (i % 2)
    {
      //odd
      OC[tmpin]++;
      if (OC[tmpin] > o_max.second)
      {
        if (tmpin != o_max.first)
        {
          o_sec_max.second = o_max.second;
          o_sec_max.first = o_max.first;
          o_max.first = tmpin;
        }
        o_max.second = OC[tmpin];
      }
      else if (OC[tmpin] > o_sec_max.second)
      {
        if (tmpin != o_sec_max.first)
        {
          o_sec_max.first = tmpin;
        }
        o_sec_max.second = OC[tmpin];
      }
    }
    else
    {
      //even
      EC[tmpin]++;
      if (EC[tmpin] > e_max.second)
      {
        if (tmpin != e_max.first)
        {
          e_sec_max.second = e_max.second;
          e_sec_max.first = e_max.first;
          e_max.first = tmpin;
        }
        e_max.second = EC[tmpin];
      }
      else if (EC[tmpin] > e_sec_max.second)
      {
        if (tmpin != e_sec_max.first)
        {
          e_sec_max.first = tmpin;
        }
        e_sec_max.second = EC[tmpin];
      }
    }
  }
  if (o_max.first == e_max.first)
  {
    int ans1 = n / 2 - o_max.second + (n / 2 + n % 2) - e_sec_max.second;
    int ans2 = n / 2 - o_sec_max.second + (n / 2 + n % 2) - e_max.second;
    cout << min(ans1, ans2) << endl;
  }
  else
  {
    int ans = n / 2 - o_max.second + (n / 2 + n % 2) - e_max.second;
    cout << ans << endl;
  }
  //cout << "emax:" << e_max.first << endl;
  //cout << "omax:" << o_max.first << endl;
  //cout << "e2max:" << e_sec_max.first << endl;
  //cout << "o2max:" << o_sec_max.first << endl;
  return 0;
}

Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0
for i in range(n):
  if b[i]>=a[i]:
    b[i]-=a[i]
    sum+=a[i]
    a[i]=0
  else:
    sum+=b[i]
    a[i]-=b[i]
    b[i]=0
  if b[i]>=a[i+1]:
    b[i]-=a[i+1]
    sum+=a[i+1]
    a[i+1]=0
  elif b[i]>0:
    sum+=b[i]
    a[i+1]-=b[i]
    b[i]=0
print(sum)

Measured memory_bytes: 18396
#include <iostream>
#include <string>

using namespace std;

string report, actual;

int main()
{
    int ans = 0;
    cin >> report >> actual;
    for(int i = 0;i < 3;i++){
      if(report[i] == actual[i]){
        ans++;
      }
    }
    cout << ans;
    return 0;
}


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

int cnt[26];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int H, W;
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		string s;
		cin >> s;
		for(int j = 0; j < W; j++){
			cnt[s[j] - 'a']++;
		}
	}

	int need[5] = { 0 };
	need[4] = (H / 2) * (W / 2);
	if(H % 2){
		need[2] += W / 2;
	}
	if(W % 2){
		need[2] += H / 2;
	}
	if(H % 2 && W % 2){
		need[1]++;
	}

	bool ok = true;
	for(int i = 4; i >= 1; i--){
		for(int j = 0; j < 26; j++){
			if(cnt[j] >= i){
				int p = min(need[i], cnt[j] / i);
				need[i] -= p;
				cnt[j] -= p * i;
			}
		}
		if(need[i]) ok = false;
	}

	if(ok){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int n,m; cin >>n>>m;
    cout << (n-1)*(m-1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int N,M;
int C[20];
int X[20004];
const long long INF = 1000000000000;
long long dp[20004][260];
long long dfs(int i_,int y_) {
    if(i_ == N) return dp[i_][y_] = 0;
    if(dp[i_][y_]!=INF) return dp[i_][y_];

    long long ret = INF;

    rep(i,M) {
        int y = y_ + C[i];
        y = max(y,0);
        y = min(y,255);
        //cout<<y<<","<<X[i_]<<endl;
        ret = min(ret,dfs(i_+1,y)+(X[i_]-y)*(X[i_]-y));

    }
    //cout<<i_<<","<<y_<<","<<ret<<endl;
    return dp[i_][y_] = ret;

}
void solve() {
    rep(i,M) cin>>C[i];
    rep(i,N) cin>>X[i];
    /*
    ans = min(ans,dfs(0,128));
    */

    long long ans = INF;
    rep(i,20004) rep(j,260) dp[i][j] = INF;
    dp[0][128] = 0;
    rep(i,N) {
        rep(j,260) {
            rep(k,M) {
                int y = j + C[k];
                y = max(y,0);
                y = min(y,255);
                dp[i+1][y] = min(dp[i+1][y],dp[i][j]+(X[i]-y)*(X[i]-y));
            }
        }
    }
    rep(i,260) ans=min(ans,dp[N][i]);
    cout<<ans<<endl;

    rep(i,M) C[i] = 0;
    rep(i,N) X[i] = 0;

}
int main() {
    while(cin>>N>>M) {
        if(N+M==0) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 41868
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3616