akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

//--------------------------- Solve ---------------------------//

int N;
int a[25][25];
mint dp[1<<21];

void solve() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }

    dp[0] = 1;

    for (int s = 0; s < 1<<N; s++) {
        int i = __builtin_popcount(s);

        for (int j = 0; j < N; j++) {
            if (a[i][j] && !(s & 1<<j)) {
                dp[s|(1<<j)] += dp[s];
            }
        }
    }

    cout << dp[(1<<N)-1] << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 19988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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

    if(N >= M / 2) cout << M / 2 << endl;
    else cout <<  N + (M - (2 * N)) / 4 << endl;
}

Measured memory_bytes: 3512
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	//type pair struct{ x, y int }

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		Fscan(in, &a[i],&b[i])
	}
	sort.Ints(a)
	sort.Ints(b)


	if n&1==1 {
		mi := a[n/2]
		mx := b[n/2]
		Fprintln(out, mx-mi+1)
	} else {
		mi := a[n/2]+a[n/2-1]
		mx := b[n/2]+b[n/2-1]
		Fprintln(out, mx-mi+1)
	}
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 8428
my $N = <STDIN>;
$mod = $N % 2;
if( $mod == 1){
  print "0";
  exit;
}
$ans = 0;
$a = $N/2;
for($i=0;$i<10000;$i++){ 
  $mod = $a % 5;
  $a = $a - $mod;
  $a = ($a / 5);
  $ans = $ans + $a;
  if($a ==0){last;}
}
print "$ans\n";

Measured memory_bytes: 640
N = int(input())
A_LIST = []

for _ in range(N):
    A = int(input())
    A_LIST.append(A)

sorted_A_LIST = sorted(A_LIST)
largest = sorted_A_LIST[-1]
second_largest = sorted_A_LIST[-2]

for i in range(N):
    if A_LIST[i] < largest:
        print(largest)
    else:
        print(second_largest)

Measured memory_bytes: 70104
def main():
    N = int(input())
    # cnt[a][b] := 先頭がa,末尾がqである数の個数
    cnt = [[0]*10 for i in range(10)]
    for i in range(1,N+1):
        s = str(i)
        cnt[int(s[0])][int(s[-1])] += 1
    ans = 0
    for a in range(10):
        for b in range(10):
            ans += cnt[a][b]*cnt[b][a]
    print(ans)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    ll L, R;
    cin >> L >> R;

    int N;
    if(R-L >= 2019) cout << 0 << endl;
    else{
        ll ans = 1e+9;
        FOR(i, L, R-1){
            FOR(j, i+1, R){
                ans = min(ans, (i*j)%2019);
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
using System;

class Program
{
    static void Main (string[] args)
    {
        int inlen = int.Parse(Console.ReadLine());
        string instr = (Console.ReadLine());

        int strlen = instr.Length;

        string outstr = "";
        if (inlen >= strlen)
        {
            outstr = instr;
        }
        else
        {
            outstr = instr.Substring(0,inlen)+ "...";
        }

        //Console.WriteLine("inlen:{0} strlen:{1} ",inlen,strlen);
        Console.WriteLine(outstr);
    }
}

Measured memory_bytes: 27536
S = list(input())
while(len(S)>=1):
    del S[-1]
    if len(S)%2!=0:
        continue
    else:
        center = len(S)//2
        f_S = S[0:center]
        s_S = S[center:len(S)]
        #print(S, f_S, s_S)
        if f_S == s_S:
            ans = len(S)
            break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){

	int t; cin>>t;
	string s;
	int c=0,c2=0,c3=0,c4=0;
	while(t--){
		cin>>s;
		if(s[0]=='A')
			c++;
		if(s[0]=='W')
			c2++;
		if(s[0]=='T')
			c3++;
		if(s[0]=='R')
			c4++;
	}
	cout<<"AC x "<<c<<endl;
		cout<<"WA x "<<c2<<endl;
		cout<<"TLE x "<<c3<<endl;
		cout<<"RE x "<<c4<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

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

typedef long long ll;

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;

    cout << max(A-2*B, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 076 C
import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def dmp(x):
    global debug
    if debug:
        print(x)


def probC():
    N, M = getIntList()
    N1097 = 10**9 + 7
    dmp((N, M))
    if N == M:
        times = 2
    elif abs(N-M) == 1:
        times = 1
    else:
        times = 0
    dmp(times)
    # if times > 0:
    count = math.factorial(N) * math.factorial(M) * times % N1097
    return count


debug = False
print(probC())


Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << W*H/2 << " " << (x==W/2 && y==H/2 ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
using namespace std;
 
const int MAXN = 501;
 
char A[5][MAXN];
int pos;
string line;
 
vector<char> exp();
vector<char> fact();
 
vector<char> exp() {
  vector<char> res = fact();
  while(1) {
    if(line[pos] == 'u') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = (res[i] || x[i]);
      }
    } else if(line[pos] == 'i') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = (res[i] && x[i]);
      }
    } else if(line[pos] == 'd') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = (res[i] && !x[i]);
      }
    } else if(line[pos] == 's') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = ((res[i] && !x[i]) || (x[i] && !res[i]));
      }
    } else {
      break;
    }
  }
  return res;
}
 
