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


int main() {
    int Q;
    int maxNum = 100005;
    cin >> Q;
    int* lower = new int[Q];
    int* upper = new int[Q];
    int* prime = new int[maxNum];
    int* similarNum = new int[maxNum];
    for (int i = 0; i < Q; ++i) {
        int l;
        int r;
        cin >> lower[i] >> upper[i];
    }
    for (int i = 0; i < maxNum; ++i) {
        prime[i] = 1;
    }
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < maxNum; ++i) {
        if (prime[2] == 1) {
            for (int j = i * 2; j < maxNum; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for (int i = 2; i < maxNum; ++i) {
        similarNum[i] = similarNum[i - 1] + ((prime[i] && prime[(i + 1) / 2]) ? 1 : 0);
    }
    
    for (int i = 0; i < Q; ++i) {
        int res = similarNum[upper[i]] - similarNum[lower[i] - 1];
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2176
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = 0;
        int sumans = 0;
        int check = 0;
        for(int i = 1; i <= n; i++){
            check = i;
            while(check >= 1){
                sum = sum + check%10;
                check = check / 10;
            }
            if(a <= sum && sum <= b){
                sumans = sumans + i;
            }
            sum = 0;
        }
        System.out.print(sumans);
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		
		if(s.length()>k)
		{
			System.out.println(s.substring(0,k) + "...");
		}
		else
		{
			System.out.println(s);
		}
	}

}


Measured memory_bytes: 27084
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N];
		int indexStart;
		int indexEnd;
		
		for(int i = 0; i < N; i++){
			x[i] = sc.nextInt();
		}
		
		indexStart = 0;
		for(int i = 0; i < N; i++){
			if(i + K - 1 > N - 1) break;
			if(x[i + K - 1] > 0) break;
			indexStart = i;
		}
		
		indexEnd = N-K;
		for(int i = 0; i < 0; i++){
			if(x[N-K-i] < 0) break;
			indexEnd = N-K-i;
		}
		
		long ans = 100000001;
		for(int i = indexStart; i <= indexEnd; i++){
			long sumCostL = 0;
			long sumCostR = 0;
			
			if(x[i] < 0) sumCostL = -x[i];
			if(x[i+K-1] > 0) sumCostR = x[i+K-1];
			
			/*
			System.out.println(":i = " + i);
			System.out.println("R = " + sumCostR);
			System.out.println("L = " + sumCostL);
			System.out.println("RRL = " + (2 * sumCostR + sumCostL));
			System.out.println("LLR = " + (2 * sumCostL + sumCostR));
			*/
			
			if(i == indexStart){
				if(sumCostL == 0) ans = sumCostR;
				if(sumCostR == 0) ans = sumCostL;
				else ans = 2 * sumCostR + sumCostL;
			}
			
			if(sumCostL == 0 && sumCostR < ans) ans = sumCostR;
			if(sumCostR == 0 && sumCostL < ans) ans = sumCostL;
			if(sumCostR <= sumCostL && 2 * sumCostR + sumCostL < ans) ans = 2 * sumCostR + sumCostL;
			if(sumCostL <= sumCostR && 2 * sumCostL + sumCostR < ans) ans = 2 * sumCostL + sumCostR;
		}
		
		//System.out.println(indexStart + " " + indexEnd);
		System.out.println(ans);
	}
}

Measured memory_bytes: 49616
S = input()
N = len(S)
ans = [0] * N

def dump(d, A):
    ans[d] = A[d % 2]
    ans[d + 1] = A[(d + 1) % 2]
    # print("dump: ", d, A, ans)



def f():
    forward = True
    d = 0
    A = [0, 0]
    for i, s in enumerate(S):
        if forward:
            A[i % 2] += 1
            if s == "L":
                d = i - 1
                forward = False
        else:
            if s == "R":
                dump(d, A)
                A = [0, 0]
                forward = True
            A[i % 2] += 1
        # print(i, s, A)
    dump(d, A)


f()
print(" ".join(map(str, ans)))


Measured memory_bytes: 10484
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int n,t=0,h=0;
  cin>>n;
  for(int i=0;i<n;i++){
    string ta,ha;
    cin>>ta>>ha;
    if(ta>ha)t+=3;
    else if(ta<ha)h+=3;
    else {t++; h++;}
  }
  cout<<t<<" "<<h<<endl;
  return 0;
}
    


Measured memory_bytes: 3112
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=k;i<n;i++){
        if(a[i-k] < a[i])cout << "Yes\n";
        else cout << "No\n";
    }
}

