akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

mat As;
ll N, M;
void dfs (ll now, ll length, vec b) {
    if (length == N) {
        // Rep (i, M) {
        //     cout << b[i] << " \n"[i==M-1];
        // }
        As.push_back(b);
        return;
    }
    for (ll i = now; i <= M; i++) {
        vec c = b;
        c.push_back(i);
        dfs(i, c.size(), c);
    }
}

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

    ll Q;
    cin >> N >> M >> Q;

    vec A = {1};
    for (ll i = 1; i <= 1; i++) {
        vec A = {i};
        dfs(1, 1, A);
    }

    // cout << As.size() << "\n";
    // for (auto v : As) {
    //     Rep (i, M) {
    //         cout << v[i] << " \n"[i==M-1];
    //     }
    // }

    vec a(Q), b(Q), c(Q), d(Q);
    Rep (i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    ll ans = 0;


    for (vec v : As) {
        ll tmp = 0;
        Rep (i, Q) {
            if (v[b[i]] - v[a[i]] == c[i]) tmp += d[i];
        }
        chmax (ans, tmp);
    }

    cout << ans << endl;
}

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

#define pb push_back
#define int long long
#define debug(n) cerr << #n << " = " << n << '\n';

using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN] , b[MAXN] , c[MAXN] , dp[MAXN][3];
int32_t main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0]; 
    for(int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0] , dp[i - 1][1]) + c[i];     
    }
    cout << max(dp[n - 1][0] , max(dp[n - 1][1] , dp[n - 1][2]));
    return 0;   
}


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

int main() {
    int N;
    cin >>N;
    vector<string>data(N);
    map<string,int>mp;
    for(int i=0;i<N;i++){
        cin >>data.at(i);
        mp[data.at(i)]++;
    }
    for(int i=0;i<N-1;i++){
        if(mp[data.at(i)]>=2){
            cout<<"No"<<endl;
            return 0;
        }
        else if(data.at(i).at(data.at(i).size()-1) != data.at(i+1).at(0)){
            cout <<"No"<<endl;
            return 0;
        }
    }  
    cout << "Yes"<<endl;
}

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

