akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // 整数の入力
        //x = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        int max = 100003;
        int[] sosu = new int[max];
        //1～10000
        for (int i = 0; i < max; i++) {
            sosu[i] = i+1;
        }
        //1を消す
        sosu[0] = 0;
        //エラトステネス
        for (int i = 1; i < Math.floor(Math.sqrt(max)); i++) {
            //小さい数探し
            int j = 0;
            for (j = 1; j < Math.floor(Math.sqrt(max)); j++) {
                if (sosu[j - 1] != 0 && !list.contains(j)) {
                    list.add(j);
                    break;
                }
            }
            //消す
            for (int k = j+1; k < max; k++) {
                if (sosu[k - 1] % j == 0) {
                    sosu[k - 1] = 0;
                }
            }
        }
        int x;
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();
        for (int i = x-1; i < sosu.length; i++) {
            if (sosu[i] != 0) {
                System.out.println(sosu[i]);
                break;
            }
        }
	}
}

Measured memory_bytes: 24488
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define pb  push_back
#define F  first
#define S  second
#define mak make_pair
const int N=1e5+3,mod=1e8;
int n,k,a[N];
ll oo=-1e9;
int mem[N];
int dp(int i)
{
    if (i==n)return 0;
    if (i>n)return -oo+6;
    int &ret=mem[a[i]];
    if (ret!=-1)return ret;
    int xx=-oo;
    for (int j=1;j<=k&&i+j<=n;j++)
    {
       int sub=abs(a[i]-a[i+j])
     ;   xx=min(sub+dp(i+j),xx);
    }
    return ret=xx;;


}


