akhauriyash/Code-Regression huggingface dataset:
# D
n = int(input())
y = list(map(int, input().split()))
for i,num in enumerate(y):
    if i % 2 == 1:
        y[i] = -y[i]

a2=[0]
for i in y:a2.append(a2[-1]+i)
def SumArea(r, l):
    return a2[l]-a2[r]
    
ans = [0 for i in range(n)]
for i in range(n):
    count=0
    if i % 2 == 1:
        count -= SumArea(i, n)
        count += SumArea(0, i)
    else:
        count += SumArea(i, n)
        count -= SumArea(0, i)
    ans[i] = count
print(*ans, sep=' ')

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

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

bool is_prime(ll x){
    if(x==1) return false;
    for(ll i=2; i*i<=x;i++){
        if(x%i == 0) return false;
    }
    return true;
}

ll f(ll n){
    if(n==1) return 1;
    return (n)*f(n-1);
}

int main(){
    fast_io
    
    int n, a, b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int cnt=0;
    int foreign=0;

    rep(i,n){
        if(s[i]=='a'){
            if(cnt<a+b){
                cout<<"Yes"<<endl;
                cnt++;
            }
            else cout<<"No"<<endl;
        }
        else if(s[i]=='b'){
            if(cnt<a+b && foreign<b){
                cout<<"Yes"<<endl;
                cnt++;
                foreign++;
            }else cout<<"No"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }

    
    return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int n, l;
    cin >> n >> l;

    Int min = pow(10, 9);
    Int sum = 0;
    for(Int i=1; i<=n; i++){
        sum += l+i-1;
    }
    for(Int i=1; i<=n; i++){
        if(abs(l+i-1) < abs(min)){
            min = l+i-1;
        }
    }
    cout << sum-min << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let s_len = s.len() as i64;
    let t = read::<String>().chars().collect::<Vec<_>>();

    let mut poses = vec![vec![]; 26];

    for (i, ch) in s.into_iter().enumerate() {
        poses[ch.to_digit(36).unwrap() as usize - 10].push(i);
    }

    let mut ans = 0;
    let mut cur_pos = 0;
    for ch in t {
        let ch = ch.to_digit(36).unwrap() as usize - 10;
        let idx = poses[ch].lower_bound(&cur_pos);
        if idx == poses[ch].len() {
            cur_pos = 0;
            ans += s_len;
            let idx = poses[ch].lower_bound(&cur_pos);
            if idx == poses[ch].len() {
                println!("-1");
                return;
            }
            cur_pos = poses[ch][idx] + 1;
        } else {
            cur_pos = poses[ch][idx] + 1;
        }
    }
    println!("{}", ans + cur_pos as i64);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


Measured memory_bytes: 4008
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int n,m;
bool path[8][8];
int ans=0;

void dfs(int num,vi vec){
	vi tmp=vec;
	tmp.push_back(num);
	sort(ALL(tmp));
	if(tmp.size()==n){
		ans++;
		return;
	}
	REP(i,n){
		if(path[num][i]){
			if(!binary_search(ALL(tmp),i)) dfs(i,tmp);
		}
	}
}

int main(){
	cin>>n>>m;
	
	REP(i,8)REP(j,8) path[i][j]=false;
	REP(i,m){
		int a,b;
		cin>>a>>b;
		path[a-1][b-1]=path[b-1][a-1]=true;
	}
	
	vi v;
	dfs(0,v);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
s=input() 
n=len(s)
cnt=0
temp=[0]*n
JinA=[] 
for i in range(n-1):
    if s[i]=="A":
        if i>0:
            temp[i]+=temp[i-1]+1 
        else:
            temp[i]+=1
    if s[i]=="B" and s[i+1]=="C" and i>0:
        temp[i+1]+=temp[i-1]
        cnt+=temp[i-1] 

print(cnt)

Measured memory_bytes: 11240
# N, M = gets.chomp.split.map(&:to_i)
# T = gets.chomp.chars
N = gets.chomp.to_i
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
D = gets.chomp.to_i
E = gets.chomp.to_i

min = [A, B, C, D, E].min
additional = (N + min - 1)/min - 1
p 5 + additional

Measured memory_bytes: 1788
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    int[] s, t;
    int i, j, c, l, r, a;

    n = sc.nextInt();
    s = new int[n];
    for(i = 0;i < n;i++){
      s[i] = sc.nextInt();
    }
    q = sc.nextInt();
    t = new int[q];
    for(i = 0;i < q;i++){
      t[i] = sc.nextInt();
    }

    c = 0;
    for(i = 0;i < q;i++){
      l = 0;
      r = n - 1;
      for(;l <= r;){
        a = (l + r) / 2;
        if(t[i] > s[a]){
          l = a + 1;
        }else if(t[i] < s[a]){
          r = a - 1;
        }else{
          c++;
          break;
        }
      }
    }

    System.out.println(c);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{
    gearup;
    int h,w,k; cin >> h >> w >> k;
    vvl dp(h+10,vl(w+10));
    dp[0][0] = 1; //dp[i][j]: iまでの高さでjに行く通り
    rep(i,h){
        rep(j,w){
            rep(bit,1<<(w-1)){ //w-1のbit全探索
                bool check_bit = true;
                rep(bi,w-2){
                    if( ((bit >> bi) & 1) && ((bit >> (bi+1)) & 1)) check_bit = false;
                }
                if(check_bit == false)continue;
                int next = j;
                if( (bit >> j) & 1)next++;
                else if( j > 0 && (bit >> (j-1)) & 1)next--;
                dp[i+1][next] += dp[i][j];
                dp[i+1][next] %= MOD;
            }
        }
    }
    out(dp[h][k-1]);
}


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

class dice {
    public:
        int top, front, right, left, back, bottom;
        dice(int a, int b, int c, int d, int e, int f) {
            top = a; front = b;
            right = c; left = d;
            back = e; bottom = f;
        }
        int tp() {
            return top;
        }
        void E() {
            int tmp = top;
            top = left;
            left = bottom;
            bottom = right;
            right = tmp;
        }
        void N() {
            int tmp = top;
            top = front;
            front = bottom;
            bottom = back;
            back = tmp;
        }
        void R() {
            int tmp = front;
            front = left;
            left = back;
            back = right;
            right = tmp;
        }
};

bool cp(dice d1, dice d2) {
    string s = "NNNNRNNNNRNNNNRNNNNRENNNNRNNNNRNNNNRNNNNRENNNNRNNNNRNNNNRNNNNRENNNNRNNNNRNNNNRNNNNRE";
    for (int i = 0; i < s.size(); i++) {
        if (d1.top == d2.top && d1.front == d2.front && d1.right == d2.right && d1.left == d2.left && d1.back == d2.back && d1.bottom == d2.bottom)
            return true;
        switch (s[i]) {
            case 'E': d2.E(); 
            case 'N': d2.N();
            case 'R': d2.R();
        }
    }
    return false;
}

int main() {
    int a, b, c, d, e, f, n;
    cin >> n;
    cin >> a >> b >> c >> d >> e >> f;
    dice d1(a, b, c, d, e, f);
    for (int ct = 0; ct < n - 1; ct++) {
        cin >> a >> b >> c >> d >> e >> f;
        dice d2(a, b, c, d, e, f);
        if (cp(d1, d2)) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, k;
  cin >> n >> k;

  ll ans = k;
  rep(i, 0, n-1) ans *= (k-1);
  cout << ans << endl;
  return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    rep(i,b){
        if((a*i)%b==c){
            cout << "YES" << endl;
            return 0;
        }
    }
    
    cout << "NO" <<endl;
    return 0;
}



Measured memory_bytes: 256
/*;

THE BEST IS YET TO COME

*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i, s, l) for (int i = s; i >= l; i--)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<int, int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define vi vector<int>
#define vip vector<pair<int, int>>
#define endl "\n"
#define ln length()
#define sz size()
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
vi g[100005];
vi dp(100005),vis(100005);

void dfs(int s)
{
    vis[s] = 1;
    for(auto i = g[s].begin(); i!=g[s].end(); i++)
    {
        if(!vis[*i])
        dfs(*i);
        dp[s] = max(dp[s],1+dp[*i]);
    }
}
signed main()
{

    fast();
    int n,m;
    cin>>n>>m;

    r(i,0,m)
    {
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
    }
    
    r(i,1,n+1)
    {
        if(!vis[i])
        dfs(i);
    }
    
    int ans = -1;
    r(i,1,n+1)
    ans = max(ans,dp[i]);

    cout<<ans;



    return 0;
}


Measured memory_bytes: 12436
import sys
import itertools
import copy
ORG=map(int, sys.stdin.readline().split())
K=int(sys.stdin.readline().strip())
L=list( itertools.product(range(3), repeat=K) )

for l in L:
    ABC=copy.deepcopy(ORG)
    for x in l:
        ABC[x]*=2
    if ABC[0]<ABC[1]<ABC[2]:
        print "Yes"
        quit()
else:
    print "No"


Measured memory_bytes: 73956
#include <stdio.h>

int main(void) {
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x>0&&y>0&&x+r<=W&&y+r<=H){
  printf("Yes\n");
 }
  else{
  printf("No\n");
 }
  return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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



int main(){
    ll h,w;
    cin >> h >> w;
    ll ans = 0;
    if(h == 1 or w == 1){
        ans = 1;
    }
    else if(h%2 == 1 and w%2 == 1){
        ans = (h+1)/2 * (w+1)/2 + ((h+1)/2-1) * ((w+1)/2-1);
    }
    else if(h % 2 == 0){
        ans = h/2 * w;
    }
    else
    {
        ans = w/2 * h;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;

int main(){

    int n,h;
    cin >> n >> h;

    vector<int> a;
    vector<int> b;

    rep(i,n){
        int tmpa,tmpb;
        cin >> tmpa >> tmpb;

        a.pback(tmpa);
        b.pback(tmpb);
    }

    sort(ALL(a));
    sort(ALL(b));

    int maxa = a[n - 1];

    int ans = divceil(h,maxa);
    int tmph = h;

    rep(i,n){
        tmph -= b[n - 1 - i];
        if(tmph >= 0){
            ans = min(ans, (i + 1) + divceil(tmph, maxa));
        }else{
            ans = min(ans, (i + 1));
            break;
        }
    }

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


Measured memory_bytes: 1276
import java.util.Scanner;

/**
 * @author subaru
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int answer = 0;
        answer += A > B ? A-- : B--;
        answer += A > B ? A : B;
        System.out.println(answer);
    }
}


Measured memory_bytes: 21588
N = int(input())
d={'AC':0,'WA':0,'TLE':0,'RE':0}
for _ in range(N):
    d[input()]+=1
print("AC x "+str(d['AC']))
print("WA x "+str(d['WA']))
print("TLE x "+str(d['TLE']))
print("RE x "+str(d['RE']))

Measured memory_bytes: 9200
/*|In The Name of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e3+5;

int n;

int main(){
    cin >> n;
    vector < int > x;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        x.push_back(a);
    }
    sort(x.begin() , x.end());
    int sm = 0;
    for(int i = 0; i < n-1; i++){
       sm += x[i];
    }
    if(x[n - 1] < sm){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class prog{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int ans = 0;
    for(int i = 0; ; i++){
      if(Math.Pow(2, i) <= N) ans = (int)Math.Pow(2, i);
      if(Math.Pow(2, i) > N) break;
    }
    Console.WriteLine(ans);
      
  }
}

Measured memory_bytes: 11092
a_i = []

for i in range(3):
	a_1, b_1 = map(int, input().split())
	a_i.append(a_1)
	a_i.append(b_1)

count1 = a_i.count(1)
count2 = a_i.count(2)
count3 = a_i.count(3)
count4 = a_i.count(4)
if(count1 == 3 or count2 == 3 or count3 == 3 or count4 == 3):
	print("NO")
else:
	print("YES")

Measured memory_bytes: 3064
#include<stdio.h> 
#include<stdlib.h> 
int i;
#define rep(i,l,r) for(i=(l);i<(r);i++)
#define per(i,l,r) for(i=(r);i>(l);i--)
int main(){ 
	int a,b,c;
	scanf("%d",&a);
	if(a%2==1)a+=1;
	int ans = a/2;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
def main():
	n = int(input())
	arr = list(map(int , input().split()))
	for i in range(0 , n):
		arr[i]=arr[i]-(i+1)
	ans=0
	md=0
	arr.sort()
	if n%2==0:
		md = (arr[n//2-1]+arr[(n//2)])//2
	else:
		md = arr[n//2]
	for i in range(0,n):
		ans = ans +abs(arr[i]-md)
	print(ans)
if __name__=="__main__":
	main()

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

using namespace std;

int main() {

    int A, B, C, D; cin >> A >> B >> C >> D;
    bool ans  = false;

    while(true) {

        C -= B;
        if(C <= 0) {
            ans = true;
            break;
        }
        A -= D;

        if(A <= 0) {
            ans  = false;
            break;
        }

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

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
    std::vector<int> vec;
    while (true) {
        vec.clear();

        int n;
        std::cin >> n;

        if (n == 0)
            break;
        
        vec.resize(n);
        for (auto&& e : vec)
            std::cin >> e;
        
        std::sort(vec.begin(), vec.end());
        std::cout << std::accumulate(vec.begin() + 1, vec.end() - 1, 0) / (n - 2) << std::endl;
    }
}


Measured memory_bytes: 3052
import math
n = int(input())
a = []
a.append(list(map(int, input().split())))
def gcd(x,y):
  if y == 0:
    return x
  return gcd(y, x % y)

pow_2 = 1
exp = 0
while pow_2 < n:
  pow_2 *= 2
  exp += 1

a[0].extend([0]*(pow_2 - n))
for i in range(1, exp):
  a.append([])
  for j in range(int(pow_2 / math.pow(2, i))):
    a[i].append(gcd(a[i-1][2*j], a[i-1][2*j+1]))

ans = [0]*n
for i in range(n):
  g = 0
  for j in range(0,exp):
    if (i >> j) % 2 == 0:
      bit = 1
    else:
      bit = -1
    g = gcd(a[j][(i>>j)+bit], g)
  ans[i] = g
print(sorted(ans)[n-1])

Measured memory_bytes: 14436
open System

let getMaxLen input =
    let rec inner = function
    | 'A' :: tl
    | 'C' :: tl
    | 'G' :: tl
    | 'T' :: tl -> 1 + (inner tl)
    | _ :: _ -> 0
    | [] -> 0

    let rec outer = function 
    | hd :: tl -> max (inner <| hd :: tl) (outer tl)
    | [] -> 0

    outer <| Seq.toList input

let input = Console.ReadLine()
printfn "%i" <| getMaxLen input


Measured memory_bytes: 14032
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
char a[101][101];
int b[101];
int c[101];

int main() {
	int x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	int xd = x2 - x1;
	int yd =y2 - y1;
	x3 = x2 - yd;
	y3 = y2 + xd;
	x4 = x3 - xd;
	y4 = y3 - yd;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> s(n);
	for (int &x : s)cin >> x;
	int q; cin >> q;
	vector<int> t(q);
	for (int &x : t)cin >> x;

	int cnt = 0;
	int lef;
	int rig;
	int mid;
	rep(i, q) {
		lef = 0;
		rig = n-1;
		while (lef <= rig) {
			mid = (lef + rig) / 2;
			
			if (s[mid] == t[i]) {
				cnt++;
				break;
			}
			else if (t[i] < s[mid]) {
				rig = mid-1;
			}
			else {
				lef = mid + 1;
			}
		}
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3264
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

void initialize(void);
void printBoard(void);
void recursive(int);

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],X[N][N];

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

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=0;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&l,&m);
    X[l][m]=1;
  }

  recursive(0);
  return 0;
}



void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
        if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N){
    printBoard();
    return ;
  }

  for(j=0;j<N;j++){
    if(NOT_FREE==col[j]|| NOT_FREE==dpos[i+j]||NOT_FREE==dneg[i-j+N-1])continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}



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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int sum=0,x=k;
  if(x-a>0){
    sum+=a;
    x-=a;
  }else{
    cout << k << endl;
    return 0;
  }
  if(x-b>0){
    x-=b;
  }else{
    cout << a << endl;
    return 0;
  }
  if(x>0){
    sum-=x;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

string str(ll cur)
{
    string s = "";
    while (cur)
    {
        s += (cur % 10 + '0');
        cur /= 10;
    }
    reverse(s.begin(), s.end());
    return s;
}

int N;

bool good(ll x)
{
    cout << "? " << x << endl;
    string s;
    cin >> s;
    return (s == "Y");
}

int main()
{
    /*
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
*/
    ll cur = 1;
    int ans = 0;
    for (ll it = 0; it < 11; it++)
    {
        if (!good(cur))
        {
            ans = it;
            break;
        }
        else
        {
            cur *= 10;
        }
    }
    if (cur == 1e11)
    {
        ll cur = 1;
        vector <ll> e;
        for (int it = 0; it < 11; it++)
        {
            if (cur != 1)
            {
                e.push_back(cur - 1);
            }
            cur *= 10;
        }
        reverse(e.begin(), e.end());
        for (auto x : e)
        {
            if (!good(x))
            {
                cout << "! " << x + 1 << endl;
                return 0;
            }
        }
        cout << "! " << 1 << endl;
    }
    else
    {
        ll max_num = 1;
        for (int it = 0; it < ans; it++)
        {
            max_num *= 10;
        }
        //N < max_num
        ll min_num = 1;
        for (int it = 0; it < ans - 1; it++)
        {
            min_num *= 10;
        }
        //N >= min_num
        ll l = min_num - 1, r = max_num - 1;
        while (l < r - 1)
        {
            ll m = (l + r) / 2;
            if (good(m * 10))
            {
                r = m;
            }
            else
            {
                l = m;
            }
        }
        cout << "! " << r << endl;
        return 0;
    }
    /*
    for (N = 1; N <= 100; N++)
    {
        int cur = 1;
        for (int it = 1; it < 9; it++)
        {
            cout << good(cur);
            cur *= 10;
        }
        cout << " = " << N << endl;
    }
    */
}



Measured memory_bytes: 648
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2];
    return 0;
}

Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        int k = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray()[1];
        int sum = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).OrderBy(v => v).Take(k).Sum();
        Console.WriteLine(sum);



    }



}

