akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <functional>
#include <numeric>
#include <string>
#include <iterator>
#include <sstream>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cstring>

using namespace std;


int formula(char **str){
	char t = **str;

	(*str)++;
	if(t == 'T') return 1;
	if(t == 'F') return 0;

	if(t == '-') return (formula(str)!=0 ? 0 : 1);
	if(t == '(') {
		int a = formula(str);

		char c = **str;
		switch(c) {
		case '*':
		case '+':
			break;
		case '-':
			(*str)++;
			if(**str != '>') return 0;
			break;
		default:
//			cout  << "failf:" << endl;
			return 0;
		}
		(*str)++;
		int b = formula(str);
		(*str)+=1;

		switch(c) {
		case '*':
			return a && b;
		case '+':
			return a || b;
		case '-':
			return (!a || b);
		default:
		//	cout  << "failf1" << endl;
			return 0;
		}

	}
	
		///	cout  << "failf2" << endl;
	return 0;
}
int equi(char *str) {
	int a = formula(&str);
	if(*str != '=') return 0;
	str++;
	int b = formula(&str);
//	cout << "ret:" << (a==b) << endl;
	return (a == b);
}

int solve(string str) {
		int N = 0;
		char a[11] = {0};

		int e[11] = {0};
		for(int i = 0; i < str.length(); i++) {
			if('a' <= str[i] && str[i] <= 'k') {
				e[str[i] - 'a']++;
				if(e[str[i] - 'a'] == 1){
					a[N] = str[i];
					N++;
				}
			}
		}

		int result = 1;
		for(int i = 0; i < (1 << N); i++) {
			int t = i;
			string s(str);
			for(int n = 0; n < N; n++) {
				for(int j = 0; j < s.length(); j++)
					if(s[j] == a[n])
						s[j] = ((t&1) ? 'T' : 'F');
				t >>= 1;
			}
//			cout << s << endl;
			if(!equi(const_cast<char*>(s.c_str()))) result = 0;

		}
		return( result );
}

