akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod ((__int128)1000000007)
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCAL
//	freopen("in", "r", stdin);
#endif
}
typedef long long ll;
typedef ll _I;
typedef double ld;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, dp[200005][2];
string s;
char t[2] = {'.', '#'};

int main() {
	doin();
	cin >> n >> s;
	for (int i = 0; i <= n; i++)
		dp[0][i] = dp[i][1] = 1000000000;
	dp[0][0] = dp[0][1] = 0;
	for (int i = 1; i <= n; i++) {
		if(s[i-1] == '.'){
			dp[i][0] = min(i>1 ? dp[i-2][0]+1 : 0, dp[i-1][0]);
			dp[i][1] = 1+min(dp[i-1][0], dp[i-1][1]);
		} else {
			dp[i][0] = 1+dp[i-1][0];
			dp[i][1] = min(dp[i-1][0], dp[i-1][1]);
		}
	}
	cout << min(dp[n][0], dp[n][1]);
}



Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
long long n,m,l,dis[305][305],newdis[305][305];
int main(){
    cin>>n>>m>>l;
    for(int i=1;i<305;i++){
        for(int j=1;j<305;j++)
            dis[i][j]=newdis[i][j]=inf;
        dis[i][i]=newdis[i][i]=0;
    }
    for(int i=0;i<m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        newdis[u][v]=dis[u][v]=w;
        newdis[v][u]=dis[v][u]=w;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(dis[i][k]!=inf&&dis[k][j]!=inf)
                    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    
	for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            newdis[i][j]=(dis[i][j]<=l?1:inf);
        newdis[i][i]=0;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(newdis[i][k]!=inf&&newdis[k][j]!=inf)
                    newdis[i][j]=min(newdis[i][j],newdis[i][k]+newdis[k][j]);
    int q,s,t;
    cin>>q;
    while(q--){
        cin>>s>>t;
        if(newdis[s][t]==inf)
            cout<<"-1"<<endl;
        else
            cout<<newdis[s][t]-1<<endl;
    }
	return 0;
}

Measured memory_bytes: 2048
n, m = map(int, input().split())
cnt = [0] * m
for _ in range(n):
  _, *a = map(int,input().split())
  for ai in a:
    cnt[ai-1] += 1
sum_ = 0
for c in cnt:
  if c == n:
    sum_ += 1
print(sum_)

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main{

	static PrintWriter out;
	static InputReader ir;

	static void solve(){
		int n=ir.nextInt();
		int[] s=new int[100003];
		s[1]++;
		for(int i=0;i<n;i++){
			s[ir.nextInt()]++;
			s[ir.nextInt()+1]--;
		}
		for(int i=0;i<100002;i++){
			s[i+1]+=s[i];
		}
		for(int i=n+1;i>=1;i--){
			if(s[i]>=i){
				out.println(i-1);
				break;
			}
		}
	}

	public static void main(String[] args) throws Exception{
		ir=new InputReader(System.in);
		out=new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer=new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

		public boolean hasNextByte() {
			if(curbuf>=lenbuf){
				curbuf= 0;
				try{
					lenbuf=in.read(buffer);
				}catch(IOException e) {
					throw new InputMismatchException();
				}
				if(lenbuf<=0) return false;
			}
			return true;
		}

		private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

		private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

		private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

		public boolean hasNext(){skip(); return hasNextByte();}

		public String next(){
			if(!hasNext()) throw new NoSuchElementException();
			StringBuilder sb=new StringBuilder();
			int b=readByte();
			while(!isSpaceChar(b)){
				sb.appendCodePoint(b);
				b=readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			int res=0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public long nextLong() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			long res = 0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

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

		public int[] nextIntArray(int n){
			int[] a=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a=new long[n];
			for(int i=0;i<n;i++) a[i]=nextLong();
			return a;
		}

		public char[][] nextCharMap(int n,int m){
			char[][] map=new char[n][m];
			for(int i=0;i<n;i++) map[i]=next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 26040
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 + 7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
 const int nmax = 5e5 + 10 ;
vector < int > b(nmax);
vector < vector < int > > seg(nmax*4) ;
void build( int node , int l , int r){
    if(l==r){
        seg[node].push_back(b[l]);
        return ;
    }
    int mid = (l+r)/2;
    build(node*2,l,mid);
    build(node*2+1,mid+1,r);
    int n = seg[node*2].size() , m = seg[node*2+1].size();
    int i = 0 , j = 0 ;
    while(i<n&&j<m){
        if(seg[node*2][i]<=seg[node*2+1][j])
            seg[node].push_back(seg[node*2][i++]);
        else
            seg[node].push_back(seg[node*2+1][j++]);
    }
    while(i<n){
        seg[node].push_back(seg[node*2][i++]);
    }
    while(j<m) seg[node].push_back(seg[node*2+1][j++]);
}
int query( int node , int l , int r , int start , int end){
    if(end < l || start > r || l > r)
        return 0 ;
    if(start <= l && end >= r){
        return seg[node].end()-lower_bound(seg[node].begin(),seg[node].end(),end+1);
    }
    int mid = (l+r)/2;
    return query(node*2,l,mid,start,end)+query(node*2+1,mid+1,r,start,end);
}
///////////////////////////////////////////////////////////////
void solve(){
    int n , q ;
    cin >> n >> q ;
    vector < int > a(n) ;
    for( int i = 0 ; i < n ; i++) cin >> a[i] ;
    map < int , int > mp ;
    for( int i = n-1 ; i >= 0 ; i--){
        if(mp.find(a[i])!=mp.end()){
            b[i] = mp[a[i]] ;
        }
        else{
            b[i]=n+1 ;
        }
        mp[a[i]] = i ;
    }
   // for( int i = 0 ; i <n  ; i++) cout <<b[i]  << " " ;
    build(1,0,nmax-1);
    while(q--){
        int l , r ;
        cin >> l >> r ;
        l--,r--;
        cout << query(1,0,nmax-1,l,r) << "\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}




Measured memory_bytes: 142916
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,k;cin>>n>>k;
    vector<bool>black(n);
    vector<vector<ll> >table(2*k,vector<ll>(2*k));
    rep(i,n){
        ll x,y;
        char c;
        cin>>x>>y>>c;
        if(c=='B')black[i]=1;
        x%=2*k;
        y%=2*k;
        if(x>=k){
            x-=k;
            black[i]=!black[i];
        }
        if(y>=k){
            y-=k;
            black[i]=!black[i];
        }
        if(black[i]){
            table[0][0]++;
            table[0][y+1]--;
            table[x+1][0]--;
            table[x+1][y+1]+=2;
        }else{
            table[x+1][0]++;
            table[0][y+1]++;
            table[x+1][y+1]-=2;
        }
    }
    rep(i,k)REP(j,1,k){
        table[i][j]+=table[i][j-1];
    }
    rep(i,k)REP(j,1,k){
        table[j][i]+=table[j-1][i];
    }
    ll ans=0;
    rep(i,k)rep(j,k){
        ans=max(ans,max(table[i][j],n-table[i][j]));
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 1e5
#define PI 3.141592653589793
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}
int binsearch(int n) //二分探索
{
    int l = -1;
    int r = maxn + 1;
    while (abs(r - l) > 1)
    {
        int mid = (r + l) / 2;
        if (true)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    return l;
}
signed main()
{
    int N;
    vector<int> L;
    cin >> N;
    rep(i, N)
    {
        int a;
        cin >> a;
        L.push_back(a);
    }
    sort(L.begin(), L.end(), greater<int>());
    int a, b, c;
    int ans = 0;
    for (int i = 0; i < N - 2; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (L[i] < (L[j] + L[k]))
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

ll gcd(ll a, ll b){
	if(b==0){
		return a;
	}else{
		return gcd(b, a%b);
	}
}

int main(void){
	string s;
	cin>>s;
	vector<ll> count1, count2;
	rep(i,s.size()){
		count1.push_back(1);
		count2.push_back(0);
	}
	rep(i,s.size()-1){
		if(s[i] == 'R'){
			count2[i+1] += count1[i];
			count1[i] = 0;
			count1[i+1] += count2[i];
			count2[i] = 0;
		}
	}
	REPS(i,s.size()-1){
		if(s[i] == 'L'){
			count2[i-1] += count1[i];
			count1[i] = 0;
			count1[i-1] += count2[i];
			count2[i] = 0;
		}
	}

	rep(i,s.size()){
		if(s[i] == 'L'){
			count1[i-1] += count2[i];
			count2[i] = 0;
		}else{
			count1[i+1] += count2[i];
			count2[i] = 0;
		}
	}
	rep(i,s.size()){
		cout<<count1[i];
		if(i != s.size()-1){
			cout<<" ";
		}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 2412
#include<stdio.h>

int main()
{
    long long n;
    long long a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    long long dev=n/(a+b);
    long long r=n%(a+b);
    long long count=0;
    count=a*dev;
    if(a>0){
        if(r>=a)
            count+=a;
        else
        {
            count+=r;
        }
        
    }
    printf("%lld\n",count);
    return 0;
}

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

using namespace std;

int main(){
  int a;
  int b;
  int c;
  int k;
  int ans=0;
  cin >> a >> b >> c >> k;
  if(k>a){
    ans+=a;
    k -= a;
  }
  else{
    cout << k << endl;
    return 0;
  }
  if(k>b){
    k -= b;
    ans -= k;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{
	map<long long,bool> bt;
	map<string,long long> ans;

	int num;
	char dummy;
	string type;
	while(cin>>num>>dummy>>type){
		if(!bt[num]){
			bt[num]=true;
			ans[type]++;
		}
	}

	cout<<ans["A"]<<endl<<ans["B"]<<endl<<ans["AB"]<<endl<<ans["O"]<<endl;

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

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

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val str = readLine()!!

    val begin = str.indexOf("A")
    // lastIndexOf覚えて!!
    val end = str.lastIndexOf("Z")

    // QWERTYASDFZXCVの場合、indexは0から始まるので6になる
    // substringの始点も0になるため、indexOfの開始位置は
    // substringの開始位置に利用できる
    // substringのbegin-endの場合、末尾文字列を含めるとき+1が必要
    val result = str.substring(begin, end + 1)
    println(result.length)
}

Measured memory_bytes: 34428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define SORT(s) sort((s).begin(),(s).end())

int main(){
    ll inf=(1LL<<63)-1;//2^63-1
    int N; cin >> N;
    vector<int> a;

    REP(i,N){
        int x; cin >> x;
        a.push_back(x);
    }
    SORT(a);

    ll ans = inf;
    for(int y=a.front(); y <= a.back(); ++y){
        ll cost = 0;
        REP(i,a.size()){
            cost += (a.at(i)-y)*(a.at(i)-y);
        }
        ans = min(ans,cost);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long ll;
const int N=1000005;
using namespace std;

int main()
{
	#ifdef Kay
		freopen ("code.in","r",stdin);
		freopen ("code.out","w",stdout);
	#endif
	ll n,m,d;
	cin>>n>>m>>d;
	ll l=d+1,r=n-d;
	ll tot=0;
	if (l<=r) tot=d+d+(r-l+1)*2;
	else tot=r+(n-l+1);
	if (d==0) tot=n;
	printf ("%.10lf",(double)tot*(m-1)/n/n);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();
// SourceTest用出力マクロ
#ifdef SOURCE_TEST
#define SPR(x) PR(x)
#define SPS(x) PS(x)
#else
#define SPR(x) \
    {}
#define SPS(x) \
    {}
#endif
int main() {
    map<char, string> cards;
    cin >> cards['a'];
    cin >> cards['b'];
    cin >> cards['c'];

    char turn = 'a';

    while (1) {
        if (cards[turn].size() == 0) break;
        auto nextTurn = cards[turn][0];
        cards[turn]   = cards[turn].substr(1, cards[turn].size() - 1);
        turn          = nextTurn;
    }

    turn = toupper(turn);
    PR(turn);
    return 0;
}


Measured memory_bytes: 3560
#include<iostream>

int main(){
    
    size_t n, ans = 0;

    std::cin >> n;

    for(size_t i = 0; i < n; i++){
        size_t l, r;
        std::cin >> l >> r;

        ans += r - l + 1;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;

int main(){
	double  a, b, c, d, e, f, num[6];
	while(cin >> a >> b >> c >> d >> e >> f){
		num[0] = a;
		num[1] = b;
		num[2] = c;
		num[3] = d;
		num[4] = e;
		num[5] = f;
		b *= d;
		c *= d;
		e *= a;
		f *= a;
		b -= e;
		c -= f;
		c /= b;
		num[0] *= num[4];
		num[2] *= num[4];
		num[3] *= num[1];
		num[5] *= num[1];
		num[0] -= num[3];
		num[2] -= num[5];
		num[2] /= num[0];
		if(num[2] == -0)
			num[2] = 0;
		if(c == -0)
			c = 0;
		cout << fixed << setprecision(3) << num[2] << ' ' << c << endl;
	}
    return 0;
}


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

int main()
{
    int h,w;
    for( ; ; )
    {
        cin >> h >> w;
        if(h==0 && w==0)
        {
            break;
        }
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if((i%2==1 && j%2==1) || (i%2==0 && j%2==0))
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long i64;

int n;
i64 a[100010];

int main()
{
    cin >> n;

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

    i64 result = 0;

    for(int i = 1;i <= n;i++)
    {
        if(a[i] == 0) continue;
        if(a[i - 1] == 1)
        {
            result += 1;
            a[i] -= 1;
        }

        i64 cou = a[i] / 2;
        result += cou;
        a[i] = a[i] % 2;
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

    n = I()
    p = LIR(n)
    for i in range(n):
        p[i].append(i)
    p.sort()
    v = []
    for i in range(n-1):
        x,y,c = p[i]
        a,b,d = p[i+1]
        v.append((min(abs(x-a),abs(y-b)),c,d))
    p.sort(key = lambda x:x[1])
    for i in range(n-1):
        x,y,c = p[i]
        a,b,d = p[i+1]
        v.append((min(abs(x-a),abs(y-b)),c,d))
    v.sort()
    par = [i for i in range(n)]
    rank = [0]*n
    ans = 0
    s = 1
    for c,a,b in v:
        if root(a) != root(b):
            ans += c
            s += 1
            if s >= n:
                break
            unite(a,b)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 125280
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_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(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<pair<int, int>> A(N), B(N);
    rep(i, N){
        int x, y;
        cin >> x >> y;
        A[i] = mp(x, i);
        B[i] = mp(y, i);
    }
    sort(all(A)), sort(all(B));
    vector<pair<int, pair<int, int>>> P;
    rep(i, 1, N){
        P.pb(mp(abs(A[i].first - A[i - 1].first), mp(A[i].second, A[i - 1].second)));
        P.pb(mp(abs(B[i].first - B[i - 1].first), mp(B[i].second, B[i - 1].second)));
    }
    
    sort(all(P));
    
    union_find uf(N);
    
    ll ans = 0;
    for(auto p: P){
        if(!uf.same(p.second.first, p.second.second)){
            uf.unite(p.second.first, p.second.second);
            ans += p.first;
        }
        
        if(uf.count(0) == N) break;
    }
    
    output(ans);
    
    return 0;
}

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

int main() {
    long long N, D;
    cin >> N >> D;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

    int ans = 0;
    for (int i = 0; i < N; i++) {
        long long dist = X[i] * X[i] + Y[i] * Y[i];
        if (dist <= D * D) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6424
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, j, H, W, K, x[2], y[2];
	char **c;
	scanf("%d %d %d", &H, &W, &K);
	scanf("%d %d %d %d", &(x[0]), &(y[0]), &(x[1]), &(y[1]));
	c = (char**)malloc(sizeof(char*) * (H + 2));
	for (i = 1; i <= H; i++) {
		c[i] = (char*)malloc(sizeof(char) * (W + 2));
		scanf("%s", &(c[i][1]));
	}
	c[0] = (char*)malloc(sizeof(char) * (W + 2));
	c[H+1] = (char*)malloc(sizeof(char) * (W + 2));
	for (i = 1; i <= H; i++) {
		c[i][0] = '@';
		c[i][W+1] = '@';
	}
	for (j = 1; j <= W; j++) {
		c[0][j] = '@';
		c[H+1][j] = '@';
	}
	
	const int sup = 1 << 30;
	int k, l, q[1000001][2], head, tail;
	int **dist = (int**)malloc(sizeof(int*) * (H + 2));
	for (i = 1; i <= H; i++) {
		dist[i] = (int*)malloc(sizeof(int) * (W + 2));
		for (j = 1; j <= W; j++) dist[i][j] = sup;
	}
	dist[x[0]][y[0]] = 0;
	q[0][0] = x[0];
	q[0][1] = y[0];
	for (head = 0, tail = 1; head < tail; head++) {
		i = q[head][0];
		j = q[head][1];
		for (k = i - 1; k >= i - K && c[k][j] == '.' && dist[k][j] > dist[i][j]; k--) {
			if (dist[k][j] == dist[i][j] + 1) continue;
			dist[k][j] = dist[i][j] + 1;
			q[tail][0] = k;
			q[tail++][1] = j;
		}
		for (k = i + 1; k <= i + K && c[k][j] == '.' && dist[k][j] > dist[i][j]; k++) {
			if (dist[k][j] == dist[i][j] + 1) continue;
			dist[k][j] = dist[i][j] + 1;
			q[tail][0] = k;
			q[tail++][1] = j;
		}
		for (l = j - 1; l >= j - K && c[i][l] == '.' && dist[i][l] > dist[i][j]; l--) {
			if (dist[i][l] == dist[i][j] + 1) continue;
			dist[i][l] = dist[i][j] + 1;
			q[tail][0] = i;
			q[tail++][1] = l;
		}
		for (l = j + 1; l <= j + K && c[i][l] == '.' && dist[i][l] > dist[i][j]; l++) {
			if (dist[i][l] == dist[i][j] + 1) continue;
			dist[i][l] = dist[i][j] + 1;
			q[tail][0] = i;
			q[tail++][1] = l;
		}
	}
	if (dist[x[1]][y[1]] < sup) printf("%d\n", dist[x[1]][y[1]]);
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 13180
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    ll ans = 0;
    ll now = 1;
    rep(i, n)
    {
        if (a[i] == now)
        {
            now++;
        }
        else if (a[i] % now == 0)
        {
            ans += a[i] / now - 1;
            if (now == 1)
            {
                now = 2;
            }
        }
        else
        {
            ans += a[i] / now;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n=sc.nextInt();
    	int[] ary =new int[n];
    	int i,m;
    	int reg=0;
    	int min=0;
    	int max=0;
    	for(i=0;i<n;i++){
    		m=sc.nextInt();
    		if(i==0){
    			min=m;
    		}
    		if(i==1){
    			max=m-min;
    		}
        
    		if(m-min>max){
    			max=m-min;
    		}
    		if(m<min){
    			min=m;
    		}
    		
    	}
    	System.out.println(max);

    }
}


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

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

const int N = 10000100;

bool prime[N];

int main(){
    fill(prime,prime+N,true);
    prime[0]=prime[1]=false;
    for(int i=2; i<N; ++i){
        if(prime[i])for(int j=2*i; j<N; j+=i) prime[j]=false;
    }

    int n;
    cin >>n;

    int ans = 0;
    for(int i=3;i<=n;++i)if(prime[i]){
        if(prime[2+i]) ans += 2;
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  string s; cin >> s;
  string t = s;
  reverse(t.begin(),t.end());
  int cnt = 0;
  for(int i=0; i<s.length(); i++){
    if(s[i] != t[i]) cnt++;
  }
  cout << cnt/2 << endl;    
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa;
	cin >> aa;
	cout << (aa * (1 + aa * (1 + aa))) << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    string S;
    cin >> S;
    for(int i = S.size()-1; i > 0; i--) {
        if (i % 2 != 0) continue;
        if (S.substr(0, i / 2) == S.substr(i / 2, i / 2)) {
            print(i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
l, a, b, mod = map(int, input().split())

def mul(m1, m2):
    m = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
    for i in range(3):
        for j in range(3):
            m[i][j] = sum(m1[i][k] * m2[k][j] for k in range(3)) % mod
    return m

# mat = [[1, 0, 0],                                                                                                                                                                                                                                            
#        [0, 1, 0],                                                                                                                                                                                                                                            
#        [0, 0, 1]]                                                                                                                                                                                                                                            
# vec = (0, a, 1)                                                                                                                                                                                                                                              

mat = [[0, 0, 0],
       [a, 0, 0],
       [1, 0, 0]]
d = 1
e = a + b * (l - 1)
while e >= d:
    d *= 10
    if a >= d:
        continue
    t = (min(d - 1, e) - a) // b + 1
    a += b * t
    bit = [[d, 1, 0],
           [0, 1, b],
           [0, 0, 1]]
    while t > 0:
        if t & 1:
            mat = mul(bit, mat)
        bit = mul(bit, bit)
        t //= 2

# print((mat[0][0] * vec[0] + mat[0][1] * vec[1] + mat[0][2] * vec[2]) % mod)                                                                                                                                                                                  
print(mat[0][0])

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

using namespace std;

int ans, n, m, a[50], b[50];
bool g[50][50];
bool c[50];

void dfs(int v, int to, int from){
	c[v] = true;
	for(int i = 0; i < n; ++i){
		if(v == to && i == from) continue;
		if(v == from && i == to) continue;
		if(g[v][i] && !c[i]) dfs(i, to, from);
	}
}

bool isBridge(int to, int from){
	bool res = false;
	for(int j = 0; j < n; ++j) c[j] = false;
	dfs(0, to, from);
	for(int i = 0; i < n; ++i) if(!c[i]) res = true;
	return res;
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		cin >> a[i] >> b[i]; --a[i]; --b[i];
		g[a[i]][b[i]] = true;
		g[b[i]][a[i]] = true;
	}
	
	for(int i = 0; i < m; ++i){
		if(isBridge(a[i], b[i])) ans++;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int i;
	int n,f,cn,a;
	while(cin >> n,n)
	{
		f=cn=0;
		for(i=0;i<n;i++)
		{
			cin >> a;
			if(a>=2)
			{
				f=1;
			}
			if(a>0) cn++;
		}
		if(f)
		{
			cout << cn+1 << endl;
		}
		else cout << "NA\n" ;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <climits>
using namespace std; 

int main(){

    string F,R;
    cin>>F>>R;

    int count = 0;

    for(int i = 0; i < F.size(); ++i){
        if(F[i] == R[i]) count++;
    }

    cout << count;

	return 0;
}

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

using namespace std;


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

	vector<int> V(N);
	for (int i = 0; i < N; i++){
		cin >> V[i];
	}

	int ans = 0;
	if(K < N){	// 全部取ることができないので、左右からいくつか取って返す
		for (int get = (K + 1) / 2; get <= K; get++){
			int release = K - get;
			vector<int> got;

			for (int left = 0; left <= get; left++){
				int temp = 0;

				for (int i = 0; i < N; i++){
					if(i < left || N - (get - left) <= i){
						got.push_back(V[i]);
					}
				}
				sort(got.begin(), got.end());
				temp = accumulate(got.begin(), got.end(), 0);

				for (int i = 0; i < release; i++){
					if(got[i] < 0){
						temp -= got[i];
					} else {
						break;
					}
				}

				ans = max(ans, temp);
				got.clear();
			}
		}
	} else {	// 全部取れるので正値だけ
		for (int i = 0; i < N; i++){
			if(V[i] > 0){
				ans += V[i];
			}
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N], b[N];
int n, m, k;
ll trakm[N];
int main(){
	int t;
	scanf("%d%d",&n,&k);
	for(int i=0; i<k; ++i){
		scanf("%d%d",a+i,b+i);
	}
	trakm[n]=1;
	trakm[n+1]=0;
	ll mod = 998244353;
	ll st, nd;
	for(int i=n-1; i>=1; --i){
		trakm[i]=trakm[i+1];
		for(int j=0; j<k; ++j){
			st=i+a[j];
			nd=min(n, i+b[j]);
			if(nd>=st){
			trakm[i]+=trakm[st]-trakm[nd+1];
			trakm[i]%=mod;
		}
		}
		// cerr<<i<<" "<<trakm[i]<<endl;
	}
	ll ans = trakm[1]-trakm[2];
	ans%=mod;
	if(ans<0){
		ans+=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5320
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
#define pi 3.14159265358979323846
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n+1);
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    que.push(1);
    dist[1] = 0;
    vector<ll> ans(n+1, -1);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv]!=-1) continue;
            dist[nv] = dist[v]+1;
            ans[nv] = v;
            que.push(nv);
        }
    }
    bool ok = true;
    for(ll i =2; i <= n; i++){
        if(ans[i]==-1) ok = false;
    }
    if(ok==false)
        cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        for(ll i = 2; i <= n; i++)
            cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 13696
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ans = []

for i in range(min(X, K)):
  for j in range(min(Y, K)):
    if (i + 1) * (j + 1) > K:
      break
    for k in range(min(Z, K)):
      if (i + 1) * (j + 1) * (k + 1) > K:
        break
      ans.append(A[i] + B[j] + C[k])

ans.sort(reverse = True)

for i in range(K):
  print(ans[i])

Measured memory_bytes: 8708
#include<bits/stdc++.h>
using namespace std;
long long st[100010],ans[100010],js[100010];
int top;
int main()
{
	int n,q;scanf("%d%d",&n,&q);
	st[0]=n;
	for (int i=1;i<=q;i++)
	{
		long long w;scanf("%lld",&w);
		if (w<=st[0]) {st[0]=w;top=0;continue;}
		while ((top)&&(st[top]>=w)) top--;
		st[++top]=w;
	}
	js[top]=1;
	for (int i=top;i>=1;i--)
	{
		long long x=st[i];
		while (x>=st[0])
		{
			int w=upper_bound(st,st+i,x)-st-1;
			js[w]+=x/st[w]*js[i];//cout<<w<<' '<<js[w]<<endl;
			x%=st[w];
		}
		ans[x]+=js[i];
	}
	ans[st[0]]+=js[0];
	//for (int i=1;i<=n;i++) cout<<js[i]<<endl;
	for (int i=n-1;i>=1;i--) ans[i]+=ans[i+1];
	for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}

signed main(){
	string S;
	cin>>S;
	vint dp(13);
	dp[0]=1;
	rep(i,S.size()){
		vint dp2(13);
		rep(j,13){
			rep(k,10){
				if(S[i]!='?'&&S[i]-'0'!=k)continue;
				add(dp2[(j*10+k)%13],dp[j]);
			}
		}
		dp=dp2;
	}
	cout<<dp[5]<<endl;
	return 0;
}

Measured memory_bytes: 512
def main():
    N=int(input())
    if(N==1):
        print(1)
        return
    K=0
    L=2
    M=1
    for i in range(N-1):
        K=L+M
        L=M
        M=K
    print(K)

if(__name__=="__main__"):
    main()

Measured memory_bytes: 3060
cards = gets.split(' ').map!(&:to_i)
# i = 1
# max = 0
# a = cards[0] + cards[1]
# while i <= cards[0] && i <= cards[3]
#     max = max + 1
#     i = i + 1
# end
# while i <= cards[0] + cards[1] && i <= cards[3]
#     i = i + 1
# end
# while i <= cards[0] + cards[1] + cards[2] && i <= cards[3]
#     max = max - 1
#     i = i + 1
# end
case
when cards[3] <= cards[0]
    puts cards[3]
when cards[3] <= cards[0] + cards[1]
    puts cards[0]
else cards[3] > cards[0] + cards[1]
    puts (cards[0] - (cards[3] - cards[0] - cards[1]))
end

Measured memory_bytes: 14392
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ss = stoi(s);
  int n = 0;
  for (int i = 0; i < s.size(); i++) {
    n += s[i] - 48;
  }
  if (ss % n == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;

int a[N], p[N], m[N], v = 1;

void als(int i, int j) {
    i = i + v - 2;
    m[i] = j;
    while (i > 0) {
        i = (i - 1) / 2;
        m[i] = max(m[2*i + 1], m[2*i + 2]);
    }
}

int mx(int v, int vl, int vr, int l, int r) {
    if (l <= vl && vr <= r)
        return m[v];
    else if (vl >= r || l >= vr)
            return 0;
        else
            return max(mx(2*v + 1, vl, (vl + vr)/2, l, r), mx(2*v + 2, (vl + vr)/2, vr, l, r));
}

int main() {
    int i, j, n;
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    while (v < n) v *= 2;
    for (i = 1; i <= n; ++i) {
        cin >> a[i];
        p[a[i]] = i;
    }
    j = 1;
    int ans = 0;
    p[0] = 1e9;
    for (i = 1; i <= n; ++i) {
        if (p[i - 1] < p[i])
            j = m[i - 1] + 1;
        else
            j = 1;
        m[i] = j;
        ans = max(j, ans);
    }
    cout << n - ans;
}


Measured memory_bytes: 2560
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))


ans = 0
for i in range(n-1):
    sum = a[i] + a[i+1]
    if sum > x:
        ans += sum - x
        a[i+1] = max(0, a[i+1] - (sum - x))
print(ans)


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

#define rep(i, n) for(ll i=0; i<n; i++)
#define all(v) v.begin(), v.end()
#define vec vector

typedef long long ll;

/*  <<bit全探索>>

    for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
        bitset<ビット数> s(tmp);
    }
*/

/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>

    string str;
    int N[桁数];

    cin >> str;

    for (int i = 0; i < 15; ++i) {

        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換

        //cout << N[i] << endl;  //確認のため表示
    }
*/

int main(){

    int S, W;
    cin >> S >> W;
    if(S <= W){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
}

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

int main(){
	int n,k;
    cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++) cin>>A[i];
    sort(A,A+n);
    int l=0,r= k-1,df = INT_MAX;
    while(r < n){
    	df = min(df,(A[r]-A[l]));
        l++;
        r++;
    }
    cout<<df<<endl;
    
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e8+1, mod=1e9+7;

int power(int a,int n){
	if(n==0) return 1;
	ll x=power(a,n/2);
	x=(x*x)%mod;
	if(n&1) return (x*a)%mod;
	return x;
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,k; ll res=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){ 
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		int big=0,small=0;
		for(int j=0;j<n;j++){
			if(a[j]>a[i])big++;
			if(a[j]<a[i])small++;
		}
		ll temp = 1LL*small*( (1LL*k*(k-1)/2)%mod );
		res+=temp%mod;
		res%=mod;
	}
	int temp=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(a[i]<a[j]) temp++;
		}
	}
	res=(res+1LL*temp*k)%mod;
	
	cout<<res;
}
// check for any potential overflow before submitting



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int t,n,m;
int arr[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	ll fin=0;
	for(int i=1;i<=n;i++)
	{
		if(i%3==0) continue;
		if(i%5==0) continue;
		fin+=i;
	}
	cout<<fin<<endl;
	return 0;
}

Measured memory_bytes: 3660
import math

n = int(input())


a = [0] * n
b = [0] * n
for i in range(n):
      x, y = map(int, input().split())
      a[i] = x
      b[i] = y

ans = 0
tmp = 0
for i in range(n):
      if b[(n-1)-i] == 1:
            continue
      
      tmp = int(b[(n-1)-i]*math.ceil(a[(n-1)-i] / b[(n-1)-i])) - a[(n-1)-i]
      if ans > tmp:
            ans = int(math.ceil((ans - tmp) / b[(n-1)-i])) * b[(n-1)-i] + tmp
      else:
            ans += tmp - ans

      #print(ans)

print(ans)

Measured memory_bytes: 12916
// Problem : B - Between a and b ...
// Contest : AtCoder - AtCoder Beginner Contest 048
// URL : https://atcoder.jp/contests/abc048/tasks/abc048_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
signed main() { 
	ll a,b,x;
	cin>>a>>b>>x;
	cout<<b/x-a/x+(a%x==0);
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

using namespace std;

int main() {
	int a, b, q;
	string str, p, cmd;

	cin >> str >> q;
	for (int i = 0; i < q; ++i) {
		cin >> cmd >> a >> b;
		if (cmd[0] == 'p') {
			cout << str.substr(a, b - a + 1) << endl;
			continue;
		}
		if (cmd[2] == 'v') {
			reverse(&str[a], &str[b + 1]);
			//cout << "reverse=" << str << endl;
			continue;
		}
		cin >> p;
		str.replace(a, b - a + 1, p);
		//cout << "replace=" << str << endl;
	}

	return 0;
}


Measured memory_bytes: 3208
n=int(input())
x=sorted(list(map(int,input().split())))
mi=int(x[0])
ma=int(x[n-1])
l=[]
a=0
mp=999999
for i in range(mi,ma+1):
    for j in range(n):
        a+=(x[j]-i)**2
    if a<mp:
        mp=a
        a=0
print(mp)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

ll extgcd(ll a, ll b, ll &x, ll &y)
{ //extended Euclidean algorithm, used for modular multiplicative inverse
    ll d = a;
    if (b != 0)
    {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else
    {
        x = 1;
        y = 0;
    }
    return d; //return gcd(a,b)
}

ll mod_inv(ll a, ll m = MOD)
{ //return inv(a) mod m, ax+my=gcd(a,m)=1, m is prime int, ax-1=mq equiv. ax-mq=1
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m; //From (possibly) negative x to positive x
}

vector<ll> fact, invfact;
void calc_fact(int n, ll m = MOD)
{ //Calculate factorial up to n
    fact.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = invfact[0] = 1;
    REP(i, n)
    {
        fact[i + 1] = fact[i] * (i + 1) % m;
        invfact[i + 1] = invfact[i] * mod_inv(i + 1) % m;
    }
}
ll perm(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return fact[n] * invfact[n - k] % m;
}
ll comb(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return (fact[n] * invfact[n - k] % m) * invfact[k] % m;
}
template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}
vector<vector<int>> G(100005);
ll ans;
int n, k;

void dfs(int from, int now){
    int chival = 0;
    for (int elem : G[now])
    {
        if (elem != from){
            dfs(now, elem);
            chival++;
        }
    }
    if (chival > 0){
        if (now == 0)
        {
            ans = (ans * perm(k - 1, chival)) % MOD;
        }else
        {
            ans = (ans * perm(k - 2, chival)) % MOD;
        }
    }
}

int main()
{
    ciosup;
    cin >> n >> k;
    int a, b;
    REP(i,n-1){
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    cout << endl;
    calc_fact(k + 4);
    ans = k;
    dfs(-1, 0);
    cout << ans << endl;
}


Measured memory_bytes: 9216