akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  int A[N];
  int x[N][N];
  int y[N][N];
  rep(i,N){cin >> A[i];
    rep(j,A[i]) cin >> x[i][j] >> y[i][j];
  }
  
  int ans = 0;

  for(int bit = 0; bit < (1<<N); bit++){
    bool ok = true;
    for(int i = 0;i<N;i++){
      if(bit & (1 << i)){//正直者のみ
        for(int j = 0; j<A[i]; j++){//証言のチェック
          if(!(bit&(1 <<x[i][j]-1)) && y[i][j] == true) ok = false;
          else if(bit& (1 <<x[i][j]-1) && y[i][j] == false) ok = false;
        }
      }
     
    }
     if(ok == true) ans = max(ans,__builtin_popcount(bit));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll n,m;
    cin >> n >> m;
    vector<tuple<ll,ll,ll,ll>>data(m);
    rep(i,m){
        ll p,y;
        cin >> p >> y;
        data[i]=make_tuple(p,y,i,0);
    }
    sort(data.begin(),data.end());
    ll v=get<0>(data[0]);
    ll now=1;
    rep(i,m){
        if(v!=get<0>(data[i])){
            now=1;
            v=get<0>(data[i]);
        }
        get<3>(data[i])=v*1000000+now;
        now++;
    }
    vector<pair<ll,ll>>ans(m);
    rep(i,m){
        ans[i]=make_pair(get<2>(data[i]),get<3>(data[i]));
    }
    sort(ans.begin(),ans.end());
    rep(i,m){
        printf("%012lld\n",ans[i].second);
    }



    return 0;
}


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

int main(){
    int x, y, z, k;
    ll t;
    vector<ll> a, b, c, d, e;
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; i++){
        cin >> t;
        a.push_back(t);
    }
    for(int i = 0; i < y; i++){
        cin >> t;
        b.push_back(t);
    }
    for(int i = 0; i < z; i++){
        cin >> t;
        c.push_back(t);
    }
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            d.push_back(a[i] + b[j]);
        }
    }
    sort(d.begin(), d.end());
    for(int i = d.size()-1; i >= 0 && i >= (int)d.size()-k; i--){
        for(int j = 0; j < z; j++){
            e.push_back(d[i] + c[j]);
        }
    }
    sort(e.begin(), e.end());
    for(int i = e.size()-1; i >= (int)e.size()-k; i--)
        cout << e[i] << endl;
}

Measured memory_bytes: 43128
#include<iostream>

using namespace std;

int main()
{
  int c[4][13]={{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0}};

  int n;
  string m;
  int v;
    
  cin >> n;

  for (int i = 0; i < n; i++)
    {
      cin >> m >> v;

      if ( m == "S" )
        {
          c[0][v-1] = 1;
        }
      else if ( m == "H" )
        {
          c[1][v-1] = 1;
        }
      else if ( m == "C" )
        {
          c[2][v-1] = 1;
        }
      else
        {
          c[3][v-1] = 1;
        }
    }

  for ( int i = 0; i < 4; i++ )
    {
      for ( int j = 0; j < 13; j++ )
        {
          if ( c[i][j] == 0 )
            {
              if ( i == 0 )
                {
                  cout << "S "  << j + 1 << endl;
                }
              else if ( i == 1 )
                {
                  cout << "H "  << j + 1 << endl;
                }
              else if ( i == 2 )
                {
                  cout << "C "  << j + 1 << endl;
                }
              else
                {
                  cout << "D "  << j + 1 << endl;
                }
            }
        }
    }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;


int main()
{
    ll MOD = 1000000007;
    string yes = "Yes\n";
    string no = "No\n";

    ll d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d) {
        cout << yes;
    }
    else cout << no;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;
typedef pair<int,int> P;
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,m,N) for(int i=m;i<N;i++)
#define mm(n,m) memset(n,m,sizeof(n))

