akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<vector<int>> g(401);
const int INF  = 1e9;
int main()
{
  int h,w; cin>>h>>w;
  char a[h][w];
  int d[410][410];
   for(int  i = 0 ; i < 410 ; i++)
    for(int j = 0 ; j < 410; j++)
        d[i][j] = INF;
  for(int i =  0 ; i < 410 ; i++)
    d[i][i] = 0;
  for(int i = 0 ; i < h ; i++ )
  {
    string s; cin>>s;
    for(int j = 0 ; j < w; j++)
      a[i][j] = s[j];
  }
  vector<int> elig;
  for(int i = 0 ; i < h ; i++)
  {
    for(int j = 0 ; j < w; j++)
    {
      if(a[i][j]=='.')
      {
          elig.push_back(i*w+j);
        if(j<w-1)
        { 
          if(a[i][j+1]=='.')
          {
            d[i*w+j][i*w+j+1] = 1;
            d[i*w+j+1][(i)*w+j] = 1;
            elig.push_back(i*w+j+1);
          }
        }
        if(i<h-1)
        {
          if(a[i+1][j]=='.')
          {
            d[i*w+j][(i+1)*w+j] = 1;
            d[(i+1)*w+j][(i)*w+j] = 1;
            elig.push_back((i+1)*w+j);
          }
        }
      }
    }
  }
  int V = elig.size();
  for(int i : elig)
    for(int j : elig)
        for(int k : elig)
            if(d[i][j]+d[i][k]<d[j][k])
 			    d[j][k] = d[i][j]+d[i][k];
  int ans = -1;
   
  for(int i = 0 ; i < 410 ; i++)
    for(int j = 0 ; j < 410 ; j++)
      if(d[i][j]!=INF)
        ans = max(ans,d[i][j]);
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 896
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.ArrayLong(3);
            Console.WriteLine((a[0] + a[1] >= a[2])?"Yes":"No");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <cstring>
#include <memory>
#include <map>

using namespace std;

#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FILL(m,v)           memset(m, v, sizeof(m))

int b[1001], x[1001], y[1001];
double wf[1001][1001];
int rt[1001][1001];

const double inf = 1e12;
map<int,int> id, rid;

void trace(int s, int g){
    int r = rt[s][g];
    if(g == r){
        cout << " " << id[g];
        return;
    }
    trace(s,r);
    trace(r,g);
}

int main(){
    int n, m;
    while(cin >> n && n){
        FILL(x, 0);
        FILL(y, 0);
        FILL(rt, 0);
        REP(i,1001) REP(j,1001) wf[i][j] = inf;
        REP(i,n){
            cin >> b[i] >> x[i] >> y[i];
            id[i] = b[i];
            rid[b[i]] = i;
        }
        REP(i,n) REP(j,n){
            if(i == j){
                wf[i][j] = 0;
                continue;
            }
            int dist = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            if(dist <= 50*50){
                wf[i][j] = sqrt((double)dist);
                rt[i][j] = j;
            }
        }
        REP(k,n) REP(i,n) REP(j,n) {
            if(wf[i][j] > wf[i][k] + wf[k][j]){
                wf[i][j] = wf[i][k] + wf[k][j];
                rt[i][j] = k;
            }
        }

        cin >> m;
        int s,g;
        REP(i,m){
            cin >> s >> g;
            s = rid[s], g = rid[g];
            if(wf[s][g] == inf){
                cout << "NA" << endl;
                continue;
            }
            cout << id[s]; trace(s,g); cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 12964
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
bitset<4000001> dp;
int main() {
	int N;
	cin >> N;
	dp[0] = 1;
	int S = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		S += A;
		dp |= dp << A;
	}
	for (int i = (S + 1) / 2; i <= S; i++) {
		if (dp[i]) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	int n,m;
	cin>>n>>m;
	if(n>=m){
		cout<<0<<endl;
		return 0;
	}
	vector<int>x(m),sa(m-1);
	for(int i=0;i<m;i++)cin>>x[i];
	sort(x);
	for(int i=1;i<m;i++){
		sa[i-1]=x[i]-x[i-1];
	}
	unsort(sa);
	for(int i=0;i<n-1;i++){
		ans+=sa[i];
	//	cout<<sa[i]<<endl;
	}
	cout<<x[m-1]-x[0]-ans<<endl;
}


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

int main()
{
	int m[2],d[2];

	cin >> m[0] >> d[0];
	cin >> m[1] >> d[1];

	if (m[0] != m[1]) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
char c[2][60];
int main(){
    cin>>n;
    for(int i=0;i<2;i++)for(int j=0;j<n;j++)cin>>c[i][j];
    long long ans=1LL;
    int i=0;
    while(i<n){
        if(c[0][i]==c[1][i]){
            if(i==0) ans*=3;
            else if(c[0][i-1]==c[1][i-1])ans*=2;
            i++;
        }else{
            if(i==0) ans*=6;
            else if(c[0][i-1]==c[1][i-1])ans*=2;
            else ans*=3;
            i+=2;
        }
        ans%=1000000007;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int MAX_N=1e5+5;

long long a[MAX_N];
long long dp[2][MAX_N];

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  dp[0][1]=a[0]+a[1];
  dp[1][1]=-a[0]-a[1];
  for(int j=2;j<n;j++){
    dp[0][j]=max(dp[0][j-1]+a[j],dp[1][j-1]+a[j]);
    dp[1][j]=max(dp[0][j-1]-a[j]-2*a[j-1],dp[1][j-1]-a[j]+2*a[j-1]);
  }
  cout<<max(dp[0][n-1],dp[1][n-1])<<endl;

}


Measured memory_bytes: 2560
//
//  main.cpp
//  dodecagon
//
//  Created by SZhang on 7/20/19.
//  Copyright © 2019 SZhang. All rights reserved.
//

#include <iostream>
using namespace std;

int main() {
    // insert code here...
    int r;
    cin>>r;
    cout<<r*r*3<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main{

	int[][] e;
	int[][] dist;
	
	int INF = 1<<29;
	
	void run(){
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			e = new int[n][n];
			//0: can use 1:tochuu 2:cant use
			dist = new int[n][3];
			for(int[]ee:e)Arrays.fill(ee, INF);
			for(int[]d:dist)Arrays.fill(d, INF);
			while(m--!=0){
				int s = sc.nextInt()-1, t = sc.nextInt()-1, c = sc.nextInt();
				e[s][t] = e[t][s] = Math.min(e[s][t], c);
			}
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(n, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return dist[o1[0]][o1[1]] - dist[o2[0]][o2[1]];
				}
			});
			dist[0][0] = 0;
//			debug(e); debug(dist);
			q.add(new int[]{0, 0});
			int res = INF;
			while(!q.isEmpty()){
				int[] V = q.poll();
				int p = V[0], s = V[1];
				if(p==n-1&&s!=1){
					res = Math.min(res, dist[p][s]);
				}
				if(s==0){
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s] + e[p][nx];
						if(w < dist[nx][0]){
							dist[nx][0] = w; q.add(new int[]{nx, 0});
						}
						w = dist[p][s];
						if(w < dist[nx][1]){
							dist[nx][1] = w; q.add(new int[]{nx, 1});
						}
					}
				}
				else if(s==1){
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s];
						if(w < dist[nx][2]){
							dist[nx][2] = w; q.add(new int[]{nx, 2});
						}
					}
				}
				else{
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s] + e[p][nx];
						if(w < dist[nx][2]){
							dist[nx][2] = w; q.add(new int[]{nx, 2});
						}
					}
				}
			}
			System.out.println(res);
		}
	}
	
