akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

typedef vector<double> vdbl;

void jordan(vector<vdbl> &a){
	int n = a.size();
	for(int i = 0; i < n; ++i){
		int idx = i;
		double piv = abs(a[i][i]);
		for(int j = i + 1; j < n; ++j){
			double p = abs(a[j][i]);
			if(piv < p){
				piv = p;
				idx = j;
			}
		}

		a[i].swap(a[idx]);
		piv = a[i][i];
		for(int j = 0; j <= n; ++j){
			a[i][j] /= piv;
		}

		for(int k = 0; k < n; ++k){
			double d = a[k][i];
			for(int j = 0; j <= n; ++j){
				if(k != i){
					a[k][j] -= d * a[i][j];
				}
			}
		}
	}
}

double check(const vdbl &x, const vdbl &y){
	int n = x.size();
	int d = n - 2;
	vector<vdbl> a(d + 1, vdbl(d + 2));
	for(int i = 0; i <= d; ++i){
		for(int j = 0; j <= d; ++j){
			for(int k = 0; k < n; ++k){
				a[j][i] += pow(x[k], i + j);
			}
		}
	}
	
	for(int j = 0; j <= d; ++j){
		for(int k = 0; k < n; ++k){
			a[j][d + 1] += y[k] * pow(x[k], j);
		}
	}

	jordan(a);

	double eps = -1.0;
	for(int i = 0; i < n; ++i){
		double s = 0.0, t = 1.0;
		for(int j = 0; j <= d; ++j){
			s += a[j][d + 1] * t;
			t *= x[i];
		}
		eps = max(eps, abs(y[i] - s));
	}
	return eps;
}

int solve(const vdbl &v){
	vdbl x(v.size() - 1), y = x;

	double mineps = 1e99;
	double ans = -1;
	for(int i = 0; i < v.size(); ++i){
		int t = 0;
		for(int j = 0; j < v.size(); ++j){
			if(j != i){
				x[t] = (double)j;
				y[t] = v[j];
				++t;
			}
		}

		double eps = check(x, y);
		if(mineps > eps){
			mineps = eps;
			ans = i;
		}
	}
	return ans;
}

int main(){
	int d;
	while(scanf("%d", &d), d){
		vdbl v(d + 3);
		for(int i = 0; i < d + 3; ++i){
			scanf("%lf", &v[i]);
		}

		printf("%d\n", solve(v));
	}
}

Measured memory_bytes: 1104
import sys
n,k=map(int,input().split())
A=[]
mod=10**9+7

zero=0
a=list(map(int,input().split()))
for i in range(n):
    if a[i]>0:
        A.append([a[i],0])
    elif a[i]<0:
        A.append([-a[i],1])
    else:
        zero+=1        
if k>n-zero:
    print(0)
    sys.exit()

A=list(reversed(sorted(A)))
cnt=0
for i in range(k):
    cnt+=A[i][1]
chk=0
for i in range(n-zero):
    chk+=A[i][1]    

if cnt%2==0:
    ans=1
    for i in range(k):
        ans=ans*A[i][0]%mod
    print(ans)
elif chk==n-zero:
    if zero>0:
        print(0)
        sys.exit()
    ans=1
    for i in range(k):
        ans=ans*A[n-i-1][0]%mod
    print((-ans)%mod)
elif k==n-zero:
    ans=1
    if zero>0:
        print(0)
    else:
        for i in range(k):
            ans=ans*A[i][0]%mod
        print((-ans)%mod)
        
else:
    if A[k][1]==0:
        p=A[k][0]
        m=0
        for i in range(k+1,n-zero):
            if A[i][1]==1:
                m=A[i][0]
                break
    else:
        m=A[k][0]
        p=0
        for i in range(k+1,n-zero):
            if A[i][1]==0:
                p=A[i][0]
                break
    #print(m,p)
    if A[k-1][1]==0:
        l=0
        Xl=-1
        for i in range(k-1):
            if A[k-i-2][1]==1:
                l=A[k-i-2][0]
                Xl=k-i-2
                break
        #print(l,k)
        if m*l>p*A[k-1][0] or Xl==-1:
            ans=1
            for i in range(k-1):
                ans=ans*A[i][0]%mod
            ans=ans*m%mod
            print(ans)
        else:
            ans=1
            for i in range(k):
                if i==Xl:
                    continue
                ans=ans*A[i][0]%mod 
            ans=ans*p%mod
            print(ans)
    else:
        l=0
        Xl=-1
        for i in range(k-1):
            if A[k-i-2][1]==0:
                l=A[k-i-2][0]
                Xl=k-i-2
                break
        #print(l,k)
        if p*l>m*A[k-1][0] or Xl==-1:
            ans=1
            for i in range(k-1):
                ans=ans*A[i][0]%mod
            ans=ans*p%mod
            print(ans)
        else:
            ans=1
            for i in range(k):
                if i==Xl:
                    continue
                ans=ans*A[i][0]%mod 
            ans=ans*m%mod
            print(ans)

Measured memory_bytes: 44400
from itertools import accumulate
from functools import reduce

