akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define SIZE 200000
typedef long long ll;
typedef pair<ll, ll>pii;
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	ll ren[SIZE];
	ll dp[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
ll da[101010], db[101010];
vector<int>pat[101010];
bool flag[101010];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	vector<pii>zat;
	for (int i = 0; i < num; i++)scanf("%lld%lld", &da[i], &db[i]), zat.push_back(make_pair(max(0LL, da[i] - db[i]), i));
	sort(zat.begin(), zat.end());
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	uf.init();
	for (int i = 0; i < num; i++)uf.ren[i] = db[i];
	for (int i = 0; i < num; i++)
	{
		ll mini = zat[i].first;
		int v = zat[i].second;
		for (int j = 0; j < pat[v].size(); j++)
		{
			if (!flag[pat[v][j]])continue;
			int w = uf.find(pat[v][j]);
			mini = min(mini, max(uf.dp[w], zat[i].first - uf.ren[w]));
		}
		flag[v] = true;
		for (int j = 0; j < pat[v].size(); j++)if (flag[pat[v][j]])uf.unite(v, pat[v][j]);
		uf.dp[uf.find(v)] = mini;
	}
	printf("%lld\n", uf.dp[uf.find(0)] + uf.ren[uf.find(0)]);
}

Measured memory_bytes: 13296
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
int main(){
  int a,b;
  cin>>a>>b;
  int s=0;
  FOR(i,1,b-a){
    s+=i;
  }
  cout<<s-a<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// return gcd(a,b)
long long gcd(long long a, long long b) {
    // O(log min(a,b))
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

    string S;
    cin >> S;

    int oc, zc;
    oc = zc = 0;

    for (auto i : S) {
        if (i == '1')
            oc++;
        else if (i == '0')
            zc++;
    }
    cout << min(oc, zc) * 2 << endl;

    return 0;
}


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

int R, G, B, N;
int main(){
    cin >> R >> G >> B >> N;
    int cnt = 0;
    for (int r = 0; (r <= N); r++){
        for (int g = 0; (g <= N - r); g++){
            int Bb = N - G * g - R * r;
            if (Bb % B == 0){
                int b = Bb / B;
                if (b < 0){
                    continue;
                }
                else{
                    // cout << r << " " << g << " " << b << endl;
                    cnt ++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif


void solve()
{
	int n ;
	cin >> n ;
	vector<int> dp(n+1, inf), a(n);
	for(auto &it : a) cin >> it; 
	dp[0] = 0 ;
	for(int i = 0 ; i < n ; ++i){
		if(i+1 < n)
			dp[i+1] = min(dp[i+1], dp[i] + abs(a[i+1] - a[i])) ;
		if(i+2 < n)
			dp[i+2] = min(dp[i+2], dp[i] + abs(a[i+2] - a[i])) ;
	} 
	cout << dp[n-1] << '\n' ;

}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

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

int main() {
  int N, A, c, cb, j;
  cb=100000000;
  cin >> N;
  
  for (int i=0; i<N; i++) {
    cin >> A;
    j=1;
    c=0;
   
    while (j==1) {
      if (A%2==0) {
        c++;
        A/=2;
        continue;
      }
      else {
        j=0;
      }
    }
    
    if (c<=cb) {
      cb=c;
    }
    else {
      continue;
    }
    
  }
  cout << cb << endl;
}
    

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var s = readLine()!!.toMutableList()
    var r = 0
    while(r == 0){
        s = s.dropLast(1).toMutableList()
        var l = s.count()
        var c = l /2
        if (s.slice(0 until c) == s.slice(c until l)) {
            r = l
        }
    }
    println(r)
}

Measured memory_bytes: 33792
from heapq import heapify, heappop, heappush
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)

BC = [tuple(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: x[1], reverse=True)

for i in range(m):
    for _ in range(BC[i][0]):
        min_num = heappop(A)
        if min_num < BC[i][1]:
            heappush(A, BC[i][1])
        else:
            heappush(A, min_num)
            break

total = sum(A)
print(total)


Measured memory_bytes: 22200
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] f = new int[N];
    for (int i = 0; i < N; i++) {
      int n = 0;
      for (int j = 0; j < 10; j++) {
        n = n << 1;
        n += scanner.nextInt();
      }
      f[i] = n;
    }
    int[][] p = new int[N][11];
    for (int i = 0; i < N; i++) for (int j = 0; j < 11; j++) p[i][j] = scanner.nextInt();

    int max = Integer.MIN_VALUE;
    for (int i = 1; i < 1 << 10; i++) {
      int b = 0;
      for (int j = 0; j < N; j++) b += p[j][Integer.bitCount(f[j] & i)];
      if (b > max) max = b;
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 27856
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
char a[N];

signed main()
{
	scanf("%s",a+1);
	int n=strlen(a+1);
	for (int i=1;i<=n;i++)
	if (a[i]=='?') putchar('D');
			  else putchar(a[i]);

	return 0;
}

Measured memory_bytes: 3908
# include <cstdio>

static const int maxn = 10000000 + 10;

struct Chain {
	int v, L, R;
} chain[maxn];

int n, cnt;

void _deleteLast() {
	// if (chain[1].L == 0) return;
	int d = chain[chain[1].L].L;
	chain[d].R = 1;
	chain[1].L = d;
}

void _deleteFirst() {
	// if (chain[0].R == 1) return;
	int d = chain[chain[0].R].R;
	chain[d].L = 0;
	chain[0].R = d;
}

void _insert(int x) {
	// printf("insert\n");
	int d = chain[0].R;
	chain[0].R = cnt;
	chain[cnt].v = x;
	chain[cnt].L = 0;
	chain[cnt].R = d;
	chain[d].L = cnt;
	cnt++;
}

void _delete(int x) {
	// printf("delete\n");
	int p = chain[0].R;
	while (chain[p].v != x) {
		p = chain[p].R;
		if (p == 1) return; // 测试例中有delete不存在值的操作
	}
	int pl = chain[p].L;
	int pr = chain[p].R;
	chain[pl].R = pr;
	chain[pr].L = pl;
}

int main() {
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	while (scanf("%d", &n) != EOF) {
		// 把chain[0]作为链头，把chain[1]作为链尾，cnt作为存储每一个链条
		chain[0].R = 1;
		chain[1].L = 0;
		cnt = 2;
		// cmd用来缓存命令
		char cmd[20];
		int x;
		for (int i = 0; i < n; i++) {
			scanf("%s", cmd);
			if (cmd[6] == '\0') {
				scanf("%d", &x);
				// printf("x is %d\n", x);
				if (cmd[0] == 'i')
					_insert(x);
				else
					_delete(x);
			} 
			else if (cmd[6] == 'F') {
				_deleteFirst();
			}
			else if (cmd[6] == 'L') {
				_deleteLast();
			}
		}
		int p = chain[0].R, first = 0;
		while (p != 1) {
			if (first != 0) {
				printf(" ");
			}
			printf("%d", chain[p].v);
			p = chain[p].R;
			first = 1;
		}
		printf("\n");
	}
	return 0;
}


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

bool isOK(int index, int key, vector<long long> &a){
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<long long> &a){
    
    int ng = -1;
    int ok = (int)a.size();
    
    while (abs(ok - ng) > 1){
        
        int mid = (ok + ng) / 2;
        
        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    
    return ok;
}


int main(){
    int n;
    cin >> n;
    
    vector<long long> a(n), b(n), c(n);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> b[i];
    rep(i, n)cin >> c[i];
    
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    
    
    long long ans = 0;
    
    rep(i, n){
        
        long long number_of_upper = binary_search(b[i], a);
        long long number_of_lower = n - binary_search(b[i]+1, c);
        //cout << number_of_upper << " " << number_of_lower << endl;
        ans += (number_of_upper) * number_of_lower;
    }
    
    cout << ans << endl;
    
}

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

int main()
{
  int a, b, m;
  cin >> a >> b >> m;
  
  vector<int> fridge(a);
  vector<int> washer(b);
  for (int i = 0; i < a; i ++)
    cin >> fridge.at(i);
  for (int j = 0; j < b; j ++)
    cin >> washer.at(j);
  
  int min_sum = 200001;
  int tmp_sum;
  
  // 割引券使用の場合を調べる
  int x, y, c;
  for (int i = 0; i < m; i ++)
  {
    cin >> x >> y >> c;
    tmp_sum = fridge.at(x - 1) + washer.at(y - 1) - c;
    if (tmp_sum < min_sum) min_sum = tmp_sum;
  }
  
  sort(fridge.begin(), fridge.end());
  sort(washer.begin(), washer.end());
  
  if (fridge.at(0) + washer.at(0) < min_sum) min_sum = fridge.at(0) + washer.at(0);
  
  cout << min_sum;
  
  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())

if N < 2 and M < 2:
    print(0)
    exit()

ans = 0

ans += N * (N - 1) // 2
ans += M * (M - 1) // 2
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
	String str = stdin.next();
	StringBuffer sb = new StringBuffer();
	for(int i = 0; i < str.length(); i++){
	    sb.append(str.charAt(str.length() - 1 - i));
	}
	System.out.println(sb.toString());
    }
}

Measured memory_bytes: 11000
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja
//Fibonacci Number
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll n; cin>>n;
    vector<ll> dp(max(n+1,2LL));
    dp[0]=1;
    dp[1]=1;    
    FOR(i,2,n+1){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n,ans=0;cin>>n;
  ll x=n/100;
  bool ok=false;
  if(n>=x*100&&n<=x*105){ok=true;}
  cout<<(ok?1:0)<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

int main()
{
    int N, W;
    std::cin >> N >> W;

    std::vector<ll> values(N);
    std::vector<ll> weight(N);
    for (auto i=0; i<N; ++i)
        std::cin >> weight[i] >> values[i];

    ll dp[N+1][W+1];
    memset(dp, 0, sizeof(dp));

    for (auto i=0; i<N; ++i)
    {
        for (auto w=0; w<=W; ++w)
        {
            // i+1 番目のブツを考慮するときの価値の最大
            if (weight[i] <= w)
                dp[i+1][w] = std::max(dp[i][w], dp[i][w - weight[i]] + values[i]);
            else
                dp[i+1][w] = dp[i][w];
        }
    }

    std::cout << dp[N][W] << std::endl;
}


Measured memory_bytes: 82396
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    int N,M;cin>>N>>M;
    string A[N],B[M];
    for(int i=0;i<N;i++) cin>>A[i];
    for(int i=0;i<M;i++) cin>>B[i];
    bool flag=false;
    for(int i=0;i<=N-M;i++){
        for(int j=0;j<=N-M;j++){
            bool flag2=true;
            for(int h=0;h<M;h++){
                for(int k=0;k<M;k++){
                    if(B[h][k]!=A[i+h][j+k]){
                        flag2=false;
                    }
                }
            }
            if(flag2) flag=true;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}





Measured memory_bytes: 256
'use strict'
function main (input) {
  input = input.split('\n')
  const troops = input[1].split('')
  const n = Number(input[0])
  let countsW = [0]
  for (let i = 1; i <= n; i++) {
    countsW[i] = (troops[i - 1] == 'W') ? countsW[i - 1] + 1 : countsW[i - 1]
  }
  let min, cnt = 0
  for (let i = 0; i < n; i++) {
    cnt = countsW[i]
    cnt += n - (i + 1) - (countsW[n] - countsW[i + 1])
    min = (min < cnt) ? min : cnt
  }
  console.log(min)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 18324
#include<math.h>

int main(){
	double xa,ya,xb,yb,xc,yc,xd,yd;
	
	while(0<=scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)){
		
	if(xc==xa){
	if((xd-xc)*(xb-xc)>0 || (ya-(yd-yb)/(xd-xb)*(xa-xb)-yb)*(yc-(yd-yb)/(xd-xb)*(xc-xb)-yb)>0){
		printf("NO\n");
		continue;
		}else{
			printf("YES\n");
			continue;
		}
		}
		if(xb==xd){
			if((xa-xb)*(xc-xb)>0 || (yb-(yc-ya)/(xc-xa)*(xb-xa)-ya)*(yd-(yc-ya)/(xc-xa)*(xd-xa)-ya)>0){
		printf("NO\n");
		continue;
		}else{
			printf("YES\n");
			continue;
		}
		}
	if((yb-(yc-ya)/(xc-xa)*(xb-xa)-ya)*(yd-(yc-ya)/(xc-xa)*(xd-xa)-ya)>0 || (ya-(yd-yb)/(xd-xb)*(xa-xb)-yb)*(yc-(yd-yb)/(xd-xb)*(xc-xb)-yb)>0){
		printf("NO\n");
		}else{
			printf("YES\n");
		}
		}
	return 0;
		}

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

int main(){
  ll n, k;
  cin >> n >> k;
  ll c = 200010;
  vector<ll> a(c, 0);
  ll kind = 0;
  vector<ll> syurui;
  rep(i, n) {
    ll x;
    cin >> x;
    if(a[x] == 0){
      kind++;
    }
    a[x]++;
  }
  rep(i, c) {
    if(a[i]) syurui.push_back(a[i]);
  }
  sort(syurui.begin(), syurui.end());
  ll ans = 0;
  int i = 0;
  while(kind > k) {
    kind --;
    ans += syurui[i];
    i++;
  }
  
cout << ans << endl;

}


Measured memory_bytes: 6672
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef long long LL;

typedef pair<LL, LL> LLLL;

int main(int argc, char* argv[]) {
	const LL INF = 1LL << 60;
	while (true) {
		int n = -1, m = -1, l = -1, q = -1, a, b, c, s, t;
		cin >> n >> m >> l;
		if (n <= 0) break;
		vector<vector<LL>> d(n, vector<LL>(n, INF));
		vector<vector<LL>> h(n, vector<LL>(n, INF));
		for (int i = 0; i < m; ++i) {
			cin >> a >> b >> c;
			d[a - 1][b - 1] = c;
			d[b - 1][a - 1] = c;
		}
		for (int i = 0; i < n; ++i) {
			h[i][i] = 0;
		}
		for (int k = 0; k < n; ++k) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
					if (d[i][j] <= l) {
						h[i][j] = 1;
					}
				}
			}
		}
		for (int k = 0; k < n; ++k) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					h[i][j] = min(h[i][j], h[i][k] + h[k][j]);
				}
			}
		}
		cin >> q;
		for (int i = 0; i < q; ++i) {
			cin >> s >> t;
			LL dist = h[s - 1][t - 1];
			cout << (dist < INF ? dist - 1 : -1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define no_of_test(x)        int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
//actual code is at the top 
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	no_of_test(x)
	{
      int n;
	  cin>>n;
	  map<string,int>mp;
	  for(int i=0;i<n;i++)
	  {
		  string s;
		  cin>>s;
		  mp[s]++;
	  }
	  int maxi=0;
	  for(auto x:mp)
	  {
		  if(x.second>maxi)
		  {
			  maxi=x.second;
		  }
	  }
	  for(auto x:mp)
	  {
		  if(maxi==x.second)
		  {
			  cout<<x.first<<'\n';
		  }
	  }
	}
	return 0;
}

Measured memory_bytes: 19300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

char fi[110][110];
 
int main(){
    int h,w;
    cin>>h>>w;

    rep(i,h){
        rep(j,w){
            cin>>fi[i][j];
        }
    }

    vector<int> hh,ww;

    rep(i,h){
        bool ok=true;
        rep(j,w){
            if(fi[i][j]=='#') ok=false;
        }
        if(ok) hh.push_back(i);
    }
    rep(j,w){
        bool ok=true;
        rep(i,h){
            if(fi[i][j]=='#') ok=false;
        }
        if(ok) ww.push_back(j);
    }

    rep(i,h){
        bool ok1=false;
        rep(j,w){
            bool ok=true;
            rep(k,hh.size()){
                if(hh[k]==i) ok=false;
            }
            rep(l,ww.size()){
                if(ww[l]==j) ok=false;
            }
            if(ok){
                cout<<fi[i][j];
                ok1=true;
            }
        }
        if(ok1) cout<<endl;
    }
}

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

int f(int n) {
	  int m = 0;
	    while (n) m += n % 10, n /= 10;
	      return m;
}

int main() {
	  int N;
	    cin >> N;
	      cout << ((N % f(N)) ? "No" : "Yes") << "\n";
}



Measured memory_bytes: 3592
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, r;
  while (cin >> n >> r, n) {
    vi v(n);
    rep(i, n) v[i] = n - i;
    rep(i, r) {
      int p, c;
      cin >> p >> c;
      vi w;
      w.reserve(c);
      for (int j = p - 1; j < p - 1 + c; j++) w.pb(v[j]);
      for (int j = p - 2; j >= 0; j--) v[j + c] = v[j];
      rep(j, w.size()) v[j] = w[j];
    }
    cout << v[0] << endl;
  }
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;
const lli MODC = 1000000007;

int main(){
    lli n, m;
    cin >> n >> m;
    if(n < m){
        lli tmp = n;
        n = m;
        m = tmp;
    }

    lli ans = 1;
    if(n == m + 1){
        for(lli i = n; i > 0; i--){
            if(i < n) ans = ((ans % MODC) * (i % MODC)) % MODC;
            ans = ((ans % MODC) * (i % MODC)) % MODC;
        }
    }else if(n == m){
        for(lli i = n; i > 0; i--){
            ans = ((ans % MODC) * (i % MODC)) % MODC;
            ans = ((ans % MODC) * (i % MODC)) % MODC;
        }
        ans = ((ans % MODC) * (2 % MODC)) % MODC;
    }else{
        ans = 0;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
string a,b,c;
cin>>a>>b>>c;
if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)){
    cout<<"YES"<<endl;
}else{
    cout<<"NO"<<endl;
}
}










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

int main(){
  int k=0;
  double a,high[10];
  while(cin>>high[k])
    k++;

  for(int j=0;j<k;j++)
    for(int i=0;i<k;i++)
      if(high[i]<high[i+1])
	swap(high[i],high[i+1]);

  for(int i=0;i<k;i++)
    a=high[0]-high[k-1];

    cout<<a<<endl;

  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;

int n,A,B,C;
int l[8];
int calc(int num, int a, int b, int c){
	if(num==n){
		if(a==0 || b==0 || c==0)return MAX;
		return abs(A-a)+abs(b-B)+abs(C-c)-30;
	}
	int w1=calc(num+1,a,b,c);
	int w2=calc(num+1,a+l[num],b,c)+10;
	int w3=calc(num+1,a,b+l[num],c)+10;
	int w4=calc(num+1,a,b,c+l[num])+10;
	if(w1<=w2 && w1<=w3 && w1<=w4)return w1;
	if(w2<=w1 && w2<=w3 && w2<=w4)return w2;
	if(w3<=w2 && w3<=w1 && w3<=w4)return w3;
	if(w4<=w2 && w4<=w3 && w4<=w1)return w4;
}

int main(void){
	cin>>n>>A>>B>>C;
	rep(i,n)cin>>l[i];
	cout<<calc(0,0,0,0)<<endl;

	return 0;

}


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

int main() {
    int t;
    string s, ans;

    cin >> s >> t;

    int cnt = t;

    for(int i = 0; i < s.size(); ++i) {
        if(cnt == t) {
            ans.push_back(s[i]);
            cnt = 0;
        }
        ++cnt;
    }

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

Measured memory_bytes: 256
// finish date: 2018/01/08
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <limits>
#include <map>

using namespace std;

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

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int main() {
    int N, H;
    cin >> N >> H;
    vector<int> a(N);
    vector<int> b(N);

    rep(i, N) cin >> a[i] >> b[i];
    int maxa = 0;
    rep(i, N) if (a[i] > maxa) maxa = a[i];
    int count = 0;
    sort(b.begin(), b.end(), greater<int>());
    rep(i, N) {
        if (b[i] > maxa) {
            H -= b[i];
            count++;
            if (H <= 0) {
                cout << count << endl;
                return 0;
            }
        }else{
            break;
        }
    }
    count += (H + maxa - 1) / maxa;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll C[100007];

int main() {
    ll A,B,K;cin >> A >>  B >> K;
    for(int i=A;i<=B;i++){
        if(i<A+K || i>B-K){
            cout << i <<  endl;
        }
    }
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll, ll> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	ll ans = 1e18;
	rep2(i, 1, 101){
		ll sm = 0;
		rep(j, n){
			sm += ((ll)a[j] - i) * (a[j] - i);
		}
		ans = min(ans, sm);
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int x,a,b;cin>>x>>a>>b;
    cout<<((abs(x-a)<abs(x-b))?"A":"B")<<endl;
}

Measured memory_bytes: 3576
n,m,x=map(int,input().split())
from itertools import product
li=[]
ans=10**9
for i in range(n):
    a=list(map(int,input().split()))
    li.append(a)
for p in product([0, 1], repeat = n):
    cnt = [0 for _ in range(m)]
    price=0
    for i in range(n):
        if p[i]==1:
            price+=li[i][0]
            for j in range(m):
                cnt[j]+=li[i][j+1]
    if min(cnt)>=x:
        ans=min(ans,price)
if ans==10**9:
    print("-1")
else:
    print(ans)




Measured memory_bytes: 9220
//config = {stdin: 'tmp', newline: '\r\n'}; // win
config = {stdin: '/dev/stdin', newline: '\n'}; // linux

line = require('fs').readFileSync(config.stdin, 'ascii')
       .split(config.newline, 2);

number = line[0].split(' ');

dice = { 'T': number[0], 'S': number[1], 'E': number[2],
         'W': number[3], 'N': number[4], 'B': number[5] };

function turn_east(dst, src) {
  dst.T = src.W; dst.S = src.S; dst.E = src.T;
  dst.W = src.B; dst.N = src.N; dst.B = src.E;
}
function turn_north(dst, src) {
  dst.T = src.S; dst.S = src.B; dst.E = src.E;
  dst.W = src.W; dst.N = src.T; dst.B = src.N;
}
function turn_south(dst, src) {
  dst.T = src.N; dst.S = src.T; dst.E = src.E;
  dst.W = src.W; dst.N = src.B; dst.B = src.S;
}
function turn_west(dst, src) {
  dst.T = src.E; dst.S = src.S; dst.E = src.B;
  dst.W = src.T; dst.N = src.N; dst.B = src.W;
}

inst = line[1];
src = {};
for (i in dice) src[i] = dice[i];
turn = {'E': turn_east, 'N': turn_north, 'S': turn_south, 'W': turn_west}
for (i in inst) {
  tmp = src;
  src = dice;
  dice = tmp;
  turn[inst[i]](dice, src);
}

console.log(dice.T);

Measured memory_bytes: 15500
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <set>
using namespace std;

#define MP make_pair

bool flag[53][53][4];

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

int main(){
	int n,x0,y0,t;
	cin >> n >> x0 >> y0 >> t;
	x0++;
	y0++;
	for(int k=0;k<n;k++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		a++;b++;c++;d++;
		if(a==c){
			if(b>d)swap(b,d);
			for(int i=b;i<d;i++){
				flag[a][i][0] = 1;
			}
			for(int i=d;i>b;i--){
				flag[a][i][2] = 1;
			}
		}
		if(b==d){
			if(a>c)swap(a,c);
			for(int i=a;i<c;i++){
				flag[i][b][1] = 1;
			}
			for(int i=c;i>a;i--){
				flag[i][b][3] = 1;
			}
		}
	}
	map<int,int> mp;
	int s = 0;
	for(int i=0;i<t;i++){
		int a;
		cin >> a;
		char b;
		cin >> b;
		s += a;
		if(b=='N'){
			mp[s] = 0;
		}else if(b=='E'){
			mp[s] = 1;
		}else if(b=='S'){
			mp[s] = 2;
		}else{
			mp[s] = 3;
		}
	}
	queue<pair<pair<int,int>,pair<int,int> > >q;
	map<pair<pair<int,int>,pair<int,int> >,bool> m;
	if(flag[x0][y0][0]==1){
		q.push(MP(MP(x0,y0),MP(0,0)));
	}
	if(flag[x0][y0][1]==1){
		q.push(MP(MP(x0,y0),MP(0,1)));
	}
	if(flag[x0][y0][2]==1){
		q.push(MP(MP(x0,y0),MP(0,2)));
	}
	if(flag[x0][y0][3]==1){
		q.push(MP(MP(x0,y0),MP(0,3)));
	}
	set<pair<int,int> > ans;
	while(1){
		auto x = q.front();
		q.pop();
		int a,b,c,d;
		a = x.first.first;
		b = x.first.second;
		c = x.second.first;
		d = x.second.second;
		//cout << a <<" " << b << " " <<c << " " << d << endl;
		if(c>s)break;
		if(c==s){
			ans.insert(MP(a-1,b-1));
		}
		if(mp.find(c+1)!=mp.end()){
			if(d==mp[c+1]){
				for(int i=0;i<4;i++){
					if(i!=d&&(i+4-d)%2==0)continue;
					if(flag[a+dx[d]][b+dy[d]][i]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]==0){
						m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]=1;
						q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,i)));
					}
				}
			}else{
				if((d+4-mp[c+1])%2!=0&&flag[a+dx[d]][b+dy[d]][mp[c+1]]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1]))]==0){
					m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1]))]=1;
					q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1])));
				}
			}
		}else{
			for(int i=0;i<4;i++){
				if(i!=d&&(i+4-d)%2==0)continue;
				if(flag[a+dx[d]][b+dy[d]][i]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]==0){
					m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]=1;
					q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,i)));
				}
			}
		}
	}
	for(auto x:ans){
		cout << x.first << " " << x.second << endl;
	}
	return 0;
}


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

