akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int ans = int.MaxValue;
        for (int i = 1; i < n; i++)
        {
            int a = i;
            int b = n - i;
            ans = Math.Min(ans, sum(a) + sum(b));
        }
        C.WriteLine(ans);
    }
    static int sum(int n)
    {
        string s = n.ToString();
        int sum = 0;
        for (int i = 0; i < s.Length; i++)
            sum += (int)Char.GetNumericValue(s[i]);
        return sum;
    }
}
//以下標準出力用のクラス
static class C
{
    [System.Runtime.InteropServices.DllImport("msvcrt.dll")]
    private static extern void printf(string s);
    public static void Write(string s) { printf(s); }
    public static void Write(char c) { printf(c.ToString()); }
    public static void Write(long n) { printf(n.ToString()); }
    public static void Write(int n) { printf(n.ToString()); }
    public static void Write(double d) { printf(d.ToString()); }
    public static void WriteLine() { printf("\n"); }
    public static void WriteLine(string s) { printf(s + "\n"); }
    public static void WriteLine(char c) { WriteLine(c.ToString()); }
    public static void WriteLine(long n) { WriteLine(n.ToString()); }
    public static void WriteLine(int n) { WriteLine(n.ToString()); }
    public static void WriteLine(double d) { WriteLine(d.ToString()); }
    public static void WriteLines(string[] s) { foreach (var i in s) WriteLine(i); }
    public static void WriteLines(char[] c) { foreach (var i in c) WriteLine(i); }
    public static void WriteLines(long[] c) { foreach (var i in c) WriteLine(i); }
    public static void WriteLines(int[] c) { foreach (var i in c) WriteLine(i); }
    public static void WriteLines(double[] d) { foreach (var i in d) WriteLine(i); }
}

Measured memory_bytes: 17360
/*
	期望乘上那个组合数就是所有方案下的答案了对吧
	首先原问题可以转化成这样一个问题
	每一个人可以从拥有的曲奇里选择某一天的一个曲奇
	答案其实也正好是 \prod c_i
	所以我们只需要关心每个人选的那个曲奇了 (神奇的是这个与原问题是等价的)
	设 x_i 表示的是有 x_i 个人在第 i 天得到了它们选择的曲奇
	先不考虑顺序, 钦定是前面 x_i 个人得到了这 x_i 个曲奇
	转移系数是 comb(N - x_i, a_i - x_i) (将剩下还没被选的曲奇随便分给其他人)
	最后再将人排序, 乘上 \frac {N!} {\prod x_i!} (同一天选的与顺序没有关系, 所以要除 x_i!)
	答案其实就是 N! \prod \frac {comb(N - x_i, a_i - x_i)} {x_i!}
	根据这个可以设出状态 f[i][j] 表示前 i 天有 j 个人选了曲奇的方案数
	转移时枚举 x_i 并乘上有关于 x_i 的系数
	状态 O(NK), 转移 O(N), 时间复杂度 O(N^2 K)
*/
#include <bits/stdc++.h>
#define K 25
#define N 1005

using namespace std;

const int mod = 1e9 + 7;

int n, k;
int a[K], f[K][N];
int fac[N], ifac[N];

inline int fpm(int x, int y) {
	int r = 1;
	while(y) {
		if(y & 1) r = 1LL * r * x % mod;
		x = 1LL * x * x % mod, y >>= 1;
	}
	return r;
}
inline int perm(int x, int y) { return 1LL * fac[x] * ifac[x - y] % mod; }
inline int comb(int x, int y) { return 1LL * perm(x, y) * ifac[y] % mod; }

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; ++i)
		scanf("%d", &a[i]);
	
	fac[0] = 1;
	for(int i = 1; i <= n; ++i) fac[i] = 1LL * i * fac[i - 1] % mod;
	ifac[n] = fpm(fac[n], mod - 2);
	for(int i = n; i; --i) ifac[i - 1] = 1LL * i * ifac[i] % mod;
	
	f[0][0] = 1;
	for(int i = 0; i < k; ++i) {
		for(int j = 0; j <= n; ++j) {
			if(!f[i][j]) continue;
			for(int x = 0; x <= a[i + 1] && j + x <= n; ++x) {
				f[i + 1][j + x] = (f[i + 1][j + x] + 
				1LL * f[i][j] * comb(n - x, a[i + 1] - x) % mod * ifac[x]) % mod;
			}
		}
	}
	
	int ans = 1LL * fac[n] * f[k][n] % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

deque<int> vi;
int main(){
    int n,ai;
    cin>>n;
    rep(i,n){
        cin>>ai;
        if(i%2==0) vi.push_back(ai);
        else vi.push_front(ai);
    }
    if(n%2==1)reverse(vi.begin(),vi.end());
    rep(i,vi.size()) cout<<vi[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		System.out.println((a * n < b)? a * n : b);
	}
}

