akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

#define INF 999999999

class Node
{
public:
	vector<int> to;
};

int flow[1002][1002];

bool dfs(int p, int T, int mf, vector<Node>& graph, vector<int>& level, vector<bool>& finished)
{
	if(p==T) return true;
	if(finished[p]) return false;
	
	finished[p]=true;
	
	for(int i=0; i<graph[p].to.size(); i++)
	{
		int next=graph[p].to[i];
		if(level[p] >= level[next]) continue;
		if(flow[p][next]) continue;
	
		if(dfs(next, T, 1, graph, level, finished))
		{
			finished[p]=false;
			flow[p][next]+=1;
			flow[next][p]-=1;
			return true;
		}
	}
	
	return false;
}

int HopcroftKarp(int S, int T, vector<Node>& graph)
{
	bool end=false;
	int total=0;
	while(!end)
	{
		end=true;
		vector<int> level(graph.size(), -1);
		level[S]=0;
		
		queue<int> q;
		q.push(S);
		while(!q.empty())
		{
			int n=q.front(); q.pop();
			for(int i=0; i<graph[n].to.size(); i++)
			{
				int next=graph[n].to[i];
				if(level[next]!=-1) continue;
				if(flow[n][next]) continue;
				level[next]=level[n]+1;
				q.push(next);
			}
		}
		
		if(level[T]==-1) break;
		
		vector<bool> finished(graph.size());
		while(dfs(S, T, INF, graph, level, finished))
		{
			total++;
			end=false;
		}
	}
	
	return total;
}

int gcd(int a, int b)
{
	return (b!=0?gcd(b,a%b):a);
}

int main()
{
	int M,N;
	while(scanf("%d%d", &M, &N), (M||N))
	{
		vector<int> red(N), blue(M);
		vector<Node> graph(N+M+2);
		for(int i=0; i<M; i++)
		{
			int t;
			scanf("%d", &t);
			blue[i]=t;
		}
		for(int i=0; i<N; i++)
		{
			int t;
			scanf("%d", &t);
			red[i]=t;
		}
		
		for(int i=0; i<M; i++)
		{
			graph[0].to.push_back(i+2);
			flow[0][i+2]=0;
			flow[i+2][0]=1;
		}
		for(int i=0; i<N; i++)
		{
			graph[M+i+2].to.push_back(1);
			flow[M+i+2][1]=0;
			flow[1][M+i+2]=1;
		}
		
		for(int i=0; i<N; i++)
		for(int j=0; j<M; j++)
		{
			if(gcd(red[i], blue[j]) >= 2)
			{
				graph[j+2].to.push_back(M+i+2);
				graph[M+i+2].to.push_back(j+2);

				flow[j+2][M+i+2]=0;
				flow[M+i+2][j+2]=1;
			}
		}
		
		printf("%d\n", HopcroftKarp(0,1,graph));

	}
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
  	int A;cin>>A;int B;cin>>B;
  	int ans;
  	if(A==B){
    	ans=A+B;
    }else{
    	ans=max(A,B);
      	ans=ans*2-1;
    }
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    f = list(map(lambda x : int(x) - 1, input().split()))
    step = [-1] * n
    step[0] = 0
    now = 0
    while step[f[now]] == -1:
        step[f[now]] = step[now] + 1
        now = f[now]
        if step[now] == k:
            print(now + 1)
            return

    k -= step[now]
    loop = step[now] - step[f[now]] + 1
    k %= loop
    for _ in range(k):
        now = f[now]
    print(now + 1)
resolve()

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

typedef int Data[6];

int L;
int as[114514];
map<int, int> table;

void Convert(int t, int *d) {
  for (int i=0; i<L; i++) {
    d[i] = t%10;
    t /= 10;
  }
}

int Restore(int *d) {
  int ret = 0;
  for (int i=L-1; i>=0; i--) {
    ret = ret*10 + d[i];
  }
  return ret;
}

int main() {
  while (1) {
    scanf("%d%d", &as[0], &L);
    if (as[0] == 0 && L == 0) return 0;

    table.clear();
    table[as[0]] = 0;

    int idx = 1;
    while (1) {
      Data d;
      Convert(as[idx-1], d);
      sort(d, d+L);
      int maxi = Restore(d);
      reverse(d, d+L);
      int mini = Restore(d);
      as[idx] = maxi - mini;
      if (table.count(as[idx])) {
        printf("%d %d %d\n", table[as[idx]], as[idx], idx - table[as[idx]]);
        break;
      }
      table[as[idx]] = idx;
      idx++;
    }
  }
}

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

using namespace std;
int main()
{
    int a,b,c;
    cin>>a;
    if(a ==1){
        cout<<"Hello World";
    }
    else if(a == 2){
        cin>>b>>c;
        cout<<(b+c);
    }

    return 0;
}


Measured memory_bytes: 3592
n,m = map(int, input().split())
h = list(map(int, input().split()))

check = [1]*n

for i in range(m):
    a,b=map(int, input().split())
    if h[a-1] >= h[b-1]:
        check[b-1] = 0
    if h[a-1] <= h[b-1]:
        check[a-1] = 0

print(sum(check))

Measured memory_bytes: 19840
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let n: usize = read!();
    let mut sum: usize = 0;
    let mut v:Vec<String> = Vec::new();
    for i in 0..n {
        let a: String = read!();
        v.push(a);
        sum+=1;
        for j in 0..v.len()-1 {
            if v[j]==v[i] {
                println!("No");
                exit(0);
            }
        }
    }
    let v=v.iter().map(|a|a.chars().collect_vec()).collect_vec();
    for i in 0..sum-1 {
        if v[i][v[i].len()-1]!=v[i+1][0] {
            println!("No");
            exit(0);
        }
    }
    println!("Yes")
}

