akhauriyash/Code-Regression huggingface dataset:
fn main(){
    let a: Vec<i32> = read_vec();
    let c0 = (a[0] - a[1]).abs() + (a[0] - a[2]).abs();
    let c1 = (a[0] - a[2]).abs() + (a[1] - a[2]).abs();
    let c2 = (a[0] - a[1]).abs() + (a[1] - a[2]).abs();
    let b = vec![c0, c1, c2];
    let min_cost = b.iter().min();
    println!("{}", min_cost.unwrap());
}

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

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<bitset>
using namespace std;
typedef long long s64;

const int ONE = 405;
const int MOD = 1e9 + 7;

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}


bitset <ONE> A[ONE], R1, R2;

int vis[ONE];
int n, m;

struct power
{
		int x, y;
}a[100005];

int main()
{
	//	freopen("data.in","r",stdin);
	//	freopen("yjt.out","w",stdout);
		n = get(), m = get();
		for(int i = 1; i <= m; i++)
			a[i].x = get(), a[i].y = get();

		for(int i = 1; i <= n; i++)
		{
			A[i][i] = 1;
			for(int j = m; j >= 1; j--)
			{
				int x = a[j].x, y = a[j].y;
				if(A[i][x] && A[i][y]) {vis[i] = 1; break;}
				if(A[i][x]) A[i][y] = 1;
				else if(A[i][y]) A[i][x] = 1;
			}
		}

		int Ans = 0;
		for(int i = 1; i <= n; i++)
			if(!vis[i])
				for(int j = i + 1; j <= n; j++)
					if(!vis[j] && !A[i][j] && !A[j][i])
						if((A[i] & A[j]).none())
							Ans++/*, cout<<i<<" "<<j<<endl*/;

		printf("%d", Ans); 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long A,B,C,D;
    cin>>A>>B>>C>>D;
    
    long c=B/C-(A-1)/C;
    long d=B/D-(A-1)/D;
    long l=C*D/(__gcd(C,D));
    long cd=B/l-(A-1)/l;
    
    //cout<<c<<endl;
    //cout<<d<<endl;
    //cout<<cd<<endl;
    cout<<(B-A+1)-c-d+cd<<endl;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split(' ')))
count = (10 ** 9)
for i in range(len(w)):
    result = sum(w[:i+1])
    result_ = sum(w[i+1:])
    if count > abs(result - result_):
        count = abs(result - result_)
print(count)

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

