akhauriyash/Code-Regression huggingface dataset:
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/7/ITP1_7_A

#include <iostream>
#include <vector>

int main()
{
    using std::vector;

    //試験を受けていない場合は点数を-1
    int m = 0; //中間試験 <=50
    int f = 0; //期末試験 <=50
    int r = 0; //再試験 <=100

    vector<char> rank;

    while (1)
    {
        std::cin >> m >> f >> r;
        // 中間試験、期末試験いずれかを欠席⇒F
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }
        else if (m == -1 || f == -1)
        {
            rank.emplace_back('F');
        }
        // 合計 >= 80      ⇒A
        else if (m + f >= 80)
        {
            rank.emplace_back('A');
        }
        // 65 <= 合計 < 80 ⇒B
        else if (m + f >= 65 && m + f < 80)
        {
            rank.emplace_back('B');
        }
        // 50 <= 合計 < 65 ⇒C
        else if (m + f >= 50 && m + f < 65)
        {
            rank.emplace_back('C');
        }
        // 30 <= 合計 < 50 ⇒D || 再試験 >= 50 ⇒ C
        else if (m + f >= 30 && m + f < 50)
        {
            if (r >= 50)
            {
                rank.emplace_back('C');
            }
            else
            {
                rank.emplace_back('D');
            }
        }
        // 合計 <30  ⇒F
        else if (m + f < 30)
        {
            rank.emplace_back('F');
        }
    }

    for (auto &elem : rank)
    {
        std::cout << elem << std::endl;
    }
}


Measured memory_bytes: 3164
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main() {
  string s;
  cin >> s;

  string alphabet = "abcdefghijklmnopqrstuvwxyz";

  for(int i = 0; i < alphabet.length(); ++i) {
    bool contain = false;
    for(int j = 0; j < s.length(); ++j) {
      if(alphabet[i] == s[j]) {
        contain = true;
        break;
      }
    }
    if(!contain) {
      cout << alphabet[i];
      return 0;
    }
  }

  cout << "None";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int test(string s)
{
  auto l=s.begin(), r=s.end();
  --r;
  int x=0;
  while(1){
    int lx=0,rx=0;
    while(*l=='x' && l!=r){
      ++l;
      ++lx;
    }
    while(*r=='x' && l!=r){
      --r;
      ++rx;
    }
    if(*l=='x') return x;
    x+=abs(lx-rx);
    if(l==r) return x;
    if(*l!=*r) return -1;
    ++l;
    if(l==r) return x;
    --r;
  }
}
int main(void)
{
  string s;
  cin >> s;
  cout << test(s) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	array<int,100>ar;
	int i,j;
	int cnt;
	int x;
	cin>>n;
	for(i=0;i<n;i++)	cin>>ar[i];
	for(i=0;i<n-1;i++){
		x=i;
		for(j=i;j<n;j++){
			if(ar[j]<ar[x])	x=j;
		}
		swap(ar[i],ar[x]);
		if(i!=x)	cnt++;
	}
	cout<<ar[0];
	for(i=1;i<n;i++)	cout<<" "<<ar[i];
	cout<<endl;
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3084
from numpy import*
(n,s),a,m,e=map(int,input().split()),list(map(int,input().split())),998244353,3001;D=zeros((n,e));D[0][a[0]]=1
for j,i in enumerate(a[1:]):D[j+1,i]+=j+2;D[j+1,i:]+=D[j,:e-i];D[j+1,:]=(D[j+1,:]+D[j,:])%m
print(int(sum(D[:, s]) % m))

Measured memory_bytes: 82868
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 1021
void build(){

}
LL n , t[ N ] , a[ N ];
void init(){
  scanf( "%lld" , &n );
  for( int i = 0 ; i < n ; i ++ )
    scanf( "%lld%lld" , &t[ i ] , &a[ i ] );
}
void solve(){
  LL tt = t[ 0 ] , aa = a[ 0 ];
  for( int i = 1 ; i < n ; i ++ ){
    LL gg = max( tt / t[ i ] , aa / a[ i ] );
    while( gg * t[ i ] < tt ||
           gg * a[ i ] < aa ) gg ++;
    tt = gg * t[ i ];
    aa = gg * a[ i ];
  }
  printf( "%lld\n" , tt + aa );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>
#include <iomanip>
#include <stack>

using namespace std;
using namespace boost::multiprecision;

vector<vector<int>> S;
int N, M;
vector<int> K;
vector<int> P;
int ans = 0;

void solve() {
	cin >> N >> M;
	K.resize(M);
	S.resize(M);
	for (int m = 0; m < M; m++) {
		cin >> K[m];
		S[m].resize(K[m]);
		for (int s = 0; s < K[m]; s++) {
			cin >> S[m][s];
			S[m][s]--;
		}
	}
	P.resize(M);
	for (int m = 0; m < M; m++)cin >> P[m];
	vector<int> tempv;
	for (int st = 0; st < pow(2, N); st++) {
		tempv.clear();
		tempv.resize(N);
		for (int n = 0; n < N; n++)tempv[n] = (st >> n) % 2;
		int m = 0;
		for (; m < M; m++) {
			int counter = 0;   //つけてるスイッチの数
			for (auto itr = S[m].begin(); itr != S[m].end(); itr++) {
				counter += tempv[*itr];
			}
			if (counter % 2 != P[m])break;
		}
		if (m == M)ans++;
	}
	cout << ans << endl;
	return;
}

Measured memory_bytes: 384
import numpy as np

d = int(input())
c = list(map(int, input().split()))
s = np.array([list(map(int, input().split())) for _ in range(d)])
t = [int(input()) for _ in range(d)]

last_day = np.zeros(26, dtype=int)

score = 0
for i in range(1, d + 1):
    last_day[t[i - 1] - 1] = i
    minus = ((last_day - i) * c).sum()
    score += s[i - 1, t[i - 1] - 1] + minus
    print(score)

Measured memory_bytes: 27492
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            v[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(v);
        float tmp = (v[0] + v[1]) / 2f;
        for (int i = 2; i < N; i++) {
            tmp = (tmp + v[i]) / 2f;
        }

        System.out.println(tmp);
    }
}

Measured memory_bytes: 21712
N, M, C = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
count = 0
N.times do
  as = []
  as = gets.split.map(&:to_i)
  sum = 0
  M.times do |i|
    sum += as[i] * bs[i]
  end
  sum += C
  count += 1 if sum > 0
end
puts count


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;

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

const ll mod = 1000000007;

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

  int k;
  cin >> k;

  ll ans = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
N, W = map(int, input().split())

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(1, N+1):
  w, v = map(int, input().split())
  for j in range(W+1):
    dp[i][j] = dp[i-1][j]
    if j >= w:
      dp[i][j] = max(dp[i][j], dp[i-1][j-w]+v)

print(dp[N][W])

Measured memory_bytes: 119916
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N = int(input())
A = list(map(int, input().split()))

L = [0] * (N + 1)
L[0] = 0
R = [0] * (N + 1)
R[0] = 0

for i in range(N):
    L[i + 1] = gcd(L[i], A[i])
    R[i + 1] = gcd(R[i], A[-i - 1])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[N - i - 1]))
