akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n){
    ll cu=i;
    while(cu<n){
      a[cu]++;
      cu+=i+1;
    }
  }
  ll ans=0;
  rep(i,n){
    ans+=a[i]*(i+1);
  }
  COUT(ans);
}

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

int main() {
    ll n;
    cin >> n;
    vector<ll> count(110000, 0);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll num;
        cin >> num;
        count[num]++;
        sum += num;
    }

    ll q;
    cin >> q;
    vector<ll> b(q);
    vector<ll> c(q);
    for (int i = 0; i < q; i++) {
        cin >> b[i] >> c[i];
    }

    for (int i = 0; i < q; i++) {
        sum += (c[i] - b[i]) * count[b[i]];
        cout << sum << endl;
        count[c[i]] += count[b[i]];
        count[b[i]] = 0;
    }

}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=1,a,b,c,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0;

string s;

vector<int> z;

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

       cin >> n >> a;
       rep(i,n){
           ans=min(ans*2,ans+a);
       }
       Cout(ans);
return 0;
}


Measured memory_bytes: 256
from collections import Counter
N=int(input())
S=input()
C=Counter(S)
nr=C["R"]
ng=C["G"]
nb=C["B"]
ans=nr*ng*nb
for i in range(N-2):
    for j in range(i+1,N-1):
        k=j+j-i
        if k<N:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ans-=1

print(ans)


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

int main(){
  int L,R;
  cin>>L>>R;
  if(R-L>=2019){
    cout<<0<<endl;
  }else{
    int r=R%2019;
    int l=L%2019;
    if(r<l){
      cout<<0<<endl;
    }else{
      int ans=2019;
      for(int i=l;i<=r;i++){
        for(int j=i+1;j<=r;j++){
          ans=min(ans,i*j%2019);
        }
      }
      cout<<ans<<endl;
    }
  }
}


Measured memory_bytes: 256
OPS = %w[+ -]

ds = gets.chomp.chars
ops = OPS.product(OPS, OPS)

combs = ([ds] * ops.size).zip(ops).map { |(d, o)| d.zip(o).flatten.join }
exp = combs.find { |comb| (eval comb) == 7 }

puts "#{exp}=7"


Measured memory_bytes: 1788
n = int(input())
dist = [list(map(int,input().split())) for i in range(n)]
use = [[True for i in range(n)] for j in range(n)]
ans = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            if dist[j][k] > dist[j][i] + dist[i][k]:
                print(-1)
                exit()
            elif j != i and j != k and i != k and dist[j][k] == dist[j][i] + dist[i][k]:
                use[j][k] = False

for i in range(n):
    for j in range(n):
        if use[i][j]:
            ans += dist[i][j]

print(ans//2)

Measured memory_bytes: 45148
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    N,S=MI()
    A=LI()
    dp=[[0]*(S+1) for _ in range(N+1)]
    #dp[i][j]はi番目までで，和がjになるのが何個作れるか．
    #ただし，その数を使わない場合，選択するかしないか選べるのでダブルでカウント
    
    dp[0][0]=1
    
    
    for i in range(N):
        #dp[i][0]+=1
        for j in range(S+1):
            dp[i+1][j]+=dp[i][j]*2
            dp[i+1][j]%=mod
            if j+A[i]<=S:
                dp[i+1][j+A[i]]+=dp[i][j]
                dp[i+1][j+A[i]]%=mod
                
    print(dp[-1][-1])
    

            

main()


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  pii curp(0,0);
  int32 curt = 0;
  REP(i,n){
    int32 t;
    pii p;
    cin >> t >> p.first >> p.second;
    int32 d = abs(p.first - curp.first) + abs(p.second - curp.second);
    if((t - curt) % 2 != d % 2 || d > t - curt){
      Yes(false);
      return 0;
    }
    curp = p;
    curt = t;
  }
  Yes(true);
  return 0;
}

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

int main(){
	long long n,k;
	cin >> n >> k;
	
	vector<long long> v(n);
	for(long long &e : v)
		cin >> e;

	long long pre = 0;	
	long long ans = 1;

	for(int i = 0;i < n;++i){
		pre += v[i];
		ans += (k >= pre);		
	}

	cout << ans;

	
}

Measured memory_bytes: 3612
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	l := a + b
	r := c + d

	switch {
	case l > r:
		fmt.Println("Left")
	case l < r:
		fmt.Println("Right")
	default:
		fmt.Println("Balanced")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define mod 1000000007

int main(){
  ll n,k;
  cin >> n >>k;
  ll a[100100]={0};
  ll buc[50]={0};
  rep(i,n){
    cin >> a[i];
    rep(j,40){//2^40>=10^12
      if(a[i]&(1ll<<j)){//j_ketame
        buc[j]++;
      }
    }
  }

  ll x=-1,ans=-1,res=-1;
  ll p=-1,answer=-1;

 //when x < k;
  rep(i,40){
    if(k&(1ll<<i)){
      //k no iketame 2^i==1=>
      //x no iketame 2^i==0
      res=0;
      ans=0;
      rep(j,i){
        if((n-buc[j])>buc[j]){
          res+=(1ll<<j);
        }
      }
      for(ll j=i+1;j<40;j++){
        if(k&(1ll<<j))res+=(1ll<<j);
      }
      rep(i,n){
        ans+=res^a[i];
      }
      answer=max(ans,answer);
    }
  }
  // when x=k;
  ans=0;
  rep(i,n){
    ans+=k^a[i];
  }
  answer=max(answer,ans);
  //cout << x << endl;
  if(k==0){
    answer=0;
    rep(i,n)answer+=a[i];
  }

  cout << answer <<endl;
}


Measured memory_bytes: 1024
#include<iostream>

int main() {
	int a[4], b[4];
	while (std::cin >> a[0] >> a[1] >> a[2] >> a[3]) {
		std::cin >> b[0] >> b[1] >> b[2] >> b[3];
		int hit = 0, blow = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					if (i == j) hit++;
					else blow++;
				}
			}
		}
		std::cout << hit << " " << blow << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3004
