akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n,m;
    cin >> n >> m;
    
    priority_queue<int> pq;

    rep(i,n) {
        int a;
        cin >> a;
        pq.push(a);
    }
    
    while(m) {
        int x = pq.top(); pq.pop();
        x /= 2;
        pq.push(x);
        m--;
    }
    
    ll sum = 0;
    while(pq.size()) {
        int x = pq.top(); pq.pop();
        sum += x;
    }
    cout << sum << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
int main(){
    string s;
    cin >> s;
    int n=s.size();
    ll dp[n+1][4];
    fill(dp[0],dp[n+1],0);
    dp[n][3] = 1;
    for(int i = n-1;i >= 0;i --){
        for(int j = 3;j >= 0;j --){
            if(j==3){
                if(s[i]=='?') dp[i][j] = 3*dp[i+1][j]%mod;
                else dp[i][j] = dp[i+1][j]%mod;
            }
            else{
                ll m1=1,m2=0;string abc="ABC";
                if(s[i]=='?') m1=3;
                if(s[i]=='?'||s[i]==abc[j]) m2=1;
                dp[i][j] = (m1*dp[i+1][j]+m2*dp[i+1][j+1])%mod;
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> cost(n), s(n), f(n);
    rep(i,n-1)cin>>cost[i]>>s[i]>>f[i];
    
    
    rep(p,n){
        int t = 0;
        for(int i=p;i<n-1;i++){
            if(t<=s[i]){
                t = s[i]+cost[i];
            }else{
                t = (t+f[i]-1)/f[i]*f[i];
                t += cost[i];
            }
        }
        cout<<t<<endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = (int)inputArray[0];
			var inputString = Console.ReadLine();

			var numList = new List<int>();

			foreach (var item in inputString) {
				numList.Add(int.Parse(item.ToString()));
			}
			//numListの数を1,2,3ではなく0,1,2にする
			var numArray = numList.Select(x => x - 1).ToArray();


			//まず偶奇を判断する
			var countComninationMod = new CountComninationMod(N);

			var oddCount = 0;
			for (int i = 0; i < N; i++) {

				var number = numArray[i];
				//偶数の場合は何もしない

				if (number % 2 ==0) {
					continue;
				}

				var toujoukaisu = countComninationMod.GetCombinatnionMod(i);
				oddCount += toujoukaisu;
			}

			//奇数の場合は1で終了
			if(oddCount %2 == 1) {
				Console.WriteLine(1);
				return;
			}

			//入力に1が含まれている場合は、2にならない。
			if (numArray.Contains(1)) {
				Console.WriteLine(0);
				return;
			}

			//偶奇判断と同じ考えで処理する
			var num2Count = 0;
			for (int i = 0; i < N; i++) {

				//0の場合は何もしない
				var number = numArray[i];
				if (number == 0) {
					continue;
				}

				var toujoukaisu = countComninationMod.GetCombinatnionMod(i);
				num2Count += toujoukaisu;
			}

			if(num2Count % 2 == 0) {
				Console.WriteLine(0);
				return;
			}

			Console.WriteLine(2);
			return;
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}

	/// <summary>
	/// n-1Cp を求めるためのクラス
	/// </summary>
	public class CountComninationMod {

		/// <summary>
		/// Nこの組み合わせ
		/// </summary>
		public int _N;
		
		/// <summary>
		/// i!が2で何回割り切れるかを保持する
		/// </summary>
		public readonly int[] _two;

		/// <summary>
		/// コンストラクタ
		/// </summary>
		/// <param name="n">n個の要素</param>
		public CountComninationMod(int n) {
			_N = n;

			_two = new int[n]  ;
			_two[0] = 0;

			for (int i = 1; i < _N; i++) {
				int cnt = 0;
				int t = i;
				while (t % 2 == 0) {
					cnt++;
					t /= 2;
				}

				_two[i] = _two[i - 1] + cnt;
			}

		}


		/// <summary>
		/// N-1こからp個を選んだ場合の組み合わせの数を,2で割ったあまりを返す
		/// </summary>
		/// <param name="p"></param>
		/// <returns></returns>
		public int GetCombinatnionMod(int p) {

			var cnt = _two[_N-1] - (_two[p] + _two[_N -1- p]);

			//分母と分子の2で割れる数が同じ=奇数
			if (cnt == 0) {
				return 1;
			}
			else {//分子の2で割れる数が分母より大きい=偶数
				return 0;
			}

		}


	}
}


Measured memory_bytes: 38056
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] a = new int[N];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
            if (a[i] > max) {
                max = a[i];
            }
            if (a[i] < min) {
                min = a[i];
            }
        }

        if (max - min > 1) {
            _out.println("No");
        } else if (max - min == 0) {
            if (max == N - 1 || 2 * max <= N) {
                _out.println("Yes");
            } else {
                _out.println("No");
            }
        } else {
            int x = 0;
            int y = 0;
            for (int i = 0; i < N; ++i) {
                if (a[i] == min) {
                    ++x;
                } else if (a[i] == max) {
                    ++y;
                }
            }
            if (x < max && 2 * (max - x) <= y) {
                _out.println("Yes");
            } else {
                _out.println("No");
            }
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

int h[2][11];
bool is_used[11];

void solve(int w, int d) {
    for (int i = 0; i < w; i++) cin >> h[0][i];
    for (int i = 0; i < d; i++) cin >> h[1][i];
    for (int i = 0; i < d; i++) is_used[i] = false;
    int ans = 0;
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < d; j++) {
            if (h[0][i] == h[1][j] && !is_used[j]) {
                is_used[j] = true;
                break;
            }
        }
        ans += h[0][i];
    }
    for (int i = 0; i < d; i++) {
        if (!is_used[i]) ans += h[1][i];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, D;
    while (true) {
        cin >> W >> D;
        if (W == 0 && D == 0) break;
        solve(W, D);
    }
    return 0;
}


Measured memory_bytes: 3116
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	static class Tuple {
		int h, w;

		Tuple(int h, int w) {
			this.h = h;
			this.w = w;
		}
	}

	int H, W, D;
	int[][] A;
	int Q;
	int[] L, R;
	int[] distMat;
	Map<Integer, Tuple> map;

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		H = Integer.parseInt(tokens[0]);
		W = Integer.parseInt(tokens[1]);
		D = Integer.parseInt(tokens[2]);
		A = new int[H][W];
		for (int i = 0; i < H; ++i) {
			tokens = in.readLine().split(" ");
			for (int j = 0; j < W; ++j) {
				A[i][j] = Integer.parseInt(tokens[j]) - 1;
			}
		}
		Q = Integer.parseInt(in.readLine());
		L = new int[Q];
		R = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			L[i] = Integer.parseInt(tokens[0]) - 1;
			R[i] = Integer.parseInt(tokens[1]) - 1;
		}
		map = new HashMap<>();
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				Tuple tuple = new Tuple(i, j);
				map.put(A[i][j], tuple);
			}
		}

		distMat = new int[H * W];
		for (int i = 0; i < D; ++i) {
			int prev = i;
			int next = i + D;
			distMat[i] = 0;

			while (next < H * W) {
				Tuple prevTuple = map.get(prev);
				Tuple nextTuple = map.get(next);
				distMat[next] = distMat[prev] + Math.abs(nextTuple.h - prevTuple.h)
						+ Math.abs(nextTuple.w - prevTuple.w);
				prev = next;
				next += D;
			}
		}
	}

	void calc() {
		for (int i = 0; i < Q; ++i) {
			int cost = distMat[R[i]] - distMat[L[i]];
			System.out.println(cost);
		}

	}

	void showResult() {
	}
}