print(ans)


Measured memory_bytes: 14436
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll>A(N);
  for(int i=0; i < N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());
  ll num=1;
  ll ans=0;
  for(int i=0; i < N-1; i++){
    if(A[i] != A[i+1]){
      if(A[i] > num){
	ans += num;
      }else if(A[i] < num){
	ans += num - A[i];
      }
      num = 1;
    }else{
      num++;
    }
  }
  int i = N-1;
  if(A[N-2] != A[N-1]){
    if(A[N-1] > 1){
       ans += 1;
     }else if(A[i] < 1){
	ans += 1 - A[i];
      }
  }else{
      if(A[i] > num){
	ans += num;
      }else if(A[i] < num){
	ans += num - A[i];
      }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    if (S.length() == 3) swap(S[0], S[2]);
    cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
 int m1, m2, d1, d2;
 scanf("%d %d", &m1, &d1);
 scanf("%d %d", &m2, &d2);
 if(m1!=m2) {
 puts("1");
 }
 if(m1==m2) {
 puts("0");
 }
 return 0;
}

Measured memory_bytes: 128
def solve():
    c = [list(map(int,input().split())) for _ in range(3)]
    for i in range(101):
        a0 = i
        b0 = c[0][0]-a0
        b1 = c[0][1]-a0
        b2 = c[0][2]-a0
        a1 = c[1][0]-b0
        a2 = c[2][0]-b0
        if c[1][1]==a1+b1 and c[1][2]==a1+b2 and c[2][1]==a2+b1 and c[2][2]==a2+b2:
            print('Yes')
            exit()
    print('No')
if __name__=='__main__':
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back



int main(){
  
  ll n,k;
  cin>>n>>k;
  

  ll answer=0;
  
  for (ll i=k;i<=n+1;i++){
    ll up,down,tmp;
    down=((i-1)*i)/2;
    up=(i*(2*n-i+1))/2;
    tmp=(up-down+1)%MOD;
    answer+=tmp;
    answer%=MOD;
  }
  
  cout<<answer<<endl;
 
  
}






















