akhauriyash/Code-Regression huggingface dataset:
/* ex4_3
  sachiyan */

#include <stdio.h>
int snow(int w, int e); //関数preのプロトタイプ宣言

int main(void){
    int west, east; //A,Bの定義
    scanf("%d %d", &west, &east); //A,Bの読み取り
    printf("%d\n", snow(west, east)); //答えを出力
}

int snow(int w, int e){ //関数preの定義　differenceを引数とする
    int pre_east; //pre_eastを定義
    int diff, answer; //差と答えの定義
    int i; //for内の変数定義
    pre_east = 0;
    diff = e - w; //高さの差を算出
    for(i = 1; i <= diff; i++){
        pre_east += i; //差と同じ値まで足し続ける
    }
    answer = pre_east - e; //関数preを呼び出し、積もる前との高さを比較する
    return(answer); //東の塔のもとの高さが分かる
}

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

int main() { 
  int n;
  long long k;
  int q;
  cin >> n;
  cin >> k;
  cin >> q;
  int b;
  vector<int> a(n+10); //回数

for (int i=1; i<=q; i++){
  cin >> b;
  a.at(b) += 1;
}

for(int i=1;i<=n; i++){
  if(k - (q - a.at(i)) > 0) cout << "Yes" << endl;
  if(k - (q - a.at(i)) <= 0) cout << "No" << endl;
}




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

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 1e10;



int n;
pair<ll,ll> a[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i].first>>a[i].second;
	if (a[i].first>a[i].second) {
	    swap(a[i].first, a[i].second);
	}
    }


    ll l1=inf,r1=0,l2=inf,r2=0;
    for (int i=0; i<n; i++) {
	l1=min(l1,a[i].first);
	r1=max(r1,a[i].first);
	
	l2=min(l2,a[i].second);
	r2=max(r2,a[i].second);
    }

    ll ans = (r1-l1)*(r2-l2); //global min and global max are in different sets
    


    
    ll len = max(r1,r2) - min(l1,l2);

    sort(a,a+n);
    reverse(a,a+n);



    //init multiset with elements from `second`
    multiset<ll> ms;
    for (int i=0; i<n; i++) ms.insert(a[i].second);


    //global min and global max are both in first set
    //this means that we're trying to minimize range in the second set
    //

    //iterate first set from hi to lo
    for (int i=0; i<n; i++) {
	//swap `second` with `first` (i.e, swap with something smaller)
	
	ms.erase(ms.find(a[i].second)); ms.insert(a[i].first);
	
	ll cur = len*(*ms.rbegin() - *ms.begin());
	//watch(cur);
	ans = min(cur, ans);
    }
  
    
    cout<<ans<<endl;  

    return 0;
}


Measured memory_bytes: 13820
using System;
using System.IO;
using System.Linq;

namespace ABC120A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = temp[0];
            var B = temp[1];
            var C = temp[2];

            var count = B / A > C ? C : B / A;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r, g, b;
    cin >> r >> g >> b;
    int a = r * 100 + g * 10 + b;
    if (a % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 
using namespace std;
int main()
{
	int n=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int b[n];
	int c=0;
	if(n%2==1){ //3       1 2 3
		for(int i=n-1;i>=0;i-=2){
			b[c]=a[i];//b[0]=3 b[1]=1
			c++;//1 2
		}
		for(int i=1;i<=n-2;i+=2){
			b[c]=a[i];//b[2]=2
			c++;//3
		}
	}//3 1 2
	else{ //4      1 2 3 4
		for(int i=n-1;i>=1;i-=2){ 
			b[c]=a[i]; //b[0]=4 b[1]=2
			c++; //1 2
		}
		for(int i=0;i<=n-2;i+=2){ 
			b[c]=a[i]; //b[2]=1 b[3]=3
			c++;//3
		}
	}//4 2 1 3
	for(int i=0;i<n;i++){
		cout<<b[i]<<" ";
	}
    return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#define Us 10000
#define Uq 500
int main(){
  int i,j,S[Us],T[Uq],Sn,Tn,count=0;
  scanf("%d",&Sn);
  for(i=0; i<Sn; i++){//入力したSnだけループ
    scanf("%d",&S[i]);
  }
  scanf("%d",&Tn);
  for(i=0; i<Tn; i++){
    scanf("%d",&T[i]);
    for(j=0; j<Sn; j++){
      if(S[j]==T[i]){
    count++;
    break;
      }//異なる整数なので見付けたらjのループをぬけてもOK
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var a = Arrays.stream(br.readLine().split(" "))
        .mapToLong(Long::parseLong)
        .toArray();

      System.out.println(
        Math.max(Math.max(Math.max(a[0] * a[2], a[1] * a[2]), a[0] * a[3]), a[1] * a[3])
      );
    }
  }
}


Measured memory_bytes: 34396
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), x = sc.nextInt();
		if(a+b < x) {
			System.out.println("NO");
		} else if (a > x) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
		
		
		
		
		
		
	}

}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define _ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define sll(x) scanf("%I64d",&x)
#define sd(x)  scanf("%d",&x)
#define pll(x) printf("%I64d",x)
#define pd(x)  printf("%d",x)

