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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n; cin>>n;
    int a, res = 0;
    FOR(i, 1, n + 1) {
        cin>>a;
        if(i & 1) {
            res += (a & 1);
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3608
a = list(map(int, input().split()))
if a[1]-a[0]>=2018:
    print(0)
else:
    l = []
    for i in range(a[1]-a[0]):
        for j in range(i+1, a[1]-a[0]+1):
            l.append(((a[0]+i)*(a[0]+j))%2019)

    print(min(l))

Measured memory_bytes: 75336
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
void MI(int &a, int v) {a = min(a,v);}
void MA(int &a, int v) {a = max(a,v);}
const int N=1e5, INF=1e9;

struct query {int s,d,c;};

signed main() {
    int n,m; cin>>n>>m;
    vector<int> adj[n];
    F(i,m) {
        int a,b; cin>>a>>b;
        a--, b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int nq; cin>>nq;
    query qs[nq];
    F(i,nq) {
        cin>>qs[i].s>>qs[i].d>>qs[i].c;
        qs[i].s--;
    }
    array<int,N> rem,c;
    c.fill(0), rem.fill(-1);
    DEC(i,nq) {
        query qq=qs[i];
        queue<int> q;
        if (rem[qq.s] < qq.d) {
            if (rem[qq.s] == -1)
                c[qq.s] = qq.c;
            rem[qq.s] = qq.d;
            q.push(qq.s);
        }
        while (!q.empty()) {
            int u = q.front(); q.pop();
            if (rem[u]) {
                for (int v : adj[u]) {
                    if (rem[v] < rem[u]-1) {
                        if (rem[v] == -1)
                            c[v] = qq.c;
                        rem[v] = rem[u]-1;
                        q.push(v);
                    }
                }
            }
        }
    }
    F(i,n) P(c[i]);
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        int[]xCopy = new int[N];
        for (int i = 0; i < N; i++ ) {
            int n = sc.nextInt();
            X[i] = n;
            xCopy[i] = n;
        }

        Arrays.sort(xCopy);

        int median1 = xCopy[N/2 - 1];
        int median2 = xCopy[N/2];

        for (int i = 0; i < N; i++) {
            if (X[i] <= median1) {
                System.out.println(median2);
            } else {
                System.out.println(median1);
            }
        }
    }

}


Measured memory_bytes: 85260
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int dp[n + 1];
    ms(dp, 0);
    forr(i, n - 1) {
        int a;
        cin >> a;
        dp[a]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << dp[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 5208
#include <stdio.h>

int main(){

    int a,count=0,i=2;

    scanf("%d",&a);

    while(1)

    {
        while(a>i){

            if(a%i==0 && a!=2){

                count++;


            }

        i++;

        }
            if(count==0)
            {
                break;

            }

    a++;
    i=2;
    count=0;

    }
        if(count==0){

        printf("%d\n",a);


    }



return 0;

}


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

int n, m;
int a[55], b[55];
bool graph[55][55], vis[55];
void dfs(int d)
{
	vis[d] = true;
	for (int i = 0; i < n; i++) {
		if (!graph[d][i]) {
			continue;
		}
		if (vis[i]) {
			continue;
		}
		dfs(i);
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
		for (int j = 0; j < n; j++) {
			vis[j] = false;
		}
		dfs(0);
		for (int j = 0; j < n; j++) {
			if (vis[j] == false) {
				ans++;
				break;
			}
		}


		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}

	cout << ans << endl;
	return 0;

}



Measured memory_bytes: 256
use std::io::*;
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 x: String = read();
    let lower_x = x.to_ascii_lowercase();
    if x != lower_x {
        println!("A");
    } else {
        println!("a");
    }
}


Measured memory_bytes: 2040
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int N;
  long long int X;
  std::cin >> N >> X;
  std::vector<long long int> x(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> x[i];
  }

  std::reverse(x.begin(), x.end());
  std::vector<long long int> cost(N);
  std::vector<long long int> pref(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    cost[i] = 2 * i + 3;
    pref[i + 1] = pref[i] + x[i];
  }
  cost[0] = 5;

  long long int energy = 1ll << 60;
  for (int i = N; i >= 1; --i) {
    long long int ris = (N + i) * X;
    int it = 0;
    for (int k = 0; it < N; ++k) {
      int next_it = std::min(it + i, N);
      ris += cost[k] * (pref[next_it] - pref[it]);
      it = next_it;
      if ( ris > energy ) break;
    }
    energy = std::min(energy, ris);
  }
  std::cout << energy << std::endl;

  return 0;
}


Measured memory_bytes: 4992
N = int(input())

node = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    node[a-1].append(b-1)
    node[b-1].append(a-1)

# 頂点1からの距離が奇数:1、偶数:0
group = [False] * N
# 親ノードを格納する
parents = list(range(N))
stack = [0]

# ノードの選択
while stack:
    p = stack.pop()
    # 子ノードの選択
    for c in node[p]:
        # 親ノードも選択されるので、その場合は飛ばす
        if c != parents[p]:
            # 子ノードの親を自分にする
            parents[c] = p
            # 子ノードのグループを自分と逆に設定する
            group[c] = not group[p]
            stack.append(c)

p = [0] * N
three = 3
if group.count(True) <= N // 3:
    other = 1
    # Trueのところには３の倍数を、Falseにはそれ以外を
    for i in range(N):
        if not group[i] and other <= N:
            p[i] = other
            other += other % 3
        else:
            p[i] = three
            three += 3
elif group.count(False) <= N // 3:
    other = 1
    # Trueのところには３の倍数を、Falseにはそれ以外を
    for i in range(N):
        if group[i] and other <= N:
            p[i] = other
            other += other % 3
        else:
            p[i] = three
            three += 3

else:
    one, two = 1, 2
    # Trueのところには３の倍数を、Falseにはそれ以外を
    for i in range(N):
        if not group[i] and one <= N:
            p[i] = one
            one += 3
        elif group[i] and two <= N:
            p[i] = two
            two += 3
        else:
            p[i] = three
            three += 3
print(" ".join(map(str, p)))


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

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

  int N, K; cin >> N >> K;
  int K2 = K * 2;
  
  vector<vector<int>> a(K2, vector<int>(K2));
  for (int i = 0; i < N; i++) {
    int x, y; cin >> x >> y;
    char c; cin >> c;
    if (c == 'W') x += K;
    a[x%K2][y%K2]++;
  }

  vector<vector<int>> cs(K2+1, vector<int>(K2+1));
  for (int i = 0; i < K2; i++) {
    for (int j = 0; j < K2; j++) {
      cs[i+1][j+1] = cs[i][j+1] + cs[i+1][j]
                   - cs[i][j] + a[i][j];
    }
  }

  auto query = [&](int x1, int y1, int x2, int y2) {
    return cs[x2][y2] - cs[x1][y2] - cs[x2][y1] + cs[x1][y1];
  };

  int ans = 0;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      int res = query(0, 0, i, j)
              + query(i, j, i+K, j+K)
              + query(0, j+K, i, K2)
              + query(i+K, 0, K2, j)
              + query(i+K, j+K, K2, K2);
      ans = max(ans, res);
      ans = max(ans, N-res);
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 31744
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
//		int[] a = new int[n];
		BitSet bs = new BitSet(n);
		for(int i=0; i<m; i++){
//			a[in.nextInt()] = 1;
			bs.set(in.nextInt()-1);
		}
		int bf = -1;
		int[] dist = new int[n];
		for(int i=0; i<n; i++){
			if(bs.get(i)) bf = i;
			if(bf>=0){
				dist[i] = Math.abs(i-bf);
			}else{
				dist[i] = Integer.MAX_VALUE;
			}
		}
		bf = -1;
		for(int i=n-1; i>=0; i--){
			if(bs.get(i)) bf = i;
			if(bf>=0){
				dist[i] = Math.min(dist[i], Math.abs(i-bf));
			}
		}
		int max = 0;
		for(int i=0; i<n; i++){
			
		}
		for(int i=0; i<n; i++) max = Math.max(max, dist[i]);
		System.out.println(max);
	}
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    for(;;){
        ll N, R;
        cin >> N >> R;

        if(N==0 && R==0){
            return 0;
        }

        vector<ll> A(N);
        FOR(i, 0, N){
            A[i] = i+1;
        }

        while(R--){
            ll p, c;
            cin >> p >> c;

            // 右手に取る
            vector<ll> temp;
            ll L = N-p+1-c;
            FOR(i, L, L+c){
                temp.push_back(A[i]);
            }

            // おろす
            FOR(i, L+c, N){
                A[i-c] = A[i];
            }

            // tempを上に乗せる
            ll insert_index = N-c;
            FOR(i, 0, c){
                A[insert_index] = temp[i];
                insert_index++;
            }
        }
        p(A[N-1]);
    }
    
    return 0;
}


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

