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

#define INF (INT64_MAX/4)
#define MOD (1000000000+7)
#define MAX 100000

int A, B, Q;
long long s[MAX];
long long t[MAX];
long long x[MAX];

int main() {
	cin >> A >> B >> Q;
	for( int i = 0; i < A; i++ ) {
		cin >> s[i];
	}
	for( int i = 0; i < B; i++ ) {
		cin >> t[i];
	}
	for( int i = 0; i < Q; i++ ) {
		cin >> x[i];
	}

	sort( s, s + A );
	sort( t, t + B );

	for( int i = 0; i < Q; i++ ) {
		int ia = lower_bound( s, s + A, x[i] ) - s;
		int ib = lower_bound( t, t + B, x[i] ) - t;
		long long da1 = s[ia] - x[i];
		if( ia >= A ) {
			da1 = INF;
		}
		long long db1 = t[ib] - x[i];
		if( ib >= B ) {
			db1 = INF;
		}
		long long da2 = INF;
		if( ia > 0 ) {
			da2 = x[i] - s[ia - 1];
		}
		long long db2 = INF;
		if( ib > 0 ) {
			db2 = x[i] - t[ib - 1];
		}
		long long ans1 = max( da1, db1 );
		long long ans2 = max( da2, db2 );
		long long ans3 = da1 * 2 + db2;
		long long ans4 = db1 * 2 + da2;
		long long ans5 = da2 * 2 + db1;
		long long ans6 = db2 * 2 + da1;
		long long ans = min( ans1, min( ans2, min( ans3, min( ans4, min( ans5, ans6 ) ) ) ) );

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3712
package main

import "fmt"

type Process struct {
	name string
	time int
}

func shift(q []Process) (Process, []Process) {
	return q[0], q[1:]
}

func main() {
	var n, q int
	fmt.Scan(&n, &q)

	queue := make([]Process, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&queue[i].name, &queue[i].time)
	}

	var p Process
	var t int
	for len(queue) > 0 {
		t += q
		queue[0].time -= q
		p, queue = shift(queue)
		if p.time <= 0 {
			t += p.time
			fmt.Println(p.name, t)
		} else {
			queue = append(queue, p)
		}
	}
}



Measured memory_bytes: 8640
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using iii = pair<int, ii>;
using viii = vector<iii>;

using ll = long long int;
using vc = vector<char>;
using vb = vector<bool>;
using ib = pair<int, bool>;
using vib = vector<ib>;

#define MOD 1000 * 1000 * 1000 + 7
#define INF 1000 * 1000 * 1000
#define EMPTY -10
#define mp(a, b) make_pair(a,b)

bool resuelveCaso() {
	int n;
	cin >> n;
	if (!cin) return false;
	int a, b;
	cin >> a >> b;

	vi v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(n);
	sort(v.begin(), v.end());

	cout << v[2] * 10 + v[1] + v[0] << '\n';


	return true;
}

int main() {
	while (resuelveCaso()) {}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextInt();
		long W = sc.nextInt();
		
		
		long i;
		long j;
		int k;
		
		long part[] = new long[3];
		
		long maxpart=0;
		long minpart;
		
		long area[] = new long[3];
		
		long subarea = 100000000L;
		
		for(i=1;i<H+1;i++){
			area[0]=i*W;
			
			for(j=1; j<3; j++){
				maxpart=0;
				minpart=5000000000L;
				
				if(j==1){
					area[1]=W*((H-i)/2);
					area[2]=W*(H-i-(H-i)/2);
				}
				if(j==2){
					area[1]=(H-i)*(W/2);
					area[2]=(H-i)*(W-(W/2));
				}
				for(k=0; k<3; k++){
					if(area[k]>maxpart){
						maxpart=area[k];
					}
					if(area[k]<minpart){
						minpart=area[k];
					}
				}
				if(maxpart-minpart<subarea){
					subarea=maxpart-minpart;
				}			
			}
		}
		
		
		for(i=1;i<W+1;i++){
			area[0]=i*H;
			
			for(j=1; j<3; j++){
				maxpart=0;
				minpart=5000000000L;
				
				if(j==1){
					area[1]=H*((W-i)/2);
					area[2]=H*(W-i-(W-i)/2);
				}
				if(j==2){
					area[1]=(W-i)*(H/2);
					area[2]=(W-i)*(H-(H/2));
				}
				for(k=0; k<3; k++){
					if(area[k]>maxpart){
						maxpart=area[k];
					}
					if(area[k]<minpart){
						minpart=area[k];
					}
				}
				if(maxpart-minpart<subarea){
					subarea=maxpart-minpart;
				}			
			}
		}
		

		
			System.out.println(subarea);

	}
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 100000
#define mod ((ll)(1e9)+7)

ll d[MAX][13];

int main(){
	string s;
	cin >> s;
	int n=s.length();

	if(s[0]=='?'){
		for(int j=0; j<10; j++) d[0][j]=1;
		for(int j=10; j<13; j++) d[0][j]=0;
	}else{
		int c=s[0]-'0';
		d[0][c]=1;
		for(int j=0; j<13; j++){
			if(j==c) continue;
			d[0][j]=0;
		}
	}

	for(int i=1; i<n; i++){
		if(s[i]=='?'){
			for(int j=0; j<13; j++){
				for(int k=0; k<10; k++){
					d[i][(10*j+k)%13]+=d[i-1][j];
					d[i][(10*j+k)%13]%=mod;
				}
			}
		}else{
			for(int j=0; j<13; j++){
				d[i][((10*j+s[i]-'0'))%13]+=d[i-1][j];
				d[i][((10*j+s[i]-'0'))%13]%=mod;
			}
		}
	}
	cout << d[n-1][5] << endl;
	return 0;
}

Measured memory_bytes: 10624
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val map = mutableMapOf<String, Int>()

    val N = scanner.nextInt()
    for (i in 1..N) {
        val str = scanner.next()
        map[str] = map.getOrElse(str, {0}) + 1
    }

    val M = scanner.nextInt()
    for (i in 1..M) {
        val str = scanner.next()
        map[str] = map.getOrElse(str, {0}) - 1
    }

    val result = map.toList().sortedBy { it -> it.second }.last().second
    if (result > 0) println(result)
    else println(0)
}

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