Measured memory_bytes: 65256
#include <iostream>
#include<set>
#include<iterator>
#include <algorithm>
using namespace std;

int main() {
    
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    
    int xdiff = x2-x1;
    int ydiff = y2 - y1 ; 
    
    int x3 = x2 - ydiff;
    int y3  = y2 + xdiff;
    
    int x4 = x1 - ydiff;
    int y4 = y1 + xdiff;
    
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
    
	  
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

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

int main () {
  ll n, m;
  cin >> n >> m;
  
  ll m_left = m-2*n;
  cout << (2*n <= m ? n + m_left/4 : m/2) << endl;
}

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

int n,ans,cnt,flag;
int nx[N][N],ny[N][N];
int used[N][N];


void dfs(int y,int x){
  
  if(used[y][x]!=-1){
    
    if(used[y][x]!=cnt) flag=1;
    
    return ;
    
  }

  used[y][x]=cnt;
  
  dfs(ny[y][x],nx[y][x]);
  
}

int main(){

  while(1){
    
    cin>>n;

    if(!n) break;

    for(int i=0;i<n;i++)

      for(int j=0;j<n;j++) cin>>nx[i][j]>>ny[i][j];
	
    memset(used,-1,sizeof(used));

    ans=0;
    cnt=0;
    
    for(int i=0;i<n;i++){
      
      for(int j=0;j<n;j++){

	if(used[i][j]!=-1) continue;
	
	flag=0;
	
	dfs(i,j);
	
	if(!flag) ans++;
	
	cnt++;

      }
      
    }
    
    cout<<ans<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 3184
#include <stdbool.h>
#include <stdio.h>

#define MAX_N 100000

int main(void) {
    int n;
    char s[MAX_N + 2];

    scanf("%d\n", &n);
    fgets(s, MAX_N + 2, stdin);

    while (true) {
        int i = 0;
        int j = 0;
        while (i < n - 1) {
            if (s[i] == s[i+1]) {
                s[j] = s[i++];
                while (s[j] == s[i] && i < n - 1) {
                    i++;
                }
                j++;
            } else {
                s[j++] = s[i++];
            }
        }
        if (s[n-2] != s[n-1]) {
            s[j++] = s[i++];
        }
        if (j == n) {
            printf("%d\n", n);
            break;
        }
        n = j;

        // printf("%d, %d, %d\n", i, j, n);
    }

    return 0;
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
string X;
VI p,dp;

ll rec(ll n){
    if(dp[n] != -1) return dp[n];
    if(n == 0) return 0;

    ll nxt = n%p[n];
    ll ret = rec(nxt) + 1;
    return dp[n] = ret;
}

void Main(){
    cin >> N;
    p.resize(N+1,0); dp.resize(N+1,-1);

    REP(i,N){
        int k = 2*i;
        if(k <= N) p[k] = p[i];
        k = 2*i+1;
        if(k <= N) p[k] = p[i]+1;
    }

    cin >> X;
    ll k = 0;
    for(char c : X) if(c == '1') k++;

    if(k == 1 && X.back() == '1'){
        REP(i,N-1){
            cout << 2 << en;
        }
        cout << 0 << en;
        return;
    }
    else if(k == 1 && X.back() == '0'){
        REP(i,N-1){
            if(X[i] == '0') cout << 1 << en;
            else cout << 0 << en;
        }
        cout << 2 << en;
        return;
    }
    else if(k == 0){
        REP(i,N) cout << 1 << en;
        return;
    }

    REVERSE(X);
    ll Xmod1=0, Xmod2=0;
    vector<ll> b1(N+1,1), b2(N+1,1);
    REP(i,N) b1[i+1] = (b1[i]*2) % (k-1);
    REP(i,N) b2[i+1] = (b2[i]*2) % (k+1);
    REP(i,N){
        if(X[i] == '1'){
            (Xmod1 += b1[i]) %= (k-1);
            (Xmod2 += b2[i]) %= (k+1);
        }
    }

    VL ans(N);
    REVERSE(X);

    REP(i,N){
        if(X[i] == '1'){
            ll n = Xmod1 - b1[N-1-i];
            if(n<0) n += k-1;
            ans[i] = rec(n) + 1;
        }
        else{
            ll n = (Xmod2 + b2[N-1-i])%(k+1);
            ans[i] = rec(n) + 1;
        }
        cout << ans[i] << en;
    }
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

using namespace std;

int main(){
  int n, x, t;
  int a, count = 0;
  
  cin >> n >> x >> t;
  
  if(n % x == 0)
  	cout << (n / x) * t << endl;
  else
    cout << (n / x + 1) * t << endl;
  
  return 0;
}

Measured memory_bytes: 3632
'use strict';
const main = input => {
  const nums = input[0].split(' ').map(val => parseInt(val));
  const h = nums[0], n = nums[1];
  let a = input[1].split(' ').map(val => parseInt(val));
  const sum = a.reduce((prev, current) => prev + current);
  console.log(h<=sum?'Yes':'No');
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

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

int main() {
    int n,w[1000],sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>w[i];
        sum +=w[i];
    }
    int m=10000000,tsum=0;
    for(int i=0;i<n;i++)
    {
        tsum +=w[i];
        sum = sum-w[i];
        int d = abs(sum-tsum);
        if(m>d)
        {
            m = d;
        }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
	int i,j,k,H,W;
	for (i=1;1;i++) {
		cin>>H>>W;
		if (H==0&&W==0) 
			break;
		for (k=0;k<H;k++) {
			for (j=0;j<W/2;j++) {
				if (k%2==0) cout<<"#.";
				if (k%2==1) cout<<".#";
			} 
			if (W%2==1 && k%2==0) cout<<"#";
			if (W%2==1 && k%2==1) cout<<".";
			cout<<endl;
		}
	cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<assert.h>

#define MAX_V 201
#define MAX_E 10001
#define TRUE 1
#define FALSE 0
#define UNUSED -1

int N, K, E; // E : the number of edges
int graph[MAX_V][MAX_E], size[MAX_V], match[MAX_V], used[MAX_V];

void add_edge(int s,int t) {
  graph[s][size[s]++] = t;
  graph[t][size[t]++] = s;
}

int dfs(int cur) {
  used[cur] = TRUE;
  int i, next, state;
  for(i=0;i<size[cur];++i) {
    next = graph[cur][i], state = match[next];
    if( state == UNUSED || ( !used[state] && dfs(state) ) ) {
      match[cur] = next;
      match[next] = cur;
      return TRUE;
    }
  }
  return FALSE;
}

int bmatch() {
  memset(match,UNUSED,sizeof match);
  int i, answer = 0;
  for(i=0;i<N;++i) {
    if( match[i] == UNUSED ) {
      memset(used, FALSE, sizeof used);
      if( dfs(i) ) {
	++answer;
      }
    }
  }
  return answer;
}

int main() {
  int i,s,t;
  scanf("%d %d %d",&N,&K,&E);
  assert( N+K < MAX_V);
  assert( E < MAX_E );
  for(i=0;i<E;i++) {
    scanf("%d %d",&s,&t);
    assert( 0 <= s && s < N );
    assert( 0 <= t && t < K );
    add_edge(s,N+t);
  }
  int maxi = bmatch();
  //printf("answer = %d\n",maxi);
  printf("%d\n",maxi);
  return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	int ans = 0;
	int cntba = 0, cnta = 0, cntb = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (int)s[i].size() - 1; j++) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++;
		}
		if (s[i][0] == 'B' && s[i].back() == 'A') cntba++;
		else if (s[i][0] == 'B') cntb++;
		else if (s[i].back() == 'A') cnta++;
	}
	if (cntba > 0) ans += cntba - 1;
	if (cntba > 0 && cnta > 0) ans++, cnta--;
	if (cntba > 0 && cntb > 0) ans++, cntb--;
	ans += min(cnta, cntb);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

int main()
{
    ll n;
    cin >> n;
    int num;
    num = sqrt(n);
    int ans = 0;
    

    for (int i = num+1; i > 0; i--)
    {
        if (n%i == 0)
        {
            n = n/i;
            ans = i;
            break;
        }else if(i == 1)
        {
            ans = i;
        }
    }
    
    cout << n+ans-2<< endl;
}

Measured memory_bytes: 256
class PotentialUnionFind
  def initialize(n)
    @size = Array.new(n + 1, 1)
    @rank = Array.new(n + 1, 0)
    @diff_weight = Array.new(n + 1, 0)
    @parent = []

    (0..n).each do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      root = find(@parent[x])
      @diff_weight[x] += @diff_weight[@parent[x]]
      @parent[x] = root
    end
  end

  def unite(x, y, w)
    w += weight(x)
    w -= weight(y)
    x = find(x)
    y = find(y)
    return false if x == y

    if @rank[x] < @rank[y]
      @diff_weight[x] = -w
      @parent[x] = y
    else
      @parent[y] = x
      @diff_weight[y] = w

      @rank[x] += 1 if @rank[x] == @rank[y]
    end

    @size[x] += @size[y]
  end

  def weight(x)
    find(x)
    @diff_weight[x]
  end

  def diff(x, y)
    weight(y) - weight(x)
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

n, m = gets.strip.split.map(&:to_i)
lrd = readlines.map {|line| line.split.map(&:to_i) }

wuf = PotentialUnionFind.new(n)

lrd.each do |l, r, d|
  if wuf.same?(l, r)
    if wuf.diff(l, r) != d
      puts 'No'
      exit
    end
  else
    wuf.unite(l, r, d)
  end
end

puts'Yes'


Measured memory_bytes: 34940
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <climits>
#include <iomanip>
 
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
 
	int x, a, b;
	cin >> x >> a >> b;

	cout << (abs(a - x) < abs(b - x) ? 'A' : 'B') << endl;

	return 0;
}

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

const int N = 3e3 + 100;
const int MOD = 1e9 + 7;

int n, m;

void init() {
	std::cin >> n >> m;
}

void work() {
	static int f[2][N][2];

	std::memset(f, 0, sizeof(f));
	for (int i = 0; i <= n; i++) {
		f[0][i][i == 0] = 1;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= 1; k++) {
				f[1][j][k] = 0;
			}
		}
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= 1; k++) {
				// red
				if (j != 0) {
					f[1][j][k | ((j - 1) == 0)] += f[0][j][k];
					f[1][j][k | ((j - 1) == 0)] %= MOD;
				}
				// blue
				if (j != n) {
					f[1][j + 1][k] += f[0][j][k];
					f[1][j + 1][k] %= MOD;
				}
			}
		}
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= 1; k++) {
				f[0][j][k] = 0;
			}
		}
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= 1; k++) {
				if (j != 0) {
					f[0][j - 1][k] += f[1][j][k];
					f[0][j - 1][k] %= MOD;
				}
				if (j != n + 1) {
					f[0][j][k] += f[1][j][k];
					f[0][j][k] %= MOD;
				}
			}
		}
	}
	int answer = 0;
	for (int i = 0; i <= n; i++) {
		answer += f[0][i][1];
		answer %= MOD;
	}
	std::cout << answer << std::endl;
}

