akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}

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

    string s;
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;

    return 0;
}


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

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

  int l = 0;
  int r = 0;
  int t = 0;
  for (int i=0; i<n; i++) {
    if (s[i] == '(') {
      t++;
    } else {
      if (t > 0) t--;
      else l++;
    }
  }
  t = 0;
  for (int i=n-1; i>=0; i--) {
    if (s[i] == ')') {
      t++;
    } else {
      if (t > 0) t--;
      else r++;
    }
  }
  rep(i, l) cout << "(";
  cout << s;
  rep(i, r) cout << ")";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define ff first
#define ss second
#define dd double
#define mod 1000000007

template<class K,class other=null_type,class cmp=less<K>> using ordered_set=tree<K,other,
cmp, rb_tree_tag, tree_order_statistics_node_update>;

inline ll md(ll x){
    return x<mod?x:x%mod;
}

ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    ll x_=power(x,y/2);
    if(y & 1){
        return md(md(x_*x_)*md(x));
    }
    else{
        return md(x_*x_);
    }
}

ll mod_inverse(ll x){
    return power(x,mod-2);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    REP(i,n){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    ll ans=arr[n-1];
    ll j=n-3;
    ll i=n-2;
    while(j>=0){
        ans+=arr[i];
        j--;
        if(j<0) break;
        ans+=arr[i];
        j--;
        i--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5140
#include<stdio.h>
int selectionSort(int* ,int);
int main(){
  int array[100],num,kai,i;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&array[i]);
  }
  kai = selectionSort(array,num);
  for(i=0;i<num;i++){
    if(i!=0)printf(" ");
    printf("%d",array[i]);
  }
  printf("\n%d\n",kai);
  return 0;
}
int selectionSort(int*A,int N){
  int j,minj,dai,i,kai=0;
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j] < A[minj]){
	minj=j;
      }
    }
    dai=A[i];
    A[i]=A[minj];
    A[minj]=dai;
    if(dai!=A[i])kai++;
  }
  return kai;
}



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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
        swap(a, b);
    if (a == 1 && b == 2)
        OP(3);
    if (a == 1 && b == 3)
        OP(2);
    if (a == 2 && b == 3)
        OP(1);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	int pertama=a+b;
	
	int kedua=a-b;
	
	int ketiga=a*b;
	
	if(pertama>=kedua && pertama>=ketiga){
		
		printf("%d\n",pertama);
	}
	
	else if(kedua>=pertama && kedua>=ketiga){
		printf("%d\n",kedua);
	}
	
	else{
		printf("%d\n",ketiga);
	}
	
	return 0;	
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#include <complex>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

int dp[2][400][400];

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

	int n;
	while (cin >> n, n){
		vector<tuple<int, int, int>> v;
		rep(i, n){
			int a, b, c;
			cin >> a >> b >> c;
			v.push_back(MT(b, a, c));
		}
		sort(ALL(v));
		MEMSET(dp, 0);
		int cur = 0, nxt = 1;
		rep(i, n){
			int a, b, c;
			tie(b, a, c) = v[i];
			rep(j, 400) rep(k, 400){
				dp[nxt][j][k] = max(dp[nxt][j][k], dp[cur][j][k]);
				if (j < a) dp[nxt][b][k] = max(dp[nxt][b][k], dp[cur][j][k] + c);
				if (k < a) dp[nxt][j][b] = max(dp[nxt][j][b], dp[cur][j][k] + c);
			}
			swap(cur, nxt);
		}
		int ans = 0;
		rep(i, 400)rep(j, 400) ans = max(ans, dp[cur][i][j]);
		cout << ans << endl;
	}

	
	return 0;
}

Measured memory_bytes: 2480
import numpy as np

N,M,X = map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(N)])
c = 10**10

for i in range(2**N):
    C = np.array([0]*(M+1))
    for j in range(N):
        if ((i >> j) & 1):
            C += A[j]
    for j in range(1,M+1):
        if C[j] < X:
            break
    else:
        c = min(c,C[0])

if c == 10**10:
    print(-1)
else:
    print(c)

Measured memory_bytes: 27224
import sys
 
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
 
