akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<set>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int p[100010];
int pre[100010],nex[100010];
inline void del(int x){pre[nex[x]]=pre[x],nex[pre[x]]=nex[x];}
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();long long ans=0;
	for(int i=1;i<=n;i++)
	{
		int d=read();
		pre[i]=i-1,nex[i]=i+1;
		p[d]=i;
	}nex[0]=1,pre[n+1]=n;
	for(int i=1;i<=n;i++)
	{
		int now=p[i];
		if(pre[now])ans+=1LL*(pre[now]-pre[pre[now]])*(nex[now]-now)*i;
		if(nex[now]!=n+1)ans+=1LL*(nex[nex[now]]-nex[now])*(now-pre[now])*i;
		del(now);
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1280
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	var grid [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			grid[i][j] = nextInt()
		}
	}
	if grid[0][0] != grid[0][1]+grid[1][0]-grid[1][1] {
		fmt.Printf("No")
		return
	}
	if grid[1][1] != grid[1][2]+grid[2][1]-grid[2][2] {
		fmt.Printf("No")
		return
	}
	if grid[2][2] != grid[2][0]+grid[0][2]-grid[0][0] {
		fmt.Printf("No")
		return
	}
	fmt.Printf("Yes")
	return
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main(void) {
	double x1,y1,x2,y2,xq,yq;
	double tempx,tempy;
	double ansx,ansy;
	double sin1,cos1;
	double angle;
	while(1) {
		if(scanf("%lf,%lf,%lf,%lf,%lf,%lf",
			&x1,&y1,&x2,&y2,&xq,&yq)==-1)break;
		angle=atan2(yq-y1,xq-x1)-atan2(y2-y1,x2-x1);
		sin1=sin(-angle*2);
		cos1=cos(-angle*2);
		tempx=xq-x1;
		tempy=yq-y1;
		ansx=tempx*cos1-tempy*sin1;
		ansy=tempx*sin1+tempy*cos1;
		ansx+=x1;
		ansy+=y1;
		printf("%f %f\n",ansx,ansy);
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int n;
int a[105];
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		int sum = 0;
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", &a[i]);
			sum += a[i];
		}
		sort(a + 1, a + n + 1);
		int ans = 0;
		if(sum % 10 != 0) ans = sum;
		else
		{
			for(int i = 1; i <= n; i++)
			{
				if((sum - a[i]) % 10 != 0)
				{
					ans = sum - a[i];
					break;
				}
			}
		}
		printf("%d\n", ans);
		memset(a, 0, sizeof(a));
	}
	return 0;
}

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

