akhauriyash/Code-Regression huggingface dataset:
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native") // Auto-Vectorisation

#include "bits/stdc++.h"
#include "chrono"
#include "random"
using namespace std;

/*
//large integers
#include <boost/multiprecision/cpp_int.hpp>
__int128 s128; // pollard rho
__uint128_t u128;

//policy based data structures
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace boost::multiprecision; 
using namespace __gnu_pbds;
*/

typedef long long int ll;
typedef long double ld;
typedef double db;
typedef pair<ll,ll> pll;
typedef unsigned long long u64;
typedef vector<ll> vl;
typedef vector<pll> vpl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef unordered_set<ll> usl;
typedef set<ll> sl;
typedef multiset<ll> mul;
typedef unordered_map<ll,ll> umll;
typedef map<ll,ll> mll;

#define int long long int
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define tc(x) ll x; cin>>x; while(x--)
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define print(a)  for (auto x : a) cout << x << " "; cout << endl
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(a) a.begin(),a.end()
#define Sort(x) sort(all((x)))
#define setbits(a) __builtin_popcountll(a)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define hell cout<<"hello"<<'\n'
#define deb(x) cerr<<#x<<" = "<<x<<'\n'
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(all(v), rng);

const string alpha   =   "zabcdefghijklmnopqrstuvwxyz";
const ld PI          =   ld(3.14159265359);
const ll P           =   1e9 + 7; // 998244353; // 1e9 + 9 // 7340033 // 4294967296;
const ll Q           =   1e9 + 6; // 998244352; // 1e9 + 8 // 7340032;
const ll ninf        =   LONG_MIN;
const ll inf         =   8e18;
const ll M           =   2e3 + 5;
const ll N           =   2e5 + 5;

void solve(){
    ll n,k,sum=0;
    cin>>n>>k;
    vl a(n);
    f(i,0,n) cin>>a[i];
    Sort(a);
    f(i,0,k) sum+=a[i];
    cout<<sum;
}
signed main(){
    teevra_gati

    solve();

    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

int N, A, B, C, D;
string S;

int main(){
    cin >> N >> A >> B >> C >> D;
    A--; B--; C--; D--;
    cin >> S;

    bool ok = true;
    for(int i = A; i + 1 <= C; i++){
        if(S[i] == '#' && S[i + 1] == '#'){
            ok = false;
        }
    }
    for(int i = B; i + 1 <= D; i++){
        if(S[i] == '#' && S[i + 1] == '#'){
            ok = false;
        }
    }

    if(D < C){
        bool can_jump_over = false;
        for(int i = B - 1; i + 1 <= D && i + 2 <= C; i++){
            if(S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.'){
                can_jump_over = true;
            }
        }
        if(!can_jump_over){
            ok = false;
        }
    }
    cout << (ok?"Yes":"No") << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <limits.h>
int FindMaxCrossingSubarray(int A[], int low, int mid, int high);
int FindMaximumSubarray(int A[], int low, int high);
int main(){
  int n;
  int i, j;
  scanf("%d", &n);
  int N[n];
  int R[n-1];
  int max=INT_MIN;
  int tmp;
  for(i=0; i<n; ++i){
	scanf("%d", &N[i]);
  }
  for(i=0; i<(n-1); ++i){
	R[i]=N[i+1]-N[i];
  }
  //sort
 int min=N[0];
  for(i=1; i<n; ++i){
	tmp=N[i]-min;
	if(tmp>max)
	  max=tmp;
	if(min>N[i])
	  min=N[i];
  }
  //

  /* for(i=0; i<(n-1); ++i){ */
  /* 	printf("%d ", R[i]); */
  /* } */
  /* printf("\n"); */
  printf("%d\n", max);
  return 0;
}

int FindMaxCrossingSubarray(int A[], int low, int mid, int high){
  int sum=0;
  int leftsum=INT_MIN, rightsum=INT_MIN;
  int i;
  for(i=mid; i>=low; --i){
	sum+=A[i];
	if(sum>leftsum)
	  leftsum=sum;
  }
  sum=0;
  for(i=(mid+1); i<=high; ++i){
	sum+=A[i];
	if(sum>rightsum)
	  rightsum=sum;
  }
  return (leftsum+rightsum);
}
int FindMaximumSubarray(int A[], int low, int high){
  if(low==high)  
	return A[low];
  else{
	int mid;
	mid=(low+high)/2;
	int leftsum, rightsum, crosssum;
	leftsum=FindMaximumSubarray(A, low, mid);
	rightsum=FindMaximumSubarray(A, mid+1, high);
	crosssum=FindMaxCrossingSubarray(A, low, mid, high);
	if((leftsum>=rightsum)&&(leftsum>=crosssum))
	  return leftsum;
	else if((rightsum>=leftsum)&&(rightsum>=crosssum))
	  return rightsum;
	else
	  return crosssum;
  }
}



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

const int maxl = 1e6 + 10;
uint64_t r[maxl][26];

int main() {
  srand(time(NULL));

  for (int i = 0; i < maxl; ++i) {
    for (int j = 0; j < 26; ++j) {
      r[i][j] = rand();
      r[i][j] = (r[i][j] << 25) ^ rand();
      r[i][j] = (r[i][j] << 25) ^ rand();
    }
  }

  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), [](string& a, string &b) {
    return a.size() < b.size();
  });

  unordered_map<uint64_t, int> m;
  int64_t ans = 0;
  for (string& s : a) {
    vector<int> v(s.size());
    for (int i = 0; i < s.size(); ++i) {
      v[i] = 1 << (s[i] - 'a');
      if (i) v[i] |= v[i - 1];
    }
    if (m.count(0)) {
      int tmp = m[0] & v.back();
      ans += __builtin_popcount(tmp);
    }

    uint64_t h = 0;
    for (int i = int(s.size()) - 1, j = 0; i >= 1; --i, ++j) {
      h ^= r[j][s[i] - 'a'];
      if (m.count(h)) {
        int tmp = m[h] & v[i - 1];
        ans += __builtin_popcount(tmp);
      }
    }
    m[h] |= v[0];
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 219580
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
    input_lines = line.split(" ")
});