vector<char> fact() {
  vector<char> res;
  if(line[pos] == 'c') {
    ++pos;
    res = fact();
    for(int i = 0; i < res.size(); ++i) {
      res[i] = 1-res[i];
    }
  } else if(isupper(line[pos])) {
    char c = line[pos];
    ++pos;
    res = vector<char>(A[c-'A'], A[c-'A']+MAXN);
  } else if(line[pos] == '(') {
    ++pos;
    res = exp();
    ++pos;
  }
  return res;
}
 
map<int,int> id, rid;
int getId(int n) {
  if(!id.count(n)) {
    id[n] = id.size()-1;
    rid[id[n]] = n;
  }
  return id[n];
}
 
int main() {
  while(1) {
    bool run = true;
    fill(A[0], A[5], false);
    id.clear();
    rid.clear();
    while(1) {
      char c;
      int n;
      if(!(cin >> c >> n)) {
	run = false;
	break;
      }
      if(c == 'R' && n == 0) break;
      for(int i = 0; i < n; ++i) {
	int a;
	cin >> a;
	a = getId(a);
	A[c-'A'][a] = true;
      }
    }
    if(!run) break;
    string s;
    cin >> s;
    line = s;
    pos = 0;
    vector<char> res = exp();
    vector<int> ans;
    for(int i = 0, cnt = 0; i < res.size(); ++i) {
      if(rid.count(i) && res[i]) {
	ans.push_back(rid[i]);
      }
    }
    sort(ans.begin(), ans.end());
    if(ans.size() == 0) {
      cout << "NULL" << endl;
    } else {
      for(int i = 0; i < ans.size(); ++i) {
	if(i) cout << " ";
	cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;

string s;
int a[2 * 100000+1], opt[2*100000], dp[1<<26], chara['z'-'a'+1], X['z'-'a'+2];

int main() {
	cin >> s;
	//初期化
	for (int i = 0; i < 26; i++) {
		chara[i] = 1 << i;
		X[i + 1] = 1 << i;
	}
	for (int i = 0; i < 1 << 26; i++)dp[i] = INT32_MAX;
	dp[0] = 0;
	for (int i = 0; i < s.length(); i++)opt[i] = INT32_MAX;

	//aの作成
	for (int i = 0; i < s.length(); i++) {
		a[i+1] = a[i] ^ chara[s[i] - 'a'];
	}

	//分割数を計算
	for (int i = 0; i < s.length(); i++) {
		for (int j = 0; j <= 26; j++) {
			if(dp[a[i+1]^X[j]] != INT32_MAX)opt[i] = min(opt[i], dp[a[i + 1] ^ X[j]] + 1);
		}
		dp[a[i + 1]] = min(dp[a[i + 1]], opt[i]);
	}

	cout << opt[s.length() - 1] << endl;
}

Measured memory_bytes: 264324
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

const int inf=1000000007;

typedef struct heapNode{
  int v;
  int val;
} node;

int cmp(const node *a,const node *b){
  return a->val<=b->val;
}

void swap(node *a,node *b){
  node t=*a;
  *a=*b;
  *b=t;
  return;
}

void push(node *h,int v,int val){
  h[0].v++;
  int k=h[0].v;
  h[k].v=v;
  h[k].val=val;
  while(k>1){
    if(cmp(h+k/2,h+k)) return;
    swap(h+k/2,h+k);
    k/=2;
  }
  return;
}

int pop(node *h){
  int res=h[1].v;
  h[1]=h[h[0].v--];
  int k=1;
  int n=h[0].v;
  while(2*k+1<=n){
    if(cmp(h+k,h+2*k) && cmp(h+k,h+2*k+1)) break;
    int next=cmp(h+2*k,h+2*k+1)?2*k:2*k+1;
    swap(h+k,h+next);
    k=next;
  }
  if(2*k<=n && !cmp(h+k,h+2*k)) swap(h+k,h+2*k);
  return res;
}

void dijkstra(int from,int *start,int *vertex,int *cost,int *next,int *path,int v){
  int *used=(int *)malloc(sizeof(int)*v);
  int i;
  for(i=0;i<v;i++){
    path[i]=inf;
    used[i]=0;
  }
  node *h=(node *)malloc(sizeof(node)*500000);
  h[0].v=0;
  path[from]=0;
  push(h,from,0);
  while(h[0].v>0){
    int s=pop(h);
    if(used[s]) continue;
    used[s]=1;
    int p=start[s];
    while(p>0){
      int t=vertex[p];
      if(path[s]+cost[p]<path[t]){
	path[t]=path[s]+cost[p];
	push(h,t,path[t]);
      }
      p=next[p];
    }
  }
  free(h);
  free(used);
  return;
}

void run(void){
  int v,e,r;
  scanf("%d%d%d",&v,&e,&r);
  int *start=(int *)malloc(sizeof(int)*v);
  int *vertex=(int *)malloc(sizeof(int)*(e+1));
  int *cost=(int *)malloc(sizeof(int)*(e+1));
  int *next=(int *)malloc(sizeof(int)*(e+1));
  int i;
  for(i=0;i<v;i++) start[i]=0;
  for(i=1;i<=e;i++){
    int s,t,d;
    scanf("%d%d%d",&s,&t,&d);
    vertex[i]=t;
    cost[i]=d;
    next[i]=start[s];
    start[s]=i;
  }
  int *path=(int *)malloc(sizeof(int)*v);
  dijkstra(r,start,vertex,cost,next,path,v);
  for(i=0;i<v;i++){
    if(path[i]==inf){
      printf("INF\n");
    } else {
      printf("%d\n",path[i]);
    }
  }
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 8788
from collections import deque

def generate():
    global que, cnt1, cnt2
    for i in range(cnt2):
        num = que.popleft()
        if 0 < int(num[-1]) < 9:
            for j in range(int(num[-1])-1, int(num[-1])+2, 1):
                que.append(num + str(j))
        elif int(num[-1]) == 0:
            que.append(num + '0')
            que.append(num + '1')
        else:
            que.append(num + '8')
            que.append(num + '9')
    cnt1 = cnt1 + cnt2
    cnt2 = len(que)

K = int(input())
cnt1 = 0
cnt2 = 9
que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])

if K <= 9:
    print(que[K-1])
    exit()

while True:
    generate()
    if K <= cnt1 + cnt2:
        print(que[K - cnt1 - 1])
        exit()

Measured memory_bytes: 12652
// 2015/05/13 Tazoe

#include <iostream>
using namespace std;

const int NOT_FOUND = -1;

int linearSearch(int key, int A[], int n)
{
	int i = 0;
	A[n] = key;

	while(A[i]!=key){
		i++;
	}

	if(i==n){
		return NOT_FOUND;
	}
	else{
		return i;
	}
}

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

	int S[10001];	// 番兵を使うので
	for(int i=0; i<n; i++){
		cin >> S[i];
	}

	int q;
	cin >> q;

	int T[500];
	for(int i=0; i<q; i++){
		cin >> T[i];
	}

	int C = 0;

	for(int i=0; i<q; i++){
		if(linearSearch(T[i], S, n)!=NOT_FOUND){
			C++;
		}
	}

	cout << C << endl;

	return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	int a, b, c;
	cin>>a>>b>>c;
	if(a==b&&b==c)
		cout<<"No"<<endl;
	else if(a==b||b==c||c==a)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

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

int main() {
	int h,w;
	cin >>h>>w;
	string s[100][100];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >>s[i][j];
		}
	}
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int q=0;q<2;q++){
				cout<< s[i][j]<<endl;
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 384
a,b,c,x,y=map(int,input().split())
ans=[]
if x>=y:
    ans.append(c*2*y+a*(x-y))
else:
    ans.append(c*2*x+b*(y-x))
ans.append(c*2*max(x,y))
ans.append(a*x+b*y)
print(min(ans))
        



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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N;
string str;

int main(){
	cin>>N;
	cin>>str;
	for(int i=0; i<str.size(); i++){
		if(str[i]+N>'Z'){
			str[i] += N - 'Z' + 'A' - 1;
		}else{
			str[i]+=N;
		}
	}
	cout<<str;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n),m(100001);
    rep(i,n)cin>>a[i],m[a[i]]++;
    int s=accumulate(all(a),0ll);
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        s+=(c-b)*m[b];
        cout<<s<<endl;
        m[c]+=m[b];
        m[b]=0;
    }
}

