akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll freq[100001]={0};
int main(){

	int n; cin>>n;
	int ar[n];
	int xx=0;

	for(int i=0;i<n;i++){
		cin>>ar[i];
		xx=xx^ar[i];
	}

	for(int i=0;i<n;i++)
		ar[i]=ar[i]^xx;

    for(int i=0;i<n;i++)
        cout<<ar[i]<<" ";

}


Measured memory_bytes: 4364
N = int(input())
S = input()

def f(m):
    se = set()
    arr = [None]*N
    for i in range(0,N-m+1):
        if i >= m:
            se.add(arr[i-m])
        arr[i] = hash(S[i:i+m])
        if arr[i] in se:
            return True
    return False

l = 0
r = N//2+1
while (r-l)>1:
    mid = (r+l)//2
    if f(mid):
        l = mid
    else:
        r = mid
print(l)

Measured memory_bytes: 3416
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld double
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define vc vector
#define rep1(it,v) for(it=v.begin();it!=v.end();it++)
#define ayush ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input(v) for(auto &it:v)cin>>it
#define inf 100000000007
#define pb push_back

int main()
{
    ll n,k; cin>>n>>k; vc<ll> v1(n), v2(k+5); input(v1);
    rep(i,1,k)
    {
        rep(j,0,n-1)
        {
            if(i>=v1[j] && v2[i-v1[j]]==0) v2[i]=1;
        }
    }
    if(v2[k]) cout<<"First";
    else cout<<"Second"; 
}

Measured memory_bytes: 4048
#include <iostream>
#include<cstring>
#include<iomanip>
using namespace std;

double probability(double p[],int n){
    double dp[n+1][n+1];
    memset(dp,0.0,sizeof(dp));
    dp[0][0] = 1.0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0)
            dp[i][j] = dp[i-1][j]*(1.0-p[i-1]);
            else
            dp[i][j] = dp[i-1][j]*(1.0-p[i-1]) + dp[i-1][j-1]*p[i-1];
        }
    }
    double ans = 0.0;
    for(int i=(n+1)/2;i<=n;i++){
        ans += dp[n][i];
    }
    return ans;
}

int main() {
    int n;
    cin>>n;
    double p[n];
    for(int i=0;i<n;i++)
    cin>>p[i];

    cout<<setprecision(10)<<probability(p,n);

    return 0;
}

Measured memory_bytes: 74060
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 h = sc.nextInt();
		int m = sc.nextInt();
		
		double ma = 360 / 60 * m;
		double ha = 360 / 12 * h + 30.0 / 60 * m;
		
		double x = Math.abs(ma - ha);
		x = Math.min(x, 360 - x);
		x = Math.toRadians(x);
		
		double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(x));
		
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 35980
let rec gcd a b =
    match (a, b) with
    | (x, 0) -> x
    | (0, y) -> y
    | (a, b) -> gcd b (a % b)

let N = stdin.ReadLine() |> int
let A = stdin.ReadLine().Split() |> Array.map int

let l = Array.scan gcd 0 A |> Array.take N
let r = Array.scanBack gcd A 0 |> Array.skip 1

Array.zip l r
|> Array.map (fun x -> gcd (fst x) (snd x))
|> Array.max
|> stdout.WriteLine


Measured memory_bytes: 34780
// class point	の練習（クラスの高度な実装）
#include <iostream>
using namespace std;



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

	cin >> a >> b >> c;

	if (a > b&&a > c) {
		if (b > c)cout << c << " " << b << " " << a << "\n";
		else cout << b << " " << c << " " << a << "\n";
	}
	else if (b > a&&b > c) {
		if (a > c)cout << c << " " << a << " " << b << "\n";
		else cout << a << " " << c << " " << b << "\n";
	}
	else {
		if (a > b)cout << b << " " << a << " " << c << "\n";
		else cout << a << " " << b << " " << c << "\n";
	}

	return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int K, S, t, z;
  	cin >> K >> S;
  	t = 0;
  	for(int x = 0; x <= K; x++){
    	for(int y = 0; y <= K; y++){
          z = S - x - y;
          if(0 <= z &&z <= K){
           t++;
          }
        }
    }
  cout << t << endl;
}

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

int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for(int i=0;i<m;i++)
{
	cin >> a[i];
}

for(int i =0;i<m;i++)
{
	n -= a[i];
}
if(n < 0)
{
	n = -1;
}
cout << n << endl;
return 0;
}


Measured memory_bytes: 3644
a = int(input())
list_a=list(map(int, input().split()))  #リスト入力
count = 0
for i in range(len(list_a)):
#     print(list_a[i],len(list_a)-i)
    if list_a[i] != i+1:
        count += 1
    
if count == 2 or count == 0:
    print("YES")
else :
    print("NO")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[205];