reader.on('close', () => {
  var c = input_lines[0]*input_lines[1];
  if(c % 2 === 0) console.log("Even");
  else console.log("Odd");
});

Measured memory_bytes: 30108
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    a = LI()
    X = [(i+1, x) for (i, x) in enumerate(a)]
    X = sorted(X, key=lambda x: x[1])
    ans = " ".join([str(x[0]) for x in X])
    print(ans)
main()



Measured memory_bytes: 27096
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
total = []
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  score = 0
  for a,b,c,d in abcd:
    if A[b-1]-A[a-1] == c:
      score += d
    total.append(score)
print(max(total))


Measured memory_bytes: 74164
#include <iostream>

using namespace std;
int n,x,y,r,p;
int main()
{
    cin>>n;
    x=n;
    y=2;
    r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    p=n*2/y;
    cout<<p<<'\n';
    return 0;
}


Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int a, b;

    for(;sc.hasNext();){
      a = sc.nextInt();
      b = sc.nextInt();
      System.out.println(a + b);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20388
input = gets.split(" ")
w = input[0].to_i
h = input[1].to_i
x = input[2].to_i
y = input[3].to_i
r = input[4].to_i
if x+r<=w && x-r>=0 && y+r<=h && y-r>=0
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 8688
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)(N);i++)
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define p(s) cout<<(s)<<endl
#define F first
#define S second
typedef long long ll;
using namespace std;

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

int H, W, C, P[10][10];
int tans = 0, ans = 0;

bool flag[10][10], visited[10][10];

void drow(int y, int x, int col){
	int precol = P[y][x];
	P[y][x] = col;

	visited[y][x] = true;

	REP(k,0,4){
		int ny = y + dy[k], nx = x + dx[k];
		if(!ck(ny,0,H) || !ck(nx,0,W)) continue;
		if(P[ny][nx] == precol && !visited[ny][nx]){
			drow(ny, nx, col);
		}
	}
	return;
}

void cnt(int y, int x, int col){
	if(P[y][x] != col) return;
	tans++;
	visited[y][x] = true;
	REP(k,0,4){
		int ny = y + dy[k], nx = x + dx[k];
		if(!ck(ny,0,H) || !ck(nx,0,W)) continue;
		if(P[ny][nx] == col && !visited[ny][nx]){
			//p('e');
			cnt(ny, nx, col);
		}
	}
	return;
}

void dfs(int step, int col){

	if(step == 5){
		tans = 0;
		REP(i,0,H)REP(j,0,W) visited[i][j] = false;
		cnt(0,0,C);
		ans = max(ans, tans);
		return;
	}

	REP(i,1,7){
		//?????¶???????????£????????????
		int cp[10][10];
		REP(k,0,H)REP(l,0,W){
			cp[k][l] = P[k][l];
		}
		REP(k,0,H) REP(l,0,W) visited[k][l] = false;
		drow(0,0,i);
		dfs(step+1, i);
		//????????????
		REP(k,0,H)REP(l,0,W){
			P[k][l] = cp[k][l];
		}
	}
	return;
}

