akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<string, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

char judge(char a, char b){
    if((a == 'r' && b == 'b') || (a == 'b' && b == 'r')) return 'g';
    if((a == 'b' && b == 'g') || (a == 'g' && b == 'b')) return 'r';
    if((a == 'g' && b == 'r') || (a == 'r' && b == 'g')) return 'b';
}

int main(){
    while(1){
        string s; cin>>s;
        if(s == "0") return 0;

        queue<P> que;
        que.push(P(s, 0));
        map<string, bool> visited;
        visited[s] = true;
        bool isNA = true;
        while(que.size()){
            string t;
            int cnt;
            tie(t, cnt) = que.front();
            que.pop();

            bool valid = true;
            for(int i=0; i<t.size()-1; i++){
                if(t[i] != t[i+1]) valid = false;
            }

            if(valid){
                isNA = false;
                cout << cnt << endl;
                break;
            }

            for(int i=0; i<t.size()-1; i++){
                if(t[i] != t[i+1]){
                    string nt = t;
                    nt[i] = nt[i+1] = judge(t[i], t[i+1]);

                    if(!visited[nt]){
                        visited[nt] = true;
                        que.push(P(nt, cnt+1));
                    }
                }
            }
        }

        if(isNA){
            cout << "NA" << endl;
        }
    }
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

string z;
bool cz[400];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> z;
  debug(SZ(z));
  if(SZ(z) != 26){
    R(i,SZ(z)){
      cz[(int)z[i]] = 1;
    }
    for(int i = 'a'; ;i++){
      if(cz[i] == 0){
        z += char(i);
        cout << z << "\n";
        return 0;
      }
    }
  }
  debug("?");
  for(int i = SZ(z) - 1;i >= 0;i--){
    for(int j = z[i]; j <= 'z'; j++){
      if(cz[j] == 1){
        cout << z.substr(0,i) + char(j) << "\n";
        return 0;
      }
    }
    cz[(int)z[i]] = 1;
  }
  cout << "-1\n";
  
}


Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int aux = n; int sum = 0;
		while(aux > 0){
			sum += aux%10;
			aux/=10;
		}
		if(n % sum == 0) System.out.println("Yes");
		else System.out.println("No");
	}

}


