akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

struct edge{ll to, cost;};
vector<vector<edge>> G(100005);
vector<ll> Djikstra(ll n, ll start){
    //小さい順に取り出す
    priority_queue<pll, vector<pll>, greater<pll>> que;

    vector<ll> min_dist(n+1);
    fill(ALL(min_dist), LINF); 

    min_dist[start] = 0;
    //firstは距離、secondは頂点番号
    que.push(make_pair(0, start));

    while(!que.empty()){
        pll top = que.top();
        que.pop();

        ll v = top.second;

        //既により短い経路があるのなら更新しない
        if(min_dist[v] < top.first)continue;

        rep(i, G[v].size()){
            edge e = G[v][i];
            //最短慶経路を更新できる場合、更新し格納
            if(min_dist[e.to] > min_dist[v] + e.cost){
                min_dist[e.to] = min_dist[v] + e.cost;
                que.push(make_pair(min_dist[e.to], e.to));
            }
        }
    }

    return min_dist;
}

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

    rep(i, n-1){
        ll u, v, w;
        cin >> u >> v >> w;
        u--, v--;

        G[u].push_back(edge{v, w});
        G[v].push_back(edge{u, w});
    }

    vector<ll> dist = Djikstra(n, 0);
    rep(i, n){
        if(dist[i] & 1)cout << 1 << endl;
        else cout << 0 << endl;
    }
}

Measured memory_bytes: 11356
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const int MAXN = 1e5 + 10;
const int INF = 1e9 + 2;
const ld pi = acos(-1);

ll n, m = -1, L, a[MAXN];

int main() {

    faster();

    cin >> n >> L;

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }

    for(int i = 1; i + 1 <= n; ++i){
        if(a[i] + a[i + 1] >= L)
            m = i;
    }

    if(m == -1){
        cout << "Impossible";
        return 0;
    }

    cout << "Possible\n";

    for(int i = 1; i < m; ++i){
        cout << i << '\n';
    }
    for(int i = n - 1; i >= m; --i){
        cout << i << '\n';
    }

    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<stack>
#include<map>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int a[10],x=0,y=0;
    stack<pair<int,int> > log;
    for(int i=0; i<10; i++) cin >>a[i];
    for(int i=0; i<10; i++){
      if(x>a[i] && y<a[i]) y = a[i];
      else if(x<a[i] && y>a[i]) x = a[i];
      else if(x<a[i] && y<a[i]){
	log.push(make_pair(x,i));
	x = a[i];
      }
      else if(x>a[i] && y>a[i]){
	if(log.empty()){
	  cout <<"NO"<<endl;
	  break;
	}
	x = log.top().first;
	i = log.top().second;
	y = a[i];
	log.pop();
      }
      if(i == 9) cout <<"YES"<<endl;
    }
  }
  return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

a = make_divisors(n)
b = make_divisors(n-1)

ans = (len(b) - 1)
for i in a:
    x = n
    if i == 1:
        continue
    elif i == n:
        ans += 1
    else:
        while x % i == 0:
            x /= i
        if x % i == 1:
            ans += 1

print(ans)


Measured memory_bytes: 3316
abc_li = list(map(int,input().split()))
abc_li.sort()

if abc_li[0]%2 == abc_li[1]%2:
    print(int((abc_li[1] - abc_li[0])/2 + abc_li[2]-abc_li[1]))
else:
    print(int((2*abc_li[2]+1-abc_li[0]-abc_li[1])/2)+1)
    

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


