akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main{
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int K=sc.nextInt();
		String S=sc.next();
		if (S.length()<=K) {
			System.out.println(S);
		} else {
			System.out.println(S.substring(0,K)+"...");
		}
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 36200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cctype>
#define rg register
#define int long long 
using namespace std;
inline int read(){
	rg int s=0,f=0;
	rg char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
	while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return f?-s:s;
}
int n,ans;
const int MAX=100015;
int b[MAX]; 
signed main(){
	n=read();
	for(rg int i=1;i<n;i=-~i) b[i]=read();
	for(rg int i=1;i<n;i=-~i) ans+=min(b[i],b[i+1]);
	ans+=b[n-1]+b[1];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s,t = input().split()
ans = "".join(item[0]+item[1] for item in  zip(s,t))
print(ans)

Measured memory_bytes: 61916
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

int main() {

	ll n;
	cin >> n;

	vector<ll> a(n);
	vector<ll> mr(n);

	ll A1 = 0;
	ll A2 = 0;

	rep(i, n) {
		cin >> a[i];
		A1 += a[i];
		if (i % 2 == 1)A2 += a[i];
	}
	mr[0] = A1 - A2 * 2;
	rep(i, n) {

		if (i > 0) {
			mr[i] = 2 * a[i - 1] - mr[i - 1];
		}
	
		if (i != n - 1)cout << mr[i] << " ";
		else cout << mr[i] << endl;
	
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; i++)
    cin >> X[i];
  sort(X.begin(), X.end());
  vector<int> diff(M);
  for (int i = 1; i < M; i++)
    diff[i] = X[i] - X[i - 1];
  sort(diff.begin(), diff.end(), greater<int>());
  int ans = 0;
  for (int i = N - 1; i < M; i++)
    ans += diff[i];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=1e4+5;
bool v[N];
int a[N],b[N],n,g;

bool check(int p){
	if(a[0]%p) return 0;
	for(int i=0;i<p-1;i++) b[i]=0;
	for(int i=0;i<=n;i++) b[i%(p-1)]=(b[i%(p-1)]+a[i])%p;
	for(int i=0;i<p-1;i++) if(b[i]) return 0;
	return 1;
}

signed main(){
	read(n);
	for(int i=n;~i;i--) read(a[i]),g=__gcd(g,abs(a[i]));
	for(int i=2;i<=n;i++) if(!v[i]){
		if(check(i)) write(i),puts("");
		for(int j=i+i;j<=n;j+=i) v[j]=1;
	}
	for(int i=2;i*i<=g;i++) if(g%i==0){
		while(g%i==0) g/=i;
		if(i>n) write(i),puts("");
	}
	if(g>n) write(g);
}


Measured memory_bytes: 3728
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] list = reader.readLine().split(" ");
        int[] l = new int[3];
        int t = 0;
        for(String p:list){
        	l[t] = Integer.parseInt(p);
        	t++;
            }
        Arrays.sort(l);
        if(l[0]==5 && l[1]==5 && l[2]==7){
        System.out.println("YES");
        }
        else {
        System.out.println("NO");}}}
        

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 ll INF=1e18;

int main(){
    string s;
    cin>>s;
    set<char> st;
    int n=s.size();
    rep(i,n)st.insert(s[i]);
    if(st.size()==n)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

// エイリアス
using ll = long long;
using P = pair<int, int>;

// 素集合データ構造
struct UnionFind {
  vector<int> par, sizes; // par:あるデータの親, sizes:あるデータが属する木のサイズ

  // コンストラクタ
  // データ一つ一つを木とし、親は自分自身に初期化する
  UnionFind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  // データxが属する木の根ノードを取得
  // 再帰的に根を調べる際に、調べた辺を根に直接繋ぎ直すことで効率化している（経路圧縮）
  int find(int x) {
    return (x == par[x] ? x : par[x] = find(par[x]));
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // それぞれのデータの根ノードを取得
    x = find(x);
    y = find(y);

    // x, yが同じ木に属するならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるようにマージする
    par[y] = x;
    sizes[x] += sizes[y];
  }

  // 2つのデータx, yが同じ木に属するかどうか
  bool same(int x, int y) {
    return (find(x) == find(y));
  }

  // データxの属する木のサイズを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

int main() {
  // 入力
  int N, M;
  cin >> N >> M;
  int a[M], b[M];
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    UnionFind uf(N);
    for (int j = 0; j < M; j++) {
      if (i == j) continue;
      uf.unite(a[j], b[j]);
    }
    if (!uf.same(a[i], b[i])) ans++;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] predict = Console.ReadLine().ToCharArray();
            char[] actual = Console.ReadLine().ToCharArray();
            int count = 0;
            for (int i = 0; i < 3; i++)
            {
                if (predict[i] == actual[i]) count++;
            }
            Console.WriteLine(count.ToString());
//            Console.Read();
        }
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int area = a*b;
int length = 2*a + 2*b;
System.out.println(area + " " + length);
sc.close();
}
}