int main(){
	string s;
	cin>>s;
	for(int i=0;i<3;i++){
		if(s[i]==s[i+1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
judge = N*[1]
for i in range(K):
	d = int(input())
	array = list(map(int, input().split()))
	for j in range(d):
		judge[array[j]-1] = 0

ans = 0
#print(judge)
for i in range(N):
	if judge[i] == 1:
		ans+=1
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var cards = { "S":[] , "H":[], "C":[], "D":[] };
  var shcd = [ 'S', 'H', 'C', 'D' ];
  for( var key in cards ) {
    for( var i=1; i<=13; i++ ) {
      cards[key].push( i );
    }
  }
  var data = input.split( '\n' );
  
  for( var i=1; i<data.length; i++ ) {
    var p = data[i].split( ' ' );

    var k = p[0].toString();
    k = 'S';
    if( 'S' == p[0] ) {
      k = 'S';
    } else if( 'H' == p[0] ) {
      k = 'H';
    } else if( 'C' == p[0] ) {
      k = 'C';
    } else if( 'D' == p[0] ) {
      k = 'D';
    }
    var res = cards[k].indexOf( Number( p[1] ) );
    if( -1 != res ) {
        cards[k].splice( res, 1 );
    }
  }
  for( var i=0; i<4; i++ ) {
    for( var j = 0; j<cards[ shcd[i] ].length; j++ ) {
      console.log( shcd[i]+" "+cards[ shcd[i] ][j] );
    }
  }
});

Measured memory_bytes: 7644
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

bool ACGT(char c) {
    if(c == 'A')
        return true;
    if(c == 'C')
        return true;
    if(c == 'G')
        return true;
    if(c == 'T')
        return true;
    
    return false;
}
int main(void) {
    string str;
    cin>>str;

    int ans = 0;
    for(int i = 0;i < str.length();i++) {
        if(ACGT(str[i])) {
            int k;
            for(k = i+1;k < str.length();k++) {
                if(!ACGT(str[k]))
                    break;
            }
            ans = max(ans,k - i);
        }
    }

    cout<<ans<<endl;

    return 0;
}







Measured memory_bytes: 256
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Tue Apr  3 00:47:31 2018
//
package main

import (
	"fmt"
)

func main() {
	var sx, sy, tx, ty int
	fmt.Scan(&sx, &sy, &tx, &ty)

	for i := 0; i < tx-sx; i++ {
		fmt.Print("R")
	}
	for i := 0; i < ty-sy; i++ {
		fmt.Print("U")
	}
	for i := 0; i < tx-sx; i++ {
		fmt.Print("L")
	}
	for i := 0; i < ty-sy; i++ {
		fmt.Print("D")
	}
	fmt.Print("D")
	for i := 0; i < tx-sx+1; i++ {
		fmt.Print("R")
	}
	for i := 0; i < ty-sy+1; i++ {
		fmt.Print("U")
	}
	fmt.Print("L")

	fmt.Print("U")
	for i := 0; i < tx-sx+1; i++ {
		fmt.Print("L")
	}
	for i := 0; i < ty-sy+1; i++ {
		fmt.Print("D")
	}
	fmt.Print("R")
	fmt.Println()
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = 10000;

int area[MAX_N+1];

void calc_area (void )
{
	memset (area, 0, sizeof (area ) );
	area[1] = 2;
	for (int i = 2; i <= MAX_N; i++ ){
		area[i] = i + area[i-1];
	} // end for
/*	
	rep (i, MAX_N + 1 )
		cerr << setw(6) << i << ": " << area[i] << endl;
*/
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.area", "r", stdin );
	calc_area ();

	int n;
	while (scanf ("%d", &n ) != EOF ){
		cout << area[n] << endl;
	} // end loop
		
	return 0;
}

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



int main()
{
    ll n,K;
    cin>>n>>K;
    vector<ll>v(n);
    vector<ll>dp(n+1,-1);
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
    }
    dp[0]=0;
    for(ll i=1;i<n;i++)
    {
        ll add=LLONG_MAX;
        for(ll k=1;k<=K;k++){
            if(k<=i)
            add=min(add,dp[i-k]+abs(v[i]-v[i-k]));
        }
        dp[i]=add;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

const int MOD =1000000007;

signed main() {
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
int ng=0,ok=200001,mid,j,ans,m2=0;
while(abs(ok-ng)>1){
    mid=(ok+ng)/2;
    j=n-1;
    ans=0;
    for(int i=0;i<n;i++){
        while(j>=0&&mid<=a[i]+a[j])j--;
        ans+=n-1-j;
    }
   
    if(ans<=m){
        ok=mid;
        m2=ans;
    }
    else ng=mid;


}
//cerr<<ans<<' '<<m<<endl;
int asumj=0,ans2=0;
j=n-1;
for(int i=0;i<n;i++){
    while(j>=0&&ok<=a[i]+a[j]){
        asumj+=a[j];
        j--;
    }
    ans2+=(n-1-j)*a[i]+asumj;
    
}
//cerr<<ans2<<endl;
ans2+=(m-m2)*ng;
cout<<ans2;


}


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

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(1, N+1):
  w, v = map(int, input().split())
  for j in range(1, W+1):
    if j >= w:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]

print(dp[N][W])

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

int main() {
    long long A, B, C;
    cin >> A >> B >> C;
    if (A%2==0 || B%2==0 || C%2==0) {
        cout << 0 << endl;
    } else {
        cout << min({A*B, B*C, C*A}) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int a[100];
int main(){
	for(int i = 1; i <= 10; i++){
		cin >> a[i];
	}
	sort(a+1, a+11);
	cout << a[10] << "\n" << a[9] << "\n" << a[8] << "\n";
	return 0;
}

Measured memory_bytes: 3116
from collections import Counter
S = []
N = int(input())
for i in range(N):
    s = input()
    S.append(s)

c = Counter(S)
max_num = max(c.values())
max_list = [i for i,j in c.items() if j==max_num]
max_list.sort()
print('\n'.join(max_list))

Measured memory_bytes: 114768
import java.util.Scanner;

class Main{

	static int[] p;
	static	int N ;

	public static void main(String[] args) {


		Scanner scanner = new Scanner(System.in);
		N = scanner.nextInt();
		p = new int[N+1];
		int ans = 0;

		for(int i = 1;i < N+1;i++){
			p[i] = scanner.nextInt();
		}

		for(int i = 1;i < N;i++){
			if(p[i] == i){
				int c = p[i];
				p[i] = p[i + 1];
				p[i+1] = c;
				ans++;
			}
		}
		if(p[N]==N){
			ans++;			

		}
		System.out.println(ans);

	}


}

class Pair implements Comparable{
	int from;
	int middle;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}





Measured memory_bytes: 50416
#define scanf_s scanf
#include <stdio.h>
#include <iostream>
using namespace std;
#define MAX 200
int main(void)
{
	long long int a, b, c, x, y;
	while (scanf_s("%lld %lld", &a, &b) != EOF) {
		if (b > a) { x = a; a = b; b = x; }
		x = a; y = b;
		c = a % b;
		while (c != 0) {
			a = b; b = c;
			c = a % b;
		}
		printf("%lld %lld\n", b, x * y / b);
	}
}

Measured memory_bytes: 1192
#include<iostream> 
#include<string>
using namespace std; 
int main(){ 
  string str;
    int ans=0;
    cin >> str;
    for (int i = 0 ; i < str.length() ; i++){
        if (str[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
  return 0; 
}

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

int n, m, A[105][105], tot, nxt[200 * 105], fst[205], cur[205], to[200 * 105], f[200 * 105], h[205];

void addedge(int u, int v, int w) {
	nxt[++tot] = fst[u]; fst[u] = tot; to[tot] = v; f[tot] = w;
	nxt[++tot] = fst[v]; fst[v] = tot; to[tot] = u; f[tot] = 0;
}
bool bfs() {
	static int q[205];
	int st = 0, ed = 0;
	for (int i = 1; i <= 2 * n + 2; ++i) cur[i] = fst[i], h[i] = -1;
	h[2 * n + 1] = 0;
	q[ed++] = 2 * n + 1;
	while (st < ed) {
		int u = q[st++];
		for (int i = fst[u]; i; i = nxt[i])
			if (f[i] > 0 && h[to[i]] == -1) {
				h[to[i]] = h[u] + 1;
				if (to[i] == 2 * n + 2) return true;
				q[ed++] = to[i];
			}
	}
	return false;
}
int dfs(int u, int fl) {
	if (u == 2 * n + 2 || !fl) return fl;
	int left = fl;
	for (int &i = cur[u], t; i; i = nxt[i])
		if (h[to[i]] == h[u] + 1 && (t = dfs(to[i], min(left, f[i]))) > 0) {
			f[i] -= t, f[i ^ 1] += t, left -= t;
			if (!left) break;
		}
	return fl - left;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			scanf("%d", A[i] + j);
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n * 2 + 2; ++j)
			fst[j] = 0;
		static int s[105][105];
		tot = 1;
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k)
				s[j][k] = 0;
			for (int k = i; k <= m; ++k)
				s[j][(A[j][k] - 1) / m + 1] = k;
			for (int k = 1; k <= n; ++k)
				if (s[j][k]) addedge(j, n + k, 1);
			addedge(n * 2 + 1, j, 1);
			addedge(n + j, n * 2 + 2, 1);
		}
		int res = 0;
		while (bfs()) res += dfs(2 * n + 1, 1 << 30);
		for (int j = 2; j <= tot; j += 2) {
			int u = to[j ^ 1], v = to[j];
			if (u >= 1 && u <= n && v > n && v <= 2 * n && !f[j])
				swap(A[u][i], A[u][s[u][v - n]]);
		}
	}
	static int B[105][105];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			printf("%d%c", A[i][j], " \n"[j == m]), B[j][i] = A[i][j];
	for (int i = 1; i <= m; ++i) {
		sort(B[i] + 1, B[i] + 1 + n, [](int x, int y) { return (x - 1) / m < (y - 1) / m; });
		for (int j = 1; j <= n; ++j)
			A[j][i] = B[i][j];
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			printf("%d%c", A[i][j], " \n"[j == m]);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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 conv(string s){
    ll ret=0;
    ll hh=atoi(s.substr(0,2).c_str());
    ll mm=atoi(s.substr(3,2).c_str());
    ll ss=atoi(s.substr(6,2).c_str());
    return 3600*hh+60*mm+ss;
}
void solve(){
    while(1){
        ll n;cin>>n;
        if(!n)return;
        vl cnt(86400);
        rep(i,n){
            string s,t;cin>>s>>t;
            ll ss=conv(s),tt=conv(t);
            cnt[ss]++;
            cnt[tt]--;
        }
        rep(i,86400)cnt[i+1]+=cnt[i];
        ll ans=0;
        rep(i,86400)chmax(ans,cnt[i]);
        cout<<ans<<endl;
    }
}

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



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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    string s;
    cin >> n >> s;

    vector<int> R,G,B;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') R.push_back(i);
        if(s[i] == 'G') G.push_back(i);
        if(s[i] == 'B') B.push_back(i);
    }

    int r = R.size();
    int g = G.size();
    int b = B.size();

    int ans = 0;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < g; j++){
            ans += b;

            int x = max(R[i],G[j]);
            int y = min(R[i],G[j]);
            int diff = x - y;

            if(binary_search(B.begin(),B.end(), x + diff)) ans--;
            if(binary_search(B.begin(),B.end(), y - diff)) ans--;
            if(diff % 2 == 0) {
                if(binary_search(B.begin(),B.end(), y + diff / 2)) ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3676
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Dish> li = new ArrayList<>();
		
		for (int i=0;i<n;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			Dish d = new Dish();
			d.a=a;
			d.b=b;
			
			li.add(d);
		}
		
		li.sort(Comparator.comparing((d) -> (d.a+d.b), Comparator.reverseOrder()));
		
		long ans = 0;
		
		for (int i=0;i<n;i++) {
			if (i%2==0) {
				ans += li.get(0).a;
				li.remove(0);
			} else {
				ans -= li.get(0).b;
				li.remove(0);
			}
		}

		System.out.println(ans);
	}



}

class Dish  {
	int a;
	int b;
}


Measured memory_bytes: 93272
n, a, b = map(int, input().split())
x = list(map(int, input().split()))

if a > b:
    print(b * (n - 1))
    exit()

d = b // a + 1

ans = 0
for i in range(n-1):
    temp = x[i+1] - x[i]
    if temp >= d:
        ans += b
    else:
        ans += temp * a

print(ans)


Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int h,w;
char c[110][110];
bool visited[110][110];
void dfs(int x,int y){
	if(visited[y][x]){
		cout<<"LOOP"<<endl;
		return;
	}
	visited[y][x]=true;
	if(c[y][x]=='>'){
		dfs(x+1,y);
		return;
	}
	if(c[y][x]=='<'){
		dfs(x-1,y);
		return;
	}
	if(c[y][x]=='v'){
		dfs(x,y+1);
		return;
	}
	if(c[y][x]=='^'){
		dfs(x,y-1);
		return;
	}
	cout<<x<<" "<<y<<endl;
	return;
}
int main(){
   	while(cin>>h>>w,h+w){
		for(int i=0;i<h;i++){
			cin>>c[i];
			for(int j=0;j<w;j++){
				visited[i][j]=false;
			}
		}
		dfs(0,0);
	}
    return 0;
}



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

int main(){
    int N,K;cin>>N>>K;
    string S;cin>>S;

    vector<int>nums;
    if(S[0]=='0')nums.push_back(0);
    for (int i=0;i<S.size();){
        int j=i;
        while(j<S.size()&&S[j]==S[i])j++;
        nums.push_back(j-i);
        i=j;
    }
    if(S.back()=='0')nums.push_back(0);

    vector<int> sums((int)nums.size()+1,0);
    for(int i=0;i<nums.size();i++)sums[i+1]=sums[i]+nums[i];

    int res=0;
    for(int left=0;left<sums.size();left+=2){
        int right=left+K*2+1;
        if(right>=sums.size())right=(int)sums.size()-1;
        res=max(res,sums[right]-sums[left]);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;cin>>s;
    int plus=0,minus=0;
    for(int i=0;i<4;i++)
    {
         if(s[i]=='+') plus++;
         else minus++;
    }
    cout<<plus-minus<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
int main(){
   string s="CODEFESTIVAL2016";
    string ss;
    cin>>ss;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=ss[i])cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.1415926535

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

#define itn int

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (s.size() == 3 || s.size() ==1)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

Measured memory_bytes: 256
program varied
  implicit none
  character(26) :: s
  integer       :: n, i, m(26), c
  read(*,*) s
  s = adjustl(s)
  n = len_trim(s)
  m = 0
  do i = 1, n
    c = ichar(s(i:i)) - 96
    m(c) = m(c) + 1
  end do
  if (maxval(m) > 1) then
    write(*,'(a)') "no"
  else
    write(*,'(a)') "yes"
  end if
end program varied


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

int main(void){
    ll N, M;
    cin >> N >> M;
    ll A[N];
    rep(i,N) cin >> A[i];
    ll B,C,sum;
    pair<ll,ll> P[M];
    rep(i,M){
        cin >> B >>C;
        P[i] = make_pair(C,B);
    }
    sort(P,P+M);
    ll cnt=0;
    ll D[N];
    fill(D,D+N,0);
    bool flag = false;
    for(ll i=M-1;i>=0;i--){
        for(ll j = cnt;j<cnt+P[i].second;j++){
            D[j] = P[i].first;
            if(j == N-1){
                 flag = true;
                 break;
            }
        }
        if(flag)break;
        cnt = cnt + P[i].second;
    }
    
    //rep(i,N) cout << D[i] << endl;
    ll ans = 0;
    sort(A,A+N);
    rep(i,N){
        ans += max(D[i],A[i]);
    }
    
    
    cout << ans << endl;
}


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

#define REP(i,n) for(long long 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)

using ll = long long;
#define INF 1e9

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> x(N);
  REP(i, N){
    cin >> x[i];
  }
  ll ans = INF;
  REP(i, N-K+1){
    ll time;
    if(x[i] * x[i+K-1] > 0){
      time = max(abs(x[i]), abs(x[i+K-1]));
    }
    else{
      time = min(abs(x[i]), abs(x[i+K-1]))*2 + max(abs(x[i]), abs(x[i+K-1]));
    }
    ans = min(ans, time);
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int H,W,K; cin >> H >> W >> K;
  vector<string> S(H);
  for(int i=0; i<H; i++) cin >> S[i];
  
  int mindiv=(int)1e9;
  for(int i=0; i<(1<<(H-1)); i++){
    vector<vector<int>> horiz;
    for(int j=0; j<H; j++){
      if( j == 0 || (i & (1 << (j-1))) > 0 ){
        vector<int> n={j};
        horiz.push_back(n);
      }else{
        horiz[horiz.size()-1].push_back(j);
      }
    }
    
    int hordiv=horiz.size();
    bool isAble=true;
    vector<vector<int>> cnttmp(hordiv, vector<int>(W));
    for(int j=0; j<W; j++){
      for(int k=0; k<hordiv; k++){
        for(int l=0; l<horiz[k].size(); l++){
          if(l==0) cnttmp[k][j]=0;
          if(S[horiz[k][l]][j]=='1') cnttmp[k][j]++;
        }
        if(cnttmp[k][j]>K) isAble=false;
      }
    }
    
    //そもそもその水平分割が無理
    if(isAble==false) continue;
    
    //水平は可能な場合、右にカウントしていく
    int tmpdiv=hordiv-1;
    vector<int> rowtmp(hordiv);
    
    for(int j=0; j<W; j++){
      for(int k=0; k<hordiv; k++){
        rowtmp[k]+=cnttmp[k][j];
      }
      
      bool isBelow=true;
      for(int k=0; k<hordiv; k++){
        if(rowtmp[k]>K) isBelow=false;
      }
      
      if(isBelow==false){
        tmpdiv++;
        for(int k=0; k<hordiv; k++){
          rowtmp[k]=cnttmp[k][j];
        }
      }
    }
    
    mindiv=min(mindiv,tmpdiv);
    
  }
  cout << mindiv << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b , c , d, e, f, g, h, i;
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;

    if(a+e == b+d && b+f == e+c && d+h == e+g && e+i == f+h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

P = []
Y = []
I = []
for i in range(m):
    a, b = map(int, input().split())
    P.append(a)
    Y.append(b)
    I.append(i)

Z = zip(P, Y, I)
Z = sorted(Z)
P, Y, I = zip(*Z)

N = []
c = P[0]
d = 1
for i in range(m):
    if c == P[i]:
        N.append("{0:06d}{1:06d}".format(c, d))
        d += 1
    else:
        c = P[i]
        d = 1
        N.append("{0:06d}{1:06d}".format(c, d))
        d += 1

Z = zip(I, N)
Z = sorted(Z)
I, N = zip(*Z)
for i in N:
    print(i)

Measured memory_bytes: 43180
import sys
sys.setrecursionlimit(10**6)

def tl(s):
	pre = False
	ref = []
	for i in s:
		if ord(i) < 58:
			if pre:
				ref[-1] = [True, ref[-1][1]*10 + int(i)]
			else:
				pre = True
				ref += [[True, int(i)]]
		else:
			ref += [[False, i]]
			pre=False
	return ref

def main():
	n = int(input())
	pibot = tl(input())
	for _ in range(n):
		temp = tl(input())
		ans = "-"
		for i in range(len(temp)):
			if i >= len(pibot):
				ans = "+"
				break
			if pibot[i] == temp[i]:
				if pibot == temp:
					ans = "+"
					break
				continue
			if pibot[i][0] and not(temp[i][0]):
				ans = "+"
			elif not(pibot[i][0]) and temp[i][0]:
				ans = "-"
			elif pibot[i][0]:
				if pibot[i][1] < temp[i][1]:
					ans = "+"
				else:
					ans = "-"
			else:
				if ord(pibot[i][1]) < ord(temp[i][1]):
					ans = "+"
				else:
					ans = "-"
			break
		print(ans)
	return

main()
				


Measured memory_bytes: 5628
def dfs(i, s, plus):
    if i == n - 1:
        b = list(map(int, s.split("+")))
        return sum(b)
    return dfs(i + 1, s, plus) + dfs(i + 1, s[:i + plus + 1] + "+" + s[i + plus + 1:], plus + 1)

s = input()
n = len(s)

print(dfs(0, s, 0))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
int x[9],y[10]={8,2,5,5,4,5,6,3,7,6};
vector<int> dp[10010];
signed main(){
	int a,b;
	cin>>a>>b;
	f(i,b){
		cin>>x[i];
	}
	sort(x,x+b);
	for(int i=b-1;i>=0;i--){
		for(int j=y[x[i]];j<=a;j++){
			if(dp[j-y[x[i]]].size()||j-y[x[i]]==0){
				if(dp[j].size()<=dp[j-y[x[i]]].size()){
					dp[j]=dp[j-y[x[i]]];
					dp[j].push_back(x[i]);
				}
				else if(dp[j].size()-dp[j-y[x[i]]].size()==1){
					f(k,dp[j].size()){
						if(k==dp[j-y[x[i]]].size()){
							if(dp[j][k]<x[i]){
								dp[j]=dp[j-y[x[i]]];
								dp[j].push_back(x[i]);
							}
							break;
						}
						if(dp[j][k]>dp[j-y[x[i]]][k]) break;
						if(dp[j][k]<dp[j-y[x[i]]][k]){
							dp[j]=dp[j-y[x[i]]];
							dp[j].push_back(x[i]);
							break;
						}
					}
				}
			}
		}
	}
	f(i,dp[a].size()) cout<<dp[a][i];
	cout<<endl;
}


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

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

    int max = a + b;
    if (max < a - b){
        max = a - b;
    }
    if (max < a * b){
        max = a * b;
    }

    cout << max << endl;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
graph = []
for i in range(N):
    graph.append([])

#頂点の番号はindex+1
for i in range(M):
    a, b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited = []
for i in range(N):
    visited.append(0)
visited[0] = 1

#print(graph)

ans = 0

#jを訪れたときはvisited[j]が1になる

def dfs(v):
    global ans
    global visited
    kita = 0
    for k in visited:
        if k == 1:
            kita += 1
        
    if kita == N:
        ans += 1
    

    for j in graph[v]:
        #print(j)
        if visited[j] == 1:
            continue
        visited[j] = 1
        dfs(j)
        visited[j] = 0


dfs(0)

print(ans)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 4e5+9;

ll a[sz], when[sz];

int main()
{
    ll n, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++) scanf("%lld", &a[i]);

    ll now = 1;
    for(ll i=1; i<=k; i++) {
        now = a[now];
        if(when[now]) {
            ll x = i - when[now];
            ll rem = k - i;
            rem %= x;
            for(ll j=0; j<rem; j++) now = a[now];
            break;
        }
        else when[now] = i;
    }

    cout << now << endl;
}


Measured memory_bytes: 6812
#include<stdio.h>
#define inf 1152921504606846976
int main(void) {
	long long int h,i, j, N, Ma, Mb, a, b,min;
	long long int AB[40];
	long long int C[40];
	static long long int dp[41][4001];
	for (i = 0; i <= 40; i++) {
		for (j = 0; j <= 4000; j++) {
			dp[i][j] = inf;
		}
	}
	dp[0][2000] = 0; min = inf;
	scanf("%lld %lld %lld", &N, &Ma, &Mb);
	for (i = 0; i < N; i++) {
		scanf("%lld %lld %lld", &a, &b, &C[i]);
		AB[i] = a*Mb - b*Ma;
	}
	for (h = 0; h < N; h++) {
		for (i = 0; i < N; i++) {
			for (j = 0; j <= 4000; j++) {
				if (dp[i][j] < dp[i][j + AB[i]] + C[i]&&i!=h) {
					dp[i + 1][j] = dp[i][j];
				}
				else {
					dp[i + 1][j] = dp[i][j + AB[i]] + C[i];
				}
			}
		}
		if (min > dp[N][2000]) { min = dp[N][2000]; };
	}
	if (min< inf) {
	printf("%lld", min);
	}
	else { printf("-1"); }
	return 0;
}

Measured memory_bytes: 1408
inData = int(input())

seqData = list(range(1,inData+1,1))
outData = [0] * inData
for thisData in seqData:
    if thisData == inData:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData))
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData))
                    break
                else:
                    pass
            print("")
    else:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData), end = "")
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData), end = "")
                    break
                else:
                    pass


