akhauriyash/Code-Regression huggingface dataset:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    from math import cos,radians
    P = 10**9+7
    INF = 10**9+10
    A,B,H,M = LMIIS()
    argA = M/60*360
    argB = (H/12+M/12/60)*360
    # print(cos(radians(90)))
    # print(argA,argB,cos(radians(abs(argA-argB))))

    print((A**2+ B**2 - 2*A*B*cos(radians(abs(argA-argB))))**0.5)

    
main()

Measured memory_bytes: 65716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll n;

vector<ll> v;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  v.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  ll anw = 0;
  ll i = 0;
  while(i < n) {
    if (v[i] == i+1) {
      anw++;
      i++;
    }
    i++;
  }
  cout << anw << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <iostream>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int v;
	cin >> v;
	vector<int> a;
	vector<int> b;

	for (int i = 1; i <= v; i++)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	for (int i = 1; i <= v; i++)
	{
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
	}

	vector<int> li;
	for (int i = 1; i <= v; i++)
	{
		li.push_back(i);
	}

	int x = 0;
	int y = 0;
	int c = 0;
	while (next_permutation(li.begin(), li.end()))
	{
		c++;
		bool check = true;
		for (int i = 0; i < v; i++)
		{
			if (a[i] != li[i])
			{
				check = false;
			}
		}
		if (check)
		{
			x = c;
		}

		check = true;

		for (int i = 0; i < v; i++)
		{
			if (b[i] != li[i])
			{
				check = false;
			}
		}
		if (check)
		{
			y = c;
		}
	}
	cout << abs(x - y);
}


