akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "utility"
#include "functional"

using namespace std;
using ll = long long int;
using V = tuple<int, int, int>;
using P = pair<ll, V>;

int N, M, E, S, T, R;
int A[10000];
int B[10000];
int eA[10000];
int eB[10000];
int eC[10000];
vector<int> G[100];
ll dist[100][100][1 << 4];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M >> E >> S >> T >> R;
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	int z = 0;
	for (int i = 0; i < E; i++) {
		cin >> eA[i] >> eB[i] >> eC[i];
		if (eC[i] == S) {
			G[eA[i]].push_back(eB[i]);
			G[eB[i]].push_back(eA[i]);
			z |= (1 << i);
		}
	}
	fill((ll*)dist, (ll*)(dist + 100), 1LL << 60);
	dist[S][0][z] = 0;
	priority_queue<P, vector<P>, greater<P>> Q;
	Q.emplace(0, V(S, 0, z));
	while (!Q.empty()) {
		P p = Q.top(); Q.pop();
		V v = p.second;
		int x = get<0>(v), y = get<1>(v), z = get<2>(v);
		if (dist[x][y][z] < p.first) continue;
		if (y + 1 <= R) {
			for (int to : G[x]) {
				int nz = z;
				for (int i = 0; i < E; i++) {
					if (eC[i] == to) nz |= (1 << i);
				}
				if (dist[to][y + 1][nz] > p.first + 1) {
					dist[to][y + 1][nz] = p.first + 1;
					Q.emplace(p.first + 1, V(to, y + 1, nz));
				}
			}
			for (int i = 0; i < E; i++) {
				if (!(z&(1 << i))) continue;
				if (eA[i] == x) {
					int nz = z;
					for (int j = 0; j < E; j++) if (eC[j] == eB[i]) nz |= (1 << j);
					if (dist[eB[i]][y + 1][nz]>p.first + 1) {
						dist[eB[i]][y + 1][nz] = p.first + 1;
						Q.emplace(p.first + 1, V(eB[i], y + 1, nz));
					}
				}
				else if (eB[i] == x) {
					int nz = z;
					for (int j = 0; j < E; j++) if (eC[j] == eA[i]) nz |= (1 << j);
					if (dist[eA[i]][y + 1][nz]>p.first + 1) {
						dist[eA[i]][y + 1][nz] = p.first + 1;
						Q.emplace(p.first + 1, V(eA[i], y + 1, nz));
					}

				}
			}
		}
		if (dist[S][0][z] > p.first + 1) {
			dist[S][0][z] = p.first + 1;
			Q.emplace(p.first + 1, V(S, 0, z));
		}
	}
	ll ans = 1LL << 60;
	for (int i = 0; i <= R; i++) {
		for (int bit = 0; bit < (1 << E); bit++) {
			ans = min(ans, dist[T][i][bit]);
		}
	}
	if (ans == 1LL << 60) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 4612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll ans = 0;
  ll R = 0;
  ll G = 0;
  ll B = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') {
      R++;
    } else if (S[i] == 'G') {
      G++;
    } else {
      B++;
    }
  }
  ans = R*G*B;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < N - i - i; j++) {
      if (S[j] != S[j+i] && S[j+i] != S[j+i+i] && S[j+i+i] != S[j]) {
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
int main(void){
    char s[5];
    int test=0,i;
    scanf("%s",s);
    for(i=0;i<3;i++){
        if(s[i]==s[i+1]){
            test=1;
        };
    };
    if(test==0){
        printf("Good");
    }
    else{
        printf("Bad");
    };
    return 0;
};


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

int main(){
  int n,i,j,c=0;
  bool b=0;
  cin>>n;
  int h[n];
  for (i=0;i<n;i++)cin>>h[i];
  for (i=0;i<n;i++){
    b=1;
    for (j=0;j<i;j++)b&=(h[j]<=h[i]);
    c+=b;
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

void solve() {
    cins(s);
    cout<<s.substr(0,3)<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};

int main() {
	FREOPEN();
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d ", &x);
		if (!ans) ans = x;
		ans = __gcd(ans, x);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])


Measured memory_bytes: 142784
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let h = read_vec::<usize>();
    let mut ans = 0;
    for num in h {
        if num >= k {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6396
#include<iostream>
using namespace std; //?
 
int main(){
    int n1, n2, n3;
    
    cin >> n1 >> n2 >> n3;
    
    if ( n1 > n2 ) {
        swap(n1 ,n2);
}

    if ( n2 > n3 ) {
        swap(n2 ,n3);
}

    if ( n1 > n2 ) {
        swap(n1 ,n2);
}

    cout << n1 << " " << n2 << " " << n3 << endl;

    return 0;		 
}


Measured memory_bytes: 3088
LINE = '#.' * 150
RLINE = '.#' * 150


def print_board(H, W):
    line = LINE[:W]
    rline = RLINE[:W]
    for i in range(H):
        if i % 2 == 0:
            print(line)
        else:
            print(rline)


while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    print_board(H, W)
    print()



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, k;
    cin>>n>>k;
    vector<ll> a(n);
    f(i, n) cin>>a[i];
    ll tans = 0;
    for(int i = 0; i <= k; i++){ //Take this much
        int can = k - i;
        for(int j = 0; j <= i; j++){
            int tcan = can;
            int l = j;
            if(l > n){
                tcan += l - n;
                l = n;
            }
            int r = i - l;
            if(l + r > n){
                tcan += l + r - n;
                r = n - l;
            }
            multiset<ll> S;
            ll ans = 0;
            f(ii, l) {
                if(a[ii] > 0) ans += a[ii];
                else S.insert(a[ii]);
            }
            int tr = r;
            for(int ii = n - 1; tr > 0; ii--, tr--){
                if(a[ii] > 0) ans += a[ii];
                else S.insert(a[ii]);
            }
            while(S.size() && tcan){
                auto it = S.begin();
                S.erase(it);
                tcan--;
            }
            while(S.size()) {
                ans += *S.begin();
                S.erase(S.begin());
            }
            //cout<<l<<' '<<r<<' '<<ans<<endl;
            tans = max(tans, ans);
        }
    }
    cout<<tans;
    return 0;
}

Measured memory_bytes: 256
### main

loop do
  t, num = gets.split.map(&:to_i)
  break if (t || num) == 0

  nums = num.to_s.split('').map(&:to_i)
  blen = nums.length - 1

  max_sum = nil
  max_nums = nil

  for bits in (0...(1 << blen))
    b = bits
    sum = 0
    mnums = []
    prv = nums[0]

    for i in (1..blen)
      if (b & 1) == 0
        prv = prv * 10 + nums[i]
      else
        sum += prv
        mnums << prv
        prv = nums[i]
      end
      b >>= 1
    end
    sum += prv
    mnums << prv
    #p [sum, mnums]

    if sum <= t
      if max_sum.nil? || max_sum < sum
        max_sum = sum
        max_nums = mnums
      elsif max_sum == sum
        max_nums = nil
      end
    end
  end

  if max_sum.nil?
    puts 'error'
  elsif max_nums.nil?
    puts 'rejected'
    #puts max_sum
  else
    puts ([max_sum] + max_nums).join(' ')
  end
end

Measured memory_bytes: 6128
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N, X, Y = i_l()
X -= 1
Y -= 1
dist = [0] * N
for i in range(N):
    for j in range(i+1, N):
        k = min(j-i, abs(i-X) + abs(j-Y) + 1)
        dist[k] += 1

for i in range(1, N):
    print(dist[i])


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

int main() {
  int A , B ; 
  cin >> A >> B ;
  
  if(A > B){
    cout << A + (A-1) << endl ; 
  }
  else if (B > A){
    cout << B + (B-1) << endl ; 
  }
  
  else{
    cout << A + B << endl ; 
  }
  
  
  
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int grundy(int x, int k) {
  while (true) {
    if (x<k||x%k==0) return x/k;
    int a = x/k;
    x = a*k + (x%k)%(a+1);
    if (x<k||x%k==0) return x/k;
    x = x-(x/k)-1;
    //cout<<"grundy("<<x<<","<<k<<")\n";
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  int g = 0;
  rep(i, N) {
    int a, k;
    cin >> a >> k;
    g ^= grundy(a, k);
  }
  if (g == 0) cout << "Aoki\n";
  else cout << "Takahashi\n";
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return 0;
  return 1;
}
int main(){
  int b;
  /*
  long long x=0;
  for(i=2;i<25;i++){
    x=x*10+1;
    cout << x<<" "<<i<<" "<<(x%i) <<endl; 
    }*/
  cin >> b;
  if(b==0||b==2) cout << 1 << endl;
  else if(b==1) cout << 2 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 1164
a=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")#26
b={0:'A',1:'B',2:'C',3:'D',4:'E',5:'F',6:'G',7:'H',8:'I',9:'J',10:'K',11:'L',12:'M',13:'N',14:'O',15:'P',16:'Q',17:'R',18:'S',19:'T',20:'U',21:'V',22:'W',23:'X',24:'Y',25:'Z'}
c={'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}
n=int(input())
s=input()
for i in range(len(s)):
    z=c[s[i]]
    z+=n
    if z>25:
        z-=26
    print(b[z],end="")
print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n;
    cin >> n;
    while (n--) {
        int x, y, b, p;
        cin >> x >> y >> b >> p;
        int B = max(5, b), P = max(2, p);
        cout << min(x * b + y * p, (x * B + y * P) / 5 * 4) << "\n";
    }
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define d first
#define wgt first
#define to second

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(11000);
int n,d[11000];

void Dijkstra()
{
	bool used[11000];
	priority_queue<pii,vector<pii>,greater<pii> > pq;
	fill(d,d+n,INT_MAX);
	memset(used,false,sizeof(used));
	pq.push(make_pair(0,0));
	while(!pq.empty())
	{
		pii u=pq.top();pq.pop();
		if(used[u.to]) continue;
		used[u.to]=true;
		d[u.to]=u.d;
		for(int i=0;i<G[u.to].size();i++)
			if(d[G[u.to][i].to]>d[u.to]+G[u.to][i].wgt)
			{
				d[G[u.to][i].to]=d[u.to]+G[u.to][i].wgt;
				pq.push(make_pair(d[G[u.to][i].to],G[u.to][i].to));
			}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[u].push_back(make_pair(w,v));
		}
	}
	Dijkstra();
	for(int i=0;i<n;i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}

Measured memory_bytes: 8032
N = int(input())
S = input()

L = ['R', 'G', 'B']
accum = [[0] * N for i in range(3)]
for i in range(3):
    l = L[i]
    if S[0] == l:
        accum[i][0] = 1
    for j in range(1, N):
        accum[i][j] = accum[i][j - 1] + (1 if S[j] == l else 0)

ans = 0
for j in range(1, N - 1):
    for i in range(j):
        if S[i] == S[j]:
            continue
        for k in range(3):
            if L[k] != S[i] and L[k] != S[j]:
                lk = L[k]
                ik = k
        ans += accum[ik][N - 1] - accum[ik][j]
        if 2 * (j + 1) - (i + 1) <= N and S[2 * (j + 1) - (i + 1) - 1] == lk:
            ans -= 1
print(ans)


Measured memory_bytes: 68960
#include<bits/stdc++.h>
#define mod 1000000007
#define pie 3.14159265358979323846264338327950288419716939937510
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
int main()
{
fast_io
li n,i,x;
cin>>n;
li a[n]={0};
for(i=0;i<n-1;i++)
{
  cin>>x;
  a[x-1]++;
}
for(i=0;i<n;i++)
cout<<a[i]<<endl;
  return 0;
}


Measured memory_bytes: 5152
#include<stdio.h>
#include<string.h>
#define LEN 100005

int min(int a, int b) {
	if( a < b ){
		return a;
	}
	else{
		return b;
	}
}

typedef struct {
	char name[ 100 ];
	int t;
} P;

P Q[ LEN + 1 ];
int head, tail, n;

void enqueue( P x ){
	Q[ tail ] = x;  
	if( tail == LEN ){
		tail = 1;
	}
	else{
		tail++;
	}
}

P dequeue(){  
	P x = Q[ head ];
	if( head == LEN ){
		head = 1;
	}
	else{
		head++;
	}
	return x;
}
    
int main(){  
	int elaps = 0, c, i, q;
	P u;
	scanf( "%d %d", &n, &q );
	for( i = 1; i <= n; i++ ){
		scanf( "%s %d", Q[ i ].name, &Q[ i ].t );
	}
	head = 1;
	tail = n + 1;
	while( head != tail ){
		u = dequeue();
		c = min( q, u.t );
		u.t -= c;
		elaps += c;
		if( u.t > 0 ){
			enqueue( u );
		}
		else{
			printf( "%s %d\n", u.name, elaps );
		}
	}
	return 0;
}

Measured memory_bytes: 10756
#include<stdio.h>

#define X 2000
#define L 2000


int n, A[X], M[L];
int loop(int, int);
 

int main(){
  int i, m;
  
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
  }  
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d", &M[i]);
  }
  
  for(i=0;i<m;i++){
    if(loop(0, M[i]) == 1)printf("yes\n");
    else printf("no\n");   
  }
  return 0;
}

int loop(int j, int m){
  int a;
  
  a = m - A[j];
  if(j > n) return 0;
  else if(a == 0) return 1;
  else if(loop(j+1, m) == 1)return 1;
  else if(loop(j+1, a) == 1)return 1;
  return 0;
}

Measured memory_bytes: 584
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    r = I()
    print(int(r**2))

main()



Measured memory_bytes: 27180
def count_anagram_strings():
    n = int(input())
    count = 0
    d = dict()
    for i in range(n):
        key = "".join(sorted(list(input())))
        if key not in d:
            d[key] = 1
        else:
            d[key] += 1

    # N numbers have N * (N - 1) / 2 pairs
    for v in d.values():
        count += v * (v - 1) / 2
    
    print(int(count))

if __name__ == '__main__':
    # n = int(input())
    count_anagram_strings()

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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

const int dx[]={1,-1,0,0},
		  dy[]={0,0,1,-1};

const int inf=1e9;

int n,m,a[N],k,q,u,v,x,y,tc,c,l,r,ans,p,cnt,root[N],sz[N];

char s[N];

bool ok[N];

set<int> nxt[26];

int main(){
	scanf("%d",&n);
	int gcd=0;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]),gcd=__gcd(a[i],gcd);
	printf("%d\n",gcd);
}



Measured memory_bytes: 2304
n = int(input())
s = input()

a = [(0, 0) for _ in range(len(s) + 1)]

i = 0
while i < len(s):
    bs, ws = a[i + 1]
    b0, w0 = a[i]

    if s[i] == '#':
        bs += 1
    else:
        ws += 1

    a[i + 1] = (bs + b0, ws + w0)
    i += 1


i = 0
can = len(s)
while i < len(a):
    can = min(can, a[i][0] + a[-1][1] - a[i][1])
    i += 1

print(can)


Measured memory_bytes: 30468
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  vector<int> h(N);
  for(int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
  }
  bool isSummit;
  int Cx = 0, Cy = 0;
  int H;

  for(int i = 0; i <= 100; i++) {
    for(int j = 0; j <= 100; j++) {
      H = -1;
      isSummit = true;
      for(int k = 0; k < N; k++) {
        if(h[k] == 0) {
          continue;
        }
        if(-1 == H) {
          H = abs(j - x[k]) + abs(i - y[k]) + h[k];
          continue;
        }
        if(H != abs(j - x[k]) + abs(i - y[k]) + h[k]) {
          isSummit = false;
          break;
        }
      }
      if(isSummit) {
        for(int k = 0; k < N; k++) {
          if(h[k] == 0
             && 0 < H - abs(j - x[k]) - abs(i - y[k])) {
            isSummit = false;
            break;
          }
        }
      }

      if(isSummit) {
        Cx = j;
        break;
      }
    }
    if(isSummit) {
      Cy = i;
      break;
    }
  }
  cout << Cx << ' ' << Cy << ' ' << H << endl;
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	deque<ll> A(N);
	REP(i,N){
		A[i]=in();
	}
	sort(ALL(A),greater<ll>());

	vector<ll> P(N);
	ll coeff=1;
	REP(i,N){
		ll V=(i==0 || i==N-1)?1:2;
		P[i]=coeff*V;
		coeff*=-1;
	}
	sort(ALL(P),greater<ll>());
	ll S1=0;
	REP(i,N) S1+=P[i]*A[i];

	coeff=-1;
	REP(i,N){
		ll V=(i==0 || i==N-1)?1:2;
		P[i]=coeff*V;
		coeff*=-1;
	}
	sort(ALL(P),greater<ll>());
	ll S2=0;
	REP(i,N) S2+=P[i]*A[i];
	out(max(S1,S2));
	return 0;
}


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

int dx[ ] = { 1, -1, 0, 0, 1, -1, -1, 1 } ;
int dy[ ] = { 0, 0, -1, 1, 1, -1, 1, -1 } ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}


void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , k ;
int main(){

   cin >> n >> k ;
   vector < int > dp( n + 1 ) ;
   forn( int , i , 1 , n + 1 ){
      dp[ i ] = k + i - 1 ;
      dp[ i ] += dp[ i - 1 ] ;
   }

   int mn = Int_max ;
   int ans = 0 ;

   forn( int , i , 1 , n + 1 ){
     int sum2 = dp[ i - 1 ] + dp[ n ] - dp[ i ] ;
     if( abs( dp[ n ] - sum2 ) < mn ){
        mn = abs( dp[ n ] - sum2 ) ;
        ans = sum2 ;
     }
   }

   cout << ans ;


   return 0 ;
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(long long N, std::vector<long long> A){
    vec<ll> ress(N);
    for(auto iter: A){
        ress.at(iter - 1)++;
    }

    for(auto iter: ress){
        cout << iter << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 6432
def insertionSort(n, A):
    for i in range(n):
        t = A[i]
        j = i - 1
        while (j >= 0) and (A[j] > t):
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = t
        print(*A)
    return A


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    insertionSort(N, A)

Measured memory_bytes: 8044
def insertion_sort(a):
    for i in range(1,len(a)):
        key = a[i]
        j = i-1
        while j >= 0 and a[j] > key:
            a[j+1] = a[j]
            j = j-1
        a[j+1] = key
        print(*a,sep=' ')
    return a


if __name__ == '__main__':
    n = input()
    a = list(map(int,input().split()))
    print(*a,sep=' ')
    insertion_sort(a)


Measured memory_bytes: 5980
use std::collections::HashMap;
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: u64 = sc.read();
    let mut a: Vec<u64> = sc.vec(n);
    for x in a.iter_mut() {
        *x -= 1;
    }
    let mut a_sum = vec![0; n + 1];
    for i in 1..n + 1 {
        a_sum[i] = (a_sum[i - 1] + a[i - 1] + k) % k;
    }
    let mut counters = HashMap::new();
    let mut result: u64 = 0;
    for i in 0..n + 1 {
        let count = counters.get(&a_sum[i]).unwrap_or(&0).clone();
        result += count;
        *counters.entry(a_sum[i]).or_insert(0) += 1;
        if i + 1 >= k as usize {
            *counters.entry(a_sum[i + 1 - k as usize]).or_insert(1) -= 1;
        }
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 23372
#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 rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    map<int,int> a,b;
    rep(i,n) {
        if(i%2 == 0) a[v[i]]++;
        else b[v[i]]++;
    }
    int amx=0,bmx=0;
    int na,nb;
    int ia,ib;
    for(auto p : a) {
        if(p.second > amx) {
            na = 1;
            amx = p.second;
            ia = p.first;
        } else if(p.second == amx) {
            na++;
        }
    }
    for(auto p : b) {
        if(p.second > bmx) {
            nb = 1;
            bmx = p.second;
            ib = p.first;
        } else if(p.second == bmx) {
            nb++;
        }
    }
    if(na >= 2 || nb >= 2) cout << n-amx-bmx << endl;
    else if(ia != ib) cout << n-amx-bmx << endl;
    else {
        int namx = 0, nbmx = 0;
        for (auto p : a) {
            if (p.second > namx && p.second < amx) {
                namx = p.second;
            }
        }
        for (auto p : b) {
            if (p.second > nbmx && p.second < bmx) {
                nbmx = p.second;
            }
        }
        cout << min(n-amx-nbmx,n-bmx-namx) << endl;
    }
}


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

#define MAX_N 100000
#define MAX_M 1000000000
typedef long long int ll;

int main() {
  int n;
  ll m;

  std::cin >> n >> m;

  if(n == 1) {
    std::cout << m << std::endl;
    return 0;
  }

ll ans = 1, tmp = 2;
while(tmp * tmp <= m) {
  if(n * tmp > m) break;
  if(m % tmp == 0) {
    ans = std::max(ans, tmp);
    if(n * m / tmp <= m) {
      ans = std::max(ans, m / tmp);
    }
  }
  ++tmp;
}

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


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

int main(void){
    // Your code here!
    long long x, count = 0;
    
    cin >> x;
    
    count += (x / 11) * 2;
    x -= (x / 11) * 11;
    if(x > 6)
        count += 2;
    else if(x > 0)
        count += 1;
        
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    s = input()
    way = [[] for _ in range(n)]
    nway = [[0,0] for i in range(n)]
    for _ in range(m):
        a,b = map(int,ipt().split())
        a -= 1
        b -= 1
        way[a].append(b)
        way[b].append(a)
        if s[a] == "A":
            nway[b][0] += 1
        else:
            nway[b][1] += 1
        if s[b] == "A":
            nway[a][0] += 1
        else:
            nway[a][1] += 1
    al = [0]*n

    q = deque()
    for i,wi in enumerate(nway):
        if wi[0] == 0 or wi[1] == 0:
            q.append(i)

    while q:
        qi = q.pop()
        al[qi] = -1
        if s[qi] == "A":
            x = 0
        else:
            x = 1
        for i in way[qi]:
            if al[i] == 0:
                if nway[i][x] == 1:
                    q.append(i)
                else:
                    nway[i][x] -= 1

    if 0 in al:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 93820
from collections import Counter


N = int(input())
lst_A = list(map(int, input().split()))
# set_A = set(lst_A)
cnt_A = Counter(lst_A)
ans = 0


# for key in set_A:
for key in lst_A:
    cnt_X = cnt_A[key - 1] + cnt_A[key] + cnt_A[key + 1]
    ans = max(ans, cnt_X)


print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];

    sort(L.begin(), L.end(), greater<int>());
    int sum = 0;
    for(int i=1; i<N; i++) {
        sum += L[i];
    }
    if(L[0] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main(void) {
	int N, M;
	cin >> N >> M;
	priority_queue <int> que;
	for (int i = 0; i < N; i++) {
		int Ai;
		cin >> Ai;
		que.push(Ai);
	}
	for (int i = 0; i < M; i++) {
		int A = que.top();
		que.pop();
		A /= 2;
		que.push(A);
	}
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

int main() {
    FAST;

    int n;
    cin >> n;

    ll sum = 0;
    ll a;
    rep(i, n){
        cin >> a;
        sum += (a - 1);
    }

    println(sum);
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int N;
   std::string S;
   std::cin >> N >> S;

   int count = 0;
   for(int i=1; i<N; ++i){
      if(S[i]=='E') ++count;
   }
   int ans = count;
   for(int i=1; i<N; ++i){
      if(S[i-1]=='W') ++count;
      if(S[i]=='E') --count;
      if(ans>count) ans = count;
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 900
#!/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()))
"""
.2分探索を考える
.各kに対してx回以上抜き出せるかという問いを考える
.各数の個数を数えて数iの個数をCiとする
.各数iを抜き出せるのはCiまで
 ⇒各数を抜き出す回数min(Ci,x)
.Σmin(Ci,x)はkx以上でなければいけない(k個x回抜き出すため)
.これを満たすときx回抜き出せる
.このままではO(n^2(logn))なので工夫する
.Σ(min(Ci,x))はk依存でないのでここを工夫する(Σ(min(Ci,x))をSxとする)
.SxはSx-1と比べてx以上のCiの数だけ増える(x以上のCiの数をDxとする)
.Sx := Sx-1 + Dx
.Dxを求める時はCのリストについてbisectを行う。
.Sx >= k*xとなるxの最大値を2分探索で求める。(O(nlogn))
"""
n = I()
a = LI()
cnt = list(Counter(a).values())
cnt.sort()
m = len(cnt)
S = [0]*(n+1)
for x in range(1,n+1):
    l = bl(cnt,x)
    S[x] = S[x-1] + (m-l)
for k in range(1,n+1):
    high,low = n+1,0
    while high - low > 1:
        mid = (high + low)//2
        if S[mid] >= k*mid:
            low = mid
        else:
            high = mid
    print(low)


Measured memory_bytes: 120496
#include <bits/stdc++.h>
using namespace std;
int main(void){

    string s;
    int b=0;
    
    cin >> s;
    
    int n = s.size();
    int m = (n-1)/2;
    int k = (n+3)/2;
    int c=0;
    for(int i=0;i<n/2;i++){
        if(s[i] == s[n-i-1]) c++;
    }
    if(c == n/2) b++;
    
    c=0;
    
    string ms = s.substr(0, m), ks = s.substr(k-1, n);
    
    for(int i=0;i<m/2;i++){
        if(ms[i] == ms[m-i-1]) c++;
    }
    if(c == m/2) b++;
    c = 0;
    for(int i=0;i<(n-k)/2;i++){
        if(ks[i] == ks[(n-k)-i]) c++;
    }
    if(c == (n-k)/2 )b++;
    
    if(b == 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,S,E,SA;
  int SUM = 0;
  cin >> N;

  
  for (int i =0; i < N; i++){
     cin >> S >> E;
    SA = E - S + 1;
    SUM += SA;
  }
    
    cout << SUM << endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int bit = 0; bit < (1 << (S.size()-1)); bit++) {
        int cnt = 0;
        for (int i = 0; i < S.size()-1; ++i) {
            cnt*=10;
            cnt+=S[i]-'0';
            if (bit & (1 << i)) {
                ans+=cnt;
                cnt = 0;
            }
        }
        cnt*=10;
        cnt+=S[S.size()-1]-'0';
        ans+=cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    
    private final static String SPACE = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int a = Integer.valueOf(inputs[0]);
                int b = Integer.valueOf(inputs[1]);
                int c = Integer.valueOf(inputs[2]);
                
                int count = 0;
                if (b < c) {
                    for (int x = a; x <= b; x++) {
                        if (c % x == 0) {
                            count++;
                        }
                    }
                } else {
                    for (int x = a; x <= c; x++) {
                        if (c % x == 0) {
                            count++;
                        }
                    }
                }
                System.out.println(count);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
}

Measured memory_bytes: 24332
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
	int n;
  	cin>>n;
  	int maxx=-1;
  	for(int i=0;i<n;i++)
    {
      	cin>>a[i];
      	maxx=max(maxx,a[i]);
    }
  	int cnt=0;
  	int max2=-1; 
  	for(int i=0;i<n;i++)
    {
      	if (a[i]==maxx)
          	cnt++;
      	if (a[i]!=maxx)
          	max2=max(max2,a[i]);
    }
  	for(int i=0;i<n;i++)
    {
      	if (a[i]<maxx)
          	cout<<maxx<<endl;
    	else if (cnt>1)
          	cout<<maxx<<endl;
      	else
          	cout<<max2<<endl;
    }
  return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int main() {
  int64_t N, M;
  cin >> N >> M;

  string s, t;
  cin >> s >> t;

  const int64_t d = gcd(N, M);
  bool result = true;
  rep(i, d) { result = result && (s[N / d * i] == t[M / d * i]); }
  cout << (result ? N * M / d : -1) << endl;

  return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int A,B,C,K,ans;
  	cin>>A>>B>>C>>K;
  	if(K<=A)
    {
    	cout<<K<<endl;
    }
  	else
    {
    	K=K-A;
      	if(K<=B)
        {
        	ans=A;
          	cout<<ans;
        }
      	else
        {
        	K=K-B;
          	ans=A-K;
          	cout<<ans;
        }
    
    }
  	

 return 0;

}

Measured memory_bytes: 3632
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

void solve1(int n,int a){
  if(1<= a and a<= n/2){
    print("Yes");
  }else if(a==n-1){
    print("Yes");
  }else{
    print("No");
  }
}

void solve2(int n,map<int,int>& mp){
  auto itr=mp.begin();
  int a=itr->first,_a=itr->second;
  if(df)print(a,_a);
  itr++;
  int b=itr->first,_b=itr->second;
  if(df)print(b,_b);
  if(b!=a+1){
    print("No");
  }else if(_a<=a and a<=_a-1+_b/2){
    print("Yes");
  }else{
    print("No");
  }
}

int main(){
  int n; cin >>n;
  map<int,int> mp;
  rep(i,n){
    int a; cin >>a;
    mp[a]++;
    if(mp.size()>2){
      print("No");
      return 0;
    }
  }
  if(mp.size()==1){
    int a=mp.begin()->first;
    solve1(n,a);
  }else{
    solve2(n,mp);
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define Maxn 800005

using namespace std;

const LL P = 200003; const double PI = acos(-1.0);

inline LL read() {
    LL x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

LL n, m = 1, val[Maxn], mapp[Maxn], trans[Maxn], g[Maxn];

struct Point {
    double x, y;
}
f[Maxn];

Point Plus(Point a, Point b) {
    Point c;
    c.x = a.x + b.x; c.y = a.y + b.y;
    return c;
}

Point Minus(Point a, Point b) {
    Point c;
    c.x = a.x - b.x; c.y = a.y - b.y;
    return c;
}

Point Mul(Point a, Point b) {
    Point c;
    c.x = a.x * b.x - a.y * b.y;
    c.y = a.x * b.y + b.x * a.y;
    return c;
}

void DFT(Point *F, bool op) {
    for(int i = 0; i < m; ++i) trans[i] = (trans[i >> 1] >> 1) | ((i & 1) ? m >> 1 : 0);
    for(int i = 0; i < m; ++i) if(i < trans[i]) swap(F[i], F[trans[i]]);
    for(int len = 2; len <= m; len <<= 1) {
        Point base = {cos(2 * PI / len), sin(2 * PI / len)};
        if(op) base.y *= -1.0;
        for(int i = 0; i < m; i += len) {
            Point now = {1.0, 0.0};
            for(int k = i; k < i + (len >> 1); ++k) {
                Point temp = Mul(now, F[k + (len >> 1)]);
                F[k + (len >> 1)] = Minus(F[k], temp);
                F[k] = Plus(F[k], temp);
                now = Mul(now, base);
            }
        }
    }
}

int main() {
    n = read();
    for(int i = 1; i <= n; ++i) val[i] = read();
    LL mul = 1;
    for(int i = 0; i <= P - 2; ++i) {
        mapp[mul] = i;
        mul = mul * 2 % P;
    }
    for(int i = 1; i <= n; ++i)
        if(val[i]) ++f[mapp[val[i]]].x;
    while(m < 2 * P - 3) m <<= 1;
    // cout << m << endl;
    DFT(f, 0);
    for(int i = 0; i < m; ++i) f[i] = Mul(f[i], f[i]);
    DFT(f, 1);
    for(int i = 0; i < m; ++i) g[i] = f[i].x * 1.0 / m + 0.5;
    LL ans = 0; mul = 1;
    for(int i = 1; i <= n; ++i) {
        if(val[i]) --g[mapp[val[i]] * 2];
    }
    for(int i = 0; i <= P - 2; ++i) {
        ans += mul * (g[i] + g[i + P - 1]) / 2;
        mul = mul * 2 % P;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23484
#B - 1 Dimensional World's Tale(ABC110)
N,M,X,Y=map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
if max(X,max(x))<min(Y,min(y)):
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> sum(N);
	for (auto i = 0; i < N - 1; ++i)
	{
		int A;
		cin >> A;
		--A;
		++sum[A];
	}

	for (auto i = 0; i < N; ++i)
	{
		cout << sum[i] << endl;
	}

	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    string S;
    cin >> S;
    cout << S.substr(0, 3) << endl;
    return 0;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000000
#define MOD 1000000001
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846
#define Q ll _; cin >> _; while(_--)
#define endl "\n"
#define cy cout << "Yes\n";
#define cn cout << "No\n";
#define flush fflush(stdout);

int main(){

    ll i,n,x;
    cin >> x >> n;
    map<ll,ll> mp;
    for(i=1;i<=n;i++){
        ll a1;
        cin >> a1;
        mp[a1]++;
    }

    if(!n){
        cout << x << endl;
        return 0;
    }

    i = x;
    ll diff;
    ll ans;
    while(1){
        if(!mp[i]){
            diff = abs(i-x);
            ans = i;
            break;
        }
        else{
            i++;
        }
    }
    i = x;
    ll diff1;
    ll ans1;
    while(1){
        if(!mp[i]){
            diff1 = abs(i-x);
            ans1 = i;
            break;
        }
        else{
            i--;
        }
    }

    if(diff>=diff1){
        cout << ans1 << endl;
    }
    else{
        cout << ans << endl;
    }


}

//    cout << fixed << setprecision(12);


Measured memory_bytes: 3636