Measured memory_bytes: 4772
def main():
    import sys
    from operator import itemgetter
    input = sys.stdin.readline

    X = int(input())
    K = int(input())
    R = list(map(int, input().split()))
    Q = []
    for r in R:
        Q.append((r, -1))
    q = int(input())
    for _ in range(q):
        t, a = map(int, input().split())
        Q.append((t, a))
    Q.sort(key=itemgetter(0))

    #print(Q)
    prev = 0
    m = 0
    M = X
    flg = -1
    R_cs = 0
    for t, a in Q:
        if a < 0:
            r = t - prev
            R_cs -= r * flg
            if flg == -1:
                m = max(0, m-r)
                M = max(0, M-r)
                flg = 1
            else:
                m = min(X, m+r)
                M = min(X, M+r)
                flg = -1
            prev = t
        else:
            if m == M:
                if flg == 1:
                    print(min(X, m + t - prev))
                else:
                    print(max(0, m - t + prev))
            else:
                am = m + R_cs
                aM = M + R_cs
                #print('am', am, 'aM', aM, m, M)
                if a <= am:
                    if flg == 1:
                        print(min(X, m + t - prev))
                    else:
                        print(max(0, m - t + prev))
                elif a >= aM:
                    if flg == 1:
                        print(min(X, M + t - prev))
                    else:
                        print(max(0, M - t + prev))
                else:
                    if flg == 1:
                        print(min(X, m + (a - am) + t - prev))
                    else:
                        print(max(0, m + (a - am) - t + prev))


