akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(x,n) for(int i=x; i < n; i++)



int main() {
	int N;
	cin >> N;
	double ans = (double)N / 2 + 0.5;
	cout << (int)ans << endl;
}

Measured memory_bytes: 256
def generate_rand(n):
    num_digit = 4
    result = []
    for i in range(10):
        temp = str(n**2)
        temp = '0' * (8 - len(temp)) + temp
        result.append(int(temp[2:-2]))
        n = result[-1]
    return result

for i in range(int(raw_input())):
    n = int(raw_input())
    print "Case %d:" % (i + 1)
    for r in generate_rand(n):
        print r

Measured memory_bytes: 4228
#include <stdio.h>

int main(){

    int x, y, z, num, den, quant;

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

    num = (x-(2*z));
    den = y+z;

    if (num%den == 0)
        quant = num/den;

    else if (num%den != 0) {
        if ((num%den) >= y) {
            quant = (num/den) + 1;
        }
        else
            quant = num/den;
    }

    printf("%d\n", quant);

    return 0;
}


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair
#define clamp(v,lo,hi) min(max(v,lo),hi)

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }

const ll MOD=1000000007LL;

int solve(int a, int b, int k){
    vi w;
    for (int n=100; n>=1; --n){
        if (a % n == 0 && b % n == 0) w.pb(n);
    }
    return w[k-1];
}

int main() {
    int a,b,k; cin >> a>>b>>k;
    cout << solve(a,b,k) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	
	long long num;
	scanf("%lld", &num);
	char name[100] ={0};
	int i = 0;
	num--;

	while(num >= 0){
	 	name[i] = num%26 + 'a';
	 	num /= 26;
		i++;
		num--;				
	}
	int len = strlen(name);
	
	for(int j=len-1;j>=0;j--){
		printf("%c", name[j]);
	}	
	return 0;
}

Measured memory_bytes: 1648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,ans=0;
  cin>>n;
  vector<int> a(n);
  for(i=0;i<n;i++) cin>>a.at(i);
  for(i=0;i<n;i++) ans+=a.at(i)-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 3560
// B - Lucas Number
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vl L(N+1); L[0] = 2; L[1] = 1;
	rp(i, 2, N+1) L[i] = L[i-1] + L[i-2];
	cout<< L[N] <<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextString()
	b := nextString()
	c := nextString()
	fmt.Printf("%s%s%s\n", string(a[0]), string(b[0]), string(c[0]))
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;
using ll = long long;

ll x, y;
ll a = 1e9 + 7;

void input(){
  cin >> x >> y;
}

ll dp[1000005];
ll fact(ll num){
  
  
  dp[0] = 1;
  dp[1] = 1;
  for (int i = 2; i <= num; i++)
  {
    dp[i] = (dp[i - 1] * i) % a;
  }
  return dp[num];
}

/*
ll comb(ll num1, ll num2){
  if(num1 < num2 || num1 < 0 ||  num2 < 0){
    return 0;
  }else{
    ll v = fact(num1);
    ll w = fact(num2);
    ll z = fact(num1 - num2);
    //return ((fact(num1))/ ((fact(num2) * fact(num1 - num2)) % a));
    return v / ((w * z) % a);
    //return v;
    //return z;
  }
  
}
*/

ll comb(ll N_, ll C_) {
	const int NUM_=1400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[a % i] * (a - a / i) % a;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%a, factr[i]=factr[i-1]*inv[i]%a;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%a*factr[N_-C_]%a;
}

ll solve(){
  if(x + y == 0){
    return 1;
  }
  ll judge = abs(x - y);
  if((x + y) % 3 != 0){
    return 0;
  }
  
  ll count = ((x + y) / 3);
  //ll tmp = (count - abs(judge)) / 2;
  //ll flag = judge / 3;
  ll tmp = (2 * x - y) / 3;

  return comb(count, tmp);
  //return tmp;
}


int main(){
  input();
  cout << solve() << endl;
  
}