Measured memory_bytes: 26232
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
int n,m;
int mei[21][21];


int main(){

    cin>>n>>m;

    rep(i,n){
        rep(j,m){
            char a;
            cin>>a;
            if(a=='#'){
                mei[i][j]=0;
            }else {
                mei[i][j] = 1;
            }
        }
    }


    int v[n][m];
    rep(i,n){
        rep(j,m)v[i][j]=0;
    }

    ll ans = 0;
    rep(i,n){
        rep(j,m){
            if(mei[i][j]==1) {
                //vector<vector<bool>> al(n, vector<bool>(m, false));
                bool al[n][m];
                rep(nn,n)rep(mm,m)al[nn][mm]=false;

                al[i][j] = true;
                queue<pair<int, int>> q;
                q.push({i, j});
                ll deep = 0;
                while (!q.empty()) {
                    deep++;
                    int qsize = q.size();


                    rep(ii, qsize) {
                        auto x = q.front();
                        q.pop();
//                        if(i==2&&j==0){
//                            cout<<"t"<<endl;
//                            cout<<x.first<<x.second<<endl;
//                        }
                        for (int k = 0; k < 4; k++) {
                            int yy = x.first + dy[k];
                            int xx = x.second + dx[k];
                                if (xx >= 0 && xx< m && yy >= 0 && yy < n) {
                                    if(!al[yy][xx]&& mei[yy][xx] == 1){

//                                        if(i==2&&j==0){
//                                            cout<<yy<<" "<<xx<<endl;
//                                            cout<<al[yy][xx]<<endl;
//                                        }
                                    al[yy][xx] = true;
                                    q.push({yy, xx});
                                    }

                            }

                        }
                    }

                }

                deep--;
                ans = max(ans, deep);
            }
        }
    }
    cout<<ans<<endl;





    
return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var vi = Console.ReadLine().Split(' ');
            var ci = Console.ReadLine().Split(' ');

            int result = 0;
            for (int i = 0; i < N; i++)
            {
                var tmp = int.Parse(vi[i]) - int.Parse(ci[i]);
                if (tmp > 0)
                {
                    result += tmp;
                }
            }

            Console.Write(result);

        }
    }

    //var N = int.Parse(Console.ReadLine());
    //var S = Console.ReadLine();
    //var K = Console.ReadLine().Split(' ');
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
double min(double a,double b){
  if(a<b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int sum_keta(int n){
  if(n==0) return 0;
  return n%10 + sum_keta(n/10);
}
int main(void){
  int a,b; cin >> a >> b;
  
  cout << ((b-a)*(b-a+1))/2 - b << endl;
}

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

const int A=1e9+7;
int main(){
  int N;
  cin >> N;
  ll ans = 1;
  for(int i= 1; i<=N; i++){
    ans *= i;
    if(ans>=A){
      ans %= A;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define int int_fast32_t
#define uint uint_fast64_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define int16 int_fast16_t
#define uint16 uint_fast16_t
#define int32 int_fast32_t
#define uint32 uint_fast32_t
#define int64 int_fast64_t
#define uint64 uint_fast64_t
#define ld long double
#define float long double
#define size(x) (int)x.size()
#define satori int testCases; cin>>testCases; while(testCases--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(r) begin(r),end(r)
#define rall(r) rbegin(r),rend(r)
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#define elapsed(__begin,__end) (__end-__begin)/CLOCKS_PER_SEC
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
float pi=3.14159265358979323846;

const int MAXN=2e5+10;

int a[MAXN];

int32_t main()
{
	fastio;
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		cin>>a[i];
	for(int i=k+1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]>a[i-k])
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}

Measured memory_bytes: 5200
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tarinai = 0
amari = 0

D = [0 for i in range(N)]
for i in range(N):
    D[i] = A[i] - B[i]
    if D[i] < 0:
        tarinai += -1 * D[i]
    elif D[i] > 0:
        amari += D[i]
if amari < tarinai:
    print(-1)
else:
    D = sorted(D)
    left = 0
    right = N - 1
    count = 0
    while True:
        if D[left] >= 0:
            break
        if D[right] == -1 * D[left]:
            left += 1
            right -= 1
            count += 2
        elif D[right] > - 1 * D[left]:
            D[right] -= -1 * D[left]
            left += 1
            count += 1
            if D[left] >= 0:
                count += 1
        else:
            D[left] += D[right]
            right -= 1
            count += 1
    print(count)


Measured memory_bytes: 18420
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N];
set < int > st;
map < int, int > cnt;
int main (){
  scanf ("%d", &n);
  forn (i, 1, n) scanf ("%d", a + i), cnt[a[i]]++, st.insert(a[i]);
  vector < int > v;
  int x = -1, y = -1;
  for (auto i : st) v.push_back(i);
  reverse (v.begin(), v.end());
  forn (i, 0, (int)v.size() - 1){
    if (cnt[v[i]] >= 2){
      if (cnt[v[i]] >= 4){
        if (x == -1 && y == -1){
          x = v[i], y = v[i];
          break;
        }
      }
      if (x == -1){
        x = v[i];
      } else {
        y = v[i];
        break;
      }
    }
  }
  //printf ("%d %d\n", x, y);
  if (x == -1 && y == -1) return printf ("0\n"), 0;
  ll ans = x * 1ll * y;
  printf ("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 10624
//===================================================================
// Contents    : AOJ ITP1_3_D
//               3つの整数 a、b、c を読み込む。
//               a から b までの整数の中に、c の約数がいくつあるかを求める
// Constraints : 1 ≤ a , b , c ≤ 10000
// Author      : 廣部智也
// LastUpdate  :
// Since       : 2020/05/23
//===================================================================

#include <stdio.h>

int main(){
    
    int a  = 0, b = 0, c = 0, i = 0, count = 0;
    
    // データの入力
    scanf("%d %d %d",&a ,&b ,&c );
    
    if( a < 1 || a > 10000 || b < 1 || b > 10000 || c < 1 || c > 10000 ){
        return 0;
    }
    
    // データの処理：a から b の値で、c を割り切れるか調べていく
    for( i = a ; i <= b ; i++ ){
        
        if( i > c ){                    // c < a や c < b のときは、ループの途中で抜ける
            break;
        }

        if( c % i == 0 ){
            count++;
        }
        
    }
    
    // データの入力
    printf("%d\n", count );
    
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    ll a[3][3];
    ll b[3][3]={0};
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) cin>>a[i][j];
    }
    ll n;
    cin>>n;
    ll c[n];
    for(int i=0;i<n;i++) cin>>c[i];
    for(int k=0;k<n;k++){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(a[i][j]==c[k]) b[i][j] = 1;
        }
    }
    }
    if(b[0][0]==1 && b[1][1]==1 && b[2][2]==1) cout<<"Yes";
    else if(b[0][0]==1 && b[0][1]==1 && b[0][2]==1) cout<<"Yes";
    else if(b[1][0]==1 && b[1][1]==1 && b[1][2]==1) cout<<"Yes";
    else if(b[2][0]==1 && b[2][1]==1 && b[2][2]==1) cout<<"Yes";
    else if(b[0][0]==1 && b[1][0]==1 && b[2][0]==1) cout<<"Yes";
    else if(b[0][1]==1 && b[1][1]==1 && b[2][1]==1) cout<<"Yes";
    else if(b[0][2]==1 && b[1][2]==1 && b[2][2]==1) cout<<"Yes";
    else if(b[0][2]==1 && b[1][1]==1 && b[2][0]==1) cout<<"Yes";    
    else cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #     
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     //   freopen("output.txt", "w", stdout);
    //     //  freopen("error.txt", "w", stderr);
    // #endif
    int n;
    cin >> n;
    vi a(n);
    rep(i, 0, n)
            cin >>
        a[i];
    sort(all(a), greater<int>());
    int s = a[0];
    int cnt = 2;
    rep(i, 1, n - 1)
    {
        if (cnt == n)
            break;
        s += a[i];
        cnt++;
        if (cnt == n)
            break;
        s += a[i];
        cnt++;
    }

    cout << s << endl;
}

Measured memory_bytes: 4716
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int power10[200001], sp[200001];
struct node {
	int tag, num;
}nd[800001];
void pushdown(int p, int l, int r) {
	if (!nd[p].tag) return;
	int mid = (l + r) / 2;
	nd[p*2].tag = nd[p*2+1].tag = nd[p].tag;
	nd[p*2].num = 1ll*nd[p].tag*sp[mid-l]%mod;
	nd[p*2+1].num = 1ll*nd[p].tag*sp[r-mid-1]%mod;
	nd[p].tag = 0;
}
void modify(int p, int l, int r, int l0, int r0, int num) {
	if (l >= l0 && r <= r0) {
		nd[p].tag = num, nd[p].num = 1ll*num*sp[r-l]%mod;
		return;
	}
	pushdown(p, l, r);
	int mid = (l + r) / 2;
	if (l0 <= mid) modify(p * 2, l, mid, l0, r0, num);
	if (r0 > mid) modify(p * 2 + 1, mid + 1, r, l0, r0, num);
	nd[p].num = (1ll*nd[p*2].num*power10[r-mid]+nd[p*2+1].num)%mod;
}
int main() {
	int n, q;
	cin >> n >> q;
	power10[0] = sp[0] = 1;
	for (int i = 1; i <= n; i++) power10[i] = power10[i-1]*10ll%mod, sp[i] = (sp[i-1]+power10[i]) % mod;
	modify(1, 1, n, 1, n, 1);
	for (int i = 1; i <= q; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		modify(1, 1, n, l, r, d);
		cout << nd[1].num << endl;
	}
}

Measured memory_bytes: 9268
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

const double inf = 1e5;

int n;
double r, t;
int x[20];
int y[20];
double dist[20][20];
bool arg[20][20][20];
double dp[10000][20][20];
double cost[10000];

void make_dist(){
    rep(i, n){
        rep(j, n){
            int a = x[i] - x[j];
            int b = y[i] - y[j];
            dist[i][j] = sqrt(a * a + b * b);
        }
    }
}

double cos_bet(int i, int j, int k){
    int a = x[j] - x[i];
    int b = y[j] - y[i];
    int c = x[k] - x[j];
    int d = y[k] - y[j];
    return (a * c + b * d) / dist[i][j] / dist[j][k];
}

void make_arg(){
    double ct = cos(t / 180 * M_PI);
    rep(i, n){
        rep(j, n){
            rep(k, n){
                if(i != j && j != k){
                    arg[i][j][k] = (cos_bet(i, j, k) >= ct);
                }
            }
        }
    }
}

int main(){
    cin >> n >> r >> t;
    rep(i, n){
        cin >> x[i] >> y[i];
    }

    make_dist();
    make_arg();

    rep(i, 10000){
        rep(j, n){
            fill_n(dp[i][j], n, inf);
        }
    }
    for(int i = 1; i < n; ++i){
        dp[1][0][i] = dist[0][i];
    }
    for(int i = 2; i < 10000; ++i){
        rep(j, n){
            rep(k, n){
                rep(p, n){
                    if(arg[p][j][k]){
                        dp[i][j][k] = min(dp[i - 1][p][j] + dist[j][k], dp[i][j][k]);
                    }
                }
            }
        }
    }

    for(int i = 1; i < 10000; ++i){
        cost[i] = inf;
        rep(j, n){
            rep(k, n){
                cost[i] = min(dp[i][j][k], cost[i]);
            }
        }
    }

    cout << upper_bound(cost, cost + 10000, r) - cost - 1 << endl;
    return 0;
}

Measured memory_bytes: 34776
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

A, B, K = map(int, input().split())
s = set()
for v in range(A, min(B + 1, A + K)):
    s.add(v)
for v in range(max(A, B - K + 1), B + 1):
    s.add(v)
for v in sorted(s):
    print(v)


Measured memory_bytes: 7624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define INF 0x3f3f3f3f
#define N 100007


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,m,i,j,a,b,ans=0;
    cin>>n>>m;

    vector<int> ht(n),max_ht(n);
    vector< vector<int> >v(n);

    for(i=0 ; i<n ; i++)cin>>ht[i];

    for(i=0 ; i<m ; i++)
    {
        cin>>a>>b;
        a--;b--;

        v[a].push_back(b);
        v[b].push_back(a);
        max_ht[a] = max(max_ht[a],ht[b]);
        max_ht[b] = max(max_ht[b],ht[a]);
    }

    for(i=0 ; i<n ; i++)
    {
        if(v[i].size()==0 || ht[i]>max_ht[i])ans++;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 9216
package main

import (
	"fmt"
	"sort"
)

func main() {
	n := make([]int, 4)
	fmt.Scan(&n[0], &n[1], &n[2], &n[3])
	sort.Ints(n)
	if n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

int lcm(int a, int b)
{
   return a / gcd(a, b) * b;
}

int main(){
  int K;
  cin >> K;
  int ans=0;
  FOR(i,1,K+1)FOR(j,1,K+1)FOR(k,1,K+1){
    ans += gcd(i,gcd(j,k));
  }
  cout << ans << endl;

}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
ll a[52],b[52],c[52],d[52];	ll n,m,q;
ll ans,ch[12];
void cal(){
	ll cnt=0;
	for(ll i=0;i<q;i++){
		if(ch[b[i]]-ch[a[i]]==c[i]){
			cnt+=d[i];
		}
	}
	ans=max(ans,cnt);
}
void dep(ll now,ll cnt){
	if(now==n){
		cal();
		return ;
	}
	for(ll i=cnt;i<=m;i++){
		ch[now]=i;
		dep(now+1,i);
	}
}
int main() {

	cin>>n>>m>>q;

	for(ll i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;b[i]--;
	}
	dep(0,1);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3532
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
    long a, b, k;
    cin >> a >> b >> k;

    if (a >= k) {
        cout << a-k << ' ' << b << endl;
    } else if (a+b >= k) {
        cout << 0 << ' ' << a+b-k << endl;
    } else {
        cout << "0 0" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, r;
    cin >> n >> r;

    if(n >= 10) cout << r << endl;
    else cout << r + 100 * (10-n) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> X;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  X.resize(N);
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    X[i] = tmp;
  }

  int ans = INF;
  for (int i = 1; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      sum += ((X[j] - i) * (X[j] - i));
    }
    ans = min(ans, sum);
  }

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


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

int main(){
	string s;
	cin >> s;
	map<string, int> mapi;
	mapi["SUN"] = 7;
	mapi["MON"] = 6;
	mapi["TUE"] = 5;
	mapi["WED"] = 4;
	mapi["THU"] = 3;
	mapi["FRI"] = 2;
	mapi["SAT"] = 1;
	cout << mapi[s] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N;

int main()
{
    cin >> N;
    vector<int> p(4), t(4);
    for (int i = 0; i < 4; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < 4; i++)
    {
        cin >> t[i];
    }

    int ans = inf;

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N; j++)
        {
            for (int k = 0; k <= N; k++)
            {
                for (int l = 0; l <= N; l++)
                {
                    if (t[0] * i + t[1] * j + t[2] * k + t[3] * l >= N)
                    {
                        ans = min(ans, p[0] * i + p[1] * j + p[2] * k + p[3] * l);
                    }
                }
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if ( A >= K ){
    cout << K << endl;
  }
  else if ( A < K && A + B >= K ){
    cout << A << endl;
  }
  else if ( A + B < K ){
    cout << 2*A + B - K << endl;
  }
}


Measured memory_bytes: 3640
inf = 10 ** 19    # 1,000,000,000,000,000,000

def main():
    a, b, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))

    ans = inf

    for _ in range(m):
        x, y, c = map(int,input().split())
        tmp = a_list[x-1] + b_list[y-1] - c
        ans = min(ans, tmp)

    a_min = min(a_list)
    b_min = min(b_list)
        
    ans = min(ans, a_min+b_min)

    print(ans)


if __name__ == '__main__':
    main()

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

typedef unsigned long long ull;

const ull INF = 2e18;

bool check(ull N, ull m, int k, int i) {
  ull tmp = 1;
  REP(j,i) {
    tmp *= m - 1;
    if(tmp >= N) return true;
  }
  REP(j,k + 1 - i) {
    tmp *= m;
    if(tmp >= N) return true;
  }
  return false;
}

int main(){
  ull N, A;
  cin >> N >> A;

  ull res = N;
  REP(k,40) {
    ull lb = 0, ub = N + 2;
    while(ub - lb > 1) {
      ull mid = (ub + lb) / 2;
      bool flag = false;
      for(int i = k; i >= 0; --i) {
        if(check(N, mid, k, i)) {
          ull time = A * k + mid * (k + 1 - i) + (mid - 1) * i;
          flag = true;
          res = min(res, time);
          break;
        }
      }
      if(flag) {
        ub = mid;
      }else{
        lb = mid;
      }
    }
  }

  cout << res << endl;
  return 0;
}



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

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int sum=0;
    for(int i=0; i<(int)s.size();i++){
        if(s[i]!=t[i]){
            sum++;
        }
    }
    cout << sum << endl;
}

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

#define MAX_N 1010

vector<int> G[MAX_N];
bool vis[MAX_N];
vector<int> ans;
int mn_len = 0x3f3f3f3f, start = -1;

void dfs(int x, set<int> &s, vector<int> &st, int len){
    if (len >= mn_len)
        return ;

    for (auto i: G[x]){
        if (!vis[i]){
            st.push_back(i);
            s.insert(i);
            vis[x] = true;
            dfs(i, s, st, len + 1);
            vis[x] = false;
            s.erase(i);
            st.pop_back();
        }
        else{
            for (int j = 0; j < len; j++){
                if (st[j] == i){
                    if (mn_len > len - j){
                        mn_len = len - j;
                        start = i;
                    }
                    break;
                }
            }
        }
    }
}

void get_ans(int x, int len, vector<int> &st){
    if ((int) ans.size() != 0)
        return ;
    if (len > mn_len)
        return ;

    for (auto i: G[x]){
        if (i == start && len == mn_len){
            for (auto j: st)
                ans.push_back(j);
            return ;
        }
        
        if (!vis[i]){
            st.push_back(i);
            vis[i] = true;
            get_ans(i, len + 1, st);
            vis[i] = false;
            st.pop_back();
        }

        if ((int) ans.size() != 0)
            return ;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
    }
    
    set<int> s;
    vector<int> st;
    for (int i = 0; i < n; i++){
        if (!vis[i]){
            st.push_back(i);
            s.insert(i);
            vis[i] = true;
            dfs(i, s, st, 1);
            vis[i] = false;
            s.erase(i);
            st.pop_back();
        }
    }

    if (mn_len == 0x3f3f3f3f)
        cout << -1 << '\n';
    else{
        memset(vis, false, sizeof(vis));
        vector<int> st;
        st.push_back(start);
        get_ans(start, 1, st);

        cout << mn_len << '\n';
        for (auto i: ans)
            cout << i + 1 << '\n';
    }

    return 0;
}


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

int main(){
  int H,W,K;
  cin >>H>>W>>K;
  char c[H][W];
  char d[H][W];
  string ch;
  for (int i = 0; i < H; i++)
  {
    cin >> ch;
    for (int j = 0; j < W; j++){
      c[i][j] =ch.at(j) ;
      }
  }
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++){
      d[i][j]=c[i][j];
      }
  }
  int s=0,t=0;
  for (int i = 0; i < (1<<(H+W)); i++)
  {
    
    for (int k = 0; k < H+W; k++)
    {
      if (i&(1<<k))
      {
        if (k < H)
        {
          for (int l = 0; l < W; l++)
          {
            d[k][l] = 'a';
          }
        }
        else
        {
          for (int l = 0; l < H; l++)
          {
            d[l][k-H] = 'a';
          }
        }
      }
    }
    
    for (int k = 0; k < H; k++)
    {
      for (int l = 0; l < W; l++)
      {
        if (d[k][l] == '#')s++;
      }
    }
    if (s==K) t++;
    for (int i = 0; i < H; i++)
    {
      for (int j = 0; j < W; j++){
        d[i][j] = c[i][j];
        }
    }
    s=0;
      
      
    
    
  }
  cout<<t;

}


