akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define DS       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    double a, b;
    cin >> a >> b;
    set<int> s;
    s.insert(floor(a / 0.08));
    s.insert(ceil(a / 0.08));
    s.insert(floor(b / 0.1));
    s.insert(ceil(b / 0.1));
    for (int i = *s.begin(); i <= *s.rbegin(); i++) {
        int x = (double)i * 0.08;
        int y = (double)i * 0.1;
        if (x == a && y == b) {
            cout << i << '\n';
            return 0;
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        l: i32,
        r: i32,
        d: i32,
    }

    if l % d == 0 {
        println!("{}", r / d - l / d + 1);
    } else {
        println!("{}", r / d - l / d);
    }
}

Measured memory_bytes: 2112
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#define pb push_back
#define mkp make_pair
using namespace std;

const int maxn = 200005;
typedef long long ll;

int n,a,b;

int main()
{
    string s;
    cin>>n>>a>>b>>s;
    int cnt = 0,o = 0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='a')
        {
            if(cnt<a+b)
            {
                puts("Yes");
                cnt++;
            }
            else
            {
                puts("No");
            }
        }
        else if(s[i]=='b')
        {
            if(cnt<a+b&&o<b)
            {
                puts("Yes");
                cnt++;
            }
            else
            {
                puts("No");
            }
            o++;
        }
        else
            puts("No");
    }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define CLR(a) a.clear()
#define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
#define SIZE(a) a.size()
#define ERASE(a, b) memset(a, b, sizeof a)
#define PB(a, b) a.push_back(b)
#define PB2(a,i,b) a[i].push_back(b)
#define LL long long
#define ULL unsigned long long
#define DBG cout<<"I Am Here"<<endl
#define DBGA(a) cout<<a<<endl
#define DBGI(b,a) cout<<b<<' '<<a<<endl
#define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
#define INF 1e9
#define INV 1e-6
#define sll(a) scanf("%I64d", &a)
#define pll(a) printf("%I64d\n", a)
#define si(a) scanf("%d", &a)
#define pii pair<LL,LL>
#define MAX 100006
#define CASE(i) printf("Case %d: ", i);
#define CSH(i) printf("Case #%d: ", i);
#define PI acos(-1)
#define piis pair<int, string>
#define fast1 ios_base::sync_with_stdio(false);
#define fast2 cin.tie(0)
#define CHECK_BIT(var,pos) ((var & (1 << pos)) == (1 << pos))
 
 
LL MOD = 1000000007;
 
using namespace std;
 
LL bigmod(LL b, LL p, LL m)
{
    if(p==0)  return 1;
    if(p%2==0)
    {
        LL x = bigmod(b,p/2,m);
        return (x%m * x%m)%m;
    }
    else return ((b%m)*bigmod(b,p-1,m)%m)%m;
}
 
 
LL MODINVERSE(LL a)
{
    return bigmod(a, MOD-2, MOD);
}
 
LL arr[104];
 
int main()
{
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i=1; i<=n; i++){
        scanf("%lld", &arr[i]);
        if(i>1){
            if(arr[i]!=arr[i-1]) cnt++;
        }
    }
    if(cnt==0){
        printf("0");
        return 0;
    }
 
    LL cost = 1<<30;
 
    for(int i=-150; i<=150; i++)
    {
        LL sum = 0;
        for(int j=1; j<=n; j++)
        {
            sum = sum + ((arr[j] - i) * (arr[j] - i));
        }
        cost = min(cost, sum);
    }
 
    printf("%lld", cost);
}

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

#define int long long

using namespace std;

signed main()
{
	int k;
	int counts[3];
	vector<int> abc[3];

	cin >> counts[0] >> counts[1] >> counts[2] >> k;

	for(int i = 0; i < 3; ++i)
	{
		abc[i].resize(counts[i]);

		for(int j = 0; j < counts[i]; ++j)
		{
			cin >> abc[i][j];
		}
	}

	vector<int> v;
	for(int i = 0; i < counts[0]; ++i)
	{
		for(int j = 0; j < counts[1]; ++j)
		{
			v.push_back(abc[0][i] + abc[1][j]);
		}
	}

	sort(v.begin(), v.end(), greater<int>());

	vector<int> v2;
	for(int i = 0; i < min(k, (int)v.size()); ++i)
	{
		for(int j = 0; j < counts[2]; ++j)
		{
			v2.push_back(v[i] + abc[2][j]);
		}
	}

	sort(v2.begin(), v2.end(), greater<int>());

	for(int i = 0; i < k; ++i)
	{
		cout << v2[i] << endl;
	}
}

Measured memory_bytes: 43368
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30
#define UNDER 10000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int t[UNDER+10][5], n;

int count(){
  int res = 0;
  rep(i, UNDER) rep(j, 5) if(t[i][j] == 1) res++;
  return res;
}