Measured memory_bytes: 22868
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	double max, min,d;
	scanf("%lf", &d);
	max = min = d;
	while (~scanf("%lf", &d)) {
		if (d > max)max = d;
		else if (d < min) min = d;
	}
	printf("%lf\n", max - min);
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=500010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,qz[N],f[N];
struct Node
{
    int x,v;
}a[N];
int C;
signed main()
{
    n=read(), C=read();
    for(ri int i=1;i<=n;i++) a[i].x=read(), a[i].v=read();
    for(ri int i=1;i<=n;i++)
    {
        f[i]=f[i-1]-(a[i].x-a[i-1].x)+a[i].v;
        qz[i]=max(qz[i-1],f[i]);
    }
    int now=0;
    int ans=0;
    ans=max(ans,qz[n]);
    for(ri int i=n;i;i--)
    {
        int lst=(i==n)?C:a[i+1].x;
        now-=lst-a[i].x;
        now+=a[i].v;
        ans=max(ans,max(now-(C-a[i].x),0ll)+qz[i-1]);
    }
    memset(f,0,sizeof(f));
    memset(qz,0,sizeof(qz));
    for(ri int i=1;i<=n;i++) a[i].x=C-a[i].x;
    for(ri int i=1;i<=n;i++)
    {
        if(i<n-i+1) swap(a[i],a[n-i+1]);
    }
    for(ri int i=1;i<=n;i++)
    {
        f[i]=f[i-1]-(a[i].x-a[i-1].x)+a[i].v;
        qz[i]=max(qz[i-1],f[i]);
    }
    now=0;
    ans=max(ans,qz[n]);
    for(ri int i=n;i;i--)
    {
        int lst=(i==n)?C:a[i+1].x;
        now-=lst-a[i].x;
        now+=a[i].v;
        ans=max(ans,max(now-(C-a[i].x),0ll)+qz[i-1]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 13124
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
const int maxn = 200009;
const int mod = 998244353;
int64 T[maxn << 2], D[maxn], n, q, lz[maxn << 2], DD[maxn];

void upd(int rt, int l, int r, int ll, int rr, int v) {
  if (ll <= l && rr >= r) {
    lz[rt] = v;
    T[rt] = DD[r - l + 1] * D[n - r] % mod * v % mod;
    return;
  }
  int mid = (l + r) >> 1;
  if (lz[rt]) {
    lz[rt << 1] = lz[rt];
    lz[rt << 1 | 1] = lz[rt];
    T[rt << 1] = lz[rt] * DD[mid - l + 1] % mod * D[n - mid] % mod;
    T[rt << 1 | 1] = lz[rt] * DD[r - mid] % mod * D[n - r] % mod;
    lz[rt] = 0;
  }
  if (ll <= mid) upd(rt << 1, l, mid, ll, rr, v);
  if (rr > mid) upd(rt << 1 | 1, mid + 1, r, ll, rr, v);
  T[rt] = (T[rt << 1] + T[rt << 1 | 1]) % mod;
}
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  D[0] = 1;
  for (int i = 1; i < maxn; ++i) D[i] = D[i - 1] * 10 % mod;
  DD[1] = 1;
  for (int i = 2; i < maxn; ++i) DD[i] = (DD[i - 1] * 10 + 1) % mod;
  cin >> n >> q;
  upd(1, 1, n, 1, n, 1);
  while (q--) {
    int l, r, v;
    cin >> l >> r >> v;
    upd(1, 1, n, l, r, v);
    cout << T[1] << '\n';
  }

  return 0;
}
//2020.09.26 20:15:23


Measured memory_bytes: 14968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define st string
#define pairi pair<int,int>
#define INF 1000000007
int connected=0, temp1, temp2,n, p,nodes=0;

void DFS(int start, vector<int> v[],vector<int> &visited) {
    visited[start] = 1;
    nodes++;
    for(int i= 0; i<v[start].size(); ++i) {        
    if(visited[v[start][i]] == 0)
        DFS(v[start][i], v, visited);        
    }    
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,e;cin>>n>>e;
    vector<int>v[n+1],visited(n+1,0);
		set<pair<int,int>> s;
   	for(int i=0;i<e;i++){
       int x,y;
      cin>>x>>y;
		 	v[x].push_back(y);
      v[y].push_back(x);
   	}
	 	for(int i=1;i<n+1;i++){
			auto ip = std::unique(v[i].begin(),v[i].end());
			v[i].resize(distance(v[i].begin(), ip)); 
		}
  connected = 0;
	int m=INT_MIN;
  for(int i=1;i<=n;++i) {
    if(visited[i] == 0 ) {
			nodes=0;
      connected++;
      DFS(i,v,visited);
    }  
		m=max(m,nodes);
    }
	cout<<m<<endl;
	return 0;
}

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

int d[] = {5,7,5,7,7};
signed
main(){
	int n;
	while(cin >> n && n!=0)
	{
			vector<int> w(n);
			for(int i=0;i<n;i++)
			{
					string s;
					cin >> s;
					w[i] = (int)s.size();
			}

			for(int i=0;i<n;i++)
			{
					int a[5] = {};
					int key = 0;
					bool flag = true;
					for(int j=i;j<n;j++)
					{
							if(key == 5){
									break;
							}
							a[key] += w[j];
							if(a[key] == d[key]){
									key++;
							}else if(a[key] < d[key]){

							}else if(a[key] > d[key]){
									flag = false;
									break;
							}
					}

					if(flag){
							cout << i+1 << endl;
							break;
					}
			}
	}
}


Measured memory_bytes: 3212
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	int n,k;
	cin >> n>>k ;

	int a[1005];

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

	sort(a,a+n);

	int co = 0;

	for (int i = 0; i < k; i++) {
		co += a[i];
	}

	cout << co;

	return 0;
}

Measured memory_bytes: 3636
<?php
    fscanf(STDIN, "%d %d", $n, $m);

    $cities = [];
    for ($i=0; $i < $m; $i++) { 
        list($prefecture, $year) = explode(" ", trim(fgets(STDIN)));
        $cities[$prefecture][$year] = $i;
    }

    // print_r($cities);
    $ans = [];
    foreach ($cities as $prefecture => $value) {
        ksort($value);
        $city = array_values($value);

        // print_r($value);

        $id = 1;
        foreach ($value as $y => $count) {
            $ans[$count]['prefecture']  = $prefecture;
            $ans[$count]['id'] = $id;
            $id++;
        }
    }
    // print_r($ans);

    ksort($ans);
    // print_r($ans);

    for ($i=0; $i < $m; $i++) { 
        echo str_pad($ans[$i]['prefecture'], 6, "0", STR_PAD_LEFT).str_pad($ans[$i]['id'], 6, "0", STR_PAD_LEFT)."\n";
    }

Measured memory_bytes: 90612
#include <bits/stdc++.h> 
#define int long long
#define deb(x) cout<<#x <<" = "<<x<<"\n";
using namespace std; 

signed main() 
{
	//freopen("input.txt", "r", stdin);
	
	int n; cin>>n;
	map<string, int> m;
	while(n--)
	{
		string s; cin>>s;
		m[s]++;
	}
	int maxi = 0;
	for(auto it : m)
		maxi = max(maxi, it.second);
	vector<string> v;
	for(auto it : m)
		if(it.second == maxi) v.push_back(it.first);
	sort(v.begin(), v.end());
	for(string x : v) cout << x <<"\n";
	
}

Measured memory_bytes: 26868
A,B,C,X,Y = map(int,input().split())
ans = list()
big = max(X,Y)

for i in range(big+1):
    x = X - i if X - i >= 0 else 0
    y = Y - i if Y - i >= 0 else 0 
    goukei = (A*x)+(B*y)+(C*i*2) 
    ans.append(goukei)
print(min(ans))

Measured memory_bytes: 7096
#include<stdio.h>

main(){
	int n, i;
	scanf("%d",&n);
	
	for(i=3;i<=n;i++){
		if(i%3==0||i%10==3||(i/10)%10==3||(i/100)%10==3||(i/1000)%10==3){
			printf(" %d",i);
		}
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Edge{
		int to;
		long cost;
		Edge(int to, long cost){
			this.to=to;
			this.cost=cost;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		ArrayList<ArrayList<Edge>> g = new ArrayList<ArrayList<Edge>>();
		int n = sc.nextInt();
		for(int i=0; i<n; i++) {
			g.add(new ArrayList<Edge>());
		}
		for(int i=0; i<n-1; i++) {
			int a=sc.nextInt(); a--;
			int b=sc.nextInt(); b--;
			long c=sc.nextLong();
			g.get(a).add(new Edge(b, c));
			g.get(b).add(new Edge(a, c));
		}

		long d[] = new long[n];
		boolean used[] = new boolean[n];
		int q = sc.nextInt();
		int k = sc.nextInt(); k--;

		ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
		stack.push(k);
		used[k]=true;
		d[k]=0;
		while(!stack.isEmpty()) {
			int u = stack.pop();
			for(Edge e : g.get(u)) {
				if(used[e.to]) continue;
				d[e.to]=d[u] + e.cost;
				used[e.to]=true;
				stack.push(e.to);
			}
		}

		for(int i=0; i<q; i++) {
			int x = sc.nextInt();x--;
			int y = sc.nextInt();y--;
			System.out.println(d[x]+d[y]);
		}
		sc.close();
	}

}


Measured memory_bytes: 182360
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int a[505][505],tot[105];
int n,m,all1 = 0,all2 = 0,all4 = 0;

void Init(){
	int sum = 0;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++) a[i][j] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(a[i][j] == 0) continue;
			sum = 0;
			if(a[i][j] == 1){
				sum++;
				a[i][j] = 0;
			}
			if(a[i][m - j + 1] == 1){
				sum++;
				a[i][m - j + 1] = 0;
			}
			if(a[n - i + 1][j] == 1){
				sum++;
				a[n - i + 1][j] = 0;
			}
			if(a[n - i + 1][m - j + 1] == 1){
				sum++;
				a[n - i + 1][m - j + 1] = 0;
			}
			if(sum == 1) ++all1;
			if(sum == 2) ++all2;
			if(sum == 4) ++all4;
		}
	}
}