int main() {
	while(1){
		cin>>H>>W>>C;
		if(H==0) break;
		REP(i,0,H){
			REP(j,0,W){
				cin>>P[i][j];
			}
		}
		ans = 0;
		dfs(0,C);
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(int argc, char** argv)
{
	long long a, b, c;
	scanf("%lld%lld.%lld", &a, &b, &c);
	printf("%lld\n", (b * 100LL + c) * a / 100LL);
	return 0;
}

Measured memory_bytes: 1732
s = input()
d = s[:2]
y = s[2:]
if((int(d)>12 or int(d)==0) and (int(y)==0 or int(y)>12)):
    print('NA')
elif(0<int(d)<=12 and 0<int(y)<=12):
    print('AMBIGUOUS')
elif(0<int(d)<=12):
    print('MMYY')
elif(0<int(y)<=12):
    print('YYMM')


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	
#include<functional>
#include<climits>

using namespace std;

namespace MyLib {

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000007;
const int INF = INT_MAX / 3-1;
const double EPS = 1e-9;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

}

using namespace MyLib;



int main() {
	int e;
	while (cin >> e, e) {
		auto ans = tuple<int, int, int>(INF, INF, INF);
		for (int z = 0;z*z*z <= e;z++) 
			for (int y = 0; y*y + z*z*z <= e; y++) {
				int x = e - z*z*z - y*y;
				if (x + y + z < get<0>(ans) + get<1>(ans) + get<2>(ans))
					ans = make_tuple(x, y, z);
				
			}
		cout << get<0>(ans) + get<1>(ans) + get<2>(ans) << endl;

	}

	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
int main() {
	int a, b; std::cin >> a >> b;
  	for (int c = 1; c <= 3; ++c) {
    	if (a * b * c % 2 == 1) {
        	std::cout << "Yes"; return 0;
        }
    }
  	std::cout << "No"; return 0;
}

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

typedef long long LL;

const int N=200000;

char s[N+9];
int n;

void into(){
  scanf("%s",s+1);
  n=strlen(s+1);
}

int pre[N+9],suf[N+9];
LL ans;

void Get_ans(){
  int cnt=0;
  for (int i=1;i<=n;++i) pre[i]=pre[i-1]+(s[i]=='0');
  for (int i=n;i>=1;--i) suf[i]=suf[i+1]+(s[i]=='0');
  int flag=1;
  for (int i=1;i<=n;++i)
	if (s[i]=='1'){
	  ans+=(pre[i]+1+(i&1)>>1)+(flag?suf[i]:0);
	  flag^=1;
	}else flag=1;
  for (int i=1;i<n-pre[n];++i) ans+=n-pre[n]-i+1>>1;
}

void work(){
  Get_ans();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  int c=min(a,b),d=max(a,b);
  int e;
  for(int i=0;i<=d-1;i++){
    e+=c*pow(10,i);
  }
  cout << e <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
typedef pair <lli,lli> pll;
 
 
lli countGreater(lli arr[], lli n, lli k) 
{ 
    lli l = 0; 
    lli r = n - 1; 
  
    lli leftGreater = n; 
  
    while (l <= r) { 
        lli m = l + (r - l) / 2; 
  

        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 

        else
            l = m + 1; 
    } 
  
    return (n - leftGreater); 
}
 
bool is_palin(string input)
{
    if (input == string(input.rbegin(), input.rend())) 
        return true;
    return false;
}
void solve()
{
    lli n;
    cin>>n;
    lli ha = (n/500)*1000;
    n = n%500;
    ha+= (n/5)*5;
    cout<<ha;
}
 
int main()
{
    kira; 
 
    lli t=1; //cin>>t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {

	int a[3], b[3], dob[4] = {}, num = 0;

	for (int k = 0; k < 3; k++) {
		cin >> a[k] >> b[k];
		a[k]--;
		b[k]--;
		for (int l = 0; l < 4; l++) {
			if (a[k] == l)dob[l]++;
			if (b[k] == l)dob[l]++;
		}
	}

	for (int l = 0; l < 4; l++) {
		if (dob[l] == 2)num++;
	}

	if (num>=2)cout << "YES\n";
	else cout << "NO\n";



	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long C = scan.nextLong();
        long K = scan.nextLong();
        long[] l = new long[N];
        for (int i = 0; i < N; i++) {
            l[i] = scan.nextLong();
        }
        Arrays.sort(l);
        long[] r = new long[N];
        for (int i = 0; i < N; i++) {
            r[i] = l[i] + K;
        }
        int answer = 0;
        long current = Long.MAX_VALUE;
        long number_of_people = 0;
        for (int i = N-1; 0 <= i; i--) {
            if (number_of_people == C) {
                answer += 1;
                number_of_people = 0;
                current = l[i];
            }
            if (r[i] < current) {
                answer += (number_of_people + (C-1))/C;
                number_of_people = 1;
                current = l[i];
                continue;
            }
            number_of_people += 1;
        }
        answer += (number_of_people + (C - 1)) / C;
        System.out.println(answer);
    }
}


Measured memory_bytes: 50180
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int head = s.length() - 1;
    int tail = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) == 'A') {
        head = i;
        break;
      }
    }
    for (int i = s.length()-1; i >= 0; i--) {
      if (s.charAt(i) == 'Z') {
        tail = i;
        break;
      }
    }
    System.out.println(tail-head+1);
  }
}

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

int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int sum = a1 + a2 + a3;
    if(sum >= 22){
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <tuple>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <tuple>

using namespace std;

#define endl '\n'

using ull = unsigned long int;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  const int precision = 13;
  cout.precision(precision);
  cout.setf(ios_base::fixed);

  int n; cin >> n;
  vector<vector<int>> dp(2, vector<int>(3, 0));

  for (int i = 1; i <= n; ++i) {
    int a, b, c; cin >> a >> b >> c;
    int cur = i%2;
    int prev = (i-1)%2;
    dp[cur][0] = a + max(dp[prev][1], dp[prev][2]);
    dp[cur][1] = b + max(dp[prev][0], dp[prev][2]);
    dp[cur][2] = c + max(dp[prev][0], dp[prev][1]);
  }

  cout << *max_element(dp[n%2].begin(), dp[n%2].end()) << endl;


  return 0;
}


Measured memory_bytes: 256
let () =
  let values = Array.init 101 (fun x -> 0) in
  let rec read () =
    try let n = read_int () in
        values.(n) <- values.(n)+1;
        read ()
    with End_of_file ->
      let rec get_mode l = function
          0 -> l
        | i -> if l = [] || snd (List.hd l) < values.(i) then
                 get_mode [(i,values.(i))] (i-1)
               else if snd (List.hd l) = values.(i) then
                 get_mode ((i,values.(i))::l) (i-1)
               else
                 get_mode l (i-1)
      in
      let mode = get_mode [] 100 in
      let rec print_mode = function
          [] -> ()
        | h::t -> Printf.printf "%d\n" (fst h);print_mode t
      in print_mode mode
  in read ()
