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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] A = new int[2][N];
        int max = 0;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < N; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < N; i++) {
            int count = 0;
            for (int j = 0; j < N; j++) {
                if (j < i) {
                    count += A[0][j];
                } else if (j == i) {
                    count += A[0][j];
                    count += A[1][j];
                } else {
                    count += A[1][j];
                }
            }
            max = Math.max(max, count);
        }
        System.out.println(max);
    }

}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<ll> a(n), b(m);
  for(i = 0; i < n; i++)
    cin >> a[i];
  for(i = 0; i < m; i++)
    cin >> b[i];
  ll maxa;
  maxa = *max_element(ALL(a));
  ll minb = *min_element(ALL(b));
  if(max(maxa, x) < min(minb, y))
    cout << "No War" << endl;
  else
    cout << "War" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        Reader.init();
        long N=Reader.nextLong();
      	if(N%2==1){
        	println(0);
        }
      	else{
        	long count=0;
            for (long i = 10; N / i >= 1; i *= 5){ 
                count += N / i; 
            }
            println(count);
        }
    }

    static int mod=1000000007;
    public static void read(int arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.nextInt(); } }
    public static void read(long arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.nextLong(); } }
    public static void read(String arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.next(); } }
    public static void print(Object O){ System.out.print(O); }
    public static void println(Object O){ System.out.println(O); }
    public static void display(int arr[]){ System.out.println(Arrays.toString(arr)); }
    public static void display(int arr[][], int N){ for(int i=0;i<N;i++){ System.out.println(Arrays.toString(arr[i])); } }
  	static long gcd(long x, long y) { return y==0 ? x : gcd(y, x % y); }
    static long lcm(long x, long y) { return x*y / gcd(x, y); }
}


class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init() {
        reader=new BufferedReader(new InputStreamReader(System.in));
        tokenizer=new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) {
            tokenizer=new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException { return Integer.parseInt(next()); }
    static double nextDouble() throws IOException { return Double.parseDouble(next()); }
    static long nextLong() throws IOException { return Long.parseLong(next()); }
    static String nextLine() throws IOException { return reader.readLine(); }
}

Measured memory_bytes: 21588
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  vector<int> A;

  rep(i, 3) {
    int a;
    cin >> a;
    A.push_back(a);
  }

  sort(A.begin(), A.end());

  cout << abs(A[1] - A[2]) + abs(A[0] - A[1]) << endl;

  return 0;
}


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

