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

int main(){
    int n,m,s,g1,g2;
    while (cin >> n >> m >> s >> g1 >> g2 && n){
        --s, --g1, --g2;
        vector<vector<int>> g(n,vector<int>(n,1e8));
        rep(i,n) g[i][i] = 0;
        rep(i,m){
            int a, b, c;
            cin >> a >> b >> c;
            --a, --b;
            g[a][b] = c;
        }
        rep(k,n)rep(i,n)rep(j,n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        int ans = 1e9;
        rep(i,n) ans = min(ans, g[s][i]+g[i][g1]+g[i][g2]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

const int INF = 2000000010;

pii a[200010];
int T1[200010], T2[200010];
vector <int> allx, ally;

void modify1(int x, int v) {
	while (x <= 200000) T1[x] = max(T1[x], v), x += x & -x;
}

void modify2(int x, int v) {
	while (x <= 200000) T2[x] = max(T2[x], v), x += x & -x;
}

int query1(int x) {
	int res = -INF;
	while (x) res = max(res, T1[x]), x -= x & -x;
	return res;
}

int query2(int x) {
	int res = -INF;
	while (x) res = max(res, T2[x]), x -= x & -x;
	return res;
}

int main () {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		allx.push_back(a[i].fi), ally.push_back(a[i].se);
	}
	sort(allx.begin(), allx.end()), allx.resize(unique(allx.begin(), allx.end()) - allx.begin());
	sort(ally.begin(), ally.end()), ally.resize(unique(ally.begin(), ally.end()) - ally.begin());
	for (int i = 0; i < n; i++) {
		a[i].fi = lower_bound(allx.begin(), allx.end(), a[i].fi) - allx.begin() + 1;
		a[i].se = lower_bound(ally.begin(), ally.end(), a[i].se) - ally.begin() + 1;
	}
	sort(a, a + n);
	int ans = -INF;
	for (int i = 1; i <= n; i++) {
		T1[i] = T2[i] = -INF;
	}
	int m = ally.size();
	for (int i = 0; i < n; i++) {
		int x = allx[a[i].fi - 1], y = a[i].se;
		int t1 = query1(y), t2 = query2(m - y + 1);
		if (t1 != -INF) ans = max(ans, t1 + x + ally[y - 1]);
		if (t2 != -INF) ans = max(ans, t2 + x - ally[y - 1]);
		modify1(y, -x - ally[y - 1]), modify2(m - y + 1, -x + ally[y - 1]);
	}
	for (int i = 1; i <= n; i++) {
		T1[i] = T2[i] = -INF;
	}
	for (int i = n - 1; i >= 0; i--) {
		int x = allx[a[i].fi - 1], y = a[i].se;
		int t1 = query1(y), t2 = query2(m - y + 1);
		if (t1 != -INF) ans = max(ans, t1 - x + ally[y - 1]);
		if (t2 != -INF) ans = max(ans, t2 - x - ally[y - 1]);
		modify1(y, x - ally[y - 1]), modify2(m - y + 1, x + ally[y - 1]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 8232
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h> 
#include<limits.h>
#include <stdbool.h>
typedef  unsigned long long ll;
#define MOD 10e9+7  //10億　= 10^9
#define length 100000+3000 //10万
#define kw_len 10+2
#define INF 16446000000009000
#define pi 3.1415926535897932384
int main(){
    ll N,sum=0;
    int i;
    ll num[10000];
    scanf("%d",&N);
    for( i=0;i<N;i++){
        scanf("%llu",num+i);
    }
    for( i=0;i<N;i++){
        if(*(num+i)%2==0){
            for(int j=0;j<N;j++){
                if(*(num+i)%2!=0)break;
                *(num+i) /= 2;
                sum++;
            }
        }
    }
  
    printf("%llu",sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m,n,mp[1200][1200],dp[1200][1200];
bool so[1000001];
int main(){
  int p=2,x=600,y=600,c=0,d=0;
  int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
  mp[600][600]=1;
  while(p<=1e6+5000){
    if(c%2==0)d++;
    for(int i=0;i<d;i++)
      y+=dy[c%4],x+=dx[c%4],mp[y][x]=p++;
    c++;
  }
  so[1]=1;
  for(int i=2;i*i<=1e6;i++)
    if(!so[i])for(int j=2;j*i<=1e6;j++)so[i*j]=1;
  while(cin>>m>>n,n){
    for(int i=0;i<1200;i++)
      for(int j=0;j<1200;j++)
	if(mp[i][j]==n)dp[i][j]=!so[n];
	else dp[i][j]=-1e8;
    int ans=0,p=0;
    for(int i=10;i<1190;i++)
      for(int j=10;j<1190;j++){
	for(int k=-1;k<=1;k++){
	  if(mp[i+1][j+k]>m)continue;
	  dp[i+1][j+k]=max(dp[i+1][j+k],dp[i][j]+!so[mp[i+1][j+k]]);
	}
	if(!so[mp[i][j]]){
	  if(dp[i][j]>ans)ans=dp[i][j],p=mp[i][j];
	  if(dp[i][j]==ans&&p<mp[i][j])p=mp[i][j];
	  }
      }
    cout<<ans<<" "<<p<<endl;
  }
  return 0;
}

Measured memory_bytes: 14364
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
const int MAX=1e5;
 
int main(){
	string s;
	cin>>s;
	int l=(int)s.length();
	int f=s[0]-'0';
	if(l==1){
		cout<<f<<endl;
		return 0;
	}
	bool all9=true;
	rep1(i,l-1)if(s[i]!='9')all9=false;
	if(all9)cout<<9*(l-1)+f<<endl;
	else cout<<9*(l-1)+f-1<<endl;
}

Measured memory_bytes: 256
program main;
var n,i,count: integer;
s:string;
 
begin
readln(n);
readln(s);
count:=0;
for i:=1 to n do
if S[i]+s[i+1]+s[i+2]='ABC' then count:=count+1;
 
writeln(count);
 
end.

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

int main(){
    int n;
    cin >> n;
    int min=1000000001, max=0;
    
    for(int i=0; i<n; i++){
        int t;
        cin >> t;

        if(t > max){
            max=t;
        }
        if(min > t){
            min=t;
        }
    }
    cout << max - min << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n, m, d;
	double[] ps, rests, ts;

	void run(){
		n=sc.nextInt();
		m=sc.nextInt();
		d=sc.nextInt();
		ps=new double[n];
		rests=new double[n];
		ts=new double[n];
		for(int i=0; i<n; i++){
			ps[i]=sc.nextDouble()/100.0;
			rests[i]=sc.nextDouble();
			double v=sc.nextDouble();
			ts[i]=d/v;
		}
		long[][] C=new long[m+1][m+1];
		C[0][0]=1;
		for(int j=1; j<=m; j++){
			C[j][0]=1;
			for(int i=1; i<=m; i++){
				C[j][i]=C[j-1][i-1]+C[j-1][i];
			}
			// debug(C[j]);
		}

		for(int a=0; a<n; a++){
			double totP=0;
			for(int i=0; i<=m; i++){
				double ta=ts[a]+i*rests[a];
				double pp=C[m][i]*pow(ps[a], i)*pow(1-ps[a], m-i);
				for(int b=0; b<n; b++){
					if(b==a){
						continue;
					}
					double p=0;
					int j;
					for(j=0; j<=m; j++){
						double tb=ts[b]+j*rests[b];
						if(ta+EPS<tb){
							p+=C[m][j]*pow(ps[b], j)*pow(1-ps[b], m-j);
						}
					}
					pp*=p;
				}
				totP+=pp;
			}
			// debug(totP);
			println(String.format("%.7f", totP));
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

using namespace std;

typedef long long ll;

vector< vector<int> > G;

void dfs(int cur, int par, vector<int>& col, bool& flag) {
	for (int nex : G[cur]) {
		if (nex == par) continue;
		if (col[nex] != -1) {
			if (col[nex] == col[cur]) flag = false;
			continue;
		}
		col[nex] = !col[cur];
		dfs(nex, cur, col, flag);
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	G.resize(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	vector<int> col(n, -1);
	ll cnt1 = 0, cnt2 = n, cnt3 = 0;
	for (int i = 0; i < n; i++) {
		if (col[i] != -1) continue;
		col[i] = 0;
		if (G[i].empty()) {
			cnt2--;
			continue;
		}
		cnt1++;
		bool flag = true;
		dfs(i, -1, col, flag);
		cnt3 += flag;
	}

	cout << (ll)n * n - cnt2 * cnt2 + cnt1 * cnt1 + cnt3 * cnt3 << endl;
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,i;
	t = 1;
	while(t--) {
	 cin >> n >> i;
	 cout << n - i + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sum_of_2_integers(int n) {
        int a,b;
        int count = 0;
        for (a=0; a < 10; a++) {
                b = n - a;
                if (b < 0) break;
                if (b <= 9) count++;
        }
        return count;
}

int sum_of_4_integers(int n) {
        int a,b;
        int count = 0;
        for (a=0; a <= 18; a++) {
                b = n - a;
                if (b < 0) break;
                if (b <= 18) {
                        count = count + sum_of_2_integers(a)*sum_of_2_integers(b);
                }
        }
        return count;
}

int main(void) {
        int n;
        while(cin >> n) {
                cout << sum_of_4_integers(n);
                cout << endl;
        }

        return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int m = scan.nextInt();
        int l = scan.nextInt();

        int[][] a = new int[n][m];
        int[][] b = new int[m][l];
        long[][] c = new long[n][l];

        for (int i = 0; i < a.length;i++) {
            for (int j = 0;j < a[i].length; j++) {
                a[i][j] = scan.nextInt();
            }
            scan.nextLine();
        }
        for (int i = 0;i < b.length;i++) {
            for (int j = 0; j < b[i].length;j++) {
                b[i][j] = scan.nextInt();
            }
            scan.nextLine();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0;j < l; j++) {
                for (int k = 0;k < m; k++) {
                    c[i][j] += a[i][k] * b[k][j];
                }
            }
        }
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[i].length; j++) {
                System.out.print(c[i][j]);
                if (j != l - 1) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 59120
#include <iostream>

using namespace std;

int main() {
	int sx, sy, tx, ty, w, h;
	cin >> sx >> sy >> tx >> ty;
	w = tx - sx;
	h = ty - sy;

	for (int i = 0; i < w; i++)cout << "R";
	for (int i = 0; i < h; i++)cout << "U";
	for (int i = 0; i < w; i++)cout << "L";
	for (int i = 0; i < h; i++)cout << "D";
	cout << "D";
	for (int i = 0; i < w+1; i++)cout << "R";
	for (int i = 0; i < h+1; i++)cout << "U";
	cout << "LU";
	for (int i = 0; i < w+1; i++)cout << "L";
	for (int i = 0; i < h+1; i++)cout << "D";
	cout << "R" << endl;

	return 0;
}

Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<string>
#include<algorithm>


using namespace std;


int n;
string s;
int solve(string::iterator& begin) {
    int ans = 0;
    if (*begin == '[') {
        begin++;
        vector<int> v;
        while(*begin != ']') {
            v.push_back(solve(begin));
        }
        begin++;
        sort(v.begin(), v.end());
        REP(i, (v.size() + 1) / 2) ans += v[i];
    } else {
        while(*begin != ']') {
            ans *= 10;
            ans += *begin - '0';
            begin++;
        }
        ans = (ans + 1) / 2;
    }
    // DD(distance(s.begin(), begin), ans);
    return ans;
}

int main()
{
    cin >> n;
    REP(i, n) {
        cin >> s;
        auto begin = s.begin();
        cout << solve(begin) << endl;
    }
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

const ll MOD = 1000000007;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin >> n >> k;
  vector<ll> sum(n+2, 0);
  REP(i,n+1) sum[i+1] = (sum[i] + i) % MOD;
  ll ans = 0;
  FOR(i,k,n+2){
    ll maxv = sum[n+1] + MOD - sum[n+1-i];
    ll minv = sum[i] + MOD - sum[0];
    ans += (maxv + MOD - minv + 1) % MOD;
    ans %= MOD;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
int cnt =0,ans=0;
const int MAX = 510000;

int main(){
    int n ;     cin >> n;
    string s;
    cin >> s;
    int cntw=0,cntr=0;
    for(int i=0;i<n;i++){
        
        if(s.at(i) == 'W')cntw++;
        if(s.at(i) == 'R')cntr++;

    }

    for(int i=0;i<cntr;i++){
        if(s.at(i) =='W')cnt++;
    }
    
    ans = min(cntw,min(cnt,cntr));
    cout << ans << endl;

    }
       


Measured memory_bytes: 3748
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	A, B, C := sc.NextInt(), sc.NextInt(), sc.NextInt()

	fmt.Println(max(0, C-(A-B)))
}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int main()
{
    int n, t, a;
    std::cin >> n >> t >> a;

    double min = 999999999;
    int min_n = 0;
    int h = 0;
    for (std::size_t i = 0; i < n; ++i) {
        std::cin >> h;
        double temp = t - h * 0.006;
        double diff = std::fabs(a - temp);
        if (diff < min) {
            min = diff;
            min_n = i + 1;
        }
    }

    std::cout << min_n << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;

int main() {
    string s, t;
    cin >> s >> t;
    
    int ans = INF;
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int m = 0;
        for (int j = i; j < i + t.size(); j++) {
            if (s[j] != t[j - i])
                m++;
        }
        ans = min(ans, m);
    }
    cout << ans << endl;
    
    return 0;
}


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

int count(int x) {
    if(x == 0) return 0;
    return (x % 10) + count(x / 10);
}

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

    if(K % 2) cout << B - A << endl;
    else cout << A - B << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){

	int n, i;
	int S[100];	/* 100????????´??°???????´????????????????????????¨ */

	scanf("%d", &n);			/* ??´??°?????\?????\??? */
		for(i=0; i<n; i++) {
			scanf("%d", &S[i]);
		}

	for(i=n-1; i>=0; i--) {		/* ??????????????¨???????????????????´???????????????¢????????? */
		if(i==0){
			printf("%d", S[i]);
	}
	else{
		printf("%d ", S[i]);	/* ?????????????´???§???????????°?¬????????´???????????????¨?????????????????????????????? */
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
# encoding: utf-8
import math
N, M = map(int, input().split())

rM = int(math.sqrt(M))

pairs = []
for a in range(1, rM + 1):
    if M % a == 0: pairs.append((a, M // a))

# a_i = p * b_i
# b_1 + b_2 + ... = m
p_max = 0
for m, p in filter(lambda x: x[0] >= N, pairs):
    if p > p_max: p_max = p

for p, m in filter(lambda x: x[1] >= N, pairs):
    if p > p_max: p_max = p

print(p_max)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>

template <class T>
struct SuffixArray {
    std::vector<int> ord, rank;

    template <class It>
    explicit SuffixArray(const It& begin, const It& end) {
        std::vector<T> dat(begin, end);
        int n = dat.size();

        ord.resize(n);
        std::iota(ord.begin(), ord.end(), 0);
        std::sort(ord.begin(), ord.end(),
                  [&](int i, int j) { return dat[i] < dat[j]; });

        rank.resize(n);
        {
            int cnt = 1;
            rank[ord[0]] = 1;
            for (int i = 1; i < n; ++i) {
                if (dat[ord[i - 1]] != dat[ord[i]]) ++cnt;
                rank[ord[i]] = cnt;
            }
        }

        // sentinel
        ord.insert(ord.begin(), n);
        rank.push_back(0);

        std::vector<int> bucket(n + 1), nrank(n + 1), idxs(n + 1);

        for (int k = 1; k < n; k <<= 1) {
            std::fill(bucket.begin(), bucket.end(), 0);

            // idxs is in acsending order by the last k characters
            for (int i = 0; i <= n; ++i) {
                idxs[i] = (ord[i] - k + n + 1) % (n + 1);
                ++bucket[rank[idxs[i]]];
            }

            for (int i = 1; i <= n; ++i) {
                bucket[i] += bucket[i - 1];
            }
            for (int i = n; i >= 0; --i) {
                ord[--bucket[rank[idxs[i]]]] = idxs[i];
            }

            int cnt = 0;
            for (int i = 0;; ++i) {
                nrank[ord[i]] = cnt;
                if (i == n) break;

                if (rank[ord[i]] != rank[ord[i + 1]] ||
                    rank[(ord[i] + k) % (n + 1)] !=
                        rank[(ord[i + 1] + k) % (n + 1)]) ++cnt;
            }
            std::swap(rank, nrank);
        }
    }
};

void solve() {
    int n, k;
    std::string s;
    std::cin >> n >> k >> s;

    std::string t = s;
    std::reverse(t.begin(), t.end());
    auto u = s + t;

    int si = 0;
    for (int i = 1; i < n; ++i) {
        if (u.substr(i, n) < u.substr(si, n)) si = i;
    }
    u = u.substr(si, n);

    int l;
    for (l = 0; l < n; ++l) {
        if (u[l] != u[0]) break;
    }
    auto back = u.substr(l);

    --k;
    while (l < n && k > 0) {
        l = std::min(n, l * 2);
        --k;
    }

    auto ans = std::string(l, u[0]) + back;
    ans = ans.substr(0, n);
    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n = sc.nextInt();
				int m = sc.nextInt();
				int a = sc.nextInt();
				if(n+m+a == 0) break;
				
				int[][] amida = new int[1001][n+1];
				while(m-- != 0) {
					int h = sc.nextInt();
					int p = sc.nextInt();
					int q = sc.nextInt();
					amida[h][p] = q;
					amida[h][q] = p;
				}
				
				int b = a;
				for(int h=1000; h>0; h--) {
					if(amida[h][b] != 0) b = amida[h][b];
				}
				System.out.println(b);
			}
		}
	}
}



Measured memory_bytes: 66712
'''
参考
https://kakedashi-engineer.appspot.com/2020/03/23/abc159d/
https://qiita.com/c-yan/items/83ae14b2fbf117355586
kを抜かない場合の方法の数を出し、そこからkを選ぶ場合の数を引く
'''
import collections

N = int(input())
A = list(map(int, input().split()))

# ボールに書かれた整数と、その個数の辞書を作成
D = collections.Counter(A)
L = {}
total = 0

# 辞書の整数=k、個数=vごとに
# その整数の個数の辞書=Lと
# 組み合わせ総数=totalを出す
for k, v in D.most_common():
    L[k] = v
    total += v * (v-1) // 2

for a in A:
    print(total - (L[a]-1))


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

int main(){
	int N,A;
	cin>>N;
	vector<int> vec(N+1);
	vector<int> ansvec(N+1);
	vec[0]=0;
	ansvec[0]=0;
	for(int i=1; i<=N; i++){
		cin>>A;
		vec[i]=A;
	}
	for(int i=1; i<=N; i++){
	ansvec[vec[i]]=i;
	}	
	for(int i=1; i<=N; i++){
		
		cout<<ansvec[i]<<" ";
	}
}
	

Measured memory_bytes: 1536
import sys
import numpy as np
import itertools

[N,M] = input().split()
N = int(N)
M = int(M)
a =[]
p = []
list_bin = []

for j in range(M):
    list_temp = [int(s) for s in input().split()]
    list_temp.pop(0)
    for i in range(N):
        if i+1 in list_temp:
            list_bin.append(1)
        else:
            list_bin.append(0)

    a.append(list_bin)
    list_bin = []
p = [int(s) for s in input().split()]

arr_switch = np.array(a)
arr_p = np.array(p)
arr_pattern = np.array(list(itertools.product([0,1], repeat=N)))

count = 0
flag = 1
for switch in arr_pattern:
    for m in range(M):
        if (not (np.dot(switch, arr_switch[m]) % 2 == arr_p[m])) or  (np.dot(switch, np.ones(N)) == -1):
           flag = 0
    if flag == 1:
        count = count + 1
    flag=1
print(count)


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

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

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
void solve()
{
    int K;
    cin >> K;
    cout << a[K - 1] << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--;y--;
        uf.merge(x,y);
    }
    int cnt=0;
    rep(i,n){
        if(uf.issame(p[i]-1,i)){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    
}


Measured memory_bytes: 2176
def mC2(m)
  m * (m - 1) / 2
end

N = $stdin.gets.to_i
A = $stdin.gets.split.map {|i| i.to_i }
counts = {}
A.each do |a|
  if counts.has_key?(a)
    counts[a] += 1
  else
    counts[a] = 1
  end
end
mC2s = {}
total = 0
counts.each do |a, c|
  mc2 = mC2(c)
  mC2s[a] = mc2
  total += mc2
end
A.each do |a|
  c = counts[a]
  puts total - mC2s[a] + mC2(c - 1)
end


Measured memory_bytes: 36868
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int Q, F, type;
  char C;
  cin >> Q;
  int cnt = 0;
  string mae = "", ato = "";
  while(Q>0){
    Q--;
    cin >> type;
    if(type == 1) cnt++;
    else{
      cin >> F >> C;
      if(F == 1){
        if(cnt % 2 == 0) mae = C + mae;
        else ato = ato + C;
      }else{
        if(cnt % 2 == 0) ato = ato + C;
        else mae = C + mae;
      }
    }
  }
  S = mae + S;
  S = S + ato;
  if(cnt%2 == 1) reverse(ALL(S));
  cout << S;
  return 0;
}


Measured memory_bytes: 1320
#n = int(input())
n,a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

#if a+b > n:
#    print(a)
#    exit()

taba = a+b

sho = n//taba
amari = n%taba
if amari >= a:
    amari = a
else:
    amari = amari
ans = sho*a + amari

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include<vector>
#include <utility>
#include <string>

using namespace std;

int main(){
  int n,a,b,c,i,j,k;
  string s;
  int x,y;
  long long ans=0;
  cin >> a >> b >> c >> x >> y;
  if(a+b>2*c){
    ans+=2*min(x,y)*c;
  }else{
    ans+=min(x,y)*(a+b);
  }
  k=min(x,y);
  x-=k;
  y-=k;
  if(x!=0){
    if(a>2*c){
      ans+=x*2*c;
    }else{
      ans+=a*x;
    }
  }else if(y!=0){
    if(b>2*c){
      ans+=y*2*c;
    }else{
      ans+=b*y;
    }
  }
//  cout << x << " " << y << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    int n, m;
    std::vector<int> days;
    std::cin >> n;
    std::cin >> m;
    for(int i = 0; i < m; i++)
    {
        int a;
        std::cin >> a;
        days.push_back(a);
    }

    int sum = std::accumulate(days.begin(), days.end(), 0);
    int ans = n - sum >= 0 ? n - sum : -1;

    std::cout << ans;

    return EXIT_SUCCESS;
} 


Measured memory_bytes: 3292
#include<cstdio>
int main()
{
	int n,t[100005],m,p,x,sum,sum2;
	while(scanf("%d",&n)!=EOF)
	{
		sum=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&t[i]);
			sum=sum+t[i];
		}
		scanf("%d",&m);
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&p);
			scanf("%d",&x);
			sum2=sum+x-t[p];
			printf("%d\n",sum2);
		}
		    
	}
	return 0;
}



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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  ll n, a, b; cin >> n >> a >> b;
  vector<ll> x(n); REP(i,n) cin >> x[i];
  ll res = 0;
  FOR(i,1,n) {
    if ((x[i] - x[i-1])*a >= b) res+= b;
    else res += (x[i]-x[i-1])*a;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

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

    bool flag = true;
    string ans = "Yes";
    int max = H[0];
    for(int i=1; i<N; i++){
        if(H[i] > max){
            max = H[i];
        }
        if(H[i] < max -1){
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

bool parity(int n){
  if(n*n*n*n%10 == 1)
    return true;
  else
    return false;
}

int power(int x, int y){
  int64_t n = 1ll;
  for(int i = 0; i < y; i++)
    n *= x;
  return n;
}
int digit(int64_t x, int y){
  return x%power(10,y+1)/power(10,y);
}

int main() {
  
  long long n;
  cin >> n;
  
  long long i,j;
  
  long long k = 1;
  while(k*k <= n){
    if(n%k == 0){
      i = k;
      j = n/k;
    }
    k++;
  }
  
  cout << i+j-2 << endl;
  
}

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

int main(){
    int n,al=0,bo=0;
    cin >> n;
    vector<int> a(n);

    for(int i=0;i<n;i++) cin >> a.at(i);
    for(int i=0;i<n;i++){
        int max=0,maxnum;
        for(int j=0;j<a.size();j++){
            if(max < a.at(j)){
                max = a.at(j);
                maxnum = j;
            }
        }
        if(i % 2 == 0){
            al += max;
        }else{
            bo += max;
        }
        a.erase(a.begin() + maxnum);
    }
    cout << al - bo << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

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


	int N;
	cin >> N;
	ll A[300000];
	rep(i, N) cin >> A[i];

	int kazu[60] = {};
	rep(i, N) {
		rep(j, 60) {
			kazu[j] += A[i] >> j & 1;
		}
	}

	ll kotae[60] = {};
	rep(i, N) {
		rep(j, 60) {
			kazu[j] -= A[i] >> j & 1;
		}

		rep(j, 60) {
			if (A[i] >> j & 1) {
				kotae[j] += N - 1 - kazu[j];
			}
			else {
				kotae[j] += kazu[j];
			}
		}

		rep(j, 60) {
			kazu[j] += A[i] >> j & 1;
		}
	}

	ll ans = 0;
	rep(i, 60) {
		kotae[i] %= mod;
		ll tmp = (1ll << i) % mod;
		ans += kotae[i] * tmp % mod;
	}
	ans %= mod;
	co(ans * modpow(2, mod - 2) % mod);


	Would you please return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000


int main(){
	
	int N;
	cin>>N;
	
	vector<int> a(N);
	
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	
	sort(a.begin(),a.end());
	
	cout<<a.back()-a.front()<<endl;
	
	
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

string hoge(int x){
    string ret = to_string(x + 1);
    while (ret.size() < 6) ret = '0' + ret;
    return ret;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<P> > p(n);
    REP(i,m){
        int x = in() - 1, y = in();
        p[x].push_back(P(y, i));
    }
    REP(i,n) sort(ALL(p[i]));

    vector<string> ans(m);
    REP(i,n){
        REP(j,p[i].size()){
            ans[p[i][j].second] = hoge(i) + hoge(j);
        }
    }

    REP(i,m) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 12416
from collections import defaultdict
n = int(input())
bars = list(map(int, input().split()))
bars.sort(reverse=True)
sides = defaultdict(int)
decided = []
ans = 0

for b in bars:
    sides[b] += 1
    if sides[b] == 2:
        decided.append(b)
        sides[b] -= 2
    if len(decided) == 2:
        ans = decided[0] * decided[1]
        break

print(ans)

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

int x[101] = {0};
int main() 
{
  int N = 0, K = 0, i = 0, ans = 0;
  cin >> N >> K;
  for (i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (i = 0; i < N; i++) {
    int a = x[i] * 2;
    int b = (K - x[i]) * 2;
    if (a < b) {
      ans += a;
    } else {
      ans += b;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val(n, k) = readLine()!!.split(" ").map(String::toInt)
    val s = readLine()!!

    var same = 0
    for(i in 0..n-2){
        if(s[i] == s[i+1]) same++
    }

    println(Math.min(n - 1, same + 2 * k))
}


Measured memory_bytes: 38360
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];

  vector<int> ans;
  int cur = -1;
  vector<bool> used(n, false);
  do {
    int p = 1;
    int u = -1;
    rep(i,n) if(!used[i]){
      dbg(i,p);
      if(v[i] == p) {
        cur = p;
        u = i;
      }
      p++;
    }
    if(cur == -1) break;
    ans.push_back(cur);
    cur = -1;
    used[u] = true;
    dbg(ans);
  } while(ans.size() < n);

  if(ans.size() != n) cout << -1 << endl;
  else {
    reverse(all(ans));
    rep(i,n) cout << ans[i] << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sz 1000009
using namespace std;
ll int mark[sz+2],prime[sz+2],np,i,j,num;
void seive() {
    prime[np++]=2;
    for(i=3; i<=sz; i+=2)
    {
        if(mark[i]==0)
        {
            prime[np++]=i;
            for(j=i*i; j<=sz; j+=2*i)
            {
                mark[j]=1;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    seive();
   ll int n,m,s=1;
   cin>>n>>m;
   ll d=__gcd(n,m);
 
   for(int i=0;prime[i]*prime[i]<=d&&i<np;i++)
   {
       if(d%prime[i]==0)
       {
            s++;
            while(d%prime[i]==0)d=d/prime[i];
       }
   }
   if(d!=1)s++;
   cout<<s<<endl;
  
    return 0;
}



Measured memory_bytes: 10368
//Hey u r far away to know this
#include <bits/stdc++.h>
using namespace std;
#define     ff                  first
#define     pb                  push_back
#define     ss                  second
#define     ll                  long long
#define     MAX                 5000
#define     mpi                 map<int, int>
#define     mpll                map<ll, ll>
#define     pll                 pair<ll, ll>
#define     plld                pair<ll, double>
#define     SKILLER             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     vi                  std::vector<int>
#define     vll                 std::vector<ll>
#define     vs                  std::vector<string>
#define     vvi                 std::vector<std::vector<int>>
#define     vvll                std::vector<std::vector<ll>>
#define     all(v)              v.begin(), v.end()
#define     allr(v)              v.rbegin(), v.rend()
#define     loop(i, a, b)     for(int i = a; i < b; i++)
#define       debug(x)         cout << x <<" " <<"\n";
#define       debug1(x, y)     cout << x << " " << y  << "\n";
#define       debug2(x, y, z)     cout << x << " " << y << " " << z<<"\n";
#define       int             ll
const   int N = 1e6+5, Mod = 1e9 + 7;
int32_t main(){
        SKILLER;
       
        int x; cin >> x;
        if(x >= 400 and x <= 599){
            cout << '8';
            return 0;
        }
        if(x >= 600 and x <= 799){
            cout << '7';
            return 0;
        }
        if(x >= 800 and x <= 999){
            cout << '6';
            return 0;
        }
        if(x >= 1000 and x <= 1199){
            cout << '5';
            return 0;
        }
        if(x >= 1200 and x <= 1399){
            cout << '4';
            return 0;
        }
        if(x >= 1400 and x <= 1599){
            cout << '3';
            return 0;
        }
        if(x >= 1600 and x <= 1799){
            cout << '2';
            return 0;
        }
        if(x >= 1800 and x <= 1999){
            cout << '1';
            return 0;
        }
        return 0;
}

Measured memory_bytes: 3636
fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}.toIntArray()

fun <T> T.print() = println(this)

fun main() {
	abc000X()
}

fun abc000X() {
	val (a,b)=list()
	for(i in 0..100){
		for(j in 0..100){
			if(i+j==a&&i*2+j*4==b){
				println("Yes")
				return
			}
		}
	}
	println("No")
}


Measured memory_bytes: 36520
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define N 200009
#define inf 1e18
int mod=1e9+7;
//int mod=998244353;
#define P pair<int,int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()

#define ordered_set tree<P, null_type,less<P>, rb_tree_tag,tree_order_statistics_node_update> 

bool vis[N];
int no=0;

void solve(){
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	int curr=1;
	//vis[curr]=1;
	int rem=k;
	if(k>2*n){
	int len=0;
	while(1){
		if(vis[curr]){
			break;
		}
		vis[curr]=1;len++;
		curr=a[curr];
	}
	int c=curr;
	memset(vis,0,sizeof(vis));
	no=0;
	while(1){
		if(vis[c])break;
		vis[c]=1;
		c=a[c];
		no++;
	}
	k-=(len-no);
	int cyc=no;
	rem=k%cyc;
	}
	//cout<<curr<<" "<<cyc<<" "<<rem<<"\n";
	for(int i=1;i<=rem;i++){
		curr=a[curr];
	}
	cout<<curr<<"\n";
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;//cin>>t;
	while(t--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 5356
N, K = list(map(int,raw_input().split()))
h  = list(map(int,raw_input().split()))
c = [0 for i in range(N)]
for j in range(1, N):
  c[j] = min([c[i]+abs(h[i]-h[j]) for i in range(max(0,j-K), j)])
print(c[-1])

Measured memory_bytes: 42348
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long n = sc.nextInt();
		long ans = (n - 1 + 1) * (n - 1) / 2;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,M; cin >> N >> M;
    int A[N][M]; int b[M];
    rep(i,N){
        rep(j,M){
            cin >> A[i][j];
        }
    }
    rep(i,M) cin >> b[i];
    rep(i,N){
        int sum=0;
        rep(j,M){
            sum+=A[i][j]*b[j];
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3172
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;



int main() {
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n+1) {
        cin >> a[i];
    }
    if(!n) {
        if(a[0] == 1) {
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    vi sum(n+1);
    sum[n] = a[n];
    rep(i, n){
        sum[n-i-1] = sum[n-i]+a[n-i-1];
    }
    bool x = true;
    vi vec(n+1);
    vec[0] = 1;
    if(a[0] == 1) x = false;
    rep(i, n) {
        vec[i+1] = vec[i]-a[i];
        if(vec[i+1]*2-a[i+1] <= 0) {
            if(i != n-1) x = false;
            if(i == n-1 && vec[i+1]*2-a[i+1] < 0) x = false;
        }
        vec[i+1] *= 2;
        if(vec[i+1] > sum[i+1]) {
            vec[i+1] = sum[i+1];
        }
    }

    ll ans = 0;
    rep(i, n+1) {
        //cout << sum[i] << endl;
        ans += vec[i];
    }
    if(!x) {
        cout << -1 << endl;
        return 0;
    }
    cout <<ans << endl;

    
}

Measured memory_bytes: 5636
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
using namespace std;
int H, W, h, w;
vector<string> field;
char s[101][101];
char b[103][103];
int main() {
    cin >> h >> w;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            cin >> s[i][j];
        }
    }
    for(int i=0; i<h+2; ++i){
        for(int j=0; j<w+2; ++j){
            b[i][j] = '#';
        }
    }
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            b[i+1][j+1]=s[i][j];
            
        }
    }
    
    for(int i=0; i<h+2; ++i){
        for(int j=0; j<w+2; ++j){
            cout << b[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,x,L[200001],A[200001];
    cin>>n>>x;
    rep(i,n) cin>>L[i];
    A[0]=0;
    rep(i,n) A[i+1]=A[i]+L[i];
    int ans=0;
    rep(i,n+1) if(A[i]<=x) ans++;
    cout<<ans;
}


Measured memory_bytes: 2304
#include<cstdio>


using namespace std;

int main(){
    char s[11], t[11];
    scanf("%s %s", s, t);
    int s_size, t_size;
    for(int i = 0; i < 11; i++){
        if (s[i] == 0){
            s_size = i - 1;
            break;
        }
    }
    for(int i = 0; i < 11; i++){
        if (t[i] == 0){
            t_size = i - 1;
            break;
        }
    }
    int a, b;
    scanf("%d %d", &a, &b);
    char u[11];
    scanf("%s", u);
    for(int i = 0; i <= s_size; i++){
        if (s[i] != u[i]){
            break;
        }
        if (i == s_size){
            printf("%d %d\n", a - 1, b);
            return 0;
        }
    }
    printf("%d %d\n", a, b - 1);
}

Measured memory_bytes: 128
import Control.Arrow ((***))
import Data.List

sortDesc = sortBy (flip compare)

main = do
  n <- readLn
  xs <- (map read . words) <$> getLine
  let (alice, bob) = (map snd *** map snd) $ partition (odd . fst) $ zip [1..n] $ sortDesc xs
  print $ sum alice - sum bob


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll a[N],prime[N],k,vis[N];
int n,flag=0;
bool isprime[N];
void Prime(){
    fill(isprime,isprime+N,1);
    k=0;
    prime[1]=0;
    for(ll i=2;i<N;i++){
        if(isprime[i]){
            prime[k++]=i;
            for(ll j=2;i*j<N;j++)
                isprime[i*j]=0;
        }
    }
}

void solve(ll n){
    for(ll i=0;i<k&&prime[i]*prime[i]<=n;i++){
        if(n%prime[i]==0){
            if(vis[prime[i]]==0) vis[prime[i]]=1;
            else{
                flag=1;
                return;
            }
            while(n%prime[i]==0){
                n/=prime[i];
            }
        }
    }
    if(n>1){
         if(vis[n]==0) vis[n]=1;
        else{
            flag=1;
            return;
        }
    }
}

inline ll gcd(ll a,ll b)
{
    return (a%b==0)?b:gcd(b,a%b);
}

int main(){
    Prime();
    cin>>n;
    ll GCD=0;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(!flag) solve(a[i]);
        if(GCD==0) GCD=a[i];
        else GCD=gcd(GCD,a[i]);
    }
    if(!flag) printf("pairwise coprime");
    else if(flag&&GCD==1) printf("setwise coprime");
    else printf("not coprime");
}


Measured memory_bytes: 13816
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
///-------------------------------------------


int gcd(int a,int b) { return b?gcd(b,a%b):a; }
set<int> rec;
int main(){
    int N;
    cin>>N;
    int cnt=0;
    while(N--){
        int x; scanf("%d",&x);
        if(rec.count(x)) rec.erase(x);
        else rec.insert(x);
    }
    cout<<rec.size()<<endl;
}





















Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int S(string s)
{
    int value = 0;
    rep(i, s.size())
    {
        value += s[i] - '0';
    }
    return value;
}

int main()
{
    string s;
    cin >> s;
    int num=stoi(s);
    if(num%S(s)==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256