akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int N, K, ans=0; cin >> N >> K; vector<int> p(N);
REP(i, N){ cin >> p[i]; }
sort(p.begin(), p.end());
REP(i, K){ ans+=p[i]; }
cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/
int cost[100100];
int n;
struct edge{
    int to;
    int cost;
};
vector<edge> es[100100];
bool used[100100]={};
void dfs(int s){
    used[s]=true;
    for(int i=0;i<es[s].size();i++){
        if(used[es[s][i].to]==false){
            cost[es[s][i].to]=cost[s]+es[s][i].cost;
            dfs(es[s][i].to);
        }
    }
}
signed main(){
    int x,y;
    cin>>x>>y;
    int ans=0;
    if(x==1){
        ans+=300000;
    }else if(x==2){
        ans+=200000;
    }else if(x==3){
        ans+=100000;
    }
    if(y==1){
        ans+=300000;
    }else if(y==2){
        ans+=200000;
    }else if(y==3){
        ans+=100000;
    }
    if(x==1&&y==1)ans+=400000;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n, k := scanInt(), scanInt64()

	as := scanInts(n)
	fs := scanInts(n)

	sort.Ints(as)
	sort.Ints(fs)

	l,r := int64(-1), int64(1<<63-1)

	for l+1 < r {
		mid := (l+r)/2
		c := int64(0)
		for i := 0; i < n; i++ {
			if mid < int64(as[i])*int64(fs[n-1-i]) {
				c += int64(as[i])-mid/int64(fs[n-1-i])
			}
		}

		if c <= k {
			r = mid
		} else {
			l = mid
		}
		// fmt.Println(l,r)
	}

	fmt.Println(r)

}


Measured memory_bytes: 5760
a,b=map(int,input().split())
ls = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
x = [list(input().split()) for i in range(a)]
for i in range(a):
  for j in range(b):
    if x[i][j] == "snuke":
      print(ls[j]+str(i+1))
      break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

char ans[110];