int		main(void)
{
	int		S;

	cin >> S;
	int		i = 1;
	set<int> a;
	for (; ; i++)
	{
		if (!a.count(S))
		{
			a.insert(S);
			if (S % 2 == 0) S /= 2;
			else S = (3 * S) + 1;
		}
		else break;
	}
	cout << i << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  string a[H];
  
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  
  string ans = "Yes";
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      
      if (a[i].at(j) == '#') {
        ans = "No";
        for (int k = 0; k < 4; k++) {
          
          if (i + dy[k] < 0 || i + dy[k] >= H 
              || j + dx[k] < 0 || j + dx[k] >= W) {
            continue;
          }
          
          if (a[i + dy[k]].at(j + dx[k]) == '#') {
            ans = "Yes";
          }
        }
        if (ans == "No") {
          cout << "No" << endl;
          return 0;
        }
      } 
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
//#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;


signed main() {

	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	string s,t;
	cin>>s>>t;

	int a,b;
	cin>>a>>b;	
	string u;
	cin>>u;
	(s==u)?a--:b--;
	cout<<a<<" "<<b;
	return 0;
}





Measured memory_bytes: 256
n=int(input())+1
w = input()
data=[0]*n*2
def update(i,x):
    i+=n
    data[i]=x
    i//=2
    while i:
      data[i]=data[i*2]|data[i*2+1]
      i//=2
def query(l,r):
    l+=n
    r+=n
    s=0
    while l<r:
      if l&1 == 1:
        s|=data[l]
        l+=1
      if r&1 == 1:
        r-=1
        s|=data[r]
      l//=2
      r//=2
    return bin(s).count('1')
def word_num(a):
    return 1<<(ord(a)-97)

for i in range(n-1):
    data[i+n] = word_num(w[i])    
for i in range(n-1,0,-1):
    data[i]=data[i*2]|data[i*2 + 1]

ans=[]
q=int(input())
for i in range(q):
    a,s,t=input().split()
    if a=='1':
        s=int(s)
        update(int(s)-1,word_num(t))
    if a=='2':
        s=int(s)
        t=int(t)
        ans.append(query(int(s)-1,int(t)))
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 43860
#include<stdio.h>
int main(void){
     int a,b,k;
     char op;
     while(op != '?'){
          scanf("%d %c %d",&a,&op,&b);
     
          if (op=='+'){
             k=a+b;
 printf("%d\n",k);

          }else if (op=='-'){
             k=a-b;
 printf("%d\n",k);

          }else if (op=='*'){
             k=a*b;
 printf("%d\n",k);

          }else if (op=='/'){
             k=a/b;
 printf("%d\n",k);

          }
          }
     return 0;
}

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

int N, a;
vector<int> A;

int main(){
  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> a; A.push_back(a);
  }
  sort(A.begin(), A.end());

  for(int i = 1; i < N; i++){
    if(A[i-1] == A[i]){ A[N-1] = 0; break; }
  }

  if(A[N-1]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}



    

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

ANS = 0
if N != 1 and M != 1:
  ANS = N * M - (2 * N + 2 * M -4)
elif N == 1 and M == 1:
  ANS = 1
else:
  ANS = N * M - 2
print(ANS)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------

int main()
{
    Phuong_; /// <3
    double n;
    cin >> n;
    cout << setprecision(10) << n*6.28318530717958623200;
    return 0;
}



Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if((a+b)/2>=c){
    int f=min(d,e);
  int g=max(d,e);
  if(g==d){
    if(c*2<=min(a,b))
      cout<<c*2*d;
    else
  cout<<f*c*2+(g-f)*a;
    }
  else{
    if(c*e*2<=f*c*2+(g-f)*b)
      cout<<c*2*e;
    else
    cout<<f*c*2+(g-f)*b;
    }
  }
  else{
    cout<<a*d+b*e;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
	int n;
	cin >> n;
	if (n%10 == 3) {
		cout << "bon" << endl;
	} else if (n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
		cout << "pon" << endl;
	} else {
		cout << "hon" << endl;
	}
}

Measured memory_bytes: 3564
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    long MOD = (long)(1e9 + 7);

    boolean ok(int p, int w) {
        if ((p & 1) == 1) return false;
        if (((p >> (w)) & 1) == 1) return false;
        for (int b = 0; b <= w; b++) {
            if (((p >>> b) & 3) == 3) {
                return false;
            }
        }
        return true;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);

        int H = sc.nextInt(), W = sc.nextInt(), K = sc.nextInt();

        long[][] dp = new long[H + 1][W + 2];
        dp[0][1] = 1;

        for (int h = 1; h <= H; h++) {
            for (int i = 0; i < (1 << W + 1); i++) {
                if (ok(i, W)) {
                    for (int j = 1; j <= W; j++) {
                        if (((i >> (j - 1)) & 1) == 1) dp[h][j - 1] = (dp[h][j - 1] + dp[h - 1][j]) % MOD;
                        if (((i >> j) & 1) == 1) dp[h][j + 1] = (dp[h][j + 1] + dp[h - 1][j]) % MOD;
                        if (((i >> (j - 1)) & 3) == 0) dp[h][j] = (dp[h][j] + dp[h - 1][j]) % MOD;
                    }
                }
            }
        }
        System.out.println(dp[H][K]);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21972
n,m = map(int, input().split())

h = [int(x) for x in input().split(' ')]
o = ['Good'] * n

road = []
for i in range(m):
    a,b = map(int, input().split())
    
    if(h[a-1] > h[b-1]):
        o[b-1] = 'Bad'
    elif(h[b-1] > h[a-1]):
        o[a-1] = 'Bad'
    else:
        o[a-1] = o[b-1] = 'Bad'

print(o.count('Good'))

Measured memory_bytes: 80436
n=int(input())
s=[0]*n
p=[0]*n
for i in range(n):
  s[i],p[i]=input().split()
a=[[s[i],int(p[i]),i+1]for i in range(n)]
a.sort(key=lambda x:(x[0],-x[1]))     
for i in range(n):
  print(a[i][2])

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll A, B;
    cin >> A >> B;
    bool f = false;

    REP(i,0,10000) {
        ll a = (ll)((double)i * 0.08);
        ll b = (ll)((double)i * 0.10);
        if (A == a && B == b) {
            _PR(i);
            f = true;
            break;
        }
    }

    if(!f) _PR(-1);

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    long long int n;
    long long int ans;
    cin >> n;
    if(n <= 6) ans = 1;
    else if(n <= 11) ans = 2;
    else {
        if(n % 11 == 0) ans = (n/11)*2;
        else {

            ans =(long long int)((n/11.0)*2);
            if(ans % 2 ==0){
                if(ans/2.0*11 < n){
                    ans++;
                }
            }else{
                if((ans-1)/2.0*11+6 < n){
                    ans++;
                }
            }

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

Measured memory_bytes: 256
n, k = map(int, input().split())
s, p, r = map(int, input().split())
t = input()
ans = 0

for i in range(k):
    pre = "0"
    for j in t[i::k]:
        if j != pre:
            pre = j
            if j == "s":
                ans += s
            elif j == "p":
                ans += p
            else:
                ans += r
        else:
            pre = "0"
print(ans)

Measured memory_bytes: 3316
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc124_a.cpp
 * time   : Fri May  1 16:38:09 2020
 * quest  : A - Buttons
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a, b) + max(a, b) - 1) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
double x[300],y[300];
double px[90000],py[90000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf",x+i,y+i);
		int now=0;
		for(int i=0;i<a;i++){
			for(int j=i+1;j<a;j++){
				if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<4.0000001){
					double d=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
					double mx=(x[i]+x[j])/2;
					double my=(y[i]+y[j])/2;
					double s=sqrt(1-d*d/4);
					double theta=atan((y[i]-y[j])/(x[i]-x[j]));
					px[now]=mx-sin(theta)*s;
					py[now++]=my+cos(theta)*s;
					px[now]=mx+sin(theta)*s;
					py[now++]=my-cos(theta)*s;
				}
			}
		}
		int ret=1;
		for(int i=0;i<now;i++){
			int k=0;
			for(int j=0;j<a;j++)if((px[i]-x[j])*(px[i]-x[j])+(py[i]-y[j])*(py[i]-y[j])<1.0000001)k++;
			ret=max(ret,k);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>

typedef long long int ll;


using namespace std;

string a,b;

int main(){
	int cnt=0;
	while(cin>>a){
		b=a;
		reverse(&b[0],&b[b.size()]);
		if(b==a)cnt++;
	}
	cout<<cnt<<endl;
}

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

const int maxn = 2e3 + 13;

int n, a[maxn * 3], dp[maxn][maxn], mxdp, rmx[maxn], cmxdp, crmx[maxn], dpu[maxn];

void Max(int i, int j, int v) {
    int &u = dp[i][j];
    if(v > u)
        u = v;
    dp[j][i] = u;
    rmx[i] = std::max(rmx[i], u);
    rmx[j] = std::max(rmx[j], u);
    mxdp = std::max(mxdp, v);
}

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n * 3; ++i) {
        scanf("%d", a + i);
        a[i] -= 1;
    }
    a[n * 3] = n;
    a[n * 3 + 1] = n;
    memset(dp, 0x80, sizeof(dp));
    memset(rmx, 0x80, sizeof(rmx));
    dp[a[0]][a[1]] = dp[a[1]][a[0]] = 0;
    rmx[a[0]] = rmx[a[1]] = 0;
    mxdp = 0;
    int extra = 0;
    for(int i = 5; i <= 3 * n + 2; i += 3) {
        cmxdp = mxdp;
        memcpy(crmx, rmx, sizeof(*rmx) * (n + 1));
        std::map<int, int> c;
        for(int k = 3; k > 0; --k)
            c[a[i - k]] += 1;
        int u = a[i - 3], v = a[i - 2], w = a[i - 1];
        if(c.size() >= 3) {
            int dpuu = dp[u][u], dpvv = dp[v][v], dpww = dp[w][w];
            for(int j = 0; j <= n; ++j) {
                Max(u, j, crmx[j]);
                Max(v, j, crmx[j]);
                Max(w, j, crmx[j]);
            }
            Max(v, w, std::max({cmxdp, dpuu + 1}));
            Max(u, w, std::max({cmxdp, dpvv + 1}));
            Max(u, v, std::max({cmxdp, dpww + 1}));
        } else if(c.size() >= 2) {
            if(v == w) {
                std::swap(u, w);
            } else if(u == w) {
                std::swap(v, w);
            }
            int dpuu = dp[u][u], dpww = dp[w][w];
            for(int j = 0; j <= n; ++j) {
                dpu[j] = dp[u][j];
            }
            Max(u, u, std::max({cmxdp, dpww + 1}));
            Max(u, w, std::max({cmxdp, dpuu + 1}));
            for(int j = 0; j <= n; ++j) {
                Max(u, j, crmx[j]);
                Max(w, j, std::max({crmx[j], dpu[j] + 1}));
            }
        } else {
            extra += 1;
            Max(v, v, cmxdp - 1);
            for(int j = 0; j <= n; ++j) {
                Max(j, v, crmx[j] - 1);
            }
        }
    }
    printf("%d\n", mxdp + extra);
    return 0;
}

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