int main() {
    string s; cin >> s;
    string t[] = { "dreamer", "dream", "eraser", "erase" };

    if (s.size() < 5) {
        cout << "NO" << endl;
        return 0;
    }

    for (int i = 0; i < s.size(); ++i) {
        bool pass = false;
        int lenmax = 0;
        rep(j, 4) {
            if (s.substr(i, t[j].length()) == t[j]) {
                i += t[j].length() - 1;
                pass = true;
                break;
            }
        }
        if (!pass) {
            if (i < 2) { cout << "NO" << endl; return 0; }
            rep(j, 4) {
                if (s.substr(i - 2, t[j].length()) == t[j]) {
                    i += -3 + t[j].length();
                    pass = true;
                    break;
                }
            }
            if (!pass) {
                if (i + 1 >= s.size()) {
                    cout << "NO" << endl;
                    return 0;
                }
                rep(j, 4) {
                    if (s.substr(i + 1, t[j].length()) == t[j]) {
                        i += t[j].length();
                        pass = true;
                        break;
                    }
                }

                if (!pass) {
                    cout << "NO" << endl;
                    return 0;
                }

            }
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		long a = parseLong(sc.next());
		long b = parseLong(sc.next());
		long c = parseLong(sc.next());
		long k = parseLong(sc.next());
		sc.close();
		out.println(k%2==0?a-b:b-a);
	}
}


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

using namespace std;
#define lint long long
#define P pair<int, int>


int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    
    int L[M], R[M];
    int p[Q], q[Q];
    
    for(int i = 0; i < M; ++i){
        cin >> L[i] >> R[i];
    }
    for(int i = 0; i < Q; ++i){
        cin >> p[i] >> q[i];
    }
    
    vector<int> lis[N + 1];
    
    for(int i = 0; i < M; ++i){
        lis[L[i]].push_back(R[i]);
    }
    for(int i = 1; i <= N; ++i){
        sort(lis[i].begin(), lis[i].end());
    }
    
    for(int i = 0; i < Q; ++i){
        int ans = 0;
        for(int j = p[i]; j <= q[i]; ++j){
            ans += upper_bound(lis[j].begin(), lis[j].end(), q[i]) - lis[j].begin();
        }
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

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


#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 100000000;

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

    vector<int> a(n);
    vector<int> b(100005,0);

    rep(i,n){
        cin >> a[i];
        b[a[i]]++;
    }

    int ans = b[0]+b[1];
    rep1(i,100000) ans = max(ans,b[i-1]+b[i]+b[i+1]);

    cout << ans << endl;

}

Measured memory_bytes: 1024
//2020 4.17 Queue 
#include <stdio.h>
#define MAX 1000000

typedef struct {
  char p[10];
  int t;
}A;

int main()
{
  A B[MAX],C[MAX];
  int i,j=0;
  int a,b;
  int temp,cnt,sum=0;
  
  scanf("%d%d",&a,&b);
  for(i=0;i<a;i++)
  {
    scanf("%s%d",B[i].p,&B[i].t);
  }
 
  i=0;
  cnt=a;
  while(cnt!=0)
  {
    temp=B[i].t-b;
    if(temp>0) {B[i].t=temp; B[i+cnt]=B[i]; sum+=b; i++;}
    else if(temp<=0) {B[i].t=B[i].t+sum; C[j]=B[i]; sum=B[i].t; i++; j++; cnt--; }
  }
  
  for(i=0;i<a;i++)
  {
    printf("%s %d\n",C[i].p,C[i].t);
  }
  
  return 0;
}


Measured memory_bytes: 5480
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

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

//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main() {
  deque<char> dq;
  string s;cin >> s;
  int n=s.size();
  dq.pb(s[0]);

  rep(i,n-1){
    if(dq.empty()){dq.pb(s[i+1]);continue;}
    char c=dq.back();
    if(c==s[i+1]) dq.pb(s[i+1]);
    else dq.pop_back();
  }
  cout << n-dq.size();
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var input = Reads();
        var n = input[0];
        var m = input[1];
        Tuple<long, long>[] t = new Tuple<long, long>[n];
        for(long i = 0; i < n; i++)
        {
            var input0 = Reads();
            t[i] = new Tuple<long, long>(input0[0], input0[1]);
        }
        var a = t.OrderBy(b => b.Item1);
        long amount = 0;
        long sum = 0;


        foreach(var x in a)
        {
            if (m - amount > x.Item2)
            {
                sum += x.Item1 * x.Item2;
                amount += x.Item2;
            }
            else
            {
                sum += x.Item1 * (m - amount);
                amount = m;
            }
            if (amount >= m)
                break;
        }
        Console.WriteLine(sum);
        Console.Out.Flush();
    }
}





Measured memory_bytes: 25396
# Problem - 最大の利益

# input
N = int(input())
nums = [0]*N
for i in range(N):
    nums[i] = int(input())

# initialization
min_v = nums[0]
max_v = nums[1] - nums[0]
for i in range(1, N):
    max_v = max(max_v, nums[i] - min_v)
    min_v = min(min_v, nums[i])

# output
print(max_v)



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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    double N;
    std::cin >> N;

    int ans = -1;
    REP(i, N + 10) {
        int price = i * 1.08;
        if(price == N) {
            ans = i;
            break;
        }
    }

    if(ans == -1) {
        std::cout << ":(" << std::endl;
    }
    else {
        std::cout << ans << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  long long int max=0,dp[100001],ddp[100001],n,w,i,j,yen,kg;
  for(i=0;i<=100000;i++){dp[i]=0;ddp[i]=0;}
  cin>>n>>w;
  for(i=0;i<n;i++)
  {
    cin>>kg>>yen;
    for(j=0;j<=w-kg;j++){if(dp[j]+yen>dp[j+kg]){ddp[j+kg]=dp[j]+yen;}}
    for(j=0;j<=w;j++){dp[j]=ddp[j];}
  }
  for(i=0;i<=w;i++){if(dp[i]>max){max=dp[i];}}
  cout<<max;
}

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


if __name__ == '__main__':
    C = [[-1 for i in range(3)] for j in range(3)]
    minv = 101
    min_a_i = -1  # 最小のときのaの添字
    min_b_i = -1
    for a_i in range(3):
        lists = list(map(int, input().split()))
        for b_i in range(3):
            C[a_i][b_i] = lists[b_i]
            if lists[b_i] < minv:
                minv = lists[b_i]
                min_a_i = a_i
                min_b_i = b_i

    # 最小の値から、aとbの取りうる範囲を全探索する
    for v in range(0, minv+1):
        A = [-1]*3
        B = [-1]*3
        A[min_a_i] = v
        for b_i in range(3):
            B[b_i] = C[min_a_i][b_i] - v
        a_i = min_a_i
        for _ in range(2):
            a_i += 1
            if a_i == 3: a_i = 0
            A[a_i] = C[a_i][a_i] - B[a_i]
        # ansCを作って元のCと比較する
        ans = [[-1 for i in range(3)] for j in range(3)]
        for a_i in range(3):
            for b_i in range(3):
                ans[a_i][b_i] = A[a_i] + B[b_i]
        if ans == C:
            print("Yes")
            exit()
    print("No")