A=int(input())
B=int(input())
C=int(input())
X=int(input())

c=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                c+=1

print(c)


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    if (d > c) {
        long long k;
        k = c;
        c = d;
        d = k;
    }

    long long ansb, cbc, cbd;
    long long ansa, cac, cad;
    cbc = b / c;
    cbd = b / d;
    cac = (a-1) / c;
    cad = (a-1) / d;

    long long gcm = 0;

    long long r = c % d;
    long long cc, dd;
    cc = c; dd = d;
    while(r != 0) {
        cc = dd;
        dd = r;
        r = cc % dd;
    }

    gcm = (c * d) / dd;
    long long cbcb, cacb;
    cbcb = b / gcm;
    cacb = (a-1) / gcm;

    long long cb, ca;
    cb = cbc + cbd - cbcb;
    ca = cac + cad - cacb;

    long long cab = cb - ca;
    long long ans = 0;
    ans = (b - a +1) - cab;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

int main(void){
  int n,a;
  cin>>n>>a;

  if(n%500<=a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
r,p,m=range,print,min
n,a,b=[list(map(int,input().split()))for i in r(3)]
l=[]
for i in r(n[2]):
  x,y,z=map(int,input().split())
  l.append(a[x-1]+b[y-1]-z)
p(m([m(a)+m(b),m(l)]))

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int n,k;
    cin >> n >> k;
    vector<int> A(n);
    ll res=999999999;
    for(auto &i: A)
    	cin >> i;
    sort(A.begin(),A.end());

    FOR(i,0,n-k+1)
    	res=min(res,A[i+k-1]*1LL-A[i]*1LL);

    cout << res << endl;

    return 0;
}


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

int n,x,y,ans;
int cnt[10020];

vector<pair<pair<int, int>, int> > a;
int main(){
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>x>>y;
        a.push_back(make_pair(make_pair(x,y),0));
    }
    for(int i=0;i<n;i++){
        cin>>x>>y;
        a.push_back(make_pair(make_pair(x,y),1));
    }
    sort(a.begin(),a.end());
    for(int i=0;i<a.size();i++){
        if(!a[i].second)
            cnt[a[i].first.second]++;
        else{
            for(int j=a[i].first.second-1;j>=0;j--){
                if(cnt[j]){
                    cnt[j]--;
                    ans++;
                    break;
                }
            }
        }    
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int l = v[i].f;
		int r = v[i].s;

		auto it = mp.lower_bound(l);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			mini[it1->s]--;
			if(mini[it1->s]==0) mini.erase(it1->s);
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(it!=mp.end() && it->f == r + 1) {
				if(it->s > mn) {
					if(mini[it->s]==1) mini.erase(it->s);
					else mini[it->s]--;
					mini[mn]++;
					it->s = mn;
				}
			}
			else {
				mp.insert({r+1,mn});
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 19276
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for (int i = 0; i < s.length(); i++) {
            if ('a' <= s.charAt(i) && s.charAt(i) <= 'z') {
                System.out.print((char)(s.charAt(i) - 'a' + 'A'));
            } else if ('A' <= s.charAt(i) && s.charAt(i) <= 'Z'){
                System.out.print((char)(s.charAt(i) - 'A' + 'a'));
            }
            else System.out.print(s.charAt(i));
        }
        System.out.print("\n");
    }
}


Measured memory_bytes: 26808
import itertools

N = int(input())

cnt_dict = {'M':0, 'A':0, 'R': 0, 'C':0, 'H':0}
first_letters = cnt_dict.keys()

for i in range(N):
    first_letter = input()[0]
    if first_letter in first_letters:
        cnt_dict[first_letter] += 1
        
sum_cnt = 0
for comb in itertools.combinations(cnt_dict, 3):
    comb_num = 1
    for c in comb:
        comb_num *= cnt_dict[c]
    sum_cnt += comb_num

print(sum_cnt)

Measured memory_bytes: 3064
open Printf
open Scanf

module IntSet = Set.Make (struct
                           type t = int
                           let compare i j = i - j
                         end)

let tpl x y = (x, y)

let () =
  let n, m = scanf "%d %d " tpl in
  let al = Array.make n IntSet.empty in
  let rec iter x =
    if x = 0 then ()
    else let a, b = scanf "%d %d " (fun x y -> (x-1, y-1)) in
         al.(a) <- (IntSet.add b al.(a));
         al.(b) <- (IntSet.add a al.(b));
         iter (x-1)
  in
  iter m;
  (if IntSet.is_empty (IntSet.inter al.(0) al.(n-1)) then "IMPOSSIBLE" else "POSSIBLE") |> 
  printf "%s\n"


Measured memory_bytes: 31488
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
char s[20];
int i,j;
int e=0;

int main(){
	int ans=0;
	int x=0;

	cin>>s;
	int n=strlen(s);
	for(i=0;i<n;i++){
		e += s[i]-'0';
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(j<=i-1){
				ans += s[j]-'0';
			}else if(j==i){
				ans += s[j]-'1';
			}else{
				ans += 9;
			}
		}
		e = max(e,ans);
		ans = 0;
	}

	cout<<e<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 101
using namespace std;
 
int w,h,ans;
int m[N][N],f[N][N];
int dx[2][6]={{0,1,0,-1,-1,-1},{1,1,1,0,-1,0}};
  int dy[2][6]={{-1,0,1,1,0,-1},{-1,0,1,1,0,-1}};

int flag;

int dfs(int x,int y,int num,int cnt){
  f[y][x]=1;
  for(int i=0;i<6;i++){
    if(y+dy[num][i]>h || x+dx[num][i]>w || y+dy[num][i]<=0 || x+dx[num][i]<=0){flag=1;continue;}
    if(m[y+dy[num][i]][x+dx[num][i]])cnt++;
    else if(!m[y+dy[num][i]][x+dx[num][i]] && !f[y+dy[num][i]][x+dx[num][i]])cnt=dfs(x+dx[num][i],y+dy[num][i],(y+dy[num][i])%2,cnt);
      }
    if(flag==1) return 0;
    else return cnt;
}
 
int main(){
   cin>>w>>h;
   for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)cin>>m[i][j];
 
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++){
      int num=i%2;
    if(m[i][j])ans+=6;
      if(m[i][j]){
    for(int dxy=0;dxy<6;dxy++){
        if(i+dy[num][dxy]>h || j+dx[num][dxy]>w || i+dy[num][dxy]<=0 || j+dx[num][dxy]<=0) continue;
        else if(m[i+dy[num][dxy]][j+dx[num][dxy]])ans--;
    }
      }else {
    if(f[i][j]==0)flag=0,ans-=dfs(j,i,i%2,0);
      }
    }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1508