Measured memory_bytes: 3616
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL r;
    LL c;
    LL k;
    cin >> r >> c >> k;
    vector<vector<LL>> v(r, vector<LL>(c, 0));
    LL tmp_r;
    LL tmp_c;
    LL tmp_v;
    for(LL i=0; i<k; i++){
        cin >> tmp_r >> tmp_c >> tmp_v;
        tmp_r--;
        tmp_c--;
        v[tmp_r][tmp_c]=tmp_v;
    }
    vector<vector<vector<LL>>> dp(r, vector<vector<LL>>(c,vector<LL>(4,0)));
    for(LL i=0; i<r; i++){
        for(LL j=0; j<c; j++){
            for(LL l=0; l<4; l++){
                if(i!=0){
                    dp[i][j][0]=max(dp[i][j][0], dp[i-1][j][l]);
                }
            }
            if(v[i][j]!=0){
                dp[i][j][1]=dp[i][j][0]+v[i][j];
            }
            for(LL l=0; l<4; l++){
                if(j!=0){
                    dp[i][j][l]=max(dp[i][j][l], dp[i][j-1][l]);
                    if(v[i][j]!=0 && l>=1){
                        dp[i][j][l]=max(dp[i][j][l], dp[i][j-1][l-1]+v[i][j]);
                    }
                }
            }
        }
    }

    LL max_ans=0;
    for(LL i=0; i<4; i++){
        max_ans=max(max_ans, dp[r-1][c-1][i]);
    }

    cout << max_ans << endl;

    return 0;
}


Measured memory_bytes: 706648
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
#include <map>
#include <cstring>
#include <cassert>
 
using namespace std;

int main(){

	int n;
	cin>>n;

	vector<long long> a(n);
	long long mi=10000000,ma=-10000000;
	int mii,mai;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(mi>a[i]) mi=a[i],mii=i;
		if(ma<a[i]) ma=a[i],mai=i;
	}

	vector<int> res;
	if(abs(ma)>=abs(mi)){
		for(int i=0;i<n;i++){
			a[i]+=a[mai];
			res.push_back(mai);
			res.push_back(i);
		}
		for(int i=0;i<n-1;i++){
			a[i+1]+=a[i];
			res.push_back(i);
			res.push_back(i+1);
		}
	}else{
		for(int i=0;i<n;i++){
			a[i]+=a[mii];
			res.push_back(mii);
			res.push_back(i);
		}
		for(int i=n-1;i>0;i--){
			a[i-1]+=a[i];
			res.push_back(i);
			res.push_back(i-1);
		}		
	}