Measured memory_bytes: 2168
def main():
    N = int(input())
    strA = input()
    listA = strA.split(" ")

    X = [0] * N
    for i in range(0, N-1):
        X[int(listA[i])-1] += 1

    for j in X:
        print(j)

if __name__ == '__main__':
    main()

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

using namespace std;

int n, k, b, q;
long long res;

int main() {

    scanf("%d%d",&n,&k);
    for (b=k+1;b<=n;b++)for (q=0;b*q<=n;q++) res += max(min(n-b*q,b-1)-max(k,1-b*q)+1,0);
    printf("%lld\n",res);

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
map<ll, ll> pat;

signed main()
{
    cin >> N;
    ll cs = 0;
    pat[0] = 1;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        cs += tmp;
        pat[cs]++;
    }
    ll ans = 0;
    for(auto& p : pat) {
        ans += p.second * (p.second-1) / 2;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<set>
#include<unordered_map>
using namespace std;
#define int long long int

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	int a[4];

	for(int i = 0;i<4;i++){
		cin>>a[i];
	}
	  int mx = a[0]*a[2];

	  for (int i = 0; i <= 1; i++) {
	    for (int j = 2; j <= 3; j++) {
	      mx = max(mx, a[i] * a[j]);
	    }
	  }
	  cout << mx << '\n';
 
}



Measured memory_bytes: 3632
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>

using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

//???
class Point {
public:
    double x, y;
    
    Point (double x = 0, double y = 0):x(x), y(y){}
    Point operator + (Point p){return Point(x + p.x, y + p.y);}
    Point operator - (Point p){return Point(x - p.x, y - p.y);}
    Point operator * (double a){return Point(a * x, a * y);}
    Point operator / (double a){return Point(x / a, y / a);}
    
    double norm(){return x*x + y*y;};
    double absolute(){return sqrt(norm());};
    
    bool operator < (const Point &p) const{
        return x != p.x ? x < p.x : y < p.y;
    }
    
    bool operator == (const Point &p) const{
        return equals(x, p.x) && equals(y, p.y);
    }
    
};
typedef Point Vector;                               //????????????
typedef struct Segment{Point p1, p2;}Segment;       //??????
typedef Segment Line;                               //??´???
typedef struct Circle{Point c; double r;}Circle;    //???
typedef vector<Point> Polygon;                      //????§???¢
//????????????a????????????
double norm(Vector a){
    return a.x * a.x + a.y * a.y;
}
//????????????a?????§??????
double absolute(Vector a){
    return sqrt(norm(a));
}


//???c1??¨???c2?????????????±???????
Vector polar(double a, double r){
    //??????a,?§????r???point????±???????
    return Point(cos(r) * a, sin(r) * a);
}
pair<Point, Point> getCrossPoints(Circle c1, Circle c2){
    Vector v = c2.c - c1.c;
    double d = absolute(v);
    double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d) );
    double t = atan2(v.y, v.x);
    return make_pair(c1.c + polar(c1.r, t+a), c1.c + polar(c1.r, t-a));
}



int main(){
    
    int cx1, cy1, cx2, cy2;
    double r1, r2;
    
    cin >> cx1 >> cy1 >> r1;
    cin >> cx2 >> cy2 >> r2;
    
    Circle c1 = {Point(cx1, cy1), r1};
    Circle c2 = {Point(cx2, cy2), r2};
    
    pair<Point, Point> ans = getCrossPoints(c1, c2);
    bool swap_flag = (ans.first.x == ans.second.x) ? ans.first.y > ans.second.y : (ans.first.x > ans.second.x);
    if(swap_flag) swap(ans.first, ans.second);
    
    printf("%.8lf %.8lf %.8lf %.8lf\n", ans.first.x, ans.first.y, ans.second.x, ans.second.y);

    return 0;
}

Measured memory_bytes: 1300
import sys
from heapq import heappop, heappush
input = sys.stdin.readline

n, m = map(int, input().split())
# Ai>Mのものは最初から除外
# Aiが最小のものから順に選ぶ

