akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std; 
int main() 
{long long a[3][3];
 for(long long i=0;i<3;i++)
 {for(long long j=0;j<3;j++)cin>>a[i][j];}
  long long n;cin>>n;
 vector<long long>v(n);
 set<long long>s;
 for(long long i=0;i<n;i++)
 {cin>>v[i];s.insert(v[i]);}
 for(long long i=0;i<3;i++)
 {
 if(s.find(a[i][0])!=s.end())a[i][0]=0;
   if(s.find(a[i][1])!=s.end())a[i][1]=0;
   if(s.find(a[i][2])!=s.end())a[i][2]=0;
 }
 if(a[0][0]==0 and a[0][1]==0 and a[0][2]==0)cout<<"Yes";
 else if(a[1][0]==0 and a[1][1]==0 and a[1][2]==0)cout<<"Yes";
 else if(a[2][0]==0 and a[2][1]==0 and a[2][2]==0)cout<<"Yes";
 else if(a[0][0]==0 and a[1][1]==0 and a[2][2]==0)cout<<"Yes";
 else if(a[0][2]==0 and a[1][1]==0 and a[2][0]==0)cout<<"Yes";
 else if(a[0][0]==0 and a[1][0]==0 and a[2][0]==0)cout<<"Yes";
 else if(a[0][1]==0 and a[1][1]==0 and a[2][1]==0)cout<<"Yes";
 else if(a[0][2]==0 and a[1][2]==0 and a[2][2]==0)cout<<"Yes";
 else cout<<"No";
 
 return 0; 
}


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

int a, b, c;

int main(){
  std::cin >> a >> b >> c;
  int ans = 0;

  for(int i = 1; i < b+1; ++i){
	int x = i*a;
	if(x%b == c){
	  ans++;
	  break;
	}
  }

  if(ans == 0){
	std::cout << "NO" << std::endl;
  }
  else{
	std::cout << "YES" << std::endl;
  }
}	


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

int main() {
	int n;
	cin >> n;
	long long int ar[n], res = 1;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
		if (ar[i] == 0) cout << "0\n", exit(0);
	}
	for (int i = 0; i < n; i++) {
		if (limit / res < ar[i]) cout << "-1\n", exit(0);
		res *= ar[i];
	}
	cout << res << endl;
}

Measured memory_bytes: 4396
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <algorithm>

using namespace std;

