akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


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

int H, W; cin >> H >> W;
VS c(H); rep(i, 0 , H) cin >> c[i];

VVI dist(H, VI(W, -1)); // 始点からの距離
queue<PII> q;
int score = 0; // 黒くしたマスの数

// 最短径路を探して，通ってない白マス数が最大得点になる．
// BFS で最短経路を通ったときのゴールの距離を見つける．
// 始めの白マス数 - 最短経路の距離 が答え．

dist[0][0] = 0; // [0][0] が始点．
q.push(make_pair(0,0));
// BFS
while (!q.empty()) {
    PII v = q.front();
    q.pop();

    rep(i, 0, 4){
        int nh = v.first + dy[i], nw = v.second + dx[i];
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (dist[nh][nw] != -1 || c[nh][nw] == '#') continue;

        dist[nh][nw] = dist[v.first][v.second] + 1;
        q.push(make_pair(nh,nw));
    }
}
// 元の白マス数を数える
rep(i, 0, H){
    rep(j, 0, W){
        if (c[i][j] == '.') ++score;
    }
}
--score;

if (dist[H-1][W-1] == -1) {
    cout << -1 << endl;
    return 0;
}
cout << score - dist[H-1][W-1] << endl;

}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
def main():
    N = int(input())
    A = {i:inp for i, inp in enumerate(map(int, input().split()), 1)}

    for i in range(2, N+1):
        A[i] -= A[i - 1]
    
    const = A[N] // 2
    ret = [str(2 * const)]

    for i in range(1, N):
        if i % 2:
            ret.append(str(2 * (A[i] - const)))
        else:
            ret.append(str(2 * (A[i] + const)))

    ret = ' '.join(ret)
    print(ret)
    

if __name__=="__main__":
    main()

Measured memory_bytes: 26436
#include <stdio.h>
int main(void)
{
    int A;      //A個口の電源タップ
    int B;      //目的の口数
    int ans = 1;    //タップ数
    int tmp;

    scanf("%d", &A);
    scanf("%d", &B);
    
    tmp = A;
    while( tmp < B )
    {
        ans++;
        tmp = tmp + (A - 1);
    }
    
    if( B == 1 )
    {
        ans = 0;
    }
    
    printf( "%d", ans );
}


Measured memory_bytes: 128
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int mp[999][999],w=read(),h=read();