Measured memory_bytes: 4472
import math
a,b,h,m = map(int,input().split())

y = 360/720
z = 360/60

hm = h*60+m

yr = y*hm
zr = z*hm

yrd = (yr-(360*(yr//360)))
zrd = (zr-(360*(zr//360)))

mid = min(yrd,zrd)
mad = max(yrd,zrd)

one = mad-mid
two = 360-one

dg = min(one,two)

cosdg = math.cos(math.radians(dg))

ans=math.sqrt(a*a+b*b-2*a*b*cosdg)

print(ans)

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int x ,a,b;
  cin >> x >> a >> b;
  if(abs(x-a) > abs(x-b))cout << 'B' << endl;
  else cout << 'A' << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N, A, B;
	string S;
	cin >> N >> A >> B >> S;
	int pass = 0, pass1 = 0;
	rep(i,N){
		if(S[i] == 'a'){
			if(pass < A+B){
				pass++;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}
		else if(S[i] == 'b'){
			if(pass < A + B && pass1 < B){
				pass++;
				pass1++;
				cout << "Yes" <<endl;
			}
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}



}

Measured memory_bytes: 976
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int n, r, t;
int pot[1000][3]; // [i][j] [i]?????????????°´??°??????[j] j0:??? j1:???(1???????????????) j2:?????????
int pos[100], p[100];

int main() {
	cin >> n >> r >> t;
	REP(i, n) scanf("%d", &p[i]);
	
	REP(i, n) pos[i] = p[i] % r;
	
	REP(i, t) {
		REP(j, r) {
			pot[j][2] += pot[j][1];
			pot[j][1] = pot[j][0];
			pot[j][0] = 0;
		}
		REP(j, n) {
			int now = pos[j];
			int next = (pos[j] + p[j]) % r;
			if (pot[now][2] == 0) pot[now][2]++;
			pot[now][2]--;
			pot[next][0]++;
			
			pos[j] = next;
		}
	}
	int ans = 0;
	REP(i, r) ans += pot[i][0] + pot[i][1] + pot[i][2];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <list>
#include <numeric>

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    list<int> Vs;
    for(int ii = 0; ii < N; ++ii){
        int in;
        cin >> in;
        Vs.push_back(in);
    }
    
    Vs.sort();
    
    int sum = accumulate(Vs.begin(), Vs.end(), 0);
    while(Vs.size() > 0 && sum%10 == 0){
        int v = Vs.front();
        if( v%10 != 0 ){
            sum -= v;
        }
        Vs.pop_front();
    }
    
    if(sum%10 == 0){
        sum = 0;
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return(0);
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	string s;
	cin>>s;
	
	int ans=0;
	
	int l=0;
	int r=s.size()-1;
	
	while(l<=r){
		if(s[l]=='x'&&s[r]!='x'){
			ans++;
			l++;
		}else if(s[l]!='x'&&s[r]=='x'){
			ans++;
			r--;
		}else if(s[l]==s[r]){
			l++;
			r--;
		}else{
			cout<<-1<<endl;
			return 0;
		}
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <limits>

std::vector<int> getWorkDays(const int n, const int k, const int c, const std::string s)
{
    std::vector<int> WorkDays;

    std::vector<bool> l(n, false);
    std::vector<bool> r(n, false);

    // とりあえず初めからたくさん働いてみる
    int workDay = 0;
    int stay = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'o' && stay == 0) {
            l[i] = true;
            workDay++;
            stay = c;
            continue;
        }
        if (stay > 0) {stay--;}
    }
    if (workDay > k) {
        return WorkDays;
    }

    // 後ろからたくさん働く
    workDay = 0;
    stay = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'o' && stay == 0) {
            r[i] = true;
            stay = c;
            continue;
        }
        if (stay > 0) {stay--;}
    }

    for (int i = 0; i < n; i++) {
        if (l[i] && r[i]) {
            WorkDays.push_back(i + 1);
        }
    }

    return WorkDays;
}

int main(int argc, char *argv[])
{
    int n, k, c;
    std::string s;

    std::cin >> n >> k >> c;
    std::cin >> s;

    std::vector<int> WorkDays = getWorkDays(n, k, c, s);

    for (const auto& it : WorkDays) {
        std::cout << it << std::endl;
    }

    return 0;
}


Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x = 0, y = 0;
  
  cin >> N;

  vector<int> vec(N);

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

  for(int j = 0; j < 1000000000; j++){
    for(int i = 0; i < N; i++){
         if(vec.at(i) % 2 != 0){
            y = 1;
            break;
         }
        vec.at(i) = vec.at(i) / 2;        
     }
    


    if(y == 1){
        break;
    }

    x++;



    }


cout << x <<endl;

}

Measured memory_bytes: 256
import std.stdio,
		std.string,
		std.conv,
		std.algorithm,
		std.range;

void main() {
	int[] xs;
	size_t[] ps;
	int n,m;
	readf("%d\n",&n);
	auto ts = readln.split.to!(int[]);
	scanf ("%d\n",&m);
	foreach (_;0..m) {
		size_t p;
		int x;
		readf("%d %d\n",&p,&x);
		ps ~= p - 1;
		xs ~= x;
	}
	auto sum = ts.sum;
	for(size_t i;i < m;++i)	{
		auto neg = ts[ps[i]] - xs[i];
		writeln(sum - neg);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans = 1;
  rep(i,n){
    if(i == 0) ans *= k;
    if(i > 0) ans *= k-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let n = s.len();
    let m = t.len();
    let mut ans = std::i64::MAX;

    for i in 0..n - m + 1 {
        let mut count = 0;
        for j in 0..m {
            if s[i + j] != t[j] {
                count += 1;
            }
        }
        if count < ans {
            ans = count;
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 2184
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back

ll dp[1000][1000],h,w;
const ll MOD=1000000007;
char a[1000][1000];

ll solve(ll x,ll y)
{
    if(x>=h||y>=w)
        return 0;
    if(a[x][y]=='#')
        return dp[x][y]=0;
    if((x==(h-1))&&(y==(w-1)))
        return dp[x][y]=1;
    if(dp[x][y]!=-1)
        return dp[x][y];

    return dp[x][y]=(solve(x+1,y)%MOD+solve(x,y+1)%MOD)%MOD;
}

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

    cin>>h>>w;
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
            cin>>a[i][j];
    }
    memset(dp,-1,sizeof dp);
    cout << solve(0LL,0LL);

      
    return 0;
}


Measured memory_bytes: 9088
from collections import defaultdict
from queue import Queue
n,m = map(int,input().split())
graph = defaultdict(list)
for _ in range(m):
	a,b = map(int,input().split())
	graph[a].append(b)
	graph[b].append(a)

visited = [0]*(n+1)
#sign = [0]*(n+1)
visited[1] = 1
q = Queue()
q.put(1)
while not q.empty():
	x = q.get()
	rooms = graph[x]
	for r in rooms:
		if visited[r] == 0:
			visited[r] = x
			q.put(r)

possible = True
for i in range(2,n+1):
	if visited[i] == 0:
		possible = False
		break
if possible:
	print("Yes")
	for i in range(2,n+1):
		print(visited[i])
else:
	print("No")

Measured memory_bytes: 38560
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
const int64_t mod = 1e9 + 7;
using namespace std;
vector<int64_t> fact;
vector<int64_t> finv;
vector<int64_t> inv;

void COMinit(int64_t N) {
  fact.resize(N);
  finv.resize(N);
  inv.resize(N);
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

int64_t COM(int64_t n, int64_t k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fact[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, K;
  cin >> N >> K;
  int64_t M = min(N, K);
  COMinit(N + 1);

  int64_t answer = 1;
  for (int i = 1; i <= M; ++i) {
    int64_t empty = COM(N, i);
    int64_t number = COM(N - 1, N - i - 1);
    int64_t add = (empty * number) % mod;
    answer = (answer + add) % mod;
  }
  cout << answer << endl;
  return 0;
}


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

const int MOD = (int)1e9+7;

int main(){
	int H,W;
	cin >> H >> W;
	vector<string> S(H);
	for(int i=0;i<H;i++)	cin >> S.at(i);

	vector<int> move_x={0,1,0,-1};
	vector<int> move_y={1,0,-1,0};
	queue<int> que_x;
	queue<int> que_y;
	que_x.push(0);
	que_y.push(0);
	vector<vector<int>> dis(H,vector<int>(W,1e9));
	dis.at(0).at(0)=0;
	while(!que_x.empty() && !que_y.empty()){
		int x=que_x.front();
		int y=que_y.front();
		que_x.pop();
		que_y.pop();
		for(int i=0;i<4;i++){
			int next_x=x+move_x.at(i);
			int next_y=y+move_y.at(i);
			if(next_x<0 || next_x>=W || next_y<0 || next_y>=H)	continue;
			if(S.at(next_y).at(next_x)=='#')	continue;
			if(dis.at(next_y).at(next_x)!=1e9)	continue;
			que_x.push(next_x);
			que_y.push(next_y);
			dis.at(next_y).at(next_x)=dis.at(y).at(x)+1;
		}
	}
	/*
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(dis.at(i).at(j)==1e9)	cout << "*";
			else	cout << dis.at(i).at(j) << " ";
		}
		cout << endl;
	}
	*/
	if(dis.at(H-1).at(W-1)==1e9){
		cout << -1 << endl;
		return 0;
	}
	
	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S.at(i).at(j)=='.')	ans++;
		}
	}
	cout << ans-dis.at(H-1).at(W-1)-1 << endl;

	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int ans = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            if (i % 2 == 1 && (x % 2) == 1) ans++;
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 32764
N = int(input())
A = list(map(int, input().split()))
x, y = 0, 0
mod = 10**9+7
for a in A:
    x = (x + a) % mod
    y = (y + a * a) % mod
print((x * x % mod - y) * pow(2, mod - 2, mod) % mod)


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

int main() {
  const auto f = [] { int x; cin >> x; return x; };
  const int N = f(), M = f();
  const auto xs = [f, N, M] {
    vector<int> xs(N);
    for (int i = 1; i <= M; ++i) {
      const int a = f(), b = f();
      ++xs[a - 1];
      ++xs[b - 1];
    }
    return xs;
  }();
  for (const auto& x : xs) cout << x << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_124
{
    class Program
    {

        static void Main(string[] args)
        {

            int[] dataRow = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int ret = 0;

            for (int i = 0; i < 2; i++)
            {
                if (dataRow[0] < dataRow[1])
                {
                    ret += dataRow[1];
                    dataRow[1]--;
                }
                else
                {
                    ret += dataRow[0];
                    dataRow[0]--;
                }
            }

            Console.WriteLine(ret);

        }

    }
}



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

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

   int cnt=0;
   while(n>0){
    int x=n%10;
    if(x ==7)cnt++;
    n/=10;
   }
   if(cnt>0)cout<<"Yes\n" ;
   else
    cout<<"No\n" ;




return 0;

}


Measured memory_bytes: 3584
N=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
start =sum(a)
for i in range(N):
    if a[i]<=b[i]:
        b[i]-=a[i]
        a[i]=0
    elif a[i]>b[i]:
        a[i]-=b[i]
        b[i]=0
    if a[i+1]<=b[i]:
        b[i]-=a[i+1]
        a[i+1]=0
    elif a[i+1]>b[i]:
        a[i+1]-=b[i]
        b[i]=0
end= sum(a)
print(start-end)

Measured memory_bytes: 18624
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a, b, c;
  cin >> a >> b >> c;

  if(a == b && b == c &&
    a < b + c && b < a + c && c < a + b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define frd(i,x,y) for(int i=x;i>=y;i--)
#define fi first
#define se second
#define ll long long
#define pb push_back
#define add push
using namespace std;
int root[100010];
struct rq
{
    int x,y;
    ll id;
};
int n;
vector<rq> ed;
int sz[100010];
ll sum=0;
rq city[100010];
bool cmp1(rq a, rq b)
{
    return (a.x<b.x);
}
bool cmp2(rq a, rq b)
{
    return (a.y<b.y);
}
bool cmp3(rq a, rq b)
{
    return (a.id<b.id);
}
void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//    freopen("Dbuilt.inp","r",stdin);
//    freopen("Dbuilt.out","w",stdout);
}
int get_root(int u)
{
    if(root[u]!=u) root[u]=get_root(root[u]);
    return root[u];
}
bool unionn(int u,int v)
{
    int x=get_root(u);
    int y=get_root(v);
    if(x==y) return false;
    if(sz[x]==sz[y]) sz[x]++;
    if(sz[x]<sz[y]) root[x]=y;
    else root[y]=x;
    return true;
}
void inp()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>city[i].x>>city[i].y;
        city[i].id=i;
    }
    for(int i=1;i<=n;i++)
    {
        root[i]=i;
        sz[i]=0;
    }
}
void lapthutu()
{
    sort(city+1,city+n+1,cmp1);
    for(int i=2;i<=n;i++)
    {
        ed.pb({city[i-1].id,city[i].id,city[i].x-city[i-1].x});
    }
    sort(city+1,city+n+1,cmp2);
    for(int i=2;i<=n;i++)
    {
        ed.pb({city[i-1].id,city[i].id,city[i].y-city[i-1].y});
    }
    sort(ed.begin(),ed.end(),cmp3);
}
void proc()
{
    lapthutu();
    int cnt=0;
    //cout<<ed.size();
    for(int i=0;i<ed.size();i++)
    {
        int u=ed[i].x;
        int v=ed[i].y;

        if(unionn(u,v))
        {
            sum+=ed[i].id;
            cnt++;
        }
        if(cnt==n-1)
        {
            cout<<sum;
            exit(0);
        }
    }
}
int main()
{
    io();
    inp();
    proc();
    return 0;
}


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

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> S(N);
    for(auto &e : S) cin >> e;

    string ans = "", tmp = "";
    auto dfs = [&](auto &&dfs, int i, int a, int b, int c) -> bool {
        if(!ans.empty()) return true;
        if(a < 0 or b < 0 or c < 0) return false;
        if(i == N) { ans = tmp; return true; }
        bool res = false;
        if(S[i] == "AB") {
            tmp += 'A';  res |= dfs(dfs, i + 1, a + 1, b - 1, c);
            tmp[i] = 'B'; res |= dfs(dfs, i + 1, a - 1, b + 1, c);
            tmp.pop_back();
        } else if(S[i] == "BC") {
            tmp += 'B'; res |= dfs(dfs, i + 1, a, b + 1, c - 1);
            tmp[i] = 'C'; res |= dfs(dfs, i + 1, a, b - 1, c + 1);
            tmp.pop_back();
        } else if(S[i] == "AC") {
            tmp += 'A'; res |= dfs(dfs, i + 1, a + 1, b, c - 1);
            tmp[i] = 'C'; res |= dfs(dfs, i + 1, a - 1, b, c + 1);
            tmp.pop_back();
        }
        return res;
    };

    if(dfs(dfs, 0, A, B, C)) {
        cout << "Yes" << '\n';
        for(auto &e : ans) cout << e << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n + 1);
	rep(i, n + 1) cin >> a[i];
	if (n != 0 && a[0] != 0) {cout << -1 << endl;return 0;}
	if (n == 0 && a[0] != 1) {cout << -1 << endl;return 0;}

	vector<ll> mx(n + 1);
	ll now = 0;
	for (int i = n; i >= 0; --i) {
		now += a[i];
		mx[i] += now;
	}
	ll ans = 1;
	now = 1;
	for (int i = 1; i <= n; ++i) {
		now *= 2;
		if (now < a[i]) {cout << -1 << endl;return 0;}
		ans += min(mx[i], now);
		now = min(now - a[i], mx[i]);
	}
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 4752
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
using namespace std;


int main(){
    int n,m ;
    cin >> n >> m ;
    vector<int> a(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    sort(a.begin(),a.end()) ;
    int sum = accumulate(a.begin(),a.end(),0) ;
    double border = sum / (m*4.0) ;
    if (border > a.at(n-m))
    {
        cout << "No" << endl ;
    }else
    {
        cout << "Yes" << endl ;
    }
    
    
}

Measured memory_bytes: 256
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

n,p = map(int,input().split())
a = list(map(int,input().split()))
zero,one = 0,0
for i in range(n):
    if a[i]%2==1:
        one += 1
    else:
        zero += 1
res = 0
if p==0:
    for i in range(0,one+1,2):
        res += cmb(one,i)
else:
    for i in range(1,one+1,2):
        res += cmb(one,i)
res *= 2**zero
print(res)


Measured memory_bytes: 3064
import java.util.Scanner;

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

        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            long[] t = new long[n];
            long sumA = 0, sumB = 0;
            for (int i = 0; i < n; i++) {
                t[i] = sc.nextLong();
                sumB += t[i];
            }

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                sumA += t[i];
                sumB -= t[i];
                if ( i == n - 1 ) {
                    continue;
                }
                ans = Math.min(ans, Math.abs(sumA - sumB));
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 87980
use std::cmp::max;
use std::collections::BTreeMap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: usize = sc.read();
    let w: usize = sc.read();
    let r: usize = sc.read();
    let c: usize = sc.read();
    if h % r == 0 && w % c == 0 {
        sc.write("No\n");
        return;
    }
    sc.write("Yes\n");
    if h % r == 0 {
        let row = create_row(w, c);
        for _ in 0..h {
            for i in 0..w {
                sc.write(row[i]);
                sc.write(" ")
            }
            sc.write("\n");
        }
    } else {
        let col = create_row(h, r);
        for i in 0..h {
            for _ in 0..w {
                sc.write(col[i]);
                sc.write(" ")
            }
            sc.write("\n");
        }
    }
}

fn create_row(n: usize, r: usize) -> Vec<i64> {
    let mut sum = vec![0; n + 1];
    for start in 0..r {
        let mut cur = start;
        while cur + r <= n {
            sum[cur + r] = sum[cur] - 1;
            cur += r;
        }
    }
    let mut cur = n;
    sum[cur] = 1;
    while cur >= r {
        sum[cur - r] = sum[cur] + 1;
        cur -= r;
    }
    let mut a = vec![0; n];
    for i in 0..n {
        a[i] = sum[i + 1] - sum[i];
    }
    a
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 5372
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int (i) = (int)a; (i) < (int)b;(i)++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;


int comp(string a,string b){
    rep(s,a.size()){
        if (a[s]-'a'<b[s]-'a'){
            return 1;
        }
        else if (a[s]-'a'>b[s]-'a'){
            return -1;
        }
    }
    return 0;
}

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i,N){
        cin >> S[i];
    }
    bool flag = true;
    while (flag){
        flag = false;
        rep(j,N-1){
            int x = comp(S[j], S[j + 1]);
            if (x==-1){
                string ss = S[j];
                S[j] = S[j + 1];
                S[j + 1] = ss;
                flag = true;
            }
        }
    }
    rep(i, N){
        cout << S[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    String T = scan.next();
    int A = scan.nextInt();
    int B = scan.nextInt();
    String U = scan.next();
    scan.close();

    System.out.print(S.equals(U) ? A-1 : A);
    System.out.print(" ");
    System.out.println(S.equals(U) ? B : B-1);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

void dfs(std::vector<int>& v)
{
}
int main()
{
    
    int n,m,x;
    cin >> n >> m >> x;
    int c[n];
    int a[n][m];
    std::map<int,int> mp;
    //std::vector<int> v[m];
    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++){
            cin >> a[i][j];
            mp[j] += a[i][j];
            //v[j].push_back(a[i][j]);
        }
    }
    for(int j=0; j<m; j++){
        if(x > mp[j]){
            cout << "-1" << endl;
            return 0;
        }
    }
    
    long long int cnt = 0;
    //                 2704155
    std::vector<int> v[3000000];
    for(int i1=0; i1<n; i1++){ cnt++;    v[cnt-1] = {i1};
    for(int i2=i1+1; i2<n; i2++){ cnt++;   v[cnt-1] = {i1, i2}; 
    for(int i3=i2+1; i3<n; i3++){ cnt++;   v[cnt-1] = {i1, i2, i3}; 
    for(int i4=i3+1; i4<n; i4++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4}; 
    for(int i5=i4+1; i5<n; i5++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4, i5}; 
    for(int i6=i5+1; i6<n; i6++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4, i5, i6}; 
    for(int i7=i6+1; i7<n; i7++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4, i5, i6, i7}; 
    for(int i8=i7+1; i8<n; i8++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4, i5, i6, i7, i8}; 
    for(int i9=i8+1; i9<n; i9++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4, i5, i6, i7, i8, i9}; 
    for(int i10=i9+1; i10<n; i10++){ cnt++;   v[cnt-1] = {i1, i2, i3, i4, i5, i6, i7, i8, i9, i10}; 
    for(int i11=i10+1; i11<n; i11++){ cnt++;  v[cnt-1] = {i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11}; 
    for(int i12=i11+1; i12<n; i12++){ cnt++; v[cnt-1] = {i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12}; 
    }}}}}}}}}}}}
    
    
    long long int min = 13 * 100000;
    for(int i=0; i<cnt; i++){
        int size = v[i].size();
        long long int sum = 0;
        std::map<int, int> tmp;
        for(int j=0; j<size; j++){
            
            int boolNo = v[i][j];
            
            sum += c[boolNo];
            //cout << boolNo << ":" << sum << ", ";
            for(int k=0; k<m; k++){
                tmp[k] += a[boolNo][k];
            }
        }
        //cout << endl;
        bool ok = true;
        for(int k=0; k<m; k++){
            if(x > tmp[k]){
                ok = false;
                break;
            }
        }
        if(ok == true){
            if(sum < min) min = sum;
        }
    }       
    cout << min << endl;

}