int main() {
  bool left{true};
  string head, tail;
  string S; cin >> S;
  int Q; cin >> Q;
  for (int i{}; i < Q; ++i) {
    int T; cin >> T;
    if (T == 1) {
      left = !left;
    } else {
      int F; cin >> F;
      char C; cin >> C;
      if ((F == 1 && left) || (F == 2 && !left)) {
        head.push_back(C);
      } else {
        tail.push_back(C);
      }
    }
  }
  reverse(head.begin(), head.end());
  S = head + S + tail;
  if (!left) {
    reverse(S.begin(), S.end());
  }

  cout << S << endl;
  return 0;
}


Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                               \
  do {                                                                         \
    cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";                        \
    dump(__VA_ARGS__);                                                         \
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////


int main()
{
  ll n; cin >> n;
  vector<ll> x(n);
  vector<ll> y(n);
  for (int i=0; i<n; i++){
    cin >> x[i];
    cin >> y[i];
  }

  ll az = -LINF;
  ll iz = LINF;
  ll aw = -LINF;
  ll iw = LINF;
  rep(i, n) {
    ll z = x[i] + y[i];
    ll w = x[i] - y[i];
    maxs(az, z);
    mins(iz, z);
    maxs(aw, w);
    mins(iw, w);
  }

  cout << max(az-iz, aw-iw) << endl;

  return 0;
}


Measured memory_bytes: 6344
/*
1. I'm the Future Red Coder :)
2. Hopefully, I'll be Yellow Soon.
*/
#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
ll power(ll a,ll b,ll m=mod) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
/*struct node {
    int l,r,nq;
};
bool compare(const node& a,const node& b) {
    if (a.r != b.r) return a.r<b.r;
    return a.l<b.l;
}*/
/* ******* DSU START ****** */
/*
const int dsusize = (int)1e5+5;
struct node {
    int data;
    int rk,pn;
}dsu[dsusize];
//ll fans;
void initialize(int n) {
    REP(i,1,n) {
        dsu[i].data = 1;
        dsu[i].rk = 0;
        dsu[i].pn = i;
    }
}
int fnd(int i) {
    if (dsu[i].pn != i) dsu[i].pn = fnd(dsu[i].pn);
    return dsu[i].pn;
}
void unn(int i,int j) {
    i = fnd(i);
    j = fnd(j);
    if (i!=j) {
        //fans -= dsu[i].data*dsu[j].data;
        if (dsu[i].rk>dsu[j].rk) {
            dsu[j].pn = i;
            dsu[i].data += dsu[j].data;
        }
        else {
            dsu[i].pn = j;
            dsu[j].data += dsu[i].data;
            if (dsu[i].rk==dsu[j].rk) {
                dsu[j].rk++;
            }
        }
    }
}
*/
/* ******* DSU END****** */

const int N = (int)2e5+5;
const int Q = 250;
ll a[N],b[N];
void solve() {
    int n;
    ll cnt=0;
    cin>>n;
    REP(i,1,n+1) {
        cin>>a[i];
    }
    REP(i,1,n) {
        cin>>b[i];
    }
    REPN(i,n,1) {
        ll temp = min(a[i+1],b[i]);
        a[i+1] -= temp;
        b[i] -= temp;
        cnt += temp;
        temp = min(a[i],b[i]);
        a[i] -= temp;
        b[i] -= temp;
        cnt += temp;
    }
    cout<<cnt;
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    }

     static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    }

    static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    }
}