int main(){
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
x= input()
l_w = []
for i in range(len(x)):
    if x[i] == 'W':
        l_w.append(i)
#print(l_w)
sum = 0
st = 0
for i,j in enumerate(l_w):
    sum += j-st
    st+= 1
print(sum)

Measured memory_bytes: 11368
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#define MAXN 100005
#define ll long long
using namespace std;
ll a[MAXN], b[MAXN], c[MAXN];
ll n;
inline void read() {
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    for(int i = 1; i <= n; i++) cin >> c[i];
}

inline ll searcha(ll x) {//上 比x更小 
    ll l = 1, r = n, mid;
    while(l <= r) {
        mid = (l+r) >> 1;
        if(a[mid] > x)//如果a[mid]更， 
            r = mid - 1;
        else
            l = mid + 1;
    }
    while(a[l] >= x && l >= 1) l --;
    if(l>n){
    	l=n;
	}
    if(l <= 0) 
		l = 0;
    return l;
}
inline ll searchc(ll x) {//下 比x更大 
    ll l = 1, r = n, mid;
    while(l <= r) {
        mid = (l+r) >> 1;
        if(c[mid] > x)
            r = mid - 1;
        else 
            l = mid + 1;
    }
    while(c[l]<=x&&l<=n){
    	l++;
	}
	if(l<0){
		l=0;
	}
	if(l>n){
		return 0;
	}
    return n-l+1;
}

int main() {
    long long ans = 0;
    ll loc1, loc2;
    read();
    sort(a+1, a+1+n);
    sort(c+1, c+1+n);
    for(int i = 1; i <= n; i++) {
        loc1 = searcha(b[i]);
        loc2 = searchc(b[i]);
       // printf("%lld\n",loc1*loc2);
        ans += loc1*loc2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007*1ll
using namespace std;
int ar[200002] ;
vector<int>ps,ne,tup ;
bool cmp(int a , int b) {return a>b ; }
int32_t main()
{
    int n,k ; cin>>n>>k ;
    int an=1 ;
    for(int i = 0 ; i < n ; i++) {cin>>ar[i] ; if(ar[i]>=0) an=0 ;}
    if(k==n)
    {
        int ans=1 ;
        for(int i = 0 ; i < n ; i++)
        {
            int x=ar[i] ;
            x=(x+mod)%mod ;
            ans=(ans*x)%mod ;
        }
        cout<<ans<<endl ;
    }
    else
    {
        if(an)
        {
           // cout<<"jkl "<<k<<endl ;
            if(k&1ll) sort(ar,ar+n,cmp) ;
            else sort(ar,ar+n) ;
            int ans=1 ;
            for(int i = 0 ; i < k ; i++)
            {
                int x=ar[i] ;
                x=(x+mod)%mod ;
                ans=(ans*x)%mod ;
            }
            cout<<ans<<endl ;
        }
        else
        {
           // cout<<"oo"<<endl ;
            int ans=1 ;
            for(int i = 0 ; i < n ; i++)
            {
                if(ar[i]>=0) ps.push_back(ar[i]) ;
                else ne.push_back(ar[i]) ;
            }
            sort(ps.begin(),ps.end()) ;
            sort(ne.rbegin(),ne.rend()) ;
          //  for(int i = 0 ; i < ps.size() ; i++) cout<<ps[i]<<" " ; cout<<endl ;
          //  for(int i = 0 ; i < ne.size() ; i++) cout<<ne[i]<<" " ; cout<<endl ;
            if(k&1)
            {
                int x=ps.back() ; ps.pop_back() ;
                ans=(ans*x*1ll)%mod ;
            }
            while((int)ps.size()>1)
            {
                int x=ps.back() ; ps.pop_back() ;
                int y=ps.back() ; ps.pop_back() ;
                tup.push_back((x*y*1ll)) ;
            }
            while((int)ne.size()>1)
            {
                int x=ne.back() ; ne.pop_back() ;
                int y=ne.back() ; ne.pop_back() ;
                tup.push_back((x*y*1ll)) ;
            }
            sort(tup.rbegin(),tup.rend()) ;
            //for(int i = 0 ; i < (int)tup.size() ; i++) cout<<tup[i]<<" " ; cout<<endl ;
            for(int i = 0 ; i < k/2 ; i++)
            {
                ans%=mod ; tup[i]%=mod ;
                ans=(ans*tup[i])%mod ;
            }
            cout<<ans%mod<<endl ;

        }
    }

}
// -1000000000 -1 -1000000000 -1000000000 -1000000000


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

int main()
{
	int X,a,b,out;
	cin >> X;
	a = X / 500;
	b = (X - a*500) / 5;
	out = a * 1000 + b * 5;
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
#define MAX 10000


using namespace std;

typedef struct {
  int h, w;
} POINT;

int main() {
  int h, w;
  int hh, ww;
  char **map;
  int **cost;
  char **dir;
  queue<POINT> que;
  POINT tmp;
  int score = 0;
  int b = 0;

  scanf("%d%d", &h, &w);
  map = new char *[h];
  dir = new char *[h];
  cost = new int *[h];
  for (int i = 0; i < h; i++) {
    map[i] = new char[w+2];
    dir[i] = new char[w];
    cost[i] = new int[w];
    scanf("%s", map[i]);
    for (int j = 0; j < w; j++) {
      //printf("%c", map[i][j]);
      if (map[i][j] == '#') b++;
      cost[i][j] = MAX;
      dir[i][j] = -1;
    }
  }
  cost[0][0] = 1;
  tmp.h = 0; tmp.w = 0;
  que.push(tmp);

  while( !que.empty() ) {
    tmp = que.front();
    que.pop();
    hh = tmp.h; ww = tmp.w;
    //printf(" current %d %d\n", hh, ww);
    if (hh-1 >= 0 && map[hh-1][ww] != '#' && cost[hh-1][ww] > cost[hh][ww]+1) {
      cost[hh-1][ww] = cost[hh][ww] + 1;
      dir[hh-1][ww] = 0;
      tmp.h = hh-1; tmp.w = ww;
      //printf("push %d, %d\n", tmp.h, tmp.w);
      que.push(tmp);
    } 
    if (ww-1 >= 0 && map[hh][ww-1] != '#' && cost[hh][ww-1] > cost[hh][ww]+1) {
      cost[hh][ww-1] = cost[hh][ww] + 1;
      dir[hh][ww-1] = 1;
      tmp.h = hh; tmp.w = ww-1;
      //printf("push %d, %d\n", tmp.h, tmp.w);
      que.push(tmp);
    } 
    if (ww+1 < w && map[hh][ww+1] != '#' && cost[hh][ww+1] > cost[hh][ww]+1) {
      cost[hh][ww+1] = cost[hh][ww] + 1;
      dir[hh][ww+1] = 2;
      tmp.h = hh; tmp.w = ww+1;
      //printf("push %d, %d\n", tmp.h, tmp.w);
      que.push(tmp);
    } 
    if (hh+1 < h && map[hh+1][ww] != '#' && cost[hh+1][ww] > cost[hh][ww]+1) {
      cost[hh+1][ww] = cost[hh][ww] + 1;
      dir[hh+1][ww] = 3;
      tmp.h = hh+1; tmp.w = ww;
      //printf("push %d, %d\n", tmp.h, tmp.w);
      que.push(tmp);
    }
  }

  if ( cost[h-1][w-1] == MAX || map[h-1][w-1] == '#' ) {
    printf("-1\n");
    return 0;
  }
  //printf("cost :%d\n", cost[h-1][w-1]);
  printf("%d\n", h*w-cost[h-1][w-1]-b);
  return 0;

  hh = h - 1; ww = w - 1;
  while (hh != 0 || ww != 0) {
    map[hh][ww] = 'p';
    if (dir[hh][ww] == 0) {
      hh++;
    } else if (dir[hh][ww] == 1) {
      ww++;
    } else if (dir[hh][ww] == 2) {
      ww--;
    } else if (dir[hh][ww] == 3) {
      hh--;
    }
  }

  score = 0; map[0][0] = 'p';
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (map[i][j] == '.') {
        score++;
      }
    }
  }
  printf("%d\n", score);
  return 0;
}






Measured memory_bytes: 256
// AOJ 3109 Canisar Cipher
// 2019.9.23 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#else
#define gc() getchar()
#define pc(x) putchar(x)
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int ins(char *s) { // 文字列の入力（特殊）
	char *p = s--; int c;
	do c = gc(), *++s = c & 0xf;
	while (c > ' ');
	return s - p;
}

#define MOD 1000000007
int M;
char C[100005]; int w;
ll p[10];
char d[12] = {0,1,2,3,4,5,6,7,8,9,10,11}; int K = 10;

void calc(void) {
	int i; ll s = 0;
	i = 10; while (i--) s += p[i] * d[i];
	if (s % MOD == M) {
		for (i = 0; i < w; i++) pc(d[C[i]]+'0');
		pc('\n');
		exit(0);
	}
}

/* algorithm of next_permutation in lexicographic order
    Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
    Find the largest index l greater than k such that a[k] < a[l].
    Swap the value of a[k] with that of a[l].
    Reverse the sequence from a[k + 1] up to and including the final element a[n].
*/
void next_permutation(void) {
	int k, l, r, t;
	
	// 右端にある最も長い降順部分列 d[k+1]... d[K-1]をみつける
	k = K-2; while (k >= 0 && d[k] > d[k+1]) k--;
	
	// 上記の降順部分列を昇順列に戻す
	l = k+1, r = K-1;
	while (l < r) t = d[l], d[l] = d[r], d[r] = t, l++, r--;
	if (k < 0) return;
	
	//d[k]より大きい要素 d[r]を見つけ、交換する
	r = k+1; while (d[k] > d[r]) r++;
	t = d[r], d[r] = d[k], d[k] = t;
}

int main()
{
	int i; ll t;
	
	M = in(), w = ins(C);
	if (M == 0 && w == 1) { puts("0"); return 0; }
	t = 1, i = w; while (i--) {
		p[C[i]] = (t + p[C[i]]) % MOD;
		t = t*10 % MOD;
	}
	i = 3628800; // 10!
	while (i--) {
		if (d[C[0]]) calc();
		next_permutation();
	}
	puts("-1");
	return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

typedef pair<int,int> P;

int judge(int k){

}

int main(){
    int n;
    cin>>n;
    vector<deque<int>>a(n);//前からの削除を高速で行いたいためdeque
    deque<P> dq;
    rep(i,n)rep(j,n-1)
    {   
        int x;
        cin>>x;
        x--;
        a[i].pb(x);
    }
    auto judge = [&](int p)
    {
        if(a[p].size()==0)return;
        int q=a[p].front();
        if(p==a[q].front()){
            if(p>a[p].front())swap(p,a[p].front());
            dq.eb(p,a[p].front());
        }
    };
    rep(i,n){
        judge(i);
    }
    int day=0;
    while(!dq.empty())
    {
        ++day;
        sort(dq.begin(),dq.end());//dequeに入っている分(その日に行われる試合は順番関係なし)
        dq.erase(unique(dq.begin(),dq.end()),dq.end());//組み合わせなのでもう片方を削除
        deque<P>bp;
        swap(dq,bp);//空配列との交換
        for(auto x:bp){
            int p=x.first;int q=x.second;
            bp.pop_front();
            a[p].pop_front();a[q].pop_front();
            judge(p);judge(q);
        }
    }
    rep(i,n)
    {
        if(a[i].size())
        {
        cout<<-1<<endl;
        return 0;
        }
    }
    cout<<day<<endl;
    return 0;
    }


Measured memory_bytes: 4736
def main():

    from collections import defaultdict
    from collections import deque
    N, M = map(int, input().split())

    dic = defaultdict(lambda :[])
    INF = 10 ** 6
    A = [INF] * N
    A[0] = 0
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        dic[a].append(b)
        dic[b].append(a)
        if a == 0 :
            A[b] = 0
        elif b == 0:
            A[a] = 0

    for i in range(1, N):
        l = len(dic[i])
        if l == 0:
            print('No')
            return
        elif l == 1:
            A[i] = dic[i][0]

    q = deque()
    for n in dic[0]:
        q.append((n, 1))
        A[n] = 0

    while len(q) > 0:
        n, d = q.popleft()
        for x in dic[n]:
            if A[x] == INF:
                A[x] = n
                q.append((x, d + 1))

    if any([v == 10 ** 6 for v in A]):
        print('No')
    else:
        print('Yes')
        for v in A[1:]:
            print(v + 1)


if __name__ == '__main__':
    main()


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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

int main() {
	int n, a, b;
	a = b = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s, t;
		cin >> s >> t;
		int ss, ts;
		ss = s.size(); ts = t.size();
		if (s == t) {
			a++; b++;
			continue;
		}
		else {
			if (s.substr(0, min(ss, ts)) == t.substr(0, min(ss, ts))) {
				if (ss > ts) a += 3;
				else b += 3;
				continue;
			}
			for (int j = 0; j < min(ss, ts); j++) {
				if (s[j] > t[j]) {
					a += 3;
					break;;
				}
				else if (s[j] < t[j]) {
					b += 3;
					break;;
				}
			}
		}
	}
	cout << a << " " << b << endl;
	return 0;
}



Measured memory_bytes: 3152
a,b=map(int,input().split())
s=input()
ans="Yes"
for i in range(a+b+1):
    if i<a or i>a:
        if s[i].isdecimal()==False:
            ans="No"
    if i==a:
        if s[i]!="-":
            ans="No"
print(ans)

Measured memory_bytes: 9036
#include <stdio.h>
#define INF 10000000

int size[100];
int to[100][100];
int cost[100][100];
int dist[100];

void dfs(int p,int c){
  int i;
  dist[p] = c;
  for(i = 0;i < size[p];i++){
    if(dist[to[p][i]] > c+cost[p][i]) dfs(to[p][i],c+cost[p][i]);
  }
}

int main(){
  int n,i,j,u;
  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf("%d",&u);
    scanf("%d",&size[u]);
    for(j = 0;j < size[u];j++){
      scanf("%d",&to[u][j]);
      scanf("%d",&cost[u][j]);
    }
  }
  
  for(i = 0;i < n;i++) dist[i] = INF;
  dfs(0, 0);
  for(i = 0;i < n;i++) printf("%d %d\n", i, dist[i]);
    
  return 0;
    
}


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

using namespace std;

inline int check(int x)
{
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return 0;
	}
	return 1;
}

