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

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

using namespace std;

#define MAX 100010

int n;
vector<int> G[MAX];
int d[MAX];

int dfs(int cur, int pre) {
  int &ans = d[cur];
  if( ans != -1 ) return ans;
  ans = 0;
  rep(i,(int)G[cur].size()) {
    int nex = G[cur][i];
    if( pre == nex ) continue;
    ans = max(ans,dfs(nex,cur)+1);
  }
  return ans;
}

int answer[MAX];
void dfs2(int cur, int pre, int d_par) {

  vector<int> cumulative_L, cumulative_R;
  rep(i,(int)G[cur].size()) {
    int nex = G[cur][i];
    int v = ( nex == pre ) ? (d_par+1) : (d[nex]+1);
    cumulative_L.pb(v);
    cumulative_R.pb(v);
  }
  
  REP(i,1,(int)cumulative_L.size()) cumulative_L[i] = max(cumulative_L[i], cumulative_L[i-1]);
  for(int i=(int)cumulative_R.size()-2;i>=0;--i) cumulative_R[i] = max(cumulative_R[i], cumulative_R[i+1]);

  answer[cur] = cumulative_L.back();

  rep(i,(int)G[cur].size()) {
    int nex = G[cur][i];
    if( nex == pre ) continue;
    int vL = (i-1>=0)?cumulative_L[i-1]:0;
    int vR = (i+1<(int)cumulative_R.size())?cumulative_R[i+1]:0;
    dfs2(nex, cur, max(vL,vR));
  }
  
}

bool debug = 1;

void solve() {
  memset(d,-1,sizeof d);
  dfs(0,-1);
  //rep(i,n) cout << i << "-th: " << d[i] << endl;
  dfs2(0,-1,0);
  //puts("---");
  //rep(i,n) cout << i << "-th: " << answer[i] << endl;
  rep(i,n) cout << (n-1)*2-answer[i] << endl;
}

int main() {
  scanf("%d",&n);
  rep(i,n-1) {
    int s,t;
    scanf("%d%d",&s,&t);
    --s, --t;
    G[s].pb(t);
    G[t].pb(s);
  }
  solve();
  return 0;
}



Measured memory_bytes: 31388
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int t;
  t=b;
  int A=0;
  int B=0;
  for(int i=0;i<a;i++){
    A+=b;
    b=b*10;
  }
  for(int i=0;i<t;i++){
    B+=a;
    a=a*10;
  }
  if(A>B){
    cout<<A<<endl;
  }
  else{
   cout<<B<<endl; 
  }
  return 0;
  }

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

string toUpper(string s){
	string t=s;
	for(int i=0; i<s.size(); i++){
		t[i]=toupper(s[i]);
	}
	return t;
}

int main(){
	string W,T;
	int a=0;
	cin >> W;
	while(1){
		cin >> T;
		if(T=="END_OF_TEXT")break;
		T=toUpper(T);
		W=toUpper(W);
		if(W==T)a++;
	}
	cout << a <<endl;
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
   int q = A * B;
  if (q % 2 == 1) {
      cout << "Odd" << endl;
    }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
import sys
def gcm(a,b):
    if a%b==0: return b
    return gcm(b,a%b)

for s in sys.stdin:
    a,b=map(int,s.split())
    if a<b:a,b=b,a
    c=gcm(a,b)
    print c,a/c*b

Measured memory_bytes: 4208
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  vector<char> s(4);
  rep(i,4) cin>>s[i];

  sort(s.begin(),s.end());
  if(s[0]==s[1] && (s[2]==s[3] && s[1]!=s[2])) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S; 
	string F = {};  
	string B = {}; 
	int Q; cin >> Q; 
	int rev = 0; 
	while(Q--){
		int a; cin >> a; 
		if(a == 1) rev = 1 - rev; 
		else{
			int f; char c; 
			cin >> f >> c; 
			if(rev + f == 2){
				B.push_back(c); 
			}
			else{
				F.push_back(c); 
			}
		}
	}
	reverse(F.begin(), F.end());
	string T = F + S + B; 
	if(rev) reverse(T.begin(), T.end()); 
	cout << T << endl; 
}

Measured memory_bytes: 1348
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
#define mset(a,x) memset(a,x,sizeof(a))
 
const int INF = 1 << 30;
int n, m;
vector<int> d, c;
 
ll dp[1010][1010];
ll rec(int pos, int i) {
    ll &r = dp[pos][i];
    if (r != -1) return r;
    if (pos == n) return r = 0;
    if (i == m) return r = INF;
    return r = min(rec(pos, i + 1), rec(pos + 1, i + 1) + d[pos] * c[i]);
}
 