int main(){
int i,j;
for (int n=read();n--;){
  int x=read(),y=read(),op=read();
  switch(op){
    case 1:{
      for (i=0;i<x;++i){
        for (j=0;j<h;++j){
          mp[i][j]=1; 
		  }
	    }
	  break;
	  }
	case 2:{
	  for (i=x;i<w;++i){
	    for (j=0;j<h;++j){
	      mp[i][j]=1;
		  }
	    }
	  break;
	  }
	case 3:{
	  for (i=0;i<w;++i){
	    for (j=0;j<y;++j){
	      mp[i][j]=1;
		  }
	    }
	  break;
	  }
	case 4:{
	  for (i=0;i<w;++i){
	    for (j=y;j<h;++j){
	      mp[i][j]=1;
		  }
	    }
	  break;
	  }
    }
//  for (i=0;i<w;++i,pl){
//    for (j=0;j<h;++j){
//      write(mp[i][j]),p32; 
//	  }
//    }
  }
int ans=0;
for (i=0;i<w;++i){
  for (j=0;j<h;++j) ans+=!mp[i][j]; 
  }write(ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

struct Point{
	int x,y;
};

const Point dir[4] = {{1,0},{0,1},{-1,0},{0,-1}};

int w,h;
char map[20][20];
bool visited[20][20];//訪問済みならtrue
int cnt;//黒いタイルを数えるカウンタ

bool inField(Point p){
	return 0<=p.x && p.x < w && 0<=p.y && p.y < h;
}

//幅優先探索
void dfs(Point pos){
	cnt++;
	visited[pos.y][pos.x] = true;
	for(int i=0;i<4;i++){
		Point next = {pos.x+dir[i].x, pos.y+dir[i].y};
		if(inField(next)==true){
			if(visited[next.y][next.x] == false && map[next.y][next.x] == '.'){
				dfs(next);
			}
		}
	}
}

int main(){
	while(true){
		cin >> w >> h;
		if(w==0){
			break;
		}
		Point init;//初期位置
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> map[i][j];
				visited[i][j] = false;
				if(map[i][j] == '@'){
					//初期代入以外はキャストする必要がある。
					init = (Point){j,i};
					map[i][j] = '.';
				}
			}
		}
		cnt = 0;
		dfs(init);
		cout << cnt << endl;
	}
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
import sys
from math import gcd
from functools import reduce

input = sys.stdin.readline

ub = 10 ** 6

smallest_prime_factor = list(range(ub + 1))
for p in reversed(range(2, len(smallest_prime_factor))):
    if p == smallest_prime_factor[p]:
        for i in range(2 * p, len(smallest_prime_factor), p):
            smallest_prime_factor[i] = p


n = int(input())
a = list(map(int, input().split()))

ans = ""
prime_factors = set()
for ai in a:
    tmp = ai
    while tmp != 1:
        p = smallest_prime_factor[tmp]
        if p in prime_factors:
            break
        prime_factors.add(p)
        while tmp % p == 0:
            tmp //= p
    else:
        continue
    break
else:
    ans = "pairwise coprime"

if ans == "":
    if reduce(gcd, a) == 1:
        ans = "setwise coprime"
    else:
        ans = "not coprime"
print(ans)

Measured memory_bytes: 189932
#include <bits/stdc++.h>
using namespace std;
const long long INFL=1LL << 60;
const long long INF=1<<29;

int main() {
    int N;
    cin >>N;
    vector<long long> A(N);
    int plus=1;
    cin>>A.at(0);
    long long ans=abs(A.at(0));
    long long Amin=abs(A.at(0));
    for(int i=1;i<N;i++){
        long long temp;
        cin >>temp;
        if(temp<0){
            temp=-temp;
            plus=1-plus;
        }
        ans+=temp;
        Amin=min(Amin,temp);
    }
    if((A.at(0)>=0)==plus) cout <<ans<<endl;
    else cout << ans-2*min(abs(A.at(0)),Amin);
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int main(){
    string s;
    cin >> s;
    string before = "AIZUNYAN";
    string after = "AIDUNYAN";
    sort(after.begin(), after.end());
    for(int i = 0; i + after.size() <= s.size(); i++){
        string t = s.substr(i, after.size());
        sort(t.begin(), t.end());
        if(after == t){
            for(int j = 0; j < after.size(); j++){
                s[i + j] = before[j];
            }
            i += after.size() - 1;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1208
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N,C,K;
    vector<ll> t;
    cin >> N >> C >> K;

    int x;
    for (int i = 0; i < N; i++){
        cin >> x;
        t.push_back(x);
    }

    sort(all(t));

    int bn = 0;
    for (int i = 0; i < N; i++){
        int minn = t[i];
        int np = 1;
        for (int k = i + 1; k < N; k++){
            if (t[k] <= minn + K && np < C){
                np++;
            } else {
                i = k-1;
                break;
            }
            i = k;
        }
        bn++;
    }
    cout << bn << endl;

}


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

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define print(x) printf("%d ", x);
#define println(x) printf("%d\n", x);
#define printarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1]);

void bubblesort(int *a, int n);

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,0,n-1) cin >> a[i];

    bubblesort(a,n);

    return 0;
}

void bubblesort(int *a, int n) {
    int swapcount = 0;
    int flag = 1;
    while(flag == 1) {
        flag = 0;
        per(i,n-1,1) {
            if(a[i] < a[i-1]) {
                swap(a[i],a[i-1]);
                flag = 1;
                swapcount++;
            }
        }
    }

    printarray(a,n);
    cout << swapcount << endl;

}



Measured memory_bytes: 3248
/* ex4_3
  bonbonc */

#include<stdio.h>
int solve(int diff,int west_height);//プロトタイプ宣言

int main(void){
	int west_height,east_height,diff,total_height;
	scanf("%d%d",&west_height,&east_height);
	diff = east_height-west_height;//西の塔と東の塔の高さの差

	printf("%d",solve(diff,west_height));

	return 0;
}

int solve(int diff,int west_height){
	int real_west_height;//西の塔の地面からの高さ
	real_west_height = diff*(diff-1)/2;//西の塔はdiff-1番目の塔なのでこの式で地面からの高さが求まる。

	return real_west_height-west_height;//地面からの高さと雪の上に出ている部分の高さの差を返す。
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin >> t;
	int c = 0;
	int n;
	vector <int> v;
	while(t--){
		cin >> n;
		v.push_back(n);
	}
	int p = v.size();
	for(int i=0;i<p;i++){
		int d = i+1;
		int f = v[i]*v[i];
		if((d%2==1) && (f%2==1)){
			c++;
		}
	}
	cout << c << endl;
		
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=10000005,mod=998244353;
int fac[N],rev[N],n,ans,res;

int power(int x,int p){
	int res=1;
	for(;p;p>>=1,x=(ll)x*x%mod)
		if(p&1) res=(ll)res*x%mod;
	return res;
}
int mul(int x,int y){
	return (ll)x*y%mod;
}
void add(int &x,int y){
	x=(x+y>=mod?x+y-mod:x+y);
}

int C(int n,int m){
	return m<0||n<m?0:mul(fac[n],mul(rev[m],rev[n-m]));
}
void init(int n){
	fac[0]=1;
	rep(i,1,n) fac[i]=mul(fac[i-1],i);
	rev[n]=power(fac[n],mod-2);
	per(i,n,1) rev[i-1]=mul(rev[i],i);
}

int main(){
	read(n);
	init(n);

	ans=res=1;
	per(c,n-1,0){
		res=mul(res,2);
		if(c<n/2){
			add(res,mod-mul(2,C(n-c-1,(n-2*c)/2-1)));
			//cout<<n<<" "<<c<<"  "<<n-c<<"   "<<res<<endl;
		}
		add(ans,mul(C(n,c),res));
	}
	cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 78336
#include<stdio.h>
int aa[60];
main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int i;
		for(i=0;i<n;i++)
		{
			scanf("%d",&aa[i]);
		}
		int q,sum=0;
		for(q=0;q<n-1;q++)
		{
			for(i=q+1;i<n;i++)
			{
				sum=sum+aa[i]*aa[q];
			}
		}
		printf("%d\n",sum);
		
	}
}

Measured memory_bytes: 128
s = input()

for i in range(len(s)):
    #print(i)
    #print(s[i])
    if (i + 1) % 2 == 0 and s[i] not in 'LUD':
        print('No')
        exit()
    if (i + 1) % 2 == 1 and s[i] not in 'RUD':
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 39856
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    map<string, bool> mp;
    for(lint i=0; i<n; i++) {
        string s;
        cin >> s;
        mp[s] = true;
    }

    cout << mp.size() << endl;
}

Measured memory_bytes: 19228
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i]==s[i+1])
		{
			cout<<i+1<<' '<<i+2<<endl;
			return 0;
		}
	}
	for(int i=0;i<s.size()-2;i++)
	{
		if(s[i]==s[i+2])
		{
			cout<<i+1<<' '<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<' '<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, a, i, c1=0, c2=0, c4=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		if(a%4==0)
			c4++;
		else if(a%2==0)
			c2++;
		else
			c1++;
	}
	if(c2>0 && c4>=c1 || c2==0 && c4>=c1-1)
    {
		cout<<"Yes"<<endl;
    }
	else
    {
		cout<<"No"<<endl;
    }
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int n = kbd.nextInt();
        int k = kbd.nextInt();
        String temp = kbd.next();
        String[] arr = temp.split("");
        arr[k - 1] = arr[k - 1].toLowerCase();
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i]);
        }
        System.out.println();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>