Measured memory_bytes: 6240
// TEMPLATE {{{
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define OJ 1
#else
#define OJ 0
#endif
 
#define endl '\n'
#define TIMESTAMP merr << "Execution time: " << (double)clock()/CLOCKS_PER_SEC << " s.\n"
class C_ {}; template <typename T> C_& operator <<(C_& __m, const T& __s) { if (!OJ) cerr << "\E[91m" << __s << "\E[0m"; return __m; }
C_ merr;
 
struct __s { __s() { if (OJ) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s(){ TIMESTAMP; } } __S;
/// END OF TEMPLATE }}}

#define size_t unsigned long long

int main(void) {
    string s;
    cin >> s;
    size_t x1 = (s[0]-'0')*10 + (s[1]-'0');
    size_t x2 = (s[2]-'0')*10 + (s[3]-'0');
    bool g1 = false, g2 = false;
    if (1 <= x1 && x1 <= 12) {
        g1 = true;
    }
    if (1 <= x2 && x2 <= 12) {
        g2 = true;
    }
    if (g1 && g2) {
        cout << "AMBIGUOUS" << endl;
    } else if (!g1 && !g2) {
        cout << "NA" << endl;
    } else if (g1) {
        cout << "MMYY" << endl;
    } else {
        cout << "YYMM" << endl;
    }
}


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

using ll = long long;

const int MAXN = 100010;
int N, M;
ll K;
int X[MAXN];
int dist[MAXN];
ll ans[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (int i = 0; i < N - 1; i++) {
		dist[i] = X[i + 1] - X[i];
	}
	vector<int> perm(N - 1);
	iota(perm.begin(), perm.end(), 0);
	cin >> M >> K;
	for (int i = 0; i < M; i++) {
		int x; cin >> x; x--;
		swap(perm[x - 1], perm[x]);
	}

	auto go = [&](vector<int> a, vector<int> b) -> vector<int> {
		vector<int> c(N - 1);
		for (int i = 0; i < N - 1; i++) {
			c[i] = a[b[i]];
		}
		return c;
	};

	vector<int> res(N - 1);
	iota(res.begin(), res.end(), 0);
	while (K) {
		if (K & 1) {
			res = go(res, perm);
		}
		perm = go(perm, perm);
		K /= 2;
	}

	ans[0] = X[0];
	for (int i = 0; i < N - 1; i++) {
		ans[i + 1] = ans[i] + dist[res[i]];
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << '\n';
	}

	return 0;
}


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

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int answer = 0;
  rep(i, N) {
    int a;
    cin >> a;
    if (i % 2 == 0 && a % 2 == 1) ++answer;
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define endl '\n'
#define MAX

typedef long long ll;
typedef pair<int,int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;


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

	int n, w;
	cin >> n >> w;
	vector<ll> a(n), b(n);
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	
	vector<vector<ll>> dp(2, vector<ll>(w + 5));
	
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= w; j++){
			dp[i % 2][j] = dp[(i + 1) % 2][j];
			if(j - a[i] >= 0)
				dp[i % 2][j] = max(dp[i % 2][j], dp[(i + 1) % 2][j - a[i]] + b[i]);
			ans = max(ans, dp[i % 2][j]);
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
def gcd(x, y):

   while(y):
       x, y = y, x % y

   return x

n,x = map(int,input().split())
a = list(map(int,input().split()))
k = []
for i in range(len(a)):
    k.append(abs(a[i]-x))
g = 0
for i in range(len(k)):
    g = gcd(g,k[i])
print(g)


Measured memory_bytes: 63640
n,c=map(int, input().split())
x=[]
xr=[]
v=[]

for _ in range(n):
    xi,vi=map(int, input().split())
    x.append(xi)
    xr.append(c-xi)
    v.append(vi)
xr.reverse()
x.insert(0,0)
xr.insert(0,0)

score=[0]
score_r=[0]

tmp=0
for i, vi in enumerate(v):
    tmp+=vi
    score.append(tmp-x[i+1])
tmp=0
for i, vi in enumerate(v[::-1]):
    tmp+=vi
    score_r.append(tmp-xr[i+1])

maxscore=[0]
maxscore_r=[0]

tmp=0
for si in score:
    maxscore.append(max(si,tmp))
    tmp=max(si,tmp)
tmp=0
for si in score_r:
    maxscore_r.append(max(si,tmp))
    tmp=max(si,tmp)

ans=0
for i, si in enumerate(score):
    tmp=si-x[i]+maxscore_r[n-i+1]
    ans=max(tmp,ans)
for i, si in enumerate(score_r):
    tmp=si-xr[i]+maxscore[n-i+1]
    ans=max(tmp,ans)
print(ans)            
        




Measured memory_bytes: 24408
A = int(input())
B = int(input())
C = int(input())
D = int(input())

if A > B:
    if C > D:
        print("%d" % (B+D))
    else:
        print("%d" % (B+C))
else:
    if C > D:
        print("%d" % (A+D))
    else:
        print("%d" % (A+C))

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define inf (int)(1e9)
#define INF 1.1529215e+18
#define MAXX 999999
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/
const int MAX_N=1000001;
int N;
V memo(MAX_N,-1);
int bfs(int n){
    Q que;
    que.push(0);
    while(!que.empty()){
        int tmp=que.front();//待ち行列の先頭を取り出す
        que.pop();//取り出したら即削除
        for(int i=1;tmp+i<=N;i*=6){
            if(memo[tmp+i]==-1){//未訪問なら
                memo[tmp+i]=memo[tmp]+1;//memo[tmp]は最短距離なので,memo[tmp+i]も最短距離です
                que.push(tmp+i);//memo[tmp+i]には最短距離が格納済み
            }
        }
        for(int j=1;tmp+j<=N;j*=9){
            if(memo[tmp+j]==-1){
                memo[tmp+j]=memo[tmp]+1;
                que.push(tmp+j);
            }
        }
    }
    return memo[n];
}
int main(){//bfsで最短経路問題に帰着
    cin>>N;
    memo[0]=0;//初期条件
    cout<<bfs(N)<<endl;
}


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

int main() {
  
    long long m,rd,rr,cd,cr;
	
    cin>>m>>rd>>rr>>cd>>cr;
     
    long long w1 = (100*cd+rd-1)/ rd;
    long long w2 = (100*cr+rr-1)/ rr;
	
    if( m < w1+w2 ){
        cout << -1 << endl;
    }else{
        cout << m-(w1+w2) << endl;
    }
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

int gcd(int x,int y){
    if(y==0) return x;
    return gcd(y, x%y);
}

signed main(){
    int N; cin >> N;
    vector<int> v(N);
    collect(v, N);
    int ans = v[N-1];
    rep(i,N-1){
        ans = gcd(ans,v[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n, W = map(int, input().split())
ws = [0]*n
vs = [0]*n

for i in range(n):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v
  
dp = [[0]*(W+1) for _ in range(n+1)]
for i in range(n):
  for j in range(W+1):
    if j - ws[i] >= 0:
      dp[i+1][j] = max(dp[i+1][j], dp[i][j-ws[i]]+vs[i])
    dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    
print(dp[-1][W])

Measured memory_bytes: 120684
n = int(input())
if n%2 != 0:
  print(0)
else:
  k = 2
  cnt2 = 0
  l = 5
  cnt5 = 0
  while k <= n:
    cnt2 += n//k
    k *= 2
  while n//l != 0:
    cnt5 += (n//l)//2
    l *= 5
  print(min(cnt2,cnt5))

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[2] = {' ', '\n'};

int main() {
  int i, j, k, n, m, l;

  int x[30] = {};
  char c;
  while (cin >> c) if (isalpha(c)) x[tolower(c) - 'a']++;
  rep(i,26) printf("%c : %d\n", i + 'a', x[i]);

  return 0;
}
  

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

vector<int> g[N];

int f[N];

int dfs(int u)  {
    if (f[u] >= 0)
        return  f[u];

    f[u] = 0;

    for(int v : g[u])   {
        int nxt = dfs(v) + 1;

        if (f[u] < nxt)
            f[u] = nxt;
    }
    return  f[u];
}

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

    int n;  cin >> n;
    int m;  cin >> m;

    for(int i = 0 ; i < m ; ++i)    {
        int x;  cin >> x;
        int y;  cin >> y;

        g[x].pb(y);
    }

    fill(f + 1,f + 1 + n,-1);

    int ans = 0;

    for(int i = 1 ; i <= n ; ++i)
        if (ans < dfs(i))
            ans = dfs(i);

    cout << ans << endl;
}

Measured memory_bytes: 9856
n,k,q = map(int,input().split())
p_list =[k-q]*n

for i in range(q):
    a_i = int(input())
    p_list[a_i-1] += 1  

for i in range(n):
    if p_list[i] <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 6596
#include <iostream>

using namespace std;

int v[20003];
int a[20003];
int b[20003];

int main() {

    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> v[i];

    for(int i = 1; i <= n; i++)
        a[i] = 1 + (n+1)*(i-1);

    for(int i = 1; i <= n; i++)
        b[i] = 1 + (n+1)*(n-i);

    for(int i = 1; i <= n; i++) {
        a[v[i]] += i;
    }

    for(int i = 1; i <= n; i++)
        cout << a[i] << " ";
    cout << '\n';
    for(int i = 1; i <= n; i++)
        cout << b[i] << " ";
    cout << '\n';

    return 0;
}


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

typedef long long ll;
const long long m = 1e9+7;

int main()
{
    ll n,k,ans=0,l,r;
    cin>>n>>k;
    for(ll i=k;i<=n+1;i++){
        l = i*(i-1)/2;
        r = n*i-l;
        ans+= r-l+1;
        //cout<<ans<<endl;
    }
    cout<<ans%m<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int n; cin >> n;
   vec<int> p(n);
   rep(i, 0, n) {
      cin >> p[i];
   }

   SORT(p);
   int sum = 0;
   rep(i, 0, n) {
      if (i == n-1) {
         sum += p[i]/2;
      } else {
         sum += p[i];
      }
   }
   cout << sum << endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io

    string s;
    cin>>s;
    vector<string> pattern={"dream", "dreamer", "erase", "eraser"};
    reverse(s.begin(), s.end());
    rep(i,4) {
        reverse(pattern[i].begin(), pattern[i].end());
    }

    int i=0,N=s.size();
    while(i<N){
        bool ok=false;
        for(int k=0;k<4;k++){
            int len=pattern[k].size();
            string ret=pattern[k];
            if(s.substr(i, len)==ret){
                ok=true;
                i+=len;
                break;
            }
        }
        if(ok==false){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 512
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    alst = list(map(int, input().split()))
    s = sum(alst)
    alst = [a * 2 for a in alst]
    lst = [-s]
    for a in alst:
      lst.extend([i + a for i in lst])
    print(min(map(abs, lst)))
main()


Measured memory_bytes: 61932
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  rep(i,m) cin >> a.at(i) >> b.at(i);

  vector<ll> s;
  rep(i,m){
    if(a.at(i)==1) s.push_back(b.at(i));
    if(b.at(i)==1) s.push_back(a.at(i));
    if(a.at(i)==n) s.push_back(b.at(i));
    if(b.at(i)==n) s.push_back(a.at(i));
  }
  sort(all(s));
  size_t bef = s.size();
  s.erase(unique(all(s)), s.end());
  if (s.size()==bef) cout << "IMPOSSIBLE" << endl;
  else cout << "POSSIBLE" << endl;

  return 0;
}

Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
typedef pair<int,int> pii;
vector<int> vs, pa, pb;
vector<pii> as, bs, qs;
signed main(){
  int n;
  cin >> n;
  qs.resize(n);
  pa.resize(n);
  pb.resize(n);
  for(int i = 0; i < n; i++){
    cin >> qs[i].ff;as.pb({qs[i].ff, i});
  }
  for(int i = 0; i < n; i++){
    cin >> qs[i].ss;bs.pb({qs[i].ss, i});
  }
  sort(all(as));sort(all(bs));
  vs.pb(0);
  for(int i = 0; i < n; i++){
    pa[as[i].ss] = pb[bs[i].ss] = i;
    if(bs[i].ff < as[i].ff)return cout << "No\n", 0;
  }
  for(int i = 0; i < n - 1; i++)
    if(bs[i].ff >= as[i+1].ff)return cout << "Yes\n", 0;
  for(int p = 0, c = 0; p || !c; p = pa[bs[p].ss],c++)
    if(c == n-1)return cout << "No\n", 0;
  cout << "Yes\n";
}


Measured memory_bytes: 4084
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
count = 0
# ソートして
for b in B:
  upeer_b = N - bisect.bisect_right(C, b)
  downer_b = bisect.bisect_left(A, b)
  count += upeer_b * downer_b

# for c in C:
#   under_c = bisect.bisect_left(B, c)
#   for b in B[:under_c]:
#     under_b = bisect.bisect_left(A, b)
#     count += under_b

print(count)


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

int main() {

  string N;
  cin >> N;
  
  int count = 0;
	
  for(int i = 0; i < N.size(); i++){
      if( N.at(i) == '+') count++;
      else count--;
    }
  
  cout << count << endl;
}

Measured memory_bytes: 256