//	for(int i=0;i<n;i++) cout<<a[i]<<" ";
//	cout<<endl;

	cout<<res.size()/2<<endl;
	for(int i=0;i<res.size();i+=2){
		cout<<res[i]+1<<" "<<res[i+1]+1<<endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int MAX = 510000;
const ll mod = 1000000007;
int main() {
  ll s;
  cin >> s;
  
  ll g[2001] = {};
  g[3] = 1;
  g[4] = 1;
  g[5] = 1;
  ll tmp = 0;
  for(int i = 6;i<=s;i++){
    //一桁の時
    tmp = 1;
    for(int j = 3;i-j >= 3;j++){
      tmp += g[i-j];
      tmp %= mod;
    }
    
    g[i] = tmp;
  }
  
  cout << g[s];
  
}

Measured memory_bytes: 3656
import sys
from fractions import gcd
def input(): return sys.stdin.readline().rstrip()

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 16276
def S(x1,y1,x2,y2,x3,y3):
    return ((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0
import sys
for dataset in sys.stdin:
    xa,ya,xb,yb,xc,yc,xd,yd=map(float,dataset.split(","))
    ABC=S(xa,ya,xb,yb,xc,yc)
    BCD=S(xb,yb,xc,yc,xd,yd)
    CDA=S(xc,yc,xd,yd,xa,ya)
    DAB=S(xd,yd,xa,ya,xb,yb)
    if ABC>0 and BCD>0 and CDA>0 and DAB>0:
        print "YES"
    elif ABC<0 and BCD<0 and CDA<0 and DAB<0:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 6324
def test():
    a,b = map(int,input().split())
    s = input()
    for i in range(a):
        if s[i].isdigit():
            pass
        else:
            print("No")
            return
    for j in range(a+1,len(s)):
        if s[j].isdigit():
            pass
        else:
            print("No")
            return
    if s[a] == "-":
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    test()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<char, int> P;

string S;
stack<char> sta;

int main(){
	cin >> S;
	for(int i = 0; i < S.length(); i++){
		if(sta.empty()) sta.push(S[i]);
		else{
			if(S[i] != sta.top()) sta.pop();
			else sta.push(S[i]);
		}
	}
	cout << S.length() - sta.size() << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;

//----------素因数分解----------
vector<ll> prime_factorization(ll n){
  vector<ll> factors(n+1,0);
  rep3(i,n+1){
    if(i<=1) continue;
    while(n%i==0){
      n/=i;
      factors[i]++;
    }
  }
  return factors;
}

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll sum=0;
  rep(i,n){
    if(i==0) continue;
    if(a[i]<a[i-1]){
      sum+=(a[i-1]-a[i]);
      a[i]=a[i-1];
    }
  }
  cout<<sum<<endl;
}


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

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

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n),l(n+1),r(n+1);
    rep(i,n)cin>>a[i];
    rep(i,n){
        l[i+1]=gcd(a[i],l[i]);
        r[i+1]=gcd(a[n-1-i],r[i]);
    }
    ll ans=0;
    rep(i,n){
        ans=max(ans,gcd(l[i],r[n-1-i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int cnt[35];

int main(){
    // reset
    FOR(i,33) cnt[i] = 0;
    // input
    int n,k; scanf("%d %d", &n, &k);
    REP(i,1,n){
        char s[15]; scanf("%s", s);
        cnt[s[0]-'A']++;
    }
    // do
    int res = 0;
    while(1){
        sort(cnt,cnt+26); reverse(cnt,cnt+26);
        if(cnt[k-1] == 0) break;
        FOR(i,k) cnt[i]--;
        res++;
    }
    // print
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void print(void);
int n,A[251];
int main(){
  int i,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&k);
    A[i]=k;
  }
  print();
  return 0;
}

void print(){
  int i;
  if(A[1]==NULL){
    printf("node 1: key = %d, \n",A[1]);
  }else if(A[2]==NULL){
    printf("node 1: key = %d, right key = %d, \n",A[1],A[2]);
  }else{
    printf("node 1: key = %d, left key = %d, right key = %d, \n",A[1],A[2],A[3]);
    for(i=2;i<=n;i++){
      if(A[2*i]==NULL){
	printf("node %d: key = %d, parent key = %d, \n",i,A[i],A[i/2]);
      }else if(A[(2*i)+1]==NULL){
	printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,A[i],A[i/2],A[2*i]);
      }else{
	printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,A[i],A[i/2],A[2*i],A[2*i+1]);
      }
    }
  }
}




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

typedef long long ll;
typedef unsigned long long ull;


const int MAX = 150001;  
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        int x; cin >> x;
        if (i%2==1 && x%2==1) ans++;
    }
    cout << ans;
       
}

Measured memory_bytes: 3140
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			double[] x = new double[4];
			double[] y = new double[4];
			double[] vx = new double[6];
			double[] vy = new double[6];
			for(int i=0; i<4; i++){
				x[i] = in.nextDouble();
				y[i] = in.nextDouble();
			}
			for(int i=0; i<3; i++){
				vx[i] = x[(i+1)%3]-x[i];
				vy[i] = y[(i+1)%3]-y[i];
				vx[i+3] = x[3]-x[i];
				vy[i+3] = y[3]-y[i];
			}
			int check = 0;
			for(int i=0; i<3; i++){
				if(vx[i]*vy[i+3]-vx[i+3]*vy[i]>0) check++;
			}
			if(check == 0 || check == 3) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

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

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


using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main(){
  int n;
  cin >> n;
  vector<int> V(n);
  rep(i, n){
    cin >> V[i];
  }
  
  long long ans = 0;
  
  ll sum = 0;
  for(int j = 0; j<n; j++){
      sum += V[j];
  }
  
 
  
  for(int i = 0; i<n; i++){
    ll sum2;
    sum -= V[i];
    sum2 = sum;
    sum2 %= 1000000007;
    sum2 *= V[i];
    ans += sum2;
    ans %= 1000000007;
  }
      
     
  
  cout << ans << endl;
    

    
}

      
      
       





Measured memory_bytes: 4016
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int H, W, M; cin >> H >> W >> M;
	vector<int> rs(M), cs(M);
	set<pair<int, int>> posSet;
	vector<int> rowNums(H, 0), colNums(W, 0);
	REP(i, M)
	{
		cin >> rs[i] >> cs[i]; --rs[i]; --cs[i];
		posSet.insert({ rs[i], cs[i] });
		++rowNums[rs[i]];
		++colNums[cs[i]];
	}
	map<int, vector<int>, greater<int>> rowNum2RowMap, colNum2ColMap;
	REP(r, H) 
	{
		rowNum2RowMap[rowNums[r]].push_back(r);
	}
	REP(c, W)
	{
		colNum2ColMap[colNums[c]].push_back(c);
	}
	int ans = rowNum2RowMap.begin()->first + colNum2ColMap.begin()->first;
	bool bombExists = true;
	for (const auto r : rowNum2RowMap.begin()->second)
	{
		for (const auto c : colNum2ColMap.begin()->second)
		{
			if (posSet.count({ r, c }) == 0)
			{
				bombExists = false;
				break;
			}
		}
		if (bombExists == false) break;
	}
	if (bombExists) --ans;
	cout << ans << endl;
}

Measured memory_bytes: 26212
package main
 
import (
	"fmt"
)

var n, m, a, b, count int