n,k = map(int, input().split())
a = list(map(int, input().split()))
acc = [0] + list(accumulate(a))
be = set()
# print(acc)
for i in range(n):
    for j in range(i+1,n+1):
        if acc[j] - acc[i] not in be:
            be.add(acc[j] - acc[i])
# print(be)
be = list(be)
mx = max(be)
# print(bin(mx))
bin_dic = {i:[] for i in range(len(str(bin(mx)))-2)}
# print(binary)
for b in be:
    for i,c in enumerate(str(bin(b))[-1:1:-1]):
        if c == '1':
            bin_dic[i].append(b)
mx_bin = 0
for i in bin_dic.keys():
    if k <= len(bin_dic[i]) and mx_bin < i:
        mx_bin = i
cands = set(bin_dic[mx_bin])
for i in range(mx_bin)[::-1]:
    tmp = set(bin_dic[i]) & cands
    if len(tmp) == k:
        cands = tmp
        break
    elif len(tmp) > k:
        cands = tmp
print(reduce(lambda x,y:x&y, cands))
      

Measured memory_bytes: 243336
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N - 1);
	for (int i=0;i<N-1;i++) {
		cin >> A[i];
	}
	
    vector<int> ans(N);
	for (int i=0;i<N-1;i++) {
		ans[A[i]-1]++;
	}
	cout << ans.at(0);
	for (int i=1;i<N;i++) {
		cout << endl << ans.at(i);
	}
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	vector<P> a, b;
	map<int, int> c, d;
	rep(i, n) {
		if (i % 2 == 0) c[v[i]]++;
		else d[v[i]]++;
	}
	for (auto p : c) a.emplace_back(p.second, p.first);
	for (auto p : d) b.emplace_back(p.second, p.first);
	sort(rall(a)); sort(rall(b));
	if (a.front().second == b.front().second) {
		int ans = a.front().first;
		if (a.size() == 1 && b.size() == 1) {
			cout << n / 2 << endl;
			return 0;
		}
		if (a[1].first >= b[1].first) {
			ans += a[1].first;
		}
		else {
			ans += b[1].first;
		}
		cout << n - ans << endl;
	}
	else {
		int ans = a.front().first + b.front().first;
		cout << n - ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6524
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;

int main(void) {
	int n; cin >> n;
	int m; cin >> m;
	vector<int> v(n);
	rep(i, n)cin >> v[i];
	sort(all(v));
	int ans = 0;
	rep(i, n) {
		m -= v[i];
		ans++;
	}
	for (int i = 0; m >= v[0]; i++) {
		m -= v[0];
		ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_097_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(16).
    01 maxlen PIC 9(1)  VALUE 4.
    01 cur    PIC 9(2)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).
    01 len    PIC 9(2).
    01 abcd1.
        03 abcd11 OCCURS 4.
            05 abcd PIC 9(3).
    01 tmp12 PIC 9(3).
    01 tmp13 PIC 9(3).
    01 tmp23 PIC 9(3).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO abcd(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    COMPUTE tmp12 = abcd(1) - abcd(2).
    COMPUTE tmp13 = abcd(1) - abcd(3).
    COMPUTE tmp23 = abcd(2) - abcd(3).

    IF (tmp13 <= abcd(4)) THEN
       DISPLAY "Yes"
    ELSE
        IF (tmp12 <= abcd(4))
           AND (tmp23 <= abcd(4)) THEN
            DISPLAY "Yes"
        ELSE
            DISPLAY "No"
        END-IF
    END-IF.

    STOP RUN.


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main() {
   string s;
   cin>>s;
   if(s=="ABC")cout<<"ARC"<<endl;
   else cout<<"ABC"<<endl;
} 



Measured memory_bytes: 3628
#include <stdio.h>

int main(void){

  int a,b,tmp;

  scanf("%d %d",&a,&b);

  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  while((tmp = a % b) != 0){
    a = b;
    b = tmp;
  }   

    printf("%d\n",b);
 
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
// head
struct edge { int to, cap, rev, cost; };
vector<edge> G[1000];
void add_edge(int from, int to, int cap, int cost = 0){
	G[from].push_back(edge{ to, cap, (int)G[to].size(),cost });
	G[to].push_back(edge{ from,0,(int)G[from].size() - 1,-cost });
}
 
int main() {
	  int N,M;
    std::cin >> N>>M;
		int ans = 1;
		if (N==1){
			std::cout << M << '\n';
			exit(0);
		}
    rep(i,1,M/N+1){
			if (M%i == 0){
				ans = i;
			}
    }
		std::cout << ans << '\n';
 
}

Measured memory_bytes: 256
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define Jehian using
#define Norman namespace
#define Saviero std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

Jehian Norman Saviero;

/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n")
#define sp printf(" ")

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y
#define SQR(x) ((x)*(x))
#define CUBE(x) (SQR(x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main(){
	vi v;
	int A, B, C;
	cin >> A >> B >> C;
	v.pb(A);
	v.pb(B);
	v.pb(C);
	sort(ALL(v));
	A = v[0];
	B = v[1];
	C = v[2];
	int cnt = 0;
	while (!(A == B && B == C)){
		if (A % 2 == B % 2 && A != B){
			A += 2;
			++cnt;
		}
		if (A % 2 == C % 2 && A != C){
			A += 2;
			++cnt;
		}
		if (B % 2 == C % 2 && B != C){
			B += 2;
			++cnt;
		}

		if (A == B && B < C){
			++A; ++B;
			++cnt;
		}
		if (B == C && C < A){
			++B; ++C;
			++cnt;
		}
		if (C == A && A < B){
			++A; ++C;
			++cnt;
		}
		if (A == B && C < B){
			C += 2;
			++cnt;
		}
		if (B == C && A < C){
			A += 2;
			++cnt;
		}
		if (C == A && B < A){
			B += 2;
			++cnt;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		long mod = (long)(1e9+7);
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long K = input.nextLong();
		int[] A = new int[N+1];
		boolean[] vis = new boolean[N+1];
		boolean quick = false;
		vis[1]=true;
		int curIndex = 1;
		ArrayList<Integer> seq = new ArrayList<Integer>();
		seq.add(1);
		for (int i = 1; i <= N; i++) {
			A[i] = input.nextInt();
		}
		while (true) {
			K--;
			int temp = A[curIndex];
			curIndex=temp;
			if (vis[curIndex]) {
				while (seq.get(0)!=curIndex) {
					seq.remove(0);
				}
				break;
			} 
			else {
				seq.add(curIndex);
				vis[curIndex]=true;
			}
			if (K==0) {
				System.out.println(curIndex);
				quick = true;
				break;
			}
		}
		if (!quick) {
			long period = seq.size();
			int index = (int) (K%period);
			System.out.println(seq.get(index));
		}
	}
}

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

int max_diff(int values[], int n) {
  int max_diff = values[1] - values[0];
  int min_value = values[0];

  for (int i = 1; i < n; i++) {
    max_diff = max(max_diff, values[i] - min_value);
    min_value = min(min_value, values[i]);
  }

  return max_diff;
};

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

  int values[n] = {0};

  for (int i = 0; i < n; i++)
    cin >> values[i];

  cout << max_diff(values, n) << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	ll x, y, z, xyz[10][1252];
	cin>>n>>m;
	REP(i, n){
		cin>>x>>y>>z;
		xyz[0][i]=x+y+z;
		xyz[1][i]=x+y-z;
		xyz[2][i]=x-y+z;
		xyz[3][i]=-x+y+z;
		xyz[4][i]=x-y-z;
		xyz[5][i]=-x+y-z;
		xyz[6][i]=-x-y+z;
		xyz[7][i]=-x-y-z;
	}
	REP(i, 8){
		sort(xyz[i], xyz[i]+n, greater<ll>());
	}
	ll ans=0;
	REP(i, 8){
		ll tmp=0;
		REP(j, m){
			tmp+=xyz[i][j];
		}
		ans=max(ans, tmp);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 384
# https://atcoder.jp/contests/abc156/tasks/abc156_c



N = gets.to_i
Xs = gets.split.map(&:to_i)

p1 = Xs.inject(:+) / N
p2 = p1 + 1

sum1 = 0
sum2 = 0
Xs.each do |x|
  sum1 += (x - p1) ** 2
  sum2 += (x - p2) ** 2
end
puts sum1 < sum2 ? sum1 : sum2


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;


int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4]==s[5]){
        cout << "Yes";
    }else{
        cout << "No";
    }
    }

Measured memory_bytes: 256
n,y=map(int,input().split())
F=y//10000
H=y//5000
ansF=-1
ansH=-1
ansN=-1
for i in range(F+1):
    tmp1=y-10000*i
#    print("==="+str(i)+"===")
#    print(tmp1)
    for j in range(H+1):
        if i+j>n:
            break
        tmp2=tmp1-5000*j
#        print("=="+str(j)+"==")
#        print(tmp2)
        if tmp2<0:
            break
        if tmp2==(n-i-j)*1000:
#            print("="+str(n-i-j)+"=")            
#            print(tmp2)
            ansF=i
            ansH=j
            ansN=n-i-j
            break
    if ansF!=-1:
        break
print("{} {} {}".format(ansF,ansH,ansN))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	int a, b, c;
	cin >> a >> b >> c;
	if(a+b+c>=22) cout << "bust";
	else cout << "win"; 
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*; 
class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        while(sc.hasNext()){
            int temp1=sc.nextInt();
            int temp2=sc.nextInt();
            int temp3=sc.nextInt();
            int ans=0;
            for(int i=1;i<=10;i++)if(i!=temp1&i!=temp2&i!=temp3&i+temp1+temp2<=20)ans++;
            if (3<ans)out.println("YES");
            else   out.println("NO"); 
        }
        out.flush();
        out.close();
    }
}

