akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

#define N 50
#define M 50

int good(char *s, char *t, int m, int i) {
	int j;

	for (j = i; j < i + m; j++)
		if (s[j] != '?' && s[j] != t[j - i])
			return 0;
	return 1;
}

int main() {
	static char s[N + 1], t[M + 1];
	int n, m, i, j;

	scanf("%s%s", s, t);
	n = strlen(s);
	m = strlen(t);
	for (i = n - m; i >= 0; i--)
		if (good(s, t, m, i)) {
			for (j = 0; j < n; j++)
				if (s[j] == '?')
					s[j] = j >= i && j < i + m ? t[j - i] : 'a';
			printf("%s\n", s);
			return 0;
		}
	printf("UNRESTORABLE\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
using namespace std;
#pragma warning (disable: 4996)

int n, m, a[500009], b[500009]; vector<int>x[500009], I; bool used[500009];

int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
		x[a[i]].push_back(b[i]);
		x[b[i]].push_back(a[i]);
	}
	int cx = 1; I.push_back(1); used[1] = true;
	while (true) {
		bool flag = false;
		for (int i = 0; i < x[cx].size(); i++) {
			if (used[x[cx][i]] == false) {
				flag = true;
				I.push_back(x[cx][i]);
				used[x[cx][i]] = true; cx = x[cx][i]; break;
			}
		}
		if (flag == false)break;
	}
	reverse(I.begin(), I.end()); cx = 1;
	while (true) {
		bool flag = false;
		for (int i = 0; i < x[cx].size(); i++) {
			if (used[x[cx][i]] == false) {
				flag = true;
				I.push_back(x[cx][i]);
				used[x[cx][i]] = true; cx = x[cx][i]; break;
			}
		}
		if (flag == false)break;
	}
	cout << I.size() << endl;
	for (int i = 0; i < I.size(); i++) {
		if (i)cout << " "; cout << I[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 18680
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

long long int gcd(long long int num1,long long int num2){
    if(num1 < num2){
        int tmp = num1;
        num1 = num2;
        num2 = tmp;
    }

    int r = num1 % num2;
    while(r != 0){
        num1 = num2;
        num2 = r;
        r = num1 % num2;
    }

    return num2;
}

int main(){
    int k;
    long long int sum = 0;
    scanf("%d",&k);
    for(int i = 1;i <= k;i++){
        for(int j = 1;j <= k;j++){
            int r1 = gcd(i,j);
            for(int l = 1;l <= k;l++){
                sum += gcd(r1,l);
            }
        }
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1708
N = int(input())
A = [int(i) for i in input().split(" ")]

k = 0
for i in range(1,N):
    k = A[i] - k

ans = (A[0] - k) // 2
ans_l = [None]*N

ans_l[1] = str(ans*2)
for i in range(1,N):
    ans = A[i] - ans
    if i==N-1:
        ans_l[0] = str(ans*2)
    else:
        ans_l[i+1] = str(ans*2)
print(" ".join(ans_l))

Measured memory_bytes: 17224
#include<iostream>
using namespace std;
int main(){
  unsigned long long x;cin>>x;
  unsigned long long c=100;
  int i=0;
  while(1){
    i++;
    c*=1.01;
    if(c>=x){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}  


Measured memory_bytes: 3636
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    x = 1
    for tmp in a:
        x *= tmp
        if x > 1000000000000000000:
            print(-1)
            return
    print(x)

solve()

Measured memory_bytes: 21740
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
 
#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 MOD 1000000007
#define INF 1000000001
 
using namespace std;
 
 
 
int main(void) {
   int n;
   int a;
   int ki=0;
   int gu4=0;
   
   cin>>n;
   FOR(i,1,n){
     cin>>a;
     if(a%4==0){
       gu4++;
     }else if(a%2==1){
         ki++;
     }
   }
   if(gu4>=ki){
     cout<<"Yes"<<endl;
   }else if(n%2==1&&ki+gu4==n){
     if(gu4+1>=ki){
       cout<<"Yes"<<endl;
     }else{
       cout<<"No"<<endl;
     }
   }else{
     cout<<"No"<<endl;
   }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string a;
	int b=0;
	cin >> a;
	//cin >> c;
	//cin >> d;
	for (int i = 0; i < 3; i++)if (a[i]=='1')b++;
	cout << b << endl;
}

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

int main(){
  int N, A, B, C, D;
  string S;
  cin >> N >> A >> B >> C >> D >> S;

  S = "#" + S + "#";
  auto can_reach = [&](int start, int end) {
	for (int i = start; i + 1 <= end; i++) {
	  if (S[i] == '#' && S[i + 1] == '#') return false;
        }
        return true;
  };
 
  if (!can_reach(A, C) || !can_reach(B, D)) {
    cout << "No" << endl;
    return 0;
  }
 
  if (C > D) {
    bool snuke_can_over = false;
    for (int i = B; i <= D; i++) {
      if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
	snuke_can_over = true;
      }
    }
    if (!snuke_can_over) {
      cout << "No" << endl;
      return 0;
    }
  }
 
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node{
	int a,b;
}a[100001];
int n,m,cnt,t;
ll ans;
priority_queue<int> q;
bool cmp(node a,node b)
{
	return a.a<b.a;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for (int i=0;i<n;++i) cin>>a[i].a>>a[i].b;
	sort(a,a+n,cmp);
	for (int i=1;i<=m;++i)
	{
		while (t<n && a[t].a<=i) q.push(a[t].b),++t;
		if (!q.empty()) ans+=q.top(),q.pop();
	}
	cout<<ans;
	return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/c.in", "r", stdin);
//  freopen("../IO/c.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<int> a(n);
  for (int &i : a) in >> i;
  vector<int> b = a;
  sort(a.begin(), a.end());
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int id = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    if (i % 2 == 0 && id % 2 == 1) {
      cnt++;
    }
  }
  out << cnt << '\n';
}

Measured memory_bytes: 3972
n=gets.to_i
ws=gets.split.map(&:to_i)
s1=ws[0]
s2=ws[1..-1].inject(:+)
diff=(s2-s1).abs
1.upto(n-2) do |i|
  s1+=ws[i]
  s2-=ws[i]
  diff=[diff,(s2-s1).abs].min
end
puts diff


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#define INF -1
using namespace std;
int absint(int a)
{
	return max(a , - a);
}
int main()
{
	static long long int N, W, w[101], v[101], dp[101][100010], i, j, k,ans=0;
	cin >> N >> W;
	for (i = 1; i <= N; i++)
	{
		cin >> w[i] >> v[i];
		for (j = 1; j <= W; j++)
		{
			dp[i][j] = INF;
		}
	}
	dp[1][0] = 0, dp[1][w[1]] = v[1];
	for (i = 2; i <= N; i++)
	{
		for (j = 0; j <= W; j++)
		{
			//if (dp[i-1][j] != INF)
			{
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
				if (j + w[i]<=W)dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]);
			}
			//printf(",%lld", dp[i][j]);
		}
		//putchar('\n');
	}
	for (i = 1; i <= W; i++)
	{
		if (dp[N][i] != INF)
		{
			ans = max(ans, dp[N][i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 78336
class UnionFindTree:
    """Disjoint-Set Data Structure
       Union-Find Tree
       complexity:
          init: O(n)
          find, unite, same: O(alpha(n))
       used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ)
    """
    def __init__(self, n):
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
M = 10 ** 5
uft = UnionFindTree(2 * M)

for _ in range(N):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    uft.unite(x, y + M)
x_dict, y_dict = dict(), dict()
for x in range(M):
    par_x = uft.find(x)
    x_dict[par_x] = x_dict.get(par_x, 0) + 1
for y in range(M, 2 * M):
    par_y = uft.find(y)
    y_dict[par_y] = y_dict.get(par_y, 0) + 1
ans = -N
for r in x_dict.keys():
    ans += x_dict.get(r, 0) * y_dict.get(r, 0)
print(ans)


Measured memory_bytes: 36844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  int N;

  cin >> N;

  string U[N];

  REP(i, N) cin >> U[i];

  int M;
  cin >> M;

  string moji;
  int door = 0;
  REP(i, M){
    int cnt = 0;
    cin >> moji;
    REP(i, N){
      if(moji == U[i]){
        cnt = 1;
        door++;
        break;
      }else{
        cnt = 0;
      }
  }
  if(cnt == 1 && door%2 == 1) cout <<  "Opened by" << " " << moji << endl;
  else if(cnt == 1 && door%2 == 0) cout <<  "Closed by" << " " << moji << endl;
  else cout <<  "Unknown" << " " << moji << endl;
}
  return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n); for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,ans;
  cin >> n;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(i%j==0){
        cnt++;
      }
    }
    if(cnt==8){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

typedef pair<int, int> pii;

const int INF = 1e9 + 7;
int q;

int main() {
	INIT
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout <<"No\n";
	} else {
		cout <<"Yes\n";
	}

	return 0;
}

Measured memory_bytes: 256
n=int(input())
c=[]
d=0
for i in range(n):
	c.append(input())
for i in range(n-1):
	if c[i][-1]!=c[i+1][0]:
		print("No")
		exit()
for i in range(n):
	for q in range(n):
		if i!=q:
			if c[i]==c[q]:
				print("No")
				exit()

print("Yes")
	

Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;



signed main(void) {
  int n; cin >> n;
  Vi t(n+1), x(n+1), y(n+1);
  rep(i,n) {
    cin >> t[i+1] >> x[i+1] >> y[i+1];
  }
  bool ok = true;
  rep(i,n) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) ok = false;
    if (dist % 2 != dt % 2) ok = false;
  }
  yes(ok);
  return 0;
}


Measured memory_bytes: 4388
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] title = new String[n];
        int[] time = new int[n];

        for (int i = 0; i < n; i++) {
            title[i] = sc.next();
            time[i] = sc.nextInt();
        }
        String x = sc.next();

        boolean isSleeping = false;

        int ans = 0;

        for (int i = 0; i < n; i++) {
            if (isSleeping) {
                ans += time[i];
            } else if (x.equals(title[i])) {
                isSleeping = true;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << ( ( b-a == c-b ) ? "YES" : "NO" ) << endl;
	return 0;
}

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

int main(){
    
    int x[4];
    int y[4];

    cin >> x[0];
    cin >> y[0];
    cin >> x[1];
    cin >> y[1];

    int xdiff = x[1] - x[0];
    int ydiff = y[1] - y[0];

    x[2] = x[1] - ydiff;
    y[2] = y[1] + xdiff;
    x[3] = x[0] - ydiff;
    y[3] = y[0] + xdiff;

    cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl; 

}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
#define rep(b,e) for(int i=b;i<e;i++)
int main(){
  int n,t,x,y;
  cin>>n;
  bool flag=false;
  int t1=0,x1=0,y1=0;
  rep(0,n){
    int temp,xtemp,ytemp;
    cin>>t>>x>>y;
    temp=t-t1,xtemp=x1-x,ytemp=y1-y;
    xtemp=abs(xtemp); ytemp=abs(ytemp);
    if(temp%2==0&&(xtemp+ytemp)%2==0&&temp>=xtemp+ytemp) {flag=true;t1=t,x1=x,y1=y;continue;}
    if(temp%2==1&&(xtemp+ytemp)%2==1&&temp>=xtemp+ytemp) {flag=true;t1=t,x1=x,y1=y;continue;}
    flag=false;
    break;
  }
  if(flag)
    cout<<"Yes"<<"\n";
  else
    cout<<"No"<<"\n";
}


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

int n, m;
int a[100], b[100], c[100], d[100];

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%d %d", a+i, b+i);
    
    for (int i = 0; i < m; i++)
        scanf("%d %d", c+i, d+i);
    
    
    for (int i = 0; i < n; i++) {
        int mdist = abs(a[i]-c[0]) + abs(b[i] - d[0]);
        int check = 1;
        
        for (int j = 1; j < m; j++) {
            int tempdist = abs(a[i]-c[j]) + abs(b[i] - d[j]);
            if (tempdist < mdist) {
                mdist = tempdist;
                check = j + 1;
            }
        }
        printf("%d\n", check);
        
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


string S;
int w;

string solve(){
	string ans;
	for(int i = 0;i < SIZE(S);i+=w) ans.pb(S[i]);
	return ans;
}


signed main(){
	cin >> S >> w;

	cout << solve() << endl;

	return 0;
}

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

using namespace std;

int main(void){
	int n;
	while(scanf("%d", &n),n){
		long long per[5000]={0};
		int flg[5000]={0};
		int count = 0;
		int cnt[5000]={0};
		int num,t,s;
		int flag = 1;
		
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &num, &t, &s);
			if(flg[num]==0){
				cnt[count] = num;
				count++;
				flg[num]=1;
			}
			per[num] += (long long)t * (long long)s;
		}
		for(int i = 0; i < count; i++){
			if(per[cnt[i]] >= (long long)1000000){
				flag=0;
				printf("%d\n", cnt[i]);
			}
		}
		if(flag)
			puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1280
def m():
    def is_included(i,d):
        s = str(i)
        for j in d:
            if str(j) in s:
                return True
        return False
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    for i in range(n, n*10):
        if not is_included(i,d):
            return i
    return 0
print(m())

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

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  ll x;
  cin >> x;
  vector<ll> a(n, 1e9);
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans += a[i];
  }
  auto b = a;
  for (int k = 1; k < n; ++k) {
    ll res = 0;
    for (int i = 0; i < n; ++i) {
      res += b[i] = min(b[i], a[(i - k + n) % n]);
    }
    ans = min(ans, res + k * x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n  = int(input())
arr = list(map(int, input().split(" ")))
z = 10 ** 18
ret = 1
for i in arr:
    #print(i)
    if(ret != -1):
        ret *= i
    elif ret == -1 and i == 0:
        ret = 0
    if( ret > z):
        ret = -1
    
print(ret)

Measured memory_bytes: 21472
I=input
n=int
for i in range(n(input())):
  I();t=[];x=0
  for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):
    for k in t:i^=k*(i^k<i)
    j=n(j);t.append(i*(j^1));x|=(i>0)&j
  print(x)

Measured memory_bytes: 9200
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<vector<ll>> g(n+1);
    FOR(i,0,n-1){
      ll a,b;
      cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    vector<ll> v(n+1,k-2);
    v[1] = k;
    FOR(i,0,g[1].size()){
      ll x = g[1][i];
      v[x] = k-1;
    }

    deque<ll> q;
    q.push_back(1);
    vector<ll> used(n+1);
    used[1] = 1;
    ll ans = k;
    ll MOD = 1e9+7;
    while(!q.empty()){
      ll from = q.front();
      q.pop_front();
      ll f = 0;
      FOR(i,0,g[from].size()){
        ll to = g[from][i];
        if(used[to] == 0){
//          cout<<to<<" "<<v[to]<<" - "<<f<<endl;
          used[to] = 1;
          q.push_back(to);
          ans = ans*(v[to] - f)%MOD;
          f++;
        }
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8948
#include <stdio.h>

int main(void) {
	int a, b;
	int rem;

	do {

		scanf("%d", &a);
		scanf("%d", &b);
	} while (a <= 0 || b <= 0 || b < a || a>20 || b > 20);
	rem = b % a;
	if (rem > 0) {
		int tmp = b - a;
		printf("%d",tmp);
	}
	else {
		int tmp = a + b;
		printf("%d", tmp);
	}


	return 0;

}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if( a < b ) {
        if( b < c ) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    } else {
        printf("No\n");
    }
}


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

typedef unsigned long long ull;

int main() {
  ull n;
  cin >> n;
  ull min;
  cin >> min;
  for (int i = 0; i < 4; i++) {
    ull x;
    cin >> x;
    if (x < min) min = x;
  }

  if (n % min != 0) {
    cout << n / min + 5 << endl;
  }
  else {
    cout << n / min + 4 << endl;
  }
}


Measured memory_bytes: 512
n,p,i,a[51];
main(){
	for(;~scanf("%d",&n),n;) {
		for(a[n]=p=i=0;i<n;i++)scanf("%d",a+i);
		for(i=1;i<=n;i++){
			if(a[i-1]-a[i]+1) {
				i-p-1&&printf(n-i?"%d-%d ":"%d-%d\n",a[p],a[i-1]);
				!(i-p-1)&&printf(n-i?"%d ":"%d\n",a[p]);
				p=i;
			}
		}
	}
	exit(0);
}

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

int main()
{
    ll D, G; cin >> D >> G;
    vector<ll> p(D, 0);
    vector<ll> c(D, 0);
    rep(i,D) {
        ll tmp1, tmp2; cin >> tmp1 >> tmp2;
        p[i] = tmp1;
        c[i] = tmp2;
    }

    ll ans = -1;
    for (int i = 0; i < (1<<D); ++i) {

        ll tmp_p = 0;
        ll tmp_a = 0;
        ll tmp_q = 0;

        for (int j = 0; j < D; ++j) {
            if ((i >> j) & 0x01) { // complete
                tmp_p += (100 * (j+1) * p[j] + c[j]);
                tmp_a += p[j];
            }
            else {
                tmp_q = j;
            }
        }

        if (tmp_p < G) {
            int s1 = 100 * (tmp_q + 1);
            int need = (G - tmp_p + s1 - 1) / s1;
            if (need >= p[tmp_q]) {
                continue;
            }
            tmp_a += need;
        }
        if (ans == -1) {
            ans = tmp_a;
        }
        else if (ans > tmp_a) {
            ans = tmp_a;
        }

    }
    cout << ans << endl;





}


Measured memory_bytes: 3624
n = int(input())
a = list(map(int, input().split()))

def solve(n):
    ans = 0
    cusm = []
    if n == -1 and a[0] > 0:
        cusm.append(-1)
        ans += abs(-1 - a[0])
    elif n == -1 and a[0] < 0:
        cusm.append(1)
        ans += abs(1 - a[0])
    elif a[0] == 0:
        cusm.append(n)
        ans += abs(n - a[0])
    else:
        cusm.append(a[0])

    for i, ai in enumerate(a):
        if i == 0: continue
        if (cusm[-1] + ai) * cusm[-1] < 0: #符号が逆なら
            cusm.append(cusm[-1] + ai)
        elif cusm[-1] > 0: #操作の必要があって前が正なら
            ans += abs(-1 - (cusm[-1] + ai))
            cusm.append(-1)
        else:  #操作の必要があって前が負なら
            ans += abs(1 - (cusm[-1] + ai))
            cusm.append(1)
    return ans

print(min(solve(1),solve(-1)))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    ll n;
    cin >> n;
    ll a[200000]={0};
  
    for(ll i=0; i<n; i++){
        cin >> a[i];
    }
    //Ai + Aj == j - i (j>i) <=> Ai + i == j - Aj
    //Li = Ai + i, Ri = i - Ai
    //Li == X && Rj == X
    map<ll, ll> L;
    map<ll, ll> R;
    ll ans = 0;
  
    for(ll i=0; i<n; i++){
        L[a[i] + i]++;
        R[i - a[i]]++;
    }

    for(ll i=0; i<n; i++){
	    //cout << L[i] << " " << R[i] << endl;
        //cout << L[a[i] + i] << " " << R[i - a[i]] << endl;
        ans += L[i] * R[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 47892
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        var S = cin.next;
        var K = S.ToCharArray();
        Array.Reverse(K);
        
        if (S == new string(K))
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13264
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int a[100001];
long b[100001];
int main(void){
	int n=nextint();
	a[0]=nextint();
	if(n==0){
		if(a[0]==1){
			puts("1");
		}else{
			puts("-1");
		}
	}else{
		if(a[0]==0){
			b[0]=1;
			for(int i=1; i<=n; i++){
				a[i]=nextint();
				if(a[i]>b[i-1]*2){
					puts("-1");
					return 0;
				}
				b[i]=b[i-1]*2-a[i];
				if(b[i]>LONG_MAX/2) b[i]=LONG_MAX/2;
			}
			b[n]=0;
			for(int i=n; i>0; i--){
				if(b[i-1]>=a[i]+b[i]){
					b[i-1]=a[i]+b[i];
				}
			}
			long ans=0;
			for(int i=0; i<=n; i++){
				ans+=a[i];
				ans+=b[i];
			}
			printf("%ld\n", ans);
		}else{
			puts("-1");
		}
	}
}


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

int main (){
  int a,b,c;cin>>a>>b>>c;
  if (a<=c&&c<=b)cout<<"Yes"<<endl;
  else if (b<=c&&c<=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

typedef long long ll;

int main() {
	ll a,b,k;
	cin >> a >> b >> k;
	for (ll i = 0;i < k;i++) {
		if (i%2==0) {
			a/=2;
			b+=a;
		} else {
			b/=2;
			a+=b;
		}
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    tmp = []
    for i, a in enumerate(A):
        tmp.append((i, a))
    tmp.sort(key=lambda a: a[1])
    ans = []
    for i in tmp:
        ans.append(i[0]+1)
    print(*ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 23656
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll p[100002];
    ll right[100002], left[100002];
    ll right2[100002], left2[100002];
    fill(right, right + n, n);
    fill(left, left + n, -1);
    fill(right2, right2 + n, n);
    fill(left2, left2 + n, -1);
    priority_queue<ll, vector<ll>, greater<ll>> quer, quer2, quel, quel2;
    for(ll i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
        while(quer2.size()){
            ll now = quer2.top();
            if(now > p[i]) break;
            quer2.pop();
            right2[now] = i;
        }
        while(quer.size()){
            ll now = quer.top();
            if(now > p[i]) break;
            quer.pop();
            right[now] = i;
            quer2.push(now);
        }
        quer.push(p[i]);
    }
    for(ll i = n - 1; i >= 0; i--){
        while(quel2.size()){
            ll now = quel2.top();
            if(now > p[i]) break;
            quel2.pop();
            left2[now] = i;
        }
        while(quel.size()){
            ll now = quel.top();
            if(now > p[i]) break;
            quel.pop();
            left[now] = i;
            quel2.push(now);
        }
        quel.push(p[i]);
    }
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        ll sum = 0;
        if(right[p[i]] != n){
            sum += (p[i] + 1) * (right2[p[i]] - right[p[i]]) * (i - left[p[i]]);
        }
        if(left[p[i]] != -1){
            sum += (p[i] + 1) * (left[p[i]] - left2[p[i]]) * (right[p[i]] - i);
        }
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5240
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <stdlib.h>
int main(void)
{
	int k;
	scanf("%d",&k);
	
	int a=0;
	int i;
	if(k%2==0 || k%5==0)
	{
		printf("-1\n");
	}
	else
	{
		for(i=1;i<=k;i++)
		{
			a=a*10+7;
			a=a%k;
			if(a==0)
			{
				break;
			}
		}
		if(i>k)
		{
			printf("-1\n");
		}
		else
		{
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 1724
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)
typedef long long ll;

int main()
{	
	
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a+b==c||a+c==b||b+c==a)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
		
		
	
	return 0;
}



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


bool search(int x, int y, vector<string> board, vector<pair<int, int>> path) {
    if (y == board.size()-1 && x == board[0].size()-1) {
        path.push_back(make_pair(x, y));
        for (int i = 0; i < board.size(); i++) {
            for (int j = 0; j < board.at(i).size(); j++) {
                if (board[i][j] == '#') {
                    auto p = make_pair(j, i);
                    if (find(path.begin(), path.end(), p) == path.end()) return false;
                } 
            }
        }
        return true;
    } else {
        if (y == board.size() - 1) {
            if (board[y][x+1] == '.') return false;
            else {
                auto p = make_pair(x, y);
                path.push_back(p);
                return search(x+1, y, board, path);
            }
        } else if (x == board[0].size() - 1) {
            if (board[y+1][x] == '.') return false;
            else {
                path.push_back(make_pair(x, y));
                return search(x, y+1, board, path);
            }
        } else {
            path.push_back(make_pair(x, y));
            if (board[y+1][x] == '.' && board[y][x+1] == '.') return false;
            else if (board[y+1][x] == '#' && board[y][x+1] == '.') return search(x, y+1, board, path);
            else if (board[y+1][x] == '.' && board[y][x+1] == '#') return search(x+1, y, board, path);
            else return (search(x+1, y, board, path) || search(x, y+1, board, path));
        }
    }
}

int main() {
    vector<string> board;
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string line;
        cin >> line;
        board.push_back(line);
    }

    //for (string line : board) cout << line << endl;
    vector<pair<int, int>> path;
    if (search(0, 0, board, path)) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
s = input()
I = []
for j in range(len(s)):
    if j == 0:
        I.append(0)
    else:
        if s[j-1] != s[j]:
            I.append(j)
r = len(I)
I = I + [N] * (3*K)
x = []
for k in range(r):
    if s[I[k]] == '0':
        x.append(I[k+2*K] - I[k])
    else:
        x.append(I[k + 2 * K + 1] - I[k])
print(max(x))

Measured memory_bytes: 11444
times = int(input())

r_list = []
for i in range(times):
    r_list.append(int(input()))

"""
発想：今までで一番大きい差と、新しく追加される値を用いた一番大きい値の大きい方を取れば良い
一番大きい差を得るためには、そこまでの数列の一番小さい値を保持しておく必要があるので、それも保持しておく
"""
r_min = r_list[0]
r_max = r_list[1] - r_list[0]
for r in range(1, len(r_list)):
    r_max = max(r_max, r_list[r]-r_min)
    r_min = min(r_min, r_list[r])

print(r_max)


Measured memory_bytes: 13592
import java.util.Scanner;
 
enum Type{
    SAME,
    A_BIG,
    B_BIG
};
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        int N = scanner.nextInt();
        String TARO,HANAKO;
        int score_TARO = 0,score_HANAKO = 0;
 
        for(int loop = 0; loop < N; loop++){
 
            TARO = scanner.next();
            HANAKO = scanner.next();
 
            switch(compString(TARO,HANAKO)){
            case SAME:
                score_TARO += 1;
                score_HANAKO += 1;
                break;
            case A_BIG:
                score_TARO += 3;
                break;
            case B_BIG:
                score_HANAKO += 3;
                break;
            }
        }
 
        System.out.printf("%d %d\n", score_TARO,score_HANAKO);
    }
 
    //A基準で比較する関数
    public static Type compString(String A,String B){
        int a_index = 0,b_index = 0;
 
        while(a_index < A.length() && b_index < B.length() && A.charAt(a_index) == B.charAt(b_index)){
            a_index++;
            b_index++;
        }
 
        if(a_index < A.length() && b_index < B.length()){
            if(A.charAt(a_index) > B.charAt(b_index)){
                return Type.A_BIG;
            }else{
                return Type.B_BIG;
            }
 
        }else if(a_index < A.length() && b_index == B.length()){
            return Type.A_BIG;
        }else if(a_index == A.length() && b_index < B.length()){
            return Type.B_BIG;
        }else{
            return Type.SAME;
        }
    }
}


Measured memory_bytes: 31076
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N;

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

    cin >> N;
    int mina = 1000000005;
    int maxa = 0;
    REP(i, N) {
        int a;
        cin >> a;
        mina = min(mina, a);
        maxa = max(maxa, a);
    }

    cout << abs(maxa - mina) << endl;
    return 0;
}


Measured memory_bytes: 764
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string line1 = Console.ReadLine();
            string line2 = Console.ReadLine();
            string line3 = Console.ReadLine();
            Console.WriteLine($"{line1[0]}{line2[1]}{line3[2]}");
        }
    }
}

Measured memory_bytes: 11092
#1は含まれない
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = set(table)
    return table

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1


A,B=map(int,input().split())
AL = divisor(A)
BL = divisor(B)
AB = list(AL & BL)
cnt = 1
for l in AB:
    if is_prime(l):
        cnt+=1

print(cnt)


Measured memory_bytes: 80044
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

ll const MAX_N = 1e5 + 10;
bool done[MAX_N];

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() {
	ll i, j;
	ll N;
	cin >> N;
	vll A(N);
	for (auto& e : A)cin >> e;
	multiset<ll> E ;
	for (auto a : A) {
		auto it = E.lower_bound(a);
		//it--;
		if (it == E.begin()) {
			E.insert(a);
		}
		else {
			it--;
			E.erase(it);
			E.insert(a);
		}
	}
		cout << E.size() << endl;

	return 0;
}


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

int main() {
  int n;
  unordered_map<int, bool> map;
  
  cin >> n;
  
  for(int i = 0; i < n; i++) {
    int key;
    
    cin >> key;
    
    if(map[key]) {
      map.erase(key);
    } else {
      map[key] = true;
    }
  }

  int ans = map.size();
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4388
#include <stdio.h>

int main() {
    int x, aaa[12];
    scanf("%d", &x);
    int a = 0, b = 0, ok = 0;
    for(int i = 1; i < 10; ++i){
        if (x%i == 0){
            aaa[ok] = i;
            ok += 1;
        }
    }
    for (int i = 0; i < ok; ++i){
        for(int j = 0; j < ok; ++j){
            if (aaa[i] * aaa[j] == x){
                b = 1;
                break;
            }
        }
    }
    if (b == 1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     ll n,m;
     ll ans=0;
     cin >> n >> m;
     ll k = min(n,m/2);
     ans += k;
     m -= 2*(k);
     ans += m/4;
     cout << ans;
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

    for (int h = 1; h <= 3500; h++) {
        for (int n = 1; n <= 3500; n++) {
            long long x = 1ll * 4 * h * n - N * n - N * h;
            long long y = 1ll * N * h * n;
            if (x > 0 && y % x == 0) {
                cout << h << " " << n << " " << y / x << endl;
                return 0;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b

const char code[10][10] = { "",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };

int main() {
	int c = 0, a, n, i,f;
	char input[10001], *p;
	S(d, n),getchar();
	for (i=0;i<n;i++,puts("")) {
		fscanf(stdin, "%[^\n]*s", input);
		getchar();
		p = input;
		c = 0;
		while (*p) {
			if (*(p + 1) != *p) {
				if (*p == '1') a = 5;
				else if (*p == '7' || *p == '9') a = 4;
				else a = 3;
				if (*p != '0') fprintf(stdout, "%c", code[*p - '0'][c%a]);
				c = 0;
			}
			else c++;
			p++;
		}
	}
	return 0;
}

Measured memory_bytes: 592
s=input()
k=int(input())
if len(s)==1:
	print(k//2)
	exit()
cnt=0
same_length=1
first=1
for i in range(len(s)-1):
 		 if s[i]==s[i+1]:
 		 	same_length+=1
 		 	if cnt==0:first+=1
 		 elif s[i]!=s[i+1]:
 		 	if cnt==0:s_left=first
 		 	cnt+=int(same_length//2)
 		 	same_length=1
if same_length==len(s):
	print(len(s)*k//2)
	exit()
s_right=same_length
cnt+=int(same_length//2)
if s[0]==s[-1] and s_left%2==1 and s_right%2==1:
	print(cnt*k+k-1)
else:
	print(cnt*k)


Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;

int N;
vector<ll> a(3010);
ll memo[3010][3010];

void init(){
    for(int i = 0; i < 3010; i++){
        for(int j = 0; j < 3010; j++){
            memo[i][j] = INFL;
        }
    }
}

ll dfs(int x, int y){
    if(memo[x][y] != INFL){
        return memo[x][y];
    }
    bool turn = (N + x + y) % 2;
    if(x == y){
        if(turn) return memo[x][y] = a.at(x);
        return memo[x][y] = -a.at(x);
    }
    if(turn){
        return memo[x][y] = max(dfs(x+1, y) + a.at(x), dfs(x, y-1) + a.at(y));
    }else{
        return memo[x][y] = min(dfs(x+1, y) - a.at(x), dfs(x, y-1) - a.at(y));
    }
}




int main() {
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    init();
    cout << dfs(0, N-1) << endl;
    
    
    
}

Measured memory_bytes: 71168
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int m = sc.nextInt();
        int k = sc.nextInt();
        if(m == 0){
            if(k == 0){
                System.out.println("0 0");
            }else{
                System.out.println(-1);
            }
            return;
        }
        if(m == 1){
            if(k == 0){
                System.out.println("0 0 1 1");
            }else{
                System.out.println(-1);
            }
            return;
        }
        int max = (int)Math.pow(2,m);
        if(max <= k){
            System.out.println(-1);
            return;
        }else if(k == 0){
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < max; i++){
                sb.append(i + " " + i + " ");
            }
            System.out.println(sb.toString().trim());
        }else{
            StringBuilder sb = new StringBuilder();
            for(int i = max-1; i >= 1; i--){
                if(i != k){
                    sb.append(i + " ");
                }
            }
            sb.append(k + " " + 0 + " ");
            for(int i = 1; i < max; i++){
                if(i != k){
                    sb.append(i + " ");
                }
            }
            sb.append(0 + " " + k + " ");
            System.out.println(sb.toString().trim());
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 51720
# -*- coding: utf-8 -*-

def main():
    N ,K  =  [int(i) for i in input().split()]
    As =   [int(i) for i in input().split()]

    rireki = []
    loop = ""

    ind = 1
    flags = [0 for _ in range(N)]
    while(1):
        if flags[ind-1] == 1:
            loop = ind
            break
        else:
            rireki.append(ind)
            flags[ind-1] = 1
            ind = As[ind-1]

        #print(flags)
    #print(rireki,loop)
    loop_c = len(rireki) - rireki.index(loop)
    if K <= len(rireki)-1:
        print(rireki[K])
    else:
        nokori = K-len(rireki)+1
        ans = nokori % loop_c
        if ans == 0:
            print(rireki[-1])
        else:
            print(rireki[rireki.index(loop)+ans-1])

if __name__ == "__main__":
    main()


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

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

	int h[100010];

	for(int i = 0;i < n;i++){
		cin >> h[i];
	}

	int ans = 0;
	for(int x = 1;x <= 100;x++){
		int old = 0;
		for(int i = 0;i < n;i++){
			if(h[i] >= x){
			       if(old == 0) ans++;
			       old = 1;
			}else{
				old = 0;
			}
		}
	}

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




Measured memory_bytes: 256