int main()
{
    long long h;
    scanf("%lld", &h);
    long long qtd = 1;
    long long ans = 0;
    while(h > 0)
    {
        ans += qtd;
        h /= 2;
        qtd *= 2;
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main(){

    int a,b,c;

    cin >> a >>b >> c;

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

    

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll n, k;
  ll r, s, p;
  string t;
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
  t = t + string(n, 'x');
  // cout << t << endl;

  ll nr = 0;
  ll ns = 0;
  ll np = 0;
  vector<int> v(n + k, 0);
  for (ll i = 0; i < n; i++) {
    if (t[i] == 'r')
      nr++;
    if (t[i] == 's')
      ns++;
    if (t[i] == 'p')
      np++;
    if (t[i] == t[i + k]) {
      v[i] += 1;
      v[i + k] += 1;
    }
  }
  ll pmax = nr * p + ns * r + np * s;

  for(ll i=0; i<n; i++){
    if(v[i] == 2){
      v[i] = 0;
      v[i-k] = 0;
      v[i+k] = 0;
      if(t[i]=='r'){
        pmax = pmax - p;
      }else if(t[i]=='s'){
        pmax = pmax - r;
      }else{
        pmax = pmax - s;
      }
    }
  }
  for(ll i=0; i<n; i++){
    if(v[i] == 1){
      v[i] = 0;
      v[i+k] = 0;
      if(t[i]=='r'){
        pmax = pmax - p;
      }else if(t[i]=='s'){
        pmax = pmax - r;
      }else{
        pmax = pmax - s;
      }
    }
  }

  cout << pmax << endl;
  return 0;
}

Measured memory_bytes: 1312
import java.util.Scanner;

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

		for(int x=a; x<=b; x++){
			if(c%x==0){
				y++;
			}
		}
		System.out.println(y);
	}
} 