# index = A(day-1), element = B(reword)
schedule = [[] for _ in range(m)]
for _ in range(n):
    day, reword = map(int, input().split())
    if day > m:
        continue
    schedule[day-1].append(reword)

hq = []
sum = 0

for i in range(m):
    while schedule[i]:
        heappush(hq, -schedule[i][-1])
        del schedule[i][-1]

    if hq:
        sum -= heappop(hq)

print(sum)


Measured memory_bytes: 17608
//🅰🅸🅸🆂🅼🅴
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <numeric>
#include <stdlib.h>

using namespace std;

typedef long long ll;

const int AI1 = 10005;
const int AIMAX = 1e6 + 1;

int main()
{
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '1') ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int l = A + B;
	int r = C + D;
	if (l == r)cout << "Balanced";
	else if (l > r)cout << "Left";
	else cout << "Right";
}

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
inline int read()
{
    register int X=0;register char ch=0;bool flag=0;
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') flag=1;
	for(;isdigit(ch);ch=getchar()) X=(X<<3)+(X<<1)+ch-'0';
	return (flag ? -X : X);
}
inline void write(int x)
{
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int mx=250005;
int n,m,cnt;
int a[501][501];
int x1[mx],y1[mx],x2[mx],y2[mx];
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(j==m && i==n) break;
			if(a[i][j]&1)
			{
				if(j<m)
				{
					a[i][j]--,a[i][j+1]++;
					x1[++cnt]=i,y1[cnt]=j,x2[cnt]=i,y2[cnt]=j+1;
				}
				else if(j==m)
				{
					a[i][j]--,a[i+1][j]++;
					x1[++cnt]=i,y1[cnt]=j,x2[cnt]=i+1,y2[cnt]=j;
				}
			}
		}
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++)
		printf("%d %d %d %d\n",x1[i],y1[i],x2[i],y2[i]);
}

Measured memory_bytes: 6016
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ret = N
    i = 0
    xor_A = A[0]
    j = 1
    while i < N-1:
        tail_flag = False
        # next_i = i+1
        if i == j:
            xor_A = A[i]
            j = i+1
        while j < N:
            if xor_A ^ A[j] == xor_A+A[j]:
                tail_flag = True
                # print(i,j, xor_A, xor_A^A[j], xor_A+A[j])
                xor_A = xor_A ^ A[j]
                ret += j-i
            else: 
                tail_flag = False
                break
            
            if j != N-1: 
                j += 1
            else: break
        
        xor_A ^= A[i]
        i += 1
        if tail_flag and j == N-1: break
                
    print(ret)
    
solve()

Measured memory_bytes: 24840
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int d;
	while(cin >> d && d) {
		int n, m;
		cin >> n >> m;

		vector<int> v;
		v.push_back(0);

		rep(i, n - 1) {
			int x;
			cin >> x;
			v.push_back(x);
		}

		v.push_back(d);
		sort(v.begin(), v.end());

		ll ans = 0;
		rep(i, m) {
			int x;
			cin >> x;

			if(x == 0) continue;
			int id = lower_bound(v.begin(), v.end(), x) - v.begin();
			int a = min(abs(v[id] - x), abs(v[id-1] - x));
			ans += a;
		}

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

Measured memory_bytes: 1728
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 202020;

int n;
int a[N], cnt[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
    ll r = 1;
    for (int i = 0; i < n - 1; i += 2) r = r * 2 % MOD;
    for (int i = 0; i < n; i++) cnt[abs(i - (n - i - 1))]--;
    for (int i = 0; i < n; i++) if (cnt[i] != 0) cout << 0, exit(0);
    cout << r;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define M_PI  3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }

 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1;
  //cin>>t;
   while(t--)
  {
      ll a;
      cin>>a;
      auto get = []( ll x ){
                      return x*=x; };
      cout<<a+get(a)+a*get(a);
  }
  return 0;

}


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

