akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::string> W){
    bool ans = true;
    set<string> word;
    REP(i, N) word.insert(W[i]);
    if (word.size() != N) ans = false;
    else {
        REP(i, N) {
            if (i == N - 1) continue ;
            if (W[i][W[i].size() - 1] != W[i + 1][0]) ans = false;
        }
    }
    if (ans) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    cin >> N;
    std::vector<std::string> W(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> W[i];
    }
    solve(N, std::move(W));
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
int main(){
	int n,high=0;
	int a[105],b[10];
	memset(b,0,sizeof(b));
	scanf("%d",&n);
	for(int i = 1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = 1;i<=n;i++){
		if(a[i]>=1&&a[i]<=399) b[1]++;
		else if(a[i]>=400&&a[i]<=799) b[2]++;
		else if(a[i]>=800&&a[i]<=1199) b[3]++;
		else if(a[i]>=1200&&a[i]<=1599) b[4]++;	
		else if(a[i]>=1600&&a[i]<=1999) b[5]++;
		else if(a[i]>=2000&&a[i]<=2399) b[6]++;
		else if(a[i]>=2400&&a[i]<=2799) b[7]++;
		else if(a[i]>=2800&&a[i]<=3199) b[8]++;
		else
			high++;
	}
	int low=0;
	for(int i = 1;i<=8;i++){
		if(b[i]!=0) low++;
	}
	int max,min;
	if(low==0) min=1,max=high;
	if(low>0&&low<=8)
	{
		min=low;
		max=low+high;
	}
	printf("%d %d\n",min,max);
}

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

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )
int N;
int A[1000];
int B[11][9];
int minv = 100000;
int calc(int n, int d = 10) {
    if (d == 0) {
        return n/A[d] + n%A[d];
    }
    int m = minv;
    int tmp = max(0, n/A[d] - 9);
    for (int i = n/A[d]; i >= tmp; i--) {
        if(i > m) {
            break;
        }
        m = min(m, i+calc(n-i*A[d], d-1));
        if(d == 10) {
            minv = min(m, minv);
        }
    }
    return m;
}
int main() {
    cin >> N;
    int a=6, b=9;
    int ii = 0;
    while(100001/a){
        A[ii++] = a;
        a*=6;
    }
    while(100001/b){
        A[ii++] = b;
        b*=9;
    }
    sort(A, A+ii);
    cout << calc(N) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		n = sc.nextInt();
		m = sc.nextInt();
		char[][] a = new char[n][n];
		char[][] b = new char[m][m];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < m; i++) {
			b[i] = sc.next().toCharArray();
		}

		boolean match = true;
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < n; x++) {
				if(y + m - 1 >= n || x + m - 1 >= n) continue;

				match = true;
				for (int y2 = 0; y2 < m; y2++) {
					for (int x2 = 0; x2 < m; x2++) {
						if(a[y + y2][x + x2] != b[y2][x2]) match = false;
					}
				}
				if(match) {
					System.out.println("Yes");
					return;
				}
			}
		}

		if(!match) {
			System.out.print("No");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int ans = 0;
    int N;
    cin >> N;
    
    vector<long int> B(N+1);
    
    for (int i=0; i<N-1; i++){
        long int b;
        cin >> b;
        B[i+1] = b;
        if( i == 0){
            B[0] = b;
        }
        if( i == N-2){
            B[N] = b;
        }
    }
    
    for(int i=0; i<N; i++){
        ans += min(B[i],B[i+1]);
    }

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


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

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
const ll MAX = 5100000;

ll fac[MAX], finv[MAX], inv[MAX], a[100010];

ll combination(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	ll n, v; cin >> n;
	map<ll, ll> m;
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i];
		m[a[i]]++;
		if (m[a[i]] == 2) {
			v = a[i];
		}
	}

	ll l = -1, r;
	for (int i = 0; i < n + 1; i++) {
		if (a[i] == v && l == -1) {
			l = i;
		}
		else if (a[i] == v) {
			r = i;
		}
	}

	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
	for (ll i = 0; i < n + 1; i++) {
		ll k = combination(l + (n - r), i);
		ll p = (combination(n + 1, i + 1) - k + MOD) % MOD;
		cout << p << endl;
	}

	return 0;
}

Measured memory_bytes: 127744
import numpy as np
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(n)]
B=np.array(B)
C=np.array(C)
cnt=0
for i in range(n):
  if (B*C[i]).sum()+c>0:
    cnt+=1
print(cnt)