Measured memory_bytes: 31488
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, k;
    bool x[105];

    cin >> n >> k;
    rep(i, n) x[i] = false;
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int bou;
            cin >> bou;
            bou--;
            x[bou] = true;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (!x[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long lli;
int main() {
	lli n, m;
	while(cin >> n >> m) {
		lli s = 0, c = 0, mi;
		vector<lli> v;
		for(lli i = 0; i < n; i++) { lli x; cin >> x; v.pb(x); s += x; }
		lli r = 4 * m;
		mi = ((s / r) + (s % r ? 1 : 0));
		for(lli i = 0; i < n; i++) { if(v[i] >= mi) c++; }
		if(c >= m) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())

dp = [0] * (W + 1)
weights2check = [0]
ans = 0
for _ in range(N):
    w, v = map(int, input().split())
    for k in range(W-w, -1, -1):
        dp[k + w] = max(dp[k + w], dp[k] + v)
        ans = max(ans, dp[k + w])


print(ans)


Measured memory_bytes: 41964
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;

  int c = 0;
  for(int i=0; i<=n-3; i++){
    if(s.substr(i,3)=="ABC"){
//      i += 3;
      c++;
    }
  }
  
  cout << c << endl;

  return 0;
}

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

int main() {
    string a;
    cin >> a;
    if((a.at(3)==a.at(2))&&(a.at(5)==a.at(4))){
            cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    } 
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    unordered_map<string, int> mp;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

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

    }

    private void solve() {
        int N = sc.nextInt();
        int cnt = 0;
        boolean finished = false;
        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }

        while (true) {
            for (int i = 0; i < N; i++) {
                if (nums[i] % 2 != 0) {
                    finished = true;
                }
                nums[i] /= 2;
            }
            if (finished) {
                break;
            }
            cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 23764
import java.io.*;
 
class Main
{
  public static void main(String args[])
  {
    int num;
    String buf;
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      buf = br.readLine();
      num = Integer.parseInt(buf);
      System.out.println(num * num * num);
    } catch(Exception e) {}
  }
}


Measured memory_bytes: 24344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B, M;
    cin >> A >> B >> M;

    vector<int> a(A),b(B);
    rep(i, A) cin >> a[i];
    rep(i,B) cin >> b[i];

    int ma = *min_element(ALL(a));
    int mb = *min_element(ALL(b));

    int ans = ma + mb;

    rep(i,M){
        int x,y,c;
        cin >> x >> y >> c;
        --x;
        --y;

        chmin(ans, a[x] + b[y] - c);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int c = Integer.parseInt(sc.next());
      String d = (a + b >= c)? "Yes" : "No";
      System.out.println(d);
    }
  }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int n, k;
int ps[2][2002][2002];
 
int sum(int r1, int c1, int r2, int c2, int w) {
	if(r1>r2 || c1>c2) return 0;
	int ret=ps[w][r2][c2];
	if(r1>0) ret-=ps[w][r1-1][c2];
	if(c1>0) ret-=ps[w][r2][c1-1];
	if(r1>0 && c1>0) ret+=ps[w][r1-1][c1-1];
	return ret;
}
 
int main() {
	scanf("%d %d",&n,&k);
	while(n--) {
		int x, y;
		char c;
		scanf("%d %d %c",&x,&y,&c);
		x%=2*k; y%=2*k;
		if(c=='W') ps[0][x][y]++;
		else ps[1][x][y]++;
	}
	for(int i=0;i<2*k;i++) {
		for(int j=0;j<2*k;j++) {
			for(int t=0;t<2;t++) {
				if(i>0) ps[t][i][j]+=ps[t][i-1][j];
				if(j>0) ps[t][i][j]+=ps[t][i][j-1];
				if(i>0 && j>0) ps[t][i][j]-=ps[t][i-1][j-1];
			}
		}
	}
	int res=0;
	for(int w=0;w<2;w++) {
		int d=sum(0,0,k-1,k-1,w)+sum(k,k,2*k-1,2*k-1,w)+
			sum(0,k,k-1,2*k-1,w^1)+sum(k,0,2*k-1,k-1,w^1);
		if(d>res) res=d;
	}
	for(int j=0;j+k+1<2*k;j++) {
		int r[3]={0,k,2*k}, c[4]={0,j+1,j+k+1,2*k};
		int sum1=0, sum2=0;
		for(int r1=0;r1<2;r1++) {
			for(int c1=0;c1<3;c1++) {
				if((r1+c1)%2) {
					sum1+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,0);
					sum2+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,1);
				} else {
					sum1+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,1);
					sum2+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,0);
				}
			}
		}
		if(max(sum1,sum2)>res) res=max(sum1,sum2);
	}
	for(int i=0;i+k+1<2*k;i++) {
		int r[4]={0,i+1,i+k+1,2*k}, c[3]={0,k,2*k};
		int sum1=0, sum2=0;
		for(int r1=0;r1<3;r1++) {
			for(int c1=0;c1<2;c1++) {
				if((r1+c1)%2) {
					sum1+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,0);
					sum2+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,1);
				} else {
					sum1+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,1);
					sum2+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,0);
				}
			}
		}
		if(max(sum1,sum2)>res) res=max(sum1,sum2);
	}
	for(int i=0;i+k+1<2*k;i++) {
		for(int j=0;j+k+1<2*k;j++) {
			int sum1=0, sum2=0;
			int r[4]={0,i+1,i+k+1,2*k}, c[4]={0,j+1,j+k+1,2*k};
			for(int r1=0;r1<3;r1++) {
				for(int c1=0;c1<3;c1++) {
					if((r1+c1)%2) {
						sum1+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,0);
						sum2+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,1);
					} else {
						sum1+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,1);
						sum2+=sum(r[r1],c[c1],r[r1+1]-1,c[c1+1]-1,0);
					}
				}
			}
			if(max(sum1,sum2)>res) res=max(sum1,sum2);
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 31488
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ld,ld>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n;
    cin>>n;
    vector<P> cylinders;
    FOR(i,0,n){
      ld r;
      cin>>r;
      ld distance = r;
      FOR(j,0,cylinders.size()){
        ld x = 2*sqrt(cylinders[j].second * r) + cylinders[j].first;
        distance = max(distance, x);
      }
      cylinders.push_back(P(distance,r));
    }
    ld ans=0;
    FOR(i,0,n){
      ans = max(ans,cylinders[i].first + cylinders[i].second);
    }
    cout(10)<<ans<<endl;
}