func main() {
  fmt.Scan(&n)
  fmt.Scan(&m)
  h := make([]int, n)
  for i:=0; i < n; i++ {
    fmt.Scan(&a)
    h[i] = a
  }
  t := make([]bool, n)
  for i := 0; i < m; i++ {
    fmt.Scan(&a)
    fmt.Scan(&b)
    if h[a - 1] == h[b - 1] {
      t[a - 1] = true
      t[b - 1] = true
    } else if h[a - 1] > h[b - 1] {
      t[b - 1] = true
    } else {
      t[a - 1] = true
    }
  }
  for _, v := range t {
    if v == false { count++ }
  }
  fmt.Println(count)
}

Measured memory_bytes: 6512
def solve(string):
    _, *a = map(int, string.split())
    ans = step = 0
    for a0, a1 in zip(a, a[1:]):
        step = max(0, a0 + step - a1)
        ans += step
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 33496
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define INF 1245678912346
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_VAL 0

signed main(){
	// cout<<fixed<<setprecision(8);
	bool flag = false;
	
	int n, m ,x, y, X, Y, temp[400] = {};
	int  maxx = -1*INF, miny = INF;
	cin>>n>>m>>X>>Y;
	// maxx = x;
	// maxy = y;
	for(int i = X+1; i <= Y; i++){
		temp[i+200] = true;
	}
	for(int i = 1; i <= n; i++){
		cin>>x;
		maxx = max(maxx, x);
	}
	// temp[maxx] = 1;
	for(int i = 1; i <= m; i++){
		cin>>y;
		miny = min(miny, y);
	}
	// temp[miny]= 2;
	
	for(int i = maxx+1; i <= miny; i++){
		if(temp[i+200] == true) flag = true;
	}
	
	
	cout<<(flag?"No War":"War")<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    rep(i, t) cin >> a[i];
    sort(ALL(a));

    int sum = 0;
    rep(i, t - 1) sum += a[i];

    cout << max(0LL, a.back() - 1 - sum) << endl;

    return 0;
}


Measured memory_bytes: 256
s = list(input())
i = len(s)
ans = 0
while i >= 3:
    if s[i-1] != s[i-2]:
        i -= 1
        ans += 1
    else:
        i -= 3
        ans += 2
if i <= 1:
    print(ans+i)
else:
    if s[i-1] != s[i-2]:
        print(ans+2)
    else:
        print(ans+1)


Measured memory_bytes: 10644
n, k = gets.chomp.split(" ").map(&:to_i)
h = Array.new(n) { gets.chomp.to_i }.sort!

ans = 10 ** 10

n.times do |i|
  break if i + k > n

  min = h[i + k - 1] - h[i]

  ans = min if ans > min
end

puts ans


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define vec vector
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(i, 0, n) cin >> v[i]
#define prv(v) rep(i, 0, v.size()) {if (i) cout << ' '; cout << v[i];} cout << '\n'
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(i, 0, h) rep(j, 0, w) cin >> v[i][j]
#define prm(v) rep(i, 0, v.size()) {rep(j, 0, v[i].size()) {if (j) {cout << ' ';} cout << v[i][j];} cout << '\n';}
typedef long long ll;
void solve();
int main() {ios::sync_with_stdio(false); cin.tie(0); solve(); return 0;}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}

const int mod = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}