int main() {
  double A,B,hour,minute;
  cin>>A>>B>>hour>>minute;
  double	pi     = 2.0 * asin(1.0);            /* πの値 */
  double unit   = pi / 180.0;                 /* 度 → ラジアン */
  double angle1=hour*30+minute*0.5;
  double angle2=minute*6;
  double angle3=max(angle1,angle2)-min(angle1,angle2);
  double angle=min(angle3,360-angle3);
  cout<<fixed<<setprecision(20)<<sqrt(A*A+B*B-2*A*B*cos(angle*unit))<<endl;
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll money = 1000;
    ll stock = 0;
    for(int i = 0; i+1 < n; i++){
        if(a[i+1] > a[i]){
            stock += money / a[i];
            money %= a[i];
            money += stock * a[i+1];
            stock = 0;
        }
    }
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 3652
import sys
from heapq import heappush, heappop
from collections import defaultdict

input = sys.stdin.readline
T = int(input())
NABCD = [list(map(int,input().split())) for i in range(T)]

for N,A,B,C,D in NABCD:
    h = [(N,0)]
    ans = D*N
    dic = defaultdict(lambda:D*N+1)
    while h:
        val, cost = heappop(h)

        if ans <= cost:
            continue

        if dic[val] <= cost:
            continue
        dic[val] = cost

        if val == 0:
            ans = min(ans,cost)
            continue
        if val == 1:
            ans = min(ans,cost+D)
            continue

        heappush(h,(0,cost + val*D))
        m2 = val % 2
        if m2 == val:
            heappush(h,(0,cost+D))
        elif m2 == 0:
            heappush(h,(val//2,cost+A))
        else:
            heappush(h,((val+1)//2,cost+A+D))
            heappush(h,((val-1)//2,cost+A+D))
        
        m3 = val % 3
        if m3 == val:
            heappush(h,(0,cost+m3*D))
        elif m3 == 0:
            heappush(h,(val//3,cost+B))
        else:
            heappush(h,((val-m3)//3,cost+B+m3*D))
            heappush(h,((val+3-m3)//3,cost+B+(3-m3)*D))

        m5 = val % 5
        if m5 == val:
            heappush(h,(0,cost+m5*D))
        elif m5 == 0:
            heappush(h,(val//5,cost+C))
        else:
            heappush(h,((val-m5)//5,cost+C+m5*D))
            heappush(h,((val+5-m5)//5,cost+C+(5-m5)*D))
    print(ans)





Measured memory_bytes: 118484
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;


struct edge {
	int cost;
	int to;
};

ll INF = 1000000000;
int N,M,s,g,v,p;
ll d[110];
vector<edge> G[110];

void dijkstra(int s) {
	priority_queue<pl, vector<pl>, greater<pl> > q;
	fill(d, d + N, INF);
	d[s] = 0;
	q.push(pl(0, s));

	while (!q.empty()) {
		pl p = q.top(); q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(pl(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	ll ans = 0;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		a--, b--;
		G[a].push_back({c,b});
		G[b].push_back({d,a});
	}
	scanf("%d,%d,%d,%d",&s,&g,&v,&p);
	s--, g--;
	dijkstra(s);
	ans += d[g];
	dijkstra(g);
	ans += d[s];
	cout << v - p - ans << endl;

	return	0; 
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<ll> V(N,0);
    vector<ll> C(N,0);
    for(ll i=0;i<N;i++){
        cin>>V[i]
    ;}
    for(ll i=0;i<N;i++){
        cin>>C[i]
    ;}
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(V[i]-C[i]>=0){ans+=V[i]-C[i];}
    ;}
    cout<<ans<<endl;

    return 0;
}


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

int main(){
	int N, A = 0, B = 0;
  	cin >> N;
  	vector <int> a(N);
  	for(int i = 0; i < N; i++){
    	cin >> a.at(i);
    }
  	sort(a.begin(),a.end());
  	int flag = 0;
  	for(int i = N - 1; i >= 0; i--){
    	if(flag == 0){
        	A += a.at(i);
          	flag = 1;
        }else{
        	B += a.at(i);
          	flag = 0;
        }
    }
  	cout << A - B << endl;
}


Measured memory_bytes: 3604
using System;

namespace ConsoleApp27
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            if(S.Length <= K)
            {
                Console.WriteLine(S);
            }
            else
            {
                Console.WriteLine(S.Substring(0 , K) + "...");
            }
        }
    }
}


Measured memory_bytes: 27536
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int n;
  while(cin >> n) {
    vector<int> v1;
    vector<int> v2;

    REP(i,n) {
      int x,y;
      input(x,y);
      v1.push_back(x+y);
      v2.push_back(x-y);
    }

    sort(ALL(v1));
    sort(ALL(v2));

    cout << max(v1[n-1] - v1[0], v2[n-1] - v2[0]) << endl;
  }
}


Measured memory_bytes: 5096
n,m = map(int,input().split())
na = [0]*n
nw = [0]*n

for i in range(m):
    a,b = input().split()

    if b == "AC":
        na[int(a)-1] = 1
    elif b == "WA":
        if na[int(a)-1] == 0:
            nw[int(a)-1] += 1
count = 0
print(sum(na),end="")
for i in range(n):
    if na[i] == 1:
        count += nw[i]
print(" {}".format(count))


Measured memory_bytes: 4596
n,*a=map(int,open(0).read().split())
dp=[[0]*(n+1)for _ in range(n+1)]
for k in range(1,n+1):
    for i in range(n-k+1):
        j=i+k
        dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1])if(n-k)%2else max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1])
print(dp[0][n])

Measured memory_bytes: 115036
s = input()

a = int(s[: 2])
b = int(s[2: ])
if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= a <= 12:
    print("MMYY")
elif 1 <= b <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;
int ans = 100000;
int n = 0;
int a, b, c;
vector<int> l(8);

void calc(vector<int> v){
  int tmpa = 0, tmpb = 0, tmpc = 0, mp = 0;

  for(int i= 0; i < n; ++i){
    if(v[i] == 0){
      if(tmpa > 0) mp += 10;
      tmpa += l[i];

    } else if(v[i] == 1){
      if(tmpb > 0) mp += 10;
      tmpb += l[i];

    } else if(v[i] == 2){
      if(tmpc > 0) mp += 10;
      tmpc += l[i];

    }
  }
  if(tmpa == 0 || tmpb == 0|| tmpc ==0) return;

  mp += abs(tmpa - a) + abs(tmpb - b) + abs (tmpc - c);
  if(mp < ans){
    ans = mp;
  }

}

void dfs(int depth, vector<int> v){
  if(depth == n)  {
    calc(v);
  } else {
    for(int i = 0; i < 4; ++i){
    v[depth] = i;
    dfs(depth + 1, v);
    }
  }
}

int main(){
  cin >> n >> a >> b >> c;
  for(int i = 0; i < n; ++i){
    cin >> l[i];
  }

  vector<int> v(8);

  dfs(0, v);

  cout << ans << endl;



}


Measured memory_bytes: 384
#include <iostream>
#include <array>

/*This function is a counter for "hit" and "blow".*/
void counter(int* n_a, int* n_b, int* hit, int* blow) {

	*hit = 0;
	*blow = 0;

	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			//the case of factor and place are same
			if (n_a[i] == n_b[j] && i == j) {
				*hit = *hit + 1;
			}
			//the case of only factor is same
			else if (n_a[i] == n_b[j]) {
				*blow = *blow + 1;
			}
		}
	}
}

int main() {

	std::array<int, 4> n_a;//selection of "A"
	std::array<int, 4> n_b;//selection of "B"

	while (std::cin >> n_a[0] >> n_a[1] >> n_a[2] >> n_a[3] && std::cin >> n_b[0] >> n_b[1] >> n_b[2] >> n_b[3]) {
		//std::cin >> n_a[0] >> n_a[1] >> n_a[2] >> n_a[3];
		//std::cin >> n_b[0] >> n_b[1] >> n_b[2] >> n_b[3];

		int hit = 0;//factor and place are same
		int blow = 0;//only factor is same

		counter(n_a.data(),n_b.data(),&hit,&blow);

		std::cout << hit << " " << blow << std::endl;
	}

	return 0;

}

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
int tall[5000];
int idx=0;
 
int main(){
  while(~scanf("%d",tall+idx)){
    idx++;
  }
 
  sort(tall,tall+idx,greater<int>());
 
  for(int i=0;i<3;i++){
    printf("%d\n",tall[i]);
  }
}

Measured memory_bytes: 1204
#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;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void dfs(int v , int p , int last , v(vi) &adj , vi &pre){
    pre[v] += last;
    for(auto to : adj[v]){
        if(to != p){
            dfs(to , v , pre[v] , adj , pre);
        }
    }
}

void solve() {
    int n , q;
    cin>>n>>q;
    v(vi) adj(n);
    for (int i = 0; i < n-1; ++i) {
        int u , v;
        cin>>u>>v;
        u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    vi pre(n , 0);
    while(q--){
        int u , cost;
        cin>>u>>cost;
        u--;
        pre[u] += cost;
    }
    dfs(0 , -1 , 0 , adj , pre);
    for(auto i : pre){
        cout<<i<<" ";
    }
    cout<<endl;

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 30592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,y;
  cin >> n >> y;
  int res10000 = -1;
  int res5000 = -1;
  int res1000 = -1;
  int a,b,c;
  for(int a = 0; a <= n; ++a){
    for(int b = 0; b <= n - a; ++b){
      c = n - b - a;
      if(y==10000*a+5000*b+1000*c){
        res10000 = a;
        res5000 = b;
        res1000 = c;
        break;
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Starting Line
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), K = sc.nextInt(), T = sc.nextInt(), U = sc.nextInt(), V = sc.nextInt(), L = sc.nextInt();
		int[] D = new int[n+1];
		for(int i=0;i<n;i++)D[i]=sc.nextInt();
		D[n] = L;
		double res = 0;
		int pos = 0, k = 0, f = 0;
		while(pos<L){
			if(pos<D[f]){
				if(0<k){
					k--;
					int nx = Math.min(L, pos+T*V);
					res+=(nx-pos+0.)/V;
					pos = nx;
				}
				else{
					res+=(D[f]-pos+0.)/U;
					pos = D[f];
				}
			}
			else{
				if(k==0){
					if(D[f]==pos){
						int nx = Math.min(L, pos+T*V);
						res+=(nx-pos+0.)/V;
						pos = nx;
						f++;
					}
					else{
						k++; f++;
					}
				}
				else if(k==K){
					int nx = Math.min(L, D[f++]+T*V);
					res+=(nx-pos+0.)/V;
					pos = nx;
				}
				else {
					f++;
					k++;
				}
			}
		}
		System.out.printf("%.8f\n", res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;
/*******************************************
****************** BY **********************
******* FUTURE GOOGLE EMPLOYEE *************
****** KARTHICK KUPPURAJ M *****************
********************************************/
#define ms(s, n) memset(s, n, sizeof(s))
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define prec(n) fixed<<setprecision(n)
#define sll(x) scanf("%lld",&x);
#define pll(x) printf("%lld",x);
#define pn printf("\n");
#define ps printf(" ");
#define pc(c) printf("%c",c);
typedef long long int ll;
#define EPS 1e-9
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MAX = 1e4;
vector<int> adj[MAX];

int dfs(int u, int par, int k, int depth = 0) {
    int ans = 0;
    if (depth >= k)
        ans++;
    for (int v: adj[u])
    {
        if (v == par)continue;
        ans += dfs(v, u, k, depth + 1);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, u, v;
    cin >> n >> k;
    for (int i = 1; i < n; ++i)
    {
        cin >> u >> v;
        u--;
        v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans = INF;
    for (int i = 0; i < n; ++i)
    {
        int c = 0;
        for (int v: adj[i])
        {
            c += dfs(v, i, k / 2);
        }
        ans = min(ans, c);
    }
    for (int i = 0; i < n; ++i)
    {
        int c = 0;
        for (int v: adj[i])
        {
            c = dfs(v, i, (k + 1) / 2)+ dfs(i, v, (k + 1) / 2);
            ans = min(ans, c);
        }

    }
    cout << ans;
    return 0;
}

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

typedef pair<int, int> ii;
typedef long long ll;

// (nPm)^2 - sigma(kCn * ((n-k)P(m-k))^2 * kPm)

const ll M = 500002, N = 500002;
const ll MOD = 1000000007; 
ll f[M];

void init(){
	f[0] = 1;
	for(int i = 1; i < M; i++){
		f[i] = (1LL * f[i-1] * i) % MOD;
	}
}

void extend_gcd(ll a, ll b, ll& x, ll& y){
	if(b == 0){
		x = 1;
		y = 0;
		return;
	}
	ll x1, y1;
	extend_gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - (a / b) * y1;
}

ll modpow(ll a, ll p){
    if (p == 0) return 1;
    
    if (p % 2 == 0) {
        return modpow(a * a % MOD, p / 2);
    
    } else
        return a * modpow(a, p - 1) % MOD;
}

ll inverse(ll k){
	ll x, y;
	extend_gcd(k, MOD, x, y);
	x = (x % MOD + MOD) % MOD;
	return x;

	// second way
	// return modpow(k, MOD - 2);
}

ll C(int k, int n){
	return (1LL * f[n] * inverse(f[k]) % MOD * inverse(f[n - k])) %  MOD; 
}

ll P(int k, int n){
	return (1LL * f[n] * inverse(f[n-k])) % MOD;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	init();
	// ll ans = P(n, m);
	// ans = (1LL * ans * ans) % MOD;
	ll ans = 0;
	ll x;
	for(int i = 0; i <= n; i++){
		// ll p = P(n - i, m - i);
		// ll t = (((1LL * C(i, n) * ((1LL * p * p) % MOD)) % MOD) * P(i, m)) % MOD;  
		ll t = C(i, n) * P(n - i, m - i) % MOD * P(n - i, m - i) % MOD * P(i, m) % MOD;
		if(i & 1) ans = (ans - t + MOD) % MOD;
		else ans = (ans + t) % MOD;
	}
	if (ans < 0) ans += MOD;

	cout << ans % MOD;
}

// 141421 356237

Measured memory_bytes: 7512
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#define dump(x ...) cerr  <<  "|| "  <<  # x  <<  "  =  ", _dump(x) 
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define LD long double
#define pii pair<int,int>
const int INF = 2e9;
const int N = 2000;
int n;
bool type[N+N +3];
int arr[N+N +3];
int pos[2][N+N +3];
int cntPref[2][N+N +3][N +3];
int dp[N +3][N +3];

int main(){ FAST
	cin >> n;
	for(int i=1; i<=n+n; ++i){
		char ch;
		cin >> ch >> arr[i];
		type[i] = (ch=='W');
	}

	for(int i=1; i<=n+n; ++i) pos[type[i]][arr[i]] = i;

	for(int pref=1; pref<=n+n; ++pref){
		for(int x=1; x<=n; ++x) cntPref[0][pref][x] = cntPref[0][pref-1][x];
		if(type[pref] == 0) for(int x=1; x<=arr[pref]; ++x) ++cntPref[0][pref][x];
	}

	for(int pref=1; pref<=n+n; ++pref){
		for(int x=1; x<=n; ++x) cntPref[1][pref][x] = cntPref[1][pref-1][x];
		if(type[pref] == 1) for(int x=1; x<=arr[pref]; ++x) ++cntPref[1][pref][x];
	}

	// for(int pref=1; pref<=n+n; ++pref) for(int i=1; i<=n; ++i) dump(pref,i,cntPref[1][pref][i]);

	for(int i=0; i<=n; ++i) for(int j=0; j<=n; ++j){
		if(i == 0 && j == 0) continue;
		else if(i == 0 && j == 1) dp[0][1] = pos[1][1] - 1;
		else if(i == 1 && j == 0) dp[1][0] = pos[0][1] - 1;
		else{
			int posi = pos[0][i];
			int candi = (i == 0) ? INF : dp[i-1][j] + cntPref[0][posi][i+1] + cntPref[1][posi][j+1];
			
			int posj = pos[1][j];
			int candj = (j == 0) ? INF : dp[i][j-1] + cntPref[0][posj][i+1] + cntPref[1][posj][j+1];

			dp[i][j] = min(candi, candj);
		}
	}
	// dump(dp[1][1]);

	cout << dp[n][n] << ln;
}

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

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
const long long INF = 1e9;

int main()
{
	int N, W; cin >> N >> W;
	vector<int> w(N), v(N);
	for(int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
	}
  
	vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
	for(int i = 0; i < N; i++){
		for(int sum_w = 0; sum_w <= W; sum_w++){
			//品物iを重さがsum_wを超えないように選ぶ
			if(sum_w - w[i] >= 0){
				chmax(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i]);
			}

			//品物iを選ばないとき
			chmax(dp[i+1][sum_w], dp[i][sum_w]);
		}
	}
	cout << dp[N][W] << endl; 
	return 0;
}


Measured memory_bytes: 80256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main(){
    int n, m, x, c[12] = { 0 }, a[12][12] = { 0 }, y, z[12] = { 0 }, b, d = 1e9, all[12], flag = 0;
    scanf("%d%d%d",&n,&m,&x);
    rep(i,n){
    scanf("%d",&c[i]);
        rep(j,m){
            scanf("%d",&a[i][j]);
        }
    }

    rep(i, 4096) {
        y = 0;
        all[0] = i / 2048;
        all[1] = (i % 2048) / 1024;
        Rep(j, 2, 12)all[j] = (i % (int)pow(2,12-j)) / (int)pow(2,11-j);
        rep(j, 12)y += c[j] * all[j];
        for (b = 0; b < m; b++) {
            rep(j, 12)z[b] += all[j]*a[j][b];
            if (z[b] < x)flag++;
            z[b] = 0;
        }
        if (flag==0)d = mi(d,y);
        flag = 0;
    }  
    if (d == (int)1e9)puts("-1");
    else printf("%d", d);
    return 0;
}

Measured memory_bytes: 2596
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func main() {
	sc := NewScanner()
	H := sc.NextInt()
	W := sc.NextInt()
	matrix := make([][]byte, H)

	for i := 0; i < H; i++ {
		matrix[i] = make([]byte, W)
		for j, s := range sc.NextLine() {
			matrix[i][j] = byte(s)
		}
	}
	i := 0
	j := 0
	change := true
	matrix[0][0] = '.'
	for change {
		change = false
		if j + 1 < W && matrix[i][j + 1] == '#' {
			j++
			matrix[i][j] = '.'
			change = true
		} else if i + 1 < H && matrix[i + 1][j] == '#' {
			i++
			matrix[i][j] = '.'
			change = true
		}
	}

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if matrix[i][j] == '#' {
				fmt.Println("Impossible")
				return
			}
		}
	}
	fmt.Println("Possible")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int sur = X % 100;
	int div = X / 100;

	if (sur <= 5 * div) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3536
n,m,k=map(int,input().split())

mod=998244353

# 階乗計算
fact=[0]*(1+n)
fact[0]=1
for i in range(1,n+1):
    fact[i]=fact[i-1]*i % mod
    
# 階乗の逆元計算
invfact=[0]*(1+n)
invfact[-1]=pow(fact[-1],mod-2,mod) # 逆元を計算するのは最後の要素だけでよくてあとは、前に戻りながらかけていく。
for i in range(n-1,-1,-1):
    invfact[i]=invfact[i+1]*(i+1) % mod
    

# 二項係数のリスト化
def cmb(n,r,mod):
    if r<0 or n<r:
        return 0
    return fact[n] * invfact[r] * invfact[n-r] % mod
    
ans=0
for i in range(k+1):
    ans+=(cmb(n-1,i,mod)*m*pow(m-1,n-i-1,mod))%mod
    ans%mod
print(ans%mod)

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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAX = 3000;
double dp[MAX][MAX/2];
double p[MAX];
int N;

double f(int i, int tails){
	if(tails < 0) return 0;
	if(i == N) return 1;
	double &ans = dp[i][tails];
	if(ans > -0.5) return ans;
	ans = 0;
	ans += p[i]*f(i + 1, tails);
	ans += (1.0 - p[i])*f(i + 1, tails - 1);
	return ans;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n;
	N = n;
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	double ans = 0;
	m = (n + 1)/2 - 1;
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= m; j++){
			dp[i][j] = -0.5;
		}
	}
	ans = f(0, m);
	cout << fixed << setprecision(10) << ans << endl;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  int coin = 0;
  if(a > b){
    coin += a;
    a -= 1;
  } else {
    coin += b;
    b -= 1;
  }
  if(a > b){
    coin += a;
    a -= 1;
  } else {
    coin += b;
    b -= 1;
  }
  cout << coin << endl;
}

Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc118/tasks/abc118_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int a, b;

int main() {
    cin >> a >> b;
    if(b%a==0) {
        print(a+b);
    } else {
        print(b-a);
    }
    return 0;
}


Measured memory_bytes: 256
/*  
    And solitare's the only game in town
    And every road that takes him
    Takes him down
    And by himself it's easy to pretend
    He'll never love again
    _________________________
    _________________________
    960 Hours of Solitude
    Quarantine_Day : 40
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<ll>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 200005

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, x; cin>>n>>m>>x;
    ll ara[n + 1] = {0};
    REP(i, m){
        int a; cin>>a;
        ara[a] = 1;
    }
    int f(0), s(0);
    for(int i = x + 1; i <= n; i++){
        if(ara[i] == 1) f++;
    }
    for(int i = x - 1; i >= 0; i--){
        if(ara[i] == 1) s++;
    }
    cout<<min(f, s)<<"\n";

    return 0;
}


Measured memory_bytes: 256
N=int(input())
H=list(map(int,input().split()))
x=0
a=[]
for i in range(N-1):
    if H[i]>=H[i+1]:
        x=x+1
    else:
        if x>=N-x-1:
            break
        else:
            a.append(x)
            x=0
            continue
a.append(x)
print(max(a))


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

int main(){
    cin.tie(0)->sync_with_stdio(false);

	string s; cin >> s;
	int k; cin >> k;

	set<string> sub;
	REP(i, (int)s.size()) for (int j = 1; j <= k; j++)
		sub.insert(s.substr(i, j));

	int i = 1;
	for (auto x : sub) {
		if (i++ == k) {
			cout << x << '\n';
			return 0;
		}
	}
    return 0;
}


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

map<long long, int> prime_factor(long long n) {
  map<long long, int> ret;
  for (long long i = 2; i * i <= n; i++)  {
    while ( n % i == 0 ) {
      ret[i]++;
      n /= i;
    }
  }
  if ( n != 1 ) { ret[n] = 1; }
  return ret;
}


int main() {
  long long n;
  cin >> n;
  int ans = 0;
  map<long long, int> pf = prime_factor(n);
  for ( auto p = pf.begin(); p != pf.end(); p++ ) {
    int ct = 1;
    while ( p->second >= ct ) {
      ans++;
      p->second -= ct;
      ct++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
from heapq import *

def main():
    def find(x):
        parent = data[x]
        if parent < 0: return x
        root = find(parent)
        data[x] = root
        return root

    def union(x, y):
        root, second = find(x), find(y)
        if root == second: return False
        if height[root] < data[second]:
            second, root = root, second
        data[root] += data[second]
        height[root] = max(height[root], height[second]+1)
        data[second] = root
        return True

    N = int(input())
    X = [(0,0)] * N
    Y = [(0,0)] * N

    for i in range(N):
        x, y = map(int, input().split())
        X[i] = (x, i)
        Y[i] = (y, i)

    X.sort()
    Y.sort()
    H = []

    for i in range(N - 1):
        x1, j1 = X[i]
        x2, j2 = X[i + 1]
        y1, k1 = Y[i]
        y2, k2 = Y[i + 1]
        # ヒープ構造を用いて常にHの最初に最小値を持ってくる
        # X座標とY座標でそれぞれHに追加
        heappush(H, (x2 - x1, j1, j2))
        heappush(H, (y2 - y1, k1, k2))

    answer = 0
    data = [-1] * (N+1)  # 1-indexed rootには-sizeが入る
    height = [0] * (N+1)

    while H:
        w, s, t = heappop(H)
        # sとtの集合が異なっていた時、道を作る
        if union(s, t):
            answer += w

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 51112
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define YES(c) if(c)co("YES");else co("NO")
#define Yes(c) if(c)co("Yes");else co("No")
#define yes(c) if(c)co("yes");else co("no")
#define coc(c, a, b) if(c)co((a));else co((b))
#ifdef LOCAL_tqk
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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; }

bool f(int n){
    if((n/10000 == n%10)&&((n/1000)%10 == (n%100)/10)) return 1;
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    lint n;
    char in[2];
    bool fl=0;
    cin>>n;
    rep(i, n){
        cin>>in;
        if(in[0]=='Y')fl=1;
    }
    coc(fl, "Four", "Three");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
bool solve(vector<int> A)
{
    int counter[100] = {};
    for (auto a : A) counter[a]++;
    bool first = true;
    int max = 1e9;
    for (int i = 0; i < 100; i++) {
        if (first && counter[i]) {
            if (counter[i] == 1) max = i * 2;
            else if (counter[i] == 2) max = i * 2 - 1;
            else return false;
            first = false;
        } else if (!first && i <= max) {
            if (counter[i] < 2) return false;
        } else if (!first) {
            if (counter[i] != 0) return false;
        }
    }
    return true;
}
int main() 
{
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    cout << (solve(A) ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        String S = scanString();
        if (S.equals("ABC")) {
            out.print("ARC");
        } else {
            out.print("ABC");
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

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

typedef long long ll;

const int Maxn = 52;

ll pw2[Maxn];
int n;
vector <int> neigh[Maxn];
int P[Maxn], L[Maxn];
bool col[Maxn];
int m;
int ma[Maxn], mb[Maxn];

void Traverse(int v)
{
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (P[v] == u) continue;
        P[u] = v; L[u] = L[v] + 1;
        Traverse(u);
    }
}

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxn; i++)
        pw2[i] = 2ll * pw2[i - 1];
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    Traverse(1);
    scanf("%d", &m);
    for (int i = 0; i < m; i++)
        scanf("%d %d", &ma[i], &mb[i]);
    ll res = 0;
    for (int i = 0; i < 1 << m; i++) {
        int bits = 0;
        fill(col, col + n + 1, false);
        for (int j = 0; j < m; j++) if (i & 1 << j) {
            bits++;
            int a = ma[j], b = mb[j];
            while (a != b)
                if (L[a] >= L[b]) { col[a] = true; a = P[a]; }
                else { col[b] = true; b = P[b]; }
        }
        ll cur = 1;
        for (int i = 2; i <= n; i++) if (!col[i])
            cur *= 2;
        if (bits % 2) res -= cur;
        else res += cur;
    }
    cout << res << endl;
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	string T; cin >> T;
	for (int i = 0; i < T.size(); i++) {
		if (T[i] == '?') T[i] = 'D';
	}
	cout << T << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3736
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()

ans = 0
dic = defaultdict(int)
dic[0] += 1
cur = 0
for i in range(n):
    cur += a[i]
    ans += dic[cur]
    dic[cur] += 1

print(ans)

Measured memory_bytes: 39452
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];
    vector<int> ans(n);
    const int inf = 1001001001;
    auto f = [](int x1, int y1, int x2, int y2) {
                 return abs(x1 - x2) + abs(y1 - y2);
             };
    rep(i, n) {
        int dist = inf;
        rep(j, m) {
            if (chmin(dist, f(a[i], b[i], c[j], d[j]))) ans[i] = j+1;
        }
    }
    rep(i, n) cout << ans[i] << endl;
}


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

int main(){
    vector<int> bingo{0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100};
    vector<int> a(9);
    int n;
    rep(i,9)cin >> a.at(i);
    int flag = 0;
    cin >> n;
    rep(i,n){
        int b;
        cin >> b;
        rep(j,9){
            if(b == a.at(j))flag |=(1<<j);
        }
    }

    rep(i,8)if((flag & bingo.at(i))==bingo.at(i)){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    char buf, ch='a';
    int i, num[26];

    for (i=0;i<26;i++) num[i]=0;
    i=0;
    while ((buf=getchar()) != EOF) {
        if (buf>=65 && buf<=90) buf+=32;
        num[buf-97]++;
        i++;
    }
    i=0;
    while(ch!=123) {
        printf("%c : %d\n", ch++, num[i++]);
    }
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> vp(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    vp.at(i) = make_pair(b, a);
  }
  sort(vp.begin(), vp.end());
  int now = 0;
  rep(i, n){
    now += vp.at(i).second;
    if(vp.at(i).first < now){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

vector<int> ReadInput(int n)
{
	vector<int> result(n);
	for (int i = 0; i < n; i++)
	{
		cin >> result[i];
	}
	return result;
}

int main()
{
	int n;
	cin >> n;
	
	vector<int> values = ReadInput(n);
	vector<int> costs = ReadInput(n);

	int ans = 0;

	for (int i = 0; i < n; i++)
	{
	 	if (values[i] - costs[i] >= 0)
	 	{
	 		ans += values[i] - costs[i];
	 	}
	}

	cout << ans << endl;
}




Measured memory_bytes: 256