using namespace std;

int nrc(int a)
{
    int nr = 0;
    while (a > 0)
    {
        ++nr;
        a /= 10;
    }
    return nr;
}

int main()
{
    int a, b, nr, x;
    cin >> a >> b;
    nr = nrc(b);
    while (nr > 0)
    {
        a *= 10;
        --nr;
    }
    a += b;
    x = (int) sqrt(a);
    if (x * x == a)
        cout << "Yes ";
    else
        cout << "No ";
    return 0;
}


Measured memory_bytes: 256
$s = <STDIN>;
chomp $s;
$N = length $s;
$flag = 0;
$A =  $s;
$B = reverse($A);
if($A ne $B ){$flag = 1;}

$T = ($N-1)/2;
$A =  substr($s, 0, $T);
$B = reverse($A);
if($A ne $B ){$flag = 1;}

$S = ($N+3)/2;
$A =  substr($s, $S-1, $T);
$B = reverse($A);
if($A ne $B ){$flag = 1;}

if($flag == 0 ){
  print "Yes";
}else{
  print "No";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


// 入力
int N;
ll h[100010];

// DP テーブル
ll dp[100010];

int main() {
    int N; cin >> N;
    rep1(i, N) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    rep1(i, 100010) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    rep1(i, N) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}


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

using namespace std;

typedef pair<int,int> Point;
const double epx = 1e-10;
const int N = 1e5+10;
int tot = 2;
Point rs[N];

double cross(Point b,Point a,Point c)
{
    return (b.first-a.first)*(c.second-a.second)-(b.second-a.second)*(c.first-a.first);
}

void getConvexHull(vector<Point> &points,int sz)
{
    sort(points.begin(),points.end());
    rs[0] = points[0];
    rs[1] = points[1];

    for(int i=2;i<sz;i++)
    {
        while(tot>=2&&cross(rs[tot-2],rs[tot-1],points[i])<-epx) tot--;
        rs[tot++] = points[i];
    }
    for(int i=sz-2;i>=0;i--)
    {
        while(tot>=2&&cross(rs[tot-2],rs[tot-1],points[i])<-epx) tot--;
        rs[tot++] = points[i];
    }
}

int main()
{
    int n;
    cin>>n;
    vector<Point> points;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        points.emplace_back(y,x);
    }

    getConvexHull(points,n);

    cout<<tot-1<<endl;
    for(int i=0;i<tot-1;i++)
    {
        cout<<rs[i].second<<" "<<rs[i].first<<endl;
    }

    return 0;
}