Measured memory_bytes: 17360
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[220000],i,acm,b[220000];
    while(~scanf("%d",&n))
    {
        acm=0;
        int sun=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i];
        }
        sort(b+1,b+n+1);
        acm=b[n];
        sun=b[n-1];
        for(i=1;i<=n;i++)
        {
            if(a[i]<acm)
                printf("%d\n",acm);
            else
                printf("%d\n",sun);
        }
    }
    return 0;
}


Measured memory_bytes: 3072
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}


#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n,ans=0;
    cin >> n;

    ll a=1, b=1;
    for(ll i=1; i<n; i++){
        ans += (n-1)/i;
    }
    
    cout << ans << endl;
 
    return 0;
}



Measured memory_bytes: 3648
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[401][401];
ll dp(int i,int j,const vector<ll>&A){
    if(i == j){
        return 0;
    }
    if(memo[i][j] != -1)
        return memo[i][j];
    ll res = 0;
    for(int k=i;k<j;k++){
        ll r = dp(i,k,A) + dp(k+1,j,A) + A[j] - ((i-1>=0)?A[i-1]:0);
        if(!res) res = r;
        else
        res = min(res,r);
    }
    memo[i][j] = res;
    return res;
}
int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);
    vector<ll>A(n+1);
    for(int i=0;i<n;i++){
        scanf("%lld",&A[i]);
    }
    for(int i=1;i<n;i++) A[i] = A[i-1] + A[i];
    memset(memo,-1,sizeof(memo));
    printf("%lld\n",dp(0,n-1,A));

	return 0;
}


