akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();

        double dist = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
        System.out.println(dist);
    }
}


Measured memory_bytes: 27936
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int N,M,Q;
int a[55],b[55],c[55],d[55];
//bool aff[55][55];
vector<int> e[55];
bool is[55];
int num[55];
int res=0;
void dfs(int now,int prev){
	if(now==N+1){
		int cu=0;
		rb(i,1,Q){
			if(num[b[i]]-num[a[i]]==c[i]){
				cu+=d[i];
			}
		}
		res=max(res,cu);
		return;
	}
	rb(i,prev,M) {
		num[now]=i;
		dfs(now+1,i);
	}
}
int main(){
	fastio;
	cin>>N>>M>>Q;rb(i,1,Q) cin>>a[i]>>b[i]>>c[i]>>d[i];
	dfs(1,1);
	cout<<res<<endl;
	return 0;
}


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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int x;
	cin >> x;
	cout << 1000*(x/500) + 5*((x%500)/5) << ende;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//
		int a = sc.nextInt();
		int mina = 100000;
		int b = sc.nextInt();
		int minb = 100000;
		int m = sc.nextInt();

		int[] cola = new int[a];
		int[] colb = new int[b];

		for (int i = 0; i < a; i++) {
			cola[i] = sc.nextInt();
			if (cola[i] < mina) {
				mina = cola[i];
			}
		}
		for (int i = 0; i < b; i++) {
			colb[i] = sc.nextInt();
			if (colb[i] < minb) {
				minb = colb[i];
			}
		}
		int pri = mina + minb;

		int[] colx = new int[m];
		int[] coly = new int[m];
		int[] colc = new int[m];

		for (int i = 0; i < m; i++) {
			colx[i] = sc.nextInt();
			coly[i] = sc.nextInt();
			colc[i] = sc.nextInt();
		}

		for (int i = 0; i < m; i++) {
			if (cola[colx[i] - 1] + colb[coly[i] - 1] - colc[i] < pri) {
				pri = cola[colx[i] - 1] + colb[coly[i] - 1] - colc[i];
			}
		}

		System.out.println(pri);

	}
}


Measured memory_bytes: 139312
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

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);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string s;
	cin >> s;

	if(s.size() == 2) cout << s << endl;
	else{
		for(int i = 2;i >= 0;i--){
			cout << s[i];
		}
		cout << endl;
	}
	
	return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, k, s;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k >> s;
	forn (i, n) {
		if (i >= k) {
			if (s == int(1e9)) cout << 1 << " ";
			else cout << int(1e9) << " ";
		} else {
			cout << s << " ";
		}
	}

	return 0;
}


Measured memory_bytes: 3552
N = input()
l = len(N)


dic = {}
for i in range(1, 10):
    for j in range(1, 10):
        dic[(str(i), str(j))] = 0

for i in range(1, int(N) + 1):
    s = str(i)
    t = (s[0], s[-1])
    if t in dic:
        dic[t] += 1
ans = 0

for i in range(1, int(N) + 1):
    s = str(i)
    t = (s[-1], s[0])
    if t in dic:
        ans += dic[t]

print(ans)






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

int zet(int a, int b){
    if(a>=b){
        return (a-b);
    }
    else{
        return (b-a);
    }
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(zet(a,b), max(zet(b,c), zet(c,a))) << endl;
}


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


void solve(long long n, std::vector<long long> a){
  deque<long long> tmp;

  for(long long i = 0; i < n; i++) {
    if(i%2==0) tmp.push_back(a[i]);
    else tmp.push_front(a[i]);
  }

  if(n % 2 == 1) reverse(tmp.begin(), tmp.end());

  for(long long i = 0; i < (n-1); i++){
    cout << tmp[i] << " ";
  }

  cout << tmp[n-1] << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long n;
  scanf("%lld",&n);
  std::vector<long long> a(n);
  for(int i = 0 ; i < n ; i++){
    scanf("%lld",&a[i]);
  }
    solve(n, std::move(a));
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  if(N % 10 == 3)
    cout << "bon" << endl;
  else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}