Measured memory_bytes: 3588
S = input()
keyence = []
s = 'keyence'
List = []
flag = False

for i in range(len(s)):
    keyence.append([s[:i], s[i:]])

for i in range(len(s)):
    List.append([S[:i], S[-(len(s)-i):]])

for i in keyence:
    if i in List:
        flag = True
        break

print("YES" if flag else "NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main (){
    int n, m; cin >> n >> m;
    if(n == m){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)

#define MAX_N 1000

struct P {
	int index;
	int value;
	bool done;
	P(int i, int v) : index(i), value(v), done(false) {}
	P() : index(-1), value(-1), done(false) {}
};

bool compareP(P a, P b)
{
	return (a.value < b.value);
}

int A[MAX_N];
P S[MAX_N];
int D[MAX_N];

std::vector<std::vector<int> > Groups;

int main(void) {
	int n;
	scanf("%d", &n);
	int min = 10000;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
		S[i].index = i;
		S[i].value = A[i];
		if (min > A[i]) {
			min = A[i];
		}
	}
	std::sort(S, S+n, compareP);
	for (int i = 0; i < n; ++i) {
		D[S[i].index] = i;
	}
	for (int i = 0; i < n; ++i) {
		if (S[i].done == true) continue;
		if (S[i].index == i) {
			//printf("%d don't move\n", S[i].value);
			S[i].done = true;
			continue;
		}
		std::vector<int> group;
		//printf("start loop %d ", S[i].value);
		int idx = S[i].index;
		S[i].done = true;
		group.push_back(S[i].value);
		while (true) {
			if (S[idx].done) break;
			//printf("%d ", S[idx].value);
			group.push_back(S[idx].value);
			S[idx].done = true;
			idx = S[idx].index;
		}
		//printf("\n");
		Groups.push_back(group);
	}
	int totalCost = 0;
	for (size_t i = 0; i < Groups.size(); ++i) {
		std::sort(Groups[i].begin(), Groups[i].end());
		int gn = Groups[i].size();
		int cost1 = 0;
		int cost2 = 0;
		for (size_t j = 1; j < gn; ++j) {
			cost1 += Groups[i][j];
			cost1 += Groups[i][0];
			cost2 += Groups[i][j];
			cost2 += min;
		}
		cost2 += (min + Groups[i][0]) * 2;
		int cost = cost1 > cost2 ? cost2 : cost1;
		totalCost += cost;
	}
	printf("%d\n", totalCost);

	return 0;
}


