akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   
    int A = sc.nextInt();
    int B = sc.nextInt();
    int ans = A*B;
    if(A<10 && B<10){
    	System.out.println(ans);
    }else{
    	System.out.println(-1);
    }
        
    }
}

Measured memory_bytes: 23892
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int r,c; 
    cin>>r>>c; 
    string s[r];
    for (int i=0;i<r;i++) cin>>s[i];
    for (int i=0;i<r;i++) cout << s[i] << endl << s[i] << endl ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n, i, ans=0, l=2;
    int a[300005];
    cin>>n;
    for(i=0; i<3*n; i++)
        cin>>a[i];
    sort(a, a+(3*n));
    for(i=0; i<n; i++)
    {
        ans+=a[3*n-l];
        l+=2;
    }
    cout<<ans;
}


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll X) {
  ll ans;
  if (X <= 599)
    ans = 8;
  else if (X <= 799)
    ans = 7;
  else if (X <= 999)
    ans = 6;
  else if (X <= 1199)
    ans = 5;
  else if (X <= 1399)
    ans = 4;
  else if (X <= 1599)
    ans = 3;
  else if (X <= 1799)
    ans = 2;
  else
    ans = 1;

  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


Measured memory_bytes: 3744
#include <iostream>
using namespace std;
int main() {
	int N;
	int A[200];
	int res = 0;
	int even_flag = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];
	for (int i = 0; i < N; ++i) even_flag += A[i]%2;

    while (even_flag == 0) {
	    ++res;
	    for (int i = 0; i < N; ++i) A[i] /= 2 ;
     	for (int i = 0; i < N; ++i) even_flag += A[i]%2;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a;
    double b,c;
    scanf("%d",&a);
    
     if(1 == a%2){
         b= a/2+1;
     }
     else{
         b =a/2;
     }
    c = b/a;

    printf("%lf",c);

    return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	xs := make([]float64, n)
	us := make([]string, n)
	for i := range xs {
		fmt.Scanf("%f %s\n", &xs[i], &us[i])
	}

	var r float64
	for i, x := range xs {
		if us[i] == "JPY" {
			r += x
		} else {
			r += x * 380000
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>

#define rep(i, j) for(int i = 0; i < j; i++)
// sp_rep
#define sp_rep(i, j) for(int i = 1; i <= j; i++)
#define all(i) i.begin(), i.end()
#define ll long long

using namespace std;

string Num2Str(int num)
{
	stringstream ss;
	ss << num;
	return ss.str();
}

int w, h, cnt;
char maze[20][20];
bool reached[20][20];

void serch(int x, int y) {
	if (x < 0 || w <= x || y < 0 || h <= y || maze[y][x] == '#') return;
	if (reached[y][x])return;
	reached[y][x] = true;
	cnt++;

	serch(x + 1, y);
	serch(x - 1, y);
	serch(x, y + 1);
	serch(x, y - 1);
}

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

	// code
	while (true) {
		cin >> w >> h;
		if (w == 0 && h == 0)break;
		cnt = 0;
		memset(reached, false, sizeof(reached));
		int sx, sy;
		rep(y, h) {
			rep(x, w) {
				cin >> maze[y][x];
				if (maze[y][x] == '@') {
					sx = x;
					sy = y;
				}
			}
		}
		serch(sx, sy);
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};
typedef vector<vector<Edge> > Graph;

bool DFS(const Graph& g,int cur,vi& vis,vi& match)
{
	foreach(e,g[cur]){
		if(vis[e->dst])
			continue;
		vis[e->dst]=1;
		if(match[e->dst]==-1 || DFS(g,match[e->dst],vis,match)){
			match[e->src]=e->dst;
			match[e->dst]=e->src;
			return true;
		}
	}
	return false;
}

int BipertiteMatching(const Graph& _g)
{
	int size=_g.size();
	Graph g=_g;
	rep(i,size) foreach(e,_g[i])
		g[e->dst].push_back(Edge(e->dst,e->src));
	
	vi vis(size),match(size,-1);
	int res=0;
	rep(i,size)
		if(match[i]==-1){
			fill(all(vis),0);
			res+=DFS(g,i,vis,match);
		}
	return res;
}

int main()
{
	for(int m,n;~scanf("%d%d",&m,&n) && m|n;){
		vi rs(m),bs(n);
		rep(i,m) scanf("%d",&rs[i]);
		rep(i,n) scanf("%d",&bs[i]);
		
		Graph g(m+n);
		rep(i,m) rep(j,n) if(__gcd(rs[i],bs[j])>1)
			g[i].push_back(Edge(i,m+j));
		int res=BipertiteMatching(g);
		printf("%d\n",res);
	}
	
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[100010][3];
ll dp[100010][3];

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

  cin>>n;
  rep(i,n)rep(j,3)cin>>a[i][j];
  rep(i,n)rep(j,3)dp[i][j]=-INF;
  rep(j,3)dp[0][j]=a[0][j];
  repl(i,1,n){
    rep(j,3){
      rep(k,3){
        if(j==k)continue;
        maxch(dp[i][k],dp[i-1][j]+a[i][k]);
      }
    }
  }
  ll res=0;
  rep(j,3)maxch(res,dp[n-1][j]);
  cout<<res<<endl;

  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

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

int main() {
    string s; cin >> s;
    ll cur = 0, pw = 1, ans = 0;
    vi cnt(2020);
    cnt[0] = 1;
    ROF(i, sz(s) - 1, 0) {
        (cur += pw * (s[i] - '0')) %= 2019;
        (pw *= 10) %= 2019;
        ans += cnt[cur];
        cnt[cur]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] t = new int[N + 1];
        int[] v = new int[N + 1];
        for (int i = 0; i < N; i++) {
            t[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            v[i] = sc.nextInt();
        }
        for (int i = N - 1; i >= 0; i--) {
            v[i] = Math.min(v[i], v[i + 1] + t[i]);
        }
        double x = 0;
        double vc = 0;
        for (int i = 0; i < N; i++) {
            double vn = v[i + 1];
            if (v[i] < vn) {
                vn = v[i];
            }
            if (vc + t[i] < vn) {
                double vmax = vc + t[i];
                x += vmax * t[i];
                x -= (vmax - vc) * (vmax - vc) / 2;
                vc = vc + t[i];
            } else {
                double vmax = Math.min(v[i], (vc + vn + t[i]) / 2);
                x += vmax * t[i];
                x -= ((vmax - vc) * (vmax - vc) + (vmax - vn) * (vmax - vn)) / 2;
                vc = vn;
            }
        }
        System.out.println(x);
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MX = 400010;

int H, W, h, w, g[510][510];

const int INF = 1e8;

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> H >> W >> h >> w;
	if (H % h == 0 && W % w == 0) {
		puts("No");
		return 0;
	}
	puts("Yes");
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W;j++){
			if(j)
				printf(" ");
			if(i%h == h-1 && j%w == w-1){
				printf("%d", -INF-1);
			}else if(i%h == 0 && j%w == 0){
				printf("%d", INF);
			}else{
				printf("%d", 0);
			}
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2816
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long X = sc.nextLong();
		long Y = sc.nextLong();
		int ans = 1;
		
		while(X<<1 <= Y) {
			X <<= 1;
			ans++;
		}
		
		System.out.println(ans);
				
		sc.close();
	}
}


Measured memory_bytes: 23124
#include<stdio.h>
int main(void){
    int a,b,N,i,ren = 0;
    scanf("%d",&N);
    
    for(i = 0;i < N;i ++){
        scanf("%d %d",&a,&b);
        if((a < 1 || a > 6) || (b < 1 || a > 6)) return 0;
        if(a == b){
            ren ++;
        }else{
            ren = 0;
        }
        if(ren == 3){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


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

using namespace std;

#define N 300000
#define INF 0x3f3f3f3f

int n,m,a[N],b[N],c[N],d[N],f1[N],f2[N],xb1,xb2,ans,tot,tmp,now,vis[N];
long long s1;
vector<int> g[N];

void gg(){
	puts("-1");
	exit(0);
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i){
		scanf("%d%d%d",a+i,b+i,c+i);
		++d[a[i]]; ++d[b[i]];
		g[a[i]].push_back(i);
	}
	for (int i=1;i<=n;++i){
		if (!vis[i]){
			int x=i; bool flag=0;
			while (1){
				if (g[x].size()!=1||d[x]!=2){
					flag=1; break;
				}
				x=b[g[x][0]];
				if (x==i) break;
			}
			if (flag){vis[i]=1; continue;}
			x=i;
			int sum=0,num=0;
			while (1){
				++num;
				vis[x]=2;
				x=b[g[x][0]];
				sum+=c[g[x][0]]-1;
				if (x==i) break;
			}
			if (num>1){
				++tot; ++ans;
				s1+=sum;
			}
			else{
				if (sum>1) f1[++xb1]=sum-1;
			}
		}
	}
	for (int i=1;i<=m;++i){
		if (a[i]!=b[i]){
			if (!c[i]) gg();
			++ans;
		}
		if (vis[a[i]]==1){
			if (c[i]>1){
				if (a[i]!=b[i]) now+=c[i]-1;
				else f2[++xb2]=c[i]-1;
			}
		}
	}
	sort(f1+1,f1+xb1+1,greater<int>());
	sort(f2+1,f2+xb2+1,greater<int>());
	for (int i=1;i<=xb1;++i) f1[i]+=f1[i-1];
	for (int i=1;i<=xb2;++i) f2[i]+=f2[i-1];
	tmp=INF;
	for (int i=0,j=xb1;i<=xb2;++i){
		int t=now+f2[i];
		if (t==0&&tot) continue;
		t+=s1;
		for (;j&&t+f1[j-1]>=tot;--j);
		if (t+f1[j]>=tot) tmp=min(tmp,i+j*2); 
	}
	if (tmp>=INF) gg();
	printf("%d\n",ans+tmp);
	
	return 0;
}
			

Measured memory_bytes: 15880
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  vector<string> ans[11];
  REP(i, 11){
    if(i == 0)continue;
    if(i == 1){
      ans[i].push_back("a");
      continue;
    }
    int m = ans[i-1].size();
    REP(j, m){
      bool check[26] = {};
      string now = ans[i-1][j];
      REP(k, i-1){
        check[now[k] - 'a'] = true;
      }
      REP(k, 26){
        string temp = now;
        if(check[k]){
          temp += (char)('a' + k);
          ans[i].push_back(temp);
        }else{
          temp += (char)('a' + k);
          ans[i].push_back(temp);
          break;
        }
      }
    }
  }
  int n;
  cin>>n;
  sort(ALL(ans[n]));
  for(string temp: ans[n]){
    cout<<temp<<endl;
  }
  return 0;
}



Measured memory_bytes: 11380
<?php
$n = (int)trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
array_unshift($arr, 'dmy');
unset($arr[0]);

$b = [];
$result = [];
for($i = $n; $i >= 1; $i--) {
    $sum = 0;
    for($j = $i + $i; $j <= $n; $j += $i) {
        if($result[$j] == 1) {
            $sum++;
        }
    }
    
    $result[$i] = 0;
    if($sum % 2 == 1) {
        if($arr[$i] == 0) {
            $b[] = $i;
            $result[$i] = 1;
        }
    } else {
        if($arr[$i] == 1) {
            $b[] = $i;
            $result[$i] = 1;
        }
    }
}

echo count($b) . "\n";

for($i = 0; $i < count($b); $i++) {
    echo $b[$i] . "\n";
}

Measured memory_bytes: 82012
n = int(input())
h = [int(x) for x in input().split()]

ans = 0
tmp = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	//freopen("ants.in","r",stdin);
	//freopen("ants.out","w",stdout);
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
const int maxn=100002;
struct ant{
	int id,x,dir;
	bool operator <(const ant& rhs)const{
		return x<rhs.x;
	}
}a[maxn];
int b[maxn],ans[maxn];
int main(){
	init();
	int n=readint(),l=readint(),T=readint(),tmp=0;
	for(int i=0;i<n;i++){
		a[i].x=readint(),a[i].dir=readint()==1?1:-1;
		a[i].id=i;
		b[i]=((a[i].x+T*a[i].dir)%l+l)%l;
		if (a[i].dir==1){
			tmp+=(a[i].x+T-b[i])/l;
			tmp=(tmp%n+n)%n;
		}
		else {
			tmp-=(b[i]-a[i].x+T)/l;
			tmp=(tmp%n+n)%n;
		}
	}
	sort(b,b+n);
	for(int i=tmp;i<n;i++)
		printf("%d\n",b[i]);
	for(int i=0;i<tmp;i++)
		printf("%d\n",b[i]);
}

Measured memory_bytes: 4864
def f(x):
  a = 0
  b = 0
  for e in x:
    b = [0, b+1][e]
    a = max(a, b)
  return a
def d(M):
  n = len(M)
  X=[]
  for i in range(-n+1,n):
    x = [0]*n
    for j in range(n):
      if 0<=i+j<n: x[j] = M[j][i+j]
    X.append(x)
  return X

while 1:
  n = input()
  if n==0: break
  A = [map(int, list(raw_input())) for _ in [0]*n]
  B = [e[::-1] for e in A]
  print max(map(f, A+zip(*A)+d(A)+d(B)))

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

int l[2000],r[2000];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string A,B;
	cin>>A>>B;
	int ca=0,cb=0,n=A.size();
	for(char c:A)
		if(c=='1')
			ca++;
	for(char c:B)
		if(c=='1')
			cb++;
	if(cb==0){
		if(ca==0)	cout<<0<<endl;
		else	cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		for(l[i]=0;;l[i]++){
			int cur = i-l[i];
			if(cur<0)	cur+=n;
			if(B[cur]=='1')
				break;
		}
		for(r[i]=0;;r[i]++){
			int cur = i+r[i];
			if(cur>=n)	cur-=n;
			if(B[cur]=='1')
				break;
		}
	}
	int ans = 1e9;
	for(int d=-n;d<=n;d++){
		vector<pair<int,int> > v;
		int cnt = 0;
		for(int i=0;i<n;i++){
			int idx = i + d;
			if(idx<0)	idx+=n;
			if(idx>=n)	idx-=n;
			if(A[i]!=B[idx]){
				cnt++;
				if(d<0){
					if(l[i]>-d)
						v.emplace_back(l[i],r[i]);
				}
				else if(d>0){
					if(r[i]>d)
						v.emplace_back(l[i],r[i]);
				}
				else if(l[i]!=0){
					v.emplace_back(l[i],r[i]);
				}
			}
		}
		sort(v.rbegin(),v.rend());
		int mxr = 0, mxl = 0;
		if(d < 0)	mxl = max(mxl,-d);
		else	mxr = max(mxr,d);
		for(auto it:v){
			ans = min(ans,cnt+2*(mxr+it.first)-abs(d));
			mxr=max(mxr,it.second);
			mxl=max(mxl,it.first);
		}
		ans = min(ans,cnt+2*(mxr+(d<0?-d:0))-abs(d));
	}
	cout<<ans<<endl;
}


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

vector<int> dx = { -1, 0, 0, 1 };
vector<int> dy = { 0, -1, 1, 0 };

void solve() {
	int H, W; cin >> H >> W;
	vector<string> canvas(H);
	rep(h, H) cin >> canvas[h];

	bool ok = true;
	int nx, ny;
	rep(h, H) rep(w, W) {
		if (canvas[h][w] != '#') continue;

		int cnt = 0;
		rep(i, 4) {
			ny = h + dy[i];
			nx = w + dx[i];
			if (ny >= H || 0 > ny || nx >= W || 0 > nx) continue;
			if (canvas[ny][nx] != '#') cnt++;
			if (cnt == 4) {
				ok = false; break;
			}
		}
	}

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

int main(void) {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0;i < n;i++)	cin >> p[i];

    int ans = 1;
    int min = p[0];
    for (int i = 0; i < n; i++)
    {
        if(min > p[i]){
            ans++;
            min = p[i];
        }
    }
    
    cout << ans << endl;

    return 0;
}

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

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    int amin = *min_element(a.begin(), a.end());
    int bmin = *min_element(b.begin(), b.end());

    int minv = amin + bmin;
    rep(i, M) {
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        int sum = a[x] + b[y] - c;
        if (sum < minv) minv = sum;
    }

    cout << minv << endl;
    return 0;
}


Measured memory_bytes: 1024
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define hurr cout<<"Road_Clear"<<endl;
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        int a[n+1];
        map<int,int>indx,val;
        for(int i = 1; i<=n;i++){
            cin >> a[i];
            if(!val[a[i]])
                val[a[i]] = i;
        }
        int vis[n+1]{};
        int cnt = 0;
        for(int i = 1; i<=n; i++){
            if(a[a[i]]==i and !vis[a[i]]){
                    //hurr;
                    cnt++;
                    vis[a[i]]=1;
            }
        }
        cout<<cnt/2<<endl;

return 0;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    string s; cin >> s; ll n = s.size();
    ll g[n+1], l[n+1]; rep(i,0,n+1) g[i] = l[i] = 0;
    rep(i,0,n) if(s[i] == '<') g[i+1] = g[i] + 1;
    rrep(i,0,n) if(s[i] == '>') l[i] = l[i+1] + 1;
    
    ll ans = 0;
    rep(i,0,n+1) ans += max(g[i],l[i]);
    cout << ans << ednl;
}


Measured memory_bytes: 8708
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    dp = [i for i in range(N+1)]

    for i in range(N):
        dp[i+1] = min(dp[i+1], dp[i]+1)
        e = 9
        while i + e <= N:
            dp[i+e] = min(dp[i+e], dp[i]+1)
            e *= 9
        e = 6
        while i + e <= N:
            dp[i+e] = min(dp[i+e], dp[i]+1)
            e *= 6

    print(dp[N])


if __name__ == '__main__':
    main()

Measured memory_bytes: 7064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int a = sc.nextInt();
            String o = sc.next();
            int b = sc.nextInt();

            if(o.equals("?"))break;
            switch (o){
                case "+":
                    System.out.println(a+b);
                    break;
                case "-":
                    System.out.println(a-b);
                    break;
                case "*":
                    System.out.println(a*b);
                    break;
                case "/":
                    System.out.println(a/b);
            }
            sc.nextLine();
        }
    }
}


