akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register
#define maxn 1200000
#define inf 0x3f3f3f3f
#define mod (ll)(1e9+7)
#pragma GCC optimize(3)
#pragma -fcrossjumping
#pragma -fdefer-pop
#pragma -fmerge-constans
#pragma -fthread-jumps
#pragma -floop-optimize
#pragma -fif-conversion
#pragma -fif-conversion2
#pragma -fdelayed-branch
#pragma -fguess-branch-probability
#pragma -fcprop-registers
#pragma -fforce-mem
#pragma -foptimize-sibling-calls
#pragma -fstrength-reduce
#pragma -fgcse
#pragma -fcse-follow-jumps
#pragma -frerun-cse-after-loop
#pragma -fdelete-null-pointer-checks
#pragma -fextensive-optimizations
#pragma -fregmove
#pragma -fschedule-insns
#pragma -fsched-interblock
#pragma -fcaller-saves
#pragma -fpeephole2
#pragma -freorder-blocks
#pragma -fstrict-aliasing
#pragma -funit-at-a-time
#pragma -falign-functions
#pragma -fcrossjumping
#pragma -finline-functions
#pragma -fweb
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline ll print(ll x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>=10)
    {
        print(x/10);
    }
    putchar(x%10+'0');
}
int n,m,a[maxn],b[maxn];
int c[maxn];
int dp[1<<13];
int main()
{
	n=read(),m=read();
	for(rg int i=1;i<=m;++i)
	{
		a[i]=read(),b[i]=read();
		for(rg int j=1;j<=b[i];++j)
		{
			int temp;
			temp=read();
			c[i]|=1<<(temp-1);
		}
	}
	int ee=0;
	for(rg int i=1;i<=n;++i) ee+=1<<(i-1);
	memset(dp,0x3f,sizeof(dp)); dp[0]=0;
	for(rg int i=1;i<=m;++i)
	{
		for(rg int j=0;j<=ee;++j)
		{
			dp[j|c[i]]=min(dp[j|c[i]],dp[j]+a[i]);
		}
	}
	if(dp[ee]==inf) puts("-1");
	else cout<<dp[ee];
	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	intl i,j,n;
	cin>>n;
	vector<intl> ar(n);
	intl x=0;
	for(i=0;i<n;i++){
		cin>>ar[i];
		x^=ar[i];
	}
	for(i=0;i<n;i++){
		intl y=x^ar[i];
		cout<<y<<" ";
	}
	cout<<"\n";
}


Measured memory_bytes: 4700
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <bitset>
#include <random>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
//typedef __int128 ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

int main() {

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

    ld n, m, d;
    cin >> n >> m >> d;

    ld ans = (n - d) * 2;
    ans /= n;
    ans *= (m - 1);
    ans /= n;

    if (d == 0) {
        ans /= 2;
    }

    cout << fixed;
    cout.precision(10);
    cout << ans << "\n";

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c,d;
scanf("%d",&a);
for(b=3;b<=a;b++){
if(b%3==0)
printf(" %d",b);
c=b;
d=b;
while(1){
if(b%3==0)
break;
c%=10;
d/=10;
if(d==0)
break;
if(c==3||d%10==3){
printf(" %d",b);
break;
}
c/=10;
}
}
printf("\n");
return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define N 200010
#define ll long long
const ll mod=1e9+7;
priority_queue<int>l;
priority_queue<int,vector<int>,greater<int> >r;
int main()
{
    int q,op,x,y;
    scanf("%d",&q);
    ll sum=0;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&op);
        if(op==1)
        {
            scanf("%d%d",&x,&y);
            sum+=y;
            l.push(x),r.push(x);
            if(l.top()>r.top())
            {
                x=l.top(),y=r.top();
                l.pop(),r.pop();
                sum+=x-y;
                l.push(y),r.push(x);
            }
        }
        else
        {
            printf("%d %lld\n",l.top(),sum);
        }
    }
    return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

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

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

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

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



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

    vector<int> A(N);
    REP(i,N) cin >> A[i];

    int max_a = 0;
    vector<int> MAX_A(N);
    for(int i=N-1;i>=0;i--){
        chmax(max_a,A[i]);
        MAX_A[i]=max_a;
    }

    vector<int> V(N);
    REP(i,N) {
        V[i] = MAX_A[i] - A[i];
    }

    sort(all(V),greater<>());

    int ans = 1;
    REP(i,N-1){
        if(V[0]==V[i+1]) ans++;
        else break;
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 1408
INF = 10 ** 9 + 7
n, m = gets.chomp.split.map(&:to_i)
cnt = [[n, m + 1].min, [n + 1, m].min].max
perm = Array.new(cnt + 1, 1)
1.step(cnt) do |i|
  perm[i] = (perm[i - 1] * i) % INF
end
res = 0
if n - m == 0 || n - m == 1
  a = [n, m + 1].min
  b = [n, m].min
  res = (res + perm[a] * perm[b]) % INF
end
if m - n == 0 || m - n == 1
  a = [n, m].min
  b = [n + 1, m].min
  res = (res + perm[a] * perm[b]) % INF
end
puts res

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)

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

    int h, w, n;
    cin >> h >> w >> n;

    int row = 0, column = 0;
    int color = 1;

    int result[h][w];

    forn(i, n) {
	unsigned a;
	cin >> a;

	forn(j, a) {
	    result[row][column] = color;

	    if(row % 2) {
		column--;
	    } else {
		column++;
	    }
	    if(column < 0) {
		column = 0;
		row++;
	    } else if (column >= w) {
		column = w-1;
		row++;
	    }
	}
	color++;
    }

    forn(i, h) {
	forn(j, w) {
	    cout << result[i][j];
	    if(j + 1 < w) cout << " ";
	}
	cout << "\n";
    }

}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int N, W, H, x, y, w, s, t, sumx, sumy, imosx[100001], imosy[100001];
 