int main()
{
	string str;

	while(1) {
		cin >> str;
		if(str == "#") break;

		int result = solve(str);

		cout << (result? "YES": "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 904
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{
    string S;
    cin >> S;
    int len = S.size();
    string S_rev = S;
    reverse(S_rev.begin(),S_rev.end());

    int cnt = 0;
    if(len%2==0)
    {
        for (int i=0; i<(int)(len/2); ++i)
        {
            if(S[i] != S_rev[i]) cnt ++;
        }
    }
    else
    {
        for (int i=0; i<(int)(len/2); ++i)
        {
            if(S[i] != S_rev[i]) cnt ++;
        }   
    }
    
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

	vi a(3);
	cin >> a[0] >> a[1] >> a[2];

	sort(a.begin(), a.end());
	cout << a[0] + a[1] << endl;
	return 0;
}

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

int main() {
	int N; cin >> N;
	int K; cin >> K;
	int H, ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> H;
		if (H >= K) ans++;
	}
	cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0;i < (int)(n);i++)
int main(){
    int h,w;
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        rep(i,h){
            rep(j,w){
                if((i + j) % 2 == 0){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3116
#!/usr/bin/env python3

s = [int(e) for e in input().split()]
K = s[0]
A = s[1]
B = s[2]

if B - 2 < A:
    print(K+1)
else:
    firstnop = A - 1
    lastnop = (K - firstnop) % 2
    midnop = (K - firstnop - lastnop) // 2
    print(1 + firstnop + midnop*(B-A) + lastnop)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    i64 a,b,c,d,e;
    scanf("%lli%lli%lli%lli%lli",&a,&b,&c,&d,&e);
    if(a>0LL) printf("%lli\n",e*(b-a));
    else printf("%lli\n",c*(-a)+d+e*b);
    return 0;
}



Measured memory_bytes: 2104
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: isize,
        aa: [isize; n]
    };
    // f(k)
    // = Σ (k-ai)^2
    // = Σ (k*k -2k*ai + ai*ai)
    // = N*k*k -2k*Σai + Σ(ai*ai)
    // = N * (k*k -2k/N*Σai) + Σ(ai*ai)
    // = N*(k - 1/N*Σai)^2 - 1/N*(Σai)^2 + Σ(ai*ai)
    let sig_ai: isize = aa.iter().sum();
    let mut min = std::isize::MAX;
    for diff in [-1, 0, 1].iter() {
        let k = sig_ai / n + diff;
        let cost = aa.iter().fold(0, |acc, a| acc + (k - a).pow(2));
        min = std::cmp::min(min, cost);
    }
    println!("{}", min);
}


Measured memory_bytes: 2156
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,k;
ll rui[200005];

int main(){
	cin >> n >> k;
	repn(i,n){
		int x; cin >> x;
		rui[i] = rui[i-1] + (x+1);
	}
	ll ans = 0;
	repn(i,n){
		if(i+k-1 > n) break;
		ans = max(ans,rui[i+k-1]-rui[i-1]);
	}
	printf("%.10f\n",(double)(ans)/2.);
}

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

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
/////////////

ll n;

void solve(){
	ll ans = n / 11LL;
	ll rem = n - 11LL * ans;
	ans *= 2;
	if(rem > 0){
		++ans;
		rem -= 6;
	}
	if(rem > 0){
		++ans;
	}
	printf("%lld\n",ans);
}

void read(){
	scanf("%lld",&n);
}

void prepare(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}

int main(){
	prepare();
	read();
	solve();



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, l; cin >> n >> l;
    vector<string> s(n);
    for(int i=0; i<n; i++) {
        cin >> s[i];
    }

    sort(s.begin(), s.end());
    for(int i=0; i<n; i++) {
        cout << s[i];
    }
        cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int ans=0,n;cin>>n;
  int a[n],b[n];
  map<int,int>m;
  for(int i=0;i<n;i++){cin>>a[i];b[i]=a[i];}
  sort(b,b+n);
  for(int i=0;i<n;i++)if(i%2)m[b[i]]=1;
  for(int i=0;i<n;i++)ans+=(i%2)^m[a[i]];
  cout<<ans/2<<endl;
}

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

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1'){
      s[i] = '9';
    }else if(s[i] == '9') {
      s[i] = '1';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

a = max(A - K, 0)	#食べ残しと０とを比較して大きい方を返す
K -= A - a			#食べた分の枚数を、残りの食べる予定量から減らす
b = max(B - K, 0)	#もし負になったら０を返す

print("{} {}".format(a, b))

Measured memory_bytes: 38384
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ( * ) a b = a * b mod 1000000007
let rec f n a = if n <= 1 then a else f (n - 1) (a * n)
let _ = Printf.printf "%d\n" @@ f n 1 * f m 1 * max 0 (2 - abs (n - m))

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

static const int MAX=100000;

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
    prenum[current]=lowest[current]=timer;
    timer++;

    visited[current]=true;
    int next;
    for(int i=0;i<G[current].size();i++){
        next=G[current][i];
        if(!visited[next]){
            parent[next]=current;
            dfs(next,current);
            lowest[current]=min(lowest[current],lowest[next]);
        }else if(next!=prev){
            lowest[current]=min(lowest[current],prenum[next]);
        }
    }
}

void art_points(){
    for(int i=0;i<N;i++) visited[i]=false;
    timer =1;
    dfs(0,-1);
    set<int> ap;
    int np=0;
    for(int i=1;i<N;i++){
        int p=parent[i];
        if(p==0)np++;
        else if(prenum[p]<=lowest[i])ap.insert(p);
    }
    if(np>1) ap.insert(0);
    for(set<int>::iterator it=ap.begin();it!=ap.end();it++)
        cout<<*it<<"\n";
}
int main(){
    int m;
    cin>>N>>m;
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();
    return 0;
}
    



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

int main() {
	int N, K, x;
	cin >> N >> K;
	
	int half = K / 2;
	int total = 0;

	for (int i = 0; i < N; i++) {
		cin >> x;
		if (x <= half) {
			total = total + x;
		} else {
			total = total + (K - x);
		}
	}
	total = total * 2;
	cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c,d=0,e=0,f=0,g=1,h=0;
    string s;
    int ans=0;
    int i[10];
    cin >>s;
    for(int n=0;n<4;n++){
	i[n]=s[n]-'0';
    }
    for(ans=0;ans<8;ans++){
	int bi=i[0];
	int bit=ans;
	for(int n=3;n>=1;n--){
	    if((bit&1)==1) bi+=i[n];
	    else bi-=i[n];
	    bit=bit>>1;
	}
	if(bi==7){
	    break;
	}
    }
    for(int n=2;n>=0;n--){
	if((ans&1)==1) s[n]='+';
	else s[n]='-';
	ans=ans>>1;
    }
    for(int n=0;n<3;n++){
	cout <<i[n];
	cout <<s[n];
    }
    cout <<i[3]<<"=7\n";
    return (0);
}


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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vbool = vector<bool>;

int main() {
    int H, W;
    cin >> H >> W;
    vvint a(H,vint(W));

    int N = 0;
    vint s, t, u, v;
    REP(y, H) REP(x, W) {
        cin >> a[y][x];
    }
    REP(y, H) REP(x, W - 1) {
        if (a[y][x] % 2 == 1) {
            N++;
            s.pb(x), t.pb(y), u.pb(x + 1), v.pb(y);
            a[y][x + 1]++;
        }
    }
    REP(y, H - 1) {
        int x = W - 1;
        if (a[y][x] % 2 == 1) {
            N++;
            s.pb(x), t.pb(y), u.pb(x), v.pb(y + 1);
            a[y + 1][x]++;
        }
    }

    cout << N << endl;
    REP(i, N) {
        printf("%d %d %d %d\n", t[i] + 1, s[i] + 1, v[i] + 1, u[i] + 1);
    }
}

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

using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define pb			    push_back

typedef long long ll;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n, m;
	cin >> n >> m;
	int a[n];
	clr(a, -1);
	
	if (m == 0) {
		if (n == 1)
			cout << 0; 
		else if (n == 2) 
			cout << 10; 
		else 
			cout << 100; 
		return 0; 
	}
 	
	for (int i = 0; i < m; ++i) {
		int s, c;
		cin >> s >> c;
		if (a[s-1] != -1 && a[s-1] != c) {
			cout << -1;
			return 0;
		}
		a[s-1] = c;
	}
//	if (a[0] == -1 && n == 1)
//		return cout << 0, 0;
//	if (a[0] == -1)
//		a[0] = 1;
//	if (a[0] == 0)
//		return cout << -1, 0;
	if (a[0] == 0) {
		if (n == 1) {
			cout << 0;
			return 0;
		}
		cout << -1;
		return 0;
	}
	if (a[0] == -1)
		a[0] = 1;
	for (int i = 0; i < n; ++i) {
		if(a[i] == -1)
			a[i] = 0;
		cout << a[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long N;
    cin >> N;
    long trans[5];
    for (int i = 0; i < 5; i++)
        cin >> trans[i];

    long min = trans[0];
    long min_n;
    for (int i=0; i<5; i++) {
        if (min > trans[i]) {
            min = trans[i];
            min_n = i;
        }
    }

    long time;
    time = N/min;
    if (N%min != 0) time++;
    time += 4;

    cout << time << endl;

    return 0;
}


Measured memory_bytes: 256
x,n = map(int, input().split())

p = list(map(int, input().split()))

hanb = 0
hans = 0

for i in range(0,100):
    big = x + i
    sml = x - i
    
    if big not in p:
        hanb += 1

    if sml not in p:
        hans += 1

    if hanb == 1 or hans == 1:
        break

if hanb == 1 and hans == 1:
    print(sml)

elif hans == 1:
    print(sml)

else:
    print(big)



Measured memory_bytes: 9204
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
parity = [-1 for _ in range(n)]
valid = True

def dfs(x):
	global valid
	p = parity[x]
	for v in adj[x]:
		if parity[v] < 0:
			parity[v] = 1^p
			dfs(v)
		elif parity[v] == p:
			valid = False
			return
	return

for _ in range(m):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

parity[0] = 0
dfs(0)
if not valid:
	print((n*(n-1)//2) - m)
else:
	o = sum(parity)
	print(o*(n-o) - m)

Measured memory_bytes: 40240
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int a,b;

  for(int i = 0;i < k;i++){
    cin >> a >> b;

    if( a > (n/2+1)) a = n-a+1;
    if( b > (n/2+1)) b = n-b+1;

    if( min(a,b)%3 == 1) cout << 1 << endl;
    else if( min(a,b)%3 == 2) cout << 2 << endl;
    else cout << 3 << endl;
  }

  return (0);
}

Measured memory_bytes: 3096
N = int(input())

l = []

flg = True

for i in range(N):
    s = input()

    if (s in l):
        flg = False
        break

    num = len(l)

    if (num != 0 and l[num - 1][-1] != s[0]):
        flg = False
        break

    l.append(s)

print("Yes" if flg else "No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
int n,m,Ans;
inline int Max(rg int A,rg int B){   return A>B?A:B;   }
int main()
{   scanf("%d%d",&n,&m);
	for(rg int i=1,End=sqrt(m);i<=End;i++)
	{	if(m%i!=0)  continue ;
		if(i>=n) Ans=Max(Ans,m/i);
		if(m/i>=n) Ans=Max(Ans,i);
	}
	printf("%d\n",Ans);
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
ans = 0
while True:
    max_A = max(A)
    if max_A < N:
        break
    S = sum(a // N for a in A)
    ans += S
    for i in range(N):
        A[i] = A[i] - (A[i] // N) * N + (S - (A[i] // N))
print(ans)


Measured memory_bytes: 3060
int main()
{
    int a[5]={0},k, i, j;
    for(i=0;i<5;i++)scanf("%d", &a[i]);
    scanf("%d", &k);
    for(i=4;i>=1;i--)
    {
        for(j=i-1;j>=0;j--)
        {
            if(a[i]-a[j]>k)
            {
                printf(":(");
                return 0;
            }
        }
    }
    printf("Yay!");
    return 0;
}


Measured memory_bytes: 128
"use strict";

function main(input) {
  input = input.trim().split(" ");
  const num = Number(input[0]) + Number(input[1]) + Number(input[2]);
  if (num >= 22) {
    console.log("bust");
  } else {
    console.log("win");
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


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

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

    //good luck kittu!
    ll x, p = 100, step = 0, t; cin>>x;
    while(p<x){
        t = p/100;
        p += t;
        step++;
    }
    cout<<step;
    return 0;
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> l(q);
  vector<int> r(q);
  rep(i, 0, q) {
    int li, ri;
    cin >> li >> ri;
    li--;
    ri--;
    l[i] = li;
    r[i] = ri;
  }

  vector<int> cnt(n, 0);
  int c = 0;
  rep(i, 0, n - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C') c++;
    cnt[i + 1] = c;
  }
  rep(i, 0, q) { cout << cnt[r[i]] - cnt[l[i]] << endl; }
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+1;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

void solve(){
    int a,b;
    cin>>a>>b;
    for(int i=1;i<4;i++){
    	if(i!=a && i!=b){
    		cout<<i<<nl;
    		return;
    	}
    }
}

int main(){
    fastio();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}	

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char W[11],T[1001];
    int i,num=0;
    scanf("%s",W);
    while(1){
        scanf("%s",T);
        if(strcmp(T,"END_OF_TEXT")==0){
            break;
        }
        for(i=0;i<strlen(T);i++){
            if(T[i]>='A' && T[i]<='Z'){
                T[i] += 32;
            }
        }
        if(strcmp(T,W)==0){
            num++;
        }
    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 2064
#include<iostream>
#include<string>
using namespace std;
int dice[6] ;

void Dice(string a,int dice[]){
  int dicetmp[6];
    for(int i = 0;i<6;i++){
      dicetmp[i] = dice[i];
    }
   if(a == "Right"){
    dice[0] = dicetmp[0];
    dice[1] = dicetmp[2];
    dice[2]  = dicetmp[3];
    dice[3]  = dicetmp[4];
    dice[4] = dicetmp[1];
    dice[5] = dicetmp[5];
  } else 
     if(a == "Left"){
    dice[0] = dicetmp[0];
    dice[1] = dicetmp[4];
    dice[2]  = dicetmp[1];
    dice[3]  = dicetmp[2];
    dice[4] = dicetmp[3];
    dice[5] = dicetmp[5];
  } else 

  if(a == "North"){
    dice[0] = dicetmp[3];
    dice[1] = dicetmp[0];
    dice[2]  = dicetmp[2];
    dice[3]  = dicetmp[5];
    dice[4] = dicetmp[4];
    dice[5] = dicetmp[1];
  } else 
    if(a == "West"){
    dice[0] = dicetmp[4];
    dice[1] = dicetmp[1];
    dice[2]  = dicetmp[0];
    dice[3]  = dicetmp[3];
    dice[4] = dicetmp[5];
    dice[5] = dicetmp[2];
  } else 
if(a == "South"){
    dice[0] = dicetmp[1];
    dice[1] = dicetmp[5];
    dice[2]  = dicetmp[2];
    dice[3]  = dicetmp[0];
    dice[4] = dicetmp[4];
    dice[5] = dicetmp[3];
  } else
if(a == "East"){
    dice[0] = dicetmp[2];
    dice[1] = dicetmp[1];
    dice[2]  = dicetmp[5];
    dice[3]  = dicetmp[3];
    dice[4] = dicetmp[0];
    dice[5] = dicetmp[4];
  }

}
  
  int main(){
    
    int n,s; string dist;
    while(cin >> n){
      if(n == 0)
	return 0;
      dice[0]=1;dice[1]=5;dice[2]=4;dice[3]=2;dice[4]=3;dice[5]=6; 
      
      s = 1;
      for(int i = 0;i<n;i++){
	cin >> dist;
	 Dice(dist,dice);
	s = s + dice[0];
      }
      cout << s <<endl;
    }
  }
     

Measured memory_bytes: 0
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long[10 ^^ 5] dp;
    dp[] = long.max;
    dp[0] = 0;
    long N = lread();
    auto h = aryread();
    foreach (i; 0 .. N - 2)
    {
        dp[i + 1].minAssign(dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2].minAssign(dp[i] + abs(h[i] - h[i + 2]));
    }
    dp[N - 1].minAssign(dp[N - 2] + abs(h[N - 2] - h[N - 1]));
    dp[N - 1].writeln();
}


Measured memory_bytes: 4892
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	string T="AKIHABARA";
	string K="KIHBR";
	int shift=0;
	int permit[6]={1,0,0,1,1,1};
	int nowper=0;
	rep(i,S.size()){
		if(S[i]=='A'){
			if(nowper<permit[shift]){
				nowper++;
			}
			else{
				prin("NO");
				return 0;
			}
		}
		else if(shift<5&&S[i]==K[shift]){
			shift++;
			nowper=0;
		}
		else{
			prin("NO");
			return 0;
		}
	}
	if(shift==5) prin("YES");
	else prin("NO");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1],b[n];
	for(int i=1;i<n;i++)
	cin>>b[i];
	a[1]=b[1];
	a[2]=b[1];
	for(int i=2;i<n;i++)
	{
		if(a[i]>b[i])
		a[i]=b[i];
		a[i+1]=b[i];
	}
	long long s=0;
	for(int i=1;i<=n;i++)
	{
		s+=a[i];
	}
	cout<<s;
 } 

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

using namespace std;

const int INF=1e9;

typedef pair<int,int> P;

priority_queue<P, vector<P>, greater<P> > M;

vector<P> edge[200005];

int N[100005];
int K;

void dijkstra(){

while(!M.empty()){

P q=M.top(); M.pop(); 

int cst=q.first; int num=q.second; 

for(int i=0; i<edge[num].size(); i++){

  int node=edge[num][i].first;
  int cost=edge[num][i].second;

  if(N[node]>cst+cost){
    N[node]=cst+cost;
    M.push(P(N[node],node));
  }

}

}

return;

}

int main() {

cin>>K;

for(int i=0; i<K; i++){
  N[i]=INF;
  if(i<K-1) edge[i].push_back(P(i+1,1));
  else edge[i].push_back(P(0,1));
  int to=(i*10)%K;
  edge[i].push_back(P(to,0));
}


M.push(P(0,1)); N[1]=0;

dijkstra();

cout<<N[0]+1<<endl;

}


Measured memory_bytes: 9084
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//string[] s = Console.ReadLine().Split();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			long ans = LCM(a, b);
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		#region 最小公倍数 long LCM(long a, long b)
		public static long LCM(long a, long b)
		{
			long gcd;
			if (b == 0) {
				gcd = a;
			} else {
				long x = a, y = b;
				long tmp = x % y;
				while (tmp != 0) {
					x = y;
					y = tmp;
					tmp = x % y;
				}
				gcd = y;
			}
			return a / gcd * b;
		}
		#endregion

	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEsL 2e9
#define PIE 3.1415a926535

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 T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    string s;
    cin>>s;
    if (s[0] == s[1] && s[1] == s[2]) {
        cout << "No" << endl;
    }
    else
        cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  char S[10];
  int i;
  int a = 0,b = 0,c = 0,d = 0;
        for(i = 0; i < n; ++i){
  scanf("%s", S);
        if(S[0] == 'A'){
        a++;
        }
        if(S[0] == 'W'){
        b++;
        }
        if(S[0] == 'T'){
        c++;
        }
        if(S[0] == 'R'){
        d++;
        }
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);
  
  return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[510][510];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
	}
	vector<pair<int,pair<int,int> > >v;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(p[i][j]%2){
			if(i<a-1){
				p[i][j]--;
				p[i+1][j]++;
				v.push_back(make_pair(0,make_pair(i,j)));
			}else if(j<b-1){
				p[i][j]--;
				p[i][j+1]++;
				v.push_back(make_pair(1,make_pair(i,j)));
			}
		}
	}
	printf("%d\n",v.size());
	for(int i=0;i<v.size();i++){
		printf("%d %d %d %d\n",v[i].second.first+1,v[i].second.second+1,v[i].second.first+1+(1-v[i].first),v[i].second.second+1+(v[i].first));
	}
}


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

int main() {
    int A, B;
    cin >> A >> B ;
    if(A <6){
        cout << 0 << endl;
    } else  if(A>12){
        cout << B << endl;
    } else {
        cout << B/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second
 
int n;
int a[200009];
int b[200009];
 
main(){
	cin>>n;
	r(i,n)cin>>a[i]>>b[i];
	int sum=0,sum2=0;
	r(i,n){
		sum += a[i]*b[i];
		sum2 += b[i];
	}

	cout<< sum2-1 + (sum-1)/9 <<endl;
}

Measured memory_bytes: 3328
/**
     **author : _KMS_
     **created : 05-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =6e5,MOD=2e9;
typedef long long ll;
set<int>st;
int main() {
      
   ios::sync_with_stdio(false);
   cin.tie(0);
    int n;
   cin>>n;
  for(int i=0;i<n;i++)
  {int a;cin>>a;st.insert(a);}
  ((int)st.size()==n)?puts("YES"):puts("NO");
               
   return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

double s(double n)
{
    return (1.0 + n) * n / 2.0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<double> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    double odp = 0;
    double ex = 0;
    for (int i = 0; i < k; ++i)
        ex += 1.0 / a[i] * s(a[i]);
    odp = max(odp, ex);
    for (int l = 1, p = k; p < n; ++l, ++p)
    {
        ex -= 1.0 / a[l - 1] * s(a[l - 1]);
        ex += 1.0 / a[p] * s(a[p]);
        odp = max(odp, ex);
    }
    cout << fixed << setprecision(6);
    cout << odp;
    return 0;
}


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

ll solve(ll a, ll b, ll c) {
  ll ret = 0;
  if(abs(a - b) % 2 == 0) {
    ret = abs(a - b) / 2;
    if(max(a, b) <= c) {
      ret += c - max(a, b);
    } else {
      ret += (max(a, b) - c + 1) / 2;
      if((max(a, b) - c) % 2 == 1) ret++;
    }
  } else return 1LL << 60;
  return ret;
}

int main(void) {
  ll A, B, C;
  cin >> A >> B >> C;

  ll ans = 1LL << 60;
  ans = min(ans, solve(A, B, C));
  ans = min(ans, solve(A, C, B));
  ans = min(ans, solve(B, A, C));
  ans = min(ans, solve(B, C, A));
  ans = min(ans, solve(C, A, B));
  ans = min(ans, solve(C, B, A));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N, X;

int f(int a, int b) {
    if (a == 0 || b == 0) return 0;
    if (b < a) swap(a, b);
    if (b % a == 0) return 2 * (b / a) * a - a;
    return 2 * (b / a) * a + f(a, b % a);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N >> X;
    cout << N + f(N - X, X) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

pii score(){
    int id,in;
    cin >> id;
    vp v;
    //first:ピンの数、second:0無,1スペア,2ストライク
    rep(i,9){
        int sum = 0;
        cin >> in;
        if(in == 10){//ストライク
            v.push_back(pii(in,2));
        }else{
            sum += in;
            cin >> in;
            v.push_back(pii(sum,0));
            v.push_back(pii(in,sum+in == 10));
        }
    }
    int sum = 0;
    cin >> in;
    sum += in;
    v.push_back(pii(in,0));
    cin >> in;
    sum += in;
    v.push_back(pii(in,0));
    if(sum >= 10){
        cin >> in;
        sum += in;
        v.push_back(pii(in,0));
    }

    int ret = 0;
    rep(i,v.size()){
        ret += v[i].first;
        if(v[i].second >= 1 && i+1 < v.size()){
            ret += v[i+1].first;
        }
        if(v[i].second == 2 && i+2 < v.size()){
            ret += v[i+2].first;
        }
    }
    //cout << "!" << ret << " " << id << endl;
    return pii(-ret, id);
}


signed main(void) {
    int m;
    while(cin >> m, m){
        vp v;
        rep(i,m)v.push_back(score());
        sort(all(v));
        rep(i,m){
            cout << v[i].second << " " << -v[i].first << endl;
        }

    }
}



Measured memory_bytes: 3116
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n;
ll a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) cin>>a[i];
    ll count=0;
    for(int i=0;i<n;i++){
        while(true){
            if(a[i]%2==1)break;
            a[i]=a[i]/2;
            count++;
        }
    }
    cout << count<< "\n";
}

Measured memory_bytes: 384
#include  <stdio.h>
#include <stdbool.h>

#define N 8
#define FREE -1
#define NOTFREE 1


void intialize();
void printboard();
void recursive(int);

int row[N],col[N],drops[2*N-1],dneg[2*N-1];
bool x[N][N];

int main (){
  int i,j,k,r,c;
  intialize();
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      x[i][j]=0;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    x[r][c]=1;
  }
  recursive(0);

  return 0;
}
void intialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<2*N-1;i++){
    drops[i]=FREE;
    dneg[i]=FREE;
  }
}
void printboard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]){
	if(row[i]!=j)
	  return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)
	printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void recursive(int i){
  int j;
  if(i==N){
    printboard();
    return;
  }
  for(j=0;j<N;j++){
    if(NOTFREE==col[j]||NOTFREE==drops[i+j]||NOTFREE==dneg[i-j+N-1])
      continue;

    row[i]=j;
    col[j]=drops[i+j]=dneg[i-j+N-1]=NOTFREE;

    recursive(i+1);
    row[i]=col[j]=drops[i+j]=dneg[i-j+N-1]=FREE;
  }
}
 


Measured memory_bytes: 2112
#include <string>
#include <queue>
#include <iostream>

using namespace std;

struct P {
    string name;
    int req;
};

int main() {
    queue<P> que;
    int n, q;
    cin >> n >> q;
    P p[n], pp;
    for (int i = 0; i < n; i++) {
        cin >> p[i].name >> p[i].req;
        que.push(p[i]);
    }

    int timer = 0;
    while (!que.empty()) {
        pp = que.front();
        if (pp.req > q) {
            pp.req -= q;
            timer += q;
            que.pop();
            que.push(pp);
        } else {
            timer += pp.req;

            cout << que.front().name << " " << timer << endl;
            que.pop();
        }
    }

    return 0;
}



Measured memory_bytes: 7072
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;

ll a[200010];

int main()
{
    ll n,t;
    while(scanf("%lld%lld",&n,&t)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%lld",&a[i]);
        ll sum=t;
        for(int i=n-2;i>=0;i--)
        {
            sum+=min(a[i+1]-a[i],t);
        }
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct edge_t {
  int to, w;
};

using weight_t = pair<int, int>;

const weight_t inf = {400, 1e9 + 10};

vector<int> solve(const vec<edge_t, 2>& g, int L, int s) {
  int V = g.size();
  vector<weight_t> dist(V, inf);
  vector<int> in_q(V, 1);
  dist[s] = {0, 0};
  int q_size = V;
  while (q_size > 0) {
    int v = -1;
    for (int i = 0; i < V; i++) {
      if (in_q[i] && (v == -1 || dist[i] < dist[v])) v = i;
    }
    in_q[v] = 0;
    --q_size;
    const weight_t w = dist[v];
    vector<weight_t> ws = {w, {w.fst + 1, 0}};
    for (auto w : ws) {
      for (const auto& e : g[v]) {
        if (w.snd + e.w > L) continue;
        const weight_t nw = {w.fst, w.snd + e.w};
        chmin(dist[e.to], nw);
      }
    }
  }
  vector<int> res(g.size(), -1);
  for (int v = 0; v < g.size(); v++) {
    if (dist[v] != inf) res[v] = dist[v].fst;
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M, L;
  while (cin >> N >> M >> L) {
    vec<edge_t, 2> g(N);
    for (int i = 0; i < M; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      if (c > L) continue;
      g[a].push_back({b, c});
      g[b].push_back({a, c});
    }
    vec<int, 2> ans(N);
    for (int i = 0; i < N; i++) ans[i] = solve(g, L, i);
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
      int s, t;
      cin >> s >> t;
      --s;
      --t;
      cout << ans[s][t] << endl;
    }
  }
  return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll x;
    cin >> x;
    for (ll a = -119; a <= 120; a++)
    {
        for (ll b = -120; b <= 119; b++)
        {
            ll ans = pow(a, 5) - pow(b, 5);
            if (ans == x)
            {
                cout << a << " " << b << "\n";
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int N = scan.nextInt();

		long[] A = new long[N];

		long sum = 0L;

		for (int i = 0; i < N; i++) {
			A[i] = scan.nextLong();
			sum += A[i];
		}

		//演算
		long result = 0L;
		long con = 1000000007L;

		for (int i = 0; i < N; i++) {
			sum -= A[i];
			result += ((sum % con) * A[i]) % con;
			result %= con;
		}

		//結果出力
		System.out.println(result);
	}
}


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

int main()

{
    char str[27];
    int  count=0,i,j, length;
    gets(str);

    length = strlen(str);

    for(i=0; i<length; i++){
        for(j=0; j<length; j++){
            if(str[j]==str[i]) count++;
        }
    }
    if(count>length) printf("no\n");
    else printf("yes\n");

    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
N = int(input())
B = list(map(int, input().split()))
num = B[0] + B[N-2]

for cnt in range(N-2):
  if B[cnt] < B[cnt+1]:
    num += B[cnt]
  else:
    num += B[cnt+1]

print(num)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long modpow(long long a,long long n){
    long long x=1;
    while(n>0){
        //nの2進数表記の右端が1
        if(n&1){
            x=x*a%MOD;
        }
        a=a*a%MOD;
        n>>=1; //nを右に1bitずらす
    }
    return x;
}
int main(){
    string s; cin>>s;
    int n=s.size();
    long long a=0,c=0,ql=0,qr=0;
    rep(i,n){
        if(s[i]=='C') c++;
        if(s[i]=='?') qr++;
    }
    long long ans=0;
    rep(i,n){
        if(s[i]=='A') a++;
        if(s[i]=='C') c--;
        if(s[i]=='B'||s[i]=='?'){
            if(s[i]=='?') qr--;
            // abc
            ans+=(((a*modpow(3,ql))%MOD)*((c*modpow(3,qr))%MOD))%MOD;
            // ab?
            ans+=(((a*modpow(3,ql))%MOD)*((qr*modpow(3,qr-1))%MOD))%MOD;
            // ?bc
            ans+=(((ql*modpow(3,ql-1))%MOD)*((c*modpow(3,qr))%MOD))%MOD;
            // ?b?
            ans+=(((ql*modpow(3,ql-1))%MOD)*((qr*modpow(3,qr-1))%MOD))%MOD;
            ans%=MOD;
            if(s[i]=='?') ql++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    ll n,a,b; cin>>n>>a>>b;
    ll ans=0,rem;
    ans+=a*(n/(a+b));
    rem=n%(a+b);
    ans+=min(rem,a);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>
#include <queue>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }

typedef long long ll;
using namespace std;

int main() {
    
    ll l;
    cin >> l;
    vector<ll> a(l+1, 0);
    REP(i, l) cin >> a[i];

    ll ans = 0;
    vector<vector<ll>> dp(l+2, vector<ll>(5, 0));
    REP(i, l+1) {
        dp[i+1][0] = dp[i][0] + a[i];
        dp[i+1][1] = min({dp[i][1], dp[i][0]})                               + (a[i] ? a[i] % 2 : 2);
        dp[i+1][2] = min({dp[i][2], dp[i][1], dp[i][0]})                     + (a[i] + 1) % 2;
        dp[i+1][3] = min({dp[i][3], dp[i][2], dp[i][1], dp[i][0]})           + (a[i] ? a[i] % 2 : 2);
        dp[i+1][4] = min({dp[i][4], dp[i][3], dp[i][2], dp[i][1], dp[i][0]}) + a[i];
    }

    cout << dp[l+1][4] << endl;

}

Measured memory_bytes: 15872
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp1 = input[0].split(" ");
	tmp2 = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(tmp1[0], 10);
	//var k = parseInt(tmp1[1], 10);
	
	
	
	// var tmp = input[1].split(" ");
     var i = 0;
   var a = [];
for (var i = 0; i < n ; i++){
  var r= parseInt(tmp2[i], 10);
    a[i] = r;}
 // console.log(a);

  var t = 0;cnt = 0;t=a[0];
  for (i=0;i<n;i++){
                    if(t>=a[i]){cnt ++;
                                  t=a[i];}
                    }
                    console.log(cnt);
        
  }


 



	//出力


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 35384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,s=0;
    cin>>n>>m;
    int a[n];
    for(int i=0 ; i<n ; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int j=0 ; j<m ; j++)
    {
        s+=a[j];
    }
    cout<<s<<endl;


    return 0;

}






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


int main()
{
    vector<int> vec;

    int n,m,res,i=0;
    cin>>n>>m;
    while(m--){

      cin>>i;
      vec.push_back(i);
        i++;
    }
   for(int i=0;i<vec.size();i++){
       n-=vec[i];
       if(n<0){
          n=-1;
          break;
       }
    }
    cout<<n<<endl;


    return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;

#define SIZE 300
#define INF 1000000000

int dist[SIZE][SIZE];
int dp[17][1<<16];

bool solve() {
  int N, M, L, S, T;
  int J[18], E[18];

  scanf("%d%d%d%d%d", &N, &M, &L, &S, &T);
  S--;

  if (N == 0) return false;

  for (int i=0; i<N; i++)
    for (int j=0; j<N; j++)
      dist[i][j] = INF * (i != j);

  for (int i=0; i<M; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--; b--;
    dist[a][b] = dist[b][a] = c;
  }

  for (int k=0; k<N; k++)
    for (int i=0; i<N; i++)
      for (int j=0; j<N; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  for (int i=0; i<L; i++) {
    scanf("%d%d", J+i, E+i);
    J[i]--;
  }
  J[L] = S; E[L] = 0;

  for (int i=0; i<=L; i++)
    for (int j=0; j<(1<<L); j++)
      dp[i][j] = INF;

  dp[L][0] = 0;

  for (int i=0; i<(1<<L); i++) {
    for (int j=0; j<=L; j++) {
      for (int k=0; k<=L; k++) {
        if (i & (1<<k)) continue;

        int b = k != L ? 1 << k : 0;

        dp[k][i|b] = min(dp[k][i|b], dp[j][i] + dist[J[j]][J[k]] + E[k]);
      }
    }
  }

  int ans = 0;

  for (int i=0; i<(1<<L); i++) {
    if (dp[L][i] <= T)
      ans = max(ans, __builtin_popcount(i));
  }

  cout << ans << endl;

  return true;
}

int main() {
  while(solve());
}



Measured memory_bytes: 7804