akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;
using ll = long long;
int main(){
  ll a,b;
  cin>>a>>b;
  if(a<=0 && b>=0) cout << "Zero" << endl;
  else if(a < 0 && b < 0 && (b-a+1)%2 == 1) cout << "Negative" << endl;
  else cout << "Positive" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int d = a / b;
		int r = a % b;
		double f = (double) a / (double) b;

		System.out.printf("%d", d);
		System.out.print(" ");
		System.out.printf("%d", r);
		System.out.print(" ");
		System.out.printf("%f", f);
	}
}



Measured memory_bytes: 26540
import numpy as np
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:W+1] = np.maximum(dp[0:W+1-w]+v,dp[w:W+1])
print(dp[-1])

Measured memory_bytes: 15492
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define TRUE 1;
#define FALSE 0;

struct node{
  struct node *prev;
  int key;
  struct node *next;
};

typedef struct node *Node;

void make1node(int);
int delnode(int);

Node nil;
    
int main(){
  int N,num,i;
  char command[15];
  Node n,del;
  nil=malloc(sizeof(struct node));
  nil->prev=nil->next=nil;
  nil->key=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",command);
    if(strcmp("deleteFirst",command)!=0 && strcmp("deleteLast",command)!=0){
    scanf("%d",&num);
    }
        if(strcmp("insert",command)==0)
      make1node(num);
    else if(strcmp("delete",command)==0)
	delnode(num);
    else if(strcmp("deleteFirst",command)==0){
      del=nil->next;
      del->prev->next=del->next;
      del->next->prev=del->prev;
    }
    else if(strcmp("deleteLast",command)==0){
      del=nil->prev;
      nil->prev=del->prev;
      del->prev->next=nil;
    }
      
	    else exit(1);
  } 
  for(n=nil;n->next!=nil;n=n->next){
     printf("%d",n->next->key);
     if(n->next->next==nil) printf("\n");
     else printf(" ");
  }
  
  return 0;
}
void make1node(int key){
  Node n;
  n=(Node)malloc(sizeof(struct node));
    n->key=key;
    n->next=nil->next;
    n->next->prev=n;
    nil->next=n;
  n->prev=nil;
  
}
int delnode(int key){
  Node n,delnode;
  for(n=nil;n->next!=nil;n=n->next){
    if(n->next->key==key){
      delnode=n->next;
      delnode->prev->next=delnode->next;
      n->next->prev=delnode->prev;
      free(delnode);
      return TRUE;
    }
  }
  return FALSE; 
}

      
     



Measured memory_bytes: 36232
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
    ll N,P;cin>>N>>P;
    ll ans = 1;
    map<ll,ll> m;
    for(ll i=2;i*i<=P;++i){
        while(P%i==0){
            P /= i;
            ++m[i];
        }
    }
    if(P!=1) m[P] = 1;

    for(auto itr=m.begin();itr!=m.end();++itr) if(itr->second>=N) ans *= pow(itr->first,(itr->second/N));
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h, w = f()
    n = f()[0]
    a = f()

    g = [ [0]*w for i in range(h)]

    cur = 0
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if a[cur]==0:
                    cur+=1
                g[i][j] = cur+1
                a[cur] -= 1
        else:
            for j in reversed(range(w)):
                if a[cur]==0:
                    cur+=1
                g[i][j] = cur+1
                a[cur] -= 1

    for i in range(h):
        for j in range(w):
            print(g[i][j], end = '')

            if (j==w-1):
                print()
            else:
                print(' ', end='')


solve()


Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main() {
    int n;ll sum = 0;
    cin >> n;
    vector<ll> a(n);
    map<ll,int> mp;
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
        sum += a[i];
    }
    int q; cin >> q;
    rep(test,q){
        int b,c; cin >> b >> c;
        sum += (c-b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9964
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<29;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    int mi = 2000000000;
    rep(i,n-k+1){
        mi = min (mi,h[i+k-1]-h[i]);
    }
    cout << mi <<endl;
}


Measured memory_bytes: 768
from collections import deque
N, x = map(int, input().split())
if x == 1 or x == 2*N-1: print("No")
else:
    A = deque([int(i) for i in range(1, 2*N)])
    Ans = [0 for i in range(2*N-1)]
    if x == 2:
        Ans[N-2], Ans[N-1], Ans[N] = 3, 2, 1
        A.remove(1)
        A.remove(2)
        A.remove(3)
        for i in range(2*N-1):
            if i < N-2 or i > N: Ans[i] = A.popleft()
    else:
        Ans[N-2], Ans[N-1], Ans[N], Ans[N+1] = x-1, x, x+1, x-2
        A.remove(x-1)
        A.remove(x)
        A.remove(x+1)
        A.remove(x-2)
        for i in range(2*N-1):
            if i < N-2 or i > N+1: Ans[i] = A.popleft()
    print("Yes")
    for a in Ans:print(a)


Measured memory_bytes: 14216
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)(v).size())

int solve(){
	int n; cin >> n;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i * j == n) return 1;
		}
	}return 0;
}
int main(){
  puts(solve() ? "Yes" : "No");
}