int main()
{
    scanf("%d", &N);
    scanf("%d", &W);
    scanf("%d", &H);
 
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &x);
        scanf("%d", &y);
        scanf("%d", &w);
        
        int lx = max(x - w, 0);
        int rx = min(x + w, W);
        int ly = max(y - w, 0);
        int ry = min(y + w, H);
        
        imosx[lx]++;
        imosx[rx]--;
        imosy[ly]++;
        imosy[ry]--;
    }
 
    bool okx = true;
    
    for(int i = 0; i < W; i++)
    {
        sumx += imosx[i];
        
        if(!sumx) okx = false;
    }
    
    bool oky = true;
    
    for(int i = 0; i < H; i++)
    {
        sumy += imosy[i];
        
        if(!sumy) oky = false;
    }
 
    printf("%s\n", okx || oky ? "Yes" : "No");
 
    return 0;
}

Measured memory_bytes: 3928
#include <iostream>
using namespace std;
int main(void){
    string s;
    long int ke[9],h=0,n=0,sum=1;
    cin>>s;
    //for(int i=0;i<9;i++)s[i]='0';
    for(int i=0;i<s.size();i++){
        ke[i]=s[i]-'0';
        h+=ke[i];
    }
    for(int i=s.size()-1;i>=0;i--){
        n+=ke[i]*sum;
        sum*=10;
    }
    if(n%h==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#define FOR(i,l,r) for(int i = l; i <= r; i++)
#define ROF(i,r,l) for(int i = r; i >= l; i--)
using namespace std;

const int MAXN = 200100;
const long long MAXD = 2000000001;

int n;
long long a[MAXN];

int main(){
  cin >> n;
  FOR(i,1,n) scanf("%lld",&a[i]);
  FOR(i,1,n) a[i] = a[i] - i;
  sort(a+1,a+n+1);
  long long k = a[(n+1)>>1];
  long long ans = 0;
  FOR(i,1,n) ans = ans + abs(a[i]-k);
  cout << ans;
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
    public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
    public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath
{
    static public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b));
    static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a);
    static private readonly long _m = 1000000000 + 7;
    static public long Mod(long val) => (val % _m + _m) % _m;
    static private long extGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (extGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
    static public long ModInverse(long a, long dummy1 = 0, long dummy2 = 0) => extGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);    
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        var N = Console.ReadLine().ToInt();
        var array = ReadLines(N).Select(s => s.ToInt()).ToArray();

        //iより小さいインデックスでの最大値を記憶
        var ruisekiLeft = new int[N + 1];
        for (int i = 0; i < ruisekiLeft.Length; i++) ruisekiLeft[i] = int.MinValue;
        for (int i = 1; i <= N; i++)
        {
            ruisekiLeft[i] = Math.Max(ruisekiLeft[i - 1], array[i - 1]);
        }

        //iより大きいインデックスでの最大値を記憶
        var ruisekiRight = new int[N + 1];
        for (int i = 0; i < ruisekiRight.Length; i++) ruisekiRight[i] = int.MinValue;
        for(int i = N - 2; i >= 0; i--)
        {
            ruisekiRight[i] = Math.Max(ruisekiRight[i + 1], array[i + 1]);
        }


        for(int i=0; i< array.Length;i++)
        {
            Console.WriteLine(Math.Max(ruisekiRight[i], ruisekiLeft[i]));
        }
    }
}

Measured memory_bytes: 32984
// https://atcoder.jp/contests/...
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

int solv(int n, int m) {
  return n + m;
}