Measured memory_bytes: 36040
#include <stdio.h>
int main()
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if ((x-r) < 0 || (x+r) > W) {
        printf("No\n");
    } else if ((y-r) < 0 || (y+r) > H){
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int N;
ll X;
ll len[51];
ll p[51];

ll P(int L, ll X) {
  if (L == 1) {
    if (X <= 4)
      return X - 1;
    else
      return 3;
  }
  if (X == 1) return 0;

  if (X <= len[L - 1] + 1) {
    return P(L - 1, X - 1);
  } else if (X > len[L - 1] + 2) {
    return P(L - 1, X - (len[L - 1] + 2)) + 1 + p[L - 1];
  } else if (X == len[L - 1] + 2) {
    return P(L - 1, X - 2) + 1;
  } else {
    // if (X == len[L])
    return len[L - 1] * 2 + 1;
  }
  return 0;
}

int main() {
  int N;
  cin >> N >> X;

  len[0] = 1, len[1] = 5;
  p[0] = 1, p[1] = 3;
  for (int i = 1; i <= 50; i++) {
    len[i] = len[i - 1] * 2 + 3;
    p[i] = 2 * p[i - 1] + 1;
  }

  cout << P(N, X) << endl;
  return 0;
}

Measured memory_bytes: 256
import copy
from collections import deque


def bfs(s, f):
    f[s[0]][s[1]] = 0
    moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    q = deque([s])
    while q:
        c = q.popleft()
        for m in moves:
            my, mx = c[0] + m[0], c[1] + m[1]

            if f[my][mx] == ".":
                f[my][mx] = f[c[0]][c[1]] + 1
                q.append([my, mx])
            else:
                continue

    f = sum(f, [])
    return max([x for x in f if type(x) == int])


def main():
    H, W = map(int, input().split())
    field = []

    for h in range(H + 2):
        field.append(["#"] * (W + 2))
        if 1 <= h <= (H):
            field[h][1:-1] = list(map(str, input().rstrip()))

    ans = 0
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if field[y][x] == ".":
                ans = max(ans, bfs([y, x], copy.deepcopy(field)))

    print(ans)


if __name__ == '__main__':
    main()

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

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

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <random>
#include <vector>
using namespace std;
#define REP(i,N) for(int i=0; i < (int)N; i++)

int main(void){
    string s;
    int a=0;
    int b=0;
    int c=0;
    int ans;
    cin >> s;

    REP(i,3){
        switch(s[i]){
            case 'a':
                a = 1;
                break;
            case 'b':
                b = 1;
                break;
            case 'c':
                c = 1;
            default: break;
        }
    }
    ans = a*b*c;
    if(ans){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

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

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

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

    vector<ll> A(n,0);

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

    ll ans = A[0];

    for(int i=1;i<n;++i)    ans = gcd(ans, A[i]);

    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int c[3][3];
    repi(i, 3, 0)
    {
        repi(j, 3, 0)
        {
            cin >> c[i][j];
        }
    }
    //i,j,k = a1,a2,a3
    repi(i, 101, 0)
    {
        repi(j, 101, 0)
        {
            repi(k, 101, 0)
            {
                if(c[0][0] - i == c[1][0] - j && c[1][0] - j == c[2][0] - k &&
                   c[0][1] - i == c[1][1] - j && c[1][1] - j == c[2][1] - k &&
                   c[0][2] - i == c[1][2] - j && c[1][2] - j == c[2][2] - k ){
                       cout << "Yes" << endl;
                       return 0;
                   }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
(let ((a (read))
      (b (read)))

  (defun judge (x y)
    (cond ((= x y) "Draw")
          ((= x 1) "Alice")
          ((= y 1) "Bob")
          ((< x y) "Bob")
          (t "Alice")))

  (format t "~A~%"
          (judge a b)))


Measured memory_bytes: 23388
#include <iostream>
#include <vector>

using namespace std;

int main() {
    
    int a;
    int b;
  
    cin >> a >> b;
    
    int ans = a*b;
  
   if (ans%2 ==0){
  
  
      cout << "Even" << endl;
    
 
   }else{
     
      cout << "Odd" << endl;
     
   }
     return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
d=[0]*(10**5 +1)#各数字の個数
for i in A:
  d[i]+=1

for i in range(Q):
  B,C=map(int,input().split())
  s += (C-B)*d[B]
  print(s)
  d[C]+=d[B]
  d[B]=0

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

long long md(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int main(){
    int N;
    cin >> N;
    vector<pair<int,int>> vec(N);
    for(int i=0;i<N;i++){
        int A;
        cin >> A;
        vec[i]=make_pair(A,i+1);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<N;i++){
        cout << vec[i].second;
        if(i==N-1)
        cout << endl;
        else
        cout << " ";
    }
}

Measured memory_bytes: 1664
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){ 
    int n; cin>>n; 
    int a[n+1],b[n+1],f,s; 
    for (int i=1;i<=n;i++) {
        cin>>a[i]; 
        b[i]=a[i];
    }
    sort(a+1,a+n+1); 
    if (n&1) f=a[n/2],s=a[n/2+1]; 
    else f=a[n/2],s=a[n/2+1]; 
    for (int i=1;i<=n;i++){
        if (b[i]<=f) cout << s << endl;
        else cout << f << endl;
    }
} 

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 6708
#include<stdio.h>
#define MAX 100
void insertionSort(int*,int);
int main(){
  int N;
  int i;
  int point[MAX];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&point[i]);
  }
  
  insertionSort(point,N);

  return 0;
}

void insertionSort(int *point,int N){
  int i;
  int j;
  int l;
  int key;

  for(i=0;i<N;i++){
    if(i!=N-1){
      printf("%d ",point[i]);
    }
    else{
      printf("%d",point[i]);
    }
  }
  printf("\n");
  for(i=1;i<=N-1;i++){
    key=point[i];
    j=i-1;
    while(j>=0 && point[j]>key){
      point[j+1]=point[j];
      j--;
      point[j+1]=key;
    }
    for(l=0;l<N;l++){
      if(l!=N-1){
	printf("%d ",point[l]);
      }
      else{
	printf("%d",point[l]);
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2084
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  if (n % 2 == 1)
    Cout(0);
  else {
    ans = 2 * n / 2;
    s = to_string(ans);
    rrrep(j, Size(s) - 1, 0) {
      if (s[j] != '0') break;
      // cnt++;
    }
    n /= 2;
    while (1) {
      /* code */
      if (n == 0) break;
      cnt += n / 5;
      n /= 5;
    }
    Cout(cnt);
  }

  return 0;
}

Measured memory_bytes: 256
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

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

const ll maxn = 1000010;

ll n, fact[maxn], ifact[maxn];
ll cnt[maxn];

ll poww(ll a, ll b) {
    ll r = 1;
    while (b) {
        if (b & 1) Mul(r, a);
        Mul(a, a);
        b >>= 1;
    }
    return r;
}

ll ent(ll a, ll b) {
    return a > b ? 0 : fact[b] * ifact[a] % MOD * ifact[b - a] % MOD;
}

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

    fact[0] = 1;
    fori (i, maxn - 1) fact[i + 1] = fact[i] * (i + 1) % MOD;
    ifact[maxn - 1] = poww(fact[maxn - 1], MOD - 2);
    forir (i, maxn - 1) ifact[i] = ifact[i + 1] * (i + 1) % MOD;

    cin >> n;
    fori (i, n) {
        cnt[n - i] = ent(i, n - 2 - i) * fact[i] % MOD * fact[n - 1 - i] % MOD;
    }
    ll s = 0;
    fori (i, n) {
        Add(s, (cnt[i + 1] - cnt[i] + MOD) * i);
    }
    cout << s << '\n';

}


Measured memory_bytes: 23808
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool turn=1;
    while(1){
        if(turn){
            c-=b;
            if(c<=0) return cout<<"Yes",0;
        }
        else{
            a-=d;
            if(a<=0) return cout<<"No",0;
        }
        turn=!turn;
    }
    return 0;
}


Measured memory_bytes: 3652
N,M=map(int,input().split())
Adj = [[0]*N for i in range(1 << N)]
for i in range(M):
    a,b=map(int,input().split())
    Adj[a-1][b-1]=1
    Adj[b-1][a-1]=1


dp = [[0]*N for i in range(1 << N)]
dp[1][0]=1

for S in range(1 << N):
    for v in range(N):
        # if not v in S:
        if S & (1<<v) == 0:
            continue
        
        # sub = S - {v}
        sub = S ^ (1 << v)

        for u in range(N):
            # if u in sub and Adj[u][v] == 1:
            if (1 << u) & sub and Adj[u][v] :
                dp[S][v]+=dp[sub][u]

ans = sum(dp[(1<<N)-1][u] for u in range(1,N))

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000001
using ll=long long;

int main(){
    int n;cin>>n;
    map<string,int> S;
    rep(i,n){
        string s;cin>>s;
        sort(s.begin(),s.end());
        S[s]++;
    }
    
    ll ans=0;
    for(const auto& i:S){
        ans+=(ll)i.second*(ll)(i.second-1)/2;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 8064
n = gets.to_i

ans = 0
dfs = -> (n) {
  stack = [7, 5, 3]
  until stack.empty? do
    x = stack.pop
    s = x.to_s
    if x <= n && s.count('7') >= 1 && s.count('5') >= 1 && s.count('3') >= 1
      ans += 1
    end
    if x > n
      next
    else
      [7, 5, 3].each {|c| stack.push(x * 10 + c)}
    end
  end
}
dfs.call(n)

puts ans



Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<numeric>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    LL coa=0,cob=0;
    CIN(N);
    I vec;
    REP(a,N){
        CIN(b);
        if(b%2==0)coa++;
        if(b%2==1)cob++;
        vec.pb(b);
    }
    coa += cob/2;
    cob %= 2;
    while(coa != 0&&coa != 1){
        int s = (coa / 2);
        coa -= 2*s;
        coa += s;
        //COUT(coa);
    }
    YES(coa+cob==1);
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>

int main()
{
  int N,A,B,C,a,b,c,i,j,k,X,Y,x,y,z;
 
  scanf("%d",&N);
  scanf("%d",&Y);

  x=y=z=-1;
  
  A=Y/10000;
  if(A>N)
  {
    A=N;
  }
  
  for(a=0;a<=A && x<0;a++)
  {
    X=Y-10000*a;
    B=X/5000;
    for(b=0;b<=B && a+b<=N && x<0;b++)
    {
      X=Y-10000*a-5000*b;
      c=X/1000;
      
      if(X%1000==0 && a+b+c==N && c>=0)
      {
        x=a;
        y=b;
        z=c;
      }
      
    }
    
  }
  
  printf("%d %d %d",x,y,z);
  
  return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	MAX_N      = 10000
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

type Neighbor struct {
	node   int
	weight int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]Neighbor, error) {
	adjacentMatrix := make([][]Neighbor, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = []Neighbor{}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id] = append(adjacentMatrix[id], Neighbor{v, c})
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]Neighbor) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]Neighbor) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for _, neighbor := range adjacents {
		edges = append(edges, Edge{start: currentNode, end: neighbor.node, weight: neighbor.weight})
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}



Measured memory_bytes: 25352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)	   for(int i = 0; i < (n); ++i)
#define all(c)		   begin(c), end(c)
#define rall(c)		   rbegin(c), rend(c)
#define SZ(a)		   ((ll) a.size())

typedef long long		   ll;
typedef unsigned long long ull;


int main(){
  int A,B;
  cin >> A >> B;
  char iro1,iro2;
  iro1='.';
  iro2='#';
  if(A>B){
    swap(A,B);
    swap(iro1,iro2);
  }
  cout << 100 << " " << 100 << endl;
  int retsu=0;
  int gyou=0;
  int Bnum=0;
  rep(i,A-1){
    if(retsu==100){
      retsu=0;
      gyou++;
      cout << endl;
    }
    if(gyou%2==0){
      cout << iro1;
      cout << iro2;
    }
    else{
      cout << iro2;
      cout << iro1;
    }
    retsu+=2;
  }
  Bnum=max(A-50,1);
  rep(i,100-retsu) cout << iro2;
  cout << endl;
  rep(i,100) cout << iro2;
  cout << endl;
  rep(i,100) cout << iro1;
  cout << endl;
  gyou+=3;
  retsu=0;
  FOR(i,Bnum,B){
    if(retsu==100){
      retsu=0;
      gyou++;
      cout << endl;
    }
    if(gyou%2==0){
      cout << iro1;
      cout << iro2;
      cout << iro1;
      cout << iro1;
    }
    else{
      cout << iro1;
      cout << iro1;
      cout << iro2;
      cout << iro1;
    }
    retsu+=4;
  }
  rep(i,100-retsu) cout << iro1;
  cout << endl;
  gyou++;
  FOR(i,gyou,100){
    rep(j,100)  cout << iro1;
    cout << endl;
  }
}


Measured memory_bytes: 256
// AOJ 2536: Median Tree
// 2017.11.30 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 1002

/* UNION-FIND library */
int p[MAX], rank[MAX];

void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

typedef struct { int s, t, c; } T;
T e[10002], e2[10002];

char buf[30], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int f[1001];
void distsort(m)
{
	int i, x;
	T *ep;

	memset(f, 0, sizeof(f));
	for (ep = e, i = 0; i < m; i++, ep++) f[ep->c]++;
	for (i = 0; i <= 1000; i++) f[i] += f[i-1];
	for (i = m; i--;) x = e[i].c, e2[--f[x]] = e[i];
}

int Kruskal(int n, int m) 
{ 
	int i, c;
	T *ep;

	for (i = 1; i <= n; i++) make_set(i);
	distsort(m);
	c = 1+(n-1)/2;
	for (ep = e2; m--; ep++) {
		if (find_set(ep->s) != find_set(ep->t)) { 
			union_set(ep->s, ep->t); 
			if (--c == 0) return ep->c; 
		} 
	}
	return 0;
} 

int main()
{
	int n, m, i;

	while (fgets(bp=buf, 30, stdin) && *bp != '0') {
		n = getint(), bp++, m = getint();
		for (i = 0; i < m; i++) {
			fgets(bp=buf, 30, stdin);
			e[i].s = getint(), bp++, e[i].t = getint(), bp++, e[i].c = getint();
		}
		printf("%d\n", Kruskal(n, m));
	}
	return 0;
}

Measured memory_bytes: 1984
from operator import itemgetter

n=int(input())
XL=[list(map(int,input().split())) for _ in range(n)]

for i in range(n):
    XL[i].append(XL[i][0]+XL[i][1])

XL.sort(key=itemgetter(2))

cnt=1
choice=0

for i in range(n):
    if XL[choice][2]<=XL[i][0]-XL[i][1]:
        choice=i
        cnt+=1

print(cnt)

Measured memory_bytes: 94812
N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
ac = sum(A)
count = 0
for i in range(N):
    if A[i] >= ac / (4*M):
        count += 1
if count >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	auto f = [](ll a,ll b){
		string A = to_string(a) ;
		string B = to_string(b) ;
		return max((ll)A.size(),(ll)B.size()) ;
	} ;
	ll n ; cin >> n ;
	ll ans = INF ;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ans = min(ans,f(i,n/i)) ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> A;
    cin >> B;
    cin >> C;

    if(A==B&&B==C) cout << "No" << endl;
    else if(A!=B&&B!=C&&A!=C) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,E)> G;
  typedef function<T(E,E)> H;
  int n;
  G g;
  H h;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(){};
  SegmentTree(int n_,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>()):
    g(g),h(h),d1(d1),d0(d0){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(n,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i]=v[i];
  }
  void update(int a,int b,E x,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return;
    }
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
  }
  void update(int a,int b,E x){
    update(a,b,x,0,0,n);
  }
  T query(int k){
    T c=dat[k];
    k+=n-1;
    E x=laz[k];
    while(k>0){
      k=(k-1)/2;
      x=h(x,laz[k]);
    }
    return g(c,x);
  }
};
//END CUT HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> raq(n,
			   [](int a,int b){return a+b;},
			   [](int a,int b){return a+b;},
			   0,0);
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>x;
      cout<<raq.query(x-1)<<endl;
    }else{
      cin>>s>>t>>x;
      raq.update(s-1,t,x);
    }
  }
  return 0;
}