Measured memory_bytes: 21844
s = gets.split.map{|item| item.to_i}

x = []
y = []
z = []

    if s[0] == 1 || s[0] == 3 || s[0] == 5 || s[0] == 7 || s[0] == 8 || s[0] == 10 || s[0] == 12
        x.push(s[0])
    elsif s[0] == 4 ||s[0] == 6 ||s[0] == 9 ||s[0] == 11
        y.push(s[0])
    elsif s[0] == 2
        z.push(s[0])
    end

    if s[1] == 1 || s[1] == 3 || s[1] == 5 || s[1] == 7 || s[1] == 8 || s[1] == 10 || s[1] == 12
        x.push(s[1])
    elsif s[1] == 4 ||s[1] == 6 ||s[1] == 9 ||s[1] == 11
        y.push(s[1])
    elsif s[0] == 2
        z.push(s[1])
    end

if x.size == 2 || y.size == 2 || z.size == 2
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
	int N;
	scanf("%d", &N);
	int A[100001];
	for (int i = 0; i < 100001; i++) A[i] = 0;

	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	qsort(A, N, sizeof(int), compare_int);

	int ans = 0, flag = 1;
	int hoge = A[0];
	for (int i = 1; i < N; i++) {
		if (hoge == A[i]) {
			flag = !flag;
		}
		else {
			ans += flag;
			hoge = A[i];
			flag = 1;
		}
	}

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

Measured memory_bytes: 892
import Control.Applicative

solve d [] = d
solve [a,b,c,d,e,f] (x:xs)
	| x == 'E' = solve [d,b,a,f,e,c] xs
	| x == 'N' = solve [b,f,c,d,a,e] xs
	| x == 'S' = solve [e,a,c,d,f,b] xs
	| x == 'W' = solve [c,b,f,a,e,d] xs

main = do
	dice <- words <$> getLine
	com <- getLine
	putStrLn $ (!! 0) $ solve dice com

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

int main() {
	long int sum=0,n,i,k,count=0;
	cin>>n>>k;
	long int a[n];
	long int min1=INT_MAX;
	for(i=0;i<n;i++)
	  {
	  	  cin>>a[i];
	  	  sum+=a[i];
	  	  min1=min(a[i],min1);
	  }
	 count=n; 
	 while(1)
	  {
	  	  sum+=min1;
		  if(sum>k)
		     break;
	  	  ++count;
	  }
	 cout<<count<<" ";
	// your code goes here
	return 0;
}

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

void solve() {
	int a, b; cin >> a >> b;
	int ans;
	if (a > 9) ans = -1;
	else if (b > 9) ans = -1;
	else ans = a * b;
	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())

flag = False
for i in range(n + 1):
    for j in range(n + 1 - i):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            flag = True
            ans = (i, j, n - i - j)

print(*ans) if flag else print('-1 -1 -1 ')


Measured memory_bytes: 3060
n = int(input())
cs = [ (s,k) for s in ['S', 'H', 'C', 'D'] for k in range(1,14) ]
for _ in range(n):
    s,k = input().split()
    cs.remove((s,int(k)))
for (s, k) in cs:
    print(s, k)

Measured memory_bytes: 7684
# finding the biggest k values

import heapq

def c():
    
    n, k = map(int, input().split())
    if k >= n:
        return 0

    healths = list(map(int, input().split()))
    heapq.heapify(healths)

    res = 0
    for _ in range(n - k):
        res += heapq.heappop(healths)

    return res


def main():
    res = c()
    print(res)

    
# function call 
main()


Measured memory_bytes: 25768
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

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

long long MAX(vector<int> Vec){//配列の最大値
  int n=Vec.size();
  int max= -2147483648;
  for(int i=0;i<n;i++){
    if(max<Vec.at(i))max=Vec.at(i);
  }
  return max;}
long long SUM(vector<int> Vec){//配列の和
  int n=Vec.size();
  int sum= 0;
  for(int i=0;i<n;i++){
    sum+=Vec[i];
  }
  return sum;}
int main() {
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n)cin>>v[i];
  if( (SUM(v)-MAX(v))>MAX(v) )cout<<"Yes";
  else cout<<"No";
}

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