Measured memory_bytes: 256
n, m = list(map(int, input().split()))
infinite = -10**14
score = [infinite for _ in range(n+1)]
score[1] = 0
routes = [[] for _ in range(n+1)]
for i in range(m):
    ai, bi, ci = list(map(int, input().split()))
    routes[ai].append([bi, ci])
#print(routes)

is_inf = True
for r in range(n+2): 
    rev = 0
    for i in range(1,n+1):
        for (to, sc) in routes[i]:
            if score[to] < score[i] + sc:
                score[to] = score[i] + sc
                if to == n:
                    rev += 1
    if rev == 0 and r > n:
        is_inf = False
        break
            
if is_inf:
    print('inf')
else:
    print(score[n])

Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    map<pair<int, int>, int> mp;
    pair<int, int> p1[100010];
    pair<int, int> p2[100010];
    rep(i, M) {
        cin >> p1[i].first >> p1[i].second;
        p2[i] = p1[i];
    }
    sort(p1, p1 + M);
    int j = 1;
    rep(i, M) {
        if (i >= 1 && p1[i].first != p1[i - 1].first) j = 1;
        mp[p1[i]] = j++;
    }
    rep(i, M) {
        printf("%06d%06d\n", p2[i].first, mp[p2[i]]);
    }


    return 0;
}


Measured memory_bytes: 9344
#include <cstdio>
#include <algorithm>
using namespace std;
int N, d[100001];
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", &d[i]);
  sort(d+1, d+1+N);
  printf("%d", d[N/2+1]-d[N/2]);
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for(size_t i = 0; i < n; i++){
		cin >> v[i];
	}
	vector<int> s = v;
	sort(s.rbegin(), s.rend());
	for(int i = 0; i < n; i++){
		int ans = s[0];
		if( s[0] == v[i] ) ans = s[1];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3200
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
	int n = cin();
    char[] s = ReadCharArray();
    int red = s.Count(c => c == 'R');
    string ans = (red > n-red) ? "Yes" : "No";
    Console.WriteLine(ans);
  }

  private static List<int> _var;
  public static int cin() { if (_var == null || _var.Count() == 0) { _var = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); } int ans = _var[0]; _var.RemoveAt(0); return ans; }
  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 13396
n = int(input())
x = [int(input()) for i in range(n)]
num,y,a = 0,set([1]),1
while num != len(y) and 2 not in y:
	num,a = len(y),x[a-1]
	y.add(a)
if 2 in y: print(len(y)-1)
else: print(-1)

Measured memory_bytes: 13220
#include <stdio.h>
#define MAX_N 200000
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
  int N;
  scanf("%d", &N);
  int A[MAX_N];

  int MAX_A0 = 0;
  int MAX_A1 = 0;
  int MAX_I0 = 0;
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    if(MAX_A0 < A[i]) {
      MAX_A1 = MAX_A0;
      MAX_A0 = A[i];
      MAX_I0 = i;
    } else if(MAX_A1 < A[i]) {
      MAX_A1 = A[i];
    }
  }

  for(int i = 0; i < N; i++) {
    if(i == MAX_I0) {
      printf("%d\n", MAX_A1);
    } else {
      printf("%d\n", MAX_A0);
    }
  }
  return 0;
}


Measured memory_bytes: 2304
import sys
input = sys.stdin.readline
from collections import deque
n,m = [int(i) for i in input().split()]
ab = deque([])
for i in range(m):
  a,b = [int(i) for i in input().split()]
  ab_appendleft = ab.appendleft
  ab_appendleft((a-1,b-1))
  
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]
  
par = [-1]*n
ans = n*(n-1)//2
chk = deque([])
chk_appendleft = chk.appendleft
chk_appendleft(n*(n-1)//2)

for i in ab:
  if not same(i[0],i[1]):
    c = size(i[0])
    d = size(i[1])
    unite(i[0],i[1])
    ans -= c*d
    chk_appendleft(ans)
  else:
    chk_appendleft(ans)

chk = list(chk)[1:]
for i in chk:
  print(i)

Measured memory_bytes: 23692
n, x, y = map(int, input().split())
ans = [0] * (n - 1)
x -= 1
y -= 1
for i in range(n-1):
    for j in range(i+1, n):
        d = min(abs(y-i)+abs(y-j), abs(x-i)+abs(x-j), abs(i-j),
                abs(y-i)+abs(x-j)+1, abs(x-i)+abs(y-j)+1) - 1
        if i == x and j == y:
            d = 0
        # print(i, j, d)
        ans[d] += 1
print(*ans, sep='\n')


Measured memory_bytes: 52060
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
int arr[n];
for(int i=1;i<=n;i++)
    cin>>arr[i];
vector<int> ans;
int vis[n+1]={};
int c=1;
int cnt=1;
while(vis[c]==0)
{vis[c]=cnt;
cnt++;
    ans.pb(c);
    c=arr[c];
}


int r=vis[c];
for(int i=0;i<ans.size();i++)
{if(k==0)
{
    cout<<ans[i]<<endl;
    return 0;
}
    k--;
}


vector<int> left;
for(int i=r-1;i<ans.size();i++)
    left.pb(ans[i]);
int s=0;
if(k==0)
{
    cout<<left[0]<<endl;
    return 0;
}
int l=left.size();
l=k%l;
l=left[l];

cout<<l<<endl;




    return 0;
}