void deleteblock(){
  for(int y = UNDER-1; y >= 0; y--){
    int f = 0;
    rep(i, 5) if(t[y][i] == 0){ f = 1; break;}
    if(f) continue;
    rep(i, 5){
      for(int c = y; c > 0; c--){
	t[c][i] = t[c-1][i];
      }
    }
    t[0][0] = t[0][1] = t[0][2] = t[0][3] = t[0][4] = 0;
    y++;
  }
  return;
}

int main(){
  while(scanf("%d", &n) && n){
    int d, p, q;
    memset(t, 0, sizeof(t));
    rep(i, 5) t[UNDER][i] = 1;

    rep(i, n){
      scanf("%d%d%d", &d, &p, &q); q--;
      if(d == 1){
	REP(y, 1, UNDER+1){
	  int f = 0;
	  REP(x, q, q+p) if(t[y][x] == 1) f = 1;
	  if(!f) continue;
	  REP(x, q, q+p) t[y-1][x] = 1;
	  break;
	}
      }else{
	rep(y, UNDER+1){
	  if(!t[y][q]) continue;
	  for(int c = y-1; c > y-p-1; c--) t[c][q] = 1;
	  break;
	}
      }
      deleteblock();
      /*      REP(i, 990, UNDER+1){
	rep(j, 5) printf("%d ", t[i][j]); puts("");
	}*/
    }

    printf("%d\n", count());
  }
  return 0;
}

Measured memory_bytes: 1392
import sys
N = int(input())
B = [int(i) for i in input().split()]

A =[]
if N == 2:
    print(N*B[0])
    sys.exit()
else:
    if B[1] >= B[0]:
      A.append(B[0])
      A.append(B[0])
    else:
      A.append(B[0])
      A.append(B[1])
    for i in range(1,len(B)-1):
        if B[i+1] >= B[i]:
          A.append(B[i])
        else:
          A.append(B[i+1])
 
x = 0
for y in A:
  x = x + y
