akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int X;
  int A;
  int B;
  cin >>X>>A>>B;
  int x=X-A;
  int y=x/B;
  int z=x-y*B;
  cout << z<< endl;
}

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

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;


void solve() {
	int n, k;
	cin >> n >> k;
	int tot = 0;

	int mt = n * (n + 1) / 2;

	for (int i = k; i <= n + 1; i++) {
		int mi = (i * (i - 1)) / 2;
		int rem = n + 1 - i;
		int ma = mt - ((rem * (rem - 1)) / 2);
		tot += (ma - mi + 1) % mod;
		tot %= mod;
	}

	cout << tot << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

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

int N, a[100], a_cnt[100];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        a_cnt[a[i]]++;
    }
    sort(a, a+N, greater<int>());
    bool possible = true;
    if(a[0] % 2 == 0){
        for(int i = 1; i < a[0]/2; i++){
            if(a_cnt[i] > 0){
                possible = false;
            }
        }
        if(a_cnt[a[0]/2] != 1){
            possible = false;
        }
        for(int i = a[0]/2 + 1; i <= a[0]; i++){
            if(a_cnt[i] < 2){
                possible = false;
            }
        }
    }else{
        for(int i = 1; i <= a[0]/2; i++){
            if(a_cnt[i] > 0){
                possible = false;
            }
        }
        for(int i = a[0]/2+1; i <= a[0]; i++){
            if(a_cnt[i] < 2){
                possible = false;
            }
        }
        if(a_cnt[a[0]/2+1] > 2){
            possible = false;
        }
    }
    cout << (possible? "Possible": "Impossible") << endl;
    
        
        
}


Measured memory_bytes: 256
s = input()
k = int(input())
n = len(s)
mod = 26
alpha = "abcdefghijklmnopqrstuvwxyz"
aldic = {}
ansstr = ""
for i, al in enumerate(alpha, 1):
    aldic[al] = i

for i in range(n - 1):
    if k >= mod - aldic[s[i]] + 1 and s[i] != "a":
        ansstr += "a"
        k -= mod - aldic[s[i]] + 1
    else:
        ansstr += s[i]
ansstr += alpha[(aldic[s[n - 1]] + k - 1) % mod]
print(ansstr)

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