Measured memory_bytes: 38512
W,a,b=map(int,input().split())
if a>b:
    if a<=b+W:
        print('0')
    else :
        print(a-b-W)
elif b>a:
    if b<=a+W:
        print('0')
    else :
        print(b-a-W)
else:
    print('0')

Measured memory_bytes: 9100
package main

import "fmt"

func main() {
	var n, m int
	var previous []int

	fmt.Scanf("%d %d", &n, &m)
	for tmp := 0; tmp <= m; tmp++ {
		previous = append(previous, tmp)
	}

	for i := 0; i < n; i++ {
		var now []int
		var k int
		fmt.Scanf("%d", &k)
		for j := 0; j < k; j++ {
			var a int
			fmt.Scanf("%d", &a)
			now = append(now, a)
		}
		previous = Uniform(previous, now)
	}
	fmt.Println(len(previous))
}

func In(a int, list []int) bool {
	for _, b := range list {
		if b == a {
			return true
		}
	}
	return false
}
func Uniform(previous, now []int) []int {
	var res []int
	for _, i := range now {
		if In(i, previous) {
			res = append(res, i)
		}
	}
	return res
}


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

int main(){
    long long A, B, C, D;
    std::cin >> A >> B >> C >> D;
    
    long long total = B - A + 1;
    long long C_num = B / C - (A - 1) / C;
    long long D_num = B / D - (A - 1) / D;
    
    long long large, small;
    if(C > D){
        large = C;
        small = D;
    }else{
        large = D;
        small = C;
    }
    
    long long tmp = large % small;
    while(tmp != 0){
        large = small;
        small = tmp;
        tmp = large % small;
    }
    
    long long CD = C * D / small;
    long long CD_num = B / CD - (A - 1) / CD;
    
    long long cnt = total - C_num - D_num + CD_num;
    
    std::cout << cnt << std::endl;
    
    return 0;
    
}



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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    string tmp;
    if(abs(a-c)<=d) tmp="Yes";
    else if(abs(a-b)<=d&&abs(b-c)<=d) tmp="Yes";
    else tmp="No";
    cout<<tmp<<endl;
}

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

using namespace std;

int main() {
	long long int a, b, x, ans;
	cin >> a >> b >> x;
	if (a != 0) {
		ans = b / x - (a - 1) / x;
	}
	else {
		ans = b / x + 1;
	}

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

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

int n;
string s,c;

int main(){
	cin >> n >> s >> c;
  	
  	string l;
  
  	for (int i=0; i<n; i++){
      l+=s[i];
  	  l+=c[i];
	}
	
  	cout << l << endl;
  
  	return 0;
}

Measured memory_bytes: 256
n = int(input())
txy = [list(map(int, input().split())) for _ in range(n)]
T=X=Y=0
ans = "Yes"

for t,x,y in txy:
  a = (t-T) - (abs(X-x) + abs(Y-y))
  if a % 2 == 0 and abs(X-x) + abs(Y-y) <= t - T:
    T,X,Y = t,x,y
  else:
    ans = "No"
    break
print(ans)

Measured memory_bytes: 27380
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	ll n ; 
	cin >> n;
	vector<ll> A(n);
	rep(i,n) cin>>A[i];
	SORT(A);

	ll ans = A[n/2] - A[n/2 -1];

	cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>


#define ll long long
#define ull unsigned long long

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

    int n;
    std::cin >> n;
    std::vector<int> vec(n);
    for (int i = 0; i < n; ++i) { std::cin >> vec[i]; }
    ll ans = LONG_LONG_MAX, tmp;
    for (int coord = 0; coord <= 100; ++coord)
    {
        tmp = 0;
        for (int d : vec) { tmp += std::pow(d - coord, 2); }
        ans = std::min(ans, tmp);
    }
    std::cout << ans << std::endl;

    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int f(string s){
	int ans = 0, cn=sz(s);
	int dp[9][2] ={};
	dp[0][0] =1;
	rep(i, cn){
		int np[9][2] = {};
		rep(j, 8) rep(d, 10){
			int wj = j;
			if(d==3) wj = j|1;
			else if(d==5) wj = j|2;
			else if(d==7) wj = j|4;
			else if(d==0) wj = j>0? 8 : j;//先頭zero処理
			else wj = 8;
			if(d < s[i] -'0') np[wj][1] += dp[j][0];
			else if(d == s[i] -'0') np[wj][0] += dp[j][0];
			np[wj][1] += dp[j][1];
		}
		swap(dp, np);
	}
	return dp[7][0] + dp[7][1];
}

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	
	
	cout << f(s) <<"\n";
	return 0;
}