Measured memory_bytes: 2808
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int A,B;
	cin >> A >> B;
	if((A+B)%2==0)cout << (A+B)/2 << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) B[i]=A[i];
  sort(all(A));
  rep(i,N){
    if(B[i]==A[N-1]) cout<<A[N-2]<<endl;
    else cout<<A[N-1]<<endl;
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define MAXN	300005
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct edge {int dest, type; };
int roota, rootb, ans[MAXN];
int tot, Queue[MAXN];
unsigned now[MAXN];
bool visited[MAXN], parity[MAXN];
vector <edge> a[MAXN];
void work(int pos) {
	for (unsigned &i = now[pos]; i < a[pos].size(); i++) {
		if (visited[a[pos][i].type]) continue;
		visited[a[pos][i].type] = true;
		work(a[pos][i].dest);
	}
	Queue[++tot] = pos;
}
void dfs(int pos, int fa) {
	parity[pos] = true;
	for (unsigned i = 0; i < a[pos].size(); i++)
		if (a[pos][i].dest != fa) {
			dfs(a[pos][i].dest, pos);
			parity[pos] ^= true;
		}
}
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		int x; read(x);
		if (x == -1) roota = i;
		else {
			a[x].push_back((edge) {i, i});
			a[i].push_back((edge) {x, i});
		}
	}
	for (int i = 1; i <= n; i++) {
		int x; read(x);
		if (x == -1) rootb = i + n;
		else {
			a[x + n].push_back((edge) {i + n, i + n});
			a[i + n].push_back((edge) {x + n, i + n});
		}
	}
	dfs(roota, 0); dfs(rootb, 0);
	for (int i = 1; i <= n; i++)
		if (parity[i] != parity[i + n]) {
			printf("IMPOSSIBLE\n");
			return 0;
		}
	printf("POSSIBLE\n");
	for (int i = 1; i <= n; i++)
		if (parity[i]) {
			a[i].push_back((edge) {i + n, i + 2 * n});
			a[i + n].push_back((edge) {i, i + 2 * n});
			
		}
	a[0].push_back((edge) {roota, 3 * n + 1});
	a[roota].push_back((edge) {0, 3 * n + 1});
	a[0].push_back((edge) {rootb, 3 * n + 2});
	a[rootb].push_back((edge) {0, 3 * n + 2});
	work(0);
	for (int i = 1; i < tot; i++) {
		if (Queue[i] + n == Queue[i + 1]) ans[Queue[i]] = 1;
		if (Queue[i + 1] + n == Queue[i]) ans[Queue[i + 1]] = -1;
	}
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 32756
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
    int x,y,z,z1;
    cin>>x>>y;
    z=4*x;
    z1=2*x;
     if(y>=z1&&y<=z&&y%2==0)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

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

