akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdlib>

using namespace std;

int main()
{
  while(true){
    char r1[5];
    char r2[5];
    scanf("%s%s", r1, r2);
    if(strcmp(r1,"0")==0&&strcmp(r2,"0")==0)break;
    
    int hit=0;
    int blow=0;
    for(int i = 0; i < 4; ++i){
      if(r1[i] == r2[i])++hit;
      for(int j = 0; j < 4; ++j){
	if(r1[i] == r2[j])++blow;
      }
    }
    blow -= hit;
    cout << hit << ' ' << blow << endl;
  }
  return 0;
}

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

int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());

    int count=-1;
    int pos=0;
    char now=s[0];
    
    rep(i,s.size()){
        int next;
        if(next!=string::npos) {
            if (now == 'B') {
                next = s.find('W', pos);
                now = s[next];
                count++;
            } else {
                next = s.find('B', pos);
                now = s[next];
                count++;
            }
            pos = next;

        }else{
            break;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 512
f = STDIN
n = f.gets.chomp.to_i
h_list = f.gets.split(" ").map(&:to_i)


dp = Array.new(n){|_| Float::INFINITY }
# 初期化
dp[0] = 0

(1..(n-1)).to_a.each do |i|
  if i == 1
    dp[1] = (h_list[0] - h_list[1]).abs
    next
  end

  d1 = (h_list[i] - h_list[i-1]).abs + dp[i-1]
  d2 = (h_list[i] - h_list[i-2]).abs + dp[i-2]
  if d1 < d2
    dp[i] = d1
  else
    dp[i] = d2
  end
end

puts dp.last


Measured memory_bytes: 9612
k,n = map(int,input().split())
a_lst = list(map(int,input().split()))

#a_lstの要素の隣同士の距離で最大のものを求め、kから減算したものが最短距離？
tmp_kyori = k - abs(a_lst[-1]-a_lst[0])#最初だけ反時計回りの距離を算出
for i in range(len(a_lst)-1):
    sa_kyori = a_lst[i+1] - a_lst[i] 
    if sa_kyori > tmp_kyori:
        tmp_kyori = sa_kyori

print(k-tmp_kyori)

Measured memory_bytes: 26444
N = int(input())
Hs = list(map(int, input().split())) + [10**10]

ans = 0
num = 0
for i in range(N):
    if Hs[i] >= Hs[i+1]:
        num += 1
    else:
        ans = max(ans, num)
        num = 0

print(ans)


Measured memory_bytes: 14224
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <deque>
#include <set>
using namespace std;
int S[1000][1000];

int main()
{
	int H, W;
	cin >> H >> W;
	int C[2];
	int D[2];
	cin >> C[1] >> C[0] >> D[1] >> D[0];
	C[0] = C[0] - 1;
	C[1] = C[1] - 1;
	D[0] = D[0] - 1;
	D[1] = D[1] - 1;
//	vector<vector<int>>S(W, vector<int>(H));
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			char c;
			cin >> c;
			if (c == '.') {
				S[x][y] = 1;
			}
			else {
				S[x][y] = 0;
			}
		}
	}
	deque<pair<int,int>>stack;
	deque<pair<int, int>>stack2;
	deque<pair<int, int>>stack3;

	pair<int, int> a(C[0], C[1]);

	int result = 0;
	while (true) {
		while (true) {
			int x = a.first;
			int y = a.second;
			if (x >= 0 && x < W&&y >= 0 && y< H&&S[x][y] == 1) {
				stack2.push_back(a);
				S[x][y] = 2;
				stack3.push_back({x- 1, y });
				stack3.push_back({ x + 1, y});
				stack3.push_back({ x ,y - 1 });
				stack3.push_back({x,y+ 1 });
			}
			if (stack3.size() == 0) {
				break;
			}
			a = stack3.back();
			stack3.pop_back();
		}
		if (S[D[0]][D[1]] == 2 || S[D[0]][D[1]] == 4) {
			cout << result;
			return 0;
		}
		bool frag = false;
		for (int i = 0; i < stack2.size(); i++) {
			int x = stack2[i].first;
			int y = stack2[i].second;
			for (int xx = x-2; xx < x+3; xx++) {
				for (int yy = y-2; yy < y+3; yy++) {
					if (xx  >= 0 && xx  < W&&yy  >= 0 && yy  < H&&S[ xx] [yy] == 1) {
						stack3.push_back({xx , yy });
//						S[x + xx][y + yy] = 4;
						frag = true;
					}
				}
			}
		}
		stack2.clear();

		if (!frag) {
			cout << -1;
			return 0;
		}
			a = stack3.back();
			stack3.pop_back();
		result++;

	}

}