int main() {
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll nmny=a*x+b*y;
    ll m=min(x,y);
    ll M=max(x,y);
    ll ahmny=M*2*c;
    ll price=0;
    ll num;
    if(x<y){
        price=b;
        num=x;
    }
    else {
        price=a;
        num=y;
    }
    ll hmny=num*2*c+(M-m)*price;
    ll mny=min(nmny,ahmny);
    mny=min(mny,hmny);

    cout << mny;
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
S = ['#'*(W+2)]
white_num = 0
for _ in range(H):
    s = input()
    white_num += s.count('.')
    S.append('#'+s+'#')
S.append('#'*(W+2))

ans = 0
for h in range(1, H+1):
    for w in range(1, W+1):
        if S[h][w] == '#':
            continue
        C = [[-1]*(W+2) for _ in range(H+2)]
        C[h][w] = 0
        q = deque()
        q.append((h, w))
        xlist = [0, 0, 1, -1]
        ylist = [1, -1, 0, 0]
        while len(q) > 0:
            x, y = q.popleft()
            for i in range(4):
                mx = x + xlist[i]
                my = y + ylist[i]
                if S[mx][my] == '#' or C[mx][my] >= 0:
                    continue
                C[mx][my] = C[x][y] + 1
                q.append((mx, my))
        max_num = 0
        for i in C:
            max_num = max(max_num, max(i))
        ans = max(ans, max_num)
print(ans)


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

int main() {
    int A;
    cin >> A; // 0 ≤ A ≤ 100
    int B;
    cin >> B; // 2 ≤ A ≤ 1000 , B is even
    if (A >= 13) cout << B;
    else {
        if (A <= 12 && A >= 6) cout << B / 2;
        else
           cout << "0";
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using LL = long long;
const int INF = 1e9;

int main(void) {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
const ll MAXN=1e5+10;

int main()//所有的循环已改正 
{
	bool a[35]={0};
	char s[MAXN];
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++){
		a[s[i]-'a']=true;
	}
	for(int i=0;i<26;i++){
		if(!a[i]){
			printf("%c",i+'a');
			return 0;
		}
	}
	printf("None");
	return 0;
}	 


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	
	static int x;
	static int y;
	
	static int gcd(int a, int b) {
		int d = a;
		if(b != 0) {
			int tmp;
			tmp = x;
			x = y;
			y = tmp;
			d = gcd(b, a%b);
			
			tmp = x;
			x = y;
			y = tmp;
			y -= (a / b) * x;
		}
		else {
			x = 1; 
			y = 0;
		}
		return d;
	}
			
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			gcd(a, b);
			
			System.out.println(x + " " + y);
		}
	}
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<ll, ll> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long double ans = (long double)a[0];
    repeat(i, 1, n) {
        ans = (ans + (a[i])) / 2.0;
    }
    cout << setprecision(16) << ans << endl;
}


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

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

  if(a==7 && b==5 && c==5){
    cout << "YES" << endl;
  }
  else if(a==5 && b==7 && c==5){
    cout << "YES" << endl;
  }
  else if(a==5 && b==5 && c==7){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 256
// ITP1_8_A Toggling Cases
import java.io.*;

class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         char[] c = br.readLine().toCharArray();
         for (int i = 0; i < c.length; i++) {
            if (c[i] >= 'A' && c[i] <= 'Z')
               c[i] = Character.toLowerCase(c[i]);
            else if (c[i] >= 'a' && c[i] <= 'z')
               c[i] = Character.toUpperCase(c[i]);
         }

         System.out.println(String.valueOf(c));
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
}