int main() {
	init();
	work();

	return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())

if x == 1 or x == 2*n-1:
    print('No')
else:
    print('Yes')
    m = n + 1
    l = n - 1
    a = [i+1 for i in range(2*n-1)]
    a[x-1] = a[n-1]
    a[n-1] = x
    if x < n:
        a[0] = a[n-2]
        a[n-2] = 1
        if n >= 3:
            a[2*n-2] = a[n-3]
            a[n-3] = 2*n-1
    else:
        a[2*n-2] = a[n]
        a[n] = 2*n-1
        if n >= 3:
            a[0] = a[n+1]
            a[n+1] = 1
    for i in range(2*n-1):
        print(a[i])

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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define F first
#define S second
#define ALL(v) (v).begin(),(v).end()

typedef pair<int,int> pii;
typedef vector<int> vint;

int main(){
	int n;
	while(cin>>n,n){
		vector<pii> v(n);
		rep(i,n) cin>>v[i].F>>v[i].S;
		sort(ALL(v));
		int sum = 0;
		rep(i,n) sum+=v[i].F;
		if(sum>=2*v.back().F){
			rep(i,n) sum+=v[i].S;
			cout<<sum<<endl;
		}
		else{
			int t = v.back().F-(sum-v.back().F);
			assert(t<1010);
			vint dp(1010,0);
			dp[0]=1;
			rep(i,n-1){
				for(int j=1010-1;j>=0;j--){
					if(j-v[i].S<0) break;
					if(dp[j-v[i].S]) dp[j]=1;
				}
			}
			rep(i,n) sum+=v[i].S;
			sum+=t;
			while(1){
				if(dp[t]){
					cout<<sum-t<<endl;
					break;
				}
				t--;
			}
		}
	}
}