int main() {
    string s;
    cin >> s;
    vector<int> vec(26, 0);
    for (int i = 0; i < s.size(); i++) {
        vec.at(s.at(i) - 'a')++;
    }

    for (int i = 0; i < vec.size(); i++) {
        if (vec.at(i) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n, flag = 0, a = 0;
    cin >> n;
    string now = "";
    string bf = "";
    string tmp = "";
    string word[n];
    string check[n];
    for(int i = 0; i < n; i++) cin >> word[i];

    bf = word[0][word[0].length() - 1];
    for(int i = 0; i < n - 1; i++){
        now = word[i + 1][0];
        if (bf != now) {flag = 1; break;}
        bf = word[i + 1][word[i + 1].length() - 1];
    }

    for(int i = 0; i < n - 1; i++){
        tmp = word[i];
        for(int j = i + 1; j < n; j++){
            if(tmp == word[j]) flag = 1;
        }
    }

    if (flag == 1) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
    }
}

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

int main(){
	int N;
	cin >> N;
	long long A,B,C,D;
	cin >> A >> B >> C >> D;
	
	long long diff_sum=B-A;
	
	for(int i=0;i<N;i++){
		long long diff_max=(N-1-i)*D-i*C;
		long long diff_min=(N-1-i)*C-i*D;
		if(diff_min<=diff_sum && diff_sum<=diff_max){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

int main()
{
    double height;
    double max = 0.0, min = 10000000;
    while( cin >> height )
    {
        if( max < height )
            max = height;
        if( min > height )
            min = height;
    }
    cout << max - min << endl;

    return 0;
}


Measured memory_bytes: 3276
N, M = map(int, input().split())

A = [input() for i in range(N)]
B = [input() for i in range(M)]


for i in range(N - M + 1):
        for j in range(N - M +1):
                flag = True
                for h in range(M):
                        for w in range(M):
                                if A[i+h][j+w] != B[h][w]:
                                        flag = False             
                                        break
                if flag == True:
                        print("Yes")
                        exit()
print("No")

Measured memory_bytes: 40176
import java.util.*;

public class Main{
  
  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    int x= sc.nextInt();
    
    int canBuy = x/100;
    int change = x%100 ;
    
    for(int i = 0; i < canBuy; i++){
      if(change >= 5){
        change -= 5;
      }else if(change >= 4){
        change -= 4;
      }else if(change >= 3){
        change -= 3;
      }else if(change >= 2){
        change -= 2;
      }else if(change >= 1){
        change -= 1;
      }
    }
    
    if(change == 0){
      System.out.println("1");
    }else{
      System.out.println("0");
    }
    
  }  
}

Measured memory_bytes: 35760
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);

    ll n,a,b; cin >> n >> a >> b;
    // vll a(n);
    // rep(i,n) cin >> a[n];
    // string s;cin >> s;
    bool ok = false;
    rng(i,a,b+1){
        if(i%n==0) {
            ok = true;
            break;
        }
    }

    // ll ans = 0;
    cout << (ok?"OK":"NG") << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

int main()
{
    int n; std::cin >> n;
    bool ok = false;
    while(n) {
        if (n % 10 == 9) {
            ok = true;
            break;
        }
        n /= 10;

    }

    std::cout << (ok ? "Yes" : "No") << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
long long int count(int l,int r);
long long int work[200000];
long long int a[200000];
int main(){
  int n;
  cin >> n;


  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  long long int ans=count(0,n);

  cout << ans << endl;
}

long long int count(int l,int r){



  if(r-l<3){
    if(a[r-1]<a[l]){
      long long int temp=a[l];
      a[l]=a[r-1];
      a[r-1]=temp;
      return 1;
    }else{
      return 0;
    }
  }else{
    int mid=(r+l)/2;

    long long int cl=count(l,mid);
    long long int cr=count(mid,r);
    int s=0;
    int t=0;

    long long int c=0;

    while(s<(mid-l) && t<(r-mid)){
      if(a[l+s]>a[mid+t]){
	work[s+t]=a[mid+t];
	c+=mid-l-s;
	t++;
      }else{
	work[s+t]=a[l+s];
	s++;
      }
    }
    while(l+s<mid){work[s+t]=a[l+s];s++;}
    while(mid+t<r){work[s+t]=a[mid+t];t++;}
    for(int i=0;i<r-l;i++){
      a[l+i]=work[i];
    }
    return cl+cr+c;
  }
}

Measured memory_bytes: 4288
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int D_MAX_V=2002;
const int D_v_size=2002;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
/*	for(int i=0;i<D_G[from].size();i++){
		if(to==D_G[from][i].t){
			D_G[from][i].c+=cap;
			return;
		}
	}*/
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
int c,d;
int x[1100];
int y[1100];

int N;

int p[11000];
int q[11000];
int at[11000];
int main(){
	int a,b;
	while(scanf("%d%d%d%d",&a,&b,&c,&d),a){
		c--;d--;
		N=a;
		for(int i=0;i<2002;i++){
			D_G[i].clear();
			D_level[i]=D_iter[i]=0;
		}
		for(int i=0;i<b;i++){
			scanf("%d%d",p+i,q+i);
			p[i]--;q[i]--;
			at[i]=D_G[p[i]].size();
			add_edge(p[i],q[i],1);
		}
		int v=max_flow(c,d);
		queue<int>Q;
		for(int i=0;i<a;i++)x[i]=y[i]=0;
		x[c]=1;
		Q.push(c);
		while(Q.size()){
			int now=Q.front();Q.pop();
			for(int i=0;i<D_G[now].size();i++){
				if(!x[D_G[now][i].t]&&D_G[now][i].c){
					x[D_G[now][i].t]=1;
					Q.push(D_G[now][i].t);
				}
			}
		}
		y[d]=1;
		Q.push(d);
		while(Q.size()){
			int now=Q.front();Q.pop();
			for(int i=0;i<D_G[now].size();i++){
				if(!y[D_G[now][i].t]&&D_G[D_G[now][i].t][D_G[now][i].r].c){
					y[D_G[now][i].t]=1;
					Q.push(D_G[now][i].t);
				}
			}
		}
		int ret=0;
		for(int i=0;i<b;i++){
			if(D_G[p[i]][at[i]].c==0)continue;
			if(x[q[i]]&&y[p[i]])ret++;
		}
		if(ret==0)printf("%d %d\n",v,ret);
		else printf("%d %d\n",v+1,ret);
	}
}

Measured memory_bytes: 1540
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  long double w,h,x,y;
  std::cin>>w>>h>>x>>y;

  std::cout<<std::setprecision(10)<<std::fixed;

  if(2*x==w&&2*y==h)std::cout<<w*h/2<<" "<<"1\n";
  else std::cout<<w*h/2<<" 0\n";

  return 0;
}



Measured memory_bytes: 256
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 a: u32 = read();
    let b: u32 = read();
    let ans = if (a * b) % 2 == 0 {"Even"} else {"Odd"};
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<assert.h>
#include<sstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define setIO(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
typedef long long ll;
typedef pair<int, int> pii;
const ll LINF = 1e18 + 7;
const int N = 55;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
//-------------head-------------
ll n, s;
ll f(ll b, ll n) {
	if (n < b)
		return n;
	return f(b, n / b) + n % b;
}
ll solve() {
	ll ret = -1, sn = floor(sqrt(n));
	if (n >= s) {
		ll d = n - s;
		for (ll b = 1, B = sqrt(d); b <= B; ++b)
			if (d % b == 0) {
				ll _b = b;
				if (_b + 1 > sn && d / _b == n / (_b + 1)) {
					if (ret == -1 || ret > _b + 1)
						ret = _b + 1;
				}
				_b = d / b;
				if (_b + 1 > sn && d / _b == n / (_b + 1)) {
					if (ret == -1 || ret > _b + 1)
						ret = _b + 1;
				}
			}
	}
	for (ll b = 2, B = sn; b <= B; ++b)
		if (f(b, n) == s) {
			if (ret == -1 || ret > b)
				ret = b;
			break;
		}
	if (n == s && ret == -1)
		ret = n + 1;
	return ret;
}
int main() {
	scanf("%lld%lld", &n, &s);
	printf("%lld", solve());
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int min(int *a, int n)
{
  int v = 1000000;
  for ( int i = 0; i < n; i++ )
    {
      if ( v > a[i] )
        {
          v = a[i];
        }
    }
  return v;
}

int max(int *a, int n)
{
  int v = -1000000;
  for ( int i = 0; i < n; i++ )
    {
      if ( v < a[i] )
        {
          v = a[i];
        }
    }
  return v;
}

long long sum(int *a, int n)
{
  long long v = 0;
  for ( int i = 0; i < n; i++ )
    {
      v += a[i];
    }
  return v;
}

int main()
{
  int a[10000];
  int n;
  
  cin >> n;

  for ( int i = 0; i < n; i++ )
    {
      cin >> a[i];
    }

  cout << min(a, n) << " " << max(a, n) << " " << sum(a, n) << endl;
  
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    string ans;
    string s; cin >> s;
    rep(i,s.size()){
        if(s[i]!='B') ans += s[i];
        else{
            if(ans.size()!=0){
                ans.pop_back();
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
xyh = [[int(i) for i in input().split()] for j in range(N)]

xyh.sort(key=lambda x: x[2])
l = xyh[-1]
Cx = 0
Cy = 0
for i in range(101):
    Cx = i
    for j in range(101):
        Cy = j
        H = abs(Cx - l[0]) + abs(Cy - l[1]) + l[2]
        for p in xyh:
            if p[2] != max(0, H - abs(Cx - p[0]) - abs(Cy - p[1])):
                break
        else:
            print(Cx, Cy, H)
            exit()
        


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=1e5+7;
typedef long long ll;
int n,Q,top=0;
ll q[N],f[N],yv[N];

void go(ll b,ll t){
	if(!b)return;
	int pos=lower_bound(q+1,q+top+1,b)-q-1;
	if(!pos)yv[b]+=t;
	else {
		ll k=b/q[pos];
		b-=k*q[pos];
		f[pos]+=k*t;
		
		go(b,t);
	}
}
int main(){
	scanf("%d%d",&n,&Q);
	q[++top]=n;
	rep(i,1,Q){ll x;
		scanf("%lld",&x);
		for(;x<=q[top];top--);
		q[++top]=x;
	}
	f[top]=1;
	rep2(i,top,2){
		go(q[i],f[i]);
		f[i]=0;
	}
	rep2(i,n,1)yv[i]+=yv[i+1];
	rep(i,1,q[1])
		printf("%lld\n",f[1]+yv[i]);
	rep(i,q[1]+1,n)puts("0");
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	int pay=0;
	while(pay<n) pay+=1000;
	
	cout<<pay-n<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#define INF 1000000000
#define MOD 1000000007
using namespace std;
using ll = long long;

// GDC
ll gcd(ll a, ll b) {
  if(b==0){
      return a;
  }else{
      gcd(b,a%b);
  }
}

int main() {    
    ll n;
    bool odd = false;
    bool even = false;
    cin >> n;
    ll ans;
    cin >> ans;
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        ans = gcd(ans,x);
    }
    cout << ans << endl;
} 


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

int main(){
  int a,b;
  cin >> a >> b;
  if (a+b>=a-b && a+b>=a*b){
    cout << a+b;
  } else if (a-b>=a+b && a-b>=a*b){
    cout << a-b;
  } else if (a*b>=a+b && a*b>=a-b){
    cout << a*b;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int a,b,c,x;
	cin>>a;cin>>b;cin>>c;cin>>x;
	int cnt=0;
	REP(i,0,a){
		REP(j,0,b){
			REP(k,0,c){
				if(x==(500*i + 100*j + 50*k)){
					cnt++;
				}
			}
		}
	}
	cout<<cnt;
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int a,b,x;
    cin>>a>>b>>x;
    if(a>x||(a+b)<x)
    cout<<"NO"<<endl;
    else
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;

ll t1, t2, a1, a2, b1, b2, ans;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(t1), read(t2), read(a1), read(a2), read(b1), read(b2);
    ll sa = t1 * a1 + t2 * a2, sb = t1 * b1 + t2 * b2;
    if (sa == sb) return printf("infinity\n"), 0;
    if (sa > sb) swap(sa, sb), swap(a1, b1), swap(a2, b2);
    if (a1 < b1) return printf("0\n"), 0;
    printf("%lld\n", t1 * (a1 - b1) / (sb - sa) * 2 + (t1 * (a1 - b1) % (sb - sa) != 0));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,s1,s2,s3;
	cin>>s;
	int k=s.size(),k1=(k-1)/2,k2=(k+3)/2;
	s2=s.substr(0,k1);
	s3=s.substr(k2-1);
	s1=s;
	reverse(s.begin(),s.end());
	//cout<<s<<" "<<s1<<" "<<s2<<" "<<s3;
	if(s==s1&&s2==s3)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a , b , c , k;
    cin >> a >> b >> c >> k;
    int ans = min(a , k);
    k -= min(a , k);
    k -= min(b , k);
    ans -= min(c , k);
    k -= min(c , k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
t = 0
def judge(x):
  s = 0
  for i in range(M):
    s += B[i]*x[i]
  s += C
  if s>0:
    return 1
  else:
    return 0
for a in A:
  t = t + judge(a)
print(t)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<string, int> a, pair<string, int> b){
    if(a.first<b.first) return true;
    else if(a.first==b.first && a.second>b.second)return true;
    else return false;
}
int main() {
	int n;
	cin>>n;
	vector<pair<string, int>>v,v1;
	for(int i=0;i<n;i++){
		string s;
		int x;
		cin>>s>>x;
		v.push_back({s,x});
		v1.push_back({s,x});
	}
	sort(v.begin(),v.end(),cmp);
	for(int i =0;i<n;i++){
		for(int j=0;j<n;j++){
			if(v[i].first==v1[j].first && v[i].second == v1[j].second)
				cout<<j+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    keyence2020b()
}

fun keyence2020b() {
    val n = readLine()!!.toInt()
    val xlList = (1..n)
        .map { readLine()!!.split(' ').map { it.toLong() }.let { Pair(it[0] - it[1], it[0] + it[1]) } }

    val sorted = xlList.sortedBy { it.second }

    var answer = 0L
    var currLeft = Long.MIN_VALUE

    for (i in 0 until n) {
        val xl = sorted[i]
        if (currLeft <= xl.first) {
            answer++
            currLeft = xl.second
        }
    }

    println(answer)
}


Measured memory_bytes: 84816
#include<stdio.h>
double MAX(double a,double b){return a<b?b:a;}
int main(){
  int n,m,i,j,k;
  double d[110][110],l[110][110],max;
  while(scanf("%d %d",&n,&m),n||m){
    for(i=0;i<110*110;i++)l[i/110][i%110]=0;
    for(i=0;i<100;i++)l[0][i]=1.0;
    for(i=0;i<n*n;i++)scanf("%lf",&d[i/n][i%n]);
    for(i=1;i<m;i++){
      for(j=0;j<n;j++){
	for(k=0;k<n;k++)l[i][k]=MAX(l[i][k],l[i-1][j]*d[j][k]);
      }
    }
    for(i=max=0;i<n;i++)max=MAX(max,l[m-1][i]);
    printf("%.2f\n",max);
  }
  return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

bool comp(const P& p1, const P& p2){
    return p1.second > p2.second;
}

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

    ll n;
    cin >> n;
    ll a, b;
    vector<P> p(n);
    REP(i, n){
        cin >> a >> b;
        p[i] = P{a, b};
    }
    sort(p.begin(), p.end(), comp);

    //REP(i, n)cout << p[i].first << " " << p[i].second << endl;
    
    ll t = p[0].second;
    REP(i, n - 1){
        t = min(p[i + 1].second, t - p[i].first);
    }
    t -= p[n - 1].first;
    if(t < 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

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

    string s; cin >> s;
    int sw = 0;

    for (int i = 1; i < s.size(); ++i) {
        if (s[i-1] != s[i]) ++sw;
    }

    cout << sw << endl;
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M, X;
    cin >> N >> M >> X;

    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));

    REP(i, N){
        cin >> C[i];
        REP(j, M){
            cin >> A[i][j];
        }
    }

    ll ans = INF;
    for (int bit = 0; bit < (1<<N); ++bit) {
        vector<ll> D(M, 0);
        ll temp = 0;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)){
                REP(j, M){
                    D[j] += A[i][j];
                }
                temp += C[i];
            }
        }
        bool flag = true;
        REP(i, M){
            if(D[i] < X){
                flag = false;
                break;
            }
        }
        if(flag){
            ans = min(ans, temp);
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;

class Main{

    boolean check(){
        Scanner sc = new Scanner(System.in);
        Pair[] D = new Pair[6];

        for ( int i = 0; i < 6; i++ ) {
            D[i] = new Pair(0, 0);
            D[i].first = sc.nextInt();
            D[i].second = sc.nextInt();
            if ( D[i].first > D[i].second) {
                int tmp = D[i].first;
                D[i].first = D[i].second;
                D[i].second = tmp;
            }
        }
        Arrays.sort(D, new Comparator<Pair>(){
                public int compare(Pair a, Pair b){
                    if ( a.first == b.first ) return a.second - b.second;
                    return a.first - b.first;
                }
            });
        for ( int i = 0; i < 6; i+=2){
            if ( D[i].first == D[i+1].first && D[i].second == D[i+1].second ) D[i/2] = D[i];
            else return false;
        }

        return D[0].first == D[1].first && D[0].second == D[2].first && D[1].second == D[2].second;
    }

    void solve(){
        if ( check() ) System.out.println("yes");
        else System.out.println("no");
    }

    class Pair{
        public int first;
        public int second;

        Pair (int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    public static void main(String[] args){ new Main().solve(); }
}




Measured memory_bytes: 26372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, x;
  cin >> a >> b;
  x = a + b;
  if(x%2 == 0){
  cout << x/2 << endl;
  }else{
  cout << x/2 + 1 << endl;
  };
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int a, b;
    scan(a, b);

    int ans;
    if (b % a == 0) {
        ans = a + b;
    }
    else {
        ans = b - a;
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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; }

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


int main()
{
    string s;
    cin>>s;
    string ans;
    for(int i=0; i<s.size(); i++)
    {
     if(s[i]=='0') ans+='0';
     else if(s[i]=='1') ans+='1';
     else if(ans.size()>0) ans = ans.substr(0,ans.size()-1);
    }
    cout<<ans<<endl;
}

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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

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

    for(int i = 1;i<=9;i++) {
        for(int j = 1;j<=9;j++) {
            if(i*j == n) {
                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";
    
}

Measured memory_bytes: 256
h,w = map(int,input().split())

import numpy as np
dp = np.zeros((h,w),np.int32)
s = np.full((h,w),'.',np.str)
for H in range(h):
    S = input()
    for W in range(w):
        s[H][W] = S[W]
        own = s[H][W]
        if H==0 and W==0: dp[H][W] = 0 if own=='.' else 1
        elif H==0: dp[H][W] = dp[H][W-1]+1 if s[H][W-1]=='.' and own=='#' else dp[H][W-1]
        elif W==0: dp[H][W] = dp[H-1][W]+1 if s[H-1][W]=='.' and own=='#' else dp[H-1][W]
        else:
            dp[H][W] = min(dp[H][W-1], dp[H-1][W])
            if own=='#':
                if s[H][W-1]=='.' and s[H-1][W]=='.': dp[H][W] += 1
                elif s[H][W-1]=='#' and s[H-1][W]=='.': dp[H][W] = min(dp[H][W-1], dp[H-1][W]+1)
                elif s[H][W-1]=='.' and s[H-1][W]=='#': dp[H][W] = min(dp[H][W-1]+1, dp[H-1][W])
print(dp[h-1,w-1])

Measured memory_bytes: 12488
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static int[] X = new int[4];
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String S = in.readLine();

		X[0] = Integer.parseInt(String.valueOf(S.charAt(0)));
		X[1] = Integer.parseInt(String.valueOf(S.charAt(1)));
		X[2] = Integer.parseInt(String.valueOf(S.charAt(2)));
		X[3] = Integer.parseInt(String.valueOf(S.charAt(3)));


		System.out.println(op(0,new String[3],X[0]));
	}

	public static String op(int idx,String[] op,int sum){
		if(idx==3){
			if(sum==7){
				return X[0]+op[0]+X[1]+op[1]+X[2]+op[2]+X[3]+"=7";
			}else{
				return null;
			}
		}
		op[idx]="+";
		String ans = op(idx+1,op,sum+X[idx+1]);
		if(ans!=null){
			return ans;
		}
		op[idx]="-";
		return op(idx+1,op,sum-X[idx+1]);

	}
}


Measured memory_bytes: 22996
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n= int(input())
bd = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c= map(int,input().split())
    bd[a-1].append((b-1,c))
    bd[b-1].append((a-1,c))
q,k= map(int,input().split())
cost = [0] * n
def dfs(curnode,pre,addcost):
    for abr in bd[curnode]:
        if abr[0]!=pre:
            cost[abr[0]]=addcost+abr[1]
            dfs(abr[0],curnode,addcost+abr[1])
dfs(k-1,-1,0)
for i in range(q):
    x,y= map(int,input().split())
    print(cost[x-1]+cost[y-1])

Measured memory_bytes: 135728
#include<bits/stdc++.h>
#define maxn 105
using namespace std;
int xe,ye;
short n,m,ans,a[maxn][maxn],p=0,np=1,dp[2][maxn][maxn][maxn];
char c[maxn][maxn];
void inline upd(short& x,short y){
	if(x<y){x=y;if(y>ans)ans=y;}
}
int inline z(int i,int j,int k,int l){
	return a[k][l]-a[i-1][l]-a[k][j-1]+a[i-1][j-1];
}
int inline cal1(int w,int h,int x,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(ye>1+_h)return 0;
	else return z(max(l,xe-_w+l-1),x,min(r,xe+l-1),x);
}
int inline cal2(int w,int h,int y,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(xe>1+_w)return 0;
	else return z(y,max(l,ye+l-_h-1),y,min(r,ye+l-1));
}
int inline cal3(int w,int h,int x,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(ye<h)return 0;
	else return z(max(l,xe-_w+l-1),x,min(r,xe+l-1),x);
}
int inline cal4(int w,int h,int y,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(xe<w)return 0;
	else return z(y,max(l,ye-_h+l-1),y,min(r,ye+l-1));
}
int main(){
//	freopen("in.txt","r",stdin);
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		scanf("%s",c[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			a[i][j]=(c[i][j]=='o')+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			if(c[i][j]=='E')xe=i,ye=j;
		}
	dp[np][1][1][m]=ans=1;
	for(int k=n;k>=1;--k,swap(p,np))for(int l=m;l>=1;--l)
		for(int i=1;i<=n-k+1;++i)for(int j=1;j<=m-l+1;++j)if(dp[np][i][j][l]){
			int x=dp[np][i][j][l];
//			printf("{%d,%d,%d,%d,%d}\n",i,j,k,l,x);
			upd(dp[np][i][j+1][l-1],x+cal1(k,l,j,i,i+k-1));
			upd(dp[p][i+1][j][l],x+cal2(k,l,i,j,j+l-1));
			upd(dp[np][i][j][l-1],x+cal3(k,l,j+l-1,i,i+k-1));
			upd(dp[p][i][j][l],x+cal4(k,l,i+k-1,j,j+l-1));
			dp[np][i][j][l]=0;
		}
	printf("%d",ans-1);
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int n;
double x[15];
string  s[15];

int main(void)
{
	cin >> n;
	for(int i = 1; i<= n; i++){
		cin >> x[i] >> s[i];
	}
	
	double ans = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == "JPY") ans += x[i];
		else ans += x[i] * 380000;
	}
	printf("%.11f\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 1e5 + 1;

int n, m;
vector <int> v[MAXN];
int dp[MAXN];
int sol;

int rek(int cvor){

    if (dp[cvor] != -1) return dp[cvor];

    for (int i = 0; i < v[cvor].size(); i++){
        dp[cvor] = max(dp[cvor], rek(v[cvor][i])+1);
    }

    if (dp[cvor] == -1) dp[cvor] = 0;

    return dp[cvor];

}

int main(){

    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        v[x].pb(y);
    }
    for (int i = 0; i < n; i++) dp[i] = -1;

    for (int i = 0; i < n; i++){
        if (dp[i] == -1) rek(i);
        sol = max(sol, dp[i]);
    }

    cout << sol;

    return 0;

}


Measured memory_bytes: 8192
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n,w,r = map(int,input().split())#n:頂点数　w:辺の数
lis=LI()
d = [[float("inf")]*n for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    x-=1
    y-=1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
#print(warshall_floyd(d))
#インデックスで与えられていることに注意
d=warshall_floyd(d)
#print(d)
z=permutations(lis,r)
mn=inf
for s in z:
    u=list(s)
    dis=0
    for i in range(r-1):
        dis+=d[u[i]-1][u[i+1]-1]
    #print(dis)
    if dis<mn:
        mn=dis
print(mn)

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

using namespace std;
#define ll long long int
const int MAXN = 1e5 + 5;

void solve(){
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;
    int x, y, z; char p;
    set<int> S[26];
    for(int i = 0; i < n; ++i){
        S[s[i] - 'a'].insert(i);
    }
    while(q--){
        cin >> x;
        if( x == 1){
            cin >> y >> p;
            y--;
            int curr = s[y] - 'a';
            int req = p - 'a';
            S[curr].erase(S[curr].find(y));
            S[req].insert(y);
            s[y] = p;
        } else {
            cin >> y >> z;
            y--;z--;
            //now iterate over all 26 char
            int diff = 0;
            for(int i = 0; i < 26; ++i){
                if(S[i].empty()) continue;
                auto it1 = S[i].lower_bound(y);
                auto it = S[i].end();
                it--;
                if(*it < y) continue;
                if( *it1 <= z and *it1 >= y){
                    diff++;
                }
            }
            cout << diff << '\n';
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while(t--)
		solve();
}


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

using namespace std;

int main(){
	long long ans = 0;
	int N, K; cin >> N >> K;
	vector<long long> a(N), S1(N+1, 0), S2(N+1, 0);
	for(int i = 0; i < N; ++i){
		cin >> a[i];
		S1[i+1] = S1[i] + a[i];
		S2[i+1] = S2[i] + max(0LL, a[i]);
	}
	for(int i = 0; i + K <= N; ++i){
		int left = i, right = i + K;
		long long res = (S2[left] - S2[0]) + max(0LL, S1[right] - S1[left]) + (S2[N] - S2[right]);
		ans = max(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;


int lp;
vi a, all, loop;
vector<bool> visited;
void dfs_a(int i) {
    if (visited[i]) {
        lp = i;
        return;
    }
    visited[i] = true;
    all.emplace_back(i);
    dfs_a(a[i]);
}
void dfs_l(int i) {
    if (visited[i]) {
        lp = i;
        return;
    }
    visited[i] = true;
    loop.emplace_back(i);
    dfs_l(a[i]);
}

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

    int N;
    ll K;
    cin >> N >> K;

    a.resize(N);
    REP(i, N) {
        cin >> a[i];
        a[i]--;
    }
    visited = vector<bool>(N, false);
    dfs_a(0);
    visited = vector<bool>(N, false);
    dfs_l(lp);

    if (all.size() > K) {
        cout << all[K]+1 << endl;
    } else {
        int l = all.size() - loop.size();
        int idx = (K-l)%loop.size();
        cout << loop[idx]+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 11900
n,l=map(int,input().split()) #指定された数の文字列を受け取る
s=sorted([input() for i in range(n)])#s[i]にn回分文字列を代入する。さらにその後ソートをする。勝手に辞書順になる

print(*s,sep="")#sの中のすべての文字列を表示。この時""で表示

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  int ans=S.size()/2;
  for(auto c:S)if(c=='p')ans--;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int M = 0;
    int S = 0;
    int temp;
    for(int i = 0; i < N; i++){
        cin >> temp;
        S += temp;
        if (temp > M)
            M = temp;
    }
    if (M< S - M)
        cout <<"Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, S);
  ll ans = 0;
  for (int i = 1; i * 2 < (int)S.length(); ++i) {
    if (S.substr(0, i) == S.substr(i, i)) ans = i * 2;
  }
  print(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,C;cin>>n>>C;
	ll x,y,z;
	vector<vector<ll>> a(C + 1,vector<ll>(100001,0LL));
	vector<vector<ll>> v(C + 1,vector<ll>(100001,0LL));
	for(int i = 0; i < n; i++) {
		cin>>x>>y>>z;
		a[z][x] += 1;
		a[z][y+1] -= 1;
	}
	for(int i = 1; i <= C; i++) {
		for(int j = 0; j < a[i].size() - 1; j++) {
			v[i][j + 1] = v[i][j] + a[i][j + 1];
			// if (v[i][j + 1] > 1){
			// 	v[i][j + 1] = 1;
			// } 
		}
	}
	int res = 0;
	for(int j = 1; j < 100001; j++) {
		int ans = 0;
		for(int i = 1; i <= C; i++) {
			if (v[i][j] >0){
				ans++;
			}
		}
		res = max(res,ans);
	}
	// for(auto i = a.begin(); i != a.end(); i++) {
	// 	cout << i->fs <<" " << i->sc.fs <<" " << i->sc.sc << endl;
	// }
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 49648
import java.util.*
fun readint()=readLine()!!.toInt()
fun readll()=readLine()!!.toLong()
fun readstring()=readLine()!!
fun readlint()=(readLine()!!.split(" ").map{it.toInt()}).toIntArray()
fun readlll()=(readLine()!!.split(" ").map{it.toLong()}).toLongArray()

fun solve() {
    val (n, k) = readlint();
    val s = readstring();
    var pre = mutableListOf<Int>();
    pre.add(0);
    var lst = 0;
    for (i in 1..(s.length-1)){
        if (s[i] == 'C' && s[i - 1] == 'A') {
            lst++;
        }
        pre.add(lst);
    }
    repeat(k) {
        val (l, r) = readlint();
        println(pre[r-1] - pre[l-1]);
    }
}
fun main(args: Array<String>) {
    val t = 1;
    repeat(t) {
        solve();
    }
} 

Measured memory_bytes: 75644
#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 << "Right" << endl;
  else cout << "Balanced" << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  
  for (int k = 0; k < N; k++){
    cin >> card.at(k);
  }
  
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  
  int Apoint = 0;
  int Bpoint = 0;
  
  for (int i = 0; i < N; i +=2){
    //Alice
    Apoint += card.at(i);
    
    //Bob
    if ((i + 1) >= N){
      break;
    }
    else{
      Bpoint += card.at(i + 1);
    }
  }
  
  //cout << Apoint << endl;
  //cout << Bpoint << endl;
  //output
  cout << (Apoint - Bpoint) << endl;
}

Measured memory_bytes: 256