int main(){
    int n,k; cin >> n >> k;
    double ans=0;
    rep2(i,n+1){
        int x=i;
        double p=1;
        while(x<k){
            x*=2;
            p/=(double)2;
        }
        ans+=p;
    }
    ans/=(double)n;
    cout << fixed << setprecision(11) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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 c(int x,int y,int z){
    set<int> st;
    st.insert(x);
    st.insert(y);
    st.insert(z);
    if(st.size()==1) return 1;
    if(st.size()==2) return 3;
    if(st.size()==3) return 6;

}
int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int ans=0;
        for(int x=1;x*x<n;x++){
            for(int y=x;y*y<n;y++){
                for(int z=y;z*z<n;z++){
                    if(x*x+y*y+z*z+x*y+y*z+z*x>i) break;
                    if(x*x+y*y+z*z+x*y+y*z+z*x==i) ans+=c(x,y,z);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3504
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

enum Tenki
{
    Sunny,
    Cloudy,
    Rainy
};

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

    cout << ((N[0] == N[2]) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
arr = [int(x) for x in input().split(' ')]
ppp = arr.copy()

arr.sort()

dc = 0

for i in range(n):
    if(arr[i] != ppp[i]):
        dc += 1

if(dc > 2):
    print("NO")
else:
    print("YES")



Measured memory_bytes: 3060
import sys
S = input()
cnt = [False] * 26
for i in S:
    if i in "abcdefghijklmnopqrstuvwxyz":
        cnt[ord(i) - ord('a')] = True
 
for i in range(len(cnt)):
    if not cnt[i]:
        print(chr(ord('a')+i))
        sys.exit()
print("None")

Measured memory_bytes: 39280
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::vector<int> h(N);
    for (int i = 0; i < N; i++) {
        std::cin >> h[i];
    }

    std::vector<int> dp(N);
    for (int i = 0; i < N; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    dp[1] = std::abs(h[1] - h[0]); 
    for (int i = 2; i < N; i++) {
        dp[i] = std::min(dp[i-1] + std::abs(h[i] - h[i-1]), dp[i-2] + std::abs(h[i] - h[i-2]));
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,a,ans=1,min;
	cin>>n;
	cin>>a;
	min=a;
	for(int i=0;i<n-1;i++)
	{
		cin>>a;
		if(a<=min)
		{
			ans++;
			min=a;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define gol(k) for(ll u=0;u<k;u++)
int main(){
	int an=0,n,d;cin>>n>>d;
	while(n--){
		ll a,b;cin>>a>>b;
		if(d>=sqrtl(a*a+b*b)) an++;}
	cout<<an;
}


Measured memory_bytes: 3612
#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>;
using V = vector<int>;
int main(int argc, char const *argv[])
{
    int d, t, s;
    cin >> d >> t >> s;
    if (d <= t * s)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
    int n; cin >> n;
    int a[1001] = {};
    long long ans = 1;
    for (int i = 2; i <= n; ++i) { //n!
        int t = 2;
        int k = i;
        while (k != 1) {
            while (k % t == 0) {
                a[t]++;
                k /= t;
            }
            t++;
        }
    }
    for (int i = 2; i <= 997; ++i) {
        ans *= a[i] + 1;
        ans %= (long long)1e9 + 7;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

#define MODX 1000000007

void solve()
{
    ll A, B;
    cin >> A >> B;
    cout << max(A - B * 2, (ll)0) << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)




int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE

// ll n;
// cin>>n;
// map <ll,ll> m1,m2;
// ve <ll> b(n),c(n);
// FOR(i,0,n)
// cin>>b[i],m1[b[i]]++;
// FOR(i,0,n)
// cin>>c[i],m2[c[i]]++;
// ll ok=1;
// FOR(i,0,n){
// 	if(m2[b[i]]>n-m1[b[i]])
// }

ll n;
cin>>n;
ve <pair<ll,ll> > v(n);
FOR(i,0,n){
	ll x,y;cin>>x>>y;
	v[i]={x,y};
}
ll ans=-INF;
ll z1=v[0].F+v[0].S,z2=v[0].S-v[0].F,z3=-v[0].F-v[0].S,z4=v[0].F-v[0].S;
FOR(i,1,n){
ans=max(ans,z1-v[i].F-v[i].S);
ans=max(ans,z3+v[i].F+v[i].S);
ans=max(ans,z2+v[i].F-v[i].S);
ans=max(ans,z4-v[i].F+v[i].S);
 z1=max(z1,v[i].F+v[i].S);z2=max(z2,v[i].S-v[i].F);
 z3=max(z3,-v[i].F-v[i].S);z4=max(z4,v[i].F-v[i].S);
}
cout<<ans;



return 0;
 }



Measured memory_bytes: 6360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	int dp[n];
	dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1];

}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,k,t;
ll facn=1,inv[maxn],a[maxn];
int main()
{
    int i,j;
  	//freopen("in.txt","r",stdin);
    scanf("%d",&n);
    inv[0]=inv[1]=1;
    for(i=1;i<=n;i++)
    {
        facn=facn*i%mod;
        if(i>=2)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        scanf("%lld",&a[i]);
    }
    for(i=2;i<=n;i++)(inv[i]+=inv[i-1])%=mod;
    ll ret=0;
    for(i=1;i<=n;i++)
    {
        ll tmp=inv[i]+inv[n-i+1]-inv[1];
        (ret+=tmp*a[i]%mod)%=mod;
    }
    (ret*=facn)%=mod;
    (ret+=mod)%=mod;
    printf("%lld\n",ret);
  	return 0;
}


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

ans = 0
for i in range(N-1):
    res = A[i]+A[i+1]
    if res>x and A[i]>x:
        ans = ans + (res-x)
        A[i+1] = 0
        A[i] = x
    elif res > x:
        ans = ans + (res-x)
        A[i+1] = A[i+1] - (res-x)
    else:
        continue
    
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110];
int main(){
    ll n,ans=0;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    sort(a,a+n,greater<ll>());
    rep(i,0,n){
        if(i%2==0)ans+=a[i];
        else ans-=a[i];
    }
    cout<<ans;
}

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

int main(){
    char a;
    cin >> a;

    if (isupper(a)) cout << "A" << endl;
    else cout << "a" << endl;

    return 0;
}

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

long long h;
vector<long long> v;

void makeh(int id);

int main() {
  cin >> h;
  v.resize(h + 1);
  for(int i = 0; i < h; ++i) cin >> v[i + 1];
  for(int i = h / 2; i > 0; --i) makeh(i);
  for(int i = 1; i <= h; ++i) cout << " " << v[i];
  cout << endl;
  return 0;
}

void makeh(int id) {
  long long l = id * 2, r = id * 2 + 1, lar = id;
  if(l <= h && v[l] > v[lar]) lar = l;
  if(r <= h && v[r] > v[lar]) lar = r;
  if(lar != id) {
    swap(v[id], v[lar]);
    makeh(lar);
  }
}



Measured memory_bytes: 6704
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int D;
vector<ll> c(26);
vector<vector<ll>> s;
vector<ll> happy;
vector<int> last;



ll update(int d){
    happy[d] += happy[d-1];
    for(int i = 0; i < 26;i++){
        happy[d] -= c[i]*(d-last[i]);
    }
    
    return happy[d];
}

template<class Type>
Type solve(Type res = Type()){
    cin >> D;
    for(auto& in: c) cin >> in;
    s.resize(D,vector<ll>(26));
    for(int i = 0; i < D;i++){
        for(auto& in:s[i]) cin >> in;
    }
    happy.resize(D+1);
    last.resize(26);
    
    {// B
        for(int d = 1; d <= D;d++){
            int t; cin >> t;
            t--;
            
            
            happy[d] = s[d-1][t];
            last[t] = d;
            
            update(d);
            
            cout << happy[d] << endl;
        }
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3740
import sys
from itertools import permutations

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, R = map(int, input().split())
    r = list(map(lambda x: int(x) - 1, input().split()))
    P = permutations(r)

    dp = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0

    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        dp[a][b] = c
        dp[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                tmp = dp[i][k] + dp[k][j]
                if tmp < dp[i][j]:
                    dp[i][j] = tmp

    ans = float("inf")
    for p in P:
        tmp = 0
        for i in range(R - 1):
            tmp += dp[p[i]][p[i + 1]]

        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


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

int main()
{
    string S;
    cin >> S;

    if( (S[0] == S[1] and S[1] == S[2]) or (S[1] == S[2] and S[2] == S[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
D,d=$<.map &:split
f=->a{a.map{|i|d[i]}.rotate.map.with_index{|v,i|d[a[i]]=v}}
(0..23).map{|i|f[[1,2,4,3]]
d==D&&(puts :Yes)^exit
i%4<1&&f[i%8<4?[0,4,5,1]:[0,2,5,3]]}
puts:No

Measured memory_bytes: 6124
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define rep(i,n) for (int i = 0 ;i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int s[6], c[6];
	rep(i, 6) {
		cin >> s[i] >> c[i];
	}
	rep(i, m) {
		for (int j = i + 1; j < m; j++) {
			if (s[i] == s[i + j] && c[i] != c[i + j]) {
				cout << "-1" << endl;
				return 0;
			}
		}
	}
	if (n == 1) {
		int f = -1;
		rep(i, m) {
			if (s[i] == 1) {
				f = i;
			}
		}
		cout << c[f] << endl;
	}
	else if (n == 2) {
		int k = -1;
		int d = -1;
		rep(i, m) {
			if (s[i] == 1) {
				k = i;
			}
			else if (s[i] == 2) {
				d = i;
			}
		}
		if (k == -1&&d!=-1) {
			cout << "1" << c[d] << endl;
		}
		else if (k == -1 && d == -1) {
			cout << "10" << endl;
		}
		else if (c[k] != 0 && d != -1) {
			cout << c[k] << c[d] << endl;
		}
		else if (c[k] != 0 && d == -1) {
			cout << c[k] << "0" << endl;
		}
		else if (c[k] == 0) {
			cout << "-1" << endl;
		}
	}
	else {
		int v = -1;
		int t = -1;
		int u = -1;
		rep(i, m) {
			if (s[i] == 1) {
				v = i;
			}
			else if (s[i] == 2) {
				t = i;
			}
			else if (s[i] == 3) {
				u = i;
			}
		}
	    if (v== -1 && t != -1 && u != -1) {
		cout << "1" << c[t] << c[u] << endl;
		}
		else if (v==-1 && t != -1 && u == -1) {
		cout << "1" << c[t] << "0" << endl;
		}
		else if (v==-1 && t == -1 && u == -1) {
		cout << "1" << "00" << endl;
		}
		else if (v==-1 && t == -1 && u != -1) {
		cout << "1"<< "0" << c[u] << endl;
		}
		else if (c[v] != 0 && t != -1 && u != -1) {
			cout << c[v] << c[t] << c[u] << endl;
		}
		else if (c[v] != 0 && t != -1 && u == -1) {
			cout << c[v] << c[t] << "0" << endl;
		}
		else if (c[v] != 0 && t == -1 && u == -1) {
			cout << c[v] << "00" << endl;
		}
		else if (c[v] != 0 && t == -1 && u != -1) {
			cout << c[v] << "0" << c[u] << endl;
		}
		else if (c[v] == 0) {
			cout << "-1" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

def read_int():
    line = sys.stdin.readline().rstrip('\n')
    return int(line)

def read_int_list():
    line = sys.stdin.readline().rstrip('\n')
    return [int(e) for e in line.split(' ')]

N = read_int()
subs = []
for _ in range(N):
    subs.append(sys.stdin.readline().rstrip('\n'))

c = Counter(subs)

for type in ['AC', 'WA', 'TLE', 'RE']:
    print(type + ' x ' + str(c[type]))

Measured memory_bytes: 16616
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();
        int k = sc.nextInt();

        int ans = 0;
        
        for (int i = 0; i<n; i++){
            if (sc.nextInt() >= k)
                ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 58540
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut vv = vec![vec![0; 0]; 8];

    for _ in 0..n {
        let x: i64 = read();
        let y: i64 = read();
        let z: i64 = read();
        vv[0].push(x + y + z);
        vv[1].push(x + y - z);
        vv[2].push(x - y + z);
        vv[3].push(x - y - z);
        vv[4].push(-x + y + z);
        vv[5].push(-x + y - z);
        vv[6].push(-x - y + z);
        vv[7].push(-x - y - z);
    }

    println!(
        "{}",
        vv.iter_mut()
            .map::<i64, _>(|v| {
                v.sort_by(|a, b| b.cmp(a));
                v.iter().take(m).sum()
            })
            .max()
            .unwrap()
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int N, M;
string S;
vector<int> path;

bool rec(int p) {
	if (p <= M) {
		path.push_back(p);
		return true;
	}
	for (int i = M; i >= 1; --i) {
		if (S[p - i] == '0') {
			path.push_back(i);
			return rec(p - i);
		}
	}
	return false;
}

int main(void) {
	cin >> N >> M;
	cin >> S;

	bool ans = rec(N);

	if (ans) {
		for (int i = (int)path.size() - 1; i >= 0; --i) {
			cout << path[i];
			if (i != 0)	cout << ' ';
			else		cout << '\n';
		}
	}
	else
		cout << "-1\n";
	return 0;
}


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


int main()
{
	int n,a;
	cin>>n>>a;
	if(a!=100)
	{
		if(n==0)cout<<a<<endl;
		else if(n==1)cout<<a*100<<endl;
		else cout<<a*10000<<endl;
	}
	else
	{
		if(n==0)cout<<101<<endl;
		else if(n==1)cout<<10100<<endl;
		else cout<<1010000<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
unit = ['', 'Man', 'Oku', 'Cho', 'Kei', 'Gai', 'Jo', 'Jou', 'Ko', 'Kan', 'Sei', 'Sai', 'Gok', 'Ggs', 'Asg', 'Nyt', 'Fks', 'Mts']
while 1
  a,b = gets.split()
  if a=='0' then break end
  p = a.to_i**b.to_i
  s = ''
  for i in 0..17
    rem = p%10000
    if rem!=0 then s = rem.to_s + unit[i] + s end
    p /= 10000
  end
  puts s
end

Measured memory_bytes: 6132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B; cin >> A >> B;
    cout << max(0,A-B*2) << endl;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int s;
    cin >> s;
    int h = s/3600;
    int m = (s - h*3600)/60;
    int ans_s = s - h*3600 - m*60;
    cout << h << ":" << m << ":" << ans_s << endl;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
void  Optimal(int *A,int **B,int n){
  int i,j,k;
  int min,x;
  
  for(i=n;1<=i;i--){
    for(j=i;j<=n;j++){
      if(i==j){
	B[i][j]=0;
      }else  {
	for(k=i;k<j;k++){
	  if(k==i){
	    min=B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j];
	  }else {
	    x=B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j];
	  if(x<min) min=x;
	  }
	}
	B[i][j]=min;
      }
    }
  }
  printf("%d\n",B[1][n]);
}
int main(){
  int n,x1,x2;
  int i,j;
  int *A;//下の配列
  int **B;
  
  scanf("%d",&n);  
  A=malloc(sizeof(int)*(n+1));
  B=malloc(sizeof(int *)*(n+1));//二次元配列の動的確保
  for(i=0;i<(n+1);i++){
    B[i]=malloc(sizeof(int)*(n+1));
  }
  for(i=0;i<n;i++){//入力
    scanf("%d%d",&x1,&x2);
    if(i==0){
      A[0]=x1;
      A[1]=x2;
    }else {
      A[i+1]=x2;
    }
  }
  Optimal(A,B,n);
  return 0;
}





Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  bool flag = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') {
      flag = 1;
    }
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  if (flag) {
    x = -x;
  }
}
const int N = 200005;
int n, f[N], r;
vector<int> g[N];
void dfs(int u, int fa) {
  for (auto v : g[u]) {
    if (v ^ fa) {
      dfs(v, u);
      r = max(r, f[u] + f[v] + 2);
      f[u] = max(f[u], f[v] + 1);
    }
  }
}
int main() {
  read(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u), read(v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  puts((r - 2) % 3 ? "First" : "Second");
  return 0;
}

Measured memory_bytes: 30296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
const int MOD = 1000000007;

int main(){
    ll s; cin>>s;
    int ans = 1;
    
    map<ll,int> mp;
    
    while(!mp.count(s)){
        mp[s]++;
        ans++;
        if(s%2) s = 3*s + 1;
        else s /= 2;
    }
    
    cout << ans <<endl;
    return 0;
}

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

int gcd(int a,int b){
  int i;
  int j;
  if (a>b){
  	i=b;
    j=a;
  } else {
    i=a;
    j=b;
  }
  while(i!=0) {
    int ii=j%i;
    j=i;
    i=ii;
  }
  return j;
}

int main() {
  int a;
  cin>>a;
  int b=0;
  for (int i=1;i<=a;++i) {
    b+=i;
    for (int j=1;j<=(i-1);++j) {
      b+=3*gcd(j,i);
    }
    for (int j=1;j<=(i-1);++j) {
      b+=3*gcd(j,i);
    }
    for (int j=1;j<=(i-1);++j) {
      for (int k=1;k<=(j-1);++k) {
        b+=6*gcd(gcd(k,j),i);
      }
    }
  }
  cout<<b<<endl;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    double D,T,S;
    cin >> D >> T >> S;
    if(D<=T*S) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <cmath>
#include <vector> 
typedef unsigned long long int ll;
#define MOD 1000000007
using namespace std;

int main(void){
  int N;
  vector<ll> v;
  cin >> N;
  ll max = 0;
  for(int i=0;i<N;i++){
    ll tmp;
    cin >> tmp;
    v.push_back(tmp);
    if(max < tmp)
      max = tmp;
  }
  ll tmp = 0;
  ll ans = 0;
  int max2 = (ll)log2(max);
  ll num = 2;
  //cout << max2 << endl;
  for(int i=0;i<=max2;i++){
    ll zero=0,one=0;
    ll power = (ll)pow(2,i)%MOD;
    for(int n=0;n<N;n++){
      if(v[n]%2 == 0){
	zero++;
      }else{
	one++;
      }
      v[n] = v[n] >> 1;
    }
    ans = (ans + ((one*zero)%MOD)*power)%MOD;
     //cout << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6512
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            int N, K;
            ReadMulti(out N, out K);

            long d = N / K;
            if (IsOdd(K)) {
                WriteAnswer(d * d * d);
            } else {
                long h = N / (K / 2) - d;
                WriteAnswer(d * d * d + h * h * h);
            }
        }


        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int x,y,n;
int gcd(int a,int b){
	return b == 0 ?a :gcd(b,a%b);
}

void max(int a,int b){
	if(a < b){
		int t = a;
		a = b;
		b = t;
	}
}

int main()
{
	scanf("%d %d %d",&x,&y,&n);
	max(x,y);
	int i = gcd(x,y);
	for(;n > 0 && i >= 1;i--){
		if(x % i == 0 && y % i == 0) n--;
	}
	printf("%d",i + 1);
	return 0;
}

Measured memory_bytes: 128
num = int(input())
lst = []
ans = " "
for i in range(1, num+1):
  if i % 3 == 0:
    lst.append(i)
  else:
    nume = []
    k = i
    while k > 0:
      if k % 10 == 3:
        lst.append(i)
        break;
      else:
        k //= 10 # 必須
length = len(lst)
for j in range(length-1):
  ans += str(lst[j]) + " "
ans += str(lst[length-1])
print(ans)



Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

struct edge{int to,cap,rev;};
struct Maxflow{//ant book p.194
	vector<vector<edge> > G;
	vector<int> level,iter;
	void initsize(int nv){
		G.resize(nv);
		level.resize(nv);
		iter.resize(nv);
	}
	void add_edge(int from,int to,int cap){
		G[from].push_back((edge){to,cap,G[to].size()});
		G[to].push_back((edge){from,0,G[from].size()-1});
	}
	void bfs(int s){
		fill(level.begin(),level.end(),-1);
		//memset(level,-1,sizeof(level));
		queue<int> que;
		level[s]=0;
		que.push(s);
		while( !que.empty() ){
			int v = que.front();que.pop();
			for(int i=0;i<G[v].size();i++){
				edge &e = G[v][i];
				if(e.cap > 0 && level[e.to]<0){
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}
	int dfs(int v,int t,int f){
		if(v==t)return f;
		for(int &i = iter[v];i<G[v].size();i++){
			edge &e = G[v][i];
			if(e.cap>0 && level[v]<level[e.to]){
				int d = dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	int max_flow(int s,int t){
		int flow=0;
		for(;;){
			bfs(s);
			if(level[t]<0)return flow;
			fill(iter.begin(),iter.end(),0);
			//memset(iter,0,sizeof(iter));
			int f;
			while((f=dfs(s,t,INT_MAX))>0){
				flow += f;
			}
		}
	}
};
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	Maxflow mf;
	int X,Y,E;
	cin>>X>>Y>>E;
	mf.initsize(X+Y+2);
	FOR(i,0,E){
		int x,y;
		cin >> x >> y;
		mf.add_edge(x+1,y+X+1,1);
	}
	FOR(i,1,X+1){
	  mf.add_edge(0,i,1);
	}
	FOR(i,1,Y+1){
	  mf.add_edge(i+X,X+Y+1,1);
	}
	cout<<mf.max_flow(0,X+Y+1)<<endl;
	return 0;
}


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

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int ans=0;
  for(int j=1; j<=N; j++){
    int cnt=0;
    int t=j;
    for(int i=0; i<10; i++){
      cnt += t%10;
      t /= 10;
    }
    if(A<=cnt && cnt<=B) ans+=j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# import collections
S = input()
# CS = collections.Counter(S)
# print(CS)
cn = S.count('N')
ce = S.count('E')
cs = S.count('S')
cw = S.count('W')
# print(cn, cs, cw, ce)
if cn > 0 and cs > 0 and ce == 0 and cw == 0:
    print('Yes')
elif cn == 0 and cs == 0 and ce > 0 and cw > 0:
    print('Yes')
elif cn > 0 and cs > 0 and ce > 0 and cw > 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        var R = int.Parse(ReadLine());
        if (R < 1200) { 
            WriteLine("ABC");
        } else if (R < 2800) {
            WriteLine("ARC");
        } else {
            WriteLine("AGC");
        }
    }
}

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

int main() {
    int n, m, sum = 0, cnt = 0;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    rep(i, n) {
        if(sum%(4*m)!=0){
          if(sum / (4 * m) < a[i])     cnt++;
        }
        else{
            if(sum / (4 * m) <= a[i])     cnt++;
        }
    }
    if(cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

typedef long long ll;
using namespace std;

int main() {
    
  int n;
  cin >> n;
  if (n == 25)
    cout << "Christmas" << endl;
  else if (n == 24)
    cout << "Christmas Eve" << endl;
  else if (n == 23)
    cout << "Christmas Eve Eve" << endl;
  else if (n == 22)
    cout << "Christmas Eve Eve Eve" << endl;
    
    
}

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

int main() {
	int N, Y,sum = 0;
	int ans[3] = {0,0,0};
	cin >> N >> Y;
	sum = N * 10000;
	ans[0] = N;
	while (sum != Y) {
		
		if (sum < Y) {
			cout << -1 << " " << -1 << " " << -1 << endl;
			return 0;
		}
		else if(sum - Y >= 5000 && ans[0] > 0){
			sum -= 5000;
			ans[0]--;
			ans[1]++;
		}
		else if (sum - Y >= 4000 && ans[1] > 0) {
			sum -= 4000;
			ans[1]--;
			ans[2]++;
		}
		else if(ans[1] > 1 ){
			ans[1] -= 2;
			ans[0]++;
			ans[2]++;
			sum += 1000;
		}
		else {
			cout << -1 << " " << -1 << " " << -1 << endl;
			return 0;
		}
	}
	cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>

using namespace std;

int N,M;
int h[2000],w[2000];
int a[1000000],b[1000000];

void init(void){
  for(int i=0;i<2000;i++){
    h[i]=0;
    w[i]=0;
  }
  for(int i=0;i<1000000;i++){
    a[i]=0;
    b[i]=0;
  }

}

int main(){
  while(1){
    init();
    scanf("%d%d",&N,&M);
    if(N==0 && M==0) break;
    for(int i=0;i<N;i++)
      scanf("%d",&h[i]);
    for(int i=0;i<M;i++)
      scanf("%d",&w[i]);

    for(int i=0;i<=N;i++){
      for(int j=0;j<=N;j++){
        if(i!=j){
          int tmp=0;
          for(int k=i;k<j;k++){
            tmp+=h[k];
          }
          a[tmp]++;
        }
      }
    }
    for(int i=0;i<=M;i++){
      for(int j=0;j<=M;j++){
        if(i!=j){
          int tmp=0;
          for(int k=i;k<j;k++){
            tmp+=w[k];
          }
          b[tmp]++;
        }
      }
    }
    //cout << "a[1]:" << a[1] << endl;
    //cout << "a[4]:" << a[4] << endl;
    //cout << "a[6]:" << a[6] << endl;

    int ans=0;
    for(int i=1;i<1000000;i++){
      if(a[i]!=0 && b[i]!=0)
        ans+=a[i]*b[i];
    }

    printf("%d\n",ans);

  }
  return 0;

}

Measured memory_bytes: 9012
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

	if (n >= k + k - 1) cout << "YES" << endl;
	else cout << "NO" << endl;

}


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

int main()
{
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int t1 = h1 * 60 + m1;
  int t2 = h2 * 60 + m2;
  int d = t2 - t1;
  int ans = d - k;
  cout << ans << endl;
}


Measured memory_bytes: 3596
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl            '\n'
#define mem(a, n)       memset(a, n, sizeof(a))
#define repeat(n)       for(int i=0; i<n; i++)
#define Unique(n)       (n).erase(unique(all(n)), (n).end())
#define isPowerOfTwo(n) (n && !(n & (n - 1)))
#define NumofDigits(n)  ((int)log10(n)+1)
#define all(a)          a.begin(), a.end()

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

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

/*
    Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

int main(){
    quicken();

    int n; cin >> n;
    int arr[n], l, r, mini, mino;
    repeat(n) cin >> arr[i];

    l = *min_element(arr, arr+n);
    r = *max_element(arr, arr+n);

    mino = INT_MAX;
    while(l<=r){
        mini = 0;
        repeat(n)
            mini += pow((arr[i]-l), 2);
        mino = min(mini, mino), l++;
    }

    cout << mino;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A,B,T;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&T);
  int n = 1;
  int ans = 0;
  while(n*A < (T+0.5)){
    ans += B;
    n += 1;
  }
  if(A>(T+0.5)){
    printf("0\n");
  }else{
  	printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 128
a,b,c,d = (int(i) for i in input().split())
def gcd(x,y):
    if x%y: return gcd(y,x%y)
    else: return y
m,a = c*d//gcd(c,d),a-1
print(b-a-b//c-b//d+b//m+a//c+a//d-a//m)

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

using namespace std;
typedef long long LL;

int num[100005];
int main() 
{   
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    num[n+1]=-1;
    int cnt=0;
	for(int i=1;i<=n;i++)
        if(num[i]==i){
        	swap(num[i],num[i+1]);
        	i++,cnt++;
		}
	cout<<cnt<<endl;
    return 0;  
}  

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[m] = {};
    rep(i, n)
    {
        int k;
        cin >> k;
        rep(j, k)
        {
            int t;
            cin >> t;
            t--;
            a[t]++;
        }
    }

    int cnt = 0;
    rep(i, m) if (a[i] == n) cnt++;

    OP(cnt);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int R = sc.nextInt();
    int S = sc.nextInt();
    int P = sc.nextInt();
    char[] T = sc.next().toCharArray();
    char[] ans = new char[T.length];
    for (int i = 0; i < T.length; i++) {
      switch (T[i]) {
        case 'r':
          ans[i] = 'P';
          break;
        case 's':
          ans[i] = 'R';
          break;
        case 'p':
          ans[i] = 'S';
          break;
      }
    }
    int score = 0;
    for (int i = 0; i < T.length; i++) {
      if (i - K >=0 && ans[i - K] == ans[i]) {
        ans[i] = 'O';
      } else {
        score += ans[i] == 'P' ? P : (ans[i]=='S' ? S : R);
      }
    }
    System.out.println(score);
  }
}


Measured memory_bytes: 28204