Measured memory_bytes: 3108
#include <queue>
#include <vector>
#include <iostream>
#include <functional>
#include <string>

using namespace std;
int main() {
    int h,w,n;
    cin>>h>>w>>n;
    if (n%max(h,w)==0)
        cout<<n/max(h,w)<<endl;
    else
        cout<<1+n/max(h,w)<<endl;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
c = s.count('A')
if c == 0 or c == n:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 38384
s = input()
n = len(s)
if s != s[::-1]:
	print ("No")
	exit()
if s[:n//2] != s[:n//2][::-1]:
	print ("No")
	exit()
if s[(n+3)//2-1:] != s[(n+3)//2-1:][::-1]:
	print ("No")
	exit()
print ("Yes")

Measured memory_bytes: 3064
import sys
import math
import itertools
#n=int(input())
def isLoop(s):
    if (s[0] == s[-1] and s[1] == s[-2]):
        return True
    else:
        return False
a, b = map(int, input().split())
ans=0
for i in range(a, b + 1):
    if (isLoop(str(i))):
        ans += 1
print(ans)

Measured memory_bytes: 3060
from sys import stdin
import math
import fractions
import heapq

r = stdin.readline().rstrip()

for i in range(2 ** 3):
    op = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            op[2 - j] = "+"
    ss = r[0] + op[0] + r[1] + op[1] + r[2] + op[2] + r[3]
    if eval(ss) == 7:
        print(ss + "=7")
        break

Measured memory_bytes: 5048
def solve(n, a, b):
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        # straight_win
        case_1 = a + (b - a - 1) // 2
        # straight_lose
        case_2 = (n - b + 1) + (b - a - 1) // 2
        return min(case_1, case_2)


def main():
    n, a, b = map(int, input().split())
    res = solve(n, a, b)
    print(res)


def test():
    assert solve(5, 2, 4) == 1
    assert solve(5, 2, 3) == 2


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld",&n);

    long count = 0;
    long i;
    for(i=0; i<n; i++) {
        long a;
        scanf("%ld",&a);
        if(a%2==0) {
            count ++;
        }
    }
    if (count==n) {
        printf("second\n");
    }
    else {
        printf("first\n");
    }


	return 0;
}



Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int x1, y1, x2, y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<x2+y1-y2<<' '<<y2-x1+x2<<' '<<x1+y1-y2<<' '<<y1-x1+x2<<endl;
    return 0;
}


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

int main(){
    long long k, a, b;
    cin >> k >> a >> b;
    if(a < b){
        if(k <= a-1){
            printf("%lld\n", k+1);
            return 0;
        }
        else{
            if(b - a <= 1){
                printf("%lld\n", 1+k);
                return 0;
            }
            
            long long exchange = (k-(a-1))/2;
            long long clap = k-(a-1) - 2*exchange;
            printf("%lld\n", a+exchange*(b-a)+clap);
            return 0;
        }
    }
    else{
        printf("%lld\n", 1+k);

        return 0;
    }
}

Measured memory_bytes: 256
// Rustで競技プログラミングの入力をスッキリ記述するマクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

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

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

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

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

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

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

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

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

fn f(n: u32) -> u32 {
    if n % 2 == 0 {
        n / 2
    } else {
        3 * n + 1
    }
}

use std::collections::HashSet;

fn solve(s: u32) {
    let mut m = HashSet::new();
    let mut i = 2;
    m.insert(s);
    let mut s = s;
    loop {
        let a_i = f(s);
        if let Some(_) = m.get(&a_i) {
            println!("{}", i);
            break;
        } else {
            m.insert(s);
            i += 1;
            s = a_i;
        }
    }
}

fn main() {
  input! {
      s: u32
  }
  solve(s)
}


Measured memory_bytes: 4476
#include<iostream>
using namespace std;
int main(){
    int n,a,b;
    cin >> n >> a >>b;
    int ans =0;
    for(int i=1;i<=n;i++){
        int digit = 0;
        int num = i;
        while(num!=0){
            digit += num%10;
            num /= 10;
        }
        if(digit>= a&&digit <= b){
            ans +=i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n = 3;
	while(n--){
		int a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		if((f -= c) < 0){ e--; f += 60; }
		if((e -= b) < 0){ d--; e += 60; }
		d -= a;
		cout << d << " " << e << " " << f << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>

using namespace std;

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

int nowmasu[1100][1100];
int nokori[1100][1100];

int main(){
	while(1){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(a==0)break;
		
		rep(i,1100)rep(j,1100)nowmasu[i][j]=nokori[i][j]=0;
		
		rep(i,a){
			rep(j,b){
				scanf("%d",&nowmasu[i][j]);
			}
		}
		
		nokori[0][0]=c-1;
		
		rep(i,a){
			rep(j,b){
				int e,f;
				e = nokori[i][j]/2 + nokori[i][j]%2;
				f = nokori[i][j]/2;
				
				if(nowmasu[i][j]==1){
					nokori[i][j+1] += e;
					nokori[i+1][j] += f;
				}else{
					nokori[i+1][j] += e;
					nokori[i][j+1] += f;
				}
				
				nowmasu[i][j] = (nowmasu[i][j]+nokori[i][j])%2;
			}
		}
		
		int py=0,px=0;
		while(1){
			if(py>=a || px>=b)break;
			if(nowmasu[py][px] == 1)px++;
			else py++;
		}
		
		printf("%d %d\n",py+1,px+1);
	}
}

Measured memory_bytes: 9000
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_T _DEF(T,in,){return in<T>(gcu());}
_DEF(int,in,){return in<int>(gcu());}
struct _IN{inline operator int(){return in();}}IN;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	outl(in() + in() + in());
}



Measured memory_bytes: 2512
#include <iostream>

using namespace std;
int main()
{
	int s,a,b,c,w,d;
	cin>>s;
	a=s/(60*60);
	s=s%(60*60);
	b=s/60;
	c=s%60;
	cout<<a<<":"<<b<<":"<<c<<endl;
	
   return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



int main(){
    int n,a ,b;
    cin >> n >> a >> b;

    cout << min(n*a , b) << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

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

    int count = 0;

    do {
        if (vec[0] != 0) continue;
        bool can = true;
        for (int i = 1; i < N; i++) {
            bool ok = false;
            for (int j = 0; j < G[vec[i-1]].size(); j++) {
                if (G[vec[i-1]][j] == vec[i]) ok = true;
            }
            if (!(ok)) can = false;
        }
        if (can) count ++;
    } while(next_permutation(vec.begin(), vec.end()));

    cout << count << endl;
    return 0;
}

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

using namespace std;

int main() {
	char cube[6][8] = {{'.', '.', 'r', 'r', '.', '.', '.', '.'},
					   {'.', '.', 'r', 'r', '.', '.', '.', '.'},
					   {'g', 'g', 'y', 'y', 'b', 'b', 'w', 'w'},
					   {'g', 'g', 'y', 'y', 'b', 'b', 'w', 'w'},
					   {'.', '.', 'o', 'o', '.', '.', '.', '.'},
					   {'.', '.', 'o', 'o', '.', '.', '.', '.'}};
	string a;
	cin >> a;
	char kari, kari2;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'U') {
			kari = cube[2][0];
			kari2 = cube[2][1];
			for (int j = 0; j < 6; j++) {
				cube[2][j] = cube[2][j+2];
			}
			cube[2][6] = kari;
			cube[2][7] = kari2;
			kari = cube[0][3];
			cube[0][3] = cube[0][2];
			cube[0][2] = cube[1][2];
			cube[1][2] = cube[1][3];
			cube[1][3] = kari;
		} else if (a[i] == 'D') {
			kari = cube[3][6];
			kari2 = cube[3][7];
			for (int j = 7; j > 1; j--) {
				cube[3][j] = cube[3][j-2];
			}
			cube[3][1] = kari2;
			cube[3][0] = kari;
			kari = cube[4][2];
			cube[4][2] = cube[5][2];
			cube[5][2] = cube[5][3];
			cube[5][3] = cube[4][3];
			cube[4][3] = kari;
		} else if(a[i] == 'L') {
			kari = cube[4][2];
			kari2 = cube[5][2];
			for (int j = 5; j > 1; j--) {
				cube[j][2] = cube[j-2][2];
			}
			cube[1][2] = cube[2][7];
			cube[0][2] = cube[3][7];
			cube[2][7] = kari2;
			cube[3][7] = kari;
			kari = cube[2][0];
			cube[2][0] = cube[3][0];
			cube[3][0] = cube[3][1];
			cube[3][1] = cube[2][1];
			cube[2][1] = kari;
		} else if (a[i] == 'R') {
			kari = cube[0][3];
			kari2 = cube[1][3];
			for (int j = 0; j < 4; j++) {
				cube[j][3] = cube[j+2][3];
			}
			cube[4][3] = cube[3][6];
			cube[5][3] = cube[2][6];
			cube[2][6] = kari2;
			cube[3][6] = kari;
			kari = cube[2][4];
			cube[2][4] = cube[3][4];
			cube[3][4] = cube[3][5];
			cube[3][5] = cube[2][5];
			cube[2][5] = kari;
		} else if (a[i] == 'F') {
			kari = cube[2][2];
			cube[2][2] = cube[3][2];
			cube[3][2] = cube[3][3];
			cube[3][3] = cube[2][3];
			cube[2][3] = kari;
			kari = cube[2][1];
			kari2 = cube[3][1];
			cube[2][1] = cube[4][2];
			cube[3][1] = cube[4][3];
			cube[4][2] = cube[3][4];
			cube[4][3] = cube[2][4];
			cube[2][4] = cube[1][2];
			cube[3][4] = cube[1][3];
			cube[1][2] = kari2;
			cube[1][3] = kari;
		} else if(a[i] == 'B'){
			kari = cube[2][6];
			cube[2][6] = cube[3][6];
			cube[3][6] = cube[3][7];
			cube[3][7] = cube[2][7];
			cube[2][7] = kari;
			kari = cube[2][5];
			kari2 = cube[3][5];
			cube[2][5] = cube[5][3];
			cube[3][5] = cube[5][2];
			cube[5][2] = cube[2][0];
			cube[5][3] = cube[3][0];
			cube[2][0] = cube[0][3];
			cube[3][0] = cube[0][2];
			cube[0][2] = kari;
			cube[0][3] = kari2;
		}
	}
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 8; j++) {
			cout << cube[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char s[4];
  cin >> s;
  for (int i = 1; i < 4; i++)
  {
    char c = s[i];
    if (c == s[i - 1])
    {
      puts("Bad");
      return 0;
    }
  }
  puts("Good");
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Triangle
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            double[] num = new double[3];

            for (int i = 0; i < 3; i++)
            {
                num[i] = double.Parse(input[i]);
            }

            double h = Math.Sin(num[2] * (Math.PI / 180)) * num[1];
            double s = h * num[0] / 2;
            double l = num[0] + num[1] + Math.Sqrt(Math.Pow((num[0]-Math.Cos(num[2] * (Math.PI / 180)) * num[1]), 2) + Math.Pow(h, 2));

            Console.WriteLine("{0:f8}",s);
            Console.WriteLine("{0:f8}", l);
            Console.WriteLine("{0:f8}", h);
        }
    }
}



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

// {{{
#define PI pair<int, int>
#define mk make_pair
#define reg register
#define ll long long
#define rep(i, a, b) for(reg int i = a; i <= b; ++i)
#define per(i, a, b) for(reg int i = a; i >= b; --i)
// }}}

using namespace std;

inline int min(reg int a, reg int b) { return a < b ? a : b; }
inline int max(reg int a, reg int b) { return a > b ? a : b; }
inline int read() {
  reg int s = 0; reg char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s;
}

int a[1001];

int main() {
  int n = read(), x = read();
  rep (i, 1, n) a[i] = read();
  int ans = 0;
  rep (i, 1, n) {
    a[i] += a[i - 1];
    if (a[i] <= x) ans++;
  }
  if (0 <= x) ans++;
  cout << ans << endl;
  return 0; 
}


/*******************************************
 _________________________________________
< B.cpp is created by zrz who is weak >
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
********************************************/

Measured memory_bytes: 256
def solve():
    M = int(input())
    d, c = [0] * M, [0] * M
    for i in range(M):
        d[i], c[i] = map(int, input().split())
    
    sum_d = 0
    for i in range(M):
        sum_d += d[i] * c[i]
    sum_c = sum(c)
    ans = (sum_c - 1) + (sum_d - 1) // 9
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 12404
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n, W;
    cin >> n >> W;
    vector<int> v(n + 1), w(n + 1);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i + 1] >> w[i + 1];
    }
    vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if (j - w[i] < 0)
            {
                dp[i][j] = dp[i - 1][j];
                continue;
            }
            dp[i][j] = max(dp[i - 1][j], dp[i][j - w[i]] + v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 6844
#include <bits/stdc++.h>
    using namespace std;
    #define all(x) (x).begin(), (x).end()
    #define SZ(X) ((int)(X).size())
    #define mod 10000007
    #define endl "\n"
    typedef unsigned long long ull;
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        // freopen("input.txt", "r", stdin);
        int l,n,m=0,sum=0;;
        cin>>n;
        for (int i = 0; i < n; i++)
        {
            cin>>l;
            m=max(m,l);
            sum+=l;
        }
         
        if(m<sum-m) cout<<"Yes"<<endl; else cout<<"No"<<endl;
        return 0;

    }