/*
  verified on 2017/11/05
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E&lang=jp
*/

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

int main() {
  int D, T, S;
  cin >> D >> T >> S;
  string ans = S * T >= D ? "Yes" : "No";
  cout << ans << endl;
}


Measured memory_bytes: 3624
ans = 'Yes'
pr = []
n = int(input())
w = input()
pr.append(w)
e = w[-1]
for i in range(n-1):
    w = input()
    if e != w[0] or w in pr:
        ans = 'No'
    pr.append(w)
    e = w[-1]
print(ans)


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

using namespace std;

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

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 998244353

inline ll madd(ll a, ll b) { return (a+b)%MOD; }
inline ll msub(ll a, ll b) { return (a-b+MOD)%MOD; }
inline ll mmul(ll a, ll b) { return (a*b)%MOD; }
inline ll msq(ll a) { return (a*a)%MOD; }

ll inverse(ll a, ll m) {
	ll m0 = m, t, q;
	ll x0 = 0, x1 = 1;
	if(m == 1) return 0;
	while(a > 1) {
		// q is quotient
		q = a/m, t = m;
		// m is remainder now
		m = a % m, a = t;
		t = x0;
		x0 = x1 - q * x0;
		x1 = t;
	}
	// Make x1 positive
	if(x1 < 0) x1 += m0;
	return x1;
}