Measured memory_bytes: 3640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i>=(n);i--)
#define printa(x,n) for(int i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
vector<int> divisor(int M){
    vector<int> dd;
    for(int i = 1; i * i <= M; i++){
        if(M % i == 0){
            dd.push_back(i);
            if(i * i != M) dd.push_back(M / i);
        }
    }
    return dd;
}

int num[1000010] = {};

void solve(){
    int N;
    cin >> N;
    int A[200010];
    rep(i,0,N) cin >> A[i];
    int ans = 0;
    rep(i,0,N) num[A[i]]++;
    rep(i,0,N){
        vector<int> div = divisor(A[i]);
        bool ok = true;
        for(auto &e: div){
            if(e == A[i]){
                if(num[e] > 1){
                    ok = false;
                    break;
                }
            }else{
                if(num[e] > 0){
                    ok = false;
                    break;
                }
            }
        }
        if(ok) ans++;
    }
    print(ans);
}

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


Measured memory_bytes: 8188
#include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100
int  n, i, judge[MAX_N], ans;

int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i = 0; i < n; i++) scanf("%d", &judge[i]);
    qsort(judge, n, sizeof(int), sort);
    ans = 0;
    for(i = 1; i < n - 1; i++) ans += judge[i];
    printf("%d\n", ans / (n - 2));
  }
  return 0;
}