Measured memory_bytes: 26188
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Problem0024
  {
    static void Main()
    {
      // height of nth floor = 5 * n - 5
      foreach (var v in ReadVelocities())
      {
        var t = v / 9.8;
        var y = 4.9 * t * t;
        var n = 0;
        while (y > 5 * n - 5)
          ++n;
        Console.WriteLine(n);
      }
    }

    static IEnumerable<double> ReadVelocities()
    {
      string line;
      while ((line = Console.ReadLine()) != null)
        yield return double.Parse(line);
    }
  }
}

Measured memory_bytes: 5700
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	string s; cin >> s;
	int o = count(s.begin(), s.end(), 'o');
	int ans = 700 + 100 * o;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
s = input()
ans = "WA"
if s[0] == "A":
  if s[2:-1].count("C") == 1:
    if s[1].islower() and s[-1].islower():
      s = s.replace("C","c").replace("A","a")
      if s.islower():
        ans = "AC"

print(ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp1[3333][3333];
ll dp2[3333][3333];

void chmax(ll &a, ll b){
	a = max(a, b);
}

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

	ll n, t;cin >> n >> t;
	vector<P> v(n);
	REP(i, n){
		ll a, b;cin >> a >> b;
		v[i] = MP(a, b);
	}

	REP(i, n){
		REP(j, t){
			chmax(dp1[i+1][j], dp1[i][j]);
			if(j > 0)chmax(dp1[i][j], dp1[i][j-1]);
			if(j + v[i].FI < t)chmax(dp1[i+1][j + v[i].FI], dp1[i][j] + v[i].SE);
		}
	}

	REV(i, n){
		REP(j, t){
			chmax(dp2[i][j], dp2[i+1][j]);
			if(j > 0)chmax(dp2[i+1][j], dp2[i+1][j-1]);
			if(j + v[i].FI < t)chmax(dp2[i][j + v[i].FI], dp2[i+1][j] + v[i].SE);
		}
	}

	ll ans = 0;
	REP(i, n){
		REP(j, t){
			ll now = (i == n - 1 ? 0:dp2[i+1][j]);
			now += (i == 0 ? 0 : dp1[i][t-j-1]);
			chmax(ans, now + v[i].SE);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 160000
#include<stdio.h>
int main(void){
    int N,x;

    scanf("%d",&N);
  int a[N];
    for(x=0;x<N;x++)
        scanf("%d",&a[x]);

    int count = 0;
    int now = 0;
    for(x=0;x<N;x++){
    if(a[x]-now==1)now=a[x];
    else count++;}

    if(count==N)count=-1;
   
    printf("%d\n",count);
    return 0;}

Measured memory_bytes: 896
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int ans = ceil(b - 1, a - 1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin >> n;
	for(int i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			cout << ' ' << i;
		}else{
			while(1){
				if(x%10==3){
					cout << ' ' << i;
					break;
				}
				x=x/10;
				if(x==0) break;
			}
		}
	}
	cout << endl;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(void) {
  int i, j, k, l, n, m;
  scanf("%d%d", &n, &m);
  char a[n][n + 10], b[m][m + 10];
  for(i = 0; i < n; ++i) scanf("%s", a[i]);
  for(i = 0; i < m; ++i) scanf("%s", b[i]);
  for(i = 0; i <= n - m; ++i) for(j = 0; j <= n - m; ++j) {
    bool s = true;
    for(k = 0; k < m; ++k) for(l = 0; l < m; ++l) if(a[i + k][j + l] != b[k][l]) s = false;
    if(s) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;

vector<ll>a(100);

int main(){
    int a,b;
    cin>>a>>b;
    int ans=max(0,a-b*2);
    cout<<ans<<endl;
}

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

using namespace std;

void Main() {
    int L, R, d;
    cin >> L >> R >> d;

    int ans = 0;
    for (int i = L; i <= R; ++i) {
        if (i % d == 0) {
            ++ans;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3588
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const int N = 100*1000+5;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int a,b,c;
    cin >> a >> b >> c;
    if((a == b && a != c) || (c == b && a != c) || (a == c && a != b))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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


vector<int > v[100001];
int dp[100001];
int n,m,i,j,x,y;
int solve(int a)
{
    if(dp[a]!=-1)
        return dp[a];
    int r=0;
    for(int i=0;i<v[a].size();i++)
        r=max(r,solve(v[a][i])+1);
    return dp[a]=r;
}


int32_t main()
{
    cin>>n>>m;

    for(i=1;i<=m;i++)
    {
        cin>>x>>y;x--;y--;
        v[x].pb(y);
    }
    for(i=0;i<n;i++)
        dp[i]=-1;
    int r=0;
    for(i=0;i<n;i++)
    {
        r=max(r,solve(i));
    }
    cout<<r;
    return 0;
}


Measured memory_bytes: 11692
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

// Most important thing in CP - Have Fun :)

const int maxn = 200005;
int parent[maxn];
int rnk[maxn];

void make_set(int v) {
    parent[v] = v;
    rnk[v] = 1;
}
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rnk[a] < rnk[b])
            swap(a, b);
        parent[b] = a;
        rnk[a] += rnk[b];
    }
}

void solve(){
	//write here
    int n,m;
    cin>>n>>m;
    for (int i = 0 ; i<n ; i++)make_set(i);
    for (int i = 0 ; i<m ; i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        union_sets(u,v);
    }
    int mxval = 0;
    for (int i = 0 ; i<n ; i++)mxval = max(mxval,rnk[i]);
    cout<<mxval<<endl;
}

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	
		solve();
	return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    rep(i, n) cin >> a[i];
    int cnt[100010] = {};
    int ans = 0;
    rep(i, n) {
        rep(j, 3) {
            cnt[a[i] + j]++;
        }
    }
    rep(i, 100010) ans = max(ans, cnt[i]);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n,h;
	cin>>n>>h;
	int sum=0;
	int t;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&t);
		if(t>=h) sum++;
	}
	cout<<sum<<endl;
	return 0;
}

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

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var sum = 0L;
            var A = ReadLongs();
            long current = 0;
            for (var i = 0; i < N; i++)
            {
                if (i == 0)
                {
                    current = A[i];
                    continue;
                }
                long tall = A[i];
                if (current <= tall)
                {
                    current = tall;
                }
                else
                {
                    sum += current - tall;
                }
            }
            return sum;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

#define N (3000)

string lcs(string X, string Y)
{
    int c[N + 1][N + 1];
    int m = (int)X.length();
    int n = (int)Y.length();
    int maxl = 0;
    
    X = ' ' + X;
    Y = ' ' + Y;
    
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int i = 0; i <= n; i++) c[0][i] = 0;
    
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    
    string s = "";
    while (m >= 1 && n >= 1) {
        if (X[m] == Y[n]) {
            s += X[m];
            m--;
            n--;
        } else {
            if (c[m - 1][n] > c[m][n - 1]) {
                m--;
            } else {
                n--;
            }
        }
    }
    reverse(s.begin(), s.end());
    
    return s;
}

int main(int argc, const char * argv[]) {
    string s1, s2;

    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
    
    return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>

int main(void){
	int N, K;
	int ans = 0;
	
	scanf("%d %d", &N, &K);
	for(int i = 0; i < N; i++){
		int height;
		scanf("%d", &height);
		if(height >= K) ans++;
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=b && a>=c) a*=pow(2,k);
  else if(b>=a && b>=c) b*=pow(2,k);
  else c*=pow(2,k);
  cout<<a+b+c<<endl;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
ab=array(N)
N.times do|i|
    ab[i]=get_i
end
ab.reverse!
ans=0
ab.each do|a,b|
  a_=a+ans
  r=a_%b
  ans+=b-r unless r.zero?
end
puts ans

Measured memory_bytes: 9596
INF = float("inf")
V, E = map(int, raw_input().split())
l = [[INF]*V for i in range(V)]
for i in xrange(E):
    s, t, d = map(int, raw_input().split())
    l[s][t] = d
for k in range(V):
    for i in range(V):
        for j in range(V):
            l[i][j] = min(l[i][j], l[i][k] + l[k][j])
for i in range(V):
    if l[i][i] < 0:
        print "NEGATIVE CYCLE"
        break
    l[i][i] = 0
else:
    for r in l:
        for i in range(V):
            if r[i] == INF: r[i] = "INF"
        print " ".join(map(str, r))

Measured memory_bytes: 6880
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n,p; cin >> n >> p;
    ll x = p;
    const ll mx = 1000001;
    vector<ll> a(mx,0);
    for(int i=2;i<mx;i++){
        ll count = 0;
        while(p%i==0){
            p/=i; count++;
        }
        a.at(i) = count;
    }
    ll ans = 1;
    for(int i=2;i<mx;i++){
        if((a.at(i)/n)==0)continue;
        ans *= pow(i,(a.at(i)/n));
    }
    if(n!=1)cout << ans << endl; else cout << x << endl;    
}

Measured memory_bytes: 8064
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define RG register
using namespace std;
const int N=1e5+10;
struct node{ int a,b; }num[N];
int n;
inline bool cmp(node a,node b){return a.a<b.a;}
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
int main()
{
	//freopen(".in","r",stdin);
	n=read();
	for(RG int i=1;i<=n;i++) num[i]=(node){read(),read()};
	sort(num+1,num+1+n,cmp);
	printf("%d\n",num[n].a+num[n].b);
	return 0;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  int judge = 0;
  while (judge <= b) {
    judge += k;
    if (a <= judge && judge <= b) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3636
N,W = map(int, input().split())

VW = [list(map(int, input().split())) for _ in range(N)]

inf = float("inf")
dp = [ [inf] * (100001) for _ in range(N+1)] # $B2ACM$K1~$8$?=E$5$N:G>.CM(B
dp[0][0] = 0

for i in range(N):
    v,w = VW[i]
    
    for p in range(0, 10001): # p$B$O2ACM(B
        dp[i+1][p+v] = min(dp[i+1][p+v], 
                           dp[i][p]+w )

        dp[i+1][p]   = min(dp[i+1][p],
                           dp[i][p] ) 

# ans_candidate = []
ans = 0
for i,w in enumerate(dp[N]):
    if w <= W:
        ans = max(ans, i)
print(ans)



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

using namespace std;

int main() {
    int a = 0, b = 0, c = 0, d = 0;
    cin >> a >> b >> c >> d;

    if (a + b > c + d) {
        cout << "Left" << endl;
    } else if (a + b == c + d) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 510000;
const int MOD = 1e9;

const double PI=3.14159265358979323846;

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

vector<double> cx, cy, c;
 ll MM = 1e12;

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

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}*/

int length(vector<int> v, int u, int HW){
    if(v.size() == 0) return HW;
    if(v[0] > u) return v[0];
    if(v[v.size() - 1] < u) return HW - v[v.size()- 1] -1;
    else{
        int i = lower_bound(ALL(v), u)- v.begin();
        return v[i] - v[i-1] -1;
    }
}

int main(){
    string str;
    cin >> str;
    if(str[0] == str[1] and str[1] == str[2]) cout << "No";
    else cout << "Yes";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<(i)<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  int n;
  cin>>n;
  vint a(n);
  repi(n)cin>>a[i];
  SORT(a);
  vint b(n);
  if(n%2==0)for(int i=0;i<n;i+=2)b[i]=(i+1),b[i+1]=b[i];
  else {b[0]=0;for(int i=1;i<n;i+=2)b[i]=(i+1),b[i+1]=b[i];}
  bool ans=true;
  rep(i,n)if(a[i]!=b[i])ans=false;
  int res=1;
  int mod=1e9+7;
  for(int i=0;i<(n/2);++i)res=res*2%mod;
  cout<<(ans?res:0)<<endl;

  return 0;
}



Measured memory_bytes: 1792
n = int(input())
p = list(map(int, input().split())) + [0]
cnt = 0
j = False

for i in range(n):
    if p[i] == i + 1:
        cnt += 1
        if p[i + 1] == i + 2:
            if j == False:
                cnt -= 1
                j = True
            else:
                j = False
    else:
        j = False
print(cnt)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

ll check_neg(const vector<ll> &a, const ll k, const ll x, const ll split) {
    ll sum = 0LL;
    ll n = a.size();

    for(ll i = 0, j = n - 1; i < split; i++) {
        while(j >= split && a[i] * a[j] < x) j--;
        sum += n - j - 1;
    }

    return sum;
}

ll check_pos(const vector<ll> &a, const ll k, const ll x, const ll split) {
    ll sum = 0LL;
    ll n = a.size();

    for(ll i = 0, j = split - 1; i < j; i++) {
        while(j > i && a[i] * a[j] >= x) j--;
        sum += j - i;
    }

    for(ll i = split, j = n - 1; i < j; i++) {
        while(j > i && a[i] * a[j] >= x) j--;
        sum += j - i;
    }

    return sum;
}

ll check(const vector<ll> &a, const ll k, const ll x, const ll split) {
    ll n = a.size();
    if(k <= split * (n - split)) return check_neg(a, k, x, split);
    else return check_pos(a, k, x, split) + split * (n - split);
}

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

    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for(ll &i : a) cin >> i;
    sort(begin(a), end(a));
    ll split = find_if(begin(a), end(a), [](ll i){return i >= 0;}) - begin(a);
    reverse(begin(a), begin(a) + split);

    ll lo = -1e18, hi = 1e18; hi++;
    while(hi - lo > 1) {
        ll mid = (hi + lo) / 2;
        if(check(a, k, mid, split) < k) lo = mid;
        else hi = mid;
    }

    cout << lo << endl;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> divisors;
  for (int i=1; i<=min(a,b); i++) {
    if (a%i==0 && b%i==0) divisors.push_back(i);
  }
  sort(divisors.rbegin(), divisors.rend());
  cout << divisors[k-1];
  return 0;
}

Measured memory_bytes: 256