Measured memory_bytes: 7564
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int count = 0;
    while (a>0){
      int min = (int) Math.pow(b,count+1);
      int minus = (int) a%min;
      a -= minus;
      count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 35596
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  string S;
  cin >> S;
  int n = S.size();
  int ret = n;
  for(int i=0; i<n-1; i++){
    if(S[i] != S[i+1]){
      ret = min(ret, max(i+1, n-(i+1)));
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef long double ld;
ll big = 1000000007ll;
ll n,m,q,k;
ll T;

ll w,h;

ll A,B;

ll upp(ll a, ll b){
if(b == 0){return 1;}
ll h = upp(a,b/2);
if(b % 2 == 0){return (h*h)%big;}
return (((h*h)%big)*(a%big))%big;
}

ll inv(ll a){
return upp(a,big-2);
}

ll solve(){

ll hfac = 1;
ll afac = 1;

for(ll c1 = 0; c1 < h-A-1;c1++){
    hfac *= (c1+1);
    hfac %= big;
}

ll ht = 1;
ll AT = 1;
for(ll c1 = 0; c1 < h-A-1; c1++){
    ht *= h+w-A-c1-2;
    ht %= big;
}
for(ll c1 = 0; c1 < A-1; c1++){
    AT *= A-c1-1;
    AT %= big;
}
AT = 1;
ll ans = 0;
for(ll c1 = 0; c1 <  w - B; c1++){

    ll ans2 = 1;
    ans2 *= ht;
    ans2 *= inv(hfac);
    ans2 %= big;
    ans2 *= AT;
    ans2 %= big;
    ans2 *= inv(afac);
    ans2 %= big;

   // cout << ans2 << " " << ht <<" " << AT << "\n";

    ans += ans2;
    ans %= big;

    if(c1 == w - B - 1){break;}


    ht *= inv(h+w-A-2-c1);
    ht %= big;
    ht *= (h+w-A-2-c1 - (h-A-1));
    ht %= big;


    AT *= (A+c1);
    AT %= big;

    afac *= (c1+1);
    afac %= big;


}

return ans;
}

int main()
{
    ll c1,c2,c3,c4,c5;
    ll x,y,z;
    ll a,b,c,d,e;
    //freopen("test_input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> h >> w >> A >> B;

    cout << solve() << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
ll inf = 1000000007;
int main() {
	int n, m;
	cin >> n >> m;
	int k;
	vector<vector<int>>s(m);
	for (int i = 0; i < m; i++) {
		cin >> k;
		s[i].resize(k);
		for (int j = 0; j < k; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	vector<int>p(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	ll ans = 0;
	for (int bit = 0; bit < (1 << n); bit++) {
		bool ok = true;
		for (int j = 0; j < m; j++) {
			int count = 0;
			for (int id : s[j]) {
				if (bit & (1 << id)) {
					count++;
				}
			}
			if (count % 2 != p[j]) {
				ok = false;
			}
		}
		if (ok)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def judge(ex,torf,i):
	if i==3:
		return eval(ex)
	else:
		return judge(ex,torf+[True],i+1) or judge(ex,torf+[False],i+1)
		
while 1:
	ex=raw_input().split("|")
	if ex[0]=="#":break
	for j in range(len(ex)):
		dic=[]
		ex[j]=list(ex[j])[1:-1]
		for i in range(len(ex[j])):
			if ex[j][i]=="&":ex[j][i]="and"
			elif ex[j][i]=="~":ex[j][i]="not"
			else:
				if ex[j][i] not in dic:
					dic.append(ex[j][i])
					ex[j][i]="torf["+str(len(dic)-1)+"]"
				else:
					ex[j][i]="torf["+str(dic.index(ex[j][i]))+"]"
		ex[j]=" ".join(map(str,ex[j]))
	for clause in ex:
		if judge(clause,[],0):
			print "yes"
			break
	else:
		print "no"

Measured memory_bytes: 4292
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {


		long Q=nextLong();
		long H=nextLong();
		long S=nextLong();
		long D=nextLong();
		long N=nextLong()*4;

		Pair[] p = new Pair[4];
		p[0]=new Pair(Q*8,1,Q*4);
		p[1]=new Pair(H*4,2,H*4);
		p[2]=new Pair(S*2,4,S*4);
		p[3]=new Pair(D,8,D*4);

		Arrays.sort(p,Pair.getComparator());

		long ans =0;
		for(int i=0;i<4;i++){
			ans+=(N/p[i].scale)*p[i].value;
			N=N%p[i].scale;

		}

		System.out.println(ans/4);

	}

	public static class Pair {
		long L2;
		long scale;
		long value;

		Pair(long L2, long scale, long value) {
			this.L2 = L2;
			this.scale = scale;
			this.value = value;
		}



		public long getL2() {
			return L2;
		}



		public long getScale() {
			return scale;
		}



		public long getValue() {
			return value;
		}



		public static Comparator<Pair> getComparator() {
			return Comparator.comparing(Pair::getL2);
		}
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 28116
import java.io.*;
import java.util.*;
 
public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int[] in=new int[10];
        for(int i=0;i<10;i++)
            in[i]=Integer.parseInt(reader.readLine());
        Arrays.sort(in);
        System.out.println(in[9]);
        System.out.println(in[8]);
        System.out.println(in[7]);
     
    }
}

Measured memory_bytes: 24156
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	int d=0,e=0,f=0;
	char s='a';
	for(int i=0;i<a.size()+b.size()+c.size();i++){
		if(s=='a'){
			s=a[d];
			if(d==a.size()){cout<<'A'<<endl;return 0;}
			d++;
		}
		if(s=='b'){
			s=b[e];
			if(e==b.size()){cout<<'B'<<endl;return 0;}
			e++;
		}
		if(s=='c'){
			s=c[f];
			if(f==c.size()){cout<<'C'<<endl;return 0;}
			f++;
		}
	}
	return 0;
}


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

   int n;
   cin >> n;
   vector<int> a(n+1);
   vector<int> b(n+1);
   int i = 0;
   for(i = 1;i<=n;i++){
    cin >> a[i] ;  
   }
   int j = 1;
   
   for(i=1;i<=n;i++){

     b[a[a[i]]] = a[i];
       
     
     
   }
    
   for(i=1;i<=n;i++){
       cout << b[i] << endl;
   }
    
    
    return 0;
}


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

namespace AC {
#define ll long long
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define PDPLL pair<double, PLL>
#define PLPLL pair<ll, PLL>
#define pb push_back
#define fi first
#define se second
#define ls rt << 1
#define rs rt << 1 | 1

    const ll N = 1e5 + 66;

    ll BUGS = 1;

    inline ll read(){
        ll x = 0;    bool flag = 1;   char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = 0; ch = getchar(); }
        while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
        if(flag) return x;  return (~(x - 1));
    }

    inline void read(ll arr[], ll s, ll e) { for(ll i = s; i <= e; ++i) arr[i] = read(); }

    inline void write(ll x){
        if(x < 0) { x = ~(x - 1); putchar('-'); }
        if(x > 9) write(x / 10); putchar(x % 10 + '0');
    }

    inline void print(ll x) { write(x); puts(""); }

    inline void print(ll arr[], ll s, ll e) {
        for(ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
        write(arr[e]); puts("");
    }

    inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }

    inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }

    inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; }

    inline void debugArr(ll arr[], ll s, ll e, string ss) {
        cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
        for(ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl;
    }

    inline void IO() {
        //ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
        //cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位
        //cout << setprecision(1); //保留1位有效数字
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
}using namespace AC;

ll n, arr[1000];

int main() {
    //IO();
    while(cin >> n) {
        read(arr, 1, n);
        ll cur = 1000;
        for(ll i = 2; i <= n; ++i) {
            if(arr[i] > arr[i - 1]) cur = cur + cur / arr[i - 1] * abs(arr[i] - arr[i - 1]);
        }
        print(cur);
    }
    return 0;
}



Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
    string str;
    int ac=0,wa=0,tle=0,re=0;
for(int i=0;i<n;i++){

    cin>>str;
    if(str=="AC") {
    ac++;
    }
else if(str =="WA"){
    wa++;
}
else if(str=="TLE"){
    tle++;
}
else{
    re++;
}
}
cout<<"AC x "<<ac<<endl;
cout<<"WA x "<<wa<<endl;
cout<<"TLE x "<<tle<<endl;
cout<<"RE x "<<re<<endl;
}



Measured memory_bytes: 3200
N=int(input())
S=0
for x in range(1,N+1):
    i=0
    j=0
    XX=x
    while i==0:
        XX=XX//10
        if XX==0:
            i=1
        j=j+1
    if j%2==1:
        S=S+1
print(S)




Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#include<set>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 11;
string s[MAXN];
//bool used[MAXN];

int main()
{
    int n, k;
    while(cin >> n >> k && n)
    {
        REP(n) cin >> s[i];
        set<string> ans;

        if(k == 2)rep(i,n)rep(j,n)if(i != j) ans.insert(s[i] + s[j]);
        if(k == 3)rep(i,n)rep(j,n)rep(l,n) if(i != j && j != l && l != i)ans.insert(s[i]+s[j]+s[l]);

        if(k == 4)rep(i,n)rep(j,n)rep(l,n)rep(m,n)
            if(i != j && i != l && i != m && j != l && j != m && l != m)
                ans.insert(s[i]+s[j]+s[l]+s[m]);

        cout << ans.size() << endl;

    }
    
    return 0;
}

Measured memory_bytes: 0
use std::io::*;
use std::str::FromStr;

fn mod_pow(x:i64, n: i64, m:i64) -> i64 {
    if n <= 0 {
        return 1_i64
    }
    if x <= 0 {
        return 1_i64
    }
    if n % 2 == 1 {
        return (x * mod_pow(x, n-1, m)) % m
    }
    return mod_pow((x*x) % m, n/2, m)
}

fn main(){
    let po = 10_i64.pow(9) + 7;

    let s: Vec<char> = read::<String>().chars().collect();
    let len = s.len();
    
    let mut ta: Vec<i64> = vec![0;len+1];
    let mut tc: Vec<i64> = vec![0;len+1];
    let mut tq1: Vec<i64> = vec![0;len+1];
    let mut tq2: Vec<i64> = vec![0;len+1];
    for i in 1..(len+1) {
        match s[i-1] {
            'A' => ta[i] += 1,
            'C' => tc[i-1] += 1,
            '?' => {
                tq1[i] += 1;
                tq2[i-1] += 1;
            },
            _ => {},
        }
    }
    for i in 1..(len+1) {
        ta[i] += ta[i-1];
        tc[len-i] += tc[len-i+1];
        tq1[i] += tq1[i-1];
        tq2[len-i] += tq2[len-i+1];
    }

    let mut ans: i64 = 0;
    for i in 1..len {
        if s[i] == 'B' || s[i] == '?' {
            let a1 = (ta[i] * mod_pow(3, tq1[i], po)) % po;
            let a2 = 
                if tq1[i] > 0 {
                    (tq1[i] * mod_pow(3, tq1[i]-1, po)) % po
                } else {0};
            let b1 = (tc[i+1] * mod_pow(3, tq2[i+1], po)) % po;
            let b2 = 
                if tq2[i+1] > 0 {
                    (tq2[i+1] * mod_pow(3, tq2[i+1]-1, po)) % po
                } else {0};
            ans += (a1 + a2) * (b1 + b2);
            ans %= po;
        }
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {bool F=K=0;char C=getchar();while(C<'0'||C>'9')
{if(C=='-')F=1;C=getchar();}while(C<='9'&&C>='0')K=(K<<1)+(K<<3)+C-'0',C=getchar();if(F)K=-K;}
template < class R > inline bool Checkmax( R &A , R B ) { return A < B ? A = B , 1 : 0 ; }
template < class R > inline bool Checkmin( R &A , R B ) { return A > B ? A = B , 1 : 0 ; }
const int MaxN = 100000 + 10 ;
int N , K , Ans , Fa[MaxN] ;
vector<int> Son[MaxN] ;
int Dfs( int Nod ) {
	register int Max = 0 ;
	for(register int i = Son[Nod].size() ; i-- ; )
		Checkmax( Max , Dfs( Son[Nod][i] ) + 1 ) ;
	// printf( "%d %d\n" , Nod , Max ) ;
	if( Max >= K - 1 and Fa[Nod] != 1 and Nod != 1 ) {
		++Ans ;
		Max = -1 ;
	}
	return Max ;
}
int main() {
	Readin( N ) ;
	Readin( K ) ;
	Readin( Ans ) ;
	Ans = ( Ans != 1 ) ;
	for(register int i = 1 ; ++i <= N ; ) {
		Readin( Fa[i] ) ;
		Son[Fa[i]].push_back( i ) ;
	}
	Dfs( 1 ) ;
	return not printf( "%d\n" , Ans ) ;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmin(T &a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    long long ans = 0;
    vector<long long> A(N);
    vector<pair<int, int>> pro;
    long long Mi = 1e9, Ma = -1e9;
    int mi, ma;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(chmin(Mi, A[i]))mi = i + 1;
        if(chmax(Ma, A[i]))ma = i + 1;
    }
    
    if(Mi < 0 && 0 < Ma){
        if(abs(Mi) < abs(Ma)){
            for(int i = 0; i < N; i++){
                if(A[i] < 0){
                    A[i] += Ma;
                    pro.push_back(make_pair(ma, i + 1));
                    ans++;
                }
            }
        }else{
            for(int i = 0; i < N; i++){
                if(0 < A[i]){
                    A[i] += Mi;
                    pro.push_back(make_pair(mi, i + 1));
                    ans++;
                }
            }
        }
    }
    
    long long sum = 0;
    for(auto a : A)sum += a;
    if(0 <= sum){
        ans += N - 1;
        for(int i = 1; i < N; i++)pro.push_back(make_pair(i, i + 1));
    }else{
        ans += N - 1;
        for(int i = N - 1; i > 0; i--)pro.push_back(make_pair(i + 1, i));
    }
    
    cout << ans << endl;
    for(int i = 0; i < pro.size(); i++){
        cout << pro[i].first << " " << pro[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 2e5 + 10;

int d[MR], v[MR];

vector<int> g[MR];

vector < int > cykl, S;

int done[MR], srt[MR], cnt;

bool wCyklu[MR];

void dfs(int nr)
{
	done[nr] = 1;
	S.push_back(nr);

	for (int i : g[nr])
		if (done[i] == 1)
		{
			FORD(j, S.size(), 0)
			{
				cykl.push_back(S[j]);
				wCyklu[cykl.back()] = 1;
				if (S[j] == i)
					break;
			}
		}
		else if (!done[i])
			dfs(i);

	S.pop_back();
	done[nr] = 2;

	srt[cnt++] = nr;
}

int main()
{
	int N;
	scanf("%d", &N);
	REP(i, N)
	{
		int p;
		scanf("%d", &p); p--;
		g[p].push_back(i);
	}

	REP(i, N)
		if (!done[i])
			dfs(i);

	if (cykl.size() % 2 == 0)
	{
		printf("POSSIBLE\n");
		return 0;
	}

	// wyznacz wartosci az do cyklu
	REP(i, N)
	{
		set<int> pom;
		for (int nr : g[srt[i]])
			if (!wCyklu[nr])
				pom.insert(v[nr]);
		FORQ(j,0,g[srt[i]].size())
			if (pom.find(j) == pom.end())
			{
				v[srt[i]] = j;
				break;
			}
	}

	// zobacz czy wszystkie wartosci taie same
	set<int> pom;
	for (int nr : cykl)
		pom.insert(v[nr]);

	if (pom.size() == 1)
		printf("IMPOSSIBLE\n");
	else
		printf("POSSIBLE\n");

	return 0;
}

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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

inline void chkmin( int &a, int b ) { if(a > b) a = b; }

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

const int N = 2e5 + 5;
int a[N], b[N], c[N];
int n;
ll k;

inline bool cmp( int a, int b)
{
	return a > b;
}

// priority_queue<int> q1;
// priority_queue<int, vector<int>, greater<int> >q2;

int main()
{
	n = _; k = _;
	for( int i = 1; i <= n; i++ ) 
		a[i] = _;
	sort(a + 1, a + n + 1, cmp);
	for( int i = 1; i <= n; i++ )
		b[i] = _;
	sort(b + 1, b + n + 1);
	ll l = 0, r = 1e12, ans = -1;
	while(l <= r)
	{
		ll mid = ( l + r) >> 1ll;
		ll tmp = 0;
		for( int i = 1; i <= n && tmp <= k; i++ ) 
			if(1ll * a[i] * b[i] > mid)
				tmp += a[i] - mid / b[i];
		if(tmp <= k)
			ans = mid, r = mid - 1;
		else 
			l = mid + 1;
	}
	cout << ans << ln;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  int a, b, n;
  cin >> n >> a >> b;
  cout << min(a * n, b) << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	string s; cin >> s;
	string ret = "Yes";
	for (int i=0; i<s.size(); i++) {
		if (i%2==0 && s[i]=='L') {
			ret = "No";
			break;
		}
		if (i%2==1 && s[i]=='R') {
			ret = "No";
			break;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[110],b[110];
int main()
{
    int n,m,x,y,i,j,Max=-101,Min=101;
    cin >> n >> m >> x >> y;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i]>Max)
            Max=a[i];
    }
    for(i=0;i<m;i++)
    {
        cin >> b[i];
        if(b[i]<Min)
            Min=b[i];
    }
	if(x<=Max && Max<Min && Min<=y)
    	cout << "No War" << endl;
    else
    	cout << "War" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    int n;
    while (cin >> n) {

        set<int> sk;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            if (sk.count(x))
                sk.erase(x);
            else {
                sk.insert(x);
            }
        }
        cout << sk.size() << endl;
    }
    return 0;
}


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

#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll N, X;
    cin >> N >> X;

    ll ans = N;
    ll hi = max(N - X, X);
    ll lo = min(N - X, X);
    while (hi % lo) {
        ll q = hi / lo;
        ll r = hi % lo;
        ans += 2 * q * lo;
        hi = lo;
        lo = r;
    }
    ans += lo * (2 * (hi / lo) - 1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include <unordered_set>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,m;
  cin >> n >> m;
  char a[n][n],b[m][m];
  rep(i,n)rep(j,n)cin >> a[i][j];
  rep(i,m)rep(j,m)cin >> b[i][j];
  rep(i,n)rep(j,n){
    if(i+m>n || j+m>n)continue;
    bool flag=true;
    rep(k,m)rep(l,m)if(a[i+k][j+l]!=b[k][l])flag=false;
    if(flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int X, fX;
  cin >> X;
  rep(i,8){
    int y,p;
    p=pow(10,i);
    y=X%(p*10);
    y/=p;
    fX+=y;
  }
  if(X%fX==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	string ans = "No";
	for( int i = 0; i < S.size()-1; ++i ) {
		if( S[i] == 'A' && S[i+1] == 'C' ) {
			ans = "Yes";
			break;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] w = sc.next().toCharArray();
		
		int[] c = new int[26];
		for (int i = 0; i < w.length; i++) {
			int idx = w[i] - 'a';
			c[idx]++;
		}
		
		boolean isBeautiful = true;
		for (int num : c)
			if (num % 2 != 0) isBeautiful = false;
		
		String ans = isBeautiful ? "Yes" : "No";
		System.out.println(ans);
		
		sc.close();
	}
}




Measured memory_bytes: 26912
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,m;
  cin >> n >> m;
  vvint to(n);
  rep(i,0,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vint ans(n,-1);
  ans[0] = INF;
  queue<int> que;
  que.push(0);
  while(que.size() != 0){
    int key = que.front();
    que.pop();
    for(int p:to[key]){
      if(ans[p] == -1){
        ans[p] = key;
        que.push(p);
      }
    }
  }
  rep(i,0,n){
    if(ans[i] == -1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  rep(i,1,n){
    cout << ans[i] + 1 << endl;
  }
}

Measured memory_bytes: 13024
n,k = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
  p[i] = (p[i]+1)/2
s = [0]
for i in range(n):
  if i==0:
    s.append(p[0])
  else:
    s.append(s[-1]+p[i])
pmax = 0
for i in range(n-k+1):
  if s[i+k]-s[i]>pmax:
    pmax = s[i+k]-s[i]
print(pmax)

Measured memory_bytes: 25604
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#include <string>
#include <queue>

#define endl '\n'
#define int long long
    
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int s = 0;
    for (int i = 0; i < n; i++) {
        s += x[i];
    }
    s = max(n*a, s);
    int dp[n + 1][s + 1];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = n; j > 0; j--) {
            for (int k = 0; k <= s; k++) {
                if (x[i] <= k) {
                    dp[j][k] += dp[j - 1][k - x[i]];
                }
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[i][i*a];
    }
    cout << ans;
}

Measured memory_bytes: 1280
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>

typedef long long ll;



int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    int lo = 0;
    int hi = 1000000000;
    while (hi - lo > 1) {
        int md = (hi + lo) / 2;
        int tot = 0;
        for (int l : v) {
            tot += (l-1) / md;
        }
        if (tot <= k) hi = md;
        else lo = md;
    }
    cout << hi << endl;
}

Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC139D()
{
	ll N;
	cin >> N;

	ull x = N % 2 == 0 ? N / 2 : N;
	x *= N % 2 == 0 ? N - 1 : (N - 1) / 2;
	cout << x << endl;
}
int main()
{
	ABC139D();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin >> n;
	while (n--){
		int point = 0;
		int hit = 0;
		int out = 0;
		string s;
		while (cin >> s){
			if (s == "HIT"){
				if (hit == 3)
					point++;
				if (hit <= 2)
					hit++;
			}
			if (s == "OUT"){
				out++;
				if (out == 3)
					break;
			}
			if (s == "HOMERUN"){
				point += hit + 1;
				hit = 0;
			}
		}
		cout << point<< endl;
	}
}

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

using namespace std;
using Int = long long;

Int lcm(Int a, Int b){
    return a * b / __gcd(a, b);
}

Int solve(Int a, Int b, Int x){
    Int s = a / x;
    if(a % x != 0) s += 1;
    Int e = b / x;

    return e - s + 1;
}

signed main(){
    Int a, b, c, d;
    cin >> a >> b >> c >> d;
    Int least_common_multi = lcm(c, d);

    cout << (b - a + 1) - solve(a, b, c) - solve(a, b, d) + solve(a, b, least_common_multi) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  static ArrayList<Edge>[] graph;
  static int vNum;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    vNum = sc.nextInt();
    Vertice[] V = new Vertice[vNum];
    graph = new ArrayList[vNum];
    for(int i = 0; i < vNum; i++) {
      graph[i] = new ArrayList<Edge>();
    }
    for(int i = 0; i < vNum; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      V[i] = new Vertice(i, x, y);
    }
    Arrays.sort(V, new Comparator<Vertice>() {
      public int compare(Vertice vertice1, Vertice vertice2) {
	return vertice1.x - vertice2.x;
      }
    });
    for(int i = 0; i < vNum - 1; i++) {
      Vertice v1 = V[i];
      Vertice v2 = V[i + 1];
      graph[v1.id].add(new Edge(v2.id, v2.x - v1.x));
      graph[v2.id].add(new Edge(v1.id, v2.x - v1.x));
    }

    Arrays.sort(V, new Comparator<Vertice>() {
      public int compare(Vertice vertice1, Vertice vertice2) {
	return vertice1.y - vertice2.y;
      }
    });
    for(int i = 0; i < vNum - 1; i++) {
      Vertice v1 = V[i];
      Vertice v2 = V[i + 1];
      graph[v1.id].add(new Edge(v2.id, v2.y - v1.y));
      graph[v2.id].add(new Edge(v1.id, v2.y - v1.y));
    }
    int ans = prim();
    System.out.println(ans);
  }

  public static int prim() {
    int total = 0;
    Queue<Edge> que = new PriorityQueue<Edge>();
    que.add(new Edge(0,0));
    boolean[] use = new boolean[vNum];
    while(!que.isEmpty()) {
      Edge e = que.poll();
      if(use[e.to]) {
        continue;
      }
      use[e.to] = true;
      total += e.cost;
      for(Edge e2 : graph[e.to]) {
        que.add(e2);
      }
    }
    return total;
  }

  static class Edge implements Comparable<Edge> {
    int to;
    int cost;

    public Edge(int to, int cost) {
      this.to = to;
      this.cost = cost;
    }
    @Override
    public int compareTo(Edge o) {
      return this.cost - o.cost;
    }
  }

  static class Vertice {
    int id;
    int x;
    int y;

    public Vertice(int id, int x, int y) {
      this.id = id;
      this.x = x;
      this.y = y;
    }
  }
}

Measured memory_bytes: 107936
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();
    bool ok = false;
    string t = "keyence";
    for(int i=0;i<=7;i++){
    	if(s.substr(0, (7 - i)) + s.substr(n - i, i) == t) ok = true;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
main(){double a,b,c,d,x=57.2958;for(;scanf("%lf%lf%lf%lf",&a,&b,&c,&d),b>-1;printf("%.0f\n",6378.1*acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(b-d))))a/=x,b/=x,c/=x,d/=x;exit(0);}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

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

    vector<ll>a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];

    ll ans=0;

    repr(i,n-1,0){
        a[i]+=ans;
        if(a[i]%b[i]!=0)ans+=b[i]-(a[i]%b[i]);
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 4760
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())
nsl = lambda: list(nsm())

mod = 1000000007

n, m = nm()
dp = [0] * (n + 1)
for i in range(m):
    tmp = ni()
    dp[tmp] = -1
dp[0] = 1
for i in range(n):
    if i + 1 < n + 1 and dp[i + 1] != -1 and dp[i] != -1:
        dp[i + 1] += dp[i] % mod
        dp[i + 1] %= mod
    if i + 2 < n + 1 and dp[i + 2] != -1 and dp[i] != -1:
        dp[i + 2] += dp[i] % mod
        dp[i + 2] %= mod
print(dp[n] % mod)

Measured memory_bytes: 7264
N, D = map(int,input().split())
l = []
ans = 0
for _ in range(N):
    xy = list(map(int,input().split()))
    l.append(xy)

for i in range(N):
    kyori = (l[i][0]**2 + l[i][1]**2)**0.5
    if kyori <= D:
        ans += 1
print(ans)

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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

string s;

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

  cin >> s;
  int dp[100001][4] = {};
  // dp[i+1][j] i文字目まで考えたときにABCとの照合を終えた数
  dp[0][0] = 1;
  rep(i, 0, s.size()) {
    rep(j, 0, 4) {
      if (s[i] != '?') {
        dp[i + 1][j] += dp[i][j];
      } else {
        dp[i + 1][j] += 3 * dp[i][j];
      }
      if (dp[i + 1][j] >= INF) dp[i + 1][j] %= INF;
    }
    if (s[i] == 'A' or s[i] == '?') dp[i + 1][1] += dp[i][0];
    if (s[i] == 'B' or s[i] == '?') dp[i + 1][2] += dp[i][1];
    if (s[i] == 'C' or s[i] == '?') dp[i + 1][3] += dp[i][2];
    dp[i][0] %= INF;
    dp[i][1] %= INF;
    dp[i][2] %= INF;
    dp[i][3] %= INF;
  }
  cout << dp[s.size()][3]%INF << endl;
  return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int n,b,c;
int main() 
{
	cin>>n>>b;
	c=1;
	for(int i=1;i<=n;i++)
	{
		c+=min(c,b);
	}
	cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

bool visited[333333];
vi adj[333333];
int ans[333333];
int par[333333];
int mx[333333];
int timer=-1;
int st[333333];
int en[333333];

void prep(int u, int p=-1)
{
	st[u]=++timer;
	for(int v:adj[u])
	{
		if(v==p) continue;
		par[v]=u;
		prep(v,u);
	}
	en[u]=timer;
}

set<int> seg[222222*4];

void update(int id, int l, int r, int pos, int v, int mode)
{
	if(pos>=r||pos<l) return ;
	if(mode) seg[id].insert(v);
	else seg[id].erase(v);
	if(r-l<2)
	{
		return ;
	}
	int mid=(l+r)>>1;
	update(id*2,l,mid,pos,v,mode); update(id*2+1,mid,r,pos,v,mode);
}

const int INF = int(1e9);
int query(int id, int l, int r, int ql, int qr)
{
	if(ql>=r||l>=qr) return INF;
	if(ql<=l&&r<=qr) return (seg[id].empty()?INF:(*seg[id].begin()));
	int mid=(l+r)>>1;
	return min(query(id*2,l,mid,ql,qr),query(id*2+1,mid,r,ql,qr));
}

int n; 
int ct=0;

void expand(int u, int limit, bool cheat=0)
{
	if(u>=limit&&!cheat) return ;
	ct++;
	update(1,0,n,st[u],u,0);
	for(int v:adj[u])
	{
		if(v==par[u]) continue;
		if(v<limit) expand(v,limit);
		else update(1,0,n,st[v],v,1);
	}
}

void solve(int u)
{
	ct=0;
	while(1)
	{
		int curv = query(1,0,n,st[u],en[u]+1);
		//cerr<<curv<<' '<<st[u]<<' '<<en[u]<<'\n';
		if(curv<mx[par[u]]||curv==u)
		{
			expand(curv,mx[par[u]],curv==u);
		}
		else break;
	}
	ans[u]=ct+ans[par[u]];
	mx[u]=max(u,mx[par[u]]);
	for(int v:adj[u])
	{
		if(v==par[u]) continue;
		solve(v);
	}	
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int u,v; cin>>u>>v; u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	par[0]=-1;
	prep(0);
	for(int v:adj[0])
	{
		update(1,0,n,st[v],v,1);
		solve(v);
	}
	for(int i=1;i<n;i++)
	{
		cout<<ans[i];
		if(i+1<n) cout<<' ';
	}
	cout<<'\n';
}


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll a, b, k; cin >> a >> b >> k;
	if(a >= k) cout << a - k << " " << b;
	else if(a < k && a + b >= k) cout << 0 << " " << b - (k - a);
	else cout << 0 << " " << 0;
} 

Measured memory_bytes: 256
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        int k=sc.nextInt(),m=7;
        int res = -1;
        for(int i=1;i<=k+2;i++){
            int t=m%k;
            if(t==0){
                res=i;
                break;
            }
            else{
                m=t*10+7;
            };
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 35724
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
#define ll long long
//ll dp[100][100001];


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin>>n>>s;
    long long dp[n + 1][n + 1];
    memset(dp, 0 , sizeof(dp));
    for(int i = 1; i <= 1 ; i++){
        dp[i][0] = 1;
    }
    long long presum[n+1] = {0};
    for(int i = 1 ; i <= n ; i++){
        presum[i] = presum[i-1] + dp[i][0];
        presum[i] = presum[i]%mod;
    }
    for(int j = 0 ; j < n - 1; j++){
        for(int i = 1 ; i <= j+2 ; i++){
            if(s[j] == '>'){
                dp[i][j+1] +=(presum[n] - presum[i-1]);
                dp[i][j+1] = dp[i][j+1]%mod;
                if(dp[i][j + 1] < 0)dp[i][j+1] += mod;
            }else if(s[j] == '<'){
                dp[i][j+1] += presum[i-1];
                dp[i][j+1] = dp[i][j+1]%mod;
            }  
        }
        for(int i = 1 ; i <= n ; i++){
        presum[i] = presum[i-1] + dp[i][j+1];
        presum[i] = presum[i]%mod;
        }
    }
    // for(int i = 0 ; i <= n ; i++){
    //     for(int j = 0 ; j < n ; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<presum[n]<<endl;
    return 0;
}


Measured memory_bytes: 70656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void){
  long int A,B;
  int i,j;
  long int ans=0;
  scanf("%ld",&A);
  scanf("%ld",&B);
  ans = (A-2)*(B-2);
  if(ans<0)
    ans = -1*ans;
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 1000005
#define LL long long
using namespace std;

int n;
LL a[N],ans;
priority_queue<int>q;

inline int qr()
{
	int x=0,w=1;char a=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

inline LL qrl()
{
	LL x=0,w=1;char a=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

int main()
{
	n=qr();
	for(register int i=1;i<=n;i++)
		a[i]=qrl();
	sort(a+1,a+n+1);
	q.push(a[n]);
	for(register int i=n-1;i>=1;i--)
	{
		//cout<<q.top()<<endl;
		ans+=q.top();
		q.pop();
		q.push(a[i]);
		q.push(a[i]);
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> imos(n+1);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        imos[i+1] = imos[i] + a[i];
    }
    map<ll,int> his;
    his[0] = 1;
    ll res = 0;
    rep1(i,n){
        res += his[imos[i]];
        his[imos[i]]++;
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 15872
n = int(input())
h = list(map(int,input().split()))

ans = []
c = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        c += 1
        if i == n-2:
            ans.append(c)
    elif h[i+1] > h[i]:
        ans.append(c)
        c = 0

if not ans:
    print(0)
    exit()
print(max(ans))


Measured memory_bytes: 89824
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> v(n, 0);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    make_fact(101000);
    make_invfact(101000);

    ll res = 0;
    for(int i = n-1; i >= 0; i--){
        if(i >= k-1){
            res = add(res, mul(v[i], comb(i, k-1)));
        }
    }
    for(int i = 0; i < n; i++){
        if(n-i-1 >= k-1){
            res = sub(res, mul(v[i], comb(n-i-1, k-1)));
        }
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back

#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const double pi=acos(-1);
void solve()
{
    double r;
    cin>>r;
    double ans=pi*2*r;
    printf("%.6f\n",ans);
}
int main()
{
	//int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 3776