Measured memory_bytes: 3624
# abc173_c.py
H,W,K = map(int,input().split())
glid = [[] for i in range(H)]
for i in range(H):
    glid[i]=list(input())
import itertools
status = [(0, 1) for _ in range(H)]
h_state = list(itertools.product(*status))
status = [(0, 1) for _ in range(W)]
w_state = list(itertools.product(*status))
ans = 0
for h_case in h_state:
    for w_case in w_state:
        nglid = [[False]*W for _ in range(H)]
        for hidx,h in enumerate(h_case):
            for widx,w in enumerate(w_case):
                if h!=1:
                    nglid[hidx][widx] = True
                if w!=1:
                    nglid[hidx][widx] = True
        black = 0

        cnt=0
        for i in range(H):
            for j in range(W):
                if glid[i][j]=="#" and not nglid[i][j]:
                    cnt+=1
        if cnt==K:
            ans+=1

print(ans)

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x=0;
  cin>>n;
  long long a[n],min=LLONG_MAX,sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<0){
        a[i]*=-1;x++;
    }
    if(a[i]<min){
        min=a[i];
    }
    sum+=a[i];
  }
  if(x%2==0){cout<<sum;}
  else{cout<<sum-2*min;}
  return 0;
}


Measured memory_bytes: 1024
let N = (Int)(readLine()!)!;
var maximum = 0;
var secondMaximum = 0;
var count: Array<Int> = Array(repeating: 0, count: 200020);
var A: Array<Int> = Array(repeating: 0, count: 200020);
for i in 0 ..< N {
    let a = (Int)(readLine()!)!;
    A[i] = a;
    if a > maximum {
        secondMaximum = maximum;
        maximum = a;
    }
    else if a > secondMaximum {
        secondMaximum = a;
    }
    count[a] += 1;
} 
for i in 0 ..< N {
    if A[i] != maximum {
        print(maximum);
    }
    else if A[i] == maximum && count[A[i]] == 1 {
        print(secondMaximum);
    }
    else {
        print(maximum);
    }
}