import numpy as np
 
N = int(readline())
A = np.array(readline().split(), dtype=np.int64)
B = np.array(readline().split(), dtype=np.int64)
 
diff = A-B
lack = -diff[diff<0]
remain = diff[diff>0]
 
x = lack.sum()
remain.sort()
cum = remain[::-1].cumsum()
 
y = 0 if x == 0 else np.searchsorted(cum,x) + 1
 
answer = len(lack) + y if y <= len(remain) else -1
print(answer)

Measured memory_bytes: 35020
import sys

input = sys.stdin.readline
D = {}
for _ in range(int(input())):
    d = {}
    for s in sorted(input().rstrip()):
        if s in d:
            d[s] += 1
        else:
            d[s] = 1
    ds = "".join((k + str(v)) for k, v in d.items())
    if ds in D:
        D[ds] += 1
    else:
        D[ds] = 1

print(sum((v * (v - 1)) // 2 for v in D.values()))



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

const int MAX_N = 100;

int N, K;
int X[MAX_N];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        scanf("%d", X + i);
    }
    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < N; i++) {
        if (X[i] < K - X[i]) {
            tmp = X[i];
        } else {
            tmp = K - X[i];
        }
        ans += tmp;
    }
    cout << ans * 2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c)
		cout<<"1";
	if((a!=b&&b==c)||(a==b&&b!=c)||(a==c&&c!=b))
		cout<<"2";
	if(a!=b&&b!=c&&c!=a)
		cout<<"3";
	return 0;
}



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

using namespace std;
int n;
long long ans;
string s;
map<pair<string,string>,int> f;
string og(string v)
{
    string w;
    w=v;
    for(int l=0;l<w.size()/2;l++)
        swap(w[l],w[w.size()-l-1]);
    return w;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    cin>>s;
    int m=n;
    for(int i=0;i<(1<<m);i++)
    {
        string s1,s2;
        s1="";
        s2="";
        for(int j=0;j<m;j++)
        {
            if((i>>j)&1)
                s1.push_back(s[j]);
            else
                s2.push_back(s[j]);
        }
        f[{s1,s2}]++;
    }
    for(int i=0;i<(1<<m);i++)
    {
        string s1,s2;
        s1="";
        s2="";
        for(int j=0;j<m;j++)
        {
            if((i>>j)&1)
                s1.push_back(s[j+m]);
            else
                s2.push_back(s[j+m]);
        }
        s1=og(s1);
        s2=og(s2);
        if(f.count({s2,s1})!=0)
            ans+=f[{s2,s1}];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 46080
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int main(){
    ll N,K,h[100010];
    ll ans=LLINF;
    cin >>N>>K;
    rep(i,N) cin>>h[i];
    sort(h,h+N);
    for(int i=0;i<N-K+1;i++){
        ans =min(ans,h[i+K-1]-h[i]);
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

int main(){
  ll r;
  cin>>r;
  cout<<3*r*r;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 20000

typedef struct {
    int map;
	int eq;
}area;

int s1[N];
area s2[N];
int top1=0, top2=0;

void push1(int x);
int pop1();
void push2(int x, int add);
area pop2();

int main(void){
	char a[N];
	int j, i, n, add=0;
	int sum=0;//全合計
	
	scanf(" %s", a);
	
	n=strlen(a);
	
	for(i=0; i<n; i++){
		if(a[i]=='\\') {
			push1(i);//i入れる
		}
		else if(a[i]=='/' && 0<top1) {
			j=pop1();//終わり
			add=i-j;//今-相当するとこ
			sum+=add;
			while(j < s2[top2-1].map && 0<top2){
				add+= pop2().eq;
			}
			push2(j, add);
		}
	}
	
    printf("%d\n", sum);
	printf("%d", top2);
	for(i=0 ; i<top2 ; i++){
		printf(" %d", s2[i].eq);
	}
	printf("\n");
	return 0;
}



void push1(int x){
    s1[top1]=x;
    top1++;
}

int pop1(){
    top1--;
    return s1[top1];
}

/*個々*/
void push2(int x, int add){
    s2[top2].map = x;
    s2[top2].eq = add;
    top2++;
}

area pop2(){
    top2--;
    return s2[top2];
}



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

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] and s[4]==s[5]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 2; i * i <= N; i++) {
        if(N % i != 0) continue;
        ll num = 0;
        while(N % i == 0) {
            N /= i;
            num++;
        }
        for(ll j = 1; ; j++) {
            if(num >= j) {
                num -= j;
                ans++;
            } else break;
        }
    }
    if(N != 1) ans++;
    cout << ans << endl;
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String str = br.readLine();
		int sum = 0;
			for(int i = 0 ; i < str.length() ; i++){
				sum += str.charAt(i) == '1' ? 1 : 0;
			}
			System.out.println(sum);
			
	}
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var P = int.Parse(Console.ReadLine().Split().Aggregate((s, t) => s += t));
            var Q = int.Parse(Console.ReadLine().Split().Aggregate((s, t) => s += t));

            var baseArray = Enumerable.Range(1, N).ToArray();
            var list = new List<int>();
            SetList(0, N, baseArray, new int[N], list);
            var dict = list.Select((s, i) => new { Key = s, Value = i }).ToDictionary(s => s.Key, s => s.Value);

            Console.WriteLine(Math.Abs(dict[P] - dict[Q]));
        }

        static void SetList(int i, int N, int[] baseArray, int[] array, List<int> list)
        {
            if (i == N)
            {
                list.Add(int.Parse(array.Select(s => s.ToString()).Aggregate((s, t) => s += t)));
                return;
            }

            foreach (var j in baseArray.Except(array))
            {
                var copy = Copy(array);
                copy[i] = j;
                SetList(i + 1, N, baseArray, copy, list);
            }
        }

        static int[] Copy(int[] x)
        {
            var ret = new int[x.Length];
            Array.Copy(x, ret, x.Length);
            return ret;
        }
    }
}