Measured memory_bytes: 74060
#include <iostream>

using namespace std;

const int max_t = 120 * 60;

inline int get_time(int h, int m, int s)
{
    return (h * 60 + m) * 60 + s;
}

void print_time(int t)
{
    int h, m;
    
    h = t / 3600;
    t = t - h * 3600;
    m = t / 60;
    t = t - m * 60;

    cout << '0' << h << ':';
    if (m / 10)
        cout << m << ':';
    else
        cout << '0' << m << ':';
    if (t / 10)
        cout << t << endl;
    else
        cout << '0' << t << endl;
}

int main()
{
    int h, m, s;

    while (cin >> h >> m >> s, h != -1 || m != -1 || s != -1) {
        int res = max_t - get_time(h, m, s);

        print_time(res);
        print_time(3 * res);
    }

    return 0;
}

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

int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    int l, m;
    int max = 0;
    l = s.size(); m = t.size();
    
    for (int i = 0; i + m <= l; ++i) {
        int tmp = 0;
        int j = 0;
        for (; j < m; ++j) {
            if (s[i+j] == t[j]) ++tmp;
        }
        if (max < tmp) max = tmp;
    }

    cout << m - max;

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

class UnionFind{
public:
  vector<int> uni;
  UnionFind(int s) : uni(s, -1) {}

