akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI(n);
    GVI(a,n);
    ll ans1=0,sum=a[0];
    if(a[0]==0){
        ans1=1;
        sum+=1;
    }
    FORIN(i,1,n){
        if(sum<0&&sum+a[i]<=0){
            ans1+=1-(sum+a[i]);
            sum=1;
        }else if(sum>0&&sum+a[i]>=0){
            ans1+=(sum+a[i])+1;
            sum=-1;
        }else{
            sum+=a[i];
        }
    }
    ll ans2=0;
    sum=0;
    if(a[0]==0){
        ans2=1;
        sum-=1;
    }else{
        ans2=abs(a[0])+1;
        sum=a[0]<0?1:-1;
    }
    FORIN(i,1,n){
        if(sum<0&&sum+a[i]<=0){
            ans2+=1-(sum+a[i]);
            sum=1;
        }else if(sum>0&&sum+a[i]>=0){
            ans2+=(sum+a[i])+1;
            sum=-1;
        }else{
            sum+=a[i];
        }
    }
    print(min(ans1,ans2));
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s;
int ans{101};
int main(){
    cin.tie(0),ios_base::sync_with_stdio(0);
    cin>>s;
    for(char c{'a'};c<='z';++c){
        string t{s};
        int cnt{};
        for(int n=t.size();n>1;--n){
            bool f{};
            for(int i{};i<n;++i)
                if(t[i]!=c){
                    f=1;break;
                }
            if(!f)break;
            for(int i{1};i<n;++i)
                if(t[i]==c)
                    t[i-1]=c;
            ++cnt;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}


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

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

    long long a, b;
    cin >> a >> b;

    if(a < b) swap(a, b);

    if((a - b) % 2){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (a + b) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
const int INF = (1<<30)-1;
int main(){
  int n,m,a,b,c,sum,ma,hiku;
  priority_queue<PA,vector<PA>,greater<PA> > pq;
  while(cin >> n >> m,n!=0||m!=0){
    sum = 0;
    vector<PA> vec[100];
    for(int i=0;i<m;i++){
      cin >> a >> b >> c;
      vec[a].push_back(PA(c,b));
      vec[b].push_back(PA(c,a));
      sum += c;
    }
    bool town[100]={false};
    hiku = 0;
    pq.push(PA(0,0));
    while(!pq.empty()){
      PA p = pq.top();
      pq.pop();
      if(town[p.second]) continue;
      
      hiku += p.first;
      town[p.second] = true;
      
      for(int i=0;i<vec[p.second].size();i++){
	int to = vec[p.second][i].second;
	if(!town[to]) pq.push(PA(vec[p.second][i].first,to));
      }
      
    }
    printf("%d\n",hiku);
  }
  return(0);
}



Measured memory_bytes: 3200
#include <iostream>

int main() {
	int A, B, C, X, Y;
	std::cin >> A >> B >> C >> X >> Y;

	int price = 0;
	int ABNum = 0;

	if(C * 2 < A) {
		A = C * 2;
	}
	if(C * 2 < B) {
		B = C * 2;
	}

	price = A * X + B * Y;

	while(ABNum < X && ABNum < Y && C * 2 < (A + B)) {
		price -= (A + B);
		price += C * 2;
		ABNum++;
	}

	std::cout << price << std::endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
	  String str = br.readLine();
	  int len = Integer.parseInt(str); 
	  str = br.readLine();
	  String[] splitStr = str.split(" ");
	  
	  int target[] = new int[len];
	  
	  for(int i = 0;i<len;i++){
	   target[i] = Integer.parseInt(splitStr[i]);
	  }

      //???????????\???????????????
	  StringBuffer sb_0 = new StringBuffer();
	  for(int v = 0; v < len;v++){
	    sb_0.append(target[v]);
	    if(v != len-1){
	      sb_0.append(" ");
	    //}else {
	      //sb_0.append("\n");
	    }
          }
          System.out.println(sb_0);
      //???????????§??????????????????

	  for(int i = 1;i<len;i++){
	    int cash = target[i];
	    int num = i-1;
	    while(num>= 0 && target[num] > cash){
	      target[num+1] = target[num];
	      num--;
	      target[num+1] = cash;
	    }
            
            StringBuffer sb = new StringBuffer();
	    for(int v = 0; v < len;v++){
	      sb.append(target[v]);
	      if(v != len-1){
	        sb.append(" ");
	      //}else {
	        //sb.append("\n");
	      }
            }
            System.out.println(sb);
	  }
	}
}

Measured memory_bytes: 27080
from collections import deque

s = deque(list(input()))
q = int(input())

rev = True

for i in range(q):
    q = list(input().split())
    if(int(q[0]) == 1):
        rev = rev ^ True
    else:
        n = int(q[1])
        if((n == 1 and rev) or (n == 2 and not rev)):
            s.appendleft(q[2])
        else:
            s.append(q[2])


txt = ''
if rev:
    txt = ''.join(s)
else:
    while not(not s):
        txt += s.pop()

print(txt)


Measured memory_bytes: 8420
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String line = reader.readLine();
			String[] sarray = line.split(" ", -1);
			int m = Integer.parseInt(sarray[0]);
			int f = Integer.parseInt(sarray[1]);
			int r = Integer.parseInt(sarray[2]);
			
			if(m == -1 || f == -1){
				if(m == -1 && f == -1){
					break;
				}else{
					System.out.println("F");
				}
			}else{
				if((m + f) >= 80){
				System.out.println("A");
				}
				if((m + f) >= 65 && (m + f) < 80){
					System.out.println("B");
				}
				if((m + f) >= 50 && (m + f) < 65){
					System.out.println("C");
				}
				if((m + f) >= 30 && (m + f) < 50){
					if(r >= 50){
						System.out.println("C");
					}else{
						System.out.println("D");
					}
				}
				if((m + f) >= 0 && (m + f) < 30){
					System.out.println("F");
				}
			}
		}
	}
}