int main()
{
	int r[55];
	int N;
	int count = 0;
	cin >> N;
	for (int i = 11; count < N; i+=10) {
		if(check(i) == 1) r[count] = i,count++;
	}
	cout << r[0];
	for (int i = 1; i < N; i++) cout << " " << r[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int N;
  scanf("%d", &N);
  
  for(int i=0; i<=10; i++) {
	if(N>i*1000) {
    } else {
      printf("%d", (i*1000)-N);
      break;
    }
  }
  
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    char hw[52][52];
    for(int i=0;i<52;i++){
        for(int j=0;j<52;j++){
            hw[i][j]='#';
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>hw[i][j];
        }
    }
    bool flag=true;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(hw[i][j]=='#'&&hw[i-1][j]=='.'&&hw[i+1][j]=='.'&&hw[i][j-1]=='.'&&hw[i][j+1]=='.')flag=false;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 384
object Main extends App {
  val Array(n, k) = io.StdIn.readLine().split(' ').map(_.toInt)
  val pn = io.StdIn.readLine().split(' ').map(_.toInt)
  var max = 0
  var start = 0
  var end = 0
  var sum = 0
  for (i <- 0 to n-k) {
    if (i == 0) for (j <- i until i+k) sum += pn(j)
    else {sum = sum - pn(i-1) + pn(i+k-1)}
    if (max < sum) {max = sum; start = i; end = i+k}
  }

  val exp = pn.slice(start,end).map(x => (1 to x).sum / x.toDouble).sum
  println(exp)
}

Measured memory_bytes: 74776
#include<bits/stdc++.h>
using namespace std ;
#define F first 
#define S second
typedef long long ll ;
const ll N = 1500 ;
ll a[N] , n , k , ans ;
int main ()
{
	cin >> n >> k ;
	for ( ll i = 1 ; i <= n ; i ++ )
		cin >> a[i] ;
	sort ( a + 1 , a + n + 1 ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( k - a[i] < 0 ) return cout << i - 1 , 0 ; 
		k -= a[i] ;
	}
	if ( k ) ans = 1 ; 
	cout << n - ans ;
} 


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b && b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
	
	return 0;
}


Measured memory_bytes: 2608
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    h: i32,
    a: i32,
  }

  puts!("{}\n", (h - 1) / a + 1);
}