Measured memory_bytes: 3344
#include<cstdio>
using namespace std;
int main(void)
{
	int a,i,j,flg;
	scanf("%d",&a);
	flg=0;
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			if(i*j==a){
				flg=1;
				printf("Yes\n");
				break;
			}
		}
		if(flg==1){
			break;
		}
	}
	if(flg==0){
		printf("No\n");
	}
	return 0;
}

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

using namespace std;

using ll = long long;

int n, w;
vector<ll> weight, value;
vector<vector<ll>> dp;



ll solve(int i, int cap){
  if(i == n) return 0;
  if(dp[i][cap] != -1) return dp[i][cap];
  ll v = -1;
  if(cap >= weight[i]){
    v = max(solve(i+1, cap), value[i] + solve(i+1, cap-weight[i]));
  }else{
    v = solve(i+1, cap);
  }
  return dp[i][cap] = v;
}


int main() {
  int tmp, tmp1;
  cin>>n>>w;
  for(int i = 0; i < n; i++){
    cin>>tmp>>tmp1;
    weight.push_back(tmp);
    value.push_back(tmp1);
  }
  dp.assign(n+1, vector<ll>(w+1, -1));
//   ll res = solve(0, w);
  ll res;
//   for(int i = 0; i <= w; i++) dp[0][i] = 0;
//   for(int i = 1; i <= n; i++){
//       for(int j = 0; j <= w; j++){
//           if(weight[i-1] <= j){
//               dp[i][j] = max(dp[i-1][j], value[i-1] + dp[i-1][j-weight[i-1]]);
//           }else{
//               dp[i][j] = dp[i-1][j];
//           }
//       }
//   }
//   res = dp[n][w];
  vector<ll> dpone(w+1, 0);
  for(int i = 1; i <= n; i++){
      auto ndp = dpone;
      for(int j = 0; j <= w; j++){
          if(weight[i-1] <= j){
              ndp[j] = max(dpone[j], value[i-1] + dpone[j-weight[i-1]]);
          }else{
              ndp[j] = dpone[j];
          }
      }
      dpone = ndp;
  }
  res = dpone[w];
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 81008
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        List<Long> pa = new ArrayList<Long>();
        for (int i = 0; i < a; ++i) {
            pa.add(scanner.nextLong());
        }
        List<Long> pb = new ArrayList<Long>();
        for (int i = 0; i < b; ++i) {
            pb.add(scanner.nextLong());
        }
        List<Long> pc = new ArrayList<Long>();
        for (int i = 0; i < c; ++i) {
            pc.add(scanner.nextLong());
        }
        Collections.sort(pa, Collections.reverseOrder());
        Collections.sort(pb, Collections.reverseOrder());
        Collections.sort(pc, Collections.reverseOrder());
        long ans = 0;
        for (int i = 0; i < x; ++i) {
            ans += pa.get(i);
        }
        for (int j = 0; j < y; ++j) {
            ans += pb.get(j);
        }
        int i = x - 1;
        int j = y - 1;
        for (int k = 0; k < x + y && k < c; ++k) {
            long minApple =
                    i >= 0 && j >= 0
                            ? Math.min(pa.get(i), pb.get(j))
                            : i >= 0 ? pa.get(i)
                            : pb.get(j);
            if (i >= 0 && j >= 0) {
                if (pa.get(i) > pb.get(j)) {
                    --j;
                } else {
                    --i;
                }
            } else if (i >= 0) {
                if (pc.get(k) >= minApple) {
                    --i;
                }
            } else if (j >= 0) {
                if (pc.get(k) >= minApple) {
                    --j;
                }
            } else {
                break;
            }
            if (pc.get(k) >= minApple) {
                ans = ans - minApple + pc.get(k);
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 105220
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=100005;
const int MOD=1000000007;

int n,k,jc[N],ny[N],ans,cnt,last[N];
struct edge{int to,next;}e[N*2];

int A(int n,int m)
{
	return n<m?0:(LL)jc[n]*ny[n-m]%MOD;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x,int fa)
{
	int deg=0;
	for (int i=last[x];i;i=e[i].next)
	{
		if (e[i].to==fa) continue;
		dfs(e[i].to,x);
		deg++;
	}
	if (!fa) ans=(LL)ans*A(k,deg+1)%MOD;
	else ans=(LL)ans*A(k-2,deg)%MOD;
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		addedge(x,y);
	}
	jc[0]=jc[1]=ny[0]=ny[1]=1;
	for (int i=2;i<=std::max(n,k);i++) jc[i]=(LL)jc[i-1]*i%MOD,ny[i]=(LL)(MOD-MOD/i)*ny[MOD%i]%MOD;
	for (int i=2;i<=std::max(n,k);i++) ny[i]=(LL)ny[i-1]*ny[i]%MOD;
	ans=1;
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n >= (int)s.size()){
        cout << s << endl;
    }else {
        cout << s.substr(0,n) + "..." << endl;
    }
     return 0;
}

Measured memory_bytes: 3644
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    ll a, b, _q;
    cin >> a >> b >> _q;
    vector<ll> s(a);
    vector<ll> t(b);
    for(int i=0;i<a;++i)
    {
        cin >> s[i];
    }
    for(int i=0;i<b;++i)
    {
        cin >> t[i];
    }
    s.push_back(-1 * 1ll << 61);
    s.push_back(1ll << 61);
    t.push_back(-1 * 1ll << 61);
    t.push_back(1ll << 61);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    for(int i=0;i<_q;++i)
    {
        ll q;
        cin >> q;
        // s lower bound
        auto s_lower_it = lower_bound(s.begin(), s.end(), q);
        ll s_lower = *(prev(s_lower_it));
        ll s_upper = *s_lower_it;
        auto t_lower_it = lower_bound(t.begin(), t.end(), q);
        ll t_lower = *(prev(t_lower_it));
        ll t_upper = *t_lower_it;
        // dump(s_lower);
        // dump(s_upper);
        // dump(t_lower);
        // dump(t_upper);
        ll same_lower = max(q - s_lower, q - t_lower);
        ll same_upper = max(s_upper - q, t_upper-q);
        ll s_upper_t_lower = s_upper - t_lower + min(s_upper - q, q - t_lower);
        ll s_lower_t_upper = t_upper - s_lower + min(t_upper - q, q - s_lower);

        cout << min(same_lower, min(same_upper, min(s_upper_t_lower, s_lower_t_upper))) << endl;
    }
}