Measured memory_bytes: 17376
#include<bits/stdc++.h>
using namespace std;
int main() 
{
     int k;
     cin>>k;
     string s;
     cin>>s;
     if(s.size()<=k)
     {
         cout<<s;
     }
     else
     {
         string t=s.substr(0,k);
         cout<<t<<"...";
     }

return 0;
}


Measured memory_bytes: 3628
N=int(input())
A=input()
c=0
B1B=0
B1R=0
B1G=0
if A[0]=="B":
 B1B+=1
elif A[0]=="R":
 B1R+=1
else:
 B1G+=1
for i in range(N-2):
 B2=A[i+1]
 for k in range(N-i-2):
  B3=A[i+2+k]
  if (B2=="B" and B3=="R")or (B2=="R" and B3=="B"):
   c+=B1G
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="G":
     c-=1
  if (B2=="G" and B3=="R")or (B2=="R" and B3=="G"):
   c+=B1B
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="B":
     c-=1
  if (B2=="B" and B3=="G")or (B2=="G" and B3=="B"):
   c+=B1R
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="R":
     c-=1
 if B2=="B":
  B1B+=1
 elif B2=="R":
  B1R+=1
 else:
  B1G+=1
print(c)


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int sx, sy, tx, ty;
	cin>>sx>>sy>>tx>>ty;
	int x = tx - sx, y = ty - sy;
	for(int i = 0; i < y; i++){
		cout<<'U';
	}
	for(int i = 0; i < x; i++){
		cout<<'R';
	}

	for(int i = 0; i < y; i++){
		cout<<'D';
	}
	for(int i = 0; i < x; i++){
		cout<<'L';
	}

	cout<<'L';
	for(int i = 0; i < y + 1; i++){
		cout<<'U';
	}
	for(int i = 0; i < x + 1; i++){
		cout<<'R';
	}
	cout<<'D';

	cout<<'R';
	for(int i = 0; i < y + 1; i++){
		cout<<'D';
	}
	for(int i = 0; i < x + 1; i++){
		cout<<'L';
	}
	cout<<'U';
	cout<<'\n';

	return 0;
}