Measured memory_bytes: 4352
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let i: i32 = sc.read();

    let res = n - i + 1;
    println!("{}", res);
}



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

#define int long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define vt vector
#define pb push_back
#define u_s unordered_set
#define u_m unordered_map
#define p_q priority_queue

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
// if using oset remove define int long long
//#define oset tree<int32_t, null_type, less<int32_t>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
//void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define deb(x...) cout << "[" << #x << "] = ["; _print(x)
int __pow(int x, int y) {int res = 1;while(y>0){if(y&1) res*=x; y>>=1; x*=x;}return res;}
int gcd(int a, int b) {if(b==0) return a; return gcd(b, a % b);}

const int N = 3e3+2, inf = 1e18;

int t, n, m, dp[N][N];

void solve()
{
    cin>>n;
    vt<int> a(n);
    for(int &x:a)
        cin>>x;
    for(int i = n-1; i>=0; i--)
    {
        for(int j = 0; j<n; j++)
        {
            if(i==j)
                dp[i][j] = a[i];
            else
                dp[i][j] = max(a[i]-dp[i+1][j], a[j]-dp[i][j-1]);
        }
    }
    cout<<dp[0][n-1]<<endl;
}
int32_t main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    t = 1;
    //cin>>t;
    for(int i = 1; i<=t; i++)
    {
        //cout<<"Case #"<<i<<":"<<endl;
        solve();
    }
}