Measured memory_bytes: 1536
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String w;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.w = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = "No";
        if (w.length() % 2 == 0) {
        	if (beautiful(w)) {
        		answer = "Yes";
        	}
        }
        
        return answer;
    }
    
    //美しい文字列か判定するメソッド
    private boolean beautiful(String w) {
    	boolean judge = true;
    	
    	//HashMapに単語とその登場回数を格納
    	HashMap<String,Integer> map = new HashMap<String,Integer>();
    	map.put(String.valueOf(w.charAt(0)), 1);
    	for (int i=1; i<w.length(); i++) {
    		int count = 1;
    		if (map.containsKey(String.valueOf(w.charAt(i)))) {
    			count += map.get(String.valueOf(w.charAt(i)));
    		}
    		map.put(String.valueOf(w.charAt(i)), count);
    	}
    	
    	//各文字の登場回数が偶数個か判定
    	for (int tmp : map.values()) {
    		if (tmp % 2 != 0) {
    			judge = false;
    			break;
    		}
    	}
    	
    	return judge;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35404
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 200010;
int n, a[N], p[N], f[N];

int main() 
{
	n = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, n) p[a[i]] = i;
    int ans = 1;
    rep(i, 1, n)
    {
        if (p[i] > p[i - 1]) f[i] = f[i - 1] + 1;
        else f[i] = 1;
        ans = max(ans, f[i]);
    }
    printf("%d\n", n - ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K, answer = LLONG_MAX;
  cin >> N >> K;
  pair<int,int> xy[N];
  for (int i = 0; i < N; i++) {
    cin >> xy[i].first >> xy[i].second;
  }
  sort(xy,xy+N);
  for (int i = 0; i < N; i++) {
    for (int j = i+K-1; j < N; j++) {
      int z[j-i+1];
      for (int k = i; k <= j; k++) {
        z[k-i] = xy[k].second;
      }
      sort(z,z+j-i+1);
      for (int k = 0; k+K-1 <= j-i; k++) {
        answer = min(answer,1ll*(xy[j].first-xy[i].first)*(z[k+K-1]-z[k]));
      }
    }
  }
  cout << answer;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

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

  int x = 0, ans = 0;
  REP(i, n){
    s[i] == 'I'? x++: x--;
    ans = max(ans, x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    ss = [list(input()) for _ in range(n)]

    ss_set = sorted(list(set(ss[0])))
    ans = ''

    for ch in ss_set:
        cnt = min(ss[i].count(ch) for i in range(n))
        ans += ch * cnt
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9084