Measured memory_bytes: 256
import math

s = input()
k = int(input())
cnt = 0
memo = 0
flg = True
if len(s) == 1:
    cnt = math.floor(k / 2)
elif len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    for i in range(1, len(s)):
        if s[0] == s[i] and flg:
            memo += 1
        else:
            flg = False
        if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
    cnt *= k
    if s[0] == s[-1] and memo % 2 == 0:
        cnt += (k - 1)
print(cnt)


Measured memory_bytes: 3064
X, N = map(int,input().split())
p = list(map(int,input().split()))

flag = 0
if N == 0:
    print(X)
else:
    X1 = X
    X2 = X
    ans = []
    while flag ==0:
        
        if not(X1 in p):
            ans.append(X1)
            flag = 1
        if not(X2 in p):
            ans.append(X2)
            flag = 1
        if flag == 1:
            print(min(ans))
            
        else:
            X1-= 1
            X2+= 1
        

Measured memory_bytes: 9204
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    char s[200];
    long long k;
    cin >> s >> k;
    int n = strlen(s);
    for (int i = 0; i < n; ++i) {
        if (s[i] != '1') {
            printf("%c\n", s[i]);
            break;
        }
        if (k == 1) {
            printf("%c\n", s[i]);
            break;
        }
        --k;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,i,j,m,n,d;
    char c;
    scanf("%d %c %d",&a,&c,&b);
    if(c=='+')
    {
        d=a+b;
        printf("%d\n",a+b);
    }
    else if(c=='-')
    {
        d=a-b;
        printf("%d\n",d);
    }
    return 0;

}


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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define IOS			ios::sync_with_stdio(0), cin.tie(0)