Measured memory_bytes: 74004
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	nn := n / 100
	target := n % 100

	if nn == 0 {
		fmt.Println(0)
	} else {
		if target > nn*5 {
			fmt.Println(0)
		} else {
			fmt.Println(1)
		}
	}
}


Measured memory_bytes: 512
N = gets.to_i
L = gets.split.map!(&:to_i).sort!

ans = 0
0.upto(N-3) do |ai|
  a = L[ai]
  (ai+1).upto(N-2) do |bi|
    b = L[bi]
    ci_max = L.bsearch_index { |c| c >= a + b } || N

    ans += ci_max - bi - 1
  end
end

puts ans

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
int main(){
string sp;
cin>>sp;
int f=(sp[0]-'0')*10+(sp[1]-'0');
int s=(sp[2]-'0')*10+(sp[3]-'0');
if(f<=12 && s<=12 && f>0 && s>0)cout<<"AMBIGUOUS";
else if(f<=12 && f>0)cout<<"MMYY";
else if(s<=12 && s>0)cout<<"YYMM";
else cout<<"NA";
}

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

int main(){
    int S,h,m,s;
    cin>>S>>h>>m>>s;

    h = S/3600;
    m = (S%3600)/60;
    s = (S%3600)%60;

    cout<<h<<":"<<m<<":"<<s<<endl;

    return 0;
}



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