Measured memory_bytes: 16928
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    // len
    vector<int64_t> a;
    int64_t prev = (1L << 30);
    for (auto i : irange(0L, n)) {
        int64_t aa;
        cin >> aa;
        if (prev >= aa) {
            a.push_back(aa);
        }

        prev = aa;
    }

    auto r = irange(1L, static_cast<int64_t>(a.size()) + 1L);
    auto it = partition_point(r.begin(), r.end(), [&a](int64_t t){
        // len, char
        vector<pair<int64_t, int64_t>> seq;

        seq.emplace_back(a[0], 0);
        for (int64_t i_block = 1; i_block < a.size(); ++i_block) {
            auto len = a[i_block];

#if 0
            cerr << "[" << t << "]" << len << endl;
            for (const auto& kv : seq) {
                cerr << kv.first << ", " << kv.second << endl;
            }
#endif
            if (seq.back().first < len) {
                if (seq.back().second == 0) {
                    seq.back().first = len;
                } else {
                    seq.emplace_back(len, 0);
                }
            }

            if (seq.back().first > len) {
                auto ii = partition_point(seq.begin(), seq.end(), [len](const pair<int64_t, int64_t>& pp) {
                    return pp.first < len;
                });
                seq.erase(ii + 1, seq.end());
                seq.back().first = len;
            }

            bool found = false;
            for (int64_t i = seq.size() - 1; i >= 0; --i) {
                auto&& block = seq[i];
                if (block.second + 1 < t) {
                    auto blocklen = (i == 0 ? block.first : block.first - seq[i-1].first);

                    seq.resize(i + 1);
                    if (blocklen == 1) {
                        ++seq[i].second;
                    } else {
                        --seq[i].first;
                        seq.emplace_back(seq[i].first + 1, seq[i].second + 1);
                    }

                    if (seq.back().first < len) {
                        seq.emplace_back(len, 0);
                    }

                    found = true;
                    break;
                }
            }

            if (!found) {
                return true;
            }
        }

        return false;
    });

    cout << *it << endl;
}