if __name__ == '__main__':
    main()


Measured memory_bytes: 89888
#include <bits/stdc++.h>
#define INFLL (0x3f3f3f3f)
using namespace std;
typedef long long ll;

ll A[100055];

ll Mx, T, L = INFLL;
int N;

int main() {
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		if(Mx < A[i]) Mx = A[i];
	}
	for(int i = 0; i < N; i++) {
		ll t = abs(A[i]*2 - Mx);
		if(L <= t || Mx == A[i]) continue;
		L = t; T = A[i];
	}

	cout << Mx << " " << T << endl;
	return 0;
}

Measured memory_bytes: 1024
def gcd(a,b):
  if a%b==0:
    return(b)
  else:
    return(gcd(b,a%b))

n=int(input())
'''
t=[int(input()) for i in range(n)]
t.sort(reverse=1)
ans=t[0]
for x in t:
  if ans%x!=0:
    ans=ans*x//gcd(ans,x)
'''
ans=int(input())
for i in range(n-1):
  u=int(input())
  if ans%u!=0:
    ans=ans*u//gcd(ans,u)



print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    string s;
    ll n;
    cin>>n;
    cin>>s;
    rep(i,s.size()){
        s[i]=(char)('A'+(s[i]-'A'+n)%26);
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll t=1;
   //std::cin >> t;
   while(t--)
   {
       ll n,i,j=0;
       std::cin >> n;
       cout<<!n<<"\n";
   }
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const double PI = acos(-1);

int main() {
	int r;
	cin >> r;
	double ans = (double)2 * PI * r;
	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define Nmax 100005
using namespace std;

vector <int> G[Nmax];
int n, m, vis[Nmax], dp[Nmax];

void read()
{
    cin >> n >> m;

    int x, y;
    for (int i = 1; i <= m; ++i) {
        cin >> x >> y;
        G[x].push_back(y);
    }
}

void dfs(int node)
{
    vis[node] = 1;
    vector <int> ::iterator it;
    for (it = G[node].begin(); it != G[node].end(); ++it) {
        if (!vis[*it]) {
            dfs(*it);
        }
        dp[node] = max(dp[node], 1 + dp[*it]);
        //cout << node << " " << dp[node] << "\n";
    }
}

void solve()
{
    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            dfs(i);
        }
    }

    int bigDP = 0;
    for (int i = 1; i <= n; ++i) {
        if (dp[i] > bigDP) {
            bigDP = dp[i];
        }
    }
    cout << bigDP;
}

int main()
{
    read();
    solve();
    return 0;
}


Measured memory_bytes: 7808
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

r,g,b,n = map(int,input().split())
count = 0