Measured memory_bytes: 24400
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,t;

int main()
{
	ll a,b;
	cin>>a>>b;
	ll ans = a/b;
	if(a%b) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define gc getchar
using namespace std;
/*inline int read(){
	char c=gc();int x=0,y=1;while(c<'0'||c>'9'){if(c=='-') y=-1;c=gc();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();return x*y;
}*/
/*inline ll read(){
	char c=gc();ll x=0,y=1;while(c<'0'||c>'9'){if(c=='-') y=-1;c=gc();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();return x*y;
}*/



int main(){
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	int n;scanf("%d",&n);
	printf("%d\n",(n&1)?n/2+1:n/2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ll long long

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1)
{
    for (int u : to[v])
    {
        if (u == p)
        {
            continue;
        }
        
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main()
{
    int n, q;
    cin >> n >> q;
    rep(i, n-1)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    
    ans.resize(n);
    rep(i, q)
    {
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }

    dfs(0);
    rep(i, n)
    {
        cout << ans[i] << endl;
    }
    
    return 0;
}

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

int N;
vector<int> A;

vector<vector<int> > cc;
int dp(int n, int t) {
    if(n == N) return t;
    int &ret = cc[n][t];
    if(ret != -1) return ret;

    ret = 0;
    ret += dp(n + 1, t | ((A[n] - 1) % 2 == 0));
    ret += dp(n + 1, t | (A[n] % 2 == 0));
    ret += dp(n + 1, t | ((A[n] + 1) % 2 == 0));
    return ret;
}

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

    A.resize(N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    cc = vector<vector<int> >(N, vector<int>(2, -1));
    printf("%d", dp(0, 0));
}


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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  int result = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      result = result + d.at(i)*d.at(j);
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(void){
  int H;
  int N;
  int T=0;
  int array[100000];
  scanf("%d",&H);
  scanf("%d",&N);
  for(int i=0; i<N; i++){
    scanf("%d",&array[i]);
    T=T+array[i];
  }
  if(T>=H){
    printf("Yes");
  }
  if(T<H){
    printf("No");
  }
}

Measured memory_bytes: 512
require 'set'

N, M, P = gets.split.map(&:to_i)
abc_list = M.times.map do
  a, b, c = gets.split.map(&:to_i)
  [a - 1, b - 1, -(c - P)]
end
graph = Array.new(N) { [] }
abc_list.each do |(a, b, c)|
  graph[a].push([b, c])
end
reverse_graph = Array.new(N) { [] }
abc_list.each do |(a, b, c)|
  reverse_graph[b].push([a, c])
end

INF = 1 << 60

def reachable(graph, s)
  visit = Set.new
  visit.add(s)
  queue = [s]
  while !queue.empty? do
    u = queue.shift
    graph[u].each do |(v, _)|
      next if visit.include?(v)
      visit.add(v)
      queue.push(v)
    end
  end
  visit
end

def bellman_ford(edge_list, s, max_count)
  d = Array.new(N, INF)
  d[s] = 0
  c = 0
  loop do
    is_update = false
    edge_list.each do |(u, v, c)|
      if d[u] != INF && d[u] + c < d[v]
        d[v] = d[u] + c
        is_update = true
      end
    end
    return d if !is_update
    c += 1
    return nil if c == max_count
  end
end

reachable_from_0 = reachable(graph, 0)
reachable_to_n = reachable(reverse_graph, N - 1)
v_set = Set.new
N.times do |v|
  v_set.add(v) if reachable_from_0.include?(v) && reachable_to_n.include?(v)
end
edge_list = abc_list.select do |(a, b, _)|
  v_set.include?(a) && v_set.include?(b)
end
ans = bellman_ford(edge_list, 0, v_set.size)
puts(ans == nil ? '-1' : [-(ans[N - 1]), 0].max)


Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
int i,j;
#define fi(o,n) for(i=o;i<n;i++)
#define fj(o,n) for(j=o;j<n;j++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define int long long int
#define double long double
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define WW 100000
#define INF 1000000000000000000 //1e18
#define EPS 0.000000001 //1e-9
//for(auto &x: a) cout<<x; to traverse along array if size is KNOWN.
//max({_,......,_}) can give maximum of any number of elements. Similarly min also.
//reverse(all(v)) would reverse a vector
//count_if(lower_bound, upper_bound, function)
int32_t main()
{   IOS
    int t,a=0;cin>>t;
    fi(1,t+1)
    {
        fj(1,t+1)
        {
            for(int k=1;k<t+1;k++)
            {
                a+=__gcd(__gcd(j,k),i);

            }
        }

    }
    cout<<a;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using ll = long long;
using namespace std;

#define MX 100001

int H, W;
vector<vector<ll>> c;
vector<vector<int>> A;

template<typename T>
void warshall_floyd(vector<vector<T>> &g, int n)
{
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}

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

    cin >> H >> W;
    for (int i = 0; i < 10; i++) {
        c.push_back(vector<ll>(10));
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        A.push_back(vector<int>(W));
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    
    warshall_floyd(c, 10);

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] >= 0) {
                ans += c[A[i][j]][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Traveling Salesman around Lake
            var line = ReadLine();
            var K = line[0];
            var N = line[1];

            var A = ReadLine().OrderBy(x => x).ToList();
            int ans = A[N - 1] - A[0];

            for(int i = 1; i < N; i++)
            {
                int distance = A[i] - A[i - 1];
                ans = Math.Min(ans, K - distance);
            }

            Console.WriteLine(ans);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 35444
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n,k;
  cin>>n>>k;
  vi x(n);
  rep(i,n)cin>>x[i];
  int ans=0;
  rep(i,n){
    int t=min(x[i],k-x[i]);
    ans+=t*2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> indeg(n);
    vector<vector<int>> g(n);
    vector<vector<int>> gt(n);
    vector<int> ord;
    m+=n-1;
    rep(i,0,m) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        g[u].push_back(v);
        gt[v].push_back(u);
        ++indeg[v];
    }
    vector<int> st;
    rep(i,0,n) if(indeg[i]==0) st.push_back(i);
    while(!st.empty()) {
        int u = st.back();
        st.pop_back();
        ord.push_back(u);
        for(int v:g[u]) {
            --indeg[v];
            if(indeg[v]==0) st.push_back(v);
        }
    }
    vector<int> time(n);
    rep(i,0,n) time[ord[i]] = i;
    vector<int> par(n,-1);
    rep(i,0,n) {
        for(int v:gt[i]) {
            if(par[i]==-1 || time[v]>time[par[i]]) par[i] = v;
        }
    }
    rep(i,0,n) cout << par[i]+1<<"\n";
}


Measured memory_bytes: 13436
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;
    

int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<lint> a(x);
    rep(i,x)cin >> a[i];
    vector<lint> b(y);
    rep(i,y)cin >> b[i];
    vector<lint> c(z);
    rep(i,z)cin >> c[i];

    sort(c.begin(),c.end(),greater<lint>());

    priority_queue<pair<lint, int>> d;
    rep(i,x)rep(j,y)d.push(make_pair(a[i]+b[j]+c[0],0));

    rep(i,k){
	auto top = d.top();
	d.pop();
	cout << top.first << endl;

	if(top.second == z-1)continue;

	d.push(make_pair(top.first - c[top.second] + c[top.second+1], top.second+1));

    }
}


Measured memory_bytes: 18796
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const LL INF=2e15;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL Add[8*200000],tree[8*200000];
const int MAXN=262144;
LL query(int a,int b,int now=1,int l=1,int r=MAXN+1){
	if(r<=a||l>=b){
		return -INF;		
	}
	if(r<=b&&l>=a){
		return tree[now]+Add[now];
	}
	int mid=(l+r)>>1;
	return max(query(a,b,now<<1,l,mid),query(a,b,(now<<1)+1,mid,r))+Add[now];
} 
LL add(int a,int b,LL val,int now=1,int l=1,int r=MAXN+1){
	if(r<=a||l>=b){
		return tree[now]+Add[now];	
	}
	if(r<=b&&l>=a){
		Add[now]+=val;
		return tree[now]+Add[now];
	}
	int mid=(l+r)>>1;
	return Add[now]+(tree[now]=max(add(a,b,val,now<<1,l,mid),add(a,b,val,(now<<1)+1,mid,r))); 
}
vector<mp> v[200000+20];
int main(){
	fastio;
	int n,m;
	cin>>n>>m;
	rb(i,1,m){
		int li,ri,ai;
		cin>>li>>ri>>ai;
		v[ri].PB(II(li,ai));
	}
	rb(i,1,n){
		sort(ALL(v[i]));
	}
	rb(r,1,n){
		LL tmp=query(1,r+1);
		LL sum=0;
		int las=1;
		for(auto it:v[r]){
			if(it.FIR==las){
			}
			else{
				add(las,it.FIR,sum);
			}	
			sum+=it.SEC;
			las=it.FIR;
		}
		if(las!=r){
			add(las,r,sum);
		}
		add(r,r+1,tmp+sum);
		
	}
	cout<<query(1,MAXN+1)<<endl;
//	add(1,2,-10);
//	add(1,2,0);
//	add(2,3,-30);
//	add(1,3,100);
//	add(3,4,70);
//	cout<<query(1,MAXN+1)<<endl;
	return 0;
}


Measured memory_bytes: 20864
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n,i,j,a,l;
        String str1,str2=" ",str3=" ";
        for(i=0; ;i++){
            str1=sc.next();
            l=str1.length();
            if(str1.equals("-")){
                break;
            }else{
                n=sc.nextInt();
                for(j=1;j<=n;j++){
                    a=sc.nextInt();
                    str2=str1.substring(0,a);
                    str3=str1.substring(a,l);
                    str1=str3+str2;
                }
            }
            System.out.println(str1);
        }
    }
}


Measured memory_bytes: 26492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, ans;

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

Measured memory_bytes: 256
# ' 'dで区切ってprintする方法
# print(*a, sep=' ')

import math

n = int(input())

p = list(map(int, input().split()))

not_same = 0

sorted_p = sorted(p)

for i in range(n):
    if sorted_p[i] != p[i]:
        not_same += 1

if not_same < 3:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>
#include<tuple>
#include<string>

using namespace std;

int main() {

	int n;
	cin >> n;
	int amari = n % 10;
	if (amari == 0 || amari == 1 || amari == 6 || amari == 8)cout << "pon\n";
	else if (amari == 3)cout << "bon\n";
	else cout << "hon\n";
	return 0;
}

Measured memory_bytes: 3592
A, B, C, K = map(int, input().split())
ans = 0

if K <= A:
    print(K)
else:
    ans = 1 * A
    K = K - A
    K = K - B
    if K > 0:
        ans += -1 * K
        print(ans)
    else:
        print(ans)

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

int gcd(int k, int n){
    if(n == 0){
        return k;
    }
    if(k % n == 0){
        return n;
    }
    return gcd(n, k % n);
}

int main()
{
    int n;
    cin >> n;
    int a[100007];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int nowlgcd, nowrgcd = 0;
    int lgcd[100007], rgcd[100007];
    lgcd[0] = 0;
    for(int i = 1; i < n; i++){
        nowlgcd = gcd(nowlgcd, a[i - 1]);
        lgcd[i] = nowlgcd;
    }
    rgcd[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--){
        nowrgcd = gcd(nowrgcd, a[i + 1]);
        rgcd[i] = nowrgcd;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, gcd(rgcd[i], lgcd[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
num=[[] for i in range(n)]
for i in range(n+1):
    num[a_list[i]-1].append(i)
for i in num:
    if len(i)==2:
        x=i[0]
        y=n-i[1]
INF=10**9+7
z=x+y
def modinv(a,m):
    b=m
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while not b==0:
        q=a//b
        (a,b)=(b,a%b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx%m
a=n+1
b=1
for i in range(n+1):
    print((a-b)%INF)
    a=(a*(n-i)*modinv(i+2,INF))%INF
    b=(b*(z-i)*modinv(i+1,INF))%INF



Measured memory_bytes: 68624
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
ans = 0
import math

a = [A,B,C,D,E]
b = []

for i in range(5):

    if a[i] % 10 != 0:
        
        b.append(a[i] % 10)

if len(b) == 0:

    for i in range(5):

        ans += a[i]

    print(ans)

else:
    
    for i in range(5):

        if a[i] % 10 != 0:

            ans += 10 * ((a[i]//10)+1)

        else:

            ans += a[i]

    print(ans-10+min(b))

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

using ll=long long;
const ll MOD=1e9+7;

ll dpL[601][601];
ll dpM[601][601];
ll dpR[601][601];


int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(k),b(k);
    for(int i=0;i<k;i++) cin>>a[i]>>b[i],a[i]--,b[i]--;

    n=n*2;
    vector<int> c(n,-1);
    for(int i=0;i<k;i++) c[a[i]]=b[i],c[b[i]]=a[i];

    auto circleMax=[&](int from,int x,int y){
        int tmpx=x-from,tmpy=y-from;
        if(x<from) tmpx=x+n-from;
        if(y<from) tmpy=y+n-from;
        return tmpx<tmpy ? y : x;
    };
    vector<ll> res(n);   
    // cerr<<circleMax(1,0,7)<<endl;

    // cerr<<"#DP Start"<<endl;
    int half=n/2;
    
    for(int i=0;i<n;i++){
        bool b=(c[i]!=-1 && c[i]<i);
        if(b) continue;
        for(int j=0;j<n;j++)for(int k=0;k<=half;k++) dpL[j][k]=dpM[j][k]=dpR[j][k]=0;
        dpL[0][0]=1;
        int cmax=i;
        for(int j=0;j+1<n;j++){
            int id=(i+j+1)%n;
            
            if(c[id]==-1){
                for(int k=0;k+1<=half;k++){    
                    dpL[j+1][k+1]+=dpL[j][k];
                    dpM[j+1][k+1]+=dpM[j][k];
                    dpR[j+1][k+1]+=dpR[j][k];
                }
                for(int k=1;k<=half;k++){
                    dpL[j+1][k-1]+=dpL[j][k]*k;
                    dpM[j+1][k-1]+=dpM[j][k]*k;
                    dpR[j+1][k-1]+=dpR[j][k]*k;
                }
            }
            else{
                cmax=circleMax(i,cmax,c[id]);
                for(int k=0;k<=half;k++){
                    dpL[j+1][k]+=dpL[j][k];
                    dpM[j+1][k]+=dpM[j][k];
                    dpR[j+1][k]+=dpR[j][k];
                }
            }
            if(c[id]==-1 && c[i]==-1 || c[id]==i){
                for(int k=0;k<=half;k++) dpM[j+1][k]+=dpL[j][k];
            }
            if(i<id && circleMax(i,id,cmax)==id){
                dpR[j+1][0]+=dpM[j+1][0];
                dpM[j+1][0]=0;
            }
            for(int k=0;k<=half;k++) dpL[j+1][k]%=MOD,dpM[j+1][k]%=MOD,dpR[j+1][k]%=MOD;
        }
        res[i]=dpR[n-1][0];
    }
    // cerr<<"#DP END"<<endl;
    // for(int i=0;i<n;i++){
    //     cerr<<"$"<<i<<" "<<res[i]<<endl;
    // }
    
    cout<<accumulate(res.begin(),res.end(),0LL)%MOD<<endl;
    return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
using namespace std;

int main(){
  int N;
  cin>>N;
  long long int A[N],B[N];
  for(int i=0; i<N; ++i){
    cin>>A[i];
  }
  
  B[0]=0;
  for(int i=0; i<N; ++i){
    if(i%2==0) B[0]+=A[i];
    else B[0]-=A[i];
  }
  
  for(int i=1; i<N; ++i){
    B[i]=(A[i-1]-(B[i-1]/2))*2;
  }
  
  for(int i=0; i<N; ++i){
    cout<<B[i]<<endl;
  }
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
struct ZFunc{
    vector<int> z;
    ZFunc(const vector<int> & v): z(v.size()){
        int n = v.size(), a = 0, b = 0;
        if(!z.empty()) z[0] = n;
        for(int i = 1; i < n; ++i) {
            int end = i; if(i < b) end = min(i + z[i-a], b);
            while(end < n && v[end] == v[end-i]) ++end;
            z[i] = end - i; if(end > b) a = i, b = end;
        }
    }
};
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < n; i++){
		vector<int> now;
		for(int j = i; j < n; j++){
			now.push_back(s[j]);
		}
		ZFunc z(now);
		vector<int> mx(n - i + 1, -(1<<30));
		for(int j = n - 1; j >= i; j--){
			mx[j - i] = max(mx[j - i + 1], z.z[j - i]);
		}
		for(int j = 1; j < n - i; j++){
			if(mx[j] >= j){
				ans = max(ans, j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

#define DIGIT_NUM 4

int main(void)
{
    int i;
    int Num;
    int EachNum[DIGIT_NUM];
    int DivNum = 1000;
    
    scanf("%d", &Num);
    
    for(i=0; i<DIGIT_NUM; i++){
        if(i==DIGIT_NUM){
            EachNum[i] = Num % DivNum;
        }else{
            EachNum[i] = Num / DivNum;
        }
        Num = Num - (Num/DivNum)*DivNum;
        DivNum /= 10;
    }
    
    if((EachNum[0] == EachNum[1] && EachNum[1] == EachNum[2])
       || (EachNum[1] == EachNum[2] && EachNum[2] == EachNum[3])){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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;
  vl a(n);
  rep(i,n) cin >> a[i];
  vl p(n);
  long p1 = 0;
  REP(i,1,n){
    p1 = (p1 ^ a[i]);
  }
  p[0] = p1;
  REP(i,1,n){
    p[i] = (a[i-1] ^ a[i] ^ p[i-1]);
  }
  rep(i,n) cout << p[i] << " ";
  cout << endl;
}

Measured memory_bytes: 6272
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        System.out.print(z+" "+x+" "+y);

    }
}


Measured memory_bytes: 39164
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n = 0;
	cin >> n;
	vector<string> hoge;
	for(int i = 0;i < n;++i) {
		string s;
		cin >> s;
		hoge.push_back(s);
	}
	int syugou[1000] = {};
	for (int i = 0;i < hoge[0].length();++i) {
		syugou[hoge[0][i] - 'a']++;
	}
	for (int i = 1;i < hoge.size();++i) {
		int pre_syugou[1000] = {};
		for (int q = 0;q < hoge[i].length();++q) {
			pre_syugou[hoge[i][q] - 'a']++;
		}
		for (int i = 0;i < 26;++i) {
			syugou[i] = min(syugou[i], pre_syugou[i]);
		}
	}
	for (int i = 0;i < 26;++i) {
		for (int q = 0;q < syugou[i];++q) {
			cout << (char)(i + 'a');
		}
	}
	cout << endl;
	return 0;
}

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

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


for(int i=1;i<n;i++)
{
  for(int j=0;j<3;j++)
  {   if(j==0)
      {dp[i][j]=dp[i][j]+max(dp[i-1][1],dp[i-1][2]);}
      else if(j==1)
      { dp[i][j]=dp[i][j]+max(dp[i-1][0],dp[i-1][2]); }
      else
      {
         dp[i][j]=dp[i][j]+max(dp[i-1][0],dp[i-1][1]);
      }
  }

}

cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));








}


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

//qsort用降順
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


int main(void){
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

if((x-r<0||y-r<0)||(x+r>w||y+r>h)){printf("No\n");}
else{printf("Yes\n");}
return 0;
}



Measured memory_bytes: 2120
h, w = [int(x) for x in input().split()]
A = []
B = []

# 列削除用フラグ初期化 1で削除
rm_pos = [1]*w

# 白マスのみの行はリスト追加しない
for i in range(h):
    a = input()
    if a != '.' * w:
        A += [list(a)]

# 白マスのみの列 検索、. が含まれていない場合は 削除フラグを0に
for j in range(w):
    for i in range(len(A)):
        if A[i][j] != '.':
            rm_pos[j] = 0 
            break

#  del list を使わず
#　列削除フラグが 0 の列のみ新規リストへ追加

for i in range(len(A)):
    tmp = []
    for j, flg in enumerate(rm_pos):
        if flg == 0:
            tmp += A[i][j]
    B += [tmp]

# 回答出力
for i in range(len(B)):
    print(''.join(B[i]))

Measured memory_bytes: 3188
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def main():
    n = int(input())
    ans = 0
    div = make_divisors(n)
    for i in div[1:]:
        var = n
        while not var%i:
            var = var // i
        if var%i == 1:
            ans += 1
    ans += len(make_divisors(n-1)) - 1
    print(ans)

main()


Measured memory_bytes: 39024
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		BigInteger lim = BigInteger.valueOf(1000000000000000000l);
		BigInteger ret = BigInteger.ONE;
		long[] A = new long[N];
		boolean end = false;
		for(int i = 0; i < N; i++) {
			A[i] = s.nextLong();
			if(A[i] == 0l) {
				System.out.println(0);
				return;
			}
		}
		for(int i = 0; i < N; i++) {
			ret = ret.multiply(BigInteger.valueOf(A[i]));
			if(ret.compareTo(lim) == 1) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(ret);
    }
}

Measured memory_bytes: 62236
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed;
// cout << setprecision(10) << val;

string check = "ATGC";
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size(), ans = 0;
  rep(i, 0, n) {
    rep(j, 0, n) {
      string sub = s.substr(i, n - j - i);
      bool flag = false;
      rep(l, 0, sub.size()) {
        flag = false;
        rep(k, 0, 4) {
          if (check[k] == sub[l]) {
            flag = true;
          }
        }
        if (!flag) break;
      }
      if (flag) chmax(ans, (int)sub.size());
    }
  }
  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);

		// 入力値の取得
		int A = sc.nextInt();
		int B = sc.nextInt();

		// 結果の出力
		System.out.println(A * B);

		sc.close();
	}
}


Measured memory_bytes: 27024
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,ans=0;
  multiset<ll> idx_set;
  cin >> n;
  vector<ll> p(n),val(n+1);
  for(int i=0;i<n;i++){
    cin >> p[i];
    val[p[i]] = i+1;
  }
  idx_set.insert(0);
  idx_set.insert(0);
  idx_set.insert(n+1);
  idx_set.insert(n+1);
  idx_set.insert(val[n]);
  for(int i=n-1;i>0;i--){
    auto aft0 = idx_set.upper_bound(val[i]);
    auto bef0 = aft0;
    bef0--;
    auto aft1 = aft0;
    aft1++;
    auto bef1 = bef0;
    bef1--;
    ll b0idx = *bef0,b1idx = *bef1,a0idx = *aft0,a1idx = *aft1;
    ans += i*(b0idx-b1idx)*(a0idx-val[i]);
    ans += i*(a1idx-a0idx)*(val[i]-b0idx);
    idx_set.insert(val[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
int n;
int a[2][105];
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[0][i]>>a[1][i];
	for(int i=3;i<=n;i++)
		if(a[0][i-2]==a[1][i-2] && a[0][i-1]==a[1][i-1] && a[0][i]==a[1][i]){
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;

int main(){
  ll n,m;
  cin>>n>>m;
  ll a[n],b[n];
  vector<pair<ll,ll>> v(n);
  rep(i,n){
    cin>>a[i]>>b[i];
    v[i]={ a[i] , b[i] };
  }
  sort(v.begin(),v.end());
  ll buy=m;
  ll money=0;
  rep(i,n){
    if(buy<=v[i].second){
      money+=v[i].first*buy;
      break;
    }else{
      buy-=v[i].second;
      money+=v[i].first*v[i].second;
    }
  }
  cout<<money;
}


Measured memory_bytes: 3328
n, m = map(int, input().split())
q = []
for _ in range(m):
    a, b = map(int, input().split())
    i, j = -1, -1
    for k in range(len(q)):
        if i == -1:
            if a in q[k]:
                i = k
        if j == -1:
            if b in q[k]:
                j = k
        if i >= 0 and j >= 0:
            break
    if i >= 0:
        if j >= 0:
            if i != j:
                q[i] |= q[j]
                q.pop(j)
        else:
            q[i].add(b)
    elif j >= 0:
        q[j].add(a)
    else:
        q.append(set([a, b]))
print(abs(n - sum([len(i) for i in q]) - len(q)))


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    vector<int> r(n);
    for(int i = 0; i < n; i++)
    {
        r[i] = i+1;
    }
    int pcount = 0;
    int qcount = 0;
    int count = 0;
    do
    {
        count++;
        bool pflag = true;
        bool qflag = true;
        for(int i = 0; i < n; i++)
        {
            if(p[i] != r[i]) pflag = false;
        }
        for(int i = 0; i < n; i++)
        {
            if(q[i] != r[i]) qflag = false;
        }
        if(pflag) pcount = count;
        if(qflag) qcount = count;
    }
    while(next_permutation(r.begin(), r.end()));
    cout << abs(pcount-qcount) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


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

    vll p;
    for (ll i = 0; i < N; i++)
    {
        ll tmp;
        cin >> tmp;
        p.ADD(tmp);
    }

    sort(p.begin(), p.end());
    
    ll result = 0;
    for (ll i = 0; i < K; i++)
    {
        result += p[i];
    }
    OUTX(result);
    

    return 0;
}


Measured memory_bytes: 3624
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{ n: usize };
    let mut ac= 0usize;
    let mut wa= 0usize;
    let mut tle= 0usize;
    let mut re= 0usize;
    for _ in 0 .. n {
        input!{ s: String };
        match s.as_str() {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            "RE" => re += 1,
            _ => {},
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++) 
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout) 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;


int main()
{
	boost;
	db d,ti,s; cin>>d>>ti>>s;
	db ans=d/s;
	if(ans<=ti)
		cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	
	

return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
 
int main(){
    string s;
    cin >> s;

    if(s == "ARC"){
        cout << "ABC" << endl;
    }
    else {
        cout << "ARC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		long x=scanner.nextLong();
		p=new long[n+1];
		l=new long[n+1];
		p[0]=1;
		l[0]=1;
		for(int i=1;i<n+1;i++) {
			p[i]=p[i-1]*2+1;
		}
		for(int i=1;i<n+1;i++) {
			l[i]=l[i-1]*2+3;
		}
		calc(x,n);
		System.out.println(res);
	}
	static long[] p;
	static long[] l;
	static long res=0;
	private static void calc(long x,int i) {
		if(x<=1) {
			res+=(i==0)?1:0;
		}else if(x<=1+l[i-1]) {
			calc(x-1,i-1);
		}else if(x==2+l[i-1]) {
			res+=p[i-1]+1;
		}else if(x<=2+l[i-1]*2) {
			res+=p[i-1]+1;
			calc(x-2-l[i-1],i-1);
		}else {
			res+=2*p[i-1]+1;
		}
	}
	
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21076
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=2000000+10,mo=1000000007;
int fac[maxn],inv[maxn];
int f[4][3],g[4][3];
int i,j,k,l,t,n,m,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,ans;
int qsm(int x,int y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
int F(int n,int m){
	return (ll)fac[n+m]*inv[n]%mo*inv[m]%mo;
}
void work(int x1,int y1,int x2,int y2,int f){
	int x,y;
	fo(x,x3,x4){
		(ans+=(ll)f*(-1)*(x+y3)*F(x-x1,y3-y1-1)%mo*F(x2-x,y2-y3)%mo)%=mo;
		(ans+=(ll)f*(x+y4+1)*F(x2-x,y2-y4-1)%mo*F(x-x1,y4-y1)%mo)%=mo;
	}
	fo(y,y3,y4){
		(ans+=(ll)f*(-1)*(y+x3)*F(y-y1,x3-x1-1)%mo*F(y2-y,x2-x3)%mo)%=mo;
		(ans+=(ll)f*(y+x4+1)*F(y2-y,x2-x4-1)%mo*F(y-y1,x4-x1)%mo)%=mo;
	}
}
int main(){
	fac[0]=1;
	fo(i,1,maxn-10) fac[i]=(ll)fac[i-1]*i%mo;
	inv[maxn-10]=qsm(fac[maxn-10],mo-2);
	fd(i,maxn-11,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
	scanf("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
	scanf("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
	f[0][0]=1,f[0][1]=x1-1,f[0][2]=y1-1;
	f[1][0]=-1,f[1][1]=x1-1,f[1][2]=y2;
	f[2][0]=-1,f[2][1]=x2,f[2][2]=y1-1;
	f[3][0]=1,f[3][1]=x2,f[3][2]=y2;
	g[0][0]=1,g[0][1]=x6+1,g[0][2]=y6+1;
	g[1][0]=-1,g[1][1]=x6+1,g[1][2]=y5;
	g[2][0]=-1,g[2][1]=x5,g[2][2]=y6+1;
	g[3][0]=1,g[3][1]=x5,g[3][2]=y5;
	fo(i,0,3)
		fo(j,0,3)
			work(f[i][1],f[i][2],g[j][1],g[j][2],f[i][0]*g[j][0]);
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    dsu d(N);
    rep(i, Q) {
        int t, u, v;
        cin >> t >> u >> v;

        if (t == 0) {
            d.merge(u, v);
        }

        if (t == 1) {
            cout << (d.same(u, v)? 1 : 0) << endl;
        }
    }
}

Measured memory_bytes: 3964