int main() {
    int64_t n, k;
    cin >> n >> k;

    int64_t ans = 0;
    for (int64_t i = 1; i <= n - k; i++) {
        ans += n / (k + i) * i + max(0l, n % (k + i) - k + (k != 0));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x,n) memset(x,n,sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=l.begin();it!=l.end();it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
const int inf=(1<<30);
const LL llinf=(1ll<<60);
const double eps=(1e-10);
//const double pi=2*acos(0.0);
//const double GOLD=((1+sqrt(5))/2);
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};

/* \( ·w·)~ Clapie ~(·w· )/ */

int main(){
	string str;
	cin>>str;

	LL thn=0,bln=0,hr=0,cnt=0;
	for(int i=0;i<len(str);i++){
		if(str[i]=='/'){
			cnt++;
			continue;
		}

		if(cnt==0){
			thn*=10;
			thn+=str[i]-'0';
		}
		else if(cnt==1){
			bln*=10;
			bln+=str[i]-'0';
		}
		else{
			hr*=10;
			hr+=str[i]-'0';
		}
	}

	if(bln<4){
		printf("Heisei\n");
	}
	else if(bln==4){
		if(hr<=30) printf("Heisei\n");
		else printf("TBD\n");
	}
	else printf("TBD\n");
}

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


int main()
{
	int n, b, f, r, v, house[4][3][10];
	cin >> n;

	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 3;j++) {
			for (int k = 0;k < 10;k++) {
				house[i][j][k] = 0;
			}
		}
	}

	for (int i = 0;i < n;i++) {
		cin >> b >> f >> r >> v;

		house[b-1][f-1][r-1] += v;
	}

	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 3;j++) {
			for (int k = 0;k < 10;k++) {
				cout << " " << house[i][j][k];
			}

			cout << "\n";
		}

		if (i != 3) {
			cout << "####################" << endl;
		}
	}

    return 0;
}



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