const int MAXN = 2e5 + 50;
ll a[MAXN];
int n;
void readInput() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
}


const int MAXA = 1e6 + 50;
ll w[MAXA];
void calcW() {
	for(ll d = 1; d < MAXA; d++) {
		w[d] = madd(w[d], inverse(d, MOD));
		for(ll k = 2; k*d < MAXA; k++)
			w[k*d] = msub(w[k*d], w[d]);
	}
}


int cnt[MAXA];
ll s1[MAXA], s2[MAXA];
void solve() {
	for(int i = 1; i <= n; i++)
		cnt[a[i]]++;

	for(ll d = 1; d < MAXA; d++) {
		for(ll k = 1; k*d < MAXA; k++) {
			s1[d] = madd(s1[d], mmul(cnt[k*d], k*d));
			s2[d] = madd(s2[d], mmul(cnt[k*d], msq(k*d)));
		}
	}

	ll ans = 0;
	for(ll d = 1; d < MAXA; d++)
		ans = madd(ans, mmul(w[d], msub(msq(s1[d]), s2[d])));
	printf("%lld\n", mmul(ans, inverse(2, MOD)));;
}



int main() {
	readInput();
	calcW();
	solve();
}

Measured memory_bytes: 29184
while True :
  a, p = map(int, input().split())
  if(a == 0 and p== 0) :
    break
  else :
    m = ["A", "B", "C", "D", "E"]
    shop = list()
    shop.append(a + p)
    for i in range(4) :
      a, p = map(int, input().split())
      shop.append(a + p)
    top = max(shop)
    Shop = shop.index(top)
    print(m[Shop], top)


