akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int a[100010][3];

int dp[100010][3];

int main() {
    int n;
 	
  	cin >> n;
  
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k){
                    continue;
                }
                dp[i+1][k] = max(dp[i + 1][k], dp[i][j] + a[i][j]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < 3; i++){
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    
    return 0;
}


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

int N;
vector<int> P;
vector<int> X;

vector<int> g[1010];
int dp[1010];
int ans[1010];

void fail(){
    cout<<"IMPOSSIBLE"<<endl;
    exit(0);
}

int dfs(int now){
    int sum=0;
    vector<pair<int,int>> v;
    for(auto nex:g[now]){
        int tmp=dfs(nex);
        v.push_back(mkp(tmp,nex));
        sum+=tmp;
    }

    bitset<5001> bst;
    bst.set(0);
    for(int i=0;i<v.size();i++){
        int tar=v[i].second;
        bitset<5001> b1=(bst<<(X[tar]));
        bitset<5001> b2=(bst<<(dp[tar]-X[tar]));

        bst=b1|b2;
    }

    int dif=-1;
    for(int k=X[now];k>=0;k--){
        if(bst[k]){
            dif=X[now]-k;
            break;
        }
    }
    if(dif==-1) fail();

    return dp[now]=sum+dif;
}

int main(){
  cin>>N;
  P.resize(N);
  X.resize(N);
  for(int i=1;i<N;i++) cin>>P[i];
  for(int i=0;i<N;i++) cin>>X[i];

  for(int i=1;i<N;i++){
      P[i]--;
      g[P[i]].push_back(i);
  }

  dfs(0);
  cout<<"POSSIBLE"<<endl;

  return 0;
}


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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

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

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



// // 二分探索(最小値を出す問題は疑う)
// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < N; ++i){
// 		res += max(0ll, A[i]-x/F[i]);
//     }
//     return res <= K;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }

int main(){
string N;
cin >> N;
int len = N.length();

int sum = 0;
REP(i, len){
  sum += N.at(i) - '0'; 
}

cout << max((int)(N.size()-1) * 9 + N.at(0) -'0'- 1, sum) << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<utility>
#include<queue>
#include<stdio.h>
//#include<sys/time.h>
#include<random>
#include<fstream>
#define INF 2000000000
using namespace std;
typedef std::pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
int n,ans,cnt;
signed main(){
	cin>>n;
	for(int i=1;i<n;i++){
		ans+=n/i;
		if(n%i==0)ans--;
	}
	cout<<ans<<endl;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    unordered_map<char, int> right, left;
    REP(i, N) {
        if (right.count(S[i])) {
            right[S[i]]++;
        } else {
            right[S[i]] = 1;
        }
    }
    int ans = 0;
    REP(i, N-1) {
        if (left.count(S[i])) {
            left[S[i]]++;
        } else {
            left[S[i]] = 1;
        }
        right[S[i]]--;
        if (right[S[i]] == 0) right.erase(S[i]);
        int tmp = 0;
        for (auto item : left) {
            if (right.count(item.first)) tmp++;
        }
        ans = max(ans, tmp);
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main(void){
  long double a,b,c;
  cin >> a >> b >> c;
  long double eps = 1.0E-14;
  cout << ((sqrt(a) + sqrt(b) + eps < sqrt(c))?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
  char a[300], b[300];
  scanf("%s %s",a,b);
  strcat(a,b);
  int s=atoi(a);
  bool f=false;
  for (int i=1; i<=1000; i++) {
    for (int j=1; j<=1000; j++) {
      if (i*j==s && i==j) {
        f=true;
      }
    }
  }
  if (f) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int min = 200000000,max = -200000000;
    	long sum=0;
    	int n = sc.nextInt();
    	int a[]= new int[n+1];
    	for(int i=0;i<n;i++) {
    		a[i]=sc.nextInt();
    		min = Math.min(min, a[i]);
    		max = Math.max(max, a[i]);
    		sum += a[i];
    	}
    	System.out.printf("%d %d %d\n",min,max,sum);
    	
    }
}


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

int main() {
	int N, K;
	cin >> N >> K;
	vector<long double> p(N);
	for (int i = 0; i < N; i++) {
		double tmp;
		cin >> tmp;
		p.at(i) = ((1 + tmp) * tmp / 2) / tmp;
	}

	vector<long double> DP(N - K + 1);
	for (int i = 0; i < K; i++) {
		DP.at(0) += p.at(i);
	}
	long double ans = DP.at(0);
	for (int i = 1; i < N - K + 1; i++) {
		DP.at(i) = DP.at(i - 1) - p.at(i - 1) + p.at(i + K - 1);
		if (DP.at(i) > ans) ans = DP.at(i);
	}

	printf("%.10Lf\n",ans);
}

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

int N;
vector<int> p,q,v;
int a,b;

void perm(int i){
  static int n=1;
  if(i<N-1){
    for(int j=i;j<N;j++){
      int tmp=v.at(j);
      for(int k=j;k>i;k--){
        v.at(k)=v.at(k-1);
      }
      v.at(i)=tmp;
      perm(i+1);
      for(int k=i;k<j;k++){
        v.at(k)=v.at(k+1);
      }
      v.at(j)=tmp;
    }
  }else{
    if(v==p){
      a=n;
    }
    if(v==q){
      b=n;
    }
    n++;
  }
}

int main(){
  cin >> N;
  p.resize(N);
  q.resize(N);
  v.resize(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> q.at(i);
  }
  for(int i=0;i<N;i++){
    v.at(i)=i+1;
  }
  perm(0);
  cout << abs(a-b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
  int X; cin >> X;
  int pos = 0;
  int ans = 0;
  rep(i, 1, X + 2) {
    pos += i;
    if (pos >= X) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int chk(vector <int> v, int n) { //cout << n << endl;
	vector <int> c;
	for(int i = 1; i <= n; i++) c.push_back(i);
	int cnt = 0;
	do {
		++cnt;

		if(c == v) return cnt;
	}while(next_permutation(c.begin(), c.end()));
	return 0;

} 


int main() {
		

    	ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    	int n; cin >> n; vector <int> a, b;
    	for(int i = 1; i <= n; i++) {
    		int x; cin >> x;
    		a.push_back(x);
    	}
    	for(int i = 1; i <= n; i++) {
    		int x; cin >> x;
    		b.push_back(x);
    	}
    	cout << abs(chk(a, n) - chk(b, n)) << endl;
     	
}

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

#define pb push_back
#define loop(i,l,r) for(int i = (l); i < (r); i++)
#define rloop(i,r,l) for(int i = (r-1); i >= (l); i--)
#define refloop(x, v) for(auto& x : (v))
#define exists(m,e) if((m).find(e) != (m).end())
#define nexists(m,e) if((m).find(e) == (m).end())
#define sortaka(v) sort((v).begin(), (v).end())
#define rsort(v) sort((v).rbegin(), (v).rend())
#define lower_bound_index(v, x) (lower_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] >= x
#define upper_bound_index(v, x) (upper_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] > x
#define scanint(x) scanf("%d", &(x))
#define scanfloat(x) scanf("%f", &(x))
#define scanll(x) scanf("%lld", &(x))
#define scanchar(x) scanf("%c", &(x))
#define scanstring(x) scanf("%s", &(x))
#define printint(x) printf("%d", x)
#define printfloat(x) printf("%.9f", x)
#define printll(x) printf("%lld", x)
#define printchar(x) printf("%c", x)
#define printstring(x) printf("%s", x)
#define printintnewline(x) printf("%d\n", x)
#define printfloatnewline(x) printf("%.9f\n", x)
#define printllnewline(x) printf("%lld\n", x)
#define printcharnewline(x) printf("%c\n", x)
#define printstringnewline(x) printf("%s\n", x)
#define square(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))

typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<long long, long long>> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef vector<string> vs;
typedef vector<vector<pair<int, int>>> vvpii;
typedef vector<vector<pair<long long, long long>>> vvpll;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long ll;

void dfs(int node, vvi &adj, set<int> &unvisited){
    unvisited.erase(node);
    int neigh = adj[node].size();
    loop(i, 0, neigh){
        if(unvisited.count(adj[node][i]) == 1){
            dfs(adj[node][i], adj, unvisited);
        }
    }
}

int main(){
    ios::sync_with_stdio(0);

    int n, m; cin >> n >> m;

    vvi adj(n, vector<int>(0));
    loop(i, 0, m){
        int s, t; cin >> s >> t; s--; t--;
        adj[s].pb(t);
        adj[t].pb(s);
    }

    int comp = 0;
    set<int>unvisited;
    loop(i, 0, n){
        unvisited.insert(i);
    }
    while(!unvisited.empty()){
        comp++;
        int node = *unvisited.begin();
        dfs(node, adj, unvisited);
    }
    cout<<comp-1<<endl;
}

Measured memory_bytes: 14876
import java.util.Scanner

import scala.util.control.Breaks

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val x = sc.nextInt()
    val n = sc.nextInt()

    val p = Set.fill(n)(sc.nextInt())

    var ans = x
    var dis = 0
    val b = new Breaks
    b.breakable {
      while (true) {
        if (!p.contains(ans - dis)) {
          ans = ans - dis
          b.break()
        } else if (!p.contains(ans + dis)) {
          ans = ans + dis
          b.break()
        } else {
          dis += 1
        }
      }
    }

    println(ans)

  }

}


Measured memory_bytes: 55780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
 
 
public class Main{
     
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	
    	boolean[] is_prime = new boolean[1000001];
    	
    	for(int i = 2; i < 1000001; i++){
    		is_prime[i] = true;
    	}
    	
    	for(int i = 2; i <= 1000; i++){
    		if(is_prime[i]){
    			for(int j = 2 * i; j < 1000001; j += i){
    				is_prime[j] = false;
    			}
    		}
    	}
    	
    	while(true){
    		final int a = sc.nextInt();
    		final int b = sc.nextInt();
    		
    		if(a == 0 && b == 0){
    			break;
    		}
    		
    		int a_sum = 0;
    		int a_max = 0;
    		for(int i = 2; i <= a; i++){
    			if(!is_prime[i]){
    				continue;
    			}else if(a % i != 0){
    				continue;
    			}
    			
    			a_sum += i;
    			a_max = i;
    		}
    		int a_key = a_max + a_max - a_sum;
    		
    		int b_sum = 0;
    		int b_max = 0;
    		for(int i = 2; i <= b; i++){
    			if(!is_prime[i]){
    				continue;
    			}else if(b % i != 0){
    				continue;
    			}
    			
    			b_sum += i;
    			b_max = i;
    		}
    		int b_key = b_max + b_max - b_sum;
    		
    		//System.out.println(a_sum + " " + a_max);
    		//System.out.println(b_sum + " " + b_max);
    		
    		if(a_key > b_key){
    			System.out.println("a");
    		}else{
    			System.out.println("b");
    		}
    	}
        
    }
     
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300005];
ll ans;
int n;
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < 3 * n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a, a + 3 * n);
    for (int i = 3 * n - 2; i >= n; i -= 2) {
        ans += a[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
S=input()
n=len(S)
if S[0]=="A":
	if 2<=S.find("C")<=n-2:
		T=S.lstrip("A")
		R=T.replace("C","c",1)
		Q=T.replace("C","c")
		if R==Q:
			if R.lower()==R:
				print("AC")
				exit()
print("WA")
			

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

long long caracal_vs_monster(long long h) {

  long long current = 1;
  while(current <= h) {
    current *= 2;
  }
  return current - 1;
}
int main() {
  long long h;
  cin >> h;
  cout << caracal_vs_monster(h);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    string a, b;
    cin >> a >> b;
    //cout << a << endl;
    //cout << b << endl;
    if(a.length()>b.length()) cout << "GREATER" << endl;
    if(a.length()<b.length()) cout << "LESS" << endl;
    if(a.length()==b.length()){
        if(a > b) cout << "GREATER" << endl;
        else if(a < b) cout << "LESS" << endl;
        else if(a == b) cout << "EQUAL" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input().strip())
val = ['z', 'a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
key = [i for i in range(27)]
corr_dict = {}

for key, val in zip(key, val):
  corr_dict[key] = val

ans = ''
num = N
while num > 26:
  ans += corr_dict[num%26]
  num = (num-1)//26

if num == 0:
    print(ans[::-1])
else:
    ans += corr_dict[num%26]
    print(ans[::-1])

Measured memory_bytes: 9168
#include <bits/stdc++.h>
int c[105][105],vis[105],d[105][105],b[105][105],a[105][105],n,m,f[105],to[105];
int dfs(int x){
	for (int i=1;i<=n;i++)
	if (d[x][i] && !vis[i]){
		vis[i]=1;
		if (f[i]==0 || dfs(f[i])){
			f[i]=x,to[x]=i;
			return 1;
		}
	}
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) 
		for (int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
			b[i][j]=(a[i][j]-1)/m+1;
			d[i][b[i][j]]++;
		}
	for (int i=1;i<=m;i++){
		memset(f,0,sizeof(f));
		for (int j=1;j<=n;j++){
			memset(vis,0,sizeof(vis));
			dfs(j);
		}
		for (int j=1;j<=n;j++){
			c[j][i]=to[j];
			d[j][to[j]]--;
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) 
			for (int k=1;k<=m;k++) 
				if (b[i][k]==c[i][j] && a[i][k]) {
					d[i][j]=a[i][k],a[i][k]=0;
					break;
				}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) printf("%d ",d[i][j]);
		puts("");
	}
	for (int i=1;i<=m;i++){
		for (int j=1;j<=n;j++){
			f[j]=d[j][i];
		}
		std::sort(f+1,f+n+1);
		for (int j=1;j<=n;j++) d[j][i]=f[j];
	}
		for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) printf("%d ",d[i][j]);
		puts("");
	}	
}

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

using namespace std;

typedef long long ll;

int main(){
  double W, H, a, b;
  cin >> W >> H >> a >> b;
  double ans = W*H/2.0;
  if(a == W/2.0 && b == H/2.0) printf("%.10f %d\n", ans, 1);
  else printf("%.10f %d\n", ans, 0);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
using namespace std;
int a,b,k;
main(){
  cin>>a>>b>>k;
  set<int>S;
  for(int i=0;i<k;i++){
    if(a+i<=b)S.insert(a+i);
    if(b-i>=a)S.insert(b-i);
  }
  for(int i:S)cout<<i<<endl;
}

Measured memory_bytes: 256
from itertools import groupby

S = input()
s = len(S)
K = int(input())

gr = []
for k, g in groupby(S):
    gr.append(len(list(g)))

if len(gr) == 1:
    print(len(S) * K // 2)
elif S[0] != S[-1]:
    print(sum([i // 2 for i in gr]) * K)
else:
    print(sum([i // 2 for i in gr]) * K - (gr[0] // 2 + gr[-1] // 2 - (gr[0] + gr[-1]) // 2) * (K - 1))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		long rc = 0;
		long gc = 0;
		long bc = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'R') {
				rc++;
			} else if(s.charAt(i) == 'G'){
				gc++;
			} else {
				bc++;
			}
		}
		long result = rc*gc*bc;
		for(int i=1; i<=n; i++){
			for(int k=i+1; k<=n; k++){
				if((i+k)%2 == 0){
					char is = s.charAt(i-1);
					char ks = s.charAt(k-1);
					char js = s.charAt(((i+k)/2)-1);
					if(is != ks && ks != js && js != is){
						result--;
					}
				}
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 28620
def main():
    item_count, capacity = [int(x) for x in input().split()]
    weights, values = [], []
    for _ in range(item_count):
        w, v = [int(x) for x in input().split()]
        weights.append(w)
        values.append(v)
    # dp[i][j]
    # = (i番目までの品物を、重さがj以下になるように選んだときの価値の最大値)
    dp = [[0] * (capacity + 1) for _ in range(item_count)]
    for item_i in range(item_count):
        for weight_i in range(1, capacity + 1):
            w = weights[item_i]
            if w <= weight_i:
                dp[item_i][weight_i] = max(
                    dp[item_i - 1][weight_i - w] + values[item_i],
                    dp[item_i - 1][weight_i])
            else:
                dp[item_i][weight_i] = dp[item_i - 1][weight_i]
    print(dp[item_count - 1][capacity])


if __name__ == '__main__':
    main()


Measured memory_bytes: 151708
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)
#define ll long long
#define P pair<int,int>
#define pb push_back

struct edge{
	int to,cost;
	edge(int to,int cost):to(to),cost(cost){}
};

int c,n,m,s,D,d[1100];
vector<edge> g[1100];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > q;
	fill(d,d+c*100+n,INF);
	d[s]=0;
	q.push(P(0,s));
	while(!q.empty()){
		P p=q.top();q.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		rep(i,g[v].size()){
			edge e=g[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
	while(cin>>c>>n>>m>>s>>D&&n){
		s--;D--;
		rep(i,c*100+n)g[i].clear();
		rep(i,m){
			int a,b,f;
			cin>>a>>b>>f;
			a--;b--;
			rep(j,c+1){
				g[j*100+a].pb(edge(j*100+b,f));
				g[j*100+b].pb(edge(j*100+a,f));
			}
			rep(j,c){
				g[(j+1)*100+a].pb(edge(j*100+b,f/2));
				g[(j+1)*100+b].pb(edge(j*100+a,f/2));
			}
		}
		dijkstra(c*100+s);
		int ans=INF;
		rep(i,c+1)ans=min(ans,d[i*100+D]);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n = i()
a = intl()
a = list(set(a))
if len(a) == n:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 26580
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 1000000000 + 7;

void solve() {
	char c;
	cin >> c;
	if (c >= 97 && c <=122) cout << "a\n";
	else cout << "A\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
from heapq import *
N, Q = map(int, input().split())
X = []
for _ in range(N):
    s, t, x = map(int, input().split())
    X.append((s-x,t-x,x))

X = sorted(X, key = lambda x: x[0])
i = 0
A, B, C = [], [], []
for _ in range(Q):
    d = int(input())
    while i < len(X) and d >= X[i][0]:
        a, b, x = X[i]
        heappush(A, (x, b))
        heappush(B, (b, x))
        i += 1
    while len(B) and B[0][0] <= d:
        b, x = heappop(B)
        heappush(C, (x, b))
    while len(C) and len(A) and C[0][0] == A[0][0]:
        heappop(A)
        heappop(C)
    print(A[0][0] if A else -1)


Measured memory_bytes: 124380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arra[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>arra[i];

    }
    int dp[n+5];
    dp[0]=0;
    if(n>1)
        dp[1]=abs(arra[1]-arra[0]);
    for(int i=2; i<n; i++)
    {
        dp[i]=min((dp[i-1]+abs(arra[i-1]-arra[i])),(dp[i-2]+abs(arra[i-2]-arra[i])));
    }
    cout<<dp[n-1]<<endl;


}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int vs = 13;
  vector<int> vx={1,1,1,1,1,1,1,1,1,0,0,0,0};
  vector<int> vy={1,1,1,0,0,0,-1,-1,-1,1,1,1,0};
  vector<int> vz={-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1};
  while(1){
    int n,m,p;
    cin >> n >> m >> p;
    if(n==0) return 0;
    vector<vector<vector<int>>> f(n,vector<vector<int>>(n,vector<int>(n,-1)));
    int x,y;
    int teban=0;
    rep(t,p){
      cin >> x >> y;
      x--,y--;
      int z;
      rep(i,n){
        if(f[x][y][i]==-1){
          z=i;
          break;
        }
      }
      f[x][y][z]=teban;
      rep(i,vs){
        int count=1;
        int nx=x,ny=y,nz=z;
        while(1){
          nx+=vx[i];
          ny+=vy[i];
          nz+=vz[i];
          if(nx<0||n<=nx||ny<0||n<=ny||nz<0||n<=nz) break;
          if(f[nx][ny][nz]!=teban) break;
          count++;
        }
        nx=x,ny=y,nz=z;
        while(1){
          nx-=vx[i];
          ny-=vy[i];
          nz-=vz[i];
          if(nx<0||n<=nx||ny<0||n<=ny||nz<0||n<=nz) break;
          if(f[nx][ny][nz]!=teban) break;
          count++;
        }
        if(count>=m){
          cout << (teban?"White":"Black") SP t+1 << endl;
          rep(j,p-t-1) cin >> x >> y;
          goto next;
        }
      }
      teban=1-teban;
    }
    cout << "Draw" << endl;
    next:;
  }
  return 0;
}



Measured memory_bytes: 3160
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]
MOD = 998244353

max_B = -1
ans = 1

for i in range(1, len(A)):
    if A[i]==0:
        ans = 0
    else:
        B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

if A[0] != 0:
    ans = 0 

for i in range(1, max_B):    
    if B[i] == 0:
        ans = 0 
        break
    else:
        ans = (ans * (B[i-1] ** B[i])%MOD)%MOD

print(ans)


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

int main() {

  int n;
  cin >> n;
  for(int i = 0; i < 30; i++) {
    for(int j = 0; j < 30; j++) {
      if(4 * i + 7 * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int INF = 10000000;
  string S;
  cin >> S;
  int N = S.size();
  int Nex[26];
  int Next[N][26];
  vector<int> Prev[N];
  int dis[N];
  queue<P> que;
  for (int i = 0; i < N; i++) {
    dis[i] = INF;
  }
  // dis : 詰みまでの距離
  // 次でつむとき,0
  for (int i = 0; i < 26; i++) {
    Nex[i] = INF;
  }
  for (int i = N-1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      Next[i][j] = Nex[j];
    }
    Nex[S[i] - 'a'] = i;
  }

  for (int i = 0; i < 26; i++) {
    if (Nex[i] == INF) {
      cout << (char)('a' + i) << endl;
      return 0;
     }
   }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 26; j++) {
      if (Next[i][j] != INF) {
        Prev[Next[i][j]].push_back(i);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    bool T = false;
    for (int j = 0; j < 26; j++) {
      if (Next[i][j] == INF) {
        T = true;
      }
    }
    if (T) {
      que.push(make_pair(0,i));
    }
  }

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (dis[p.S] <= p.F) {
      continue;
    }
    dis[p.S] = p.F; 
    for (int i = 0; i < (int)Prev[p.S].size(); i++) {
      if (dis[Prev[p.S][i]] > p.F + 1) {
        que.push(make_pair(p.F+1,Prev[p.S][i]));
      }
    }
  }
  string ans = "";
  int now = -1;
  int pos = -1;
  while (0 == 0) {
    int mx = INF;
    char c;
    pos = -1;
    if (now == -1) {
      for (int i = 0; i < 26; i++) {
        if (mx > dis[Nex[i]]) {
          mx = dis[Nex[i]];
          pos = Nex[i];
          c = i + 'a';
        }
      }
    } else {
      for (int i = 0; i < 26; i++) {
        if (mx > dis[Next[now][i]]) {
          mx = dis[Next[now][i]];
          pos = Next[now][i];
          c = i + 'a';
        }
      }
    }
    now = pos;
    ans += c;
    if (mx == 0) {
      break;
    }
  }
  for (int i = 0; i < 26; i++) {
    if (Next[now][i] == INF) {
      ans += 'a' + i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 61864
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, a, b;
    cin>>n>>a>>b;

    for(ll i=1;i<=max(a, b);++i){
        inv[i] = modpow(i, MOD - 2);
    }
    ll sum = modpow(2, n);
    sum--;
    ll x = nCk(n, a);
    ll y = nCk(n, b);
    ll res = (x + y) % MOD;

    ll ans = 0;
    if(sum >= res){
        ans += (sum - res) % MOD;
    }else{
        ans = (sum + MOD - res) % MOD;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  VI S(N),T(N),C(N);
  rep(i,N) cin>>S[i]>>T[i]>>C[i];
  VVI X(M,VI(100100));
  rep(i,N){
    X[C[i]-1][S[i]]++;
    X[C[i]-1][T[i]+1]--;
  }
  rep(i,M) rep(j,100100) X[i][j+1]+=X[i][j];
  rep(i,M) rep(j,100100) if(X[i][100099-j]==0 and X[i][100099-j]==1) X[i][100099-j]=1;
  int ans=0;
  rep(i,100100){
    int tmp=0;
    rep(j,M) if(X[j][i]) tmp++;
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}

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

signed main(){
  int N, Q; cin >> N >> Q;
  string s; cin >> s;
  vector<char> t(Q), d(Q);
  for(int i = 0; i < Q; i++) cin >> t[i] >> d[i];
  int left = -1, right = N, ans = N;
  while(right - left > 1){
    int mid = (right + left) / 2, mid1 = mid;
    for(int i = 0; i < Q; i++){
      if(t[i] == s[mid] && d[i] == 'L') mid--;
      if(t[i] == s[mid] && d[i] == 'R') mid++;
      if(mid == N || mid == -1) break;
    }
    if(mid == -1) left = mid1;
    else right = mid1;
  }
  ans -= left + 1;
  left = -1, right = N;
  while(right - left > 1){
    int mid = (right + left) / 2, mid1 = mid;
    for(int i = 0; i < Q; i++){
      if(t[i] == s[mid] && d[i] == 'L') mid--;
      if(t[i] == s[mid] && d[i] == 'R') mid++;
      if(mid == N || mid == -1) break;
    }
    if(mid == N) right = mid1;
    else left = mid1;
  }
  ans -= (N - right);
  cout << ans << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long long num, a, decide=0, first, sec;
  vector<long long> list;
  cin >> num;
  for (long long i=0; i<num; i++) {
    cin >> a;
    list.push_back(a);}
  sort(list.begin(), list.end());
  first = list[0];
  for (long long i=1; i<num; i++) {
    sec = list[i];
    if (sec==first) {cout << "NO"; decide=1; break;}
    first = sec;}
  if (decide==0) {cout << "YES";}}

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

int c[15] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

int main() {
  int n, a, b;
  cin >> n;
  while(n--) {
    cin >> a >> b;
    int res = 100;
    int minI, minJ;
    for(int i = 0; i < 15; ++i) {
      for(int j = 0; j < 15; ++j) {
        if(c[i] == a && c[j] == b) {
          int next = (j-i+15)%15;
          if(res > next) {
            res = next;
            minI = i;
            minJ = j;
          }
        }
      }
    }
    for(int k = minI; k != minJ; k = (k+1)%15) {
      cout << c[k] << " ";
    }
    cout << c[minJ] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(int argc, char const *argv[]) {
	long n,i,a,num=0;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a);
		if(a%2==1) num++;
	}
	if(num%2==1) printf("NO\n");
	else printf("YES\n");
	return 0;
}

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


int main() {
  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll> a(n);
  vector<ll> b(m);
  vector<ll> A(n+1);
  vector<ll> B(m+1);
  A[0]=0;B[0]=0;
  ll l1=0,l2=0;
  rep(i,n){
    cin>>a[i];
    A[i+1]=A[i]+a[i];
    if (A[i+1]<=k)l1=i;
  //  cout<<"k"<<k<<" "<<A[i+1]<<" "<<l1<<endl;
  }
  rep(i,m){
    cin>>b[i];
    B[i+1]=B[i]+b[i];
    if (B[i+1]<=k)l2=i;
  }
  ll ans=0;
//  cout<<l1<<endl;
  rep(i,l1+2){
    ll rest=k-A[i];
    ll id=upper_bound(B.begin(),B.end(),rest)-B.begin();
  //  cout<<"i"<<i<<"id"<<id<<endl;
    ans=max(ans,i+id-1);
  }


cout<<ans;


}


Measured memory_bytes: 9604
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

class UnionFind(n: Int) {
    private val parent: MutableList<Int> = MutableList(n) { it }
    private val rank: MutableList<Int> = MutableList(n) { 0 }
    private val _size: MutableList<Int> = MutableList(n) { 1 }

    private fun root(x: Int): Int {
        if (parent[x] == x) return x
        parent[x] = root(parent[x])

        return parent[x]
    }

    fun union(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return

        if (rank[rx] < rank[ry]) {
            val tmp = rx
            rx = ry
            ry = tmp
        }

        if (rank[rx] == rank[ry]) rank[rx]++

        parent[ry] = rx
        _size[rx] += _size[ry]
    }

    fun isSame(x: Int, y: Int): Boolean = root(x) == root(y)

    fun size(x: Int): Int = _size[root(x)]
}

fun main() {
    val (n, m, k) = readIntList()
    val friendUf = UnionFind(n + 1)
    val notCandidates = Array(n + 1) { mutableListOf<Int>() }

    for (i in 0 until m) {
        val (a, b) = readIntList()
        friendUf.union(a, b)
        notCandidates[a].add(b)
        notCandidates[b].add(a)
    }
    
    for (i in 0 until k) {
        val (c, d) = readIntList()
        if (friendUf.isSame(c, d)) {
            notCandidates[c].add(d)
            notCandidates[d].add(c)
        }
    }

    val friendCandidates = Array(n + 1) { 0 }
    for (i in 1..n) {
        friendCandidates[i] = friendUf.size(i) - notCandidates[i].size - 1
    }

    println(friendCandidates.drop(1).joinToString(separator = " "))
}


Measured memory_bytes: 86460
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int x,a; cin>>x>>a;
  if (x < a) cout << 0 << endl;
  else cout << 10 << endl;

}


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T ceil(T a, T b) { return a / b + !!(a%b); }
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
	out << '(' << a.first << ',' << a.second << ')';
	return out;
}
template<class T>
ostream &operator <<(ostream& out, const vector<T>& a) {
	out << '[';
	REP(i, a.size()) { out << a[i]; if (i != a.size() - 1)out << ','; }
	out << ']';
	return out;
}

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

signed main(void) {
	int x, y;
	cin >> x >> y;
	if (x%y == 0) {
		cout << -1 << endl;
		return 0;
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
 

 int main(){
     int n;
     cin>>n;
     rep(i,999){
         int a=n/100, b=n/10, c=n%10;
         b%=10;
         if(a==b && b==c) break;
         n++;
     }
     cout<<n<<endl;
 }

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

int main(){
  int v1,v2,i;
  int l[10],d;
  double h,d1;
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
	      l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v1,&v2)!=EOF){
    for(i=0,d=0;i<10;i++) d+=l[i];
    h=(double)d/(double)(v1+v2);
    d1=h*v1;
    for(i=0;i<10;i++){
      if((d1-(double)l[i])<=0)
	break;
      d1-=(double)l[i];
    }
    printf("%d\n",i+1);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#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 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    ll ans = 0;
    ll cnt = 0;

    for(int i = s.size()-1; i >= 0; i--) {
        if(s[i]=='W') {
            ++cnt;
        }else {
            ans += cnt;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 720
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(a):
        b = [0]*(n+1)
        for i in range(n):
            l = max(0,i-a[i])
            r = min(n,i+a[i]+1)
            b[l] += 1
            b[r] -= 1
        for i in range(n):
            b[i+1] += b[i]
        return b[:n]
    n,k = LI()
    a = LI()
    while k:
        if sum(a) == n**2:
            break
        a = f(a)
        k -= 1
    print(*a)
    return

#Solve
if __name__ == "__main__":
    solve()


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n) {


	string  str = to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size() / 2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if (str[i] != str[str.size() - i - 1]) {
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, m,c=0, k, sum = 0;
	c_p_c();

	cin>>n>>m;
	if(n>=1 and n<=9 and m>=1 and m<=9){
		cout<<n*m<<endl;

		// cout<<"No"<<endl;
	}
	else
		cout<<"-1"<<endl;
}


Measured memory_bytes: 3572
S = input()
nS = len(S)
white = ("01"*100000)[:nS]
black = ("10"*100000)[:nS]
sa_white = len([1 for x,y in zip(S, white) if x!=y])
sa_black = len([1 for x,y in zip(S, black) if x!=y])
print(min(sa_white, sa_black))

Measured memory_bytes: 4528
n, x, m = map(int, input().split())
idx = [-1] * m
a = []
leng = 0
tot = 0

while idx[x] == -1:
    a.append(x)
    idx[x] = leng
    leng += 1
    tot += x
    x = (x*x)%m

c = leng - idx[x]
s = 0
for i in range(idx[x], leng):
    s += a[i]

ans = 0
if n<=leng:
    for i in range(n):
        ans += a[i]
else:
    ans += tot
    n -= leng
    ans += s*(n//c)
    n %= c
    for i in range(n):
        ans += a[idx[x]+i]

print(ans)


Measured memory_bytes: 71136
#include <stdio.h>

int main(void) {
  int i, j, ans = 0, k, s;
  scanf("%d%d", &k, &s);
  for(i = 0; i <= k; ++i) for(j = 0; j <= k; ++j) if(s - i - j <= k && i + j <= s) ++ans;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

const int N = 200005;
pll ara[N];
LL n , d;

int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cin >> n >> d;
    int cnt = 0;
    FOR(i,1,n){
        LL x , y;
        cin >> x >> y;
        LL D = SQR(x) + SQR(y);
        cnt += (D <= SQR(d));
    }
    cout << cnt << "\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Measured memory_bytes: 3484