akhauriyash/Code-Regression huggingface dataset:
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long r, d, x;
    scan(r, d, x);
    auto tmp = x;
    foreach (i; 0 .. 10)
    {
        tmp = calc_algae(r, tmp, d);
        tmp.writeln();
    }
}

auto calc_algae(long r, long x, long d)
{
    return r * x - d;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N, K, S;
    cin >> N >> K >> S;
    rep(i, K) cout << S << " ";
    rep(i, N - K) {
        if (S != 1000000000) cout << S + 1 << " ";
        else cout << 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

long long gcd(long long a, long long b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

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

int main(){
  vector<int> candy(3);
  for(int i = 0;i<3;i++){
    cin >> candy.at(i);
  }
  sort(candy.begin(),candy.end());
  reverse(candy.begin(),candy.end());
  if(candy.at(0) == candy.at(1)+candy.at(2)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] input = Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray();
            int ans = 1;
            bool flag = true ; //増加→true
            bool first = false; //配列の最初
            for (long j = 0; j < input.Length - 1; ++j)
            {
                if (input[j] != input[j + 1])
                {
                    if (input[j] < input[j + 1]) flag = true;
                    else flag = false;
                    break;
                }
            }

            for (long i = 1; i < input.Length - 1; ++i)
            {


                if (flag)
                {
                    if (input[i - 1] > input[i])
                    {
                        first = true;
                        //flag = !flag;



                    }
                }
                else
                {
                    if (input[i - 1] < input[i])
                    {
                        first = true;
                        //flag = !flag;

                    }
                }
                if (first)
                {
                    ans++;
                    first = false;
                    //Console.WriteLine(i + "番目 " + ans + "個 flag=" + flag);

                    for (long j = i; j < input.Length - 1; ++j)
                    {
                        if (input[j] != input[j + 1])
                        {
                            if (input[j] < input[j + 1]) flag = true;
                            else flag = false;
                            break;
                        }
                    }
                }

                if(i == input.Length - 2)
                {
                    //Console.WriteLine(i + "番目 flag=" + flag);
                    if (flag)
                    {
                        if (input[i] > input[i + 1]) ++ans;
                    }
                    else
                    {
                        if (input[i] < input[i + 1]) ++ans;
                    }
                }
                
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 20832
n = int(input())


def prime_factorize(n):
    map = {}
    while n % 2 == 0:
        if 2 in map:
            map[2]+=1
        else:
            map[2]=1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f in map:
                map[f]+=1
            else:
                map[f]=1
            n //= f
        else:
            f += 2
    if n != 1:
        if n in map:
            map[n]+=1
        else:
            map[n]=1
    return map

map = prime_factorize(n)

count = 0
for key in map:
    k = 1
    while map[key] >= k:
        map[key]-=k
        count+=1
        k+=1
print(count)

Measured memory_bytes: 9232
import java.util.Scanner;

public class Main {
    static int SumOfDegits(int n) {
        int sum = 0;
        while(n > 0) {
            sum += n%10;
            n /= 10;
        }
        return sum;
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int sum = 0;
        for (int i = 1; i <= N; i++) {
            int digitsSum = SumOfDegits(i);
            if(digitsSum >= A && digitsSum <= B) {
                sum+=i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
# coding: utf-8
N = int(input())
ans = 1

robot_list = []
for i in range(N):
    x, l = map(int,input().split())
    s = x - l
    t = x + l
    robot_list.append([s, t])

robot_list.sort(key=lambda x:x[1])
#print(robot_list)
c = robot_list[0][1]

for i in range(1,N):
    if robot_list[i][0] >= c:
        ans += 1
        c = robot_list[i][1]
print(ans)

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

int main() {
  string s,t;
  int a,b;
  string u;
  cin >> s >> t >> a >> b >> u;
  if(u==s) cout << a-1 << " " << b << endl;
  else cout << a <<" " << b-1 << endl;
  
}

Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))
arrC = list(map(int,input().split()))

arrC = [0] + arrC

ans = 0
for i,dishnum in enumerate(arrA):
    if i == 0:
        ans += arrB[dishnum-1]
    else:
        ans += arrB[dishnum-1]
        if arrA[i] == arrA[i-1]+1:
            ans += arrC[dishnum-1]

print(ans)
# print("{:.10f}".format(ans))


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
	char s[102];
	scanf("%s", s);
	int i, n = strlen(s);
	int c = 0;
	for (i = 0; i < n; i++)
		if (s[i] != s[n - i - 1])
			c++;
	for (i = 0; i < n / 2; i++)
		if (s[i] != s[n / 2 - i - 1])
			c++;
	for (i = (n + 1) / 2; i < n; i++)
		if (s[i] != s[n - i + (n + 1) / 2 - 1])
			c++;
	if (c == 0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
import sys
input=sys.stdin.readline

class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rnk=[0]*(n+1)

    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

uf=UnionFind(n)
for _ in range(m):
    x,y,z=map(int,input().split())
    x-=1
    y-=1
    uf.Unite(x,y)
r=[0]*n
for i in range(n):
    r[i]=uf.Find_Root(i)
s=set(r)
print(len(s))


Measured memory_bytes: 75864
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int t = scan.nextInt();
        int a = scan.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = scan.nextInt();
        }
        double min = Integer.MAX_VALUE;
        int ans = 0;
        for (int i = 0; i < n; i++) {
          double tem = (t-(h[i] * 0.006));
          if (min > Math.abs(tem - a)) {
              min = Math.abs(tem - a);
              ans = i+1;
          }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24532
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for j in range(m)]

limit = 60

vis = [False]*(n+2)
graph = [[False for i in range(n+2)] for j in range(n+2)]

def dfs(x):
    vis[x] = True
    for i in range(1,n+1):
        if graph[x][i] == False:
            continue
        if vis[i] == True:
            continue
        #print(i)
        dfs(i)

for i in range(m):
    graph[ab[i][0]][ab[i][1]] = True
    graph[ab[i][1]][ab[i][0]] = True

bridge = 0

ans = 0

for i in range(m):
    vis = [False]*(n+2)
    graph[ab[i][0]][ab[i][1]] = False
    graph[ab[i][1]][ab[i][0]] = False
    
    dfs(1)
    #print(vis)
    #exit()
    
    bridge = False
    for j in range(1,n+1):
        if vis[j] == False:
            bridge = True
    if bridge:
        ans += 1
    
    graph[ab[i][0]][ab[i][1]] = True
    graph[ab[i][1]][ab[i][0]] = True

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define endl '\n'

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

    int num_2, num_4, odd;
    num_2 = num_4 = odd = 0;
    for(int i=0; i<n; i++){
        int number;
        cin >> number;

        if(number%4 == 0){
            num_4 ++;
        }else if(number%2 == 0){
            num_2 ++;
        }else{
            odd++;
        }
    }

    if(num_2 == 0){
        if(num_4+1 >= odd){
            cout << "Yes" << endl;
            
        }
        else{
            cout << "No" << endl;
            
        }
    }else{
        if(num_4 >= odd){
            cout << "Yes" << endl;
           
        }else{
            cout << "No" << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::char;

fn main() {
    let s: String = read();
    let cnt = s.chars().filter(|&c| c == 'o').count();
    
    println!("{}",700 + (100 * cnt));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 27 21:13:33 2019

@author: doppe
"""

import math

N = int(input())

if (N == 1):
    print(1)
else:
    max = 1
    for i in range(2, int(math.sqrt(N) + 1)):
        if (N % i == 0):
            max = i
    print(int(max + (N / max) -2))


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

ll dp[51][2501];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, A;
    cin >> N >> A;

    vi X(N);
    REP(i, N) cin >> X[i];

    dp[0][0] = 1;

    FOR(k, 1, N + 1) {
        REVFOR(i, 1, k+1) {
            REP(j, 2501) {
                if (j - X[k-1] > -1) dp[i][j] += dp[i-1][j - X[k-1]];
            }
        }
    }

    ll ans = 0;
    FOR(i, 1, N+1) {
        ans += dp[i][A * i];
    }

    print(ans);
}


Measured memory_bytes: 4536
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define INF 1000000000
#define endl "\n"
#define all(s) s.begin(),s.end()
#define pb push_back
#define uno unordered_map
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define w(zz) int zz; cin>>zz; while(zz--)
#define foreach(var,i) for(auto i = var.begin();i!=var.end();i++)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll power(ll a, ll n) {ll res = 1; while (n) {if (n % 2) {res *= a;} n >>= 1; a *= a;} return res;}
ll powerm(ll a, ll n, ll m) {ll res = 1; while (n) {if (n % 2) {res = (res * a) % m;} n >>= 1; a = (a * a) % m;} return res;}
using namespace std;
int main(){
	fast();
	int n;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll s = 0;
	ll x = a[0];
	for(int i=1;i<n;i++){
		if(a[i]<x){
			s+=(x-a[i]);
		}
		x = max(a[i],x);
	}
	cout<<s<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
int x[125252], y[125252], z[125252];

int dat[125252];
int root(int x){
    return dat[x]<0 ? x : dat[x]=root(dat[x]);
}
void unite(int a, int b){
    a=root(a); b=root(b);
    if(a==b)return;
    dat[a] += dat[b];
    dat[b] = a;
    return;
}

int main(){
    scanf("%d%d",&n,&m);
    REP(i,m)scanf("%d%d%d",x+i,y+i,z+i),x[i]--,y[i]--;
    fill(dat,dat+n,-1);
    REP(i,m)unite(x[i],y[i]);
    int ans = 0;
    REP(i,n)if(root(i)==i)ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string t;
    cin >> s >> t;
    vector <int> a(s.size());
    vector <int> b(t.size());
    for (int i = 0; i < s.size(); ++i){
        if (s[i] == 'A'){
            a[i] = 2;
        }
        else{
            a[i] = 1;
        }
    }
    for (int i = 0; i < t.size(); ++i){
        if (t[i] == 'A'){
            b[i] = 2;
        }
        else{
            b[i] = 1;
        }
    }
    vector <int> pref_a(a.size() + 1);
    vector <int> pref_b(b.size() + 1);
    for (int i = 1; i < pref_a.size(); ++i){
        pref_a[i] = (pref_a[i - 1] + a[i - 1]);
    }
    for (int i = 1; i < pref_b.size(); ++i){
        pref_b[i] = (pref_b[i - 1] + b[i - 1]); 
    }
    int q;
    cin >> q;
    while (q--){
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        l1--,l2--;
        int fir = (pref_a[r1] - pref_a[l1])%3;
        int sec = (pref_b[r2] - pref_b[l2])%3;
        if (sec == fir){
            cout << "YES" << "\n";
        }
        else{
            cout << "NO" << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int len,i,j,cnt=0;

    cin>>s;
    len=s.size();

    for(i=0,j=len-1; i<len/2; i++,j--)
    {
        if(s[i]!=s[j])
            cnt++;
    }

    cout<<cnt<<"\n";
    return 0;

}


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

int main () {
  int a, b, c;
  bool ans = false;
  cin >> a >> b >> c;

  if (a < c) {
    if (c < b) {
      ans = true;
    }
  }else if (a > c) {
    if (c > b) {
      ans = true;
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

	int sum=0;
	for(char c:s) sum+=c-'0';
	cout<<max<int>(sum,(s[0]-'1')+9*(s.length()-1))<<'\n';

	return 0;
}


Measured memory_bytes: 256
s=input()
l=list(s)
lst=[]
# bi=[bin(2**i) for i in range(0,len(s))]
for i in range(1<<(len(s)-1)):
    st=l[0]
    for j in range(len(s)-1):
        if (i>>j)&1:
            st+=l[j+1]
        else:
            st+='+'+l[j+1]
    lst.append(eval(st))
print(sum(lst))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int> a(3);
    for (int i=0;i<3;i++) cin >> a[i];
    sort(a.begin(),a.end());
    if (a[0]==5 && a[1]==5 && a[2]==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * 提出
	 *
	 */

	public static void main(String args[]) {
		Scanner scanner= new Scanner(System.in);
		int a = 0;
		int b = 0;
		int c = 0;
		int count = 0;

		a = scanner.nextInt();
		b = scanner.nextInt();
		c = scanner.nextInt();

		for (int i = a; i <= b; i++) {
			/* 約数の場合 */
			if (c % i == 0) {
				count++;
			}
		}
		System.out.println(count);

	}
}



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

r=N-1
p=-1
for l in reversed(range(N)):
  if A[l]>A[r]:
    r=l
  else:
    if A[r]-A[l]==p:
      ans+=1
    elif A[r]-A[l]>p:
      ans=1
      p=A[r]-A[l]
      
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define gettime printf("\nTime : %0.3lf\n",clock()*1.0/CLOCKS_PER_SEC);
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define Set(x,a) memset(x,a,sizeof(x));

#define vs vector<string>
#define vi vector<int>
#define ll long long
#define ff first
#define ss second

struct comp {
       bool operator() (int a,int b) {
            return a>b;
       }
};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    ll a, b;
    cin>>a>>b;
    if (a % b == 0) {
        cout<<"-1"<<endl;
    }
    else {
        ll ans = a * 2;
        while (ans % b == 0) {
            ans += a;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,s;
int flg[101] = {};
long long ans;
int count;
int dp[11][1001][101];
long long test;

void saiki(int sum,int mae,int kai) {
  count ++;
  if(kai == n && sum == s) ans++,dp[kai][sum][mae]++;
  if(kai == n && sum != s) dp[kai][sum][mae] = -1;
  //  if(kai == n) cout <<"kai="<< kai<<" sum="<< sum <<" mae="<< mae <<" result="<<dp[kai][sum][mae]<< endl;
  					 
  if(kai < n && sum <= s) {
    for(int i=0;i<=100;i++){
      if(flg[i] == 0 && mae < i && sum+i <= s) {
	if(dp[kai+1][sum+i][i] == -1) continue;
	else if(dp[kai+1][sum+i][i] > 0) {
	  ans += dp[kai+1][sum+i][i];
	  dp[kai][sum][mae] += dp[kai+1][sum+i][i];
	  continue;
	  } 
	flg[i] = 1;
	saiki(sum+i,i,kai+1);
	flg[i] = 0;
	if(kai == 0 && dp[kai+1][sum+i][i] > 0) test+=dp[kai+1][sum+i][i];
	if(dp[kai+1][sum+i][i] >= 1) dp[kai][sum][mae]+=dp[kai+1][sum+i][i];
	//cout <<"kai="<< kai<<" sum="<< sum <<" i="<< i <<" result="<<dp[kai+1][sum+i][i]<< endl;
      }
      
    }
    if(dp[kai][sum][mae] == 0) dp[kai][sum][mae] = -1;
    
  }
  
}


int main() {


    while(1) {
    cin >> n >>s;
    if(n == 0 && s == 0) break;

    for(int i=0;i<=n;i++) 
      for(int j=0;j<=s;j++)
	for(int k=0;k<=100;k++)
	dp[i][j][k] = 0;
    for(int i=0;i<=100;i++) flg[i] = 0;
    
    ans = 0;
    count = 0;
    test = 0;
    saiki(0,-1,0);
    //cout << ans << endl;
    //cout <<count << endl;
    cout << test << endl;
    }
  
    return 0;
}

Measured memory_bytes: 5080
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

R, C, K = map(int, readline().split())

V = [[0]*(C+1) for _ in range(R+1)]
for i in range(K):
    r,c,v = map(int,readline().split())
    V[r][c] = v

dp = [0] * (C+1)
dp[0] = 0

for i in range(1,R+1):
    ndp = [0] * (C+1)
    row = V[i]
    ldp = [0] * 4
    for j in range(1,C+1):
        # ldp[0] = max(ldp[0], dp[j])
        ldp[0] = dp[j]
        for k in range(2,-1,-1):
            ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合
        ndp[j] = max(ldp)
    dp = ndp
print(dp[C])

Measured memory_bytes: 154724
N,K=map(int,input().split())
S=input()

len_ch=0
for i in range(1,N):
  if S[i-1]!=S[i]:
    len_ch+=1

if len_ch>2*K:
  print(N-1-len_ch+2*K)
else:
  print(N-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b;
	cin >> a >> b;

	int x = a/0.08;
	int y = b/0.1;
	int max = x > y ? x : y;
	int min = x > y ? y : x;
	int poss = -1;
	for (int i = 0; i <= 100000; ++i)
	{
		if ((int)(i*0.08) == a && (int)(i*0.1) == b )
			poss = i;
		if (poss != -1)
			break;
		
	}
	cout << poss << endl;

	return 0;
}

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


int main() {

    int x;
    cin >> x;
    int ans = 1;
    for (int b = 2; b <= x; ++b) {
        int v = b * b;
        while (v <= x) {
            ans = max(ans, v);
            v *= b;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    idx = [0] * N
    D = [[-1] * (N) for _ in range(N)]
    for j in range(N):
        D[j][0] = 0
    while True:
        f = True
        for i in range(N):
            if idx[i] >= N - 1: continue
            m = A[i][idx[i]]
            if A[m][idx[m]] == i:
                d = max(D[i][idx[i]], D[m][idx[m]])
                idx[i] += 1
                idx[m] += 1
                D[i][idx[i]] = d + 1
                D[m][idx[m]] = d + 1
                f = False
        if f: break
    ans = -1
    for i in range(N):
        ans = max(ans, D[i][N - 1])
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    A = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(N)]
    main(N, A)


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

int absolute(int a) {
  if (a >= 0) return a;
  else return -a;
}

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  
  if (x1 == x2) {
    int d;
    d = y2 - y1;
    x3 = x2 - d;
    y3 = y2;
    x4 = x3;
    y4 = y1;
    
  } else {
    int dx = absolute(x2 - x1);
    int dy = absolute(y2 - y1);
    int pn = (x2 - x1) * (y2 - y1);
    if (pn >= 0) {
      if (x1 <= x2) {
        x3 = x2 - dy;
        y3 = y2 + dx;
        x4 = x1 - dy;
        y4 = y1 + dx;
      } else {
        x3 = x2 + dy;
        y3 = y2 - dx;
        x4 = x1 + dy;
        y4 = y1 - dx;
      }
    } else {
      if (x1 <= x2) {
        x3 = x2 + dy;
        y3 = y2 + dx;
        x4 = x1 + dy;
        y4 = y1 + dx;
      } else {
        x3 = x2 - dy;
        y3 = y2 - dx;
        x4 = x1 - dy;
        y4 = y1 - dx;
      }
    }
  }
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    i = 0
    for _ in range(n):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            i += 1
            if i >= 3:
                print("Yes")
                return
        else:
            i = 0
    print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9168
S_ = input()
T = input()
ans = list(S_)


def check(S1, S2):
    for i in range(len(S1)):
        if S1[i] == S2[i] or S1[i] == "?":
            continue
        else:
            return(False)

    return(True)


for i in reversed(range(len(S_) - len(T) + 1)):
    result = check(S_[i:i+len(T)], T)
    if result:
        for j in range(len(T)):
            ans[i+j] = T[j]
        for j in range(len(ans)):
            if ans[j] == "?":
                ans[j] = "a"
        print("".join(ans))

        exit(0)

print("UNRESTORABLE")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
//ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;

ll gcd(ll n,ll m)
{
    if(m==0) return n;
    return gcd(m,n%m);
}

int main(void)
{
    double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            a=gcd(i,j);
            if(a==1) sum+=n;
            else if(a==2)
            {
                sum+=a*(n/2);
                sum+=n-n/2;
            }
            else if(a==3)
            {
                sum+=a*(n/3);
                sum+=n-n/3;

            }
            else
            {
                for(k=1;k<=n;k++)
                    sum+=gcd(a,k);
            }
        }
    }
    cout<<sum;
    return 0;
}





Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 2e5;
ll a,b;
ll fac[N];

void init() {
	fac[1] = 1;
	for(int i=2;i<=100000;i++) {
		fac[i] = (fac[i-1] * i) % mod;
	}
}

int main(int argc, char** argv) {
	init();
	cin>>a>>b;
	if(abs(a-b) >= 2) {
		cout<<0<<endl;
		return 0;
	}
	
	if(a - b) {
		cout<<(fac[a] * fac[b]) % mod <<endl;
	}else {
		cout<<((fac[a] * fac[b]) % mod) * 2 % mod <<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int x[10000],y[10000],a=0,i;
	while(1){
		scanf("%d %d",&x[a],&y[a]);
		if(x[a]==0&&y[a]==0)
			break;
		if(x[a]>y[a]){
			i=x[a];
			x[a]=y[a];
			y[a]=i;
		}
		a++;
	}
	for(i=0;i<a;i++)
		printf("%d %d\n",x[i],y[i]);
	return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int ret=0,n,t;
	cin >> n >> t;
	vector<int> v(100001,INT_MAX/2);
	v[0]=0;
	for (int i=0; i<n; ++i){
		int w,val;
		cin >> w >> val;
		for (int k=100000-val; k>=0; --k){
			if (v[k]+w < v[k+val]) v[k+val] = v[k]+w;
		}
	}
	for (int i=0; i<=100000; ++i){
		if (v[i] > 0 and v[i] <= t) ret=i;
	}
	cout << ret;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    ll N;
    ll a[5],k,sum = 0;
    ll cnt = 1;
    bool f;
    cin >> N;
    vector<ll> H(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    for(int i = 1; i < N; i++){ 
        f= true;
        for(int j = 0; j < i; j++){
            if(H[j] > H[i])f = false;
        } 
        if(f)cnt++;
    }
    cout << cnt << endl;   
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N, A, B;
vint flow1 = {0, 1, 3, 2, 2, 0, 1, 3}, flow2 = {3, 2, 0, 1, 1, 0, 2, 3};

signed main() {
    cin >> N >> A >> B;
    int cnt = 0;
    for (int i = 0; i < N; i++)if ((A & (1 << i)) != (B & (1 << i)))cnt++;
    if ((cnt & 1) == 0) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    int n = N - cnt + 1;
    vint vec;
    for (int i = 0; i < (1 << n); i++)vec.push_back(i ^ (i >> 1));
    for (int i = 0; i < (cnt - 1) / 2; i++) {
        vint nvec(vec);
        vec.clear();
        int j = 0;
        for (; j < 4; j++)vec.push_back(nvec[0] + (flow1[j] << (N - cnt + 1 + 2 * i)));
        for (; j < 8; j++)vec.push_back(nvec[1] + (flow1[j] << (N - cnt + 1 + 2 * i)));
        for (; j < nvec.size() * 4; j++) vec.push_back(nvec[j / 4] + (flow2[j % 8] << (N - cnt + 1 + 2 * i)));
    }

    for (int i = 0; i < vec.size(); i++) {
        int a = A;
        bitset<22> bs(vec[i]);
        int x = N - cnt, y = 0;
        for (int j = 0; j < N; j++) {
            if ((A & (1 << j)) != (B & (1 << j))) {
                a ^= bs[x] << j;
                x++;
            } else {
                a ^= bs[y] << j;
                y++;
            }
        }
        cout << a << endl;
    }
}


Measured memory_bytes: 2160
import java.util.List;
import java.util.Scanner;

public class Main {

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

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

		int N = sc.nextInt();

		//始点から出て、始点に戻ってこないといけないのでA[0]とA[N+1]の分、2コ多く確保する。
		int[] A=new int[N+2];

		//始点兼終点は位置0
		A[0]=A[N+1]=0;

		//A[1]～A[N]まで入力を受け取る
		for (int i = 1; i < N+1; i++) {
			A[i]=sc.nextInt();
		}

		//まずは全点の総和をとっておき、各点については計算しておいた総和のとの差を考える
		//ことで計算量を省略する。
		
		int sum=0;
		for (int i = 1; i < N+2; i++) {
			sum+=Math.abs(A[i]-A[i-1]);
		}

		//↑と変わるのは点iの周りだけ
		//具体的にはi-1→i→i+1がなくなり、新しくi-1→i+1へ経路ができる。
		
		for (int i = 1; i < N+1; i++) {

			int ans=sum-Math.abs(A[i-1]-A[i])-Math.abs(A[i]-A[i+1])+Math.abs(A[i-1]-A[i+1]);

			System.out.println(ans);
		}


	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 65636
from collections import Counter
N = int(input())
# A = [0]*(N+1)
counter = Counter()
until = int((N**0.5)+1)

for x in range(1, until):
    for y in range(1, until):
        for z in range(1, until):
            tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            counter[tmp] += 1
for i in range(1, N+1):
    print(counter[i])

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

int main(){
	int N;
	cin >> N;
	vector<bool>array(INF,0);
	ll a;
	string ans = "YES";
	for(int i = 0; i< N;i++){
		cin >> a;
		if(array[a] == 1){
			ans = "NO";
			break;
		}else{
			array[a] =1;
		}
	}
	cout << ans << endl;

	return 0;
}

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

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

struct edge {
    int to, cost;
};
int V;
vector<edge> G[MAX_V];
vector<bool> is_leaf(MAX_N, false);
int d_takahashi[MAX_V];
int d_aoki[MAX_V];

void dijkstra_takahashi(int s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする。
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d_takahashi, d_takahashi + V, INF);
    d_takahashi[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d_takahashi[v] < p.first) continue;
        for (int i = 0; i < (int)G[v].size(); i++) {
            edge e = G[v][i];
            if (d_takahashi[e.to] > d_takahashi[v] + e.cost) {
                d_takahashi[e.to] = d_takahashi[v] + e.cost;
                que.push(P(d_takahashi[e.to], e.to));
            }
        }
    }
}

void dijkstra_aoki(int s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする。
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d_aoki, d_aoki + V, INF);
    d_aoki[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d_aoki[v] < p.first) continue;
        for (int i = 0; i < (int)G[v].size(); i++) {
            edge e = G[v][i];
            if (d_aoki[e.to] > d_aoki[v] + e.cost) {
                d_aoki[e.to] = d_aoki[v] + e.cost;
                que.push(P(d_aoki[e.to], e.to));
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    V = n;
    int takahashi, aoki;
    cin >> takahashi >> aoki;
    takahashi--;
    aoki--;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(edge{b, 1});
        G[b].push_back(edge{a, 1});
    }
    rep(i, n) {
        if (G[i].size() == 1) is_leaf[i] = true;
    }
    dijkstra_takahashi(takahashi);
    dijkstra_aoki(aoki);
    int m = 0;
    rep(i, n) {
        if (is_leaf[i] && (d_takahashi[i] < d_aoki[i])) {
            if (m < d_aoki[i] - 1) {
                m = d_aoki[i] - 1;
            }
        }
    }
    cout << m << endl;
}


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

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

    int bunbo = n;
    double bunshi;
    if (bunbo % 2 == 1) bunshi = (double) (n-1)/2 + 1;
    else if (bunbo % 2 == 0) bunshi = (double) n/2;

    cout << fixed << setprecision(15) << bunshi / bunbo << endl;

    return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


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

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

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n 
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}

int main() {
    ll N, W;
    cin >> N >> W;

    vector<ll> w(N+1), v(N+1);
    for(ll i = 1; i <=N ;i++) {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    for(ll i = 0; i <= W; i++) dp[0][i] = 0;
    for(ll i = 0; i <= N; i++) dp[i][0] = 0;
    for(ll n = 1; n <= N; n++) {
        for(ll j = 1; j <= W; j++) {
            if(j-w[n] < 0) dp[n][j] = dp[n-1][j];
            else dp[n][j] = max(dp[n-1][j], v[n] + dp[n-1][j-w[n]]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;


    
}



Measured memory_bytes: 80256
N,K=map(int,input().split())

alist=[]
max_a=0
for _ in range(N):
  a=int(input())
  alist.append(a)
  max_a=max(max_a,a)
#print(alist)

class SegTree:
  #init(init_val, ide_ele): 配列init_valで初期化 O(N)
  def __init__(self, init_val, segfunc, ide_ele):
    #init_val: 配列の初期値
    #segfunc: 区間にしたい操作
    #ide_ele: 単位元
    #n: 要素数
    #num: n以上の最小の2のべき乗
    #tree: セグメント木(1-index)
    n = len(init_val)
    self.segfunc = segfunc
    self.ide_ele = ide_ele
    self.num = 1 << (n - 1).bit_length()
    self.tree = [ide_ele] * 2 * self.num
    # 配列の値を葉にセット
    for i in range(n):
      self.tree[self.num + i] = init_val[i]
    # 構築していく
    for i in range(self.num - 1, 0, -1):
      self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

  #update(k, x): k番目の値をxに更新 O(logN)
  def update(self, k, x):
    #k番目の値をxに更新
    #k: index(0-index)
    #x: update value
    k += self.num
    self.tree[k] = x
    while k > 1:
      self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
      k >>= 1

  #query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
  def query(self, l, r):
    #[l, r)のsegfuncしたものを得る
    #l: index(0-index)
    #r: index(0-index)
    res = self.ide_ele
    l += self.num
    r += self.num
    while l < r:
      if l & 1:
        res = self.segfunc(res, self.tree[l])
        l += 1
      if r & 1:
        res = self.segfunc(res, self.tree[r - 1])
      l >>= 1
      r >>= 1
    return res

#segfunc
def segfunc(x,y):
  return max(x,y) #最大値
#ide_ele
ide_ele=-float("inf") #最大値

#初期化
seg=SegTree([0]*(max_a+1), segfunc, ide_ele)
for i in range(N):
  a=alist[i]
  l=max(0,a-K)
  r=min(max_a,a+K)
  
  max_range=seg.query(l,r+1)
  seg.update(a,max_range+1)
  
print(seg.query(0,max_a+1))

Measured memory_bytes: 110480
n = int(input())
L = list(map(int,input().split()))

def gcd(x,y):
    if y > x:
        x,y = y,x
    if x%y == 0:
        return y
    else:
        return gcd(y,x%y)
        
from functools import reduce
ans = reduce(gcd,L)
print(ans)

Measured memory_bytes: 19936
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#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) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int>a(N); rep(i, 0, N)cin >> a[i];

	int x(0), sum(0),y(0);
	rep(i, 0, N) {
		sum += a[i];
		if (i & 1 && sum >= 0) {
			x += abs(sum) + 1;
			sum = -1;
		}
		else if (!(i & 1) && sum <= 0) {
			x += abs(sum) + 1;
			sum = 1;
		}
	}
	sum = 0;
	rep(i, 0, N) {
		sum += a[i];
		if (i & 1 && sum <= 0) {
			y += abs(sum) + 1;
			sum = 1;
		}
		else if (!(i & 1) && sum >= 0) {
			y += abs(sum)+ 1;
			sum = -1;
		}
	}
	dump(x, y);
	cout << min(x, y) << endl;
	return 0;
}

Measured memory_bytes: 1024
// Vivek Rai
// Blazer_007

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

#define fastio 		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf         0x3f3f3f3f
//#define INF         0x3f3f3f3f3f3f3f3fLL
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define ppi	        pair<ll,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define see(x)	    cout<<x<<endl;
#define see2(x,y)   cout<<x<<" "<<y<<endl;
#define see3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define bit(x, y)   (((x)>>(y))&1)
#define bpt(x)      (__builtin_popcount(x))
#define bptl(x)     (__builtin_popcountll(x))
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define N 2000010

using namespace std;
//using namespace __gnu_pbds;

//typedef priority_queue<int> maxHeap;
//typedef priority_queue<int,vector<int>,greater<int>()) minHeap;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// find_by_order(index) -> value at given index or Kth smallest element in set
// order_of_key(X) -> number of elements strictly less than X
//typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

struct item{
    int wt;
    int val;
};

ll solve(vector<item> ar,int n,int W){
    ll dp[n+1][W+1];
    //Base Case
    loop(w,0,W+1)
        dp[1][w] = 0;
    dp[1][ar[1].wt] = ar[1].val;

    loop(i,2,n+1){
        loop(w,0,W+1){
            dp[i][w] = dp[i-1][w];
            if(ar[i].wt > w)
                continue;
            dp[i][w] = max(dp[i][w],ar[i].val+dp[i-1][w-ar[i].wt]);
        }
    }
    return *max_element(dp[n],dp[n]+W+1);
}

void solution(){
    int n,w;
    cin >> n >> w;
    vector<item> ar(n+1);
    loop(i,1,n+1){
        cin >> ar[i].wt >> ar[i].val ;
    }
    cout << solve(ar,n,w) << endl;
}

signed main(){
    fastio
    // #ifndef ONLINE_JUDGE
    // 	freopen("input.txt", "r" , stdin);
    // 	freopen("output.txt", "w", stdout);
    // #endif

    ll t=1;
    // cin>>t;
    loop(i,1,t+1){
    	//cout<<"Case #"<<i<<": ";
    	solution();
    }
}




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

int main(){
	int t, n;
	while( cin >> t ){
		if( t == 0 ) break;
		
		cin >> n;
		for(int i=0 ; i < n ; i++ ){
			int s, f;
			cin >> s >> f;
			t -= f - s;
		}
		if( t <= 0 ){
			cout << "OK" << endl;
		}else{
			cout << t << endl;
		}
	}
}

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

using namespace std;

#define int long long

signed main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    for(int i=0;i<n;++i){
        cin>>b[i];
    }
    for(int i=0;i<n;++i){
        cin>>c[i];
    }
    int ans=0;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i=0;i<n;++i){
        auto it=c.end()-upper_bound(c.begin(),c.end(),b[i]);
        auto it2=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        ans+=it*it2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int MAX_N=100;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans=1LL;
    rep(i,n){
        ll t;
        cin >> t;
        ans=lcm(ans,t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//カントリーロード
#include <algorithm>
#include <iostream>
using namespace std;
int T, N, K, X[100000+10], A[100000+10];
int main() {
 cin >> T;
 for (int t=0; t<T; ++t) {
  cin >> N >> K;
  for (int i=0; i<N; ++i) cin >> X[i];
  for (int i=0; i+1<N; ++i) A[i]=X[i+1]-X[i];
  sort(A,A+N-1);
  int sum = 0;
  for (int i=0; i<N-K; ++i) sum += A[i];
  cout << sum << endl;
 }
}


Measured memory_bytes: 1960
<?php

function input_and_explode() {
    $input_line = trim(fgets(STDIN));
    return explode(" ", $input_line);
}

$S = input_and_explode()[0];
$S = str_split($S);
list($cond_1, $cond_2, $cond_3) = array(false, false, false);
$count_C = 0;
$count_small = 0;

if ($S[0] === 'A') {
    $cond_1 = true;
}

if (in_array('C', array_slice($S, 2, count($S) - 3))) {
    $cond_2 = true;
}

for ($i = 0, $len = count($S); $i < $len; $i++) {
    if (ctype_lower($S[$i])) {
        $count_small++;
    }
}

if ($count_small === count($S) - 2) {
    $cond_3 = true;
}

if ($cond_1 && $cond_2 && $cond_3) {
    $state = 'AC';
} else {
    $state = 'WA';
}

echo "$state\n";

Measured memory_bytes: 4728
program prob19
    implicit none
    integer :: s
    read(*,*) s
    s = mod(s,10)

    select case(s)
    case(3)
        write(*,'(a)') "bon"
    case(2,4,5,7,9)
        write(*,'(a)') "hon"
    case default
       write(*,'(a)') "pon"
    end select



    stop
contains
end program prob19

Measured memory_bytes: 2864