  int root(int a){
    if(uni[a] < 0) return a;
    return uni[a] = root(uni[a]);
  }

  bool connect(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;
    if(uni[a] > uni[b]) swap(a, b);
    uni[a] = uni[a] + uni[b];
    uni[b] = a;
    return true;
  }

  bool isConnect(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return -uni[root(a)];
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  rep(i, 0, M) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    uf.connect(x, y);
  }
  set<int> st;
  rep(i, 0, N) st.insert(uf.root(i));
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 5376
#include <cstdio>
#include <set>

using namespace std;

int main() {
    size_t N;
    scanf("%zu", &N);

    set<int> d;
    int dup=0;
    for (size_t i=0; i<N; ++i) {
        int A;
        scanf("%d", &A);

        if (d.count(A)) {
            ++dup;
        } else {
            d.insert(A);
        }
    }

    if (dup & 1)
        ++dup;

    printf("%zu\n", N-dup);
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

class mint
{
  const ll mod = 1000000007;
  ll x;

public:
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const
  {
    return mint(-x);
  }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint &a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint &a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint &a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint &a) const
  {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &m)
  {
    os << m.x;
    return os;
  }
};

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

  bool **g = new bool *[H];
  REP(h, H)
  {
    g[h] = new bool[W];

    string r;
    cin >> r;

    REP(w, W)
    {
      g[h][w] = (r[w] == '.');
    }
  }