void solve() {
  rd(int, n, m);
  vec<bool> dangerous(n + 10, false);
  rep(i, 0, m) {
    rd(int, x);
    dangerous[x] = true;
  }
  vec<int> dp(n + 1);
  dp[0] = 1;
  rep(i, 0, n) {
    if (!dangerous[i + 1]) {
      add(dp[i + 1], dp[i]);
    }
    if (!dangerous[i + 2]) {
      add(dp[i + 2], dp[i]);
    }
  }
  pr(dp[n]);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10,inf=1e9+10;
int a[M],cnt[M],ans[M];
pii hlp[M];
main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],hlp[i]=mp(a[i],i);
	sort(hlp+1,hlp+n+1);
	int mn=hlp[n].S;
	for(int i=n;i>=1;i--)
	{
		mn=min(mn,hlp[i].S);
		while(hlp[i].F==hlp[i-1].F)i--,mn=min(hlp[i].S,mn);
		int cnt=hlp[i-1].F;
		int dis=hlp[i].F-cnt;
		int len=n-i+1;
		ans[mn]+=len*dis;
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
//using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

int main(){
  string s,rs;
  cin >> s;
  rs = s;
  reverse(All(rs));
  if(s==rs){
    s = s.substr(0,(s.size()-1)/2);
    rs = s;
    reverse(All(rs));
    if(rs==s){
      cout<< "Yes" <<endl;
      return 0;
    }
  }
  cout<< "No" <<endl;
}


Measured memory_bytes: 256
/**
 * @author yuzining
 * @date 2020/08/02 20:23
 */

#ifdef local
#include "D:\vscode\acm\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

const int N = 5e5 + 10;
int base[N], C[N];

queue<int> c[N];

void add(int at, int x) {
  for(int i = at; i < N; i += i & (-i)) {
    base[i] += x;
  }
}

int query(int at) {
  int ans = 0;
  for(int i = at; i > 0; i -= i & (-i)) {
    ans += base[i];
  }
  return ans;
}

pair<int, int> q[N];

int ans[N], id[N];

void Main() {
  int n, Q; cin >> n >> Q;
  for(int i = 1; i <= n; i++) {
    cin >> C[i];
    c[C[i]].push(i);
  }
  for(int i = 1; i <= Q; i++) {
    cin >> q[i].first >> q[i].second;
  }
  iota(id, id + Q + 1, 0);
  sort(id + 1, id + 1 + Q, [&](const int& x, const int& y) {
    return q[x] < q[y];
  });
  for(int i = 1; i <= n; i++) {
    if(!c[i].empty()) {
      add(c[i].front(), 1);
      c[i].pop();
    }
  }
  int cur = 1;
  for(int i = 1; i <= Q; i++) {
    const int j = id[i];
    while(cur < q[j].first) {
      add(cur, -1);
      if(!c[C[cur]].empty()) {
        add(c[C[cur]].front(), 1);
        c[C[cur]].pop();
      }
      cur++;
    }
    ans[j] = query(q[j].second);
  }
  for(int i = 1; i <= Q; i++) {
    cout << ans[i] << "\n";
  }
}

Measured memory_bytes: 352940
from collections import defaultdict
n = int(input())
x = []
y = []
p = []

INF = 1e18
#URDL = 0123

def ff(p):
    pp = sorted(p, key= lambda x: x[0])
    res = INF
    for i in range(1,len(pp)):
        if (pp[i-1][1] == 0 and pp[i][1] !=0):
            res = min(res, pp[i][0] - pp[i-1][0])
    return res

def f(d):
    res = INF
    for k in d.values():
        res = min(res,ff(k))
    return res

for i in range(n):
    i1, i2, i3 = input().split()
    x.append(int(i1))
    y.append(int(i2))
    if (i3 == 'U'):
        p.append(0)
    elif (i3 == 'R'):
        p.append(1)        
    elif (i3 == 'D'):
        p.append(2)
    else:
        p.append(3) 

ans = INF

for _ in range(4):
    d = defaultdict(list)
    for i in range(n):
        if p[i] != 0 and p[i]!= 2:
            continue
        d[x[i]].append((y[i],p[i]))
    ans = min(ans,f(d)*5)

    d = defaultdict(list)
    for i in range(n):
        if p[i] != 0 and p[i]!= 1:
            continue
        d[x[i]+y[i]].append((y[i],p[i]))
    ans = min(ans,f(d)*10)

    for i in range(n):
        px, py = x[i], y[i]
        x[i], y[i] = py, -px
        p[i] = (p[i]+1)%4  

if ans == INF:
    print("SAFE")
else:
    print(ans)

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

int main(){
    int K, S;
    cin >> K >> S;
    
    int ans = 0;
    for(int i = 0; i <= K; ++i){
        for(int j = 0; j <= K; ++j){
            ans += (S - i - j <= K && S - i - j >= 0);
        }
    }
        
    cout << ans << endl;

    return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  multiset<int> S;
  Solver(LL n) : n(n){};

  void solve() {
    map<int, int> cnt;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      //a[i] = i % ((int)sqrt(n));
    }
    for (int i = 0; i < n; ++i) {
      cnt[a[i]]++;
    }
    vector<int> inv(n);
    for (auto p : cnt) {
      for (int i = 0; i < p.second; ++i) {
        inv[i]++;
      }
    }
    for (auto i : inv) {
      if (i == 0) break;
      S.insert(i);
    }
    S.insert(0);
    vector<LL> ans(n + 1);
    ans[0] = n;
    LL k = 1;
    for (; k * k <= n * 1; ++k) {
      ans[k] = calc(k);
      if (ans[k] * ans[k] < n / 1) {
        k++;
        break;
      }
    }
    DBG(S)
    DBG(k)
    int l_mid = ans[k - 1];
    int bound_prev = k - 1;
    for (int l = l_mid; l >= 0; --l) {
      int bound = calc_bound(l, bound_prev);
      for (int i = bound_prev + 1; i <= bound; ++i) {
        ans[i] = l;
      }
      bound_prev = bound;
    }
    for (int i = 1; i <= n; ++i) {
      cout << ans[i] << endl;
    }
  }
  int calc_bound(int l, int bound_prev) {
    DBG(l, bound_prev)
    int ub = n + 1;
    int lb = bound_prev;
    while (ub - lb > 1) {
      int mid = (ub + lb) / 2;
      if (calc(mid) >= l)
        lb = mid;
      else
        ub = mid;
    }
    return lb;
  }
  int calc(int k) {
    multiset<int> T = S;
    int ret = 0;
    while (1) {
      auto it = T.lower_bound(k);
      if (it == T.end()) break;
      int now = *it;
      int pre = *prev(it);
      ret++;
      int tmp = now - k + pre;
      T.erase(it);
      T.erase(T.lower_bound(pre));
      T.insert(tmp);
      T.insert(0);
    }
    return ret;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 33408
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, vector<long long> A){
    bitset<4000010> dp;
    dp[0] = 1;
    long long s = accumulate(A.begin(), A.end(), 0);
    for (int i = 0; i < A.size(); i++) {
        dp |= (dp << A[i]);
    }
    for (int i = (s+1)/2; i < s+1; i++) {
        if (dp[i]) {
            std::cout << i << std::endl;
            return;
        }
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    vector<long long> A(N-1+1);
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&A[i]);
    }
    solve(N, A);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 1792
S = input()

ans = 1e9
for c in range(ord('a'), ord('a') + 26):
    c = chr(c)
    res = []
    for i, s in enumerate(S):
        if c == s:
            res.append(i)
    if len(res) == 0:
        continue
    if len(res) > 1:
        D = [res[i + 1] - res[i] - 1 for i in range(0, len(res) - 1)]
        res1 = max(D)
    else:
        res1 = 0
    res2 = max(res[0], len(S) - res[-1] - 1)
    ans = min(ans, max(res1, res2))

print(ans)


Measured memory_bytes: 38896
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

LL rec( LL n );
LL memo[90];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    LL n;
    cin >> n;
    cout << rec( n ) << endl;
    return 0;
}

