akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <cassert>
#include <time.h>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>
#define print_time()cout<<clock()/CLOCKS_PER_SEC<<" s"<<endl;

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//  std::ios::sync_with_stdio(false);
//  std::cin.tie(NULL);
//  return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


struct aa {
	int a, b;
	bool operator<(const aa& rhs)const {
		if (b == rhs.b)return a < rhs.a;
		return b < rhs.b;
	}
}rifa[100010];
priority_queue<aa>q;
bool cmp(aa a, aa b) {
	return a.a < b.a;
}
int main() {
	IOS;
	int n, m; cin >> n >> m;
	repi(0, n) {
		cin >> rifa[i].a >> rifa[i].b;
	}
	sort(rifa, rifa + n, cmp);
	int ans = 0, c = 0, p = 0;
	repi(0, m) {
		while (p<n && rifa[p].a <= i + 1)q.push(rifa[p++]);
		if (q.empty())continue;
		aa tmp = q.top(); q.pop();
		if (tmp.a <= i + 1)ans += tmp.b;
		else break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2168
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cA = Counter(A)
mod = pow(10,9)+7
ans = pow(2,n//2)
for i in range(n//2+n%2):
    if i==0 and n%2==1:
        if cA[0] !=1:
            ans = 0
            break
    elif cA[2*i+1-n%2]!=2:
        ans = 0
        break
print(ans%mod)

Measured memory_bytes: 20552
#include <iostream>
#include <algorithm> 
#include <vector>
#include <string>
#include <map>
#include <math.h>
 
using namespace std;
using ll = long long int;
 
ll n, k;
 
ll calcBit(ll target)
{
  ll count = 1;
  while(target > 1)
  {
    target /= 2;
    count++;
  }
  return count;
}
 
ll calcCount(vector<ll> &x, ll offset, ll target)
{
  ll count = 0;
  ll index = 1ll << offset;
  for(ll i = 0; i < x.size(); i++)
  {
    if(x[i] & index)
    {
      count++;
    }
  }
  if(target == 0)
  {
    return x.size() - count;
  }else{
    return count;
  }
}
 
void dfs(vector<vector<ll>> &dp, vector<vector<bool>> &flag, vector<ll> x, ll index, int smaller)
{
  /*
   * 桁DP用のDFS関数
   * smaller=0のときkに忠実に探索
   * samller=1のとき以降どんな値でも良い
   * indexは桁数
   */
  //最初に到達済みか判断
  //到達済みならdp[index][smaller]の値を返す
  if(flag[index][smaller]) return;
  flag[index][smaller] = true; 
  //0,1の増加分を計算
  ll count0 = calcCount(x, index, 0);
  ll count1 = calcCount(x, index, 1);
  ll plus0 = count1 << index;
  ll plus1 = count0 << index;
  //index == 0のときはdfsを呼ばずに結果を返す
  ll result = 0; 
  if(index == 0){
    if(smaller == 0)
    {
      //忠実なので自身の桁を選んだ増加分を返す
      if(k & (1ll << index))
      {
        result = max(plus1, plus0);
      }else{
        result = plus0;
      }
    }else{
      //自由なのでplus0とplus1の大きい方を返す
      result = max(plus0, plus1);
    }
    dp[index][smaller] = result;
    //cout << "index = " << index << " smaller = " << smaller << " result = " << result << endl;
    return;
  }
  //忠実に探索するパターンと自由に探索するパターンを呼び出し
  dfs(dp, flag, x, index - 1, 0);
  dfs(dp, flag, x, index - 1, 1); 
  //dpの更新 
  if(smaller == 0)
  {
    //exactly -> smaller
    //忠実から自由なので1桁小さいsmallerに今の桁の数字を選んだときの増加分を足す
    if(k & (1ll << index))
    {
      result = max(result, dp[index - 1][1] + plus0);
    }
    //exactly -> exactly
    //忠実から忠実なので1桁小さいexactlyに今の桁の数字を選んだときの増加分を足す
    if(k & (1ll << index))
    {
      result = max(result, dp[index - 1][0] + plus1);
    }else{
      result = max(result, dp[index - 1][0] + plus0);
    }
  }else{
    //smaller -> smaller
    //自由に配置できるため1桁小さいsmallerにplus0とplus1の大きい方を足す
    result = max(result, dp[index - 1][1] + max(plus0, plus1));
  }
  dp[index][smaller] = result;
  //cout << "index = " << index << " smaller = " << smaller << " result = " << result << endl;
}
 
int main()
{
  cin >> n >> k;
  vector<ll> x(n);
  for(int i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  //桁をDFSしながら辿っていく
  ll bits = calcBit(k);
  vector<vector<ll>> dp(41, vector<ll>(2, 0));
  vector<vector<bool>> flag(41, vector<bool>(2, false));
  dfs(dp, flag, x, 40, 0);
  cout << dp[40][0] << endl;
}


Measured memory_bytes: 33152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

int main()
{
  ll k;
  cin >> k;
  if (k % 2 == 0)
  {
    cout << "-1" << endl;
    return 0;
  }
  ll a = 7;
  for (int i = 0; i <= k; ++i)
  {
    a %= k;
    if (a == 0)
    {
      cout << i + 1 << endl;
      return 0;
    }
    a = a * 10 + 7;
  }
  cout << "-1" << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

;;
;
bool func(int i){;;
    int cnt = 0;;
    if(1<i){;
    for(int j = 1; j <= i; ++j){;;;
        if(i%j==0) {;++cnt;};
    }
;}
else {;
    for(int j = 1; j >= i; --j){;;;
        if(i%j==0) {;++cnt;};
    }
;};;;;
    if(cnt==8) {;return true;}
    else {;return false;};
};
int main(){
  ;;
    int n;
    cin >> n;
    ;
    int ans = 0;;
    ;
    for(int i= 1; i <= n; i += 2){;;
        if(func(i)) {;++ans;;};
    };;
    cout << (ans) << endl;;
}

Measured memory_bytes: 256
N = int(input())
def gcd(x, y):
  k, l = x, y
  while l:
    k, l = l, k % l
  return k
def factorization(n):
  a = n
  p = 2
  D = {}
  while a != 1:
    cnt = 0
    while a % p == 0:
      cnt += 1
      a //= p
    if cnt:
      D[p] = cnt
    p += 1
    if p * p > n and a != 1:
      D[a] = 1
      break
  return D
X = factorization(2*N)
F = {1}
for i in X:
  tmp = set()
  for j in F:
    tmp.add(j)
    p = j
    for k in range(X[i]):
      tmp.add(p*i)
      p *= i
  for j in tmp:
    F.add(j)
def extgcd(a, b, c):
  x, y, u, v, k, l = 1, 0, 0, 1, a, b
  while l:
    x, y, u, v, k, l = u, v, x - u * (k // l), y - v * (k // l), l, k % l
  return c*x, c*y
m = 2*N+1
for i in F:
  if gcd(i, (2*N)//i) == 1:
    x, y = extgcd((2*N)//i, -i, 1)
    while x <= 0 or y <= 0:
      x += i
      y += (2*N)//i
    m = min(x*((2*N)//i), m)
print(m)

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

int main() {
  int sum = 1, N, K;
  cin >> N;
  cin >> K;

  for (int i = 0; i < N; i++) {
    if (sum * 2 <= sum + K) {
      sum *= 2;
    }
    else {
      sum += K;
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws Exception
	{
		int n=nextInt();
		String s=nextLine();
		int cnt=0;
		for(int i=0;i+2<s.length();i++)
			if(s.charAt(i)=='A' && s.charAt(i+1)=='B' && s.charAt(i+2)=='C')
				cnt++;
		out.println(cnt);
	}

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

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 32952
function main(arg) {
	arg = arg.split("\n")
	var N = Number(arg[0])
	var H = Number(arg[1])
	var W = Number(arg[2])

	var w = N - W + 1
	var h = N - H + 1 
	console.log(w * h)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22076
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    long int i,v[5];
    for(i=0;i<5;i++)
    {
        cin>>v[i];
    }
    for(i=0;i<5;i++)
    {
        if(v[i]==0)
        {
            cout<<i+1<<endl;
        }
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#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,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
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)1e5+5;
const int Q = 301;
const int logN = 16;

void solve() {
    string s;
    char ch;
    cin>>s;
    int q;
    cin>>q;
    bool rev = false;
    vector<pair<int,char> > str;
    REP(i,0,s.size()-1) {
        str.pb({i,s[i]});
    }
    int beg = -1;
    int en = s.size();
    while (q--) {
        int t;
        cin>>t;
        if (t==1) {
            rev = !rev;
            //swap(beg,en);
        }
        else {
            cin>>t>>ch;
            if (t==1) {
                if (rev) {
                    str.pb({en++,ch});
                }
                else {
                    str.pb({beg--,ch});
                }
            }
            else {
                if (!rev) {
                    str.pb({en++,ch});
                }
                else {
                    str.pb({beg--,ch});
                }
            }
        }
    }
    sort(all(str));
    s = "";
    for (auto it:str) {
        s += it.second;
    }
    if (rev) reverse(all(s));
    cout<<s;
}
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: 6592
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;

int N;
int A[100001];
int B[100001];
int C[100001];
ll miria = 0;

int main(){
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  sort(A,A+N);
  for(int i = 0;i < N;i++){
    cin >> B[i];
  }
  sort(B,B+N);
  for(int i = 0;i < N;i++){
    cin >> C[i];
  }
  sort(C,C+N);

  for(int i=0;i<N;i++){
    miria += (lower_bound(A,A+N,B[i]) - A) * ((C + N) - upper_bound(C,C+N,B[i]));
  }

  cout << miria << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define MAXN 100005
#define mod 998244353
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
set<ll>ans;
int main(){
    ios::sync_with_stdio(false);
    #define int ll
    int n;
    cin>>n;
    if(n==2){
        cout<<1<<endl;return 0;
    }
    ans.insert(n);
    ans.insert(n-1);
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            int tp=i,nn=n;
            bool y=0;
            while(nn>=tp){
                if(nn%tp==0){
                    nn/=tp;
                    if(nn==1){
                        y=1;break;
                    }
                }
                else{
                    if(nn==1){
                        y=1;break;
                    }
                    nn-=1;
                    if(nn%tp==0){
                        y=1;break;
                    }
                    else{
                        y=0;break;
                    }
                }
            }
            if(y){
                ans.insert(tp);
            }
            if(n/i!=tp){
                tp=n/i;
                nn=n;
                bool y=0;
                while(nn>=tp){
                    if(nn%tp==0){
                        nn/=tp;
                        if(nn==1){
                            y=1;break;
                        }
                    }
                    else{
                        if(nn==1){
                            y=1;break;
                        }
                        nn-=1;
                        if(nn%tp==0){
                            y=1;break;
                        }
                        else{
                            y=0;break;
                        }
                    }
                }
                if(y){
                    ans.insert(tp);
                }
            }

        }
    }
    n-=1;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            ans.insert(i);
            if(n/i!=i){
                ans.insert(n/i);
            }
        }
    }
    cout<<ans.size()<<endl;
    return 0;
}


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

int main(){


  int n;
  
  cin>>n;
  
  if (n<105){
    cout<<0<<endl;
  }
  
  else if (n<135){
    cout<<1<<endl;
  }
  
  else if (n<165){
    cout<<2<<endl;
  }
  
  else if (n<189){
    cout<<3<<endl;
  }
  
  else if (n<195){
    cout<<4<<endl;
  }
  
  else {
    cout<<5<<endl;
  }
  
  
  
    
}
  













Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// greatest common divisor and least common multiple
// gcd is calculated by Euclidean Algorithm
// lcm = m * n / gcd(m,n)
template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    if (b == 0)
        return a;
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << "\n";
    return 0;
}

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


using namespace std;


#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-8;
const ll MOD = 998244353;
const ld PI = 3.141592653589793;
const int maxn = 100001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

vector<int> g[3][maxn];
int grun[3][maxn];
ll cnt[3][maxn];
ll pw[3 * maxn];

signed main() {
#ifdef zxc
    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    mt19937 mt(228);
//            freopen("", "r", stdin);
//        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(10);
    cout << fixed;
    auto start = chrono::steady_clock::now();
///

    int n;
    cin>>n;
    int m[3];
    for (int i = 0; i < 3; ++i) {
        cin >> m[i];
        for (int j = 1; j <= m[i]; ++j) {
            int a, b;
            cin >> a >> b;
            if (a > b) {
                swap(a, b);
            }
            g[i][a].push_back(b);
        }
    }
    vector<int> vals;
    vals.reserve(n + 1);
    vector<int> used(n + 1);
    for (int i = 0; i < 3; ++i) {
        for (int j = n; j >= 1; --j) {
            for (int to:g[i][j]) {
                vals.push_back(to);
                used[grun[i][to]] = 1;
            }
            for (int e = 0; e <= n; ++e) {
                if (!used[e]) {
                    grun[i][j] = e;
                    break;
                }
            }
            while (!vals.empty()) {
                used[grun[i][vals.back()]] = 0;
                vals.pop_back();
            }
        }
    }
//    for (int i = 1; i <= n; ++i) {
//        debug(i,grun[2][i]);
//    }
    ll bs = (ll) 1e18 % MOD;
    pw[0] = 1;
    for (int i = 1; i <= 3 * n; ++i) {
        pw[i] = pw[i - 1] * bs % MOD;
    }


    int mx_val = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = 1; j <= n; ++j) {
            cnt[i][grun[i][j]] += pw[j];
            if (cnt[i][grun[i][j]] >= MOD) {
                cnt[i][grun[i][j]] -= MOD;
            }
            mx_val = max(mx_val, grun[i][j]);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= mx_val; ++i) {
        for (int h = 0; h <= mx_val; ++h) {
            int need = i ^h;
            ans += cnt[0][i] * cnt[1][h] % MOD * cnt[2][need] % MOD;
            if (ans >= MOD) {
                ans -= MOD;
            }
        }
    }
    cout << ans;

///
    auto end = chrono::steady_clock::now();
    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);
}



Measured memory_bytes: 19072
from itertools import combinations
class Dice:
    def __init__(self,dim=list(range(1,7))):
        self.dim = dim

    def roll(self,direction):
        if direction == "N":
            buff = self.dim[0]
            self.dim[0] = self.dim[1]
            self.dim[1] = self.dim[5]
            self.dim[5] = self.dim[4]
            self.dim[4] = buff

        if direction == "E":
            buff = self.dim[3]
            self.dim[3] = self.dim[5]
            self.dim[5] = self.dim[2]
            self.dim[2] = self.dim[0]
            self.dim[0] = buff

        if direction == "W":
            buff = self.dim[0]
            self.dim[0] = self.dim[2]
            self.dim[2] = self.dim[5]
            self.dim[5] = self.dim[3]
            self.dim[3] = buff

        if direction == "S":
            buff = self.dim[0]
            self.dim[0] = self.dim[4]
            self.dim[4] = self.dim[5]
            self.dim[5] = self.dim[1]
            self.dim[1] = buff

def dice_ident(lsts,comb):
    for i in comb:
        D1 = Dice(lsts[i[0]])
        D2 = Dice(lsts[i[1]])
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if D1.dim == D2.dim:
                return print("No")
            D1.roll(op)
    return print("Yes")
            

number = int(input())
comb = list(combinations(range(number),2))
lsts = []
for i in range(number):
    lsts.append(list(map(int,input().split())))

dice_ident(lsts,comb)


Measured memory_bytes: 6004
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int arr[3][3];
  int n;
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin>>arr[i][j];
    }
  }
  cin>>n;
  int b[n];
  for(int i=0;i<n;i++)
    cin>>b[i];
  for(int i=0;i<n;i++)
  {
    for(int k=0;k<3;k++)
    {
      for(int j=0;j<3;j++)
      {
        if(arr[k][j]==b[i])
           arr[k][j]=0;
      }
    }
  }
  int counter=0;
   for(int i=0;i<3;i++)
   { int count=0;
     for(int k=0;k<3;k++)
     {
       if(arr[i][k]==0)
         count++;
     }
     if(count==3){
       counter=1;
       break;
     }
   }
    for(int i=0;i<3;i++)
   { int count=0;
     for(int k=0;k<3;k++)
     {
       if(arr[k][i]==0)
         count++;
     }
     if(count==3){
       counter=1;
       break;
     }
   }
  if(arr[0][0]==0 && arr[1][1]==0 && arr[2][2]==0)
    counter=1;
  if(arr[2][0]==0 && arr[1][1]==0 && arr[0][2]==0)
    counter=1;
  if(counter==1)
    cout<<"Yes";
  else
    cout<<"No";
  
  return 0;
}

Measured memory_bytes: 256
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int BIT[500001][26];
int n;

void ins(int idx,int val,int id)
{
	while(idx<=n)
	{
		BIT[idx][id]+=val;
		idx+=(idx)&(-idx);
	}
}

int query(int idx,int id)
{
	int ans=0;
	while(idx>0)
	{
		ans+=BIT[idx][id];
		idx-=(idx)&(-idx);
	}
	return ans;
}

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int i,q,j;
		string s;
		cin>>n>>s>>q;
		for(i=0;i<n;i++)
		{
			ins(i+1,1,s[i]-'a');
		}
		
		while(q--)
		{
			int ty;
			cin>>ty;
			if(ty==1)
			{
				int tem;
				char c;
				cin>>tem>>c;
				if(s[tem-1]!=c)
				{
					ins(tem,-1,s[tem-1]-'a');
					ins(tem,1,c-'a');
					s[tem-1]=c;
				}
			}
			else
			{
				int ans=0,l,r;
				cin>>l>>r;
				for(i=0;i<26;i++)
				{
					if(query(r,i)-query(l-1,i))
						ans++;
				}
				cout<<ans<<endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 102556
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a,i,M,N;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++)
	{
		scanf("%d",&a);
		N-=a;
	}
	if(N>=0)
	printf("%d",N);
	else
	printf("-1");
	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    int ans[2][S.length()];
    rep(i, 2) rep(j, S.length()) ans[i][j] = 0;
    //境目のLに集める
    rep(i, S.length()) ans[0][i] = 1;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'R'){
            ans[0][i+1] += ans[1][i];
            ans[1][i+1] += ans[0][i];
            ans[0][i] = ans[1][i] = 0; 
        }
    }
    for(int i = S.length()-1; i >= 1; i--){
        if(S[i] == 'L' && S[i-1] == 'L'){
            ans[0][i-1] += ans[1][i];
            ans[1][i-1] += ans[0][i];
            ans[0][i] = ans[1][i] = 0;
        }
    }
    rep(i, S.length()){
        if(i == S.length()-1) cout << ans[0][i] << endl;
        else cout << ans[0][i] + ans[1][i+1] << " ";
    }
    return 0;
}

Measured memory_bytes: 1488
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;
void add_mod(int& a,int b){
    a+=b;
    if(a>m)
        a-=m;
}
int main(){
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(n));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    vector<int> dp(1<<n);
    dp[0] = 1;
    for(int mask = 0;mask<(1<<n)-1;mask++){
        int i = __builtin_popcount(mask);
        for(int j=0;j<n;j++){
            if(a[i][j]&&!(mask&(1<<j))){
                int temp = mask^(1<<j);
                add_mod(dp[temp],dp[mask]);
            }
        }
    }
    cout<<dp[(1<<n)-1]<<"\n";
    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(a[i]!=a[j] && a[j]!=a[k] && a[i]+a[j]>a[k])
        ans++;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=200010;
long long A[N],B[N],s; 
int n;
void solve()
{
    s=0;
    for(int i=0;i<n;i++)
    {
	scanf("%lld",&A[i]);
	s+=A[i];
    }
    for(int i=0;i<n-1;i++)
	B[i]=A[i+1]-A[i];
    B[n-1]=A[0]-A[n-1];
    long long t=(long long)n*(n+1)/2;
    if(s%t)
	{
	puts("NO");
	return;
	}
    s/=t;
	long long cnt=0;
    for(int i=0;i<n;i++)
	{
        if((s-B[i])%n||s-B[i]<0)
		{
		puts("NO");
		return;
		}
        cnt+=(s-B[i])/n;
    }if(cnt!=s)
	{
	puts("NO");return;}
    puts("YES");
}
int main(){
    while(~scanf("%d",&n))
	solve();
    return 0;
}

Measured memory_bytes: 1664
loop{
    degree = Hash.new(0)
    loop {
        i, j = gets.tap{|s| exit unless s}.split.map &:to_i
        break if i == 0
        degree[i] += 1
        degree[j] += 1
    }
    if degree.all?{|k, c| (k < 3) ^ c.even?}
        puts 'OK'
    else
        puts 'NG'
    end
}

Measured memory_bytes: 6092
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		ll a[5], k;
		cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
		if (cin.fail()) break;

		bool error = false;
		for (int i = 0; !error && i < 5; i++) {
			for (int j = i + 1; !error && j < 5; j++) {
				if (abs(a[i] - a[j]) > k) {
					error = true;
				}
			}
		}
		cout << (error ? ":(" : "Yay!") << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll N, ans = 1;
    cin >> N;
    vector<ll> A(N);
    repi(i, N, 0)
    {
        cin >> A[i];
        ans *= 3;
    }
    ll odd = 1;
    repi(i, N, 0)
    {
        if (A.at(i) % 2 == 0)
        {
            odd *= 2;
        }
    }
    cout << ans - odd << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>


using namespace std;


int main(){
	int n,m,sumn,summ,ansn,ansm;
	int a[101],b[101],flag=0;
	
	while(n != 0 || m != 0){
		sumn=0;summ=0;ansn=100000;ansm=100000;
		
		cin >> n >> m;
		
		if(n==0 && m==0)break;
	
		for(int i=0;i<n;i++){
			cin >> a[i];
			sumn += a[i];
		}
		
		for(int i=0;i<m;i++){
			cin >> b[i];
			summ += b[i];
		}
		
		for(int i=0;i<n;i++){
			int j;
			for(j=0;j<m;j++){
				if( (sumn - summ) == 2*(a[i] - b[j])){
					if(ansn+ansm > i+j){
						ansn=i;
						ansm=j;
					}
					flag=1;
				}
			}
		}
		if(flag==0){
			cout << -1 << endl;
		}else{
			cout << a[ansn] << ' ' << b[ansm] << endl;
			flag =0;
		}
	}
	
		
		
	return 0;
}


Measured memory_bytes: 3080
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  int a[N];
  FOR(i,0,N)cin>>a[i];
  int b[N];
  FOR(i,0,N)b[N-i-1]=a[i];
  map<int, int> ma,mb;
  int diff=0;
  vector<int> ans;
  FOR(i,0,N){
    if(a[i]!=b[i]){
      diff+=2;
      ma[a[i]]++;
      mb[b[i]]++;
      if(mb[a[i]]>0){
        mb[a[i]]--;
        ma[a[i]]--;
        diff-=2;
      }
      if(ma[b[i]]>0){
        ma[b[i]]--;
        mb[b[i]]--;
        diff-=2;
      }
    }
    if(diff==0)ans.push_back(i+1);
  }
  FOR(i,0,ans.size()){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 8628
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    int sl=s.length(),tl=t.length();
    int dp[sl+1][tl+1];
    memset(dp,0,sizeof(dp));
    for(int i=sl-1;i>=0;i--){
        for(int j=tl-1;j>=0;j--){
            if(s[i]==t[j]) dp[i][j]=dp[i+1][j+1]+1;
            else dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
            
        }
    }
    int lcsl=dp[0][0];
    char lcs[lcsl+1];
    //lcs[lcsl]='\0';
    int i=0,j=0,ind=0;
    while(i<sl and j<tl){
        if(s[i]==t[j]){
            lcs[ind++]=s[i];
            i++;j++;
        }
        else{
            if(dp[i+1][j]>dp[i][j+1]){
                i++;
            }
            else{
                j++;
            }
        }
    }
    for(int q=0;q<lcsl;q++) cout<<lcs[q];
}

Measured memory_bytes: 35456
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;
int main () { 
	int a;
	cin >> a;
		if(a >= 1200){
			cout << "ARC" << endl;
		}else
			cout << "ABC" << endl;
} 			


Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    ld X;
    cin>>X;
    ld ans=100;
    ll cnt=0;
    while (ans<X)
    {
        ans=ans/100;
        ans=ans*101;
        ans=floor(ans);
        cnt++;
    }
    cout<<cnt<<endl;
    

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int A,B,C;cin >> A >> B >> C;
    if(A+B+C >= 22)cout << "bust" << endl;
    else cout << "win" << endl;
}



Measured memory_bytes: 256
from collections import deque

#　listからr個を順に取り出す順列、戻り値はイテレーター
# itertools.permutations(list, n)
# listからr個を選ぶ組み合わせ、戻り値はイテレーター
# itertools.permutations(list, n)

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

ans = 0
tmp = []

def dfs():
    global tmp
    stack = deque([[[], 0]])
    while stack:
        cur, i = stack.pop()
        if i == n:
            tmp.append(cur)
            continue
        mi = 1
        if i:
            mi = cur[-1]
        for next in range(mi, m+1):
            stack.append([cur+[next], i+1])
dfs()
# print(tmp)

for item in tmp:
    cand = 0
    for a, b, c, d in abcd:
        if item[b-1] - item[a-1] == c:
            cand += d
    ans = max(ans, cand)

print(ans)



Measured memory_bytes: 23360
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	a,b,c = l[i-1], l[i], l[i+1]
	if a < b < c:
		ans += 1
	elif c < b < a:
		ans += 1
print(ans)

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
const int mod = (int)1e9+7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	int n;
	cin>>n;
	vector<double> dp(n+1);
	dp[0] = 1;
	double p;
	for(int i=0;i<n;i++){
		cin>>p;
		vector<double> new_dp(n+1);
		for(int j=0;j<=n;j++){
			new_dp[j] = dp[j]*(1-p) + dp[j-1]*p;
		}
		dp = new_dp;
	}
	double ans = 0;
	for(int i=n/2+1;i<=n;i++){
		ans += dp[i];
	}
	cout<<setprecision(14)<<ans;
    return 0;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef  long double lld;
const ll mod = 1e9 + 7;
const ll mx = 1e6 + 1;
ll prime[mx];
ll mx_pow[mx];
void initialize(){
    f(i, mx)prime[i] = i;
    for(ll i = 2; i * i <= mx; ++i){
        if(prime[i]){
            for(ll j = i + i; j < mx; j += i){
                if(prime[j] == j)prime[j] = i;
            }
        }
    }
}
ll power(ll x, ll y){
    ll res = 1;
    while(y > 0){
        if(y & 1)res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) %  mod;
    }
    return res;
}
ll inverse_modulo(ll x){
    return power(x, mod - 2) % mod;
}
ll find_lcm(vector<ll>&a, ll n){
    memset(mx_pow,0, sizeof(mx_pow));
    f(i, n){
        ll no = a[i];
        unordered_map<ll, ll>m;
        while(no > 1){
            m[prime[no]]++;
            no /= prime[no];
        }
        for(auto &it : m){
            mx_pow[it.first] = max(mx_pow[it.first], it.second);
        }

    }
    ll ans = 1;
    for(ll i = 1; i < mx; ++i){
        ans = (ans * power(i, mx_pow[i])) % mod;
    }
    return ans;

}
void input(){
    initialize();
    ll n; cin >> n;
    vector<ll>a(n);
    f(i, n) cin >> a[i];
    ll x = find_lcm(a, n);
    ll ans = 0;
    f(i, n){
        ans = (ans + (x * inverse_modulo(a[i])) % mod) % mod;
    }
    cout << ans << endl;
}
int main(){
    input();
    return 0;
}


Measured memory_bytes: 16000
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }

    int min = a[0],max = a[0];
    for(int i = 1; i < n; i++){
        if(min > a[i]){
            min = a[i];
        }
        if(a[i] > max){
            max = a[i];
        }
    }
    printf("%d\n", max - min);

    return 0;
}

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