int main() {
	int n;cin>>n;
	int a=0,w=0,t=0,r=0;
	while(n--)
	{
	    string s;cin>>s;
	    if(s=="AC")
	    a++;
	    else if(s=="WA")
	    w++;
	    else if(s=="TLE")
	    t++;
	    else
	    r++;
	}
	cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<w<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<t<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<r<<endl;

	return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
typedef long long ll;
const int MAXN = 400;
const int MOD = int(1E9) + 7;
int N, C, A[MAXN + 5], B[MAXN + 5];
ll Pow[MAXN + 5][MAXN + 5], D[MAXN + 5];
ll dp[MAXN + 5][MAXN + 5];
void init() {
	for(int i=1;i<=MAXN;i++)
		D[i] = 1;
	for(int i=0;i<=MAXN;i++) {
		for(int j=1;j<=MAXN;j++) {
			Pow[i][j] = Pow[i][j-1] + D[j];
			D[j] = D[j] * j % MOD;
		}
	}
}
int main() {
	init();
	scanf("%d%d", &N, &C);
	for(int i=1;i<=N;i++)
		scanf("%d", &A[i]);
	for(int i=1;i<=N;i++)
		scanf("%d", &B[i]);
	for(int i=0;i<=C;i++)
		dp[N][i] = (Pow[i][B[N]] - Pow[i][A[N]-1] + MOD) % MOD;
	for(int i=N-1;i>=1;i--) {
		for(int j=C;j>=0;j--) {
			for(int k=j;k>=0;k--) {
				dp[i][j] = (dp[i][j] + (Pow[k][B[i]] - Pow[k][A[i]-1] + MOD) % MOD * dp[i+1][j-k]) % MOD;
			}
		}
	}
	printf("%lld\n", dp[1][C]);
}

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

int main(){
  int d, t, s;
  cin >> d >> t >> s;
  if(d % s == 0){
    if(d / s <= t){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
  }
  else{
    if(d / s + 1 <= t){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
  }
}

Measured memory_bytes: 3608
n, x, y = map(int, input().split())

cnt = [0] * n
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        dist1 = j - i
        dist2 = min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1
        dist = min(dist1, dist2)
        cnt[dist] += 1

print(*cnt[1:], sep="\n")


Measured memory_bytes: 47580
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int,int>; using pil = pair<int,ll>;
using pli = pair<ll,int>; using pll = pair<ll,ll>;
const int MOD = 1000000007, MOD2 = 998244353;
const int INF = 0x3f3f3f3f, INF2 = 0x3f3f3f37;
const ll LINF = 0x3f3f3f3f3f3f3f3f, LINF2 = 0x3f3f3f3f3f3f3f3d;



int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if (s == u) --a;
    if (t == u) --b;
    cout << a << ' ' << b << '\n';
}

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

struct UnionFind{

    vector<int> par;     //par[i] := iの親の番号

    //最初は全てが寝であるとして初期化
    UnionFind(int n) : par(n){
        for(int i = 0; i < n; i++) par[i] = i;
    }

    //データ x が属する木の根を再帰で得る : root(x) = {x の木の根}
    int root(int x){
        if(par[x] == x) return x;
        return root(par[x]);
    }

    //x と y の木を併合
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
    }

    //x と y のが属する木が同じか
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

struct info{
    int s, t;
    double w;
    info(){}
    info(int s, int t, double w):s(s),t(t),w(w){}
    bool operator<(const info &a) const{
        return w > a.w;
    }
    bool operator>(const info &a) const{
        return w < a.w;
    }
};

int main(){

    int n, m; cin >> n >> m;
    vector<vector<pair<int, double> > > adj(n);
    vector<double> x(n);
    vector<double> y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];

    UnionFind unionfind(n);
    vector<info> edge;


    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--;
        b--;
        edge.push_back(info(a, b, sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]))));      
    }

    sort(edge.begin(), edge.end());

    double ans = 0.0;
    for(auto x : edge){

        //cout << x.w << endl;

        if(!unionfind.same(x.s, x.t)){
            unionfind.unite(x.s, x.t);
        }else{
            ans += x.w;
        }
    }

    printf("%.10f\n", ans);
    //cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4036
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
a = [(a[i],i) for i in range(n)]
b = [(b[i],i) for i in range(n)]
a.sort()
b.sort()
for i in range(n):
    if b[i][0] < a[i][0]:
        print('No')
        quit()

edges = [None]*n
for i in range(n):
    edges[a[i][1]] = b[i][1]

lst = [None]*n

def dfs(s):
    if lst[s] == None:
        lst[s] = tmp
        dfs(edges[s])
    return

tmp = 0
for i in range(n):
    if lst[i] == None:
        dfs(i)
        tmp += 1

lst = list(Counter(lst).values())
if len(lst) >= 2:
    print('Yes')
    quit()

for i in range(n-1):
    if b[i][0] >= a[i+1][0]:
        print('Yes')
        quit()

print('No')


Measured memory_bytes: 133904
#include<iostream>
#include<string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <cstdlib>
using namespace std;

int n, q;
vector<int> S;