for i in range(n//r + 1):
    tempn = n-r*i
    for j in range(tempn//g + 1):
        if (tempn-g*j) % b == 0:
            count += 1

print(count)









Measured memory_bytes: 3064
'use strict';
function Main(input) {
  const coins = Number.parseInt(input, 10);
  let maxCoins500 = Math.floor(coins / 500);
  for (let i = maxCoins500; 0 <= i; --i) {
    for (let j = 0; j < 1000; ++j){
      const remain = coins - (500 * i + 5 * j);
      if (remain < 0 || remain < 5) {
        console.log(1000 * i + 5 * j);
        return;
      }
    }
  }
  console.log(0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>

using namespace std;

int main(){
  int A;
  cin >> A;
  
  if(A == 25) cout << "Christmas";
  else if(A == 24) cout << "Christmas Eve";
  else if(A == 23) cout << "Christmas Eve Eve";
  else if(A == 22) cout << "Christmas Eve Eve Eve";

}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll modpow(ll a,ll n){
    ll res=1;
    while(n){
        if(n&1)(res*=a)%=mod;
        n>>=1;
        (a*=a)%=mod;
    }
    return res;
}
int main(){
 ll m,n;
 cin>>m>>n;
 cout<<modpow(m,n)<<"\n";
}


Measured memory_bytes: 3232
#include<stdio.h>
char s[105][105];
int dix[] = {-1,0,1,-1,1,-1,0,1};
int diy[] = {-1,-1,-1,0,0,1,1,1};
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int i;
for(i=1;i<=n;i++)
scanf("%s",&s[i][1]);
int j,k;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
 if(s[i][j]=='#')printf("%c",s[i][j]);
else {
int cur = 0;
for(k=0;k<8;k++)if(s[i+dix[k]][j+diy[k]]=='#')cur++;
printf("%d",cur);
}
}
printf("\n");
}
return 0;
}

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

using namespace std;

int main() {
	int n,k; cin >> n >> k;
	vector<long long> x(n),y(n);
	vector<pair<int,int> >xy(n);
	for(int i=0;i<n;++i) {
		cin >> x[i] >> y[i];
		xy[i]=make_pair(x[i],y[i]);
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	long long ans=9e18;
	for(int x1=0;x1<n;++x1) {
		for(int x2=x1+1;x2<n;++x2) {
			for(int y1=0;y1<n;++y1) {
				for(int y2=y1+1;y2<n;++y2) {
					int cnt=0;
					for(int i=0;i<n;++i) {
						if(x[x1]<=xy[i].first&&xy[i].first<=x[x2]&&
						   y[y1]<=xy[i].second&&xy[i].second<=y[y2]) ++cnt;
					}
					if(cnt>=k) ans=min(ans,(x[x2]-x[x1])*(y[y2]-y[y1]));
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

int main(void) {
	char s[128];
	int i,r=0,l;
	while(scanf("%s",s) != EOF){
		l = strlen(s);
		for(i = 0;i < l;i++){
			if(s[i] != s[(l - i - 1)]){break;}
			if(i == l-1){r++;}
		}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
  string s;
  int n,min=1000, box;
  cin >> s;
  n = s.length();

  for(int i=0; i < n-2;i++){
    box = stoi(s.substr(i,3));
    if(abs(753-box) < min)
      min = abs(753-box);
  }

  cout << min << endl;
  
  return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  ll cnt1 = n / k, cnt2 = n / k + 1;
  cout << min(abs(n - k * cnt1), abs(n - k * cnt2)) << endl;
  return 0;
}


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

int main() {
	int N;
	int a[100000];
	int sum=0;

	cin >> N;

	for (int i = 0; i < N; i++)	cin >> a[i];
	for (int i = 0; i < N; i++)	if (i == a[a[i] - 1] - 1) sum++;

	cout << sum / 2 << endl;

	return 0;
}

Measured memory_bytes: 640
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [s]: string[] = tmp.shift().split(" ");
    switch (s) {
      case "SUN":
        return "7";
      case "MON":
        return "6";
      case "TUE":
        return "5";
      case "WED":
        return "4";
      case "THU":
        return "3";
      case "FRI":
        return "2";
      case "SAT":
        return "1";
    }
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


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

int main() {
  int D, G;
  cin >> D >> G;

  vector<int> p(D);
  vector<int> c(D);
  for (int i = 0; i < D; i++) {
    cin >> p.at(i) >> c.at(i);
  }
    
  // 任意の得点問題をコンプした場合の合計点
  vector<int> comp_point((1<<D) + 1, 0);
  vector<int> comp_number((1<<D) + 1, 0);
  for (int bit = 0; bit < (1<<D); bit++) {
    for (int i = 0; i < D; i++) {
      if (bit & (1<<i)) {
        comp_point.at(bit) += c.at(i) + 100*(i+1)*p.at(i);
        comp_number.at(bit) += p.at(i);
      }
    }
  }

  int min = 1000000;
  for (int bit = 0; bit < (1<<D); bit++) {
    // すでにGを超えていたらminと比較
    if (comp_point.at(bit) >= G && comp_number.at(bit) < min) min = comp_number.at(bit);

    // 足りない分だけ補充
    if (comp_point.at(bit) < G) {
      bool tmp = false;
      
      for (int i = D-1; i >= 0; i--) {
        if (!(bit & (1<<i))) {
          for (int P = 1; P < p.at(i); P++) {
            comp_number.at(bit)++;
            comp_point.at(bit) += 100*(i+1);
            if (comp_point.at(bit) >= G) {
              tmp = true;
              break;
            }
          }
        }
        if (tmp) break;
      }
      if (comp_point.at(bit) >= G && comp_number.at(bit) < min) min = comp_number.at(bit);
    }
  }

  cout << min << endl;
}

Measured memory_bytes: 256
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]

lin = [0]*(n+1)

if m != 0:
    for i in range(m):
        lin[int(stdin.readline().rstrip())] = -1

dp = [-1]*(n+1)

dp[0] = 1

if lin[1] == -1:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    if lin[i] == -1:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%(10**9+7))

Measured memory_bytes: 460788
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define pb  push_back
#define mb  make_pair
#define fi  first
#define se  second

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
const ll mod = 1000000007;

void solve()
{
    ll n, k;
    cin >> n >> k;
    int arr[n+1] = {0};
    while(k--)
    {
        int t;
        int p;
        cin >> p;
        rep(i,0,p)
        {
            cin >> t;
            arr[t]++;
        }
    }
    int res = 0;
    rep(i,1,n+1)
        if(arr[i]==0)
            res++;
    cout << res;
}

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


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
 
#define A first
#define B second
 
typedef long long ll;
constexpr int MOD = 1000000007;
 
template<typename T>
void print(const vector<T> &v, bool add_one = false, int start = -1, int end = -1) {
  if (start < 0) start = 0;
  if (end < 0) end = int(v.size());
 
  for (int i = start; i < end; i++)
    cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}

inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}

inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}

inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}

inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}

inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}

inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}