  mint **dp = new mint *[H + 1];
  FOR(h, 0, H)
  {
    dp[h] = new mint[W + 1];
  }
  dp[1][1] += 1;

  FOR(h, 1, H)
  {
    FOR(w, 1, W)
    {
      if (g[h - 1][w - 1])
        dp[h][w] += dp[h - 1][w] + dp[h][w - 1];
    }
  }

  cout << dp[H][W] << endl;

  return 0;
}

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

int main()
{
    int n; scanf("%d", &n);
    int ar[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &ar[i]);
    }
    int CountGood = 0;
    for(int i = 2; i < n; i++)
    {
        if(ar[i-1] < ar[i] && ar[i] < ar[i+1])
        {
            CountGood++;
        }
        else if(ar[i-1] > ar[i] && ar[i] > ar[i+1])
        {
            CountGood++;
        }
    }
    printf("%d\n", CountGood);
    return 0;
}


Measured memory_bytes: 3796
from sys import stdin
l = list(stdin.readline().rstrip())
s = [int(i) for i in l]
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i+1, f + '+' + str(s[i+1]), sum + s[i+1])
        dfs(i+1, f + '-' + str(s[i+1]), sum - s[i+1])
dfs(0, str(s[0]), s[0])


Measured memory_bytes: 3060
import math
def better(l, ans):
    for i in range(2, n):
        ans[i] = min(ans[i - 1] + abs(l[i]-l[i - 1]), ans[i - 2] + abs(l[i]-l[i - 2]))
    return ans