bool binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == S.at(mid)) {
			return true;
		}
		else if (key > S.at(mid)) {
			left = mid + 1;
		}
		else {
			right = mid;
		}
	}
	return false;
}
int main() {
	int i,j;
	int ans = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		int s;
		cin >> s;
		S.push_back(s);
	}
	cin >> q;
	for (i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (binarySearch(t) == true) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3520
#include<iostream>
using namespace std;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int main(){
  int m,n;
  while(cin>>m>>n){
    cout << gcd(m,n) << ' ' << lcm(m,n) << endl;
  }
}
 

Measured memory_bytes: 1160
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;
typedef struct Z { ll l,r,nxt; vector<ll> bordercnt,totcnt; Z() {} Z(ll l,ll r,ll nxt):l(l),r(r),nxt(nxt) {} } Z;

char s[MAXN+1]; int n;
ll ql,qr;

int nxt[MAXN]; // nxt[i] = longest border of [0..i]
int scnt[MAXN][26];


vector<Z> z;
vector<ll> add(vector<ll> a,vector<ll> b) { vector<ll> c(26); REP(i,26) c[i]=a[i]+b[i]; return c; }
vector<ll> sub(vector<ll> a,vector<ll> b) { vector<ll> c(26); REP(i,26) c[i]=a[i]-b[i]; return c; }
vector<ll> calc(ll r) {
	vector<ll> ret(26,0);
	int at=0; while(at<SZ(z)&&z[at].r<r) ret=add(ret,z[at].totcnt),++at; assert(at<SZ(z));
	if(at==0) {
		REP(i,26) ret[i]=r==0?0:scnt[r-1][i];
	} else {
		ret=add(ret,sub(calc(z[at].nxt+r-z[at].l-1),z[at-1].bordercnt));
	}
	return ret;
}

void run() {
	scanf("%s%lld%lld",s,&ql,&qr); --ql; n=strlen(s);
	//n=100; REP(i,n/2) s[i]=s[n/2+i]='a'+rand()%2; s[n]='\0'; ql=1; qr=1000000000000000000;

	nxt[0]=0; FOR(i,1,n) { nxt[i]=nxt[i-1]; while(nxt[i]!=0&&s[i]!=s[nxt[i]]) nxt[i]=nxt[nxt[i]-1]; if(s[i]==s[nxt[i]]) ++nxt[i]; }
	//REP(i,n) printf("%d ",nxt[i]); puts("");
	memset(scnt,0,sizeof(scnt)); REP(i,n) { if(i!=0) REP(j,26) scnt[i][j]=scnt[i-1][j]; ++scnt[i][s[i]-'a']; }

	z.clear(); z.PB(Z(0,n,-1)); z.back().totcnt=calc(n);
	ll cnxt=nxt[n-1]; while(2*cnxt>=n) cnxt=nxt[cnxt-1]; int at=0;
	while(z.back().r<qr) {
		//printf("cnxt=%lld\n",cnxt);
		z.back().bordercnt=calc(cnxt);
		//printf("cnxt=%lld:",cnxt); REP(j,26) printf(" %lld",z.back().bordercnt[j]); puts("");
		vector<ll> totcnt=sub(calc(z.back().r-cnxt),z.back().bordercnt);
		//printf("cnxt=%lld:",cnxt); REP(j,26) printf(" %lld",totcnt[j]); puts("");
		z.PB(Z(z.back().r,z.back().r+z.back().r-2*cnxt,cnxt+1));
		z.back().totcnt=totcnt;
		cnxt=z.back().nxt+z.back().r-z.back().l-1-1;
		while(at<SZ(z)&&cnxt>=z[at].r) ++at; assert(at<SZ(z));
		cnxt=at==0?nxt[cnxt]:z[at].nxt+cnxt-z[at].l;
		//printf("cnxt=%lld\n",cnxt);
	}
	//REPSZ(i,z) { printf("(%lld,%lld,%lld)",z[i].l,z[i].r,z[i].nxt); REP(j,26) printf(" %lld",z[i].totcnt[j]); if(i!=SZ(z)-1) { printf(" |"); REP(j,26) printf(" %lld",z[i].bordercnt[j]); } puts(""); }
	vector<ll> ret=sub(calc(qr),calc(ql)); REP(j,26) { if(j!=0) printf(" "); printf("%lld",ret[j]); } puts("");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 21632
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
    int n, h, w;
    cin >> n >> h >> w;
    int res = (n - h + 1) * (n - w + 1);
    if(res < 0)res = 0;
    cout << res << endl;
}





Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, M;
vector<ll> bipartite(vector<vector<ll>>& connection) {
  vector<ll> res = {1, 0};
  vector<ll> color(N, -1);
  color.at(0) = 0;
  queue<ll> q;
  q.push(0);
  while (!q.empty()) {
    ll now = q.front();
    q.pop();
    ll now_color = color.at(now);
    ll dif_color = (now_color + 1) % 2;
    for (ll i = 0; i < connection.at(now).size(); ++i) {
      ll check = connection.at(now).at(i);
      if (color.at(check) == now_color) {
        res.at(0) = -1;
        return res;
      }
      else if (color.at(check) == -1) {
        color.at(check) = dif_color;
        q.push(check);
        res.at(dif_color) += 1;
      }
    }
  }
  return res;
}

int main() {
  cin >> N >> M;
  vector<vector<ll>> connection(N);
  for (ll i = 0; i < M; ++i) {
    ll A, B;
    cin >> A >> B;
    A -= 1;
    B -= 1;
    connection.at(A).push_back(B);
    connection.at(B).push_back(A);
  }
  vector<ll> color_num = bipartite(connection);
  // cout << color_num.at(0) << color_num.at(1) << "\n";
  if (color_num.at(0) == -1) {
    ll ans = N * (N - 1) / 2 - M;
    cout << ans << "\n";
  }
  else {
    ll ans = color_num.at(0) * color_num.at(1);
    ans -= M;
    cout << ans << "\n";
  }
}


Measured memory_bytes: 7168
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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

int main()
{
	map<char, bool> check;
	string s;
	cin >> s;

	rep(i, s.length())
	{
		if (check[s[i]] != true) check[s[i]] = true;	//未登録のアルファベットだったら追加
		else
		{
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}

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

int main() {
	int a[10]; cin >> a[0] >> a[1] >> a[2];

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

	return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <iomanip>
#include <cassert>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i, v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
typedef long long ll;
#define pint pair<int, int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

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

    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    vector<int> sum(n + 1);
    sum[0] = 0;
    rep(i, n) sum[i + 1] = (sum[i] + v[i]) % m;
    map<int, int> ma;
    ll ans = 0;
    rep(i, n + 1)
    {
        ans += ma[sum[i]];
        ma[sum[i]]++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
   int n, t;
   cin>>n>>t;
   int ci, ti;
   int cost = INT32_MAX;
   int flag=0;
   for (int i = 0; i < n; i++)
   {
       cin>>ci>>ti;
       cost= ti<=t ? min(cost,ci) : cost;
       if (cost == ci)
       {
           flag = 1;
       }
       

   }
   if (flag == 0)
   {
       cout<<"TLE";
   }
   else
   {
       cout<<cost;
   }
   
   
   
   return 0;
}


Measured memory_bytes: 3600
from sys import stdin,stdout
def f(A):
	for i in A:
		if i%2==0:
			if i%3!=0 and i%5!=0:
				return 'DENIED'
	return 'APPROVED'

def main():  	
	for x in stdin:

		A = list(map(int,input().split()))
		
		print(f(A))

if __name__ == "__main__":
    main()


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T> inline
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

int dfs(int n, const vector<int> &hs) {
    if (n == hs.size() - 1) {
        return 0;
    }

    int cost1 = n + 1 < hs.size() ? abs(hs[n] - hs[n + 1]) + dfs(n + 1, hs) : int(1e5);
    int cost2 = n + 2 < hs.size() ? abs(hs[n] - hs[n + 2]) + dfs(n + 2, hs) : int(1e5);

    int ret = min(cost1, cost2);

    return ret;
}

int dfs_memo(int n, const vector<int> &hs, vector<int> &memo) {
    if (n == hs.size() - 1) {
        return 0;
    }

    if (memo[n] > -1) {
        return memo[n];
    }

    int cost1 = n + 1 < hs.size() ? abs(hs[n] - hs[n + 1]) + dfs(n + 1, hs) : int(1e5);
    int cost2 = n + 2 < hs.size() ? abs(hs[n] - hs[n + 2]) + dfs(n + 2, hs) : int(1e5);

    int ret = min(cost1, cost2);

    memo[n] = ret;

    return ret;
}

template <typename T> inline
void chmin(T &a, T b){
    if (a > b) {
        a = b;
    }
}

int dp1(const vector<int> &hs) {
    vector<int> costs(hs.size());

    costs[0] = 0;
    costs[1] = abs(hs[0] - hs[1]);

    FOR(i, 2, hs.size()) {
        costs[i] = min(costs[i - 2] + abs(hs[i - 2] - hs[i]), costs[i - 1] + abs(hs[i - 1] - hs[i]));
    }

    return costs.back();
}

int dp2(const vector<int> &hs) {
    vector<LL> costs(hs.size(), 1LL << 60);

    costs[0] = 0;
    REP(i, costs.size()) {
        if (i + 1 < costs.size()) chmin(costs[i+1], costs[i] + abs(hs[i] - hs[i + 1]));
        if (i + 2 < costs.size()) chmin(costs[i+2], costs[i] + abs(hs[i] - hs[i + 2]));
    }

    return costs.back();
}

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

    int N; cin >> N;

    vector<int> h(N);
    REP(i, N) cin >> h[i];

//    cout << dfs(0, h) << endl;

//    vector<int> memo(N, -1);
//    cout << dfs_memo(0, h, memo) << endl;

//  cout << dp1(h) << endl;

    cout << dp2(h) << endl;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<>();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    int type = sc.nextInt();
		    String key = sc.next();
		    if (type == 0) {
		        int value = sc.nextInt();
		        map.put(key, value);
		    } else {
		        sb.append(map.get(key)).append("\n");
		    }
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 195056
package main
 
import(
  "fmt"
	"bufio"
	"os"
	"strings"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}
 
func abc141c(N ,K ,Q int){
	var ans int
	list := []int{}
	for i := 0; i < N; i++{
		list = append(list, 0)
	}
	for i := 0; i < Q; i++{
		fmt.Scan(&ans)
		list[ans-1]++
	}
	for i := 0; i < N; i++{
		if Q - list[i] < K {
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	}
}	
 
func main(){
	x,y,z := 0,0,0
	fmt.Scan(&x)
	fmt.Scan(&y)
	fmt.Scan(&z)
	abc141c(x,y,z)
}

Measured memory_bytes: 7868
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    vector<int> s(m),c(m),ans(n);
    rep(i,m){
        cin>>s[i]>>c[i];
        if(s[i]!=n&&c[i]==0){
            cout<<-1;
            return 0;
        }
        rep(k,i){
            if(s[i]==s[k]&&c[i]!=c[k]){
                cout<<-1;
                return 0;
            }
        }
        ans[s[i]-1]=c[i];
    }
    if(ans[0]==0&&n!=1) ans[0]=1;//一番左が分からない場合
    rep(i,n) cout<<ans[i];
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool yymm=false,mmyy=false;
    string s,fst="",lst="";
    cin>>s;
    for(int i=0; i<4; i++)
    {
        if(i<2)
            fst+=s[i];
        else
            lst+=s[i];
    }
    int f=stoi(fst);
    int l=stoi(lst);
    if(f>=0 && f<=99)
    {
        if(l>=1&& l<=12)
        {
            yymm=true;
        }
    }
    if(f>=1&& f<=12)
    {
        if(l>=0&&l<=99)
        {
            mmyy=true;
        }
    }
    if(yymm && mmyy)
        cout<<"AMBIGUOUS\n";
    else if( yymm ==true && mmyy== false)
    {
        cout<<"YYMM\n";
    }
    else if(yymm==false && mmyy==true)
    {
        cout<<"MMYY\n";
    }
    else
        cout<<"NA\n";
}



Measured memory_bytes: 3632
using System;
using System.Linq;
 
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != "0 0") {
                int[] count = input.Split().Select(p => int.Parse(p)).ToArray();
                Player current, first;
                current = first = new Player();
                for(int i=0; i < count[0]; ++i) {
                    current.Index = i + 1;
                    (current.Next = new Player()).Prev = current;
                    current = current.Next;
                }
                current = current.Prev;
                current.Next = first;
                first.Prev = current;
                while(current != current.Next) {
                    for(int i=0; i < count[1]; ++i) {
                        current = current.Next;
                    }
                    current.Prev.Next = current.Next;
                    current.Next.Prev = current.Prev;
                }
                Console.WriteLine(current.Index);
            }
        }
    }
    class Player
    {
        public Player Next { get; set; }
        public Player Prev { get; set; }
        public int Index { get; set; }
    }
}

