akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1e+18;
int iINF = 1e9;

vector<ll> memo(51, 0);

int 
main()
{
  int H, N; cin >> H >> N;
  rep(i, 0, N){
    int tmp; cin >> tmp;
    H -= tmp;
  }

  if(H <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}

void chmin(int &a, int &b){if (a>b){a = b; return;}return;}
void chmax(int &a, int &b){if (a<b){a = b; return;}return;}


const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int N; cin >>N;
  vector<vector<int>> dp(N+1, vector<int>(3,0));
  for (int i=0; i<N; i++){
    int a,b,c; cin >>a >>b >>c;
    chmax(dp.at(i+1).at(0), dp.at(i).at(1) + a);
    chmax(dp.at(i+1).at(0), dp.at(i).at(2) + a);
    chmax(dp.at(i+1).at(1), dp.at(i).at(0) + b);
    chmax(dp.at(i+1).at(1), dp.at(i).at(2) + b);
    chmax(dp.at(i+1).at(2), dp.at(i).at(0) + c);
    chmax(dp.at(i+1).at(2), dp.at(i).at(1) + c);
  }
  int ans = max(dp.at(N).at(0), max(dp.at(N).at(1), dp.at(N).at(2)));
  cout <<ans <<endl;
}

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

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

    cin >> a >> b >> c;

    int temp1 = a;
    a = b;
    b = temp1;

    int temp2 = a;
    a = c;
    c = temp2;

    cout << a << " " << b << " " << c << endl;

    return 0;
}


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

#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define ll long long
#define pr_qu priority_queue
#define vec(name,size,common) vector<ll> (name)((size),(common))