Measured memory_bytes: 5596
# import math
# import statistics
# import itertools
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
#e1,e2= map(int,input().split())
# f = list(map(int,input().split()))
#g = [input() for _ in range(e1)]
n=1
while True:
    if 360*n%a==0:
        print(360*n//a)
        exit()
    else:
        n+=1




Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b == c || b + c == a || c + a == b){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int n,m,x,l,r,a[100],i,l1,r1;
    cin>>n>>m>>x;
    for(i=1;i<=m;i++)
    {
        cin>>a[i];
    }
    l=x;r=n-x;l1=0;r1=0;
    for(i=1;i<=m;i++)
        if(a[i]<l)
    {
        l1++;
    }
    for(i=1;i<=m;i++)
        if(a[i]>x)
    {
        r1++;
    }
    if(r1<l1)
    {
        cout<<r1;
    }
    if(r1>l1)
    {
        cout<<l1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
const int ESIZE = MAXN << 1;
int n, m;
int et = 1, fir[MAXN], to[ESIZE], ne[ESIZE], len[ESIZE];
int col[MAXN];
long long A[5], ans;

void link(int u, int v) {
    to[++et] = v, ne[et] = fir[u], fir[u] = et;
    to[++et] = u, ne[et] = fir[v], fir[v] = et;
    len[et - 1] = 1, len[et] = -1;
}

bool dfs(int o, int fa, int c) {
    A[col[o] = c]++, A[3]++; bool flag = 1;
    for (int i = fir[o]; i; i = ne[i]) {
        A[4]++;
        if (i != fa) {
            if (col[to[i]] == -1)
                flag &= dfs(to[i], i ^ 1, (c + len[i] + 3) % 3);
            else if (col[to[i]] != (c + len[i] + 3) % 3)
                flag = 0;
        }
    }
    return flag;
}

int main() {
    scanf("%d %d", &n, &m);
	for (int i = 1, x, y; i <= m; i++) {
		scanf("%d %d", &x, &y);
        link(x, y);
    }
    for (int i = 1; i <= n; i++)
        col[i] = -1;
    for (int i = 1, res; i <= n; i++)
        if (col[i] == -1) {
            A[0] = A[1] = A[2] = A[3] = A[4] = 0;
            res = dfs(i, 0, 0);
            if (res)
                ans += A[0] && A[1] && A[2] ? A[0] * A[1] + A[1] * A[2] + A[2] * A[0] : A[4] >> 1;
            else
                ans += A[3] * A[3];
        }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    vector<int> S = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
    
    int N;
    cin >> N;
    vector<int> dp(N + 1, 1001000100);
    dp[0] = 0;
    rep(i, N + 1) {
        for (int x : S) {
            if (i + x <= N) {
                dp[i + x] = min(dp[i + x], dp[i] + 1);
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N];
        int[] F = new int[N];
        long allcost = 0;

        for(int i=0; i<N; i++){
            A[i]=sc.nextInt();
            allcost = allcost + A[i];
        }

        for(int i=0; i<N; i++){
            F[i]=sc.nextInt();
        }

        if(allcost<=K){
            System.out.println(0);
            return;
        }
        Arrays.sort(A);
        Arrays.sort(F);

       long ok = A[N-1]*(long)F[N-1];
        long ng = 0;

        while(ok-ng>1){
            long h = (ok+ng)/2;
            long tot = 0;
            for(int i=0; i<N; i++){
                tot = tot+Math.max(A[N-i-1]-h/F[i], 0);
            }
            if(tot>K){
                ng = h;
            }else{
                ok = h;
            }
        }
        System.out.println(ok);
        
    }
}


Measured memory_bytes: 62688
#include <bits/stdc++.h>
#ifdef DOC
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) \
_FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) \
_FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) \
_FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) \
_FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) \
_FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                  \
    _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1) \
    (MACRO, __VA_ARGS__)