Measured memory_bytes: 256
import collections
N=int(input())
S=[input() for i in range(N)]

c=collections.Counter(S)
most=c.most_common()
m_cnt=most[0][1]

dicts=[]

for i in most:
    if i[1]==m_cnt:
        dicts.append(i[0])
    else:
        break
dicts.sort()
for i in dicts:
    print(i)

Measured memory_bytes: 47640
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	string s = readln.chomp;
	
	int[] ans = [-1, -1];
	
	// search for "aa"
	for(int i = 0; i < s.length - 1; i ++){
		if(s[i] == s[i + 1]) ans = [i + 1, i + 2];
		}
	
	// search for "aba"
	for(int i = 0; i < s.length - 2; i ++){
		if(s[i] == s[i + 2]) ans = [i + 1, i + 3];
		}
	
	ans.map!(to!string).join(" ").writeln;
	}



Measured memory_bytes: 536
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

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

    int N;
    cin >> N;
    vector<int> v(N), noten;
    for (int i = 0; i < N; ++i){
        cin >> v[i];
        if (v[i] % 10 != 0) noten.push_back(v[i]);
    }

    int sum = accumulate(v.begin(), v.end(), 0);

    if (sum % 10 != 0) cout << sum << endl;
    else {
        if (noten.size() == 0) cout << 0 << endl;
        else cout << sum - *std::min_element(noten.begin(), noten.end()) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>

using namespace std;

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

class Point{
public:
  double x,y;
  
  Point(double x = 0, double y = 0): x(x),y(y){};
  
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double a) {return Point(a*x,a*y);}

  double own_dot(){return x*x+y*y;};
  double abs(){return sqrt(own_dot());}

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

struct Segment{Point p1,p2;};

double dot(Point a, Point b){
  return a.x*b.x+a.y*b.y;
}
double cross(Point a, Point b){
  return a.x*b.y-a.y*b.x; 
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS) return CLOCKWISE;
  if(dot(a,b) < -EPS) return ONLINE_BACK;
  if(a.own_dot() < b.own_dot()) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4){
  return ( ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 &&
	   ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0);
}

bool isIntersect(Segment s1, Segment s2){
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}


Point in[8];
Segment seg[8];