Measured memory_bytes: 4008
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    if((a < c and c < b) or (a > c and c > b)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mk make_pair
#define ll long long


signed main(){
  ios::sync_with_stdio(NULL);
  cin.tie(nullptr);
  //freopen("in", "r", stdin);
  //freopen("../out.txt", "w", stdout);
  string a,b;
  cin>>a>>b;
  int ans=0;
  for(int i=0;i<3;++i)
  	if(a[i]==b[i])ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
        for j in range(b+1):
                for k in range(c+1):
                        if i*500+j*100+50*k==x:
                                ans+=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,c,d,p;
  cin >> a >> b >> c >> d >> p;
  int x,y;
  x=a*p;
  y=b;
  if(p>c)y+=(p-c)*d;
  
  cout << min(x,y) << endl;
}



Measured memory_bytes: 3184
#include <stdio.h>
int a, b, c, x;
int main() {
	scanf("%d%d%d", &a, &b, &c);
	if (a < c && b < c)x = a * b;
	if (a < b && c < b)x = a * c;
	if (b < a && c < a)x = b * c;
	printf("%d\n", x / 2);
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int L = a + b;
  int R = c + d;
  if (L > R)
    cout << "Left" << endl;
  else if (L == R)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

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

int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    long long ans=0;
    long long sum=a[0];
    if(sum <= 0){
        ans = -sum+1;
        sum = 1;
    }
    for(int i=1; i<n; i++){
        if(sum*(sum+a[i]) >= 0){
            ans += abs((sum+a[i])-(-sum/abs(sum)));
            sum = -sum/abs(sum);
        }
        else sum+=a[i];
    }
    long long t = 0;
    sum = a[0];
    if(sum >= 0){
        t = sum+1;
        sum = -1;
    }
    for(int i=1; i<n; i++){
        if(sum*(sum+a[i]) >= 0){
            t += abs((sum+a[i])-(-sum/abs(sum)));
            sum = -sum/abs(sum);
        }
        else sum+=a[i];
    }
    ans = min(t,ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int mx_ad=-1e9;
    int gv[200005];
    for(int i=0;i<n;i++) cin>>gv[i];
    int mn_num=gv[0];
    for(int i=1;i<n;i++){
        mn_num=min(gv[i-1],mn_num);
        mx_ad=max(mx_ad,gv[i]-mn_num);
        //if(mx_ad==0) cout<<gv<<" "<<mn_num<<endl;
    }
    cout<<mx_ad<<endl;
    return 0;
}




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

typedef long long ll;
ll H;

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

    cin >> H;

    ll ans = 0, n = 1;
    while(1) {
        if(H == 1) break;

        H /= 2;
        ans += n;
        n *= 2;
    }

    cout << ans + n << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	double w;
	double h;
	double x;
	double y;
		cin >> w >> h >> x >> y;
		cout << w*h / 2;



	cout << " ";
	if (2*x == w && 2*y==h)
		cout << 1;
	else cout << 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
  int h,w;
  char c[101][101];
  scanf("%d %d",&h,&w);
  while(h != 0 && w != 0){
    for(int i=0;i<h;i++){
      scanf("%s",c[i]);
    }
    int x=0,y=0;
    while(c[y][x] != '.'){
      
      if(c[y][x] == '0'){
	printf("LOOP\n");
	break;
      }else if(c[y][x] == '>'){
	c[y][x] = '0';
	x++;
      }else if(c[y][x] == '<'){
	c[y][x] = '0';
	x--;
      }else if(c[y][x] == '^'){
	c[y][x] = '0';
	y--;
      }else if(c[y][x] == 'v'){
	c[y][x] = '0';
	y++;
      }
    }
    if(c[y][x] != '0') printf("%d %d\n",x,y);
    scanf("%d %d",&h,&w);
  }
  return (0);
}

Measured memory_bytes: 2576
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n=0;
    int i=0;
    int k=0;
    long S[101];
    int T1=0;
    int T2=0;
    bool flug=true;
    int count=0;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>S[i];
        
    }
    
    while (flug==true)
    {
        flug=false;
        for (k=n;k>=2;k--)
        {
            if (S[k]<S[k-1])
            {
                T1=S[k];
                T2=S[k-1];
                S[k]=T2;
                S[k-1]=T1;
                flug=true;
                count++;
            }
        }
    }
    
    for (i=1;i<n;i++)
    {
        
        cout<<S[i]<<" ";
    }
    cout<<S[n]<<endl;
    cout<<count<<endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

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

  rep(i,s.size()) {
    s[i] += n;
    s[i] -= 'A';
    s[i] %= 'Z' - 'A' + 1;
    s[i] += 'A';
  }

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

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