Measured memory_bytes: 28548
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;
vector<ll> A(100001, 0);

int main(void){
	
	scanf("%d", &N);
	for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
	
	int mod4 = 0, odd = 0;
	for(int i = 0; i < N; ++i){
	    if(A[i] % 4 == 0) ++mod4;
	    else if(A[i] % 2 == 1) ++odd;
	}
	
	if(N % 2 == 0 && mod4 >= odd) printf("Yes\n");
	else if(N % 2 == 1 && mod4 + 1 >= odd) printf("Yes\n");
	else printf("No\n");
	
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int root[60]; // 親
int ran[60]; // 木の深さ

int N, M, a, b;
vector <P> v;
vector <P> cur_v;

// 初期化
void init(int n){
	REP(i, n+1){
		root[i] = i;
		ran[i] = 0;
	}
}

// 木の根を求める
int find(int x) {
	if (root[x] == x) {
		return x;
	} else {
		return root[x] = find(root[x]);
	}
}

// x と y の属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(ran[x] < ran[y]) {
		root[x] = y;
	} else {
		root[y] = x;
		if(ran[x] == ran[y]) ++ran[x];
	}
}

// x と y が同じ集合に属するか否か
bool same(int x, int y) {
    return find(x) == find(y);
}

int main(){
    scanf("%d%d", &N, &M);

    REP(i, M){
        scanf("%d%d", &a, &b);
        v.push_back(P(a, b));
    }

    cur_v = v;
    init(N);
    int ans = 0;

    REP(i, M){
        cur_v.erase(cur_v.begin() + i);

        REP(j, cur_v.size()){
            int s = cur_v[j].first;
            int t = cur_v[j].second;
            unite(s, t);
        }

        for(int j=2;j<=N;++j){
            if(!same(1, j)){
                ++ans;
                break;
            }
        }

        cur_v = v;
        init(N);
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
# coding=utf-8

S1 = []
S2 = []
total_square = 0
j = 0

input = list(input())

for i, val in enumerate(input):
    sq = 0
    if val == '\\':
        S1.append(i)
    elif val == '/':
        if len(S1) > 0:
            j = S1.pop()
            total_square += (i - j)
            if len(S2) > 0:
                if (S2[-1][0] > j):
                    while (S2[-1][0] > j):
                        poped = S2.pop()
                        sq += poped[1]
                        if len(S2) == 0:
                            break
                    S2.append([j, sq + (i-j)])
                else:
                    S2.append([j, (i-j)])
            else:
                S2.append([j, i-j])

print(total_square)
print(len(S2), end = "")
for data in S2:
    print(' ' + str(data[1]), end = "")
print()

Measured memory_bytes: 8368
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

using namespace std;

double N;
double x[1919],y[1919];
//円の中心付近を出して
//そこから遠い点に向かって徐々に寄せていき本当の中心を割り出す
//山登り法っぽい発想らしい

double dist(double a, double b){
    return a*a + b*b;
}

int main(){

    cin >> N;
    double X = 0;
    double Y = 0;

    for(ll i = 0; i < N; i++){
        cin >> x[i] >> y[i];
        X += x[i];
        Y += y[i];
    }

    //平均を取る．円の中心付近になる
    X /= N;
    Y /= N;

    //ループ回数を増やすと精度が上がる
    double P = 0.1;
    double d = 0;
    for(ll i = 0; i < 30000; i++){
        ll idx = 0;
        d = dist(X-x[0], Y-y[0]);
        for(ll j = 1; j < N; j++){
            //仮の中心から各座標への距離を求める
            double t_d = dist(X-x[j], Y-y[j]);
            if(d < t_d){
                d = t_d;
                idx = j;
            }
        }
        //cout << fixed << setprecision(18) << d << endl;
        //遠いところへ仮の座標を少しだけずらす
        X += (x[idx] - X) * P;
        Y += (y[idx] - Y) * P;
        //cout <<  fixed << setprecision(18) << X << " " << Y << endl;
        //ずらし量を徐々に減らしていく
        //ここでも精度が変わる
        P *= 0.999;
    }

    cout << fixed << setprecision(15) << sqrt(d) << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int b[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++)
		cin >> b[i];
	int sum = b[1];
	for (int i = 1; i <= n; i++) {
		sum += min(b[i], b[i + 1]);
	}
	sum += b[n-1];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2741&lang=jp
// references : http://suikaba.hatenablog.com/entry/2017/05/23/194505
const int INF = 1e9;
int dp[51][51][51][51][2][2];
int a[51];
int b[51];
int n, m;

int calc_score(int a1, int b1, int a2, int b2, int turn) {
	int score_a = 0, score_b = 0;
	if (turn == 0) {
		if (a2 - a1 < b2 - b1) {
			if (b[b1] != -1) score_b = b[b1];
			b1++;
		}
		for (int k = 0; k < a2 - a1;k++) {
			if (a[a1 + k] == -1) score_b = 0;
			else score_a += a[a1 + k];
			if (b[b1 + k] == -1) score_a = 0;
			else score_b += b[b1 + k];
		}
	}
	else {
		if (b2 - b1 < a2 - a1) {
			if (a[a1] != -1) score_a = a[a1];
			a1++;
		}
		for (int k = 0; k < a2 - a1;k++) {
			if (b[b1 + k] == -1) score_a = 0;
			else score_b += b[b1 + k];
			if (a[a1 + k] == -1) score_b = 0;
			else score_a += a[a1 + k];
		}
	}
	return score_a - score_b;
}

int solve(int a1, int b1, int a2, int b2, int turn, int pass) {
	int& ret = dp[a1][b1][a2][b2][turn][pass];
	if (ret != INF) return ret;
	if (turn == 0) {
		ret = -INF;
		if (pass == 1) ret = max(ret, 0);
		else ret = max(ret, solve(a2, b2, a2, b2, 1, (a1 == a2) && (b1 == b2)) + calc_score(a1, b1, a2, b2, 0));
		if (a2 < n) ret = max(ret, solve(a1, b1, a2 + 1, b2, 1, 0));
	}
	else {
		ret = INF;
		if (pass == 1) ret = min(ret, 0);
		else ret = min(ret, solve(a2, b2, a2, b2, 0, (a1 == a2) && (b1 == b2)) + calc_score(a1, b1, a2, b2, 1));
		if (b2 < m) ret = min(ret, solve(a1, b1, a2, b2 + 1, 0, 0));
	}
	return ret;
}

int main(void) {
	cin.tie(0);ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < n;i++) cin >> a[i];
	for (int i = 0; i < m;i++) cin >> b[i];
	fill(dp[0][0][0][0][0], dp[50][50][50][50][2], INF);
	cout << solve(0, 0, 0, 0, 0, 0) << endl;
}

Measured memory_bytes: 108920
#include<stdio.h>
#include <string.h> 
int main(){
char a[102],b[102];
int i,A,B;
scanf("%s",a);
scanf("%s",b);
A=strlen(a);
B=strlen(b);
if (A>B) printf("GREATER\n");
if (A<B) printf("LESS\n");
if (A==B){
for(i=0;i<A;i++){
if (a[i]>b[i]) {
printf("GREATER\n");
return 0;
}
if (a[i]<b[i]) {
printf("LESS\n");
return 0;
}
}
printf("EQUAL\n");
}
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <numeric>

using namespace std;

int findMax(int n, int arr[]){
    int max_times = 0;

    if(n==1) return 0;

    int pos = 0;
    while(pos < n-1){
        int tmp_max_times = 0;
        while (arr[pos] >= arr[pos + 1])
        {
            tmp_max_times++;
            pos++;
            if (pos + 1 > n - 1)
                break;
        }
        pos++;
        max_times = max(max_times, tmp_max_times);
    }

    return max_times;
}

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

    cout << findMax(n, h) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
using namespace std;
int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	if (h==1||w==1){
		puts("1");return 0;
	}
	printf("%lld\n",(1LL*h*w+1)/2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define deb(a) cout << a << ": "
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sliczny() {
    int n, a, ans = 0;
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a;
        if(i % 2 == 1 && a % 2) {
            ans++;
        }
    }
    cout << ans << '\n';
}

int32_t main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
  //cin >> T; 
    for(int t = 1; t <= T; t++) {
    //cout << "Case #" << t << ": ";
        sliczny();
    }
  return 0;
}


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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String s = fs.next();
		long k = fs.nextLong();
		char ans = '1';
		
		for(int i=0;i<k;i++) {
			if(s.charAt(i)!='1') {
				ans = s.charAt(i);
				System.out.println(ans);
				return;
			}
		}
		System.out.println(ans);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 23124
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)
        {
            int n = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());
            int y = int.Parse(Console.ReadLine());

            int ans = 0;
            if(n<k)
            {
                ans = n * x;
            }
            else
            {
                ans = k * x + (n - k) * y;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 2648
N,M,K=map(int,input().split())
ret = 'No'
for m in range(M+1):
  a=K-m*N
  b=M-2*m
  if 0<=a and 0<b and a%b==0:
    n=a//b
    if 0<=n<=N:
      ret = 'Yes'
print(ret)

Measured memory_bytes: 3060
#include <iostream>

const int N = 51;

char map[N][N], map2[N][N];
int a, b;

bool contain(int x, int y){
    for(int h = 0; h < b; ++h){
        for(int w = 0; w < b; ++w){
            if(map[h + y][w + x] != map2[h][w])return false;
        }
    }
    return true;
}

int main(){
    std::cin >> a >> b;
   
    for(int i = 0; i < a; ++i){
        for(int j = 0; j < a; ++j){
            std::cin >> map[i][j];
        }
    }
    
    for(int i = 0; i < b; ++i){
        for(int j = 0; j < b; ++j){
            std::cin >> map2[i][j];
        }
    }
     
    for(int i = 0; i < a - b + 1; ++i){
        for(int j = 0; j < a - b + 1; ++j){
            if(contain(j, i)){
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }
    
    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
t=min(a,b)
t1=t
s=max(a,b)
c=1
i=2
while t > 1 and i <=int(t1**(0.5)+1):
  frag=0
  while t%i ==0:
    t=t/i
    if frag==0 and s%i ==0:
      c=c+1
    frag=1
  if i==2:
    i=3
  else:
    i= i+2
if s%t==0 and t > int(t1**(0.5)+1):
  c=c+1
print(c)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

ll extgcd(ll a, ll b, ll &x, ll &y)
{ //extended Euclidean algorithm, used for modular multiplicative inverse
    ll d = a;
    if (b != 0)
    {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else
    {
        x = 1;
        y = 0;
    }
    return d; //return gcd(a,b)
}

ll mod_inv(ll a, ll m = MOD)
{ //return inv(a) mod m, ax+my=gcd(a,m)=1, m is prime int, ax-1=mq equiv. ax-mq=1
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m; //From (possibly) negative x to positive x
}

vector<ll> fact, invfact;
void calc_fact(int n, ll m = MOD)
{ //Calculate factorial up to n
    fact.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = invfact[0] = 1;
    REP(i, n)
    {
        fact[i + 1] = fact[i] * (i + 1) % m;
        invfact[i + 1] = invfact[i] * mod_inv(i + 1) % m;
    }
}
ll perm(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return fact[n] * invfact[n - k] % m;
}
ll comb(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return (fact[n] * invfact[n - k] % m) * invfact[k] % m;
}

int main()
{
    ciosup;
    int n,k;
    cin >> n >> k;
    calc_fact(2 * n);
    ll ans = 0;
    FOR(i, 1 , k + 1)
    {
        cout << (comb(k - 1, i - 1) * comb(n - k + 1, i)) % MOD << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

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

    map<char,char> m;
    bool flag=true;

    rep(i,s.size()){
        char x = s[i];
        char y = t[i];
        if(m.count(x)){
            if(m[x] != y) flag = false;
        }else{
            m[x] = y;
        }
    }

    map<char,char> inv;
    for(auto p : m){
        auto key = p.first;
        auto val = p.second;
        if(inv.count(val)) flag = false;
        else inv[val] = key;
    }

    if(flag){
        for(auto p : m){
            auto key = p.first;
            auto val = p.second;
            int i = 0;
            while(m.count(val)){
                if(val == key){
                    break;
                }
                if(i > 30){
                    flag = false;
                    break;
                }
                val = m[val];
                i++;
            }
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
string s;
int n;cin>>n>>s;
char k;
for(int i=0;i<s.size();i++){
    k=('A'+((s[i]-'A')+n)%('Z'-'A'+1));
    cout<<k;
}
return 0;
}


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

using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;
    priority_queue<int, vector<int>, greater<int>> p;
    int pt;
    for(int i = 0; i < n; ++i) {
        cin >> pt;
        p.emplace(pt);
    }

    int ans = 0;

    while(k > 0) {
        ans += p.top();
        p.pop();
        k--;
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

for i in range(1,N):
    A1[i] = A1[i] + A1[i-1]

ans = A2.copy()
ans[0] += A1[0]

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

print(ans[N-1])

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n: String,
    }
    let s:Vec<char> = n.chars().collect();
    if s[2] == s[3] &&  s[4] == s[5]{ 
        let ans = "Yes";
    println!("{}", ans);
    }
    else {
        let ans="No"; 
    println!("{}", ans);
    }
}


Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class ALphabet {
public:
	void solve(std::istream& in, std::ostream& out) {
	    char c;in>>c;
	    if(c>='a') out<<"a"<<endl;
        else out<<"A"<<endl;

	}
};


int main() {
	ALphabet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
  int n;
  int a[1000+10];
  while(cin >> n && n!=0){
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    int ans[1000+10];
    for(int i=0;i<n-1;i++){
      ans[i]=abs(a[i+1]-a[i]);
    }
    sort(ans,ans+n-1);
    cout << ans[0] << endl;
  }
  return 0;
}



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

int main() {
  ll n,a,b,sum=0;
  cin >> n >> a >> b;
  sum+=(n/(a+b))*a;
  n%=a+b;
  sum+=min(n,a);
  cout<<sum<<endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

struct N {
  int i, v;
};

bool operator<(const N &l, const N &r) {
  return l.v > r.v;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> p(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  int k;
  cin >> k;
  priority_queue<N> q;
  ll INF = 1LL << 30;

  vector<int> ans(n, -INF);
  for (int i = 0; i < k; i++) {
    int j, val;
    cin >> j >> val;
    j--;
    q.push(N{j, val});
  }
  while (q.size()) {
    auto now = q.top();
    q.pop();
    if (ans[now.i] > -INF) {
      if (ans[now.i] != now.v) {
        cout << "No" << endl;
        return 0;
      }
      continue;
    }
    ans[now.i] = now.v;
    for (auto &j : p[now.i]) {
      if (ans[j] > -INF) {
        if (abs(ans[j] - ans[now.i]) == 1) {
          continue;
        } else {
          cout << "No" << endl;
          return 0;
        }
      } else {
        q.push(N{j, now.v + 1});
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 8308