akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var zennbu = Console.ReadLine().Split();
    var a = int.Parse(zennbu[2]);
    var b = int.Parse(zennbu[0]);
    var c = int.Parse(zennbu[1]);
    Console.WriteLine(a+" "+b+" "+c);
   
  }
}

Measured memory_bytes: 11220
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
  for (auto val : vec) {
    if (std::is_fundamental<T>::value)
      stream << " " << val;
    else
      stream << std::endl << val;
  }
  return stream;
}

int main() {
  int N, R;
  std::cin >> N >> R;
  int res = 0;
  if (N >= 10) {
    res = R;
  } else {
    // R = X - (100 * (10 - N));
    res = R + (100 * (10 - N));
  }
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

bitset<4100000> DP;

int main(){
	
	int N;
	cin >> N;
	
	int S = 0;
	
	DP[0] = 1;
	
	for(int i = 0; i < N; i++){
		int A;
		cin >> A;
		S += A;
		
		DP |= DP << A;
	}
	
	int mid = S / 2 + S % 2;
	
	for(int i = mid; i <= S; i++){
		if(DP[i]){
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
  IOS();
  string s;
  cin>>s;
  if( s[0]!='A' ) return cout<<"WA"<<endl,0;
  int cnt=0;
  int idx=0;
  for(int i=2;i<SZ(s)-1;i++)if( s[i]=='C' ) idx=i,cnt++;
  if( cnt!=1 ) return cout<<"WA"<<endl,0;
  debug(cnt,idx);
  REP1(i,SZ(s)-1)if( i!=idx && s[i]>='A' && s[i]<='Z' ){
    debug(i);
    return cout<<"WA"<<endl,0;
  }
  cout<<"AC"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  ll X, Y, Z;
  vector<ll> score1(N), score2(N), score3(N), score4(N), score5(N), score6(N), score7(N), score8(N);
  for(int i=0;i<N;++i) {
    cin>>X>>Y>>Z;
    score1[i] = X+Y+Z;
    score2[i] = X+Y-Z;
    score3[i] = X-Y-Z;
    score4[i] = X-Y+Z;
    score5[i] = -X+Y+Z;
    score6[i] = -X+Y-Z;
    score7[i] = -X-Y-Z;
    score8[i] = -X-Y+Z;
  }
  sort(score1.begin(), score1.end(), greater<ll>());
  sort(score2.begin(), score2.end(), greater<ll>());
  sort(score3.begin(), score3.end(), greater<ll>());
  sort(score4.begin(), score4.end(), greater<ll>());
  sort(score5.begin(), score5.end(), greater<ll>());
  sort(score6.begin(), score6.end(), greater<ll>());
  sort(score7.begin(), score7.end(), greater<ll>());
  sort(score8.begin(), score8.end(), greater<ll>());
  ll ans = -1;
  ll tmp;
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score1[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score2[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score3[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score4[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score5[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score6[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score7[i];
  }
  ans = max(ans, tmp);
  tmp = 0;
  for(int i=0;i<M;++i) {
    tmp += score8[i];
  }
  ans = max(ans, tmp);
  cout<<ans<<endl;
}



Measured memory_bytes: 3664
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cctype>
#include <complex>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1<<30;
const int EPS = 1e-8;
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int > Pii;
int n;
int stage[20][20];
int memo[1<<17];
int check(int bit,int ns){
    if(bit == 0) return stage[ns][0];
    int ret = stage[ns][0];
    rep(i,n){
        if(bit>>i & 1){
            ret = min(ret,stage[ns][i+1]);
        }
    }
    return ret;
}
int dsearch(int bit,int dep){
    if(memo[bit])return memo[bit];
    if(dep == n)return 0;
    int ans = INF;
    rep(i,n){
        if(!(bit>>i & 1)){
            int sub = check(bit,i);
            ans = min(ans,sub+dsearch(bit|1<<i,dep+1));
        }
    }
    return memo[bit] = ans;
}
int main(){
    while(scanf("%d",&n),n){
        memset(stage,0,sizeof(stage));
        memset(memo,0,sizeof(memo));
        rep(i,n){
            rep(j,n+1){
                scanf("%d",&stage[i][j]);
            }
        }
        printf("%d\n",dsearch(0,0));
    }
    return 0;
}

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

int main(){
  ll H,N;cin >> H >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  ll Amax = 0;//Bsum = 0;
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i];
    Amax = max(Amax,A[i]);
    //Bsum += B[i];
  }
  ll Ha = H + Amax + 1;
  //ll INF = Bsum + 1;
  vector<vector<ll>> DP(N+1,vector<ll>(Ha,-1));
  DP[0][0] = 0;
  for(int i=1;i<=N;i++){
    for(int j=0;j<Ha;j++){
      DP[i][j] = DP[i-1][j];
      if(A[i-1]<=j){
        if(DP[i-1][j-A[i-1]]>=0){
          if(DP[i][j]>=0){
            DP[i][j] = min(DP[i][j],DP[i-1][j-A[i-1]]+B[i-1]);
          }else{
            DP[i][j] = DP[i-1][j-A[i-1]]+B[i-1];
          }
        }
        if(DP[i][j-A[i-1]]>=0){
          if(DP[i][j]>=0){
            DP[i][j] = min(DP[i][j],DP[i][j-A[i-1]]+B[i-1]);
          }else{
            DP[i][j] = DP[i][j-A[i-1]]+B[i-1];
          }
        }
      }
      //if(A[i]<=j){
      //  DP[i][j] = min(DP[i][j],DP[i-1][j-A[i-1]]+B[i-1]);
      //}
    }
  }
  ll ans = -1;
  for(int j=H;j<Ha;j++){
    if(DP[N][j]>=0){
      if(ans == -1){
        ans = DP[N][j];
      }else{
        ans = min(ans,DP[N][j]);
      }
    }
  }
  cout << ans << endl;
}

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

int main(void){
    while(1){
        int n,m,k;
        cin >> n >> m;
        if(n == 0 && m == 0) break;

        int costs[m+1][m+1];
        int times[m+1][m+1];
        for(int i=0;i<m+1;i++){
            for(int j=0;j<m+1;j++){
                costs[i][j] = 1000000;
                times[i][j] = 1000000;
            }
        }

        for(int i =0;i<n;i++){
            int x,y,z,zz;
            cin >> x >> y >> z >> zz;
            costs[x][y] = z;
            times[x][y] = zz;
            costs[y][x] = z;
            times[y][x] = zz;
        }

        for(int k = 1;k < m+1;k++){
            for(int i = 1;i<m+1;i++){
                for(int j = 1;j < m+1;j++){
                    costs[i][j] = min(costs[i][j],costs[i][k] + costs[k][j]);
                    times[i][j] = min(times[i][j],times[i][k] + times[k][j]);
                }
            }
        }

        cin >> k;
        int p,q,r;
        for(int i = 0;i<k;i++){
            cin >> p >> q >> r;
            if (r == 1){
                cout << times[p][q] << "\n";
            }else{
                cout << costs[p][q] << "\n";
            }

        }
    }
}

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

int main() {
  long long n, p;
  cin>>n>>p;
  map<long long, long long> m;
  for (int i=2; i<sqrt(p)+1; i++) {
    while (p % i == 0) {
      ++m[i];
      p = p / i;
    }
  }
  if (p > 1) {
    ++m[p];
  }
  long long ans = 1;
  for (auto mi: m) {
    if (mi.second >= n) {
      ans = ans * pow(mi.first, mi.second / n );
    }
  }
  cout<<ans<<endl;

}

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

#define                 ll            long long
#define                 mx            100005
#define                 read          freopen("in.txt", "r", stdin);
#define                 optimize      ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

int main()
{
	optimize

	int a, b;

	cin >> a >> b;

	for(int i = b-a+1; i < a+b; i++) cout << i << " ";


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] array = new char[str.length()];
        int count = 0;

        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(0) == '1') {
                if (i % 2 == 0) {
                    array[i] = '1';
                } else {
                    array[i] = '0';
                }
            } else {
                if (i % 2 == 0) {
                    array[i] = '0';
                } else {
                    array[i] = '1';
                }
            }
            if (str.charAt(i) != array[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 27692
using System;
using System.Linq;


namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var ans = input[0] <= input[1] * input[2] ? "Yes" : "No";
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int L = sc.nextInt();
        int R = sc.nextInt();
        
        int min = 2019 * 2019;
        R = Math.min(R, L + 2050);
        
        for(int i = L; i < R; i++){
            for(int j = i + 1; j <= R; j++){
                min = Math.min(min, ( (i % 2019) * (j % 2019) ) % 2019 );
            }
        }
        
        System.out.println( min );
        
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod1 = 1000000007;
const ll mod2 = 1000000009;

mat mul(const mat&A,const mat&B,ll M)
{
  mat C(A.size(),vec(B[0].size()));
  for(int i = 0; i < int(A.size()); i++) {
    for(int k = 0; k < int(B.size()); k++) {
      for(int j = 0; j < int(B[0].size()); j++) {
        //C[i][j] = (C[i][j]+A[i][k]*B[k][j])%M;
        C[i][j] |= A[i][k]&B[k][j];
      }
    }
  }
  return C;
}

mat pow(mat A,ll n,ll M)
{
  mat B(A.size(),vec(A.size()));
  if( n == 1 ) return A;
  for(int i = 0; i < int(A.size()); i++) {
    B[i][i] = 1;
  }
  while( n > 0 ) {
    if( n&1 ) B = mul(B,A,M);
    A = mul(A,A,M);
    n >>= 1;
  }
  return B;
}

int main(void)
{
  int n,m,z,s,t;
  for(;;) {
    scanf("%d%d%d",&n,&m,&z); if( n+m+z == 0 ) break;
    vector<pair<int,int> > G(m*2);
    mat g(m*2+1,vec(m*2+1,0));
    for(int i = 0; i < m; i++) {
      scanf("%d%d",&s,&t);
      s--; t--;
      G[i*2]   = make_pair(s,t);
      G[i*2+1] = make_pair(t,s);
    }
    for(int i = 0; i < m*2; i++) {
      g[m*2][i] = (G[i].first == 0 ? 1 : 0);
    }
    for(int i = 0; i < m*2; i++) {
      for(int j = 0; j < m*2; j++) {
        if(i == j) continue;
        if( G[i].second == G[j].first && G[i].first != G[j].second ) {
          g[i][j] = 1;
        }
      }
    }
    mat A = pow(g,z,mod1);
    //mat B = pow(g,z,mod2);
    bool ok = false;
    for(int i = 0; i < m*2+1; i++) {
      if( G[i].second==n-1 && A[m*2][i] ) ok = true;
      //if( G[i].second==n-1 && (A[m*2][i] || B[m*2][i]) ) ok = true;
    }
    puts(ok?"yes":"no");
  }
  return 0;
}

Measured memory_bytes: 1364
def 解():
    N,K = [int(_) for _ in input().split()]
    aH = [int(_) for _ in input().split()]
    INF=float("inf")
    dp=[INF]*N
    dp[0]=0
    for i in range(N):
        dp[i] = min(dp[i-j] + abs(aH[i-j]-aH[i]) for j  in  range(min(K+1,i+1)))
    print(dp[-1])
解()


Measured memory_bytes: 55648
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] count = new int[2 * 100000];
		for (int i = 0; i < N; i++) {
			count[(A[i] = sc.nextInt()) - 1] += 1;
		}
		long pattern = 0;
		for (int i : count) {
			pattern += i * (i - 1L) / 2;
		}
		for (int a : A) {
			int c = count[a - 1];
			long orig = (c * (c - 1L)) / 2;
			long to = Math.max(((c - 1L) * (c - 2)) / 2, 0);
			System.out.println(pattern - orig + to);
		}
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 104212
import heapq

N = int(input())
*A, = map(int,input().split())
A.sort(reverse = True)
ans = 0
q = [-A[0]]
hpop = heapq.heappop
hpush = heapq.heappush
for a in A[1:]:
    ans += -hpop(q)
    hpush(q,-a)
    hpush(q,-a)

print(ans)

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

int compare_int(const void *a, const void *b) {
  return *(int*)a - *(int*)b;
}

int main() {
  int N,K;
  scanf("%d %d",&N,&K);
  int hight[N];
  for (int i = 0; i < N; i++) {
    scanf("%d",&hight[i]);
  }
  qsort(hight,N,sizeof(int),compare_int);
  int min=hight[N-1];
  for (int i = 0; i < N-K+1; i++) {
    int dif = hight[i+K-1] - hight[i];
    if (min > dif) min = dif;
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 892
from itertools import combinations
import math
#N = int(input())
#C = input()
D, T, S=map(int,input().split())
#C = []
#for i in range(N):
#    C.append(list(map(int,input().split())))

if D > T*S:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9176
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()

flag = False
for h in range(1,3501):
    for n in range(h,3501):
        a = 4*h*n-N*n-N*h
        b = N*h*n
        if a > 0 and b%a == 0:
            w = b//a
            flag = True
            break
    if flag:
        break

print(h,n,w)

Measured memory_bytes: 40556
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

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




int main(){
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll k=-1;
    for(int i=0;i<a.size();i++){
        if(a[i]==x){continue;}
        if(k==-1){k=abs(a[i]-x);}
        else{k=gcd(k,abs(a[i]-x));}
    }
    assert(k!=-1);
    cout<<k<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int N, D, X;
   cin >> N >> D >> X;
   vector<int> A(N);
   for(int i = 0; i < N; i++){
      cin >> A[i];
   }

   int cnt = 0;
   for(int i = 0; i < N; i++){
      int j = 0;
      while(true){
         if(j*A[i] + 1 > D){break;}
         j++;
         cnt++;
      }
   }

   cout << cnt + X << endl;

   return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll a,b,c,d;
    a=(int)s[0]-48;
    b=(int)s[1]-48;
    c=(int)s[2]-48;
    d=(int)s[3]-48;
    if((a+b+c+d)==7)
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    else if((a+b+c-d)==7)
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    else if((a+b-c+d)==7)
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    else if((a-b+c+d)==7)
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    else if((a-b+c+d)==7)
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    else if((a-b-c-d)==7)
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    else if((a+b-c-d)==7)
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    else if((a-b-c+d)==7)
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    else if((a+b-c+d)==7)
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    else if((a-b+c-d)==7)
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    return 0;
}

Measured memory_bytes: 3616
n, k = map(int, input().split())

mod = 10 ** 9 + 7
inv = pow(2, mod - 2, mod=mod)

def calc(b, e, c):
    global mod
    global inv
    res = (e + b) % mod
    res = ((res * c) % mod ) * inv
    return res % mod

ans = 0
for i in range(k, n + 2):
    min_val = calc(0, i - 1, i)
    max_val = calc(n - i + 1, n, i)
    ans += (max_val - min_val + 1) % mod
    ans %= mod

print(ans)

Measured memory_bytes: 9152
n, k = map(int, input().split())
s = input()
ls = []

now = 1
cnt = 0
for ele in s:
    if int(ele) == now:
        cnt += 1
    else:
        ls.append(cnt)
        now = 1 - now #1と0の切替
        cnt = 1
ls.append(cnt)

# 1-0-1-0-1が欲しい
# 1-0-1-0の場合、1の場合を足す
if len(ls) % 2 == 0:
    ls.append(0)

Add = 2*k+1 #[left, right)
ans = 0

left = 0
right = 0
tmp = 0 # [left, right)のsum

# print(ls)
# 1-0-1-0..の１から始める
for i in range(0,len(ls),2):
    nextLeft = i
    nextRight = min(i + Add, len(ls))
    # print(" value", tmp)
    # print(" p left ", left)
    # print(" p right", right)

    while nextLeft > left:
        # print("left  point, value", left, tmp)
        tmp -= ls[left]
        left += 1
    while nextRight > right:
        # print("right point, value", right, tmp)
        tmp += ls[right]
        right += 1

    ans = max(tmp, ans)
    # print("ans",ans)
    # print("\n")

print(ans)

Measured memory_bytes: 10036
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::*;
use proconio::{input, fastout, marker::*};

#[fastout]
fn main() {
  input!{
    d:f64,
    t:f64,
    s:f64
  }
  println!("{}",if d/s <= t {"Yes"}else{"No"});
}


Measured memory_bytes: 2196
#include<stdio.h>

int main(){

  int i,j,N,min,tmp,count=0,A[101];

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

  for(i=0;i<N;i++){
    min=i;
    for(j=i;j<N;j++){
      if(A[j]<A[min]){
	min=j;
      }
    }
      tmp=A[i];
      A[i]=A[min];
      A[min]=tmp;
      if(i!=min)count++;
  }

  for(i=0;i<N-1;i++)
    printf("%d ",A[i]);

  printf("%d\n",A[i]);
  printf("%d\n",count);

  return 0;
}

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

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

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll A,B;
    cin >> A >> B;
    if(B*2 > A){
        cout << "0" << endl;
    } else {
        cout << A - B*2 << endl;
    }
}

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

class Program
{
    public static void Main()
    {


        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
        double k = 0;

        for(int i = 0;i < N;i++)
        {
            k = k + (1 / A[i]);
        }

        Console.WriteLine(1 / k);

    }
}

Measured memory_bytes: 11348
#include <iostream>
using namespace std;
int main() {
	int s, a, b, c, d;
	cin >> s;
	a = s / 1000;
	b = (s - a * 1000) / 100;
	c = (s - a * 1000 - b * 100) / 10;
	d = s - a * 1000 - b * 100 - c * 10;

	if (a == b || b == c || c == d) {
		cout << "Bad\n";
	}
	else
		cout << "Good\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [abs(x[i] - y[i]) for i in range(n)]
dist_1 = 0.
dist_2 = 0.
dist_3 = 0.
dist_infty = float(max(z))
for i in range(n):
    dist_1 += z[i]
    dist_2 += z[i] ** 2
    dist_3 += z[i] ** 3
dist_2 = pow(dist_2, 1 / 2.)
dist_3 = pow(dist_3, 1 / 3.)
print(dist_1, dist_2, dist_3, dist_infty, sep='\n')

Measured memory_bytes: 5652
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

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

	vector<int> vec(N + 2);
	int sumCost = 0;
	{
		int buf = 0;
		for (int i = 0; i < N; ++i) {
			cin >> vec[i + 1];

			sumCost += abs(buf - vec[i + 1]);
			buf = vec[i + 1];
		}

		vec[0] = 0;
		vec[N + 1] = 0;
		sumCost += abs(buf - 0);
	}

	for (size_t i = 1; i < vec.size() - 1; ++i) {
		int cost = sumCost;
		int buf = abs(vec[i] - vec[i - 1]) + abs(vec[i] - vec[i + 1]);

		cost = cost - buf + abs(vec[i - 1] - vec[i + 1]);
		cout << cost << endl;
	}

	return 0;
}

Measured memory_bytes: 3768
#include<stdio.h>
#include<string.h>
#define NIL (-1)
#define M 1000000
#define L 14
char H[M][L];
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key%(M-1)); }

int find(char str[]){
  long long key, i,h;
  key = getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if (strlen(H[h])==0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i,a;
  key = getKey(str);
  for(i=0;;i++){
    a=(h1(key)+i*h2(key))%M;
    if(strcmp(H[a],str)==0)return 1;
    else if (strlen(H[a])==0){
      strcpy(H[a],str);
      return 0;
    }
  }
  return 0;
}
int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
    
    if ( com[0] == 'i' ){
      insert(str);
    }
    else {
      if (find(str)){
        printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }
    return 0;
}



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



int main()
{
    std::string s;
    int sum1=0,sum2=0;
    std::cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='A') sum1++;
        else sum2++;
    }
    if(sum1==0 || sum2==0) std::cout<<"No"<<"\n";
    else std::cout<<"Yes"<<"\n";
    return 0;
}


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

int main() {
  int x, n;
  cin >> x >> n;
  int p[102]; //0 ~ 101
  rep(i, 102) p[i] = true;
  rep(i, n) {
    int t;
    cin >> t;
    p[t] = false;
  }
  int m = INT_MIN;
  rep(i, 100) {
    if (x - i >= 0 && p[x - i]) {
      m = x - i;
      break;
    }
    if (x + i < 102 && p[x + i]) {
      m = x + i;
      break;
    }
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
typedef struct position
{
    int x;
    int y;
    int h;
}T;
int main()
{
    int n,i,j,k,p=0,ch,h,Cx,Cy,H;
    scanf("%d",&n);
    T a[100];
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].h);
    }
     while(a[p].h==0)p++;
    for(i=0;i<=100;i++)
    {
        for(j=0;j<=100;j++)
        {
            ch=a[p].h+abs(i-a[p].x)+abs(j-a[p].y);
            for(k=0;k<n;k++)
            {
               h=ch-abs(i-a[k].x)-abs(j-a[k].y);
               if(h<0)h=0;
               if(h!=a[k].h)break;
            }

            if(k==n)
            {

                Cx=i;Cy=j;H=ch;printf("%d %d %d",Cx,Cy,H);return 0;
            }
        }

    }return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
S = [int(_) for _ in input()]

now = 1
cnt = 0
one_zero = [0]
for i in S:
    if i == now:
        cnt += 1
    else:
        one_zero.append(cnt)
        now = 1 - now
        cnt += 1
if (cnt != 0):
    one_zero.append(cnt)

add = 2 * K + 1
ans = 0
for i in range(0,len(one_zero),2):
    right = min(i+add, len(one_zero)-1)
    ans = max(ans, one_zero[right] - one_zero[i])

print(ans)

Measured memory_bytes: 7832
N = int(input())
p = [int(c) for c in input().split()]

swapped = False
result = 'YES'
for i in range(N):
  if p[i] == i + 1:
    continue
  
  temp = p[i]
  if swapped or p[temp - 1] != i + 1:
    result = 'NO'
    break
  
  p[i] = p[temp - 1]
  p[temp - 1] = temp
  swapped = True
      
print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

struct UnionFind
{
  vector<i64> data;
  i64 cnt;
  UnionFind(i64 size)
  {
    data.resize(size, -1);
    cnt = size;
  }
  bool unite(i64 x, i64 y)
  {
    x = root(x);
    y = root(y);
    if (x != y)
    {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
      cnt--;
    }
    return x != y;
  }
  bool same(i64 x, i64 y)
  {
    return root(x) == root(y);
  }
  i64 root(i64 x)
  {
    return (data[x] < 0 ? x : data[x] = root(data[x]));
  }
  i64 size(i64 x)
  {
    return -data[root(x)];
  }
};

int main()
{
  i64 n, m, q;
  cin >> n >> m >> q;
  vector<pair<i64, i64>> d;
  UnionFind uf(n);
  for (i64 _ = 0; _ < q; _++)
  {
    i64 a, b, c;
    cin >> a >> b >> c;
    if (c == 0)
      uf.unite(a, b);
    else
      d.push_back({a, b});
  }
  if (m == n - 1)
  {
    if (d.size() == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
  }
  for (pair<i64, i64> i : d)
    if (uf.same(i.first, i.second))
    {
      cout << "No" << endl;
      return 0;
    }
  if (m <= n - uf.cnt + uf.cnt * (uf.cnt - 1) / 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> l(n);
    rep(i, 0, n) cin >> l[i];
    sort(l.begin(), l.end());

    ll ans = 0;
    rep(i, 0, n) rep(j, i+1, n) {
        auto itr = lower_bound(l.begin(), l.end(), l[i] + l[j]);
        if (j < itr - l.begin()) ans += (itr - l.begin() - j - 1);
    }
    cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<double> v;
	double tmp;
	for(int i=0;i<n;i++){
		cin >> tmp;
		v.push_back(tmp);
	}
	sort(v.begin(),v.end(),greater<double>()); //降順にソート
	double a,b;
	vector <double>vn;
	while(v.size() > 1){
		a = v.back();
		v.pop_back();
		b = v.back();
		v.pop_back();
		v.push_back((a+b)/2);
	}
	double res = v.back();
	cout << fixed;
	cout << setprecision(6);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int n,k;
long long ans=0;
int main() {
  scanf("%d%d",&n,&k);
  for (int i=k+1;i<=n;++i) {
    int lim=n/i;
    ans+=1ll*(lim)*(i-k);
    ans+=max(0ll,1ll*(n%i)-max(0ll,1ll*k-1));
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3820
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        mut s: [Chars; n],
    };
    let mut max_len = 0;
    for s_i in s.iter_mut() {
        s_i.sort();
        max_len = std::cmp::max(max_len, s_i.len());
    }
    let mut ans = vec![];
    let mut j = vec![0; n];
    for o in 0..26 {
        let c = ('a' as u8 + o as u8) as char;
        let mut min_l = max_len;
        for (i, j_i) in j.iter_mut().enumerate() {
            let mut l = 0;
            while *j_i < s[i].len() && s[i][*j_i] == c {
                l += 1;
                *j_i += 1;
            }
            min_l = std::cmp::min(min_l, l);
        }
        for _ in 0..min_l {
            ans.push(c);
        }
    }
    println!("{}", ans.iter().collect::<String>());
}


Measured memory_bytes: 2212
#include<cstdio>
#include<cstring>
using int64=long long;
constexpr int N=10001,mod=998244353;
char a[N],b[N];
int fact[N],factinv[N],f[N][N];
void exgcd(const int &a,const int &b,int &x,int &y) {
	if(!b) {
		x=1,y=0;
		return;
	}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
inline int inv(const int &x) {
	int ret,tmp;
	exgcd(x,mod,ret,tmp);
	return (ret%mod+mod)%mod;
}
inline int C(const int &n,const int &m) {
	if(n<m||n<0||m<0) return 0;
	return (int64)fact[n]*factinv[m]%mod*factinv[n-m]%mod;
}
int main() {
	scanf("%s%s",a,b);
	const int n=strlen(a);
	for(register int i=fact[0]=1;i<=n;i++) {
		fact[i]=(int64)fact[i-1]*i%mod;
	}
	factinv[n]=inv(fact[n]);
	for(register int i=n;i;i--) {
		factinv[i-1]=(int64)factinv[i]*i%mod;
	}
	int s1=0,s2=0;
	for(register int i=0;i<n;i++) {
		if(a[i]=='1'&&b[i]=='1') s1++;
		if(a[i]=='1'&&b[i]=='0') s2++;
	}
	for(register int i=0;i<=s2;i++) {
		f[0][i]=(int64)fact[i]*fact[i]%mod;
	}
	for(register int i=1;i<=s1;i++) {
		for(register int j=1;j<=s2;j++) {
			f[i][j]=((int64)f[i-1][j]*i%mod*j%mod+(int64)f[i][j-1]*j%mod*j%mod)%mod;
		}
	}
	int ans=0;
	for(register int i=0;i<=s1;i++) {
		(ans+=(int64)f[s1-i][s2]*fact[i]%mod*fact[i]%mod*C(s1,i)%mod*C(s1+s2,i)%mod)%=mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 345344
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int x,y;
   cin >> x >> y;

   int a[12] = { 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

   if( a[x-1] == a[y-1]) cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w int
	for {
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 { 
			break
		}
		
		if h >= 1 && h <= 300 && w >= 1 && w <= 300{
			for i := 0; i < h; i++ {
				for j := 0; j < w; j++ {
					if ((i + j) % 2) == 0 {
						fmt.Print("#")
					}else {
						fmt.Print(".")
					}
				}
				fmt.Println()
			}
			fmt.Println()
		}else {
			break
		}
	}
}


Measured memory_bytes: 1124
N,K=map(int,input().split())
H=list(map(int,input().split()))
Cost=[1e30 for i in range(N)]
Cost[0]=0
Cost[1]=abs(H[1]-H[0])
for i in range(2,N):
    for k in range(1,min(i,K)+1):
        Cost[i]=min(Cost[i], Cost[i-k] + abs(H[i]-H[i-k]))
print(Cost[N-1])

Measured memory_bytes: 58848
n = int(input())
if n == 3:
    print("2 5 63")
elif n == 4:
    print("2 5 20 63")
elif n == 5:
    print(2, 8, 14, 3, 9)
elif n <= 8:
    for i in [2, 3, 4, 8, 9, 10, 6, 12][:n]:
        print(i)
else:
    a = [2, 3, 4, 8, 9, 10, 6, 12]
    i = 0
    j = 0
    for _ in range(n // len(a) * len(a)):
        print(a[i] + j, end=" ")
        i += 1
        if i == len(a):
            i = 0
            j += 12

    i = n - n // len(a) * len(a)
    if i == 5:
        for k in [2, 4, 6, 3, 9]:
            print(j + k, end=" ")
    elif i == 4:
        for k in [2, 4, 3, 9]:
            print(j + k, end=" ")
    elif i == 3:
        for k in [6, 3, 9]:
            print(j + k, end=" ")
    else:
        if i >= 6:
            for k in [2, 3, 4, 8, 9, 10]:
                print(k+j, end=" ")
            i -= 6
        j += 6
        for _ in range(i):
            print(j, end=" ")
            j += 6


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

int main(void)
{
#if 0
    int i;
    int x, y;

    for (;;) {
        if (scanf("%d %d", &x, &y) == EOF) {
            break;
        }
        x += y;
        for (i = 1; ; i++) {
            x /= 10;
            if (x == 0) {
                break;
            }
        }
        printf("%d\n", i);
    }
#else
    int i;
    int x, y;
    char st[10];

    for (;;) {
        if (scanf("%d %d", &x, &y) == EOF) {
            break;
        }
        x += y;
        sprintf(st, "%d", x);
        printf("%d\n", strlen(st));
    }
#endif
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	string s, t; cin >> s >> t;
	s += t;
	LL x = stoll(s);
	LL a = sqrt(x);



	cout << (a*a==x?"Yes":"No") << endl;

	return 0;
}


Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, K;
bool can[1000010];

signed main() {
    cin >> N >> M >> K;
    repq(i,0,N) repq(j,0,M) {
        int c = M*i + N*j - 2*i*j;
        // printf("i = %lld, j = %lld, c = %lld\n", i, j, c);
        can[c] = true;
    }
    cout << (can[K] ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

double dp[3001][3001],ara[3001];
int n;

double func(int indx, int head)
{
    if(indx==n+1)
    {
        int tail=n-head;
        if(head>tail) return 1.0;
        return 0.0;
    }
    if(dp[indx][head]!=-1.0) return dp[indx][head];

    double ans=0,temp=1.0;
    ans+=ara[indx]*func(indx+1, head+1);
    ans+=(1.00-ara[indx])*func(indx+1, head);
    return dp[indx][head]=ans;
}

int main()
{
    int i,j;
    cin>>n;
    for(i=1; i<=n; i++) cin>>ara[i];
    for(i=0; i<=3000; i++)
    {
        for(j=0; j<=3000; j++)
        {
            dp[i][j]=-1.0;
        }
    }

    double ans=func(1,0);
    cout<<setprecision(10);
    cout<<ans<<endl;
}


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

using namespace std;

vector<int> adj[100001];
int longest[100001];
bool visited[100001];
vector<int> now;

void dfs(int v){
    visited[v] = true;

    for (int u : adj[v]){
        if (visited[u] == false){
            dfs(u);
        }
        longest[v] = max(longest[v] , 1 + longest[u]);
    }



}




int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    for (int i = 0 ; i < m ; i++){
        int v,u;
        cin >> v >> u;
        adj[v].push_back(u);
    }


    for (int i = 1 ; i <= n ; i++){
        if (visited[i] == false){
            dfs(i);
        }
    }

    int ans = 0;

    for (int i = 1 ; i <= n ; i++){
        ans = max(ans , longest[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12232
import sys
from itertools import accumulate

input = sys.stdin.readline


def main():
    N, M, Q = map(int, input().split())
    LR = [None] * M
    for i in range(M):
        LR[i] = tuple(map(int, input().split()))
    pq = [None] * Q
    for i in range(Q):
        pq[i] = tuple(map(int, input().split()))

    S = [[0] * (N + 1) for _ in range(N + 1)]
    for L, R in LR:
        S[L][R] += 1
    for i in range(N + 1):
        S[i] = list(accumulate(S[i]))

    ans = [0] * Q
    for i, (p, q) in enumerate(pq):
        for j in range(p, q + 1):
            ans[i] += S[j][q] - S[j][p - 1]

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 113128
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll P, Q, R;

int main() {
	cin >> P >> Q >> R;
	cout << P + Q + R - max(P, max(Q, R));
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#A
def A():
    n = S()
    n1 = n[::-1]
    for i in range(len(n)):
        if n1[i] != n[i]:
            print("No")
            return
    print("Yes")
    return

#B
def B():
    a, b, c, d = LI()
    ans = [0 for i in range(101)]
    ans[a] += 1
    ans[b] -= 1
    ans[c] += 1
    ans[d] -= 1
    for i in range(100):
        ans[i+1] += ans[i]
    print(ans.count(2))
#C
def C():
    n = II()
    ans = 1
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    for _ in range(n):
        t = II()
        ans = ans // gcd(ans, t) * t
    print(ans)
    return

#D
def D():
    n = II()
    vedg = defaultdict(list)
    for _ in range(n-1):
        a, b, c = LI()
        vedg[a].append((b, c))
        vedg[b].append((a, c))
    dist = defaultdict(lambda :inf)
    Q, k = LI()
    q = deque([k])
    dist[k] = 0
    while q:
        f = q.pop()
        for t, value in vedg[f]:
            if dist[t] > dist[f] + value:
                dist[t] = dist[f] + value
                q.append(t)
    for _ in range(Q):
        x, y = LI()
        print(dist[x] + dist[y])
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 90584
#include <bits/stdc++.h>
using namespace std;
 
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
void fastscan(int &x)
 {
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    } 
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int inf = 2e18+5;
const int nax = 100010;
const int mod1 = 998244353;
   

signed main()
 {
int n,W;
  cin>>n>>W;
  //int v[n],w[n],dp[n+1][W+1];
  vector<int> v(n),w(n);
  vector<vector<int>> dp(n+1,vector<int> (W+1));
  loop(i,0,n)
   cin>>w[i]>>v[i];
  loop(i,0,n+1)
    dp[i][0] = 0;
  loop(i,0,W+1)
   dp[0][i] = 0;  
  loop(i,1,n+1)
   {
    loop(j,0,W+1)
     {
      if(w[i-1]>j)
         dp[i][j] = dp[i-1][j];
      else
       {
        dp[i][j] = max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
       } 
     }
   } 
  cout<<dp[n][W];
return 0;
}

Measured memory_bytes: 80256
#include<iostream>
using namespace std;
int main(){
    long long a, n, m;
    cin >> a >> n >> m;
    int  cnt=0;
    for(int y=1;y<=72;y++){
        long long x=1;
        for(int t=1;t<=n;t++){
            x*=(y+a);
        }
        long long sum=0;
        long long tmp=x;
        while(tmp){
            sum+=tmp%10;
            tmp/=10;
        }
        if(x<=m && sum==y){
            cnt++;
        }
    }
    cout << cnt << endl; 
    return 0;
}


Measured memory_bytes: 3132
n=int(input())
a=list(map(int,input().split()))
cnt=0
#n=200000
if 1 not in a:
  print(-1);exit()
from collections import*  
b=deque(a)
#print(b)
i=1
while True:
  if len(b)==0:
    break
  if b[0]==i:
    cnt+=0
    b.popleft()
    i+=1
  else:
    cnt+=1
    b.popleft()
  #print(b,cnt)     

print(cnt)

Measured memory_bytes: 26012
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){

  int i;
  int h1,m1,s1,h2,m2,s2;

  for(i=0;i<3;i++){
    scanf("%d %d %d %d %d %d",&h1,&m1,&s1,&h2,&m2,&s2);

    if(s2-s1>=0){
      s1=s2-s1;
    } else {
      s2+=60;
      m2--;
      s1=s2-s1;
    }

    if(m2-m1>=0){
      m1=m2-m1;
    } else {
      m2+=60;
      h2--;
      m1=m2-m1;
    }

    h1=h2-h1;

    printf("%d %d %d\n",h1,m1,s1);

  }

  return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

const int MOD=1e9+7;
vector<string> F;
int D[1000][1000];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, M;
	cin>>N>>M;
	F.resize(N);
	for(int i=0;i<N;i++) cin>>F[i];
	D[0][0]=1;
	for(int j=1;j<M;j++) {
		if(F[0][j]=='.' && F[0][j-1]=='.') D[0][j]=D[0][j-1];
	}
	for(int i=1;i<N;i++) {
		if(F[i][0]=='.' && F[i-1][0]=='.') D[i][0]=D[i-1][0];
		for(int j=1;j<M;j++) {
			if(F[i][j]=='.') {
				if(F[i-1][j]=='.') D[i][j]+=D[i-1][j];
				if(F[i][j-1]=='.') D[i][j]+=D[i][j-1];
				D[i][j]%=MOD;
			}
		}
	}
	cout<<D[N-1][M-1]<<'\n';
	return 0;
}

Measured memory_bytes: 5248