int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i=1; i*i<n; i++)if(n%i==0 && (n/i)-1>i){
    ans += (n/i)-1;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int ans = 1;
  int num = 2;
  while (n >= k) {
    ans += 1;
    n = n / k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define se second
typedef long long ll;
const int maxn = 200005;
typedef pair<int, int>par;
const ll mod = 1e9+7;

int t[maxn][100];

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in", "r",stdin);
    #endif // acm


    int n;
    ll k;

    cin >> n >> k;

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

    for( int i = 1; i <= 62; i++ ){
        for( int j = 1; j <= n; j++ ){
            t[j][i] = t[ t[j][i-1] ][i-1];
        }
    }


    int nod = 1;
    for( int i = 62; i >= 0; i-- ){
        if( k - (1ll << i) >= 0 )
            k -= (1ll << i), nod = t[nod][i];
    }

    cout << nod << "\n";


    return 0;
}


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

int main() {
  
  int N;
  cin >> N;
  
  int sum =0;
  
  for(int i=0; i<N; i++){
    
      int L,R;
    
    cin >> L >> R;
    sum += R-L+1;
  }
  
  cout << sum;
}

Measured memory_bytes: 256
// abc154_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    set<int> st;
    REP(i, N){
        int x;
        cin >> x;
        st.insert(x);
    }

    if (st.size() == N){
        print("YES");
    } else {
        print("NO");
    }


    return 0;
}


Measured memory_bytes: 9600
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