Measured memory_bytes: 10768
#include <bits/stdc++.h>
using namespace std;
char a[100][100];
int main()
{
	int n,m,i,j,k;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		getchar();
		for(j=0;j<m;j++)
			scanf("%c",&a[i][j]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			if(a[i][j]!='.')
				break;
		if(j==m)
		{
			for(j=i+1;j<n;j++)
				for(k=0;k<m;k++)
					a[j-1][k]=a[j][k];
			n--;
			i--;
		}
	}
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
			if(a[j][i]!='.')
				break;
		if(j==n)
		{
			for(j=i+1;j<m;j++)
				for(k=0;k<n;k++)
					a[k][j-1]=a[k][j];
			m--;
			i--;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			printf("%c",a[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn=100+5;
int n,m;
int a[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    int sum=0;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int cnt=0;
    for(int i=1;i<=n;++i)
    {
        if(a[i]*4*m>=sum) ++cnt;
    }
    puts(cnt>=m?"Yes":"No");
    return 0;
}

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

int main(){
  int a,b,x,y,z;
  cin >> a >> b;
  if ( a > b ){
    cout << "a > b" << endl;
    }
  else { if (a < b) {
      cout << "a < b" << endl;
    }
    else { 
      cout << "a == b" << endl;
    }
  }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
  int N, C; cin >> N >> C;
  int D[31][31]={0}, c[3][30]={0};
  int ans = 1<<30;
  int X;
  rep(i, C)rep(j, C) cin >> D[i][j];
  rep(i, N)rep(j, N) cin >> X, c[(i+j)%3][X-1]++;
  rep(i, C)rep(j, C)if(i != j)rep(k, C)if(i != k && j != k) {
    int tmp = 0;
    rep(l, C) tmp += D[l][i]*c[0][l];
    rep(l, C) tmp += D[l][j]*c[1][l];
    rep(l, C) tmp += D[l][k]*c[2][l];
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long n,tab[90];
    tab[0]=2;
    tab[1]=1;
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        tab[i]=tab[i-1]+tab[i-2];
    }
    cout<<tab[n];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int dp[100010];
int niz[110];
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> niz[i];
	for (int i = 0; i <= k; i++)
		for (int j = 0; j < n; j++)
			if (niz[j] <= i)
				if (!dp[i - niz[j]])
					dp[i] = 1;
	if (dp[k])
		cout << "First" << endl;
	else
		cout << "Second" << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int n = sc.nextInt();
        var a = new int[n + 1];
        var b = new int[n];
        for (int i = 0; i < n + 1; i++)
            a[i] = sc.nextInt();
        for (int i = 0; i < n; i++)
            b[i] = sc.nextInt();

        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            int tmp = Math.Min(a[i], b[i]);
            ans += tmp;
            b[i] -= tmp;
            a[i] -= tmp;
            tmp = Math.Min(b[i], a[i + 1]);
            ans += tmp;
            b[i] -= tmp;
            a[i + 1] -= tmp;
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 31596
from math import sqrt

def main():
    n, d = map(int, input().split())
    ans = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if sqrt(x**2 + y**2) <= d:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9188
def dfs(i, total, S, remain):
    global ans
    if i == D:
        if S < G:
           use = max(remain)
           N = min(L[use-1][0], -(-(G-S)//(100*use)))
           S += 100 * N * use
           total += N
           
        if S >= G:
           ans = min(ans, total)
    else:
        dfs(i+1, total, S, remain)
        dfs(i+1, total + L[i][0], S + 100 * (i+1) * L[i][0] + L[i][1], remain - {i+1})

D, G = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(D)]
ans = 10 ** 9

dfs(0, 0, 0, set(range(1, D+1)))

print(ans)

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(N); IN(A);

  vector<int> x(N);
  int max_X = 0;
  REP(i, N) {
    cin >> x[i];
    max_X = max(max_X, x[i]);
  }
  vector<vvll> dp(N+2, vvll(N+10, vll(2551, 0)));
  // dp[j][k][s] = j枚目まででk枚選んで合計をsとする
  dp[0][0][0] = 1;
  REP(j, N) REP(k, N) REP(s, 2501) {
    dp[j+1][k][s] += dp[j][k][s];
    dp[j+1][k+1][s+x[j]] += dp[j][k][s];
  }
  ll ans = 0;
  for (int k = 1; k <= N; ++k)
    ans += dp[N][k][k*A];

  OUT(ans);

  return 0;
}


Measured memory_bytes: 63744
#include <stdio.h>
int main(){
  int i,j,sum,min,max,n,m;

  while(1){
    scanf("%d",&m);
    if(m == 0) break;
    min = 501;
    max = -1;
    for(i=0;i<m;i++){
      for(sum=0,j=0;j<5;j++){
	scanf("%d",&n);
	sum += n;
      }
      if(max<sum) max=sum;
      if(min>sum) min=sum;
    }
    printf("%d %d\n",max,min);
  }
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<string.h>
int main(void){
  char s[110];
  int i,k;
  scanf("%s",s);
  k=(strlen(s)-1)/2;
  for(i=0;i<k;i++){
    if(s[i]!=s[k-i]&&s[i]!=s[k+1+i]){puts("No");return 0;}
  }
  puts("Yes");
 return 0; 
}


Measured memory_bytes: 1660
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef struct segment_tree_void {
  void *array;
  int32_t size;
  size_t val_size;
  void (*func) (void *, const void *, const void *);
} segment_tree;

static inline void segment_tree_memcpy (void *dst, const void *src, size_t size) {
  uint8_t *p = dst;
  const uint8_t *q = src;
  while (size--) {
    *p++ = *q++;
  }
}

segment_tree* new_segment_tree (const void *ini, const int32_t n, const size_t val_size, void (*func) (void *, const void *, const void *)) {
  int32_t k = 1;
  while (k < n) k *= 2;
  segment_tree *s = (segment_tree *) calloc (1, sizeof (segment_tree));
  s->array = calloc (2 * k, val_size);
  s->size = k;
  s->val_size = val_size;
  s->func = func;
  for (int32_t i = k; i < 2 * k; ++i) {
    segment_tree_memcpy ((uint8_t *)s->array + i * val_size, ini, val_size);
  }
  uint8_t *a = s->array;
  for (int32_t i = k - 1; i > 0; --i) {
    func (a + i * val_size, a + (2 * i) * val_size, a + (2 * i + 1) * val_size);
  }
  return s;
}

void update (segment_tree * const s, int32_t k, const void *val) {
  k += s->size;
  uint8_t *p = s->array;
  const size_t size = s->val_size;
  segment_tree_memcpy (p + k * size, val, size);
  for (k >>= 1; k > 0; k >>= 1) {
    s->func (p + k * size, p + 2 * k * size, p + (2 * k + 1) * size);
  }
}

void find (const segment_tree *s, int32_t l, int32_t r, void *res) {
  int32_t lindex[64];
  int32_t rindex[32];
  int32_t llen = 0;
  int32_t rlen = 0;
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) lindex[llen++] = l++;
    if (r & 1) rindex[rlen++] = --r;
  }
  while (rlen > 0) {
    lindex[llen++] = rindex[--rlen];
  }
  const uint8_t *p = s->array;
  segment_tree_memcpy (res, p + lindex[0] * s->val_size, s->val_size);
  for (int32_t i = 1; i < llen; ++i) {
    s->func (res, res, p + lindex[i] * s->val_size);
  }
}

typedef int32_t i32;
typedef int64_t i64;

typedef struct index_val {
  i32 index;
  i32 val;
} node;

void func (void *c, const void *a, const void *b) {
  node *p = (node *)a;
  node *q = (node *)b;
  *(node *)c = p->val < q->val ? *p : *q;
}

typedef struct range {
  i32 l, r;
} range;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  const node ini = {0, n + 1};
  segment_tree *s = new_segment_tree (&ini, n, sizeof (node), func);
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    update (s, i, &((node){i, a}));
  }
  range stack[32];
  i32 top = 0;
  stack[top++] = (range) {0, n};
  i64 ans = 0;
  while (top > 0) {
    range t = stack[--top];
    if (t.r <= t.l) continue;
    node v;
    find (s, t.l, t.r, &v);
    i32 k = v.index;
    ans += (i64) (k - t.l + 1) * (t.r - k) * v.val;
    if (k - t.l <= t.r - k) {
      stack[top++] = (range) {k + 1, t.r};
      stack[top++] = (range) {t.l, k};
    } else {
      stack[top++] = (range) {t.l, k};
      stack[top++] = (range) {k + 1, t.r};
    }
  }
  printf ("%" PRIi64 "\n", ans);
}

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


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  long long n;
  cin >> n;
  long long k[n];
  cin >> k[0];
  rep(i,n-1){
    long long y;
    cin >> y;
    k[i+1]=k[i]+y;
  }
  long long ans=100000000000000;
  long long l=0,r=2;
  rep(i,n-3){
    long long y=i+1;
    while(l<y-1&&(abs(2*k[l]-k[y])>abs(2*k[l+1]-k[y]))){
      l++;
    }
    long long mi=min(k[l],k[y]-k[l]);
    long long ma=k[y]-mi;
    while(r<n-2&&(abs(2*k[r]-k[y]-k[n-1])>abs(2*k[r+1]-k[y]-k[n-1]))){
      r++;
    }
    long long mii=min(k[r]-k[y],k[n-1]-k[r]);
    long long maa=k[n-1]-k[y]-mii;
    ans=min(ans,max(ma,maa)-min(mi,mii));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int dp[4005][4005];
int n,A,B,a[50],b[50],c[50],ans=1e9;
int main()
{
	for(int i=0;i<4005;i++)for(int j=0;j<4005;j++)dp[i][j]=1e9;
	cin>>n>>A>>B;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=0;
	for(int i=0;i<n;i++)
		for(int x=4000;x>=a[i];x--)
			for(int y=4000;y>=b[i];y--)
				dp[x][y]=min(dp[x][y],dp[x-a[i]][y-b[i]]+c[i]);
	int x=A,y=B;
	while(x<=4000&&y<=4000)
	{
		ans=min(ans,dp[x][y]);
		x+=A;
		y+=B;
	}
	if(ans==1e9)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 62976
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())

int main()
{
    int k,s; cin >> k >> s;
    int cnt=0;
    rep(x,k+1){
        rep(y,k+1){
            int z = s-x-y;
            if(0 <= z && z <= k) cnt++;
        }
    }
    cout << cnt << endl;

}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
#include <stdio.h>                                                              
int main(void)                                                                  
{                                                                               
  int i, j;                                                                     
                                                                                
  for (i=1; i<10; i++)                                                          
    for (j=1; j<10; j++)                                                        
      printf("%dx%d=%d\n", i, j, i*j);                                          
                                                                                
  return 0;                                                                     
}                                                                               
                                                                                
                       

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int n,k;
  cin >> n >> k;
  int treat[n];
  for(int i = 0; i < n; i++) {
    treat[i] = 0;
  }
  for(int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for(int j = 0; j < d; j++) {
      int a;
      cin >> a;
      treat[a-1] += 1;
    }
  }
  cout << count(treat,treat+n,0) << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> v;
int n,k;

bool C(int x){
	bool res[10001];
	fill(res,res+10001,false);
	for(int i=0;i<=v.size();i++){
		for(int j=10000;j>=0;j--){
			if(i-1==x) continue;
			else if(i==0&&j==0) res[j] = true;
			else if((i==0||j-v[i-1]<0||!res[j-v[i-1]])&&!res[j]) res[j] = false;
			else res[j] = true;
		}
	}
	for(int i=k-v[x];i<k;i++){
		if(res[i]) return true;
	}
	return false;
}

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(x<k) v.push_back(x);
	}
	sort(v.begin(),v.end());
	n = v.size();
	int lb = -1,ub = n;
	while(ub-lb>1){
		int mid = (ub + lb) / 2;
		if(C(mid)) ub = mid; // need
		else lb = mid;
	}
	printf("%d\n",ub);
}


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

typedef long long ll;

int main() {
	vector<ll> a; int n, ans = 0; cin >> n;
	for (int i = 0; i < n; i++) {
		ll tmp; cin >> tmp;
		a.push_back(tmp);
	}

	for (int i = 0; i < a.size(); i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int a= sc.nextInt();
		int b= sc.nextInt();
		List<Integer> plist = new ArrayList<>();
		int oneCount =0;
		int twoCount =0;
		int threeCount =0;
		
		for(int i=0;i<n;i++){
			int p = sc.nextInt();
			if(p<=a){
				oneCount++;
			}else if(p<=b){
				twoCount++;
			}else{
				threeCount++;
			}
		}
		System.out.println(Math.min(oneCount,Math.min(threeCount,twoCount)));
	}


}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t &x,int64_t &y,int64_t a,int64_t b){
  if(a==0){
    x=0;
    y=1;
    return b;
  }
  int64_t g=gcd(y,x,b%a,a);
  x-=b/a*y;
  return g;
}
int64_t fsum(int64_t n,int64_t m,int64_t a,int64_t b){
  if(a>=m||b>=m)
    return fsum(n,m,a%m,b%m)+n*(n-1)/2*(a/m)+n*(b/m);
  if(n==0||a==0)
    return 0;
  int64_t x,y,g;
  g=gcd(x,y,a,m);
  x=b/g*(-x%m+m)%(m/g);
  int64_t d=0;
  if(b%g==0&&x<n)
    d=(n-1-x)/(m/g)+(b==0?0:1);
  return (a*(n-1)+b)/m*(n-1)+d-fsum((a*(n-1)+b)/m,a,m,m-b);
}
int main(){
  int t;
  cin>>t;
  for(int _=0;_<t;_++){
    int64_t n,m,a,b;
    cin>>n>>m>>a>>b;
    cout<<fsum(n,m,a,b)<<endl;
  }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1001
int main(){
  vector<int> fib;
  int i,j,k;
  fib.push_back(2);
  fib.push_back(3);
  for(i=2;i<1050;i++) fib.push_back((fib[i-2]+fib[i-1])%MOD);
  int n,d;
  while(cin>>n>>d){
    int o=1;
    vector<int> v;
    for(i=0;i<n;i++) v.push_back(fib[i]);
    sort(v.begin(),v.end());
    for(i=1;i<n;i++){
      if(abs(v[i]-v[i-1])>=d) {
	o++;
      }
    }
    cout << o << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
t1,t2=[int(j) for j in input().split()]
a1,a2=[int(j) for j in input().split()]
b1,b2=[int(j) for j in input().split()]
c1,c2=a1-b1,a2-b2
d1,d2=c1*t1,c2*t2
if d1>0:
    d1=-d1
    d2=-d2
if d1+d2<0:
    print(0)
elif d1+d2==0:
    print("infinity")
else:
    print(2*(-d1//(d2+d1))+[0,1][int(bool(-d1%(d2+d1)))])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll inf = 1e9+7;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

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

int keta(ll n){
    if (n < 100000) {
        if (n < 1000) {
            if (n < 10)
                return 1;
            else if (n < 100)
                return 2;
            else
                return 3;
        } else {
            if (n < 10000)
                return 4;
            else
                return 5;
        }
    } else {
        if (n < 10000000) {
            if (n < 1000000)
                return 6;
            else
                return 7;
        } else {
            if (n < 100000000)
                return 8;
            else if (n < 1000000000)
                return 9;
            else if (n < 10000000000)
                return 10;
            else 
                return 11;
        }
    }
}

int f(ll a, ll b){
  return max(keta(a), keta(b));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  int ans = 12;
  for(ll a = 1; a <= sqrt(n); ++a){
    if(n%a) continue;
    ll b = n/a;
    ans = min(ans, f(a,b));
  }
  cout << ans << "\n";
  return 0;
}   

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

int main() {
  int N, r, l;
  int t = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> r >> l;
    t += l - r + 1;
  }
  cout << t << endl;
}
    

Measured memory_bytes: 256
X,N = map(int,input().split())
P = list(map(int,input().split()))
ans = 100
l = 101
for i in range(0,102):
    if P.count(i) == 0:
        if abs(i-X) < l:
            #print(i)
            l = abs(i-X)
            ans = i
print(ans)


Measured memory_bytes: 9180
#include <iostream>
#include <cfloat>
#include <cmath>
using namespace std;
 
 
//0021
int main(){
    double xA, yA, xB, yB, xC, yC, xD, yD;
    char ch;
	int n;

	cin >> n;
    for(int i=0; i<n; ++i){
		cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD;
        double x1,y1,x2,y2;
        y1=yB-yA;
        x1=xB-xA;
        y2=yD-yC;
        x2=xD-xC;
 
        if(fabs((x1*y2)-(x2*y1)) <= DBL_EPSILON){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
 
    }
 
}

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

#include <numeric>

#include <map>

using namespace std;

typedef long long LL;

int a[2000010];

int n, cnt;

int main() {
    cin >> n;
    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m, j int
	arr := make([]int, 0)
	total := 0
	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &j)
		arr = append(arr, j)
		total += j
	}
	// popular := total / (4 * m)
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))
	// flag := true
	// for i := 0; i < m; i++ {
	// 	if arr[i] < popular {
	// 		flag = false
	// 		break
	// 	}
	// }
	if arr[m-1]*4*m >= total {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll cj[100001],ci[100001];
int main(){
    int n;
    string s;
    cin>>n>>s;
    ll sum=0,jo=0,j=0;
    rep(i,n){
        cj[i]=j;
        if(s[i]=='J')++j;
        else if(s[i]=='O') jo+=j;
        else sum+=jo;
    }
    ll mx=jo;
    ll ii=0,oi=0;
    for(int i=n-1;i>=0;--i){
        ci[i]=ii;
        if(s[i]=='I') ++ii;
        else if(s[i]=='O') oi+=ci[i];  
    }
    mx=max(oi,mx);
    FOR(i,1,n-1){
        mx=max(mx,cj[i]*ci[i-1]);
    }
    cout<<sum+mx<<endl;
    return 0;
}


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

using namespace std;

void upfile()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int maxN = 2e5 + 10;

int p[maxN], n, cnt = 0, t;

vector<int> pos[26];

string s;

long long ans;

struct BIT
{
    int t[maxN];

    int GetB(int m)
    {
        int ans = 0;
        for (; m>0; m -= m & -m)
            ans += t[m];
        return ans;
    }

    int Update(int m)
    {
        for (; m<=n; m += m & -m)
            ++t[m];
    }
} Tree;

int main()
{
    upfile();
    cin >> s;
    n = s.size();
    s = " " + s;
    for (int i=1; i<=n; ++i)
        pos[s[i] - 'a'].push_back(i);

    for (int i=0; i<26; ++i)
    {
        int m = pos[i].size();
        int a = 0;
        int b = m - 1;
        cnt += m % 2;
        if (cnt >= 2)
        {
            cout << -1;
            return 0;
        }

        while (a <= b)
        {
            p[pos[i][a]] = pos[i][b];
            ++a;
            --b;
        }
    }

    for (int i=1; i<=n; ++i)
        if (p[i] && p[i] != i)
        {
            ans += Tree.GetB(p[i]) + Tree.GetB(i);
            Tree.Update(p[i]);
        }
        else if (p[i] == i)
            t = i;

    if (n % 2 != 0)
        for (int i=1; i<=n; ++i)
            if (p[i] != 0)
                if (i < t && p[i] < t || i > t && p[i] > t)
                    ++ans;

    cout << ans;

}


Measured memory_bytes: 2512
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**9
eps = 10**-7

N,M = map(int,input().split())
# 1-indexed union-find
# parent(親)
par = [i for i in range(N+1)]
# rank(深さ)
rank = [0]*(N+1)
# 同グループの頂点数
# size = [1]*(N+1)

# 木の根を求める
def root(x):
    if par[x] == x:             # 根の時
        return x
    else:
        par[x] = root(par[x])   # 経路圧縮
        return par[x]

# xとyの属する集合を併合(ランク有)
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y              # xの親をyに
        #size[y] += size[x]      # yの頂点数+=xの頂点数
    else:
        par[y] = x              # yの親をxに
        #size[x] += size[y]      # xの頂点数+=yの頂点数
        if rank[x] == rank[y]:
            rank[x] += 1

LRD = [tuple(map(int,readline().split())) for i in range(M)]

for (L,R,D) in LRD:
    unite(L,R)

from collections import defaultdict,deque
rel = defaultdict(lambda: [])

for (L,R,D) in LRD:
    rel[root(L)].append((L,R,D))

for k,v in rel.items():
    dist = defaultdict(lambda: [])
    for (L,R,D) in v:
        dist[L].append((R,D))
        dist[R].append((L,-D))
    que = deque([])
    x = {}
    for k1,v1 in dist.items():
        x[k1] = 0
        for (to,dis) in v1:
            x[to] = dis
            que.append(to)
        break
    while que:
        fro = que.popleft()
        for (to,dis) in dist[fro]:
            if to not in x.keys():
                x[to] = x[fro] + dis
                que.append(to)
    for (L,R,D) in v:
        if x[R] - x[L] != D:
            print('No')
            exit()
    if max(x.values()) - min(x.values()) > 10**9:
        print('No')
        exit()
print('Yes')

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

using namespace std;

int convert(char c);

int main()
{
    string str;
    int length = 0;
    long long count = 0;
    while(1){
        cin >> str;
        if(str == "0") break;

        length = str.size();
        vector<int> digit(length);
        for(int i = 0; i < length; i++){
            digit[i] = convert(str[i]);
        }
        
        vector<vector <int>> cnt;
        //res[end][res]はend+1桁目で終わる数で、11を法としてresに等しい物の個数
        cnt.resize(length);
        for(int i = 0; i < length; i++){
            cnt[i].resize(11);
        }
        if(digit[0] != 0)cnt[0][digit[0]]++;
        for(int end = 1; end < length; end++){
            for(int res = 0; res < 11; res++){
                int temp = (res*10 + digit[end]) % 11;
                cnt[end][temp] = cnt[end-1][res];
            }
            if(digit[end] != 0)cnt[end][digit[end]]++;
        }

        count = 0;
        for(int end = 1; end < length; end++){
            count += cnt[end][0];
        }
        cout << count << endl;
    }
    return 0;
}

int convert(char c)
{
    int a = c - 48;
    return a;
}

Measured memory_bytes: 8424
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

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

    int h, w;
    cin >> h >> w;
    string data[h];
    for (int i = 0; i < h; i++)
    {
        cin >> data[i];
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (data[i][j] == '#')
            {
                bool has_black = false;
                for (int k = 0; k < 4; k++)
                {
                    if (i + dx[k] >= 0 && i + dx[k] < h && j + dy[k] >= 0 && j + dy[k] < w)
                    {
                        if (data[i + dx[k]][j + dy[k]] == '#')
                        {
                            has_black = true;
                        }
                    }
                }
                if (!has_black)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int N;

    cin >> N;

    if(N%2 == 1){
        cout << N/2 + 1 << endl;
    }else{
        cout << N/2;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

// long version
long long int GCD(long long int x, long long int y){
    if(x>y){
        long long int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            long long int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

/*
    Greatest Common Divisor
*/

int main() {
    int x, y;
    cin >> x >> y;

    int ans = GCD(x, y);

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



Measured memory_bytes: 3124
EPS = 1e-9
INF = 1e9

def check(a,b)
  (a - b).abs <= EPS || (a - b).abs <= [a.abs, b.abs].max * EPS
end

gets.to_i.times do
  arr = gets.chomp.split(" ").map(&:to_f)
  a = [].push(arr.shift).push(arr.shift)
  b = [].push(arr.shift).push(arr.shift)
  c = [].push(arr.shift).push(arr.shift)
  d = [].push(arr.shift).push(arr.shift)

  a,b=b,a if a[0]>b[0]
  c,d=d,c if c[0]>d[0]

  # a<b, c<d

  ab = INF
  cd = INF

  ab = (b[1]-a[1])/(b[0]-a[0]) if !check(a[0],b[0])
  cd = (d[1]-c[1])/(d[0]-c[0]) if !check(c[0],d[0])

  puts check(ab, cd) ? "YES" : "NO"
end

Measured memory_bytes: 6128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int k, s, ans = 0; cin >> k >> s;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z && z <= k)ans++;
		}
	}cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define eb emplace_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e6+3;

bool mm[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)mm[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!mm[i])for(int j = i*i; j<N; j+=i)mm[j]=1;
	for(int i = 3; i<N; i+=2)if(!mm[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	int n; cin>>n;
	vl v(n);
	fore(i,0,n)cin>>v[i];
	sort(all(v),greater<lli>());
	lli res= v[0];
	int j = 1;
	for(j=1;j<1+(n-2)/2;j++)res+=2*v[j];
	if(n&1 and n>2)res+=v[j];
	cout<<res<<ENDL;

}


Measured memory_bytes: 4772
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <complex>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef double D;
typedef complex<D> P;
typedef vector<P> Pol;
int N,M;
D eps=1e-9;
D cx[100],cy[100],cr[100];
P cp[100];
int ibase;
vector<int> arounds[100];
vector<Pol> Pols;
bool comp(const int& l,const int& r){
	P a=cp[l]-cp[ibase],b=cp[r]-cp[ibase];
	return arg(a)<arg(b);
}
bool in(int id,P p){
	return abs(cp[id]-p)<cr[id];
}
bool contain(Pol pol,P p){
	bool in=false;
	rep(i,pol.size()){
		P a=pol[i]-p,b=pol[(i+1)%pol.size()]-p;
		if(imag(a)>imag(b)) swap(a,b);
		if(imag(a)<eps&&eps<imag(b)&&imag(conj(a)*b)>eps) in=!in;
	}
	return in;
}
bool can(P sp,P gp){
	rep(i,N){
		if(in(i,sp)!=in(i,gp)) return false;
	}
	rep(i,N){
		if(in(i,sp)&&in(i,gp)) return true;
	}
	for(auto pol:Pols){
		if(contain(pol,sp)!=contain(pol,gp)) return false;
	}
	return true;
}
bool intersect(int i,int j){
	if(i==j) return false;
	D d=abs(cp[i]-cp[j]);
	if(d>cr[i]+cr[j]) return false;
	if(d+cr[i]<cr[j]||d+cr[j]<cr[i]) return false;
	return true;
}
int main(){
	while(true){
		cin>>N>>M;
		if(N==0) break;
		rep(i,N) arounds[i].clear();
		Pols.clear();
		rep(i,N) cin>>cx[i]>>cy[i]>>cr[i];
		rep(i,N) cp[i]=P(cx[i],cy[i]);
		rep(i,N){
			ibase=i;
			rep(j,N) if(intersect(i,j)) arounds[i].pb(j);
			sort(all(arounds[i]),comp);
		}
/*		rep(i,N){
			for(auto j:arounds[i]) cout<<j<<" ";
			puts("");
		}*/
		bool use[100][100]={};
		rep(i,N){
			for(auto j:arounds[i]){
				if(use[i][j]) continue;
				Pol pol;
				int s=i,t=j;
				do{
//					show(s);
//					show(t);
					pol.pb(cp[s]);
					use[s][t]=true;
					ibase=s;
/*					vector<int>::iterator it=upper_bound(all(arounds[s]),t,comp);
					if(it==arounds[s].end()){
						it=arounds[s].begin();
						puts("HERE");
					}
					t=s,s=*it;*/
					int nxt=0;
					rep(k,arounds[s].size()){
						if(arounds[s][k]==t){
							nxt=k+1;
							break;
						}
					}
					if(nxt==arounds[s].size()) nxt=0;
					nxt=arounds[s][nxt];
					t=s,s=nxt;
				}while(s!=i);
				Pols.pb(pol);
//				cout<<"pol  ";
//				rep(i,pol.size()) cout<<pol[i]<<" ";
//				cout<<endl;
			}
		}
		rep(i,M){
			D sx,sy,gx,gy;
			cin>>sx>>sy>>gx>>gy;
			P sp=P(sx,sy),gp=P(gx,gy);
			cout<<(can(sp,gp)?"YES":"NO")<<(i==M-1?"\n":" ");
		}
	}
}

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> b(M);
  for (int i = 0; i < M; i ++) cin >> b[i];

  int ans = 0;
  for (int i = 0; i < N; i ++) {
    int sum = C;
    for (int j = 0; j < M; j ++) {
      int a; cin >> a;
      sum += a * b[j];
    }
    if (sum > 0) ans ++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define mod (1000000007)
#define ll long long int

int main(void){
  int A,B;
  char op;
  cin >> A >> op >> B;
  if(op=='+'){
    cout << A+B << endl;
  }else{
    cout << A-B << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
    char c=getchar();ll f=1,x=0;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return x*f;
}
#define mod 1000000007
void MOD(int &x){if(x>=mod)x-=mod;}
#define maxn 100010
#define inf (1<<30)

int main(){
	int a,b,c;
	in(a);in(b);in(c);
	if(c-(a-b)<0)cout<<0<<endl;
	else cout<<c-(a-b)<<endl;
}

Measured memory_bytes: 256