Measured memory_bytes: 34688
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector <int> a(n);
  vector <pair <int, int> > cb;
  for (int i = 0; i < n; i++) {
	  cin >> a[i];
	  cb.push_back(make_pair(a[i], 1));
	}

  for (int i = 0; i < m; i++) {
	  int b, c;
	  cin >> b >> c;
	  cb.push_back(make_pair(c, b));
	}
  sort(cb.begin(), cb.end(), greater <pair <int, int> >());
  vector <int> ans;
  for (int i = 0; i < cb.size(); i++) {
	  for (int j = 0; j < cb[i].second; j++) {
		  ans.push_back(cb[i].first);
		}
	  if (ans.size() >= n) {
		  break;
		}
	}
  long long answer = 0;
  for (int i = 0; i < n; i++) {
	  answer += ans[i];
	}
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3824
N,W = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

dp = [{0:0} for i in range(N+1)]
for i,(w,v) in enumerate(src):
    for w0,v0 in dp[i].items():
        if w0 not in dp[i+1]:
            dp[i+1][w0] = v0
        else:
            dp[i+1][w0] = max(dp[i+1][w0], v0)
        if w0+w > W: continue
        if w0+w not in dp[i+1]:
            dp[i+1][w0+w] = v0+v
        else:
            dp[i+1][w0+w] = max(dp[i+1][w0+w], v0+v)
print(max(dp[-1].values()))


Measured memory_bytes: 655600
# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))
ans = {}
#各番号がいくつずつあるのかを整理
#keyに番号、valueにその番号が書かれてあるボールの数
for i in range(n):
    if not s[i] in ans:
        ans[s[i]] = 1
    else:
        ans[s[i]] += 1
#iC2の総和
answer = 0
for i,j in ans.items():
    answer += j*(j-1)//2