//	void debug(Object...o){
//		System.out.println(Arrays.deepToString(o));
//	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
whn=input().split(" ")
W=int(whn[0])
H=int(whn[1])
N=int(whn[2])
a=[]
for i in range(N):
    a.append(input().split(" "))

left=0
right=W
top=H
bottom=0

for i in range(N):
    if a[i][2]=="1":
        if left<int(a[i][0]):
            left=int(a[i][0])
    elif a[i][2]=="2":
        if right>int(a[i][0]):
            right=int(a[i][0])
    elif a[i][2]=="3":
        if bottom<int(a[i][1]):
            bottom=int(a[i][1])
    elif a[i][2]=="4":
        if top>int(a[i][1]):
            top=int(a[i][1])


if left>=right:
    print(0)
elif top<=bottom:
    print(0)
else:
    print((top-bottom)*(right-left))
    


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    int indB=0;

    cin >> A >> B;

    int a[A];
    int b[B];

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

    int dp[A][2];

    if(a[0]==b[0]) dp[0][0]=1;
    else dp[0][0]=0;

    for(int i=1; i<A; ++i) {
        if(a[i]==b[0]) dp[i][0]=1;
        else dp[i][0]=max(dp[i-1][0],0);
    }

    int ans=0;

    for(int j=1; j<B; ++j) {
        indB=j%2;
        if(a[0]==b[j]) dp[0][indB]=1;
        else dp[0][indB]=0;
        for(int i=1; i<A; ++i) {
            if(a[i]==b[j]) {
                dp[i][indB]=dp[i-1][(indB+1)%2]+1;
                ans=max(dp[i][indB],ans);
            } else {
                dp[i][indB]=dp[i-1][indB];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<math.h>
int main(void){
  int n,i,sum=0,no;
  scanf("%d",&n);
  long A[n],j;
  for(i=0;i<n;i++){
    scanf("%ld",&A[i]);
    if(A[i]==2)
      sum++;
    else if(A[i]%2!=0){
      no=1;
      for(j=3;j<=sqrt(A[i]);j+=2){
        if(A[i]%j==0){
          no=0;
          break;
        }
      }
      if(no==1)
        sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 672
import sys
input = lambda: sys.stdin.readline().rstrip()

N, T = map(int, input().split())

ans = 10 ** 10
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)

print(ans if ans != 10**10 else "TLE")

Measured memory_bytes: 62212
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_A = sum(A)
# print(sum_A)
ans = [0] * (N - 1)
for i in range(N):
    if i == N - 1:
        break
    sum_A -= A[i]
    ans[i] = sum_A
    # print(i, ans)

# print(ans)
ans_num = 0
for i in range(len(ans)):
    ans_num += A[i] * ans[i]

print(ans_num % mod)


Measured memory_bytes: 31524
k=int(input())
if k%2==0:
    print(-1)
    exit()
def solver(k):
    tmp=7%k
    cnt=1
    while cnt <= k:
        if tmp%k != 0:
            tmp=(tmp*10+7)%k
            cnt+=1
        else:
            return cnt
    return -1
        
print(solver(k))

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N;
int a[10010];
int b[10010];
int c[10010];
vector<int> G[10010];
int in[10010];
int s[10010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N;
  REP(i,N-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
    in[a[i]]++;
    in[b[i]]++;
  }
  REP(i,N) cin >> c[i];
  sort(c,c+N);
  queue<int> que;
  set<int> st;
  REP(i,N) {
    if (in[i] == 1) {
      que.push(i);
      st.insert(i);
    }
  }
  int num = 0;
  while (!que.empty()) {
    int v = que.front(); que.pop();
    s[v] = c[num++];
    for (int nv : G[v]) if (st.count(nv) == 0) {
      in[nv]--;
      if (in[nv] == 1) {
        que.push(nv);
        st.insert(nv);
      }
    }
  }
  int ans = 0;
  REP(i,N-1) {
    ans += min(s[a[i]],s[b[i]]);
  }
  cout << ans << endl;
  REP(i,N) {
    cout << s[i] << " \n"[i+1==N];
  }


  return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;


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

    ll A, B, C;
    cin >> A >> B >> C;

    ll ans = B + min(A+B+1, C);
    cout << ans << endl;

    return 0;
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
long long n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	long long ans = 0 ;
	for(long long i = 1ll ; i * i <= n ; ++i)
	{
		if((n - i) % i == 0)
		{
			long long x = (n - i) / i ;
			if(x == 0)
				continue ;
			if(n / x == n % x)
				ans += (n - i) / i ;
		}
	}
	return cout<<ans<<"\n" , 0 ;
}		

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

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// ***************************************

const ll INF = 1e+20;
vector<vector<ll>> dp;

int main(void) {

	int N, K;
	cin >> N >> K;

	vector<ll> A(N);
	for (auto& a : A) {
		cin >> a;
	}
	vector<ll> dp(N, 1e10);
	dp[0] = 0;

	REP(i, N - 1) {
		FOR(j, i + 1, min<ll>(N, i + K + 1)) {
			chmin(dp[j], dp[i] + abs(A[i] - A[j]));
		}
	}
	cout << dp[N - 1] << endl;

	return 0;
}

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

int N;
int ans;
void f(long long n, bool f7, bool f5, bool f3){
  if(n > N) return;
  if(f7 && f5 && f3) ans++;
  f(n*10+7, f7|1, f5, f3);
  f(n*10+5, f7, f5|1, f3);
  f(n*10+3, f7, f5, f3|1);
}
int main() {
  
  cin >> N;
  f(7, true, false, false);
  f(5, false, true, false);
  f(3, false, false, true);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
constexpr long long INF = 1LL << 62;

struct CHT {
    struct Line {
        long long a, b;
        Line(long long a, long long b) : a(a), b(b) {}
        long long get(long long x) { return a * x + b; }
    };
    deque<Line> deq;

    bool check(Line f1, Line f2, Line f3) {
        return (f2.a - f1.a) * (f3.b - f2.b) >= (f2.b - f1.b) * (f3.a - f2.a);
    }

    void insert(long long a, long long b) {
        Line line(a, b);
        while(deq.size() >= 2 && check(*(deq.end()-2), *(deq.end()-1), line)) deq.pop_back();
        deq.push_back(line);
    }

    long long query(long long x) {
        while(deq.size() >= 2 && deq[0].get(x) >= deq[1].get(x)) deq.pop_front();
        return deq.front().get(x);
    }
};


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    long long N, C; cin >> N >> C;
    vector<long long> h(N);
    for(int i=0; i < N; ++i) cin >> h[i];
    
    CHT cht;
    vector<long long> dp(N, INF);
    dp[0] = 0;
    // dp[j] = min(dp[j], hj^2 + hi^2 - 2*hj*hi + C + dp[i])(0 <= i < j)
    // ***  CHT 
    // **   insert(f(x)) : f(x) = -2*a*x + b (a = h[i], b = h[i] * h[i] + dp[i])
    // **   query(x) : value of min f(x)
    cht.insert(-2 * h[0], h[0] * h[0] + dp[0]);
    for(int i=1; i < N; ++i) {
        chmin(dp[i], cht.query(h[i]) + h[i] * h[i] + C);
        cht.insert(-2 * h[i], h[i] * h[i] + dp[i]);
    }

    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 5632
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << -1;
		return;
	}
	ll ost = 0;
	for (int i = 0; i <= 1e7; i++) {
		ost *= 10;
		ost += 7;
		ost %= n;
		if (ost == 0) {
			cout << i + 1;
			return;
		}
	}
	cout << -1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<int(n);i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int,int>;
const ll mod = 1e9+7;

int main(){
  ll a,b,k;
  cin>>a>>b>>k;

  if(a-k>0) cout<<a-k<<" "<<b<<endl;
  else if(b-(k-a)>0) cout<<0<<" "<<b-(k-a)<<endl;
  else cout<<0<<" "<<0<<endl;

  return 0;
}

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

bool graph[710][710], dp[710][710];
int num[710], N, M, cnt[1410];

bool dfs(int key){
    for(int i=1; i<=N; ++i){
        if(i!=key && !graph[key][i]){
            if(num[i]<1){
                num[i]=num[key]-1+(num[key]%2)*2;
                if(!dfs(i)) return false;
            }
            else if(num[i]%2==num[key]%2) return false;
        }
    }
    return true;
}

int main() {
	cin >> N >> M;
	for(int i=0; i<M; ++i){
	    int a, b;
	    cin >> a >> b;
	    graph[a][b]=graph[b][a]=1;
	}
	int now=0;
	for(int i=1; i<=N; ++i){
	    if(num[i]<1){
	        num[i]=now*2+1;
	        if(!dfs(i)){
	            cout << -1 << endl;
	            return 0;
	        }
	        ++now;
	    }
	}
	for(int i=1; i<=N; ++i) ++cnt[num[i]];
	dp[0][0]=1;
	for(int i=0; i<now; ++i){
	    for(int j=0; j+cnt[i*2+1]<=N; ++j) dp[i+1][j+cnt[i*2+1]] |= dp[i][j];
	    for(int j=0; j+cnt[i*2+2]<=N; ++j) dp[i+1][j+cnt[i*2+2]] |= dp[i][j];
	}
	int sol=N/2;
	while(!dp[now][sol]) --sol;
	cout << (sol*(sol-1)+(N-sol)*(N-sol-1))/2 << endl;
	return 0;
}


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

int main() {
    int a, b, c, x, y, tmp = 1e9, ans = 0;
    cin >> a >> b >> c >> x >> y;
    if (x > y) {
        ans = min({a * x + y * b, c * 2 * y + (x - y) * a, 2 * c * x});

    } else
        ans = min({a * x + y * b, 2 * c * x + (y - x) * b, 2 * c * y});

    cout << ans << endl;
}

Measured memory_bytes: 3596
N = int(input())

if N == 1:
  print(1)
  exit()

for i in range(N+1):
    if i == 0:
        L_0 = 2
    elif i == 1:
        L_1 = 1
    else:
        L_2 = L_0 + L_1
        L_0 = L_1
        L_1 = L_2
        
print(L_2)

Measured memory_bytes: 9132
# https://atcoder.jp/contests/abc158/tasks/abc158_c


A, B = gets.split.map(&:to_i)

ai = (A / 0.08).ceil
ax = ((A + 1) / 0.08 - 1).ceil
bi = (B / 0.1).ceil
bx = ((B + 1) / 0.1 - 1).ceil

ans = ([*ai..ax] & [*bi..bx]).min || -1

puts ans


Measured memory_bytes: 3836
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int H, W;
    cin >> H >> W;
    lli count = 0;
  	if(H==1&&W>1){
    	cout << "1" <<endl;
      	return 0;
    }
  	if(H>1&&W==1){
    	cout << "1" <<endl;
      	return 0;
    }
    if (W % 2 == 1)
    {
        for (int i = 0; i < H; i++)
        {
            if (i % 2 == 0)
            {
                count += (int)(W / 2) + 1;
            }
            else
            {
                count += (int)W / 2;
            }
        }
    }
    else
    {
        for (int i = 0; i < H; i++)
        {
            count += (W / 2);
        }
    }
  	cout << count <<endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

int main() {
    ll X, Y ,Z;
    cin >> X >> Y >> Z;
    ll A, B ,C;
    A = Z;
    B = X;
    C = Y;
    cout << A << " " << B << " " << C << endl; 
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool use[n];
    for(int i = 0; i < n; i++) {
        use[i] = false;
    }
    int ac = 0;
    int bc = 0;
    for(int i = 0; i < n; i++) {
        int ma = 0;
        int id = -1;
        for(int j = 0; j < n; j++) {
            if(use[j]) continue;
            if(ma < a[j]) {
                ma = a[j];
                id = j;
            }
        }

        ac += ma;
        if(id == -1) break;
        use[id] = true;

        ma = 0;
        id = -1;
        for(int j = 0; j < n; j++) {
            if(use[j]) continue;
            if(ma < a[j]) {
                ma = a[j];
                id = j;
            }
        }
        if(id == -1) break;
        bc += ma;
        use[id] = true;
    }
    cout << ac - bc << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>

const int mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	int *A = new int[N];
	int *B = new int[N];
	int *C = new int[N - 1];
	for (int i = 0; i < N; i++)scanf("%d", A + i);
	for (int i = 0; i < N; i++)scanf("%d", B + i);
	for (int i = 0; i < N - 1; i++)scanf("%d", C + i);
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += B[i];
		if (i != 0 && A[i] - A[i - 1] == 1) {
			res += C[A[i] - 2];
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	ll q;
	cin >> q;
	while(q--){
		string n;
		cin >> n;
		ll ans = 0;
		while(n.size() > 1){
			if(ans > 10000) break;
			int maxi = 0;
			for(int pos = 1; pos < n.size(); pos++){
				int l = stoi(n.substr(0, pos));
				int r = stoi(n.substr(pos));
				maxi = max(maxi, l * r);
			}
			n = to_string(maxi);
			ans++;
		}
		
		if(ans > 10000) cout << -1 << endl;
		else cout << ans << endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 3292
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}

}

class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
		 int count=0;
		 int res=1;

		 int n = sc.nextInt();
		 int x = sc.nextInt();
		 int[] L =new int[n];
		 for(int i=0;i<n;i++) {
			 L[i]=sc.nextInt();
			 count+=L[i];
			 if(count<=x) {
				 res++;
			 }
		 }
		 
		 System.out.println(res);



	 }
	 }

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

using namespace std;

long long a, b, c, d;

int main() {
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	printf("%lld\n", max(max(a*c, a*d), max(b*c, b*d)));
	return 0;
}


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

using namespace std;

typedef complex<double> P;

string ccw(P a,P b,P c)
{
    P ab=b-a,ac=c-a;
    P tmp=ab*conj(ac);
    if(tmp.imag()>0)
    {
        return "CLOCKWISE";
    }else if(tmp.imag()<0)
    {
        return "COUNTER_CLOCKWISE";
    }else if(tmp.real()<0)
    {
        return "ONLINE_BACK";
    }else if(abs(ac)>abs(ab))
    {
        return "ONLINE_FRONT";
    }else
    {
        return "ON_SEGMENT";
    }
}

int main()
{
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    int q;
    cin>>q;
    while(q--)
    {
        double x,y;
        cin>>x>>y;
        cout<<ccw(P(x1,y1),P(x2,y2),P(x,y))<<endl;
    }

    return 0;
}




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

int main(){
    int N, M;
    cin >> N >> M;
    int max_x;
    int min_y;
    cin >> max_x >> min_y;
    for (int i = 0; i < N; i++){
        int x;
        cin >> x;
        max_x = max(max_x, x);
    }
    for (int i = 0; i < M; i++){
        int y;
        cin >> y;
        min_y = min(min_y, y);
    }
    if (max_x < min_y){
        cout << "No War" << endl;
    }
    else{
        cout << "War" << endl;
    }
}



Measured memory_bytes: 256
# coding: utf-8

from bisect import bisect_left


def leq_search(xs, x, s, t):
    # x以下で最大のindex
    if t-s <= 5:
        res = 0
        for i in range(s, t):
            if xs[i] <= x:
                res = i
        return res

    i = (s+t)//2
    if xs[i] <= x:
        return leq_search(xs, x, i, t)
    else:
        return leq_search(xs, x, s, i)


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    S = [None] * (N+1)
    S[0] = 0
    for i in range(1, N+1):
        S[i] = S[i-1] + A[i-1]

    T = [None] * (M+1)
    T[0] = 0
    for i in range(1, M+1):
        T[i] = T[i-1] + B[i-1]

    n_read = 0
    for i in range(N+1):
        # print(i)
        if S[i] > K:
            break
        n = leq_search(T, K-S[i], 0, M+1)
        # print(n, T, K-S[i])
        if n_read < n + i:
            n_read = n + i
    
    return n_read


print(main())


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int M = 101;

int H, W;
int sx, sy;
short ac[M][M];
string s[M];
short dp[M][M][M][M];

short get(int a, int b, int c, int d) { //[a,c],[b,d]
	if (a > c || b > d) return 0;
	return ac[c+1][d+1] - ac[c+1][b] - ac[a][d+1] + ac[a][b];
}

short calc(int p, int q, int r, int s) {//dead : bottom p, top r, right r, left s
	if (dp[p][q][r][s] != -1) {
		return dp[p][q][r][s];
	}
	short &res = dp[p][q][r][s];
	res = 0;

	if (p + r < H) {
		if (sx - p - 1 >= r) {
			res = max<short>(res, calc(p + 1, q, r, s) + get(sx - p - 1, max(sy - q, s), sx - p - 1, min(sy + s, W - 1 - q)));
		}
		if (sx + r + 1 < H - p) {
			res = max<short>(res, calc(p, q, r + 1, s) + get(sx + r + 1, max(sy - q, s), sx + r + 1, min(sy + s, W - 1 - q)));
		}
	}

	if (q + s < W) {
		if (sy - q - 1 >= s) {
			res = max<short>(res, calc(p, q + 1, r, s) + get(max(sx - p, r), sy - q - 1, min(sx + r, H - 1 - p), sy - q - 1));
		}
		if (sy + s + 1 < W - q) {
			res = max<short>(res, calc(p, q, r, s + 1) + get(max(sx - p, r), sy + s + 1, min(sx + r, H - 1 - p), sy + s + 1));
		}
	}

	return res;
}

int main() {
	cin >> H >> W;
	rep(i, H) cin >> s[i];
	rep(i, H) {
		rep(j, W) {
			ac[i+1][j+1] = ac[i+1][j] + ac[i][j+1] - ac[i][j] + (s[i][j] == 'o');
			if (s[i][j] == 'E') {
				sx = i, sy = j;
			}
		}
	}
	memset(dp, -1, sizeof(dp));

	cout << calc(0, 0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 203648
n = int(input())
a = n**(0.5)
if n%a==0:
    a = a-1
else:
    pass
a = int(a)
#print(a)
ans = 0
for i in range(1,a+1):
    #print(i)
    b = n//i
    if n%b==0:
        b=b-1
    else:
        pass
    #print(b)
    ans += (b-i)*2+1
print(ans)

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

long double dist(int i, int j, vector<vector<int>> p, int d) {
  long long sum = 0;
  for (int k = 0; k < d; k++)
    sum += pow(p.at(i).at(k) - p.at(j).at(k), 2);
  return sqrt(sum);
}

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> p(n, vector<int>(d));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < d; j++) cin >> p.at(i).at(j);
  int cnt = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      if (dist(i, j, p, d) == (int)dist(i, j, p, d)) cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input()) # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(n):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]

l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1, key=lambda d:d[1],reverse=True)

l0.append(("wild card",0))
l1.append(("wild card",0))

if l0[0][0]!=l1[0][0]: #文字が同じ場合
    print(len(num)-l0[0][1]-l1[0][1])
elif n==2:
    print(1)
else:
    print(n-max(l0[0][1]+l1[1][1],l0[1][1]+l1[0][1]))


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

using namespace std;
long n;
long a[100050];
int main(){
cin>>n;
long q=0;
for(int i=1;i<=n;i++)
    {cin>>a[i];
    if(a[i]==i) q++;
    }
  //  cout<<q<<endl;
long dem =0,i=1;
while(q>0&&i<=n)
{if(a[i]==i&&a[i+1]==i+1){dem++;
q=q-2;
i=i+2;
}
else if(a[i]==i)
{
    dem++;
    q=q-1;
    i=i+1;
}
else i++;
//cout<<i<<" "<<dem<<endl;
}

cout<<dem;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1141&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MAX_PRIME = 1000010;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}

int a,d,n;
ll solve(){
    ll res = 0;
    while(n--){
        while(!is_prime[a]) a += d;
        res = a; a+=d;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    init_primes();
    while(cin >> a >> d >> n,a){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 7264
#include <strings.h>
#include <stdio.h>

int min(int a, int b)
{
    return (a > b ? b : a);
}
 
int max(int a, int b)
{
    return (b > a ? b : a);
}
 
int main(void) {
    int i, j, k, h, w;
    int m[501][501];
    int area, hmin;
    char map[500][501];
    int cnt[500][500];
    char str[501];

    while (scanf("%d %d", &h, &w), h + w) {
	area = 0;
#if 1
	bzero(m, sizeof(m));
	for (i = 0; i < h; i++) {
	    scanf("%s", str);
	    for (j = 0; j < w; j++) {
		int c;
		if (str[j] == '*') c = 0;
		else {
		    if (i == 0) c = 1;
		    else c = m[i-1][j]+1;
		}
		m[i][j] = c;
	    }
	}
#else
        for (i = 0; i < h; i++){
            scanf("%s", map[i]);
        }
         
        for (i = 0; i < h; i++){
            for (j = 0; j < w; j++){
                if (i == 0){
                    cnt[i][j] = map[i][j] == '*' ? 0 : 1;
                }
                else {
                    if (map[i][j] == '.'){
                        cnt[i][j] = cnt[i - 1][j] + 1;
                    }
                    else {
                        cnt[i][j] = 0;
                    }
                }
            }
        }
#endif
/*
	for (i = 0; i < h; i++) {
	    for (j = 0; j < w; j++) {
		printf("%d", m[i][j]);
	    }
	    putchar('\n');
	}
*/
#if 1
	for (i = 0; i < h; i++) {
	    for (j = 0; j < w; j++) {
		hmin = 10000000;
		for (k = j; k < w; k++) {
		    if (m[i][k] < hmin) hmin = m[i][k];
		    if (area < hmin * (k-j+1)) area = hmin * (k-j+1);
		}
	    }
	}
#else
        for (i = 0; i < h; i++){
            for (j = 0; j < w; j++){
                hmin = 10000000;
                for (k = j; k < w; k++){
                    hmin = min(cnt[i][k], hmin);
                    area = max(area, (k - j + 1) * hmin);
                }
            }
        }
#endif
	printf("%d\n", area);
    }
    return 0;
}

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

using namespace std;

char s[200000];

int main(){
    int A, B, N;

    cin >> N >> A >> B;

    cin >> s;

    int rank = 0;
    int b_rank = 0;
    for (int i = 0; i < N; i++){
        if (s[i] == 'a' && rank < (A + B)){
            cout << "Yes" << endl;
            rank++;
        }
        else if (s[i] == 'b' && rank < (A + B) && b_rank < B){
            cout << "Yes" << endl;
            rank++;
            b_rank++;
        }
        else {
            cout << "No" << endl;
        }
    }
    return(0);
}


Measured memory_bytes: 896
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define ull signed long long
const ull INF = 1ull << 60;

int main (){
  ull N, D, A;
  cin >> N >> D >> A;
  pair<ull, ull> monster[N];
  for (ull i = 0; i < N; ++i) {
    ull a, b;
    cin >> a >> b;
    monster[i] = make_pair(a, b);
  }
  sort (monster, monster + N);

  ull sum = 0;
  ull damage = 0;
  queue<pair<ull, ull> > que;
  for (ull i = 0; i < N; ++i) {
    // cout << i << " " << sum << " " << damage << endl;
    ull x = monster[i].first;

    while (!que.empty()) {
      ull r = que.front().first;
      ull d = que.front().second;
      if (r < x) {
        damage -= d;
        que.pop();
      } else {
        break;
      }
    }

    ull h = monster[i].second - damage;
    // cout << x << " " << h << endl;


    ull num = 0;
    if (h > 0) {
      num = ((h - 1) / A) + 1;
    }
    damage += num * A;
    sum += num;
    que.push(make_pair(x + 2 * D, num * A));
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 6656
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    if(n>=1000) cout<<"ABD"<<endl;
    else cout<<"ABC"<<endl;
}


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

#define sc(x) scanf("%d",&x);
#define rep(x ,n) for(int x=0; x<n; x++)
#define ll long long
#define finish(x) return cout << x << endl,0;
#define scarr(a,n) for(int x=0; x<n; x++)scanf("%d",&a[x]);

#define MAX_N 100005
#define LOG_N 18
#define SQRT_N 300

struct edge{
    int fr ,to ,col ,dis;
    bool operator==(const edge&rhs) const{
        return fr == rhs.fr && to == rhs.to && col == rhs.col && dis == rhs.dis;
    }
};

int n ,q;
int a ,b ,c ,d;
vector <edge> adj[MAX_N];
map <int ,vector<edge>> edgs;
map <int ,vector<pair<int ,int>>> treed;

int depth[MAX_N] ,dist[MAX_N] ,anc[LOG_N][MAX_N] ,st[MAX_N] ,en[MAX_N] ,id;
void pre(int u){
    st[u] = id++;
    for(edge&e : adj[u]){
        adj[e.to].erase(find(adj[e.to].begin() ,adj[e.to].end() ,edge{e.to ,e.fr ,e.col ,e.dis}));
        depth[e.to] = depth[u]+1;
        dist[e.to] = dist[u]+e.dis;
        anc[0][e.to] = u;
        pre(e.to);
    }
    en[u] = id-1;
}
void dfs(int u ,int c ,vector<pair<int ,int>>&dist){
    for(edge&e : adj[u]){
        dist[e.to] = dist[u];
        if(e.col == c)
            dist[e.to].first += e.dis,
            dist[e.to].second += 1;
        dfs(e.to ,c ,dist);
    }
}
int lca(int u ,int v){
    if(depth[u] < depth[v])
        swap(u ,v);
    int diff = depth[u]-depth[v];
    for(int j=LOG_N-1; ~j; j--)
        if(diff&(1<<j))
            u = anc[j][u];
    if(u == v)
        return u;
    for(int j=LOG_N-1; ~j; j--)
        if(anc[j][u] != anc[j][v])
            u = anc[j][u] ,v = anc[j][v];
    return anc[0][u];
}
bool ispar(int p ,int v){
    return st[p] <= st[v] && en[v] <= en[p];
}

int main()
{
    sc(n)sc(q)
    for(int i=1; i<n; i++){
        sc(a)sc(b)sc(c)sc(d)
        adj[a].push_back({a ,b ,c ,d});
        adj[b].push_back({b ,a ,c ,d});
        edgs[c].push_back({a ,b ,c ,d});
    }

    memset(anc ,-1 ,sizeof anc);
    pre(1);
    for(int j=1; j<LOG_N; j++)
    for(int i=1; i<=n; i++)
        if(~anc[j-1][i])
            anc[j][i] = anc[j-1][anc[j-1][i]];
    for(int c=1; c<n; c++){
        if(edgs[c].size() > SQRT_N){
            treed[c].resize(n+1);
            dfs(1 ,c ,treed[c]);
        }
    }

    for(int i=0; i<q; i++){
        sc(c)sc(d)sc(a)sc(b)
        int lc = lca(a ,b) ,ans = dist[a]+dist[b]-2*dist[lc];
        if(edgs[c].size() <= SQRT_N){
            for(edge&e : edgs[c]){
                if((ispar(lc ,e.fr)&&ispar(lc ,e.to)) && ((ispar(e.fr ,a)&&ispar(e.to ,a)) || (ispar(e.fr ,b)&&ispar(e.to ,b))))
                    ans += -e.dis + d;
            }
        }
        else{
            vector<pair<int, int>>&dist = treed[c];
            int rem = dist[a].first+dist[b].first-2*dist[lc].first;
            int add = dist[a].second+dist[b].second-2*dist[lc].second;
            add *= d;
            ans += -rem + add;
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 32500
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;

}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = 1 + n;

  while(head != tail){
    u = dequeue();
    if(q < u.t){
      c = q; 
    }else{
      c = u.t;
    }
    u.t -= c;
    elaps +=  c;

    if(u.t > 0){
      enqueue(u);
    }else{
      printf("%s %d\n",u.name, elaps);
    }
    
  }

  
  return 0;
}



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

int S(int N){
  int ans = 0;
  while(N){
    ans += N%10;
    N /= 10;
  }
  return ans;
}

int main(){
  int N;
  cin >> N;
  cout << (N%S(N)==0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(int argc, char** argv){
    int N;
    cin >> N;
    vector<pair<int, int>> v(N);
    for (int i=0; i<N; i++) cin >> v[i].second >> v[i].first;
    sort(v.begin(), v.end());

    int t = 0;
    for (int i=0; i<N; i++){
        t += v[i].second;
        if (t > v[i].first) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
char str[11],ch[11];
int n,i;
using namespace std;
bool check(int a,int b){
	if(b==10) b -= 10;
	if(ch[a] == str[b] && ch[a] != '\0') check(a+1,b+1);
	else if(ch[a] == '\0') return true;
	else return false;

}
int main(){
	int j,count;
	while(cin >> ch){
		count = 0;
		cin >> n;
		for(i=0;i<n;i++){
			cin >> str;
			for(j=0;j<10;j++){
				if(ch[0] == str[j]) if(check(0,j)){
					count++;
					break;
				}
			}
		}
		cout << count << endl;
		for(i=0;i<10;i++){
			ch[i] = '\0';
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

ll dfs(vector<vector<ll>> const& tree, const int now, const int from, const int K) {
  int canUseColorNum = K;
  if (from == -1) canUseColorNum -= 1;
  else canUseColorNum -= 2;

  if (tree[now].size() > K) return 0;
  ll canPaintNum = 1;
  for (auto&& itr : tree[now]) {
    if (itr == from) continue;
    canPaintNum *= canUseColorNum--;
    canPaintNum %= MOD;
  }
  for (auto&& itr : tree[now]) {
    if (itr == from) continue;
    canPaintNum *= dfs(tree, itr, now, K);
    canPaintNum %= MOD;
  }

  return canPaintNum;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> tree(n+1);
  rep(i, n-1) {
    int a,b;
    cin >> a >> b;
    --a, --b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  ll ans = k * dfs(tree, 0, -1, k);
  cout << (ans % MOD) << endl;
}


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

namespace AtCoder.ABC106.B
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力値の検証は割愛
            var N = int.Parse(Console.ReadLine());

            var calculator = new Calculator();

            var answer = calculator.GetAnswers(N, divisorsCount: 8);

            Console.WriteLine(answer.Count());
        }
    }

    public class Calculator
    {
        public IEnumerable<int> GetAnswers(int max, int divisorsCount)
        {
            return Enumerable.Range(1, max).Where(i =>
            {
                return i % 2 == 1 && GetDivisors(i).Count() == divisorsCount;
            });
        }

        public IEnumerable<int> GetDivisors(int value)
        {
            return Enumerable.Range(1, value).Where(i => value % i == 0);
        }
    }
}


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

int main(){
	int n;
	while(cin >> n){
		bool f = true;
		for(int i = 1; i <= n; i++){
			int t,x,y;
			scanf("%d%d%d",&t,&x,&y);
			if(t % 2 == 0){
				if(t < x + y) f = false;
				if((x+y) % 2 != 0) f = false;
			}
			else{
				if(t < x + y) f = false;
				if((x+y) % 2 != 1) f = false;
			}
		}
		if(f)
			printf("Yes\n");
		else 
			printf("No\n");			
	}
	
	return 0;
} 

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(new BufferedInputStream(System.in));
		int count = 0;
		String W = scan.nextLine();
		if (W.length() <= 10) {
			while (scan.hasNext()) {
				String T = scan.nextLine();
				if ("END_OF_TEXT".equals(T)) {
					break;
				} else {
					String[] in = T.split(" ");
					for (int i = 0; i < in.length; i++) {
						String str = in[i];
						if (str.length() <= 10) {
							if (W.equalsIgnoreCase(str)) {
								count++;
							}
						}
					}
				}
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 26168
=begin
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
=end
a, b, c = gets.chomp.split.map!{|x| x.to_i}.sort!
if a % 2 == 0 || b % 2 == 0 || c % 2 == 0
    puts(0)
else
    puts(a * b)
end

Measured memory_bytes: 1788