int main(){
  while(1){
    
    for(int i = 0; i < 4; i+=2)
      if(!(cin >> in[i].x >> in[i].y)) return 0;

    for(int i = 4; i < 8; i+=2)
      cin >> in[i].x >> in[i].y;
    
    in[1] = Point(in[0].x, in[2].y);
    in[3] = Point(in[2].x, in[0].y);
    in[5] = Point(in[4].x, in[6].y);
    in[7] = Point(in[6].x, in[4].y);
    
    for(int i = 0; i < 4; i++){
      seg[i].p1 = in[i];
      seg[i].p2 = in[(i+1)%4];
    }

    for(int i = 4; i < 8; i++){
      seg[i].p1 = in[i];
      if(i == 7) seg[i].p2 = in[4];
      else seg[i].p2 = in[i+1];
    }
 

    bool ans = false;

    if(in[0].x <=  in[4].x && in[0].y <= in[4].y && in[2].x >= in[6].x && in[2].y >= in[6].y ||
       in[0].x >=  in[4].x && in[0].y >= in[4].y && in[2].x <= in[6].x && in[2].y <= in[6].y)
      ans = true;

    for(int i = 0; i < 4; i++)
      for(int j = 4; j < 8; j++)
	ans = (ans||isIntersect(seg[i],seg[j]));


    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

ll n, x, ans, okashi;

int main() {
  cin >> n >> x;
  vector<int> a(n);
  okashi = 0;
  rep (i, n) {
    cin >> a.at(i);
    okashi += a.at(i);
  }
  sort(a.begin(), a.end());
  ans = 0;
  if (okashi >= x) {
    rep (i, n) {
      if (x >= a.at(i)) {
        x -= a.at(i);
        ans++;
      }else{
        break;
      }
    }
  }else{
    ans = n - 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n;
	scanf("%d", &n);
	int arr[4] = {};
	char x[4];
	for(int i = 0; i < n; i++){
		scanf("%s",x);
		if(x[0] == 'A'){
			arr[0]++;
		}else if(x[0] == 'W'){
			arr[1]++;
		}else if(x[0] == 'T'){
			arr[2]++;
		}else if(x[0] == 'R'){
			arr[3]++;
		}
	}
	printf("AC x %d\n", arr[0]);
	printf("WA x %d\n", arr[1]);
	printf("TLE x %d\n", arr[2]);
	printf("RE x %d\n", arr[3]);
	
	
	return 0;
}


Measured memory_bytes: 1736
import scala.io.Source

object Main extends App {
  for (line <- Source.stdin.getLines if line != "0 0") {
    val Array(h, w) = line.split(" ").map(_.toInt)
    for (i <- 1 to h) {
      for ( j <- 1 to w) {
        print { if ((i+j) % 2 == 0) "#" else "." }
      }
      println()
    }
    println()
  }
}

Measured memory_bytes: 54304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/


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

	vector<int> a(3);
	rep(i, 3)cin >> a[i];

	// 一番大きい者に合わせる
	// その値にならない場合は最大値を+1

	sort(allof(a));

	int ans = 0;

	while (a[0] <= a[2] - 2) {
		a[0] += 2;
		ans++;
	}
	while (a[1] <= a[2] - 2) {
		a[1] += 2;
		ans++;
	}

	// これで、a[0]とa[1]がa[2]より1少ないか同じか
	if (a[0] == a[1]) {
		if (a[0] == a[2]) ans += 0;
		else {
			ans++;
		}
	}
	else {
		ans += 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    set<string> t;
    for (int i = 0; i < n; ++i) cin >> s, t.insert(s);
    cout << t.size() << endl;
    return 0;
}


Measured memory_bytes: 19188
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n;
  stack<int> r;
  queue<int> w;
  string s;
  cin >> n >> s;
  rep(i,n)
  {
    if (s[i] == 'W') {
      w.push(i);
    } else {
      r.push(i);
    }
  }
  if (w.size() == 0 || r.size() == 0) {
    cout << 0;
  } else {
    int i = 0;
    while (w.size() != 0 && r.size() != 0 && w.front() < r.top()) {
      w.pop();
      r.pop();
      i++;
    }
    cout << i;
  }
  return 0;
}


Measured memory_bytes: 4400
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  string w;
  std::cin >> w;
  vector<int> counter(24, 0);
  for(int idx = 0; idx < w.size(); idx++){
    counter[(int)(w[idx] - 'a')] += 1;
  }

  bool ans = true;
  for(int idx = 0; idx < 24; idx++){
    if(counter[idx] % 2 == 1) ans = false;
  }

  if(ans){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 510;
int dist[maxn][maxn], a[maxn][maxn];

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    forn(i, n) forn(j, n) {
        a[i][j] = 1;
        dist[i][j] = min(min(i, n - i - 1), min(j, n - j - 1));
    }

    int ans = 0;
    forn(t, n * n) {
        int z;
        cin >> z;
        --z;
        int x = z / n, y = z % n;
        ans += dist[x][y];
        a[x][y] = 0;
        vector<pii> q = {{x, y}};
        forn(cur, q.size()) {
            int x = q[cur].fi, y = q[cur].se;
            forn(d, 4) {
                int xx = x + dx[d], yy = y + dy[d];
                if (min(xx, yy) < 0 || max(xx, yy) >= n) continue;
                int cost = dist[x][y] + a[x][y];
                if (cost >= dist[xx][yy]) continue;
                dist[xx][yy] = cost;
                q.pb({xx, yy});
            }
        }
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
int h,w,n;
int main(){
  cin >> h >> w >> n;
  cout << (h > w? roundup(n,h):roundup(n,w)) << endl; 
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a >= k) cout << k << endl;
  else{
    int ans = a;
    k -= a;
    if(b >= k){
      cout << ans << endl;
    }
    else{
      cout << ans - (k-b) << endl;
    }
  }
}

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

#define ll long long int
using namespace std;

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll A[n]; ll B[m]; ll preA[n+1]; ll preB[m+1];
    preA[0] = 0; preB[0] = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> A[i];
        preA[i+1] = preA[i] + A[i];
    }
    for (ll i = 0; i < m; ++i) {
        cin >> B[i];
        preB[i+1] = preB[i] + B[i];
    }
    ll ans=0;
    ll index = m;
    for (ll i = 0; i <= n; ++i) {
        ll Left = k - preA[i];
        if (Left < 0){
            break;
        }
        while (preB[index] > Left){
            index--;
        }
        ans=max(ans,index+i);
    }
    cout << ans<<endl;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A+B+C==17) {
    if(A==7||B==7||C==7) {
      if(A==5||B==5||C==5) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      cout << "NO" << endl;
    }
  } else {
    cout << "NO" << endl;
  }
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e7 + 1;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

vector<int> cnt(Maxn, 1);

int32_t main() {
    IOS int n;  cin>>n;
    fr(i,2,n+1){
        for(int j=i;j<=n;j+=i)
            cnt[j]++;
    }
    int ans = 0;
    fr(i,1,n+1){
        ans += i*cnt[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81220
import math

n = int(input())

# nが奇数ならば必ず0
if n % 2 == 1:
    print(0)
else:
    s = 0
    p = 0
    while 10 * (5 ** p) <= n:
        s += n // (10 * (5 ** p))
        p += 1
    print(s)


Measured memory_bytes: 9092
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    if (a[n-1] - a[0] > 1) {
        cout << "No" << endl;
        return;
    }
    int index = 0;
    while (a[index] == a[0]) index++;
    if (a[n-1] == a[0]) {
        if (a[0] <= n / 2 || a[0] == n - 1) cout << "Yes" << endl;
        else cout << "No" << endl;
        return;
    } 
    dump(index);
    if (index > a[0] || index < n - (n - a[0] - 1) * 2) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 640
n,m = map(int,input().split())
bit = [bin(i)[2:].zfill(3) for i in range(2**3)]
ans = -int(1e10)
cake = []
for i in range(n):
    a,b,c = map(int,input().split())
    cake.append((a,b,c))
for i in range(2**3):
    u = []
    cond = bit[i]
    for j in range(n):
        cnt = 0
        for k in range(3):
            if cond[k] == "0":
                cnt += cake[j][k]
            else:
                cnt -= cake[j][k]
        u.append(cnt)
    u.sort(reverse=True)
    ans = max(ans, sum(u[:m]))
print(ans)




Measured memory_bytes: 42352
import itertools
import math

n=int(input())
#print(n)
p=list(itertools.permutations(range(n)))
l=[]
for i in range(n):
    la=list(map(int,input().split()))
    l.append(la)
ans=0
for i in p:
    for j in range(1,n):
        tmp=0
        tmp+=(l[i[j]][0]-l[i[j-1]][0])**2
        tmp+=(l[i[j]][1]-l[i[j-1]][1])**2
        ans+=math.sqrt(tmp)
ans/=(len(p)) 
print(ans)




Measured memory_bytes: 7972
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
struct Point{double x,y;};
double dis(Point a,Point b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point tri(Point a, Point b, Point c){
  double a1,a2,b1,b2,c1,c2;
  a1=2*(b.x-a.x);
  b1=2*(b.y-a.y);
  c1=a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y;
  a2=2*(c.x-a.x);
  b2=2*(c.y-a.y);
  c2=a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y;
  Point p;
  p.x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
  p.y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
  return p;
}
int main(){
  int n;cin >> n;int i;
  for(i=0;i<n;i++){
  Point a,b,c;cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
  Point x = tri(a,b,c);
  printf("%.3f %.3f %.3f\n",x.x,x.y,dis(x,a));
  }
}


Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;


ll dp[3100][3100];

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    
    
    //ある配列が与えられた時に
    //その配列から先頭を取ったときと、末尾を取った時からのスコアわかっている
    //どちらの行動を取るのが良いか
    for(int len=1;len<=n;len++){
        for(int i=0;i+len<=n;i++){
            int j=i+len;
            
            if ((n-len)%2==0){
                //太郎の行動
                dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
            }else {
                //次郎の行動
                dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
            }
        }
    }
    
    cout<<dp[0][n]<<endl;
    
   
}


Measured memory_bytes: 73984
#include <stdio.h>
#include <stdbool.h>

bool is_leap_year(int y);

int get_leap_years(int* leap_years_list, int year_begin, int year_end);

int main()
{
    int leap_years_list[1000]; //A.D. 0 - A.D. 3000 の間に閏年は高々1000個しかない

    bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので

    while (true) {
        int year_begin, year_end;

        //読み込み
        scanf("%d %d", &year_begin, &year_end);

        //終了判定
        if (year_begin == 0 && year_end == 0) {
            break;
        }

        //閏年を計算する
        int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end);

        //セットとセットの間には空行を入れる
        if (first_set) {
            first_set = false;
        } else {
            putchar('\n'); //putcharは一文字だけ出力する関数です
        }

        //閏年を出力
        if (leap_years_count == 0) {
            puts("NA"); //putsは与えられた文字列を出力した後改行する関数です
        } else {
            for (int i = 0; i < leap_years_count; i++) {
                printf("%d\n", leap_years_list[i]);
            }
        }
        
    }
}

bool is_leap_year(int y)
{
    if (y % 400 == 0) {
        return true; 
    } else if (y % 100 == 0) {
        return false;
    } else {
        return y % 4 == 0; 
    }
}

int get_leap_years(int* leap_years_list, int year_begin, int year_end)
{
    int leap_years_count = 0;
    for (int year = year_begin; year <= year_end; ++year) {
        if (is_leap_year(year) == true) {
            *(leap_years_list + leap_years_count) = year;
            ++leap_years_count;
        }
    }
    return leap_years_count;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int m_max=1e5+5;
vector<int> G[m_max];
vector<int> rG[m_max];
int used[m_max];
int dfs(int v, int d){
  int dep=d;
  //cout << "from " << v << endl;
  for(int i:G[v]){
    int t=0;
    if(used[i]==-1) t=dfs(i,d+1);
    else t=used[i]+d+1;
//    cout << "if go to " << i << " dep : " << t << endl;
    dep=max(dep,t);
  }
  used[v]=dep-d;
  return dep;
}


int main(){

  int n,m;
  cin >> n >> m;
  int x,y;
  set<int> s;
  rep(i,n) used[i]=-1;
  rep(i,m){
    cin >> x >> y;
    x--;y--;
    G[x].pb(y);
    rG[y].pb(x);
    s.insert(y);
  //  cout << x <<" " << y << endl;  
  }
  int dp[n];
  int lm=0;
  rep(i,n) dp[i]=-1;
  rep(i,n){
    if(s.count(i)==0){
      //  cout << "s " <<i << endl;
      lm = max(lm,dfs(i,0));      
    }    
  }
  //cout << s.count(3) << endl;
  //rep(i,n) cout << used[i] << endl;
  cout << lm << endl;
    

  
  return 0;

}


Measured memory_bytes: 22912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solve(new Scanner(System.in));
	}
	
	public void solve(Scanner sc) {
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		if(b%a == 0) {
			System.out.println(a+b);
		} else {
			System.out.println(b-a);
		}
		
	}
}


Measured memory_bytes: 23760
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

class edge{
public:
	Int cost;
	size_t from, to;
	edge(Int c, size_t f, size_t t){
		cost = c;
		from = f;
		to = t;
	}
};
using edges = vector<edge>;
using graph = vector<edges>;
void readgraph(graph &g, size_t E, bool D, bool C, bool Z){ // E:num_of_edges, D:directed, C:costed, Z:already 0-indexed
	for(size_t i=0; i<E; ++i){
		edge e(1, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
		if(!Z){
			--e.from;
			--e.to;
		}
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}
Int n, Q;
vector<vector<Int>> c;
vector<Int> ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> Q;
	graph g(n);
	readgraph(g, n-1, false, false, false);
	c.resize(n);
	vector<bool> f(n, false);
	queue<Int> q;
	q.push(0);
	while(!q.empty()){
		Int p = q.front(); q.pop();
		f[p] = true;
		for(auto i:g[p]){
			Int t = i.to;
			if(f[t]) continue;
			c[p].push_back(t);
			q.push(t);
		}
	}
//	for(Int i=0; i<n; ++i)
//		for(size_t j=0; j<c[i].size(); ++j)
//			cout << c[i][j] << " \n"[j+1==c[i].size()];
	ans.resize(n, 0ll);
	for(Int i=0; i<Q; ++i){
		Int p, x; cin >> p >> x;
		ans[p-1] += x;
	}
	q.push(0);
	while(!q.empty()){
		Int p = q.front(); q.pop();
		for(auto i:c[p]){
			ans[i] += ans[p];
			q.push(i);
		}
	}
	for(Int i=0; i<n; ++i)
		cout << ans[i] << " \n"[i+1==n];
}

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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;

int n,x,mn=1e5,ans;

int main() {
   io;
   cin >> n >> x;
   int a[n];
   for(int i = 0 ; i < n ; i++) {
        cin >> a[i];
        mn = min(mn,a[i]);
        x -= a[i];
   }
   ans = n + x / mn;
   cout << ans;
}


Measured memory_bytes: 256
n=int(input())
x=[[0,0,0]]+[list(map(int,input().split()))for i in range(n)]
y=[]
for i in range(n):
    s,t,r=x[i+1]
    q,p,w=x[i]
    temp=s-q
    abso=abs(t-p)+abs(r-w)
    if temp<abso or (temp%2!=abso%2):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 28068
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<unordered_set>
#include<string.h>
#include<unordered_map>
#include<numeric>
#include<iomanip>
#include<string.h>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;

#define FOR(i,N) for(int i=0;i<N;i++)

ll mod=1e9+7;
double EPS=1e-8;



int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    int odd=0,even=0;
    ll ans=1;
    ll minus=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2){
            odd++;
            minus*=1;
        } else {
            even++;
            minus*=2;
        }
        ans*=3;
    }
    cout<<ans-minus<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

ll sol(ll n) {
  if (n < 0)
    return 0;
  int r = n % 4;
  if (r == 0)
    return n;
  if (r == 1)
    return 1;
  if (r == 2)
    return n + 1;
  if (r == 3)
    return 0;
  return -1;
}

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

  ll a, b;
  cin >> a >> b;
  cout << (sol(a - 1) ^ sol(b)) << endl;
}


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