int main() {
  int a, b;

  while (cin >> a >> b) {
    if (a == 1) {
      a += 13;
    }
    if (b == 1) {
      b += 13;
    }
    if (a > b) {
      cout << "Alice" << endl;
    } else if (a < b) {
      cout << "Bob" << endl;
    } else {
      cout << "Draw" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <complex>

using namespace std;
typedef long long ll;


typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define re(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl;

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans=0;
ll a,b,c,d,e,f,g,h,w;
ll start,end;
ll x[500005],y[500005],z[500005];
ll checks[50],checkt[50];
char s[500005],t[500005];
bool flag;

int main(){
    cin>>s>>t;
    n = strlen(s);
    for(i=0;i<n;i++){
        if(checks[s[i]-'a'] == 0){
            checks[s[i]-'a'] = num + 1;
            num ++;
            x[i] = num;
        }else{
            x[i] = checks[s[i]-'a'];
        }
    }
    num = 0;
    for(i=0;i<n;i++){
        if(checkt[t[i]-'a']==0){
            checkt[t[i]-'a'] = num + 1;
            num ++;
            y[i] = num ;
        }else{
            y[i] = checkt[t[i]-'a'];
        }
    }
    flag = false;
    for(i=0;i<n;i++){
        if(x[i]!=y[i])flag=true;
    }
    
    if(flag){
        p("No");
    }else{
        p("Yes");
    }
    return 0;
    
}



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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int tnum = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = i + 1; j < 4; j++)
        {
            if (s[i] == s[j])
            {
                tnum++;
            }
        }
    }
    if (tnum == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;
  
string S[100050];

int main() {
  ll N,A,B,C,cnt=1;
  cin>>N>>A>>B>>C;
  char c[N];
  
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  for(int i=0;i<N;i++){
    string s;
    s=S[i];
    if(s=="AB"){
      if(A==0&&B==0){
        cout<<"No";
        cnt=0;
        break;
      }
      if(A==1&&B==1&&C==0){
        string s2=S[i+1];
        if(s2=="AC"){
          A++;
          B--;
          c[i]='A';
          continue;
        }
        if(s2=="BC"){
          A--;
          B++;
          c[i]='B';
          continue;
        }
      }
      if(A>B){
        A--;
        B++;
        c[i]='B';
      }
      else{
        A++;
        B--;
        c[i]='A';
      }
    }
    if(s=="BC"){
      if(C==0&&B==0){
        cout<<"No";
        cnt=0;
        break;
      }
      if(A==0&&B==1&&C==1){
        string s2=S[i+1];
        if(s2=="AC"){
          C++;
          B--;
          c[i]='C';
          continue;
        }
        if(s2=="AB"){
          C--;
          B++;
          c[i]='B';
          continue;
        }
      }
      
      if(C>B){
        C--;
        B++;
        c[i]='B';
      }
      else{
        C++;
        B--;
        c[i]='C';
      }
    }
    if(s=="AC"){
      if(A==0&&C==0){
        cout<<"No";
        cnt=0;
        break;
      }
      if(A==1&&B==0&&C==1){
        string s2=S[i+1];
        if(s2=="AB"){
          A++;
          C--;
          c[i]='A';
          continue;
        }
        if(s2=="BC"){
          A--;
          C++;
          c[i]='C';
          continue;
        }
      }
      if(A>C){
        A--;
        C++;
        c[i]='C';
      }
      else{
        A++;
        C--;
        c[i]='A';
      }
    }
  }
  if(cnt){
    cout<<"Yes"<<endl;
    for(int i=0;i<N;i++){
      cout<<c[i]<<endl;
    }
  }
  return 0;
}


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

int main()
{
	int X, Y;
	scanf("%d%d", &X, &Y);
	
	int b = (Y - 2 * X) / 2, a = X - b;
	if(2 * a + 4 * b == Y && a >= 0 && b >= 0)
		printf("Yes");
		
	else
		printf("No");
}


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

using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const double pi = 3.14159265358979323846;

bool isSquare(long double x)
{


	long double sr = sqrt(x);
	return ((sr - floor(sr)) == 0);
}
int arr[3];
int main()
{
//	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	Iint(n);
	for (int i = 0; i < n; ++i)
	{
		Ill(a); Ill(b);
		if(a==1 && b==1)
		{
			std::cout << 0 <<"\n";
		}
		else if(a==1&&isSquare(b))
		{
			std::cout << 2*sqrt(b)-3<<"\n";
			
		}
		else if (b == 1 && isSquare(a))
		{
			std::cout << 2 * sqrt(a) - 3 << "\n";

		}
		else
		{
			ll t = floor(sqrtl(a*b));
			bool bb = a*b>t*(t + 1);
			std::cout << 2 * t - 2 + bb -(a!=b && isSquare(a*b))<< "\n";

		}
	


	}

}




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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int a[n], b[n];
  REP(i,n) {
    cin >> a[i] >> b[i];
  }
  int ans = 0;
  REPR(i,n-1) {
    if(b[i] == 1) continue;
    a[i] += ans%b[i];
    if(a[i]%b[i] == 0) continue;
    ans += b[i] - (a[i] % b[i]);
  }
  cout << ans;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

// 0 --> swim
// 1 --> catch bags
// 2 --> homework

ll a[100005][3], dp[100005][3];

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

Measured memory_bytes: 4992
#include <cstdio>

const int MaxN = 200000;
const int Mod = 1000000007;

struct Graph {
  int cnte;
  int Head[MaxN + 5], To[MaxN * 2 + 5], Next[MaxN * 2 + 5];

  inline void addEdge(int from, int to) {
    cnte++; To[cnte] = to;
    Next[cnte] = Head[from]; Head[from] = cnte;
  }
};

int N;
int Fac[MaxN + 5], InvFac[MaxN + 5];
int Siz[MaxN + 5], F[MaxN + 5], Ans[MaxN + 5];
Graph G;

inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % Mod; }
inline int pw(int x, int y) { int z = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) z = mul(z, x); return z; }
inline int inv(int x) { return pw(x, Mod - 2); }
inline int sep(int x, int y) { return mul(x, inv(y)); }
inline int binom(int n, int m) { return mul(Fac[n], mul(InvFac[m], InvFac[n - m])); }

void init() {
  scanf("%d", &N);
  for (int i = 1; i < N; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G.addEdge(u, v);
    G.addEdge(v, u);
  }
  Fac[0] = 1;
  for (int i = 1; i <= N; ++i) Fac[i] = mul(Fac[i - 1], i);
  InvFac[N] = inv(Fac[N]);
  for (int i = N; i >= 1; --i) InvFac[i - 1] = mul(InvFac[i], i);
}

void dfs(int u, int f) {
  Siz[u] = 1;
  F[u] = 1;
  for (int i = G.Head[u]; i; i = G.Next[i]) {
    int v = G.To[i];
    if (v == f) continue;
    dfs(v, u);
    Siz[u] += Siz[v];
    F[u] = mul(mul(F[u], F[v]), binom(Siz[u] - 1, Siz[v]));
  }
}

void dfs2(int u, int f) {
  Ans[u] = F[u];
  for (int i = G.Head[u]; i; i = G.Next[i]) {
    int v = G.To[i];
    if (v == f) continue;
    int remFu = F[u], remFv = F[v], remSu = Siz[u], remSv = Siz[v];
    F[u] = sep(sep(F[u], F[v]), binom(Siz[u] - 1, Siz[v]));
    Siz[u] -= Siz[v];
    Siz[v] += Siz[u];
    F[v] = mul(mul(F[v], F[u]), binom(Siz[v] - 1, Siz[u]));
    dfs2(v, u);
    F[u] = remFu, F[v] = remFv, Siz[u] = remSu, Siz[v] = remSv;
  }
}

void solve() {
  dfs(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= N; ++i) printf("%d\n", Ans[i]);
}

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

Measured memory_bytes: 9984
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       int x = sc.nextInt();
       int y = sc.nextInt();

       long i = a * x + b * y;
       long ii = c*2 * Math.max(x, y);
       long iii = 0;
       if(x > y){
        iii = c*2 * y + a * (x - y);
       }else{
        iii = c*2 * x + b * (y - x);
       }

       System.out.println(Math.min(Math.min(i, ii), iii));
    }
}