int main(){

    int n;
    cin >> n;
    map<string,int> m;

    rep(i,n){
        string t;
        cin >> t;
        m[t]--;
    }

    vector<pair<int,string>> a(m.size());

    for(auto it=m.begin();it!=m.end();it++){
        a.push_back({it->second,it->first});
    }

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

    cout << a[0].second << endl;
    for(int i=1;i<a.size();i++){
        if(a[i].first==a[i-1].first){
            cout << a[i].second << endl;
        }else{
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 31432
using System;

namespace ConsoleApp1
{

    class Program
    {

        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            for (int i = 0; 1 < 200; i++)
                for (int j = -200; j < 200; j++)
                {
                    long calc = (long)(Math.Pow(i, 5) - Math.Pow(j, 5));
                    if (calc == x)
                    {
                        Console.WriteLine($"{i} {j}");
                        return;
                    }
                }

        }

    }
}



Measured memory_bytes: 27764
N = int(input())
MONSTER = list(map(int, input().split()))
HERO = list(map(int, input().split()))

count = 0

for i in range(N):
    battle = min(HERO[i], MONSTER[i])
    count += battle
    HERO[i] -= battle
    MONSTER[i] -= battle

    if HERO[i] > 0:
        battle = min(HERO[i], MONSTER[i+1])
        count += battle
        HERO[i] -= battle
        MONSTER[i+1] -= battle


print(count)


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

signed main() {
	int r, d, x;
	
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int MOD=MOD2;



int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
            int n;
            cin>>n;
            n%=10;
            if(n==2 || n==4 || n==5 || n==7 || n==9)cout<<"hon"<<endl;
            else if(n==3)cout<<"bon"<<endl;
            else cout<<"pon"<<endl;

      } 
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
const ll INF=1e10+1;
using namespace std;

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

ll N;
vector<bool> used;
vector<vector<pair<ll,ll> > > node;
//vector<vector<ll> > l;
vector<bool> color;

void dfs(ll id,ll value);

int main(){
	cin >> N;
	used = vector<bool>(N+1,false);
	node = vector<vector<pair<ll,ll> > >(N+1);
	//l = vector<vector<ll> >(N+1,vector<ll>(N+1,INF));
	color = vector<bool>(N+1, 0);

	for(ll i=0;i<N-1;i++){
		ll u,v,w;
		cin >> u >> v >> w;
		node[u].pb({v,w});
		node[v].pb({u,w});
	}

	color[1] = 1;
	dfs(1,0);

	for(ll i=1;i<=N;i++){
		cout << color[i] << endl;
		//if(color[i]) putchar('1');
		//else putchar('0');
		//putchar('\n');
	}
}

void dfs(ll id,ll value)
{
	used[id]=true;
	for(ll key=0;key<node[id].size();key++)
	{	
		ll nxnode = node[id][key].first;
		if(used[nxnode]) continue;

		ll nxvalue = value + node[id][key].second;
		if(used[nxnode]==false){
			if(nxvalue % 2 == 0){
				color[nxnode] = 1;
			}
			dfs(nxnode,nxvalue);
		}
	}
}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i < n; ++i){
        cin >> a[i];
    }
    long long ans = max(0, a[0]-x);
    a[0] -= max(0, a[0]-x);
    for(int i = 1; i < n; ++i){
        ans += max(0, a[i]+a[i-1]-x);
        a[i] -= max(0,a[i]+a[i-1]-x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3736