akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

N = int(input())
cnt = defaultdict(int)

for i in range(1, N + 1):
    h = str(i)[0]
    f = str(i)[-1]
    if f == '0':
        continue
    cnt[(h, f)] += 1

ans = 0
dlst = list(cnt.items())
for i, v in dlst:
    ans += v * cnt[i[1], i[0]]

print(ans)

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 14:34:05 2020

@author: shinba
"""

a,b,k = map(int,input().split())

if a >= k:
    print(a-k,b)
elif a+b >= k:
    print(0,a+b-k)
else:
    print(0,0)


Measured memory_bytes: 2940
#include <iostream>

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

  if ((a + b) % 2 == 0) {
    std::cout << (a + b) / 2 << std::endl;
  } else {
    std::cout << (a + b) / 2 + 1 << std::endl;
  }
}

Measured memory_bytes: 256
"""
https://atcoder.jp/contests/intro-heuristics/tasks/intro_heuristics_a
"""

import numpy as np


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N, = load_input_as_int_array()
    focus = N % 1000
    result = 1000 - focus if focus != 0 else 0
    print(result)


main()


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007

typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li sum = 0;
li n, k;

li a[555];
li b[555];
li bs[555];

inline bool check(li x) {
    rin{
        b[i] = a[i] % x;
    }
    sort(b, b + n);
    bs[0] = 0;
    rin{
        bs[i + 1] = bs[i] + b[i];
    }
    li res = INF;
    rep(i, n + 1) {
        res = min(res, max(bs[i], (x * (n - i) - (bs[n] - bs[i]))));
    }
    return res <= k;
}

int main() {
    cin >> n >> k;
    rin{
        cin >> a[i];
        sum += a[i];
    }
    li res = 1;
    repp(i, 1, sqrt(sum) + 2) {
        if (sum % i == 0) {
            if (check(i)) {
                res = max(res, i);
            }
            if (check(sum / i)) {
                res = max(res, sum / i);
            }
        }
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 256
import math

X = int(input())

i = 0
while i < 1:
  sq = int(math.sqrt(X) // 1)
  j = 0
  for k in range(1, sq+1, 1):
    if X % k != 0:
      j += 1
  else:
    if j == sq-1:
      print(X)
      break
    else:
      j = 0
      X += 1

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

int main()
{
	int num = 0;
	int A, B, C, D;
	cin >> num;
	A = num / 1000;
	num = num % 1000;
	B = num / 100;
	num = num % 100;
	C = num / 10;
	D = num % 10;
	for (int b = -1; b <= 1; b += 2) {
		for (int c = -1; c <= 1; c += 2) {
			for (int d = -1; d <= 1; d += 2) {
				if (A + b*B + c*C + d*D == 7) {
					cout << A;
					if (b == -1) cout << "-";
					else cout << "+";
					cout << B;
					if (c == -1) cout << "-";
					else cout << "+";
					cout << C;
					if (d == -1) cout << "-";
					else cout << "+";
					cout << D << "=" << 7 << endl;
					return 0;
				}
			}
		}
	}
    return 0;
}

Measured memory_bytes: 256
A,B,C=map(int,input().split())
K=int(input())
a=A
b=B
c=C
ans=0
for i in range(8):
  if b<=a:
    b*=2
    ans+=1
for i in range(8):
  if c<=b:
    c*=2
    ans+=1
if ans<=K:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9184
using System;

namespace B___NarrowRectanglesEasy
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var w = int.Parse(input[0]);
            var a = int.Parse(input[1]);
            var b = int.Parse(input[2]);
            var c = Math.Max(a, b) - (Math.Min(a, b) + w);
            if (c >= 0)
            {
                Console.WriteLine(c);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(x,y) x=min(x,y)
using namespace std;
using P = pair<int,int>;

const int INF = 1001001001;

int main() {
  int N,M,L;
  cin >> N >> M >> L;
  vector<vector <int>> dist(N,vector<int>(N,INF));
  rep(i,N) dist[i][i] = 0;
  rep(i,M) {
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k,N) rep(i,N) rep(j,N) chmin(dist[i][j],dist[i][k]+dist[k][j]);
  vector<vector <int>> dist2(N,vector<int>(N,INF));
  rep(i,N) rep(j,N) {
    if(dist[i][j] <= L) dist2[i][j] = 1;
  }
  rep(k,N) rep(i,N) rep(j,N) chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  int q;
  cin >> q;
  rep(qi,q) {
    int s,t;
    cin >> s >> t;
    --s; --t;
    int ans = dist2[s][t] -1;
    if(dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
int a[510][510];
long long b[510][510], g[510][510];
long long dp[510][510];
inline void upd(long long &v, long long x) {
	if (v > x) v = x;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			scanf("%d", &a[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			g[i][j] = g[i][j-1];
			for (int k = i; k < j; k++) {
				g[i][j] += a[k][j];
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			b[i+1][j+1] = b[i+1][j] + b[i][j+1] + a[i][j] - b[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i - 1; j > 0; j--) {
			dp[i][j] = 1ll << 60;
			for (int k = j - 1; k >= 0; k--) {
				upd(dp[i][j], dp[j][k] + g[j][i-1] + b[i][k] - b[j][k]);
			}
		}
		dp[i][0] = g[0][i-1];
	}
	long long ans = 1ll << 60;
	for (int i = 0; i < n; i++) {
		upd(ans, dp[n][i]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 7168
import java.util.Scanner;                          
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);    
        int a = stdIn.nextInt();  
        int b = stdIn.nextInt(); 
        int c = a*b;
        int d = 2*(a+b);
        System.out.println( c + " " + d );
                         
    }
}

Measured memory_bytes: 26108
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL);
    char x;
    cin>>x;
    if(isupper(x))cout<<"A";
    else cout<<"a";
    
    return 0;
}



Measured memory_bytes: 3604
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N, M = getNM()
A = getList()
A.sort()

lista = []
for i in range(M):
    b, c = getNM()
    lista.append([b, c])
lista.sort(reverse = True,key = lambda i:i[1])

listalta = [0]
for i in range(M):
    listalta.append(listalta[i] + lista[i][0])
listalta.pop(0)

for i in range(N):
    index = bisect_left(listalta, i + 1)
    # index >= M(indexが枠外に飛んでないか)
    if index != M and A[i] < lista[index][1]:
        A[i] = lista[index][1]
print(sum(A))

Measured memory_bytes: 81508
#include <stdio.h>

int gcd(int a,int b){
  if(a%b==0) return b;
  return gcd(b,a%b);
}
 
int main(){
  int k;
  scanf("%d",&k);
  int ans = 0;
  for(int a = 1; a<=k; a++){
    for(int b = 1; b<=k; b++){
      for(int c = 1; c<=k; c++){
        ans += gcd(gcd(a,b),c);
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,d;
	cin>>n>>d;
	vector<vector<int>> x(n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<d;j++)
		{
			int val;
			cin>>val;
			x[i].push_back(val);
		}
	}	
	int res=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int dist = 0;
			for(int k=0;k<d;k++)
				dist+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			int m = sqrt(dist);
			if(m*m==dist)++res;
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
  string s, t;
  int ans = 0;
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++)
  {
    if (s[i] != t[i])
    {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 3908
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int ans = a + (int) Math.pow(a, 2) + (int) Math.pow(a, 3);
        System.out.println(ans);
   }
}

Measured memory_bytes: 35684
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=1e6+9;
const int mod=1e9+7;
using namespace std;
int cnt[MAX];

int main(){
	ll a,b,c;
	int n;
	int arr[10];
	int k;
	for(int i=1;i<=5;i++)
		cin>>arr[i];
	sort(arr+1, arr+6);
	int mn=INT_MAX;
	do{
		int res=0;
	for(int i=1;i<=5;i++){
		while(res%10!=0)
			res++;
		res=res+arr[i];
		
	}
	mn=min(res, mn);
}while(std::next_permutation(arr+1 ,arr+6));
	cout<<mn;
	

}

Measured memory_bytes: 256
MAX = 10**9 + 7

def mod_inv(i, mod):
    return pow(i, mod-2, mod)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up = up * (_N - i) % MAX
        low = low * (i + 1) % MAX
    ret = up * mod_inv(low, MAX) % MAX
    return ret

def solve():
    N, K = [int(_) for _ in raw_input().split()]
    for i in range(1, K+1):
        if i == 1:
            ret = N - K + 1
        else:
            ret = combination(K-1, i-1)
            if i - 1 > N - K:
                ret = 0
            elif i - 1 < N - K:
                # ret = (ret * pow(i+1, N -K-i+1, MAX))%MAX
                ret = (ret * combination(N-K+1, i))%MAX
        print ret

if __name__ == '__main__':
    solve()


Measured memory_bytes: 32620
S=input()
a = 0
for i in range(len(S)):
  if i%2==0 :
    if S[i] != "L":
    	a += 1
  else:
    if S[i] != "R":
    	a += 1
if a == len(S):
  print("Yes")
else:
  print("No")

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

int main(){
  long long int H, W;
  cin >> H >> W;

  long long int a, b, c;
  long long int ans = LLONG_MAX;
  vector<long long int> v(100001);

  //case0
  if(H % 3 == 0){
    ans = 0;
  }
  else{
    for(int i = 1; i < H; i++){
      a = i * W;
      b = ((H - i) / 2) * W;
      c = H * W - a - b;
      v.at(i) = max(a, max(b, c)) - min(a, min(b, c));
      ans = min(ans, v.at(i));
    }
    for(int i = 1; i < H; i++){
      a = i * W;
      b = (H - i) * (W / 2);
      c = H * W - a - b;
      v.at(i) = max(a, max(b, c)) - min(a, min(b, c));
      ans = min(ans, v.at(i));
    }
  }

  //case1
  if(W % 3 == 0){
    ans= 0;
  }
  else{
    for(int i = 1; i < W; i++){
      a = H * i;
      b = H * ((W - i) / 2);
      c = H * W - a - b;
      v.at(i) = max(a, max(b, c)) - min(a, min(b, c));
      ans = min(ans, v.at(i));
    }
    for(int i = 1; i < W; i++){
      a = H * i;
      b = H / 2 * (W - i);
      c = H * W - a - b;
      v.at(i) = max(a, max(b, c)) - min(a, min(b, c));
      ans = min(ans, v.at(i));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
  int maxnum,max,in1,in2,i;
  while(scanf("%d %d",&in1,&in2) && in1 && in2){
    max=in1+in2+(maxnum=0);
    for(i=1;i<=4;i++){
      scanf("%d %d",&in1,&in2);
      if(in1+in2>max) max=in1+in2,maxnum=i;
    }
    printf("%c %d\n",'A'+maxnum,max);
  }
  return 0;
}

Measured memory_bytes: 600
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		
		if((B-A)%2==0) {
			System.out.println((B-A)/2);
		}
		else {
			long cand = N-B+1+(B-A-1)/2;
			long cand2 = A+(B-A-1)/2;
			System.out.println(Math.min(cand, cand2));
		}

//		out.println(result);

//		out.flush();
	}


}

//class FastScanner {
//	private final InputStream in = System.in;
//	private final byte[] buffer = new byte[1024];
//	private int ptr = 0;
//	private int buflen = 0;
//	private boolean hasNextByte() {
//		if (ptr < buflen) {
//			return true;
//		}else{
//			ptr = 0;
//			try {
//				buflen = in.read(buffer);
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//			if (buflen <= 0) {
//				return false;
//			}
//		}
//		return true;
//	}
//	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
//	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
//	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
//	public String next() {
//		if (!hasNext()) throw new NoSuchElementException();
//		StringBuilder sb = new StringBuilder();
//		int b = readByte();
//		while(isPrintableChar(b)) {
//			sb.appendCodePoint(b);
//			b = readByte();
//		}
//		return sb.toString();
//	}
//	public long nextLong() {
//		if (!hasNext()) throw new NoSuchElementException();
//		long n = 0;
//		boolean minus = false;
//		int b = readByte();
//		if (b == '-') {
//			minus = true;
//			b = readByte();
//		}
//		if (b < '0' || '9' < b) {
//			throw new NumberFormatException();
//		}
//		while(true){
//			if ('0' <= b && b <= '9') {
//				n *= 10;
//				n += b - '0';
//			}else if(b == -1 || !isPrintableChar(b)){
//				return minus ? -n : n;
//			}else{
//				throw new NumberFormatException();
//			}
//			b = readByte();
//		}
//	}
//	public int nextInt() {
//		long nl = nextLong();
//		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
//		return (int) nl;
//	}
//	public double nextDouble() { return Double.parseDouble(next());}
//}
//


Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;

static const int maxW = 50, maxH = 50;
static const int INF = 100000;
typedef pair<int ,int> P;

int main(void){
  //score = H*W - (mindist + 1)
  //queue構造で最短経路を求めて，そこからscoreを求める。
  int H, W;
  char s[maxH][maxW];
  int d[maxH][maxW];
  int numDot = 0;
  int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> s[i][j];
      d[i][j] = INF;
      if(s[i][j] == '.') numDot++;
    }
  }
  queue<P> que;
  que.push(P(0, 0));
  d[0][0] = 0;

  while(que.size()){
    P qFir = que.front(); que.pop();//最初のqueueを取り出す
    if(qFir.first == W - 1 && qFir.second == H - 1) break;//終了条件
    for(int i = 0; i < 4; i++){
      int newX = qFir.first + dx[i], newY = qFir.second + dy[i];
      if(newX >= 0 && newX < W && newY >= 0 && newY < H && d[newY][newX] == INF && s[newY][newX] != '#'){
        //cout << newX << " " << newY << endl;
        que.push(P(newX, newY));
        d[newY][newX] = d[qFir.second][qFir.first] + 1;
      }
    }
  }
  if(d[H - 1][W - 1] == INF) cout << -1 << endl;
  else cout << numDot - d[H - 1][W - 1] - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void check(int, int);

int main(void) {
    int h, w;
    while(scanf("%d %d", &h, &w), h || w) {
        check(h, w), printf("\n");
    }
    return 0;
}

void check(int h, int w) {
    int i, j;
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            if((i + j) % 2) {
                printf(".");
            } else {
                printf("#");
            }
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
N = int(input())
A = list(map(int, input().split()))

def long_repeat(line):
    cnt = 1
    max = 1
    if line != "":
        for i in range(1,len(line)):
            if line[i] == line[i-1] and line[i]==1and line[i-1]==1:
                cnt+=1
                if cnt > max:
                    max = cnt
            else:
                cnt = 1
        return max
    else:
        return 0
if sum(A) == 0:
    print(1)
else:
    print(long_repeat(A)+1)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};



int main(){
    ll n;   cin >> n;
    vector<pair<ll, ll>> a(n);
    rep(i, n){
        cin >> a[i].first;
        a[i].second = i+1;
    }
    sort(ALL(a));
    set<ll> st;
    st.insert(0);st.insert(n+1);
    ll res=0;
    rep(i, n){
        ll index=a[i].second;
        auto itr = st.lower_bound(index);
        ll right = *itr;
        ll left = *prev(itr);
        st.insert(index);
        //cout << a[i].second-left << ' ' << right-a[i].second << endl;
        res += a[i].first*(left-a[i].second)*(a[i].second-right);
    }
    cout << res << endl;
}


Measured memory_bytes: 15596
#include <stdio.h>
#include <math.h>

typedef struct {
	double x,y;
} pt; 

void split(int n, pt a, pt b){
	pt s,t,u;
	double r=3.14159265358979323846*60.0/180.0;
	
	if(n==0)
		return;
		
	s.x=(2.0*a.x+1.0*b.x)/3.0;  	s.y=(2.0*a.y+1.0*b.y)/3.0;
	t.x=(1.0*a.x+2.0*b.x)/3.0;  	t.y=(1.0*a.y+2.0*b.y)/3.0;
	u.x=(t.x-s.x)*cos(r)-(t.y-s.y)*sin(r)+s.x;	u.y=(t.x-s.x)*sin(r)+(t.y-s.y)*cos(r)+s.y;

	split(n-1,a,s);
	printf("%.5f %.5f\n",s.x,s.y); 
	split(n-1,s,u);
	printf("%.5f %.5f\n",u.x,u.y); 
	split(n-1,u,t);
	printf("%.5f %.5f\n",t.x,t.y); 
	split(n-1,t,b);
}

int main(){
	pt p1 = {0,0},p2 = {100,0};

	int n;
	
	scanf("%d",&n);
	printf("%.5f %.5f\n", p1.x, p1.y);
	
	split(n,p1,p2);
	
	printf("%.5f %.5f\n",p2.x,p2.y);
	
	return 0;
}



Measured memory_bytes: 2144
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long[] ar = new long[n];
		long min = 0;
		long tmp = 0;
		
		ar[0] = s.nextLong();
				
		for(int i = 1; i < n; i++) {
			
			tmp = s.nextLong();
			
			if(tmp < ar[i-1])
				min += ar[i-1] - tmp;
			
			ar[i] = Math.max(ar[i-1], tmp);
			
		}
		
		
		System.out.println(min);
		

	}

}

Measured memory_bytes: 60864
p, r, a, o = 0, 0, 0, 0
while True:
    l, m, n = map(int, input().split())
    if l > m:
        l, m = m, l
    if m > n:
        m, n = n, m
    if l > m:
        l, m = m, l
    if l + m <= n:
        break
    if l ** 2 + m ** 2 == n ** 2:
        r += 1
    elif l ** 2 + m ** 2 > n ** 2:
        a += 1
    elif l ** 2 + m ** 2 < n ** 2:
        o += 1
    p += 1
print(p, r, a, o)


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

int main(){
    int n, x;
    cin >> n >> x;
    int pulos[n];
    int qtd_pulos = 1 ;
    int dist = 0;
    for(int i =0;i< n;i++){
        cin >> pulos[i];
        if(dist +pulos[i] <= x){
            dist = dist + pulos[i];
            qtd_pulos++;
        }
        else{
            break;
        }
    }

    cout << qtd_pulos<< endl;
}


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

#define NIL -2000000000

typedef struct{
  int k;
  int lk;
  int rk;
}Node;

void maxHeapify(Node *, int, int);
void buildMaxHeap(Node *,int);

int main(){

  Node *A;
  int h,i,x;

  scanf("%d",&h);

  A = malloc((h+1)*sizeof(Node));

  for(i = 1 ; i <= h ; i++) A[i].k = A[i].lk = A[i].rk = NIL;


  for(i = 1 ; i <= h ; i++){
    scanf("%d",&x);

    A[i].k = x;
    if(i%2 == 0) A[i/2].lk = x;
    else if(i%2 == 1) A[i/2].rk =x;

  }

  buildMaxHeap(A, h);

  for(i = 1 ; i <= h ; i++){

    printf(" %d",A[i].k);

  }

  printf("\n");

  return 0;

}


void buildMaxHeap(Node *A, int h){
  int i;
  for(i = h/2 ; i >= 1 ; i--)
    maxHeapify(A, i, h);
}

void maxHeapify(Node *A, int i, int h){
  int l, r, largest,tmp;

  l = i*2;
  r = i*2+1;

  if(l <= h && A[l].k > A[i].k) largest = l;
  else largest = i;

  if(r <= h && A[r].k > A[largest].k) largest = r;


  if(largest != i){
    tmp = A[i].k;
    A[i].k = A[largest].k;
    A[largest].k = tmp;
    maxHeapify(A, largest, h);
  }

}

Measured memory_bytes: 6460
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    n <- readLn :: IO Int
    cs <- U.unfoldrN n B.uncons <$> B.getLine
    q <- readLn :: IO Int
    ks <-map read.words <$> getLine
    mapM_ (print.solve cs) ks

solve :: U.Vector Char -> Int -> Int
solve cs k = score $ U.foldl' step (U.foldl' step0 emptyQ pre) $ U.zip cs post
  where
    (pre, post) = U.splitAt k cs
    step0 q c = push c q
    step q (ck, c) = push c $ pop ck q

data Q = Q !Int !Int !Int !Int

emptyQ :: Q
emptyQ = Q 0 0 0 0

push :: Char -> Q -> Q
push c q@(Q d m dm dmc) = case c of
    'D' -> Q (d + 1) m dm dmc
    'M' -> Q d (m + 1) (dm + d) dmc
    'C' -> Q d m dm (dmc + dm)
    _   -> q

pop :: Char -> Q -> Q
pop c q@(Q d m dm dmc) = case c of
    'D' -> Q (d - 1) m (dm - m) dmc
    'M' -> Q d (m - 1) dm dmc
    _   -> q

score :: Q -> Int
score (Q _ _ _ dmc) = dmc


Measured memory_bytes: 7164
(let [N (read-line)
      Ni (map #(Character/digit % 10) N)] 
  (-> Ni 
      distinct 
      count 
      ( #(cond
          (= 1 %) N 
          (= (first Ni) (apply max Ni)) (apply str (repeat 3 (first Ni)))
          :else (apply str (repeat 3 (inc (first Ni))))))
      println))

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,m,k;cin>>n>>m>>k;
    vl a(n),b(m);
    vl suma(n+1,0),sumb(m+1,0);
    rep(i,n){cin>>a[i];suma[i+1]=suma[i]+a[i];}
    rep(i,m){cin>>b[i];sumb[i+1]=sumb[i]+b[i];}
    int ans=0;
    for(int i=1;i<=n;++i){
        if(suma[i]>k)break;
        int l=upper_bound(all(sumb),k-suma[i])-sumb.begin();
        ans=max(l+i-1,ans);
    }
    for(int i=1;i<=m;++i){
        if(sumb[i]>k)break;
        int l=upper_bound(all(suma),k-sumb[i])-suma.begin();
        ans=max(l+i-1,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9600
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>
#include <iomanip>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	for (int n; cin >> n; ) {
		int ans = 2;
		rep(i, n - 1) ans += i + 2;
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
MOD = 1000000007


def GCD(a, b):
    if b == 0:
        return a
    else:
        return GCD(b, a % b)


def modinv(a, mod=MOD):
    b = mod
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= mod
    if u < 0:
        u += mod
    return u


def LCM(a, b):
    return (a // GCD(a, b)) * b


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

l = 1
for i in range(n):
    l = LCM(l, a[i])
ans = 0
l %= MOD
for i in range(n):
    ans += l * modinv(a[i]) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define forn(i,n) for(int i=0;i!=n;i++)
ll n,c,g,a,we,ac,L[7],p[7],m,k,dp[500][500];
int main(){
cin>>n>>c,c*=n,m=n-1,k=1<<m;
forn(i,n)cin>>L[i],L[i]*=n;
sort(L,L+n);
iota(p,p+m,0);
do{
    memset(dp,0,sizeof(dp)),dp[L[m]][0]=1;
    forn(i,c)if(i%n){
        we = p[i%n-1];
        forn(mask,k)if(!((1<<we)&mask))
            for(ac=i;ac<=c;ac++)dp[max(ac,min(c,L[we]+i))][mask+(1<<we)]+=dp[ac][mask];
    }g+=dp[c][k-1],a++;
}while(next_permutation(p,p+m));
printf("%.15f",g/pow(c/n,m)/a);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
 ll n; cin>>n;
 ll res=0;
 map <int,ll> name;
 name[0]=0;
 name[1]=0;
 name[2]=0;
 name[3]=0;
 name[4]=0;
 REP(i,n){
   string s;
   cin>>s;
   if(s[0]=='M')name[0]++;
   if(s[0]=='A')name[1]++;
   if(s[0]=='R')name[2]++;
   if(s[0]=='C')name[3]++;
   if(s[0]=='H')name[4]++;
 }
 REP(i,3){
   FOR(j,i+1,4){
     FOR(k,j+1,5)
   res+=name[i]*name[j]*name[k];
   }
 }
  cout<<res<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, M, min, r int64
	min = 1000000000000000
	fmt.Scan(&N)
	for i := 0; i < 5; i++ {
		fmt.Scan(&M)
		if M < min {
			min = M
		}
	}
	r = 4 + (N+min-1)/min
	fmt.Println(r)

}

Measured memory_bytes: 512
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-25 17:18:01
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

bool is_pal(string s) {
    int n = s.length();
    for (int i = 0; i <= n/2; i++) {
        char a, b;
        a = s[i]; b = s[n-i-1];

        if (a != b) return false;
    }

    return true;
}

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

    int n = s.length();
    string a, b;
    a = s.substr(0, n/2);
    b = s.substr(n/2+1);

    if (is_pal(s) && is_pal(a) && is_pal(b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

int main() {
    int A, B, C, D, ans;
    cin >> A >> B >> C >> D;
    if ((D <= A) | (B <= C)) {
        ans = 0;
    } else if (C <= A) {
        ans = min(B, D) - A;
    } else {
        ans = min(B, D) - C;
    }
    cout << ans << endl;
}

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

int main(){
    int k;
    cin >> k;
    queue<ll> q;
    for(ll i = 1;i<10;i++) q.push(i);
    int c = 0;
    while(!q.empty()){
        c++;
        ll x = q.front();q.pop();
        if(c == k){
            cout << x << endl;
            return 0;
        }
        if(x % 10 != 0) q.push(10 * x + (x % 10) -1);
        q.push(10 * x + (x % 10));
        if(x % 10 != 9)q.push(10 * x + (x % 10) + 1);
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;


int main(){
  string s; cin >> s;
  int n = s.size();

  int ans = 0;
  rep(i,n){
    if(i%2 == 1 &&(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') ) ans = 0;
    else if(i%2 == 0 &&(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') ) ans = 0;
    else{
      ans = 1;
      break;
    }
  }

  vector<string> out = {"Yes","No"};
  cout << out[ans] << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll C[51][51];

void comb_table(int N) {
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                C[i][j] = 1LL;
            } else {
                C[i][j] = C[i-1][j-1] + C[i-1][j];
            }
        }
    }
}

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

    int n, p;
    cin >> n >> p;

    int even = 0, odd = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2) odd++;
        else even++;
    }

    ll ans = 0;
    comb_table(50);
    for (int i = 0; i <= odd; i++) {
        if (i % 2 == p) {
            ans += C[odd][i];
        }
    }

    cout << ans * (1LL << even) << "\n";
    return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


bool solve(int N){
    if (N > 17) return true;
    switch (N) {
        case 1: case 2: case 3:
        case 5: case 6:
        case 9: case 10:
        case 13:
        case 17:
            return false;
        default:
            return true;
    }
}

int main() {
    int N; cin >> N;
    cout << (solve(N) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    L = int(input())

    Lstr = bin(L)[2:]

    N = len(Lstr)
    M = (N - 1) * 2 + (Lstr.count("1") - 1)

    print(N, M)
    c = 1
    for i in range(1, N):
        print(i, i + 1, c)
        print(i, i + 1, 0)
        c *= 2

    c = 2 ** (N - 1)
    for i, v in enumerate(Lstr[::-1]):
        if i == N - 1:
            continue
        if v == "1":
            print(i + 1, N, c)
            c += 2 ** i



if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
s=list(input())
p=['1' if i%2==0 else "0" for i in range(len(s))]
q=['0' if i%2==0 else "1" for i in range(len(s))]
print(min(len([0 for i in range(len(s)) if s[i]!=p[i]]),len([0 for i in range(len(s)) if s[i]!=q[i]])))

Measured memory_bytes: 6312
Base = input().split(" ")
N = int(Base[0])
TL = int(Base[1])
TX = 10000

for i in range(N):
    Roi = input().split(" ")
    Coi = int(Roi[0])
    TLi = int(Roi[1])
    if TL >= TLi:
        if TX >= int(Coi) or i ==0:
            TX = Coi
if TX == 10000:
    print("TLE")
else:
    print(TX)

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

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

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

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  lol a[n + 5], r[n + 5] = {};
  reps(i, n){
    cin >> a[i];
  }
  r[n] = a[n];
  for(int i = n - 1;i >= 1;i --){
    r[i] = gcd(a[i], r[i + 1]);
  }
  lol memo = a[1], ans = r[2];
  for(int i = 2;i < n;i ++){
    ans = max(ans, gcd(memo, r[i + 1]));
    memo = gcd(memo, a[i]);
  }
  cout << max(ans, memo) << '\n';
  return 0;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    vi n(4);
    rep(i,4) cin >> n.at(i);
    string res = "NO";
    set<ll> s;
    rep(i,4) s.insert(n.at(i));
    if(s.count(1)&&s.count(9)&&s.count(7)&&s.count(4)) res = "YES";
    cout << res << endl;
}

Measured memory_bytes: 3656
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      for(int i = 1; i <= 9; i++)
        for(int j = 1; j <= 9; j++)
          if(i * j == n) {
            System.out.println("Yes");
            return;
          }
      System.out.println("No");
  }
}


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

int main ()
{
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    while(1){
        int a,b;
        cin >> a >> b;
        if(a==0 && b==0)break;
        for(int i=0; i<a; i++) {
            for(int j=0; j<b; j++) {
                if (i==0 ||i==(a-1) ||j==0 || j==(b-1) ) {
                    cout << "#";
                }
               else
                   cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  int mx, mx2;
  vi sa(n);
  rep(i,n) sa[i] = a[i];
  sort(sa.rbegin(),sa.rend());
  mx = sa[0];
  mx2 = sa[1];
  bool ok = false;
  int cnt = 0;
  rep(i,n){
    if(a[i] != mx) cout << mx << endl;
    else cout << mx2 << endl;
  }
}


Measured memory_bytes: 4840
//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define DP_maxn 16
#define maxn 1000000+10
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

int a,b,c,d;
int ans = 0;

int main(){
	cin>>a>>b;
	c = max(a,b);
	d = min(a,b);
	ans += c;
	c -= 1;
	ans += max(c,d);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n; cin>>n;
    pair<int,int> a[n],b[n];
    rep(i,n) cin>>a[i].second>>a[i].first;
    rep(i,n) cin>>b[i].first>>b[i].second;
    sort(a,a+n); reverse(a,a+n);
    sort(b,b+n);
    int ans=0,aindex=0,bindex=0;
    while(bindex<n){
        if(a[aindex].second<b[bindex].first&&a[aindex].first<b[bindex].second){
            ans++;
            a[aindex].second=INF;
            aindex=0; bindex++;
        }else{
            aindex++;
            if(aindex==n){
                bindex++;
                aindex=0;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
'use strict';
  (function(stdin) { 
      var inputs = stdin.toString().trim();
      var params = inputs.split('\n')[0].split(' ').map(Number);
      (function(a,b) {
        console.log(a * b,(a + b)*2);

    }(params[0],params[1])); 
  }(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  string s; cin>>s;
  s = regex_replace(s, regex(","), " ");
  cout << s << endl;
}

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


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

#define MAX 100000
#define INF (1<<29)

typedef struct{
  char mark;
  int num;
} Card;

int getMarkNumber(char);
void swap(Card*,Card*);
int partition(int,int,Card*);
void quickSort(int,int,Card*);
void merge(int,int,int,Card*);
void mergeSort(int,int,Card*);

int main(){
  int n,i,isStable;
  Card A[MAX],B[MAX];

  scanf("%d\n",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%c%d\n",&A[i].mark,&A[i].num);
    B[i] = A[i];
  }
  quickSort(0,n-1,A);
  mergeSort(0,n,B);
  isStable = 1;
  for(i = 0 ; i < n ; i++){
    if(A[i].mark != B[i].mark || A[i].num != B[i].num){
      isStable = 0;
      break;
    }
  }
  printf("%s\n",(isStable ? "Stable" : "Not stable"));
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n",A[i].mark,A[i].num);
  }
  return 0;
}

int getMarkNumber(char x){
  if(x == 'S'){ return 0; }
  if(x == 'H'){ return 1; }
  if(x == 'C'){ return 2; }
  return 3;
}

void swap(Card *a,Card *b){
  Card tmp = *a;
  *a = *b;
  *b = tmp;
}

int partition(int l,int r,Card *A){
  int x = A[r].num,i = l,j;
  for(j = l ; j < r ; j++){
    if(A[j].num <= x){
      swap(&A[i++],&A[j]);
    }
  }
  swap(&A[i],&A[r]);
  return i;
}

void quickSort(int l,int r,Card *A){
  int q;
  if(l < r){
    q = partition(l,r,A);
    quickSort(l,q-1,A);
    quickSort(q+1,r,A);
  }
}

void merge(int left, int mid, int right,Card *B){
  int n1 = mid - left,n2 = right - mid,i,j,k;
  Card L[n1+1],R[n2+1];
 
  for(i = 0 ; i < n1 ; i++){
    L[i] = B[left + i];
  }
  for(i = 0 ; i < n2 ; i++){
    R[i] = B[mid + i];
  }
  L[n1] = R[n2] = (Card){'#',INF};
  for(i = 0,j = 0,k = left ; k < right ; k++){
    if(L[i].num <= R[j].num){
      B[k] = L[i++];
    }else{
      B[k] = R[j++];
    }
  }
}
 
void mergeSort(int left,int right,Card *B){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(left,mid,B);
    mergeSort(mid,right,B);
    merge(left,mid,right,B);
  }
}

Measured memory_bytes: 2952
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

/* //約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}*/


int main() {
  int N,Remove=0;
  ll x,l,bx,bl;
  cin >> N;
  vector<Vl> v;

  REP(i,N) {
    cin >> x >> l;
    v.push_back({x,l});
    }
  sort(v.begin(), v.end(), [](auto& x, auto& y){return x[0] < y[0];});
  // REP(i,N) cout << v[i][0] << ' ' << v[i][1] << endl;
  REP(i,N) {
    x = v[i][0];
    l = v[i][1];
    if (i==0) {
      bx=x;bl=l;
      continue;
    }
    // cout << bx << ' ' << bl << endl;
    if (bx+bl>x-l) {
      Remove++;
      if (bx+bl>x+l) {bx=x;bl=l;}
      continue;
    }
    bx=x;bl=l;
  }
  cout << N-Remove << endl;
}

Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
string x;
cin>>x;
for(int i=0;i<x.size();i++){
    char g;
    if(x[i]+n>'Z'){g=((x[i]+n)%'Z')+'A'-1;}
    else g=x[i]+n;
    cout<<g;
}
    return 0;
}


Measured memory_bytes: 256