Measured memory_bytes: 21972
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SnukeAndVoyage solver = new SnukeAndVoyage();
        solver.solve(1, in, out);
        out.close();
    }

    static class SnukeAndVoyage {
        private static final int INF = 100000000;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            List<Integer>[] g = new ArrayList[n + 1];
            for (int i = 0; i <= n; i++) g[i] = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int from = in.nextInt();
                int to = in.nextInt();
                g[from].add(to);
                g[to].add(from);
            }
            int[] dist = new int[n + 1];
            ArrayDeque<Integer> q = new ArrayDeque<>();
            Arrays.fill(dist, INF);
            dist[1] = 0;
            q.add(1);
            while (!q.isEmpty()) {
                int cur = q.poll();
                for (int child : g[cur]) {
                    if (dist[child] > dist[cur] + 1) {
                        dist[child] = dist[cur] + 1;
                        q.add(child);
                    }
                }
            }
            out.println(dist[n] > 2 ? "IMPOSSIBLE" : "POSSIBLE");
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

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

    }
}



Measured memory_bytes: 87736
n=10000000
p=[1]*(n+1)
p[0],p[1]=0,0
for i in range(2,int(n**0.5)+1):
    if p[i]:        
        for j in range(i*i,n+1,i):
            p[j]=0
#p=[i for i in range(n+1) if p[i]==1]
while 1:
    n=int(input())
    if n==0: break
    if n<19:print(13)
    else:
        for i in range((n+1)//10*10-1,2,-10):
            if (p[i],p[i-2],p[i-6],p[i-8])==(1,1,1,1):
                print(i)
                break

Measured memory_bytes: 85524
#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 1000000007

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

vector<pair<int,int>> make_seica(string str){
	vector<pair<int,int>> ret;
	if(str[0] == '0')ret.EB(1,0);
	else ret.EB(0,0);
	REP(i,str.size()-1){
		if(str[i] != str[i+1])ret.EB(str[i] - '0',i+1);
	}
	if(str[str.size() - 1] == '0')ret.EB(0,str.size());
	else ret.EB(1,str.size());
	
	while(ret.size() < 5005)ret.EB(1-ret.back().FI,str.size());
	
	return ret;
}

int solve_seica(vector<pair<int,int>> a, vector<pair<int,int>> b){
	int ret = INF;
	REP(i,a.size()){
		int now = 0;
		if(a[i].FI != b[b.size() - 1].FI)continue;
		REV(j,b.size()){
			int tmp = i - ((int)b.size() - 1 - j);
		//	cout << tmp << " " << j << endl;
			if(tmp >= 0){
				now += (abs(a[tmp].SE - b[j].SE));
			}
			else{
				now += b[j].SE;
			}
		}
		//cout << "      " << i << " " << now << endl;
		ret = min(ret, now);
	}
	return ret;
}

int main(){
	
	int n;cin >> n;
	string s,t;cin >> s >> t;
	auto a = make_seica(s);
	auto b = make_seica(t);
		
	cout << min(solve_seica(a,b),solve_seica(b,a)) << endl;
	
	return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
const int MAX = 161;
int n,k,m;

void add(int& a,int b){
  a += b;
  if(a >= m)
    a -= m;
}
int licz(int x){
  vector<int> dp(k);
  dp[0] = 1;
  R(_,x){
    vector<int> ak(k);
    R(i,k){
      add(ak[0],dp[i]);
      if(i != k-1)
        add(ak[i+1],dp[i]);
    }
    swap(ak,dp);
  }
  int res = 0;
  R(i,k){
    add(res,dp[i]);
  }
  return res;
}
int dp[MAX][MAX][MAX];
int ak[MAX][MAX][MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> k >> m;
  if(k & 1){
    dp[0][0][0] = 1;
    R(i,n){
      debug("--------------",i);
      R(sk1,n/2+2)R(sk2,n/2+2)R(lim, k+1){
        ak[sk1][sk2][lim] = 0;
      }
      R(sk1,n/2+2)R(sk2,n/2+2)R(lim, k+1){
        if(lim == 0 || (lim&1))
          add(ak[sk2][0][0],dp[sk1][sk2][lim]);
        else
          add(ak[sk2][0][lim-1],dp[sk1][sk2][lim]);
        if(lim == 0){
          if(sk2*2 > k)
            add(ak[sk2][sk1+1][k-2*sk1], dp[sk1][sk2][lim]);
          else
            add(ak[sk2][sk1+1][0], dp[sk1][sk2][lim]);
        }else{
          if(lim > 1)
            add(ak[sk2][sk1+1][lim-1], dp[sk1][sk2][lim]);
        }
      }
      R(sk1,n/2+2)R(sk2,n/2+2)R(lim, k+1){
        dp[sk1][sk2][lim] = ak[sk1][sk2][lim];
        if(dp[sk1][sk2][lim]){
          debug(sk1,sk2,lim, dp[sk1][sk2][lim]);
        }
      }
    }
    int res = 0;
    R(sk1,n/2+2)R(sk2,n/2+2)R(lim, k+1){
      add(res, dp[sk1][sk2][lim]);
    }
    cout << res << "\n";
  }else{
    k/=2;k++;
    cout << licz(n/2) * licz((n+1)/2) % m << "\n";
  }
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
#define INF 1061109567
#define int long long
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N = 5e5 + 10;
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9, base = 121448;
typedef pair<int, int> ii;
int n, h[N][2], pw[N][2];
string s;
map<ii, int> mp;
void add(int &x, int y, int mod) {
	x += y;
	if (x >= mod) x -= mod;
}
void rem(int &x, int y, int mod) {
	x -= y;
	if (x < 0) x += mod;
}
int fpow(int a, int p, int mod) {
	if (!p) return 1;
	int ans = fpow(a, p >> 1, mod);
	ans = ans * ans % mod;
	if (p & 1) ans = ans * a % mod;
	return ans;
}
int inv(int x, int mod) {
	return fpow(x, mod - 2, mod);
}
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	//Hash 'em. Then for a range L -> R, if the pointer at L is P, it's (h[r] - h[l - 1]) / b ^ p
	pw[0][0] = pw[0][1] = 1;
	fw (i, 1, N) {
		pw[i][0] = pw[i - 1][0] * base % mod1;
		pw[i][1] = pw[i - 1][1] * base % mod2;
	}
	int cur = 25e4 + 5;
	fw (i, 0, n) {
		h[i][0] = i ? h[i - 1][0] : 0;
		h[i][1] = i ? h[i - 1][1] : 0;
		if (s[i] == '>') cur++;
		else if (s[i] == '<') cur--;
		else if (s[i] == '+') add(h[i][0], pw[cur][0], mod1), add(h[i][1], pw[cur][1], mod2);
		else rem(h[i][0], pw[cur][0], mod1), rem(h[i][1], pw[cur][1], mod2);
		//cout << "h["<<i<<"][0] = " << h[i][0] << ", 1 = " << h[i][1] << " cur = " << cur << "\n";
		mp[ii(h[i][0], h[i][1])]++;
	}
	cur = 0;
	int ans = 0;
	ans += mp[ii(h[n - 1][0], h[n - 1][1])]; //0 -> any good points
	fw (i, 0, n) {
		if (s[i] == '>') cur++;
		else if (s[i] == '<') cur--;
		mp[ii(h[i][0], h[i][1])]--;
		int pw0, pw1;
		if (cur >= 0) pw0 = pw[cur][0], pw1 = pw[cur][1];
		else pw0 = inv(pw[-cur][0], mod1), pw1 = inv(pw[-cur][1], mod2);
		//cout << (h[n - 1][0] * pw0 + h[i][0]) % mod1 << " " << (h[n - 1][1] * pw1 + h[i][1]) % mod2 << "\n";
		ans += mp[ii((h[n - 1][0] * pw0 + h[i][0]) % mod1, (h[n - 1][1] * pw1 + h[i][1]) % mod2)];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 44052
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(), x.end()
using namespace std;
ll power(ll x, ll y,ll  m) 
{ 
    if (y == 0) 
        return 1; 
    ll  p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
ll modInverse(ll a, ll m) 
{ 
    ll g = __gcd(a, m); 
    if (g != 1) 
        cout << "Inverse doesn't exist"; 
    
    
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
        
              return power(a, m-2, m); 
    
} 

ll fact[1000];
void fac(ll m)
{
	ll i;
	fact[0]=1;
	for(i=1;i<1000;i++)
	{
		fact[i]=(i*fact[i-1])%m;
	}
}

ll comb(ll n,ll k,ll m)
{
	return(fact[n]*modInverse(fact[k],m)%m *modInverse(fact[n-k],m)%m)%m;
}
bool cmp(pair<ll,ll> a,pair<ll,ll>b)
{
	if(a.second==b.second)
	return a.first<b.first;
	return a.second>b.second;
}
void SieveOfEratosthenes(ll n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
     bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;
  //cin>>t;
  t=1;

  while(t-- > 0) {
  	ll k;
  	cin>>k;
  	string s;
  	s="ACL";
  	ll i;
  	for( i=0;i<k;i++)
  	{
  		cout<<s;
	  }
	  cout<<endl;
}
return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  cout << !n << endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  int n=0;
  int m=0;
  int l=0;
  for(int i=0;i<N;i++){
    if(a.at(i)%4==1||a.at(i)%4==3){
      n++;
    }
    else if(a.at(i)%4==0){
      l++;
    }
    else{
      m++;
    }
  }
  if(m==0){
  if(n-l<=1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  }
  else{
    if(n-l<=0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  }
 
}
      

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

const int TOP = 0,FRONT = 1,LEFT = 3, RIGHT = 2,BACK = 4,BOTTOM = 5;
class Dice{
public:
  vector<int> val;
  Dice():val(6){for(int i=0;i<6;i++) val[i] = i;}
  Dice(int val[6]){for(int i=0;i<6;i++) this->val[i] = val[i];}
  Dice(vector<int> val):val(val){assert(val.size() == 6);}
  int& operator [](int a){return val[a];}
  bool operator == (Dice a){
    for(int i=0;i<6;(i%2? a.rotN():a.rotE()),i++)
      for(int j=0;j<4;j++){
        if(val == a.val) return 1;
        a.rotCW();
      }
    return 0;
  }

  void rot(string s){
    if(s == "N" || s == "B") rotN();
    else if(s == "S" || s == "F") rotS();
    else if(s == "E" || s == "R") rotE();
    else if(s == "W" || s == "L") rotW();
    else if(s == "CW") rotCW();
    else if(s == "CCW") rotCCW();
    else assert(!"rot error"); /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  }

  
  void rot(char ch){rot(string(1,ch));}
  
  //奥に転がす
  void rotN(){
    swap(val[TOP],val[FRONT]);
    swap(val[FRONT],val[BOTTOM]);
    swap(val[BOTTOM],val[BACK]);
  }

  //手前に転がす
  void rotS(){
    //rotN(),rotN(),rotN();
    swap(val[TOP],val[BACK]);
    swap(val[BACK],val[BOTTOM]);
    swap(val[BOTTOM],val[FRONT]);
  }
  
  //右に転がす
  void rotE(){
    swap(val[TOP],val[LEFT]);
    swap(val[LEFT],val[BOTTOM]);
    swap(val[BOTTOM],val[RIGHT]);
  }

  //左に転がす
  void rotW(){
    //rotE(),rotE(),rotE();
    swap(val[TOP],val[RIGHT]);
    swap(val[RIGHT],val[BOTTOM]);
    swap(val[BOTTOM],val[LEFT]);
  }

  //上から見て時計回りに回す
  void rotCW(){
    swap(val[FRONT],val[RIGHT]);
    swap(val[RIGHT],val[BACK]);
    swap(val[BACK],val[LEFT]);
  }

  //上からみて反時計回りに回す。
  void rotCCW(){
    //rotCW(),rotCW(),rotCW();
    swap(val[FRONT],val[LEFT]);
    swap(val[LEFT],val[BACK]);
    swap(val[BACK],val[RIGHT]);
  }

  void init(int top,int front){
    for(int i=0;i<6;(i%2? rotN():rotE()),i++)
      for(int j=0;j<4;j++){
        if(val[TOP] == top && val[FRONT] == front) return;
        rotCW();
      }
    assert(!"can not find");
  }
};

int main(){
  int n;
  cin>>n;
  vector<Dice> A(n);
  for(int i=0;i<n;i++)
    for(int j=0;j<6;j++) cin>>A[i][j];
                           
  int ans = 1;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(A[i] == A[j]) ans = 0;
  
  cout<<(ans? "Yes":"No")<<endl;
  return 0;
}



Measured memory_bytes: 3172
// 素数かどうかの判定
#include <stdio.h>
#include <math.h>

#define TRUE 1
#define FALSE 0

int isPrime(int p) {
	// pが2
	if (p == 2) {
		return TRUE;
	}

	// pが2未満 または 偶数
	if (p < 2 || (p % 2) == 0) {
		return FALSE;
	}

	for (int i = 3; i <= sqrt(p); i += 2) {
		if (p % i == 0) {
			return FALSE;
		}
	}
	return TRUE;
}

int main() {
    int i, n, input;
	int cnt = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &input);
		if(isPrime(input)) cnt++;
	}

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


Measured memory_bytes: 2084
import java.util.Scanner;

//Kobutanukitsuneko
public class Main{

	static class N{
		int id, ind, outd;
		boolean v;
		public N(int id) {
			this.id = id;
			v = true;
		}
		public void visit(){
			v = true;
			for(int i=0;i<26;i++){
				if(e[id][i]&&!node[i].v)node[i].visit();
			}
		}
	}
	
	static N[] node;
	static boolean[][] e;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			node = new N[26];
			for(int i=0;i<26;i++)node[i]=new N(i);
			e = new boolean[26][26];
			for(int i=0;i<n;i++){
				char[] s = sc.next().toCharArray();
				int f = s[0]-'a';
				int t = s[s.length-1]-'a';
				node[f].outd++;
				node[t].ind++;
				node[f].v = node[t].v = false;
				e[f][t] = true;
			}
			boolean f = true;
			for(int i=0;i<26;i++){
				if(node[i].ind!=node[i].outd){
					f = false;
					break;
				}
			}
			if(f){
				for(int i=0;i<26;i++){
					if(!node[i].v){
						node[i].visit();
						break;
					}
				}
				for(int i=0;i<26;i++){
					if(!node[i].v)f = false;
				}
			}
			System.out.println(f?"OK":"NG");
		}
	}
}

Measured memory_bytes: 12000
X = int(input())
List = [1]
a =0
for i in range(2,35):
  for j in range(2,11):
    a = i**j
    if a <= 1000:
      List.append(i**j)
    else:
      break
List.sort()
k = 0
for i in range(len(List)):
  if List[i] > X:
    k = i-1
    break
  elif List[i] == X:
    k = i
    break
print(List[k])

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string convL(vector<string> vec)
{
  string str = vec[0];

  for(int i = 1; i < vec.size(); i++){
    string st = vec[i];
    str += (char)('A'+(int)(st[0]-'a'));
    for(int j = 1; j < st.size(); j++){
      str += st[j];
    }
  }

  return str;
}

string convU(vector<string> vec)
{
  string str = "";

  for(int i = 0; i < vec.size(); i++){
    string st = vec[i];
    str += (char)('A'+(int)(st[0]-'a'));
    for(int j = 1; j < st.size(); j++){
      str += st[j];
    }
  }

  return str;
}

string convD(vector<string> vec)
{
  string str = vec[0];

  for(int i = 1; i < vec.size(); i++){
    str += ("_" + vec[i]);
  }

  return str;
}

vector<string> split(string str)
{
  vector<string> vec;
  string s = "";

  for(int i = 0; i < str.size(); i++){
    if(str[i] == '_'){
      vec.push_back(s);
      s = "";
    } else if(str[i] >= 'a' && str[i] <= 'z'){
      s += str[i];
    } else {
      if(s.size() > 0){
	vec.push_back(s);
      }
      s = "";
      s += (char)('a'+(int)(str[i]-'A'));
    }
  }
  if(s.size() > 0){
    vec.push_back(s);
  }

  return vec;
}

int main()
{
  string s1, s2;

  while(cin>>s1>>s2){
    if(s2 == "X"){
      break;
    }
    vector<string> vec = split(s1);

    if(s2 == "L"){
      s1 = convL(vec);
    } else if(s2 == "U"){
      s1 = convU(vec);
    } else {
      s1 = convD(vec);
    }

    cout << s1 << endl;
  }

  return 0;
}

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


int main(void) 
{
    double input;
    cin >> input;
    double len = input / 3;

    double result = len * len * len;

    printf("%.10f\n", result);
}

Measured memory_bytes: 256
function Main(input) {
  	input = input.split("\n")  
	input = input.map(x => x.split(" "))
  	let output = 0
    const D = input[0][1]
  	
  	for(let i=1;i<=input[0][0];i++){
    	if(Math.sqrt(input[i][0]*input[i][0]+input[i][1]*input[i][1]) <= D){
        	output++   
        }
    }
  
    console.log(output)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 105252
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan =new Scanner(System.in);
		int K=scan.nextInt();
		String S=scan.next();
		if(S.length()<=K) {
			System.out.print(S);
		}
		else {
			for(int i=0;i<K;i++)
				System.out.print(S.charAt(i));
			System.out.print("...");
		}
	}

}


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

int main(){
  int N, s = 0;
  cin >> N;
  vector<int> D(N);
  for(int i = 0; i < N; i++){
    cin >> D.at(i);
  }
  for(int i = N-1; i >= 0; i--){
    for(int j = 0; j < D.size()-1; j++){
      s += D.at(i) * D.at(j);
    }
    D.pop_back();
  }
  cout << s << endl;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int n, m, k;
ll v[3005][3005];

ll memo[3005][3005][4];

ll dp(int x, int y, int h) {
	if (x>n or y>m) return 0;
	if (memo[x][y][h] != -1) return memo[x][y][h];
	ll sol = 0;
	if (v[x][y] and h) {
		sol = max(sol, v[x][y] + max(dp(x+1, y, 3), dp(x, y+1, h-1)));
	}
	sol = max(sol, max(dp(x+1, y, 3), dp(x, y+1, h)));
	return memo[x][y][h] = sol;
}

int main() {
	memset(memo, -1, sizeof memo);
	scanf("%d%d%d", &n, &m, &k);
	for (int i=0 ; i<k ; i++) {
		int x, y, w;
		scanf("%d%d%d", &x, &y, &w);
		v[x][y] = w;
	}
	printf("%lld\n", dp(1, 1, 3));
	return 0;
}

Measured memory_bytes: 356876
#include<iostream>

using namespace std;

int main(){
    
    int x1, y1, x2, y2;
    int dif_x, dif_y;

    cin >> x1 >> y1 >> x2 >> y2;

    dif_x = x2 - x1;
    dif_y = y2 - y1;

    cout << x2 - dif_y << " " << y2 + dif_x << " " << x1 - dif_y << " " << y1 + dif_x << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph= vector<vector<int>>;
using coord= pair<int, int>;
const int INF= 1e9;

void solve(const Graph &weights, Graph *dp){
  const int N= weights.size();

  for(int k=0; k<N; k++){
    for(int from=0; from<N; from++){
      for(int to=0; to<N; to++){
        dp->at(from).at(to)= min(dp->at(from).at(to), dp->at(from).at(k)+ dp->at(k).at(to));
      }
    }
  }
}


int main(){
  constexpr char block= '#';
  const vector<coord> diff= {make_pair(0,-1), make_pair(-1,0), make_pair(1,0), make_pair(0,1) }; // 探索方向
  int H,W;
  cin >> H >> W;

  vector<string> board(H);
  for(int h=0; h<H; h++){
    cin >> board.at(h);
  }

  Graph gph(H*W, vector<int>(H*W, INF));
  for(int x=0; x<H; x++){
    for(int y=0; y<W; y++){
      int id_p= x+ y*H;
      if(board.at(x).at(y) != block){
        gph.at(id_p).at(id_p)= 0; 
        for(auto [dx, dy]:diff){
          int id_ngh= (x+dx)+ (y+dy)*H;
          if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
          else if(board.at(x+dx).at(y+dy)==block){
            continue;
          }
          else{
            gph.at(id_p).at(id_ngh)= 1;
            gph.at(id_ngh).at(id_p)= 1;
          }
        }
      }
    }
  }

  Graph dp= gph;
  solve(gph, &dp);

  int ans= -1;
  for(int i=0; i< H*W; i++){
    for(int j=0; j< H*W; j++){
      if(dp.at(i).at(j) != INF){
        ans= max(ans, dp.at(i).at(j));
      }
    }
  }

  
  cout << ans << endl;
}

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

const int INF = 1<<30;

struct STmax{
private:
    int n;
    vector<ll> dat;
public:
    STmax(int siz){
        n = 1;
        while(n < siz)   n *= 2;
        dat.resize(2*n-1, 0);
    }

    void update(int x, ll val){
        x += (n-1);
        dat[x] = val;
        while(x > 0){
            x = (x-1)/2;
            dat[x] = max(dat[2*x+1], dat[2*x+2]);
        }
    }
    
    // focus on k-th node, who controls [l, r)
    ll query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)   r = n;
        if(r <= a || b <= l)    return 0;
        if(a <= l && r <= b)    return dat[k];

        ll lx = query(a, b, 2*k+1, l, (l+r)/2);
        ll rx = query(a, b, 2*k+2, (l+r)/2, r);
        return max(lx, rx);
    }
};

int main(){
    int n;
    cin >> n;
    STmax seg(n+1);
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        seg.update(x, seg.query(0, x)+x);
    }
    cout << (ll)n*(n+1)/2-seg.query(0, n+1) << endl;
}


Measured memory_bytes: 4964
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] a=new int[N];
		for(int i=0;i<N;i++)a[i]=sc.nextInt();
		
		int pl=0;
		int count=1;
		for(int i=1;i<N;i++){
			if(pl==1 && a[i]-a[i-1]<0){
				count++;
				pl=0;
			}
			else if(pl==-1 && a[i]-a[i-1]>0){
				count++;
				pl=0;
			}
			else{
				if(a[i]-a[i-1]>0)pl=1;
				else if(a[i]-a[i-1]<0) pl=-1;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 50656