int main(){
  int str[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
  int mon,day;
  while(cin >>mon >>day){
    if(mon==0&&day==0)break;
    for(int i = 0 ; i < mon ; i++)
      day += str[i];
    day=day%7;
    if(day==0)cout<<"Wednesday"<<endl;
    else if(day==1)cout<<"Thursday"<<endl;
    else if(day==2)cout<<"Friday"<<endl;
    else if(day==3)cout<<"Saturday"<<endl;
    else if(day==4)cout<<"Sunday"<<endl;
    else if(day==5)cout<<"Monday"<<endl;
    else cout<<"Tuesday"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
n = gets.to_i
s = gets
ans = s.count("R") * s.count("G") * s.count("B")
0.upto(n-1) do |i|
  (i+1).upto(n-1) do |j|
    k = j + j - i
    break if k >= n
    if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
      ans -= 1
    end
  end
end
puts ans

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

int a[7368792];
int n, m, ans;

int solve() {
    a[0] = a[1] = 1;
    int cnt = 0;
    for (int i = n; ; ++i) {
        if (cnt >= m) break;
        if (a[i] == 0) {
            //cout << i << endl;
            for (int j = 1; j * i <= 7368791; ++j) {
                a[i * j] = 1;
            }
            cnt++;
            //cout << "cnt = " << cnt << endl;
        }
    }
    for (int i = n; i < 7368792; ++i) {
        if (a[i] == 0) return i;
    }

    return -1;
}

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

    while (cin >> n >> m, n | m) {
        memset(a, 0, sizeof(a));
        ans = solve();
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 31860
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define rp(p,mp) for(auto p : mp)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n;
cin >> n;
map<string,int> mp;
rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
}
int m = 0;
vector<string> s;
rp(p,mp) m = max(m,p.second);
rp(p,mp){
    if(m == p.second)
        cout << p.first << endl;
}
}


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

def main():
    n, k = map(int, input().split())
    ab_list = [list(map(int, input().split())) for _ in range(n)]
    ab_list.sort(key= lambda x:x[0])

    cnt = 0

    for ab in ab_list:
        cnt += ab[1]
        if cnt >= k:
            print(ab[0])
            break
    
if __name__ == '__main__':
    main()

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

int depth[100000];

struct node {
  int parent, child, sibling;
};
struct node tree[100000];

void showInfo(int id) {
  char type[20];
  if(tree[id].parent == -1)
    strcpy(type, "root");
  else if(tree[id].child != -1)
    strcpy(type, "internal node");
  else
    strcpy(type, "leaf");

  printf("node %d: parent = %d, depth = %d, %s, ", id, tree[id].parent, depth[id], type);

  printf("[");
  if(tree[id].child != -1) {
    id = tree[id].child;
    while(tree[id].sibling != -1) {
      printf("%d, ", id);
      id = tree[id].sibling;
    }
    printf("%d", id);
  }
  printf("]\n");
}

void setDepth(int id, int d) {
  depth[id] = d;
  if(tree[id].child != -1)
    setDepth(tree[id].child, d + 1);
  if(tree[id].sibling != -1)
    setDepth(tree[id].sibling, d);
  if(tree[id].child == -1)
    return;
}

int main() {
  int i, j, n, id, k, root, c[100000];

  scanf("%d", &n);
  for(i = 0;i < n;i++) {
    tree[i].sibling = -1;
    tree[i].parent = -1;
    tree[i].child = -1;
  }

  for(i = 0;i < n;i++) {
    scanf("%d", &id);
    scanf("%d", &k);
    if(k != 0) {
      for(j = 0;j < k;j++) {
        scanf("%d", &c[j]);
        tree[c[j]].parent = id;
        if(j > 0)
          tree[c[j - 1]].sibling = c[j];
      }
      tree[id].child = c[0];
    }
  }

  for(i = 0;i < n;i++)
    if(tree[i].parent == -1)
      root = i;

  setDepth(root, 0);

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

  return 0;
}



Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
  int a,b;
  cin>>a>>b;
  if(a<b){
cout<<"a < b"<<endl;
}
  if(a>b){
cout<<"a > b"<<endl;
}
  if(a==b){
cout<<"a == b"<<endl;
}
 return 0;
}


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


int main() 
{
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n)
    {
        int x;
        cin >> x;
        b[(n - 1) - i] = x;
    }
    int cnt=0;
    int back=0;
    rep(i, b.size())
    {
        if(b[(n - 1-back)-cnt]!=i+1)
        {
            b.pop_back();
            back++;
            i--;
        }
        else
        {
            cnt += 1;   
        }
    }
    if(cnt==0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n-cnt << endl;
    }



    return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	vector<int> count(26,0);
	rep(i,h){
		rep(j,w){
			int c = s[i][j] - 'a';
			count[c] += 1;
		}
	}
	if(h * w == 1){
		puts("Yes");
		return 0;
	}
	else if(h * w == 2){
		bool flag = true;
		char c = '.';
		rep(i,h) rep(j,w) {
			if(c == '.') c = s[i][j];
			else {
				if(c != s[i][j]) flag = false;
			}
		}
		if(flag) puts("Yes");
		else puts("No");
		return 0;
	}
	// とりあえず処理をまとめないで i * k or k * 1 のときを書く
	if (h == 1 || w == 1){
		int need = (h * w) / 2;
		rep(i,26){
			if(count[i] >= 2){
				need -= count[i] / 2;
			}
		}
		if(need == 0){
			puts("Yes");
		} else {
			puts("No");
		}
		return 0;
	}

	//cout << "ikiteru" << endl;
	int need4, need2;
	need4 = (h / 2) * (w / 2) ;
	need2 = (h/2) * (w%2) + (w/2) * (h%2);
	//cout << "need4 = " << need4 << endl;
	//cout << "need2 = " << need2 << endl;
	rep(i,26){
		while(count[i] >= 4){
			if(need4 == 0) break;
			count[i] -= 4;
			need4 --;
		}
	}
	rep(i,26){
		while(count[i] >= 2){
			if(need2 == 0) break;
			count[i] -= 2;
			need2 --;
		}
	}
	if(need4 == 0 && need2 == 0){
		puts("Yes");
	} else {
		puts("No");
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll ans=0;
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1]){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b,c,d;
    double e;
    cin >> a >> b;
    c = a/b;
    d =a%b;
    e= 1.0*a/b;
    //printf("%d " "%d,%.5lf\n",c,d,e);
    // insert code here...
//    cout << c <<" " << d << " " ;
//    printf("%d",c);
  //  printf(" ");
   // printf("%d",d);
   // printf(" ");
    printf("%d %d %.5lf\n",c,d,e);
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int A,B,H,M;
  cin>>A>>B>>H>>M;
  
  double pi = 3.141592653589793;
  int time=60*H+M;
  
  double s=(double)(0.5*time);
  double l=(double)(6*time);
  
  double delta=(l-s)*pi/180;
  
  double ans=A*A+B*B-2*A*B*cos(delta);
  ans=sqrt(ans);
  
  cout<<fixed;
  cout<<setprecision(20)<<ans<<endl;
  
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b;
    cin >> a >> b;
    int c, d;
    cin >> c >> d;
    int t = min(a,b);
    int u = min(c,d);
    OUT(t+u) 

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int c[3][3];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++) cin >> c[i][j];
	}
	for(int i = 1; i < 3; i++){
		if(c[i][0] - c[i][1] != c[0][0] - c[0][1] || 
				c[i][1] - c[i][2] != c[0][1] - c[0][2]){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int j = 1; j < 3; j++){
		if(c[0][j] - c[1][j] != c[0][0] - c[1][0] || 
				c[1][j] - c[2][j] != c[1][0] - c[2][0]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n,l,big,small,discount;
	scanf("%d%d",&n,&l);
	big=l+n-1;
	small=l;
	if(small>0)
		discount=small;
	else if(big<0)
		discount=big;
	else
		discount=0;

	printf("%d",((small+big)*n/2)-discount);
	return 0;
}

Measured memory_bytes: 128
def HCF(a,b):
    if a==0:
        return b
    return HCF(b%a,a)
N = long(raw_input())
x = long(raw_input())
for i in range(1,N):
    y = long(raw_input())
    x = (x*y)/HCF(x,y)
print x


Measured memory_bytes: 2568
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
const int maxin = (int)1e6+5;
vector<int>spf(maxin,1);
void seive(){
	for(int i=1;i<maxin;i++){
		spf[i] = i;
	}
	for(int i=4;i<maxin;i+=2){
		spf[i] = 2;
	}
	for(int i=3;i<maxin;i+=2){
		if(spf[i] == i){
			for(int j=i*i;j<maxin;j+=i){
				if(spf[j] == j){
					spf[j] = i;
				}
			}
		}
	}
}
void add(int x,map<int,int>&cnt){
	set<int>pf;
	while(x != 1){
		pf.insert(spf[x]);
		x /= spf[x];
	}
	for(auto i : pf){
		cnt[i] += 1;
	}
}
int32_t main(){
	
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	seive();
   	int n;
   	cin >> n;
   	vector<int>v(n);
   	int g = 0;
   	for(int i=0;i<n;i++)
   	{
   		cin >> v[i];
   		g = __gcd(g,v[i]); 
   	}
   	if(g != 1){
   		cout << "not coprime\n";
   		return 0;
   	}
   	map<int,int>cnt;
   	for(int i=0;i<n;i++){
   		add(v[i],cnt);
   	}
   	for(auto i : cnt){
   		if(i.second > 1){
   			cout << "setwise coprime\n";
   			return 0;
   		}
   	}
   	cout << "pairwise coprime";
    return 0;
}

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

#define datatype point
#define int long long int

typedef struct {
	int num;
	int x;
	int y;
}point;

typedef struct node_sub{
	int val;
	struct node_sub *prev;
	struct node_sub *next;
}node;

//比較関数
int compare(datatype a, datatype b, int R, int C){
	if(a.y == 0 || a.x == R){
		if(b.y == C || b.x == 0){
			return -1;
		}
		else{
			return a.x + a.y - b.x - b.y;
		}
	}
	else{
		if(b.y == 0 || b.x == R){
			return 1;
		}
		else{
			return b.x + b.y - a.x - a.y;
		}
	}
	
}

//昇順
void sort_sub(datatype *origin, int left, int right, datatype *tmp, int R, int C){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp, R, C);
		sort_sub(origin, half, right, tmp, R, C);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if((compare(tmp[j], tmp[k], R, C) <= 0 && j < half) || k == right){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(datatype *origin, int N, int R, int C){
	datatype *tmp = (datatype *)malloc(sizeof(datatype) * N);
	sort_sub(origin, 0, N, tmp, R, C);
}

signed main(){
	int R, C, N, x1, y1, x2, y2, i, j;
	scanf("%lld%lld%lld", &R, &C, &N);
	point *p = (point *)malloc(sizeof(point) * 2 * N);
	for(i = 0, j = 0; i < N; i++){
		scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
		if((x1 % R == 0 || y1 % C == 0) && (x2 % R == 0 || y2 % C == 0)){
			p[j].num = j;
			p[j].x = x1;
			p[j].y = y1;
			p[j + 1].num = j;
			p[j + 1].x = x2;
			p[j + 1].y = y2;
			j += 2;
		}
	}
	N = j;
	sort(p, N, R, C);
	/*for(i = 0; i < N; i++){
		printf("%lld  ", p[i].num);
	}
	printf("\n");*/
	node *nod = NULL;
	node *now;
	node *new;
	//printf("test1: N = %lld\n", N);
	for(i = 0; i < N; i++){
		new = (node *)malloc(sizeof(node));
		new->val = p[i].num;
		new->prev = NULL;
		new->next = nod;
		if(nod != NULL){
			nod->prev = new;
		}
		nod = new;
	}
	j = N;
	node *pre, *nex;
	for(now = nod; ;){
		if(now->next == NULL){
			printf("NO\n");
			return 0;
		}
		if(now->val == now->next->val){
			pre = now->prev;
			nex = now->next->next;
			if(nex == NULL){
				j -= 2;
				break;
			}
			if(pre == NULL){
				nex->prev = NULL;
				now = nex;
			}
			else{
				pre->next = nex;
				nex->prev = pre;
				now = pre;
			}
			j -= 2;
		}
		else{
			now = now->next;
		}
	}
	if(j == 0){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e16;
const ll mod=1000000007;
typedef pair<ll,ll> pi;

void solve()
{
 ll n,d;
cin>>n>>d;
ll temp=d*d;
ll ans=0;
for(ll i=0;i<n;i++)
{
    ll x,y;
    cin>>x>>y;
    ll temp2=x*x+y*y;
    if(temp2<=temp)
        ans++;
}
cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    for(ll i=1;i<=t;i++)
    {
        solve();
        cout<<endl;

    }
    return 0;
}

Measured memory_bytes: 3608
n,m=map(int,input().split())
#2c=s  
#n s m c  
def check(k):
    n1=n 
    m1=m 
    if k>=n:
        req=(k-n1)*2+2*k 
    else:
        req=2*k 
    return req<=m  
lo=0 
hi=10**30 
ans=0 
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        lo=mi+1 
    else:
        hi=mi-1 
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    ll t;  cin >> t;

    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll b[n];
    ll vmin = a[0];
    b[0] = 0;

    reps(i, 1, n){
        vmin = min(vmin, a[i]);
        b[i] = a[i] - vmin;
    }

    ll bmax = *max_element(b, b+n);
    ll cnt = 0;

    rep(i, n){
        if(b[i] == bmax) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll cnt=x/d;
	cnt=min(cnt,k);
	x-=cnt*d;
	k-=cnt;
	if(k%2==0){
		cout<<x<<endl;
	}else{
		x=min(abs(x-d),abs(x+d));
		cout<<x<<endl;
	}

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int deg[4] = {0, 0, 0, 0};
    for (int i = 0; i < 3; i++) {
        int a, b; cin >> a >> b; a--; b--;
        deg[a]++; deg[b]++;
    }
    sort(all(deg));
    if (deg[0] == 1 && deg[1] == 1 && deg[2] == 2 && deg[3] == 2) cout << "YES" << endl; else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
    double n, s[1001], sum;
    cin >> n;
	while(n != 0){
		sum  = 0;
		for (int i = 0; i < n; i++){
        	cin >> s[i];
        	sum += s[i];
    	}
    	double m = sum / n;
		double a = 0;
		for (int i = 0; i < n; i++){
			a += (s[i] - m) * (s[i] - m);
		} 
		cout << fixed << setprecision(4); 
		cout << sqrt(a / n) << endl;
		cin >> n; 
	}
    return 0;
}


Measured memory_bytes: 3280
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import           Control.Applicative
import          Data.List

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

output :: [Int] -> IO ()
output (x : xs) | xs == [] = print x
                | otherwise = putStr (show x ++ " ") >> output xs

main :: IO ()
main = readInts >>= output <$> sort



Measured memory_bytes: 3588
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    if (abs(a - c) <= d) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    if (abs(a - b) <= d && abs(b - c) <= d) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}


template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

int main(){
	int n;in(n);
	ll a,b;
	cin>>a>>b;
	n--;
	REP(i,0,n){
		ll ta,tb;cin>>ta>>tb;
		ll tc = (a+ta-1)/ta*ta;
		ll td = tc/ta*tb;
		ll te = (b+tb-1)/tb*tb;
		ll tf = te/tb*ta;
		if((tc>=a && td>= b) && (tf>=a && te>=b)){
			if(tc>tf){
				swap(tc,tf);swap(td,te);
			}
			a = tc,b = td;
		}else if((tc>=a && td>= b)){
			a = tc,b = td;
		}else{
				swap(tc,tf);swap(td,te);
			a = tc,b = td;
		}
	}
	cout<<a+b;
	return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

ll IN(){
	int c,f;ll x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int top=100000;
const int N=top+19;
const ll oo=1e18;

map<ll,int> num,vis;
map<ll,ll> M,anti;
int pri[N],v[N];
int n,res;

void Init(){
	For(i,2,top+1){
		if (!v[i]) pri[++*pri]=i;
		for (int j=1;j<=*pri&&pri[j]*i<=top;j++){
			v[pri[j]*i]=1;
			if (i%pri[j]==0) break;
		}
	}
}
ll Mul(ll x,ll y){
	return 1.0*x*y<=oo?x*y:oo;
}
void gao(ll x){
	ll y,z;
	if (M.count(x)){
		y=M[x];
	} else{
		ll &res=M[x];
		y=1;z=1;
		for (int i=1;i<=*pri&&1ll*pri[i]*pri[i]<=x;i++)
			if (x%pri[i]==0){
				int c=0;
				while (x%pri[i]==0) x/=pri[i],c++;
				c%=3;
				For(j,0,c) y*=pri[i];
				c=(3-c)%3;
				For(j,0,c) z=Mul(z,pri[i]);
			}
		if (x>1){
			y*=x;
			z=Mul(z,x);
			z=Mul(z,x);
		}
		res=y;
		anti[y]=z;
		anti[z]=y;
	}
	num[y]++;
}

int main(){
	Init();
	n=IN();
	For(i,0,n) gao(IN());
	for (auto u:num){
		ll a=u.fi;
		if (!vis.count(a)){
			vis[a]=vis[anti[a]]=1;
			if (anti[a]==oo) res+=num[a];
			lf (anti[a]==a) res++;
			else res+=max(num[a],num[anti[a]]);
		}
	}
	printf("%d\n",res);
}

Measured memory_bytes: 37760
N, K = map(int, input().split())
heights = list(map(int, input().split()))

dp = [float('inf') for i in range(N)]
dp[0] = 0

for i, h in enumerate(heights[1:]):
    index = i + 1
    for j in range(K):
        back = ~j
        if index + back >= 0:
            dp[index] = min(dp[index], dp[index + back] +
                            abs(heights[index] - heights[index + back]))


print(dp[-1])


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

int main(){
    int K, X;
    cin >> K >> X;
    if(K * 500 > X || K * 500 == X){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,X,M = map(int, input().split())

LOOP = [X]
wk = X
s = set()
s.add(X)
flg = True
for i in range(N-1):
  a = wk * wk % M
  if a == 0:
    print(sum(LOOP))
    exit(0)
  if a in s:
    wk = a
    flg = False
    break
  LOOP.append(a)
  s.add(a)
  wk = a
#print(LOOP)
if flg:
  print(sum(LOOP))
else:
  for i in range(len(LOOP)):
    if LOOP[i] == wk:
      beg_i = i
      break
  fin_i = len(LOOP) -1
  ans = sum(LOOP[:beg_i])
  N -= beg_i
  L = LOOP[beg_i:]
  LS = len(L)
  #print(LS)
  ans += sum(L) * (N//LS)
  N = N % LS
  ans += sum(L[:N])
  print(ans)


Measured memory_bytes: 76388
#include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define coord_comp(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define v_index(v, x) (lower_bound(all(v),x)-(v).begin())
typedef pair<int,int> pp;
typedef long long ll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T1,typename T2>
void read(pair<T1,T2>& p){ read(p.first); read(p.second); }
template<typename T,typename... Args>
void read(T&a,Args&...b){ read(a); read(b...); }

ll work(ll sa, ll sb){
	if(sa<sb) swap(sa, sb);
	if(sa % sb == 0){
		return (sa/sb*2 - 1) *1LL* sb;
	} else return (sa/sb)*2*sb + work(sb, sa%sb);
}

int main(){
	ll n, x;
	read(n, x);
	printf("%lld\n", n + work(n-x, x));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N; cin >> N;
	using P = pair<ll,ll>;
	V<P> v(N);
	rep(i,N){
		ll x,l; cin >> x >> l;
		v[i] = P(x-l,x+l);
	}
	sort(all(v),[&](P l,P r){return l.sc < r.sc;});
	ll s = -1e10;
	int ans = 0;
	for(P p: v){
		if(s <= p.fs){
			ans++;s=p.sc;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <iostream>
#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int suma = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 5 != 0 && i % 3 != 0) suma += i;
    }
    cout << suma;
    return 0;
}


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

int top,S[1000];

void push(int x){
	S[++top]=x;
}

int pop(){
	top--;
	
	return S[top+1];
}

int main(void){
	int a,b;
	top=0;
	char s[100];
	
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+' ){
			a=pop();
			b=pop();
			push(a+b);
		}
		else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}else if(s[0]=='*'){
			b=pop();
			a=pop();
			push(a*b);
		}else{
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
        if (A[i] == 0) {
            cout << "0\n";
            return 0;
        }
    }

    ll ans = 1;
    REP(i, N) {
        if (ans >= LONG_MAX / A[i]) {
            cout << "-1\n";
            return 0;
        }
        ans *= A[i];
    }
    if (ans > 1000000000000000000) cout << "-1\n";
    else cout << ans << "\n";
}


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

int main() {
  int n;
  string s,t;
  cin >> n;
  cin >> s >> t;
  int l=0;
  for(int i=1;i<n+1;i++){
    if(s.substr(n-i,i)==t.substr(0,i))l=i;
  }
  cout << 2*n-l;
}






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

using namespace std;

int calc(int A[], int X, int N)
{
    int costN = 0;
    for (int i = X; i <= N; i++)
    {
        costN += A[i];
    }
    
    int cost0 = 0;
    for (int i = X; i >= 0; i--)
    {
        cost0 += A[i];
    }

    return (costN < cost0)? costN: cost0;
}

int main()
{

    int N, M, X;
        
    cin >> N;
    cin >> M;
    cin >> X;
    
    int A[N+1] = {0};
    
    for (int i = 0; i < M; i++)
    {
        int pos;
        cin >> pos;
        A[pos] = 1;
    }
    
    cout << calc(A, X, N) << endl;
}

Measured memory_bytes: 256
n=int(input())
s=[]
for i in range(n):
  s.append(input())
from collections import Counter
zisyo=Counter(s)
ans=[]
a=max(zisyo.values())
for i in zisyo:
  if zisyo[i]==a:
    ans.append(i)

ans.sort()
for i in ans:
  print(i)
    
    

  
  


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

#define int long long
#define mod 1000000007
#define p pair<int,int>
#define MAX 1000010

using namespace std;

map <int,int> m1,m2;
int a[200010];

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

    int n;
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> a[i];

    int ans = 0;
    
    for(int i=0;i<n;i+=2)
        m1[a[i]]++;

    for(int i=1;i<n;i+=2)
        m2[a[i]]++;

    pair<int,int> t1{0,0};
    pair<int,int> t2{0,0};
    pair<int,int> t3{0,0};
    pair<int,int> t4{0,0};

    for(auto i:m1)
    {
        if(t1.second < i.second)
            t1 = i;
    }

    m1.erase(t1.first);

    for(auto i:m1)
    {
        if(t2.second < i.second)
            t2 = i;
    }

    for(auto i:m2)
    {
        if(t3.second < i.second)
            t3 = i;
    }

    m2.erase(t3.first);

    for(auto i:m2)
    {
        if(t4.second < i.second)
            t4 = i;
    }

    if(t1.first == t3.first)
        cout << n - max(t1.second + t4.second, t2.second + t3.second) << endl;
    else
        cout << n - t1.second - t3.second << endl;

    return 0;
}

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

using namespace std;

int main(){
    long long N, ans, m;
    cin >> N;

    ans = 0;

    for(int i = 1; i < int(sqrt(N)) + 10; i++)
    {
        if (N%i == 0){
            m = N/i - 1;
            if (m > 0 && N/m == N%m){
                ans += m;
            }
        }
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    cout << a*(n/(a+b)) + min(a,(n % (a+b))) << endl;
    return 0;
}

Measured memory_bytes: 256
use std::cmp::min;

macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(i64;;);

    let mut sum = 0;
    let mut num0 = 0;
    for (i, &v) in vs.iter().enumerate() {
        sum = if i % 2 == 0 {
            if sum + v >= 0 {
                num0 += sum + v + 1;
                -1
            } else {
                sum + v
            }
        } else {
            if sum + v <= 0 {
                num0 += 1 - (sum + v);
                1
            } else {
                sum + v
            }
        }
    }

    let mut sum = 0;
    let mut num1 = 0;
    for (i, &v) in vs.iter().enumerate() {
        sum = if i % 2 == 1 {
            if sum + v >= 0 {
                num1 += sum + v + 1;
                -1
            } else {
                sum + v
            }
        } else {
            if sum + v <= 0 {
                num1 += 1 - (sum + v);
                1
            } else {
                sum + v
            }
        }
    }
    println!("{}", min(num0, num1));
}


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

int main()
{
    char a,b;
    cin >> a >>b;
    bool boola = a == 'H';
    bool boolb = b == 'H';
    bool result = false;
    if(boola && boolb) result = true;
    else if (boola || boolb) result = false;
    else result = true;


    if(result)
    {
        cout << 'H' << endl;
    }
    else
    {
        cout << 'D' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <cstdlib>
using namespace std;

#define ll long long 

char s[2][55];

const int mod = 1e9 + 7;

int main() {
	
	int n;
	scanf("%d", &n);
	scanf("%s %s", s[0], s[1]);
	
	ll ans;  int up;

	if (s[0][0] == s[1][0]) {
		ans = 3;
		up = 1;
	}
	else {
		ans = 6;
		up = 2;
	}

	for (int i = up; i < n; i ++) {
		if (s[0][i] == s[1][i]) {
			if (s[0][i - 1] == s[1][i - 1])
				 ans = (ans * 2) % mod;
		}
		else {
			if (s[0][i - 1] == s[1][i - 1]) ans = (ans *2) % mod;
			else  ans = ( ans * 3) % mod;
			i++;
		}
		
	}
	
	printf("%lld\n", ans);

	//system("pause");

	return 0;
}
/*
2
aa
bb
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  lol n, k;
  cin >> n >> k;
  lol a[n + 5];
  reps(i, n){
    cin >> a[i];
  }
  bool isvisited[n + 5] = {false};
  lol na = 1, num[n + 5], memo = 0;
  while(!isvisited[na]){
    isvisited[na] = true;
    num[na] = memo;
    memo ++;
    na = a[na];
  }
  if(a[na] == 0){
    k %= memo;
  } else {
    if(k < num[na]){
      ;
    } else {
      //cout << num[na]<< " ";
      memo = memo - num[na];
      k -= num[na];
      k = num[na] + (k % memo); 
    }
  }
  na = 1;
  rep(i, k){
    na = a[na];
  }
  cout << na << '\n';
  return 0;
}


Measured memory_bytes: 6952
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[h,w,d]=i2()
a=[]
for i in range(h):
 s=i2()
 for j in range(w):
  a.append([s[j],[i,j]])
q=i1()
lr=[]
for i in range(q):
 lr.append(i2())
 
a=sorted(a)
f=[0 for i in range(h*w)]
for i in range(h*w-d):
  f[i+d]=f[i]+abs(a[i][1][0]-a[i+d][1][0])+abs(a[i][1][1]-a[i+d][1][1])

for i in lr:
 print(f[i[1]-1]-f[i[0]-1])


Measured memory_bytes: 92892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int ans = 700;
		for (int i = 0; i < s.length();i++) {
			if (s.charAt(i) == 'o') {
				ans += 100;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h> 
using namespace std; 
typedef   long long int ll;
int main () {
    ll n,x,y,k,k1,k2,l,ans;cin>>n>>x>>y;
    ll a[n+1]={0};
    for (ll i=1;i<n;i++) {
      //  cout<<"LOL"<<i<<" "<<endl;
        for (ll j=i+1;j<=n;j++) {
           k=j-i;
           if (j<y) {
              k1=x-i;
              if (k1<0) k1=-k1;
              k2=y-j;
              l=k1+k2+1;
           }
           if (j==y) {
               k1=x-i;
               if (k1<0) k1=-k1;
               l=k1+1;
           }
           if (j>y) {
               k1=j-y;
               k2=x-i;
               if (k2<0) k2=-k2;
               l=k1+k2+1;
           }
          // cout<<k<<"   "<<l<<endl;
           ans=min(k,l);
           a[ans]++;
        }
    }
    for (ll i=1;i<n;i++) {
       cout<<a[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int x;
    cin >> x;
    if(x == 0)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans[ohara],a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll cou[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>k;
    rep(i,50)ans[i]=i;
    rep(i,50){
        ans[i]+=(k/50)*50;
        cou[i]=k/50;
    }
    rep(i,k%50){
        ans[i]+=50;
        cou[i]++;
    }
    rep(i,50){
        ans[i]-=(k-cou[i]);
    }

    Cout(50);
    rep(i,50){
        if(i==49)Cout(ans[i]);
        else cout<<ans[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0){break;}
			System.out.println(Math.min(a, b) + " " + Math.max(a, b));
		}
	}
}



Measured memory_bytes: 36280
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
ll d[20],v[20];
ll ans[20];
void add(int k,ll x,ll y)
{
	if(k==1)
	{
		ans[k-1]=x;
		ans[k]=y;
		return;
	}
	ll g=__gcd(ans[k-1],x);
	//cout << "g :"<<  g << endl;
	ans[k]=y*(ans[k-1]/g);
	for(int i=0;i<k;i++)ans[i]*=(x/g);
}
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			cin >> d[i] >> v[i];
			ll g=__gcd(d[i],v[i]);
			d[i]/=g;
			v[i]/=g;
		}
		for(int i=1;i<n;i++)
		{
			ll A,B;
			A=d[i]*v[i-1];
			B=d[i-1]*v[i];
			ll G=__gcd(A,B);
			A/=G;
			B/=G;
			//cout << A << ' ' << B << endl;
			add(i,A,B);
		}
		for(int i=0;i<n;i++)printf("%lld\n",ans[i]);
		//for(int i=0;i<n;i++)printf("%lld\n",ans[i]/v[i]*d[i]);
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;
    const ll INF = 1e18;
    vector<vector<ll>> dp(n + 1, vector<ll>(3, -INF));
    dp[0][0] = 0;
    dp[1][2] = a[0];
    dp[1][1] = 0;
    repr(i, 2, n + 1) {
        if (i % 2 == 0) chmax(dp[i][0], max(dp[i - 1][2], dp[i - 2][0] + a[i - 1]));
        else {
            chmax(dp[i][1], max(dp[i - 1][0], dp[i - 2][1] + a[i - 1]));
            chmax(dp[i][2], dp[i - 2][2] + a[i - 1]);
        }
    }
    ll ans = 0;
    if (n % 2 == 0) ans = dp[n][0];
    else ans = dp[n][1];
    cout << ans << endl;
}

Measured memory_bytes: 15640