class Main{
	static int[] dp;
	static LinkedList<Integer>[] graph;
	static int rec(int v) {
		if(dp[v] != -1) return dp[v];

		int ret = 0;
		for(int u : graph[v]) {
			ret = Math.max(ret, rec(u) + 1);
		}
		return dp[v] = ret;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int N = sc.nextInt(), M = sc.nextInt();
			graph = new LinkedList[N];
			for(int i = 0; i < N; i++) graph[i] = new LinkedList<Integer>();
			for(int i = 0; i < M; i++) {
				int x = sc.nextInt(), y = sc.nextInt();
				graph[x - 1].add(y - 1);
			}
			dp = new int[N];
			Arrays.fill(dp, -1);
			int ans = 0;
			for(int i = 0; i < N; i++) ans = Math.max(ans, rec(i));
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 98292
#include <stdio.h>
#include <string.h>

#define MAX_N 100

void init(int*,int[10][4]);
int getMark(char);
int selectionSort(char*,int*,int,int[10][4]);
int bubbleSort(char*,int*,int,int[10][4]);
void print(char*,int*,int,int);

int main(){
  int idx[10],data[10][4];
  int N,A[MAX_N],A2[MAX_N],i,isStable;
  char M[MAX_N],M2[MAX_N],ch;

  init(idx,data);

  scanf("%d%c",&N,&ch);
  for(i = 0 ; i < N ; i++){
    scanf("%c%d%c",&M[i],&A[i],&ch);
    M2[i] = M[i];
    A2[i] = A[i];
    data[A[i]][idx[A[i]]++] = getMark(M[i]);
  }
  isStable = bubbleSort(M,A,N,data);
  print(M,A,N,isStable);
  isStable = selectionSort(M2,A2,N,data);
  print(M2,A2,N,isStable);
  return 0;
}

void init(int *idx,int data[10][4]){
  int i,j;
  for(i = 0 ; i < 10 ; i++){
    idx[i] = 0;
    for(j = 0 ; j < 4 ; j++){
      data[i][j] = -1;
    }
  }
}

int getMark(char M){
  if(M == 'H'){ return 0; }
  if(M == 'C'){ return 1; }
  if(M == 'S'){ return 2; }
  if(M == 'D'){ return 3; }
  return -1;
}

int selectionSort(char *M,int *A,int N,int data[10][4]){
  int i,j,temp,min,idx,cur[10],isStable = 1;
  char temp2;
  memset(cur,0,sizeof(cur));
  for(i = 0 ; i < N ; i++){
    min = A[i]; idx = i;
    for(j = i+1 ; j < N ; j++){
      if(A[j] < min){
        min = A[j];
        idx = j;
      }
    }
    if(A[idx] < A[i]){
      temp = A[i];
      A[i] = A[idx];
      A[idx] = temp;
      temp2 = M[i];
      M[i] = M[idx];
      M[idx] = temp2;
    }
  }
  for(i = 0 ; i < N ; i++){
    if(data[A[i]][cur[A[i]]] != getMark(M[i])){
      isStable = 0;
      break;
    }
    ++cur[A[i]];
  }
  return isStable;
}

int bubbleSort(char *M,int *A,int N,int data[10][4]){
  int i,j,temp,cur[10],isStable = 1;
  char temp2;
  memset(cur,0,sizeof(cur));
  for(i = 0 ; i < N ; i++){
    for(j = N-1 ; j > i ; j--){
      if(A[j-1] > A[j]){
        temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;
        temp2 = M[j];
        M[j] = M[j-1];
        M[j-1] = temp2;
      }
    }
  }
  for(i = 0 ; i < N ; i++){
    if(data[A[i]][cur[A[i]]] != getMark(M[i])){
      isStable = 0;
      break;
    }
    ++cur[A[i]];
  }
  return isStable;
}

void print(char *M,int *A,int N,int isStable){
  int i;
  for(i = 0 ; i < N ; i++){
    printf("%c%d%c",M[i],A[i],(i < N-1 ? ' ' : '\n'));
  }
  if(isStable == 1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }
}

Measured memory_bytes: 612
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<map>
#include<cstdio>
using namespace std;
char s[15];
int mod=19260817,base=31,vis[500],Num;
int n,m,num[10000000];
int hashe(char t[])
{
    int len=strlen(t);
    int ans=0;
    for (int i=0;i<len;i++)
    ans+=t[i]*31%mod+ans/17;
    return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		int now=hashe(s);
		vis[++Num]=now;
		num[now]++;
	}	
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		cin>>s;
		num[hashe(s)]--;
	}
	int Max=0;
	for(int i=1;i<=Num;i++)
	{
		Max=max(Max,num[vis[i]]);
	}
	cout<<Max;
	return 0;
}

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

typedef long long ll;
#define mod 1000000000