int main ()
{
 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*for (int i=0;i<=N;i++)
    mem[i]=oo;*/
 memset(mem,-1,sizeof mem);
 cin>>n>>k;
 for (int i=1;i<=n;i++)
    cin>>a[i];
    cout<<dp(1);

}


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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int count = 1;
    int pos = 0;
    int i = 0;
    while (count <= n)
    {
        pos += l[i];
        i++;
        if (pos > x)
            break;
        else
            count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::collections::VecDeque;
fn main() {
    input! { n, c: isize, h: [isize; n] };
    let mut dp = vec![0; n];
    let mut deq = VecDeque::new();
    for i in 0..n - 1 {
        {
            let check = |j1: usize, j2: usize, j3: usize| {
                let a1 = -2 * h[j1];
                let a2 = -2 * h[j2];
                let a3 = -2 * h[j3];
                let b1 = dp[j1] + h[j1] * h[j1];
                let b2 = dp[j2] + h[j2] * h[j2];
                let b3 = dp[j3] + h[j3] * h[j3];
                (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2)
            };
            while deq.len() >= 2 && check(deq[deq.len() - 2], deq[deq.len() - 1], i) {
                deq.pop_back();
            }
        }
        deq.push_back(i);
        let x = {
            let f = |j: usize, i: usize| -2 * h[j] * h[i] + dp[j] + h[j] * h[j];
            while deq.len() >= 2 && f(deq[0], i + 1) >= f(deq[1], i + 1) {
                deq.pop_front();
            }
            f(deq[0], i + 1) + h[i + 1] * h[i + 1] + c
        };
        dp[i + 1] = x;
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char str[10],*p,st;
  int n;
  scanf("%s",str);
  for(p=str,n=0,st=*p-1;*p;p++){
    if(st!=*p){
      n=1;
      st = *p;
    }
    else
      n++;
    if(n==3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"
#define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42

void exgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b * x;
}

signed main(){
	cout<<fixed<<setprecision(7);
	
	int a, b, x, y;
	
	cin>>a>>b;
	
	exgcd(a,b,x,y);
	
	cout<<x<<" "<<y<<endl;
	
	return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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 (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n; cin >> n;
    lol d; cin >> d;
    REP(i, n)
    {
        int x, y; cin >> x >> y;
        double d2 = sqrt(pow(x, 2) + pow(y, 2));
        if(d2 <= d)
            result++;
    }
    

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python

n = int(input())
mod = 10**9+7

tot = 10**n

inc0 = (tot - 9**n)%mod
inc9 = (tot - 9**n)%mod
inc0or9 = (tot - 8**n)%mod

ans = (inc0+inc9-inc0or9)%mod
print(ans)


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    string t = "hi";
    for (int i = 0; i < (int)s.size(); i+=2) {
        if (s.substr(i, 2) != t) {
            dump("No");
            return 0;
        }
    }
    dump("Yes");
    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;
const int inf = 1001001001;

int pcnt(int n) {
    return __builtin_popcount(n);
}

int f(int n) {
    if(n == 0) return 0;
    return f(n%pcnt(n))+1;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> x(n);
    rep(i,n) x.at(i) = s.at(i) - '0';
    
    int pc = 0;
    rep(i,n) pc += x.at(i);
    vector<int> ans(n);
    
    rep(b,2) {
        int npc = pc;
        if(b == 0) npc++; else npc--;
        if(npc <= 0) continue;
        int r0 = 0;
        rep(j,n) {
            r0 = (r0*2)%npc;
            r0 += x.at(j);
        }
        
        int k = 1;
        for(int j = n-1; j >= 0; j--) {
            if(x.at(j) == b) {
                int r = r0;
                if(b == 0) r = (r + k)%npc;
                else r = (r-k+npc)%npc;
                ans.at(j) = f(r)+1;
            }
            k = (k*2)%npc;
        }
    }
    rep(i,n) cout << ans.at(i) << endl;

    
    
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int N,W;
    cin>>N>>W;
    vi w(N), v(N);
    REP(i,N) cin>>w[i]>>v[i];

    int V = N*1000;
    vl dp(V+5, numeric_limits<ll>::max());
    dp[0] = 0;
    REP(i,N){
        FORR(j,0,V){
            if(dp[j] != numeric_limits<ll>::max())
                chmin(dp[j + v[i]], dp[j] + w[i]);
        }
    }
    //DEBUG_VEC(dp);

    ll ans = 0;
    REP(i,V+1){
        if(dp[i] <= W)
            chmax(ans,(ll)i);
    }
    cout << ans << endl;
    return 0;
}

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

int N;
int A[220];

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

    int res = 0; //操作可能な回数(求める答え)

    while(true) {
        bool exist_odd = false; //奇数の有無を判定するフラグ
        for(int i=0; i<N; ++i) {
            if(A[i] % 2 != 0) exist_odd = true; //奇数が存在したらtrue
        }

        if(exist_odd) break;

        for(int i=0; i<N; ++i) {
            A[i] /= 2;
        }
        ++res;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,to[200001],next[200001],tot,col[100001],head[100001],sum[3],cnt;
long long ans;
bool flag;
void add(int u,int v){to[++tot]=v,next[tot]=head[u],head[u]=tot;}
void dfs(int x,int color){
    ++cnt;
    col[x]=color;
    sum[color]++;
    for(int i=head[x];i;i=next[i]){
        if(!col[to[i]])dfs(to[i],3-color);
        else if(col[x]==col[to[i]])flag=true;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }
    for(int i=1;i<=n;i++)if(!col[i]){
        dfs(i,1);
        if(!flag)ans+=1LL*sum[1]*sum[2];
        else ans+=1LL*cnt*(cnt-1)/2;
        sum[1]=sum[2]=flag=cnt=0;
    }
    printf("%lld\n",ans-m);
    return 0;
}

Measured memory_bytes: 3200
from itertools import combinations_with_replacement
 
N, M, Q = map(int, input().split())
input_lst = [list(map(int, input().split())) for _ in range(Q)]
 
max_score = 0
for pattern in combinations_with_replacement(range(1, M + 1), N):
    score = 0
    for row in input_lst:
        a, b, c, d = row
        if pattern[b - 1] - pattern[a - 1] == c:
            score += d
    if score > max_score:
        max_score = score
print(max_score)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
int main (){
    int i,j=0,x,y,z;
    cin>>x>>y>>z;
    for(i=0;i<y-x+1;i++){
        if(z%(x+i)==0){j++;}
        }
        cout<<j<<endl;
        return 0;
    }


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

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

    sort(a, a+n);

    int b=0;
    for(int i=0; i<n-1; i++){
        if(b==1) break;
        if(a[i]==a[i+1]){
            b=1;
            break;
        }
    }

    if(b==1) cout << "NO" << endl;
    else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1024
s=list(input())
t=list(input())
n=len(s)
m=len(t)
s.sort()
t.sort(reverse=True)
ans='No'
for i in range(min(n,m)):
    if s[i]<t[i]:
        ans='Yes'
    elif s[min(n,m)-1]==t[min(n,m)-1] and n<m:
        ans='Yes'
print(ans)

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

string s, t, S, T;
int n, m;
string a[110];
string b[110];

int main()
{
    cin >> s >> t;
    n = s.length();
    m = t.length();
    
    for(int i = 0; i < n; i++)
    {
        a[i] = s[i];
    }
    sort(a, a+n);
    
    for(int i = 0; i < m; i++)
    {
        b[i] = t[i];
    }
    sort(b, b+m);
    reverse(b, b+m);
    
    S = a[0];
    
    for(int i = 1; i < n; i++)
    {
        S = S + a[i];
    }
    
    T = b[0];
    
    for(int i = 1; i < m; i++)
    {
        T = T + b[i];
    }
    
    if(S < T)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

/*
int go(int i,int sum){

        if(dp[i][sum]!=-1) return dp[i][sum];

       dp[i][sum] =min(val[i]+go(i+1,W-a[i]),go(i+1,W));
       return dp[i][sum];
}
*/

 int main()
{
   // fast;

    int n;
    string s; cin >> n >> s;
    int cnt = 0;
    for(int i = 0; i< n-2; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
    }

    cout << cnt << '\n';

   return 0;
}


Measured memory_bytes: 384
package main

import (
	"bytes"
	"fmt"
	"strconv"
)

func main() {
	var (
		n int
		a []int
	)

	fmt.Scan(&n)
	a = make([]int, n)

	for i, _ := range a {
		fmt.Scan(&a[i])
	}

	cnt := selection(a)
	fmt.Println(join(a))
	fmt.Println(cnt)
}

func selection(a []int) (cnt int) {
	var (
		mini int
	)
	for i := range a {
		mini = i
		for j := i + 1; j < len(a); j++ {
			if a[mini] > a[j] {
				mini = j
			}
		}
		if mini != i {
			a[mini], a[i] = a[i], a[mini]
			cnt++
		}
	}
	return
}

func join(a []int) string {
	var buf bytes.Buffer
	for i := range a {
		if i > 0 {
			buf.WriteString(" ")
		}
		buf.WriteString(strconv.Itoa(a[i]))
	}
	return buf.String()
}



Measured memory_bytes: 1160
#ABC 171 D - Replacing 18:36

def func(x,y): #x -> y, xの要素数を返す
    if x not in d:
        v = 0
    else:
        v = d[x]
        if y not in d:
            d[y] = 0
            d[y] = d[x]
            del d[x]
        else:
            d[y] += d[x]
            del d[x]
    return v

n = int(input())
a = list(map(int, input().split()))
d = {}
for key in a:
    if key not in d:
        d[key] = 0
    d[key] += 1

q = int(input())
sum_a = sum(a)
for i in range(q):
    b,c = map(int, input().split())
    v = func(b,c)
    sum_a += (c-b)*v 
    print(sum_a)
    

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class CReplacingInteger {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n, k;
	    in >> n >> k;
        ll rest = n%k;
        out << min(rest, k-rest) << endl;
	}
};


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


Measured memory_bytes: 256
#include<bitset>
#include<iostream>
using namespace std;
const int N=405;
bitset<N>f[N],g;
int n,m,U[N*N],V[N*N];
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;++i)cin>>U[i]>>V[i];
	for(int i=1;i<=n;++i){
		f[i].set(i);
		for(int j=m;j;--j)
		if(f[i].test(U[j])&&f[i].test(V[j])){g.set(i);break;}else
		if(f[i].test(U[j]))f[i].set(V[j]);else
		if(f[i].test(V[j]))f[i].set(U[j]);
	}
	int ans=0;
	for(int i=1;i<=n;++i)
	if(!g[i])
	for(int j=i+1;j<=n;++j)
	if(!g[j]&&(f[i]&f[j]).none())++ans;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int a, b;
int main() {
    DAU
    cin >> a >> b;
    if (a * b == 2)
        cout << 3;
    else if (a * b == 3)
        cout << 2;
    else cout << 1;
    PLEC
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int a,b;
    while(s!="-"){
        cin >> a;
        for(int i=0; i<a; i++){
            cin >> b;
            s=s.substr(b,s.size()-b)+s.substr(0,b);
        }
        cout << s << endl;
        cin >> s;
    }
    return 0;
}


Measured memory_bytes: 3156
#!/usr/bin/env python3
import sys


def solve(n: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    count = [0] * (n + 1)
    tmp = 0
    for idx in range(n - 1):
        if S[idx:idx + 2] == 'AC':
            tmp += 1
        count[idx + 1] = tmp
    #print(count)
    for i in range(Q):
        ret = count[r[i] - 1] - count[max(0, l[i] - 2)]
        if l[i] > 1 and S[l[i] - 2:l[i]] == 'AC':
            ret -= 1
        print(ret)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14140
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int x = sc.nextInt();
    for (int i=-300;i<300;i++){
      if (Math.abs(i-x) < k){
        System.out.print(i);
        System.out.print(" ");
      }
    }
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>    
#include <cstring>
#include <array>
#include <cctype>
#include <string.h>
#include <vector>
#include <limits.h>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cassert>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <bitset>
using namespace std;
#define PI 3.14159265359
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll a,b;

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

	cin >> a >> b;

	cout << (b-a)*(b-a+1)/2 - b << endl;

	return 0;
}


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


N, Q = MAP()
ab = [LIST() for _ in range(N-1)]
px = [LIST() for _ in range(Q)]

graph = defaultdict(list)

for a, b in ab:
	graph[a-1].append(b-1)
	graph[b-1].append(a-1)

ans = [0]*N

for p, x in px:
	ans[p-1] += x

check = [1]*N
check[0] = 0

q = deque([0])

while q:
	n = q.popleft()
	for node in graph[n]:
		if check[node]:
			ans[node] += ans[n]
			check[node] = 0
			q.append(node)

print(*ans)


Measured memory_bytes: 162652
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
long dfs(long n)
{
  if(n==0)return 0;
  return 1+2*dfs(n/2);
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  long n;cin>>n;cout<<dfs(n)<<endl;

  
  return 0;
}

Measured memory_bytes: 256
S = input()

answer1 = '10' * (len(S) // 2) + '1' * (len(S) % 2)
answer2 = '01' * (len(S) // 2) + '0' * (len(S) % 2)
count1 = bin(int(answer1, 2) ^ int(S, 2))[2:].count('1')
count2 = bin(int(answer2, 2) ^ int(S, 2))[2:].count('1')
print(min(count1, count2))

Measured memory_bytes: 3592
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2005;
char mp[N][N];int r[N][N],c[N][N],s[N][N],n,m,q;
inline int qs(R int x,R int y,R int xx,R int yy){
	return s[xx][yy]-s[x-1][yy]-s[xx][y-1]+s[x-1][y-1];
}
inline int qr(R int x,R int y,R int xx,R int yy){
	return r[xx][yy]-r[x-1][yy]-r[xx][y-1]+r[x-1][y-1];
}
inline int qc(R int x,R int y,R int xx,R int yy){
	return c[xx][yy]-c[x-1][yy]-c[xx][y-1]+c[x-1][y-1];
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	fp(i,1,n){
		scanf("%s",mp[i]+1);
		fp(j,1,m)s[i][j]=(mp[i][j]=='1')+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	}
	fp(i,1,n)fp(j,1,m-1){
		r[i][j]=r[i-1][j]+r[i][j-1]-r[i-1][j-1]+(mp[i][j]=='1'&&mp[i][j+1]=='1');
	}
	fp(i,1,n-1)fp(j,1,m){
		c[i][j]=c[i-1][j]+c[i][j-1]-c[i-1][j-1]+(mp[i][j]=='1'&&mp[i+1][j]=='1');
	}
	for(R int x,y,xx,yy;q;--q){
		scanf("%d%d%d%d",&x,&y,&xx,&yy);
		printf("%d\n",qs(x,y,xx,yy)-qr(x,y,xx,yy-1)-qc(x,y,xx-1,yy));
	}
	return 0;
}

Measured memory_bytes: 52864
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;
    vl x(n);
    ll bad = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        bad += (x[i] != i + 1);
    }
    cout << (bad <= 2 ? "YES" : "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;

int n,d[51];

int main(){
    cin>>n;
    rep(i,n)cin>>d[i];
    sort(d,d+n+1);
    for(int i=1;i<=n;i+=2)d[i]=24-d[i];
    sort(d,d+n+1);
    int ans=24;
    rep(i,n)ans=min(ans,d[i+1]-d[i]);
    cout<<min(ans,min(24-d[n],d[n]))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{

    int X,Y;
    cin>>X>>Y;

    cout << X+(Y/2)<<endl;

    return 0;
}


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

int GCD(int a,int b,int c){
  return gcd(a,gcd(b,c));
}

signed main(){
  int k;cin>>k;
  int ans=0;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
        ans+=GCD(a,b,c);
      }
    }
  }
  cout<<ans<<endl;
}


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

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

using namespace std;
using lint=long long;

vector<long long> divisors(long long a){
	vector<long long> res;
	for(long long i=1;i*i<=a;i++) if(a%i==0) {
		res.emplace_back(i);
		if(i*i<a) res.emplace_back(a/i);
	}
	sort(res.begin(),res.end());
	return res;
}

int main(){
	lint n; scanf("%lld",&n);

	int ans=divisors(n-1).size()-1;
	for(lint d:divisors(n)) if(d>=2) {
		lint m=n;
		while(m%d==0) m/=d;
		if(m%d==1) ans++;
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 384
N=int(input())
K=int(input())

sN=str(N)
keta=len(sN)

#dp[i][j][t]=Nと同じ桁数の整数で上からi桁目までで0でない数字がj個あるものの個数
dp=[[[0]*2 for __ in range(K+1)] for _ in range(keta+1)]
dp[0][0][1]=1

for i in range(keta):
    for j in range(K+1):
        for k in range(2):
            for n in range(10):
                if k==1 and n>int(sN[i]): break
                ni=i+1
                nj=j if n==0 else j+1
                if nj>K: continue
                nk=1 if k==1 and n==int(sN[i]) else 0
                dp[ni][nj][nk]+=dp[i][j][k]

print(dp[keta][K][0]+dp[keta][K][1])


Measured memory_bytes: 41456
#include<stdio.h>
int main()
{
  int n;
  int b,f,r,v;
  int i,j,k;
  int m[4][3][10];
  for(i=0;i<4;i++)
    {
      for(j=0;j<3;j++)
	{
	  for(k=0;k<10;k++)
	    {
	      m[i][j][k]=0;
	    }
	}
    }
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d%d%d%d",&b,&f,&r,&v);
      m[b-1][f-1][r-1]+=v;
    }
  for(i=0;i<4;i++)
    {
      for(j=0;j<3;j++)
	{
	  for(k=0;k<10;k++) printf(" %d",m[i][j][k]);
	  printf("\n");
	}
      if(i!=3) printf("####################\n");
    }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;

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

  vector<bool> v(1e5+10,true);
  v[0] = false;
  v[1] = false;
  for (int i = 2; i < v.size(); i++){
    if (v[i] == false) continue;
    for(int j = 2*i; j < v.size(); j += i){
      v[j] = false;
    }
  }

  vector<bool> x(1e5+10, false);
  for (int i = 2; i < x.size(); i++){
    if ((v[i] == true) && (v[(i+1)/2] == true)) x[i] = true;
  }

  vector<int> a(1e5+10,0);
  for (int i = 1; i < a.size(); i++){
    if (x[i] == true) a[i] = a[i-1] + 1;
    else a[i] = a[i-1];
  }

  rep(i,q){
    int l, r;
    cin >> l >> r;
    cout << a[r] - a[l-1] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,j=0;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);

    for(int i=0; i<n-1; i++)
        if(a[i]!=a[i+1])j++;

    cout<<j+1;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int n,m;
vector<vector<int> > to;
vector<int> deg;
int dp[100010];

int main(){
  cin >> n >> m;
  to.resize(n);
  deg.resize(n);
  rep(i,n-1+m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    deg[b]++;
  }
  queue<int> q;
  map<int,int> mp;
  rep(i,n)if(deg[i]==0) {q.push(i); mp[i]=0;}
  while(q.size()){
    int v=q.front(); q.pop();
    for(auto nv:to[v]){
      deg[nv]--;
      if(deg[nv]==0){
        q.push(nv);
        mp[nv]=v+1;
      }
    }
  }
  for(auto c:mp){
    cout << c.second << endl;
  }
}


Measured memory_bytes: 14464
import sys
H,W = map(int,input().split())
S = ["."*(W+2)]
for _ in range(H):
    s = input()
    s = "."+s+"."
    S.append(s)
S.append("."*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j] == "#":
            if S[i+1][j] == S[i-1][j] == S[i][j+1] == S[i][j-1] == ".":
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 38896
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18, N=200005;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
struct M{
	vector<vector<ll>> mat;
	M(ll n){
		mat.resize(n,vector<ll>(n,0));
	}
	M operator*(const M& a) const{
		ll n=mat.size();
		M ans=M(n);
		rep(i,0,n){
			rep(j,0,n){
				rep(k,0,n)ans.mat[i][j]=add(ans.mat[i][j],mult(mat[i][k],a.mat[k][j]));
			}
		}
		return ans;
	}
};
void solve(){
	ll n, k, res=0;
	cin>>n>>k;
	M ans(n);
	M v(n);
	rep(i,0,n)
		rep(j,0,n)
			cin>>v.mat[i][j];
	rep(i,0,n)ans.mat[i][i]=1;
	while(k){
		if(k%2)ans=ans*v;
		v=v*v;
		k>>=1;
	}
	rep(i,0,n)
		rep(j,0,n)
			res=add(res,ans.mat[i][j]);
	cout<<res;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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 (b<a) { a=b; return 1; } return 0; }

int main() {
	int k,x;
	cin >> k >> x;
	for(int i = x-(k-1); i<=x+(k-1); i++) {
		cout << i;
		if(i == x+(k-1)) cout << endl;
		else cout << " ";
	}

  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<vector<char>> a(n,vector<char>(10));
    rep(i,n)rep(j,10) cin>>a[i][j];
    rep(i,n) sort(all(a[i]));
    sort(all(a));

    in cnt=0;
    int lef=0, rig=1;
    while(rig<n){
        if(a[lef]==a[rig]){
            rig ++;
            if(rig==n){
                cnt += (in)(rig-lef)*(rig-lef-1)/2;
            }
            continue;
        }
        else{
            cnt += (in)(rig-lef)*(rig-lef-1)/2;
            lef=rig;
            rig ++;
        }
    }
    cout<<cnt<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 8656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll a, ll b) {
    if (a > b) swap(a, b);
    if (b % a == 0) {
        return (b/a)*a*2-a;
    }
    return (b/a)*a*2+f(b%a, a);
}
int main () {
    ll N, X;
    cin >> N >> X;
    if (X+X == N) {
        cout << N/2*3 << endl;
        return 0;
    }
    cout << N+f(X, N-X) << endl;
}

Measured memory_bytes: 256
const main = (input) => {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inpt: Array<string> = input.split(' ');
	let ans = true;
	for (let i = 0; i < 2; i++) {
		ans = inpt[i].charAt(inpt[i].length-1) === inpt[i+1].charAt(0);
		if (!ans) break;
	}

	console.log(ans ? 'YES' : 'NO');
}

// *** debug start ***
const debug = ()  => {
	const input = (<HTMLInputElement>document.getElementById('input')).value;
	input && main(input);
}
// *** debug end ***

//
declare function require(x: string): any;
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

typedef long long ll;			//ld.
typedef unsigned long long ull;	//llu.


int main(){
	char a[15];
	char b[15];
	char c[15];
	scanf("%s %s %s",a,b,c);
	int ada = 0;
	if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0])
		ada=1;
	if(ada==1)
		printf("YES\n");
	else
		printf("NO\n");
}


Measured memory_bytes: 1628
n, k = map(int, input().split())
s = input()

nums = []
now = 1 # 今見ている数
cnt = 0 # nowが並んでいる個数
for i in range(n):
    if s[i] == str(now):
        cnt += 1
    else:
        nums.append(cnt) # 切り替わりで追加
        now = 1 - now # 0と1を切り替える
        cnt = 1 # 新しいものをカウントし始める
# 最後
if cnt != 0:
    nums.append(cnt)

# 調整
if len(nums) % 2 == 0:
    nums.append(0)

add = 2 * k + 1

# 累積和を作る
acc = [0] * (len(nums) + 1)
for i in range(len(nums)):
    acc[i + 1] = acc[i] + nums[i]

res = 0
# 偶数番目だけ見る
for i in range(0, len(nums), 2):
    # [left, right)
    left = i
    right = min(i + add, len(nums))
    tmp = acc[right] - acc[left]
    res = max(res, tmp)

print(res)

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

#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;

using vecint = vector<int>;
using ll = int64_t;

// ax+by=gcd(a,b)
// |x|+|y| -> min
// x <= y
ll extgcd(ll a, ll b, ll& x, ll& y) {
  ll g = a; x = 1; y = 0;
  if (b) g = extgcd(b, a%b, y, x), y -= (a / b) * x;
  return g;
}

int main()
{
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  int h1 = H%h;
  int w1 = W%w;
  if (h1 == 0 && w1 == 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  int h2 = h-h1;
  int w2 = w-w1;
  int alpha = h*w-h2*w2;
  int beta = h2*w2;
  ll x,y;
  ll g = extgcd(alpha, beta, x, y);
  int pad = H*W-(H-h1)*(W-w1);
  int neg = g * (H/h) * (W/w);
  int lb = neg / pad;
  int n = (lb+x+beta-1)/beta+1;
  int p = beta*n-x;
  int q = -alpha*n-y;
  REP(i,H) {
    REP(j,W) {
      if (j) cout << ' ';
      if (i%h >= h1 && j%w >= w1) {
        cout << q;
      } else {
        cout << p;
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n; R(n);
    VI AA(n+1);
    FOR(i,1,n)R(AA[i]);
    VI res;
    for(int i=n;i>0;i--){
        bool suc=0;
        for(int j=i;j>0;j--){
            if(AA[j]==j){
                suc=1;
                res.PB(j);
                AA.erase(AA.begin()+j);
                break;
            }
        }
        if(!suc){
            W(-1);
            return 0;
        }
    }
    reverse(ALL(res));
    W(res);
    return 0;
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 0; i < n-1; i++) {
        ll u, v;
        cin >> u >> v;
        ll maxx = max(u,v), minn = min(u, v);
        ans += ((i+1)*(i+2))/2;
        ans -= (n-maxx+1)*minn;
    }
    ans += (n*(n+1))/2;
    cout << ans;
    return 0;
}




Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
int par[200000];
vector<int> out[200000];
int pos[200000];
set<int> s[200000];
int dfs(int v) {
	set<int> s;
	for (int to : out[v]) s.insert(dfs(to));
	int x = 0;
	while (s.find(x) != s.end()) x++;
	return x;
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> par[i];
		par[i]--;
		out[par[i]].push_back(i);
	}
	vector<int> vec;
	memset(pos, -1, sizeof(pos));
	pos[0] = 0;
	vec.push_back(0);
	int now = par[0];
	while (pos[now] == -1) {
		pos[now] = vec.size();
		vec.push_back(now);
		now = par[now];
	}
	int p = pos[now];
	for (int i = p; i < vec.size(); i++) {
		int prev;
		if (i == p) prev = vec.size() - 1;
		else prev = i - 1;
		for (int to : out[vec[i]]) {
			if (to == vec[prev]) continue;
			s[vec[i]].insert(dfs(to));
		}
	}
	vec.push_back(vec[p]);
	for (int i = 0; i <= out[vec[p]].size(); i++) {
		int x = i;
		for (int j = p + 1; j < vec.size(); j++) {
			int y = 0;
			while (y == x || s[vec[j]].find(y) != s[vec[j]].end()) y++;
			x = y;
		}
		if (x == i) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 23028
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

const int MAX_N = (int)2e5 + 5;
int D[MAX_N], ans[MAX_N];
map<int, vector<pii>> mp;
set<int> S;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, Q; cin >> N >> Q;
    for(int i=0;i<N;i++){
        int s, t, x; cin >> s >> t >> x;
        mp[x].emplace_back(pii(s, t));
    }
    for(int i=0;i<Q;i++){
        cin >> D[i];
        S.emplace(i);
    }
    S.emplace(Q);

    for(auto &p : mp){
        for(auto pp : p.second){
            int l = distance(D, lower_bound(D, D+Q, pp.first-p.first));
            int r = distance(D, lower_bound(D, D+Q, pp.second-p.first));
            int cur = l;
            while(cur<r){
                if(S.count(cur)==0) cur = *S.lower_bound(cur);
                else{
                    ans[cur] = p.first;
                    S.erase(cur);
                    cur++;
                }
            }
        }
    }
    for(int i=0;i<Q;i++){
        if(ans[i]==0) printf("%d\n", -1);
        else printf("%d\n", ans[i]);
    }
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c)
    {
        cout << c << endl;
    }
    else if (a != b && a == c)
    {
        cout << b << endl;
    }
    else if (a != b && a != c)
    {
        cout << a << endl;
    }
    return 0;
}

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

int A,B;

int main() {
    cin>>A>>B;
    for (int i=1; i<=1000; i++) {
        if (int(i*0.08)==A&&int(i*0.1)==B) {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


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


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

int main(){
	int R, G, B, N;
	long long int final_result = 0;
	cin >> R >> G >> B >> N;
	for(int r = 0; r <= 3000; r++){
		for(int g = 0; g <= 3000; g++){
			int b = N - r * R - g * G;
			if(b >= 0 && b % B == 0)final_result++;
		}
	}
	cout << final_result << '\n';

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];

	sort(a.rbegin(), a.rend());
	ll tmp1=0;
	ll tmp2=0;
	REP(i, N){
		if(i%2==0) tmp1 += a[i];
		else tmp2 += a[i];
	}
	cout << tmp1 - tmp2 << endl; 
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n,k = inpl()
print(k * (k-1) **(n-1) )

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

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

  vector<int> v(n);

  for(int i=0; i < n; i++){
    cin >> v.at(i);
  }

  bool ans = true;
  for(int i=0; i < n-1; i++){
    if(v[i] < v[i+1]){
      v[i+1]--;
    }
    if(v[i] > v[i+1]){
      ans = false;
      break;
    }
  }

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


Measured memory_bytes: 640