akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;


template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

map<string, LL> dp[101];

bool check(string s) {
  if (s[0] == 'A' && s[1] == 'G' && s[2] == 'C') return false;
  if (s[1] == 'A' && s[0] == 'G' && s[2] == 'C') return false;
  if (s[0] == 'A' && s[2] == 'G' && s[1] == 'C') return false;
  if (s[0] == 'A' && s[1] == 'G' && s[3] == 'C') return false;
  if (s[0] == 'A' && s[2] == 'G' && s[3] == 'C') return false;

  if (s[1] == 'A' && s[2] == 'G' && s[3] == 'C') return false;
  if (s[1] == 'A' && s[3] == 'G' && s[2] == 'C') return false;
  if (s[2] == 'A' && s[1] == 'G' && s[3] == 'C') return false;
  return true;
}

int main() {
  int N; cin >> N;
  vector<string> cs = {"A", "C", "G", "T"};
  for (string c1: cs) {
    for (string c2 : cs) {
      for (string c3 : cs) {
        string s = c1 + c2 + c3;
        if (s == "AGC" || s == "ACG" || s == "GAC") continue;
        dp[3][s] = 1LL;
      }
    }
  }

  for (int i = 3; i < N; ++i) {
    for (auto [s, v] : dp[i]) {
      for (string c : cs) {
        string s2 = s + c;
        if (check(s2)) {
          dp[i + 1][s2.substr(1)] += v;
          dp[i + 1][s2.substr(1)] %= kMod;
        }
      }
    }
  }

  LL cnt = 0;
  for (auto [s, v] : dp[N]) {
    cnt = (cnt + v) % kMod;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4000
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = o.getValue(0);
    var As = o.getArray(1);

    var results = [];
    for(var i = 0; As.length > i; i++) {
        results[As[i]] = i + 1;
    }

    return results.join(" ");
}


Measured memory_bytes: 43988
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int in[N], pref[N];
signed main()
{
#ifdef home
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    int n, k, ans = 0, sum = 0;
    ;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> in[i];
    for (int i = 1; i <= n; i++)
    {
        pref[i] = pref[i - 1] + in[i];
    }
    for (int i = n; i > k; i--)
        if (in[i] > 0)
            sum += in[i];
    for (int l = 1, r = l + k - 1; r <= n; l++, r++)
    {
        ans = max(ans, sum);
        ans = max(ans, sum + pref[r] - pref[l - 1]);
        if (in[l] > 0)
            sum += in[l];
        if (r + 1 <= n && in[r + 1] > 0)
            sum -= in[r + 1];
    }
    cout << ans;
}

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();

	ll n,w;
	cin>>n>>w;

	pair<int, int> item[n];

	int maxv = 0;
	loop(i,0,n)
	{
		int wt, val;
		cin>>wt>>val;
		
		maxv += val;
		item[i] = {wt,val};
	}

	ll dp[maxv+1] = {};
	loop(i,1,maxv+1)
		dp[i] = 1e12;

	loop(i,0,n)
	{
		int wt = item[i].f;
		int val = item[i].s;

		for(int j = maxv; j>=val; j--)
			dp[j] = min(dp[j], dp[j-val] + wt);

		// cout<<dp[100],nl;
	}

	for(int i = maxv; i>=0; i--)
	{
		if(dp[i]<=w)
		{
			cout<<i,nl;
			break;
		}
	}
	


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

Measured memory_bytes: 1024
path = []
for _ in range(3):
    path.append(list(map(int, input().split())))
count = [0] * 4
for i in range(3):
    for j in range(2):
        count[path[i][j]-1] += 1
count.sort()
if count == [1,1,2,2]:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int N;
vector<bool> ans;
vector<int> H;

void f(int n, int m){
  if(H[n] >= H[m]){
    ans[m] = false;
  }
  if(H[n] <= H[m]){
    ans[n] = false;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int M; cin >> N >> M;
  ans.assign(N, true);
  H.assign(N, 0);
  REP(i, N){
    cin >> H[i];
  }
  REP(i, M){
    int a, b; cin >> a >> b; a--; b--;
    f(a, b);
  }
  int res = 0;
  REP(i, N){
    if(ans[i]) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 3712
N = int(input())
L = list(map(int,input().split()))
ans = 0
k = 0
l = 0
for i in range(N-1):
  if L[i] == i+1:
    k = L[i]
    l = L[i+1]
    L[i] = l
    L[i+1] = k
    ans += 1
    k = 0
    l = 0
if L[N-1] == N:
  ans += 1
print(ans)

Measured memory_bytes: 13880
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

template <typename T>
T pow(T a, ll n, ll MOD) {
    a %= MOD;
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll N;
    cin >> N;
    N *= 2;
    ll M;
    M = N;
    vector<ll> fac;
    vector<ll> ps;
    for(ll i = 2; i*i <= N; i++){
        if(M%i == 0){
            ll cur = 1;
            while(M%i == 0){
                cur *= i;
                M /= i;
            }
            ps.push_back(i);
            fac.push_back(cur);
        }
    }
    if(M != 1) {
        ps.push_back(M);
        fac.push_back(M);
    }
    int sz = fac.size();
    ll ans = N-1;
    if(N == 2){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 0; i < (1<<sz); i++){
        ll x = 1, y = 1;
        for(int j = 0; j < sz; j++){
            if(i&(1<<j)) x *= fac[j];
            else y *= fac[j];
        }

        // cout << x << ' ' << y << endl;
        
        if(y < x){
            if(y == 1) continue;
            // x*inv % y = 1にしたい
            ll p = 1;
            ll inv = 1;
            for(int j = 0; j < sz; j++){
                if(!(i&(1<<j))) {
                    p *= (fac[j]/(ps[j]))*(ps[j]-1);
                }
            }
            inv = pow<ll>(x, p-1, y);
            ll K = (x*inv)-1;
            // cout << K << ':' << x*inv << ' ' << inv << endl;
            ans = min(ans, K);
        }else{
            if(x == 1) continue;
            // y*inv % x = -1にしたい
            ll inv = 1;
            ll p = 1;
            for(int j = 0; j < sz; j++){
                if((i&(1<<j))) {
                    p *= (fac[j]/(ps[j]))*(ps[j]-1);
                }
            }
            inv = pow<ll>(y, p-1, x);
            inv *= -1; inv += x; inv %= x;
            ll K = (y*inv);
            // cout << K << "->" << inv << endl;
            ans = min(ans, K);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  int sum = 700;
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s.at(i) == 'o') {
      sum += 100;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
b = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[float("inf")] * (pow(10, 5) + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
  for j in range(pow(10, 5) + 1):
    if dp[i][j] != float("inf"):
      dp[i + 1][j + b[i][1]] = min(dp[i][j] + b[i][0], dp[i + 1][j + b[i][1]])
    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
res = 0
for j in range(pow(10, 5) + 1):
  if dp[-1][j] <= W:
    res = max(res, j)
print(res)

Measured memory_bytes: 313000
#include <iostream>
    #include <string>
    using namespace std;
     
    int main()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
        
        int a,s,d,f;
        cin >> a >> s >> d >> f;
        
        cout << (((a+s) < (d+f)) ? "Right" : (((a+s) > (d+f))? "Left" : "Balanced"))<< endl;
    }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if((x + r) <= W && (x - r) >= 0 && (y + r) <= H && (y - r) >= 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}

#[fastout]
fn main() {
  input! {
     N:usize,
     XYP:[(i64,i64,i64);N]
  }
  let N: usize = N;
  let mut XYP: Vec<(i64, i64, i64)> = XYP;
  let inf = std::i64::MAX;
  let mut xkyori = vec![vec![inf; N]; 2usize.pow(N as u32)];
  let mut ykyori = vec![vec![inf; N]; 2usize.pow(N as u32)];

  for pat_i in 0..2usize.pow(N as u32) {
    for i in 0..N {
      // そうでない場合、すべての路線への距離の最小値を求める。
      let (x, y, p) = XYP[i];
      xkyori[pat_i][i] = x.abs();
      ykyori[pat_i][i] = y.abs();
      for j in 0..N {
        if pat_i >> j & 1 == 1 {
          xkyori[pat_i][i] = min(xkyori[pat_i][i], (x - XYP[j].0).abs());
          ykyori[pat_i][i] = min(ykyori[pat_i][i], (y - XYP[j].1).abs());
        }
      }
      xkyori[pat_i][i] *= p;
      ykyori[pat_i][i] *= p;
    }
  }
  debug!(xkyori);
  debug!(ykyori);
  // ここまでで前処理。xkyoriとykyoriが計算できた。
  let mut ans = vec![inf; N + 1];
  // 3進数を計算。0=線路なし,1=X路線, 2=Y路線
  for pat_i in 0..3usize.pow(N as u32) {
    // pat_xとpat_yの作成
    let mut k = 0;
    let mut pat = pat_i;
    let mut pat_x = 0;
    let mut pat_y = 0;
    for i in 0..N {
      match pat % 3 {
        1 => {
          pat_x += 2usize.pow(i as u32);
          k += 1;
        }
        2 => {
          pat_y += 2usize.pow(i as u32);
          k += 1;
        }
        _ => (),
      }
      pat = pat / 3;
    }
    let mut t_ans = 0;
    for i in 0..N {
      t_ans += min(xkyori[pat_x][i], ykyori[pat_y][i]);
    }
    ans[k] = min(ans[k], t_ans);
  }
  for a in ans {
    println!("{}", a);
  }
}


Measured memory_bytes: 11784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;


public class Main {

    public static void main(String[] args) throws IOException {
        //Input 整数を入力する
        BufferedReader br =
                new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int n = Integer.parseInt(str);
        //借金
        double loan = 100000;

        //入力した整数後の借金の残高を求める
        //1週間とは限らないから、ループの処理を入れる
        for(int i=1; i<=n; i++){
           //借金に5%の利子を加える
           loan = loan * 1.05;
           //借金の1000円未満を切り上げる
           BigDecimal bd = new BigDecimal(String.valueOf(loan));
           //第1引数が0の場合、小数第一位を切り上げ(参考)
           //1000未満は切り上げのため、第1引数を-3とし、百の位を切り上げする
           loan = bd.setScale(-3, BigDecimal.ROUND_UP).doubleValue();
        }
        //表示する際に、小数点を含む形で出力しないために、借金をint型のresultに格納する
        int result = (int) loan;
        System.out.println(result);
    }
}

Measured memory_bytes: 16988
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int[] ar =new int[n];
        int cnt=0;
        for(int i=0;i<n;i++){
            ar[i]=scn.nextInt();
            if(ar[i]!=i+1) cnt++;
        }
        if(cnt<=2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21716
#include<stdio.h>

int main(void)
{
  while(1){
  int m1,m2;
  int a=0,b=0,c=0;
  int margin;

  scanf("%d",&m1); scanf("%d",&m2);
  if(m1==0 && m2==0 )break;

  margin=m2-m1;

  while(1){
    if( margin<1000 )break;
    c++;
    margin-=1000;
  }
  while(1){
    if( margin<500 )break;
    b++;
    margin-=500;
  }
  while(1){
    if( margin<100 )break;
    a++;
    margin-=100;
  }
  printf("%d %d %d\n",a,b,c);
  }
  return 0;
}

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

int main(){
  int n, count;
  cin >> n;
  count = 0;
  vector<int> number(n);
  for(int i = 0; i < n; i++){
    cin >> number.at(i);
  }
  for(int i = 0; i < n; i++){
    if(number.at(i) != i + 1) count++;
  }
  if(count < 3) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
s=input()
dp=[1 for i in range(max(10,s+1))]
for i in range(3):
    dp[i]=0
for i in range(s+1):
    for j in range(3,i):
        dp[i]+=dp[i-j]
    dp[i]%=(10**9+7)
print dp[s]%(10**9+7)


Measured memory_bytes: 68108
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define maxn 100005
using namespace std;
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
typedef long long ll;
ll n,m,ans[maxn],father[maxn],sizee[maxn],height[maxn];
void init()
{
    for(int i=0;i<=maxn;i++)
    {
        father[i]=i;
        sizee[i]=1;
    }
}
int findd(int node)
{
    if(father[node]!=node) father[node]=findd(father[node]);
    return father[node];
}
bool same(int a,int b)
{
    return findd(a)==findd(b);
}
void uni(int a,int b)
{
    if(same(a,b))return;
    int roota=findd(a);
    int rootb=findd(b);
    if(sizee[roota]>sizee[rootb])
    {
        father[rootb]=roota;
        sizee[roota]+=sizee[rootb];
    }
    else
    {
        father[roota]=rootb;
        sizee[rootb]+=sizee[roota];
    }
}
int main()
{
    while(cin>>n>>m)
    {
        init();
        vii edge;
        ans[m]=(n*(n-1))/2;
        for(int i=0;i<m;i++)
        {
            int a,b;
            cin>>a>>b;
            edge.pb(mp(a,b));
        }
        reverse(edge.begin(),edge.end());
        for(int i=0;i<m;i++)
        {
            ans[m-i-1]=ans[m-i];
            if(findd(edge[i].first)==findd(edge[i].second)) continue;
            else
            {
                ans[m-i-1]-=sizee[findd(edge[i].first)]*sizee[findd(edge[i].second)];
                uni(edge[i].first,edge[i].second);
            }
        }
        for(int i=1;i<=m;i++) cout<<ans[i]<<"\n";
    }

}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    Int odd = 0;
    for (auto &a : A) odd ^= a;
    for (auto &a : A) a &= ~odd;
    int rank = 0;
    for (int i = 60; i >= 0; i--) {
        int pivot = -1;
        for (int j = rank; j < N; j++) {
            if (A[j] & (1LL << i)) {
                pivot = j;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[rank], A[pivot]);
        for (int j = rank + 1; j < N; j++) {
            if (A[j] & (1LL << i)) {
                A[j] ^= A[rank];
            }
        }
        rank++;
    }
    Int even = 0;
    for (int i = 0; i < rank; i++) {
        even = max(even, even ^ A[i]);
    }
    cout << even + (even | odd) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

/*


*/
#define max 2147483647


void merge(int *a,int left,int mid,int right){
        int n1 = mid - left;
        int n2 = right - mid;
        int L[n1+1],R[n2+1];
        int i;
        for(i=0;i<n1;i++){
            L[i] = a[left + i];
        }
        for(i=0;i<n2;i++){
            R[i] = a[mid + i];
        }
        L[n1]=max;
        R[n2]=max;
        int j=0,k=0;
        for(i=left;i<right;i++){
            if(L[j]<R[k]){
                a[i] = L[j];
                j++;
            }
            else{
                a[i] = R[k];
                k++;
            }
        }

}


void merge_sort(int *a,int left,int right){
    int middle;
    if(left + 1 < right){
        middle = (left + right)/2;
        merge_sort(a,left,middle);
        merge_sort(a,middle,right);
        merge(a,left,middle,right);
    }
}


int main(void){
    int n,x;
    scanf("%d %d",&n,&x);
    int a[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    merge_sort(a,0,n);
    int counter = 0;
    long long now = x;
    for(i=0;i<n;i++){
        now -=a[i];
        if(now>=0){
            counter++;
        }
    }
    if(now>0){
        counter--;
    }
    printf("%d\n",counter);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll h, n;
    cin >> h >> n;
    vector<pair<ll, ll>> m(n);
    ll a, b;
    ll mx = 0;
    REP(i, n) {
        cin >> a >> b;
        m[i] = {a, b};
        chmax(mx, a);
    }
    vl dp(h + mx + 1, LINF);
    dp[0] = 0;
    REP(i, h + mx + 1) REP(j, n) {
        if (i - m[j].first >= 0) chmin(dp[i], dp[i - m[j].first] + m[j].second);
    }
    ll ans = LINF;
    for (int i = h; i < h + mx + 1; i++) chmin(ans, dp[i]);
    cout << ans << endl;
}


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

int N;
vector<int> S, T;

int main(void) {
	string str, ans;

	S.resize(26, 50);
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> str;
		T.clear();
		T.resize(26, 0);
		for (int p = 0; p < (int)str.length(); ++p)
			++T[(int)(str[p] - 'a')];
		for (int c = 0; c < 26; ++c) {
			if (S[c] == 0)
				continue;
			if (T[c] < S[c])
				S[c] = T[c];
		}
	}
	ans = "";
	for (int c = 0; c < 26; ++c) {
		if (S[c] != 0)
			ans += string(S[c], 'a' + (char)c);
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define MAX_N 100000
int N, Q; vector<int>vec, vec2;
string S[MAX_N][3], T[4];
bool Find(string U, string V) {
	int X = U.size(), Y = V.size();
	for (int i = 0; i <= X - Y; i++) {
		string W = U.substr(i, Y);
		if (W == V) {
			return true;
		}
	}
	return false;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i][0] >> S[i][1] >> S[i][2];
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		if (i >= 1) { cout << endl; }
		cin >> T[0] >> T[1] >> T[2] >> T[3];
		vec.clear(); vec2.clear();
		for (int j = 0; j < N; j++) {
			vec.push_back(j);
		}
		vec2 = vec;
		if (T[0] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (Find(S[vec[j]][0], T[0]) == true) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2;
		if (T[1] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (Find(S[vec[j]][1], T[1]) == true) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2;
		if (T[2] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (S[vec[j]][2] >= T[2]) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2;
		if (T[3] != "*") {
			vec2.clear();
			for (int j = 0; j < vec.size(); j++) {
				if (S[vec[j]][2] <= T[3]) {
					vec2.push_back(vec[j]);
				}
			}
		}
		vec.clear(); vec = vec2; vec2.clear();
		for (int j = 0; j < vec.size(); j++) {
			cout << S[vec[j]][0] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int solve(int n,int m)
{
	if (n<m) return 0;
	if (n%m==0) return n/m;
	int t=n/m,p=(n-t*m)/(t+1);
	if (p) return solve(n-p*(t+1),m);
	else return solve(n-t-1,m);
}
int main()
{
	int n=read(),ans=0;
	for (int i=1;i<=n;i++) 
	{
		int x=read(),y=read();
		ans^=solve(x,y);
	}
	puts(ans?"Takahashi":"Aoki");
	return 0;
}


Measured memory_bytes: 3616
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        while(sc.hasNext()){
            double v = sc.nextDouble();
            int n=0;
            while(v>=9.8*Math.sqrt(5*n/4.9))n++;
            System.out.println(n+1);
        }
 
    }
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {
    ll N,M,i;
    cin >> N >> M;
    vector<ll> d;

    for(i=1; i*i<=M; i++)
        if(M%i == 0) {
            d.push_back(i);
            d.push_back(M/i);
        }
    sort(d.begin(), d.end(), greater<int>());

    for(int x: d)
        if(x*N <= M) {
            cout << x << endl;
            return 0;
        }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;


int main()
{
    int N,M;
    cin>>N>>M;
    vector<int>X(M),Y;
   
    for(int i=0;i<M;i++){
        cin>>X[i];
    }
     if(N>=M){
        cout<<0<<endl;
        exit(0);
    }
    sort(X.begin(),X.end());
    for(int i=1;i<M;i++){
        Y.push_back(abs(X[i]-X[i-1]));
    }
    sort(Y.begin(),Y.end());
    long long sum=0;
    for(int i=0;i<M-N;i++){
        sum+=Y[i];
    }
    cout<<sum<<endl;

}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
	int A, B = 0;
	cin >> A >> B;
	if ((A + B) % 2 == 0)
	{
		cout << ((A + B) / 2);
		return 0;
	}
	cout << "IMPOSSIBLE";
}



Measured memory_bytes: 256
x_1, y_1, x_2, y_2 = map(int, input().split())

dx = x_2 - x_1
dy = y_2 - y_1


x_3 = x_2 - dy
y_3 = y_2 + dx
  
x_4 = x_1 - dy
y_4 = y_1 + dx
print(str(x_3) + ' ' + str(y_3) + ' ' + str(x_4) + ' ' + str(y_4))

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int main(){
  int *a,n,i,j,k,key,*flag;

  scanf("%d",&n);
  a = (int *) malloc(n*sizeof(int) );
  flag = (int *) malloc(n*sizeof(int) );

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

  /* 素数ではない数を探して「key」から数を減らす */
  key=n;
  for(i=2;i<10001;i++){
    
    for(j=0;j<n;j++){
      if(a[j]==i)flag[j]=0;
      
      if(flag[j]){
	if(a[j]%i==0){
	  flag[j]=0;
	  key--;
	}
      }
    }
    if(i!=2)i++;
  }

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

  return 0;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a - mod; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

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


void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  string s;
  cin >> s;

  ll ans = 0;
  map<char, int> mp;
  mp['r'] = 0;
  mp['s'] = 1;
  mp['p'] = 2;
  vector<int> v(n); // 妥協したか
  rep(i, n) {
    if (i - k >= 0 && s[i] == s[i - k] && v[i - k] == 0) {
      v[i] = 1;
      continue;
    }

    // cout << (mp[s[i]] - 1 + 3) % 3 << endl;
    ans += a[(mp[s[i]] - 1 + 3) % 3];
  }
  cout << ans << endl;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
#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 Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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






int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = (1000-n%1000)%1000;

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


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

vec a(2002,0);
mat dp(2,vec(2001,-1));
ll dfs(bool xturn, ll num){
    if(dp[xturn][num] != -1) return dp[xturn][num];
    ll ans = abs(a[0] - a[num]);
    reps(i,1,num){
        ans = xturn ? max(ans, dfs(xturn^1, i)) : min(ans, dfs(xturn^1, i));
    }
    dp[xturn][num] = ans;
    return ans;
}
int main() {
    cin>>N>>H>>W;
    rep(i,N) cin>>a[N-1-i];
    a[N] = W;
    cout<<dfs(1,N)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;++i)

const int N=2005;
const int P=924844033;
int n,k,a[N],fac[N];
long long f[N][N][2][2];
bool vis[N];

int main() {
    scanf("%d%d",&n,&k);
    fac[0]=1;
    FOR(i,1,n) fac[i]=1LL*fac[i-1]*i%P;
    int tot=0;
    FOR(i,1,n) if(!vis[i]) for(int j=i;j<=n;j+=k) vis[j]=1,a[++tot]=j;
    f[0][0][0][0]=1;
    a[0]=-(1<<30);
    FOR(i,1,n) {
        f[i][0][0][0]=1;
        FOR(j,1,i) {
            f[i][j][0][0]=(f[i-1][j][1][0]+f[i-1][j][0][0]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][0])%P;
            f[i][j][0][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][1][0]+f[i-1][j-1][0][0])%P;
            f[i][j][1][0]=(f[i-1][j][0][1]+f[i-1][j][1][1]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][1])%P;
            f[i][j][1][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][0][1]+f[i-1][j-1][1][1])%P;
        }
    }
    int ans=0;
    FOR(i,0,n) {
        int sum=(f[n][i][0][0]+f[n][i][0][1]+f[n][i][1][0]+f[n][i][1][1])%P;
        if(i&1) (ans+=P-1LL*sum*fac[n-i]%P)%=P;
        else (ans+=1LL*sum*fac[n-i]%P)%=P;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 73504
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
char x='.',y='#';
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int a,b;
    scanf("%d%d",&a,&b);
    int i,j;
    printf("100 100\n");
    for (i=0;i<50;i+=2)
    {
        for (j=0;j<100;j+=2)
        {
            if (b>1)
            {
                printf("#");
                b--;
            }
            else
            {
                printf(".");
            }
            printf(".");
        }
        printf("\n");
        for (j=0;j<100;j++)
        {
            printf(".");
        }
        printf("\n");
    }
    a--;
    b--;
    for (i=0;i<50;i+=2)
    {
        for (j=0;j<100;j++)
        {
            printf("#");
        }
        printf("\n");
        for (j=0;j<100;j+=2)
        {
            if (a>0)
            {
                printf(".");
                a--;
            }
            else
            {
                printf("#");
            }
            printf("#");
        }
        printf("\n");
    }
    return 0;
} 


Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  var cnt = 0
  val l = new Array[Int](250001)
  val r = new Array[Int](250001)

  def merge(a:Array[Int],left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      cnt += 1
    }
  }

  def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] =
    if(h==0) l
    else scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)

  def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1
      w /= 2
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val l = getSortIndex(n)
    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(a,e._1,mid,e._2)
      }
    }
    merge(a,0,n/2,n)
    println(a.mkString(" "))
    println(cnt)
  }
}

Measured memory_bytes: 317000
#include <iostream>
#include <cstdio>
#include <string>

//#define PI 3.141592653589

using namespace std;



int main()
{
	int price;
	int change;
	int num;		//おつりの枚数
	
	while (1)
	{
		cin >> price;
		if (price == 0) break;
		change = 1000 - price;
		num = 0;
		num += change / 500;
		change %= 500;
		num += change / 100;
		change %= 100;
		num += change / 50;
		change %= 50;
		num += change / 10;
		change %= 10;
		num += change / 5;
		change %= 5;
		num += change / 1;
		cout << num << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
S = list(input())
N = len(S)
if N == 26:
    if S == list("zyxwvutsrqponmlkjihgfedcba"):
        print(-1)
    else:
        O = [0]*(N+1)
        for i in range(N):
            O[i] = ord(S[i])

        for i in range(N)[::-1]:
            co = [0]*N
            
            for j in range(1,25):

                for k in range(N):
                    co[k] = O[k]

                co[i] += j

                if co[i] > 122:
                    continue
                else:
                    if len(set(co[0:i+1])) == len(co[0:i+1]):
                        ans = co[0:i+1]
                        break

            else:
                continue
            break

        for i in range(len(ans)):
            ans[i] = chr(ans[i])

        cans = "".join(ans)
        print(cans)

else:
    #a97 z122
    O = [0]*(N+1)
    for i in range(N):
        O[i] = ord(S[i])

    for i in range(97,123):
        if i not in O:
            last = i
            break 
    
    O[N] = i

    for i in range(N+1):
        O[i] = chr(O[i])
    
    ans = "".join(O)
    print(ans)

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

int main() {
  int N;
  cin >> N;
  string c;
  cin >> c;
  int red = 0;
  int red_left = 0;
  for(int i = 0; i < N; i++){
    if(c.at(i) == 'R'){
      red++;
    }
  }
  for(int i = 0; i < red; i++){
    if(c.at(i) == 'R'){
      red_left++;
    }
  }
  cout << red - red_left << endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(dist(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
#define MAX_N 100010

struct edge {
  ll to, cost;
};

vector<edge> vertexEdge[MAX_N];
ll dist[MAX_N];
ll n;

void dijkstra(ll s){
  priority_queue<pll, vector<pll>, greater<pll>> que;
  fill(dist, dist+n, LLINF);
  dist[s] = 0;
  que.push(pll(0, s));
  while(!que.empty()){
    pll p = que.top();
    que.pop();
    ll v = p.SE;
    if(dist[v] < p.FI)
      continue;
    for(int i = 0; i < vertexEdge[v].size(); i++){
      edge e = vertexEdge[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        que.push(pll(dist[e.to], e.to));
      }
    }
  }
}

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

  cin >> n;

  ll a,b,c;
  REP(i, n-1){
    cin >> a >> b >> c;
    a--;
    b--;
    vertexEdge[a].push_back({b,c});
    vertexEdge[b].push_back({a,c});
  }

  ll q,k;
  cin >> q >> k;
  k--;
  vll x(q), y(q);
  REP(i, q){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }

  dijkstra(k);


  REP(i, q){
    ll a = x[i];
    ll b = y[i];
    cout << dist[a]+dist[b] << endl;
  }

}


Measured memory_bytes: 12656
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<vector>
#include<list>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
  int N;
  long T;
  cin >> N >> T;
  
  vector<long> t(N);
  rep(i, N)
    cin >> t[i];

  long total = 0;
  rep(i, N-1)
    total += min(t[i+1] - t[i], T);

  total += T;
  
  cout << total << endl;
  
  return 0;
}

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

int main() {
  int value1;
  int value2;
  
  int ans;
  int mod;
  
  cin >> value1 >> value2;
  
  mod = (value1 + value2) % 2;
  ans = (value1 + value2 - mod) / 2;
  
  if (mod > 0)
  {
    ans = ans + 1;
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;

ll dfs(ll cur, set<ll>& s, const vvl& d) {
  if (s.size() == 0) return 0;
  ll ans = INF;
  set<ll> s0 = s;
  for (auto& x : s) {
    // cout << x << endl;
    s0.erase(s0.find(x));
    ans = min(ans, d[cur][x] + dfs(x, s0, d));
    s0.insert(x);
  }
  return ans;
}

int main() {
  //
  ll n, m, R;
  cin >> n >> m >> R;
  vl r(R);
  vvl d(n, vl(n, INF));
  set<ll> s;
  rep(i, R) {
    cin >> r[i];
    r[i]--;
    s.insert(r[i]);
  }
  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    d[a][b] = min(d[a][b], c);
    d[b][a] = min(d[b][a], c);
  }
  rep(k, n) {
    rep(i, n) {
      rep(j, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
    }
  }

  set<ll> s0 = s;
  ll ans = INF;
  for (auto& x : s) {
    s0.erase(s0.find(x));
    ans = min(ans, dfs(x, s0, d));
    s0.insert(x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 760
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  string S,T;
  cin >> S >> T;
  int l = S.size();
  bool flag = true;
  rep(i,l){
    if(S.at(i)!=T.at(i))flag = false;
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(){
	int a[4], b[4], hit = 0, blow = 0, i, j;
	while(1){
		for(i = 0; i < 2; i++) scanf("%1d", &a[i]);
		if(a[0] == 0 && a[1] == 0) break;
		for(; i < 4; i++) scanf("%1d", &a[i]);
		for(i = 0; i < 4; i++) scanf("%1d", &b[i]);
		for(i = 0; i < 4; i++){
			for(j = 0; j < 4; j++){
				if(i == j){
					if(a[i] == b[j]) hit++;
				}
				else if(a[i] == b[j]) blow++;
			}
		}
		printf("%d %d\n", hit, blow);
		hit = 0;
		blow = 0;
	}
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int c[500], s[500], f[500];
	for(int i = 0; i < n - 1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i = 0; i < n - 1; i++){
		int now = 0;
		for(int j = i; j < n - 1; j++){
			// jからj + 1へ行く
			if(now < s[j]){
				now = s[j] + c[j];
			} else {
				now += (f[j] - (now % f[j])) % f[j] + c[j];
			}
		}
		cout << now << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
/*
	Author: Luis Manuel D�az Bar�n (LUISMO)
	Problem:
	Online Judge:
	Idea:
*/
#include<bits/stdc++.h>
// Types
#define ll long long
#define ull unsigned long long
// IO
#define sf scanf
#define pf printf
#define mkp make_pair
#define fi first
#define se second
#define endl "\n"

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e16 + 3;
const int mod = 1e9 + 7;
const int lim = 2e5 + 2;

int N;

ll ai, bi, ci;
ll dp[lim][3];

void solve()
{
    cin >> N;

    for(int i = 1; i <= N; i++)
    {
        cin >> ai >> bi >> ci;
        dp[i][0] = ai + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = bi + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = ci + max(dp[i-1][1], dp[i-1][0]);
    }

    ll answ = max(dp[N][0], max(dp[N][1], dp[N][2]));
    cout << answ;
}

void fastIO()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
}

void IO()
{
	if(fopen("d:\\lmo.in","r") != NULL)
	{
		freopen("d:\\lmo.in","r",stdin);
	}
	else if(fopen("/media/Beijing/lmo.in","r") != NULL)
	{
		freopen("/media/Beijing/lmo.in", "r", stdin);
	}
}

int main()
{
	IO();

	fastIO();

	solve();
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second
#define MOD 1000000007LL

using namespace std;
using pii=pair<int,int>;
using ll=long long;

ll fastpow(ll a, int b)
{
    ll ret=1;
    while(b!=0){
        if(b%2) ret=(ret*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return ret;
}

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

    int n,k;
    cin>>n>>k;

    vector<ll> dp(k+1);
    ll answer=0;
    for(int i=k; i>=1; i--){
        ll now=k/i;
        int tmp=n;
        now=fastpow(now,n);
        dp[i]=now;
        for(int j=2; j*i<=k; j++) dp[i]=(dp[i]-dp[j*i]+MOD)%MOD;
        answer=(answer+(((ll)i*dp[i])%MOD))%MOD;
    }
    cout<<answer;

    return 0;
}


Measured memory_bytes: 3916
#include <stdio.h>
int main(){
  int d,n;
  scanf("%d%d",&d,&n);
  if(n==100)n++;
  if(d==0)printf("%d",n);
  if(d==1)printf("%d",100*n);
  if(d==2)printf("%d",10000*n);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int a[100005],n;
long long s,cnt;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		if(a[i]!=0)
			s+=a[i];
		if(a[i]==0||i==n){
			cnt+=s/2;
			s=0;
		}
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
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; }


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

  int n;cin>>n;
  vec p(n);
  rep(i,n){
    cin>>p[i];
  }

  int num=p[0];
  int cnt=1;
  rep(i,n-1){
    if(num>=p[i+1]){
      cnt++;
      num=p[i+1];
    }else{
    }
  }

  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W,H,x,y;
  cin >> W >> H >> x >> y;
  int b=0;
  if(x+x==W&&y+y==H)b=1;
  cout << float(W)*float(H)/2.0f << ' '<< b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
    string s; cin >> s;
    int c0 = 0, c1 = 0;
    rep(i, sz(s)) {
        if (s[i] == '0') c0++;
        else c1++; 
    }
    int ans = 2*min(c0, c1);
    cout << ans << endl;
}

Measured memory_bytes: 512
package main

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

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

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`


				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	a, b, _, k := nextInt(), nextInt(), nextInt(), nextInt()

	ans := 0
	if k > a {
		ans = a
		k -= a
		if k > b {
			k -= b
			ans -= k
		}
	} else {
		//終わり
		ans = k
	}

	//fmt.Fprintln(out, "[DEBUG]", d)
	//fmt.Fprintln(out, "[DEBUG]", time.Now())
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 1796