int main() 
{
   string s,t;
   cin>>s>>t;
   ll m=s.size();
   ll n=t.size();
   ll ans=n;
   for(ll i=0;i<=m-n;i++)
   {
      ll count=0;
      for(ll j=0;j<n;j++)
      {
         if(s[i+j]!=t[j])  count++;
      }
      ans=min(ans,count);
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3628
main :: IO()
main = do
    getLine
    s <- getLine
    k <- readLn
    putStrLn $ rePut s (s !! (k - 1))
    
rePut :: String -> Char -> String
rePut str moji
    | str == []					= []
    | head str /= moji			= "*" ++ rePut (tail str) moji
    | otherwise					= (head str):rePut (tail str) moji

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    if(abs(a-b) <= (v-w)*t) print("YES");
    else print("NO");
    return 0;
}

Measured memory_bytes: 3660
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl B(N-1); rep(i, N-1) cin >> B[i];
    
    vl A(N, 0);
    A[0] = B[0]; A[N-1] = B[N-2];
    FOR(i, 1, N-1){
        A[i] = min(B[i-1], B[i]);
    }
    ll ans = 0;
    rep(i, N) ans += A[i];
    cout << ans << endstr;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<ll > ruiseki;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
ll N, M;

//3手先まで読んで判断する
//負けても減点にはならない
int main() {

    ll N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;

    map<char, ll > mp;
    mp['r'] = R;
    mp['s'] = S;
    mp['p'] = P;

    //R=ぐー　S=ちょき　P=ぱー
    string T;
    cin >> T;

    //自分の出した手
    vector<char > hoge(N);

    ll ans = 0;
    for(ll i = 0; i < K; i++){
        ll cn = 0;
        for(ll j = i; j < N; j += K){
            //cout << cn << endl;
            if(j != i){
                //cout << "koko" << endl;
                if(T[j] == T[j-K]){
                    if(cn % 2 == 1){
                        hoge[j] = '*';
                        //cout << "same" << endl;
                        cn++;
                        continue;
                    }
                }else{
                    cn = 0;
                }
            }
            if(T[j] == 'r'){
                //グーを出されたらパーで勝つ
                ans += P;
                hoge[j] = 'p';
            }else if(T[j] == 's'){
                //チョキを出されたらグーで勝つ
                ans += R;
                hoge[j] = 'r';
            }else if(T[j] == 'p'){
                //パーを出されたらチョキで勝つ
                ans += S;
                hoge[j] = 's';
            }
            cn++;
        }
    }

    ll ans2 = 0;
    for(ll i = 0; i < N; i++){
        //cout << hoge[i] << " ";
        ans2 += mp[hoge[i]];
    }
    //cout << endl;

    cout << ans2 << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

ll d(ll a)
{
    ll ret = 0;
    while (a > 0)
    {
        a /= 10;
        ret++;
    }
    return ret;
}

// C++ゆるさねえリスト
// accumulate(all(a), 0LL);
// 二分探索

int main()
{
    ll a, b, ans;
    cin >> a >> b;

    ans = lcm(a, b);

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


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

struct Card{char suit,value;};

void bubble(struct Card A[],int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i;j--){
      if(A[j].value< A[j-1].value){
	Card t = A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}

void selection(struct Card A[],int N){
  for(int i=0;i<N;i++){
    int minj = i;
    for(int j=i;j<N;j++){
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[],int N){
  for(int i=0;i<N;i++){
    if(i>0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[], int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0;i<N;i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

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

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

int main(void){
	          ll i;

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

	          ll N,M;
	          string S,T;

	          cin >> N >> M ;
	          cin >> S >> T;

	          for(i=1;i<=N;i++){
	        	  if(M*(i-1LL)%N==0LL){
	        		  ll j=M*(i-1LL)/N+1LL;
	        		  if(j>=1LL && j<=M){
	        			  if(S[i-1LL]!=T[j-1LL]){
	        				  cout << -1 << endl;
	        				  return 0;
	        			  }
	        		  }
	        	  }
	          }

	          ll ans=lcm(N,M);

	          cout << ans << endl;

	          return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    int N,b;
    cin>>N;
    int a[N];
    rep(0,i,N){
        cin>>b;
        a[b-1]=i+1;
    }
    rep(0,i,N)cout<<a[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
typedef long long int lli;
const int lim = 1e9+7;

lli n,a,b;
bool judge(lli num, vector<lli> h){
	REP(i, n) h[i] -= b*num;
	lli diff = a-b;
	REP(i, n){
		if(h[i] <= 0) continue;
		if((h[i]+diff-1)/diff > num) return false;
		num -= (h[i]+diff-1)/diff;
	}
	return true;
}

int main(){
	cin >> n >> a >> b;
	vector<lli> h(n);
	REP(i, n) cin >> h[i];
	lli l=0, u=lim;
	while(l < u){
		lli mid = (l+u)/2;
		if(judge(mid, h)){
			u = mid;
		}else{
			l = mid+1;
		}
	}
	cout << l << endl;
	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++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 irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
vpll G[100005];
ll dist[100005];
ll q,k;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  rep(i,n-1){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }
  cin>>q>>k;
  k--;
  
  priority_queue<pll, vector<pll>, greater<pll>> que;
  que.emplace(0,k);
  fill(dist,dist+n,LINF);
  dist[k]=0;
  while(!que.empty()){
    auto p=que.top(); que.pop();
    ll v=p.second, c=p.first;
    if(dist[v]<c) continue;
    for(auto np: G[v]){
      ll nv=np.first, nc=np.second;
      if(chmin(dist[nv],dist[v]+nc)){
        que.emplace(dist[nv],nv);
      }
    }
  }
  
  rep(i,q){
    ll x,y; cin>>x>>y; x--,y--;
    cout<<dist[x]+dist[y]<<endl;
  }
  
}

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

enum
{
	N_MAX = 100000,
};

int red[N_MAX] = { 0 };
int num[N_MAX] = { 0 };

int main()
{
	int n, m, x, y;
	
	cin >> n >> m;
	
	red[0] = 1;
	for (int i = 0; i < n; i++)
	{
		num[i] = 1;
	}
	

	for (int i = 0; i < m; i++)
	{
		cin >> x >> y;
		x--;
		y--;
		if ( red[x] != 0 )
		{
			red[y] = 1;
			if ( num[x] == 1 )
			{
				red[x] = 0;
			}
		}
		num[x]--;
		num[y]++;
	}
	
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cnt += red[i];
	}
	
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 1024
n, a, b = map(int, input().split())
mod = 10**9+7
def nCr(N, R, mod):
	R = min(R, N-R)
	numer = denom = 1
	for i in range(1, R+1):
		numer = numer * (N+1-i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod-2, mod) % mod


ans = pow(2,n,mod)
ans -= 1
ans -= nCr(n,a,mod)
ans %= mod
ans -= nCr(n,b,mod)
ans %= mod
print (ans)

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

int main(){
    int n;
    while(cin >> n, n){
        int cnt = 0, input;
        bool able = false;
        
        for(int i = 0; i < n; i++){
            cin >> input;
            if(input > 1)   able = true;
            if(input > 0)   cnt++;
        }
        
        if(able)    cout << cnt+1 << endl;
        else        cout << "NA" << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}
int main()
{
    vok();
    int n;
    IN n;
    string s;
    IN s;
    ll mod1=0, mod2=0;
    ll val1=0, val2=0;
    loop(i,0,n)
    {
        if(s[i]=='1')
        {
            mod1++;
            mod2++;
        }
    }
    mod1++, mod2--;
    if(mod1==1 && mod2==-1)
    {
        loop(i,0,n)
        {
            OUT 1<<endl
        }
        return 0;
    }
    loop(i,0,n)
    {
        if(s[i]=='1')
        {
            val1+=P(2,n-i-1,mod1);
            val1%=mod1;
            if(mod2!=0)
            {
                val2+=P(2,n-i-1,mod2);
                val2%=mod2;
            }
        }
    }
    loop(i,0,n)
    {
        if(s[i]=='1')
        {
            if(mod2==0)
            {
                OUT 0<<endl
                continue;
            }
            ll temp=val2;
            temp-=P(2,n-i-1,mod2);
            temp%=mod2;
            temp+=mod2;
            temp%=mod2;
            int ans=1;
            while(temp!=0)
            {
                temp%=set_bits(temp);
                ans++;
            }
            OUT ans<<endl
        }
        else
        {
            ll temp=val1;
            temp+=P(2,n-i-1,mod1);
            temp%=mod1;
            temp+=mod1;
            temp%=mod1;
            int ans=1;
            while(temp!=0)
            {
                temp%=set_bits(temp);
                ans++;
            }
            OUT ans<<endl
        }
    }
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
const int INF = 0x3f3f3f3f;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            ++cnt;
        }
    }
    if (cnt > n - cnt) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256