#answer-nC2+(n-1)C2 = answer-n+1
#nはans[s[i]],よって以下の出力で求められる
for i in range(n):
    print(answer-ans[s[i]]+1)


Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll s,c,ans=0;cin>>s>>c;
  if(2*s>c) ans=c/2;
  else ans=s+(c-2*s)/4;
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void)
{
   int i, f1=0, f2=1;
   char s[101];

   scanf("%s",s);

   i=strlen(s);

   while((s[f1]!='L')&&(f1<i))
      f1=f1+2;

   while((s[f2]!='R')&&(f2<i))
      f2=f2+2;

   if((i<=f1)&&(i<=f2))
      printf("Yes\n");

   else
      printf("No\n");
   return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    int x = A + B;
    int y = A - B;
    int z = A * B;
    
    cout << max(max(x, y), z) << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


answers = "Left Balanced Right".split()
A, B, C, D = fetch_int_input()

left = A + B
right = C + D
if left > right:
    id = 0
elif left < right:
    id = 2
else:
    id = 1

print(answers[id])


Measured memory_bytes: 38384
#include <cstdio>

using namespace std;

int main()
{
	int n, p[100000] = {}, i, tmp, c = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	for (i = 0; i < n; i++) {
		if (p[i] == i + 1) {
			if (i != n - 1) {
				tmp = p[i];
				p[i] = p[i + 1];
				p[i + 1] = tmp;
				c++;
			}
			else {
				tmp = p[i];
				p[i] = p[i - 1];
				p[i - 1] = tmp;
				c++;
			}
		}
    }

	printf("%d\n", c);

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,ans,j,p,i;
    cin>>a>>b>>c;
    i=a/(b+c);
    j=a%(b+c);
    ans=b*i+min(j,b);
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=5e5+7;
const int mod=998244353;
const double pi=3.1415926535897932384;
double isp=1e-13;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}//要求MOD为质数
ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return a;}ll ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
ll getInv(int a,int mod){ll x,y;ll d=exgcd(a,mod,x,y);return d==1?(x%mod+mod)%mod:-1;}//求a在mod下的逆元，不存在逆元返回-1，不要求MOD为质数
int n,c[MX],a[MX],ans[MX];
void upd(int pos,int val)
{
    for(int x=pos;x<=n;x+=x&-x)
        c[x]+=val;
}
int Sum(int pos)///从0位置到pos位置的区间和
{
    int ans=0;
    for(int x=pos;x;x-=x&-x)
        ans+=c[x];
    return ans;
}
unordered_map<int,int>vis;
vector<pair<int,int>>mp[MX];
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  int q;
  cin>>n>>q;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=q;i++)
  {
       int l,r;
       cin>>l>>r;
       mp[r].push_back(make_pair(l,i));
  }
  for(int i=1;i<=n;i++)
  {
      //cout<<vis[a[i]]<<endl;
      if(vis[a[i]])upd(vis[a[i]],-1);
      upd(i,1);
      vis[a[i]]=i;
      for(auto x:mp[i])
      {
          int l=x.first;
          ans[x.second]=Sum(i)-Sum(l-1);
      }
  }
  for(int i=1;i<=q;i++)
  {
      cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 51048
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    while(cin>>a>>b>>c){
        if(a+b>=c)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<bitset>
#include<queue>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
const int maxn = 100+50;
const int maxm = 4e5 + 10;
const int inf_max = 0x3f3f3f;
using namespace std;
typedef long long ll;
ll a,b,k;
int main()
{
    cin>>a>>b>>k;
    ll cur;
    if(k >= b) cur = b - 1;
    else cur = k;
    cout<<((a * cur) / b - a * (cur / b))<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	map<int,ll> cnt;
	int N,M;
	cin >> N >> M;
	rep(i,N){
		int x;
		cin >> x;
		cnt[-x]++;
	}
	rep(i,M){
		int n,x;
		cin >> n >> x;
		cnt[-x] += n;
	}
	ll ans = 0;
	rep(i,N){
		int x = cnt.begin()->fs;
		ans += x;
		cnt[x]--;
		if(cnt[x] == 0) cnt.erase(x);
	}
	cout << -ans << endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long ll;
#define NP next_permutation
#define MP make_pair

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n = 5;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 1e9;

  rep(i,n){
    int time = 0;
    rep(j,n){
      if(j == i) continue;
      time += a[j];
      while(time % 10 != 0){
        time ++;
      }
    }
    time += a[i];
    ans = min(ans, time);
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
N, K = map(int, input().split())
H = list(map(int, input().split()))

tmp = [10 ** 12 for _ in range(N)]
tmp[0] = 0
tmp[1] = abs(H[1] - H[0])

for i in range(2, N):
    for k in range(1, K+1):
        if i - k >= 0:
            tmp[i] = min(tmp[i], tmp[i - k] + abs(H[i] - H[i - k]))
        else:
            break
print(tmp[N-1])

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

int eat_cnt[33];

int main() {
    int N, M;
    cin >> N >> M;
    int K, A;
    for (int i = 0; i < N; i++) {
        cin >> K;
        for (int j = 0; j < K; j++) {
            cin >> A;
            eat_cnt[A]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < 33; i++) {
        if (eat_cnt[i] == N) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int n, DP[1<<16][17], cost_set2vertex[1<<16][16];
vector<int> submasks[1<<16], cost_set2set[1<<16];
vector<ii> adj[20];


int dp(int mask, int v){

    if(mask == (1<<n)-1){
        if(v == n-1)    return 0;
        return MOD;
    }
    int &ans = DP[mask][v];
    if(ans != -1)   return ans;

    ans = MOD;

    //move to next vertex
    for(auto it : adj[v]){
        if((mask >> it.ff) & 1) continue;
        ans = min(ans, cost_set2vertex[mask][it.ff]-it.ss + dp(mask|(1<<it.ff), it.ff));
    }

    //consume a new set but stay at v
    int complement = ((1<<n)-1) ^ mask;
    for(int i=0;i<(int)submasks[complement].size();i++){
        ans = min(ans, cost_set2set[complement][i] + dp(mask|submasks[complement][i], v));
    }

// cout<<"DP "<<mask<<" "<<v<<" returns "<<ans<<endl;
    return ans;
}



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

    int m;
    cin>>n>>m;
    while(m--){
        int a, b, c;
        cin>>a>>b>>c;
        a--;    b--;
        adj[a].pb(ii(b, c));
        adj[b].pb(ii(a, c));
    }

    for(int mask=0;mask<(1<<n);mask++)
        for(int v=0;v<n;v++)
            for(auto it : adj[v])
                if((mask >> it.ff) & 1)
                    cost_set2vertex[mask][v] += it.ss;

    for(int mask=1;mask<(1<<n);mask++){
        int complement = ((1<<n)-1) ^ mask;
        for(int submask=mask;submask>0;submask=(submask-1)&mask){
            submasks[mask].pb(submask);
            int tot = 0, maxi = 0;
            for(int i=0;i<n;i++)
                if((complement >> i) & 1){
                    tot += cost_set2vertex[submask][i];
                    maxi = max(maxi, cost_set2vertex[submask][i]);
                }
            cost_set2set[mask].pb(tot - maxi);
        }
    }


    memset(DP, -1, sizeof(DP));
    cout<<dp(1<<0, 0);
    return 0;
}








Measured memory_bytes: 125568
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll sum;
ll diff=101;//１０の倍数でない最小の整数　ない場合は１０１

int main(){
	ll n;
	cin >> n;
	ll s[n];
	cinf(s,n);
	rep(i,n){
		sum+=s[i];
		if(s[i]%10!=0){
			if(diff>s[i])
				diff=s[i];
		}
	}
	if(sum%10==0){
		if(diff!=101)
			sum-=diff;
		else
			sum=0;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3596
#include<iostream>
    #include<cstdio>
    #include<math.h>
    #include<string>
    #include<algorithm>
    #include<functional>
    #include<vector>
    #include<set>
    #include<map>
    #define INF 999999
    #define EPS 1.0e-6
     
    using namespace std;
     
    typedef long long ll;
    typedef pair<int, int> P;
     
    int n;
     
    int main()
    {
    	cin >> n;
    	int l, r;
    	int num = 0;
    	for (int i = 0; i < n; i++) {
    		cin >> l >> r;
    		num += r - l + 1;
    	}
    	cout << num << endl;
    	return 0;
    }

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  //ll n; cin>>n;
  ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  string s; cin >> s;
  s[b-1]=s[b-1]+'a'-'A';
  ll result = 0;
  ll buf = 0;
  bool judge = true;
  cout<<s<<endl;

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  char a;
  cin >> a;

  if ('A' <= a && a <= 'Z') cout << "A" << endl;
  if ('a' <= a && a <= 'z') cout << "a" << endl;
}


Measured memory_bytes: 3620
#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;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ll m,f,r;
	while ((m+f+r)!=-3) {
		cin>>m>>f>>r;
		if ((m+f+r)!=-3) {
			if ((m<0) or (f<0)) {
				cout<<"F"<<endl;
			}
			else {
				ll sum=m+f;
				if (sum>=80) {
					cout<<"A"<<endl;
				}
				else {
					if (sum>=65) {
						cout<<"B"<<endl;
					}
					else {
						if (sum>=50) {
							cout<<"C"<<endl;
						}
						else {
							if (sum>=30) {
								if (r>=50) {
									cout<<"C"<<endl;
								}
								else {
									cout<<"D"<<endl;
								}
							}
							else {
								cout<<"F"<<endl;
							}
						}
					}
				
				}
				
				
			}
		}
	}
}
	




Measured memory_bytes: 3080
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var s = cin.ReadLine;
            var count = 0;
            var temp = 0;
            for (var i = 0; i < s.Length; i++) {
                if (s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T') {
                    temp = 0;
                } else {
                    temp++;
                }
                
                if (count < temp) {
                    count = temp;
                }
            }

            WriteLine(count);
        }

        private double MultipleCeil(double value, double multiple) {return Math.Ceiling(value / multiple) * multiple;}

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

vvi adj;
vi des, des_back, asc, asc_back;

void dfs1(int v, int p) {
    i64 dif = 0;
    vi ds_back;
    for (int s: adj[v]) {
        if (s != p) {
            dfs1(s, v);
            dif = max(dif, des_back[s] - des[s]);
            ds_back.push_back(des_back[s] + 2);
        }
    }
    i64 all = accumulate(ds_back.begin(), ds_back.end(), 0);
    des_back[v] = all;
    if (p == -1 || adj[v].size() > 1) dif++;
    des[v] = all - dif;
}

void dfs2(int v, int p) {
    using ii = pair<i64, int>;
    vector<ii> difs = {ii(0, 0)};
    for (int s: adj[v]) {
        if (s != p) {
            difs.push_back(ii(des_back[s] - des[s], s));
            asc_back[s] = des_back[v] - des_back[s] + asc_back[v];
        }
    }
    sort(difs.begin(), difs.end(), greater<>());
    for (int s: adj[v]) {
        if (s != p) {
            asc[s] = min(des_back[v] - des_back[s] + asc[v] - 1, asc_back[v] - difs[difs[0].second == s].first + des_back[v] - des_back[s] - 1 - (difs.size() > 2));
            dfs2(s, v);
        }
    }
}

int main() {
    int n;
    cin >> n;
    adj = vvi(n);
    des = vi(n, 1e18);
    des_back = vi(n, 1e18);
    asc = vi(n, 1e18);
    asc_back = vi(n, 1e18);

    for (int i = 0; i < n - 1; i++) {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        adj[s].push_back(t);
        adj[t].push_back(s);
    }

    dfs1(0, -1);
    // for (int i = 0; i < n; i++) {
    //     cout << "des" << i + 1 << " " << des[i] << endl;
    //     cout << "des_back" << i + 1 << " " << des_back[i] << endl;
    // }

    asc[0] = 0;
    asc_back[0] = 0;
    dfs2(0, -1);
    // for (int i = 0; i < n; i++) {
    //     cout << "asc" << i + 1 << " " << asc[i] << endl;
    //     cout << "asc_back" << i + 1 << " " << asc_back[i] << endl;
    // }

    for (int i = 0; i < n; i++) {
        cout << min(des[i] + asc_back[i], des_back[i] + asc[i]) << endl;
    }
}


Measured memory_bytes: 30252
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 100
#define MAX_E 1000
using namespace std;
struct edge {
	int to, cap, rev;
	edge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {};
};

int V, E;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void AddEdge(int from, int to, int cap) {
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}

void BFS(int s) {
	fill(level, level + V, -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (size_t i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int DFS(int v, int t, int f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = DFS(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int Dinic(int s, int t) {
	int flow = 0;
	while (true) {
		BFS(s);
		if (level[t] < 0) return flow;
		fill(iter, iter + V, 0);
		int f;
		while ((f = DFS(s, t, INF)) > 0) {
			flow += f;
		}
	}
}

int main()
{
	cin >> V >> E;
	for (int i = 0, u, v, c; i < E; i++) {
		cin >> u >> v >> c;
		AddEdge(u, v, c);
	}
	cout << Dinic(0, V - 1) << endl;
	return 0;
}

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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;

int f(int init, int num, int k){
    if(num == 0)
        return init;
    return min(f(2*init,num-1,k), f(init+k,num-1,k));
}

void solve(){
    int n,k;
    cin>>n>>k;
    cout<<f(1,n,k)<<'\n';
}

int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}


Measured memory_bytes: 256
#112_D
N,M=map(int,input().split())
#M//N以下のMの約数の最大
divisors=[]
for i in range(1,int(M**.5)+1):
    if M%i==0:
        divisors.append(i)
        if i!=(M//i):
            divisors.append(M//i)
Ans=1
for x in sorted(divisors):
    if M//N>=x:
        Ans=x
    else:
        break
print(Ans)

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int H = Integer.parseInt(in.next());
            int W = Integer.parseInt(in.next());
            int ans = 0;

            String a[] = new String[H];
            for (int i = 0; i < H; i++) {
                a[i] = in.next();
            }

            boolean r[] = new boolean[H];
            boolean c[] = new boolean[W];

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (a[i].charAt(j) == '#') {
                        r[i] = true;
                        c[j] = true;
                    }
                }
            }

            for (int i = 0; i < H; i++) {
                if (r[i]) {
                    for (int j = 0; j < W; j++) {
                        if (c[j]) {
                            out.print(a[i].charAt(j));
                        }
                    }
                    out.println();
                }
            }
        }

    }
}



Measured memory_bytes: 23152
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

template <typename T>
T ceilDiv(T a, T b) {
    return a > 0 && b > 0 ? (a + b - 1) / b : a / b;
}

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll l = ceilDiv((-a + b + c * (n - 1)), (c + d));
    ll r = (-a + b + d * (n - 1)) / (c + d);

    if (l > r || r < 0 || l > n - 1)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,x;
int i,j;
bool k[1000001];
bool l[1000001];
int p[30];

int max(int a,int b){return a>b?a:b;}

int comp(const void *a,const void *b){
	int *p=(int*)a;
	int *q=(int*)b;
	return *q-*p;
}

int main(){
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0&&x==0)return 0;
		for(i=0;i<=x;i++)k[i]=false;
		for(i=0;i<=x;i++)l[i]=true;
		for(i=0;i<n;i++){
			scanf("%d",&p[i]);
			k[p[i]]=true;
		}
		for(i=1;i<=x;i++){
			if(k[i]){
				for(j=0;j<n;j++)if(i+p[j]<=x)k[i+p[j]]=true;
			}
		}
		int ans=0;
		for(i=2;i<=x;i++){
			if(l[i]){
				for(j=1;j*i<=x;j++){
					l[j*i]=false;
				}
				if(k[i])ans=max(ans,i);
			}
		}
		if(ans==0)printf("NA\n");
		else printf("%d\n",ans);
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    string s;
    cin >> s;

    if (s.substr(0,4) == "YAKI") {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N + 1);
  vector<int64_t> score(N+1);
  for (int64_t i = 1; i <= N; ++i) {
    cin >> A[i];
    if (i >= K + 1) {
      if (A[i] > A[i - K]) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 6360
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
    #define vec(n) vector<int>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

  
  
    int main(){
      int n;
      cin >> n;
      string s;
      cin >> s;

      auto Se = vec(n);
      auto Sw = vec(n);
      if(s[0] == 'E')Se[0] = 1;
      else Sw[0] = 1;
      REP(i,1,n){
        if(s[i] == 'E')Se[i] = Se[i-1]+1;
        else Se[i] = Se[i-1];
      }
      REP(i,1,n){
        if(s[i] == 'W')Sw[i] = Sw[i-1]+1;
        else Sw[i] = Sw[i-1];
      }
      

      int mn = 300000;
      rep(i,n){
        int now = Sw[i-1]+Se[n-1]-Se[i];
        if(!i)now = Se[n-1]-Se[i];
        mn = min(mn,now);
      }
      cout << mn <<endl;
    }

    


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  cin >> k;
  queue<ll> q;
  for (int i = 1; i < 10; ++i) q.push(i);
  for (int i = 0; i < k - 1; ++i) {
    ll x = q.front();
    q.pop();
    for (int j = -1; j < 2; ++j) {
      ll y = x % 10 + j;
      if (y >= 0 && y <= 9) q.push(x * 10 + y);
    }
  }
  cout << q.front() << endl;
  return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
// #define mod  1000000007
#define N 102
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
const int inf = (int)1e18 + 10;
int a[N];
signed main(){
 int n , cnt = 0 , t = 0;
  cin >> n;
  for(int i = 1 ; i <= n ; i++){
    cin >> a[i];
    if(a[i] == i)
      cnt++;
    else 
      t++;
  }
  if(cnt == n){
    cout << "YES\n";
    return 0;
  }
  else if (t  > 2){
    cout << "NO\n";
    return 0;
  }

  for(int i = 1 ; i<=n ; i++){
    if(a[i] != i){
         int x = a[i];
         if(a[x] == i){
          cout << "YES\n";
          return 0;
         }
    }
  }

  cout << "NO\n";

}	

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

int main()
{
  int seven = 0, five = 0;

  for (int i = 0; i < 3; ++i) {
    int n; cin >> n;
    
    if (n == 7) ++seven;
    else if (n == 5) ++five;
  }

  cout << (five == 2 && seven == 1 ? "YES\n" : "NO\n");
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 200005;
typedef long long lld;
lld n;
lld a[N];
lld st[N], top = 0;
lld lef[N], rig[N];
lld ans = 0;
int main() {
//	freopen("data.in", "r", stdin);
	scanf("%lld", &n);
	for(lld i = 1; i <= n; i++) 
		scanf("%lld", &a[i]);
	for(lld i = 1; i <= n; i++) {
		if(a[i] > st[top]) {
			st[++top] = a[i]; 
			continue;
		}
		while(a[i] < st[top]) {
			rig[st[top]] = i;
			top--;
		}
		st[++top] = a[i];
	}
	while(top > 0){
		rig[st[top]] = n + 1;
		top--;
	}
	top = 0;
	for(lld i = n; i >= 1; i--) {
		if(a[i] > st[top]) {
			st[++top] = a[i];
			continue;
		}
		while(a[i] < st[top]) {
			lef[st[top]] = i;
			top--;
		}
		st[++top] = a[i];
	}
	while(top > 0) {
		lef[st[top]] = 0;
		top--;
	}
	for(lld i = 1; i <= n ;i++) {
		lld left = i - lef[a[i]];
		lld right = rig[a[i]] - i;
		lld tmp = 1ll * right * left;
		ans += 1ll * tmp * a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>

int rot[5][7] = {
{0,1,2,3,4,5,6},{0,2,6,3,4,1,5},{0,4,2,1,6,5,3},{0,3,2,6,1,5,4},{0,5,1,3,4,6,2}};
int assign[7];		// サイコロの1～6の各面に割り当てる数字
int tr['Z'];

void dice_init(int *a)
{
	int i;
	int t[5] = {0,'N','E','W','S'};
	for (i = 1; i <= 6; i++) assign[i] = a[i];
	for (i = 1; i <= 4; i++) tr[t[i]] = i;
}

char s[102];
int main()
{
	int i, k1, k2;
	int a[7], dice[2][7];
	char *p;

	for (i = 1; i <= 6; i++) scanf("%d", a+i);
	dice_init(a);
	scanf("%s", p=s);
	for (i = 1; i <= 6; i++) dice[0][i] = rot[0][i];
	for (k1 = 0, k2 = 1; *p; k1 = k2, k2 = !k2) {
		for (i = 1; i <= 6; i++) dice[k2][i] = dice[k1][rot[tr[*p]][i]];
		p++;
	}
	printf("%d\n", assign[dice[k1][1]]);
	return 0;
}



Measured memory_bytes: 2076
// Problem : C - Traveling Salesman around Lake
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e9 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, k, arr[maxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> k >> n;
	REP(i, n) cin >> arr[i];
	int ans = inf;
	REP(i, n) {
		if (i > 0)
			ans = min(ans, k - arr[i] + arr[i - 1]);
		else
			ans = min(ans,arr[n - 1] - arr[0]);
		if (i < n - 1)
			ans = min(ans, arr[i] + k - arr[i + 1]);
	}
	cout << ans << endl;
	return 0;
}
 


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

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];

void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    to[u].push_back({v, w});
    to[v].push_back({u, w});
  }
  dfs(0, 0);
  for (int i = 0; i < N; i++) cout << dist[i] % 2 << endl;
}

Measured memory_bytes: 11948
import java.util.Scanner;

    public class Main {

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);

            StringBuilder a = new StringBuilder(sc.next());
            StringBuilder b = new StringBuilder(sc.next());
            StringBuilder c = new StringBuilder(sc.next());
            System.out.print(a.charAt(0));
            System.out.print(b.charAt(0));
            System.out.print(c.charAt(0));
        }

    }

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                               \
  do {                                                                         \
    cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";                        \
    dump(__VA_ARGS__);                                                         \
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////


int main()
{
  ll n; cin >> n;
  ll q; cin >> q;

  dsu d(n);
  vector<int> ans;
  for (int i=0; i<q; i++){
    int t,u,v; cin>>t>>u>>v;
    if (t==0) d.merge(u, v);
    else ans.push_back(d.same(u, v));
  }
  for (auto v:ans) cout << v << endl;

  return 0;
}


Measured memory_bytes: 4476
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, K; cin >> N >> K;
    int ans = 1;
    rep(i, N)ans = min(ans * 2, ans + K);
    cout << ans << endl;
}

Measured memory_bytes: 3592
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

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

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let M: usize = sc.get();
    let mut digit = 0;
    let mut sum = 0;
    for _ in 0..M {
        let d: usize = sc.get();
        let c: usize = sc.get();
        sum += d * c;
        digit += c;
    }
    let init = 9 * digit + sum;
    let end = if sum % 9 == 0 { 9 } else { sum % 9 } + 9;
    let ans = (init - end) / 9;
    println!("{}", ans);
}


Measured memory_bytes: 4352