Measured memory_bytes: 2912
#include<stdio.h>
int main(){
  int a,b,ans=0;
  scanf("%d%d",&a,&b);
  if(a==1 && b==1){
    ans+=400000;
  }
  if(a==1){
    ans+=300000;
  }
  if(b==1){
    ans+=300000;
  }
  if(a==2){
    ans+=200000;
  }
  if(b==2){
    ans+=200000;
  }
  if(a==3){
    ans+=100000;
  }
  if(b==3){
    ans+=100000;
  }

  printf("%d\n",ans);
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const double INF=1000000000000000.0;
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;}

int main(){
	ll N,M; cin>>N>>M;
    priority_queue<P,vector<P>,greater<P>> que[100001];
    vector<ll> Y(M+1);
    vector<ll> p(M+1);
    vector<ll> ans(M+1);
    rep1(i,M){
        cin>>p[i]>>Y[i];
        que[p[i]].push(mp(Y[i],i));
    }
    rep1(i,N){
        ll cnt=1;
        while(!que[i].empty()){
            P pp=que[i].top(); que[i].pop();
            ans[pp.b]=cnt++;
        }
    }
    rep1(i,M){
        printf("%06lld%06lld\n",p[i],ans[i]);
    }
}

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

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

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
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; }
//lambda: [&](int x, int y){return x<y;}