Measured memory_bytes: 6020
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int A[11];
int main(){
	int N;
	int cnt=0;
	cin>>N;
	rep(i,N){
		cin>>A[i];
		if(A[i]%2==0)cnt++;
	}
	int ans=1;
	rep(i,N)ans*=3;
	int t=1;
	rep(i,cnt)t*=2;
	ans-=t;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb std::ios::sync_with_stdio(false)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
/*** TEMPLATE CODE STARTS HERE ***/
ll n;
ll ans;
ll x;
ll a[200050];
ll ABS(ll x)
{
	return x>0?x:-1*x;
}
int main()
{
	// freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
	// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    ans=1e18;
    gbtb;
    cin>>n>>x;
    repd(i,1,n)
    {
    	cin>>a[i];
    	a[i]=a[i]+a[i-1];
    }
    for(int k=1;k<=n;++k)
    {
    	ll sum = 0;
    	ll now = 3;
    	for(int i=n;i>=1;i-=k)
    	{
    		sum+=(a[i]-a[max(0,i-k)])*max(now,5ll);
    		now+=2;
    		if(sum>=ans)
    		{
    			break;
    		}
    	}
    	ans=min(ans,sum+=1ll*(k+n)*x);

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

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}


Measured memory_bytes: 1792
use std::io::Read;
use std::collections::VecDeque;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let mut graph: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..m {
        let ai: usize = iterator.next().unwrap().parse().unwrap();
        let bi: usize = iterator.next().unwrap().parse().unwrap();
        let ai = ai - 1;
        let bi = bi - 1;
        graph[ai].push(bi);
        graph[bi].push(ai);
    }

    let mut ans: usize = 0;
    let mut visited: Vec<bool> = vec![false; n];
    for i in 0..n {
        if visited[i] {
            continue;
        }
        let mut a: usize = 0;
        let mut q: VecDeque<usize> = VecDeque::new();
        visited[i] = true;
        q.push_back(i);
        a += 1;
        while let Some(u) = q.pop_front() {
            for &v in &graph[u] {
                if visited[v] {
                    continue;
                }
                visited[v] = true;
                q.push_back(v);
                a += 1;
            }
        }
        ans = max(ans, a);
    }
    ans.to_string()
}


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

vector<int> v[111111];
vector<P> p;
int u[111111][2],c[2];

void dfs(int x,int t) {
  if(u[x][t]) return;
  c[t]++;
  u[x][t]=1;
  for(int i=0; i<v[x].size(); i++) dfs(v[x][i],t^1);    
}

bitset<100001> t;

int main() {
  int n,m;
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0; i<n; i++) {
    if(u[i][0]||u[i][1]) continue;
    c[0]=c[1]=0;
    dfs(i,0);
    if(c[0]<c[1]) swap(c[0],c[1]);
    p.push_back(P(c[0],c[1]));
  }
  for(int i=0; i<n; i++) {
    if(u[i][0]&&u[i][1]) {
      cout << -1 << endl;
      return 0;
    }
  }
  t.set(0);
  for(int i=0; i<p.size(); i++) {
    t=(t<<p[i].first)|(t<<p[i].second);
  }
  ll ans=0;
  for(ll i=0; i<=n; i++) {
    if(t[i]) ans=max(ans,i*(n-i)-m);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10288
N, K = map(int, input().split()) 

A = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

b = 0
for a in A:
    b = gcd(a, b)

if K % b or K > max(A):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Measured memory_bytes: 14252
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const long long MAX = 1000000000;

bool query(long long x)
{
    cout << "? " << x << endl;
    char c;
    cin >> c;
    return c == 'Y';
}

int main()
{
    long long n = 0;

    for(int i=0; i<9; ++i){
        int left = 0;
        int right = 9;
        if(i == 0)
            ++ left;

        while(left < right){
            int mid = (left + right) / 2;
            long long x = (n * 10 + mid + 1) * MAX - 1;
            if(!query(x))
                left = mid + 1;
            else
                right = mid;
        }

        n *= 10;
        n += left;

        if(left < 9){
            long long x = n + 1;
            if(query(x)){
                cout << "! " << n << endl;
                return 0;
            }
        }
        else{
            long long x = 10 * n - 1;
            if(!query(x)){
                cout << "! " << n << endl;
                return 0;
            }
        }
    }

    n *= 10;
    cout << "! " << n << endl;
    return 0;
}


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

int main()
{
    int n;
    string s;

    cin >> n;
    cin >> s;

    int count = 0;


  
    rep(i, n - 2)
    {
        if (s.at(i) == 'A')
        {
            if (s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
            {
                count++;
            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
import time
import sys

def fib(n):
    memo = [0] * n
    memo[0:2] = [2, 1]
    for i in range(2, n):
        memo[i] = memo[i - 1] + memo[i - 2]
    return memo[i]

def main():
    N = input()
    if(int(N) == 0):
        print(2)
        sys.exit()
    elif(int(N) == 1):
        print(1)
        sys.exit()
    else:
        print(fib(int(N)+1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int main() {
    ll n,m,ans=0;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a,b);
    }
    rep(i,n){
        ll hoge = uf.size(i);
        ans = max(hoge,ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4020
#include <iostream>

using namespace std;

const int speY = 200;
const int ordY = 195;

const int bigM = 20;
const int smlM = 19;

const int Y3 = speY + ordY * 2;

int calcDay(int Y, int M, int D)
{
	int day = 0;

	day += Y3 * ((Y - 1) / 3);
	day += ordY * ((Y - 1) % 3);

	if (Y % 3)
		day += (M - 1) / 2 * (bigM+smlM) + ((M - 1) % 2) * bigM;
	else
		day += (M - 1) * bigM;

	return day + D;
}

int main()
{
	int mDay = calcDay(1000, 1, 1);

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int Y, M, D;
		cin >> Y >> M >> D;

		cout << calcDay(1000, 1, 1) - calcDay(Y, M, D) << endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	vector<int> ns;
	map<int,int> ss;
	int t;
	for(t=0;t<n;t++) 
	{
		int a;
		scanf("%d",&a);
		if(ss[a] == 0)
			ns.push_back(a);
		ss[a] ++;
	}
	int ma=0;
	sort(ns.begin(),ns.end());
	for(t=0;t<ns.size();t++)
	{
		ma = max(ma,ss[ns[t]]);
		if(t != 0)
		{
			if(ns[t-1]+2==ns[t] || ns[t-1]+1==ns[t])
				ma = max(ma,ss[ns[t-1]]+ss[ns[t]]);
		}
		if(t != ns.size()-1)
		{
			if(ns[t+1]-2==ns[t] || ns[t+1]-1==ns[t])
				ma = max(ma,ss[ns[t+1]]+ss[ns[t]]);
		}
		if(t!=0 && t!=ns.size()-1)
		{
			if(ns[t-1]+1==ns[t] && ns[t+1]-1==ns[t])
				ma = max(ma,ss[ns[t-1]]+ss[ns[t]]+ss[ns[t+1]]);
		}
	}
	printf("%d\n",ma);
	return 0;
}

Measured memory_bytes: 5500