int suf[200005];

void solve() {
  int N; cin >> N;
  vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = N - 1; i >= 0; i--){
    if(i == N - 1) suf[i] = A[i];
    else suf[i] = addmd(suf[i + 1], A[i]);
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    ans = addmd(ans, mulmd(A[i], suf[i + 1]));
  }
  cout << ans;
}

 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}

Measured memory_bytes: 4792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;
/*
縦をitemの列
横をweightの行として今回の講義通りに動的計画法で実装した
*/

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

    vi v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];

    vvi dp(N + 1, vi(W + 1, 0));

    for (int i = 1; i < N + 1; i++) {
        for (int j = 0; j < W + 1; j++) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);

            if (j >= w[i-1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i-1]] + v[i-1]);
            }
        }
    }


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

}


Measured memory_bytes: 6840
let N = stdin.ReadLine() |> int
let d = stdin.ReadLine().Split() |> Array.map int

let rec resolver r i =
    if i = N then r
    else
        let rec loop r j =
            if j = N then resolver r (i + 1)
            else loop (r + d.[i] * d.[j]) (j + 1)
        loop r (i + 1)

resolver 0 0 |> stdout.WriteLine

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        
        if(a < b){
            for(int i = 0; i < b; i++){
                System.out.print(a);
            }
        }else{
            for(int i = 0; i < a; i++){
                System.out.print(b);
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 24148
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
  int N;
  cin >> N;

  vector<int> A(N);

  REP0(i, N)
  {
    cin >> A[i];
  }

  vector<int> L(N), R(N);
  L[0] = abs(A[0]);
  R[N - 1] = abs(A[N - 1]);

  REP1(i, N - 1)
  {
    L[i] = L[i - 1] + abs(A[i - 1] - A[i]);
    R[N - i - 1] = R[N - i] + abs(A[N - i - 1] - A[N - i]);
  }

  REP0(i, N)
  {
    if (i == 0)
    {
      cout << abs(A[i + 1]) + R[i + 1] << endl;
      continue;
    }
    if (i == N - 1)
    {
      cout << abs(A[i - 1]) + L[i - 1] << endl;
      continue;
    }

    cout << L[i - 1] + abs(A[i - 1] - A[i + 1]) + R[i + 1] << endl;
  }
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
  char x[2], y[2];
  cin >> x >> y;
  if(x[0]-'A' > y[0]-'A') cout << ">" << endl;
  else if(x[0]-'A' < y[0]-'A') cout << "<" << endl;
  else cout << "=" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
int main(){
 
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];   

    ll sum = 0;
    rep(i,n-1){
        if(a[i] > a[i+1]){
            sum += a[i] - a[i+1];
            a[i+1] = a[i];
        }
    }

    cout << sum << endl;

    return 0;
 
}

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

int main() {
  char c[6];
  cin >> c[0] >> c[1] >> c[2] >> c[3] >> c[4] >> c[5];
  bool ok = true;
  if (c[0] != c[5] || c[1] != c[4] || c[2] != c[3]) {ok = false;}
  if (ok) {cout << "YES" << endl;}
  else {cout << "NO" << endl;}
}
          


Measured memory_bytes: 256
T = int(input())
for i in range(T):
    num = list(map(int, input().split()))
    coler = input().split()
    groups = [[], [], []]
    for i, c in enumerate(coler):
        if c == "R":
            groups[0].append(num[i])
        elif c == "G":
            groups[1].append(num[i])
        else:
            groups[2].append(num[i])
    for group in groups:
        while len(group) != 0 and len(group) % 3 == 0:
            tmp = group[:]
            group.sort()
            i = group[0]
            if group.count(i) >= 3:
                for _ in range(3):
                    group.remove(i)
            if i + 1 in group and i + 2 in group:
                for j in range(3):
                    group.remove(i + j)
            if tmp == group:
                break
    if len(groups[0]) == len(groups[1]) == len(groups[2]) == 0:
        print(1)
    else:
        print(0)


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n, m; cin >> n >> m;
  vector <pii> res;
  int x = (n + 1) / 2;
  auto F = [&](int l, int r){
    while (l < r){
      res.push_back(pii(l, r));
      l++; r--;
    }  
  };
  F(1, x);
  if (n & 1) F(x + 1, n);
  else F(x + 2, n);
  for (int i = 0; i < m; i++) cout << res[i].first << ' ' << res[i].second << '\n';
  return 0;
}

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