let n = stdin.ReadLine() |> int

// -2進数は実質-2,-1,0,1を数字として持つ4進数と考えられる
let divideMinDigit n :(string * int) =
    match n%4 with
    | 0 -> ("00", n )
    | -3| 1 -> ("01", n-1 )
    | -2| 2 -> ("10", n+2 )
    | -1| 3 -> ("11", n+1 )

let rec strMinus2 (str:string, num) =
    match num with
    | 0 -> if str.Substring(0,1) = "0" then str.Substring(1,str.Length-1) else str
    | _ ->
    divideMinDigit num
    |> (fun (newStr, remainNum) -> strMinus2 (newStr+str, remainNum/4))

if n = 0 then "0" else strMinus2 ("", n) 
|> stdout.WriteLine

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
	ll n,count(0);
	cin >> n;
	vector<ll>a(n + 1);
	vector<ll>b(n);

	for (int i(0); i < n + 1; i++)	cin >> a[i];

	for (int i(0); i < n; i++)		cin >> b[i];

	for (int i(0); i < n; i++){
		if (a[i] + a[i + 1] < b[i]){
			count += a[i] + a[i + 1];
			a[i + 1] = 0;
		}
		else if (a[i] + a[i + 1] >= b[i] && a[i] <= b[i]){
			count += b[i];
			a[i + 1] -= b[i] - a[i];
		}
		else if (a[i] > b[i]){
			count += b[i];
		}
	}
	cout << count << endl;
	return 0;
}

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

namespace AGC14 {
    class Program {
        static int[] abc;
        static int[] _abc;
        static int num = 0;
        static bool even = true;
        static void Main(string[] args) {
            abc =Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            _abc = new int[] { 0, 0, 0 };
            Split();
            Console.WriteLine(num);
        }
        static void Split() {
            while (true) {
                for(int i = 0; i < 3; i++) {
                    if (abc[i] % 2 == 1) even = false;

                }
                if (!even) break;
                if(abc[0] == abc[1] && abc[1] == abc[2]) {
                    num = -1;
                    break;
                }
                num++;
                _abc[0] = (abc[1] + abc[2]) / 2;
                _abc[1] = (abc[0] + abc[2]) / 2;
                _abc[2] = (abc[0] + abc[1]) / 2;
                abc[0]  =_abc[0];
                abc[1] = _abc[1];
                abc[2] = _abc[2];
                //Console.WriteLine("no:" + num + " " + abc[0] + " " + abc[1] + " " + abc[2]);
            }
        }
    }
}


Measured memory_bytes: 11220
K = int(input())

def ca(a,b):
    if a == 1:
        return 1
    while True:
        if a == 1:
            return 1
        if a == 0:
            return b
        t = a
        a = b %a
        b = t
    return b

def cal(a,b,c):
    mo = ca(a,b)
    ans = ca(mo,c)
    return ans