signed main() {
	char a; cin >> a;
	if (a == 'A')puts("T");
	else if (a == 'T')puts("A");
	else if (a == 'G')puts("C");
	else puts("G");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,i,j,t;
  int v[55];
  double sum;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&v[i]);
  }
  for(i=0;i<N;i++){
    for(j=N-1;i<j;j--){
      if(v[j]<v[j-1]){
      t=v[j];
      v[j]=v[j-1];
      v[j-1]=t;
    }
  }
}
sum=v[0];
for(i=0;i<N;i++){
  sum=(sum+v[i])/2.0;
}
printf("%lf",sum);
  return 0;
}


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

int main() {
  int N, C, K;
  cin >> N >> C >> K;

  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  sort(T.begin(), T.end());

  int ans = 1, limit = T[0] + K, space = C;
  for (int i = 0; i < N; i++) {
    if (space == 0 || limit < T[i]) {
      ans++;
      space = C;
      limit = T[i] + K;
    }
    space--;
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
table=[[] for i in range(N)]
Lin=[0]*N
for i in range(M):
    w,v=map(int,input().split())
    table[w-1].append(v-1)
    Lin[v-1]+=1
H=[]
for i in range(N):
    if Lin[i]==0:
        H.append(i)
dp=[-1]*N
def f(x):
    if dp[x]!=-1:
        return dp[x]
    if len(table[x])==0:
        return 0
    t=0
    for i in table[x]:
        t=max(t,f(i)+1)
    dp[x]=t
    return t
for i in H:
    f(i)
print(max(dp))


Measured memory_bytes: 162592
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		int ret=0;
		for(int i=1;i<c;i++){
			for(int j=1;j<c;j++){
				if(i*(100+a)/100+j*(100+a)/100==c){
					ret=max(ret,i*(100+b)/100+j*(100+b)/100);
				}
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1012
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int[] l = new int[n];
    for(int i = 0; i < n; i++) {
      l[i] = sc.nextInt();
    }
    int ans = Integer.MAX_VALUE;
    for(int i = 1; i < (int)Math.pow(4, n); i++) {
      int la = 0;
      int lb = 0;
      int lc = 0;
      int[] num = new int[4];
      for(int j = 0; j < n; j++) {
        int s = i / (int)Math.pow(4, j);
        s = s % 4;
        if(s == 1) {
          la += l[j];
          num[1]++;
        }
        if(s == 2) {
          lb += l[j];
          num[2]++;
        }
        if(s == 3) {
          lc += l[j];
          num[3]++;
        }
      }
      if((la > 0) && (lb > 0) && (lc > 0)) {
        int t = Math.abs(la - a) + Math.abs(lb - b) + Math.abs(lc - c) + 10 * (num[1] - 1) + 10 * (num[2] - 1) + 10 * (num[3] - 1);
        ans = Math.min(ans, t);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 24520