const int MOD = 998244353;

signed main(void){
    int n;cin>>n;
    int dmax=0;
    vint cnt(n,0);
    rep(i,n){
        int d;cin>>d;
        if(i==0&&d!=0||i!=0&&d==0){
            cout << 0 << endl;
            return 0;
        }
        cnt[d]++;
        chmax(dmax,d);
    }

    ll ans=1;
    rep(i,dmax){
        ll res=1;
        rep(j,cnt[i+1])res=res*cnt[i]%MOD;
        ans=ans*res%MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using ll = long long int;

int main(int argc,char *argv[])
{
	ll n,m;
	std::cin >> n >> m;
	
	ll a;
	for(ll i = 0;i < m;++i)
	{
		std::cin >> a;
		n -= a;
	}

	if (n < 0) { std::cout << "-1" << std::endl; }
	else { std::cout << n << std::endl; }

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
const int INF = (int)1e18 + 18 ;
const int maxx = (int) 1e6 + 6 ;
using namespace std ;
 
 
int n, k;
 
signed main() {

	cin >> n >> k;

	int a[n];

	vector<int> dp(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	dp[0] = 0;
	dp[1] = dp[0] + abs(a[1] - a[0]);
	for(int i = 2; i < n; i++){
		vector <int> vec;
		for(int j = 1; j <= k; j++){
			if(i-j >= 0){
				vec.push_back(dp[i - j] + abs(a[i] - a[i - j]));
			}
		}

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

		dp[i] = vec[0];
	}

	cout << dp[n - 1] << endl;


return 0;
 
}

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) {
		string s;
		cin >> s;
		if (s[0] == 'A' && s[1] == 'B'  && s[2] == 'C')
			cout << "ARC" << endl;
		else
			cout << "ABC" << endl;

	}
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 13) cout << b;
    else if (a <= 5) cout << 0;
    else cout << b / 2;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<int> next(n);

    for (int i = 0; i < m; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        l--;
        next[l] = max(next[l], r);
    }
    for (int i = 0; i < n; ++i) {
        next[i] = max(next[i], i+1);
        if(i) next[i] = max(next[i], next[i-1]);
    }
    vector<ll> dp(n+1, -INF<ll>);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        dp[i+1] = max(dp[i+1], dp[i]);
        dp[next[i]] = max(dp[next[i]], dp[i]+v[i]);
    }
    cout << dp[n] << "\n";
    return 0;
}


Measured memory_bytes: 6032
f = []

for i in range (5):
  f.append(int(input()))
  
time = 0

machi = []
for i in range (5):
  if f[i]%10 == 0:
    time += f[i]
  else:
    time += f[i] + (10-(f[i]%10))
    machi.append(10-(f[i]%10))
    
if len(machi) == 0:
  print(time)
else:
  print(time- max(machi))

Measured memory_bytes: 3060
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

std::string str1,str2;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	std::getline(std::cin,str1);
	std::getline(std::cin,str2);
	std::sort(str1.begin(),str1.end());
	std::sort(str2.begin(),str2.end(),std::greater<char>());
	std::cout<<(str1<str2?"Yes\n":"No\n");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3.5
S = int(input())
if S < 60:
    print("0:0:",S,sep='')
elif S < 3600:
    print("0:",int(S/60),":",S%60,sep='')
