akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

struct cards
{
	char s;
	int  v;
};

void bblsort( cards c[], int N )
{
	for( int i = 0; i < N; i++ ) {
		for( int j = N - 1; j > i; j-- ) {
			if( c[ j ].v < c[ j - 1 ].v ) {
				swap( c[ j ], c[ j - 1 ] );
			}
		}
	}
}

void selsort( cards c[], int N )
{
	for( int i = 0; i < N; i++ ) {
		int mini = i;
		for( int j = i; j < N; j++ ) {
			if( c[ j ].v < c[ mini ].v ) {
				mini = j;
			}
		}
		swap( c[ i ], c[ mini ] );
	}
}

void copy( cards c[], cards d[], int N )
{
	for( int i = 0; i < N; i++ ) {
		d[ i ] = c[ i ];
	}
}

void dump( cards c[], int N )
{
	for( int i = 0; i < N; i++ ) {
		cout << c[ i ].s << c[ i ].v;
		if( i != N -1 ) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
}

void chkstable( cards s[], cards c[], int N )
{
	bool isstable = true;
	for( int i = 0; i < N; i++ ) {
		if( s[ i ].s != c[ i ].s and s[ i ].v == c[ i ].v ) {
			isstable = false;
		}
	}

	if( isstable == true ) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
}

int main()
{
	int N;
	cin >> N;
	cards c[ N ];
	for( int i = 0; i < N; i++ ) {
		string tmp;
		cin >> tmp;
		c[ i ].s = tmp[ 0 ];
		c[ i ].v = tmp[ 1 ] - '0';
	}

	cards b[ N ];
	copy( c, b, N );
	bblsort( b, N );
	dump( b, N );
	chkstable( b, b, N );

	cards s[ N ];
	copy( c, s, N );
	selsort( s, N );
	dump( s, N );
	chkstable( b, s, N );

	return 0;
}



Measured memory_bytes: 3096
#include<stdio.h>
int main(void){
  int i,n,cnt,c,a,ha;

  scanf("%d",&ha);
  
  for(i=0;i<ha;i++){
    cnt=0;
    scanf("%d %d %d",&c,&a,&n);
    while(1){
      if(1<=c&&1<=a&&1<=n){
	c--;a--;n--;cnt++;
      }else if(2<=c&&1<=a){
	c-=2;a--;cnt++;
      }else if(3<=c){
	c-=3;cnt++;
      }else{
	break;
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
#include <math.h>

using namespace std;
typedef long long ll;
///定義場所///
ll i, j, k, l, m, n;
ll N, M, K, H, W, T, P;
ll MOD = 1000000000+7;
//ll ans = 0;
//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<int ,int> firstElof, pair<int,int> secondElof)
{
	return firstElof.second < secondElof.second;
}
int Keta(ll F) {
	int keta = 1;
	while (F/10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
//////////////

int main() {
	cin >> N >> K;
	ll shikiri = N - K + 1;
	for (i = 1; i <= K; i++) {
		ll put = 1;
		ll k = shikiri;
		while (k >= shikiri - i + 1) {
			put = (put * k) % MOD;
			k--;
		}
		k = i;
		while (k >= 2) {
			put = (put * modinv(k,MOD)) % MOD;
			k--;
		}
		//ここまでで青塊の置き方の通りを決めた
		//それぞれの青塊に何個青を置くか
		ll aodama = 1;
		ll j = K - 1;
		for (l = 0; l < i - 1; l++) {
			aodama = (aodama * j) % MOD;
			j--;
		}
		for (l = 2; l <= i - 1; l++) {
			aodama = (aodama * modinv(l,MOD)) % MOD;
		}
		cout << (put * aodama) % MOD << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> B = new List<int>();
    static decimal result;
    static int N;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく



    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        // delegate int CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。
        //PriorityQueue pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
        Read1();
        Read2(N-1);
      int[] A=new int[N];
      A[0]=B[0];
      for(int i=1;i<N-1;i++){if(B[i]>B[i-1]){A[i]=B[i-1];}else{A[i]=B[i];}}
      A[N-1]=B[N-2];
      for(int i=0;i<N;i++){result+=A[i];}
        Console.WriteLine(result.ToString());
    }


    static void Read1()
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2(int kosuu)
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < kosuu; i++) { B.Add(int.Parse(tmp[i])); }
    }

}

Measured memory_bytes: 13268
s = raw_input()
k = x = 0
try:
        while 1:
                cj = co = ci = 0
                while s[x] == "J":
                        cj += 1
                        x += 1
                while s[x] == "O":
                        co += 1
                        x += 1
                while s[x] == "I":
                        ci += 1
                        x += 1
                if co <= cj and co <= ci:
                        k = max(co,k)
except IndexError:
        if co <= cj and co <= ci:
                k = max(co,k)
        print(k)

Measured memory_bytes: 5324
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    ll x;
    cin >> x;
    int n500 = x / 500;
    x %= 500;
    int n5 = x / 5;
    ll ans = n500 * 1000 + n5 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int n = A - B;
	string ans = "N";

	if (n>=0) {
		ans = "delicious";
	}
	else {
		if (abs(n) <= X) ans = "safe";
		else ans = "dangerous";
	}

	cout << ans << endl;
}

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

int main(){
  int n[10];
  cin>>n[0]>>n[1]>>n[2];
  sort(n,n+3);
  if(n[0]==n[1]){
    cout<<n[2]-n[0];
    return 0;
  }
  int a=n[1]-n[0];
  int b=n[2]-n[0];
  if(b%2==0){
    if(a%2==0){
      cout<<(2*b-a)/2<<"\n";
    }else{
      cout<<(2*b-a+1)/2+1<<"\n";
    }
  }else{
    b--;
    if(a%2==0){
      cout<<(2*b-a)/2+1<<"\n";
    }else{
      cout<<(2*b-a+1)/2+2<<"\n";
    }
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  int a[n + 2];
  a[0] = a[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int sum = 0;
  for (int i = 0; i < n + 1; i++) {
    sum += abs(a[i] - a[i + 1]);
  }

  for (int i = 1; i <= n; i++) {
    int ans = sum;
    ans -= abs(a[i - 1] - a[i]);
    ans -= abs(a[i] - a[i + 1]);
    ans += abs(a[i - 1] - a[i + 1]);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
using namespace std;

vector<double> out;
int main() {
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<double> s(n);
        double ave = 0;
        for(int i = 0; i < n; i++){
            cin >> s[i];
            ave += s[i];
        }

        ave /= n;
        double ans = 0;
        vector<double> b(n);
        for(int i = 0; i < n; i++){
            double tmp = s[i] - ave;
            b[i] = tmp * tmp;
            ans += b[i];
        }

        //printf("%lf\n", sqrt(ans / n));
        out.push_back(ans/n);
    }

    for(int i = 0; i < out.size(); i++){
        printf("%.8lf\n", sqrt(out[i]));
    }
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define double long double
const int mod = 1e9 + 7;
const int K = 26;

int32_t main()
{   
    fastio;
    
    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    int a[n][m];
    for(int i=0; i<n; i++){
    	cin >> c[i];
    	for(int j=0; j<m; j++){
    		cin >> a[i][j];
    	}
    }

    int cost = -1;
    for(int i=0; i<(1LL<<n); i++){
    	//cout << i << endl;
    	vector<int> b(m,0);
    	int temp = 0;
    	for(int j=0; j<n; j++){
    		int idx = (1LL<<j);
    		if(i&idx){
    			for(int k=0; k<m; k++){
    				b[k] += a[j][k];
    			}
    			temp += c[j];
    		}
    	}
    	bool pass = true;
    	for(int j=0; j<m; j++){
    		//cout << b[i] << " ";
    		if(b[j] < x){
    			pass = false;
    			break;
    		}
    	}
    	//cout << endl;
    	if(pass){
    		if(cost == -1) cost = temp;
    		cost = min(cost, temp);
    	}
    }

    cout << cost << endl;
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> count(N);
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    while (vec.at(i) % 2 == 0) {
      vec.at(i) /= 2;
      count.at(i) += 1;
    }
  }
  sort(count.begin(), count.end());
  cout << count.at(0) << endl;
}


Measured memory_bytes: 256
function inc(dp,S,a)
  for i=S:-1:a
    dp[i+1]+=dp[i-a+1]
    if dp[i+1]>=998244353
      dp[i+1]-=998244353
    end
  end
end
function main()
  N,S=map(x->parse(Int,x),split(readline()))
  dp=zeros(Int,S+1)
  ans=0
  const mod=998244353
  for a=map(x->parse(Int,x),split(readline()))
    dp[1]+=1
    inc(dp,S,a)
    ans+=dp[S+1]
  end
  println(ans%mod)
end
main()

Measured memory_bytes: 111960
import numpy as np

n = int(input())
P = input()
P = P.split(' ')

count = 0
for i in range(1, n-1):
    p_1 = int(P[i-1])
    p_2 = int(P[i])
    p_3 = int(P[i+1])
    
    p_list = np.argsort([p_1, p_2, p_3])
    if p_list[1] == 1:
        count += 1
print(count)

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

int N;
int A[100][100]={0};
int m=0;

int search(int sum, int right, int down){
    if(right==N-1 && down==1){
        if(sum>m) m = sum;
    }
    else if(right==N-1){
        search(sum+A[down+1][right], right, down+1);
    }
    else if(down==1){
        search(sum+A[down][right+1], right+1, down);
    }
    else{
        search(sum+A[down][right+1], right+1, down);
        search(sum+A[down+1][right], right, down+1);
    }
    
    return m;
}

int main(){
    cin >> N;
    int M=0;
    
    for(int i=0; i<2; i++){
        for(int j=0; j<N; j++){
            cin >> A[i][j];
        }
    }
    M = search(A[0][0], 0, 0);
    
    cout << M << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }

int main()
{
    int n,A=0,B=0,i=1;
    cin>>n;
    vi a(n),b(n),c(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)c[i]=i+1;
    do{
        if(c==a) A=i;
        if(c==b) B=i;
        i++;
    }while(next_permutation(all(c)));
//    cout<<A<<" "<<B<<endl;
    cout<<abs(B-A)<<endl;
}

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

d_num = (10 ** 9) + 7

if N == 1:
    print(0)
elif N == 2:
    print(2)
else:
    ans = 10 ** N - 2 * (9 ** N) + (8 ** N)
    ans = ans % d_num
    print(ans)

Measured memory_bytes: 11012
#include <iostream>
using namespace std;
bool overlap(int a, int b, int c, int d){
  if ( d <= a ) return false;
  if ( b <= c ) return false;
  return true;
}
int main(void){
  int a, b, s, f, n;
  cin >> a >> b >> n;
  for ( int i = 0; i < n; i++ ){
    cin >> s >> f;
    if ( overlap(a, b, s, f) ){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}



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

const int dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 }, MAXN = 1005;
char mp[MAXN][MAXN];
queue<pair<pair<int, int>, int> > Q;
bool se[MAXN][MAXN];
int n, m, ans;

bool isval(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < m;
}
void addv(pair<int, int> v, int d) {
	for (int i = 0; i < 4; i++) {
		int nx = v.first + dx[i], ny = v.second + dy[i];
		if (isval(nx, ny) && !se[nx][ny])
			Q.push({ { nx, ny }, d + 1 }), se[nx][ny] = 1;
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			cin >> mp[i][j];
			if (mp[i][j] == '#')
				Q.push({ {i, j}, 0 }), se[i][j] = 1;
		}
	while (!Q.empty()) {
		addv(Q.front().first, Q.front().second);
		ans = max(ans, Q.front().second);
		Q.pop();
	}
	cout << ans;
}

Measured memory_bytes: 14352
def main(n:int,t:int,lst:list):
    lst=list(filter(lambda x:x[1]<=t,lst))
    if len(lst):
        return min(map(lambda x:x[0],lst))
    else:
        return "TLE"
n,t=map(int,input().split())
lst=[list(map(int,input().split()))for i in range(n)]
print(main(n,t,lst))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;

int main()
{
    lint N, K;
    cin >> N >> K;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    vector<lint> F(N);
    REP(i, N) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<lint>());
    lint l = 0;
    lint r = 1e12;
    lint m = (l+r) / 2;
    lint anstmp = 1e12;
    while(l <= r){
        lint need = 0;
        REP(i, N) {
            if(A[i]*F[i] > m) {
                need += (A[i]*F[i]-m-1) / F[i] + 1;
            }
        }
        if(need > K) {
            l = m + 1;
        } else {
            if(m < anstmp) {
                anstmp = m;
            }
            r = m - 1;
        }
        m = (l+r) / 2;
    }
    cout << anstmp << endl;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	string s,t;

	cin >> N >> s >> t;

	int ans = 0;
	for(int i = 1; i <= N; i++){
		// cerr << s.substr((int)s.size()-i,i) << " " <<  t.substr(0,i) << endl;
		if(s.substr((int)s.size()-i,i) == t.substr(0,i))
			ans = i;
	}

	cout << 2*N-ans << endl;

	return 0;
}

Measured memory_bytes: 256
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let H,N = RS int64|>fun c -> c.[0],c.[1]
    RS int64
    |>Array.sum
    |>fun c -> if c>=H then "Yes" else "No"
    |>stdout.WriteLine
    0

Measured memory_bytes: 17376
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	if !sc.Scan() {
		panic("cannot read stdin")
	}
	s := strings.Split(sc.Text(), " ")

	var a, b int
	var err error
	if a, err = strconv.Atoi(s[0]); err != nil {
		panic(err)
	}
	if b, err = strconv.Atoi(s[1]); err != nil {
		panic(err)
	}

	// 下記の性質を使ったもの
	// 任意の偶数nについて、n xor (n + 1) = 1
	// * aが奇数の場合、bが偶数の場合には初期値にセット
	l := b - a + 1
	res := -1
	if a%2 == 1 {
		res = a
		l--
	}
	if b%2 == 0 {
		if res < 0 {
			res = b
		} else {
			res = res ^ b
		}
		l--
	}

	// * 偶数とそれに続く奇数のXORが1になる性質+XORの性質を用いて残りの箇所の計算結果を取得
	c := (l / 2) % 2
	if res < 0 {
		res = c
	} else {
		res = res ^ c
	}

	fmt.Println(res)

	// 地道に計算する方法: TLEになる
	// maxLen := len(fmt.Sprintf("%b", b))
	// digits := make([]int, maxLen)
	// for ; a <= b; a++ {
	// 	v := zerofill(fmt.Sprintf("%b", a), maxLen)
	// 	for i, b := range v {
	// 		bInt, err := strconv.Atoi(string(b))
	// 		if err != nil {
	// 			panic(err)
	// 		}
	// 		digits[i] += bInt
	// 	}
	// }

	// var sum int
	// for i := 0; i < maxLen; i++ {
	// 	b := digits[i] % 2
	// 	sum += b * int(math.Pow(2, float64(i)))
	// }

	// fmt.Println(sum)
}

func zerofill(b string, l int) string {
	for len(b) < l {
		b = "0" + b
	}

	return b
}

Measured memory_bytes: 640
from collections import Counter
import math

N, P = map(int,input().split())
if N >= 41:
    print(1)
    exit(0)
if N >= P:
    print(1)
    exit(0)
if N == 1:
    print(P)
    exit(0)
if N == 2:
    M = P
    Q = []
    k = 2
    while k*k <= M:
        if M%k == 0:
            M //= k
            Q.append(k)
        else:
            k += 1
    if M > 1:
        Q.append(M)
    R = Counter(Q)
    ans = 1
    for k in R:
        if R[k] >= 2:
            ans *= k**(R[k]//2)
    print(ans)
    exit(0)

ans = 1
k = 1
while pow(k,N) <= P:
    if P%pow(k,N)==0:
        ans = k
    k += 1

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int n; cin >> n;
	int ans = 0;
	for(int i = 0; i < n; ++i){
		int a, b;
		cin >> a >> b;
		ans += b - a + 1;
	}
	cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i =0;i<N;i++)
    cin >>vec.at(i);
  for (int i=0;i<N;i++){
    for(int j=0;j<N-1;j++){
      if(vec.at(j) <vec.at(j+1)){
        int a = vec.at(j);
        vec.at(j) = vec.at(j+1);
        vec.at(j+1) = a;
      }
    }
  }
  int count = 0;
  for(int i=0;i<N;i++){
    if(i %2 == 0)
      count += vec.at(i);
    else
      count -= vec.at(i);
  }
  cout << count <<endl;
     
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
 
int main(){
    int n; string s,s2;
    cin >> n >> s >> s2;
    ll ans;
    vector<char> v;
    int i = 0;
    while(i < n) {
        if(s[i] == s[i + 1]) {
            v.pb('b');
            i += 2;
        }else{
            v.pb('a');
            i++;
        }
    }
    if(v[0] == 'a') ans = 3;
    else ans = 6;
    for(int j = 0;j < v.size() - 1;j++) {
        if(v[j] == 'a' && v[j+1] == 'a'){
            ans *= 2;
            ans %= MOD;
        }else if(v[j] == 'a' && v[j+1] == 'b'){
            ans *= 2;
            ans %= MOD;
        }else if(v[j] == 'b' && v[j+1] == 'b'){
            ans *= 3;
            ans %= MOD;
        }
    }
    cout << ans % MOD << endl;
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    sx,sy,tx,ty=list(map(int,input().split()))
    dx,dy=tx-sx,ty-sy
   
    s=""
    s+="R"*dx+"U"*dy
    s+="L"*dx+"D"*dy
    s+="D"+"R"*(dx+1)+"U"*(dy+1)+"L"
    s+="U"+"L"*(dx+1)+"D"*(dy+1)+"R"
    print(s)
    
    
if __name__=="__main__":
    main()
    

Measured memory_bytes: 3060
def main():
    red_box, green_box, blue_box, target = map(int, input().split())
    answer = 0
    for i in range(target // red_box + 1):
        for j in range(target // green_box + 1):
            now_balls = red_box * i + green_box * j
            if (target - now_balls) % blue_box == 0 and target >= now_balls:
                answer += 1
            elif target < now_balls:
                break
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INA(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : -(a))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

string s;
int n;

ll ful[MAXN];
ll haimu[MAXN];

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> s;
	n = s.size();
	
}


void preprocess() {
	
	ful[0] = haimu[0] = 1;
	FOR(i, 1, n) {
		ful[i] = ful[i-1]*3 % MOD;
		haimu[i] = haimu[i-1] * 2 % MOD;
	}
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	int cnt1 = 0;
	ll res = 0;
	
	FOR(i, 0, n-1) {
		if (s[i] == '1') {
			res = (res + haimu[cnt1] * ful[n-1-i]) % MOD;
			cnt1++;
		}
	}
	
	res = (res + haimu[cnt1]) % MOD;
	
	cout << res << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


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

int main() {
  
  int N; string S, front, back; cin >> N >> S;
  
  front = S.substr(0, N / 2); back = S.substr(N / 2, N / 2);
  
  if (N % 2 == 0 && front == back) cout << "Yes" << endl;
  
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

const int dx4[] = { 1, 0, -1, 0 }, dy4[] = { 0, 1, 0, -1 };
const int dx8[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy8[] = { 0, -1, -1, -1, 0, 1, 1, 1 };



template<typename T>
bool chmax(T& a, T b, bool equal = false) {
	if (a < b || equal && a == b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false) {
	if (b < a || equal && a == b) {
		a = b;
		return true;
	}
	return false;
}



/******************************************************************************************/

ll dp[100000][5];

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	
	bool flag1 = (s[0] == s.back());
	bool flag2 = (s.size() % 2 == 1);

	if(flag1^flag2){
		cout << "First" << endl;
	}
	else
	{
		cout << "Second" << endl;
	}







	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string> 
#include <vector>                                                               #include <utility>                                                              #include <map>
#include <algorithm>
                                                                                using namespace std;

int main()
{                                                                                 int N, K;
  cin >> N >> K;
  int v = 1;
  int n = 0;                                                                      for (; n < N; ++n) {
    if (v > K) break;
    v += v;
  }
  for (; n < N; ++n) v += K;
  cout << v << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int num[1010];
    int sum = 0;

    cin >> n;

    for (int i = 0; i < 2*n; i++) cin >> num[i];

    sort(num, num+(n*2));

    for (int i = 0; i < 2*n; i += 2) {
        sum += min(num[i], num[i+1]);
    }

    cout << sum << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

int n, m, k;
vector<pair<int, bool>> G[MAX_N];
bool vis[MAX_N];
int compSize;
set<int> cur;

void dfs(int v) {
    vis[v] = true;
    compSize++;
    cur.insert(v);
    //cout << v << "\n";
    for (auto e: G[v]) {
        int to = e.first;
        bool ok = e.second;
        if (ok && !vis[to]) {
            dfs(to);
        }
    }
}

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

    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back({v, true});
        G[v].push_back({u, true});
    }
    for (int i = 0; i < k; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back({v, false});
        G[v].push_back({u, false});
    }

    vector<int> ans(n+5);

    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            compSize = 0;
            cur.clear();
            dfs(i);
            for (int it: cur) {
                int tmp = 0;
                for (auto e: G[it]) {
                    int to = e.first;
                    if (cur.count(to)) tmp++;
                }
                //cout << it << ": " << tmp << "\n";
                ans[it] = max(0, compSize - tmp - 1);
            }
        }
    }


    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " ";
    }





    return 0;
}


Measured memory_bytes: 14592
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let _n : usize = get_one();
    let t : Vec<i32> = get_vec();
    let sm = t.iter().fold(0, |s, a| s + a);
    let m : usize = get_one();
    let mut pxs = Vec::new();
    for _i in 0..m {
        let px = get_vec::<i32>();
        let p = px[0] as usize;
        let x = px[1];
        pxs.push((p,x));
    }
    for (p,x) in pxs {
        println!("{}", sm - t[p-1] + x);
    }
}


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

int main(){
    int n;
    int ma,mb;
    cin >> n >> ma >> mb;
    int a[n],b[n],c[n];
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[n+1][401][401];
    for(int i=0; i<401; i++){
        for(int j=0; j<401; j++){
            for(int k=0; k<n+1; k++){
                dp[k][i][j] = 10000;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i=1; i<n+1; i++){
        for(int ca=0; ca < 401; ca++){
            for(int cb=0; cb < 401; cb++){
                if(dp[i-1][ca][cb] == 10000) continue;
                dp[i][ca][cb] = min(dp[i-1][ca][cb],dp[i][ca][cb]);
                dp[i][ca+a[i-1]][cb+b[i-1]] = min(dp[i-1][ca][cb]+c[i-1],dp[i][ca+a[i-1]][cb+b[i-1]]);
            }
        }
    }
    int ans = 10000;
    for(int ca=1; ca<401; ca++){
        for(int cb=1; cb<401; cb++){
            if(ca*mb==cb*ma){
                ans = min(ans,dp[n][ca][cb]);
            }
        }
    }
    if(ans == 10000) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 25984
#include<iostream>

int main(){
    int a,b,c;
    std::cin>>a>>b>>c;
    int sum=0;
    int cnt=1;
    while(1){
        if(sum>=c)break;
        else{
            if(cnt%7==0){
            sum=sum+a+b;
            
            // std::cout<<"sum="<<sum<<" cnt="<<cnt<<"\n";
            cnt++;
        }
        else{
            sum+=a;
            // std::cout<<"sum="<<sum<<" cnt="<<cnt<<"\n";
            cnt++;
        }

        }
        
    }
    std::cout<<cnt-1<<"\n";
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int X[100005];
int Y[100005];
int N,A,B,C,m,n,a,b,c,x,y,z,i,j,k;
int main()
{
	cin>>N;
	for(i=N;i>=1;i--)
	{
		cin>>X[i];
	}
	for(j=1;j<=N;j++)
	{
		if(j==N)
		break;
		if(X[j]>=X[j+1])
		continue;
		else
		X[j+1]--;
		if(X[j]<X[j+1])
		{
			cout<<"No";
			return 0;
		}
	}
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var A = ReadLongs();
            var numCount = new long[100001];
            var sum = 0L;
            for (int i = 0; i < N; i++)
            {
                numCount[A[i]]++;
                sum += A[i];
            }

            var Q = ReadLong();
            var sb = new StringBuilder();
            for (int i = 0; i < Q; i++)
            {
                var (B, C) = Read2Longs();
                var r = Calc(numCount, B, C, sum);
                sb.AppendLine(r.ToString());

                sum = r;
            }

            return sb.ToString().Trim();
        }

        private static long Calc(long[] numCount, long b, long c, long preSum)
        {
            var bcount = numCount[b];
            numCount[c] += bcount;
            numCount[b] = 0;

            return preSum - b * bcount + c * bcount;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 49992
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b =[]
c =[]
for i in range(m):
    b1, c1 = [int(i) for i in input().split()]
    b.append(b1)
    c.append(c1)

mp = {}
e = []
ans1 = 0
ans2 = n

for i in range(n):
    temp = a[i]
    if temp in mp:
        mp[temp] = mp[temp]+1
    else:
        mp[temp] = 1
        e.append(temp)

for i in range(m):
    temp_a = b[i]
    temp = c[i]
    if temp in mp:
        mp[temp] = mp[temp]+temp_a
    else:
        mp[temp] = temp_a
        e.append(temp)

e = sorted(e)
#print(e)
e.reverse()
#print(e)
ind = 0

while True:
    temp = mp[e[ind]]
    if temp <= ans2:
        ans1 += e[ind]*temp
    else:
        ans1 += e[ind]*ans2
        break
    ans2 -= temp
    ind +=1

print(ans1)

Measured memory_bytes: 36132
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vvl G(n);
    vector<pair<ll, ll>> vp;
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
        vp.eb(a, b);
    } 
    
    vl cs(n);  // cs[i] : 頂点iとiの親を結ぶ辺の色
    vl used(n);  // used[i] : 頂点iを訪れたら1
    map<pair<ll, ll>, ll> mp;
    queue<ll> Q;

    Q.push(0);
    used[0] = 1;
    while(!Q.empty()) {
        ll v = Q.front();
        Q.pop();
        ll color = 1;
        for(auto u : G[v]) {
            if(used[u]) {
                continue;
            }
            if(color == cs[v]) {
                color++;
            }
            cs[u] = mp[make_pair(u, v)] = mp[make_pair(v, u)] = color;
            color++;
            used[u] = 1;
            Q.push(u);
        }
    }
    
    ll K = 0;
    rep(i, n) {
        chmax(K, (ll)G[i].size());
    }
    out(K);

    for(auto p : vp) {
        out(mp[p]);
    }

    re0;
}

Measured memory_bytes: 22128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n+5];
    long long sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
    }

    int c,min=1e9;
    for(int i=-100;i<=100;i++){
        c=0;
        for(int j=1;j<=n;j++){
            c+=(arr[j]-i)*(arr[j]-i);
        }
        if (c<min){
            min=c;
        }
    }
    printf("%d\n",min);

}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  int ans = 0;
  if (A[0] > 0) {
    ans -= A[0]*2;
  }
  if (A[N-1] < 0) {
    ans += A[N-1]*2;
  }
  for (int i=0; i<N; i++) {
    ans += abs(A[i]);
  }
  cout << ans << endl;
  
  if (A[0] > 0) {
    for (int i=0; i<N-2; i++) {
      cout << A[0] << ' ' << A[i+1] << endl;
      A[0] -= A[i+1];
    }
    cout << A[N-1] << ' ' << A[0] << endl;
    return 0;
  }
  
  if (A[N-1] < 0) {
    for (int i=0; i<N-1; i++) {
      cout << A[N-1] << ' ' << A[i] << endl;
      A[N-1] -= A[i];
    }
    return 0;
  }
  
  for (int i=0; i<N; i++) {
    if (A[i] < 0) {
      continue;
    }
    if (i == 0) {
      continue;
    }
    if (i == N-1) {
      cout << A[i] << ' ' << A[0] << endl;
      A[i] -= A[0];
      break;
    }
    cout << A[0] << ' ' << A[i] << endl;
    A[0] -= A[i];
  }
  for (int i=1; i<N; i++) {
    if (A[i] >= 0) {
      break;
    }
    cout << A[N-1] << ' ' << A[i] << endl;
    A[N-1] -= A[i];
  }
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
double abz(double i){
    if(i>=0){
        return i;
    }else{
        return i*(-1);
    }
}
double h[1005];
int main(void){
    double N,T,A; cin>>N>>T>>A;
    for(int i=1;i<=N;i++){
        cin>>h[i];
    }
    double save=1000000000;
    int ans;
    for(int i=1;i<=N;i++){
        if(save>=abz(A-(T-h[i]*0.006))){
            save=abz(A-(T-h[i]*0.006));
            ans=i;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <stack>
#define sz size()
#define pb push_back
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll exp(ll t,ll x){if(x==0) return 1;if(x==1) return t;if(x%2==1) return (t*exp((t*t)%mod,x/2))%mod;if(x%2==0) return exp((t*t)%mod,x/2);} 
ll gcd(ll x,ll y){return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){return u<b?u:bsum(u/b,b)+u%b;}
bool isprime(ll x){for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
void YAY(void){cout<<"YES"<<endl;}
void NAY(void){cout<<"NO"<<endl;}
int gro[222222];
int gra[222222];
vector<int> road[222222];
vector<int> rail[222222];
bool visro[222222];
bool visra[222222];
int goc, gac;
int n, k, l;
map<pair<int, int>, int> cnt;
void dfso(int cur, int whi)
{
	if(visro[cur])
	{
		return;
	}
	visro[cur]=true;
	gro[cur]=whi;
	for(int i=0 ; i<road[cur].sz ; i++)
	{
		dfso(road[cur][i],whi);
	}
}
void dfsa(int cur, int whi)
{
	if(visra[cur])
	{
		return;
	}
	visra[cur]=true;
	gra[cur]=whi;
	for(int i=0 ; i<rail[cur].sz ; i++)
	{
		dfsa(rail[cur][i],whi);
	}
}
int main(void)
{
	cin>>n>>k>>l;
	int i;
	int u, v;
	for(i=1 ; i<=k ; i++)
	{
		scanf("%d %d",&u,&v);
		road[u].pb(v);
		road[v].pb(u);
	}
	for(i=1 ; i<=n ; i++)
	{
		if(!visro[i])
		{
			goc++;
			dfso(i,goc);
		}
	}
	for(i=1 ; i<=l ; i++)
	{
		scanf("%d %d",&u,&v);
		rail[u].pb(v);
		rail[v].pb(u);
	}
	for(i=1 ; i<=n ; i++)
	{
		if(!visra[i])
		{
			gac++;
			dfsa(i,gac);
		}
	}
	for(i=1 ; i<=n ; i++)
	{
		cnt[make_pair(gro[i],gra[i])]++;
	}
	for(i=1 ; i<=n ; i++)
	{
		printf("%d ",cnt[make_pair(gro[i],gra[i])]);
	}
	return 0;
}

Measured memory_bytes: 29312
/* 
*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    int n, limit;
    cin >> n >> limit;
    vector<int> w(n+5), val(n+5);
    for(int i = 0; i < n; ++i)
    {
        cin >> w[i] >> val[i];
    }
    vector<ll> dp(limit+5);
    for(int i = 0; i < n; ++i)
    {
        for(int j = limit; j >= w[i]; --j)
        {
            dp[j] = max(dp[j], dp[j-w[i]] + val[i]);
        }
    }
    cout << dp[limit] << "\n";
    return 0; 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

const int MOD = 1e9 + 7;

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

  int n, k; cin >> n >> k;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  vector<int> freq(2005);
  for (int &x : a) ++freq[x];
  for (int i = 1; i <= 2000; ++i) {
    freq[i] += freq[i - 1];
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) if (a[i] > a[j]) ++ans;
  }
  ans = 1LL * ans * k % MOD;
  for (int &x : a) {
    ans = (1LL * ans + (1LL * (k - 1) * k / 2LL) % MOD * freq[x - 1] % MOD) % MOD;
  }
  cout << ans << endl;

  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}


Measured memory_bytes: 256
#include<stdio.h>

int cnt;
int a[90010],b[90010];
void f(int v,int x){
	if(x<=1)return;
	x--;
	int near=(x+1)/2;
	int no=x/2;
	for(int i=1;i<=near;i++){
		a[cnt]=v;
		b[cnt]=v+i;
		cnt++;
	}
	f(v+1,near);
	f(v+1+near,no);
}
int ask(int x){
	printf("%d\n",x);
	fflush(0);
	char s[10];
	scanf("%s",s);
	if(s[0]=='Y')return 0;
	if(s[1]=='e')return 1;
	return 2;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	f(1,n);
	printf("%d\n",cnt);
	for(int i=0;i<cnt;i++)printf("%d %d\n",a[i],b[i]);
	fflush(0);
	while(k--){
		int v=1,cnt=n;
		int ret=1;
		while(ret){
			ret=ask(v);
			if(ret==1){
				v=v+1;
				cnt=cnt/2;
			}else if(ret==2){
				v=v+1+cnt/2;
				cnt-=cnt/2+1;
			}
		}
	}
}


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

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

    long long sum;
    for(int i=0;i<N;i++){
        if(i==0){
            sum=K;
        }
        else sum*=K-1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
)
 
func main() {
	var (
		n     int
		count int
	)
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}
 
	flag := true
	for flag {
		for i := 0; i < n; i++ {
			if nums[i]%2 == 0 {
				nums[i] /= 2
			} else {
				flag = false
			}
		}
		if flag {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
n = int(input())
ab = []
cd = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    ab.append(tmp)
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    cd.append(tmp)

AB = sorted(ab, key=lambda x: x[1],reverse=True)
CD = sorted(cd, key=lambda x: x[0])

ans = 0
for b in CD:
    for r in AB:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            AB.remove(r)
            break

print(ans)

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

int main() {
    string s;
    cin >> s;
    ll ans = s.size();
    for(int i=0;i<s.size();i++){
        //連続する文字数
        ll num=1;
        while(i<s.size()&&s[i] ==s[i+1]){
            num++;
            i++;
        }
        ans -= (num+1)/3;
        //次の文字にくっつけるなら、次の文字はその次の文字と一致しないので飛ばせる。(終端でもloopが終了するだけなので問題なし)
        if((num+1)%3==0){
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int a, b, h;
    scanf("%d%d%d", &a, &b, &h);
    printf("%lld\n", ((ll)a + b)*h / 2);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 128
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

decrease = [0]*n
for i in range(q):
    decrease[a[i]-1] += 1

for i in range(n):
    if k - q + decrease[i] > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 8592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}



int main(){
  string s;cin>>s;
  if((s[5]-'0')*10+s[6]-'0'<5)cout<<"Heisei"<<endl;
  else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left
n=int(input())
l=list(map(int,input().split()))
l.sort()

ans=0
for a in range(n-2):
    for b in range(a+1,n-1):
        ans+=max(0,bisect_left(l, l[a] + l[b])-b-1)
        
        
print(ans)


Measured memory_bytes: 3188
// B.

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[])
{
	LL d, n, b = 1;
	cin >> d >> n;
	for (LL i = 0; i < d; ++i) {
		b *= 100;
	}
	LL ans = b * (n < 100 ? n : 101);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
A=[int(i)-1 for i in input().split()]
ds=[0]*m
de=[[] for i in range(m)]
h,dec=0,0
for i in range(n-1):
  if A[i+1]-A[i]>0:
    h+=A[i+1]-A[i]
  else:
    h+=A[i+1]+1
    dec+=1
  de[A[i+1]].append((i,(A[i+1]-A[i])%m))
for i in range(m):
  for a in de[i]:
    ds[(i-a[1]+1)%m]+=1
ans=float("inf")
for i in range(m):
  for a in de[i]:
    h+=a[1]-1
    dec-=1
  h-=dec
  ans=min(h,ans)
  if i<=m-2:
    dec+=ds[i+1]
  
print(ans)

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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp
//tgamma(i+1) is 1!
void solve(){
    ll n, k;
    cin >> n >>k;
    ll ans = min(n % k, k - (n%k));
    cout << ans;
}

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








Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int t;
		for(int i=0;i<2;i++){
			if(a>b){
				t=a;
				a=b;
				b=t;
			}
			if(b>c){
				t=b;
				b=c;
				c=t;
			}
		}
		System.out.println(a+" "+b+" "+c);
	}
}


Measured memory_bytes: 26016
#include <iostream>
#include <algorithm>
#include <set>

int main(){
    int t, n, k;
    
    std::cin >> t;
    while(t--){
        int prev, tmp;
        
        std::cin >> n >> k;
        std::multiset<int> dist;
        
        std::cin >> prev;
        
        for(int i = 0; i < n - 1; ++i){
            std::cin >> tmp;
            
            dist.insert(tmp - prev);
            prev = tmp;
        }
        
        int sum = 0, cnt = 0;        
        for(auto it = dist.begin(); it != dist.end() && cnt < n - k; ++it, ++cnt){
            sum += *it;
        }
        
        std::cout << sum << std::endl;
    }
}

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

int main() {
  int n[10];

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

  sort(n, n+10);
  for(int i = 0; i < 3; i++) {
    cout << n[9-i] << endl;
  }
}

Measured memory_bytes: 1172
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;

    int length = s.length();
    int max_len = 0;
    for (int i = 0; i < length; ++i) {
        int len = 0;
        for (int j = i; j < length; ++j) {
            bool flag = false;
            switch (s[j]) {
                case 'A':  // fall through
                case 'C':  // fall through
                case 'G':  // fall through
                case 'T':
                    ++len;
                    break;
                default:
                    flag = true;
                    break;
            }
            if (flag)
                break;
        }
        max_len = max(max_len, len);
    }
    cout << max_len << '\n';
}


Measured memory_bytes: 256