int main(){
	scanf("%d %d",&n,&m);
	Init();
	memset(tot,0,sizeof(tot));
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			char x;
			scanf(" %c",&x);
			tot[x - '0']++;
		}
	}
	if(all4 > 0){
		for(int i = 'a' - '0';i <= 'z' - '0';i++){
			int sum = tot[i] / 4;
			if(all4 >= sum){
				all4 -= sum;
				tot[i] -= 4 * sum;
			}
			else{
				tot[i] -= 4 * all4;
				all4 = 0;
			}
			if(all4 == 0) break;
		}
		if(all4 != 0){
			printf("No");
			return 0;
		}
	}
	if(all2 > 0){
		for(int i = 'a' - '0';i <= 'z' - '0';i++){
			int sum = tot[i] / 2;
			if(all2 >= sum){
				all2 -= sum;
				tot[i] -= 2 * sum;
			}
			else{
				tot[i] -= 2 * all2;
				all2 = 0;
			}
			if(all2 == 0) break;
		}
		if(all2 != 0){
			printf("No");
			return 0;
		}
	}
	if(all1 > 0){
		for(int i = 'a' - '0';i <= 'z' -'0';i++){
			int sum = tot[i] / 1;
			if(all1 >= sum){
				all1 -= sum;
				tot[i] -= 1 * sum;
			}
			else{
				tot[i] -= 1 * all1;
				all1 = 0;
			}
			if(all1 == 0) break;
		}
		if(all1 != 0){
			printf("No");
			return 0;
		}
	}
	for(int i = 'a' - '0';i <= 'z' - '0';i++){
		if(tot[i] != 0){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(void){
    
    int i;
    char s[100001];
    
    scanf("%s",s);
    
    for(i=0;i<strlen(s);i=i+2) printf("%c",s[i]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define int ll
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const ll INF = 1e15 + 7;

int dp[26][26][101], dp1[105][26];
string s;

struct t{
	int a[26][26];
	t() {
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++)
				a[i][j] = INF;

	}
};

t f(int k) {
	if(k == 1) {
		t ret;
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++)
				ret.a[i][j] = dp[i][j][s.size()-1];
		return ret;
	}
	t tt = f(k/2);
	if(k & 1) {
		t ret, ttt;
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++)
				for(int kk=0;kk<26;kk++)
					for(int l=0;l<26;l++)
						if(j != kk) {
							ttt.a[i][l] = min(ttt.a[i][l], tt.a[i][j] + tt.a[kk][l]);
						}
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++)
				for(int kk=0;kk<26;kk++)
					for(int l=0;l<26;l++)if(j != kk) {
							ret.a[i][l] = min(ret.a[i][l], ttt.a[i][j] + dp[kk][l][s.size()-1]);
						}
		return ret;
	} else {
		t ret;
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++)
				for(int kk=0;kk<26;kk++)
					for(int l=0;l<26;l++)
						if(j != kk) {
							ret.a[i][l] = min(ret.a[i][l], tt.a[i][j] + tt.a[kk][l]);
						}
		return ret;
	}
}

int32_t main()
{
	IO_OP;
	
	int k;
	cin >> s >> k;
	if(s.size() == 1) {
		cout << k / 2 << endl;
		return 0;
	}
	if(s.size() == 2) {
		if(s[0] == s[1]) cout << k << endl;
		else cout << 0 << endl;
		return 0;
	}
	for(int i=0;i<26;i++)
		for(int j=0;j<26;j++)
			for(int k=0;k<101;k++)
				dp[i][j][k] = INF;
	for(int i=0;i<26;i++)
		dp[i][i][0] = 1;
	dp[s[0]-'a'][s[0]-'a'][0] = 0;
	for(int i=1;i<s.size();i++) {
		for(int j=0;j<26;j++) {
			for(int k=0;k<26;k++) {
				for(int l=0;l<26;l++) if(l != k)
					dp[j][k][i] = min(dp[j][k][i], dp[j][l][i-1] + (s[i]-'a' != k));
			}
		}
	}
	t res = f(k);
	int ans = INF;
	for(int i=0;i<26;i++)
		for(int j=0;j<26;j++)
			ans = min(ans, res.a[i][j]);
	cout << ans << endl;
}





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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  
  int leftBound = 1;
  int rightBound = n;
  for (int i = 1; i <= m; ++i) {
    int l, r;
    cin >> l >> r;
    leftBound = max(leftBound, l);
    rightBound = min(rightBound, r);
  }
  
  cout << max(rightBound - leftBound + 1, 0);
}

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