int main(){

  ll x;
  cin>>x;

ll co;
ll sum;
for(int i=1;;i++){
  sum =(i*(i+1))/2;
  co=i;
  if(sum>=x){
    break;
  }
}
  cout<<co<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll t[n], a[n];
    REP(i,n){
        cin >> t[i];
    }
    REP(i,n){
        cin >> a[i];
    }
    ll cnt_t[n], cnt_a[n];
    REP(i,n){
        cnt_t[i] = 1;
        cnt_a[i] = 1;
    }
    ll mx = 0;
    REP(i,n){
        if(t[i] <= mx){
            cnt_t[i] = t[i];
        }else{
            if(t[i] > a[i]){
                cout << 0 << endl;
                return 0;
            }
        }
        mx = max(mx, t[i]);
    }
    mx = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i] <= mx){
            cnt_a[i] = a[i];
        }else{
            if(a[i] > t[i]){
                cout << 0 << endl;
                return 0;
            }
        }
        mx = max(mx, a[i]);
    }
    ll ans = 1;
    REP(i,n){
        ans *= min(cnt_t[i], cnt_a[i]);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
n,m=map(int,input().split())
s=[list(map(int,input().split()))for i in range(m)]
p=list(map(int,input().split()))
a=0
for bit in range(1<<n):
 for j in range(m):
  c=0
  for k in s[j][1:]:
   if bit&(1<<(k-1)):c+=1
  if c%2!=p[j]:break
 else:a+=1
print(a)

Measured memory_bytes: 9028
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const uli mod=1e9+7;
const int mx=1e3+10;
uli f[mx];
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    int v=i;
    for(int p=2;p*p<=v;p++){
      int x=0;
      while(v%p==0)x++,v/=p;
      if(x>0)f[p]=(f[p]+x)%mod;
    }
    if(v!=1)f[v]=(f[v]+1)%mod;
  }
  uli ans=1;
  for(int i=0;i<mx;i++){
    ans=ans*uli(f[i]+1)%mod;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<string.h>
#include<set>
#include<ctype.h>
#include<cstdlib>

using namespace std;

int arr[10];
int sub[10];
int n,k;
int now = 0;
int cont;
int c = 0;

set<int> visit2;

void saiki(int[],int);

int main()
{
	for(;;)
	{
		visit2.clear();
		int i;
		c = 0;
		now = 0;
		
		scanf("%d",&n);
		scanf("%d",&k);
		if(n == 0 && k == 0){
			break;
		}
		
		for(i = 0; i < n; i++){
			scanf("%d",&arr[i]);
		}
		for(i = 0; i < n; i++){
			sub[0] = arr[i];
			saiki(sub,1);
			now++;
		}
		cout <<visit2.size()-c << endl;
	}
}

void saiki(int temp[], int kk)
{
	//k:TõK
	int used[50] = {0};
	int i,j;
	int t = 0;
	char str[256] = "";
	
	for(i = 0; i < kk; i++){
		sprintf(str+strlen(str),"%d",temp[i]);
	}
	
	t = atoi(str);
	
	if(kk == k){
		visit2.insert(t);
		return;
	}
	else{
		for(i = 0; i < kk; i++){
			for(j = 0; j < n; ++j ){     
				if( used[j] == 0 && arr[j] == temp[i] ){
					used[j] = 1;
					break;
				}
			}
		}
		
		for(i = 0; i < n; i++){
			if(used[i] == 0){
				temp[kk] = arr[i];
				used[i] = 1;
				saiki(temp, kk+1);
				used[i] = 0;
			}
		}
	}
}
			

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int x[2000];
int main(){
	int n;cin>>n;
	double m=0;
	rep(i,n){
		scanf("%d",&x[i]);
		m+=x[i];
	}
	m/=n;
	int M=floor(m),M2=ceil(m);
	ll ans=0,ans2=0;
	rep(i,n){
		ans+=(x[i]-M)*(ll)(x[i]-M);
		ans2+=(x[i]-M2)*(ll)(x[i]-M2);
	}
	cout<<min(ans,ans2)<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(n-1):
  for j in range(n-1,i,-1):
    if a[j] < a[j-1]:
      c += 1
      a[j],a[j-1] = a[j-1],a[j]
print(' '.join(map(str,a)))
print(c)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define MAX 105

using namespace std;

int N;
int ans, B[MAX];

int main() {
	ios::sync_with_stdio(0);
	cin >> N;
	B[0] = B[N] = INT_MAX;
	for(int i = 1; i < N; ++i) cin >> B[i]; 
	for(int i = 1; i <= N; ++i) ans += min(B[i], B[i - 1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "cstdio"
#include "string"
#include "cmath"
using namespace std;

const int maxn = 1e5;

int main(int argc, char const *argv[])
{
	int n;
	double res = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		double t;
		scanf("%lf", &t);
		res += 1.0/t;
	}
	res = 1.0/res;
	printf("%.6f", res);
	return 0;
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

S = input()[::-1]

arr = []
for i, x in enumerate(S):
	if x in digits:
		n = pow(10, i, 13)*int(x)%13
		arr.append(n)
	else:
		arr.append(pow(10, i, 13))

dp = [[0]*13 for _ in range(len(S)+1)]
#dp[i][j] : i桁目までで13で割って余る可能性の数
dp[0][0] = 1

for i, x in enumerate(arr, 1):
	if S[i-1] == "?":
		for k in range(10):
			for j in range(13):
				dp[i][j] += dp[i-1][(j-k*x)%13]
				dp[i][j] %= mod

	else:
		for j in range(13):
			dp[i][j] += dp[i-1][(j-int(x))%13]
			dp[i][j] %= mod


print(dp[-1][5])


Measured memory_bytes: 98932
#include<iostream>

using namespace std;

int main()

{

	int a,b;	cin>>a>>b;

	if(a>=b){

		for(int i=0;i<a;i++){

			cout<<b;

			}

		}

	else {

		for(int i=0;i<b;i++){

			cout<<a;

		}

		}

		return 0;}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
long long x,a,b,n;
long long min(long long a,long long b) {
	return a<b?a:b;
}
int main() {
  scanf("%lld%lld%lld",&a,&b,&n);
  x=min(n,b);
  if(x==b) x--;
  long long ans=(long long)(a*x/b)-a*(long long)(x/b);
  return printf("%lld\n",ans),0;
}

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

int func(int c1, int c2, int c3){
	bool b[10];
	int c = c1 + c2, i, ans = 0;
	fill(b, b+10, false);
	for(i = 1;i < 10;i++)if(i+c <= 20)b[i] = true;
	b[c1] = b[c2] = b[c3] = false;
	for(i = 0;i < 10;i++)if(b[i])ans++;
	return ans*100/7;
}

int main(){
	int c1, c2, c3;
	while(cin >> c1 >> c2 >> c3){
		if(func(c1, c2, c3) >= 50)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    cout<<fixed<<setprecision(10);

    int n;cin>>n;
    double sum=0.00000;

    rep(i,n){
        double a;
        cin>>a;
        sum+=(1/a);
    }
    double ans=1/sum;
    cout<<ans<<endl;

}


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

signed main(){
    int K,X;
    cin >> K >> X;
    
    if(K*500>=X) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,n,i;
  scanf("%d %d %d",&n,&a,&b);
  for(i=a;i<=b;i++){
    if(i%n==0){
      printf("OK\n");
      return 0;
    }
  }
  printf("NG\n");    
  return 0;
}


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


int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  vector<ll> k(n-1);
  for(long long i = 1; i <= n-1; i++){
    for(long long j = i+1; j <= n; j++){
      ll p, q;
      p = j - i;
      q = (max(x,i)-min(x,i))+(max(y,j)-min(y,j))+1;
      
      k[min(p,q)-1]++;
    }
  }
  rep(i,n-1){
    cout << k[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::*;

pub trait SafeIndex<T> {
    fn at(&self, index: isize) -> Option<&T>;
    fn at_d(&self, index: isize) -> &T {
        self.at(index).unwrap()
    }
}
impl<T> SafeIndex<T> for Vec<T> {
    fn at(&self, index: isize) -> Option<&T> {
        let length = self.len() as isize;
        if 0 <= index && index < length {
            Some(&self[index as usize])
        } else {
            None
        }
    }
}
impl<T> SafeIndex<T> for &[T] {
    fn at(&self, index: isize) -> Option<&T> {
        let length = self.len() as isize;
        if 0 <= index && index < length {
            Some(&self[index as usize])
        } else {
            None
        }
    }
}
pub trait SafeIndexMut<T> {
    fn at_mut(&mut self, index: isize) -> Option<&mut T>;
    fn at_mut_d(&mut self, index: isize) -> &mut T {
        self.at_mut(index).unwrap()
    }
}
impl<T> SafeIndexMut<T> for Vec<T> {
    fn at_mut(&mut self, index: isize) -> Option<&mut T> {
        let length = self.len() as isize;
        if 0 <= index && index < length {
            Some(&mut self[index as usize])
        } else {
            None
        }
    }
}
impl<T> SafeIndexMut<T> for &mut [T] {
    fn at_mut(&mut self, index: isize) -> Option<&mut T> {
        let length = self.len() as isize;
        if 0 <= index && index < length {
            Some(&mut self[index as usize])
        } else {
            None
        }
    }
}

fn main() {
    input! {
        h: usize,
        w: usize,
        s: [Bytes; h],
    }

    let mut min_cost = vec![vec![0; w]; h];
    min_cost[0][0] = (s[0][0] == b'#') as usize;

    for x in 0..w as isize {
        for y in 0..h as isize {
            if x == 0 && y == 0 {
                continue;
            }
            *min_cost.at_mut_d(y).at_mut_d(x) = std::cmp::min(
                min_cost.at(y - 1).and_then(|i| i.at(x)).unwrap_or(&100000000)
                    + (s.at(y - 1)
                        .and_then(|i| i.at(x))
                        .map(|i| i == &b'.')
                        .unwrap_or(true)
                        && s.at_d(y).at_d(x) == &b'#') as usize,
                min_cost.at(y).and_then(|i| i.at(x - 1)).unwrap_or(&100000000)
                    + (s.at(y)
                        .and_then(|i| i.at(x - 1))
                        .map(|i| i == &b'.')
                        .unwrap_or(true)
                        && s.at_d(y).at_d(x) == &b'#') as usize,
            );
        }
    }

    println!("{}", min_cost[h - 1][w - 1]);
}


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

int main(void) {
    int a, b; cin >> a >> b;
    for (int i = 1; i <= 3; i++) {
        if ((a * b * i) % 2 == 1) 
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
flag=0

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

for i in range(n):
	if(a[i]%2==0):
		if(a[i]%3!=0 and a[i]%5!=0):
			flag=1

if(flag==1):
	print("DENIED")
else:
	print("APPROVED")

Measured memory_bytes: 3060
#くじ引き

import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	line = input()
	line_list = re.split(" +", line)
	num1, num2 = int(line_list[0]), int(line_list[1])
	if (num1 * num2) % 2 == 0:
		print("Even")
	else:
		print("Odd")

if __name__ == '__main__':
	main()

Measured memory_bytes: 12504
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int psum=0,gsum=0;
    int ans=0;
    for(int i=0;i<str.length();i++)
    {
        if(str[i]=='g')
        {
            if(psum<gsum) ans++,psum++;
            else gsum++;
        }
        else
        {
            if(psum<gsum) psum++;
            else gsum++,ans--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
	int k,o,j;
	cin>>k;
	o=0;
	j=0;
	for(int i=1;i<=k;i++)
	{
		if(i%2==0)
		o++;
		else if(i%2==1)
		j++;
	}
	cout<<o*j<<endl;
 } 

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

#define endl '\n'

bool pal(string s){
    for (int i=0; i<s.size()/2; i++) if (s[i] != s[s.size()-1-i]) return false;
    return true;
}

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

    string s; cin >> s;
    int n = s.size();
    if (!pal(s) || !pal(s.substr(0, (n-1)/2)) || !pal(s.substr((n+3)/2 - 1, n))) cout << "No\n";
    else cout << "Yes\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
int N;
int a[200], b[200], c[200], d[200];
pair<int, int> red[200], blue[200];

int main() {
  cin >> N;
  priority_queue<pair<int, int>> que_red;
  rep(i, 0, N) {
    cin >> a[i] >> b[i];
    red[i] = make_pair(a[i], b[i]);
    que_red.push(red[i]);
  }

  priority_queue<pair<int, int>> que_x;
  rep(i, 0, N) {
    cin >> c[i] >> d[i];
    blue[i] = make_pair(c[i], d[i]);
    que_x.push(blue[i]);
  }

  vector<int> blue_y;

  int ans = 0;
  while (!que_red.empty()) {
    auto r = que_red.top();
    que_red.pop();

    while (!que_x.empty() && que_x.top().first > r.first) {
      auto b = que_x.top();
      que_x.pop();
      blue_y.push_back(b.second);
    }

    sort(blue_y.begin(), blue_y.end());
    vector<int> newvec;
    bool can = false;
    for (auto e : blue_y) {
      if (!can && e > r.second) {
        ans++;
        can = true;
      } else {
        newvec.push_back(e);
      }
    }
    blue_y = newvec;
  }

  cout << ans << endl;
}

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

int main(){
	string sa,sb,sc;
	cin>>sa>>sb>>sc;
	char turn='a';
	int si=0,sj=0,sk=0;

	while(1){
		if(turn=='a'){
			if(si==sa.size()){
				cout<<'A'<<endl;
				return 0;
			}else{
				turn=sa[si];
				si++;
			}
		}
		

		if(turn=='b'){
			if(sj==sb.size()){
				cout<<'B'<<endl;
				return 0;
			}else{
				turn=sb[sj];
				sj++;
			}
		}
		

		if(turn=='c'){
			if(sk==sc.size()){
				cout<<'C'<<endl;
				return 0;
			}else{
				turn=sc[sk];
				sk++;
			}
		}
		

	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<int,ll>;
using Pd = pair<double,double>;
using T = tuple<double,double,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 100005;
const ll lmod = 1e9+7;

ll part(ll t){
  ll res = 0LL;
  ll p[MAX_N];
  rep(i,t){
    scanf("%lld",p+i);
  }
  rep(i,t-1){
    res = (res + (i+1) * (t-i-1) * (p[i+1]-p[i])) % lmod;
  }
  return res;
}

int main(){
  ll n,m; cin >> n >> m;
  ll x = part(n);
  ll y = part(m);
  cout << (x*y) % lmod << endl;
  return 0;
}


Measured memory_bytes: 1024
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
a,b=map(int,input().split())
if a==b:
  print(a)
  exit()
if a==0:
  i=0
  resb=0
  while True:
    if i==0:
      if ((b+1)//2)%2==1:
        resb+=1
      i+=1
      continue
    if 2**i>b+1:
        break
    if ((b+1)%(2**i))%2==1 and ((b+1)//(2**i))%2==1:
        resb+=2**i
    i+=1
  print(resb)
  exit()
  
n_b=b.bit_length()
n_a=(a-1).bit_length()
i=0
res=0

while True:
    if i==0:
      if (a//2)%2==1:
        res+=1
      i+=1
      continue
    if 2**i>a:
        break
    if (a%(2**i))%2==1 and (a//(2**i))%2==1:
        res+=2**i
    i+=1
i=0
resb=0
while True:
  if i==0:
    if ((b+1)//2)%2==1:
      resb+=1
    i+=1
    continue
  if 2**i>b+1:
        break
  if ((b+1)%(2**i))%2==1 and ((b+1)//(2**i))%2==1:
        resb+=2**i
  i+=1
print(res^resb)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    ll r, d, x;
    cin>>r>>d>>x;
    ll sol[15] = {};
    sol[0] = x;
    ll i;
    FOR(i, 1, 11)
    {
        sol[i] = r*sol[i-1] - d;
        cout<<sol[i]<<endl;
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
L,R = map(int,input().split())
minnum = 2019
if R - L > 2019:
    print(0)
    exit()
else:
    for i in range(L,R+1,1):
        for j in range(i+1,R+1,1):
            minnum = min(minnum,i*j%2019)
print(minnum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll n, k;
    cin >> n >> k;
    cout << min(n % k, k - n % k) << endl;
}

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


Measured memory_bytes: 3616
from itertools import *
H, W, K = map(int, input().split())
S = [list(map(int, input())) for i in range(H)]
ans = 100000
for p in product([0,1],repeat=H-1):
    tmp_ans = sum(p)
    index = []
    for i,j in enumerate(p):
        if j == 1:
            index.append(i+1)
    count = [0] * (len(index) +1)
    for w in range(W):
        plate = [yoko[w] for yoko in S]
        tmp = [0]*(len(index)+1)
        if index == []:
            tmp[0] = sum(plate)
        else:
            tmp[0] = sum(plate[0:index[0]])
            for itr in range(len(index)):
                if itr == len(index) -1:
                    tmp[itr+1] += sum(plate[index[itr]:])
                else:
                    tmp[itr+1] += sum(plate[index[itr]:index[itr+1]])
        if max(tmp) > K :
            tmp_ans = 11111111111
        tmp_sum = [x+y for (x,y) in zip(count,tmp)]
        if max(tmp_sum) > K:
            tmp_ans +=1
            count = tmp
        else:
            count = tmp_sum
    if tmp_ans < ans:
        ans = tmp_ans

print(ans)







Measured memory_bytes: 53356
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll> > drink;
  for (int i = 0; i < N; i++) {
    ll A, B;
    cin >> A >> B;
    drink.push_back(make_pair(A, B));
  }

  sort(drink.begin(), drink.end());

  ll ans = 0, sum = 0;
  for (int i = 0; i < N; i++) {
    if (sum + drink[i].second >= M) {
      ans += (M - sum) * drink[i].first;
      break;
    } else {
      ans += drink[i].first * drink[i].second;
    }
    sum += drink[i].second;
  }

  cout << ans << endl;
}

Measured memory_bytes: 2420
#include<stdio.h>

int A[500001],n;

void   maxHeapify(int k)
{
  int l,r,largest,x,y;
  l=2*k;
  r=2*k+1;
  if(l<=n&&A[l]>A[k]) largest=l;
  else largest=k;
  if((r<=n)&&(A[r]>A[largest])) largest=r;

  if(largest!=k)
    {
      x=A[k];
      y=A[largest];
      A[k]=y;
      A[largest]=x;
      maxHeapify(largest);
    }
}

void buildMaxHeap(void)
{
  int i;
  for(i=n/2;i>=1;i--)
    {
      maxHeapify(i);
    }
}


int main()
{
  int i,k=0;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
    }

  buildMaxHeap();

  for(i=1;i<=n;i++)
    {
      printf(" %d",A[i]);
    }
  printf("\n");

  return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#define int long long
using namespace std;
signed main(){
	int h,n;
	cin>>h>>n;
	int a[n+1],b[n+1],maxv=-1;
	for(int i=1;i<=n;++i){
		cin>>a[i]>>b[i];
		maxv=max(maxv,a[i]);
	}
	maxv+=h;
	int dp[n+1][maxv+1];
	for(int j=1;j<=maxv;++j)
		dp[0][j]=0x3f3f3f3f;
	dp[0][0]=0;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=maxv;++j){
			dp[i][j]=dp[i-1][j];
			if(j>=a[i])
				dp[i][j]=min(dp[i][j],dp[i][j-a[i]]+b[i]);
		}
	int minv=0x3f3f3f3f;
	for(int i=h;i<=maxv;++i)
		minv=min(minv,dp[n][i]);
	cout<<minv<<endl;
	return 0;
}

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

#define long long int

const int D = 365;
vector<int> C(26), ans(D, 0);
vector<vector<int>> S(D, vector<int>(26));

void debug1()
{
    //rep(i,26) cout << C[i] << " "; cout << endl;
    rep(i,D){
        rep(j,26)cout << S[i][j] << " ";
        cout << endl;
    }
}
void rand_init()
{
    rep(i,26) C[i] = rand() % 100;
    rep(i,D) rep(j,26) S[i][j] = rand() % 20000;
}
void input()
{
    int tmp;
    cin >> tmp;
    if(tmp == 0)
    {
      rand_init();
      return;
    }
    rep(i,26) cin >> C[i];
    rep(i,D)rep(j,26) cin >> S[i][j];
    rep(i,D) cin >> ans[i]; rep(i,D) ans[i]--; //B,C問題用
}
void output()
{
    for(auto x : ans)
        cout << x+1 << "\n";
}
int calc(vector<int> &vec)
{
    int score = 0;
    vector<int> last(26, -1);
    rep(i,D) score += S[i][ans[i]];
    rep(i,D)
    {
        int cur = vec[i];
        last[cur] = i;
        rep(j,26)
        {
            score -= C[j] * (i - last[j]);
        }
        //cout << score << endl;
    }
    return score;
}
bool is_increase(vector<int> &old, vector<int> &cur, int d, int q)
{
    int a = S[d][q] - S[d][old[d]];
    int p = old[d], b = 0, c = 0;
    int last = -1;
    rep(i,D)
    {
      if(cur[i] == p) last = i;
      else b += C[p] * (i - last);
    }
    last = -1;
    rep(i,D)
    {
      if(cur[i] == q) last = i;
      else c += C[p] * (i - last);
    }
    return (a + b - c > 0);
}
    
void greedy()
{
    vector<int> last(26, -1);
    rep(i,D)
    {
      int cur = 0, pt = -1e9;
      rep(j,26)
      {
        int sum = S[i][j];
        rep(k, 26)
        {
          if(j == k) continue;
          sum -= C[k] * (i - last[k]);
        }
        if(sum > pt)
        {
          cur = j;
          pt = sum;
        }
      }
      ans[i] = cur;
      last[cur] = i;
    }   
}
void rand_ans()
{
  rep(i,D) ans[i] = rand() % 26;
}
void incremental()
{
    rep(t, 100000)
    {
        int d = rand() % D, q = rand() % 26;
        vector<int> old = ans;
        ans[d] = q;
        if(calc(ans) < calc(old))
            ans = old;
    }
}
void solve()
{
  greedy();
  //rand_ans();
  incremental();
}
void rand_test(int r)
{
    rep(q,r)
    {
        rand_init();
        solve();
        cout << 1000000 + calc(ans) << endl;
    }
}
int main()
{
    input();
    //rand_test(10);
    solve();
    output();
    //cout << calc(ans) << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ll n,f=100,c;
  	string a,b;
	cin >> n;
	for ( ll i = 1 ; i <= sqrt(n) ; i++ ) {
		if ( n % i == 0 ) {
			a=to_string(i);
			b=to_string(n/i);
			f=min(f,(ll)max(a.length(),b.length()));
		}
	}
	cout << f; 
}

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

#define L 1000000
int cnt = 0;

	int debug;


void insertionSort(int A[L], int n, int g){
	for(int i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v){
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[L],int n){
	int m = 0;
	int G[n];

	int o = 0;
	for(o = 0; o < 100; o++){
		m = m * 3 + 1;
		if(m > n){
			break;
		}
	}
	G[0] = (m - 1) / 3;
	m = 1;
	for(int i = o - 1; i > 0; i--){
		G[o - i] = (G[o - 1 - i] - 1) / 3;
		m++;
	}
	
	for(int i = 0; i < m; i++){
//		printf("i = %d",i);
		insertionSort(A, n, G[i]);
	}
	printf("%d\n",m);
	printf("%d",G[0]);
	for(int i = 1; i < m;i++){
		printf(" %d",G[i]);
	}
	printf("\n");
}

int main(){
	int n;
	int val[L];
	
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&val[i]);
//		printf("val[%d] = %d",i,val[i]);
	}
//	printf("n = %d",n);
	shellSort(val,n);
	
	printf("%d\n",cnt);
	for(int i = 0; i < n; i++){
		printf("%d\n",val[i]);
	}
	
	return 0;

}


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

const int MOD = 1e9+7;

using namespace std;

int main() {
    int H, W;
    cin>>H>>W;
    vector<string> Grid(H);
    for(int i = 0; i<H;i++) {
        cin>>Grid[i];
    }
    vector<vector<int>> dp(H + 1, vector<int>(W + 1, 0));
    //dp[1][1] = 1;
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            //cout<<'a'<<'\n';
            if(i == 1 && j == 1) {
                dp[i][j]=1;
                //cout<<"done"<<'\n';
            }
            else if(Grid[i - 1][j - 1] == '.') {
                //cout<<Grid[i - 1][j - 1]<<' ';
                dp[i][j] = (dp[i-1][j] % MOD + dp[i][j - 1] %MOD) %MOD;
            }
            else  {
                dp[i][j] = 0;
            }
        }
        //cout<<'\n';
    }
    // for(auto vec : dp) {
    //     for(auto i : vec) {
    //         cout<<i<<" ";
    //     }
    //     cout<<'\n';
    // }
    cout<<dp[H][W]<<'\n';
    return 0;
}

Measured memory_bytes: 5248
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
a.sort()
ans = 1
for aa in a:
    ans *= aa
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 20000
#include <cstdio>
#include <algorithm>
#include <vector>

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

int main(void){
	int n;
	scanf("%d",&n);
	int cmin[5]={12345,12345,12345,12345,12345};

	rep(i,n){
		int cur;
		scanf("%d",&cur);
		rep(i,5){
			if(cmin[i]>cur){
				for(int j=4;j>i;j--) cmin[j]=cmin[j-1];
				cmin[i]=cur;
				break;
			}
		}	
	}

	vector<ll> can;
	rep(i,5)rep(j,5){
		if(i==j) continue;
		int ten=10,cur=cmin[j];
		while(cur/10) cur/=10,ten*=10;
		int add=cmin[i]*ten+cmin[j];
		can.emplace_back(add);
	}
	sort(can.begin(),can.end());
	printf("%d\n",can[2]);
	return 0;
}

Measured memory_bytes: 2756
n,m = map(int,input().split())
x,y,z = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    z.append(c)
def solve(x,y,z,m):
    ans = 0
    for bit in range(8):
        #print((bit>>2)&1,(bit>>1)&1,(bit>>0)&1)
        w = []
        for i in range(n):
            t = x[i]*(-1)**((bit>>2)&1)+y[i]*(-1)**((bit>>1)&1)+z[i]*(-1)**((bit>>0)&1)
            w.append(t)
        w.sort(reverse=True)
        ans = max(ans,sum(w[:m]))
    return ans

ans = solve(x,y,z,m)
print(ans)

Measured memory_bytes: 39408
#include <string>
#include <set>
#include <iostream>
#include <vector>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	char table[26];
	for (auto& e : table)e = -1;
	for (int i = 0; i < s.length(); i++) table[s[i] - 'a'] = t[i];
	char cntr[26] = { 0 };
	for (auto& e : table) if(e != -1) cntr[e-'a'] ++;
	for (auto e : cntr) if (e > 1) goto no;
	for (auto& e : s) e = table[e - 'a'];
	if (s != t) goto no;
	cout << "Yes" << endl;
	return 0;
	no:
	cout << "No" << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

void solve() {
    int n, m;
    cin >> n >> m;
    bool mat[n][m];
    ll dp[n][m];
    memset(dp, 0LL, sizeof dp);
    dp[0][0] = 1;
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, m) {
            if (s[j] == '#') {
                mat[i][j] = 0;
            }
            else {
                mat[i][j] = 1;
            }
        }
    }
    rep(i, n) {
        rep(j, m) {
            if (i == 0 && j == 0) continue;
            if (!mat[i][j]) continue;
            if (i > 0) {
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            }
            if (j > 0) {
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
            }
        }
    }
    cout << dp[n - 1][m - 1] << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        //solve();
    }
}

int main() {
    //querySolve();
    solve();

}


Measured memory_bytes: 12324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc127_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  vector<int> l(M);
  vector<int> r(M);
  rep(i, M) { cin >> l[i] >> r[i]; }

  int L = l[0];
  int R = r[0];
  rep(i, M) {
    L = max(l[i], L);
    R = min(r[i], R);
  }

  ll ans = R - L + 1;

  cout << (ans > 0 ? ans : 0) << endl;
}

Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;

//a, a + 1, a + 2, ... , b - 1, bの総和を求める関数(a <= b)。計算量はO(1)
Int Sum(Int a, Int b) {
	if (b < a)return 0;
	if ((b - a + 1) % 2 == 0)return (a + b) * (b - a + 1) / 2;
	else return (a + b) * ((b - a + 1) / 2) + (a + b) / 2;
}

void calc() {

	Int N, M; std::cin >> N >> M;
	std::vector<bool> exist(N, false);
	std::vector<Int> num(N, 1);
	exist[0] = true;

	rep(i, M) {
		Int x, y; std::cin >> x >> y; --x; --y;
		if (exist[x])exist[y] = true;
		--num[x]; ++num[y];
		if (num[x] == 0)exist[x] = false;
	}
	Int cnt = 0;
	rep(i, N) {
		if (exist[i])cnt++;
	}

	std::cout << cnt;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> myds;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define F first
#define S second
#define vec(x) vector<x> 
#define pi(x,y) pair<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repd(i,x,y,k) for(int i=x;i<y;i+=k)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define rev(x) reverse(all(x))
#define uniq(x) x.resize(distance(x.begin(),unique(all(x))))
#define full(x,a) memset(x,a,sizeof(x))
#define lcm(x,y) ((x*y)/__gcd(x,y))
#define mod 1000000007
#define bitcount __builtin_popcountll
#define pb push_back
#define indexof order_of_key
#define valueat find_by_order

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

int gcdextended(int a,int b,int &x,int &y){if(!a){x=0,y=1;return b;}int x1,y1;int ans=gcdextended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return ans;}
int inv(int a){int x,y;int ans=gcdextended(a,mod,x,y);return(x%mod+mod)%mod;}
int nCr(int n,int k){int res=1;k=(k>n-k)?n-k:k;rep(i,0,k){res*=(n-i);res/=(i+1);}return res;}
int POW(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res%mod*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
//void seive(){prime[0]=0;prime[1]=0;rep(i,2,10002)prime[i]=1;for(int i=2;i*i<=10000;i++){if(prime[i]){for(int j=i*i;j<=10000;j+=i)prime[j]=0;}}} 

int n,a,b;

void input(){
	cin>>n>>a>>b;
}

void solve(){
	int ans=n/(a+b);
	ans*=a;
	ans+=min(a,n%(a+b));
	cout<<ans<<endl;
}

main(){
	fastio;
	int t=1;
	while(t--){
		input();
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int flag1 = 0,flag2=0;
	char a[4];
	string s;
	cin >> s;
  
	for (int j = 0; j<4; j++)
	{
		for (int i = 0; i<4; i++)
		{
			if (s.at(j) == s.at(i)) flag1++;
		}
		if (flag1 != 2)flag2 = 1;
		flag1 = 0;
	}
	if (flag2 == 0) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
n=int(input())
a=sorted([int(input()) for i in range(n)])
b=[a[i] for i in range(n-1,-1,-1)]
c=[abs(a[i//2]-b[i//2]) if i%2==0 else abs(b[i//2]-a[i//2+1]) for i in range(n-1)]
c.append(abs(b[(n-1)//2]-a[0]))
d=[abs(b[i//2]-a[i//2]) if i%2==0 else abs(a[i//2]-b[i//2+1]) for i in range(n-1)]
d.append(abs(a[(n-1)//2]-b[0]))
print(max(sum(c)-min(c),sum(d)-min(d)))

Measured memory_bytes: 15712
n=int(input())
a=[int(v) for v in input().split()]
q=int(input())
d=dict()
s=0
for j in range(n):
    if a[j] in d:
        d[a[j]]=d[a[j]]+1
    else:
        d[a[j]]=1
    s=s+a[j]
for j in range(q):
    b,c=map(int,input().split())
    if b in d:
        s=s-(d[b]*b)+d[b]*c
        if c in d:
            d[c]=d[c]+d[b]
        else:
            d[c]=d[b]
        del d[b]
    print(s)

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

const int mod = 1000000007;

int main(){
    int ans = 0;
    int h, a;
    cin >> h >> a;
    while (h > 0)
    {
        ans++;
        h -= a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

struct UnionFind {
  int n,num;
  vector<int> r,p;
  UnionFind() {}
  UnionFind(int n) : n(n), num(n), r(n,1), p(n,0) {
    iota(p.begin(),p.end(),0);
  }
  int find(int x) {
    return (x == p[x] ? x : p[x] = find(p[x]));
  }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x,y);
    r[x] += r[y];
    p[y] = x;
    num--;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return r[find(x)];
  }
  int count() {
    return num;
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N,M;
  cin >> N >> M;
  UnionFind uf(N);
  REP(i,M) {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    X--; Y--;
    uf.unite(X,Y);
  }
  cout << uf.count() << endl;

  return 0;
}

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

const int mod = 1e9+7;

int main(){
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	multiset<int> s;

	for(int i = 0; i < n; i++){
		int t;
		cin >> t;
		if(n%2 == t%2 || t > n-1) cout << 0, exit(0);
		s.insert(t);
		if(s.count(t) >= 3) cout << 0, exit(0);
	}
	
	if(n % 2 == 1 && s.count(0) != 1) cout << 0, exit(0);
	
	int ans = 1;

	for(int i = 0; i < n/2; i++)
		ans = ans*2 % mod;

	cout << ans;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

#define maxN 100000
uint64_t dp[maxN];
uint16_t H[maxN];

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

  for (int n=0; n<N; ++n)
    cin >> H[n];

  dp[0] = 0;
  for (int n=1; n<N; ++n)
    dp[n] = UINT64_MAX;

  for (int n=0; n<N; ++n) {
    for (int k=1; k<=K; ++k) {
      if (n+k >= N)
	break;
      dp[n+k] = min(dp[n+k], dp[n]+abs(H[n+k]-H[n]));
    }
  }

  cout << dp[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1280
#pragma GCC optimize ("O3")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>
 
using namespace std;
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double
 
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;
 
 
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	sort(all(A));
	ll ans = 0;
	REP(i, N - 2) {
		FOR(j, i + 1, N - 1) {
			FOR(k, j + 1, N) {
				if (A[i] + A[j] <= A[k])break;
				if (A[i] < A[j] + A[k] && A[j] < A[i] + A[k] && A[k] < A[i] + A[j])ans++;
			}
		}
	}
	print(ans);
}
 
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

int32_t main() {
	fastio;

    int k, n; cin >> k >> n;
    vector<int> a(n);
    for(auto &x: a) cin >> x;

    vector<int> start(n); start[0] = 0;
    //cout << start[0] << " ";
    for(int i=1; i<n; i++){
        start[i] = start[i-1] + (a[i]-a[i-1]);
        //cout << start[i] << " ";
    }
    //cout << endl;

    vector<int> e(n); e[n-1] = 0;
    //cout << e[n-1] << " ";
    for(int i=n-2; i>=0; i--){
        e[i] = e[i+1] + a[i+1]-a[i];
        //cout << e[i] << " ";
    }
    //cout <<endl;

    int ans = min(e[0], start[n-1]);
    int dist = k-a[n-1]+a[0];
    for(int i=0; i<n-1; i++){
        ans = min(ans, dist + start[i] + e[i+1]);
    }

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


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 200005
 
using namespace std;
typedef long long ll;
 
int A[SIZE];

int imos1[SIZE];

ll imos2[SIZE];
 
int main() {
	int n,m;
	scanf("%d %d",&n,&m);
	int now;
	scanf("%d",&now);now--;
	ll all=0;
	for(int i=1;i<n;i++)
	{
		int to;
		scanf("%d",&to);to--;
		now%=m;
		if(now>to) to+=m;
		all+=to-now;
		imos1[now+1]++;
		imos1[to+1]--;
		imos2[now+1]+=now;
		imos2[to+1]-=now;
		now=to;
	}
	for(int i=1;i<2*m;i++)
	{
		imos1[i]+=imos1[i-1];
		imos2[i]+=imos2[i-1];
	}
	ll ret=all;
	for(int i=0;i<m;i++)
	{
		int a=imos1[i];
		ll b=imos2[i];
		ll nxt=all;
		nxt-=(ll) a*(ll) i-b-a;
		a=imos1[i+m],b=imos2[i+m];
		nxt-=(ll) a*(ll) (i+m)-b-a;
		ret=min(ret,nxt);
	}
	printf("%lld\n",ret);
	return 0;
}

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

#define NMAX 1000
#define MAX(a, b) (a > b ? a : b)

using namespace std;

//ifstream fin("f.in");
//ofstream fout("f.out");

int buttonA, buttonB;
int total;

int main()
{
    cin >> buttonA >> buttonB;
    total += MAX(buttonA, buttonB);
    if(buttonA > buttonB) buttonA--;
    else buttonB--;
    total += MAX(buttonA, buttonB);
    cout << total << '\n';
    return 0;
}


Measured memory_bytes: 256