namespace ABC163_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nm[0];
            var m = nm[1];
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine(n - a.Sum() >= 0 ? n - a.Sum() : -1);
        }
    }
}


Measured memory_bytes: 28952
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

long long a, b, k[100005], mon, ans;
int main() {
	cin >> a >> b;
	map<long long, long long>m;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
		mon += k[i];
		++m[mon%b];
	}

	for (auto i : m) {
		auto n = i.second;
		ans += (n*(n - 1)) / 2;
	}

	cout << ans + m[0] << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
	
typedef long long int ll;
ll n,m,l,r,k;

ll chk(ll x)
{
	ll ans=0;
	for (int i = 1; i <= n; ++i)
	{
		ans+=min(m,x/i);
	}
	return ans;
}
int main()
{
	ll x,y,z;
	cin>>x>>y>>z;
	if(x+y+z>=22)
		cout<<"bust"<<endl;
	else
		cout<<"win"<<endl;
}



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

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

    vector<string> a(n);
    vector<string> b(n);

    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];


    rep(i,n-m+1){
        rep(j,n-m+1){
            rep(k,m){
                string sub = a[i+k].substr(j,m);
                if(sub != b[k]) break;
                if(k == m-1){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())

G = [list(input()) for _ in range(H)]

ans = H * W

def calc(lst):
    group = sum(lst) + 1
    tmp = [[0] * W for _ in range(group)] #何グループに分かれるか
    k = 0
    for j in range(W):
        for i in range(H):
            if G[i][j] == '1':
                tmp[k][j] += 1
            if lst[i] == 1 or i == H - 1:
                k = (k + 1) % group
    
    cut = group - 1
    for j in range(W):
        flag = False
        for i in range(group):
            if tmp[i][j] > K:
                return 10 ** 9
            if j < W - 1:
                if tmp[i][j] + tmp[i][j + 1] > K: #次の戸合わせてKより大きくなるなら切る
                    flag = True
        if flag:
            cut += 1
        else:
            for i in range(group):
                if j < W - 1:
                    tmp[i][j + 1] += tmp[i][j]
    return cut


for i in range(2 ** (H - 1)): #ビットでカットするラインを探索
    lst = [0] * H
    for j in range(H - 1):
        if (i >> j) & 1: #切れるとき
            lst[j] = 1
    # print (lst)
    ans = min(ans, calc(lst))

print (ans)
    


Measured memory_bytes: 52316
N = int(input())
blues = {}
reds = {}
for i in range(N):
    s = input()
    if s in blues:
        blues[s] += 1
    else:
        blues[s] = 1
    reds[s] = 0
M = int(input())
for i in range(M):
    s = input()
    if s in reds:
        reds[s] += 1
    else:
        reds[s] = 1

res = 0
for s in blues:
    res = max(res, blues[s]-reds[s])

print(res)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
 
int main(){
  long long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      cout << (j == 0 ? "": " ") << c[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    map<int, int> mp;

    int n;
    cin >> n;

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

    if (n % 3 == 0) {
        if (mp.size() > 3) {
            cout << "No\n";
            return 0;
        }
        int m = n / 3, x = 0;
        for (auto p : mp) {
            if (p.second % m) {
                cout << "No\n";
                return 0;
            }
            p.second /= m;
            while (p.second--) {
                x ^= p.first;
            }
        }
        if (x != 0) {
            cout << "No\n";
        }
        else {
            cout << "Yes\n";
        }
    }
    else if (mp.size() > 1 || mp.begin()->first != 0) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";
    }

    return 0;
}

Measured memory_bytes: 3840
def main():
	N = int(input())
	current = N
	ans = ""
	while current != 0:
		if current % 2 == 0:
			ans = "0" + ans
		else:
			ans = "1" + ans
			current -= 1
		current //= -2

	if ans == "":
		ans = "0"

	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    #sに含まれる文字を一文字ずつ抽出する.
    #ここで抽出した文字を組み合わせて辞書順に文字列を構成していく
    #K<=5だから高々26^5個の文字列を構成することになる
    l = sorted(list(set(s)))
    #cnd:=構成した文字列を辞書順に格納するリスト
    cnd = []
    #f(sub):=subから構成可能なK文字以下のSの部分文字列を構成する関数
    def f(sub):
        cnd.append(sub)
        if len(sub) < K: 
            #lから選んでsubに一文字追加する
            for i in l:
                nx = sub+i
                if nx in s:
                    return f(nx)
    for i in l:
        f(i) 
    print(cnd[K-1])
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, A, B;
  cin >> N >> A >> B;
  if((B-A)%2 == 0){
    cout << (B-A)/2 << endl;
  }
  else{
    int64_t ans = min(N-A,B-1);
    int64_t x = A-1;
    int64_t y = N-B;
    int64_t z = min(x,y)+1;
    ans = min(ans,z + (B-A-1)/2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int m,f,r;
	int s;
	while(1) {
		cin >> m >> f >> r;
		if(m==-1 && f == -1 && r == -1) break;
		s=m+f;
		if(m==-1 || f == -1) cout << 'F' << endl;
	else if(s>=80) cout << 'A' << endl;
	else if(s>=65 && s<80) cout << 'B' << endl;
		else if(s>=50 && s<65) cout << 'C' << endl;
		else if(s>=30 && s<50 && r>=50) cout << 'C' << endl;
		else if(s>=30 && s<50 && r<50) cout << 'D' <<endl;
		else cout << 'F' << endl;
	}
}


Measured memory_bytes: 3100
#include <stdio.h>
int main(){
	int n, k, x, y, ans = 0;
	scanf(" %d %d %d %d", &n, &k, &x, &y);
	if(n >= k){ 
		ans = k * x + (n - k) * y;
	}
	else ans = n * x;
	printf("%d\n", ans);
	return 0;
}

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

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for ( int i = 0; flag; i++) {
		flag = 0;
		for (int j = N - 1; j > i; j--) {
			if (A[j] < A[j-1]) {
				swap(A[j],A[j-1]);
				flag = 1;
				sw++;
			}
		}
	} 
    return sw;
}

int main(){
	int A[100],N, sw;
	cin >> N;
	for( int i = 0; i < N; i++ ) cin >> A[i]; 
    
	sw = bubbleSort(A, N);
	
	for( int i = 0; i < N; i++ ) {
		if(i) cout << " ";
		cout << A[i];  
	} 
    cout << endl;
    cout << sw << endl;
    
    return 0;
}

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

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String line;
        
        loop:
        while((line = br.readLine()) != null){
            char[] arr = line.toCharArray();

            // vertical check
            for(int i = 0; i < 3; i++){
                if(arr[i] != 's' && arr[i] == arr[i+3] && arr[i+3] == arr[i+6]){
                    System.out.println(arr[i]);
                    continue loop;
                }
            }

            // horizontal check
            for(int i = 0; i < 3; i++){
                if(arr[3*i] != 's' && arr[3*i] == arr[3*i+1] && arr[3*i+1] == arr[3*i+2]){
                    System.out.println(arr[3*i]);
                    continue loop;
                }
            }

            // oblique check
            if(arr[0] != 's' && arr[0] == arr[4] && arr[4] == arr[8]){
                System.out.println(arr[0]);
                continue loop;
            }
            if(arr[2] != 's' && arr[2] == arr[4] && arr[4] == arr[6]){
                System.out.println(arr[2]);
                continue loop;
            }

            System.out.println("d");
        }
    }
}


Measured memory_bytes: 24164
#include <iostream>

using namespace std;

int main() {
    int t;
    while (cin >> t, t != 0) {
        int n; cin >> n;
        for (int i = 0; i < n; i++) {
            int s, f; cin >> s >> f;
            t -= (f-s);
        }
        if (t <= 0) cout << "OK" << endl;
        else cout << t << endl;
    }
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int r, g;
	cin >> r >> g;

	dunk(2 * g - r);

	return 0;
}

Measured memory_bytes: 892