LL rec( LL n )
{
    if( n == 0 ) return 2;
    if( n == 1 ) return 1;
    if( memo[n] ) return memo[n];
    memo[n] = rec( n - 1 ) + rec( n - 2 );
    return memo[n];
}



Measured memory_bytes: 256
import itertools


n = int(input())
geo = [list(map(int, input().split())) for i in range(n)]

sum_dist = 0
num_pattern = 0

for pattern in itertools.permutations([i for i in range(n)], n):
    for i in range(1, n):
        x, y = geo[pattern[i]]
        x_prev, y_prev = geo[pattern[i-1]]
        d = ((x-x_prev) ** 2 + (y-y_prev) ** 2) ** 0.5
        sum_dist += d
    num_pattern += 1

print(sum_dist / num_pattern)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  for(int i=a;i<=b;i++){
    int sum=0;
    int x=i%10;
    int y=i/10000;
    int z=(i-y*10000)/1000;
    int s=(i-y*10000-z*1000)/100;
    int t=(i-y*10000-z*1000-s*100)/10;
    if(x==y){
      sum++;
    }
    if(t==z){
      sum++;
    }
    if(sum==2){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import Foundation

/*＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿
 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
 ￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣*/
let main: () = {
    let x = readInt()
    if x == 0 {
        print(0, 0)
        return
    }
    var l: [(Int, Int)] = [(0, 0), (1, 1)]
    var nl: [(Int, Int)] = [(-1, -1)]
    var i = 1
    let c = Int(pow(10.0, 9.0))
    while (l[i].1 - l[i-1].1) < c {
        i += 1
        let r = Int(pow(Double(i), 5.0))
        l.append((i, r))
        nl.append((-i, -r))
    }
    l += nl
    for (ai, av) in l {
        for (bi, bv) in l {
            if av - bv == x {
                print(ai, bi)
                return
            }
        }
    }
}()

func check(_ x: Int, _ y: Int, _ p: Int) -> Bool {
    (x - y) == p
}

/*＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣*/

private func readString() -> String {
    readLine()!
}

private func readStringArray() -> [String] {
    readString().components(separatedBy: " ")
}

private func readInt() -> Int {
    Int(readString())!
}

private func readIntArray() -> [Int] {
    readStringArray().map { Int($0)! }
}

private func readStringTupple() -> (String, String) {
    let array = readStringArray()
    return (array[0], array[1])
}

private func readStringTupple() -> (String, String, String) {
    let array = readStringArray()
    return (array[0], array[1], array[2])
}

private func readIntTupple() -> (Int, Int) {
    let array = readIntArray()
    return (array[0], array[1])
}

private func readIntTupple() -> (Int, Int, Int) {
    let array = readIntArray()
    return (array[0], array[1], array[2])
}


Measured memory_bytes: 13564
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<ll>arr(n);
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	// cout<<"here";
	ll res=0,temp=0;
	for(int i=1;i<n;i++){
		temp=2*arr[i-1]-temp;
		res+=temp;
	}
	ll x=sum-res;
	vector<ll>result(n);
	for(int i=0;i<n;i++){
		result[i]=x;
		x=arr[i]*2-x;
	}
	for(int i=0;i<n;i++){
		cout<<result[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>

int main() {
    //for( int i = 1 ; i <= 10000 ; i++ ) {
    int i = 1 ;
    while( true ) {
        int x ;
        std::cin >> x ;
        
        if( x == 0 ) {
            break ;
        }
        
        std::cout << "Case " << i << ": " << x << std::endl ;
        i++ ;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n;
ll a[100];
ll ans=1000;
ll k;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i-1]<a[i]){
            k=ans/a[i-1];
            ans=ans-k*a[i-1];
            ans=ans+k*a[i];
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int n, k;
int a[100005];
int dp[100005];

int main(void)
{
  cin >> n >> k;
  for(int i = 1; i <= n; i++) cin >> a[i];

  for(int i = 2; i <= n; i++){
    dp[i] = 1e9;
    for(int j = 1; j <= k; j++){
      if(i-j >= 1) dp[i] = min(dp[i], dp[i-j] + abs(a[i-j] - a[i]));
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod
#define digit(x) floor((log10(x))+1)


#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

int main()
{
	fast;
//	string s;
	int i,n;
	cin >> n;
	int flag=0;
	while(n>0)
	{
		if(n%10==7)
		{
			flag=1;
			break;
		}
		n/=10;
	}
	if(flag==1)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
}

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
#define MOD               998244353

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
ll _accumulate(const VL &v) { return accumulate(ALL(v), (ll)0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 枝定義
struct Edge
{
	int	from;
	int	to;
	Edge(){}
	Edge(int a, int b) : from(a), to(b){}
};

// 処理
void Solve()
{
	int N;
	cin >> N;
	vector<Edge> edgeList;
	REP(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		edgeList.emplace_back(a, b);
	}

	VL c(N);
	REP(i, N) cin >> c[i];
	sort(ALL(c), greater<ll>());

	vector<vector<int>>	G(N);
	for (auto one : edgeList) {
		G[one.from].emplace_back(one.to);
		G[one.to].emplace_back(one.from);
	}

	VL vAns(N, 0);
	ll idx = 0;
	ll ansAll = 0;
	vAns[0] = c[idx++];

	queue<ll> que;
	vector<bool> isUsed(N, false);
	que.push(0);
	isUsed[0] = true;
	while (!que.empty()) {
		ll next = que.front(); que.pop();
		for (auto nextTo : G[next]) {
			if (!isUsed[nextTo]) {
				isUsed[nextTo] = true;
				que.push(nextTo);
				vAns[nextTo] = c[idx];
				ansAll += c[idx];
				idx++;
			}
		}
	}

	cout << ansAll << endl;
	for(auto one : vAns) {
		cout << one << endl;
	}
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	string S;
	cin >> S;
	int ans = 0;
	rep(i, S.size()) {
		if (S.compare(i, 1, "U") == 0 || S.compare(i, 1, "D") == 0) {
			continue;
		}
		else if (i % 2 == 0 & S.compare(i, 1, "R") == 0) {
			continue;
		}
		else if(i % 2 == 1 & S.compare(i, 1, "L") == 0){
			continue;
		}
		else {
			ans = 1;
			break;
		}
	}
	if (ans == 0) {
		print("Yes");
	}
	else {
		print("No");
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int Partition(int *,int *,char *,int,int);
void QSort(int *,int *,char *,int,int);
int main()
{
  int i,n,s=0;
  int A[200000],B[200000];
  char ch,C[100000];
    
  scanf("%d%c",&n,&ch);
  for(i=0;i<n;i++){
    scanf("%c%c%d%c",&C[i],&ch,&A[i],&ch);
    B[i]=i;
  }
 
  QSort(A,B,C,0,n-1);
  for(i=0;i<n;i++){
    if(B[i]>B[i+1] && A[i]==A[i+1]){
      s=1;
      break;
    }
  }
  if(s==0)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",C[i],A[i]);
  }
  return 0;
}
 
void QSort(int *A,int *B,char *C,int p,int r)
{
  int q;
  if(p<r){
    q=Partition(A,B,C,p,r);
    QSort(A,B,C,p,q-1);
    QSort(A,B,C,q+1,r);
  } 
}
 
 
int Partition(int *A,int *B,char *C,int p,int r)
{
  int x,i,j,temp;
  char ch;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
      temp=B[i];
      B[i]=B[j];
      B[j]=temp;
      ch=C[i];
      C[i]=C[j];
      C[j]=ch;
    }
     
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp; 
  temp=B[i+1];
  B[i+1]=B[r];
  B[r]=temp;
  ch=C[i+1];
  C[i+1]=C[r];
  C[r]=ch;
  return i+1;
}  


Measured memory_bytes: 2636