akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    string x;
    int len,sum;
    while(1){
        cin >> x;
        if(x[0]=='0') break;
        sum=0;
        len=int(x.length());
        for(int i=0;i<len;i++){
            sum+=x[i]-48;
        }
        cout << sum << endl;
    }
    
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
    long long int a[n],d[n+1];
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(i==0){
			d[i]==0;
		}
		else if(i<=k){
			d[i]=abs(a[i]-a[0]);
		}
		else{
			d[i]=d[i-1]+abs(a[i]-a[i-1]);
			for(int j=1;j<=k;j++){
				d[i]=min(d[i],d[i-j]+abs(a[i]-a[i-j]));
			}
		}
	}
	cout<<d[n-1];
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0

for i,a in enumerate(A):
  ans += B[a-1]
  #print(ans, i)
  if i:
    #print(A[i-1],a)
    if A[i-1] + 1 == a:
      ans += C[a-2]
print(ans)

Measured memory_bytes: 38384
N,Y = map(int,input().split())

for i in range(N+1):
    A = i
    for j in range(N+1):
        B = j
        C = N - A - B
        if C < 0:
            break
        s = 10000*A+5000*B+1000*C
        if s == Y:
            a = str(A)
            b = str(B)
            c = str(C)
            print(a+" "+b+" "+c)
            exit()

print("-1"+" "+"-1"+" "+"-1")

Measured memory_bytes: 3064
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int n;
int m;
vector < int > profit[N];

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        if(a > m)
            continue;
        profit[m - a].push_back(b);
    }
    int ans = 0;
    priority_queue < int > best;
    for(int i = m-1; i >= 0; i--){
        for(auto v : profit[i]){
            best.push(v);
        }
        if(best.size()){
            ans += best.top();
            best.pop();
        }
    }
    printf("%d\n" , ans);
}

Measured memory_bytes: 5632
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main() {
	int A,B,C,mx,mn,tyu;
	cin>>A>>B>>C;
	mx=max(A,max(B,C));
	mn=min(min(A,B),C);
	tyu=A+B+C-mx-mn;
	if(((mx-mn)+(mx-tyu))%2==0)
	{
		cout<<((mx-mn)+(mx-tyu))/2;
	}
	else
	{
		mx++;
		mn++;
		cout<<((mx-mn)+(mx-tyu))/2+1;
	}
	}

Measured memory_bytes: 256
n,m,l = [ int(s) for s in input().split() ]
  
a = [ [0] * m for i in range(n) ]
b = [ [0] * l for i in range(m) ]
c = [ [0] * l for i in range(n) ]

for i in range(n):
    x = [ int(s) for s in input().split() ]
    a[i][:m] = x

for i in range(m):
    y = [ int(s) for s in input().split() ]
    b[i][:l] = y

for j in range(n):
    for k in range(l):
        total = 0
        for i in range(m):
            total += a[j][i] * b[i][k]
        c[j][k] = total

for i in range(n):
    print(*c[i])