else:
    print(int(S/3600),":",int((S%3600)/60),":",(S%60)%60,sep='')


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    string S; cin >> S;
    bool flag = true;
    rep(i,S.length()){
        if(i%2 == 0 && !(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')){
            cout << "No";
            flag = false;
            break;
        }
        if(i%2 == 1 && !(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')){
            cout << "No";
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  int a=0,b=0,c=0;
  rep(i,n) {
    int x;
    R x;
    if(x%4==0) a++;
    else if(x%2==0) b++;
    else c++;
  }
  if(!a) {
    if(b==1||c) {
      pr("No");
      return;
    }
  }
  while(c>0&&a>0) {
    c--;
    a--;
  }
  if(!a) {
    if(!c||c==1&&!b) pr("Yes");
    else pr("No");
  } else pr("Yes");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main(int argc, const char * argv[]) {
    int N,B[10]={},C[10]={},b=0,c=0,i,j,ball[10],flag=0,k;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        for(j=0;j<10;j++){
            scanf("%d",&ball[j]);
            if(j==0){
                B[b]=ball[j];
                b++;
                c++;
            }
            else if(B[b-1]>ball[j]&&C[c-1]<ball[j]){
                C[c-1]=ball[j];
                if(C[1]!=0)
                c++;
            }
            else if(B[b-1]>ball[j]&&C[c-1]>ball[j]){
                flag=1;
                continue;
            }
            else if(ball[j]-B[b-1]<ball[j]-C[c-1]){
                B[b]=ball[j];
                b++;
            }
            else{
                C[c]=ball[j];
                    c++;
            }
        }
        if(flag==0)
            printf("YES\n");
        if(flag==1)
            printf("NO\n");
        
        b=0;c=0;
        for(k=0;k<10;k++){
            //printf("%d %d\n",B[k],C[k]);
            B[k]=0;
            C[k]=0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 580
C = [list(map(int, input().split())) for _ in range(3)]
targets = [(0, 1), (1, 0), (1, 2), (2, 1), (2, 0), (0, 2)]
for i, j in targets:
    if (C[i][i] + C[i][j] + C[j][i] + C[j][j]) % 2 != 0:
        print("No")
        break
else:
    if sum([sum(c) for c in C]) % 3 != 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 3064
import java.util.*;

class BS
{
    public Boolean BinarySearch(int b, int [] arr)
    {
        int l = 0; int r = arr.length; Boolean hasItem = false;
        while(l<r)
        {
            int mid = (l+r)/2;
            int key = arr[mid];
            if(key==b)
            {
                hasItem=true;
                break;
            }
            else if(b<key) r = mid;
            else l = mid+1;
        }
        return hasItem;
    }
}
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a [] = new int[n];
        for(int i = 0; i<n; i++) a[i] = sc.nextInt();
        int q = sc.nextInt();
        BS bs = new BS();
        int cnt = 0;
        for(int i = 0; i<q; i++) 
        {
            if(bs.BinarySearch(sc.nextInt(),a))
            {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}



Measured memory_bytes: 67404
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  w, h, x, y = map(int, readline().split())
  s = w*h/2
  if x==w/2 and y==h/2:
    ans = 1
  else:
    ans = 0
  print('{} {}'.format(s, ans))
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5216
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;

int vertex_no(int h, int w, int i, int j, int b) {
	return h * w*b + w * (j - 1) + i;
}
int grid[105][105];

struct edge
{
	int from; int to; long long cost; int rev;
};
int const MAX = 100005;
vector<edge> G[MAX];
long long const INF = 10000000000000016;
int parent[MAX];
int from_edge[MAX];
long long costs[MAX];

bool dfs(int n, int start, int goal, vector<edge>V[], long long &amount) {
	for (int i = 0; i <= n; i++) {
		parent[i] = -1;
	}
	stack<int> s;
	parent[start] = 0;
	costs[start] = INF*5;
	s.push(start);
	while (!s.empty()) {
		int now = s.top();
		s.pop();
		for (int i = 0; i < G[now].size(); i++) {
			edge next_edge = G[now][i];
			int next = next_edge.to;
			if (parent[next] == -1 && next_edge.cost > 0) {
				parent[next] = now;
				from_edge[next] = i;
				costs[next] = min(costs[now], next_edge.cost);
				s.push(next);
			}
		}
	}
	amount = costs[goal];
	return parent[goal] != -1;
}

void max_flow(int n, int start, int goal, vector<edge>V[], long long &flow) {
	long long amount;
	while (dfs(n, start, goal, V, amount)) {
		int now = goal;
		while (now != start) {
			int p = parent[now];
			G[p][from_edge[now]].cost -= amount;
			int r = G[p][from_edge[now]].rev;
			G[now][r].cost += amount;
			now = parent[now];
		}
		flow += amount;
	}
}

int dir_x[4] = { 1,0,-1,0 };
int dir_y[4] = { 0,1,0,-1 };

int main() {
	int start, goal;
	int h; int w;	
	cin >> h >> w;
	start = 0;
	goal = h * w * 2 + 1;
	for (int j = 1; j <= h; j++) {
		for (int i = 1; i <= w; i++) {
			char c;
			cin >> c;
			grid[i][j] = (c == 'X');
			if (c == 'X' && (i == 1 || i == w || j == 1 || j == h)) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	for (int i = 1; i <= w; i++) {
		for (int j = 1; j <= h; j++) {
			if (i == 1 || i == w || j == 1 || j == h) {
				int x, y;
				x = vertex_no(h, w, i, j, 0);
				y = goal;
				G[x].push_back({ x,y,INF,int(G[y].size()) });
				G[y].push_back({ y,x,INF,int(G[x].size() - 1) });
				y = x;
				x = vertex_no(h, w, i, j, 1);
				G[x].push_back({ x,y,1,int(G[y].size()) });
				G[y].push_back({ y,x,0,int(G[x].size() - 1) });
			}
			else if (grid[i][j] == 1) {
				int x, y;
				x = vertex_no(h, w, i, j, 0);
				for (int k = 0; k < 4; k++) {
					y = vertex_no(h, w, i + dir_x[k], j + dir_y[k], 1);
					G[x].push_back({ x,y,INF,int(G[y].size()) });
					G[y].push_back({ y,x,0,int(G[x].size() - 1) });
				}
				y = x;
				x = start;
				G[x].push_back({ x,y,INF,int(G[y].size()) });
				G[y].push_back({ y,x,0,int(G[x].size() - 1) });
			}
			else {
				int x, y;
				x = vertex_no(h, w, i, j, 0);
				for (int k = 0; k < 4; k++) {
					y = vertex_no(h, w, i + dir_x[k], j + dir_y[k], 1);
					G[x].push_back({ x,y,INF,int(G[y].size()) });
					G[y].push_back({ y,x,0,int(G[x].size() - 1) });
				}
				y = x;
				x = vertex_no(h, w, i, j, 1);
				G[x].push_back({ x,y,1,int(G[y].size()) });
				G[y].push_back({ y,x,0,int(G[x].size() - 1) });
			}
		}
	}
	long long flow = 0;
	max_flow(h*w*2 + 1, start, goal, G, flow);
	std::cout << flow << endl;
}

Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {
	
	public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
       int ar[]=new int[4];
       for(int i=0;i<3;i++)
       {
           int a=sc.nextInt();
           int b=sc.nextInt();
           ar[a-1]+=1;
           ar[b-1]+=1;
       }
       for(int i:ar)
       {
           if(i>2)
           {
               System.out.println("NO");
               System.exit(0);
           }
       }
       System.out.println("YES");
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n, a[2][100], sum0, sum1 = 0, ans;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[0][i];
    }
    for(int i = 0; i < n; i++){
        cin >> a[1][i];
        sum1 += a[1][i];
    }
    sum0 = a[0][0];
    ans = sum0 + sum1;
    for(int i = 1; i < n; i++){
        sum0 += a[0][i];
        sum1 -= a[1][i-1];
        ans = max(ans, sum0 + sum1);
    }
    cout << ans << endl;
    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  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() {
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll,ll>,P> mp;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x,y);
    x /= g;
    y /= g;
    if (y < 0) x = -x, y = -y;
    if (y == 0 && x < 0) x = -x, y = -y;
    bool rot90 = (x <= 0);
    if (rot90) {
      ll tmp = x;
      x = y; y = -tmp;
    }
    if (rot90) mp[{x,y}].first++;
    else mp[{x,y}].second++;
  }

  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;

  ans += zero;
  cout << ans << endl;
  return 0;
}


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

#define MAX 100000001
bool p[MAX];

int main()
{
	int N;
	/*
	for (int i=0; i<MAX; i++)
		p[i] = true;

	p[0] = [1] = false;
	for (int i=2; i*i<MAX; i++)
	{
		if (p[i])
		{
			for (int k=i; k<MAX; k+=i)
				p[k] = false;
		}
	}*/

	while (cin >> N, N)
	{
		int sum = 1;
		if (N == 1) sum = 0;
		for (int i=2; i*i<=N; i++)
		{
			if (N%i == 0)
			{
				sum += i;
				sum += N/i;
			
				if (i == N/i)
				{
					sum -= i;
				}
			}
		}

		if (sum < N) cout << "deficient number" << endl;
		else if (sum == N) cout << "perfect number" << endl;
		else cout << "abundant number" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n, a, b, c;
  cin >> n >> a >> b;
  if (n > 2) c = (n - 2) * (b - a) + 1;
  else {
    if (n == 2) c = 1;
    else {
      if (a == b) c = 1;
      else c = 0;
    }
  }
  if (a > b) c = 0;
  cout << c << endl;
}

Measured memory_bytes: 256
#(0)入力環境
import bisect#listをsortしたまま要素を挿入できる
n = int(input())
l = sorted(list(map(int,input().split())))

#(1)考察
#aとbの二重ループのなかで最後の一つは二分探索で高速に
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += bisect.bisect_left(l,l[i] + l[j]) - (j + 1)
        

print(ans)

Measured memory_bytes: 9300
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)[::-1]

minp = a[p-1]
result = 0
td = 0
count = 0
tpcount = 1
tptd = 0
pre = minp
for i in range(p, n):
    if pre != a[i]:
        td += tptd
        count += tpcount
        tptd = 0
        tpcount = 0
    if m * min(n-v, count) >= (minp - a[i]) * count - td and minp <= a[i] + m:
        result+=1
        tpcount+=1
        tptd+= minp - a[i]
        pre = a[i]
    else:
        break
print(result+p)

Measured memory_bytes: 62768
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())

using namespace std;

int main() {
	int a = 0;
	string s;
	cin >> s;
	ff(i, 0, s.size() / 2 ) {
		if (s[i] != s[s.size() - 1 - i]) {
			a++;
		}
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,x=0,y=0,ans=0;
    
    cin >> n;
    vector<int> vec (n,0);

    for (int i=0;i<n;i++){
        cin >> vec.at(i);
    }
    for (int i=0;i<n;i++){
        for (int j=i+1;j<n;j++){
            ans += vec.at(i) * vec.at(j); 
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC124A
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').ToArray();

            var A = int.Parse(line[0]); var B = int.Parse(line[1]);

            if(A > B)
            {
                Console.WriteLine(A + A - 1);
            }
            else if(A < B)
            {
                Console.WriteLine(B + B - 1);
            }
            else
            {
                Console.WriteLine(A + B);
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  ll ans = 0;
  if (a[0] > x) {
    ans += a[0]-x;
    a[0] -= a[0]-x;
  }
  rep(i,n-1) {
    ll sum2 = a[i]+a[i+1];
    if (sum2 > x) {
      ans += sum2-x;
      a[i+1] -= sum2-x;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1152