Measured memory_bytes: 20504
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  long long N;
  cin >> N;
  long long ans;
  ans = N * (N-1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

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

    int d, t, s;

    cin>>d>>t>>s;

    if(t * s >= d) {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author NMouad21
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    AFrog1 solver = new AFrog1();
    solver.solve(1, in, out);
    out.close();
  }

  static class AFrog1 {
    public final void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int[] h = in.nextIntArray(n);
      int[] dp = new int[n];
      for (int i = 1; i < n; i++) {
        dp[i] = Math.abs(h[i] - h[i - 1]) + dp[i - 1];
        if (i - 2 >= 0) {
          dp[i] = Math.min(dp[i], Math.abs(h[i] - h[i - 2]) + dp[i - 2]);
        }
      }
      out.println(dp[n - 1]);
    }
  }

  static final class InputReader {
    private final InputStream stream;
    private final byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader() {
      this.stream = System.in;
    }

    public InputReader(final InputStream stream) {
      this.stream = stream;
    }

    private final int read() {
      if (this.numChars == -1) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return -1;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public final int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {}

      byte sgn = 1;
      if (c == 45) { // 45 == '-'
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
        res *= 10;
        res += c - 48; // 48 == '0'
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    private static final boolean isSpaceChar(final int c) {
      return c == 32 || c == 10 || c == 13 || c == 9
          || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t'
    }

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


Measured memory_bytes: 21460
data = []
i = 0
while n = gets
  data[i] = n.chomp.to_i
  i+=1
end

b = 0

for a in 0..i-2
  for b in 0..i-2
    if data[b] < data[b+1]
      data[b],data[b+1] = data[b+1],data[b]
    end
  end
end

for i in 0..2
  puts data[i]
end


Measured memory_bytes: 6876
import math
pi=math.pi
def cal_h_hand_arg(h,m):
  arg=2*pi*h/12.0+2*pi*(1/12.0)*(m/60.0)
  return arg
def cal_m_hand_arg(m):
  arg=2*pi*(m/60)
  return arg

A,B,H,M=map(float,input().split())
h_arg=cal_h_hand_arg(H,M)
m_arg=cal_m_hand_arg(M)
diff_arg=abs(h_arg-m_arg)
if diff_arg > pi:
  diff_arg=2*pi-diff_arg
ans=A**2+B**2-2*A*B*math.cos(diff_arg)
print(math.sqrt(ans))

Measured memory_bytes: 9460
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }
    let ans = if s == "AAA" || s == "BBB" {
        "No"
    } else {
        "Yes"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        String[] second = br.readLine().split(" ", 2);
        int a = Integer.parseInt(second[0]);
        int b = Integer.parseInt(second[1]);
        String third = br.readLine();
        if (third.equals(first[0])) {
            a--;
        } else {
            b--;
        }
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 22228
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
vector<int> G[100000];
vector<int> C[100000];
int n; bool used[100000];
int dfs(int k) {
	int res = 0;
	int len = G[k].size();
	rep(i, len) {
		int v = G[k][i];
		res ^= dfs(v)+1;
	}
	return res;
}
int main() {
	cin >> n;
	rep(i, n - 1) {
		int x, y; cin >> x >> y; x--; y--;
		C[x].push_back(y);
		C[y].push_back(x);
	}
	fill(used, used + n, false);
	queue<int> q; q.push(0); used[0] = true;
	while (!q.empty()) {
		int x = q.front(); q.pop();
		int len = C[x].size();
		rep(i, len) {
			int v = C[x][i];
			if (used[v])continue;
			used[v] = true; q.push(v); G[x].push_back(v);
		}
	}
	if (dfs(0))cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int T,A,B;
  cin >> T >> A >> B;
  if( A * T > B ){
  	cout << B << endl;
  }else if(A * T < B){
  	cout << A * T << endl;
  }else{
  	cout << A * T << endl;
  }
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B = LI()

    ans = max(A + B, A - B, A * B)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		long cnt = 0;
		for(long i = 1; i <= N; i++)
		{
			long num = N / i;
			cnt += num * (num + 1) / 2 * i;
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 27564
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n, k;
	string s;
	cin >> n >> k >> s;
	int best = 0;
	for (char c : string("LR")) {
		string t = s;
		for (int i = 0, m = k; i < n && m > 0; i++) {
			if (t[i] == c) continue;
			t[i] = c;
			if (i == n-1 || t[i+1] == c) --m;
		}

		int ans = 0, prev = 0;
		for (int i = 1; i < n; i++) {
			if (t[i] != t[prev]) {
				ans += i - prev - 1;
				prev = i;
			}
		}
		ans += n - prev - 1;
		best = max(best, ans);
	}
	cout << best << endl;
}


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

bool a[1000001] ;
int main(){
    a[0] = 1 ;
    a[1] = 1 ;
    vector<int> v ;
    for(int i=2;i<=1000000;i++){
        if ( a[i] == 0 ){
            v.push_back(i);
            for(int j=i+i;j<=1000000;j+=i){
                a[j] = 1 ;
            }
        }
    }

    int x ;
    while(cin >> x){
        long long c = 0 ;
        for(int i=0;i<v.size();i++){
            if ( v[i] > x ) break;
            c++;
        }
        cout << c << endl;
    }



    return 0 ;
}



Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(20)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  string S; cin >> S;
  const int N = S.size();
  int left[500010] = {}, right[500010] = {};
  int cnt = 0;
  REP(i, N){
    if(S[i] == '<') cnt++;
    else cnt = 0;
    left[i+1] = cnt;
  }
  cnt = 0;
  RREP(i, N){
    if(S[i] == '>') cnt++;
    else cnt = 0;
    right[i] = cnt;
  }
  int ans = 0;
  REP(i, N+1){
    ans += max(left[i], right[i]);
  }
  cout << ans << endl;
}

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

using namespace std;

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

  int n, k;
  cin >> n>>k;
  if (n%k == 0) {
    cout << "0\n";
  } else{
    cout << "1\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<vector<int>> a(1111, vector<int>(1111, -INF));
int h, w;
int ans = 0;
deque<pair<int, int>> q;

void dbg()
{
    FOR(i, 1, h + 1) {
        FOR(j, 1, w + 1) {
            cout<<(a[i][j] == -INF ? '.' : '#');
        }
        cout<<endl;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>h>>w;
    REP(i,h) {
        REP(j,w) {
            char c;
            cin>>c;
            if (c == '#') {
                a[i+1][j+1] = 0;
                q.push_back({i+1, j+1});
            }
        }
    }
    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop_front();
        if (x != 1 && a[x-1][y] == -INF) {
            a[x-1][y] = a[x][y] + 1;
            ans = max(ans, a[x-1][y]);
            q.push_back({x-1, y});
        }
        if (x != h && a[x+1][y] == -INF) {
            a[x+1][y] = a[x][y] + 1;
            ans = max(ans, a[x+1][y]);
            q.push_back({x+1, y});
        }
        if (y != 1 && a[x][y-1] == -INF) {
            a[x][y-1] = a[x][y] + 1;
            ans = max(ans, a[x][y-1]);
            q.push_back({x, y-1});
        }
        if (y != w && a[x][y+1] == -INF) {
            a[x][y+1] = a[x][y] + 1;
            ans = max(ans, a[x][y+1]);
            q.push_back({x, y+1});
        }
        //dbg();
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 13328
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int main(){
    ll x;cin>>x;
    ll res = 1000*(x/500);
    x %= 500;
    res += 5*(x/5);
    cout<<res;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll>a(n);
	rep(i, n) {
		ll buffer;
		cin >> buffer;
		buffer--;
		a[i] = buffer;
	}
	ll c(0);
	ll x = 0;
	bool ok = false;
	vector<ll>xx(n);
	vector<ll>b(n);
	ll cc(0);
	while (1) {
		
		if (b[x] != 0) {
			break;
		}
		xx[cc] = x;
		b[x] += 1;
		x = a[x];
		++c;
		if (c >= k) {
			ok = true;
			break;
		}
		++cc;

	}
	ll ans = 0;
	ll q;
	if (ok) {
		cout << x+1;
		return 0;
	}
	else {
		rep(i, xx.size()) {
			if (xx[i] == x) {
				q = i;
				break;
			}
		}
	
		ll d = cc - q;
		k = k - (q-1);
		k = k % d;

		if (k == 0) {
			k = d;
		}
		cout << xx[q + k - 1]+1 << endl;;
	}

	return 0;
}

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

    divisors.sort()
    return divisors


n=int(input())
l=make_divisors(n)
ans=1<<40
for i in range(len(l)//2+1):
    ans=min(ans,l[i]-1+n//l[i]-1)
print(ans)


Measured memory_bytes: 38980
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, M = MI()

    routes = []

    cities = [[] for i in range(N)]

    for i in range(M):
        a, b = MI()
        cities[a-1].append(b-1)
        cities[b-1].append(a-1)

    groups = [-1] * N

    group = 0

    for i in range(N):
        if groups[i] != -1:
            continue
        deque = cl.deque([i])
        groups[i] = group
        while len(deque) > 0:
            city = deque.popleft()
            next_cities = cities[city]
            for next_city in next_cities:
                if groups[next_city] != -1:
                    continue
                groups[next_city] = group
                deque.append(next_city)

        group += 1

    print(group - 1)


main()


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

int main(){ 
    int n;
    cin >> n;
    int a[n+1]={0};
    for(int i = 1 ; i<=n ; i++){
       cin >> a[i];
   }
   int b[n+1]={0};
   for(int i = 1 ; i<=n ; i++){
       b[a[i]] = i;
   }
   
   for(int i = 1; i<= n; i++){
   cout << b[i] << " ";
   }
   return 0;
}

Measured memory_bytes: 1536
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,h,w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main() {
    int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
    int x=tx-sx;
    int y=ty-sy;
    rep(i,y) cout<<"U";
    rep(i,x) cout<<"R";
    rep(i,y) cout<<"D";
    rep(i,x) cout<<"L";
    cout<<"L";
    rep(i,y+1) cout<<"U";
    rep(i,x+1) cout<<"R";
    cout<<"D"<<"R";
    rep(i,y+1) cout<<"D";
    rep(i,x+1) cout<<"L";
    cout<<"U";
    cout<<endl;
}

Measured memory_bytes: 256
#line 1 "dijkstra.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp"
#line 1 "../../lib/graph/dijkstra.hpp"
#include <climits>
#include <limits>
#include <queue>
#include <vector>

#ifndef DIJKSTRA
#define DIJKSTRA

template <class T> struct edge {
  int to;
  T cost;
};

// sからの各頂点への最短距離をdに格納して返す。計算量はO(E logV)
template <class T> void dijkstra(const int s, const std::vector<std::vector<edge<T>>> &g, std::vector<T> &d) {
  std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> q;

  constexpr T MAX = std::numeric_limits<T>::max();

  for (auto &di : d) {
    di = MAX;
  }
  d[s] = 0;
  q.push(std::make_pair(d[s], s));

  while (!q.empty()) {
    const auto p = q.top();
    q.pop();

    const int v = p.second;
    if (d[v] < p.first)
      continue;

    for (const auto e : g[v]) {
      const int u = e.to;
      const T next_cost = d[v] + e.cost;
      if (d[u] <= next_cost)
        continue;
      d[u] = next_cost;
      q.push(std::make_pair(d[u], u));
    }
  }
}

#endif
#line 3 "dijkstra.test.cpp"
#include <climits>
#include <iostream>
#include <vector>

int main() {
  int v, e, r;
  std::cin >> v >> e >> r;

  std::vector<std::vector<edge<int>>> g(v);

  for (int i = 0; i < e; i++) {
    int s, t, d;
    std::cin >> s >> t >> d;
    g[s].push_back({t, d});
  }

  std::vector<int> ans(v);
  dijkstra(r, g, ans);

  for (int i = 0; i < v; i++) {
    if (ans[i] == INT_MAX) {
      std::cout << "INF" << std::endl;
    } else {
      std::cout << ans[i] << std::endl;
    }
  }
}



Measured memory_bytes: 12900
// AGC021
// A - Digit Sum 2

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_K = 16;

ll N;
int d[MAX_K + 1];

int solve() {
    int L = 0;
    for (ll i = 0, t = 1; i <= MAX_K; i++, t *= 10) {
        d[i] = N / t % 10;
        if (d[i] != 0) {
            L = i + 1;
        }
    }

    int pos_l = -1, pos_r = -1;
    int s = 0;
    for (int i = 0; i < L; i++) {
        if (d[i] == 9) {
            if (pos_r == i - 1) {
                pos_r = i;
            }
        } else {
            pos_l = i;
        }
        s += d[i];
    }

    if (pos_l == -1 || (pos_l == L - 1 && pos_r == L - 2)) {
        return s;
    }
    return d[min(L - 1, pos_l + 1)] - 1 + (L - 1) * 9;
}

int main() {
    cin >> N;

    cout << solve() << endl;

    return 0;
}


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

int main() {
	int n, q, endTime = 0;
	cin >> n >> q;
	queue<pair<string, int> > Q;
	string name; int time;
	for (int i = 0; i < n; i++) {
		cin >> name >> time;
		Q.push(make_pair(name, time));
	}
	pair<string, int> t;
	while (!Q.empty()) { //队列不空的时候 
		t = Q.front(); Q.pop();
		if (t.second <= q) {
			endTime += t.second;
			cout << t.first << " " << endTime << endl;
		} else {
			t.second -= q;
			endTime += q;
			Q.push(t);
		}
	}
	return 0;
}


Measured memory_bytes: 6356
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 3002

int n;
int m;

long long int dp[2002][3002];

vector<pair<int, int> > v;

vector<pair<int, int> > need;


int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int val, h;
		scanf("%d%d", &val, &h);
		v.push_back(make_pair(val, h));
	}
	for (int i = 0; i < m; i++) {
		int t, s;
		scanf("%d%d", &t, &s);
		need.push_back(make_pair(t, s));
	}
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = LLONG_MIN;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < need.size(); i++) {
		long long int have_money = need[i].first;
		long long int mx = LLONG_MIN;
		long long int pv = LLONG_MIN;
		for (int j = 0; j <= n; j++) {  //used
			if (j)have_money -= v[j - 1].first;
			if (j>1)mx += abs(v[j - 1].second - v[j - 2].second);
			mx = max(mx, pv);
			if (j)mx += v[j - 1].second;
			if (have_money < 0LL)break;
			long long int strength = dp[i][j];
			if (strength >= need[i].second) {
				dp[i + 1][j] = max(dp[i + 1][j], strength);
			}
			pv = strength;
			if (mx >= 0LL && mx >= need[i].second) {
				dp[i + 1][j] = max(dp[i + 1][j], mx);
			}
		}
	}
	long long int cost = need.back().first;
	for (int j = 0; j <= n; j++) {
		if (j)cost -= v[j - 1].first;
		if (cost < 0)break;
		if (dp[need.size()][j] >= 0) {
			printf("%lld\n", cost);
			return 0;
		}
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 26752
import fractions

def lcm(a, b):
    return int((a * b) / fractions.gcd(a, b))

A, B, C, D = map(int, input().split())

c_divide = (B // C) - ((A - 1) // C)
d_divide = (B // D) - ((A - 1) // D)
cd_divide = (B // lcm(C, D)) - ((A - 1) // lcm(C, D))
ans = (B - A + 1) - c_divide - d_divide + cd_divide
print(max(ans, 0))

Measured memory_bytes: 64108
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[3][1005];
int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld%lld", &a[0][i], &a[1][i], &a[2][i]);
	}
	LL ans = -1e18;
	for(int i=0;i<8;i++){
		vector<LL> res;
		for(int j=1;j<=n;j++){
			LL cost = 0;
			for(int k=0;k<3;k++){
				if((i>>k)&1) cost += a[k][j];
				else cost -= a[k][j];
			}
			res.push_back(cost);
		}
		sort(res.begin(), res.end());
		reverse(res.begin(), res.end());
		LL tmp = 0;
		for(int j=0;j<m;j++){
			tmp += res[j];
		}
		ans = max(ans, abs(tmp));
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int n,A[2000];
int solve(int i,int m)
{
  if(m==0)
  {
    return 1;
  }
  if(i>=n)
  {
    return 0;
  }
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}
int main(void)
{
  int q,M,i;
  scanf("%d\n",&n );
  for(i=0;i<n;i++)
  {
    scanf("%d\n",&A[i]);
  }
  scanf("%d\n",&q);
  {
    for(i=0;i<q;i++)
    {
      scanf("%d\n",&M);
      if(solve(0,M))
      {
        printf("yes\n");
      }
      else
      {
        printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  string S;
  cin>>S;
  int K;
  cin>>K;
  rep(i,S.size()){
    if(S[i]=='a') continue;
    int X='z'+1-S[i];
    if(K>=X){
      S[i]='a';
      K-=X;
    }
  }
  S[S.size()-1]='a'+(S[S.size()-1]-'a'+K)%26;
  cout<<S<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int check = 0;
  if (S.at(0) == S.at(1)) {
    if (S.at(2) == S.at(3) && S.at(0) != S.at(2)) {
      check = 1;
    }
  }
  else if (S.at(0) == S.at(2)) {
    if (S.at(1) == S.at(3) && S.at(0) != S.at(1)) {
      check = 1;
    }
  }
  else if (S.at(0) == S.at(3)) {
    if (S.at(1) == S.at(2) && S.at(0) != S.at(1)) {
      check = 1;
    }
  }
  if (check == 1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
#define Q 500

int main(){

  int a[N], b[Q], cnt = 0;
  int i, j, n, q;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);

  scanf("%d", &q);
  for(i = 0; i < q; i++) scanf("%d",& b[i]);

  for(j = 0; j < q; j++){
    for(i = 0; i < n; i++){
      if(a[i] == b[j]){
    cnt++;
    break;
      }
    }
  }

  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 640
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

x,y = map(int,input().split())
if x!=0 and x!=1:
    a = combinations_count(x, 2)
else:
    a=0
if y!=0 and y!=1:
    b = combinations_count(y, 2)
else:
    b=0

print(a+b)

Measured memory_bytes: 3060