ans = 0
for a in range(1,K-1):
    ans += a
    ans += 6*cal(a,a,K)
    for b in range(a+1,K):
        ans += 6*cal(a,b,b)
        for c in range(b+1,K+1):
            ans += 6*cal(a,b,c)
    
ans += K + K-1 +6
if K == 1:
    print(1)
elif K == 2:
    print('9')
else:

    print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
typedef long long ll;

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

	ll a,b,k;

	cin >> k >> a >> b;

	ll x = b/k;
	ll mul = x*k;

	if (mul >= a)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;

	return 0;
}

Measured memory_bytes: 3604
import sys
#input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    s = "#" + input() + "#"
    move = []
    for _ in range(M):
        a,b = map(str,input().split())
        if b == "R":
            b = 1
        else:
            b = -1
        move.append((a,b))
        
    def drop_out(pos,edge):
        col = s[pos]
        for c,d in move:
            if c == col:
                pos += d
                if pos == edge:
                    return True
                col = s[pos]
        return False
    
    l,r = 0,N+1
    while r-l>1:
        mid = (l+r)//2
        if drop_out(mid,0):
            l = mid
        else:
            r = mid
    left = l
    
    l,r = 0,N+1
    while r-l>1:
        mid = (l+r)//2
        if drop_out(mid,N+1):
            r = mid
        else:
            l = mid
    right = r

    print(right-left-1)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 20016
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(int(readline()) for _ in range(N))
    A.sort(reverse=True)
    B = []
    C = []
    lb = 0
    rb = -1
    lc = 0
    rc = -1
    for i in range(N):
        if i % 2 == 0:
            B.append(A[lb])
            lb += 1
            C.append(A[rc])
            rc -= 1
        else:
            B.append(A[rb])
            rb -= 1
            C.append(A[lc])
            lc += 1
    ansb = 0
    for i in range(N - 2):
        ansb += abs(B[i] - B[i + 1])
    ansb += max(abs(B[0] - B[-1]), abs(B[-2] - B[-1]))

    ansc = 0
    for i in range(N - 2):
        ansc += abs(C[i] - C[i + 1])
    ansc += max(abs(C[0] - C[-1]), abs(C[-2] - C[-1]))


    print(max(ansb,ansc))


if __name__ == '__main__':
    main()


Measured memory_bytes: 15420
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int X, N;
    cin >> X >> N;

    vector<bool> a(200);

    for(int i = 0; i < N; i++) {
        int p;
        cin >> p;
        a[p] = true;
    }

    int ans = 300;
    int z;

    for(int i = 0; i < 200; i++) {
        if(a[i]) continue;
        if(abs(i - X) < ans) {
            ans = abs(i - X);
            z = i;
        }
    }

    cout << z << endl;
}

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

int main(){
  string s;
  cin>>s;
  bool c=false,f=false;
  int n;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C' || s[i]=='c'){
      c=true;
      n=i;
      break;
    }
  }
  for(int i=n;i<s.size();i++){
    if(s[i]=='F' || s[i]=='f'){
      f=true;
      break;
    }
  }
  if(c==true && f==true){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	// tuple definition
	public static class Tuple {
		int pi;
		int qi;
		char c;
		Tuple(int pi, int qi, char c) {
			this.pi = pi;
			this.qi = qi;
			this.c = c;
		}
	}
	
	public static void main(String[] args) {
		// input
		Scanner sc = new Scanner(System.in);
		String p = sc.nextLine();
		String q = sc.nextLine();

		// prefix
		p = "$" + p;
		q = "$" + q;
		
		int pn = p.length(), qn = q.length();
		// pnxt[i][j] := pにおいて位置 i に居て次に j(0/1) が現れるindex
		int[][] pnxt = new int[4010][2];
		pnxt[pn][0] = pnxt[pn][1] = pn;
		int plas0 = pn, plas1 = pn;
		for(int i = pn - 1; i >= 0; --i) {
			pnxt[i][0] = plas0;
			pnxt[i][1] = plas1;
			if(p.charAt(i) == '0') plas0 = i;
			if(p.charAt(i) == '1') plas1 = i;
		}
		// qnxt[i][j] := pnxt同様
		int[][] qnxt = new int[4010][2];
		qnxt[qn][0] = qnxt[qn][1] = qn;
		int qlas0 = qn, qlas1 = qn;
		for(int i = qn - 1; i >= 0; --i) {
			qnxt[i][0] = qlas0;
			qnxt[i][1] = qlas1;
			if(q.charAt(i) == '0') qlas0 = i;
			if(q.charAt(i) == '1') qlas1 = i;
		}

		// queue definition
		Queue<Tuple> que = new ArrayDeque<>();
		boolean[][] visited = new boolean[4010][4010];
		// restore definition
		Tuple[][] res = new Tuple[4010][4010];

		String ans = "";
		// BFS
		que.add(new Tuple(0, 0, '$'));
		visited[0][0] = true;
		res[0][0] = new Tuple(-1, -1, '$');
		while(!que.isEmpty()) {
			Tuple e = que.remove();
			int pi = e.pi, qi = e.qi;
			char c = e.c;
			if(pi == pn && qi == qn) {
				ans = ans + c;
				break;
			}
			int npi0 = pnxt[pi][0], nqi0 = qnxt[qi][0];
			if(!visited[npi0][nqi0]) {
				visited[npi0][nqi0] = true;
				res[npi0][nqi0] = new Tuple(pi, qi, c);
				que.add(new Tuple(npi0, nqi0, '0'));
			}
			int npi1 = pnxt[pi][1], nqi1 = qnxt[qi][1];
			if(!visited[npi1][nqi1]) {
				visited[npi1][nqi1] = true;
				res[npi1][nqi1] = new Tuple(pi, qi, c);
				que.add(new Tuple(npi1, nqi1, '1'));
			}
		}

		int pi = pn, qi = qn;
		// restore
		while(true) {
			Tuple e = res[pi][qi];
			if(e.c == '$') {
				System.out.println(ans);
				return;
			}
			ans = e.c + ans;
			pi = e.pi;
			qi = e.qi;
		}
	}
}