using namespace std;
typedef long long ll;
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main() {
    ll n, m, k;
    ll i, j, h;
    cin >> n;
    vector<ll> a(n),b(n);
    for(i=0;i<n;i++){
        cin >>a[i];
        b[i]=a[i];
    }
    sort(a.begin(),a.end());
    ll cnt=0;
    for(i=0;i<n;i++){
        if(a[i]!=b[i]){
            cnt++;
        }
    }
    if(cnt<=2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace abc124_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var s = Console.ReadLine().ToCharArray();

      var a = 0;
      var b = 0;

      for (var i = 0; i < s.Length; i++)
      {
        if (i % 2 == 0)
        {
          if (s[i] == '0')
          {
            a++;
          }
          else
          {
            b++;
          }
        }
        else
        {
          if (s[i] == '0')
          {
            b++;
          }
          else
          {
            a++;
          }
        }
      }

      Console.WriteLine(a < b ? a : b);
    }
  }
}

Measured memory_bytes: 11488
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

vector<ll>path[100010];
vector<ll>whgt[100010];
ll cost[100010];
int flg[100010];

int main(){

    int N;
    cin >> N;
    for(int i = 1; i < N; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        path[a].push_back(b);
        whgt[a].push_back(c);
        path[b].push_back(a);
        whgt[b].push_back(c);
    }
    int Q, K;
    cin >> Q >> K;
    queue<ll>que;
    que.push(K);
    flg[K] = 1;
    while(!que.empty()){
        int id = que.front();
        que.pop();
        for(int i = 0; i < path[id].size(); i++){
            int nxt = path[id][i];
            ll wht = whgt[id][i];
            if(flg[nxt])continue;
            flg[nxt] = 1;
            que.push(nxt);
            cost[nxt] = cost[id] + wht;
        }
    }
    for(int q = 0; q < Q; q++){
        int x, y;
        cin >> x >> y;
        cout << cost[x] + cost[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 15848
#include <iostream>
using namespace std;
int main() {
    int n;
    while (cin >> n && n) {
        int cnt = 0;
        for (int i=1; i<n; ++i) {
            int sum = 0;
            for (int j=i; j<n; ++j) {
                sum += j;
                if (sum == n) {
                    cnt ++;
                    break;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,m; cin>>n>>m;
    vector<ll> ans(n,-1);
    bool possible=true;
    rep(i,m){
        ll s,c; cin>>s>>c;
        if(ans[s-1]==-1 || ans[s-1]==c) ans[s-1]=c;
        else possible=false;
    }
    if(m==0 && n==1){
        cout<<0<<endl;
        return 0;
    }
    if(n==1 && ans[0]==0){
        cout<<0<<endl;
        return 0;
    }
    if(possible && ans[0]!=0){
        rep(i,n){
            if(ans[i]==-1){
                if(i==0) cout<<1;
                else cout<<0;
            }else{
                cout<<ans[i];
            }
        }
        cout<<endl;
    }else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
R = Hash.new {|h, k| h[k] = {}}
(N - 1).times do
  a, b, c = gets.split.map(&:to_i)
  R[a][b] = c
  R[b][a] = c
end

Q, K = gets.split.map(&:to_i)
D = []; D[K] = 0
U = []; U[K] = true

que = [K]
while x = que.shift
  R[x].each do |node, cost|
    next if U[node]
    D[node] = cost + D[x]
    U[node] = true
    que << node
  end
end

Q.times do
  x, y = gets.split.map(&:to_i)
  puts D[x] + D[y]
end


Measured memory_bytes: 47416
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n, k;
    int a[1005];
    int sum = 0; 
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    for(int i = 0; i < k; i++){
        sum += a[i];
    }
    cout << sum;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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 mxn = 2e5;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

ll iv[mxn + 1];
ll nck(int n, int k)
{
	// return f1[n] * f2[k] % M * f2[n - k] % M;
	ll ans = 1;
	for (int i = 1; i <= k; i++)
		ans = ans * (n - i + 1) % M * iv[i] % M;
	return ans;
}
int main()
{
	fast;
	iv[1] = 1;
	for (int i = 2; i <= mxn; ++i)
		iv[i] = M - M / i * iv[M % i] % M;
	// not possible, mxn exceeds 1e7/1e6
	// for (int i = 1; i <= mxn; ++i)
	// {
	// 	f1[i] = f1[i - 1] * i % M;
	// 	f2[i] = f2[i - 1] * iv[i] % M;
	// }
	int n, a, b;
	cin >> n >> a >> b;
	ll ans = pw(2, n);
	cout << (ans + 2 * M - nck(n, a) - nck(n, b) + M - 1) % M;
}

Measured memory_bytes: 5216
#! -*- coding:utf-8 -*-
n = int(input())
s1 = list(map(str,list(input())))
s2 = list(map(str,list(input())))

flag = 0
a = 0

x = 1
for i in range(n):
    if a == 1:
        a = 0
    elif flag == 0 and s1[i] == s2[i]:
        x *= 3
        flag = 1
    elif flag == 0 and s1[i] != s2[i]:
        x *= 3 * 2
        a = 1
        flag = 2
    elif flag == 1 and s1[i] == s2[i]:
        x *= 2
        flag = 1
    elif flag == 1 and s1[i] != s2[i]:
        x *= 2 * 1
        a = 1
        flag = 2
    elif flag == 2 and s1[i] == s2[i]:
        x *= 1
        flag = 1
    elif flag == 2 and s1[i] != s2[i]:
        x *= 3
        a = 1
        flag = 2
print(x%1000000007)


Measured memory_bytes: 3064
#include<stdio.h>
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int max(const int x,const int y){return y<x?x:y;}
int main()
{
  int N=IN(),M=IN(),K=IN(),i=0,j=0,count=0,A[200000],B[200000];long long sum=0;
  while(i<N){A[i++]=IN();}
  while(j<M){B[j]=IN();if(sum+B[j]>1ll*K){break;}sum+=B[j++];}
  count=j--;
  for(i=0;i<N;i++)
  {
    sum+=A[i];
    while(sum>K&&j>=0)sum-=B[j--];
    if(sum>K)break;
    count=max(count,i+j+2);
  }
  return printf("%d\n",count),0;
}

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

int main()
{
	char arr[6];
  	for(int i = 0; i < 6; i++)
    {
		cin>>arr[i];
    }
	if((arr[2] == arr[3]) && (arr[4] == arr[5]))
    {
		cout<<"Yes"<<endl;
    }
	else
    {
		cout<<"No"<<endl;
    }
  	return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  int X;
  cin >> X;
  int ans = 0;
  int n = 1;
  while(X > 0){
    ans++;
    X -= n;
    n++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# WAになったのでシンプルな愚直法で解き直し

K, S = map(int,input().split())

ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if (z >= 0) and (z <= K):
            ans += 1

print(str(ans))


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

int n;
vector<vector<int>> g;

vector<int> bfs(int s)
{
  vector<int> ret, par(n, -1);
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int crt = q.front();
    q.pop();
    for (int nxt : g[crt])
    {
      if (par[nxt] != -1)
        continue;
      par[nxt] = crt;
      q.push(nxt);
    }
  }
  if (par[s] == -1)
    return vector<int>(n + 1);
  ret.push_back(par[s] + 1);
  int p = par[s];
  while (p != s)
  {
    p = par[p];
    ret.push_back(p + 1);
  }
  return ret;
}

int main()
{
  int m;
  cin >> n >> m;
  g.resize(n);
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
  }
  vector<int> ans(n + 1);
  rep(i, n)
  {
    vector<int> tmp = bfs(i);
    if (tmp.size() < ans.size())
      ans.swap(tmp);
  }
  if (ans.size() == n + 1)
  {
    puts("-1");
    return 0;
  }
  printf("%d\n", ans.size());
  for (int i : ans)
    printf("%d\n", i);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define ll long long
vector<int>E[2005];
int a[2005],b[2005],n,c[5][2005],mp[2005];
void add(int i,int x,int fg)
{
	while(i<=n)
	{
		c[fg][i]+=x;
		i+=i&(-i);
	}
}
int query(int i,int fg)
{
	int res=0;
	while(i)
	{
		res+=c[fg][i];
		i-=i&(-i);
	}
	return res;
}
int Query(int L,int R,int fg)
{
	return query(R,fg)-query(L-1,fg);
}
int main(int argc, char** argv) {
	int k,q;
	cin>>n>>k>>q;
	rep(i,1,n)scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	int m=unique(b+1,b+n+1)-b-1;
	rep(i,1,n)
	{
		int w=lower_bound(b+1,b+m+1,a[i])-b;
		mp[w]=a[i];
		a[i]=w;	
		E[a[i]].pb(i);
	//	cout<<a[i]<<" "<<i<<endl;
	}
	int mn=1e9;
	rep(i,0,m-1)//最小值取i+1 
	{
		if(E[i].size())
		rep(j,0,E[i].size()-1)
		{
			add(E[i][j],1,1);
		}
		memset(c[2],0,sizeof(c[2]));
		memset(c[3],0,sizeof(c[3]));
		int now=i+1;
		int Q=q,mx=i+1;
		while(now<=m&&Q)
		{
			if(E[now].size())
			rep(j,0,E[now].size()-1)
			{
				//cout<<j<<" "<<now<<"???"<<endl;
				if(!Q)break;
				int l=1,r=E[now][j],L,R;
				while(l<=r)
				{
					int mid=(l+r)>>1;
					if(Query(mid,E[now][j],1)+Query(mid,E[now][j],2)==0)
					{
						L=mid;
						r=mid-1;
					}
					else l=mid+1;
				}
				l=E[now][j],r=n;
				while(l<=r)
				{
					int mid=(l+r)>>1;
					if(Query(E[now][j],mid,1)+Query(E[now][j],mid,2)==0)
					{
						R=mid;
						l=mid+1;
					}
					else r=mid-1;
				}
				if(R-L-Query(L,R,3)+1>=k)
				{
			//	if(i==0)	cout<<R<<" "<<L<<"   "<<now<<"   "<<E[now][j]<<" "<<i+1<<endl; 
					mx=now;
					add(E[now][j],1,3);
					Q--;
				}
				else
				{
					add(E[now][j],1,2);
				}
				///cout<<now<<" ?"<<endl;
			}
			now++;
		}
	//	cout<<mx<<" "<<(i+1)<<endl;
		if(Q==0)
		mn=min(mn,mp[mx]-mp[i+1]);
	}
	cout<<mn;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
//随着左端点单调向右，右端点也一定是单调向左
const int N = 3e5 + 9;
using ll = long long;
int n, m, w[N], q[N], t;
ll f[N], g[N], fy[N], gy[N], fT[N], ans[N], gT[N], dw[N];
 
template<class T> void Max (T &x, T y) { if (x < y) x = y; }
 
void Solve (int l, int r) {
	if (r == l) return Max(ans[l], f[l - 1] + g[l + 1] + 1 - w[l]);
	int mid = (l + r) >> 1;
	ll j;
	for (int i = l; i <= mid; ++i) {
		while (t > 1 && 1.0 * (fy[i] - fy[q[t]]) / (i - q[t]) >= 1.0 * (fy[q[t]] - fy[q[t - 1]]) / (q[t] - q[t - 1])) --t; q[++t] = i;
	}
	for (int i = mid + 1; i <= r; ++i) {
		while (t > 1 && 1.0 * (fy[q[t]] - fy[q[t - 1]]) / (q[t] - q[t - 1]) <= 2ll * i) --t;
//		j = -1e18; for (int t = l; t <= mid; ++t) Max(j, fy[t] - 2ll * i * t);
		j = fy[q[t]] - 2ll * i * q[t];
		(j += 1ll * i * i - fT[i] * 2 - i) >>= 1;
		dw[i] = j + g[i + 1];
	}
	for (int i = r; i > mid; --i) {
		if (i < min(n, r)) Max(dw[i], dw[i + 1]);
		Max(ans[i], dw[i]);
	}
	
	t = 0;
	for (int i = r; i > mid; --i) {
		while (t > 1 && 1.0 * (gy[i] - gy[q[t]]) / (i - q[t]) <= 1.0 * (gy[q[t]] - gy[q[t - 1]]) / (q[t] - q[t - 1])) --t; q[++t] = i;
	}
	for (int i = mid; i >= l; --i) {
		while (t > 1 && 1.0 * (gy[q[t]] - gy[q[t - 1]]) / (q[t] - q[t - 1]) >= -2ll * (n + 1 - i)) --t;
//		j = -1e18; for (int t = mid + 1; t <= r; ++t) Max(j, gy[t] - 2ll * (n + 1 - i) * (n + 1 - t));
		j = gy[q[t]] - 2ll * (n + 1 - i) * (n + 1 - q[t]);
		(j += 1ll * (n + 1 - i) * (n + 1 - i) - gT[i] * 2 - (n + 1 - i)) >>= 1;
		dw[i] = j + f[i - 1];
	}
	for (int i = l; i <= mid; ++i) {
		if (i > max(1, l)) Max(dw[i], dw[i - 1]);
		Max(ans[i], dw[i]);
		if (ans[7] == -4692)
		puts("A");
	}
	Solve(l, mid);
	Solve(mid + 1, r);
}
 
 
void Dp (ll *f, ll *y, ll *T) {
	for (int i = 1; i <= n; ++i) T[i] = T[i - 1] - 1 + w[i];
	q[t = 1] = 0;
	for (int i = 1; i <= n; ++i) {
		f[i] = -1e18;
//		for (int j = 0; j < i; ++j) Max(f[i], y[j] - 2ll * i * j);
		while (t > 1 && 1.0 * (y[q[t]] - y[q[t - 1]]) / (q[t] - q[t - 1]) <= 2ll * i) --t;
		f[i] = y[q[t]] - 2ll * i * q[t];
		(f[i] += 1ll * i * i - T[i] * 2 - i) >>= 1;
		Max(f[i], f[i - 1]);
		y[i] = f[i] * 2 + 1ll * i * i + i + T[i] * 2;
		while (t > 1 && 1.0 * (y[i] - y[q[t]]) / (i - q[t]) >= 1.0 * (y[q[t]] - y[q[t - 1]]) / (q[t] - q[t - 1])) --t; q[++t] = i;
	}
}
 
int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
	memset(ans, 0xc0, sizeof ans);
	Dp(f, fy, fT);
	reverse(w + 1, w + n + 1);
	Dp(g, gy, gT);
	reverse(w + 1, w + n + 1);
	reverse(gy + 1, gy + n + 1);
	reverse(g + 1, g + n + 1);
	reverse(gT + 1, gT + n + 1);
	Solve(0, n + 1);
	scanf("%d", &m);
	for (int i = 1, p, x; i <= m; ++i) {
		scanf("%d%d", &p, &x);
		printf("%lld\n", max(ans[p] + w[p] - x, f[p - 1] + g[p + 1]));
	}
	return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int p[1003];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void mer(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if(p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    pair<ll, pii> a[2020] = {};
    ll x, w = 0, q[2020] = {1};
    cin >> n >> m >> x;
    for (int i = 1; i <= m; i++) q[i] = q[i - 1] * 2 % mod;
    for (int i = 0; i < m; i++) cin >> a[i].second.first >> a[i].second.second >> a[i].first;
    sort(a, a + m);
    for (int i = 1; i <= n; i++) p[i] = -1;
    for (int i = 0; i < m; i++) {
        if (root(a[i].second.first) != root(a[i].second.second)) {
            w += a[i].first;
            mer(a[i].second.first, a[i].second.second);
        }
    }
    int u = 0, t = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 1; j <= n; j++) p[j] = -1;
        ll v = a[i].first;
        mer(a[i].second.first, a[i].second.second);
        for (int j = 0; j < m; j++) if (j != i) {
            if (root(a[j].second.first) != root(a[j].second.second)) {
                v += a[j].first;
                mer(a[j].second.first, a[j].second.second);
            }
        }
        if (v < x) u++;
        if (v == x) t++;
    }
    if (w == x) {
        cout << (q[t] - 2) * q[m - t] % mod;
    } else {
        cout << 2 * (q[t] - 1) * q[m - t - u] % mod;
    }
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];

    vector<vector<ll>> dp(n+1, vector<ll>(k+1, 0));
    rep(i, n+1) dp[i][0] = 1;
    rep(i, n){
        rep(j, k){
            dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j];
            dp[i+1][j+1] %= MOD;
            if(0<=j-a[i]){
                dp[i+1][j+1] += MOD-dp[i][j-a[i]];
                dp[i+1][j+1] %= MOD;
            }
        }
    }
    cout << dp[n][k] << endl;
}


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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == '1') ++counter;
    if (s[1] == '1') ++counter;
    if (s[2] == '1') ++counter;
    cout << counter << endl;
}


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

#define sz(s) (int)(s).size()
#define sqr(x) (x) * (x)
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define pi acis(-1)
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 1000000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	string s, x;
	cin >> s >> x;
	x.erase(x.size()-1, 1);
	if (s == x)
		cout << "Yes";
	else
		cout << "No";	
		
	




}



Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << "\n";
    } else {
        ll fives = 5;
        ll ret   = 0;
        while (fives <= n) {
            ret += n / (fives * 2);
            fives *= 5;
        }
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
($a,$b,$c,$d,$e,$f)=split(' ', <>);

for ($suma = 0; $suma <= 30; $suma += $a) {
    for ($sumb = $suma; $sumb <= 30; $sumb += $b) {
        $water{$sumb}++;
    }
}

$e30 = $e*30;

for ($sumc = 0; $sumc <= $e30; $sumc += $c) {
    for ($sumd = $sumc; $sumd <= $e30; $sumd += $d) {
        $suger{$sumd}++;
    }
}

$max = -1;
@water = sort{$a<=>$b}(keys %water);
@suger = sort{$a<=>$b}(keys %suger);
for $w (@water) {
    if ($w == 0) {
        next;
    }

    for $s (@suger) {
        if ($s > $w * $e ) {
            last;
        }
        ($s + $w*100 > $f)and last;
        if ($max < $s*100/$w) {
            $resw = $w;
            $ress = $s;
            $max = $s*100/$w;
        }
    }
}
printf("%d %d\n", $ress+$resw*100, $ress);

Measured memory_bytes: 1280
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main() {
	int N, sum = 0;
	int *l, *r;
	cin >> N;
	l = (int*)malloc(sizeof(int)*N);
	r = (int*)malloc(sizeof(int)*N);
	for (int i = 0;i < N;i++) {
		cin >> l[i] >> r[i];
	}
	for (int i = 0;i < N;i++) {
		sum += (r[i] - l[i] + 1);
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import math


A, B, N = MAP()


def f(x, A, B):
    return math.floor(A * x / B) - A * math.floor(x / B)


if N < B - 1:
    print(f(N, A, B))
else:
    print(f(B - 1, A, B))


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

int main() {
	double n, a[1001], ans=0;
	cin>>n; for(int i=0;i<n;i++) cin>>a[i];
	
	for(int i=0;i<n;i++) ans+=1/a[i];
	cout<<fixed;
	cout.precision(6);
	cout<<1/ans;
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c!='a' && c!='e' && c!='i' && c!='o' && c!='u') {
    cout << "consonant" << endl;
    return 0;
  }
  cout << "vowel" << endl;
  return 0;
}

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

int main() {
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k = 0;
  cin >> k;
  cout << a[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    ll n,m;cin>>n>>m;
    vector<ll> b(n);
    ll xx=-1;
    ll y;cin>>y;
    if(y%2==1){
        cout<<0<<endl;
        return 0;
    }
    b[0]=y/2;
    while(y>0){
        if(y%2==1){
            xx=b[0]*2/y;
            break;
        }
        y/=2;
    }
    for(int i=1;i<n;i++){
        ll x;cin>>x;
        if(x%2==1){
            cout<<0<<endl;
            return 0;
        }
        b[i]=x/2;
        if((x/xx)%2==0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll L=b[0];
    for(int i=1;i<n;i++){
        L=lcm(L,b[i]);
        if(L>m){
            cout<<0<<endl;
            return 0;
        }
    }
    m/=L;
    ll res=(m+1)/2;
    cout<<res<<endl;
}

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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define ll long long int
#define mod 1000000007

int n;

void solve()
{
    cin>>n;
    ll a[n];
    
    for(int i=0;i<n;i++)
        cin>>a[i];
    
    ll presum[n];
    presum[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        presum[i]=(presum[i+1]+a[i+1])%mod;;
    }
    
    ll ans = 0;
    
    for(int i=0;i<n;i++)
    {
        ans = (ans + (a[i]*presum[i])%mod)%mod;
    }
    
    cout<<ans;
}

int main()
{
    sync;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}







Measured memory_bytes: 6784
n=int(input())
s=input()
ans=0
for i in range(1000):
    num=str(i).zfill(3)
    if s.find(num[0])==-1:
        continue
    s1=s[s.find(num[0])+1:]
    if s1.find(num[1])==-1:
        continue
    s2=s1[s1.find(num[1])+1:]
    if s2.find(num[2])==-1:
        continue
    ans+=1
print(ans)

Measured memory_bytes: 42608
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int n,m,cnt,idx;
int dfn[100001];
vector<int> G[100001];
inline int Tjcv(int u,int fa)
{
	int child=0,lowu;
	lowu=dfn[u]=++idx;
	for(int i=0,v;i<G[u].size();i++)
	{
		v=G[u][i];
		if(v!=fa)
		{
			if(!dfn[v])
			{
				++child;
				int lowv=Tjcv(v,u);
				lowu=min(lowu,lowv);
				if(lowv>dfn[u])
				{
					++cnt;
				}
			}
			else
			{
				lowu=min(lowu,dfn[v]);
			}
		}
	}
	return lowu;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0,u,v;i<m;i++) 
	{
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++) 
	{
		if(!dfn[i])
		{
			Tjcv(i,-1);
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

int linearsearch(long T, long S[], int n){
    int i;
    for(i = 0; i < n; i++){
        if(S[i] == T) return 1;
    }
    return 0;
}

int main(){
    int n, q, ans = 0;
    scanf("%d", &n);
    long S[n];
    int i;
    for(i = 0; i < n; i++){
        scanf("%ld", &S[i]);
    }
    scanf("%d", &q);
    long T[q];
    for(i = 0; i < q; i++){
        scanf("%ld", &T[i]);
    }
    for(i = 0; i < q; i++){
        ans += linearsearch(T[i], S, n);
    }
    printf("%d\n", ans);
    return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





ll int arr[g_size];



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

	ll int n,m,T,res;

    ll int maxi=-mx,mini=mx,y=0,x,a=0;

	ll int i,j=-1,k;

	bool flag;

	string s1,s2;

	char s[100000];

	ll int ara[n_size],ara2[n_size];

	cin>>n;

	vll vec,v;


	f(i,0,n-1){
        cin>>m;
        vec.pb(m);
	}

    sort(vec.bb,vec.ee,greater<>());

//    f(i,0,n-1) cout<<vec[i]<<" ";
//    cout<<endl;

    res=0;
    x=1;
    y=0;
    a=0;

    f(i,1,n-1)
    {
        if(vec[i]==vec[i-1]){

            y++;

            if(y==3){
                cout<<arr[1]*arr[1]<<endl,exit(0);
            }

            if(arr[x-1]!=vec[i]){
                arr[x]=vec[i];
                x++;

                if(x==3) {
                    cout<<arr[1]*arr[2]<<endl,exit(0);
                }
            }

        }
        else y=0;
    }

    cout<<0<<endl;

}


Measured memory_bytes: 1400
# 2020/05/02
# AtCoder Beginner Contest 165 - D

# Input
a, b, n = map(int,input().split())

# Calc
if n >= b:
    ans = int(a * (b - 1) / b) - a * int((b-1) / b)
else:
    ans = int(a * n / b) - a * int(n / b)

# Output
print(ans)


Measured memory_bytes: 9172
def setmax(n,arr,ans)
  1.upto(n-1) do |ii|
    abs = arr[ii-1] - arr[ii]
    if abs > 0
      arr[ii] += arr[ii-1]
      ans.push([ii,ii+1])
    end
  end
end
def setmin(n,arr,ans)
  (n-2).downto(0) do |ii|
    abs = arr[ii] - arr[ii+1]
    if abs > 0
      arr[ii] += arr[ii+1]
      ans.push([ii+2,ii+1])
    end
  end
end
n = gets.chomp.to_i
arr = gets.chomp.split.map{ |item| item.to_i}
ans = []
min = arr.min
mini = arr.index(min)
max = arr.max
maxi = arr.index(max)
list = []
n.times do |i|
  list.push([i,arr[i]])
end
list.sort!{ |a,b| a[1] <=> b[1]}

if min >= 0
  setmax(n,arr,ans)
elsif max <= 0
  setmin(n,arr,ans)
else
  if (max.abs - min.abs) >= 0
    n.times do |ii|
      if arr [ii] <= 0
        jj = list.select{ |item| (item[1] + arr[ii]) >= 0}[0]
        arr[ii] += jj[1]
        ans.push([jj[0]+1,ii+1])
      end
    end
    setmax(n,arr,ans)
  else
    n.times do |ii|
      if arr [ii] >= 0
        jj = list.select{ |item| (item[1] + arr[ii]) <= 0}[-1]
        arr[ii] += jj[1]
        ans.push([jj[0]+1,ii+1])
      end
    end
    setmin(n,arr,ans)
  end
end
print ans.size,"\n"
ans.each do |one|
  print one[0]," ",one[1],"\n"
end


Measured memory_bytes: 1788
import java.util.Scanner;
import java.util.stream.LongStream;


public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)){
			int N = scanner.nextInt();
			long[] list = new long[N];
			for(int i=0;i<N;i++){
				list[i] = scanner.nextInt();
			}
			long min = LongStream.of(list).min().getAsLong();
			long max = LongStream.of(list).max().getAsLong();
			long sum = LongStream.of(list).sum();
			System.out.println(min+" "+max+" "+sum);
		}
	}
}

Measured memory_bytes: 47180