Measured memory_bytes: 10880
N,M,Q = map(int,input().split())
A = [0]*Q
B = [0]*Q
C = [0]*Q
D = [0]*Q
for i in range(Q):
    A[i],B[i],C[i],D[i] = map(int,input().split())

from itertools import combinations_with_replacement as comb_rplc
answer = 0

for seq in comb_rplc(range(1,M+1),N):
    candi = 0
    
    for i in range(Q):
        if seq[B[i]-1]-seq[A[i]-1] == C[i]:
            candi += D[i]
    answer = max(candi,answer)
print(answer)

Measured memory_bytes: 73680
#include<iostream>
using namespace std;
int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  for(int i=0; i<3; i++){
    for(int j=i+1; j<3; j++){
      if(A[i] > A[j]){
        int tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }
  int ans1 = abs(A[0]-A[1]);
  int ans2 = abs(A[1]-A[2]);
  cout << ans1 + ans2 << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int cnt = 0, check = 0;
int main() {
	char temp;
	for (int i = 0; i < 3; i++) {
		cin >> temp;
		if (temp == 'R') {
			cnt++;
		}
		else {
			if (cnt > check)check = cnt;
			cnt = 0;
		}
	}
	if (cnt != 0) check = cnt;
	cout << check;
}

Measured memory_bytes: 3616