;;

Measured memory_bytes: 2132
S = gets.chomp.chars
X, Y = gets.chomp.split(" ").map(&:to_i)

is_x, c, x, y = [true, 0, [], []]
S.each{|s|
  if s == 'T' then
    is_x ? x << c : y << c
    c = 0
    is_x = (not is_x)
  else
    c += 1
  end
}
is_x ? x << c : y << c if c > 0

def solve(ary, t)
  c = Hash.new{|h, k| h[k] = 0}
  ary.each{|a| c[a] += 1}
  bef = [0]
  c.each{|k, v|
    nxt = []
    (0..v).each{|i|
      wk = -(k * v) + 2 * i * k
      bef.each{|b| nxt << b+wk}
    }
    bef = nxt.uniq
  }
  bef.include?(t)
end

wk = 0
wk = x.shift if S[0] == 'F'
puts solve(x, X-wk) && solve(y, Y) ? 'Yes' : 'No'


Measured memory_bytes: 34940
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
C = [int(i) for i in input().split()]

C.sort()

M = sum(C[:-1])
d = [-1] * N

from collections import deque

que = deque([0])
while que:
    v = que.popleft()
    d[v] = C.pop()
    for w in edge[v]:
        if d[w] < 0:
            que.append(w)

print(M)
print(*d)

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

using namespace std;

// 2つの値の最大公約数を求める
int gcd(int x, int y)
{
	if (y == 0) return x;
	return gcd(y, x%y);
}