int main() {
    int n, ans = 0, temp = 0;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h.at(i);
    rep(i, n - 1) {
        if(h.at(i + 1) <= h.at(i)) temp++;
        else temp = 0;
        ans = max(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  string x;
  int n=0,e=0,w=0,s=0;
  cin>>x;
  rep(i,x.length()){
    switch(x[i]){
      case 'N':
        n=1; break;
      case 'E':
        e=1; break;
      case 'W':
        w=1; break;
      case 'S':
        s=1; break;
    }
  }
  if(n^s==0 && e^w==0){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	




int main(){

	string s,t;
	
	cin >> s >> t;
	
	int sz = SZ(s);
	
	while(sz--){
		
		if(s==t){
			cout << "Yes" << endl;
			return 0;
		}
		
		s = s.back()+s;
		s.pop_back();
	
	}
	
	cout << "No" << endl;
	
	
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int kaisu=sc.nextInt();
		int tasu=sc.nextInt();
		int moto=1;
		for(int i=0; i<kaisu; i++) {
			if(moto<tasu) {
				moto*=2;
			}
			else {
				moto+=tasu;
			}
		}
		System.out.println(moto);
	}
}

Measured memory_bytes: 25300
/*input
happy,newyear,enjoy
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	string s;
	cin>>s;
	REP(i,SZ(s)) if(s[i]==',') s[i]=' ';
	cout<<s;
	return 0;
}


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

using namespace std;
int op[100005], sp, sign[100005], ans, last;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> op[i];
    sort(op + 1, op + n + 1);
    for (int i = 1; i <= n; i++)if (op[i] < 0)++sp;
    if (sp == 0) {
        sign[1] = -1;
        for (int i = 2; i <= n; i++)sign[i] = 1;
        for (int i = 1; i <= n; i++)ans += op[i] * sign[i];
        cout << ans << endl;
        last = op[1];
        for (int i = 2; i < n; i++)cout << last << " " << op[i] << endl, last -= op[i];
        cout << op[n] << " " << last;
        return 0;
    } else if (sp == n) {
        sign[n] = 1;
        for (int i = 1; i < n; i++)sign[i] = -1;
        for (int i = 1; i <= n; i++)ans += sign[i] * op[i];
        cout << ans << endl;
        last = op[n];
        for (int i = n - 1; i >= 1; i--)cout << last << " " << op[i] << endl, last -= op[i];
    } else {
        int kk = 0;
        for (int i = 1; i <= n; i++)if (op[i] < 0)sign[i] = -1, kk = i; else sign[i] = 1;
        for (int i = 1; i <= n; i++)ans += op[i] * sign[i];
        cout << ans << endl;
        last = op[n];
        for (int i = kk; i >= 2; i--)cout << last << " " << op[i] << endl, last -= op[i];
        int last2 = op[1];
        for (int i = kk + 1; i < n; i++)cout << last2 << " " << op[i] << endl, last2 -= op[i];
        cout << last << " " << last2;
    }
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> T in(){T x;cin>>x;return x;}

int main(){
	int N; cin>>N;
	vi C(N);
	ll sumA=0, sumB=0, minus=0;
	int ans = 0;
	rp(i, 0, N){
		int a = in<int>();
		sumA += a;
		C[i] = a;
	}
	rp(i, 0, N){
		int b = in<int>();
		sumB += b;
		C[i] -= b;
		if(C[i]<0){
			ans++;
			minus += C[i];
		}
	}

	if(sumA < sumB){ puts("-1"); return 0; }

	sort(all(C));

	for(int i=C.size()-1; minus<0 && i>=0 && C[i]>0; --i){
		ans++;
		minus += C[i];
	}

	cout<< ans <<endl;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<String, Integer> s = new HashMap<>();
		long ans = 0;
		for (int i = 0; i < N; i++) {
			String[] input = sc.next().split("");
			Arrays.sort(input);
			String tmp = String.join("", input);
			if (s.containsKey(tmp)) {
				int v = s.get(tmp) + 1;
				ans += v;
				s.put(tmp, v);
			} else {
				s.put(tmp, 0);
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 99828
from collections import namedtuple

Point = namedtuple('Point', 't x y')

def canMove(p1, p2):
  dt = p2.t - p1.t
  dx = p2.x - p1.x
  dy = p2.y - p1.y
  if dx + dy > dt:
    return False
  if (dt - (dx + dy)) % 2 == 0:
    return True
  return False

N = int(input())
prev = Point(0, 0, 0)
for _ in range(N):
  t, x, y = map(int, input().split())
  next = Point(t, x, y)
  if not canMove(prev, next):
    print('No')
    break
  prev = next
else:
  print('Yes')

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	ll mi = INF;
	ll ma = -INF;	
	FOR(i,0,N){
		ll k;
		cin >> k;
		if(ma<k)ma=k;
		if(mi>k)mi=k;
	}
	cout << ma-mi << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[1000000000*2];
		int h = sc.nextInt();
		int n = sc.nextInt();
		int count=0;
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			count=count+a;
		}
		if(count>=h)
			System.out.println("Yes");
		else
			System.out.println("No");
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<tuple<string,int,int>> ms(n);
    string ctmp,ct;
    int pntmp,pnt,numtmp,num;
    for(int i=0;i<n;i++){
        cin >> ct >> pnt;
        ms.at(i) = make_tuple(ct,pnt,i);
    }
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    sort(ms.begin(),ms.end());

    tie(ctmp,pntmp,numtmp) = ms.at(0);
    vector<tuple<int,string,int>> tmpp;
    vector<tuple<int,string,int>> rev;
    tmpp.push_back(make_tuple(pntmp,ctmp,numtmp));
    for(int i=1;i<n;i++){
        tie(ct,ignore,ignore) = ms.at(i);
        if(ct==ctmp){
            tie(ct,pnt,num) = ms.at(i);
            tmpp.push_back(make_tuple(pnt,ct,num));
        }
        else{
            reverse(tmpp.begin(),tmpp.end());
            for(auto tm:tmpp)
                rev.push_back(tm);
            for(auto tm:tmpp)
                tmpp.pop_back();
            tie(ctmp,pntmp,numtmp) = ms.at(i);
            tmpp.push_back(make_tuple(pntmp,ctmp,numtmp));
        }
        if(i==n-1){
            reverse(tmpp.begin(),tmpp.end());
            for(auto tm:tmpp)
                rev.push_back(tm);
            for(auto tm:tmpp)
                tmpp.pop_back();
        }
    }
    for(auto a:rev){
        tie(ignore, ignore ,num) = a;
        cout << num+1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, R, C;
string S;

int table[3][3];

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

    REP(i, 3) {
        REP(j, 3) { cin >> table[i][j]; }
    }

    cin >> N;
    vector<int> b(N);
    REP(i, N) cin >> b.at(i);

    REP(k, N) {
        REP(i, 3) {
            REP(j, 3) {
                if (b[k] == table[i][j]) {
                    table[i][j] = -1;
                }
            }
        }
    }

    bool flag = false;
    REP(i, 3) {
        if (table[i][0] == -1 && table[i][1] == -1 && table[i][2] == -1) {
            flag = true;
        }
        if (table[0][i] == -1 && table[1][i] == -1 && table[2][i] == -1) {
            flag = true;
        }
    }
    if (table[0][0] == -1 && table[1][1] == -1 && table[2][2] == -1) {
        flag = true;
    }
    if (table[0][2] == -1 && table[1][1] == -1 && table[2][0] == -1) {
        flag = true;
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int x, y, i;
	for (i = 0; i < 3000; i++)
	{
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0)
		{
			break;
		}
		if (x>y)
		{
			printf("%d %d\n", y, x);
		}
		else{
			printf("%d %d\n", x, y);
		}
	}
	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
typedef long long ll;
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

ll N,K,c;

int main() {
	cin >> N >> K;
	
	REP(i, K+1, N+1) {
		c += (N/i)*MAX(0,i-K) + MAX(0,N%i-K+1);
		if (K==0) c--;
	}
	
	cout << c;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    ll sum = 0;
    for(auto c : s) sum += (c - '0');
    cout << (sum % 9 == 0 ? "Yes\n" : "No\n");
    return 0;
}



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

int main()
{
    size_t N;
    cin >> N;

    int D1, D2;
    int current = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> D1 >> D2;
        if (D1 == D2)
        {
            current++;
        }
        else
        {
            current = 0;
        }
        if (current >= 3)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3632
package main

import (
	"fmt"
)
func wariwari(n int) int {
	count := 0
	for {
		if n % 2 == 0 {
			count ++
			n /= 2
		}else {
			return count
		}
	}
}


func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	var count int
	for i := 0; i < n; i++ {
		count += wariwari(a[i])
	}

	fmt.Println(count)
}



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

template<typename t>inline t min_(t a,t b){return a<=b?a:b;}
template<typename t>inline t max_(t a,t b){return a>=b?a:b;}
template<typename t>inline void chkmin(t&a,t b){if(a>b)a=b;}
template<typename t>inline void chkmax(t&a,t b){if(a<b)a=b;}

typedef long long ll;
const int maxn=1e4+10;
int n,a[maxn],b[maxn];
ll x,y;

int main(){
	cin>>n;
	for(int i=0;i<n;++i)
		cin>>a[i];
	for(int i=0;i<n;++i)
		cin>>b[i];
	for(int i=0;i<n;++i){
		if(a[i]>b[i])
			x+=a[i]-b[i];
		else
			y+=(b[i]-a[i])/2;
	}
	puts(x<=y?"Yes":"No");
	return 0;
}


Measured memory_bytes: 384
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let s: String = parse_line().unwrap();
    let mut ret = String::new();
    for c in s.chars() {
        match c {
            'B' => {
                ret.pop();
            }
            _ => {
                ret.push(c);
            }
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n, k;
   cin >> n >> k;
   set<int> st;
   vector<int> d(k);
   for(int i = 0;i < k;i++) {
       cin >> d[i];
       for(int j = 0;j < d[i];j++) {
           int x;
           cin >> x;
           st.insert(x);
       }
   }
   cout << n-st.size()<< endl;
}

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

#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol a,b;
  cin >>a>>b>>n;
  lol ans=0;
  chmax(ans,(a*n)/b-a*(n/b));
  lol x=min(b-1,n);
  chmax(ans,(a*x)/b-a*(x/b));
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n;
string s;


ll pc(ll a){
    ll res = 0;
    while(a > 0){
        if (a % 2 == 1) res++;
        a /= 2;
    }
    return res;
}

ll u, d, nowd[210000], nowu[210000];
int main() {
    cin >> n >> s;
    ll npc = 0;
    REP(i, n){
        if (s[i] == '1') npc++;
    }
    nowu[n - 1] = 1;
    nowd[n - 1] = 1;
    if(npc != 1){
        nowd[n - 1] %= npc - 1;
        REPR(i, n - 1){
            if (s[i] == '1') d += nowd[i];
            d %= (npc - 1);
            if(i > 0)nowd[i - 1] = nowd[i] * 2 % (npc - 1);
        }
    }
    nowu[n - 1] %= npc + 1;
    REPR(i, n - 1){
        if (s[i] == '1') u += nowu[i];
        u %= (npc + 1);
        if(i > 0)nowu[i - 1] = nowu[i] * 2 % (npc + 1);
    }
    REP(i, n){
        if(s[i] == '1'){
            if (npc == 1) cout << 0 << endl;
            else{
                ll cnt = 1, mod = npc - 1;
                ll now = (d - nowd[i] + mod) % mod;
                while(now != 0){
                    now %= pc(now);
                    cnt++;
                }
                cout << cnt << endl;
            }
        }
        else{
            ll cnt = 1, mod = npc + 1;
            ll now = (u + nowu[i] + mod) % mod;
            //cout << i << " " << nowu[i] << " " << u << " " << mod << endl;
            while(now != 0){
                now %= pc(now);
                cnt++;
            }
            cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 6892
import java.util.*;

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

		if(a<b && b<c){
			System.out.println("Yes");
		}else{
            System.out.println("No");
        }

	}
}


Measured memory_bytes: 26204
#include<bits/stdc++.h>
using namespace std;
int a[100009],len=0;
int main()
{
	char s;
	while(scanf("%c",&s)!=EOF)
	{
		if(s=='B'&&len>0)
		{
			a[len]=0;
			len--;
		}
		if(s=='1')a[++len]=1;
		if(s=='0')a[++len]=0;
	}
	for(int i=1;i<=len;i++)cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
  int64_t Q, H, S, D;
  std::cin >> Q >> H >> S >> D;
  int cs, cd;
  int64_t N;
  std::cin >> N;
  cd = N >> 1;
  cs = N & 1;
  S = std::min(S, std::min(Q * 4, H * 2));
  D = std::min(2 * S, D);
  std::cout << cd * D + cs * S << std::endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, T = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

ans = [-1, 0] # [最大の差, 個数]
max_right = -1

for i in range(N - 2, -1, -1):
    if A[i + 1] > max_right:
        max_right = A[i + 1]
    left = A[i]
    if max_right - left > ans[0]:
        ans = [max_right - left, 1]
    elif max_right - left == ans[0]:
        ans[1] += 1

print(ans[1])
    




Measured memory_bytes: 58864
#include <stdio.h>
#define N 100000

typedef struct{
  int parent;
  int left;
  int right;
} Node;

int depth(int);
void judgenode(int);
void children(int);

Node node[N];

main() {
  int i,j,id,k,n,left,child;

  scanf("%d",&n);

  for(i=0; i<n; i++) {
    node[i].parent = -1;
    node[i].left = -1;
    node[i].right = -1;
  }

  for(i=0; i<n; i++) {
    scanf("%d%d",&id,&k);
    for(j=0; j<k; j++){
      scanf("%d",&child);
      if(j == 0)
	node[id].left = child;
      else
	node[left].right = child;
      node[child].parent = id;
      left = child;
    }
  }


  for(i=0; i<n; i++) {
    printf("node %d: parent = %d, depth = %d, ",i,node[i].parent,depth(i));
    judgenode(i);
    children(i);
  }

  return 0;

}


  int depth(int i) {
    int count=0, iparent;
    iparent=i;
    while(1) {
      if(node[iparent].parent == -1)
	break;
      iparent = node[iparent].parent;
      count+=1;
    }
    return count;
  }


  void judgenode(int i) {
    if(node[i].left == -1 && node[i].parent != -1)
      printf("leaf,");
    else if(node[i].parent == -1)
      printf("root,");
    else 
      printf("internal node,");
  }


void children(int i) {
  int sibling;
  printf(" [");
  if(node[i].left != -1) {
    printf("%d",node[i].left);
    sibling = node[i].left;
    while(1) {
      if(node[sibling].right == -1)
	break;
      printf(", %d",node[sibling].right);
      sibling = node[sibling].right;
    }
  }
  printf("]\n");
}

Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cntR = 0;
    for (int i = 0; i < n; ++i)
    {
        if (s[i] =='R') cntR++;
    }
    if (cntR > (n-cntR)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int a = input();

    cout << a + a * a + a * a * a << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

int main() {

  int array[5] = {0};
  int array2[5] = {0};
  int temp = 0;
  for (int i = 0; i < 5; i++) {
    cin >> array[i];
    temp = array[i] % 10;
    array2[i] = (10 - temp) % 10;
  }
  
  int lastIndex = 0;
  for (int i = 1; i < 5; i++) {
    if (array2[i] > array2[lastIndex]) {
      lastIndex = i;
    }
  }
  
  int result = 0;
  for (int i = 0; i < 5; i++) {
    if (i == lastIndex) {
      continue;
    }
    if (result % 10 != 0) {
      result = (result / 10 + 1) * 10;
    }
    result += array[i];
  }
  
  if (result % 10 != 0) {
    result = (result / 10 + 1) * 10;
  }
  result += array[lastIndex];
  
  cout << result << endl;
}


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

int main(){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;

	
	vector<int> block;
	int cnt = 1;
	rep(i,s.size()-1){
		if(s[i+1] == s[i]){
			cnt++;
		}
		else{
			block.push_back(cnt);
			cnt = 1;
		}
	}
    block.push_back(cnt);
	
	vector<int> point;
	point.push_back(0);
	rep(i,block.size()){
		point.push_back(point.back()+block[i]);
	}
	
	int res = 0;
	if(s[0]=='1'){
		
		if(point.size() <= 2*k+2){
			cout << n << endl;
			return 0;
		}
		
		int i = 0;
		while(i+(2*k+1) <= point.size()){
		    if(i+(2*k+1) == point.size()){
		        res = max(res, point[i+(2*k)]-point[i]);
		    }
		    else{
		        res = max(res, point[i+(2*k+1)]-point[i]);
		    }
			
			i += 2;
		}
	}
	else{
		// 00010101001100
		
		if(point.size() <= 2*k+1){
			cout << n << endl;
			return 0;
		}
		int i = 0;
		while(i+(2*k+1) <= point.size()){
			if(i==0){
				res = max(res, point[2*k-1]-point[0]+1);
				i++;
			}
			else{
			    if(i+(2*k+1) == point.size()){
			        res = max(res, point[i+(2*k)]-point[i]);
			    }
			    else{
			        res = max(res, point[i+(2*k+1)]-point[i]);
			    }
				
				i += 2;
			}
			
			
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1528
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>

int main() {

	int n;
	std::cin >> n;

	std::vector<int> v;
	v.resize(n);

	for (auto&e : v)
		std::cin >> e;
			

	std::sort(std::begin(v), std::end(v));

	auto it = std::unique(std::begin(v), std::end(v));

	while (std::distance(std::begin(v), it) != 1) {
		auto beg = std::begin(v);
		//auto me = *beg == 0 ? *(++beg) : *beg;

		for (auto itk = ++std::begin(v); itk != it; ++itk) {
			//if (me != *itk)
				*itk = *itk % *beg == 0 ?*beg : *itk % *beg;
		}
		std::sort(std::begin(v), it);
		it = std::unique(std::begin(v), it);
	}
	
	std::cout << v[0] << "\n";
	/*
	while (v[0] > 1) {
		auto rem = v[1] % v[0];
		v[1] = v[0];
		v[0] = rem;
	}

	std::cout << ( v[0]==0 ? v[1] : v[0] ) << "\n";
	*/
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string.h>
using namespace std;

int main(){
	char input[10];
	int loc = 0, all = 0;
	int point = 0;
	int out = 3;
	int e;

	cin >> e;
	while(e != 0){
		cin >> input;
		if( strcmp(input, "HIT") == 0 ){
			loc++;
			if(loc > 3){
				loc--;
				point++;
			}
				
		}else if( strcmp(input, "OUT") == 0){
			out--;
			if(out == 0){
				out = 3;
				e--;
				loc = 0;
				cout << point << endl;
				point = 0;
			}
		}else if( strcmp(input, "HOMERUN") == 0){
			point++;
			point += loc;
			loc = 0;
		}
	}

}

Measured memory_bytes: 1164
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
using namespace std;
int main(){
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n, m;
    cin >> n >> m;
    vector<ll> acc(n + 1);
    acc.eb(0);
    rep(i, n) { cin >> acc[i + 1]; acc[i + 1] = (acc[i + 1] + acc[i]) % m; }
    // outa(acc, n + 1);
    
    map<ll, int> mp;
    rep(i, n + 1) mp[acc[i]]++;
    ll ans = 0;
    for (auto e : mp) ans += (ll)e.S * (e.S - 1) / 2;
    out(ans);
}






Measured memory_bytes: 4976
import heapq

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

Q = [[-A[1],-A[0]]]*2
heapq.heapify(Q)

ans = A[0]
for a in A[2:]:
    #print(Q)
    top = heapq.heappop(Q)
    ans += -top[0]

    heapq.heappush(Q, [-a,-top[0]])
    heapq.heappush(Q, [-a,-top[1]])
    #print(ans)
    
print(ans)


Measured memory_bytes: 49508
#include <stdio.h>
int cmp(int *x, int *y) { return *y - *x; }
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int *l = calloc(n, sizeof(int));
  for(int i = 0; i < n; i++) scanf("%d", &(l[i]));
  qsort(l, n, sizeof(int), cmp);
  int sum = 0;
  for(int i = 0; i < k; i++) sum += l[i];
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 128
def main():
    n, w = map(int, input().split())
    dp = [-1] * (w + 1)
    dp[w] = 0
    for i in range(n):
        input_w, input_v = map(int, input().split())
        for i in range(input_w, w + 1):
            if dp[i] == -1:
                continue
            if dp[i - input_w] < dp[i] + input_v:
                dp[i - input_w] = dp[i] + input_v
    print(max(dp))

main()

Measured memory_bytes: 9016
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

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

    int left = 0;
    while (str[left] != 'A') left++;
    int right = str.size()-1;
    while (str[right] != 'Z') right--;

    cout << right - left + 1 << endl;

    return 0;
}

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

int main(){
  int A,B,sum=0;
  cin >> A >> B;
  string S;
  cin >> S;
  if(S[A]=='-'){
    sum++;
    for(int i=0;i<A;i++){
      if(S[i]!='-'){
        sum++;
      }
    }
    for(int i=A+1;i<A+B+1;i++){
      if(S[i]!='-'){
        sum++;
      }
    }
  }
  if(sum==A+B+1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// atcoder/agc018/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n, m;
  while (cin >> n >> m) {
    int a[n][m];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cin >> a[i][j];
        --a[i][j];
      }
    }

    bool used[m] = {false, };
    int mn = 1 << 29;

    while (count(used, used + m, false)) {
      int cnt[m] = {0, };

      for (int i = 0; i < n; ++i) {
        int idx = -1;
        for (int j = 0; j < m; ++j) {
          if (!used[a[i][j]]) {
            idx = a[i][j];
            break;
          }
        }
        ++cnt[idx];
      }
      int idx = max_element(cnt, cnt + m) - cnt;
      setmin(mn, cnt[idx]);
      used[idx] = true;
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int a[200001];
int d[200001];
vector <int> v;

int main(void){
    int n; cin >> n; for(int i = 1;i <= n;i++)cin >> a[i];
    for(int i = n;i >= 1;i--){
        int sum = 0;
        for(int j = 2;j * i <= n;j++)sum += d[j*i];
        d[i] = (a[i]^(sum%2));
    }
    for(int i = 1;i <= n;i++){
        if(d[i])v.push_back(i);
    }
    printf("%d\n", v.size());
    for(int i = 0;i < v.size();i++)printf("%d ", v[i]);
	return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    for(int i=1; i<=9; i++){
      for(int j=1; j<=9; j++){
        if(N == i*j){
          System.out.println("Yes");
          return;
        }
      }
    }
    
    System.out.println("No");
  }
}


Measured memory_bytes: 23764
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n

INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def prob():
    d = Debug()
    d.off()
    N = getInt()
    S = input()
    r, b = 0, 0
    for h in S:
        if h == 'R':
            r += 1
        else:
            b += 1
    d.dmp((r,b),'r,b')
    if r > b:
        return 'Yes'
    else:
        return 'No'


ans = prob()
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N, M; cin >> N >> M;
	vector<int> g; g.clear();
	for (int i = 1; i * i <= M; ++i){
		if (M % i == 0){
			g.push_back(i);
			if (i * i != M){
				g.push_back(M / i);
			} // end if
		} // end if
	} // end for

	sort(ALL(g));
	int ind = upper_bound(ALL(g), M / N) - g.begin();
	int res = g[ind-1];
  
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int x[4], y[4];
  int i, j, k;

  scanf("%d %d %d %d", &x[0], &y[0], &x[1], &y[1]);

  x[2] = x[1] - (y[1] - y[0]);
  y[2] = y[1] + (x[1] - x[0]);

  x[3] = x[2] - (y[2] - y[1]);
  y[3] = y[2] + (x[2] - x[1]);

  printf("%d %d %d %d\n", x[2], y[2], x[3], y[3]);
  return 0;
}


Measured memory_bytes: 128
from collections import defaultdict
N,K=map(int,input().split())
Hash=defaultdict(lambda:0)
for i in range(K):
    x=int(input())
    L=list(map(int,input().split()))
    for i in L:
        Hash[i]=1
count=0
for i in range(1,N+1):
    if Hash[i]==0:
        count+=1
print(count)

Measured memory_bytes: 67888
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
typedef long long ll;

int len(int n) {
    return log10(n) + 1;
}

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

    int n;
    cin >> n;
    int res = 0;
    Rep (i, 1, n + 1) {
        if (len(i) % 2) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3936
import java.util.*;

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


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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 201000;
typedef pair<int,int> pii;
pii b[N]; int st[N];
int n, R, C, tp, tot;

inline int get(int x, int y) {
	if(x and x != R and y and y != C) return -1;
	if(y == 0) return x;
	if(x == R) return R + y;
	if(y == C) return R + C + (R-x);
	return R + C + R + (C-y);
}

int main() {
	read(R), read(C), read(n);
	for(int i=1,x,y,t1,t2;i<=n;++i) {
		read(x), read(y), t1 = get(x, y);
		read(x), read(y), t2 = get(x, y);
		if(t1 == -1 or t2 == -1) continue;
		b[++tot] = pii(t1, i);
		b[++tot] = pii(t2, i);
	}
	sort(b+1, b+tot+1);
	for(int i=1;i<=tot;++i)
		if(tp and st[tp] == b[i].second) --tp;
		else st[++tp] = b[i].second;
	puts(tp ? "NO" : "YES");
	return 0;
}

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

int main(){
  int n;
  long long X=0, x=0,ans=10000000000000LL;
  cin >> n;
  
  vector<long long> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
    X += a.at(i);
  }
  
  for(int i=0; i<n; i++){
    x+=a.at(i);
    if(i+1 < n)
      ans = min(ans, abs(X-2*x));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<tuple>
#include<queue>

using namespace std;

typedef long long ll;
typedef tuple<ll, ll, ll> T3;

int N;
ll A[200000 + 10];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	sort(A, A + N, greater<ll>());

	if (N == 2) {
		cout << A[0] << endl;
		return 0;
	}

	ll ans = A[0];
	priority_queue<T3> pq;
	pq.push(make_tuple(min(A[0], A[1]), A[0], A[1]));
	pq.push(make_tuple(min(A[0], A[1]), A[0], A[1]));
	for (int i = 2; i < N; i++) {
		auto tp = pq.top();
		pq.pop();
		ans += get<0>(tp);
		ll l = get<1>(tp), r = get<2>(tp);
		pq.push(make_tuple(min(l, A[i]), l, A[i]));
		pq.push(make_tuple(min(A[i], r), A[i], r));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11132
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int n,m;cin>>n>>m;
  set<int> a;
  set<int> b;
  rep(i, n) {
    int tmp;
    cin>>tmp;
    a.insert(tmp);
  }
  rep(i, m) {
    int tmp;
    cin>>tmp;
    b.insert(tmp);
  }
  dump(a);
  dump(b);

  int s,t;
  s = 0; t = 0;
  int ans = 1;
  int count = 0;
  rrep(i, 1, (n*m)+1){
    int p = a.count(i);
    int q = b.count(i);

    if (p && q) {
    }
    else if(p==1 && q==0){
      ans *= t;
      ans %= MOD;
    }
    else if(p==0 && q==1){
      ans *= s;
      ans %= MOD;
    }
    else if(p==0 && q==0){
      ans *= (s*t)-count;
      ans %= MOD;
    }
    else{
      assert(false);
    }

    s += p;  // embeded row
    t += q;  // embeded column
    count++;
    dump(s,t,ans);
  }
  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 384
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)
    return divisors

n=int(input())
arr=make_divisors(n)
#arr.sort()

count=0
for i in arr:
    if i==1:
        continue
    if n//(i-1) == n%(i-1):
        count+=i-1
print(count)

Measured memory_bytes: 3264
n=int(input())
a=list(map(int,input().split()))
c2=0
c4=0
for aa in a:
  if aa%2 == 0:
    if aa%4 == 0:
      c4+=1
    else:
      c2+=1
c0=n-(c2+c4)
cc=c4-c0
if c2>=1 and c2 != n:
  cc-=1
print("Yes" if cc >= -1 else "No")


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

using namespace std;

int main(){

	string S;
	cin >> S;
	
	if(S.size()==2){
		cout << S << endl;
		return 0;
	}

	if(S.size()==3){
		cout << S[2] <<S[1] <<S[0] <<endl;
		return 0;
	}


	return 0;

}

Measured memory_bytes: 256
import os, sys, re, math
import itertools

N = int(input())
P = tuple([int(n) for n in input().split()])
Q = tuple([int(n) for n in input().split()])

nums = [n for n in range(1, N + 1)]
patterns = itertools.permutations(nums, N)
i = 0
for pattern in patterns:
    if pattern == P:
        pi = i
    if pattern == Q:
        qi = i
    i += 1

print(abs(pi - qi))

Measured memory_bytes: 9820
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
string s;
signed main()
{
    cin>>s;
    int n=s.length();
    for(ri int i=n-1;~i;)
    {
        //printf("%lld\n",i);
        if(i>=4 && s.substr(i-4,5)=="dream") i-=5;
        else if(i>=4 && s.substr(i-4,5)=="erase") i-=5;
        else if(i>=6 && s.substr(i-6,7)=="dreamer") i-=7;
        else if(i>=5 && s.substr(i-5,6)=="eraser") i-=6;
        else{
            puts("NO");
            return 0;
        }
        
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 3724