Measured memory_bytes: 2420
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n, d int
	fmt.Scan(&n, &d)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var cnt int
	for i := 0; i < n; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		if x*x+y*y <= d*d {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 4956
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
   
int main() 
{
  ll n,m,c1=0,c2=0;
  cin>>n>>m;
  for(ll i=0;i<m;i++)
  {
    c1=c1*10+n;
  }
  for(ll i=0;i<n;i++)
  {
    c2=c2*10+m;
  }
  cout<<max(c1,c2);
}

Measured memory_bytes: 256
import itertools
import math

N = int(input())
XY = []
for i in range(N):
    x, y = map(int, input().split())
    XY.append([x, y])

_sum = 0
for v in itertools.permutations(XY, N):
    for i in range(1, len(v)):
        ve = (v[i][0]-v[i-1][0])**2 +  (v[i][1]-v[i-1][1]) ** 2
        _sum += math.sqrt(ve)

print(_sum/math.factorial(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, q; scanf("%d%d", &n, &q); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);

	std::vector<i64> s(n + 1), s2(n + 1);
	for(int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	for(int i = 0; i < n; i++) s2[i + 1] = s2[i] + (n % 2 != i % 2 ? a[i] : 0);
	while(q--) {
		int x; scanf("%d", &x);
		
		int ok = 0, ng = n + 1;
		while(std::abs(ok - ng) > 1) {
			int mid = (ok + ng) >> 1;
			int d = mid;
			
			if(a[n - mid] < x) ng = mid;
			else {
				if(2 * d - 1 > n) ng = mid;
				else {
					if(a[n - d] - x < x - a[n - (2 * d - 1)]) ng = mid;
					else ok = mid;
				}
			}
		}
		int d = ok;
		
		i64 ans = (s[n] - s[n - d]);
		if(n - 2 * d > 0) ans += s2[n - 2 * d];
		printf("%lld\n", ans);
	}
	return 0;
}


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

int main()
{
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  bool F=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      if(i*j+(n-i)*(m-j)==k){
	F=1;
      }
    }
  }
  puts(F?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
#define INF 1e10

using namespace std;

int main() {
    ios
    ll n, k;
    cin>>n>>k;
    vector <ll> a(n);
    repi(i, n) cin>>a[i];
    bool dp[k+1];
    ll a_min = k;
    repi(i, n) a_min = min(a_min, a[i]);
    repi(i, k+1){
        dp[i] = false;
        repi(j, n) if(i>=a[j]) dp[i] |= !dp[i-a[j]];
    }
    cout<<(dp[k] ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    string s;
    cin >> s;
    int ans = 0;
    for(const auto &c:s) {
        ans += c - '0';
    }
    cout << ans << endl;
}

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

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> okasi(n);
  for(int i=0;i<k;i++){
    int d;
    cin >> d;
    for(int j=0;j<d;j++){
      int a;
      cin >> a;
      okasi.at(a-1)=1;
    }
  }
  int count =0;
  for(int i=0;i<n;i++){
    if(okasi.at(i)==0){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int N;
	cin >> N;
	int low = 0, high = N;
	while (high-low > 1) {
		const int med = (low+high)/2;
		ll tmp = (ll)(med) * (med-1)/2;
		if (tmp+med >= N) high = med;
		else low = med;
	}
	int rest = N;
	for (int i = high; i > 0; i--) {
		if (i <= rest) {
			cout << i << endl;
			rest -= i;
		}
	}
	return 0;
}


Measured memory_bytes: 384
f = lambda :list(map(int,input().split()))
N = int(input())
A1 = f()
A2 = f()

dp = [[0 for i in range(N)] for j in range(2)]

dp[0][0] = A1[0]
dp[1][0] = dp[0][0] + A2[0]

for i in range(1,N):
    dp[0][i] = dp[0][i-1] + A1[i]
for j in range(1,N):
    dp[1][j] = max((dp[0][j], dp[1][j-1])) + A2[j]

print(dp[1][N-1])


Measured memory_bytes: 3064
#include <iostream>
#include <unordered_map>

using namespace std;

int main()
{
    // INPUT
    int n;
    cin >> n;
    
    unordered_map<string, int> banyak;
    banyak["AC"] = 0;
    banyak["AC"] = 0;
    banyak["AC"] = 0;
    banyak["AC"] = 0;
    string in;
    while(n--){
        cin >> in;
        
        banyak[in] ++;
    }
    
    // OUTPUT
    cout << "AC x " << banyak["AC"] << endl
        <<  "WA x " << banyak["WA"] << endl
        <<  "TLE x " << banyak["TLE"] << endl
        <<  "RE x " << banyak["RE"] << endl;
    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    for(int i = 0; i < n; ++i){
        ll pi;
        cin >> pi;
        p.at(i) = make_pair(pi, i);
    }
    sort(p.begin(), p.end(), greater<pair<ll, ll>>());

    multiset<ll> s;
    s.insert(n); s.insert(n);
    s.insert(-1); s.insert(-1);
    ll ans = 0;
    for(auto x : p){
        s.insert(x.second);
        const auto it = s.find(x.second);

        // 1 番大きい値を左側に置く場合
        ans += x.first * (*prev(it, 1) - *prev(it, 2)) * (*next(it, 1) - *it);

        // 1 番大きい値を右側に置く場合
        ans += x.first * (*it - *prev(it, 1)) * (*next(it, 2) - *next(it, 1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    cin>>a;
    b=a;
    reverse(b.begin(),b.end());
    if(a!=b)
    {
        cout<<"No";
        return 0;
    }
    int n=a.size();
    b=a.substr(0,(n-1)/2);
    c=b;
    reverse(c.begin(),c.end());
    if(c!=b)
    {
        cout<<"No";
        return 0;
    }
    b=a.substr((n+1)/2,n-1);
    c=b;
    reverse(c.begin(),c.end());
    if(c!=b)
    {
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i=0;i<(n); ++i)
using namespace std;
typedef long long ll;


int main()
{
	string s;
	cin >> s;
	vector<char>stack;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'S')stack.push_back('S');
		else {
			if (stack.size() == 0)stack.push_back('T');
			else if (stack[stack.size() - 1] == 'S')stack.pop_back();
			else stack.push_back('T');
		}
	}
	cout << stack.size() << endl;
}

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

int main()
{
	int k,s;
	cin >> k >> s;
	int count = 0;
	
	for(int i = 0; i <= k; i++) {	
		for(int j = max(0, s - k - i); j <= k && i+j <= s; j++) {
			count++;
		}
	}
	cout << count << endl;
}

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

int main()
{
    long n;
    cin >> n;
    vector<long long> a(n);
    map<long long, long> pc, nc;
    for (long i = 0; i < n; i++)
    {
        cin >> a[i];
        pc[a[i] + (i+1)] ++;
        if ((i+1) - a[i] >= 0)
            nc[(i+1) - a[i]] ++;
    }
    long long fans = 0;
    for (auto i: pc)
    {
        fans += i.second * nc[i.first];
    }
    cout << fans;
    return 0;
}

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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK cerr <<"OK"<< endl
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

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

  int a, b;

  cin >> a >> b;

  if(1 <= a && a <= 9 && 1 <= b && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define ll long long
#define int ll
#define endl "\n"

signed main () {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	string nums;
	cin >> nums;
	int current = 0;
	for (int i = 0; i < nums.size(); i++) {
		int digit = (nums[i] - '0');
		current += digit;
	}
	if (current % 9 == 0) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;

}


Measured memory_bytes: 3780
#include <algorithm>
#include <iostream>
#include <stdint.h>
#include <vector>
 
using namespace std;
 
int32_t main()
{
  uint32_t N;
  cin >> N;
 
  vector<uint64_t> lines;
  for (uint32_t _ = 0; _ < N; _++) {
    uint64_t line;
    cin >> line;
    lines.push_back(line);
  }
 
  sort(lines.begin(), lines.end());
 
  uint64_t width_found = false;
  uint64_t width = 0;
  uint64_t height = 0;
 
  while (!lines.empty()) {
    uint64_t line = lines.back();
    if (!width_found) {
      if (width == line) {
        width_found = true;
      } else {
        width = line;
      }
    } else {
      if (height == line) {
        break;
      } else {
        height = line;
      }
    }
    lines.pop_back();
  }
 
  cout << width * height << endl;
 
  return 0;
}

Measured memory_bytes: 1400
void main()
{
    long n = rdElem;
    long[] p = rdRow;

    long cnt;
    long pmax = p[0];
    foreach (x; p)
    {
        if (x <= pmax) ++cnt;
        pmax = min(pmax, x);
    }

    cnt.writeln;
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 11536
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n ;
	map<int, int>a;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	int ret =0;
	for (auto itr = a.begin(); itr != a.end(); ++itr) {
		int key = itr->first;
		int value = itr->second;
		int ans = value;
		if (itr != a.begin()) {
			if (prev(itr)->first == key - 1)ans += prev(itr)->second;
		}
		if (next(itr)!=a.end()) {
			if (next(itr)->first == key + 1)ans += next(itr)->second;
		}
		ret = max(ans, ret);
	}
	print(ret);
}

Measured memory_bytes: 7432
#include<iostream>
using namespace std;
int main()
{
	const int MAX = 100;
	int A[MAX][MAX], B[MAX][MAX]; 
        long C[MAX][MAX] = {0};
	int n, m, l;
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];
	for (int i = 0; i < m; i++)
		for (int j = 0; j < l; j++)
			cin >> B[i][j];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < l; j++)
			for (int k = 0; k < m; k++)
				C[i][j] += A[i][k] * B[k][j];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
			if (j != l - 1)
				cout << C[i][j] << " ";
			else
				cout << C[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 3156
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main() {
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
  if(x>=0&&x+r<=W&&y>=0&&y+r<=H){
    cout<<"Yes"<<endl;
    }
  else{
    cout<<"No"<<endl;
    }
 }

Measured memory_bytes: 1160
'''
問題：
    整数 A, B があります。

    A + B, A − B, A ×B
    の中で最大の数を出力してください。
'''

'''
制約：
入力は全て整数である。
−100 ≤ A, B ≤ 100
'''

# 標準入力から A, B の値を取得する
a, b = map(int, input().split())

result_list = [a + b, a - b, a * b] # 結果格納用リスト

print(max(result_list))


Measured memory_bytes: 9144
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
constexpr double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<lint> a(n), b(n);
    rep(i, n){
        cin >> a[i];
    }
    priority_queue< LLP > que;
    rep(i, n){
        cin >> b[i];
        if(b[i] > a[i]){
            que.push({b[i], (lint)i});
        }
    }

    lint ans = 0;
    while(!que.empty()){
        LLP p = que.top();
        que.pop();
        lint dif = b[p.second] - a[p.second];
        lint cnt = dif / (b[(p.second - 1 + n) % n] + b[(p.second + 1) % n]);
        if(cnt == 0LL){
            cout << -1 << endl;
            return 0;
        }
        b[p.second] -= cnt * (b[(p.second - 1 + n) % n] + b[(p.second + 1) % n]);
        ans += cnt;
        if(b[p.second] > a[p.second]){
            que.push({b[p.second], p.second});
        }
    }

    cout << ans << endl;

    return 0;
}

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

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

typedef pair<int, int>P;

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


struct edge { int to; double cost; };
int V;//頂点数
vector<edge>G[MAX];
double d[MAX];//始点からの距離
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < (double)p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

double dist(int x1, int y1, int x2, int y2) {
	return sqrt((double)((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));
}
double dist2(int x1, int y1, int x2, int y2, int r1, int r2) {
	return max((double)0, dist(x1, y1, x2, y2) - r1 - r2);
}

int x[1010], y[1010], r[1010];
int xs, ys, xg, yg;
signed main() {
	int N;


	cin >> xs >> ys >> xg >> yg;
	cin >> N;
	V = N + 2;
	x[0] = xs, y[0] = ys, r[0] = 0, x[N + 1] = xg, y[N + 1] = yg, r[N + 1] = 0;
	FOR(i,1, N+1) {
		cin >> x[i] >> y[i] >> r[i];
	}
	REP(i, N + 2) {
		FOR(j, i + 1, N + 2) {
			double di = dist2(x[i], y[i], x[j], y[j], r[i], r[j]);
			G[i].push_back({ j,di} );
			G[j].push_back({ i,di });
		}
	}
	dijkstra(0);
	cout << setprecision(10) << d[N + 1] << endl;;
}	


Measured memory_bytes: 47892
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int ans=0;
  for(Int i=0;i<n;i++) if(a[i]%2==0) ans++;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T>
struct BIT{
  //0オリジンで与える
  vector<T>bit;
  int N;

  BIT(int n):N(n){
    bit.assign(++n,0);
  }

  T sum(int i){
    T s=0;
    ++i;//0オリジンに対応させる
    while(i>0){
      s+=bit[i];
      i-=i&-i;//iから最後の1のビットを減算
    }
    return s;
  }

  void add(int i,T x){
    ++i;//0オリジンに対応させる
    while(i<(int)bit.size()){
      bit[i]+=x;
      i+=i&-i;
    }
  }

  T Lower_bound(T k){
    if(k<=0)
      return 0;
    T x = 0;
    T mul = 1;
    while (mul<N){
      mul *= 2;
    }
    for (T i = mul; i > 0;i/=2){
      if(x+i<=N&&bit[x+i]<k){
        k -= bit[x + i];
        x += i;
      }
    }
    return x;
  }
};

void solve()
{
	int n,q;
	cin>>n>>q;
	vector<int>used(n,-1);
	vector<int>c(n);
	vector<pair<int,int>>v;
	rep(i,n){
		cin>>c[i];
		c[i]--;
		if(used[c[i]]!=-1){
			v.eb(used[c[i]],i);
			used[c[i]]=i;
		}
		else {
			used[c[i]]=i;
		}
	}
	vector<pair<pair<int,int>,int>>query(q);
	rep(i,q){
		cin>>query[i].first.first>>query[i].first.second;
		query[i].first.first--;
		query[i].first.second--;
		query[i].second=i;
	}
	if(!v.empty())sort(rall(v));
	sort(rall(query));
	vector<int>ans(q);
	// for(auto x:v){
	// 	cout<<x.first<<" "<<x.second<<"\n";
	// }
	int pos=0,qpos=0;
	BIT<int>tree(n);
	for(int i=n-1;i>=0;--i){
		while(pos<v.size()&&v[pos].first==i){
			tree.add(v[pos].second,1);
			pos++;
		}
		while(qpos<q&&query[qpos].first.first==i){
			ans[query[qpos].second]=(query[qpos].first.second-query[qpos].first.first+1)-tree.sum(query[qpos].first.second);
			qpos++;
		}
	}
	rep(i,q){
		cout<<ans[i]<<"\n";
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 20780
#include <stdio.h>
int main(int argc, char const *argv[]) {
  int s,s1,s2,s3,s4;
  scanf("%d",&s );
  s1=s/1000;
  s2=(s-s1*1000)/100;
  s3=(s-s1*1000-s2*100)/10;
  s4 =(s-s1*1000-s2*100-s3*10);

  if(s1==s2 || s2==s3 || s3 == s4){
    printf("Bad");
  }else{
    printf("Good" );
  }
  return 0;
}


Measured memory_bytes: 128