print(x+B[-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
int main()
{
    ll n;
    cin>>n;
    ll m=n,sum=0;
    while(m>0)
    {
        sum+=m%10;
        m=m/10;
    }
  //  cout<<sum<<endl;
    if(n%sum==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define fi first
#define se second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,b,a) for(ll i = b;i>=a;i--)
#define sz size()
#define PQ priority_queue
#define len length()
#define mll map<ll,ll>
#define mpll map<pll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pair<ll,ll> >
#define mp(x,y)  make_pair(x,y)
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define ALL(v) v.begin(),v.end()
#define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const ll MAX = 405;

int main() {
    
    string s,t;
    cin>>s>>t;
    int n = s.len,m = t.len;
    int ans = 10000;
    For(i,0,n){
        int cur = 0;
        if(i+m>n)break;
        For(j,i,m+i){
            if(s[j]!=t[j-i])cur++;
        }
        ans = min(ans,cur);
       // cout<<cur<<" ";
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string S;
    cin >> S;
    int sum = 0;
    for (int i = 0; i < S.size()/2; i++) {
        if (S[i] != S[S.size() - i - 1]) sum++;
    }
    cout << sum << endl;
    return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	while(cin >> n){
		ll sum[n+5] = {};
		f(n){
			cin >> sum[i];
		}
		ll ans = 0;
		for(ll i=1LL<<40;i>=2;i>>=1){
			ll ff = ans + i;
			//cout<<ff/2<<' '<<min(sum[0],sum[1])<<endl;
			if(ff/2>min(sum[0],sum[n-1]))continue;
			ll now = ff/2;
			fr(j,0,n-1){
				now = sum[j]-now;
			}
			//cout<<now+ff/2<<' '<<sum[n-1]<<endl;
			if(now+ff/2>sum[n-1]&&n%2==0){
				ans += i;
			}
			else if(now+ff/2<sum[n-1]&&n%2==1){
				ans += i;
			}
			else if(now+ff/2==sum[n-1]){
				ans += i;
				break;
			}
		}
		f(n){
			cout << ans <<' ';
			ans = (sum[i] - ans/2)*2; 
		}
		cout << endl;
	}
}

Measured memory_bytes: 2176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>

using namespace std;

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

//10^9 + 7
const ll MOD = 1000000007;

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

	ll array[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	cout << array[K - 1] << endl;
}

Measured memory_bytes: 256
a,b,c,x = 4.times.map{ gets.to_i }
cnt = 0
(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      cnt += 1 if i * 500 + j * 100 + k * 50 == x
    end
  end
end

puts cnt

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

int main(){
  int N; cin>>N;
  vector<int> d(N);
  for (int i=0;i<N;++i)cin>>d[i];
  
  sort(d.begin(),d.end());
  int left =d[N/2-1];
  int right =d[N/2];
  
  cout<<right-left<<endl;
}

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

int main(){
  long long int x,count=0;

  scanf("%lld",&x);

  count+=(x/11)*2;
  x-=count/2*11;
  if(x>=7)count+=2;
  else if(0<x&&6>=x) count++;

  printf("%lld\n",count);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a, b, c;
	cin >> a >> b >> c;
	if (a==b&&b==c)
	{
		cout << "No" << endl;
		return 0;
	 } 
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  vector<P> v(n);
  for(int i=0; i<n; ++i){
    cin >> v[i].first;
    v[i].second = i+1;
  }
  sort(v.begin(),v.end());
  for(int i=0; i<n; ++i){
    printf("%d",v[i].second);
    if(i == n-1) printf("\n");
    else printf(" ");
  }
}

Measured memory_bytes: 4020
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll dp[101010];
int main(){
    int n,k;
    cin>>n>>k;
    ll h[n];
    rep(i,n)cin>>h[i];
    rep(i,n)dp[i]=longinf;
    dp[0]=0;
    rep(i,n)rep(j,k){
        dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(h[i+j+1]-h[i]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

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

map<ll, ll> prime;

void Factor(ll n){
    ll sq = sqrt(n) + 1;
 
    for(int i = 2; i <= sq; ++i){
        sq = sqrt(n) + 1;
        if(n%i == 0){
            if(prime.find(i) == prime.end())prime[i] = 0;
            while(n%i == 0){
                n /= i;
                prime[i]++;
            }
        }
    }
 
    if(n != 1){
        if(prime.find(n) == prime.end())prime[n] = 1;
        else prime[n]++;
    }
}

int main(){
    ll n;
    cin >> n;
    rep(i, n)Factor(i+1);

    ll over3, over5, over15, over25, over75;
    over3 = over5 = over15 = over25 = over75 = 0; 

    all_map(itr, prime){
        ll cnt = itr->second + 1;
        if(cnt >= 3)over3++;
        if(cnt >= 5)over5++;
        if(cnt >= 15)over15++;
        if(cnt >= 25)over25++;
        if(cnt >= 75)over75++;
    }

    ll com = over5*(over5-1)/2;

    ll ans = over75 + (over25)*(over3-1) + over15*(over5-1) + com*(over3-2);

    cout << max((ll)0, ans) << endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        BigDecimal a = sqrt(new BigDecimal(scanner.nextLong()), 50);
        BigDecimal b = sqrt(new BigDecimal(scanner.nextLong()), 50);
        BigDecimal c = sqrt(new BigDecimal(scanner.nextLong()), 50);
        if(a.add(b).compareTo(c) == -1) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

    public static BigDecimal sqrt(BigDecimal a, int scale){

        BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
        if(scale < 17){
            x = x.setScale(scale, BigDecimal.ROUND_HALF_EVEN);
            return x;
        }

        BigDecimal b2 = new BigDecimal(2);
        for(int tempScale = 16; tempScale < scale; tempScale *= 2){
            x = x.subtract(
                    x.multiply(x).subtract(a).divide(
                            x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
        }
        return x;
    }
}

Measured memory_bytes: 22228
import java.util.Scanner;

class Main{
   private static double a;

    
  public static void main(String[] args){
    
    Scanner s= new Scanner(System.in);
    a=s.nextDouble();
   double num=Math.PI;
  System.out.printf("%.6f %.6f\n",(a*a*num),(2*a*num));
    
    
  
      
      
      
  }}


Measured memory_bytes: 28392
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define deb(x) cout << #x << " = " << x << ' ';
#define rep(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 998244353;
const int N = 2e5+2;


int main()
{
    int n;
    scn(n);

    ll p = 1, lim = 1e18;

    // cout << lim;

    bool fnd = 0;

    rep(i, 0, n) {
        ll val;
        lscn(val);

        if(val == 0)
            fnd = 1;

        if(val != 0)
        lim /= val;

        if(lim != 0) {
            p *= val;
        }
    }

    // cout << p << ' ';

    if(fnd || lim > 0) {
        if(fnd) {
            cout << 0;
        } else {
            cout << p;
        }
    } else {
        cout << -1;
    }

    return 0;
}

Measured memory_bytes: 3764
#include<stdio.h>
void swap (int *x ,int *y){
	int t;
  t = *x;
  *x = *y;
  *y = t;
}
int main (void){
  int X,Y,Z;
  scanf(" %d %d %d",&X,&Y,&Z);
  swap(&X,&Y);
  swap(&X,&Z);
  printf("%d %d %d",X,Y,Z);
}

Measured memory_bytes: 1736
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    
    String S = stdIn.next();
    String T = stdIn.next();
    
    int count = 0;
    for(int i = 0;i < S.length();i++){
      if(S.charAt(i) == T.charAt(i)){
        count++;
      }
      else
        break;
    }
    
    if(count == S.length() && S.length() + 1 == T.length())
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

      
    

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

int main(){
  int n;
  int d_words[5]={5,7,5,7,7};
  while(cin>>n && n!=0){
    int* n_words=new int[n];
    for(int i=0;i<n;i++){
      string str;
      cin>>str;
      n_words[i]=str.size();
    }
    int start=0;
    int success=0;
    while(!success){
      int t_words=0;
      int tmp=start;
      int tmp2=0;
      while(1){
        tmp2+=n_words[tmp];
        if(tmp2==d_words[t_words]){
          t_words++;
tmp2=0;
          if(t_words==5){
            success=start+1;
            break;
          }
}else if(tmp2>d_words[t_words]){
            break;
          }
       
        tmp++;
      }
      start++;
    }
    cout<<success<<endl;
  }
}



Measured memory_bytes: 3212
S = input()
zero = []
turn = []

def sum_n(n):
    return (n ** 2 + n) // 2

for i, s in enumerate(S):
    if i == 0:
        if s == '<':
            zero.append(i)
        else:
            turn.append(i)
            zero.append(-1)
    else:
        if s_ == '>' and s == '<':
            zero.append(i)
        elif s_ == '<' and s == '>':
            turn.append(i)
    if i == len(S) - 1:
        if s == '>':
            zero.append(i + 1)
        else:
            turn.append(i + 1)
            zero.append(i + 2)
    s_ = s

#print(len(zero), zero)
#print(len(turn), turn)

ans = 0

for i in range(len(turn)):
    ans += sum_n(zero[i+1] - turn[i] - 1)
    ans += sum_n(turn[i] - zero[i] - 1)
    ans += max(zero[i+1] - turn[i], turn[i] - zero[i])
print(ans)

Measured memory_bytes: 52040
#include<bits/stdc++.h>
using namespace std;
string  s;
int main()
{
    cin>>s;
    if(s[s.size()-1]=='s')
    {
        cout<<s;
        cout<<"es"<<endl;
    }
    else
    {
        cout<<s;
        cout<<'s'<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    int N,Q,K;
    ll dis[MAXN];
    int vis[MAXN];
    vector<pair<int,int>>G[MAXN];
    void dfs(int root,ll sum){
        dis[root]=sum;
        vis[root]=true;
        for(auto e:G[root]){
            if(vis[e.first])continue;
            dfs(e.first,sum+e.second);
        }
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N;
        for(int u=0;u<N-1;u++){
            int a,b,c;
            cin>>a>>b>>c;
            G[a].push_back({b,c});
            G[b].push_back({a,c});
        }
        cin>>Q>>K;
        dfs(K,0);
        while(Q--){
            int x,y;
            cin>>x>>y;
            cout<<dis[x]+dis[y]<<"\n";
        }
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, tmp, ans = 0;
	cin >> nn;
	if(nn == 1)
	{
		cout << 0 << endl;
		return 0;
	}
	set<int64> memo;
	for(int64 ii = 2;ii <= sqrt(nn);ii++)
	{
		if(nn % ii == 0)
		{
			memo.insert(ii);
			memo.insert(nn / ii);
		}
	}
	memo.insert(nn);
	for(auto ite = memo.begin();ite != memo.end();ite++)
	{
		tmp = *ite;
		tmp--;
		if(nn % tmp == nn / tmp)
		{
			ans += tmp;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
    Int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    
    priority_queue<int, vector<int>, greater<int>> p;
    priority_queue<int, vector<int>, greater<int>> q;
    priority_queue<int> r;

    rep(i,A) {
        int pi;
        cin >> pi;
        p.push(pi);
    }

    rep(i,B) {
        int qi;
        cin >> qi;
        q.push(qi);
    }

    rep(i,C) {
        int ri;
        cin >> ri;
        r.push(ri);
    }

    if (A - X > 0) {
        rep(i,A-X) p.pop();
    }

    if (B - Y > 0) {
        rep(i,B-Y) q.pop();
    }

    Int ans = 0;

    priority_queue<int> all;

    while(!p.empty()) {
        all.push(p.top());
        p.pop();
    }

    while(!q.empty()) {
        all.push(q.top());
        q.pop();
    }

    while(!r.empty()) {
        all.push(r.top());
        r.pop();
    }

    rep(i,X + Y) {
        ans += all.top();
        all.pop();
    }

    cout << ans << endl;
}

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

int main()
{
    string str;
    cin >> str;
    long long K;
    cin >> K;
    int ins = 0;
    while(true){
        if(ins >= K){
            cout<<1<<endl;
            return 0;
        }
        if(str.at(ins) != '1'){
            cout<<str.at(ins)<<endl;
            return 0;
        }
        ins++;
    }
    return 0;
}


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

typedef long long ll;
int N, M;
vector<int> arr;
vector<ll> A, B;

void add(int l, int r, ll a, ll b) {
    if(l > r) return;
    A[l] += a;
    B[l] += b;
    A[r + 1] += -a;
    B[r + 1] += -b;
}

int main() {
    scanf("%d %d", &N, &M);
    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        arr[i]--;
    }

    A = vector<ll>(M + 1, 0);
    B = vector<ll>(M + 1, 0);

    for(int i = 0; i < N - 1; i++) {
        if(arr[i] < arr[i + 1]) {
            add(arr[i] + 1, arr[i + 1], -1, arr[i + 1] + 1);
            add(0, arr[i], 0, arr[i + 1] - arr[i]);
            add(arr[i + 1] + 1, M - 1, 0, arr[i + 1] - arr[i]);
        }
        else {
            add(0, arr[i + 1], -1, arr[i + 1] + 1);
            add(arr[i] + 1, M - 1, -1, M + arr[i + 1] + 1);
            add(arr[i + 1] + 1, arr[i], 0, M - arr[i] + arr[i + 1]);
        }
    }

    ll mn = 1e18;
    ll suma = 0;
    ll sumb = 0;
    for(int i = 0; i < M; i++) {
        suma += A[i];
        sumb += B[i];

        //cout << suma << ' ' << sumb << endl;

        mn = min(mn, suma*i + sumb);
    }

    printf("%lld", mn);
}


Measured memory_bytes: 2176
i[15][15];
main(a,x,y)
{
  while(1)
    {
      scanf("%d",&a);
      if(!a)
	exit(0);
      for(x=0;x<a;x++)
	i[a][x]=i[x][a]=i[a][a]=0;
      for(x=0;x<a;x++)
	for(y=0;y<a;y++)
	  {
	  scanf("%d",&i[x][y]);
	  i[a][y]+=i[x][y];
	  i[x][a]+=i[x][y];
	  i[a][a]+=i[x][y];
	  }
      for(x=0;x<=a;x++)
	{
	for(y=0;y<=a;y++)
	  {
	    printf("%5d",i[x][y]);
	    }
	puts("");
	}
    }
}

Measured memory_bytes: 0
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#include<map>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;


long long now, num, N, K, M, ans,sosu[100000];
string S, T;
bool h,w[10], k[100],con[300];
char cc;

int main() {

	cin >> N>> M>>K>>now;
	for (int i = 0; i < N+1; i++) {
		for (int j = 0; j < M+1; j++) {
			for (int k = 0; k < K+1; k++) {
				if (500 * i + 100 * j + 50 * k == now)ans++;
			}
		}
	}
	cout <<ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, a, b;
	cin >> n >> a >> b;
	
	cout << min(a, b) << ' ' << max(0, b+a - n) << '\n';
	
	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	LL n; cin >> n;
	vector<LL> a(n);

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

	LL t = 1;
	LL cnt = 0;
	while (mx > t) {
		cnt++;
		t *= 2;
	}
	
	vector<LL> tb(cnt);

	for (LL i = 0; i < n; i++) {
		for (LL j = 0; j < cnt; j++) {
			if (a[i] & (1LL << j)) {
				tb[j]++;
			}
		}

	}

	LL ans = 0;
	for (LL i = 0; i < n - 1; i++) {
		for (LL j = 0; j < cnt; j++) {
			if (a[i] & (1LL << j)) {
				tb[j]--;
			}
		}

		for (LL j = 0; j < cnt; j++) {
			if (a[i] & (1LL << j)) {
				LL x = n - (i + 1) - tb[j];
				
				x *= (1LL << j)%MOD;
				ans += x;
				ans %= MOD;
			}
			else {
				LL x = tb[j];
				
				x *= (1LL << j) % MOD;
				ans += x;
				ans %= MOD;
			}
		}

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


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;

#define MOD 98244353
long long int ppow(long long int i, long long int j) {
	long long int res = 1LL;
	while (j) {
		if ((j & 1LL)) {
			res *= i;
			if (res >= MOD) {
				res %= MOD;
			}
		}
		j >>= 1;
		i *= i;
		if (i >= MOD) {
			i %= MOD;
		}
	}
	return res;
}


#define MAX 100002

int n;
int m;

vector<pair<int,int> > en[MAX];

vector<pair<int, long long int> > dq;

long long int dist[MAX];

void ins(long long int val, int idx) {
	while (dq.size() && dq.back().second >= val) {
		dq.pop_back();
	}
	dq.push_back(make_pair(idx, val));
}

int main() {
	cin >> n >> m;
	while (m--) {
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		l--;
		r--;
		en[r].push_back(make_pair(l, c));
	}
	for (int i = 0; i < n; i++) {
		dist[i] = LLONG_MAX;
	}
	dist[0] = 0;
	dq.push_back(make_pair(0, 0));
	for (int i = 1; i < n; i++) {
		for (auto f : en[i]) {
			int lef = f.first;
			int cost = f.second;
			int i2 = lower_bound(dq.begin(), dq.end(), make_pair(lef, -1LL)) - dq.begin();
			if (i2 == dq.size())continue;
			dist[i] = min(dist[i], dq[i2].second + cost);
		}
		if (dist[i] != LLONG_MAX) {
			ins(dist[i], i);
		}
	}
	if (dist[n - 1] == LLONG_MAX) {
		puts("-1");
		return 0;
	}
	printf("%lld\n", dist[n - 1]);
	return 0;
}

Measured memory_bytes: 8568
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


# n = II()
# one = [1]
# six = [6 ** i for i in range(1, 6+1)]
# nine = [9 ** i for i in range(1, 5+1)]
# numbers = one + six + nine
# numbers.sort(reverse=True)

N = int(input())
dp = [INF] * 100001
dp[0], dp[1] = 0, 1
L = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
# dp[n]は，n円を引き出す最小引き出し回数
for i in range(2, 100001):
    for j in range(len(L)):
        if i-L[j] >= 0:
            dp[i] = min(dp[i-L[j]]+1, dp[i])
# 100円を引き出す時，まず，100-L[0] = 100-1=99で1円でのみで引き出すことを考える
# dp[100]にまずmin(dp[99]+1，INF)で99円引き出すための最小引き出し回数に1をたす（1円引き出す
# を考える
# 次に，その値と，94円から引き出すための最小回数+1とさっきのdp[99]を比較して，最小値を更新する
# 100000 * 10くらい 1000000くらい
print(dp[N])


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

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int n;
	cin>>n;
	cout<<n*n*n<<endl;
	
	return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int X, A;
int main() {
    cin >> X >> A;

    if (X < A) {
        printf("0\n");
    } else {
        printf("10\n");
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N_MAX 500000
#define LAST 2000000000

int L[(N_MAX/2)+2];
int R[(N_MAX/2)+2];
int count;

void merge(int A[], int n, int left, int mid, int right){
  int i,j,k;
  int n1,n2;

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }

  for(j = 0; j < n2; j++){
    R[j] = A[mid + j];
  }

  L[n1] = R[n2] = LAST;

  i=0;
  j=0;

  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

  void mergeSort(int A[], int n, int left, int right){
    if( left+1 < right ){
      int mid = (left + right)/2;
      mergeSort(A,n,left,mid);
      mergeSort(A,n,mid,right);
      merge(A,n,left,mid,right);
    }
  
  }

int main(){
  int A[N_MAX], n, i;

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

  mergeSort(A,n,0,n);

  for(i=0; i<n; i++){
    if(i > 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

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

  return 0;
}



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

int main(){
    int n;
    cin >> n;
    string s, t, ans;
    cin >> s >> t;
    rep(i,0,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(6) << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;
    
    return 0;
}



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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N,T;
	cin>>N>>T;
	vector<int> c(N);
	vector<int> t(N);
	int C=1001;
	REP(i,N){
		cin>>c[i]>>t[i];
		if(t[i]<=T&&c[i]<C)C=c[i];
	}
	if(C==1001)cout << "TLE" << endl;
	else cout << C << endl;

	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  int cn = 0;
  for(int i=0;i<n;i++){
    if(p[i]!=i+1)cn++;
  }
  if(cn>2){
    puts("NO");
  }else{
    puts("YES");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
int main()
{
	FAST
	#ifdef ayk_16
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	ll a,b,k;
	cin>>a>>b>>k;
	ll m=min(a,k);
	a-=m;
	k-=m;
	m=min(b,k);
	b-=m;
	k-=m;
	cout<<a<<' '<<b;
}

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

const int maxN=402;
const long long INF=(1LL<<60);

int n;
long long v[maxN];

long long sum[maxN];
long long dp[maxN][maxN];

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

    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+v[i];
    }

    for(int i=n;i>=1;i--){
        for(int j=i+1;j<=n;j++){
            long long val=INF;
            for(int k=i;k<j;k++){
                val=min(val,dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
            }
            dp[i][j]=val;
        }
    }

    cout<<dp[1][n];

    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n;
	cin >> n;
	int tmp=n, sum=0;
	while(tmp){
		sum+=tmp%10;
		tmp/=10;
	}
	if(n%sum)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
	static int n,mat[][];
	static long ans;
	static StringBuilder allset;
	static long dp[][];
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=1;
//		Integer.parseInt(br.readLine().trim());
		OutputStream outputStream =System.out;
        PrintWriter out =new PrintWriter(outputStream);
		StringBuilder printans=new StringBuilder();
		while(t-->0)
		{
			StringTokenizer tok=new StringTokenizer(br.readLine()," ");
			n=Integer.parseInt(tok.nextToken());
			
			mat=new int[n][n];
			for(int i=0;i<n;i++) {
				tok=new StringTokenizer(br.readLine()," ");
				for(int j=0;j<n;j++)
					mat[i][j]=Integer.parseInt(tok.nextToken());
			}
			dp=new long[n+1][1<<n];
			memset();
			printans.append(call(0,0));
		}
		out.println(printans);
		out.close();
		
	}
	static long call(int i,int mask) {
		
		if(i==n) {
			
			if((mask&1<<n+1)==0)return 1;
			
			
			return 0;
		}
		if(dp[i][mask]!=-1)return dp[i][mask];
		Long ans=0l;
		for(int j=0;j<n;j++) {
			if((mask & (1<<j))==0 && mat[i][j]==1) {
				mask|=(1<<j);
				ans+=call(i+1,mask);
				mask^=(1<<j);
			}
			
			
		}
		dp[i][mask]=ans%mod;
		return ans%mod;
	}
	static void memset() {
		for(int i=0;i<dp.length;i++) {
			Arrays.fill(dp[i], -1);
		}
	}
	static int mod=(int)1e9+7;
}

Measured memory_bytes: 524736
#include<stdio.h>
bool isline[100][1000];

int main(){
	while(1){
		int i,j;
		int n,m,a;
		scanf("%d %d %d",&n,&m,&a);
		if(n==0)return 0;
		for(i=0;i<n;i++)for(j=0;j<1000;j++)isline[i][j]=false;
		for(i=0;i<m;i++){
			int h,p,x;
			scanf("%d %d %d",&h,&p,&x);
			isline[p-1][h-1]=true;
		}
		int pos=a-1;
		for(i=999;i>=0;i--){
			if(isline[pos][i])pos++;
			else if(pos>=1&&isline[pos-1][i])pos--;
		}
		printf("%d\n",pos+1);
	}
}
			

Measured memory_bytes: 1124
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a % 2 && b % 2) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine(Math.Max(Math.Max(AB[0]+AB[1], AB[0]-AB[1]),AB[0]*AB[1]));
        }
    }
}


Measured memory_bytes: 13396
abc = list(map(int, input().split()))
if len(set(abc)) == 1 and abc[0] % 2 == 0:
    print(-1)
    quit()
count = 0
for i in range(10**5):
    even = [i // 2 for i in abc if i % 2 == 0]
    if len(set(even)) == 3:
        count += 1
        abc = [even[0] + even[1], even[1] + even[2], even[2] + even[0]]
    else:
        print(count)
        quit()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;

int main()
{
	string s;
	while(cin >> s){
		int n[10];
		for (int i = 0; i < 10; ++i)
		{
			n[i] = s[i] - '0';	
		}
		for (int i = 0; i < 9; ++i)
		{
			for (int i = 0; i < 9; ++i)
			{
				n[i] = (n[i] + n[i + 1]) % 10;
			}
		}
		cout << n[0] << endl;
	}
}

Measured memory_bytes: 1180
N, M = map(int, input().split())  # Nはコマの数, Mは目標の座標数
X = [int(x) for x in input().split()]  # 目標の座標リスト

if N >= M:  # N >= Mならば全ての座標にコマを置いて終わるため移動しない
    print(0)
else:  # N < M
    X.sort()  # Xを昇順にソート
    L = [X[i] - X[i-1] for i in range(1, M)]
    L.sort()
    ans = X[-1] - X[0]
    for i in range(1, N):
        ans -= L[-i]
    print(ans)


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

using namespace std;

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

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 lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			int price = 4 * i + 7 * j;

			if (price == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> S;
int main(){
  int N;
  while(cin>>N && N){
    string ss, gs; cin>>ss>>gs;
    int St = 0, G = 0;
    REP(i, N){
      St |= (int)(ss[i] == 'B') << i;
      G |= (int)(gs[i] == 'B') << i;
    }
    priority_queue<S> que;
    int dist[1<<16][16];
    REP(i, 1<<N)REP(j, N) dist[i][j] = INF;
    REP(i, N){
      dist[St][i] = 0;
      que.push(S(0, P(St, i)));
    }
    while(!que.empty()){
      S s = que.top(); que.pop();
      int d = s.first * -1;
      int state = s.second.first;
      int u = s.second.second;
      if(state == G){
        cout<<d<<endl;
        break;
      }
      if(dist[state][u] < d) continue;
      REP(i, N)REP(j, N)if((state >> i & 1) != (state >> j & 1)){
        int nst = state ^ (1 << i) ^ (1 << j);
        int nd = d + abs(i - u) + abs(j - i);
        int nu = j;
        if(dist[nst][nu] > nd){
          dist[nst][nu] = nd;
          que.push(S(nd * -1, P(nst, nu)));
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 8776
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  deque<int>d;
  rep(i,n){
    int p=lower_bound(d.begin(),d.end(),a[i])-d.begin();
    if(p==0)d.push_front(a[i]);
    else d[p-1]=a[i];
  }
  
  int ans=d.size();
  cout << ans << endl;
    
  return 0;     
}


Measured memory_bytes: 1024
import itertools
N = int(input())
M = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(N):
    s = input()
    if M.get(s[0]) != None:
        M[s[0]] += 1
X = [M[key] for key in M.keys()]
Z = [i for i in range(5)]
Y = list(itertools.combinations(Z,r=3))
ans = 0
for i in Y:
    tmp = 1
    for j in i:
        tmp *= X[j]
    ans += tmp
print(ans)

Measured memory_bytes: 3064
def remaining_balls():
    s,t = input().split()
    a,b = input().split()
    u = input()
    s = str(s.lower())
    t = str(t.lower())
    a = int(a)
    b = int(b) 
    u = str(u.lower())

    temp1 = s.count(s)
    temp2 = t.count(t)
    temp3 = u.count(u)
    temp1 = a
    temp2 = b
    if u == s:
        a = temp1 - temp3
        print(a, b)
    elif u == t:
        b = temp2 - temp3
        print(a, b)
    else:
        pass


remaining_balls()


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();
    int M = sc.nextInt();

    String[][] A = new String[N][N];

    for (int i = 0; i < N; i++) {
      String a = sc.next();
      A[i] = a.split("");
    }

    String[] B = new String[M];

    for (int i = 0; i < M; i++) {
      B[i] = sc.next();
    }

    sc.close();

    String[][] A2 = new String[N][N];

    int maxK = 0;
    int maxI = 0;

    for (int k = 0; k < N; k++) {
      for (int i = 0; i < N - M + 1; i++) {
        String a_ = "";
        for (int j = i; j < i + M; j++) {
          a_ += A[k][j];
        }
        A2[k][i] = a_;
        maxK = Math.max(maxK, k);
        maxI = Math.max(maxI, i);
      }
    }

    String result = "No";

    int cA = 0;
    int rA = 0;
    int cB = 0;

    while (cA <= maxI) {
      while (rA <= maxK) {
        if (A2[rA][cA].equals(B[cB])){
          result = "Yes";
          cB++;
          rA++;
          if (cB == M) {
            rA = maxK + 1;
          }
        } else {
          result = "No";
          rA++;
          cB = 0;
        }
      }
      if (result.equals("Yes")) {
        cA = maxI + 1;
      } else {
        rA = 0;
        cB = 0;
        cA++;
      }
    }

    if (result.equals("Yes") && cB != M) {
      result = "No";
    }

    System.out.println(result);

  }

}

Measured memory_bytes: 27544
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
sample_input = list(range(3))
sample_input[0] = '''5 100
p1 150
p2 80
p3 200
p4 350
p5 20'''
sample_input[1] = ''''''
sample_input[2] = ''''''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
import copy

class Queue:
    queue = []
    def __init__(self, queue_list = []):
        self.queue = copy.copy(queue_list)
        pass
    def dequeue(self):
        if self.queue == []:
            return None
        return self.queue.pop(0)
        pass
    def enqueue(self, item):
        self.queue.append(item)

class Process:
    name = None
    time = -1
    def __init__(self, a_name, a_time):
        self.name = a_name
        self.time = a_time
    def execute(self, a_time):
        used_time = min(a_time, self.time)
        self.time -= a_time
        return used_time
    def is_ended(self):
        if self.time <= 0:
            return True
        else:
            return False
            
input_str = input()
num_of_process = int(input_str.split()[0])
quantum = int(input_str.split()[1])

input_process = []

for n in range(num_of_process):
    input_str = input()
    input_split = input_str.split()
    process = Process(input_split[0], int(input_split[1]))
    input_process.append(process)

process_queue = Queue(input_process)

time = 0
while True:
    process = process_queue.dequeue()
    if process is None:
        break
    used_time = process.execute(quantum)
    time += used_time
    if process.is_ended():
        timestamp = process.name + ' ' + str(time)
        print(timestamp)
    else:
        process_queue.enqueue(process)
        
        

Measured memory_bytes: 20000
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;


int main() 
{
	int n, x, cnt = 0;

	while (true)
	{
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;

		cnt = 0;

		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				for (int k = j + 1; k <= n; k++)
				{
					if (i + j + k ==x)
						cnt++;
				}
			}
		}
		cout << cnt << endl;
	}

	

	return 0;
}

Measured memory_bytes: 3088