Measured memory_bytes: 7056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n;
    string s[n];
    int cou[n] = {};
    int a=0,b=0,ab=0;
    rep(i, n){
        cin >> s[i];
        rep(j, s[i].length()-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B'){
                cou[i]++;
            }
        }
        if(s[i][s[i].length()-1]=='A'){
            if(s[i][0]=='B'){
                ab++;
            }else{
                a++;
            }
        }else if(s[i][0]=='B'){
            b++;
        }
    }
    int sum = 0;
    rep(i, n){
        //cout << cou[i] << endl;
        sum += cou[i];
    }
    /*int mm = min(ab,b);
    sum += mm;
    ab -= mm;
    b -= mm;
    mm = min(ab, a);
    sum += mm;
    ab -= mm;
    a -= mm;
    if(ab > 0){
        sum += ab-1;
    }else{
        sum += min(a,b);
    }*/
    /*if(b >= ab){
        sum += ab;
        ab = 0;
        sum += min(a,b);
        cout << sum << endl;
    }else{
        sum+=b;
        ab -= b;
        if(a >= ab){
            sum += ab;
            ab = 0;
            sum += min(a,b);
            cout << sum << endl;
        }else{
            sum+=a;
            ab -= a;
        }
    }*/
    //cout << ab << a << b << endl;
    if(ab>0){
        sum+=ab-1;
        ab = 1;
        if(a==0&&b==0){
            cout << sum << endl;
            return 0;
        }else{
            if(a > 0){
                ab = 0;
                sum++;
                sum += min(a,b);
                cout << sum << endl;
                return 0;
            }else{//a nasi
                ab = 0;
                sum++;
                cout << sum << endl;
                return 0;
            }
        }
    }else{
        sum += min(a,b);
        cout << sum << endl;
        return 0;
    }
    //for(int i = ab;ab >= 0;ab--){

    //}
    return 0;
}


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

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
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); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, K; cin >> N >> K;
	vl A(N);
	REP(i,N) cin >> A[i];
	FOR(i, K, N) {
		if (A[i] > A[i - K]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint& operator/=(const mint r) {
    ll a = r.x, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    x = x * u % MOD;
    if (x < 0) x += MOD;
    return *this;
  }
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  ll n; cin >> n;
  Vll a(n); cin >> a;

  int k = 0;
  mint ans = 1;
  rep(i, n) {
    int x = 2*(i-k) + 1;
    if (a[i] < x) {
      ans *= i-k+1;
      ++k;
    }
  }
  rep(i, n-k) ans *= (i+1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
# https://beta.atcoder.jp/contests/abc112/tasks/abc112_b

def solve():
    cost = 1001
    N, time = map(int, input().split())
    for _ in range(N):
        c, t = map(int, input().split())
        if t <= time:
            if c <= cost:
                cost = c

    if cost == 1001:
        print('TLE')
    else:
        print(cost)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			if(i*j==n)
			{
				cout<<"Yes\n";
				return 0;
			}
		}
	}
	cout<<"No\n";
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long int ll;
const int N=1e5+5,M=1e4+5;
int n,a[N],memo[N];
int solve(int ind){
    if(ind==n-1)
        return 0;
    if(~memo[ind])
        return memo[ind];
    if(ind+1!=n-1)
    return memo[ind]= min( abs(a[ind+1]-a[ind])+ solve(ind+1), abs(a[ind+2]-a[ind])+solve(ind+2) ) ;
    return memo[ind]= abs(a[ind+1]-a[ind]);
}
int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    memset(memo,-1,sizeof memo);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<solve(0)<<'\n';
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(){
int a[5];
int b[5];
int c[5];
int i;
int tmp=10;
for(i=0;i<5;i++){
  cin>>a[i];
}

for(i=0;i<5;i++){
  c[i]=a[i]/10;
  if(a[i]%10!=0) c[i]++;
  b[i]=a[i]%10;
}

for(i=0;i<5;i++){
  if(b[i]>0) tmp=min(tmp,b[i]);
}

int ans=0;
for(i=0;i<5;i++){
  ans+=c[i]*10;
}
ans-=10;
ans+=tmp;
cout<<ans<<endl;


}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;

    vector<string> v;

    for (int i = 0; i < s.size(); ++i) {
        string t = "";

        for (int j = i; j < s.size(); ++j) {
            t += s[j];

            if (v.size() == 0) {
                v.push_back(t);
                break;

            }

            if (v[v.size() - 1] != t) {
                v.push_back(t);

                i = j;
                break;
            }
        }
    }

    cout << v.size() << endl;
}