Measured memory_bytes: 1036
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    sort(x.rbegin(), x.rend());
    sort(y.begin(), y.end());
    if (x[0] >= y[0]) {
        cout << "War" << endl;
        return 0;
    }
    for (int z = X+1; z <= Y; z++) {
        if (x[0] < z && y[0] >= z) {
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 3548
#include<stdio.h>
#define  _CRT_SECURE_NO_WARNINGS

int main(void) {
	int i,x;
	
	for(i=1;1;i++) {
                scanf("%d", &x);
                if(x==0) break;
		printf("Case %d: %d\n", i, x);
                
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}
int N,A,B,C;
vector<int> l;
int dfs(int count,int a,int b,int c){
   if(count==N){
      if(a==0||b==0||c==0){
         return 1000000000;
      }else{
         return abs(a-A)+abs(b-B)+abs(c-C);
      }
   }
   int ans=dfs(count+1,a,b,c);
   if(a>=1){
      ans=min(ans,dfs(count+1,a+l[count],b,c)+10);
   }else{
      ans=min(ans,dfs(count+1,a+l[count],b,c));
   }
   if(b>=1){
      ans=min(ans,dfs(count+1,a,b+l[count],c)+10);
   }else{
      ans=min(ans,dfs(count+1,a,b+l[count],c));
   }
   if(c>=1){
      ans=min(ans,dfs(count+1,a,b,c+l[count])+10);
   }else{
      ans=min(ans,dfs(count+1,a,b,c+l[count]));
   }
   return ans;
}
int main(void){
   cin>>N>>A>>B>>C;
   l.resize(N);
   for(int i=0;i<N;i++){
      cin>>l[i];
   }
   cout<<dfs(0,0,0,0)<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll k, a, b;
    cin>>k>>a>>b;

    if (a / k < b / k || a % k == 0) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
#define int long long
signed main(){
    int N,A,B;
    cin>>N>>A>>B;
    vector<int> town(N);
    for(int i=0;i<N;i++) cin>>town[i];

    int ans = 0;

    for(int i=0;i<N-1;i++){
        ans += min(A*(town[i+1]-town[i]),B);
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = 100500, INF = 1e9;

int n, k, X[MAXN];

int getans(int l, int r){
    int xl = X[l], xr = X[r], ans;

    if((xl < 0) == (xr < 0)){
        ans = max(abs(X[l]), abs(X[r]));
//        printf("De %d a %d es %d\n", xl, xr, ans);
        return ans;
    }
    int add = min(abs(X[l]), abs(X[r]));
    ans = abs(xl) + abs(xr) + add;
//    printf("De %d a %d es %d\n", xl, xr, ans);
    return ans;
}

int main(){
//	freopen("input.txt", "r", stdin);
	while(scanf("%d %d", &n, &k) >= 1){
        forn(i, n)scanf("%d", &X[i]);

        int l = 0, r = k, ans = INF;
        while(r <= n){
            ans = min(ans, getans(l, r-1));
            l++; r++;
        }
        printf("%d\n", ans);
    }
	return 0;
}


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

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

	string S, T;
	cin >> S >> T;

	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
S,T=[0],[0]
for c in input():S+=[S[-1]+1+(c=='B')]
for c in input():T+=[T[-1]+1+(c=='B')]
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    print('NO'if(T[d]-T[c-1]-S[b]+S[a-1])%3 else'YES')

Measured memory_bytes: 12252
import sys
import math
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
ra = lambda: list(map(int, sys.stdin.readline().split()))

n, d = ra()
x = []
for i in range(n):
    l = ra()
    x.append(l)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
            total += (x[i][k] - x[j][k])**2
        if math.sqrt(total).is_integer():
            ans += 1

print(ans)



Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 3e5 + 5, md = 1e9 + 7;

inline int add(int x, int y) {
    x += y;
    if(x >= md) x -= md;
    return x;
}

inline int sub(int x, int y) {
    x -= y;
    if(x < 0) x += md;
    return x;
}

inline int mul(int x, int y) { return 1ll * x * y % md; }

inline int fpow(int x, int y) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = mul(ans, x);
        y >>= 1; x = mul(x, x);
    }
    return ans;
}

ll a[N];
int n, ans;

int main() {
    read(n);
    for(register int i = 1; i <= n; i++) read(a[i]);
    for(register int bit = 0; bit < 60; bit++) {
        int cnt = 0;
        for(register int i = 1; i <= n; i++) cnt += ((a[i] >> bit) & 1);
        ans = add(ans, mul((1ll << bit) % md, mul(cnt, n - cnt)));
    }
    print(ans, '\n');
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a[33] = {0 ,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k];
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dp = [[0]*n for _ in range(3)]
for i in range(n):
    if n < k:
        if t[i] == 'r':
            dp[2][i] = p
        elif t[i] == 's':
            dp[0][i] = r
        else:
            dp[1][i] = s
    else:
        if t[i] == 'r':
            dp[2][i] = max(dp[0][i-k], dp[1][i-k]) + p
            dp[0][i] = max(dp[1][i-k], dp[2][i-k])
            dp[1][i] = max(dp[0][i - k], dp[2][i - k])
        elif t[i] == 's':
            dp[0][i] = max(dp[1][i - k], dp[2][i - k]) + r
            dp[1][i] = max(dp[0][i - k], dp[2][i - k])
            dp[2][i] = max(dp[0][i - k], dp[1][i - k])
        else:
            dp[1][i] = max(dp[0][i - k], dp[2][i - k]) + s
            dp[0][i] = max(dp[1][i - k], dp[2][i - k])
            dp[2][i] = max(dp[0][i - k], dp[1][i - k])
res = 0
for i in reversed(range(n-k,n)):
    res += max(dp[0][i],dp[1][i],dp[2][i])
print(res)

Measured memory_bytes: 14620
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int number = scan.nextInt();
		int sum = 0;
		int num = number;
		while(number > 0){
			   sum += number % 10;
			   number /= 10;
		}
		
		if(num % sum == 0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define int long long
#define N 411

using namespace std;
const int INF = (int)1e17;

int n, arr[N], dp[N][N], sum[N][N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	for(int i=0; i<n; i++) cin >> arr[i];
	for(int i=0; i<n; i++) {
		int x = 0;
		for(int j=i; j<n; j++) {
			x += arr[j];
			sum[i][j] = x;
		}
	}
	for(int k=0; k<n; k++) {
		for(int i=0; i+k<n; i++) {
			if(k == 0) dp[i][i] = 0;
			else {
				dp[i][i+k] = INF;
				for(int j=i; j<i+k; j++) {
					dp[i][i+k] = min(dp[i][i+k], dp[i][j] + dp[j+1][i+k]);
				}
				dp[i][i+k] += sum[i][i+k];
			}
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

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

using namespace std;

int sum(int n){
    int sum = 0;
    for(int i = 1; i <= n; i++){
        sum += i;
    }
    return sum;
}

int main(){
    int a, b, ans;
    cin >> a >> b;
    
    for(int i = 1; i <= 999; i++){
        if(sum(i)-a == sum(i+1)-b){
            ans = sum(i)-a;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;
struct range {
	int l, r, c;
	range(int l = 0, int r = 0, int c = 0) : l(l), r(r), c(c) {}
	bool operator<(const range &rhs) const {
		return l > rhs.l;
	}
};
bool rcomp(const range &lhs, const range &rhs) {
	return lhs.r < rhs.r;
}
int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< range > v1(N), v2(N);
	vector< bool > done(N, false);
	rep(i, N) {
		int L, R;
		cin >> L >> R;
		v1[i] = range(L, R, i);
		v2[i] = range(L, R, i);
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end(), rcomp);
	vector< int > s1(N + 1), s2(N + 1);
	rep(i, N) s1[i + 1] = s1[i] + v1[i].l * 2;
	rep(i, N) s2[i + 1] = s2[i] + v2[i].r * 2;
	int ans = 0;
	rep(l, N + 1) for (int r = l - 1; r <= l + 1; r++) {
		if (r < 0 || r > N)
			continue;
		chmax(ans, s1[l] - s2[r]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
def solve(n, w):
    s1, s2 = 0, sum(w)
    res = s2
    for i in range(n):
        s1 += w[i]
        s2 -= w[i]
        res = min(res, abs(s2-s1))
    return res

n = int(input())
w = list(map(int, input().split()))
print(solve(n, w))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> ID(N+5,0);
    rep(i,M){
        int L,R;
        cin >> L >> R;
        ID[L] ++;
        ID[R+1] --;
    }
    int ans = 0;
    repX(i,ID.size(),1){
        ID[i] = ID[i-1] + ID[i];
        if(ID[i]==M)ans ++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
import sys


from inspect import currentframe


def pri(*args):
    names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))


def solve(n, c):
    flat = ord("A")
    vote_count = [[i, 0] for i in range(26)]
    for i in range(n):
        vote_str = c[i]
        vote_count[ord(vote_str) - flat][1] += 1

        vote_count.sort(key=lambda x: x[1])
        if vote_count[-1][1] > vote_count[-2][1] + (n - i - 1):
            print(chr(vote_count[-1][0] + ord("A")) + " " + str(i+1))
            return
        vote_count.sort()
    print("TIE")
    return


if __name__ == '__main__':
    while True:
        n_input = int(input())
        if n_input == 0:
            break
        c_imput = list(map(str, input().split()))

        solve(n_input, c_imput)




Measured memory_bytes: 7420
#include<bits/stdc++.h>
using namespace std;
signed main(){
int n,a[60];
int count=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<=n-1;j++){
count+=a[i]*a[j];
}
}
cout<<count<<"\n";
return(0);
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7
dp = [[0 for _ in range(k+1)] for i in range(n)]

for i in range(n):
    dp[i][0] = 1

sum_a = []
now = 0
for i in a:
    now += i
    sum_a.append(now)
#print(sum_a)
for i in range(n):
    for j in range(1,k+1):
        if sum_a[i] < j:
            dp[i][j] = 0
            break
        dp[i][j] = dp[i][j-1]
        if i > 0:
            dp[i][j] += dp[i-1][j]
            if j>a[i]:
                dp[i][j] -= dp[i-1][j-a[i]-1]

        dp[i][j] %= mod
        #print(i+1,j,dp[i][j])


print(dp[n-1][k])

Measured memory_bytes: 171272
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		int result = 0;
		int[][] array = new int[10][10];
		for(int i = 1; i <= n; i++){
		    int head = Integer.valueOf(String.valueOf(i).substring(0,1));
		    int tail = i%10;
		    array[head][tail]++;
		}
		
		int keta = String.valueOf(n).length();
		for(int i = 1; i <= n; i++){
		    int head = Integer.valueOf(String.valueOf(i).substring(0,1));
		    int tail = i%10;
		    if(tail == 0) continue;
		    result += array[tail][head];
		}
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 41436
# -*- coding: utf-8 -*-

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


K = int(input())

base = [1,2,3,4,5,6,7,8,9]
ans = [1,2,3,4,5,6,7,8,9]

for i in range(100000):
	for j in range(3):
		if ans[i]%10 == 0 and j ==0:
			continue
		elif ans[i]%10 == 9 and j ==2:
			continue
		ans.append(ans[i]*10+j-1+ans[i]%10)

print(ans[K-1])


Measured memory_bytes: 16408
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int n;

	while( cin >> n){
		int count = 0;
		for(int a=0; a<10; a++){
			for(int b=0; b<10; b++){
				for(int c=0; c<10; c++){
					for(int d=0; d<10; d++){
						if((a+b+c+d)==n){count++;}
					}
				}
			}
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    s = input().rstrip()

    print(s.rfind("Z") - s.find("A") + 1)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 63164
import std.stdio;
import std.string;
import std.conv;
import std.math;

void main ()
{
	double a = 100000;
	int n = to!int(chomp(readln()));
	foreach (i; 0 .. n)
	{
		a = a * 1.05;
		if(a % 1000)
			a = a - (a % 1000) + 1000; 
	} 
	writeln(to!int(a));
}

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

int main() {
  int N;
  cin >> N;
  
  for(int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if(A % 2 == 0 && (A % 3 != 0 && A % 5 != 0)) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;  
  return 0;
}

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

int main(void){
	int e,ans;
	while(cin>>e,e){
		int ans = 1e8;
		for(int z=0;z*z*z<=e;++z){
			for(int y=0;y*y<=e-z*z*z;++y){
				int x = e-y*y-z*z*z;
				ans = min(x + y + z, ans);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int		main() {
	int			n;
	int			m;
	int			size;
	int			k;

	cin >> n;
	vector<string>	s(n);
	vector<int>		count(n);	

	for (int i = 0; i < n; i++)
	{
		string	str;

		cin >> str;
		s.at(i) = str;
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (s.at(j) == s.at(i))
			{
				count.at(j)++;
				break;
			}
		}
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		string	str;

		cin >> str;
		for (int j = 0; j < n; j++)
		{
			if (s.at(j) == str)
			{
				count.at(j)--;
				/* break; */
			}
		}
	}
	k = count.at(0);
	for (int i = 1; i < n; i++)
	{
		if (count.at(i) > k)
			k = count.at(i);
	}
	if (k >= 0)
		cout << k + 1;
	else
		cout << 0;
	cout << endl;	
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a > b){swap(a,b);}
    if(c > b){swap(b,c);}
    
    if(a == 5 && b == 7 && c == 5){cout<<"YES"<<endl;}
    else cout<< "NO" << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1e5 + 10;
int n, a[N], t, c[N];
LL s = 0, s1 = 0;
int main() {
	scanf("%d",&n);
	rep(i,1,n) 
		scanf("%d",&a[i]), 
		s += a[i],
		s1 += i;
	if (s % s1) { printf("NO\n"); return 0; }
	else t = s / s1;
	int tmp = a[n];
	rep(i,1,n) {
		LL d = a[i] - tmp; if (d > t) { printf("NO\n"); return 0; }
		if ((t - d) % n) { printf("NO\n"); return 0; }
		c[i] = (t - d) / n;
		tmp = a[i];
	}
	LL cur = 0;
	rep(i,1,n) cur += 1LL * (n - i + 2) * c[i];
	rep(i,1,n) {
		cur -= 1LL * n * c[i];
		if (cur != a[i]) { printf("NO\n"); return 0; }
		cur += t;
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 1024
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N, M, K = map(int, input().split())
uf = UnionFind(N)
direct = [set() for _ in range(N)]
IN = sys.stdin.readlines()
for i in range(M):
    a, b = map(int, IN[i].split())
    a -= 1; b -= 1
    uf.union(a, b)
    direct[a].add(b)
    direct[b].add(a)
for i in range(M, M + K):
    a, b = map(int, IN[i].split())
    a -= 1; b -= 1
    if uf.find(a) == uf.find(b):
        direct[a].add(b)
        direct[b].add(a)
ans = []
for i in range(N):
    cnt = -uf.parents[uf.find(i)] - 1
    cnt -= len(direct[i])
    ans.append(cnt)

print(*ans)


Measured memory_bytes: 127012
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int a = input.nextInt();
    int b = input.nextInt();
    int c = input.nextInt();
    if (a < b && b < c) {
        System.out.println("Yes");
    }
    else {
        System.out.println("No");
    }
    }
}


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

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

#define Canuc80k cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
#define I_AM ios_base::sync_with_stdio(0);
#define FORS(i,a,b,c) for (int i=a;i<=b;i+=c)
#define FORSD(i,a,b,c) for (int i=a;i>=b;i-=c)

const ll N = 1e6 + 1;
const ll M = 1e9 + 7;

int v[N], w[N], f[N];
int n, m;

int main() {
    I_AM Canuc80k

    cin >> n >> m;
    FOR (i, 1, n) 
        cin >> v[i] >> w[i];
    
    f[0] = 0;
    FOR (i, 1, m) {
        FOR (j, 1, n) 
            if (i >= w[j])
                f[i] = max(f[i], f[i - w[j]] + v[j]);
    }

    cout << f[m] << endl;
}



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

int main(){
    string s,ans;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]!='B')ans.push_back(s[i]);
        else {
        if(ans.size()!=0)ans.pop_back();
        }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

// const ll mod = static_cast<ll>(1e9) + 7;
const ll mod = 998244353;

ll N;
vector<ll> D;

const ll MAXN = 100000 + 5;
ll M[MAXN];

ll solve()
{
    if (D[0]) { return 0; }

    ll ans = 1;

    M[0] = 1;

    rep (i, N - 1)
    {
        const ll d = D[i + 1];
        if (d == 0) { return 0; }

        const ll m = M[d - 1];
        if (m == 0) { return 0; }

        ++M[d];

        ans *= m;
        ans %= mod;
    }

    return ans % mod;
}

int main()
{
    cin >> N;

    D.assign(N, 0);
    for (auto&& d : D) { cin >> d; }

    if (D[0] != 0)
    {
        cout << 0 << endl;
        return 0;
    }

    sort(D.begin(), D.end());

    const ll ans = solve();
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int s;
    cin >> s;
    int ax = ceil(sqrt(s));
    int by = ceil(sqrt(s));
    int t = ax * by - s;
//    cout << t << endl;
    for (int ay = 1; ay * ay <= t; ++ay) {
        if (t % ay == 0) {
            if (t / ay <= (int)1e9) {
                int bx = t / ay;
                cout << 0 << " " << 0 << " " << ax << " " << ay << " " << bx << " " << by << endl;
                return 0;
            }
        }
    }
    cout << 0 << " " << 0 << " " << ax << " " << 0 << " " << 0 << " " << by << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int ret = 0;
  int pre = 0;
  for (int i = 0; i < n; ++i) {
    if ((a[i] - pre) % 2) {
      ret ^= n - i;
    }
    pre = a[i];
  }
  puts(ret ? "first" : "second");
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>

const int M = (1e9)+7;

int main()
{
	int h, w;
	cin >> h >> w;
	ll dp[h+1][w+1];

	char arr[h][w];
	for(int i = 0; i < h; i++)
	for(int j = 0; j < w; j++)
	cin >> arr[i][j];
	memset(dp, 0, sizeof(dp));
	
	if (arr[0][0] == '#')
	{
		cout << 0 << endl;
		return 0;
	}
	for(int i = 1; i <= h; i++)
	for(int j = 1; j <= w; j++)
	{
		if (i == 1 && j == 1)
		dp[i][j] = 1;
		else
		{
			if (arr[i-1][j-1] == '.')
			dp[i][j] = (dp[i-1][j]+dp[i][j-1])%M;
		}
		
	}

	cout << dp[h][w] <<  endl;


	return 0;
}

Measured memory_bytes: 12364
import java.util.Scanner;

public class Main {

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

	    long N=gi();
	    long M=gi();
        
	    if(N==1 && M==1) {
	    	System.out.print(1);
	    } else if(N==1){
	    	System.out.print(M-2);
	    } else if(M==1) {
	    	System.out.print(N-2);
	    } else {
	    	System.out.print((M-2)*(N-2));
	    }



	    //System.out.print(max);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s / 100;
  s2 = s / 10 % 10;
  s3 = s % 10;
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  string s,t;cin>>s>>t;vc ss(s.size()),tt(t.size());
  rep(i,s.size())ss[i]=s[i];
  rep(i,t.size())tt[i]=t[i];
  sort(all(ss));sort(all(tt));reverse(all(tt));
  string sd,td;
  rep(i,ss.size())sd+=ss[i];
  rep(j,tt.size())td+=tt[j];
  
  if(sd<td)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}







Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int num;
	int keta;
	
	while (scanf("%d %d", &a, &b) != EOF){
		num = a + b;
		keta = 0;
		while (num > 0){
			num /= 10;
			keta++;
		}
		printf("%d\n", keta);
	}
	return (0);
}
			
	
	

Measured memory_bytes: 600
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;

const int big=1e6+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,i;cin>>n;
	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(n);
	for(i=0;i<n;i++){cin>>a[i];}
	sort(a.begin(),a.end());
	for(i=0;i<n;i++){cin>>b[i];}
	sort(b.begin(),b.end());
	for(i=0;i<n;i++){cin>>c[i];}
	sort(c.begin(),c.end());
	llint ans=0;
	for(i=0;i<n;i++){
		ans+=(llint)(lower_bound(a.begin(),a.end(),b[i])-a.begin())*(n-(upper_bound(c.begin(),c.end(),b[i])-c.begin()));
	}
	cout<<ans<<endl;
	return 0;
}

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


int main(){
  string s;
  int i,n,nnum,wnum,snum,num;

  cin >> s;
  n=s.size();
  nnum=wnum=snum=num=0;
  for(i=0;i<n;++i){
    if(s[i]=='N'){
      nnum++;
    }else if(s[i]=='W'){
      wnum++;
    }else if(s[i]=='S'){
      snum++;
    }else{
      num++;
    }
  }
  if(num>0 && wnum==0){
    cout << "No" << endl;
  }else if(wnum>0 && num==0){
    cout << "No" << endl;
  }else if(nnum>0 && snum==0){
    cout << "No" << endl;
  }else if(snum>0 && nnum==0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int s[10005];
void trip()
{
	for (int i=1;i<=10000;i++)
    {
    	int x,y,z,num=0;
    	for (x=1;x<=sqrt(i);x++)
		{
			if (x*x+3+2*x>i) break;
			for (y=1;y<=sqrt(i);y++)
			{
				if (x*x+y*y+x*y+1+x+y>i) break;
				for (z=1;z<=sqrt(i);z++)
				{
					if (x*x+y*y+z*z+x*y+y*z+x*z>i) break;
					if (x*x+y*y+z*z+x*y+y*z+x*z==i) num++;
				}
			}
		}
		s[i]=num;
	}
}

int main()
{
    int n;
    trip();
    while (~scanf("%d",&n))
    	for (int i=1;i<=n;i++) printf("%d\n",s[i]);
    return 0;
}


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

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

  ll r = 0;
  for (ll i = 1; i <= n; i++) r += i * (n + 1 - i);

  for (int i = 0; i < n - 1; i++) {
    ll u, v;
    cin >> u >> v;
    u--, v--;
    if (u > v) swap(u, v);
    r -= (u + 1) * (n - v);
  }
  cout << r << endl;
}


Measured memory_bytes: 3620
/*
        i Apologize 3la el Habda
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;

long double EPS = 1e-6;


const int N = 3000 + 500;
ld p[N];
ld dp[N][N];
int n;
int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i)
                cin >>p[i];
    for(int i = 0; i <= n; ++i)
            for(int j = 0; j <= n; ++j)
                dp[i][j] = 0;
    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];
    for(int i = 2; i <= n; ++i){
            for(int j = 0; j <= n; ++j){
                    dp[i][j] = dp[i - 1][j] * (1 - p[i]);
                    if(j)
                            dp[i][j] += dp[i - 1][j - 1] * p[i];
            }
    }
    ld ans = 0;
    for(int i = (n + 1)/2; i <= n; ++i){
            ans += dp[n][i];
    }
    cout << fixed << setprecision(12) <<  ans << "\n";
 return 0;
}


Measured memory_bytes: 166016
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define int long long

typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,t,s,e;
vector<P>edge[100005];
int dep[100005];


void dfs1(int v,int u){
    if(u == -1) dep[v] = 0;else dep[v] = dep[u]+1;
	rep(i,edge[v].size()){
		int to = edge[v][i].fi; if(to == u) continue;
		dfs1(to,v);
	}
}
int D[100005];
void dfs3(int v,int u){
	if(u == -1) D[v] = 0; else D[v] = D[u]+1;
	rep(i,edge[v].size()){
		int to = edge[v][i].fi; if(to == u) continue;
		dfs3(to,v);
	}
}
int dist(int a){
    return D[a];
}
bool cmp(const P&a,const P&b){
	if(dist(a.fi) != dist(b.fi)) return dist(a.fi) > dist(b.fi);
	else return a.sc-1LL*edge[a.fi].size()*t < b.sc-1LL*edge[b.fi].size()*t;
}
bool fail = 0;
int cost[100005],cost2[100005];
int mn(int a,int b){ if(dep[a] < dep[b]) return b; else return a; }
void dfs2(int v,int u){ 
	rep(i,edge[v].size()){
		int to = edge[v][i].fi; if(to == u) continue;
		if(cost[mn(v,to)] <= cost2[to]+cost2[v]) fail = 1;
		cost2[to]+=t;
		dfs2(to,v);
	}
	if(v == e){
		puts(fail?"No":"Yes"); exit(0);
	}
	if(cost[mn(u,v)] <= cost2[u]+cost2[v]) fail = 1;
	cost2[u]+=t;
}
signed main(){
	cin >> n >> t >> s >> e;
	rep(i,n-1){
		int a,b,w; scanf("%lld%lld%lld",&a,&b,&w);
		edge[a].pb(mp(b,w));
		edge[b].pb(mp(a,w));
	}
	dfs1(s,-1); dfs3(e,-1);
	repn(i,n){
		sort(edge[i].begin(),edge[i].end(),cmp);
		rep(j,edge[i].size()){
			if(dep[i] > dep[edge[i][j].fi]) continue;
			cost[edge[i][j].fi] = edge[i][j].sc;
		}
	}
	dfs2(s,-1);
}


Measured memory_bytes: 16848
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    ll ans=0;
    map<int,P>m;
    REP(i,n){
        m[a[i]].first=i%2;
    }
    sort(ALL(a));
    REP(i,n){
        m[a[i]].second=i%2;
    }
    for(auto p:m){
        if(p.second.first!=p.second.second)ans++;
    }
    ans/=2;
    OUT(ans);
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

  float pi = 3.1415926535;
  cout << setprecision(12) << 2 * r * pi;
}

Measured memory_bytes: 3728
from functools import reduce

MOD = 1000000007

def comb(n, r):
    if n < 0 or r < 0 or r > n:
        return 0
    r = min(r, n - r)
    if r == 0: return 1

    numer = [n - r + i + 1 for i in range(r)]
    denom = [i + 1 for i in range(r)]

    for i in range(1, r):
        divisor = denom[i]
        if divisor > 1:
            offset = (n - r) % (i + 1)
            for j in range(i, r, i+1):
                numer[j - offset] //= divisor
                denom[j] //= divisor

    # res = 1
    # for i in range(r):
    #     if numer[i] > 1:
    #         res *= numer[i]
    # return res

    return reduce(lambda x, y: x*y if y > 1 else x, numer)
    # return reduce(mul, numer)

def main():
    x, y = map(int, input().split())
    ans = 0
    if (x+y)%3==0 and x <= 2*y <= 4*x:
        n = (x + y) // 3
        r = y - n
        ans = comb(n, r) % MOD
    print(ans)

if __name__ == "__main__":
    import sys
    if sys.platform =='ios':
        sys.stdin=open('in.txt')
    sys.setrecursionlimit(10**6)
    main()


Measured memory_bytes: 32032
S=input()
if S[0]=='S':
    if S[1]=='U':
        print(7)
    else:
        print(1)
elif S[0]=='M':
    print(6)
elif S[0]=='T':
    if S[1]=='U':
        print(5)
    else:
        print(3)
elif S[0]=='W':
        print(4)
else:
        print(2)

Measured memory_bytes: 3060