#define watch(x) cerr << #x " = " << (x) << "; ";
#define debug(...)                       \
    cerr << "Line " << __LINE__ << ": "; \
    FOR_EACH_MACRO(watch, __VA_ARGS__)   \
    cerr << endl
#else
#define debug(...)
#endif

using namespace std;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c)
{
    os << '[';
    for (auto it = begin(c); it != end(c); ++it)
        os << (it == begin(c) ? "" : ", ") << *it;
    return os << ']';
}
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
#define ALL(vt) vt.begin(), vt.end()
#define ALLR(vt) vt.rbegin(), vt.rend()
int solve(){
    int n; cin >> n;
    vector<vector<int>> p(3, vector<int> (n));
    R(i, 0, n){
        cin >> p[0][i] >> p[1][i] >> p[2][i];
    }
    vector<int> dp(3, 0);
    dp[0] = p[0][0]; dp[1] = p[1][0]; dp[2] = p[2][0];
    R(i, 1, n){
        int a,b,c;
        a = dp[0]; b = dp[1]; c = dp[2];

        dp[0] = max(b + p[0][i], c + p[0][i]);
        dp[1] = max(a + p[1][i], c + p[1][i]);
        dp[2] = max(a + p[2][i], b + p[2][i]);
        // debug(dp);
    }
    return max({dp[0], dp[1], dp[2]});
}
int main(){
    cout << solve();
}

Measured memory_bytes: 1792
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1e9, maxn=2e5+5;

int n,a[maxn],sum[maxn];

signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]), a[i] -= i;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)sum[i] = sum[i-1]+a[i];
	
	LL ans=1e18;
	for(int k=1;k<=n;k++){
		int oth = sum[k] - (sum[n]-sum[k]);oth *= -1;
		int id = 2*k-n;
		if(id > 0 || k == n)ans = min(ans,oth+id*a[k]);
		else ans = min(ans,oth+id*a[k+1]);
//		printf("%lld\n",oth);
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3328
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	bool IsEven = (n % 2 == 0);
	list<int> l;
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0)
			l.push_back(a[i]);
		else
			l.push_front(a[i]);
	}
	if (!IsEven) l.reverse();
	for (auto& xx : l) cout << xx << " ";
	cout << endl;
}

Measured memory_bytes: 9216