int main(){
    string o, e;
    cin >> o >> e;

    rep(i, o.size()){
        ans[2*i] = o[i];
    }
    rep(i, e.size()){
        ans[2*i+1] = e[i];
    }
    rep(i, o.size()+e.size()){
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a + b  > c + d)
    cout << "Left" << endl;
  else if (a + b == c + d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline int isPrime_L(T n){
  T i;
  if(n<=1){
    return 0;
  }
  if(n<=3){
    return 1;
  }
  if(n%2==0){
    return 0;
  }
  for(i=3;i*i<=n;i+=2){
    if(n%i==0){
      return 0;
    }
  }
  return 1;
}
int main(){
  int X;
  rd(X);
  while(!isPrime_L(X)){
    X++;
  }
  wt_L(X);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// {
//   int X;
//   rd(X);
//   while(!isPrime(X)) X++;
//   wt(X);
// }


Measured memory_bytes: 256
import math
import sys
sys.setrecursionlimit(30000)
N=int(input())
edges=[[] for i in range(N+1)]
d=[-1 for i in range(N+1)]
for i in range(1,N):
	u,v,w=[int(i) for i in input().split()]
	edges[u].append([v,w])
	edges[v].append([u,w])
def kyori(u):
	for v,w in edges[u]:
		if d[v]==-1:
			d[v]=d[u]+w
			kyori(v)
d[1]=0
kyori(1)
for i in d[1:]:
	if i%2==0:
		print(1)
	else:
		print(0)

Measured memory_bytes: 154272
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
s = int(input())
up = s//100
dn = s - up*100
yymm = (0 < int(dn) <= 12)
mmyy = (0 < int(up) <= 12)
if yymm:
    if mmyy:
        print('AMBIGUOUS')
    else:
        print('YYMM')
else:
    if mmyy:
        print('MMYY')
    else:
        print('NA')

Measured memory_bytes: 5076
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
  int key;
  int pk;
  int lk;
  int rk;
}node;

int parent(int);
int left(int);
int right(int);
void print(int);

int A[250];
int heapsize=0;
int H;

int main(){
  
  int i;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=H;i++){
    print(i);
    printf("\n");
  }
  return 0;
}
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return (2*i+1);
}
void print(int i){
  int p,l,r;
  p=parent(i);
  l=left(i);
  r=right(i);
  printf("node %d: key = %d, ",i,A[i]);
  if(i!=1)printf("parent key = %d, ",A[p]);
  if(l<=H)printf("left key = %d, ",A[l]);
  if(r<=H)printf("right key = %d, ",A[r]);
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;

const int Inf = 100000;
const int mod = 1e9 + 7;
const double Pi = acos(-1);

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

int h, w, a, b;
long long ans = 0;
long long Fact[500005], iFact[500005];

long long BinPow(long long n, int k)
{
	if(k == 0)
	{
		return 1;
	}
	long long temp = BinPow(n, k >> 1);
	if(k % 2 == 0)
	{
		return temp * temp % mod;
	}
	else
	{
		return temp * temp % mod * n % mod;
	}
}

long long C(int k, int n)
{
	if(n < k or k < 0)
	{
		return 0;
	}
	return Fact[n] * iFact[k] % mod * iFact[n - k] % mod;
}

signed main()
{
	Fact[0] = 1;
	for(int i = 1; i <= 500000; i++)
	{
		Fact[i] = Fact[i - 1] * i % mod;
	}
	iFact[500000] = BinPow(Fact[500000], mod - 2);
	for(int i = 499999; i >= 0; i--)
	{
		iFact[i] = iFact[i + 1] * (i + 1) % mod;
	} 
	cin >> h >> w >> a >> b;
	for(int i = h - a; i >= 1; i--)
	{
		ans += C(i - 1, i + b - 2) * C(h - i, h - i + w - b - 1) % mod;
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 11444
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<b)return 0; a=b; return 1;}



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

    int n,m;
    cin>>n>>m;
    int ans = m*(m-1)/2 + n*(n-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{

 ll n,k,d,c=0,x,y,ans;
 cin>>n>>k>>d;
 n=abs(n);
 x=n%d;
 y=n/d;
 if(y>=k)
 {
   ans=n-(d*k); 
 }else
 {
   k=k-y;
   if(k%2==0)  ans=abs(x);
   else  ans=min(abs(x-d),abs(x+d));
 }
 cout<<ans<<endl;

}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <bitset>

using namespace std;

int dp[2][100];

int main(){
    int N, A[2][100];

    cin >> N;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < N; j++){
            cin >> A[i][j];
        }
    }

    dp[0][0] = A[0][0];
    
    for(int i = 1; i < N; i++) dp[0][i] = A[0][i] + dp[0][i-1];
    
    dp[1][0] += dp[0][0] + A[1][0];
    for(int i = 1; i < N; i++){
        dp[1][i] = max(dp[0][i], dp[1][i-1]) + A[1][i];
    }
    

    cout << dp[1][N-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

const int K = 1e9;
signed main() {
  int s; cin >> s;
  int y1 = K - s % K;
  if (y1 == K) y1 = 0;
  assert((s + y1) % K == 0);
  int y2 = (s + y1) / K;
  cout << "0 0 " << K << " " << y1 << " " << 1 << " " << y2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
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;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (A < C && C < B) {
        cout << "Yes" << endl;
    } else if (B < C && C < A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_g
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define infinity (ll)4e18
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

ll dfs(ll dp[], vector<ll> v[], ll node)
{
    if (dp[node] != -1)
        return dp[node];
    ll val = 0;
    for (ll i = 0; i < (ll)v[node].size(); i++)
        val = max(val, 1 + dfs(dp, v, v[node][i]));
    return dp[node] = val;
}

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

    ll n, m, a, b;
    cin >> n >> m;
    vector<ll> v[n + 1];
    for (ll i = 0; i < m; i++)
    {
        cin >> a >> b;
        v[a].push_back(b);
    }
    ll dp[n + 1];
    memset(dp, -1, sizeof(dp));
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
        ans = max(ans, dfs(dp, v, i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	long N,i,temp,c=0;
	cin>>N;
	for(i=1;i<=N;i++){
		cin>>temp;
		if(i!=temp){
			c++;
		}
	}
	if(c<=2){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
const char code[10][10] = {"","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ" };

int main() {
	int c = 0,a;
	char input[10001],*p;
	for (;~fscanf(stdin, "%[^\n]*s", input)!=NULL; puts("")) {
		getchar();
		p = input;
		c = 0;
		while (*p) {
			if (*(p+1) != *p) {
				if (*p == '1')a = 5;
				else if (*p == '7' || *p == '9') a = 8;
				else a = 6;
				if(*p!='0') fprintf(stdout, "%c", code[*p - '0'][c%a]);
				c = 0;
			}
			else c++;
			if(*p=='0'&&*(p+1)=='0') putchar(' ');
			p++;
		}
	}
	return 0;
}

Measured memory_bytes: 540
#include<stdio.h>
int main(){
  int s,h,m,m1,h1;
  scanf("%d",&s);
  h=s/3600;
  h1=s%3600;
  m=h1/60;
  m1=h1%60;
  printf("%d:%d:%d\n",h,m,m1);
  return(0);
}

Measured memory_bytes: 2720
def resolve():
    N, M = map(int, input().split())
    SC = [list(map(int, input().split())) for _ in range(M)]

    res = [0] * N
    called = [0] * N

    for sc in SC:
        s = sc[0] - 1
        c = sc[1]
        # 同じ桁を指定しながら、別の数値を指定した場合
        if called[s] == 1 and res[s] != c:
            print(-1)
            return
        
        res[s] = c
        called[s] = 1

    # 先頭が0となる場合
    if N != 1 and res[0] == 0:
        if called[0] == 1:
            print(-1)
            return
        else:
            res[0] = 1

    print(''.join(map(str, res)))



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;
  
  if(A+B == C+D){  
    cout << "Balanced" <<endl;
  }
  else if(A+B > C+D){
    cout << "Left" <<endl;
  }
  else if(A+B < C+D){
    cout << "Right" <<endl;
  }
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = Integer.parseInt(scan.next());
        int n = Integer.parseInt(scan.next());

        if (n == 0) {
            System.out.println(x);
            scan.close();
            return;
        }

        Set<Integer> set = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            set.add(Integer.parseInt(scan.next()));
        }
        scan.close();

        int a = x;
        int b = x;
        while (true) {
            if (!set.contains(b)) {
                System.out.println(b);
                return;
            }
            if (!set.contains(a)) {
                System.out.println(a);
                return;
            }
            a++;
            b--;
        }

    }
}


Measured memory_bytes: 35732
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

const int M=1000000;

ll g(ll a, ll b) {
	if (a < b)
		swap(a, b);
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main(){
	int n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	VI f(M+1,0);
	REP(i,n){
		f[a[i]]++;
	}
	bool notp=0;
	for(int i=2;i<=M;i++){
		int c=0;
		for(int j=i;j<=M;j+=i){
			c+=f[j];
		}
		if(c>=2){
			notp=1;
			break;
		}
	}
	int gg=a[0];
	REP(i,n-1){
		gg=g(gg,a[i+1]);
	}
	if(!notp)
		cout << "pairwise coprime" << endl;
	else if(gg==1)
		cout << "setwise coprime" << endl;
	else
		cout << "not coprime" << endl;
	return 0;
}

Measured memory_bytes: 18728
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int n,k,r,s,p;
    string str;
    cin>>n>>k;
    cin>>r>>s>>p>>str;
    int res=0;
    for(int i=0;i<n;++i) {
        if(i-k>=0 && str[i]==str[i-k]) {
            str[i]='*';
            continue;
        }
        if(str[i]=='r') res+=p;
        else if(str[i]=='s') res+=r;
        else if(str[i]=='p') res+=s;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 512
five = int(input()) + 1
hand = int(input()) + 1
fives = int(input()) + 1
ans = int(input()) 
tmp = 0
 
for i in range(five):
  for j in range(hand):
    for k in range(fives):
      ask = 500 * i + 100 * j + 50 * k
      if ans == ask:
        tmp = tmp + 1

print(tmp)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
void kouri(int, int,int);
int  sum_max = 0;
int c[90][90];
int c2[90][90] = { 0 };
int a, b;
int nx[] = { 1,0,-1,0 };
int ny[] = { 0,-1,0,1 };
int main() {
    while (1) {
        sum_max = 0;
        cin >> a;
        cin >> b;
        if (a == 0 && b == 0)return 0;
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                cin >> c[i][j];
            }
        }
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                if (c[i][j] == 1) {
                    kouri(i, j, 0);
                }
            }
        }
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                c[i][j] = 0;
            }
        }
        cout << sum_max << endl;
    }
}
void kouri(int x, int y, int sum) {
    c[x][y] = 0;
    sum++;
    if (c[x][y + 1] == 1)kouri(x, y + 1, sum);
    if (c[x][y - 1] == 1)kouri(x, y - 1, sum);
    if (c[x + 1][y] == 1)kouri(x + 1, y, sum);
    if (c[x - 1][y] == 1)kouri(x - 1, y, sum);
    c[x][y] = 1;
    if (sum > sum_max)sum_max = sum;
}