Measured memory_bytes: 261716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		
		char[] list = str.toCharArray();
		int count = 0;
		int ans = 0;
		for (char c : list) {
			if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
				count++;
				if (ans < count) {
					
					ans = count;
				}
			} else {
				count = 0;
			}
		}
		
		System.out.println(ans);
		
		scan.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9;
const long double PI=acos(-1);



void solve(int T){
    int n;
    cin>>n;
    int mn=n+1;
    int ans=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x<=mn){
            ans++;
            mn=min(mn,x);
        }
    }
    cout<<ans<<"\n";
}

int main() {
    //fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
ll gojou(ll n){return pow(n,5);}
int main()
{
   int a,b,c;
   bool f=true;
   string s,t;
   cin>>s>>t;
   for(int i=0;i<s.size();i++)
   {
   	if(s[i]!=t[i])f=false;
   }
   cout<<(f?"Yes":"No");
}


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

using namespace std;

#define LL long long
#define u64 unsigned long long
#define u32 unsigned int
#define reg register
#define Raed Read
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,x) for(reg int i=Head[x]; i; i=Nxt[i])

inline int Read() {
	int res = 0, f = 1;
	char c;
	while (c = getchar(), c < 48 || c > 57)if (c == '-')f = 0;
	do res = (res << 3) + (res << 1) + (c ^ 48);
	while (c = getchar(), c >= 48 && c <= 57);
	return f ? res : -res;
}

template<class T>inline bool Min(T &a, T const&b) {
	return a > b ? a = b, 1 : 0;
}
template<class T>inline bool Max(T &a, T const&b) {
	return a < b ? a = b, 1 : 0;
}

const int N=2e5+5,M=1e5+5,mod=998244353;

bool MOP1;

inline void Add(LL &x,int y) {
	x+=y;
	if(x<0)x+=mod;
	if(x>=mod)x-=mod;
}

struct point {
	int x,y;
} S[N];

struct cmpy {
	bool operator()(point _,point __)const {
		return _.y<__.y;
	}
};

int X[N];

struct BIT {
	int c[N];
	inline void clear(void) {
		memset(c,0,sizeof c);
	}
	inline void Add(int x) {
		for(; x<N; x+=x&-x)c[x]++;
	}
	inline int Sum(int x) {
		int res=0;
		for(; x; x^=x&-x)res+=c[x];
		return res;
	}
} tr;

int F2[N];

bool MOP2;

inline void _main(void) {
	int n =Read();
	F2[0]=1;
	rep(i,1,n)F2[i]=(1ll*F2[i-1]<<1)%mod;
	rep(i,1,n) S[i].x=X[i]=Read(),S[i].y=Read();
	sort(X+1,X+n+1);
	rep(i,1,n)S[i].x=lower_bound(X+1,X+n+1,S[i].x)-X;
	LL Ans=1ll*n*(F2[n]-1)%mod;
	rep(i,1,n) {
		Add(Ans,-(F2[i]-2));
		Add(Ans,-(F2[n-i+1]-2));
	}
	sort(S+1,S+n+1,cmpy());
	rep(i,1,n) {
		Add(Ans,(F2[tr.Sum(S[i].x)]-1));
		Add(Ans,(F2[i-1-tr.Sum(S[i].x)]-1));
		tr.Add(S[i].x);
	}
	tr.clear();
	drep(i,n,1) {
		Add(Ans,(F2[tr.Sum(S[i].x)]-1));
		Add(Ans,(F2[n-i-tr.Sum(S[i].x)]-1));
		tr.Add(S[i].x);
	}
	printf("%lld\n",Ans);
}