n = int(input())
l = list(map(int, input().split()))
ans = [0] * n
ans[1] = abs(l[1]-l[0])
print(better(l, ans)[len(ans)-1])

Measured memory_bytes: 20780
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

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

    vector<int> turn(n,0);
    vector<int> sat(n,0);
    vector<int> add_sat(n-1,0);

    rep(i,n){
        cin >> turn[i];
    }
    rep(i,n){
        cin >> sat[i];
    }
    rep(i,n-1){
        cin >> add_sat[i];
    }

    int sum = 0;
    int ch = 999;
    for(auto t : turn){
        sum += sat[t-1];
        if(ch == t-1){
            sum += add_sat[ch-1];
        }
        ch = t;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

string beautify(string str) {
	string ret = "";
	for (int i = 0; i < str.size(); ++i) {
		char c = str[i];
		if ('a' <= c && c <= 'z') ret += c;
		else if ('A' <= c && c <= 'Z') ret += (char)(c-'A'+'a');
	}
	return ret;
}

string shuffle(string str, int n) {
	string ret = "";
	for (int i = n; i < str.size(); ++i) {
		ret += str[i];
	}
	for (int i = 0; i < n; ++i) {
		ret += str[i];
	}
	return ret;
}

int main() {
	string str;
	while ( cin >> str && str != "-" ) {
		int n; cin >> n;
		for (int i = 0; i < n; ++i) {
			int h; cin >> h;
			str = shuffle(str, h);
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 1216
#include <iostream>
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<((int)n);i++)
using namespace std;
int main(){
	int i,n;	
	char str[10],cnt,Ch1,Ch2;
	bool first,second,sign[10];
	int idx;
	cin >> str;	
    sort(str, str+4);
    if ((str[0]==str[1]) && (str[2] == str[3]) && (str[0]!=str[3]))
    {
      cout << "Yes" << endl;    	
	}
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <map>
using namespace std;

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

int main() {
	int n, k; cin >> n >> k;
	cout <<(long long)( k * pow(k - 1, n - 1)) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		
		long ans = 0;
		HashMap<Integer, Integer> map = new HashMap<>();
		for(int i=0; i<N; i++) {
			Integer pair = map.get(-A[i]+i);
			if(pair != null)
				ans += pair;
			
			pair = map.get(A[i]+i);
			if(pair == null)
				pair = 0;
			map.put(A[i]+i, pair+1);
		}
		
		System.out.println(ans);
		sc.close();
	}
}



Measured memory_bytes: 59272
#include <stdio.h>
 
int main(void)
{
    int D[6];
    int i, t, f, q, e, tp, fp, t1, t2, f1, f2;
 
    for (i = 0; i < 6; i++) scanf("%d", &D[i]);
 
    scanf("%d", &q);
 
    for (i = 0; i < q; i++)
    {
        scanf("%d", &t);
        tp = 0;
        while (D[tp] != t) 
        {
            tp++;
        }
        scanf("%d", &f);
        fp = 0;
        while (D[fp] != f) 
        {
            fp++;
        }
 
        t1 = tp / 3;
        t2 = t1 > 0 ? 3 - (t1 + tp % 3) : tp % 3;
        f1 = fp / 3;
        f2 = f1 > 0 ? 3 - (f1 + fp % 3) : fp % 3;
 
        e = t1 ^ f1;
        e = f2 - (t2 + 1) % 3 != 0 ? !e * 3 : e * 3;
        e += e > 0 ? (t2 + f2) - 1 : 3 - (t2 + f2);
 
        printf("%d\n", D[e]);
    }
     
    return 0;
}


Measured memory_bytes: 2112
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

    ll m,d;
    cin >> m >> d;

    ll ans = 0;

    for(ll i = 1; i <= m; i++)  // month
    for(ll j = 10; j <= d; ++j)  // day
    {
        ll d1,d2;
        d1 = j / 10;
        d2 = j - d1 * 10;
        if(i == d1 * d2 && d1 >= 2 && d2 >= 2)
            ans++;
    }

    cout << ans << endl;

    return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

long long Combi::nPk_modp(long long n, long long k, long long p)
{
  ll ans = 1;
  for(long long i = k; i <= n; i++)
  {
    ans = (ans * i) % p;
  }

  return ans;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e10
#define mod 1000000007
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)
vi graph[100000];
int vis[100000], c[100000], dis[100000];
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
bool func(int x, int y)
{
	return x > y;
}

int32_t main()

{
	//c_p_c();
	int k;
	string s;
	cin >> k >> s;
	int l = s.length();
	string res = "";
	if (l <= k)
		cout << s;
	else
	{
		for (int i = 0; i < k; i++)
			res += s[i];
		cout << res << "." << "." << ".";
	}
}






Measured memory_bytes: 5976