#define clr(x) memset(x,0,sizeof x)
#define sf .second.first
#define ss .second.second
#define mid    ((l+r)>>1)
#define Pi acos(-1)
#define EPS 1e-12
#define MOD  1000000007
#define MOD1 1000000009
#define INF  1000000000

#define N 100005

ll n,w,a[200],v[200],dp[200][N];


int main()
{
    cin >>n>>w;
    int mx=0;
    for(int i=0; i<n; i++){
            cin>>a[i]>>v[i];
            mx+=v[i];
    }

    for(int i=0;i<200;i++)
        for(int j=1;j<=mx;j++)
        dp[i][j]=MOD*6;

        //cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;
    for(int i=0;i<n;i++){
        for(int j=0;j<=mx;j++){
            if(i==0)
            dp[i][v[i]]=a[i];
            else if(v[i]<=j)
                dp[i][j]=min(a[i]+dp[i-1][j-v[i]],dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    for(int i=mx;i>=0;i--){
        if(dp[n-1][i]<=w){
            cout<<i<<endl;
            return 0;
        }
    }

    //cout<<dp[n][w]<<endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> v0(100010,0), v1(100010,0);
  int l, m;
  for (int i = 0; i < n/2; i++) {
    cin >> l >> m;
    v0.at(l)++;
    v1.at(m)++;
  }

  int index0_1 = 0, index0_2 = 0, index1_1 = 0, index1_2 = 0;
  for (int i = 1; i <= 100000; i++) {
    if (v0.at(i) > v0.at(index0_1)) {
      index0_2 = index0_1;
      index0_1 = i;
    }
    else if (v0.at(i) > v0.at(index0_2)) {
	index0_2 = i;
    }
    if (v1.at(i) > v1.at(index1_1)) {
      index1_2 = index1_1;
      index1_1 = i;
    }
    else if (v1.at(i) > v1.at(index1_2)) {
	index1_2 = i;
    }
  }

  if (index0_1 == index1_1) {
    cout << n - max(v0.at(index0_2) + v1.at(index1_1),v0.at(index0_1) + v1.at(index1_2)) << endl;
  }
  else {    
    cout << n - v0.at(index0_1) - v1.at(index1_1) << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

const double eps = 1.0e-7;
const double pi = 4.0 * atan(1.0);

double getArea(vector<int> v) {
    int last = 360;
    for (int i=0; i<(int)v.size(); ++i) last -= v[i];
    v.push_back(last);
    double ret = 0;
    for (int i=0; i<(int)v.size(); ++i) {
        ret += sin((double)v[i] * pi / 180);
    }
    return ret;
}

int main() {
    int m, n;
    while (cin >> m, m) {
        vector<int> v1(m-1);
        for (int i=0; i<m-1; ++i) {
            cin >> v1[i];
        }
        cin >> n;
        vector<int> v2(n-1);
        for (int i=0; i<n-1; ++i) {
            cin >> v2[i];
        }
        double area1, area2;
        area1 = getArea(v1);
        area2 = getArea(v2);
        if (abs(area1 - area2) < eps) {
            cout << 0 << endl;
        } else if (area2 < area1) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h> 
#define ll long long int
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

using namespace std; 

vector< pair<int, int> > test[20];
int ans=0;

void printTheArray(int arr[], int n) 
{ 
    int cnt=0;
    
    bool diterima = 1;
    for (int i = 0; i < n; i++) { 
        //cout << arr[i] << " "; 
        
        bool lolos = 1;
        if(arr[i]==1) {
        
            for(int j=0;j<test[i].size();j++) {
                if(arr[test[i][j].fs-1] != test[i][j].sc) {
                    lolos = 0;
                    break;
                }
            }
            
            cnt++;
        }
        if(!lolos) {
            diterima=0;
            break;
        }
    } 
    
    if(diterima) {
        ans = max(ans,cnt);
    }
    //cout << endl; 
} 
  
void generateAllBinaryStrings(int n, int arr[], int i) 
{ 
    if (i == n) { 
        printTheArray(arr, n); 
        return; 
    } 
  
    arr[i] = 0; 
    generateAllBinaryStrings(n, arr, i + 1); 
 
    arr[i] = 1; 
    generateAllBinaryStrings(n, arr, i + 1); 
} 
  

int main() 
{ 
    int n;
    cin>>n; 
  
    int arr[n]; 
    
    for(int i=0;i<n;i++) {
        int t; cin>>t;
        for(int j=0;j<t;j++) {
            int x,y; cin>>x>>y;
            test[i].pb(mp(x,y));
        }
    }

    generateAllBinaryStrings(n, arr, 0); 
    
    cout<<ans<<endl;
  
    return 0; 
} 

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

template <typename T> vector<vector<T>> make_vector_2d(int n, int m, T initialValue) {
    auto r = vector<vector<T>>(n);
    for (int i = 0; i < n; i++) r[i] = vector<T>(m, initialValue);
    return r;
}

int main() {

    const int maxdigit = 15;
    auto dp = make_vector_2d(10, maxdigit, 0ll);
    for (int i = 0; i < 10; i++) dp[i][0] = 1ll;
    for (int j = 1; j < maxdigit; j++) {
        dp[0][j] = dp[0][j - 1] + dp[1][j - 1];
        dp[9][j] = dp[8][j - 1] + dp[9][j - 1];
        for (int i = 1; i < 9; i++) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + dp[i + 1][j - 1];
    }

    int k;
    cin >> k;
    bool sw = false;
    int i2, j2;
    
    for (int j = 0; j < maxdigit; j++) {
        for (int i = 1; i < 10; i++) {
            if (k <= dp[i][j]) {
                sw = true;
                i2 = i;
                j2 = j;
                break;
            }
            else {
                k = k - dp[i][j];
            }
        }
        if (sw) break;
    }

    cout << i2;
    for (int j = j2 - 1; j >= 0; j--) {
        // j桁目がi2-1の場合
        if (i2 != 0) {
            if (k <= dp[i2 - 1][j]) {
                cout << (i2 - 1);
                i2--;
                continue;
            }
            else {
                k = k - dp[i2 - 1][j];
            }
        }
        // j桁目がi2の場合
        if (k <= dp[i2][j]) {
            cout << i2;
            continue;
        }
        else {
            k = k - dp[i2][j];
            // それ以外 = j桁目がi2+1の場合
            cout << (i2 + 1);
            i2++;
        }
    }
    cout << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str, sa, sb;

vector<ll> adj[maxn];
bool check;
struct dang
{
    ll val, sl;
};
dang st[maxn];
ll bs(ll v)
{
    ll lf = 1, rt = n, mid, t1;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(b[mid] < v)lf = mid + 1;
        else rt = mid - 1;
    }
    t1 = lf;
    lf = 1, rt = n, mid;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(b[mid] <= v)lf = mid + 1;
        else rt = mid - 1;
    }
    if(b[t1] == v)return rt - t1 + 1;
    else return 0;
}
void test()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = a[i] + i;
        //cout << b[i]<< " ";
    }
    //cout << '\n';
    sort(b+1, b+1+n);
    ans = 0;
    for(int i = 2; i <= n; i ++)
    {
        //cout << i - a[i]<<" ";
        if(i > a[i])
        {
            ans += bs(i - a[i]);
        }
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}



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

int main(){
    double N, K;
    cin >> N >> K;

    double ret = 0;
    for(int i = 1; i <= N; i++){
        double tmp = 1.0/N;
        int now = i;
        while(now < K){
            now *= 2;
            tmp /= 2;
        } 
        ret += tmp;
    }
    

    printf("%.12f\n", ret);

    return 0;
}

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

i = 0
ans = 0
while x > 0 and i<= n-1:
  if x >= l[i]:
    x -= l[i]
    if i == n-1:
      if x == 0:
        ans += 1
        break
      else:
        break
    else:
      i += 1
      ans += 1
  else:
    x = 0
    break
print(ans)
  


Measured memory_bytes: 38512
from collections import deque
h,w=map(int,input().split())
G=[]
for _ in range(h):
  s=input()
  S=[]
  for i in range(w):
    S.append(s[i])
  G.append(S)

si,sj=0,0
gi,gj=h-1,w-1
INF=float('inf')
dist=[[INF for i in range(w)] for j in range(h)]
dist[si][sj]=1
Q=deque()
Q.append((si,sj))
while Q:
  pi,pj=Q.popleft()
  for di,dj in [[-1,0],[1,0],[0,-1],[0,1]]:
    ni,nj=pi+di,pj+dj
    if 0>ni or ni>h-1:
      continue
    if 0>nj or nj>w-1:
      continue
    if G[ni][nj]=='#':
      continue
    if dist[ni][nj]>dist[pi][pj]+1:
      dist[ni][nj]=dist[pi][pj]+1
      Q.append((ni,nj))
ans=0      
for i in range(h):
  for j in range(w):
    if G[i][j]=='.':
      ans+=1
ans-=dist[gi][gj]
if ans<0:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 74460
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    char b;
    
    cin >> b;
    
        if( b == 'A'){
        
        cout << 'T' <<endl;
        
        }
    
        if( b == 'T'){
        
        cout << 'A' <<endl;
        
        }
        if( b == 'C'){
        
        cout << 'G' <<endl;
        
        }
        if( b == 'G'){
        
        cout << 'C' <<endl;
        
        }
    
    
    
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	string s = ReadLine();
	char last = 'a';
	bool bad = false;

	for (int i = 0; i < 4; i++)
	{
	    if (s[i] == last)
	    {
		bad = true;
		break;
	    }
	    last = s[i];
	}

	WriteLine(bad?"Bad":"Good");
    }
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    
    int cnt = 0;
    for(int i = 0; i < N; ++i){
        if(i + 1 == a[a[i] - 1])     cnt++;
    }
    cnt /= 2;
    
    cout << cnt << endl;
}

Measured memory_bytes: 640
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}



int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	//sort(a, a + n);
	int q;
	cin >> q;
	while(q--){
		int b, e, k;
		cin >> b >> e >> k;
		int ans = 0;
		for(int i = b; i < e; i++)if(a[i] == k)ans++;
		cout << ans << '\n';
	}
	return 0;
}



Measured memory_bytes: 3208
#include <iostream>

using namespace std;
int main() {
    int N;
    char A[101], B[101], C[101];
    cin >> N;
    cin >> A;
    cin >> B;
    cin >> C;
    int sum = 0;
    for (int i=0; i<N; i++) {
        if (A[i] == B[i] && B[i] == C[i]) sum += 0;
        else if (A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) sum += 1;
        else sum += 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e10;
const int MAX_N = 200001;
int main() {

	int n; cin >> n;
	vector<int> a(n); rep(n)cin >> a[i];
	vector<int> gr(n), gl(n);
	gr[0] = a[0], gl[0] = a[n - 1];
	for (int i = 1; i < n; i++) {
		gr[i] = gcd(gr[i - 1], a[i]),gl[i] = gcd(gl[i - 1], a[n - 1 - i]);		
	}
	int ans = max(gl[n - 2], gr[n - 2]);
	
	for (int i = 1; i < n - 1; i++) {
		ans = max(ans, gcd(gr[i - 1], gl[n - 2 - i]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
local DBG = false
if not DBG then
    assert = function()end
end
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function dbgpr_t(tbl, use_pairs)
    if DBG then
        local enum = ipairs
        if use_pairs then
            enum = pairs
        end
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in enum(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

local function dbgpr_tp(tbl)
    dbgpr_t(tbl, true)
end

local function str2tbl(s)
    -- limit of #s is approximately 999959
    --local t = {string.byte(s, 1, #s)}
    local t = {}
    local a = string.byte('a')
    local char = string.char
    local sub = string.sub
    local byte = string.byte
    for i=1, #s do
        t[i] = byte(sub(s, i, i), 1, 1) - a + 1
    end
    return t
end

-- E
local S = str2tbl(io.read("*l"))
local T = str2tbl(io.read("*l"))
--dbgpr_t(S)
--dbgpr_t(T)
local function search_s(n, c)
    for i=n,#S do
        if S[i] == c then
            --return i
            return i - n + 1
        end
    end
    return false
end
local lookup = {}
lookup[0] = {}
for c=1,26 do
    lookup[0][c] = search_s(1, c)
end
for i=1,#S do
    lookup[i] = {}
    for c=1,26 do
        if c == S[i] then
            lookup[i][c] = search_s(i+1, c)
        else
            local prev = lookup[i-1][c]
            lookup[i][c] = prev and prev - 1 or false
        end
    end
end

if DBG then
    for i=0,#S do
        local tbl = lookup[i]
        dbgpr(tbl)
        dbgpr(i)
        io.write("[dbg]")
        for j,v in ipairs(tbl) do
            io.write(string.char(j+96))
            io.write(":")
            io.write(v and v or '*')
            io.write(" ")
        end
        print("")
    end
end
local cur = 0
local ans = 0
local i = 1
while i <= #T do
    local c = T[i]
    dbgpr("!", "i=", i, ans, "c=", c, "cur=", cur, "#lookup", #lookup)
    local step = lookup[cur][c]
    dbgpr(i, ans, c, cur, step)
    if step then
        dbgpr(cur, step)
        ans = ans + step
        cur = cur + step
        assert(cur <= #S)
        i = i + 1
    elseif cur ~= 0 then
        ans = ans + (#S - cur)
        cur = 0
    else
        -- cur == 0
        print("-1")
        return
    end
end
print(ans)

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {
    int n,m;
    cin>>n>>m;

    vector<pair<int,char>>sc(m);
    rep(i,m) cin>>sc[i].first>>sc[i].second;

    rep2(i,0,999){
        string s=to_string(i);
        bool jdg=true;

        if (s.size()!=n) continue;

        rep(i,m){
            if(s[sc[i].first-1]!=sc[i].second){
                jdg=false;
                break;
            }
        }

        if(jdg){
            cout<<i<<endl;
            return 0;
        }

    }

    cout<<-1<<endl;
}


Measured memory_bytes: 384
n, k = map(int, input().split())
r, s, p_ = list(map(int, input().split()))
p = [r, p_, s]
t = str(input())

dp = [[0 for _ in range(3)] for _ in range(n+1)]
# 0: r, 1: p, 2: s
d = {'r': 1, 'p': 2, 's': 0}
for i in range(1, n+1):
    v_num = d[t[i-1]]
    for j in range(3):
        # 勝てる数字
        if i < k + 1:
            if j == v_num:
                dp[i][j] = p[j]
            else:
                dp[i][j] = 0
        else:
            tmp = dp[i-k][:]
            tmp.pop(j)
            if j == v_num:
                dp[i][j] = max(tmp) + p[j]
            else:
                dp[i][j] = max(tmp)
ans = 0
for i in range(1, k+1):
    ans += max(dp[-i])
print(ans)


Measured memory_bytes: 56796
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

int main()
{
    LL a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    if (a + b >= c) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K; cin >> N >> K;
  int ans = 0;
  rep(i,N) {
    int h; cin >> h;
    if(h >= K) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
int n = stdIn.nextInt();
		long max = 0;
		for(int i = 0; i < n; i++){
			max += i;
		
		}
		System.out.println(max);
    }
}

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

const int N = 3;
int a[N][N];
bool b[N][N];

void mark(int n) {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (a[i][j] == n) b[i][j] = true;
    }
  }
}

bool ok() {
  for (int i = 0; i < N; ++i) {
    if (b[i][0] && b[i][1] && b[i][2]) return true;
  }
  for (int j = 0; j < N; ++j) {
    if (b[0][j] && b[1][j] && b[2][j]) return true;
  }
  if (b[0][0] && b[1][1] && b[2][2]) return true;
  if (b[0][2] && b[1][1] && b[2][0]) return true;
  return false;
}

int main() {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> a[i][j];
    }
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int p;
    cin >> p;
    mark(p);
  }
  cout << (ok() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
def modpow(a, n, mod)
  exp = Math.log(n, 2).floor
  rep = modpow_cl(a, n, exp, mod)
  return rep[0]
end

def modpow_cl(a, n, exp, mod)
  if exp < 0
    rep = [1, a]
  else
    if n >= 2**exp
      rep = modpow_cl(a, n-2**exp, exp-1, mod)
      rep[0] = rep[0]*rep[1] % mod
    else
      rep = modpow_cl(a, n, exp-1, mod)
    end
    rep[1] = rep[1]**2 % mod
  end
  return rep
end

def modcomb(n, k, mod)
  return 1 if k < 1 || n <= k
  nume = deno = 1
  for i in 1..k
    nume = nume*(n-i+1) % mod
    deno = deno*i % mod
  end
  return nume*modpow(deno, mod-2, mod) % mod
end

N, A, B = gets.split.map(&:to_i)
MOD = 10**9+7

ans = modpow(2,N,MOD)-1-modcomb(N,A,MOD)-modcomb(N,B,MOD)
puts ans % MOD

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

int N;
int A[210];

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

  int res = 0;

  //操作が行える限り操作を繰り返す
  while (true) {
    bool exist_odd = false; // A[i]がすべて偶数か判定
    for (int i = 0; i < N; ++i) {
      if (A[i] % 2 != 0) exist_odd = true; //奇数があったらフラグ立てる
    }

    if (exist_odd) break;

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

  cout << res << endl;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
 
// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
 
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>
 
/* ---------- Namespace ---------- */
using namespace std;
 
/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>
 
/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
 
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    map<int, int> m;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        m[a]++;
    }
 
    if (m.size() > 3) {
        cout << "No" << endl;
        return 0;
    }
 
    vector<int> vec;
    for (auto it = m.begin(); it != m.end(); it++) {
        vec.push_back(it->first);
    }
 
    if (m.size() == 3) {
        if (N % 3 == 0 && (vec[0] ^ vec[1]) == vec[2] && m[vec[0]] == m[vec[1]] && m[vec[1]] == m[vec[2]]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else if (m.size() == 2) {
        int x = vec[0]; // こっちがおおい
        int y = vec[1];
        if (m[y] > m[x]) swap(x, y);
 
        if (N % 3 == 0 && m[x] == 2 * m[y] && y == 0) {
            cout << "Yes" << endl;
        } else if (N % 3 == 2 && (m[x] - 1) == 2 * (m[y] - 1) && y == 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (vec[0] == 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    cout << (s < t ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

#include <sstream>
#include <istream>

using namespace std;

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

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

	if(n%k==0){
		cout << "0" << endl;
	}else{
		cout << "1" << endl;
	}

	return 0;
}


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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  while ( cin >> N, N ) {
    vector<int> day[31];    
    for ( int i = 0; i < N; i++ ) {
      int f;
      cin >> f;
      for ( int j = 0; j < f; j++ ) {
	int d;
	cin >> d;
	day[--d].push_back(i);	
      }
    }

    set<int> all[N];
    for ( int i = 0; i < N; i++ ) all[i].insert(i);    
    int ans = -1;
    for ( int i = 0; i < 31; i++ ) {
      for ( int n: day[i] ) { 
	for ( int m: day[i] ) {
	  for ( int s: all[m] ) all[n].insert(s);
	}
      }

      bool flag = false;
      for ( int i = 0; i < N; i++ ) {
	if ( all[i].size() == N ) {
	  flag = true;
	  break;
	}
      }

      if ( flag ) {
	ans = i+1;
	break;
      }
    }

    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S1,S2,S3;
  cin >> S1 >> S2 >> S3;
  
  S1[0] += 'A'-'a';
  S2[0] += 'A'-'a';
  S3[0] += 'A'-'a';
  
  cout << S1.at(0) << S2.at(0) << S3.at(0) << endl;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    int maxv = 0;
    for (int i = 0; i < n - 1; ++i) {
        maxv = max(a[i + 1] - a[i], maxv);
    }
    cout << a[n - 1] - a[0];
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(string, S, T);

    T += S;
    outl(T);

    return 0;
}


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

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;	
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
const int N = 3e5 + 55;
int n;
int cnt[61][2] = {{0}};
int arr[N];
int pw[65];
const int M = 1e9 + 7;
int f (int n) {
	if (n % 2 == 0)
		return ((n / 2) * (n - 1)) % M;
	else
		return (n * ((n - 1) / 2)) % M;
}
void solve() { 
	pw[0] = 1;
	for (int i = 1; i < 65; i += 1)
		pw[i] = (pw[i - 1] * 2) % M;
	cin >> n;
	for (int i = 1; i <= n; i += 1) {
		cin >> arr[i];
		for (int bit = 0; bit < 60; ++bit) {
			if ((1ll << bit) & arr[i])
				cnt[bit][1]++;
			else
				cnt[bit][0]++;
		}
	}
	int tot = 0;
	for (int bit = 0; bit < 60; ++bit) {
		// 1 1
		int ans = 0;
		// ans += (f(cnt[bit][1]) * pw[bit]) % M;
		// ans %= M;
		// 1 0 
		ans += (pw[bit] * ((cnt[bit][0] * cnt[bit][1]) % M)) % M;
		ans %= M;
		tot += ans, tot %= M;
	} cout << tot;
}



Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
	int a, b, c, i, t;
	scanf("%d %d %d\n", &a, &b, &c);
	for(i=a; i<=b; i++)
	{
		if(c%i == 0){
			t = t+1;
		}
	}
	printf("%d\n", t);


	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  int count=0;
  cin>>a>>b;
  for(int i=0;i<a.length();i++){
    if(a[i]!=b[i])
      count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3860
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(solve(n));
		sc.close();
		return ;
    }
    
    static String solve(int n) {
    	for (int i = 0; i < 26; i++) {
    		for (int j = 0; j < 20; j++) {
    			if (4*i + 7*j == n) {
    				return "Yes";
    			}
    		}
    	}
    	return "No";
    }
    
    
}


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

int main(){
    string s,a;
    int k;
    cin>>k>>s;
    if (s.size()<=k){
        cout<<s<<endl;
    }else{
        for(int i=0;i<k;i++){
            cout<<s.at(i);
        }
        cout<<"..."<<endl;
    }

}


Measured memory_bytes: 3632
import itertools
n,m=map(int,input().split())
l=[[0]*n for _ in range(m)]
for i in range(m):
    ltmp=list(map(int,input().split()))
    for j in ltmp[1:]:
        l[i][j-1]=1
p=list(map(int,input().split()))
lit=list(itertools.product([0,1],repeat=n))
ans=0
for i in lit:
    atmp=[]
    for j in l:
        tmp=sum([x*y for (x,y) in zip(i,j)])%2
        atmp.append(tmp)
    if atmp==p:ans+=1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch MixJuice | diff MixJuice.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address MixJuice.cpp && ./a.out

/*

 6/21/2020

 5:02-

 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N,K;

void solve() {
  sort(A,A+N);
  LL res=0;
  REP(i,K) res+=A[i];
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>K;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "No" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
bool ng=false;
struct edge{ll to;};
struct graph{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;
    vector<ll> atai;
    vector<ll> kaku;

    graph(ll n): N(n), G(N), used(N,false), atai(N,-INF), kaku(N,-INF) {}

    void ade(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無向ならON
    }

    void dfs(ll v, ll now){
        used[v]=true;
        for(auto E : G[v]){
            if(used[E.to] and ( (now+atai[E.to])%2==0/* or atai[E.to]>now+1*/))ng=true;
            if(kaku[E.to]!=-INF and kaku[E.to]<now-1) ng=true;
            if(ng) return;
            if(kaku[E.to]==-INF and maxi(atai[E.to], now-1)){
                dfs(E.to,now-1);
            }
        }
    }
};
//--MAIN-----------------------------------
void Main(){
    ll N; cin>>N;
    graph g(N);
    // 大きいものからdfsする 大きい値に書き換え 取れる最小の値を示す
    // 確定しているのにでかいので入ったらng, 確定していなければ更新してすすめる
    rep(i,N-1){
        ll a,b; cin>>a>>b;
        g.ade(--a,--b);
    }
    ll K; cin>>K;
    vector<P> PV;
    rep(i,K){
        ll v,p; cin>>v>>p;
        PV.emplace_back(p,--v);
        g.kaku[v]=p;
        g.atai[v]=p;
    }
    sort(ALL(PV),greater<P>());
    for(auto x: PV){
        g.dfs(x.second,x.first);
        if(ng) dame;
    }
    cout<< "Yes" <<"\n";
    for(auto x: g.atai){
        cout<< x <<"\n";
    }
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 10224
#!python3

from fractions import gcd
iim = lambda: map(int, input().rstrip().split())

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))
    return ans

def resolve():
    N = int(input())
    A = list(iim())
    mod = 10**9 + 7

    lcm = 1
    #c2 = dict()
    #for a in A:
    #    for n, m in factor(a):
    #        if n in c2:
    #            c2[n] = max(c2[n], m)
    #        else:
    #            c2[n] = m

    #lcm = 1
    #for n, m in c2.items():
    #    lcm *= n**m%mod % mod
    for a in A:
        lcm = lcm // gcd(lcm, a) * a
    lcm %= mod

    s = 0
    for a in A:
        s += lcm*pow(a, mod-2, mod)%mod
        s %= mod

    print(s)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 6136
// AOJ 1154 "月曜土曜素因数" (ICPC国内予選 2008 Problem B)
import java.util.Scanner;
import java.util.BitSet;

public class Main {
    static BitSet isNotMSPrime; // 月曜土曜素数でないならtrue
    static final int MAX_N = 300000;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        isNotMSPrime = new BitSet(MAX_N);
        sieve();
        while (true) {
            int n = sc.nextInt();
            if (n == 1) {
                break;
            }
            
            System.out.print(n + ":");
            for (int i = 6; i <= n; i++) {
                if (i % 7 != 1 && i % 7 != 6) {
                    continue;
                }
                if (!isNotMSPrime.get(i) && n % i == 0) {
                    System.out.print(" " + i);
                }
            }
            System.out.println();
        }
    }
    
    public static void sieve() {
        isNotMSPrime.set(0);
        isNotMSPrime.set(1);
        for (int i = 2; i <= MAX_N; i++) {
            if (i % 7 != 1 && i % 7 != 6) {
                isNotMSPrime.set(i);
                continue;
            }
            if (!isNotMSPrime.get(i)) {
                for (int j = i * 2; j <= MAX_N * 2; j += i) {
                    isNotMSPrime.set(j);
                }
            }
        }
    }
}

Measured memory_bytes: 23808
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <map>
#include <unordered_set>
#include <tuple>
#include <queue>
#include <set>
#include <cstring>
#include <functional>
#include <random>
#include <chrono>

#define ar array
#define all(arr) (arr).begin(), (arr).end()
#define range(i, n) for (int i=0; i < n; ++i)
#define rall(arr) (arr).rbegin(), (arr).rend()

typedef long long ll;
typedef long double ld;

using namespace std;

const ll INF = 1e18;
const int INFi = 2e9;
const int maxN = 1e6 + 5;
const int md2 = 998244353;
const int md = 1e9 + 7;

double getTime() { return clock() / (double) CLOCKS_PER_SEC; };

int d[maxN];

void solve() {
    int n; cin >> n;
    for(int i = 1; i <= n; ++i) {
        for(int j = i; j <= n; j += i) d[j]++;
    }
    ll ans = 0;
    for(int c = 1; c < n; ++c) {
        ans += d[n-c];
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //cout << setprecision(15) << fixed;
    int tests = 1;
    //cin >> tests;
    range(_, tests) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 7552
#include<stdio.h>
#include<math.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	ll N,T;
	scanf("%lld %lld",&N,&T);

	ll t1 = 0, t2 = 0, sum = T;
	FOR(i,0,N){
		scanf("%lld",&t2);
		sum += fmin(T,t2-t1);
		t1 = t2;
	}
	
	printf("%lld\n",sum);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=2e5+10;

int dp[1<<20],n,f[1<<20],vl[maxn],cnt[20];
vector <int> v;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		vl[u]^=c; vl[v]^=c;
	}
	for(int i=0;i<16;i++) cnt[i]=0;
	for(int i=0;i<n;i++){
	//	cout<<vl[i]<<endl; 
		cnt[vl[i]]++;
	}
	int ans=0;
	for(int i=1;i<16;i++){
		ans+=cnt[i]/2;
		if(cnt[i]%2==1){
		//	cout<<i<<endl;
			v.pb(i);
		}
	}
//	cout<<mask<<endl;
	for(int msk=0;msk<(1<<(int)v.size());msk++){
		int val=0;
		for(int i=0;i<v.size();i++){
			if(msk&(1<<i)){
				val^=v[i];
			}
		}
	//	if(val==0) cout<<msk<<endl;
		if(val==0) f[msk]=1;
	}
	for(int msk=0;msk<(1<<(int)v.size());msk++){
		int u=msk;
		while(u>0){
			if(f[u]){
				dp[msk]=max(dp[msk],dp[u^msk]+1);
			}
			u=(u-1)&msk;
		}
	}
	printf("%d\n",ans+(int)v.size()-dp[(1<<(int)v.size())-1]);
	return 0;
}


Measured memory_bytes: 2816
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define mp make_pair
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;

bool edge[55][55],flag[55];

void dfs(int node) {
	if (flag[node])return;

	flag[node] = true;
	for (int i = 0; i < 55; i++) {
		if (edge[node][i]) {
			dfs(i);
		}
	}
}

int main(){
	for (int i = 0; i < 55; i++)for (int j = 0; j < 55; j++)edge[i][j] = false;

	int n, m, ans=0;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		edge[a][b] = true; edge[b][a] = true;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int i = 0; i < 55; i++) flag[i] = false;
			if (edge[i][j]) {
				edge[i][j] = false; edge[j][i] = false;
				dfs(0);
				for (int i = 0; i < n; i++) {
					if (flag[i] == false) {
						ans++; break;
					}
				}
				edge[i][j] = true; edge[j][i] = true;
			}
		}
	}

	cout << ans/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    int n=0,f=0,k=0,c=0,d=0,l=0,i=0;
    cin >> n;
    string a[n],out;
    int b[n][26],e[26];
//配列bのリセット(デバッグ用)
    for(i = 0; i < n; i++){
        for(int f = 0; f < 26; f++){
            b[i][f] = 0;
            e[f]=50;
        }}
//S_nへの文字列の代入
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
//S_nからの文字情報の取得
    for(f=0;f<n;f++){
        c = a[f].size();
        for(int l=0;l<c;l++){
            d = (int)(a[f].at(l)) - (int)'a';
            b[f][d] += 1;
        }}
//S_nにおける各配列の最小の取得
    for (i=0; i<26; i++) {
        for (l=0;l<n;l++){
            if (e[i] >= b[l][i]) {
                e[i] = b[l][i];
            }}}
//結果文字列の作成
        for(l=0;l<26;l++){
            for (k=0;k<e[l];k++) {
                out.push_back(97+l);
            }
        }
//結果文字列の出力
   cout << out <<endl;
    return 0;
}


Measured memory_bytes: 256