int pow10(int x) {
  if (x == 0) {
    return 1;
  }
  return 10 * pow10(x - 1);
}

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

  vector<int> cand(N);
  for (int i = 0; i < N; ++i) {
    cand[i] = -1;
  }

  int s, c;
  for (int i = 0; i < M; ++i) {
    cin >> s >> c;
    if (cand[s - 1] != -1 && cand[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (N > 1 && c == 0 && (s - 1) == 0) {
      cout << -1 << endl;
      return 0;
    }
    cand[s - 1] = c;
  }

  int result = 0;
  if (cand[0] == -1) {
    cand[0] = N > 1 ? 1 : 0;
  }
  for (int i = 1; i < N; ++i) {
    if (cand[i] == -1) {
      cand[i] = 0;
    }
  }

  int counter = 0;
  for (int i = N - 1; i >= 0; --i) {
    result += pow10(counter) * cand[i];
    ++counter;
  }
  cout << result << endl;
  return 0;
}



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

using namespace std;

const int INF = 0x0ffffff;

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int H, W, N;
    cin >> H >> W >> N;
    H = max(H, W);
    if (N % H == 0) cout << (N / H) << endl;
    else cout << ((N / H) + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
M = 10**6
p = [1]*M
p[0] = p[1] = 0
for i in range(2, 4*10**4):
    if p[i]:
        for j in range(i*i, M, i):
            p[j] = 0
C = [0]*M
for i in range(2, M):
    if p[i] and p[(i+1)//2]:
        C[i] = C[i-1] + 1
    else:
        C[i] = C[i-1]
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(C[r] - C[l-1])

Measured memory_bytes: 67960
#include <bits/stdc++.h>
using namespace std;
 
vector<int> anntena(5);
int k;
 
int main() {
  for (int i = 0; i < 5; i++) {
    cin >> anntena[i];
  }
  cin >> k;
  sort(anntena.begin(), anntena.end());
  string ans = (anntena[4] - anntena[0] > k) ? ":(" : "Yay!";
  cout << ans << endl;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

divs = make_divisors(N)

check = lambda x: x if N/x < x-1 else 1
divs_ok = list(map(check, divs))

print(sum(divs_ok) - len(divs_ok))


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


int main(){
    int n;
    cin >> n;
    double x[n];
    double y[n];
    double dst_sum = 0;
    double dst;
    int i,j;
    double ans;
    int count =0;
    
    rep(i,n){
        cin >> x[i];
        cin >> y[i];
    }
    
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            dst = sqrt(pow(x[i] - x[j],2.0)+pow(y[i] - y[j],2.0));
            //cout << dst << endl;
            dst_sum += dst;
            count++;
        }
        //cout << count << endl;
        //count = 0;
    }
    

    
    ans = dst_sum * 2 / n;
    
    cout << setprecision(20) << ans << endl;

    
    return 0;
}
    


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


int main()
{
    int n;
    cin>>n;
    vector<vector<int>> happy(n,vector<int>(3,0));
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
        cin>>happy[i][j];
  
    vector<vector<int>> dp(n+1,vector<int>(3,0));;
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=happy[i-1][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=happy[i-1][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=happy[i-1][2]+max(dp[i-1][1],dp[i-1][0]);
    }
   cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}

Measured memory_bytes: 14320
N = int(input())
A = list(map(int, input().split()))

bar = [0]
bar_tmp = 0
for Ai in A:
    bar_tmp += Ai
    bar.append(bar_tmp)

A_sum = sum(A)
targ = A_sum / 2

for i_r in range(N):
    if bar[i_r] > targ: break
i_l = i_r - 1

pen_l = abs(A_sum - 2 * bar[i_l])
pen_r = abs(2 * bar[i_r] - A_sum)

print(min(pen_l, pen_r))

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

char S[305];
int K;
int cache[305][305][305];

int LPS(int i, int j, int k) {
	if (~cache[i][j][k]) return cache[i][j][k];

	if (i == j) return cache[i][j][k] = 1;
	if (j - i == 1 && S[i] != S[j]) return cache[i][j][k] = k ? 2 : 1;
	if (j - i == 1 && S[i] == S[j]) return cache[i][j][k] = 2;
	if (S[i] != S[j]) {
		cache[i][j][k] = max(LPS(i+1, j, k), LPS(i, j-1, k));
		if (k) cache[i][j][k] = max(cache[i][j][k], LPS(i+1, j-1, k-1) + 2);
		return cache[i][j][k];
	}
	if (S[i] == S[j]) return cache[i][j][k] = LPS(i+1, j-1, k) + 2;
}

int main() {
	scanf("%s%d", S, &K);

	int len = strlen(S);

	for (int i = 0; i < 305; ++i) for (int j = 0; j < 305; ++j) for (int k = 0; k < 305; ++k) cache[i][j][k] = -1;

	printf("%d\n", LPS(0, len-1, K));
}

Measured memory_bytes: 111104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cfenv>
#include <cmath>

using namespace std;

int main() {
  int n,k,d;
  cin>>n>>k;
  int a;
  int count=0;
  map<int,int> s;
  for(int i=0;i<k;i++){
    cin>>d;
    for(int j=0;j<d;j++){
      cin>>a;
    decltype(s)::iterator it = s.find(a);
    if (it == s.end()){ // 見つからなかった
      s[a]=1;
      count++;
    }   
    }
  }
      cout<< n-count<<endl;

  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

char bo[500][500];
char r[500][500];
char b[500][500];

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

	int H, W;
	cin >> H >> W;

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			r[i][j] = b[i][j] = '.';
		}
	}
	for(int i = 0; i < H; i++) {
		r[i][0] = b[i][W - 1] = '#';
	}
	for(int i = 0; i < H; i++) {
		for(int j = 1; j < W - 1; j++) {
			if(i % 2) r[i][j] = '#';
			else b[i][j] = '#';
		}
	}


	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if(c == '#') {
				r[i][j] = b[i][j] = '#';
			}
		}
	}

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			cout << r[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			cout << b[i][j];
		}
		cout << endl;
	}
}

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

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

Measured memory_bytes: 3084
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) 
    cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    if((n+1)/2>=k){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int m,f,r;
    scanf("%d %d %d",&m,&f,&r);
    while(m  > -1 ||  f > -1 || r > -1){
        if(m < 0 || f < 0 || m + f < 30){
            printf("F\n");
        } else if(m + f < 50 && r < 50){
            printf("D\n");
        } else if(m + f < 65){
            printf("C\n");
        } else if(m + f < 80){
            printf("B\n");
        } else {
            printf("A\n");
        }
        scanf("%d %d %d",&m,&f,&r);
    }
    return 0;
}

Measured memory_bytes: 584
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int a, b;
    cin >> a >> b;

    int ans = 0;
    int sum = 1;
    while (sum < b) {
        ans++;
        sum += a - 1;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
N, K = map(int, input().split())
P = list(map(lambda s: int(s) - 1, input().split()))
C = list(map(int, input().split()))

ans = -1_000_000_000
for i in range(N):
    S = [C[i]]
    p = P[i]
    while p != i:
        S.append(C[p])
        p = P[p]
    s = sum(S)
    n = len(S)
    acc = 0
    for i in range(min(n, K + 2)):
        acc += S[i]
        a = acc
        if s > 0:
            a += s * ((K - (i + 1)) // n)
        ans = max(a, ans)

print(ans)


Measured memory_bytes: 80864
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a==0)return b;
  else if(b==0)return a;
  else if(a>b)return gcd(a%b,b);
  else return gcd(a,b%a);
}