Measured memory_bytes: 12496
#include <bits/stdc++.h>
using namespace std;
long long dp[3001][3];
int a[3];
int main () {
  int n;
  long long sum = 0;
  scanf ("%d %d %d %d",&a[0],&a[1],&a[2],&n);
  dp[0][0] = 1;
  for (int y = 0; y < 3; y++) {
    for (int x = 0; x <= n-a[y]; x++) {
      for (int z = y; z >= 0; z--) {
        dp[x + a[y]][y] += dp[x][z];
      }
    }
    sum += dp[n][y];
  }
  printf ("%lld\n",sum);
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <random>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define LLREP(i,n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define SORT(x) sort(ALL(x))
#define REVE(x) reverse(ALL(x))
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef queue<int> QI;
typedef long long LL;

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;
}

Measured memory_bytes: 256
import heapq as h

# input
n, m = map(int, input().split())
la = list(map(lambda x: int(x)*-1, input().split()))

h.heapify(la)

while m > 0:
    max = abs(la[0])
    h.heapreplace(la, (max // 2)*-1)
    m -= 1

print(abs(sum(la)))


Measured memory_bytes: 14180
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
bool prime(int x){
	for(int i=2;i*i<=x;i++)
	if(x%i==0)
	return false;
	return true;
}
bool isprime[200010];
int main(){
	int x;
	cin>>x;
	for(int i=1;i<=2*x;i++){
		isprime[i]=prime(i);
	}
	for(int i=x;;i++)
	if(isprime[i]){
		cout<<i;
		return 0;
	}
	re 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int K, N;
  scanf("%d", &K);
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  std::sort(A.begin(), A.end());
  long long ans = 2*K;
  for (int i=1; i<N; i++){
    ans = std::min(ans, (long long)K-((long long)A[i]-(long long)A[i-1]));
  }
  ans = std::min(ans, (long long)K-((long long)A[0]+K-A[N-1]));
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
        int A, B, K;
        cin >> K >> A >> B;

        while(A <= B)
        {
                if(A % K == 0)
                {
                        cout << "OK" << endl;
                        return 0;
                }

                A++;
        }

        cout << "NG" << endl;

        return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int D,h,w,x[N],y[N],qz[N];
signed main()
{
    h=read(), w=read(), D=read();
    for(ri int i=1;i<=h;i++)
    {
        for(ri int j=1;j<=w;j++)
        {
            int k=read();
            x[k]=i, y[k]=j;
        }
    }
    for(ri int i=D+1;i<=h*w;i++) qz[i]=qz[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
    for(ri int Q=read();Q;Q--)
    {
        int p,q;
        p=read(), q=read();
        printf("%lld\n",qz[q]-qz[p]);
    }
    return 0;
}

Measured memory_bytes: 5824
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

vector<ll>graph[N];
bool vis[N], f;
ll ans[N];

void bfs(ll src)
{
    deque<ll> dq;
    dq.eb(src);
    vis[src] = 1;
    while(!dq.empty())
    {
        ll ma_src = dq.front();
        dq.pop_front();
        for(auto adj: graph[ma_src]){
            if(!vis[adj]){
                vis[adj] = 1;
                ans[adj] = ma_src;
                dq.eb(adj);
                f = 1;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m, i, u, v;
    cin >> n >> m;
    for(i = 0; i < m; i++){
        cin >> u >> v;
        graph[v].eb(u);
        graph[u].eb(v);
    }
    bfs(1);
    if(!f) cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        for(i = 2; i <= n; i++){
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 17800
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define forn(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define TC(n) while(n--)
#define forb(i,n) for(int i=n-1;i>=0;--i)
#define repb(i,n) for(int i=n;i>=1;--i)
#define print(a) cout << a << endl
#define prin(a) cout << a
#define scan(a) cin >> a 
#define scan2(a,b) cin >> a >> b
#define scan3(a,b,c) cin >> a >> b >> c
#define scan4(a,b,c,d) cin >> a >> b >> c >> d
typedef vector<int> vi;
typedef vector<pair <int,int> > vpii;
typedef map<int,int > mapii;
typedef set<int> si;

typedef long long LL;
typedef unsigned long long ULL;

const int aMAX = 1e6+6;
const LL LLMAX = 1e18;
const int MAX = 1e9;
const int mMAX = 1e3 + 3;
int arr[aMAX];
int mat[mMAX][mMAX];

vi v;
int n,t;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	scan(n);
	forn(i,n){
		scan(t);
		v.pb(t);
	}
	sort(all(v));
	reverse(all(v));

	int st = 0;
	forn(i,n){
		//print(v[i]);
		if(i % 2 == 0) st+= v[i];
		else st -= v[i];
		//print(st);
	}

	print(st);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    double money,ans=0;
    string s;
    for(int i = 0; i < n; i++)
    {
        cin>>money>>s;
        if(s=="JPY")ans+=money;
        if(s=="BTC")ans+=money*380000;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
l=[0,0,0]
for i in P:
    if i<=A:
        l[0]+=1
    elif i<=B:
        l[1]+=1
    else:
        l[2]+=1
print(min(l))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll IMF = 1LL << 60;
int main() {
  ll X;
  cin >> X;
  int a, b;
  for(ll i = -200; i <= 200; i++) {
    for(ll j = -200; j <= 200; j++) {
      if(pow(i, 5) - pow(j, 5) == X) {
       a = i;
       b = j;
      }
    }
  }

  cout << a << " " << b;
  return 0;
}

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

public class Main{
    
    public static void main(String[] arg){

        Scanner scan =new Scanner(System.in);

        int n=scan.nextInt();
        int l=scan.nextInt();
        ArrayList<Integer> S=new ArrayList<>();
        ArrayList<Integer> absS=new ArrayList<>();
        
        for(int i=0;i<n;i++){
            S.add(l+i);
            absS.add(Math.abs(l+i));
        }

        int minIndex=absS.indexOf(Collections.min(absS));
        S.set(minIndex,0);
        
        int sum=0;
        for(int d : S){
            sum+=d;
        }
        System.out.print(sum);



    }
}

Measured memory_bytes: 21844
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double d=sc.nextDouble();
		double t=sc.nextDouble();
		double s=sc.nextDouble();
		if((d/s)<=t) System.out.println("Yes");
		else System.out.println("No");

	}

}


Measured memory_bytes: 28716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using df = vector<vll>;
// df data(n, vll(m));
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, m, n) for (ll i = m; i < n; ++i)


int main() {
  int n;
  ll x;
  cin >> n >> x;
  vll arr(n);
  rep(i, n) cin >> arr[i];
  sort(arr.begin(), arr.end());
  ll sum = 0;
  rep(i, n) sum += arr[i];
  int res = 0;
  if (sum == x) {
    res = n;
  } else if (sum < x) {
    res = n - 1;
  } else {
    sum = 0;
    rep(i, n) {
      sum += arr[i];
      if (sum > x) {
        res = i;
        break;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	string a, b;
	cin >> a >> b;
	if (a.size() > b.size())puts("GREATER");
	else if (a.size() < b.size())puts("LESS");
	else {
		if (a > b)puts("GREATER");
		else if (a < b)puts("LESS");
		else puts("EQUAL");
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a[5];
  for(int i  = 0; i < 5; i++)
  	cin>>a[i];
  for(int i = 0; i < 5; i++)
  {
    if(a[i] == 0)
      	cout<<i+1;
   }
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
using namespace std;
 
 int main()
 {
	 int a[3], i, c;
	 for(i=0; i<3; i++){
		 cin >> a[i];
	 }
	 if(a[2]<a[1])
	 swap(a[2], a[1]);
	 if(a[1]<a[0])
	 swap(a[1],a[0]);
	 if(a[2]<a[1])
	 swap(a[1],a[2]);
	 c=a[2]-a[0];
	 cout << c;
 }


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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        long N = cin.nextLong();
        long M = cin.nextLong();

        double X = Math.Sqrt(M);
        long ans = 0;

        for (int i = 1; i <= X; i++)
        {
            if (M % i == 0)
            {
                if (i >= N)
                {
                    ans = Math.Max(M / i, ans);
                }
                else if (M / i >= N)
                {
                    ans = Math.Max(i, ans);
                }
            }
        }

        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

using namespace std;

int main(){
	ll n; cin >> n;
	vl a(n);
	for (ll i = 0; i < n; ++i){
		ll t; cin >> t;
		ll count = 0;
		while (t % 2 == 0){ t /= 2; count++; }
		a[i] = count;
	}cout << *min_element(all(a)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<set>

using namespace std;

int main(void){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0, A + B - N) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        int[] data = Console.ReadLine().Split().Select(int.Parse).ToArray();
        if(data[0] == data[1])
        {
            Console.WriteLine("a == b");
        }else if(data[0] > data[1])
        {
            Console.WriteLine("a > b");
        }else
        {
            Console.WriteLine("a < b");
        }
    }
}


Measured memory_bytes: 18404
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;

int32_t main()
{
	usecppio
	int a, b;
	cin >> a >> b;
	cout << 6-a-b;
}

Measured memory_bytes: 256
#ABC110 B 

#入力
N, M, X, Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

#処理
isnotWar = False
if X < Y:
    for Z in range(X+1,Y+1): 
        if max(x) < Z and min(y) >= Z:
            isnotWar = True
            
if isnotWar:
    print("No War")
else:
    print("War")            

Measured memory_bytes: 3064
from itertools import permutations

n = int(input())
li = [i for i in range(1,n+1)]
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

for i,j in enumerate(permutations(li)):
    if j == p:
        num_p = i
    if j == q:
        num_q = i

print(abs(num_p-num_q))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int n, k;
    cin >> n >> k;
    long long min = 10000000000000000;
    vector<int>as(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
    }
    for (int i = 0; i < n - k + 1; i++){
        if (as[k + i - 1] <= 0){
            if (-1 * as[i] < min){
                min = -1 * as[i];
            }
        }
        if (as[k + i - 1] >= as[i] && as[i] >= 0){
            if (as[k + i - 1] < min){
                min = as[k + i - 1];
            }
        }
        if (as[k + i - 1] >= 0 && as[i] <= 0){
            if (-2 * as[i] + as[k + i - 1] < min){
                min = -2 * as[i] + as[k + i - 1];
            }
            if (-1 * as[i] + 2 * as[k + i - 1] < min){
                min = -1 * as[i] + 2 * as[k + i - 1];
            }
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
using namespace std;
#define N 32
#define inf 1000000

int d[N][N], a[N][N];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int n, m, i, j, I, J, ans;
queue <pair< int, int> > q;
char c;
bool valid (int X, int Y){
    if (X < 0 || Y < 0)
        return false;
    if (X < n && Y < m)
        return true;
    return false;
}
int min_road (int xs, int ys, int xf, int yf){
    if (a[xs][ys] || a[xf][yf])
        return 0;
    int it, jt, x, y, X, Y, found;
    for (it = 0; it < n; ++it)
        for (jt = 0; jt < m; ++jt)
        d[it][jt] = inf;
    d[xs][ys] = 0;
    q.push(make_pair(xs, ys));
    found = 0;
    while (!q.empty() && !found){
        x = q.front().first;
        y = q.front().second;
        if (x == xf && y == yf){
            found = 1;
        }
        q.pop();
        for (it = 0; it < 4; ++it){
            X = x + dx[it];
            Y = y + dy[it];
            if (valid (X, Y) && !a[X][Y] && d[x][y] + 1 < d[X][Y]){
                d[X][Y] = 1 + d[x][y];
                q.push (make_pair (X, Y));
            }
        }
    }
    while (!q.empty())
        q.pop();
    if (d[xf][yf] < inf){
        //cout << xs <<" " << ys << " " << xf << " " << yf << " " << d[xf][yf] << '\n';
        return d[xf][yf];
    }
    else
        return 0;
}
int main()
{
    cin >> n >> m;
    for (i = 0; i < n; ++i){
        for (j = 0; j < m; ++j){
            cin >> c;
            if (c == '#'){
                a[i][j] = 1;
            }
            else
                a[i][j] = 0;
        }
    }
    ans = 0;
    for (i = 0; i < n; ++i)
        for (j = 0; j < m; ++j)
        for (I = 0; I < n; ++I)
        for (J = 0; J < m; ++J){
        ans = max (ans, min_road(i, j, I, J));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int length = s.size();
    for (int i = 0; i < length; i++) {
        if (i % 2 == 0){
            cout << s[i];
        }
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 592
from operator import itemgetter
def f(ab, cnt, price, n, m):
        for i in range(n):
                if cnt + ab[i][1] > m:
                        for j in range(1, ab[i][1]):
                                cnt += 1
                                if cnt == m:
                                        price += ab[i][0] * j
                                        break
                        # print(cnt)
                        # print(price)
                        # print("--------")
                        break
                else:
                        cnt += ab[i][1]
                        price += ab[i][0] * ab[i][1]
                        # print(cnt)
                        # print(price)
                        # print("--------")
        # if cnt < m:
        #         print("再帰")
        #         f(ab, cnt, price, n, m)
        # else:
        #         return price
        return price

n, m = map(int, input().split())
ab = []
for _ in range(n):
        ab.append(list(map(int, input().split())))
ab.sort()
# print(ab)
# print("*********")
cnt = 0
price = 0
# for i in range(n):
#         if cnt + ab[i][1] > m:
#                 print("if")
#                 for j in range(1, ab[i][1]):
#                         cnt += j
#                         if cnt == m:
#                                 price += ab[i][0] * j
#                                 break
#                 print(cnt)
#                 print(price)
#                 print("--------")
#                 break
#         else:
#                 cnt += ab[i][1]
#                 price += ab[i][0] * ab[i][1]
#                 print(cnt)
#                 print(price)
#                 print("--------")
print(f(ab, cnt, price, n, m))

Measured memory_bytes: 61864
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int nax = 1e5+5;
int a[nax];
signed main(){
	int n;
	cin>>n;
	int cnt=0;
	int cnt1=0;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		if(a[i]%2==0){
			cnt++;
		}
	}
	for(int i=1; i<=n; i++){
		if(a[i]%2==0){
			if(a[i]%3==0 || a[i]%5==0){
				cnt1++;
			}
		}
	}
	if(cnt==cnt1){
		cout<<"APPROVED"<<endl;
	}
	else{
		cout<<"DENIED"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
//ループverです。移動後はvisitedが増えるので, visited昇順にループを回せば良いです。
#include <iostream>
#include <algorithm>
using namespace std;

int INF = 1000000007;
int n, m;
bool canMove[15][15] = {false};
int ecost[15][15];
int dp[1 << 15][15];	//dp[visited][pos] = これまでの最小コスト（visitedの下位i(>=0)ビット目が1⇔頂点iを訪問済み, pos…現在地.）

int main() {
	int i, j, k;
	
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		ecost[s][t] = d;
		canMove[s][t] = true;
	}
	
	for (i = 0; i < (1 << n); i++) for (j = 0; j < n; j++) dp[i][j] = INF;
	dp[1][0] = 0;
	for (i = 1; i < (1 << n) - 1; i++) {
		for (j = 0; j < n; j++) {
			//if (dp[i][j] >= INF) continue;	//この行は無くてもよい
			for (k = 0; k < n; k++) {
				if (!canMove[j][k]) continue;
				if ((i >> k) & 1) continue;
				dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + ecost[j][k]);
			}
		}
	}
	
	int ans = INF;
	for (j = 0; j < n; j++) {
		if (dp[(1 << n) - 1][j] < INF && canMove[j][0]) {
			ans = min(ans, dp[(1 << n) - 1][j] + ecost[j][0]);
		}
	}
	if (ans >= INF) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


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

int main() {
  int N, A, B, x;
  cin >> N >> A >> B;
  
  x = N * A - B;
  
  if (x > 0){
    cout << B << endl;
  }
  else{
    cout << N * A << endl;
  }
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;
int N;
vector<int> h;
vector<int> memo;

int mi(int pos) {
    if (memo[pos] != INF) { return memo[pos]; }

    if (pos == 0) return memo[0] = 0;
    int res = INF;
    if (pos - 1 >= 0) res = min(res, mi(pos - 1) + abs(h[pos] - h[pos - 1]));
    if (pos - 2 >= 0) res = min(res, mi(pos - 2) + abs(h[pos] - h[pos - 2]));

    return memo[pos] = res;
}

int main() {
    cin >> N;

    h = vector<int>(N, INF);
    rep(i, N) cin >> h[i];

    // 状態 i : 足場 i にいる
    // mi(i) : 足場 i にいる時の最小コスト
    memo    = vector<int>(N + 4, INF);
    memo[0] = 0;

    cout << mi(N - 1) << endl;

    return 0;
}

Measured memory_bytes: 8788
from math import floor
N = int(input())

S = int((N * (N+1)) / 2)

fizz = floor(N/3)
buzz = floor(N/5)
fizzbuzz = floor(N/15)
print(S - int(3 * fizz * (fizz+1)/2) -
          int(5*buzz*(buzz+1) /2) +
          int(15 * fizzbuzz * (fizzbuzz+1)/2))

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

import static java.lang.System.in;

class Main{
    static int n;
    static long[] x,c,v,sum;
    static long[][] f;
    static long[] dp;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), K = sc.nextInt();
        PriorityQueue<Sushi> pq = new PriorityQueue<>();
        for(int i=0;i<n;i++){
            int t = sc.nextInt(), d = sc.nextInt();
            pq.add(new Sushi(t,d));
        }
        PriorityQueue<Integer> outCan = new PriorityQueue<>();
        long sum = 0;
        int[] used = new int[n+1];
        int kinds = 0;
        for(int i=0;i<K;i++){
            Sushi cur = pq.poll();
            if(used[cur.type]==0) kinds++;
            else outCan.add(cur.deli);
            used[cur.type]++;
            sum += cur.deli;
        }
        long ans = sum + ((long)Math.pow(kinds,2));
        while(kinds<=K&&pq.size()>0&&outCan.size()>0){
            Sushi cur = pq.poll();
            if(used[cur.type]>0) continue;
            used[cur.type]++;
            sum -= outCan.poll();
            sum += cur.deli;
            kinds++;
            ans = Math.max(ans,sum+((long)Math.pow(kinds,2)));
        }
        System.out.println(ans);
    }
    static class Sushi implements Comparable<Sushi>{
        int type, deli;
        public Sushi(int t, int d){this.type=t; this.deli=d;}
        public int compareTo(Sushi o){
            return o.deli-this.deli;
        }
    }
}


Measured memory_bytes: 91168
n,m,x=gets.chomp.split(" ").map { |e| e.to_i }
a=gets.chomp.split(" ").map { |e| e.to_i }

tax = Array.new(n+1,0)

for i in a do
  tax[i] = 1
end

ans1 = ans2 =  0

for i in x+1..n do
  ans1 += tax[i]
end

for j in 0..x do
  ans2 += tax[j]
end

puts ans1 > ans2 ? ans2 : ans1

Measured memory_bytes: 2044
def solve():
    A, B = map(int, input().split())
    s1 = tuple(map(int, input().split()))
    s2 = tuple(map(int, input().split()))
    result = 0

    for i in range(B):
        k = 0
        cnt = 0
        for j, n in enumerate(s2[i:]):
            for m in s1[k:]:
                k += 1
                if n == m:
                    cnt += 1
                    break
        if cnt > result:
            result = cnt
        if result >= B-i:
            break
    print(result)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 8452
N, M = map(int, input().split())
List = []
for _ in range(N):
  P, Q = map(int,input().split())
  List.append([P,Q])
List = sorted(List)
total = 0
for item in List:
  for _ in range(item[1]):
    total += item[0]
    M -= 1
    if M == 0:
      break
  if M == 0:
    break
print(total)

Measured memory_bytes: 20816
$n, $m = gets.split.map(&:to_i)

$lights = []

$m.times do |i|
  k, *s = gets.split.map(&:to_i)
  ss = Array.new($n, 0)
  s.each do |poyo|
    ss[poyo - 1] = 1
  end
  $lights << ss
end

$answer = gets.split.map(&:to_i)

def rec(i, switches)
  if i >= $n
    cond = $m.times.all? {|i|
      sum = 0      
      $n.times do |j|
        sum += $lights[i][j] * switches[j]
      end

      sum % 2 == $answer[i]
    }

    cond ? 1 : 0
  else
    rec(i + 1, switches + [0]) + rec(i + 1, switches + [1])
  end
end

p rec(0, [])

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;


int main(){
    vector<set<int>> a(8010),b(8010);
    a.at(0).insert(0);b.at(0).insert(0);
    string s;
    cin >> s;
    int x,y;
    cin >> x >> y;
    int aa=1,bb=1,n=0,c=0;
    rep(i,s.size()){
        if (s.at(i)=='F') c++;
        if (s.at(i)=='T') {
            if (n==0){
                for (auto itr=a.at(aa-1).begin();itr!=a.at(aa-1).end();++itr){
                    if (aa==1) a.at(aa).insert(*itr+c);
                    else {a.at(aa).insert(*itr+c);
                    a.at(aa).insert(*itr-c);}
                    //cout << aa << " " << *itr << endl;
                }
                aa++;
            }
            else{
                for (auto itr=b.at(bb-1).begin();itr!=b.at(bb-1).end();++itr){
                    b.at(bb).insert(*itr+c);
                    b.at(bb).insert(*itr-c);
                    //cout << bb << " " << *itr << endl;
                }
                bb++;
            }
            c=0;n=1-n;
        }
    }
    if (n==0){
                for (auto itr=a.at(aa-1).begin();itr!=a.at(aa-1).end();++itr){
                    if (aa==1) a.at(aa).insert(*itr+c);
                    else {a.at(aa).insert(*itr+c);
                    a.at(aa).insert(*itr-c);}
                    //cout << aa << " " << *itr << endl;
                }
                aa++;
            }
            else{
                for (auto itr=b.at(bb-1).begin();itr!=b.at(bb-1).end();++itr){
                    b.at(bb).insert(*itr+c);
                    b.at(bb).insert(*itr-c);
                    //cout << bb << " " << *itr << endl;
                }
                bb++;
            }
    
    if (a.at(aa-1).find(x)!=a.at(aa-1).end() && b.at(bb-1).find(y)!=b.at(bb-1).end()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 234504
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-8
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define N 500005
//#define M 1000005
#define pi 3.14159265358979323846 
#define cpdd const pdd
#define hash Hash
#define list List
using namespace std;
typedef long long LL;
using namespace std;
char c[200005];
int main(){
	int x1,y1,x2,y2;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	double sub=20-pi*5;
	double add=pi*10-20;
	if(x2<x1)
	{
		swap(x1,x2);
		swap(y1,y2);
	}
	int n;
	scanf("%d",&n);
	pii p[200005];
	for(int i=0;i<n;i++)
	scanf("%d %d",&p[i].x,&p[i].y);
	if(y1>y2){
		y1=-y1;
		y2=-y2;
		for(int i=0;i<n;i++)
		p[i].y=-p[i].y;
	}
	sort(p,p+n);
	vector<int> v;
	v.pb(-1e9);
	{
		int i;
		for(i=0;i<n;i++)
		if(p[i].x>=x1)
		break;
		for(;i<n&&p[i].x<=x2;i++)
		{
			if(p[i].y<y1||p[i].y>y2)
			continue;
			if(v.back()<p[i].y)
			v.pb(p[i].y);
			*lower_bound(v.begin(),v.end(),p[i].y)=p[i].y;
		}
	}
	int tot=v.size()-1;
	double ans=(double)(x2-x1)*100+(double)(y2-y1)*100; 
	if(tot>min(y2-y1,x2-x1)){
		//printf("%d %d\n",tot,y2-y1);
		ans+=-sub*min(y2-y1,x2-x1)+add;
	}
	else{
		ans-=sub*(tot);
	}
	printf("%.15lf\n",ans);
}

Measured memory_bytes: 2936
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let k: i32 = read();
    let x: i32 = read();
    let y: i32 = read();

    let ans = x * [n, k].iter().min().unwrap() + y * [n - k, 0].iter().max().unwrap();
    println!("{}", ans);
}

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

using namespace std;

/* bool isok(int mid, int key, vector<int> &vc){
      if(vc[mid] >= key) return true;
      else return false;
}

int binary_search(int key, vector<int> &vc){
    int begin = -1;
    int end = vc.size();
    while(begin - end == 1){
        int mid = (begin + end)/2;
        if(isok(mid, key, vc)) end = mid;
        else begin = mid;
    }
    if()
    return end;
}
*/
int main(){
    int n, cnt=0;
    cin >> n;
    vector<int> ls;
    for(int i=0; i<n; i++){
        int l;
        cin >> l;
        ls.push_back(l);
    }
    sort(ls.begin(), ls.end());
    for(int i=0; i<n; i++){
        int a = ls[i];
        for(int k=0; k<i; k++){
            int b = ls[k];
            int ab = a + b;
            int point = lower_bound(ls.begin(), ls.end(), ab) - ls.begin();
            cnt += point - i - 1;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
double prob[102][101];
signed main() {
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(12);
  while(true) {
    int N, T, L, B; cin >> N >> T >> L >> B;
    if(N==0) break;
    set<int> LOSE, BACK;
    REP(i,L) {
      int l; cin >> l; LOSE.insert(l);
    }
    REP(i,B) {
      int b; cin >> b; BACK.insert(b);
    }
    REP(t,102) REP(n,101) prob[t][n] = 0;
    prob[0][0] = 1.0;
    REP(t,T) {
      REP(n,N+1) {
        if(n==N) {
          prob[t+1][n] += prob[t][n];
        }
        else {
          for(int d = 1; d <= 6; ++d) {
            int next = n + d;
            if(next > N) {
              next -= 2 * (next - N);
            }
            if(LOSE.count(next)) {
              prob[t+2][next] += prob[t][n] / 6;
            }
            else if(BACK.count(next)) {
              prob[t+1][0] += prob[t][n] / 6;
            }
            else {
              prob[t+1][next] += prob[t][n] / 6;
            }
          }
        }
      }
    }
    cout << prob[T][N] << endl;
  }
}

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

const ll MOD = ll(1e9 + 7);

ll dp[60][4][4];
string b[2];

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

	int N;
	cin >> N;
	cin >> b[0] >> b[1];

	dp[0][3][3] = 1;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < 4; j++) { // 上の左
			for(int k = 0; k < 4; k++) { // 下の左
				ll num = dp[i][j][k];
				if(num == 0) continue;
				if(b[0][i] == b[1][i]) {
					for(int c = 0; c < 3; c++) {
						if(c == j || c == k) continue;
						dp[i + 1][c][c] += num;
						dp[i + 1][c][c] %= MOD;
					}
				}
				else {
					for(int u = 0; u < 3; u++) {// 上に塗る色
						if(i - 1 >= 0 && b[0][i - 1] == b[0][i]){
							if(j != u) continue;
						}
						else if(j == u) continue;
						for(int d = 0; d < 3; d++) { // 下に塗る色
							if(i - 1 >= 0 && b[1][i - 1] == b[1][i]){
								if(k != d) continue;
							}
							else if(k == d) continue;

							if(u == d) continue;
							dp[i + 1][u][d] += num;
							dp[i + 1][u][d] %= MOD;
						}
					}
				}
			}
		}
	}

	ll ans = 0;
	for(int j = 0; j < 4; j++) { // 上の左
		for(int k = 0; k < 4; k++) { // 下の左
			ans += dp[N][j][k];
			ans %= MOD;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//0026 Dropping Ink
//ÉCNðÆµÄV~ðÂ¯é
//¢­ç©CNðÆµ½ãAÜ¾V~ªoÄ¢È¢Æ±ëÆAêÔZ¢V~ÌÊð¦æ

//¡ñàI¹ð½à¢ÄÈ¢æH

#include<iostream>
#include<algorithm>
#include<limits>
using namespace std;

class Paper
{
public:
	static const int N = 10;
	static const int SIDE_SIZE = N+4;	//åÌCNÅRêÈ¢öxÌCN
	static const int FIELD_SIZE= SIDE_SIZE * SIDE_SIZE;
private:
	int a[FIELD_SIZE];
public:

	Paper(){fill(a, a+FIELD_SIZE, 0);}
	void Drop(int x, int y, int dropSize)
	{
		if(dropSize >= 3)
		{
			static const int X[] = {-2, 0, 2, 0};
			static const int Y[] = {0,  2, 0,-2};
			const int s = sizeof(X)/sizeof(X[0]);
			for(int i = 0; i < s; i++)
				Get(x+X[i], y+Y[i])++;
		}
		if(dropSize >= 2)
		{
			static const int X[] = {-1, 1, 1, -1};
			static const int Y[] = {1, -1, 1, -1};
			const int s = sizeof(X)/sizeof(X[0]);
			for(int i = 0; i < s; i++)
				Get(x+X[i], y+Y[i])++;
		}
		static const int X[] = {0, 1, 0, -1, 0};
		static const int Y[] = {0, 0, 1, 0, -1};
		const int s = sizeof(X)/sizeof(X[0]);
		for(int i = 0; i < s; i++)
			Get(x+X[i], y+Y[i])++;
	}
	int& Get(int x, int y){return a[(y+2)*SIDE_SIZE + (x+2)];}
};

int main(void)
{
	int x, y, size;
	char dummy;

	Paper p;

	while( cin >> x >> dummy >> y >> dummy >> size )
	{
		p.Drop(x, y, size);
	}

	int whiteCount = 0,
		maxDensity = numeric_limits<int>::min();
	for(x = 0; x < Paper::N; x++)
	{
		for(y = 0; y < Paper::N; y++)
		{
			int density = p.Get(x, y);
			if(!density)
				whiteCount++;
			maxDensity = max(maxDensity, density);
		}
	}

	cout << whiteCount << endl << maxDensity << endl;

	return 0;
}

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

typedef long long ll;

int main(){
	static int n,m;
	static int l[100010],r[100010];
	scanf("%d%d",&n,&m);
	for(int i = 1 ; i <= m ; i ++){
		scanf("%d%d",&l[i],&r[i]);
	}
	
	int MIN = 1, MAX = n;
	for(int i = 1 ; i <= m ; i ++){
		MIN = max( MIN , l[i] );
		MAX = min( MAX , r[i] );
	}
	cout << max( 0 , MAX-MIN+1 ) << endl;
}

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

public class Main {
	public void solve() throws IOException {
		long[][] dp = new long[5][4001];
		dp[0][0] = 1;
		for(int i = 1; i < 5; i++){
			for(int j = 0; j <= 4000; j++){
				if( dp[i-1][j] > 0 ){
					for(int k = 0; k <= 1000 && j+k <= 4000; k++){
						dp[i][j+k] += dp[i-1][j];
					}
				}
			}
		}
		String str = null;
		while( (str = reader.readLine()) != null ){
			int n = Integer.parseInt(str);
			writer.println(dp[4][n]);			
		}
		writer.flush();
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() throws IOException {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
}

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

using namespace std;

long a[111111], b[111111];
int main() {
	long n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%ld", a + i);
		for (int j = 0; j < 50; j++)
			if (a[i] & 1l << j) b[j]++;
	}
	long x = 0, m = 0;
	for (int j = 0; j < n; j++)
		m += k ^ a[j];
	for (int i = 0; i < 50; i++) {
		x |= long(b[i] < n - b[i]) << i;
		long y = (1l << i) - 1;
		if (k&y + 1) {
			long X = k & ~(y * 2 + 1) | x & y, f = 0;
			for (int j = 0; j < n; j++)
				f += X ^ a[j];
			m = max(m, f);
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 1024