int main(){
    int n,k;
    cin>>n>>k;
    int h[n];
    rep(i,n)cin>>h[i];
    
    int res = 0;
    rep(i,n){
        if(h[i]>=k){
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 640
#include <iostream>

#define MAX_SIZE (100000 + 100)

bool P[MAX_SIZE];

int main()
{
  int X;
  std::cin >> X;

  for (int i = 3; i < MAX_SIZE; i += 2) P[i] = true;

  P[2] = true;
  for (int i = 3; i < MAX_SIZE; i += 2)
  {
    if (P[i])
    {
      for (int j = i * 2; j < MAX_SIZE; j += i)
      {
        P[j] = false;
      }
    }
  }

  int ans = X;
  while (!P[ans]) ++ans;

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b, c; cin >> a >> b >> c;
    cout << min(c, b/a) << ln;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b,c;
    cin >> a >> b >> c;
    // 文字列の入力
    if (a + b+ c >= 22){
      	cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {


	int a,b;
	cin>>a>>b;

	if((a*b)%2>0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


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

#define ll  long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)

struct bun{
    ll w,v;
};


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w; 
    cin >> n>>w;
    bun a[n];
    ll dp[n][w + 1] = { 0 };
    rep(i,0,n){
        cin >> a[i].w >> a[i].v;
    }
    rep(i,0,w + 1){
        if(i - a[0].w < 0 ) dp[0][i] = 0;
        else dp[0][i] = a[0].v;
    }
    rep(i,1,n){
        rep(j,0,w + 1){
            if(j - a[i].w >= 0)
            dp[i][j] = max(dp[i - 1][j - a[i].w] + a[i].v,dp[i - 1][j]);
            else dp[i][j] = dp[i - 1][j];

        }
    }
    cout << dp[n - 1][w];
    


}

Measured memory_bytes: 78336
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

long a[5];
int main(void){
	int n, i, j, k;
	scanf("%d\n", &n);
	for(i=0; i<n; i++){
		char c=getchar();
		switch(c){
			case 'M': a[0]++; break;
			case 'A': a[1]++; break;
			case 'R': a[2]++; break;
			case 'C': a[3]++; break;
			case 'H': a[4]++; break;
		}
		while((c=getchar())!=10);
	}
	long ans=0;
	for(i=0; i<5; i++){
		for(j=0; j<i; j++){
			for(k=0; k<j; k++){
				ans += a[i]*a[j]*a[k];
			}
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 128
n,m = gets.split.map(&:to_i)
MOD = (10**9)+7
if (n-m).abs > 1
    puts 0
    exit
end
def factorial(x)
    (1..x).inject{|sum, i| (sum * i) % MOD}
end
a = [n,m]
if n != m
    puts (factorial(a.max)*factorial(a.min))%MOD
else
    puts 2*(factorial(a.max)**2)%MOD
end

Measured memory_bytes: 1788
def solve():
    N,M,X = map(int, input().split())
    A = list(map(int, input().split()))
    count = 0
    for i in range(M):
        if A[i] > X:
            break
        count += 1
    count2 = 0
    for j in range(count+1,M+1):
        count2 += 1
    print(min(count, count2))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
# https://atcoder.jp/contests/abc074/tasks/arc083_b

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

total = 0
for n in range(N):
    for m in range(n + 1, N):
        total += A[n][m]

flag = False
for n in range(N):
    for m in range(n + 1, N):
        for k in range(N):
            if k != n and k != m:
                if A[n][m] > A[n][k] + A[k][m]:
                    flag = True
                    break
                elif A[n][m] == A[n][k] + A[k][m]:
                    # この辺はいらない
                    total -= A[n][m]
                    break
        if total < 0 or flag:
            break
    if total < 0 or flag:
        break

if flag:
    print(-1)
else:
    print(total)

Measured memory_bytes: 74776
n = gets.to_i
list = []
n.times{
  command =gets.split(" ")
  case command[0]
  when "insert"
    num = command[1].to_i
    list.unshift(num)
  when "delete"
    num = command[1].to_i
    index = list.index(num)
    if index != nil
      list.delete_at(index)
    end
  when "deleteFirst"
    list.shift
  when "deleteLast"
    list.pop
  end
}

puts list.join(" ")

Measured memory_bytes: 23152
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

ll cnt = 1 ;

void DFS(vvll &g,ll h,ll w){
	if(g.at(h).at(w)==0) return ;
	g.at(h).at(w) = 0 ;
	for(int i=h-1;i<=h+1;i++) for(int j=w-1;j<=w+1;j++) DFS(g,i,j) ;
}

int main(){
	while(1){
		ll w,h ;
		cin >> w >> h ;
		if(w==0&&h==0) break ;
		vvll g(h+2,vll(w+2,0)) ;
		for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin >> g.at(i).at(j) ;
		ll ans = 0 ;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(g.at(i).at(j)==1){
					ans++ ;
					DFS(g,i,j) ;
				}
			}
		}
		cout << ans << endl ;
	}
}



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

int N, M;

int main() {
  map<string, int> pscore;
  cin >> N;
  string s;
  for (int i = 0; i < N; i++) {
    cin >> s;
    pscore[s]++;
  }
  cin >> M;
  string t;
  map<string, int> mscore;
  for (int i = 0; i < M; i++) {
    cin >> t;
    mscore[t]++;
  }
  int ans = 0;
  for (auto itr = pscore.begin(); itr != pscore.end(); itr++) {
    ans = max(ans, pscore[itr->first] - mscore[itr->first]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf = 1e18;


int main() {
    ll H,W;
    cin>>H>>W;
    if(H%3==0 || W%3==0) p(0);
    else{
        ll ans = min(H,W);
        for(ll i=1; i<W; i++){
            ll mn = H/2 * i, mx = (H+1)/2 * i;
            ans=min(ans, max(abs(H*(W-i) - mn), abs(H*(W-i) - mx)));
        }
        for(ll i=1; i<H; i++){
            ll mn = W/2 * i, mx = (W+1)/2 * i;
            ans=min(ans, max(abs(W*(H-i) - mn), abs(W*(H-i) - mx)));
        }
        p(ans);
    }

    return 0;
}

Measured memory_bytes: 256
// B - Exactly N points

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1000000007;
// using mint = modint1000000007;
// const ll MOD = 998244353;
// using mint = modint998244353;

int main() {
	int N;
	cin >> N;

	unordered_set<int> ans;
	int k = 1;
	while (1) {
		ans.insert(k);
		if ((1+k) * k / 2 >= N) break;
		k++;
	}

	ans.erase((1+k) * k / 2 - N);

	for (int a : ans) {
		cout << a << endl;
	}

	return 0;
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<i64> b(n);
    for (auto& e : b) cin >> e, e--;

    deque<i64> ans;
    for (i64 i = n - 1; i >= 0; i--) {
        for (i64 j = i; j >= 0; j--) {
            if (b[j] == j) {
                b.erase(begin(b) + j);
                ans.push_front(j + 1);
                break;
            }
        }
    }

    if (!b.empty()) {
        cout << -1 << endl;
        return;
    }

    for (auto& e : ans) cout << e << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
my $s = <>;
my ($N,$K) = split(/ /,$s);

$s = <>;
my @DB = split (/ /,$s);
my %flag;
my $next = 1;
for(my $i=0;$i<$K;$i++){
    #print "now $next\n";
    if( $flag{$next}< 1 ){
        $flag{$next} = $i;
    }else{
        #print "still came  $i -$flag{$next} \n";
        my $mod =  $i -$flag{$next};
        if( ($K-$i) > $mod ){
          #print "$i + int((($K-$i)-($K-$i)%$mod)/$mod)*$mod\n";
          $i = $i + int((($K-$i)-($K-$i)%$mod)/$mod)*$mod-$mod;
        }
    }
    $next = $DB[$next-1];
    #print "i$i\n";
    #print  "nx $next\n";
}
print "$next"

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int main() {

	FAST;

	string a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = 0; i < (int)a.length(); i ++) {
		ans += (a[i] != b[i]);
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
    long n, k;
    cin >> n >> k;
    long ans = k;
    rep(i, n - 1) ans *= k - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define n 1000000007

int main(){
	int i;
	long N;
	unsigned long long ans = 1;
	int sc;
	sc = scanf("%ld", &N);
	for(i = 1; i <= N; i ++){
		ans *= i;
		ans %= n;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
# A - Can't Wait for Holiday

# 文字列 S の入力
S = input()
# print(S)

# 何日後か求める条件文
if S == 'SUN':
    # print(7)
    answer = 7
elif S == 'MON':
    # print(6)
    answer = 6
elif S == 'TUE':
    # print(5)
    answer = 5
elif S == 'WED':
    # print(4)
    answer = 4
elif S == 'THU':
    # print(3)
    answer = 3
elif S == 'FRI':
    # print(2)
    answer = 2
elif S == 'SAT':
    # print(1)
    answer = 1

print(answer)


Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n, x, m;
  cin >> n >> x >> m;
  vector<int> chk(m, -1);
  vector<ll> loop;
  while(chk.at(x) == -1){
    chk.at(x) = loop.size();
    loop.push_back(x);
    x = (x*x) % m;
  }
  ll ans = 0;
  // for(auto i : chk) cerr << i << " ";
  // cerr << endl;
  // for(auto p : loop) cerr << p << " ";
  // cerr << endl;
  if(n < loop.size()){
    rep(i, n){
      ans += loop.at(i);
    }
  }else{
    int pos = chk.at(x);
    ll lsum = 0;
    rep(i, loop.size()){
      if(pos <= i) lsum += loop.at(i);
      ans += loop.at(i);
    }
    ll sz = loop.size() - pos;
    n -= loop.size();
    ans += lsum*(n/sz);
    n %= sz;
    rep(i, n){
      ans += loop.at(i+pos);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4248
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=[-A[i] for i in range(0,N)]
heapq.heapify(A)
for i in range(0,M):
    m=(-1)*heapq.heappop(A)
    m=m//2
    m=-m
    heapq.heappush(A,m)
print((-1)*sum(A))

Measured memory_bytes: 14180
INF = 2000000000
@count = 0
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = []
  r = []
  (n1).times do |i|
    l[i] = a[left + i]
  end
  (n2).times do |i|
    r[i] = a[mid + i]
  end
  l[n1] = r[n2] = INF
  i = 0
  j = 0
  for k in left...right do
    @count += 1
    if l[i] <= r[j]
      a[k] = l[i]
      i = i + 1
    else
      a[k] = r[j]
      j = j + 1
    end
  end
end

def mergeSort(a, left, right)
  if left + 1 < right
    mid = (left + right) / 2
    mergeSort(a, left, mid)
    mergeSort(a, mid, right)
    merge(a, left, mid, right)
  end
end

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
mergeSort(a, 0, a.size())
puts a.join(' ')
puts @count

Measured memory_bytes: 73320
object Main extends App {
  val n = scala.io.StdIn.readLine.toInt
  val a = (1 to n).map { _ =>
    scala.io.StdIn.readLine.toInt
  }
  val aa = a.sorted.reverse
  val max01 = aa.head
  val max02 = aa(1)
  a.foreach { aaa =>
    if (aaa == max01) {
      println(max02)
    } else {
      println(max01)
    }
  }
}

Measured memory_bytes: 61576
#include<stdio.h>
int main(void){
    int dp[100][3][3],plan[100],n,m,a,b,i,j,k,l;
    scanf("%d%d",&n,&m);
    for(i=0; i<n; i++){
        plan[i]=-1;
        for(j=0; j<3; j++){
            for(k=0; k<3; k++){
                dp[i][j][k]=0;
            }
        }
    }
    for(i=0; i<m; i++){
        scanf("%d%d",&a,&b);
        plan[a-1]=b-1;
    }
    for(i=0; i<3; i++){
        if(plan[0]==i || plan[0] == -1){
            for(j=0; j<3; j++){
                if(plan[1]==j || plan[1] == -1){
                    dp[1][i][j]=1;
                }else{
                    dp[1][i][j]=0;
                }
            }
        }else{
            for(j=0; j<3; j++){
                dp[0][i][j]=0;
            }
        }
    }
    for(i=2; i<n; i++){
        for(j=0; j<3; j++){
            for(k=0; k<3; k++){
                for(l=0; l<3; l++){
                    if( (j!=k || j!=l || k!=l) && ( plan[i] == l || plan[i] == -1) ){
                        dp[i][k][l] = (dp[i][k][l] + dp[i-1][j][k])%10000;
                    }
                }
            }
        }
    }
    a=0;
    n--;
    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            a = (a + dp[n][i][j])%10000;
        }
    }
    printf("%d\n",a);
    return 0;
}

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

using namespace std;

#define ll long long
#define ar array

int n;
int a[1000001];
int inp[200001];

void solve(){

    cin >> n;

    for (int i = 0; i < 1000001; i++)
    {
        a[i] = 0;
    }
    
    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> inp[i];
    }
    
    sort(inp, inp+n);

    int max = inp[n-1];

    for (int i = 0; i < n; i++)
    {
        int x = inp[i];
        //cout << "i: " << i << endl;
        if(a[x] == 1){
            a[x] +=1;
            continue;
        }
        for (int j = x; j <= max; j = j+x)
        {
            
            a[j] += 1;
        }
        
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if(a[inp[i]] == 1) ans++;
    }
    
    
    cout << ans << endl;
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 8260
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  int a,b;
  cin>>a>>b;
  bool res=false;
  for(int i=a;i<=b;i++){
   if(i%n==0){
     cout<<"OK";
     res=true;
     break;
   }
  }
  if(res==false)
    cout<<"NG";
  return 0;
}
    

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n, k;cin >> n >> k;
	n %= k;
	cout << min(n, abs(n-k)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, H[111111], c = 0, cp = 0;

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> H[i];

  for (int i = 0; i < N - 1; i ++) {
    if (H[i] >= H[i + 1]) {
      c ++;
    }
    else {
      c = 0;
    }

    cp = std::max(c, cp);
  }

  std::cout << cp << std::endl;

  return 0;
}


Measured memory_bytes: 640
import copy
H,W,K=map(int,input().split())
L=[]
for i in range(H):
  L_=list(input())
  L.append(L_)

cnt=0
for i in  range(2**H):
  l=copy.deepcopy(L)
  
  for k in range(H):
    if (i>>k)&1:
      l[k]=['.']*W
    
  for j in range(2**W):
    ll=copy.deepcopy(l)
   
    for m in range(W):
      if (j>>m)&1:
        for n in range(H):
          if ll[n][m]=='#':
            ll[n][m]='.'
            
    counted=0
    for o in range(H):
      counted+=ll[o].count('#')
    #print(ll)
    if counted==K:
      cnt+=1    

print(cnt)

Measured memory_bytes: 9300
N,M,X = gets.chomp.split.map(&:to_i)
C = N.times.map{gets.chomp.split.map(&:to_i)}

D = C.transpose
count = 0
(1..M).each do |i|
  if D[i].sum < X
    count += 1
  end
end
if count != 0
  puts "-1"
  exit
end

bits = [0, 1].repeated_permutation(N).to_a
ans = (10 ** 5) * 12

bits.each do |bit|
  rikaido = [0] * (M + 1) 
  (0..N-1).each do |j|
    if bit[j] == 1
      (0..M).each do |k|
        rikaido[k] += C[j][k]
        if rikaido[1..M].all? { |n| n >= X }
          ans = rikaido[0] if ans >= rikaido[0]
        end
      end
    end
  end
end

puts ans

Measured memory_bytes: 15708
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        double n = s.nextInt();
        double d = s.nextInt();
        
        System.out.println((int) Math.ceil(n / (2 * d + 1)));
	}
}

Measured memory_bytes: 20948
import java.awt.geom.Point2D;
import java.util.*;

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

	public Main() {
		new AOJ0090().doIt();
	}

	class AOJ0090{
		void doIt(){
			final double EPS=1.0e-8;
			while(true){
				int n = in.nextInt();
				if(n==0)break;
				ArrayList<Point2D> p = new ArrayList<Point2D>();
				ArrayList<Point2D> list = new ArrayList<Point2D>();
				for(int i=0;i<n;i++){
					String res[] = in.next().split(",");
					p.add(new Point2D.Double(Double.parseDouble(res[0]),Double.parseDouble(res[1])));
				}
				for(int i=0;i<n;i++)for(int s=i+1;s<n;s++){
					Point2D[] a = intersectPtCC(new Circle(p.get(i),1),new Circle(p.get(s),1));
					if(a==null)continue;
					list.add(a[0]);list.add(a[1]);
				}
				int result = 1;
				for(int i=0;i<list.size();i++){
					int cnt = 0;
					for(int s=0;s<n;s++)if(list.get(i).distance(p.get(s))<=1+EPS)cnt++;
					result = Math.max(result, cnt);
				}
				System.out.println(result);
			}
		}

		class Circle{
			Point2D p;
			double r;
			Circle(Point2D p,double r){ 
				this.p=p;
				this.r=r;
			}
			Circle(double x,double y,double r){  
				this.p=new Point2D.Double(x,y); 
				this.r=r;
			}
		}
		 //円と円の交点
		Point2D [] intersectPtCC(Circle a,Circle b){
		double dis = a.p.distance(b.p);
		if(dis > a.r + b.r)return null;
		Point2D v = sub(b.p, a.p);
		double rc=(dis*dis+a.r*a.r- b.r*b.r)/(2*dis);
		double rate = rc / dis;
		v = mul(rate, v);
		Point2D c = add(v, a.p);
		double disC2c = c.distance(b.p);
		double disqc = Math.sqrt(b.r * b.r - disC2c * disC2c);
		Point2D v2 = sub(b.p, c);
		v2 = mul(disqc / disC2c, v2);
		Point2D [] res = new Point2D[2];
		res[0] = add(normalVector1(v2), c);
		res[1] = add(normalVector2(v2), c);
		return res;
		}

		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}
		Point2D mul(double n,Point2D p1){
			return new Point2D.Double(p1.getX()*n,p1.getY()*n);
		}
		Point2D sub(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()-p2.getX(),p1.getY()-p2.getY());
		}
		Point2D add(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()+p2.getX(), p1.getY()+p2.getY());
		}
	}
}

Measured memory_bytes: 26996
<?php
$input = trim(fgets(STDIN));
List($r, $c) = explode(" ", $input);

$table = [];
for ($i = 0; $i < $r; $i++) {
  $input = trim(fgets(STDIN));
  $table[] = explode(" ", $input);
}

$sum_c = array_fill(0, $c + 1, 0);
for ($i = 0; $i < $r; $i++) {
  $table[$i][] = array_sum($table[$i]);
  for ($j = 0; $j < $c+1; $j++) {
    $sum_c[$j] += $table[$i][$j];
  }
}

foreach ($table as $row) {
  echo implode(" ", $row) . PHP_EOL;
}
echo implode(" ", $sum_c) . PHP_EOL;

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

#define MOD (1000000000+7)
#define MAX 100

int N;

int main() {
	cin >> N;

	vector< pair< int, int>> v;
	vector< pair< int, int>> c;
	if( N % 2 ) {
		for( int i = 1; i <= N / 2; i++ ) {
			c.push_back( make_pair( i, N - i ) );
		}
	}
	else {
		for( int i = 1; i <= N / 2; i++ ) {
			c.push_back( make_pair( i, N - i + 1 ) );
		}
	}
	for( int i = 1; i < N; i++ ) {
		for( int j = i + 1; j <= N; j++ ) {
			pair< int, int> p( i, j );
			auto it = find( c.begin(), c.end(), p );
			if( it != c.end() ) {
				continue;
			}
			v.push_back( p );
		}
	}

	cout << v.size() << endl;
	for( int i = 0; i < v.size(); i++ ) {
		cout << v[i]. first << " " << v[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
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)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main() {
  int N,L; cin >> N >> L;
//  vector <string> S(N);
  string S[N];
  rep(i, N) cin >> S[i];
  sort(S, S+N);
  rep(i, N) cout << S[i];
  cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
using namespace std;

typedef long double ld;

int main() {
  int N,M,ans;
  cin>>N>>M;
  vector<int> fav(M,0);
  for (int i = 0; i < N; i++) {
    int K,tmp;
    cin>>K;
    for (int j = 0; j < K; j++) {
      cin>>tmp;
      tmp--;
      fav[tmp]++;
    }
  }
  ans = 0;
  for (int i = 0; i < M; i++) if (fav[i]==N) ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    double sum = 0;
    rep(i,0,N){
        int x;
        cin >> x;
        sum += 1.0 / x;
    }
    printf("%.9lf\n", 1 / sum);
}

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

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    if(s == "Y"){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 3632
s = input().strip()
K = int(input())

indices = [0]*5
substrings = [sorted(list(set([s[i:i+l] for i in range(len(s)-l+1)])))[:5]+['zzzzz'] for l in range(1,6)]
for k in range(K):
    s = min(substrings[l][i] for l, i in enumerate(indices))
    # print([substrings[l][i] for l, i in enumerate(indices)])
    indices[len(s)-1] += 1
    if k == K-1:
        print(s)


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
//N        a0 ... an
//rev(N)   an ... a0
//rev(N)-N an-a0 ... a0-an
//n <= 18
const int maxn=20;
int lim;
ll D,ans,pw[maxn];
void dfs(int x,ll rest,ll num){
	if(x>lim/2){
		if(!rest)ans+=num;
		return;
	}
	if((x==lim/2)&&(lim%2==0)){
		if(!x)dfs(x+1,rest,num*9);
		else dfs(x+1,rest,num*10);
		return;
	}
	if(rest>=0){
		ll dlt=pw[lim-x]-pw[x];
		ll mini=rest/dlt,cnt=10-mini;
		if(!x)cnt--;
		if(cnt>0)dfs(x+1,rest-mini*dlt,num*cnt);
		mini++;cnt=10-mini;
		if(!x)cnt--;
		if(cnt>0)dfs(x+1,rest-mini*dlt,num*cnt);
	}else{
		ll dlt=pw[lim-x]-pw[x];
		ll mini=rest/dlt;
		ll cnt=10+mini;
		if(!mini&&!x)cnt--;
		if(cnt>0)dfs(x+1,rest-mini*dlt,num*cnt);
		mini--;cnt=10+mini;
		if(cnt>0)dfs(x+1,rest-mini*dlt,num*cnt);
	}
}
int main(){
	read(D);
	pw[0]=1;rep(i,1,18)pw[i]=10*pw[i-1];
	for(lim=0;lim<=18;lim++)dfs(0,D,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*input
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................


*/

/*
Author : batman
I am not a human being 
I make  people's living
Without me you'll always be TLE
Come lemme get you Accepted!!
^_^
*/

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

// ALL DEFFINES HERE
#define ll long long int
#define ii pair<int, int>
#define mp make_pair
#define N 100005
#define rep(i, n) for(i=0; i < n; i++)
#define Rep(i, k, n) for(i=k; i < n; i++)
#define pb push_back
#define vi vector<int>
#define vii vector< vector<int> >
#define vl vector<ll>
#define F first
#define S second
#include <initializer_list>
// ALL declarations here const ints etc
const  ll mod =1000000000+7; 

// --->>> main starts here
int comp(int x)
{
	return x > 5?1:0;
}
int main()
{
	ll n, m;
	cin >> n >> m;
	ll i, j;
	char mat[1005][1005];
	ll dist[n+1][m+1];
	rep(i, n)
	rep(j, m)dist[i][j]=0;
	rep(i, n)
		rep(j, m)
			cin >> mat[i][j];
	for ( i=1; i<m; i++)
		if ( mat[0][i] == '.')
			dist[0][i]=1;
		else
			break;
		for ( i=1; i<n; i++)
		if ( mat[i][0] == '.')
			dist[i][0]=1;
		else
			break;
	for ( i=1; i < n; i++)
	{
		for  (j=1; j < m; j++)
		{
			if ( mat[i][j]=='.')
				dist[i][j]=((dist[i-1][j]*1LL)%mod+((dist[i][j-1])*1LL)%mod)%mod;
		}
	}
	cout << dist[n-1][m-1]%mod<< "\n";
	


}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int m;
int a[100005];
int t;
map<int,ll> g;
map<int,ll> ::iterator it;

int main()
{
    ll t;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>t;
        a[i]=(t+a[i-1]+m)%m;
        g[a[i]]++;
    }
    g[0]++;
    ll ans=0;
    for(it=g.begin();it!=g.end();it++)
    {
       // cout<<v[i]<<endl;
           ans+=(it->second*(it->second-1))/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
int main(){
 vector<int> vec;
  for(int i=1; i<=5; ++i){
    int v;
    cin>>v;
    vec.push_back(v);
  }
  int ans = -1;
  for(int i=1; i<=5; ++i){
   if(vec[i-1] != i){
   	ans = i;
   }
  }
  cout<<ans;
}

Measured memory_bytes: 3592
from collections import defaultdict
import heapq


def dijkstra(N, adj, cost, start):
    INF = 10 ** 15
    min_cost = [INF] * N
    min_cost[start] = 0
    que = [(0, start)]
    while len(que) > 0:
        c, node = heapq.heappop(que)
        for next_node in adj[node]:
            next_cost = min_cost[node] + cost[(node, next_node)]
            if next_cost < min_cost[next_node]:
                min_cost[next_node] = next_cost
                heapq.heappush(que, (next_cost, next_node))
    return min_cost


def main():
    MONEY_MAX = 10 ** 15
    N, M, S, T = list(map(int, input().split()))
    S -= 1
    T -= 1
    adj = defaultdict(list)
    yen = defaultdict(int)
    snuuk = defaultdict(int)
    for _ in range(M):
        U, V, A, B = list(map(int, input().split()))
        U -= 1
        V -= 1
        adj[U].append(V)
        adj[V].append(U)
        yen[(U, V)], yen[(V, U)] = A, A
        snuuk[(U, V)], snuuk[(V, U)] = B, B
    min_yen = dijkstra(N, adj, yen, S)
    min_snuuk = dijkstra(N, adj, snuuk, T)
    # 都市iで両替をしてs -> tを移動した場合の最小コスト
    min_cost = [y + s for y, s in zip(min_yen, min_snuuk)]
    city_cost = [(cost, city) for city, cost in enumerate(min_cost)]
    heapq.heapify(city_cost)
    ans = [0] * N
    cost, city = heapq.heappop(city_cost)
    for i in range(N):
        # i年後に都市0 ～ i - 1の両替所は使えない
        while city < i:
            cost, city = heapq.heappop(city_cost)
        ans[i] = MONEY_MAX - cost
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Measured memory_bytes: 213228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-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 void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    if(N < M) swap(N, M);
    ll ans = 1;
    if(N == M){
        for(int i=N;i>1;i--){
            ans *= i;
            ans %= MOD;
        }
        for(int i=M;i>1;i--){
            ans *= i;
            ans %= MOD;
        }
        ans *= 2;
        ans %= MOD;
    }
    else if(N - 1 == M){
        for(int i=N;i>1;i--){
            ans *= i;
            ans %= MOD;
        }
        for(int i=M;i>1;i--){
            ans *= i;
            ans %= MOD;
        }
    }
    else ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    FOR(i, 0, n) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());
    int now = 0;
    int cnt = 0;
    int cap = 0;
    FOR(i, 0, n) {
        if (t[i] <= now&&cap <= c - 1) {
            cap++;
            continue;
        }
        cnt++;
        cap = 1;
        now = t[i] + k;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    char a;
    cin >> a;
    if ('A'<=a&&a<='Z') cout << 'A' << endl;
    else cout << 'a' << endl;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 1e3 + 10;
const ll INF = LLONG_MAX;

namespace Flow {
    bool chkmax(ll &a, const ll &b) { return b > a ? a = b, true : false; }

    struct Node {
        struct Edge *head, *from;
        ll dis;
        bool inq;
        Node();
    };
    vector<Node *> nodes;
    Node::Node() : head(NULL) { nodes.push_back(this); }

    struct Edge {
        Node *to;
        ll len, cap;
        Edge *nxt, *rev;
        Edge(Node *to, int len, int cap, Edge *nxt): to(to), len(len), cap(cap), nxt(nxt) {}
    };

    void createEdge(Node *u, Node *v, int len, int cap) {
        u->head = new Edge(v, len, cap, u->head);
        v->head = new Edge(u, -len, 0, v->head);
        (u->head->rev = v->head)->rev = u->head;
    }

    bool SPFA(Node *S, Node *T) {
        for (Node *i : nodes) i->dis = -INF, i->inq = false;
        S->dis = 0;
        queue<Node *> que;
        que.push(S); S->inq = true;
        while (!que.empty()) {
            Node *x = que.front(); que.pop(); x->inq = false;
            for (Edge *i = x->head; i; i = i->nxt) {
                if (i->cap && chkmax(i->to->dis, x->dis + i->len)) {
                    i->to->from = i;
                    if (!i->to->inq) {
                        i->to->inq = true;
                        que.push(i->to);
                    }
                }
            }
        }
        return T->dis != -INF;
    }

    ll solve(Node *S, Node *T) {
        ll cost = 0;
        while (SPFA(S, T)) {
            ll f = INF;
            for (Node *i = T; i != S; i = i->from->rev->to) f = min(f, i->from->cap);
            for (Node *i = T; i != S; i = i->from->rev->to) {
                i->from->cap -= f; i->from->rev->cap += f;
                cost += i->from->len * f;
            }
        }
        return cost;
    }
}

struct Point {
    ll x, y;
    int cnt;
} pA[MAX_N], pB[MAX_N];

int N;

Flow::Node *S, *A, *B, *C, *D, *T;

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%lld%lld%d", &pA[i].x, &pA[i].y, &pA[i].cnt);
    for (int i = 1; i <= N; i++) scanf("%lld%lld%d", &pB[i].x, &pB[i].y, &pB[i].cnt);
    S = new Flow::Node();
    A = new Flow::Node();
    B = new Flow::Node();
    C = new Flow::Node();
    D = new Flow::Node();
    T = new Flow::Node();
    for (int i = 1; i <= N; i++) {
        Flow::Node *t = new Flow::Node();
        Flow::createEdge(S, t, 0, pA[i].cnt);
        Flow::createEdge(t, A, -pA[i].x - pA[i].y, pA[i].cnt);
        Flow::createEdge(t, B, pA[i].x - pA[i].y, pA[i].cnt);
        Flow::createEdge(t, C, pA[i].x + pA[i].y, pA[i].cnt);
        Flow::createEdge(t, D, -pA[i].x + pA[i].y, pA[i].cnt);
    }
    for (int i = 1; i <= N; i++) {
        Flow::Node *t = new Flow::Node();
        Flow::createEdge(t, T, 0, pB[i].cnt);
        Flow::createEdge(A, t, pB[i].x + pB[i].y, pB[i].cnt);
        Flow::createEdge(B, t, -pB[i].x + pB[i].y, pB[i].cnt);
        Flow::createEdge(C, t, -pB[i].x - pB[i].y, pB[i].cnt);
        Flow::createEdge(D, t, pB[i].x - pB[i].y, pB[i].cnt);
    }
    ll ans = Flow::solve(S, T);
    printf("%lld\n", ans);
}


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

using namespace std;



int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int total = 0;
    for (int i = 0; i < N; i++) {
        total += A[i];
    }
    int closeInt;
    if (total%N == 0) {
        closeInt = total/N;
    }
    else if (ceil( double(total)/N) - double(total)/N < double(total)/N - floor(double(total)/N)) {
        closeInt = int(ceil( double(total)/N));
    }
    else {
        closeInt = int(floor(double(total)/N));
    }
    int cost = 0;
    for (int i = 0; i < N; i++) {
        cost += (closeInt - A[i]) * (closeInt - A[i]);
    }
    cout << cost;

    return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int INF=9e18;
const int N=1e5+1;
int a[N];
map<int,int> mp1;
map<int,int> mp2;
vector<pair<int,int>> vec1;
vector<pair<int,int>> vec2;
main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(i%2)mp1[a[i]]++;
        else mp2[a[i]]++;
    }
    for(auto x:mp1)vec1.push_back({x.S,x.F});
    for(auto x:mp2)vec2.push_back({x.S,x.F});
    int mn=INF;
    vec2.push_back({0,0});
    vec1.push_back({0,0});
    sort(vec1.begin(),vec1.end());
    sort(vec2.begin(),vec2.end());
    reverse(vec1.begin(),vec1.end());
    reverse(vec2.begin(),vec2.end());
    if(vec1[0].S!=vec2[0].S){
        cout<<n-(vec1[0].F+vec2[0].F);
    }
    else{
        mn=min(mn,n-(vec1[0].F+vec2[1].F));
        mn=min(mn,n-(vec1[1].F+vec2[0].F));
        cout<<mn<<endl;
    }
}


Measured memory_bytes: 12460
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
ll x;
cin >> x;
if (x < 1200) cout << "ABC";else cout << "ARC";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(all(a));
    cout << a[0] + a[1] + a[2]*10 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#define ll long long
using namespace std;

ll n,y;
int main(){
	cin >> n >> y;
	if((y / 1000) > n * 10 || (y / 1000) < n * 1){
		printf("-1 -1 -1");	return 0;
	}
	for(int i = 0; i <= n ; i++){
		for(int j = 0; j <= n - i; j++){
			for(int k = 0; k <= n - i - j; k++){
				if(10000 * i + 5000 * j + 1000 * k == y && i + j + k == n){
					printf("%d %d %d",i,j,k);
					return 0;
				}
			}
		}
	}
	printf("-1 -1 -1");
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s,t,u,r;
  int a,b=0;
  cin>>s;
  cin>>t;
  cin>>a;
  cin>>b;
  cin>>u;
  if(s==u){
    a=a-1;
  r= to_string(a) +" "+ to_string(b);
  cout<< r; 
  }
  else{
    b= b-1;
    r= to_string(a) +" "+ to_string(b);
    cout<<r;
  }
  return 0;
}

Measured memory_bytes: 256
import sys


def solve(inp):
    A = list(map(int, inp.readline().strip().split(' ')))

    A = sorted(A)
    if A[0] + A[1] == A[2]:
        return "Yes"
    else:
        return "No"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int N,F[MAXN],Pow0[MAXN],Pow1[MAXN];char s[MAXN];
int main()
{
	int c=0;
	for (int i=1;i<MAXN;++i)
	{
		int v=i;
		int cnt=0;
		while (v) cnt+=(v&1),v>>=1;
		F[i]=F[i%cnt]+1;
	}
	cin>>N;
	scanf("%s",s+1);
	for (int i=1;i<=N;++i) if (s[i]=='1') ++c;
	int v0=0,v1=0;
	for (int i=1;i<=N;++i)
	{
		if (c-1>0) v0=(v0*2+(s[i]-48))%(c-1);
		v1=(v1*2+(s[i]-48))%(c+1);
	}
	if (c-1>0) Pow0[0]=1%(c-1);
	Pow1[0]=1%(c+1);
	for (int i=1;i<=N;++i)
	{
		if (c-1>0) Pow0[i]=(Pow0[i-1]*2)%(c-1);
		Pow1[i]=(Pow1[i-1]*2)%(c+1);
	}
	for (int i=1;i<=N;++i)
		if (s[i]=='1')
		{
			if (c-1==0)
			{
				printf("0\n");
			}
			else
			{
				int v=v0;
				v-=Pow0[N-i];
				if (v<0) v+=(c-1);
				printf("%d\n",F[v]+1);
			}
		}
		else
		{
			int v=v1;
			v+=Pow1[N-i];
			if (v>=c+1) v-=(c+1);
			printf("%d\n",F[v]+1);
		}
	return 0;
}

Measured memory_bytes: 6356
## coding: UTF-8
N = int(input())
h = list(map(int,input().split()))
dp = [-1] * N

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, N):
    #print('i:{}, h[i]:{}'.format(i, h[i]))
    #print('dp[i-2]+abs(h[i-2]-h[i]):{}, dp[i-1]+abs(h[i-1]-h[i]):{}'.format(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i])))
    dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]))
    #print(dp)

print(dp[-1])


Measured memory_bytes: 52428
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include<cstring>
#include <math.h>
using namespace std;

typedef long long ll;
int main()
{
    int a,b;
    cin>>a>>b;
    int k=max(a,b);
    if((int)(a/0.08)==(int)(b/0.1))
    {
        cout<<b*10<<endl;
        return 0;
    }
    for(int i=k;i<=500000;i++)
    {
        int t=i*0.08;
        int y=i*0.1;
        if(y==b&&t==a)
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}



Measured memory_bytes: 256