typedef signed long long ll;

int h, n, x, y;
int a[10101],b[101010];
ll f[20100];

int i, j;

void solve() {
	
	cin>>h>>n;
	
	for(i=0; i<20001; ++i) 
	   f[i]=1LL<<60;
	
	f[0]=0;
	
	for(i=0; i<n; ++i) {
		cin >> x >> y;    
		for(j=0; j<h; ++j) 
		   f[j+x] = min(f[j+x], f[j]+y);
	}
	
	ll minv=1LL<<60;
	
	for(i=h;i<=20000;i++) 
	   minv=min(minv, f[i]);
	
	cout << minv << endl;	
}

int main(){
	
	int i;
	
	solve(); 
    
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	string s;
	int a = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		a += s[i] - '0';
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
// auto mod int
const int mod = 1000000007;//998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, k; cin >> n >> k;
   combination C(n);
   mint ans = 0;
   rep(i,min(n,k+1)) ans += C(n,i)*C(n-1,i);
   cout << ans << endl;
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int n, m;
char a[10][10];

bool isvalid(int x, int y)
{
	if(x>=0&&x<n&&y>=0&&y<m) return true;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			cin>>a[i][j];
		}
	}
	int x = 0; int y = 0;
	vector<ii> moves;
	moves.pb(mp(0,0));
	for(int i = 1; i <= n + m - 2; i++)
	{
		bool c = 0; bool d = 0;
		if(isvalid(x+1,y)&&a[x+1][y]=='#')
		{
			c=1;
		}	
		if(isvalid(x,y+1)&&a[x][y+1]=='#')
		{
			d=1;
		}
		if(c^d)
		{
			if(c)
			{
				x++;
				moves.pb(mp(x,y));
			}
			else
			{
				y++;
				moves.pb(mp(x,y));
			}
		}
		else
		{
			cout<<"Impossible\n"; return 0;
		}
	}
	for(int i = 0; i < moves.size(); i++)
	{
		a[moves[i].fi][moves[i].se] = '.';
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			if(a[i][j]=='#')
			{
				cout<<"Impossible\n"; return 0;
			}
		}
	}
	cout<<"Possible\n";
}


Measured memory_bytes: 764
import sys
def input():
	return sys.stdin.readline().strip()


N = int(input())
A = input()
B = input()
C = input()

ans = 0

for i in range(N):
	if A[i] == B[i] and B[i] == C[i]:
		ans += 0
	elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
		ans += 1
	else:
		ans += 2

print(ans)

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n,b,f,r,v;
  cin >> n;
  int house[5][4][11]={0};
  rep(i,n){
    cin >> b >> f >> r >> v;
    house[b][f][r]+=v;
  }
  rep1(i,4){
    rep1(j,3){
      rep1(k,10){
        cout << ' ' << house[i][j][k];
      }
      cout << endl;
    }
    if(i!=4)cout<< "####################" << endl;
  }
}



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