Measured memory_bytes: 10996
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  vi A(3);
  string ans="No";
  rep(i,0,3) cin>>A[i];
  sort(ALL(A));
  if(A[0]+A[1]==A[2])
    ans="Yes";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{	
	int b[100] = {0};
	int a[100] = {0};
	int n,i,j,s;
	int m = 0;
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> b[i];
	}
	for (i = 0; i < n; ++i) {
		if (b[i] > i + 1) {
			m = 1;
			break;
		}
	}
	for (i = n - 1; i > -1; --i) {
		for (j = i; j > -1; --j) {
			if (j + 1 == b[j]) {
				a[i] = b[j];
				for (s = j; s < i; ++s) {
					b[s] = b[s + 1];
				}
				b[i] = -1;
				break;

			}
		}
	}
	if (m == 1)cout << "-1" << "\n";
	else {
		for (i = 0; i < n; ++i) {
			cout << a[i] << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, k, ans, H[MAXN];

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

    cin >> n >> k;
    for (ll i = 0; i < n; i++) cin >> H[i];
    sort(H, H + n);
    for (ll i = 0; i < n - k; i++) ans += H[i];
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

class Main {

	static final int M = 1000000007;

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int[][] dp = new int[n][k + 1];
		int[][] sum = new int[2][k + 2];
		for (int i = 0; i <= Math.min(k, a[0]); i++) {
			dp[0][k - i] = 1;
		}
		for (int i = 0; i <= k; i++) {
			sum[0][k - i] = (sum[0][k - i + 1] + dp[0][k - i]) % M;
		}

		for (int i = 1; i < n; i++) {
			for (int j = 0; j <= k; j++) {
				dp[i][k - j] = (sum[(i + 1) % 2][k - j] - sum[(i + 1) % 2][1 + Math.min(k, k - j + a[i])]) % M;
				dp[i][k - j] = (dp[i][k - j] + M) % M;
				sum[i % 2][k - j] = (sum[i % 2][k - j + 1] + dp[i][k - j]) % M;
			}
		}

		System.out.println(dp[n - 1][0]);
	}
}


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

int main(int argc, char const *argv[])
{
  string s,s1="",s2="";
  cin>>s;
  for(int i = 0;i<3;i++){
    s1 += s[0];
    s2 += s[0]+1;
  }
  if(s<=s1)
    cout<<s1<<endl;
  else 
    cout<<s2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue


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;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	string s; cin >> s;
	s = "#" + s + "#";
	bool ok = true;
	for (int i = a; i + 1 <= c;i++) {
		if (s.at(i) == '#'&&s.at(i + 1) == '#') {
			ok = false; break;
		}
	}
	for (int i = b; i + 1 <= d; i++) {
		if (s.at(i) == '#'&&s.at(i + 1) == '#') {
			ok = false; break;
		}
	}
	if (c < d) {
		if (ok)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (ok) {
			bool ok2 = false;
			for (int i = b; i <= d; i++) {
				if (s.at(i - 1) == '.'&&s.at(i) == '.'&&s.at(i + 1) == '.') {
					ok2 = true; break;
				}
			}
			if (ok2)cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 720
fun c100(args: Array<String>) {
    val numList = args[1].split(" ").map { it.toInt() }
    val ans = numList
            .map {
                var curr = it
                var cnt = 0
                while (curr % 2 == 0) {
                    curr /= 2
                    cnt++
                }
                cnt
            }
            .sum()
    println(ans)
}

fun main(args: Array<String>) {
    c100(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 42932
#include <stdio.h>

int main(void){
	int i,suma=0,sumb=0,a;

	for(i=0;i<4;i++){
		scanf("%d",&a);
		suma+=a;
	}
	for(i=0;i<4;i++){
		scanf("%d",&a);
		sumb+=a;
	}
	if(suma>sumb)
		printf("%d\n",suma);
	else 
		printf("%d\n",sumb);
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	int a=0,b=0;
	cin>>s;
	for(int i=0;i<3;i++){
		if(s[i]=='A')
			a=1;
		else
			b=1;
	}
	if(a&&b)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
	return x*f;
}
int deg[100010];
int main(){
	//freopen("aa.in","r",stdin);
	//freopen("aa.out","w",stdout);
	int n=read(),m=read();
	for(int i=1;i<=m;i++){
		int a=read(),b=read();
		deg[a]++,deg[b]++;
	}
	for(int i=1; i<=n; i++){
		if(deg[i]%2){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	
	fclose(stdin);fclose(stdout);
	return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll m,d;
    cin >> m >> d;
    ll ans = 0;
    for(i = 1;i <= m;++i){
        for(j = 1;j <= d;++j){
            if(j < 10) continue;
            ll t = j/10;
            ll s = j%10;
            if(t < 2) continue;
            if(s < 2) continue;
            if(i == t*s) ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let (h, w): (i64, i64) = (sc.input(), sc.input());
    let picture: Vec<Vec<char>> = (0..h)
        .map(|_|{
            let line: String = sc.input();
            let cs: Vec<char> = line.chars().collect();
            cs
        }).collect();

    for line in &picture {
        for ch in line.iter() {
            print!("{}", ch);
        }
        println!();
        for ch in line.iter() {
            print!("{}", ch);
        }
        println!();
    }
}


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

using namespace std;

int main() {

    int n, W;

    cin >> n >> W;

    int v[n], w[n];
    int dp[W + 1];

    for(int i = 0; i < n; ++i) {
        cin >> v[i] >> w[i];
    }

    fill(dp, dp + W + 1, 0);

    for(int i = 0; i < n; ++i) {
        for(int j = W; j >= w[i]; --j) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << endl;

}

Measured memory_bytes: 1200
def main():
    from bisect import bisect_left as bl
    from itertools import accumulate as ac

    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    aa = [0]+list(ac(a))
    an = aa[n]

    ok = 0
    ng = 10**10
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if sum([n-bl(a, mid-a[i]) for i in range(n)]) >= m:
            ok = mid
        else:
            ng = mid

    c = -m+sum([n-bl(a, ok-a[i]) for i in range(n)])
    ans = -c*ok
    for i in range(n):
        d = bl(a, ok-a[i])
        ans += an-aa[d]+(n-d)*a[i]
    print(ans)


main()

Measured memory_bytes: 16192
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cassert>
#include<deque>
using namespace std;

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//////////////////////

int const N = 1e5 + 41;
ll const INF = 1e9  * 1LL * 1e9;

int n, m, a[N];
ll coef[N], add[N];

void solve(){
	cin >> n >> m;
	fr(i, 0, n) cin >> a[i];
	fr(i, 0, n-1){
		if(a[i] < a[i+1]){
			add[1] += (a[i+1] - a[i]);
			coef[a[i]+2] -= 1;
			coef[a[i+1]+1] += 1;
			add[a[i+1]+1] -= 1;
			add[a[i+1]+1] += (a[i+1] - a[i]);
		}else{
			add[1] += (a[i+1] - 1 + 1);
			add[1] += 1; coef[1] -= 1;
			coef[a[i+1]+1] += 1;
			add[a[i+1]+1] -= 1;
			add[a[i+1]+1] += (m - a[i] + a[i+1]);
			coef[a[i]+2] -= 1;
		}
	}

	ll ans = INF;
	ll sum = 0;
	ll c = 0;
	fr(i, 1, m+1){
		sum += add[i];
		c += coef[i];
		sum += c;
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 2176
S = input()

while True:
    if len(S) == 0:
        print("YES")
        break
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    else:
        print("NO")
        break

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c;
  cin >> a;
  if(a == 1){
    cout << "Hello World\n";
    return 0;
  }
  if(a == 2){
    cin >> b >> c;
    cout << b + c << "\n";
    return 0;
  }
}
  

Measured memory_bytes: 3544
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

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

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	ls := scanInts(n)
	sort.Ints(ls)
	var cnt int
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if ls[j]-ls[i] < ls[k] && ls[k] < ls[i]+ls[j] &&
					ls[i] != ls[j] && ls[j] != ls[k] && ls[k] != ls[i] {
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1780
import sys
from io import StringIO
import unittest


def resolve():
    A, B = [int(i) for i in input().split()]
    mina = int(-(-min(A / 0.08, B / 0.1) // 1))
    while int(mina * 0.08) == A or int(mina * 0.1) == B:
        if int(mina * 0.08) == A and int(mina * 0.1) == B:
            print(mina)
            return
        mina += 1
    else:
        print(-1)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2"""
        output = """25"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8 10"""
        output = """100"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """19 99"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """25 32"""
        output = """320"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a <= k) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using lint=int64_t;
using namespace std;

class Info
{
	public:
	lint div;
	lint size;
	lint value;
};

bool cmp(const Info &a,const Info &b)
{
	return a.div<b.div;
}

int main()
{	
	Info info[4]={};
	for(int i=0;i<4;i++)
	{
		info[i].size=pow(2,i);
		cin >> info[i].value;
		info[i].div=info[i].value*(8/info[i].size);
	}
	
	lint N;
	cin >> N;
	N*=4;
	
	sort(info,info+4,cmp);
	
	lint ans=0;
	for(int i=0;i<4;i++)
	{
		ans+=info[i].value*(N/info[i].size);
		N=N%info[i].size;
		if(N==0)break;
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
map<int,int>mp;
int main(){
    while(cin>>n>>m){
        mp.clear();
        for(int i=1;i<=m;i++){
            int x,y;
            cin>>x>>y;
            mp[x]++,mp[y]++;
        }
        int f=1;
        for(int i=1;i<=n;i++){
            if(mp[i]%2)f=0;
        }
        f?puts("YES"):puts("NO");
    }
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAXN = 2e6;
int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  int a, b;
  cin >> a >> b;
  for(int i=0;i<MAXN;i++) {
    int t1 = i*0.08+1e-9;
    int t2 = i*0.10+1e-9;
    if (t1==a && t2 ==b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 <<endl;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
)

func main() {
  var n, tmp int
  fmt.Scanf("%d", &n)
  
  var l []int
  for i := 0; i < n; i++ {
    fmt.Scanf("%d", &tmp)
    l = append(l, tmp)
  }
  sort.Slice(l, func(i, j int) bool { return l[i] < l[j] })
  ans := 0
  for _, i := range l {
    if n < 3 {
      break
    }
    for _, j := range l {
      if j <= i {
        continue
      }
      for _, k := range l {
        if k <= i || k <= j {
          continue
        }
        if k < i + j {
          ans++
        }
      }
    }
  }
  fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;

    vector<int> xv(n);
    vector<int> yv(m);

    rep(i, n) cin >> xv[i];
    rep(i, m) cin >> yv[i];

    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());

    int x_max = xv[n-1];
    int y_min = yv[0];

//    cout << y_min << " " << x_max << endl;
    if ( y_min - x_max >= 1 && y_min >= x_max && x_max >= x && y_min <= y ) cout << "No War" << endl;
    else                                                                    cout << "War" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()

long long roman(char c)
{
	char a[7+1] = "IVXLCDM";
	long long x[7] = { 1,5,10,50,100,500,1000 };
	for (int i = 0; i < 7; i++)
	{
		if (a[i] == c)
		{
			return x[i];
		}
	}
	return 0;
}


int main()
{
	string a;
	while (cin >> a)
	{
		long long ans = 0;
		reverse(all(a));
		long long b = 0;
		for (int i = 0; i < a.size(); i++)
		{
			long long now = roman(a[i]);
			if (b <= now)
			{
				ans += now;
			}
			else
			{
				ans -= now;
			}
			b = now;
		}
		cout << ans << endl;
	}

}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 3E3 + 3;

int dp[MAXN][MAXN][4];
int mat[MAXN][MAXN];
int n;
int m, k;
int f(int x, int y, int q) {
  if (x == n && y == m) {
    if (q < 3)
      return mat[x][y];
    return 0;
  }

  int &ret = dp[x][y][q];
  if (~ret)
    return ret;

  ret = 0;
  // up
  if (x < n) {
    ret = max(ret, f(x + 1, y, 0));
    if (q < 3) {
      ret = max(ret, mat[x][y] + f(x + 1, y, 0));
    }
  }

  // right
  if (y < m) {
    ret = max(ret, f(x, y + 1, q));
    if (q < 3) {
      ret = max(ret, mat[x][y] + f(x, y + 1, q + 1));
    }
  }

  return ret;
}

// #define MULTIPLE_TEST_CASES
void solve() {
  memset(dp, -1, sizeof dp);
  cin >> n;

  cin >> m >> k;

  while (k--) {
    int x, y, v;
    cin >> x >> y >> v;
    mat[x][y] = v;
  }
  cout << f(1, 1, 0) << endl;
}

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

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 356060
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @s = gets.chomp
    @t = gets.chomp
    @n = s.size
    @m = t.size
  end

  def solve
    ans = 10**15
    0.upto(n-m) do |i|
      cnt = 0
      m.times do |j|
        cnt += 1 if s[i+j] != t[j]
      end
      ans = cnt if ans > cnt
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14384
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int x = sc.nextInt();

        int[] ds = new int[N];
        for (int i = 0; i < N; i++) {
            ds[i] = Math.abs(sc.nextInt() - x);
        }

        int ans = ds[0];
        for (int i = 0; i < N; i++) {
            ans = gcd(ans, ds[i]);
        }

        System.out.println(ans);
    }


    static int gcd(int x, int y) {
        while (true) {
            int tmp = x % y;
            if (tmp == 0) {
                return y;
            }
            x = y;
            y = tmp;
        }
    }
}


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

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


const int MAX_N = 100010;
//Quick Find Weighted
class QuickFindWeighted{
    public:
        int i2g[MAX_N];//i2g[i] := 頂点iが所属するグループ
        vector<int> g2i[MAX_N];//g2i[g]:= グループgに所属する頂点番号
        void init(int n){
            for (int i = 0; i < n; ++i){
                i2g[i] = i;
                g2i[i].push_back(i);
            }
        }
        // 座標iaと座標ibは同じグループに所属しているか？
        bool issame(int ia, int ib){
            return i2g[ia] == i2g[ib];
        }
        // 座標iaの所属するグループと座標ibの所属するグループを1つにする(異なるグループに属するものに)
        void merge(int ia, int ib){
            if(issame(ia, ib)) return;
            //iaの所属するグループがibの所属するグループより小さくならないようにする(一般的マージテク)
            if(g2i[i2g[ia]].size() < g2i[i2g[ib]].size()){
                swap(ia, ib);
            }
            int ga = i2g[ia], gb = i2g[ib];//グループgbの方が要素数が少ない
            for(auto u : g2i[gb]){//uには頂点の番号はいる
                i2g[u] = ga;//グループの番号を更新
            }
            g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());//つなげる
            g2i[gb].clear();
        }
};


int main(void) {
	int n, m; cin >> n >> m;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	rep(i, n) p[i]--;
	vector<int> x(m), y(m);
	rep(i, m) cin >> x[i] >> y[i];
	rep(i, m) x[i]--, y[i]--;


	QuickFindWeighted uf;
	uf.init(n);
	rep(i, m) uf.merge(x[i], y[i]);

	int ans = 0;
	rep(i, n) {
		set<int> v1, v2;
		for (auto u : uf.g2i[i]) {
			v1.insert(u);
			v2.insert(p[u]);
		}
		
		for (auto u : v1) if (v2.count(u)) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 19428
n, k = map(int, input().split())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

flag = [False for i in range(n + 1)]
r = []
num = 1
while num < n + 1:
    if flag[num] == False:
        temp = [c[num]]
        flag[num] = True
        num2 = p[num]
        while flag[num2] == False:
            flag[num2] = True
            temp.append(c[num2])
            num2 = p[num2]
        else:
            r.append(temp)
            num += 1
    else:
        num += 1
ans = -float("inf")
for i in r:
    temp = sum(i)
    sum_i = [0]
    for j in range(len(i)):
        sum_i.append(sum_i[-1] + i[j])
    for j in range(len(i)):
        sum_i.append(sum_i[j + 1] + temp)
    num1 = k % len(i)
    num2 = k // len(i)
    if temp < 0:
        for j in range(1, min(len(i), k) + 1):
            for l in range(len(i)):
                ans = max(ans, sum_i[l + j] - sum_i[l])
    else:
        if num2 >= 1:
            for j in range(1, len(i) + 1):
                for l in range(len(i)):
                    ans = max(ans, sum_i[l + j] - sum_i[l] + temp * (num2 - 1))
        for j in range(1, num1 + 1):
            for l in range(len(i)):
                ans = max(ans, sum_i[l + j] - sum_i[l] + temp * num2)
print(ans)

Measured memory_bytes: 74868
import math

s = input().rstrip().split(' ')
N = int(s[0])
D = int(s[1])

cnt = 0
d_list = []

for i in range(N):
  d_list.append(input().rstrip().split(' '))

for i in range(N-1):
  for n in range(i+1, N):
    num = 0
    for d in range(D):
        num += (int(d_list[i][d]) - int(d_list[n][d])) ** 2
    
    test = math.sqrt(num)
    
    if test.is_integer():
      cnt += 1
    
print(cnt)


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

A, B, C = 0, 0, 0
for _ in range(N):
    a, b, c = map(int, input().split())
    A, B, C = max(B, C) + a, max(C, A) + b, max(A, B) + c
ans = max(A, B, C)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(void){
    ll N, a,b,c,d; cin >> N >> a >> b >> c >> d;

    for(int k=0; k<N; k++){
        ll left = a+c*k-d*(N-1-k);
        ll right = a+d*k-c*(N-1-k);

        if(left <= b && b <= right){
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;
    int n = s.size();
    int p1=0,p2=0;
    int cnt=0;
    rep(i,n){
        if(i%2==0) {if(s[i]=='0') cnt++;}
        else {if(s[i]=='1') cnt++;}
    }
    p1 = cnt; cnt=0;
    rep(i,n){
        if(i%2==0) {if(s[i]=='1') cnt++;}
        else {if(s[i]=='0') cnt++;}
    }
    p2 = cnt;
    cout << min(p1,p2) << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int ans = 1;
		for(int i = 2; i < x; i++) {
			int j = i;
			if(x >= Math.pow(j, 2)) {
				while(j <= x) {
					j *= i;
				}
				j /= i;
				ans = Math.max(ans, j);
			}
		}
		System.out.println(ans);

	}

}


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

using namespace std;

long long solve(int k, vector<vector<int>>& graph, int idx, int prev) {
    if (k < static_cast<int>(graph[idx].size())) {
        return 0;
    }

    long long r = 1;
    for (int i = 0, j = k - (prev == -1 ? 1 : 2); i < static_cast<int>(graph[idx].size()); i++) {
        if (graph[idx][i] != prev) {
            r *= j;
            r %= 1000000007;
            j--;

            r *= solve(k, graph, graph[idx][i], idx);
            r %= 1000000007;
        }
    }

    return r;
}

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

    vector<vector<int>> graph(n, vector<int>(0));
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }

    cout << (k * solve(k, graph, 0, -1)) % 1000000007 << endl;
}


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

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

#include <iostream>
using namespace std;

ll sum(ll l, ll r) { return (l + r) * (r - l + 1) / 2; }

int main() {
  ll n, k;
  cin >> n >> k;
  ll MOD = 1000000000 + 7;
  // n+1
  // k,k+1 ... n-1,n
  ll ans = 0;

  for (int i = k; i <= n + 1; ++i) {
    ll l, r;
    l = sum(0, i - 1);
    r = sum(n - (i - 1), n);
    ans = (ans + (r - l + 1)) % MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int L[60][60]={};
char c;
int x,y,H,W,t=0;
int main(){
  cin >> H >> W;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin >> c;
      if(c=='#'){
        x=j;
        y=i;
        L[x-1][y-1]++;
        L[x][y-1]++;
        L[x+1][y-1]++;
        L[x-1][y]++;
        L[x+1][y]++;
        L[x-1][y+1]++;
        L[x][y+1]++;
        L[x+1][y+1]++;
        L[x][y]=114514;
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      string s=to_string(L[j][i]);
      if(L[j][i]>=114514) cout << "#";
      else cout << s;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    cout << n/3 << endl;

    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
// #include<iostream>
// #include<string>
// #include<vector>
// #include<set>
// #include<map>
// #include<algorithm>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N))cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N))cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N))cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUT4(P1,P2,P3,P4) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<" "<<(P4)<<endl
#define OUTS(I,N,V) REP((I),(N))cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

long f(long n){
  if(n<=0)return 0;
  switch(n%4){
    case 0:return n;
    case 1:return 1;
    case 2:return n+1;
    case 3:return 0;
  }
}

long A,B;
inline void solve(void){
  IN2(A,B);
  OUT(f(A-1)^f(B));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++) {
  	cin >> A[i];
  }
  vector<ll> acc(N + 1);
  for(int i = 0; i < N; i++) {
    acc[i + 1] = acc[i] + A[i];
  }
  
  ll ans = 1LL << 62;
  for(int j = 2; j <= N - 2; j++) {
    int i1 = lower_bound(all(acc), acc[j] / 2) - acc.begin();
    int k1 = lower_bound(all(acc), (acc[N] + acc[j]) / 2) - acc.begin();
    vector<int> I = {i1}, K = {k1};
	if (i1 - 1 >= 0) I.push_back(i1 - 1);
    if (k1 - 1 > j) K.push_back(k1 - 1);
    for(int u = 0; u < I.size(); u++) {
      for(int v = 0; v < K.size(); v++) {
        int i = I[u], k = K[v];
        vector<ll> sum = {acc[N] - acc[k], acc[k] - acc[j], acc[j] - acc[i], acc[i]};
        sort(all(sum));
        ans = min(ans, sum.back() - sum[0]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll max_flow_dfs(Graph& G, ll v, ll t, ll f, vector<bool>& used)
{
	if (v == t)
		return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); ++i) {
		Edge& e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used);
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}


//二部マッチングにも使える
ll max_flow(Graph& G, ll s, ll t)
{
	ll flow = 0;
	for (;;) {
		vector<bool> used(G.size());
		REP(i, used.size())used[i] = false;
		ll f = max_flow_dfs(G, s, t, INF, used);
		if (f == 0) {
			return flow;
		}
		flow += f;
	}
}

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

	ll n;
	cin >> n;

	Graph g(2 * n + 2);

	vector<P> a(n);
	REP(i, n) {
		cin >> a[i].first >> a[i].second;
	}
	vector<P> b(n);
	REP(i, n) {
		cin >> b[i].first >> b[i].second;

		REP(j, n) {
			if (a[j].first < b[i].first && a[j].second < b[i].second) {
				add_edge(g, j + 1, i + n + 1, 1, true, 0);
			}
		}
	}

	REP(i, n) {
		add_edge(g, 0, i+1, 1, true, 0);
		add_edge(g, i + n + 1, 2 * n + 1, 1, true, 0);
	}

	cout << max_flow(g, 0, 2 * n + 1) << endl;


	return 0;
}


Measured memory_bytes: 512