//               2^21
long long memo[2100000];
     
int N;
int a[21][21];

//                 どのペアに属しているか
long long dp(int i, int bit){
  if(i==N) return 1;
     
  if(memo[bit]!=-1) return memo[bit];
     
  long long ans=0;
     
  for(int j=0;j<N;j++){
    
    //  相性がいい    j人目の女性がペアに属していない
    if(a[i][j]==1&&(bit&(1<<j))==0){

      //                    j人目の女性がペアに属している
      ans=(ans+dp(i+1,bit|(1<<j)))%1000000007;
    }
  }
     
  return memo[bit]=ans;
}
     
int main(){
  cin>>N;
     
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>a[i][j];
    }
  }
     
  memset(memo,-1,sizeof(memo));
     
  cout<<dp(0,0)<<endl;
     
  return 0;
}


Measured memory_bytes: 16640
#include<iostream>//入出力
#include <algorithm>//アルゴリズム
using namespace std;

int main() {

//変数
	int n, d[120],ans=0;

//入力

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

//操作

	sort(d, d + n);

	for (int i = 1;i < n;i++) {
		
		if (d[i - 1] == d[i])	ans -= 1;
	}

//出力

	cout << ans + n << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
typedef long long ll;
typedef pair<int, int> P;

bool isprime(int n){
  if(n == 0 || n == 1) return false;
  for(int i = 2; i * i <= n; i++){
    if(n % i == 0) return false;
  }
  return true;
}

int main(){
  int N, p;
  while(cin >> N >> p && (N != -1 || p != -1)){
    vector<int> primes;
    vector<int> nums;
    while(primes.size() < 100){
      if(isprime(++N)) primes.push_back(N);
    }
    rep(i, (int)primes.size())rep(j, i + 1){
      nums.push_back(primes[i] + primes[j]);
    }
    sort(nums.begin(), nums.end());
    cout << nums[p-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 968
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;

map<string, int> item;
map<string, vector<string> > recipe;
map<string, int> dp;

int solve(string s){
    if(dp.count(s))return dp[s];
    
    int res = 1 << 29;
    if(item.count(s)){
        res = min(res, item[s]);
    }
    
    if(recipe.count(s)){
        int total = 0;
        
        vector<string> &grp = recipe[s];
        for(int i=0;i<grp.size();i++)total += solve(grp[i]);
        
        res = min(res, total);
    }
    
    return dp[s] = res;
}

int main(){
    int N, M;
    while(cin >> N && N){
        item.clear();
        recipe.clear();
        dp.clear();
        
        for(int i=0;i<N;i++){
            string name;
            int price;
            
            cin >> name >> price;
            item[name] = price;
        }
        
        cin >> M;
        for(int i=0;i<M;i++){
            string name;
            int k;
            
            cin >> name >> k;
            vector<string> grp(k);
            
            for(int j=0;j<k;j++)cin >> grp[j];
            
            recipe[name] = grp;
        }
        
        string target;
        cin >> target;
        
        cout << solve(target) << endl;
    }
}

Measured memory_bytes: 1236
import math
S = input()
L = len(S)
Rcount = 0
Lcount = 0
r = 0
l = 0
i = 0
ans = [0] * L
while i < L:
    #Rの数
    while True:
        if S[i] == "R":
            i+=1
            Rcount += 1
        else:
            break
    r = i-1
    #Lの数
    while i<L:
        if S[i] == "L":
            i+=1
            Lcount += 1
        else:
            break
    l = r+1
    ans[l] = math.floor(Rcount/2) + math.ceil(Lcount/2)
    ans[r] = math.floor(Lcount/2) + math.ceil(Rcount/2)
    Rcount = 0
    Lcount = 0
print(*ans)

Measured memory_bytes: 10828
#include <cstdio>

int A[4][4];

int combination[8][3][2]={
    {{1,1},{1,2},{1,3}},
    {{2,1},{2,2},{2,3}},
    {{3,1},{3,2},{3,3}},
    {{1,1},{2,1},{3,1}},
    {{1,2},{2,2},{3,2}},
    {{1,3},{2,3},{3,3}},
    {{1,1},{2,2},{3,3}},
    {{1,3},{2,2},{3,1}}
};

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

    int N;
    scanf("%d",&N);

    for(int i=0;i<N;i++){
        int temp;
        scanf("%d",&temp);
        for(int y=1;y<=3;y++)
            for(int x=1;x<=3;x++)
                if (A[y][x]==temp) A[y][x]=0;
    }

    bool bingo=false;
    for(int i=0;i<=7;i++){
        auto fisrt=combination[i][0];
        auto second=combination[i][1];
        auto third=combination[i][2];

        if (A[fisrt[0]][fisrt[1]]==0&&A[second[0]][second[1]]==0&&A[third[0]][third[1]]==0
        ) bingo=true;
    }

    if (bingo) puts("Yes"); else puts("No");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define int long long
#define y second
#define x first

using namespace std;

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	int h; cin >> h;
	int w; cin >> w;
	int n; cin >> n;
	std::set<pair<int, int> > v;
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		v.insert({x, y});
	}
	std::vector<int> mw(h + 1, 0);
	int x = 1, y = 1;
	mw[1] = 1;
	while (true) {
		if (v.find({x + 1, y}) != v.end() || (x == h))
			break;
		x++;
		if (y == w)
			break;
		if (v.find({x, y + 1}) == v.end())
			y++;
		mw[x] = y;
	}
	for (int i = 1; i <= h; ++i)
		if (mw[i] == 0)
			mw[i] = max(mw[i - 1] + 1, i + 1);
	int mi = h;
	for (auto r : v)
		if (r.second < r.first && mw[r.first] >= r.second)
			mi = min(mi, r.first - 1);
	cout << mi;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;
const int N = 1e5+5;
int n;
int A[N][3];
int dp[N][3];


int32_t main()
{
    
   
    crap;
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>A[i][0]>>A[i][1]>>A[i][2];
    }

    dp[0][0]=A[0][0];
    dp[0][1]=A[0][1];
    dp[0][2]=A[0][2];
    for(int i=1;i<n;i++){
    	dp[i][0] = A[i][0]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1] = A[i][1]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2] = A[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;


   
   
   
}

Measured memory_bytes: 4992
//https://atcoder.jp/contests/agc030/tasks/agc030_c
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main(){
    int K;
    cin>>K;
    if(K==1){
        cout<<1<<endl;
        cout<<1<<endl;
    }
    else{
        int n = 2;
        while(n*2<K)n+=2;
        cout<<n<<endl;
        for(int i:range(n)){
            for(int j:range(n)){
                int color = (i+j)%n;
                if(i%2==1&&n+color<K){
                    color+=n;
                }
                cout<<color+1<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int W = Integer.parseInt(sc.next());
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    
    int a = Math.max(A,B);
    int b = Math.min(A,B);
    
    System.out.println(Math.max(0,a-(b+W)));
  }
}

Measured memory_bytes: 21716