int main(void)
{
	int N;
	vector<int> A;
	vector<int> L, R;

	cin >> N;
	A.resize(N + 2);
	L.resize(N + 2);
	R.resize(N + 2);
	for (int i = 1; i <= N; i++) {
		int tmp;
		cin >> A[i];
	}

	L[1] = 0;
	for (int i = 1; i <= N; i++) {
		L[i + 1] = gcd(L[i], A[i]);
	}
	R[N + 1] = 0;
	for (int i = N; i >= 1; i--) {
		R[i] = gcd(R[i + 1], A[i]);
	}

	int ans = 0;
	ans = gcd(L[1], R[1]);
	for (int i = 1; i < N; i++) {
		ans = max(ans, gcd(L[i], R[i + 1]));
	}
	ans = max(ans, L[N]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main()
{
    int num;
    cin>>num;
    int currency[num];
    cin>>currency[0]>>currency[1];
    int min=(currency[0]<currency[1]?currency[0]:currency[1]);
    int tmp=currency[1]-currency[0];
    for(int i=2;i<num;i++)
    {
        cin>>currency[i];
        if(currency[i]-min>tmp) tmp=currency[i]-min;
        if(currency[i]<min) min=currency[i];
    }
    cout<<tmp<<endl;
    return 0;
}


Measured memory_bytes: 3836
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

long long n,k,r,c,x,y,z,w;

int on_which(int x,int y)
{
	if(x==0)
	{
		return y;
	}
	if(y==c)
	{
		return c+x;
	}
	if(x==r)
	{
		return r+2*c-y;
	}
	if(y==0)
	{
		return 2*(r+c)-x;
	}
	return -1;
}


int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>r>>c>>n;
	vector<vector<int>> points;
	// vector<vector<int>> points_x, points_y;
	// points_x = points;
	// points_y = points;
	for(int i=0;i<n;++i)
	{
		cin>>x>>y>>z>>w;
		int one = on_which(x,y), two = on_which(z,w);
		if(one!=-1 && two!=-1){
			if(one>two) swap(one,two);
			points.emplace_back(vector<int>{one,two});
		}
	}

	sort(points.begin(),points.end());
	n = points.size();

	// debug;
	// for(int i=0;i<n;++i)
	// {
	// 	cout << points[i][0] << " " << points[i][1] << endl;
	// }

	if(points.size()==0)
	{
		cout << "YES" << endl;
		return 0;
	}

	stack<int> s;

	int start = points[0][0], end = points[0][1];
	s.push(end);
	bool ok = true;
	for(int i=1;i<n;++i)
	{
		int curr_start = points[i][0], curr_end = points[i][1];
		while(!s.empty())
		{
			if(curr_start>s.top())
			{
				s.pop();
			}
			else
			{
				break;
			}
		}
		if(s.empty())
		{
			s.push(curr_end);
		}
		else
		{
			if(s.top()>curr_end)
			{
				s.push(curr_end);
			}
			else
			{
				ok = false;
				//cout << q.front() << " " << curr_end << endl;
				break;
			}
		}
	}
	if(!ok)
	{
		cout << "NO" << endl;
	}
	else
	{
		cout << "YES" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 6964
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int> 
#define vll vector<ll> 
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << " - " << x << endl;
const ll MOD = 1e9 + 7;
const ll INF = 1<<29;
const ll MAX_N = 2e5 + 7;
using namespace std;
int cel(int a,int b) { return ( (a / b) + ((a % b) != 0) ); }

int get(int n){
    int a = 1,b = 1,c = -(2*n);
    int d = (b*b) - (4*a*c);
    double sqt = (double)sqrt(d);
    int x = (-b+sqt)/2,y = (-b-sqt)/2,ans;
    for(auto it:{x,y}){
        if(it>0){
            ans = it;
            break;
        }
    }
    return ans;
}

int main() {
    IOS;
    ll n; cin >> n;
    map<int,int>mp;
    for(ll i=2;i*i<=n;++i){
        while(n % i==0){
            mp[i]++;
            n /= i;
        }
    }
    if(n>1) mp[n]++;
    ll sum = 0;
    for(auto x:mp) sum += get(x.second);
    cout << sum;
}

Measured memory_bytes: 3684
//Krunal_Mathukiya
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define li long int
#define pb push_back
#define mkp make_pair
#define nikalL return
#define chalavo continue
#define basHo break
#define umap unordered_map
#define fr(i,s,n) for(int i=s;i<=n;++i)
#define frr(i,s,n) for(int i=s;i>=n;--i)
#define jaldiKarNe ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
int n;
lli arr[402];
lli pre[402];
lli dp[402][402];
int vis[402][402];
// {length,cost}
lli fn(int i,int j) {
	if(i==j) return 0;
	if(vis[i][j]) return dp[i][j];
	vis[i][j]=1;
	lli cost=1e18;
	lli len=pre[j]-pre[i-1];
	fr(mid,i,j-1) cost=min(cost,fn(i,mid)+fn(mid+1,j)+len);
	return dp[i][j]=cost;
}
int main(){
	jaldiKarNe;
	cin>>n;
	fr(i,1,n) cin>>arr[i];
	fr(i,1,n) pre[i]=pre[i-1]+arr[i];
	cout<<fn(1,n);
}

Measured memory_bytes: 5576
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <list>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

using P = std::pair<int, int>;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> path(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    path[a].push_back(b);
    path[b].push_back(a);
  }

  vector<int> X(n, -1);
  X[0] = 0;
  std::queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int c = que.front(); que.pop();
    for (const auto& to : path[c]) {
      if (X[to] == -1) {
        X[to] = c;
        que.push(to);
      }
//      if (c == tmp.first) {
//        if (X[tmp.second] == -1) {
//          X[tmp.second] = tmp.first;
//          que.push(tmp.second);
// //         cout << X[tmp.second] << '\n';
//        }
//        if (it != path.begin()) --it;
//        path.remove(tmp);
//      } else if (c == tmp.second){
//        if (X[tmp.first] == -1) {
//          X[tmp.first] = tmp.second;
//          que.push(tmp.first);
////          cout << X[tmp.first] << '\n';
//        }
//        if (it != path.begin()) --it;
//        path.remove(tmp);
////        --it;
////        path.erase(it);
//      }
    }
  }

  rep(i, n) {
    if (X[i] == -1) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  srep(i,1,n) {
    cout << X[i]+1 << '\n';
  }
}


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

int main(){
    int n , m;
    cin >> n >> m;
    int k = max(n , m);
    int value = min(n , m);
    
    string req = "";
    while(k--){
        req += (value + '0');
    }
    cout << req << "\n";
return 0;
}


Measured memory_bytes: 256
<?php

$n = (int)trim(fgets(STDIN));
$w = array();
for ($i = 0; $i < $n; $i+=1){
    $w[] =trim(fgets(STDIN));
}


$tmp = array_unique($w);
if (sizeof($tmp) != sizeof($w))
{
    echo "No\n";
}else{

    $a = "";
    $b = $w[0][0];
    $flag = true;

    foreach($w as $k => $v)
    {
        $a = $v[0];
        if($b != $a){
            $flag = false;
            break;
        }

        $b = $v[strlen($v)-1];
    }

    if($flag)
        echo "Yes\n";
    else
        echo "No\n";
}
?>


Measured memory_bytes: 3956
#include <iostream>
#include <vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

using namespace std;

const int N=100000 /*値*/;
bool prime[N];
short next2017[N];

void eratosthenes(){
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
}

void prime2017(){
  int d=0;
  rep(i, N){
    d++;
    next2017[N-i-1]=d;
    if (prime[N-i-1]){
      if(prime[(N-i)/2]){
        d=0;
      }
    }
  }
}

int main(){
  eratosthenes();
  prime2017();
  int x,z;
  int Q;
  cin >>Q;
  vector <int> l(Q),r(Q);
  for(int i=0;i<Q;i++){
    cin >>l[i] >>r[i];
  }
  for(int k=0;k<Q;k++){
    z=0;
    x=l[k];
    if(prime[(x+1)/2]*prime[x]==0) x+=next2017[x];
    for(;x<=r[k];x+=next2017[x]){
      z++;
    }
    cout <<z <<endl;
  }
  return 0;
}

Measured memory_bytes: 1664
import sys

n = int(input())
h = []
for i in range(5):
    a = int(input())
    h.append(int(a))

h.sort()
wh = h[0]
ww = n % wh
if ww == 0:
    wn = int(n / wh) - 1 + 5
else:
    wn = int(round((n / wh) + 0.5)) - 1 + 5

print(wn) 


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


int main(){

    int n;
    cin >> n;
    vector<vector<int>> vv(n, vector<int>(2));
    rep(i,n) {
        int x, y; cin >> x >> y;
        vv[i][0] = x;
        vv[i][1] = y;
    }
    ll d = 0;
    double sq = 0;
    double sum = 0;
    rep(i,n) {
        rep(j,n) {
            d = (vv[i][0] - vv[j][0]) *(vv[i][0] - vv[j][0]) + (vv[i][1] - vv[j][1]) * (vv[i][1] - vv[j][1]);
            sq = sqrt(d);
            sum += sq;
        }
    }
    double ans = double(sum) / n;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if( (a < c && c < b) || (b < c && c < a)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	x := n / 3600
	y := n % 3600 / 60
	z := n % 3600 % 60
	str := fmt.Sprintf("%d:%d:%d", x, y, z)
	fmt.Println(str)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}



Measured memory_bytes: 1100
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 C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    }

    static String solve(int A, int B, int C, int D) {
        if (A + B > C + D) {
            return "Left";
        } else if (A + B < C + D) {
            return "Right";
        } else {
            return "Balanced";
        }
    }
}

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

int main(){
   string s;
   cin>>s;
   bool ok=false;
   for(int i=0;i<s.size();i++){
       if(s[i]=='7')ok=true;
   }
   if(ok)cout<<"Yes";
   else cout<<"No";
}

Measured memory_bytes: 3624
#include <iostream>

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

using namespace std;

int main(){
	string s;
	cin >> s;
	
	int l = s.length();
	
	string ans;
	
	bool used[27];
	REP(i,26) used[i] = false;
	
	REP(i,l){
		int d = s[i]-97;
		used[d] = true;
	}
	
	if (l<26){
		char po;
		REP(i,26){
			if (!used[i]){
				po = i+97;
				s.push_back(po);
				cout << s << endl;
				return 0;
			}
		}
	}else{
		if (s == "zyxwvutsrqponmlkjihgfedcba"){
			cout << "-1" << endl;
			return 0;
		}else{
			for (int i=(l-1); i>=0; i--){
				int d = s[i]-97;
				s.erase(i);
				for (int k=d; k<26; k++){
					if(!used[k]){
						char po = k+97;
						s.push_back(po);
						cout << s << endl;
						return 0;
					}
				}
				used[d] = false;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int N, hai=0, cha=0, midori=0, mizu=0, ao=0, ki=0, daidai=0, aka=0, kin=0, c=0;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a[i];
    if (a[i]<400) {
      hai=hai+1;
    }
    else if (a[i]<800) {
      cha=cha+1;
    }
    else if (a[i]<1200) {
      midori=midori+1;
    }
    else if (a[i]<1600) {
      mizu=mizu+1;
    }
    else if (a[i]<2000) {
      ao=ao+1;
    }
    else if (a[i]<2400) {
      ki=ki+1;
    }
    else if (a[i]<2800) {
      daidai=daidai+1;
    }
    else if (a[i]<3200) {
      aka=aka+1;
    }
    else {
      kin=kin+1;
    }
  }
  if (hai>0) {
    c=c+1;
  }
  if (cha>0) {
    c=c+1;
  }
  if (midori>0) {
    c=c+1;
  }
  if (mizu>0) {
    c=c+1;
  }
  if (ao>0) {
    c=c+1;
  }
  if (ki>0) {
    c=c+1;
  }
  if (daidai>0) {
    c=c+1;
  }
  if (aka>0) {
    c=c+1;
  }
  cout << max(c,1) << " " << c+kin << endl;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int d=1;d<10;++d){
        if(n % d==0){
            int d1 = n / d;
            if(d1 < 10){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d %d %d', $a, $b, $c);
if(($a == $b || $b == $c || $a == $c) && !($a == $b && $b == $c && $a == $c)) {
    echo 'Yes', PHP_EOL;
} else {
    echo 'No', PHP_EOL;
}

Measured memory_bytes: 4604
use proconio::*;
use rand::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut res = 0;
    let mut last_helds = [0; 26];
    let mut tmp = vec![0usize; d];
    let mut ans;
    let mut rng = thread_rng();
    let mut max_ans = 0;
    for i in 0..d {
        tmp[i] = rng.gen_range(1, 27);
    }
    ans = tmp.clone();
    max_ans = satisfaction(&tmp, &c, &s, d);

    for _ in 0..100000 {
        for i in 0..d {
            tmp[i] = rng.gen_range(1, 27);
        }
        let score = satisfaction(&tmp, &c, &s, d);
        if max_ans < score {
            ans = tmp.clone();
            max_ans = score;
        }
    }

    // println!("{}", satisfaction(&ans, &c, &s, d));
    for a in ans {
        println!("{}", a);
    }
}

fn satisfaction(ans: &Vec<usize>, c: &Vec<i64>, s: &Vec<Vec<i64>>, d: usize) -> i64 {
    let mut last_helds = [0; 26];
    let mut res = 0;

    for day in 1..=d {
        res += s[day - 1][ans[day - 1] - 1];
        last_helds[ans[day - 1] - 1] = day as i64;
        for i in 0..26 {
            res -= c[i] * (day as i64 - last_helds[i]);
        }
    }

    res
}


Measured memory_bytes: 2756
a,b,k=map(int,input().split())
d=a+b
if(k>=d):
    print("0 0")
elif(d>k and a<k):
    print("0 ",d-k)
elif(d>k and a>=k):
    print(a-k,b)
elif(a<k and d>=k):
    print("0 ",d-k)



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

using namespace std;

const int maxn = 1e5 + 5;

struct Edges
{
    int v, next;
} e[maxn << 1];
int h[maxn], mem;
int dep[maxn];
bool vis[maxn];
bool du[maxn];
int ansx[maxn], ansy[maxn], top;
bool sum[maxn];
void pre()
{
    memset(h, -1, sizeof(h));
    mem = 0;
    top = 0;
    memset(vis, 0, sizeof(vis));
    memset(du, 0, sizeof(du));
    memset(sum, 0, sizeof(sum));
}

void add( int u, int v )
{
    e[mem].v = v;
    e[mem].next = h[u];
    h[u] = mem++;
}

void dfs(int u, int f)
{
    vis[u] = 1;
    dep[u] = dep[f] + 1;
    for(int i=h[u]; i+1; i=e[i].next)
    {
        int v = e[i].v;
        if(v==f) continue;
        if(vis[v]){
            if(dep[u]<dep[v]||(dep[u]==dep[v]&&u<v))
            {
                du[u] ^= 1;
                ansx[top] = u;
                ansy[top++] = v;
            }
            continue;
        }
        du[u]^=1;
        dfs(v, u);
    }
}

vector<int> last;



void change(int u, int v)
{
    du[u] ^= 1;
    du[v] ^= 1;
}

bool dfsans(int u, int f)
{
    vis[u] = 1;
    //printf("dfsans %d %d\n", u, f);
    bool now=du[u];
    for(int i=h[u]; i+1; i=e[i].next)
    {
        int v = e[i].v;
        if(v==f) continue;
        if(vis[v]) continue;
        bool flag = dfsans(v, u);
        if(flag){
            ansx[top] = v;
            ansy[top] = u;
        }
        else{
            ansx[top] = u;
            ansy[top] = v;
        }
        top++;
        now ^= flag;
    }
    return now;
}

int main()
{
    int n, m;
    scanf( "%d%d", &n, &m );
    pre();
    for( int i = 1; i <= m; i++ )
    {
        int u, v;
        scanf("%d%d", &u, &v);
        add(u, v);
        add(v, u);
    }
    if(m&1){
        printf("-1\n");
        return 0;
    }
    dep[1] = 1;
    dfs(1, 1);
    last.clear();
    for(int i=1; i <= n; i++)
    {
        if(du[i]){
            last.push_back(i);
        }
    }
    memset(du, 0, sizeof(du));
    memset(vis, 0, sizeof(vis));
    int l = last.size();
    for(int i=0; i < l / 2; i++)
    {
        change(last[i], last[l-1-i]);
    }
    dfsans(1, 1);
    for(int i=0; i<top; i++)
    {
        printf("%d %d\n", ansx[i], ansy[i]);
    }
    //printf("%d\n", top);
    return 0;
}


Measured memory_bytes: 9976
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int64_t H,x=0,count=0;
  vector<int64_t> A(41,0);
  for(int i=0;i<41;i++){x+=pow(2,i);A.at(i)=x;}
  cin>>H;
  while(H>=2){H/=2;count++;}
  cout<<A.at(count)<<endl;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.length();
    reverse(S.begin(), S.end());
    for(int i = 0; i <= N; i++){
        if(S.find("remaerd") == 0){
            S.replace(0, 7, "");
        }
        if(S.find("maerd") == 0){
            S.replace(0, 5, "");
        }
        if(S.find("resare") == 0){
            S.replace(0, 6, "");
        }
        if(S.find("esare") == 0){
            S.replace(0, 5, "");
        }
    }
    if (S.length() == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <stdio.h>

main()
{
	int x, y, w;

	scanf("%d %d", &x, &y);

	while(x != 0 || 0 !=y)
	{
		if(x > y)
		{
			w = x;
			x = y;
			y = w;
		}
		printf("%d %d\n", x, y);
		scanf("%d %d", &x, &y);
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main () {
	int a,b;
	string s;
	cin >> a >> b;
	cin >> s;
	bool judge = true;
	for (int i = 0; i < a + b + 1; ++i)
	{
		if(i < a){
			if((int)(s[i] - '0') > 9 || (int)(s[i] - '0') < 0){
				judge = false;
			}
		}else if(i == a){
			if(s[a] != '-')judge = false;
		}else{
			if((int)(s[i] - '0') > 9 || (int)(s[i] - '0') < 0){
				judge = false;
			}
		}
	}
	if(judge){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int H,W,i,j;
    scanf("%d %d",&H,&W);
    while(H!=0&&W!=0){
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if((i+j)%2==0){
                printf("#");
            }else{
                printf(".");
            }
        }printf("\n");
    }printf("\n");
    scanf("%d %d",&H,&W);
    }
    return 0;
}


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

int main(){
    string S;
    cin >> S;
    ll cnt = 0;
    ll k = 0;
    ll n = S.size();
    for (ll i = 0; i < n; i++){
        if (S.at(i) == 'B'){
            cnt += i;
            k ++;
        }
    }
    ll black = 0;
    for (int i = n - 1; i > n - 1 - k; i--){
        black += i;
    }
    cout << black - cnt << endl;
    return 0;
}

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

int main(){
  int N,A,B,count1=0,count2=0;
  string s;

  cin>>N>>A>>B;
  cin>>s;
  for(int i=0;i<N;i++){
    if(s[i]=='c'){
      cout<<"No"<<endl;
    }else if(s[i]=='b'){
      if(count1<A+B&&count2<B){
	cout<<"Yes"<<endl;
	count1++;
	count2++;
      }else{
	cout<<"No"<<endl;
      }
    }else if(s[i]=='a'){
      if(count1<A+B){
	cout<<"Yes"<<endl;
	count1++;
      }else{
	cout<<"No"<<endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    ll n, k;
   
    cin >> n >> k;
    n = n % k;
    n = min(n, k-n);
    cout << n << endl;
    return 0;
}

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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;

string s;
int n;
ll ans;

int read() {
    if (!(cin >> s)) {
        return 0;
    }
    n = (int) s.size();
    return 1;
}

vector<ll> work(vector<string> vs) {
    vector<ll> res;
    int vsn = (int) vs.size();
    for (int i = 0; i < vsn; i++) {
        string s_Number = vs[i];
        ll i_Number = 0;
        ll pw = 1;
        for (int j = s_Number.size() - 1; j >= 0; j--) {
            i_Number = i_Number + ((s_Number[j] - '0') * pw);
            pw *= 10;
        }
        res.pb(i_Number);
    }
    return res;
}

void solve() {
    if (n == 1) {
        printf("%s\n", s.c_str());
        return ;
    }
    --n;
    ans = 0;
    vector<int> lens;
    vector<string> s_nums;
    for (int i = 0; i < (1 << n); i++) {
        lens.clear();
        lens.pb(0);
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                lens.pb(j + 1);
            }
        }
        lens.pb(n + 1);

        s_nums.clear();
        for (int j = 0; j < (int) lens.size() - 1; j++) {
            s_nums.pb(s.substr(lens[j], lens[j + 1] - lens[j]));
        }

        vector<ll> i_nums = work(s_nums);
        for (int j = 0; j < (int) i_nums.size(); j++) {
            ans += i_nums[j];
        }
    }
    printf("%ld\n", ans);
}

int main(int argc, char *argv[]) {
    //precalc();
    while (read()) {
        solve();
    }
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

long long T,N;


int main(){
	cin>>N>>T;
	int t;
	int ans=0;
	int x=0,at=0;
	for(int i=0;i<N;i++){
		cin>>t;
		if(t<at)ans-=at-t;
		ans+=T;
		at=t+T;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {

	int n;
	string s;

	cin >> n >> s;

	int maxn=0;

	for (int cutlast = 1; cutlast < n; cutlast++)
	{
		int num = 0, a[26] = {}, b[26] = {}, jud[26] = {};

		for (int i = 0; i < cutlast; i++)
		{
			a[s[i]-'a']++;
			//printf("front:a[%d]++;\n", s[i] - 'a');
		}

		for (int i = cutlast; i < n; i++)
		{
			b[s[i]-'a']++;
			//printf("back:a[%d]++;\n", s[i] - 'a');
		}

		for (int i = 0; i < 26; i++)
		{
			if (a[i] >0&& b[i]>0&&jud[i]==0) {
				jud[i]++;
				num++;
			}
		}

		/*for (int i = 0; i < n; i++)
		{
			if (i + cutlast < n) {
				if (a[s[i] - 'a'] > 0 && a[s[i] - 'a'] == a[s[i + cutlast] - 'a'] && jud[s[i] - 'a'] == 0) {
					jud[s[i] - 'a']++;
					num++;
					//cout << "jud\n";
					printf("i=%d,a[%d]=%d,a[%d]=%d,num=%d,jud[%d]=%d\n", i, s[i] - 'a', a[s[i] - 'a'], s[i + cutlast] - 'a', a[s[i + cutlast] - 'a'], num, s[i] - 'a', jud[s[i] - 'a']);
				}
			}
		}*/

		maxn = max(maxn, num);

		//printf("cutlast=%d,maxn=%d\n", cutlast, maxn);
	}

	cout << maxn << "\n";

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    L = Scanner.map_int()
    L.sort()
    ans = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j + 1, N):
                if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                    continue
                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
                    ans += 1
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10804
#include <stdio.h>

int sosuu(int x)
{
   int i;

   if ( x < 2 ) return 0;
   else if ( x == 2 ) return 1;
   if ( x % 2 == 0 ) return 0;

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

int main(void)
{
   int n, x, i;
   int wa = 0;

   scanf("%d", &n);

   for ( i = 0; i < n; i++) {
      scanf("%d", &x);
      if ( sosuu(x) ) wa = wa+1;
   }
   printf("%d\n", wa);

   return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque

def solve():
    N = II()
    E = [[] for _ in range(N)]

    for i in range(N-1):
        a, b = MI1()
        E[a].append((b, i))
        E[b].append((a, i))

    q = deque([(0, -1, -1)])
    ans = [0] * (N-1)
    while len(q) > 0:
        current, v_pre, c_pre = q.popleft()
        color = 1
        for (nv, idx) in E[current]:
            if nv == v_pre: continue
            if color == c_pre:
                color += 1
            q.append((nv, current, color))
            ans[idx] = color
            color += 1

    print(max(ans))
    printlist(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 45692