int main(void){
  int a,b,k;
  cin>>a>>b>>k;
  int g = gcd(a,b);
  int c=0;
  for(int i=g;i>=1;i--){
    if(g%i==0)c++;
    if(c==k){
      c++;
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define A first
#define B second
using namespace std;

typedef long long ll;
typedef pair <int, int> pi;
constexpr double PI = atan(1) * 4;
constexpr int inf = 0x3f3f3f3f;
inline int LSB(int i) {return (i & -i);}

int n, h[100005], k;
ll c[100005];

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

    cin >> n >> k;
    for(int i = 0; i < n; i++){
    	cin >> h[i];
    	c[i] = 1e18 + 5;
    }
    c[0] = 0;
    for(int i = 0; i < n; i++){
    	for(int j = i + 1; j <= min(i + k, n - 1); j++){
            c[j] = min(c[j], c[i] + abs(h[j] - h[i]));
        }
    }
    cout << c[n-1] << endl;
    return 0;
}



Measured memory_bytes: 4764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int A, B;
    cin >> A >> B;
    cout << ((A * B) % 2 == 1 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;


int main() {
    int n;
    cin >> n;
    
    set<char> a;
    
    for (int i = 0; i < n; ++i)
    {
        char tmp;
        cin >> tmp;
        a.insert(tmp);
    }
    
    if (a.size() == 3)
    {
        cout << "Three" << endl;
    }
    else
    {
        cout << "Four" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX1 2000
#define MAX2 2000

int a[MAX1],n,s;

int solve(int,int);
main(){
  int q;
  int i,j;
  int m[MAX2];

  scanf("%d",&n);

  for(i=0; i<n; i++){

    scanf("%d",&a[i]);

  }

  scanf("%d",&q);

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

  for(i=0; i<q; i++){
    s = m[i];
    if(1 == solve(0,m[i]))printf("yes\n");
    else printf("no\n");
  }

return 0;
}
int solve(int f,int t){

  if(t == 0) return 1;

  if(f == n) return 0;

  if(t == a[f]) return 1;

  if(solve(f+1,t-a[f]) == 1)return 1;

  if(solve(f+1,t) == 1)return 1;
}

Measured memory_bytes: 592
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  if(s[a] == '-') {
    bool b = true;
    for(int i = 0; i < a; i++) if(s[i] < '0' || s[i] > '9') b = false;
    for(int i = 0; i < b; i++) if(s[a + 1 + i] < '0' || s[a + 1 + i] > '9') b = false;
    if(b) {
      cout << "Yes" << endl;
      return 0;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//    >File Name: 061A.cpp
//    > Author: Webwei

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

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(" ").map { it.toDouble() }
    val d = Math.sqrt( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) )
    println("%5f".format(d))
}


Measured memory_bytes: 33956
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d=0;
    cin>>a>>b>>c;
    if(a > 2*b){
        if(c%500==0)  d=b*(c/500);
        else d=b*(c/500)+b;
    }
    else if(a < 2*b && (a>b || a==b)){
        if(c%1000==0) d=a*(c/1000);
        else if(0<c%1000 && c%1000<=500) d=a*(c/1000)+b;
        else  d=a*(c/1000)+a;
        
    }
    else if(a == 2*b){
         if(c%500==0)  d=b*(c/500);
        else d=b*(c/500)+b;
    }
    else if(a < b){
        if(c%1000==0) d=c/1000*a;
        else d=(c/1000)+a;
    }
    else if(a==b && b==c){
        d=a;
        
    }
    
    cout<<d<<endl;


   return 0;
}


Measured memory_bytes: 3116
def diff2next10(num)
  num % 10 != 0 ? num % 10 : 10
end

dishes = 5.times.map { gets.to_i }
last = dishes.min { |a, b| diff2next10(a) <=> diff2next10(b) }

ans = 0
last_ordered = false

dishes.each do |d|
  if d == last && !last_ordered
    ans += d
    last_ordered = true
  else
    ans += d + (10 - diff2next10(d)).abs
  end
end

puts ans


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int h,w;
    cin >> h >> w;
    vs s(h);
    rp(i,h){
        cin >> s.at(i);
    }
    char A[h][w],B[h][w];
    rp(i,h){
        rp(j,w){
            A[i][j]=s.at(i).at(j);
            B[i][j]=s.at(i).at(j);
        }
    }
    
    rp(i,h){
        int cnt=0;
        rp(j,w){
            if(A[i][j]=='.'){
                cnt++;
            }
        }
        if(cnt==w){
            rp(j,w){
                B[i][j]='0';
            }
        }
    }
    
    rp(i,w){
        int cnt=0;
        rp(j,h){
            if(A[j][i]=='.'){
                cnt++;
            }
        }
        if(cnt==h){
            rp(j,h){
                B[j][i]='0';
            }
        }
    }
    
    rp(i,h){
        int cnt=0;
        rp(j,w){
            if(B[i][j]!='0'){
                cout << B[i][j];
                cnt++;
            }
        }
        if(cnt){
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=5e5+50,P=998244353;

int mul(int a,int b) { return 1ll*a*b%P; }
int add(int a,int b) { a+=b; return a>=P?a-P:a; }
int sub(int a,int b) { a-=b; return a<0?a+P:a; }

int n,m,ans,fac[N],inv[N];

int C(int n,int m){
	if(n<0||m>n)return 0;
	return mul(fac[n],mul(inv[m],inv[n-m]));
}

int main(int argc,char *argv[]){
	cin>>n>>m;
	fac[0]=1; rep(i,1,m)fac[i]=mul(fac[i-1],i);
	inv[1]=1; rep(i,2,m)inv[i]=mul(P-P/i,inv[P%i]);
	inv[0]=1; rep(i,1,m)inv[i]=mul(inv[i],inv[i-1]);
	rep(R,n,m){
		ans=add(ans,C(m,R));
		ans=sub(ans,C(m,R+R-(n-1)));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int V,r[200001]={0},f[200001]={0},z=0;
vector<int> G[200001],ans;
int dfs(int x){
    if(r[x]&&!f[x]) z=1;
    if(z||r[x]) return 0;
    r[x]=1;
    for(auto i:G[x]) dfs(i);
    ans.push_back(x);
    f[x]=1;
}
void tsort(){
    rep(i,V) dfs(i);
    reverse(all(ans));
}
int dp[200001]={0};
int longpass(){
    for(auto i:ans)for(auto j:G[i]) dp[j]=max(dp[j],dp[i]+1);
    return *max_element(dp,dp+V);
}
int main(){
    int n,m,x,y;
    cin>>n>>m;
    V=n;
    rep(i,m) cin>>x>>y,G[x-1].push_back(y-1);
    tsort();
    cout<<longpass();
}

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

#define MAX_N 25
#define NIL -1
bool is_nil(int i) {
  return i == NIL;
}

struct Node {
  int parent;
  int left;
  int right;
};
Node N[MAX_N];

void preorder(int p) {
  printf(" %d", p);
  if(!is_nil(N[p].left))
    preorder(N[p].left);
  if(!is_nil(N[p].right))
    preorder(N[p].right);
}

void inorder(int p) {
  if(!is_nil(N[p].left))
    inorder(N[p].left);
  printf(" %d", p);
  if(!is_nil(N[p].right))
    inorder(N[p].right);
}

void postorder(int p) {
  if(!is_nil(N[p].left))
    postorder(N[p].left);
  if(!is_nil(N[p].right))
    postorder(N[p].right);
  printf(" %d", p);
}

int main() {
  for(int i=0; i<MAX_N; i++) {
    N[i].parent = -1;
    N[i].left = -1;
    N[i].right = -1;
  }

  int n;
  cin >> n;
  for(int i=0; i<n; i++) {
    int id, left, right;
    cin >> id >> left >> right;

    N[id].left = left;
    N[id].right = right;
    if(!is_nil(left)) {
      N[left].parent = id;
    }
    if(!is_nil(right)) {
      N[right].parent = id;
    }
  }

  int root;
  for(int i=0; i<n; i++) {
    if(is_nil(N[i].parent)) {
      root = i;
    }
  }

  cout << "Preorder" << endl;
  preorder(root);
  cout << endl;

  cout << "Inorder" << endl;
  inorder(root);
  cout << endl;

  cout << "Postorder" << endl;
  postorder(root);
  cout << endl;

  return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)

/////////////////////////////////////////////////////////

void Main(){
  const ll large = 3000;
  ll N, A; cin >> N >> A;
  vector<ll> x(N);
  rep(i, 0, N) cin >> x[i];
  vector<ll> plus, minus, equal;
  rep(i, 0, N){
    if(x[i] > A) plus.push_back(x[i] - A);
    else if(x[i] < A) minus.push_back(A - x[i]);
    else equal.push_back(0);
  }
  
  ll N_plus = plus.size();
  vector<vector<ll>> dp_plus(large, vector<ll>(N_plus + 1, 0));
  dp_plus[0][0] = 1;
  rep(i, 0, large){
    rep(j, 0, N_plus + 1){
      if(j > 0){
        dp_plus[i][j] += dp_plus[i][j - 1]; //do not use j-th card
        if(i - plus[j - 1] >= 0) dp_plus[i][j] += dp_plus[i - plus[j - 1]][j - 1];//use j-th card
      }
    }
  }

  ll N_minus = minus.size();
  vector<vector<ll>> dp_minus(large, vector<ll>(N_minus + 1, 0));
  dp_minus[0][0] = 1;
  rep(i, 0, large){
    rep(j, 0, N_minus + 1){
      if(j > 0){
        dp_minus[i][j] += dp_minus[i][j - 1]; //do not use j-th card
        if(i - minus[j - 1] >= 0) dp_minus[i][j] += dp_minus[i - minus[j - 1]][j - 1];//use j-th card
      }
    }
  }
  
  ll res = 0;
  rep(i, 0, large){
    res += dp_plus[i][N_plus] * dp_minus[i][N_minus];
  }
  res = res * pow(2, equal.size()) - 1;
  
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(){
    int n,a[10];
    cin>>n;
    int x=1,y=1;
    for (int i=0; i<n; i++){
        cin>>a[i];
        x*=3;
        if(a[i]%2==0)y*=2;
    }
    cout<<x-y<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
queNum = int(input())


reverse_cnt = 0
begin_lst = []
end_lst = []
for _ in range(queNum):
    query = input()

    if query == '1':
        reverse_cnt += 1
        begin_lst, end_lst = end_lst, begin_lst
    else:
        num, fi, ci = query.split()
        if fi == '1':
            begin_lst.append(ci)
        else:
            end_lst.append(ci)
    
if reverse_cnt % 2 == 0:
    pass
else:
    s = s[::-1]

print(''.join(reversed(begin_lst)) + s + ''.join(end_lst))

Measured memory_bytes: 6264
#include "bits/stdc++.h"
using namespace std;
int main(){
    int K, even, odd;
    cin >> K;
    even = K / 2, odd = K / 2;
    if(K % 2 == 1)
    odd++;
    int ans = even * odd;
    cout << ans << endl;
    return 0; 
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  LL ans;
  int N;
  cin >> N;

  ans = N * 800 - (N / 15) * 200;

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        # (actual_value, expected_value)
        self.assertEqual(True, False)


def solve():
    s, t, a, b, u = read()
    result = think(s, t, a, b, u)
    write(result)


def read():
    s, t = read_line().split(" ")
    a, b = read_int(2)
    u = read_line()
    return s, t, a, b, u


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s, t, a, b, u):
    if s == u:
        return a - 1, b
    else:
        return a, b - 1


def write(result):
    print(result[0], result[1])


if __name__ == '__main__':
    # unittest.main()
    solve()


Measured memory_bytes: 51312
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
    speed_up;
    int w, h, n, a;
    cin>>w>>h>>n;
    int lx = 0, rx = w, uy = h, dy = 0, x, y;
    while(n--)
    {
        cin>>x>>y>>a;
        if(a == 1) lx = max(lx, x);
        if(a == 2) rx = min(rx, x);
        if(a == 3) dy = max(dy, y);
        if(a == 4) uy = min(uy, y);
    }

    int b, c;
    b = max(0, rx - lx);
    c = max(0, uy - dy);

    cout<<b*c<<endl;


    return 0;

}


Measured memory_bytes: 3652
H, W, N = map(int, raw_input().split())
dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
board = {}

for i in xrange(N):
    a, b = map(int, raw_input().split())
    for j in xrange(9):
        x, y = a+dx[j], b+dy[j]
        if x <= 1 or x >= H or y <= 1 or y >= W:
            continue
        if (x, y) in board:
            board[(x, y)] += 1
        else:
            board[(x, y)] = 1
ans = [0] * 10
for v in board.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for a in ans:
    print a


Measured memory_bytes: 154108
#include <stdio.h>
int main(void)
{
	int  count[4][3][10] = {}; 
	int  n, b, f, r, v, i, a, c, d ,e , j, k;
	for(e=0;e<4; e++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				count[e][j][k]  = 0;
			}
		}
	}


	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		count[b-1][f-1][r-1] += v;
	}
	

	for(a=0;a<4;a++){
		for(d=0;d<3;d++){
			for(c=0;c<10;c++){
				printf(" %d", count[a][d][c]); 
			}
			printf("\n");
		}
		if(a == 3) break;
		printf("####################\n");
	}


return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define M(x,y) ((x)>(y)?(x):(y))
#define m(x,y) ((x)<(y)?(x):(y))

int main() {
	int n, ans=0, count[200010];
	char s[200010][11];
	scanf("%d\n", &n);
	rep(i, n) scanf("%s", &s[i]);
	qsort(s, n, 11, strcmp);
	count[0] = 1;
	Rep(i,1,n) {
		if (strcmp(s[i - 1], s[i]) == 0) {
			count[i] = count[i - 1] + 1;
		}
		else {
			count[i] = 1;
		}
	}
	rep(i, n) { if (count[i] == 1)ans++; }
	printf("%d", ans);
}

Measured memory_bytes: 5740
#include <iostream>

using namespace std;

int main()
{
    int n,a[201],i,chk=0,sum=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    while(chk!=1){
    for(i=0;i<n;i++){
        if(a[i]%2==0){
            a[i]=a[i]/2;
        }
        else if(a[i]%2!=0){
            chk=1;
            break;
        }
    }
    if(chk==0) sum+=1;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3568
while True:
  a = int(input())
  if a == 0:
    break
  n = int(1)
  c = int(0)
  while True:
    if a//(5**n) == 0:
      break
    else:
      n += 1
  #print(n)
  for b in range(n):
    c += (a//(5**(b+1)))
  print(c)



Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const ll N_MAX = 1000001;

ll fac[1000001];
ll dp[1000001];

void init(){
    fac[0] = 1;
    for(int i = 1; i <= N_MAX; i++) {
        fac[i] = fac[i-1]*i;
        fac[i] %= MOD;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    ll N, H, D;
    cin >> N >> H >> D;
    ll sum = 0;
    for(int i = 1; i <= N; i++){
        sum += fac[i];
        sum %= MOD;
    }
    dp[0] = 1;
    ll tmp = 0;
    for(int i = 1; i <= H; i++){
        if(i-D-1 >= 0) {
            tmp -= dp[i-D-1];
            tmp += MOD;
            tmp %= MOD;
        }
        tmp += dp[i-1];
        tmp %= MOD;
        if(i != H) dp[i] = (tmp*sum)%MOD;
        else dp[i] = tmp;
    }
    ll ans = (dp[H]*fac[N])%MOD;
    cout << ans << endl;
}

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

mod = 10**9 + 7

if N < 2:
    print(0)
else:
    #9がない
    no9 = 1
    no09 = 1
    tot = 1
    for i in range(N):
        no9 *= 9
        no9 %= mod
        no09 *= 8
        no09 %= mod
        tot *= 10
        tot %= mod
    print((tot - 2 * no9 + no09) % mod)


Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a == b && a == c)
			System.out.println(1);
		else if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b))
			System.out.println(2);
		else
			System.out.println(3);
		sc.close();
	}
}

Measured memory_bytes: 21840
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
long long modinv(long long a,long long mod)
{
  return modpow(a,mod-2,mod);
}
vector<long long> fact,inv;
long long mod=1e9+7;
void init(int n){
  fact.resize(n);
  inv.resize(n);
  fact[0]=1LL;
  rep(i,n-1){
    fact[i+1]=(long long)fact[i]*(i+1)%mod;
  }
  inv[n-1]=modinv(fact[n-1],mod);
  rrep(i,n-1){
    inv[i]=(long long)inv[i+1]*(i+1)%mod;
  }
}
long long comb(ll a,ll b){
  return fact[a]*inv[b]%mod*inv[a-b]%mod;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,y;cin>>x>>y;
  if((x+y)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  ll a,b;
  a=y-(x+y)/3;
  b=x-(x+y)/3;
//  cout<<a<<" "<<b<<endl;
  if(a<0||b<0){
    cout<<0<<endl;
    return 0;
  }
  init(2e6);
  cout<<comb(a+b,a)<<endl;


  return 0;

}


Measured memory_bytes: 31616
from itertools import product

def offset(a, b):
    result = 0
    if b == 0: return 0
    for i in range(b+1):
        if (a >> i) & 1:
            result |= (1 << b) >> i
    return result

H, W = map(int, input().split())
diff = [list(map(int, input().split())) for _ in range(H)]
M = 80
for i in range(H):
    B = list(map(int, input().split()))
    for j in range(W):
        diff[i][j] = abs(diff[i][j] - B[j])
dp = [[0]*W for _ in range(H)]
dp[0][0] = 1 << diff[0][0]
for i, j in product(range(H), range(W)):
    if (i, j) == (H-1, W-1): break
    if i+1 < H:
        k = diff[i+1][j]
        dp[i+1][j] |= (dp[i][j] >> k) | (dp[i][j] << k) | (offset(dp[i][j], k))
    if j+1 < W:
        k = diff[i][j+1]
        dp[i][j+1] |= (dp[i][j] >> k) | (dp[i][j] << k) | (offset(dp[i][j], k))
ans = dp[H-1][W-1]
print((ans & -ans).bit_length() - 1)

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans=0;
  int cnt=0;
  rep(i,n){
    if(s[i]=='I'){cnt++;}else{cnt--;}
    ans = max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s;
  cin >> s;
  int res = 1 << 30;
  for(char c = 'a';c <= 'z';c++){
    string t = s;
    int cnt = 0;
    while(t != string(t.length(),c)){
      string u = "";
      cnt++;
      for(int i = 0;i < t.size()-1;i++){
        if(t[i] == c || t[i+1] == c)u += c;
        else u += t[i];
      }
      t = u;
    }
    res = min(res,cnt);
  }
  cout << res << endl;

  





  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<vector<int>> G;
vector<ll> A;
vector<int> ans;
vector<ll> lis;
deque<pair<int, ll>> q;
void dfs(int tmp, int par) {
  auto it = lower_bound(all(lis), A[tmp]);
  q.emplace_back((int)(it-lis.begin()), *it);
  *it = A[tmp];
  ans[tmp] = lower_bound(all(lis), longinf) - lis.begin();
  for(int ne: G[tmp]) {
    if(ne != par) dfs(ne, tmp);
  }
  auto b = q.back();
  lis[b.first] = b.second;
  q.pop_back();
}
int main() {
  int N;
  cin >> N;
  A = vector<ll>(N);
  ans = vector<int>(N);
  rep(i, N) cin >> A[i];
  G = vector<vector<int>>(N);
  rep(i, N-1) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  lis = vector<ll>(N, longinf);
  dfs(0, -1);
  rep(i, N) cout << ans[i] << endl;
  return 0;
}


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

int main() {
    int K,A,B;
    cin >> K >> A >> B;

    bool flag = false;

    for(int i=1;i<=1000;i++){
        if((A<=K*i)&&(K*i<=B)){
            flag = true;
        }
    }

    if(flag) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double A = scan.nextInt();
		double B = scan.nextInt();
		double H = scan.nextInt();
		double M = scan.nextInt();

		double hour = 2* Math.PI *((H * 60 + M) / (12 * 60));
		double min = 2* Math.PI *(M / 60);
		double theta = Math.abs(hour - min);
		
		double length = Math.sqrt(B*B + A*A - 2*A*B*Math.cos(theta));
		System.out.println(length);
		scan.close();
	}

}


Measured memory_bytes: 35980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[13][2][2][2];
int digit[13];
int dfs(int len,bool if3,bool if5,bool if7,bool limit,bool zero){
    if(len==0)
        return if3&&if5&&if7;
    if(!limit&&!zero&&dp[len][if3][if5][if7])
        return dp[len][if3][if5][if7];
    int up = limit?digit[len]:9;
    ll cnt = 0;
    if(zero)
        cnt+=dfs(len-1,if3,if5,if7,limit&&0==up,zero);
    for(int i=1;i<=up;i++){
        if(i!=3&&i!=5&&i!=7)
            continue;
        cnt+=dfs(len-1,if3||i==3,if5||i==5,if7||i==7,limit&&i==up,zero&&i==0);
    }
    if(!limit&&!zero)
        dp[len][if3][if5][if7]=cnt;
    return cnt;
}

int solve(int x){
    int k = 0;
    while (x){
        k++;
        digit[k]=x%10;
        x/=10;
    }
    return dfs(k,0,0,0,1,1);
}
int main(){
    ios::sync_with_stdio(false);
    int n;cin>>n;cout<<solve(n)<<endl;
}

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

namespace Find_a_Word_2
{
    class Program
    {
        static int ans = 0;
        static void Main(string[] args)
        {
            String str = Console.ReadLine();
            str = str.ToLower();
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                if (input[0] == "END_OF_TEXT") break;

                for (int i = 0; i < input.Length; ++i)
                {
                    input[i] = input[i].ToLower();
                    if (input[i] == str) ++ans;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 9036
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: K-City
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  cin >> n >> m;
  printf("%d\n", (n - 1) * (m - 1));
  return 0;
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n,a,b = inp
if((a-b)%2==0)
  puts (a-b).abs/2
else
  lg = (small(a,b) -1)
  buf1 = lg + r_up((a-lg-1),2)+r_up((b-lg-1),2)
  rg = (small(n-a,n-b))
  buf2 = rg + r_up(((n-a)-rg),2)+r_up(((n-b)-rg),2)
  puts [buf1,buf2].min
end

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

#define ll long long int

struct point
{
    ll x,y,h;
};

ll calculate_applitute(ll h,ll x,ll y,ll cx,ll cy)
{
    ll h1=h-abs(x-cx)-abs(y-cy);
    //cout<<"h1="<<h1<<endl;
    ll res= max(h1,0ll);
    //cout<<"res="<<res<<endl;
    return res;
}

ll solve(ll cx,ll cy,vector<point>&points)
{
    ll i,j,first,last,mid,f=0;
    first=1;
    last=1e15;
    while(first<=last)
    {
        //cout<<"first="<<first<<" last="<<last;
        if(f)
        {
            break;
        }
        if(first==last)
        {
            f=1;
        }
        mid=(first+last)/2;
        //cout<<" mid="<<mid<<endl;
        int right=1;
        for(i=0;i<points.size();i++)
        {
            ll cur=calculate_applitute(mid,points[i].x,points[i].y,cx,cy);
            //cout<<"cur="<<cur<<endl;
            if(cur!=points[i].h)
            {
                right=0;
                if(cur<points[i].h)
                {
                    //cout<<"for "<<i<<"th point cur h="<<cur<<" correct_h="<<points[i].h<<endl;
                    first=mid+1;
                }
                else
                    last=mid-1;
                break;
            }
        }
        if(right)
        {
            return mid;
        }
    }
    return 0;

}

int main()
{
    ll n,i,j,x,y,h,cx,cy,ch;
    scanf("%lld",&n);
    vector<point>points;
    for(i=1;i<=n;i++)
    {
        point tmp;
        scanf("%lld %lld %lld",&x,&y,&h);
        tmp.x=x;
        tmp.y=y;
        tmp.h=h;
        points.push_back(tmp);
    }
    int done;
    for(i=0;i<=100;i++)
    {
        for(j=0;j<=100;j++)
        {
            done=0;
            ll cur;
            if(cur=solve(i,j,points))
            {
                cx=i;
                cy=j;
                ch=cur;
                done=1;
                break;
            }
        }
        if(done)
        {
            break;
        }
    }
    printf("%lld %lld %lld\n",cx,cy,ch);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int N;
	cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> ans(N);
    rep(i, N) ans[A[i]-1] = i+1;
    rep(i, N) cout << ans[i] << ' ';
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int par[200010], ran[200010];

void init() {
	for (int i = 0; i <= 200001; i++) {
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (ran[x] < ran[y]) par[x] = y;
	else {
		if (ran[x] == ran[y])ran[x]++;
		par[y] = x;
	}
}

int n;
pair<long long, long long> cnt[200010];
long long ans;

signed main() {
	cin >> n;
	init();
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		unite(x, 100001 + y);
	}
	for (int i = 0; i <= 100000; i++)cnt[find(i)].first++;
	for (int i = 100001; i <= 200001; i++)cnt[find(i)].second++;
	for (int i = 0; i <= 200001; i++) {
		ans += cnt[i].first*cnt[i].second;
	}
	cout << ans - n << endl;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int sum = 0;
    int[] array = new int[n];
    boolean flag = false;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
      sum += array[i];
    }

    int reg = (sum+(4*m-1))/(4*m);

    int count = 0;

    for(int i=0; i<n; i++){
      if(array[i] >= reg){
        count += 1;
        //System.out.println("number:"+i);
      }
      if(count >= m){
        flag = true;
        break;
      }

    }


    if(flag==true){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
      //System.out.println(count);

  }
}

Measured memory_bytes: 23252
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - A x B &#43; C
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

/* global variables */

int cs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 1; i < n; i++)
    for (int j = i; j < n; j += i) cs[j]++;

  int sum = 0;
  for (int i = 1; i < n; i++) sum += cs[i];

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


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ret = 0;
  for(int i = 2; i < N; i++) {
    if(S[i - 2] == 'A' && S[i - 1] == 'B' && S[i] == 'C') ++ret;
  }
  cout << ret << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
struct Y{
int hx,hy,rx,ry,t;
};
int c[51][51][51][51],mp[52][52];
int main(){
int w,h,i,j,a[2]={1,-1},b[2];
Y e;
while(1){
queue<Y> q;
	cin>>w>>h;
	if(w==0&&h==0)break;
	cin>>e.hx>>e.hy>>e.rx>>e.ry;
	e.t=0;
	q.push(e);
	memset(c,0,sizeof(c));
	memset(mp,1,sizeof(mp));
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>mp[i][j];
		}
	}
	while(!q.empty()){
		e=q.front();
		q.pop();
		c[e.hy][e.hx][e.ry][e.rx]=1;
		if(e.t>=100||e.hx==e.rx&&e.hy==e.ry)break;
		e.t++;
		for(i=0;i<2;i++){
			if(mp[e.hy+a[i]][e.hx]==0&&c[e.hy+a[i]][e.hx][e.ry-a[i]][e.rx]==0&&mp[e.ry-a[i]][e.rx]==0||mp[e.ry-a[i]][e.rx]==0&&c[e.hy][e.hx][e.ry-a[i]][e.rx]==0&&mp[e.hy+a[i]][e.hx]!=0||mp[e.hy+a[i]][e.hx]==0&&mp[e.ry-a[i]][e.rx]!=0&&c[e.hy+a[i]][e.hx][e.ry][e.rx]==0){
				b[0]=0;																										
				b[1]=0;																																		
				if(mp[e.hy+a[i]][e.hx]==0){																											
					e.hy+=a[i];																																			
					b[0]=1;																																					
				}																																													
				if(mp[e.ry-a[i]][e.rx]==0){																																										
					e.ry-=a[i];																																		
					b[1]=1;																																																														
				}		
				c[e.hy][e.hx][e.ry][e.rx]=1;																																																																																																																
				q.push(e);																											
				if(b[0]==1)e.hy-=a[i];																														
				if(b[1]==1)e.ry+=a[i];																											
			}																																																												
			if(mp[e.hy][e.hx+a[i]]==0&&mp[e.ry][e.rx-a[i]]==0&&c[e.hy][e.hx+a[i]][e.ry][e.rx-a[i]]==0||mp[e.hy][e.hx+a[i]]==0&&c[e.hy][e.hx+a[i]][e.ry][e.rx]==0&&mp[e.ry][e.rx-a[i]]!=0||mp[e.ry][e.rx-a[i]]==0&&mp[e.hy][e.hx+a[i]]!=0&&c[e.hy][e.hx][e.ry][e.rx-a[i]]==0){
				b[0]=0;
				b[1]=0;
				if(mp[e.hy][e.hx+a[i]]==0){
					e.hx+=a[i];
					b[0]=1;
				}
				if(mp[e.ry][e.rx-a[i]]==0){
					e.rx-=a[i];
					b[1]=1;
				}
				c[e.hy][e.hx][e.ry][e.rx]=1;
				q.push(e);
				if(b[0]==1)e.hx-=a[i];
				if(b[1]==1)e.rx+=a[i];
			}
		}
		e.t--;
	}
	if(e.hy==e.ry&&e.hx==e.rx)cout<<e.t<<endl;
	else cout<<"NA"<<endl;
}
return 0;
}

Measured memory_bytes: 29620