int main() {
    cin >> n >> m;
    d.resize(n); c.resize(m);
    for (int& i : d) scanf("%d", &i);
    for (int& i : c) scanf("%d", &i);
 
    if (m < n) {
        cout << 0 << endl;
        return 0;
    }
 
    mset(dp, -1);
    int ans = rec(0, 0);
    assert(ans >= 0);
    cout << ans << endl;
 
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  map<char, char> st, ts;
  for (int i = 0; i < s.size(); i++) {
    if (st.count(s[i]) == 0) st[s[i]] = t[i];
    else if (st[s[i]] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < t.size(); i++) {
    if (ts.count(t[i]) == 0) ts[t[i]] = s[i];
    else if (ts[t[i]] != s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

char grid[10][10];

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        scanf("%s", grid[i]);
    }
    int ans = 0;
    char tmp[10][10];
    for (int i = 0; i < (1 << h); i++) {
        for (int j = 0; j < (1 << w); j++) {
            int black = 0;
            for (int hh = 0; hh < h; hh++) {
                for (int ww = 0; ww < w; ww++) {
                    if (((1 << hh) & i) && ((1 << ww) & j) && grid[hh][ww] == '#') {
                        black++;
                    }
                }
            }
            if (black == k) {
                ans++;
            }
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3828
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type item struct {
	value    int
	priority int
	index    int
}

type priorityQueue []*item

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i].priority > pq[j].priority
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *priorityQueue) Push(x interface{}) {
	n := len(*pq)
	e := x.(*item)
	e.index = n
	*pq = append(*pq, e)
}

func (pq *priorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	e := old[n-1]
	e.index = -1
	*pq = old[0 : n-1]
	return e
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	v := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range v {
		sc.Scan()
		v[i], _ = strconv.Atoi(sc.Text())
	}

	ans := 0
	for i := 0; i <= min(k, n); i++ {
		for j := 0; j <= min(k, n); j++ {
			if i+j > min(k, n) {
				continue
			}
			rem := k - i - j
			s := 0
			pq := make(priorityQueue, 0, i+j)
			heap.Init(&pq)
			for i2 := 0; i2 < i; i2++ {
				s += v[i2]
				heap.Push(&pq, &item{value: v[i2], priority: -v[i2]})
			}
			for j2 := 0; j2 < j; j2++ {
				x := v[n-1-j2]
				s += x
				heap.Push(&pq, &item{value: x, priority: -x})
			}
			for l := 0; l < rem; l++ {
				if pq.Len() == 0 {
					break
				}
				top := heap.Pop(&pq).(*item).value
				if top >= 0 {
					break
				}
				s -= top
			}
			ans = max(ans, s)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2432
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
//#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
//using namespace atcoder;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int Nmax = 50;
int N;
ll A[Nmax];

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

	ll ans = 0;
	while(true){
		ll x = 0;
		for(int i=0; i<N; i++){
			x += A[i]/N;
		}
		ans += x;
		for(int i=0; i<N; i++){
			A[i] += x - (A[i]/N)*(N+1);
		}

		bool f = true;
		for(int i=0; i<N; i++){
			f = f && A[i] < N;
		}

		if(f) break;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3652
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3938203
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL dp[111][111111];
// 重さ 1000 の 品物が, 100個 ある場合よりも少し大きめの値を設定.
const int C = 1000 * 100 + 100;

int main(){
    
    // 1. 入力情報取得.
    vector<pair<LL, LL>> vec;
    int N;
    LL W;
    scanf("%d %lld", &N, &W);
    vec.push_back(make_pair(-1, -1));
    for(int i = 0; i < N ; i++){
        LL x, y;
        scanf("%lld %lld", &x, &y);
        vec.push_back(make_pair(x, y));
    }
    for(int j = 1; j <= C; j++) dp[0][j] = LL(1e18);
    
    // 2. dp更新.
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= C; j++){
            dp[i][j] = dp[i - 1][j];
            if(j - vec[i].second >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - vec[i].second] + vec[i].first);
        }
    }
    // for(int j = 0; j <= C; j++) if(dp[N][j] <= W) printf("dp[%d][%d]=%lld ", N, j, dp[N][j]);
    // printf("\n");
    
    // 3. 出力.
    LL ans = 0;
    for(LL j = 0; j <= C; j++) if(dp[N][j] <= W) ans = max(ans, j);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 88192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> P(N,0);
    for(ll i=0;i<N;++i)cin>>P[i];
    ll count=0;
    ll ren=0;
    vector<bool> ng(N,0);
    for(ll i=1;i<N;++i){
        if(P[i]>P[i-1])ren++;
        else ren=0;
        if(ren>=K-1){
            ng[i]=1;
            count++;
        }
    }

    set<ll> S;
    for(ll i=0;i<K;++i)S.insert(P[i]);
    ll ans;
    if(count>=1)
    ans=2;
    else ans=1;
    if(ng[K-1])ans--;
    for(ll i=K;i<N;++i){
        if(ng[i]){
            S.erase(P[i-K]);
            S.insert(P[i]);continue;
        }
        ans++;
        if(*S.begin()==P[i-K]&&*(prev(S.end()))<P[i]){ans--;}
        S.erase(P[i-K]);
        S.insert(P[i]);
    }
    prt(ans)

    return 0;
}


Measured memory_bytes: 11264
from math import sqrt,atan2,cos,sin
while(1):
    try:
        x1,y1,x2,y2,xq,yq = [float(i) for i in input().split(",")]
        r = sqrt((xq-x1)**2 + (yq-y1)**2)
        th1 = atan2(y2-y1,x2-x1)
        th2 = atan2(yq-y1,xq-x1)
        th3 = -(th2 - th1) + th1
        print("{:.6f} {:.6f}".format(x1+r*cos(th3),y1+r*sin(th3)))
    except EOFError:
        break


Measured memory_bytes: 5752
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn str_to_ints(s: String) -> std::vec::Vec<i64> {
    let mut ret = std::vec::Vec::new();
    let ws = s.split_whitespace();
    for w in ws {
        ret.push(w.parse().unwrap());
    }
    ret
}

fn read_ints() -> std::vec::Vec<i64> {
    str_to_ints(read_line())
}

fn main() {
    let abbcca = read_ints();
    let ab = abbcca[0];
    let bc = abbcca[1];
    let ca = abbcca[2];

    if ab > bc && ab > ca {
        println!("{}", bc * ca / 2);
    }
    if bc > ca && bc > ab {
        println!("{}", ca * ab / 2);
    }
    if ca > ab && ca > bc {
        println!("{}", ab * bc / 2);
    }
}

Measured memory_bytes: 4352
#include <stack>
#include<queue>
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
  string word;
  stack<int> s;
  while(cin>>word){
    if(word == "+"){
      int x = s.top();
      s.pop();
      int y = s.top();
      s.pop();
      int z = x+y;
      s.push(z);
    }
    else if(word == "-"){
      int x = s.top();
      s.pop();
      int y = s.top();
      s.pop();
      int z = y-x;
      s.push(z);
    }
    else if(word == "*"){
      int x = s.top();
      s.pop();
      int y = s.top();
      s.pop();
      int z = x*y;
      s.push(z);
    }
    else{
      int x = atoi(word.c_str());
      s.push(x);
    }
  }
    int x = s.top();
    cout<<x<<endl;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  ll a;
  ll b;
  cin >>a>>b;
  if(a>0) {
    cout<<"Positive"<<endl;
  }
  else if (a==0) {
    cout<<"Zero"<<endl;
  }
  else if((a<0) &&(b>=0))  {
    cout<<"Zero"<<endl;
  }
  else if((a<0) &&(b<0))   {
    ll c=b-a+1;
    if(c%2==0) {
      cout<<"Positive"<<endl;
    }
    else {
      cout<<"Negative"<<endl;
    }
    
    
  }
  
  
  
}
    
  

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	long long n,a,b;
	cin>>n;
	for(long long i=1;i*i<=n;i++)
	{
		if(n%i==0)
		a=i;
		b=n/a;
	}
	cout<<a+b-2<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main{
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	long N = sc.nextLong();
	long arr[] = new long[5];
		for(int i=0; i<5; i++){
		arr[i] = sc.nextLong();
		}
	Arrays.sort(arr);
	long ans;
		if(N%arr[0]>0){
		ans = 5+N/arr[0];
		}
		else{
		ans = 4+N/arr[0];
		}
	System.out.println(ans);
	}
}

Measured memory_bytes: 23380
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------- 
    A = int(input())
    B = int(input())
    L = [1,2,3]
    for i in L:
        if i != A and i != B:
            print(i)


if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 5176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,x1,temp=0;  cin>>n;
    ll arr[n];
    rep(i,0,n)  cin>>arr[i];
    

    for(ll j=n-2; j>=0; --j) temp+=((j&1?1:-1)*arr[j]);
    x1=(arr[n-1]-temp)/2;
    cout<<2*x1<<" ";
    vector<ll> vec(n,0);
    vec[0]=2*x1;
    for(ll i=1; i<n; ++i) 
    {
        vec[i]=(arr[i-1]-(vec[i-1]/2));
        vec[i]*=2;
        cout<<vec[i]<<" ";  
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 4844
# encoding:utf-8

def set_char(data):
    if data[len(data)-1] == "#":
        return "."
    else:
        return "#"

while True:
    str_line_1 = "#"
    str_line_2 = "."

    H ,W = map(int, input().split(" "))

    if H == W == 0:
        break

    for i in range(W - 1):
        str_line_1 += set_char(str_line_1)
        str_line_2 += set_char(str_line_2)

    for i in range(H):
        if (i % 2) == 0:
            print(str_line_1)
        else:
            print(str_line_2)
    print()

Measured memory_bytes: 7680
#include <iostream>
using namespace std;
int main()
{
	int n, m, x[1000], k = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int a = 0; a < n - 1; a++) {
		for (int b = 0; b < n - a - 1; b++) {
			if (x[b] > x[b + 1]) {
				swap(x[b], x[b + 1]);
			}
		}
	}
	for (int j = 0; j < m; j++) {
		k += x[j];
	}
	cout << k;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; string s;
  cin >> N >> s ;
  string ans = "";
  int now = 0;
  rrep(i,N-1){
    if(s[i]=='('){
      if(now>0){
        ans = '(' + ans;
        now--;
      }else{
        ans = '(' + ans + ')';
      }
    }else{
      ans = ')' + ans;
      now++;
    }
  }
  ans = string(now,'(') + ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#AGC035-A XOR Circle
"""
問題：
円環状にリストの数値を配置した時、aのどの要素についても
ai == a(i-1)^a(i+1)
となるように配置できるか判定せよ
解法：
できるかどうかを判定すればよいので実際に組み立てる必要はない。
n<=10**5であることから、選び方を考えなくて良い解法が存在するはず
全てのXORの合計が0?
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

ans = 0
for i in lst1:
    ans = ans^i

print("Yes" if ans == 0 else "No")

Measured memory_bytes: 55024
#include<iostream>
#include<vector>
#include<iterator>
#include<unordered_map>
using namespace std;
using loi=long int;

// Problem https://atcoder.jp/contests/abc073/tasks/abc073_c
loi solver(loi numCount,vector<loi> joiSaidNum){
    loi result;
    result = 0;
    unordered_map<loi,loi> dict;
    for(loi j=0;j<numCount;j++){
        dict[joiSaidNum.at(j)]=dict[joiSaidNum.at(j)]+1;
    }
    for(auto itr=dict.begin();itr!=dict.end();itr++){
            result = result + (itr->second)%2;
    }
    return result;
}


int main(void){
    loi answer;
    answer = 0;
    loi N;
    cin >> N;
    vector<loi> Ai(N,0);
    for(loi j=0;j<N;j++){
        cin >> Ai.at(j);
    }
    answer = solver(distance(Ai.begin(),Ai.end()),Ai);
    cout << answer << endl;
}

Measured memory_bytes: 5924
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    ret = 1
    for b in range(1, N):
        for p in range(2, N//2):
            if b ** p <= N:
                ret = max(ret, b ** p)

    print(ret)


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++) {
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  int A=0, B=0, x=0;
  
  for(int i=0;i<N;i++) {
    if(i%2==0) A+=a.at(i);
    else B+=a.at(i);
  }
  
  x = A - B;
  cout << x << endl;
  
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdint.h>

int64_t data[2 ^ 250];

int32_t main(void)
{
  int64_t num;
  scanf("%ld", &num);

  uint32_t i;
  for (i = 0; i < num; i++) {
    scanf("%ld", &data[i]);
  }

  for (i = 0; i < num; i++) {
    printf("node %u: key = %ld, ", i + 1, data[i]);
    if (0 < ((i + 1) / 2)) {
      printf("parent key = %ld, ", data[((i + 1) / 2) - 1]);
    }

    if (2 * (i + 1) < (num + 1)) {
      printf("left key = %ld, ", data[2 * (i + 1) - 1]);
    }

    if ((2 * (i + 1) + 1) < (num + 1)) {
      printf("right key = %ld, ", data[2 * (i + 1) + 1 - 1]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    while (true) {
        if ((C - B) <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        else {
            C = C - B;
        }
        if ((A - D) <= 0) {
            cout << "No" << endl;
            return 0;
        }
        else {
            A = A - D;
        }
    }
}

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

int main(void){
	string str[3];
	while(1){
		cin >> str[0];
		if(str[0]=="0")break;
		cin >> str[1];
		cin >> str[2];
		if(str[0]=="bbb" || str[1]=="bbb" || str[2]=="bbb")cout << "b" << endl;
		else if(str[0][0]=='b' && str[1][0]=='b' && str[2][0]=='b')cout << "b" << endl;
		else if(str[0][1]=='b' && str[1][1]=='b' && str[2][1]=='b')cout << "b" << endl;
		else if(str[0][2]=='b' && str[1][2]=='b' && str[2][2]=='b')cout << "b" << endl;
		else if(str[0][0]=='b' && str[1][1]=='b' && str[2][2]=='b')cout << "b" << endl;
		else if(str[0][2]=='b' && str[1][1]=='b' && str[2][0]=='b')cout << "b" << endl;
		else if(str[0]=="www" || str[1]=="www" || str[2]=="www")cout << "w" << endl;
		else if(str[0][0]=='w' && str[1][0]=='w' && str[2][0]=='w')cout << "w" << endl;
		else if(str[0][1]=='w' && str[1][1]=='w' && str[2][1]=='w')cout << "w" << endl;
		else if(str[0][2]=='w' && str[1][2]=='w' && str[2][2]=='w')cout << "w" << endl;
		else if(str[0][0]=='w' && str[1][1]=='w' && str[2][2]=='w')cout << "w" << endl;
		else if(str[0][2]=='w' && str[1][1]=='w' && str[2][0]=='w')cout << "w" << endl;
		else cout << "NA" << endl;
	}
    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if(a==1){
        if(b==1){
            cout << "Draw";
        }else{
            cout << "Alice";
        }
    }else if(b==1){
        cout << "Bob";
    }else{
        if(a>b){
            cout << "Alice";
        }else if(a<b){
            cout << "Bob";
        }else{
            cout << "Draw";
        }
    }
    return 0;
}

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

using namespace std;

int main() {
        int N,K;
        int num = 1;
        cin >> N >> K;
        for (int i = 0 ; i < N; i++){
                if ( num > K) {
                        num += K;
                        continue;
                }
                num *= 2;
        }
        cout << num << endl;
}

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;
int mod = 1000000007;

void solve();

int main(void){
    string s; cin >> s;
    char ans[s.length()+1];
    rep(i, s.length()+1) ans[i] = '\0';
    int idx = 0;
    rep(i, s.length()){
        if(s[i] == 'B'){
            if(idx > 0) idx--;
            ans[idx] = '\0';
        }
        else{
            ans[idx] = s[i];
            idx++;
        }
    }
    printf("%s\n", ans);
    return 0;
}

void solve(){}

Measured memory_bytes: 256
def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def main(inputs):
	k,n=getIntList(inputs[0])
	aList=getIntList(inputs[1])
	
	d=k-aList[n-1]+aList[0]
	di=n-1
# 	print(d,di)
	for ai in range(n-1):
		dd=aList[ai+1]-aList[ai]
# 		print(dd)
		if dd>d:
			di=ai
			d=dd
	
	print(k-d)


if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)


Measured memory_bytes: 25308
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
T = [int(input()) for _ in range(N)]
a = T[0]
for i in range(1,N):
    b = T[i]
    c = gcd(a,b)
    a = (a//c)*b
print(a)

Measured memory_bytes: 62172
#include<bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int N = 1e6 + 6,mod = 998244353 ;

ll k = 1e18;

int n;
pair<int,int>P[N];


void odd(){

        multiset<pair<int,int>>S;

        int mid = (n+1)/2;
        for(int i = 1; i <= mid; i++){
                S.insert({P[i].ss,i});
        }
        auto it = S.end();
        it--;
        //cout << (*it) << endl;
        //S.insert(5);
        //cout << (*it) << endl;


        int mn = P[mid].ff, mx = mn;
        for(int i = mid+1; i <= n; i++){
                int x = (*it).ff;
                int ind = (*it).ss;
                if(x < P[i].ff){
                        mx = x;
                        break;
                }
                mx = P[i].ff;
                S.insert({P[i].ss,i});
                it = S.find({x,ind});
                if(P[i].ss < x){
                        it--;
                }
        }

        mx = max(mx,(*it).ff);

        cout << mx - mn + 1 << endl;
}

void even(){
        multiset<pair<int,int>>S;

        int mid = n/2 + 1;
        for(int i = 1; i <= mid; i++){
                S.insert({P[i].ss,i});
        }
        auto it = S.end();
        it--;

        int mn = P[mid].ff+P[mid-1].ff, mx = mn;
        for(int i = mid+1; i <= n; i++){
                int x = (*it).ff;
                int ind = (*it).ss;
                if(x < P[i].ff){
                        mx = x;
                        break;
                }
                auto it1 = it;
                it1--;
                mx = x + (*it1).ff;
                S.insert({P[i].ss,i});
                it = S.find({x,ind});
                if(P[i].ss < x){
                        it--;
                }
        }

        auto it1 = it; it1--;
        mx = max(mx,(*it).ff+(*it1).ff);

        cout << (mx - mn + 1) << endl;
}

inline void test_case(){

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> P[i].ff >> P[i].ss;
        }

        sort(P+1,P+1+n);

        if(n%2==1){
                odd();
        } else {
                even();
        }

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

        int T = 1;
        //cin >> T;
        while(T--){
                test_case();
        }
}


Measured memory_bytes: 14528
#include <iostream>

using namespace std;

long long MOD = 1e9+7;

long long N,K;
long long C[2001][2001];

long long comb(long long a,long long b){
    if(b == 0){
        return C[a][b] = 1;
    }
    if(a == b){
        return C[a][b] = 1;
    }
    if(C[a][b] != -1) return C[a][b];
    return C[a][b] = (comb(a-1,b-1) + comb(a-1,b)) % MOD;
}

int main(){
    cin >> N >> K;
    for(int i=0;i<2001;i++){
        for(int j=0;j<2001;j++){
            C[i][j] = -1;
        }
    }
    for(long long i=1;i<=K;i++){
        if(N-K+1 < i){
            cout << 0 << endl;
            continue;
        }
        cout << (comb(N-K+1, i) * comb(K-1, i-1)) % MOD << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 5e5 + 5;
const ll mod = 1e9 + 7;

ll f[N], inv[N];

ll bigmod(ll x, ll y) {
  ll res = 1;
  while(y) {
    if(y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}

void work() {
  f[0] = 1;
  for(int i = 1; i < N; i++) {
    f[i] = (f[i - 1] * i) % mod;
  }
  inv[N - 1] = bigmod(f[N - 1], mod - 2);
  for(int i = N - 2; i >= 0; i--) {
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
  }
}

ll comb(ll n, ll r) {
  if(n + r - 2 < r - 1 or r - 1 < 0) return 0;
  ll up = (f[n + r - 2]);
  ll down = (inv[n - 1] * inv[r - 1]) % mod;
  return (up * down) % mod;
}

int main() {
  work();
  ll h, w, a, b; cin >> h >> w >> a >> b;
  ll ways = 0;
  for(ll c = b + 1; c <= w; c++) {
    ways = (ways + (comb(h - a, c) % mod * comb(a, w - c + 1) % mod)) % mod;
  }
  cout << ways << '\n';
}

Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  if(s < t){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
  return 0;
}


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


const int MAXN = 1005;

int main() {
  int n,k;
  string s;
  cin>>n>>k>>s;
  int c=0;
  rep(i,n-1){
    if (s[i+1]!=s[i]) c++;
  }
  rep(i,k){
    c-=2;
  }
  if (c<0)c=0;
  cout<<n-1-c;

}


Measured memory_bytes: 512
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=10**9+7
    H,N=MI()
    A=[0]*N
    B=[0]*N
    
    for i in range(N):
        A[i],B[i]=MI()
        
    inf =10**20
    dp=[[inf]*(H+1)for _ in range(N+1)]
    # dp[i]はi番目の魔法まででhpをj減らす方法
    
    dp[0][0]=0
    
    for i in range(N):
        a=A[i]
        b=B[i]
        for j in range(H+1):
            dp[i+1][j]=min(dp[i+1][j],
                           dp[i][j])
            if j-a>=0:
                dp[i+1][j]=min(dp[i+1][j],
                               dp[i+1][j-a]+b)
            else:
                dp[i+1][j]=min(dp[i+1][j],
                               dp[i+1][0]+b)
                
    print(dp[-1][-1])

main()


Measured memory_bytes: 154108
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
	int i, n, x, y, r;
	double dis1 = 0; double dis2 = 0; double dis3 = 0;double disinf = 0;
	vector<int> X,Y,R;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		X.push_back(x);
	}
	for (i = 0; i < n; i++) {
		cin >> y;
		Y.push_back(y);
	}
	for (i = 0; i < n; i++) {
		r = max(X[i] - Y[i],Y[i]-X[i]);
		R.push_back(r);
	}
	for (i = 0; i < n; i++) {
		dis1 += R[i];
		dis2 += pow(R[i], 2);
		dis3 += pow(R[i], 3);
		if (R[i] > disinf)disinf = R[i];
	}
	cout << fixed << setprecision(7) << dis1 << endl;
	cout << fixed << setprecision(7) << pow(dis2,0.5) << endl;
	cout << fixed << setprecision(7) << pow(dis3,double(1)/3) << endl;
	cout << fixed << setprecision(7) << disinf << endl;
	char t;
	cin >> t;
	return 0;
}



Measured memory_bytes: 3448
import math
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
def calc(P):
    data = list(range(0,len(P)))
    re = 0
    for i in range(len(P)):
        if data[P[i] - 1] > 0:
            re += data[P[i] -1]*math.factorial(len(P) - 1 -i)
        for j in range(P[i] - 1, len(P)):
            data[j] -= 1
    return re
a = calc(P)
b = calc(Q)
print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>

using namespace std;

typedef long long LL;

int main() {
  LL W, H;
  cin >> W >> H;

  LL x, y;
  cin >> x >> y;

  cout << fixed << setprecision(9) << (long double)(W * H / 2.0) << " " << (x * 2 == W && y * 2 == H ? 1 : 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
char s[33];

int main() {
	scanf("%s", &s);
	int l = strlen(s);
	bool flg = 1;
	if(s[0] != 'A') flg = 0;
	int cnt = 0;
	for(int i = 2; i <= l - 2; i++)
		if(s[i] == 'C') cnt++;
	if(cnt != 1) flg = 0;
	for(int i = 0; i < l; i++) {
		if(s[i] > 'A' && s[i] <= 'Z' && s[i] != 'C') flg = 0;
	}
	if(flg) puts("AC");
	else puts("WA");
}

Measured memory_bytes: 764
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#include<map>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;

long long now,l,r,Ln,Rn,Lnn,Rnn,Lm,Rm,Lmm,Rmm,L[100001],R[100001],D,a[100000],num, N, K, M, ans,sosu[100000];
string S, T;
bool h;
char cc;


int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	r = l = 0;
	for (int i = 0; i < N; i += 2) {
		L[a[i]]++;
		l++;
	}
	for (int i = 1; i < N; i += 2) {
		R[a[i]]++;
		r++;
	}
	Lm = Lmm = 0;
	Ln = Lnn = -1;
	Rm = Rmm = 0;
	Rn = Rnn = -1;
	for (int i = 1; i < 100001; i++) {
		if (Lm < L[i]) {
			Lm = L[i];
			Ln = i;
		}
		if (Rm < R[i]) {

			Rm = R[i];
			Rn = i;
		}
	}
	for (int i = 1; i < 100001; i++) {
		if (Lmm < L[i]&&i!=Ln) {
			Lmm = L[i];
			Lnn = i;
		}
		if (Rmm < R[i]&&i!=Rn) {

			Rmm = R[i];
			Rnn = i;
		}
	}

	if (Rn == Ln) {
		cout << min(l - Lm + r - Rmm, l - Lmm + r - Rm) << endl;
		return 0;
	}
	cout << l - Lm + r - Rm << endl;
	return 0;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

bool st[100005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; gi(n), gi(m);
	int l = 1, r = n;
	while(m--) {
		print(l); pc(' '); 
		if(n%2 == 0 && ((r - l) == n/2 || (r - l) == n/2-1)) r--;
		print(r);
		pc('\n');
		l++; r--;
	}
}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> v(1, 0);
    for (ll i = 1; i < s.size(); i++)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            v.push_back(v.back() + 1);
        }
        else
        {
            v.push_back(v.back());
        }
    }
    for (ll i = 0; i < q; i++)
    {
        ll l, r;
        cin >> l >> r;
        cout << v[r - 1] - v[l - 1] << endl;
    }
}

Measured memory_bytes: 1908
#include<iostream>
using namespace std;
int n,m;
int a;
int gg;
int main(){
	cin>>n>>m;
	gg=0;
	for(int i=0;i<m;i++){
		cin>>a;
		gg+=a;
	}
	if(n-gg>=0) cout<<n-gg<<endl;
	else{
		cout<<-1<<endl; 
	}
	return 0;
}

Measured memory_bytes: 3644
#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=1e9+7;
ll n;
vector<vector<ll> >G(100010);
vector<ll>road(0);
ll sz[100010];
bool dfs(ll i,ll p){
    bool f=0;
    if(i==n)f=1;
    for(auto e:G[i]){
        if(e==p)continue;
        f|=dfs(e,i);
    }
    if(f)road.pb(i);
    return f;
}
ll dfs2(ll i,ll p){
    ll c=1;
    for(auto e:G[i]){
        if(e==p)continue;
        c+=dfs2(e,i);
    }
    return sz[i]=c;
}
int main(){
    cin>>n;
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(1,0);
    dfs2(1,0);
    reverse(all(road));
    bool t=(n-sz[road[(road.size()+1)/2]]>sz[road[(road.size()+1)/2]]);
    //cout<<sz[load[(load.size()+1)/2]]<<endl;
    cout<<(t?"Fennec":"Snuke")<<endl;
}

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

int main(){
    int n,q;
    cin >> n >> q;
    vector<char> s(n);
    int l,r;
    for(int i = 0;i < n;i ++){
        cin >> s.at(i);
    }
    int cnt = 0;
    vector<int> t(n);

    for(int i = 0;i < n-1;i ++){
        if(s.at(i)=='A' &&s.at(i+1)=='C'){
            t.at(i+1) = 1;
        }
    }

    for(int i = 0;i < n;i ++){
        if(t.at(i) == 1){
            t.at(i) += cnt;
            cnt ++;
        }
    }

    for(int i = 1;i < n;i ++){
        if(t.at(i) == 0){
            t.at(i) = t.at(i-1);
        }
    }

    int x,y;
    for(int i = 0;i < q;i ++){
        cin >> l >> r;
        cout << t.at(r-1) - t.at(l-1) << endl;
    }

}

Measured memory_bytes: 1280
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
INF = 1001001001
dist = [[INF for _ in range(w)] for _ in range(h)]

d = deque()
for i in range(h):
    for j in range(w):
        if maze[i][j] == '#':
            d.append([i, j])
            dist[i][j] = 0
ans = 0
while(d):
    y,x = d.popleft()
    difflist = [[1,0], [0,1], [-1, 0], [0, -1]]
    for dy, dx in difflist:
        y2 = y + dy
        x2 = x + dx
        if 0 <= y2 < h and 0 <= x2 < w and dist[y2][x2]>(dist[y][x] + 1):
            d.append([y2, x2])
            dist[y2][x2] = dist[y][x] + 1
            ans = max(ans, dist[y2][x2])

print(ans)

Measured memory_bytes: 177884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vi dp(n + 1, n + 1);
  dp[0] = 0;
  rep(i, n) {
    dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    int sixs = 6;
    while(i + sixs <= n) {
      dp[i + sixs] = min(dp[i + sixs], dp[i] + 1);
      sixs *= 6;
    }
    int nines = 9;
    while(i + nines <= n) {
      dp[i + nines] = min(dp[i + nines], dp[i] + 1);
      nines *= 9;
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int i,N,sum=0;
  cin >> N;

  for(i=0;i<3;i++){
    
    if(N<(int)(pow(10,2*i+1)+0.5)){
      sum+=N-(int)(pow(10,2*i)+0.5)+1;
      break;
    }
    sum+=(int)(pow(10,2*i+1)-pow(10,2*i)+0.5);
    
    if(N>=(int)(pow(10,2*i+1)+0.5) && N < (int)(pow(10,2*i+2)+0.5)){
      break;
    }
  }
  cout << sum << endl;
  return 0;
}
    
  


Measured memory_bytes: 256
from itertools import accumulate

def main():
    inf=float("inf")
    n,k=map(int,input().split())
    plst=list(map(int,input().split()))
    clst=list(map(int,input().split()))
    sm=-inf

    seen=[0]*n
    for i in range(n):
        if seen[i] : continue
        pos=i
        work=[]
        while not seen[pos]:
            seen[pos]=1
            work.append(clst[pos])
            pos=plst[pos]-1
        nwork=len(work)
        loop_sum=sum(work)
        work=[0]+list(accumulate(work))
        
        numcut=min(nwork,k)

        for i in range(nwork):
            for j in range(i,i+numcut):
                if j<nwork :
                    smwork=work[j+1]-work[i]
                else :
                    smwork=work[nwork]-work[i]+work[j-nwork+1]
                if loop_sum>0:
                    smwork+=loop_sum*((k-(j+1-i))//nwork) 
                if smwork>sm : sm=smwork

    print(sm)

main() 

Measured memory_bytes: 69196
#include <stdio.h>
int main()
{
    int n,m,l,i,j,k;
    long c;
    scanf("%d %d %d",&n,&m,&l);
    int a[n][m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    int b[m][l];
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            c=0;
            for(k=0;k<m;k++){
                c+=a[i][k] * b[k][j];
            }
            printf("%ld",c);
            if(j<l-1){
                printf(" ");
            } else {
                printf("\n");
            }
        }
    }
    return 0;
}

    


Measured memory_bytes: 2108
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int ROW_MAX = 10;
const int COL_MAX = 10000;
int col_cnt[COL_MAX];
int mat[ROW_MAX][COL_MAX];
int r, c;
int result;

void dfs(int row_id, bool flip) {
    if (row_id == r) {
        int res = 0;
        for (int i = 0; i < c; i++) {
            res += max(col_cnt[i], r-col_cnt[i]);
        }
        result = max(result, res);
        return;
    }
    if (flip) {
        for (int i = 0; i < c; i++) {
            if (mat[row_id][i]) {
                mat[row_id][i] = 0;
                col_cnt[i]--;
            } else {
                mat[row_id][i] = 1;
                col_cnt[i]++;
            }
        }
    }
    dfs(row_id+1, false);
    dfs(row_id+1, true);
    if (flip) {
        for (int i = 0; i < c; i++) {
            if (mat[row_id][i]) {
                mat[row_id][i] = 0;
                col_cnt[i]--;
            } else {
                mat[row_id][i] = 1;
                col_cnt[i]++;
            }
        }
    }
}

int main() {
    while (1) {
        scanf("%d%d", &r, &c);
        if (!r) break;
        memset(col_cnt, 0, COL_MAX*sizeof(int));
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                scanf("%d", &mat[i][j]);
                if (mat[i][j]) {
                    col_cnt[j]++;
                }
            }
        }
        result = 0;
        dfs(0, false);
        dfs(0, true);
        printf("%d\n", result);
    }
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 256