signed main() {
#define offline1
#ifdef offline
	freopen("chessboard.in", "r", stdin);
	freopen("chessboard.out", "w", stdout);
	_main();
	fclose(stdin);
	fclose(stdout);
#else
	_main();
#endif
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int h, n;
vector< int > a( 1e3 + 3 ), b( 1e3 + 3 );
long long dp[ 10004 ][ 1003 ];

long long solve( int h, int n )
{
	if( h <= 0 )
	{
		return 0;
	}
	if( n == 0 )
	{
		return 1e18;
	}
	if( dp[ h ][ n ] != -1 )
	{
		return dp[ h ][ n ];
	}
	dp[ h ][ n ] = min( b[ n ] + solve( h - a[ n ], n ), solve( h, n - 1 ) );
	return dp[ h ][ n ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> h >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> a[ i ] >> b[ i ];		
	}
	memset( dp, -1, sizeof( dp ) );
	cout << solve( h, n ) << "\n";	
	return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
#define MAX 3001
int dp[MAX][MAX];
string getLCS(string& s,string& t,int len)
{
    string LCS;
    int i = 0,j = 0;
    while(len > 0)
    {
        if(s[i] == t[j])
        {
            LCS.push_back(s[i]);
            i++;
            j++;
            len--;
        }
        else
        {
            if(dp[i][j+1] > dp[i+1][j])
                j++;
            else
                i++;
        }
    }
    return LCS;
}
int lenLCS(string& s,string& t,int i,int j)
{
    if(i >= s.length() || j >= t.length())
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    if(s[i] == t[j])
        return dp[i][j] = 1 + lenLCS(s,t,i+1,j+1);
    else
    {
        return dp[i][j] = max(lenLCS(s,t,i+1,j),lenLCS(s,t,i,j+1));
    }
}
string solve(string& s,string& t)
{
    memset(dp,-1,sizeof dp);
    int len = lenLCS(s,t,0,0);
    return getLCS(s,t,len);
}
int main() {
    string s,t;
    cin>>s>>t;
    cout<<solve(s,t);
}

Measured memory_bytes: 39260
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int tako[] = new int[N];
    for(int i=0; i<N; i++){
        tako[i] = sc.nextInt();
    }


    int sumTako = 0;
    for(int i=0; i<N; i++){
        for (int j=i+1; j<N; j++)
            sumTako += (tako[i]*tako[j]);
    }

    System.out.println(sumTako);

    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
 
using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
 
int main()
{
#if LOCAL_ENVIRONMENT == 1
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  ll N = input();
  ll K = input();
  vector<ll> dist;
  for(ll i=0;i<N;i++){
    ll a = input();
    dist.push_back(a);
  }

  ll dp[N];
  dp[0] = 0;
  for(ll i=1;i<=N;i++){
    ll minVal = abs(dist[i] - dist[i-1]) + dp[i-1];
    for(ll j=2;j<=K;j++){
      if(i-j < 0)continue;
      minVal = min(minVal, abs(dist[i] - dist[i-j]) + dp[i-j]);
    }
    dp[i] = minVal;
  }

  output(dp[N-1]);

  return 0;
}

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    string S;
    cin >> S;
    int w;
    cin >> w;
    for(int i = 0, i_len = S.size(); i < i_len; i += w) cout << S[i];
    cout << endl;
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  map<int, int> M;
  
  for (int i = 0; i < N; ++i) {
    int num;
    cin >> num;
    M[num]++;
  }
//cout << M.size() << "]" << K << endl;
  int ans;
  if (K >= M.size()) {
    ans = 0;
    cout << ans << endl;
    return 0;
  }
  // M.size > K
  int msize = M.size();
  
  typedef pair<int, int> int_pair;
  struct pair_order {
    bool operator()(int_pair& l, int_pair& r) {
    	return tie(l.second, l.first) > tie(r.second, r.first);
    }
  };
  
  priority_queue<int_pair, vector<int_pair> ,pair_order> pq;
  
  for (int_pair m : M) {
    pq.push(m); 
  }
  
  ans = 0;
  while(msize != K && !pq.empty()) {
//cout << K << "[" << msize << "[" << ans << endl;
    int_pair m = pq.top();
    ans += m.second;
    msize--;  
    
    pq.pop(); 
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 14548
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let s: String = read();
    let sc: Vec<char> = s.chars().collect();
    println!(
        "{}",
        sc[0].to_string() + &(sc.len() - 2).to_string() + &sc[sc.len() - 1].to_string()
    );
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
  int main()
{
int A,B,C;
  
  cin>>A>>B>>C;
  int N;
  if(A-B>C)
  {
    N=0;
  }
  if(A-B<=C)
  {
    N=C-A+B;
  }
  cout<<N<<endl;
  
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    rep(i,INF){
        if(i & 1){
            a -= d;
        }else{
            c -= b;
        }
        if(a <= 0 || c <= 0) break;
    }

    cout << (a > 0 ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    char rem[n][m+1];
    int vis[n][m];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            vis[i][j]=0;
        }
    }
    int black=0;
    for (int i=0;i<n;i++)
    {
        scanf("%s",rem[i]);
        for (int j=0;j<m;j++)
        {
            if (rem[i][j]=='.')black++;
        }
    }
    queue<pair<int,int> >q;
    q.push(pair<int,int>(0,0));
    int siz=0;
    int ans=-1;
    int step=0;
    int x,y;
    while (!q.empty())
    {
        siz=q.size();
        for (int i=0;i<siz;i++)
        {
            x=q.front().first;
            y=q.front().second;
            if (x+1<n&&vis[x+1][y]==0&&rem[x+1][y]=='.')
            {
                vis[x+1][y]=1;
                q.push(pair<int,int>(x+1,y));
            }
            if (x-1>=0&&vis[x-1][y]==0&&rem[x-1][y]=='.')
            {
                vis[x-1][y]=1;
                q.push(pair<int,int>(x-1,y));
            }
            if (y+1<m&&vis[x][y+1]==0&&rem[x][y+1]=='.')
            {
                vis[x][y+1]=1;
                q.push(pair<int,int>(x,y+1));
            }
            if (y-1>=0&&vis[x][y-1]==0&&rem[x][y-1]=='.')
            {
                vis[x][y-1]=1;
                q.push(pair<int,int>(x,y-1));
            }
            q.pop();
        }
        if (vis[n-1][m-1]==1)
		{
			ans=step;
			break;
		}
        step++;
    }
    if (ans==-1)printf ("-1\n");
    else
    {
    	printf ("%d\n",black-2-step);
	}
}

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

int N, D1, D2, dp[609][609]; bool used[609][609]; vector<pair<int, int>>v1, v2, p1, p2;
vector<pair<int, int>>x[609][609];

void dfs(int px, int py, int depth) {
	if (dp[px][py] >= 0) return;
	dp[px][py] = depth;
	if (depth == 0) p1.push_back(make_pair(px, py));
	else p2.push_back(make_pair(px, py));

	for (int i = 0; i < x[px][py].size(); i++) {
		dfs(x[px][py][i].first, x[px][py][i].second, depth ^ 1);
	}
}

int main() {
	cin >> N >> D1 >> D2;
	for (int i = -2 * N; i <= 2 * N; i++) {
		for (int j = -2 * N; j <= 2 * N; j++) {
			if (i*i + j*j == D1) v1.push_back(make_pair(i, j));
			if (i*i + j*j == D2) v2.push_back(make_pair(i, j));
		}
	}
	for (int i = 0; i < 2 * N; i++) {
		for (int j = 0; j < 2 * N; j++) {
			dp[i][j] = -1;
			for (int k = 0; k < v1.size(); k++) {
				int cx = i + v1[k].first, cy = j + v1[k].second;
				if (cx < 0 || cy < 0 || cx >= 2 * N || cy >= 2 * N) continue;
				x[i][j].push_back(make_pair(cx, cy));
			}
		}
	}
	vector<pair<int, int>>V;
	for (int i = 0; i < 2 * N; i++) {
		for (int j = 0; j < 2 * N; j++) {
			if (dp[i][j] != -1) continue;
			p1.clear(); p2.clear();
			dfs(i, j, 0);
			if (p1.size() > p2.size()) swap(p1, p2);
			for (int k = 0; k < p2.size(); k++) V.push_back(p2[k]);
		}
	}
	for (int i = 0; i < V.size(); i++) used[V[i].first][V[i].second] = true;

	for (int i = 0; i < 2 * N; i++) { for (int j = 0; j < 2 * N; j++) { dp[i][j] = -1; x[i][j].clear(); } }

	for (int i = 0; i < 2 * N; i++) {
		for (int j = 0; j < 2 * N; j++) {
			if (used[i][j] == false) continue;
			for (int k = 0; k < v2.size(); k++) {
				int cx = i + v2[k].first, cy = j + v2[k].second;
				if (cx < 0 || cy < 0 || cx >= 2 * N || cy >= 2 * N || used[cx][cy] == false) continue;
				x[i][j].push_back(make_pair(cx, cy));
			}
		}
	}
	vector<pair<int, int>>W;
	for (int i = 0; i < 2 * N; i++) {
		for (int j = 0; j < 2 * N; j++) {
			if (dp[i][j] != -1 || used[i][j] == false) continue;
			p1.clear(); p2.clear();
			dfs(i, j, 0);
			if (p1.size() > p2.size()) swap(p1, p2);
			for (int k = 0; k < p2.size(); k++) W.push_back(p2[k]);
		}
	}
	for (int i = 0; i < N*N; i++) {
		cout << W[i].first << " " << W[i].second << endl;
	}
	return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<int> X = {a, b, c, d};
  sort(X.begin(), X.end());
  if (X[0] == 1 && X[1] == 4 && X[2] == 7 && X[3] == 9) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
num=1
if l.count(0)!=0:
    print(0)
else:
    flag=True
    for i in l:
        if num>10**18:
            print(-1)
            flag=False
            break
        else:
            num*=i
    if flag==True:
        if num>10**18:
            print(-1)
        else:
            print(num)

Measured memory_bytes: 21612
import Control.Applicative ((<$>))
import Control.Monad (foldM)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Bool (bool)

main :: IO ()
main = do
  B.getLine
  B.lines <$> B.getContents >>= solve

solve :: [ByteString] -> IO ()
solve bs = foldM f Leaf bs >> return ()
  where f :: BSTree Int -> ByteString -> IO (BSTree Int)
        f tr bs = case B.words bs of
                   [com, bn] | com == sfind -> do
                                 putStrLn $ bool "no" "yes" $ bstFind (readi B.readInt bn) tr
                                 return tr
                             | com == sdelete -> do
                                 return (bstDelete (readi B.readInt bn) tr)
                             | otherwise -> do
                                 return (bstInsert (readi B.readInt bn) tr)
                   _ -> do
                     printList $ inOrder tr
                     printList $ preOrder tr
                     return tr
        sfind = B.pack "find"
        sdelete = B.pack "delete"
        
data BSTree a = Leaf | Node a (BSTree a) (BSTree a) deriving Show

bstInsert :: (Ord a) => a -> BSTree a -> BSTree a
bstInsert x (Node y lt rt) | x > y = Node y lt (bstInsert x rt)
                           | x < y = Node y (bstInsert x lt) rt
                           | otherwise = Node y lt rt
bstInsert x Leaf = Node x Leaf Leaf

bstFind :: (Ord a) => a -> BSTree a -> Bool
bstFind _ Leaf = False
bstFind x (Node y lt rt) | x == y = True
                         | x > y = bstFind x rt
                         | otherwise = bstFind x lt

bstFindMin :: BSTree a -> Maybe a
bstFindMin Leaf = Nothing
bstFindMin (Node x Leaf _) = Just x
bstFindMin (Node _ lt _) = bstFindMin lt

bstDelete x Leaf = Leaf
bstDelete x (Node y lt rt) | x < y = Node y (bstDelete x lt) rt
                           | x > y = Node y lt (bstDelete x rt)
                           | otherwise = case (lt, rt) of
                                          (Leaf, Leaf) -> Leaf
                                          (Leaf, rt) -> rt
                                          (lt, Leaf) -> lt
                                          _ -> let (Just mn) = bstFindMin rt
                                               in Node mn lt (bstDelete mn rt)

foldPre :: (a -> b -> b) -> b -> BSTree a -> b
foldPre f z Leaf = z
foldPre f z (Node x l r) = f x y2
  where y1 = foldPre f z r
        y2 = foldPre f y1 l

foldIn :: (a -> b -> b) -> b -> BSTree a -> b
foldIn f z Leaf = z
foldIn f z (Node x l r) = foldIn f y2 l
  where y1 = foldIn f z r
        y2 = f x y1

preOrder :: BSTree a -> [a]
preOrder = foldPre (:) []

inOrder :: BSTree a -> [a]
inOrder = foldIn (:) []

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . (' ':) . unwords . map show

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n



Measured memory_bytes: 107616
#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() {
	ios::sync_with_stdio(false);
	int h, w, n, a;
	cin >> h >> w >> n;
	int b[h][w] = {};
	int x = 0, y = 0;
	for (int i = 0 ; i < n ; i++) {
		cin >> a;
		for (int j = 0 ; j < a ; j++) {
			b[x][y] = i + 1;
			y++;
			if (y == w) {
				y = 0;
				x++;
			}
		}
		
	}
	for (int i = 0 ; i < h ; i++) {
		if (i % 2 == 0) {
			for (int j = 0 ; j < w ; j++) cout << b[i][j] << ' ';
		}
		else {
			for (int j = w - 1 ; j >= 0 ; j--) cout << b[i][j] << ' ';
		}
		cout << endl;
	}
}

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

typedef long long ll;
ll r, d, a, i;
int main()
{
	cin >> r >> d >> a;
	for (i = 1; i <= 10; i++) {
		a = a * r - d;
		cout << a << endl;
	}
    return 0;
}


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

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

alis = [0]*n

alis[0] = blis[0]

for i in range(1, n-1):
    alis[i] = min(blis[i-1], blis[i])
    
alis[n-1] = blis[n-2]

print(sum(alis))


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>

using namespace std;

int N;
int A[100];

void printA() {
  for (int i=0; i<N; i++) {
    printf("%d", A[i]);
    if (i < N-1) putchar(' ');
  }
  putchar('\n');
}

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) scanf("%d", &A[i]);
  for (int i=1; i<N; i++) {
    printA();
    int key = A[i], j = i-1;
    while (j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
  }
  printA();
  return 0;
}

Measured memory_bytes: 2668
s=int(input());
for n in range(s//4,3501):
 for h in range(3501):
  x=4*h*n-s*n-s*h
  if x>0:
   if ((s*h*n)/x).is_integer():
    print(int((s*h*n)/x),h,n)
    exit()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n;
    cin >> n;
    vector<long long> l(n, 0), h(n), t(n), a(n);
    cin >> t[0];
    l[0] = h[0] = t[0];
    for (int i = 1; i < n; i++) {
        cin >> t[i];
        if (t[i] > t[i-1]) {
            l[i] = h[i] = t[i];
        }
        else {
            h[i] = t[i];
            l[i] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    t.push_back(0);
    for (int i = n-1; i >= 0; i--) {
        if (t[i] > t[i+1]) {
            if (l[i] <= t[i] && t[i] <= h[i]) {
                l[i] = h[i] = t[i];
            }
            else {
                puts("0");
                return 0;
            }
        }
        else {
            h[i] = min(h[i], t[i]);
            if (l[i] > h[i]) {
                puts("0");
                return 0;
            }
        }
    }
    long long ans = 1, p = 1000000007;
    for (int i = 0; i < n; i++) {
        ans *= (h[i]-l[i]) + 1;
        ans %= p;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
h,w=map(int,input().split())
lis = []
for _ in range(h):
 lis.append(input())
for i in range(h):
 for j in range(w):
  if lis[i][j] == "#":
    if (i == 0 or lis[i-1][j] == ".") and (j==0 or lis[i][j-1] == ".")  and (i == h-1 or lis[i+1][j] == ".") and (j == w-1 or lis[i][j+1] == "."):
      print("No")
      quit()
print("Yes")

Measured memory_bytes: 3064