int main(){
  int n,a,cnt;
  cnt=0;
  cin>>n;
  for (int i=0;i<n;i++){
    cin>>a;
    if (a%2==1){
      cnt++;
    }
  }
  if (cnt%2==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;

  int n1,n2,n3;
  n1=s1[0]-'a'; n2=s2[0]-'a'; n3=s3[0]-'a';

  char c1='A'+n1,c2='A'+n2,c3='A'+n3;
  cout<<c1<<c2<<c3<<endl;
}


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

int main(){
	int n,d;cin>>n>>d;
	int a=2*d+1;
	cout<<(n+a-1)/a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int res = 0;
	for (int i = 1; i <= N; i+=2) {
		int c = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0)c++;
		}
		if (c == 8)res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n, 1);

  vector<i64> b(n + 1), res;
  for (i64 i = n; i >= 1; --i) {
    i64 x = 0;
    for (i64 j = 2 * i; j <= n; j += i) {
      x ^= b[j];
    }
    b[i] = x ^ a[i];
    if (b[i]) res.push_back(i);
  }

  cout << res.size() << '\n';
  for (i64 x : res) cout << x << '\n';
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i ++)
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

vector<unsigned long long> v;

unsigned long long pow(int n) {
        return stoull(string("1").append(n, '0'));
}

unsigned long long get(unsigned long long n) {
        return n * 8 + 32;
}

void calc(int n) {
        v.push_back(v.back() + get(n) * pow(n - 2) * 6 - 5);
        if (v.back() < INFL) calc(n + 1);
}

string getstring(int k, unsigned long long a) { 
        string res;
        for (int i = 1; i < 16; i ++) { 
                if (i % 3 == 0) res.append("Fizz");
                if (i % 5 == 0) res.append("Buzz");
                if (i % 3 && i % 5) res.append(to_string(pow(k - 1) - 10 + a * 15 + i));
        }
        return res;
}

int main() {
        unsigned long long s;
        cin >> s;
        v.push_back(0);
        v.push_back(0);
        calc(2);
        int k = 2;
        while (s > v[k]) k ++;
        s -= v[k - 1];
        unsigned long long a = (s + 4) / get(k);
        unsigned long long b = (s + 4) % get(k) - (a ? 0 : 5);
        cout << (getstring(k, a) + getstring(k, a + 1)).substr(b, 20) << endl;
        return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
int main(void)
{
    int n;

    cin >> n;

    long long l[87];
    for (int i = 0; i <= n; i++) {
        if (i==0) {
            l[i] = 2;
            continue;
        }
        if (i==1) {
            l[i] = 1;
            continue;
        }
        l[i] = l[i-1] + l[i-2];
    }
    cout << l[n] << endl;

    return 0;
}

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

main(){
  int n,q;
  cin>>n;
  vector<int>v(n);
  r(i,n)cin>>v[i];
  cin>>q;
  while(q--){
    int a;
    cin>>a;
    if(*lower_bound(v.begin(),v.end(),a)==a)cout<<1<<endl;
    else cout<<0<<endl;
  }
}


Measured memory_bytes: 3116
n, t = map(int, input().split())

c_list = []
t_list = []
min_c = 1000
n_append = 0
argmin_c = None
for _ in range(n):
    c_i, t_i = map(int, input().split())
    
    if t_i <= t:
        c_list.append(c_i)
        t_list.append(t_i)
        n_append += 1
        if min_c >= c_i:
            min_c = c_i
            argmin_c = len(c_list) - 1 

if n_append > 0:
    print(c_list[argmin_c])
else:
    print("TLE")

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

int main() {
  vector<vector<int> > cards(4, vector<int>(14, 1));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string kind;
    int digit;
    cin >> kind >> digit;
    if (kind == "S")
      --cards[0][digit];
    if (kind == "H")
      --cards[1][digit];
    if (kind == "C")
      --cards[2][digit];
    if (kind == "D")
      --cards[3][digit];
  }
  string kinds("SHCD");
  for (int k = 0; k < 4; k++)
    for (int i = 1; i <= 13; i++) {
      if (cards[k][i])
        cout << kinds[k] << " " << i << endl;
    }
  return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  vector<int> n(x);
  for(int i=0; i<x; i++) {
    cin >> n[i];
  }
  vector<int> p(x);
  for(int i=0; i<x; i++) {
    cin >> p[i];
  }
  vector<int> a(x-1);
  for(int i=0; i<x-1; i++) {
    cin >> a[i];
  }
  int ans = 0;
  int num = 100;
  int t;
  for(int i=0; i<x; i++) {
    bool j = false;
    if(num == n[i]-1) {
      j = true;
      t = num-1;
    }
    num = n[i];
    int point = p[i];
    int add = a[i];
    ans += p[i];
    if(j) {
      ans += a[t];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      	int[] B = new int[N-1];
      	for (int i = 0; i < N-1; i++) {
        	B[i] = sc.nextInt(); 
        }
		int total = B[0];
      	for (int i = 0; i < N-2; i++) {
          total += Math.min(B[i], B[i+1]);
        }
      	total += B[N-2];
      	System.out.println(total);
	}
}

Measured memory_bytes: 23764