Measured memory_bytes: 3080
#include <cstdio>
#include <vector>
#include <functional>

using namespace std;

int BipartiteGraph(const vector<vector<int>> &g) {
        int n = g.size();
        vector<int> color(n, -1);
        int white_cnt = 0;
        function<bool (int, int, int)> dfs = [&](int u, int prev, int c) {
                color[u] = c;
                if (c == 1) white_cnt ++;
                for (auto v : g[u]) if (v != prev) {
                        if (color[v] == -1) {
                                if (!dfs(v, u, 1 - c)) return false;
                        } else if (color[v] != 1 - c) {
                                return false;
                        }
                }
                return true;
        };
        if (!dfs(0, -1, 0)) return -1;
        return white_cnt;
}

int main() {
        int n, m;
        scanf("%d %d", &n, &m);
        vector<vector<int>> g(n);
        for (int i = 0; i < m; i ++) {
                int a, b;
                scanf("%d %d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        int cnt = BipartiteGraph(g);
        if (cnt == -1) printf("%lld\n", (long long) n * (n - 1) / 2 - m);
        else printf("%lld\n", (long long) cnt * (n - cnt) - m);
        return 0;
}


Measured memory_bytes: 6784
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let y: i32 = read();

    let mut a: i32 = -1;
    let mut b: i32 = -1;
    let mut c: i32 = -1;

    for i in 0..n+1 {
        for j in 0..n+1-i {
            let k = n - i - j;
            if (10000 * i) + (5000 * j) + (1000 * k) == y {
                a = i;
                b = j;
                c = k;
                break;
            }
        }
    }

    println!("{} {} {}", a, b, c);
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    int i = 0;
    while (h[i] == 0) i++;

    rep (X, 101) {
        rep (Y, 101) {
            bool bad = false;
            int H = h[i] + abs(x[i] - X) + abs(y[i] - Y);
            rep (j, N) {
                if (max(H - abs(x[j] - X) - abs(y[j] - Y), 0) != h[j]) {
                    bad = true;
                    break;
                }
            }
            if (not bad) {
                print(X, Y, H);
                return 0;
            }
        }
    }

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"

using namespace std;

int main() {
    int h, w;
    cin >> h, w;
    string s;
    getline(cin, s);
    vector<string> v(h);
    for (int i = 0; i < h; ++i) {
        getline(cin, s);
        v[i] = s;
    }
    for (int j = 0; j < h; ++j) {
        for (int i = 0; i < 2; ++i) {
            cout << v[j] << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 256
import collections
S=input()
dic=collections.defaultdict(int)
for i in range(len(S)):
  dic[S[i]]+=1
smax=[0,"d"]
for i in dic:
  if dic[i] > smax[0]:
    smax=[dic[i],i]

if len(dic.values())==1:
  if len(S)==1:
    print("YES")
  else:
    print("NO")
  exit(0)
    
elif len(dic.values())==2:
  if len(S)==2:
    print("YES")
  else:
    print("NO")
  exit(0)
if sum(dic.values()) - smax[0]>= smax[0]:
  if smax[0] - min(dic.values()) <= 1:
    print("YES")
    exit(0)
    
print("NO")


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
int d[maxn];
int main()
{
    int n , m;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a , b;
        cin >> a >> b;
        d[a]++;
        d[b]++;
    }
    for(int i = 1; i <= n; i++)
        cout << d[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const int MAX_V = 200001;
typedef pair<int, int> P;

vector<vector<int>> G(MAX_V);
vector<ll> ans(MAX_V);

void dfs(int v, int p, ll cost) {
    ans[v] += cost;
    for (int to : G[v]) {
        if (to == p) continue;
        dfs(to, v, ans[v]);
    }
}

int main()
{
    int N, Q;
    cin >> N >> Q;

    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0, -1, 0);

    rep(i, N) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 25092
N, K = map(int, input().split())
d = []
A = []
for _ in range(K):
    d.append(int(input()))
    A.append([int(e) for e in input().split()])
snukes = [0] * (N+1)
for a in A:
    for item in a:
        snukes[item] += 1
snukes = snukes[1:]
print(len([e for e in snukes if e == 0]))

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


// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3") 
// #pragma GCC optimization ("unroll-loops")
 
#define ll  long long int
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
#define MD          1000000007
#define M           100011

long long  md=MD;


int solve(){
	ll n,i,j,k;

	cin>>n;--n;
	cout<<(n*n+n)/2<<"\n";



	return 0;
}


int main(){

 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t,i;

    t=1;
    // cin>>t;

    while(t--){
    	solve();
    }



    

}



Measured memory_bytes: 256
li=[]
for i in range(5):
    li.append(int(input()))

min=9

min_f=0

for i in range(5):
    if min> li[i]%10 >0:
        min=li[i]%10
        min_f=i

cnt=0

for i in range(5):
    if i==min_f:
        continue
    if li[i]%10==0:
        cnt+=li[i]
    else:
        cnt+=li[i]+10-li[i]%10
print(cnt+li[min_f])

Measured memory_bytes: 61952
n=int(input())

xy=[[int(_) for _ in input().split()]for i in range(n)]

print(max(max([a[0]+a[1] for  a in xy])-min([a[0]+a[1] for  a in xy]),max([a[0]-a[1] for  a in xy])-min([a[0]-a[1] for  a in xy])))
# print(max([a[0]-a[1] for  a in xy])-min([a[0]-a[1] for  a in xy]))

Measured memory_bytes: 50296
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n, t;
int a[100000];

int main(){
  cin >> n >> t;
  rep(i, n) cin >> a[i];
  int mn = inf, mx = 0;
  rep(i, n){
    chmax(mx, a[i] - mn);
    chmin(mn, a[i]);
  }
  int res = 0;
  int ii = 0;
  rep(i, n){
    if (a[i] - a[ii] == mx) res++;
    if (a[ii] > a[i]) ii = i;
  }
  cout << res << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
using namespace std;

#define all(c) c.begin(),c.end()
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i,0,n)
#define MAX(x, y)  ((x > y)? x : y);
#define MIN(x, y)  ((x < y)? x : y);
#define dump(x)  cout << #x" = " << x << endl;
#define debug(x) cout << #x" = " << x << " (" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
typedef vector<int> vi;

int main() {
	ll n, k, x, y;
	cin >> n >> k >> x >> y;

	ll ans = 0;

	REP(i, n) {
		if (i + 1 <= k) ans += x;
		else ans += y;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int a; cin >> a;
  string op; cin >> op;
  int b; cin >> b;
  auto ans = op == "+" ? a+b : a-b;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++) cin>>A[i];

  int ans=0;
  int now=0;
  for(int i=0;i<N-1;i++){
    if(A[i]>=A[i+1]){
      now++;
    }else{
      ans=max(ans,now);
      now=0;
    }
    if(i==N-2) ans=max(ans,now);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
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();
		sc.close();
		
		if (A == B) {
			System.out.println(C);
		} else if (A == C) {
			System.out.println(B);
		} else if (B == C) {
			System.out.println(A);
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    string s;
    int k_;
    cin >> s >> k_;
    int n = sz(s);
    
    ll dp[n + 1][4][2];
    rep(i, n + 1) rep(j, 4) rep(k, 2) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    
    rep(i, n) rep(j, 4) rep(k, 2) rep(l, 10) {
        if (k == 0 && l > s[i] - '0') continue;
        if (j + (l != 0) >= 4) continue;
        dp[i + 1][j + (l != 0)][k | (l < s[i] - '0')] += dp[i][j][k];
    }
    ll ans = 0;
    rep(k, 2) ans += dp[n][k_][k];
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


template<typename T>
vector<vector<T>> keisann(const vector<vector<T>>l, const vector<vector<T>>r) {
	vector<vector<T>>ans(l.size(), vector<T>(r[0].size()));
	assert(l[0].size() == r.size());
	for (unsigned int h = 0; h < l.size(); ++h) {
		for (unsigned int i = 0; i < r.size(); ++i) {
			for (unsigned int w = 0; w < r[0].size(); ++w) {

				ans[h][w] |= l[h][i] * r[i][w];
			}
		}
	}
	return ans;
}

template<typename T>
vector<vector<T>>powgyou(vector<vector<T>>a, const long long int n) {
	assert(a.size() == a[0].size());
	if (!n) {
		vector<vector<T>>e(a.size(), vector<T>(a[0].size()));
		for (unsigned int i = 0; i < a.size(); ++i) {
			e[i][i] = 1;
		}
		return e;
	}
	if (n == 1)return a;
	else {
		vector<vector<T>>ans(a.size(), vector<T>(a[0].size(), 0));
		ans = powgyou(a, n / 2);
		ans = keisann(ans, ans);
		if (n % 2) {
			ans = keisann(ans, a);
		}
		return ans;
	}
}


int main() {
	while (1) {
		int N, M, Z; cin >> N >> M >> Z;
		if (!N)break;
		vector<pair<int, int>>edges;
		edges.push_back(make_pair(-1, 0));
		for (int i = 0; i < M; ++i) {
			int s, d; cin >> s >> d; s--; d--;
			edges.push_back(make_pair(s, d));
			edges.push_back(make_pair(d, s));
		}
		vector<vector<int>>field(edges.size(), vector<int>(edges.size()));
		for (int i = 0; i < edges.size(); ++i) {
			for (int j = 0; j <edges.size(); ++j) {
				auto a = edges[i];
				auto b = edges[j];
				if (a.second == b.first&&a.first != b.second) {
					field[j][i] = true;
				}
			}
		}
		vector<vector<int>>start(edges.size(), vector<int>(1));
		start[0][0] = true;
		vector<vector<int>>kake = powgyou<int>(field, Z);
		vector<vector<int>>ans = keisann<int>(kake, start);
		bool ok = false;
		for (int i = 0; i <edges.size(); ++i) {
			if (edges[i].second == N - 1 && ans[i][0])ok = true;
		}
		if (ok)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 5792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c;cin >> n >> c;
    int a[c][c];
    int b[n][n];
    int ans=inf;
    for(int i=0;i<c;i++){
        for(int j=0;j<c;j++){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> t(3,vector<int>(c));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> b[i][j];
            b[i][j]--;
            t[(i+j)%3][b[i][j]]++;
        }
    }
    for(int i=0;i<c;i++){
        for(int j=0;j<c;j++){
            for(int k=0;k<c;k++){
                if(i==j||j==k||k==i){
                    continue;
                }
                int res=0;
                int p[3]={i,j,k};
                for(int l=0;l<3;l++){
                    for(int m=0;m<c;m++){
                        res+=a[m][p[l]]*t[l][m];
                    }
                }
                chmin(ans,res);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define ll long long

int main() {
    ll d;
    cin >> d;
    ////////
    vector<vector<ll>> s(365, vector<ll>(26, 0));
    vector<int> c(26);
    vector<ll> t(d, 1);
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        ll tmp = 0;
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
            if(tmp < s[i][j]) {
                tmp = s[i][j];
                t[i] = j+1;
            }
        }
    }

    /////////////////
    /*
    for(int i = 0; i < d; i++) {
        t[i] = i+1;
    }
    */
    //for(int i = 0; i < d; i++) cin >> t[i];
    ll mx_v = 0;
    vector<ll> swap_set;
    vector<pair<int, int>> p(d);
    for(int i = 0; i < d; i++) {
        mx_v = -1;
        int ni = i, nj = 0;
        for(int j = 0; j < 26; j++) {
            if(s[i][j] > mx_v) {
                mx_v = s[i][j];
                ni = i;
                nj = j;
            }
        }
        swap_set.push_back(mx_v);
        p[i] = make_pair(ni, nj);
        //p.push_back(make_pair(ni, nj));
    }

    ///////////////
    ll m;
    m = d;
    //cin >> m;
    vector<pair<int, int>> dq(m);
    for(int i = 0; i < m; i++) {
        //cin >> dq[i].first >> dq[i].second;
        dq[i].first = p[i].first+1;
        dq[i].second = p[i].second+1;
        //cout << dq[i].first << " " << dq[i].second << endl;
    }
    vector<ll> ans(d, 0);
    ll v = 0;
    //ll tmp = 0;
    map<ll, ll> mp;
    priority_queue<ll> que;
    vector<vector<ll>> list(m, vector<ll>(d, 1));
    //int num = 0;
    for(int k = 0; k < m; k++) {
        //
        //tmp = t[dq[k].first-1];
        //cout << dq[k].first-1 << " " << t[dq[k].first-1] << endl;
        t[dq[k].first-1] = dq[k].second; 

        /////////////////////
        vector<ll> last(26, 0);
        for(int i = 0; i < d; i++) {
            //if(t[i]-1 >= 26) cout << "t: " << t[i]-1 << endl;
            v += s[i][t[i]-1];//-1
            //v += s[t[i]-1][];
            //v += 
            last[t[i]-1] = i+1;//-1
            for(int j = 0; j < 26; j++) {
                v -= c[j]*((i+1)-last[j]);
            }    
        }
        //cout << v << endl;
        que.push(v);
        mp[v] = k;
        for(int i = 0; i < d; i++) {
            //list[k].push_back(t[i]);
            list[k][i] = t[i];
            //cout << t[i] << endl;
        }
        v = 0;
    }

    //cout << mp[que.top()] << endl;
    //cout << list[0].size() << endl;
    //cout << m << endl;
    ll tmp = que.top();
    for(int i = 0; i < m; i++) {
        //cout << list[mp[que.top()]][i] << endl;
        cout << list[mp[tmp]][i] << endl;
        //cout << que.top() << endl;
        //que.pop();
        /*
        cout << "i: " << i << endl;
        for(int j = 0; j < list[i].size(); j++) {
            cout << list[i][j]+1 << endl;
        }
        */
        
    }

    return 0;
}

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

int main(){
  double T;
  int D,ta,tb,da,db;
  cin >> T >> D >> ta >> tb >> da >> db;

  double res = 1e9;
  for(int a=0;a*da<=D;a++){
    int va = a*da;
    for(int b=0;va+b*db<=D;b++){
      int vb = b*db;
      if(va+vb==0)continue;
      double Tp = (double)(ta*va + tb*vb)/(va+vb);
      res = min(res, abs(Tp-T));
    }
  }
  cout << fixed << setprecision(9) << res << endl;
}

Measured memory_bytes: 1288
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
#include <ctime>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n % 1000 == 0)
        cout << 0 << endl;
    else
        cout << 1000 - n % 1000 << endl;
    return 0;
}

Measured memory_bytes: 3652
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
while 1:
 h,m,s=map(int,input().split())
 if h<0:break
 d=7200-h*3600-m*60-s
 p(d);p(d*3)


Measured memory_bytes: 5612
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	var n, m, ans int
	var k [30]int
	var a [30][30]int
	fmt.Scanf("%d %d", &n, &m)
	for i := 0; i < n; i++ {
		k[i] = nextInt()
		for j := 0; j < k[i]; j++ {
			a[i][j] = nextInt()
		}
	}

	f := map[int]int{}
	for i := 0; i < m; i++ {
		f[i+1] = 0
	}

	for i := 0; i < n; i++ {
		for j := 0; j < k[i]; j++ {
			b := f[a[i][j]]
			f[a[i][j]] = b + 1
		}
	}

	for i := 0; i < m; i++ {
		if f[i+1] == n {
			ans++
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int n,a,s[2];
priority_queue<int> q;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a,q.push(a);
    for(int i=1;i<=n;i++){a=q.top();q.pop();s[i&1]+=a;}
    cout<<s[1]-s[0];
    return 0;
}

Measured memory_bytes: 256