int32_t main() {

	IOS;

	vector<int> v(10000001, 2);
	v[1] = 1;

	for (int i = 2; i <= 1e7; i++) {
		for (int j  = 2 * i; j <= 1e7; j += i)
			v[j]++;
	}

	int n;
	cin >> n;

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		ans += i * v[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 81256
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <cmath>
#include <ctime>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <chrono>
#include <functional>
#include <random>
#include <numeric>
#include <tuple>
#include <bitset>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int, int> ii;
template<class T> string toString(T x) { ostringstream ss; ss << x; return ss.str(); }
void solve();
int main() {
#ifdef LOCAL_COMP
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
	solve();
#ifdef LOCAL_COMP
	cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	ll n, p;
	while (cin >> n >> p) {
		if (n == 1) {
			cout << p << endl;
			continue;
		}
		vector<ll> div;
		for (ll i = 1; i*i <= p; i++) {
			if (p % i == 0) {
				div.push_back(i);
				if (i*i != p) div.push_back(p / i);
			}
		}
		ll ans = 1;
		for (ll d : div) {
			if (2 <= d && d <= ll(1e6)) {
				ll now = 1;
				ll cnt = 0;
				while (true) {
					if (now * d > p || p % (now * d) != 0) break;
					now *= d;
					cnt++;
				}
				ans = max(ans, (cnt / n) * d);
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long x,y,i;
    cin>>x>>y;
    if(x%y==0){
        cout<<-1;
        return 0;
    }
    for(i=2; i<=1000000000000000000; ++i){
        if((x*i)%y!=0){
            cout<<x*i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
let n = read_int ()
let k, ans = read_int (), ref max_int
let _ = for i = 0 to n do let x = ref 1 in for j = 1 to i do x := !x * 2 done; x := !x + (n - i) * k; ans := min !ans !x done; Printf.printf "%d\n" !ans

Measured memory_bytes: 384
N = gets.chomp.to_i
S = gets.chomp.chars
ans = 0
(N - 1).times do |i|
  a = S.slice(0..i).uniq
  b = S.slice(i+1..-1).uniq
  max = 0
  a.each do |j|
    max += 1 if b.include?(j)
  end
  ans = max if max > ans
end
puts ans


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

int main(){
  int A_0, B, C_0, D;	//A_0, C_0:初期体力
  cin >> A_0 >> B >> C_0 >> D;
  
  int A, C;
  A = A_0;
  C = C_0;
  
  while(true){
    C -= B;
    if(C < 1){
      cout << "Yes" << endl;
      break;
    }
    
    A -= D;
    if(A < 1){
      cout << "No" << endl;
      break;
    }
  }
  
}
  

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

int main() {
  string S;
  cin >> S;
  int Sum=0, A=S.at(0)-'0';
  bool N=1;
  for(int i=1; i<S.size(); i++){
    if(S.at(i)!='9') N=0;
  }
  Sum+=(S.size()-1)*9;
  if(S.size()!=1 && N==0) Sum=Sum+A-1;
  else Sum+=A;
  cout << Sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void){
	int floy[101][101][2];
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0&&m==0){
			break;
		}
			
		for(int b=0;b<2;b++){
			for(int i=0;i<=m;i++){
				for(int j=0;j<=m;j++){
					floy[i][j][b]=1<<29;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			int a,b,cost,time;
			scanf("%d%d%d%d",&a,&b,&cost,&time);
			floy[a][b][0]=cost;
			floy[b][a][0]=cost;
			floy[a][b][1]=time;
			floy[b][a][1]=time;
		}
		
		for(int b=0;b<2;b++){
			for(int k=1;k<=m;k++){
				for(int i=1;i<=m;i++){
					for(int j=1;j<=m;j++){
							floy[i][j][b]=min(floy[i][j][b],floy[i][k][b]+floy[k][j][b]);
					}
				}
			}
		}
		
		
		int kazu;
		scanf("%d",&kazu);
		
		for(int i=0;i<kazu;i++){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			printf("%d\n",floy[a][b][c]);
		}
	}
}

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

using namespace std;

typedef long long ll;

ll inq(ll x, ll y, ll mod)
{
    if (y == 0) return 1 % mod;
    ll l = inq(x, y / 2, mod);
    if (y % 2) return l * l % mod * x % mod;
    return l * l % mod;
}

ll gcdex(ll a, ll b, ll &x, ll &y)
{
    // Solves the equation ax + by = gcd(a, b)
    // returns gcd(a, b)
    // save x and y in given values
    //
    // Correctness tested on random tests.
    //
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    ll x1, y1;
    ll g = gcdex(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return g;
}

pair<ll, ll> crt(vector<ll> r, vector<ll> m)
{
    // Finds such x, that x mod m[i] = r[i] for each i
    // if such x does not exist returns {0, 0}
    //
    // Correctness tested on random tests.
    //
    int n = r.size();
    for (int i = 0; i < n; i++) r[i] %= m[i];
    ll r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++)
    {
        ll r1 = r[i], m1 = m[i];
        if (m0 < m1)
        {
            swap(m0, m1);
            swap(r0, r1);
        }
        if (m0 % m1 == 0)
        {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        ll x, y;
        ll g = gcdex(m0, m1, x, y);
        ll u = m1 / g;
        if ((r0 - r1) % g != 0)
            return {0, 0};
        ll z = (r1 - r0) / g % u * x % u;
        r0 += z * m0;
        m0 *= u;
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

const int K = 1;

ll solve(ll a, ll m)
{
    if (m == 1) return K;
    ll phi = m;
    ll z = m;
    for (int i = 2; i * i <= z; i++)
    {
        if (z % i == 0)
        {
            phi /= i;
            phi *= (i - 1);
            while (z % i == 0)
            {
                z /= i;
            }
        }
    }
    if (z > 1)
    {
        phi = phi / z * (z - 1);
    }
    ll g = __gcd(m, phi);
    ll y = solve(a, g);
    vector<ll> R = {y, inq(a, y, m)};
    vector<ll> M = {phi, m};
    pair<ll, ll> ze = crt(R, M);
    while (ze.first < K) ze.first += ze.second;
    return ze.first;
}

int main()
{
    int q;
    cin >> q;
    while (q--)
    {
        ll a, m;
        cin >> a >> m;
        ll r = solve(a, m);
        ll phi = m;
        ll z = m;
        for (int i = 2; i * i <= z; i++)
        {
            if (z % i == 0)
            {
                phi /= i;
                phi *= (i - 1);
                while (z % i == 0)
                {
                    z /= i;
                }
            }
        }
        if (z > 1)
        {
            phi = phi / z * (z - 1);
        }
        cout << m * phi + r % (m * phi) << "\n";
    }
}


Measured memory_bytes: 3608
def dfs(v,c,m,n,k,s)
    if c == k
        return 1 if m == s
        return 0 if m != s
    end
    return 0 if v > n || m > s
    ans = 0
    (v+1).upto(n) do |i|
        ans += dfs(i,c+1,m+i,n,k,s)
    end
    return ans
end
loop do
    n, k, s = gets.split.map(&:to_i)
    break if n == 0 && k == 0 && s == 0
    puts dfs(0,0,0,n,k,s)
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main()
{
    lld a, b, c;
    cin >> a >> b >> c;
    lld d = 2 * sqrtl(a * b);
    if (a + b + d < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, i, j, k, s;
	cin >> n;
	vector<int> a(n), b;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) {
		for (j = i; (j < n) && (a[j] == j + 1); j++);
		if (i != j) b.push_back(j - i);
		i = j;
	}

	s = 0;
	for (auto p : b) {
		if (p % 2 == 0) s += p / 2;
		else s += p / 2 + 1; 
	}
	cout << s << "\n";

	return 0;
}



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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(){
    cin.tie(0);
   	ios::sync_with_stdio(false);

    string S;
    cin >> S;
    int f, s;
    f = stoi(S.substr(0, 2));
    s = stoi(S.substr(2, 2));

    if(f > 12 || f == 0){// Mが12ならば

        if(1 <= s && s <=12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }

    }else{// 
        if(1 <= s && s <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextInt();
    long w = sc.nextInt();
    int n = sc.nextInt();
    HashMap<Long, Integer> map = new HashMap<Long, Integer>();
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong() - 1;
      long b = sc.nextLong() - 1;
      long a1 = Math.max(0, a - 2);
      long b1 = Math.max(0, b - 2);
      for(long j = a1; j <= a; j++) {
        for(long k = b1; k <= b; k++) {
          if(((j + 2) < h) && ((k + 2) < w)) {
            long t = j * w + k;
            if(map.containsKey(t)) {
              map.put(t, map.get(t) + 1);
            } else {
              map.put(t, 1);
            }
          }
        }
      }
    }
    long[] num = new long[10];
    for(Long key : map.keySet()) {
      num[map.get(key)]++;
    }
    long sum = 0;
    for(int i = 1; i <= 9; i++) {
      sum += num[i];
    }
    num[0] = (h - 2) * (w - 2) - sum; 
    for(int i = 0; i < 10; i++) {
      System.out.println(num[i]);
    }
  }
}

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

int main(){
    int n,cnt=0;
    cin >> n;
    int p[n];
    for (int i=0;i<n;++i) cin >> p[i];

    for(int i=1;i<n-1;++i){
        if(p[i-1]<p[i] && p[i]<p[i+1]){
            cnt += 1;
        }
        else if(p[i+1]<p[i] && p[i]<p[i-1]){
            cnt += 1;
        }
    }

    cout << cnt << endl;

    }



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

vector<int>prime(999999,0);
//vector<int>prime1(1000001,0);
vector<int>mark(9999999,0);
int nprime;

void sieve(int n)///FINDING PRIME
{
    int limit=sqrt(n*1.0)+1,s=0;nprime=0;
    mark[1]=1;///1 if not prime.
    mark[2]=0;prime[nprime++]=2;//cout<<2<<endl;
    //for(int i=4;i<=n;i+=2)mark[i]=1;
    for(int i=3;i<=n;i+=2){
        if(!mark[i]){prime[nprime++]=i;//cout<<i<<endl;
        if(i<=limit){///karon limit er upor theke n porjonto not prime gula already cuta hoise.
            for(int j=i*i;j<=n;j+=i*2){
                mark[j]=1;
            }
        }}
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    char x;
    cin>>x;
    if(x>='A'&&x<='Z')cout<<"A";
    else cout<<"a";
}


Measured memory_bytes: 46128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main() {
    int n;
    cin>>n;
    ll a[n];
    for (int i=0;i<n;i++) {
        cin>>a[i];
    }
    
    
    ll b[n+1]{};
    for (int i=0;i<n;i++) {
        b[i+1]=(b[i]+a[i])%mod;
    }
    ll ans=0;
    for (int i = 0; i < n - 1; i++) {
        ans+=a[i]*(b[n]-b[i+1]+mod);
        ans%=mod;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 6720
parseInt(x) = parse(Int,x)

function main()
  N = parseInt(readline())
  H = map(parseInt,split(readline()))
  c = 1
  for i = (N-1):-1:1
    a = H[i+1]-H[i]
    a == -1 ? H[i] -= 1 : tmp = 0
    a < -1 ? c = -1 : tmp = 0
  end
  c == 1 ? println("Yes") :println("No")
end

main()

Measured memory_bytes: 124416
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

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

    int n;
    cin >> n;
    vi t(n), x(n), y(n);
    rep(i, n){ cin >> t[i] >> x[i] >> y[i]; }

    int nowX = 0, nowY = 0;
    int beforeT = 0;
    rep(i, n){
        //show(t[i] - beforeT);
        //show(abs(nowX - x[i]) + abs(nowY - y[i]));
        if(t[i] - beforeT < abs(nowX - x[i]) + abs(nowY - y[i])){
            no;
            return 0;
        }else if(t[i] - beforeT == abs(nowX - x[i]) + abs(nowY - y[i])){
            nowX = x[i]; nowY = y[i];
            beforeT = t[i];
        }else{
            //show(t[i] - beforeT - abs(nowX - x[i]) - abs(nowY - y[i]));
            if((t[i] - beforeT - abs(nowX - x[i]) - abs(nowY - y[i])) % 2 == 0){
                nowX = x[i]; nowY = y[i];
                beforeT = t[i];
            }else{
                no;
                return 0;
            }
        }
    }
    yes;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define INF ( 1 << 25 )
int Q, m[6], tmp[] = { 1, 5, 10, 50, 100, 500};
int hoge(int n){ //n円のおつり
  int ret = 0;
  for(int i = 5 ; i >= 0 ; i-- ){
    while(tmp[i] <= n) n -= tmp[i], ret++;
  }
  return ret;
}
int java(int n){ //n円はらいたい
  int ret = 0;
  for(int i = 5 ; i >= 0 ; i-- ){
    int a = min( n / tmp[i], m[i]);
    n -= a * tmp[i];
    ret += a;
  }
  return ret;
}
int main(){
  while(cin >> Q, Q){
    int sum = 0;
    for(int i = 0 ; i < 6 ; i++ ){
      cin >> m[i];
      sum += tmp[i] * m[i];
    }
    int ret = INF;
    for(int i = Q ; i <= Q + 500 ; i++ ){
      ret = min( ret, java(i) + hoge(i - Q));
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1160
# coding:utf-8

N, M = map(int, input().split(' '))
ans = ['-1' for _ in range(N)]
if M == 0:
    if N == 1:
        print('0')
    elif N == 2:
        print('10')
    else:
        print('100')
else:
    ans = ['-1' for _ in range(N)]
    for _ in range(M):
        s, c = input().split(' ')
        try:
            if ans[int(s)-1] == '-1':
                ans[int(s)-1] = c
            elif ans[int(s)-1] == c:
                pass
            else:
                print('-1')
                exit(0)
        except IndexError:
            print('-1')
            exit(0)

    output = ''
    for el in ans:
        if output == '' and el == '-1':
            output += '1'
        elif el =='-1':
            output += '0'
        else:
            output += el
    if output[0] == '0' and len(output) != 1:
        print('-1')
    else:
        print(output)


Measured memory_bytes: 3064
S = input()
 
ans_list = ["AKIHABARA",\
            "KIHABARA","AKIHBARA","AKIHABRA","AKIHABAR",\
            "KIHBARA","KIHABRA","KIHABAR","AKIHBRA","AKIHBAR","AKIHABR",\
            "AKIHBR","KIHABR","KIHBAR","KIHBRA",\
            "KIHBR"]
 
if S in ans_list:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;

int a, b, c;

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

    cin >> a >> b >> c;

    int i;
    bool f = false;
    for (i=0; i<=b*1000; i+=a) {
        if (i % b == c) {
            f = true;
            break;
        }
    }

    outl(f ? "YES" : "NO");

}



Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt()
  val xy = Array.fill(n)(sc.nextInt, sc.nextInt)
  println(xy.count(distance(_) <= d))

  def distance(v:(Int, Int)) = {
    import scala.math.pow
    import scala.math.sqrt
    sqrt(pow(v._1, 2) + pow(v._2, 2))
  }
}


Measured memory_bytes: 66648
#prag\
ma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
#define N 100005
using namespace std;
int n,m,fa[N],dist[N];
void Init()
{
	for(int i=1;i<=n;++i)
	{
		fa[i]=i;
		dist[i]=0;
	}
}
int Find(int x)
{
	if(fa[x]==x) return x;
	int tmp=fa[x]; fa[x]=Find(fa[x]); dist[x]+=dist[tmp];
	return fa[x];
}
int main()
{
	scanf("%d%d",&n,&m);
	Init();
	for(int i=1;i<=m;++i)
	{
		int l,r,d; scanf("%d%d%d",&l,&r,&d);
		int tl=Find(l),tr=Find(r);
		if(tl==tr)
		{
			if(dist[l]+d!=dist[r])
			{
				printf("No\n");
				return 0;
			}
		}
		else
		{
			fa[tr]=tl;
			dist[tr]=dist[l]-dist[r]+d;
		}
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 1024
#C - Sum of product of pairs
N = int(input())
A = list(map(int,input().split()))
SUM = 0
jsum= 0
MOD = 1000000007
for j in range(N):
    jsum = (jsum + A[j]) % MOD

for i in range(N-1):
    jsum = (jsum - A[i]) % MOD
    SUM = ( SUM + (jsum * A[i] % MOD ) ) % MOD

# 出力
print(SUM)


Measured memory_bytes: 31444
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 10 21:07:31 JST 2020
 **/

signed main() {
    std::string a, b;
    std::cin >> a >> b;
    std::cout << (a.size() + 1 == b.size() && a == b.substr(0, a.size()) ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, R;
  cin >> N >> R;
  cout << R + 100 * max(0, 10 - N) << endl;
  return 0;
}


Measured memory_bytes: 3564
#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
while len(s) > 0:
    flag = 0
    for w in words:
        w = w[::-1]
        if s[0:len(w)] == w:
            s = s[len(w)::]
            # s = s.replace(w, "").lstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 3188
N, L = map(int, input().split())

x = []
y = []
for i in range(N):
  a = L + (i + 1) - 1
  x.append(a)
  y.append(abs(a))
z = min(y)
if z in x:
  x.remove(z)
else:
  j = -z
  x.remove(j)
print(sum(x))

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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    priority_queue<double, vector<double>, greater<double>> q;
    for (int i = 0; i < N; i++) {
        int cur;
        cin >> cur;
        q.push(cur);
    }

    while (q.size() > 1) {
        double m1 = q.top(); q.pop();
        double m2 = q.top(); q.pop();
        q.push((m1 + m2) / 2.0);
    }

    cout << setprecision(15) << q.top() << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i=0; i<N-1;i++){
    int b;
    cin >> b;
    a.at(b-1)++;
  }
  for (int i=0; i<N; i++){
    cout << a.at(i) << endl;
  }
}

Measured memory_bytes: 4040
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	int f,e;
	cin>>s;
	rep(i,s.size()){
		if(s[i]=='A'){
			f=i;
			break;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='Z'){
			e=i;
			break;
		}
	}
	cout<<e-f+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    if(s[0]!='A')
    {
        cout<<"WA"<<endl;
        return 0;

    }
    int l=s.length();
    int cnt=0;
    for(int i=2;i<l-1;i++)
        if(s[i]=='C')
            cnt++;
    if(cnt!=1)
    {
        cout<<"WA"<<endl;
        return 0;
    }
    cnt=0;
    for(int i=0;i<l;i++)
        if(isupper(s[i]))
            cnt++;
    if(cnt!=2)
    {
        cout<<"WA"<<endl;
        return 0;
    }
    cout<<"AC"<<endl;
    return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n;
        ll a[n];
        FOR(i,0,n)  cin>>a[i];
        ll ans=M;
        FOR(i,-100,101)
        {
          ll cost=0;
          FOR(j,0,n)
            cost += pow((a[j]-i),2);
          ans = min(ans,cost);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
	string str;
	char ball='A';
	while(cin>>str){
		if(str.at(0)==ball){
			ball=str.at(2);
		}
		else if(str.at(2)==ball){
			ball=str.at(0);
		}
	}
	cout<<ball<<endl;
}

Measured memory_bytes: 1172
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int map[100][100][100];
std::vector<ull> X1, X2, Y1, Y2, D1, D2, X, Y, D;

int compress(std::vector<ull> &v1, std::vector<ull> &v2, std::vector<ull> &v, int w){
    REP(i, w){
        int s = v1[i], t = v2[i];

        v.push_back(s);
        v.push_back(t);
    }

    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    REP(i, w){
        v1[i] = std::find(v.begin(), v.end(), v1[i]) - v.begin();
        v2[i] = std::find(v.begin(), v.end(), v2[i]) - v.begin();
    }

    return v.size();
}

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

    REP(i, N){
        int x1, y1, d1, x2, y2, d2;
        std::cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;

        X1.push_back(x1);
        Y1.push_back(y1);
        D1.push_back(d1);
        X2.push_back(x2);
        Y2.push_back(y2);
        D2.push_back(d2);
    }

    int w_x, w_y, w_d;
    w_x = compress(X1, X2, X, N);
    w_y = compress(Y1, Y2, Y, N);
    w_d = compress(D1, D2, D, N);

    REP(i, N){
        int x1 = X1[i], y1 = Y1[i], d1 = D1[i],
            x2 = X2[i], y2 = Y2[i], d2 = D2[i];

        map[d1][y1][x1] += 1;
        map[d1][y2][x1] += -1;
        map[d1][y1][x2] += -1;
        map[d1][y2][x2] += 1;
        map[d2][y1][x1] += -1;
        map[d2][y2][x1] += 1;
        map[d2][y1][x2] += 1;
        map[d2][y2][x2] += -1;
    }

    REP(k, w_d){
        REP(i, w_y){
            FOR(j, 1, w_x){
                map[k][i][j] += map[k][i][j-1];
            }
        }
    }

    REP(k, w_d){
        REP(i, w_x){
            FOR(j, 1, w_y){
                map[k][j][i] += map[k][j-1][i];
            }
        }
    }

    REP(i, w_y){
        REP(j, w_x){
            FOR(k, 1, w_d){
                map[k][i][j] += map[k-1][i][j];
            }
        }
    }

    ull res = 0;
    REP(i, w_d-1){
        REP(j, w_y-1){
            REP(k, w_x-1){
                if(map[i][j][k] >= K){
                    res += (D[i+1]-D[i]) * (Y[j+1]-Y[j]) * (X[k+1]-X[k]);
                }
            }
        }
    }

    std::cout << res << std::endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  int count=1;
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  for(int i=0;i<n-1;i++){
    if(d[i]!=d[i+1]){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<string> t;
  vector<int> d;
  for(int i = 0; i < n; ++i) {
    string st;
    int sd;
    cin >> st >> sd;
    t.push_back(st);
    d.push_back(sd);
  }
  string w;
  cin >> w;
  
  int answer = 0;
  bool f = false;
  for(int i = 0; i < n; ++i) {
    if(f) {
      answer += d[i];
      continue;
    }
    if(w.compare(t[i]) == 0) {
      f = true;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256