akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10^^9 + 7;

alias Edge = Tuple!(int, "to", int, "cost", int, "rev");

void main() {
    int h, w;
    scan(h, w);

    auto adj = new Edge[][](h + w + 2, 0);

    int si, sj, ti, tj;

    void addEdge(int u, int v, int cap) {
        adj[u] ~= Edge(v, cap, adj[v].length.to!int);
        adj[v] ~= Edge(u, 0, adj[u].length.to!int - 1);
    }

    foreach (i ; 0 .. h) {
        auto line = readln.chomp;

        foreach (j ; 0 .. w) {
            int y = i + 1, x = h + j + 1;
            if (line[j] == 'S') {
                si = i, sj = j;
                addEdge(0, y, inf);
                addEdge(0, x, inf);
            }
            else if (line[j] == 'T') {
                ti = i, tj = j;
                addEdge(y, h + w + 1, inf);
                addEdge(x, h + w + 1, inf);
            }
            else if (line[j] == 'o') {
                addEdge(y, x, 1);
                addEdge(x, y, 1);
            }
        }
    }

    if (si == ti || sj == tj) {
        writeln(-1);
        return;
    }
    else {
        int ans = FordFulkerson(adj, 0, h + w + 1);
        writeln(ans);
    }
}

int FordFulkerson(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    bool[] visited = new bool[](n);

    int dfs (int u, int f) {
        if (u == t) {
            debug {
                writef("%d ", t);
            }
            return f;
        }

        visited[u] = 1;

        foreach (ref e ; adj[u]) {
            if (e.cost > 0 && !visited[e.to]) {
                int d = dfs(e.to, min(f, e.cost));

                if (d > 0) {
                    e.cost -= d;
                    adj[e.to][e.rev].cost += d;

                    debug {
                        writef("%d ", u);
                    }

                    return d;
                }
            }
        }

        return 0;
    }

    int F;

    while (true) {
        visited[] = 0;

        int f = dfs(s, inf);

        debug {
            writeln("flow: ", f);
        }

        if (f == 0) break;

        F += f;
    }

    return F;
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#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 RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);


  int h, a;
  cin >> h >> a;
  int ans;

  if (h % a == 0)ans = h/a;
  else ans = int(h/a) + 1;
  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){

int a,b;
scanf("%d %d",&a,&b);

if(a<b){
 printf("a < b\n");
}else if(a>b){
 printf("a > b\n");
}else if(a==b){
 printf("a == b\n");
}

return 0;

}

Measured memory_bytes: 580
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
char op[5];
int main()
{
    int a[5],x,t=3;
    int sum=0;
    scanf("%d",&x);
    memset(op,'+',sizeof(op));
    while(t>=0)
    {
        a[t]=x%10;
        x=x/10;
        sum=sum+a[t];
        t--;
    }
    if(sum==7)
        printf("%d+%d+%d+%d=7\n",a[0],a[1],a[2],a[3]);
    else
    {
        int cha=(sum-7)/2,f=0;
        for(int i=1; i<4; i++)
        {
            if(a[i]==cha)
            {
                op[i]='-';
                f=1;
                break;
            }
        }
        if(f==0)
        {
            if(a[1]+a[2]==cha)
            {
                op[1]='-';
                op[2]='-';
            }
            else if(a[1]+a[3]==cha)
            {
                op[1]='-';
                op[3]='-';
            }
            else if(a[2]+a[3]==cha)
            {
                op[2]='-';
                op[3]='-';
            }
            else if(a[1]+a[2]+a[3]==cha)
            {
                op[1]='-';
                op[2]='-';
                op[3]='-';
            }
        }
        printf("%d%c%d%c%d%c%d=7\n",a[0],op[1],a[1],op[2],a[2],op[3],a[3]);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll n;
vl dp,DP;

int main(){
	cin>>n;
	dp=DP=vl(n);
	dp[0]=DP[0]=1;
	for(int i=1;i<n;i++){
		dp[i]=(dp[i-1]+(i>2?DP[i-3]:0))%mod;
		DP[i]=(dp[i]+DP[i-1])%mod;
	}
	ll res=n,N=n-1;
	for(int i=1;i<n;i++) (res+=N*(N*dp[i-1]%mod+dp[i]))%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    int a[3]; rep(i,3) cin>>a[i];
    int l[n]; rep(i,n) cin>>l[i];
    int ans=INF;
    for(int i=0;i<=pow(4,n);i++){
        int tmp=i;
        int sum[4]={},cnt[4]={};
        for(int j=0;j<n;j++){
            sum[tmp%4]+=l[j];
            cnt[tmp%4]++;
            tmp/=4;
        }
        if(cnt[0]==0||cnt[1]==0||cnt[2]==0) continue;
        int tmpans=0;
        rep(i,3) tmpans+=10*(cnt[i]-1);
        rep(i,3) tmpans+=abs(a[i]-sum[i]);
        ans=min(ans,tmpans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return pro;
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll ans=n*n*n;
    cout<<ans;
    return 0;
}


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

typedef vector <int> vi;
typedef pair< int , int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	FIO;
	int n, k, sum = 0;
	cin >> n >> k;
	int p[n];
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}
	sort(p, p + n);
	for (int i = 0; i < k; i++)
	{
		sum += p[i];

	}
	cout << sum << "\n";
	return 0;

}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int count=0;
        int A2,B2,C2;
        while( A%2==0 && B%2==0 && C%2==0 ){
            if(A==B&&B==C&&A==C){
                System.out.println("-1");
                return;
            }
            A2=A/2;
            B2=B/2;
            C2=C/2;
            A=B2+C2;
            B=A2+C2;
            C=B2+A2;
            
            count++;
        }
        System.out.println(count);
    }
}


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

using namespace std;

typedef pair<int,int> ii;

int n;
int res[100001];
int col[100001];
int cnt = 0;
vector<ii> AdjList[100001];

void dfs(int u,int p,int pre_col)
{
	int cur_col = 0;
	for (int i=0;i<AdjList[u].size();i++)
	{
		int v = AdjList[u][i].first;
		int id = AdjList[u][i].second;
		if (v != p)
		{
			cur_col++;
			if (cur_col == pre_col) cur_col++;
			dfs(v,u,cur_col);
			col[id] = cur_col;
		}
	}
	cnt = max(cnt,cur_col);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	            
	cin >> n;
	for (int i=1;i<=n-1;i++)
	{
		int u,v;
		cin >> u >> v;
		AdjList[u].push_back(ii(v,i));
		AdjList[v].push_back(ii(u,i));
	}
	dfs(1,-1,-1);          
	cout << cnt << '\n';
	for (int i=1;i<=n-1;i++)
		cout << col[i] << '\n';
}

Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;

	while(cin >> n) {
		int ans = 0;

		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				for(int k = 0; k < 10; k++) {
					for(int l = 0; l < 10; l++) {
						if(i + j + k + l == n) {
							ans++;
						}
					}
				}
			}
		}

		cout << ans << endl;

	}
}

Measured memory_bytes: 1160
n,k=map(int,input().split())
s=input()
loc=[1]
for i in range(1,n):
  if s[i]!=s[i-1]:
    loc.append(i+1)
loc.append(n+1)
r=len(loc)
x=[]
for j in range(r-1):
  y=loc[j]
  if s[y-1]==str(0):
    x.append(loc[min(r-1,j+2*k)]-loc[j])
  else:
    x.append(loc[min(r-1,j+2*k+1)]-loc[j])
print(max(x))

Measured memory_bytes: 11032
n,x,y = map(int,input().split())
ans = [0]*(n)
for i in range(n):
    tbl = [0]*n
    for j in range(i,n):
        tbl[j] = min(abs(j+1-i-1),abs(i+1-x)+1+abs(j+1-y))
        ans[tbl[j]] += 1
[print(i) for i in ans[1:]]

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
const ll INF = 1000000007;
const ld PI = 3.141592653589;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);}

int main(){
    FAST_IO;
    ll _=1;
    //cin>>_;
    for(ll ii=1;ii<=_;ii++)
    {
		ll a,b,v,w,t;
		cin>>a>>v>>b>>w>>t;
        ll d=abs(a-b),dd=(v-w)*t;
        cout<<((d<=dd)?"YES":"NO");
	}
	//cout<< "Done in " <<fixed<<setprecision(15)<<(double)clock()/7.33e8<<"sec"<< endl;
    return 0;
}


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

int main() {
    long a, b, c;
    cin >> a >> b >> c;

    long cab = c - a - b;
    if (cab < 0) {
        cout << "No" << endl;
        return 0;
    }
    bool yes = 4 * a * b < cab * cab;
    cout << (yes ? "Yes" : "No") << endl;

    return 0;
}


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

int main(){
    string word;
    string text;
    int count = 0;
    cin >> word;
    while(1){
        cin >> text;
        if(text == "END_OF_TEXT") break;
        for(int i = 0; text[i] != '\0'; i++){
            if(text[i] >= 'A' && text[i] <= 'Z'){
                text[i] = text[i] + 32;
            }
        }
        if(text == word) count++;     
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,K,mt=0,res=100000;
	vector<int>A;
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		int a;
		cin>>a;
		A.push_back(a);
		mt=A[mt]>A[i]?i:mt;
	}
	for(int i=0;i<=K;i++)
	{
		int t=1;
		int r=mt+(K-i);
		int l=mt-i;
		for(int sp=r;sp<N;sp+=K-1)t++;
		for(int sp=l;sp>0;sp-=K-1)t++;
		res=min(res,t);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <string.h>
#include<algorithm>
#include <numeric>      // std::accumulate
#include <iomanip>      // std::setprecision


using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define v           vector <int>
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define EPS			 1e-9
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;

bool cmp(const pair<int, int>& a, const pair<int, int>& b)
{
    return (a.second < b.second);
}

int gcd(int a, int b) 
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
long long power(ll n, ll k) 
{
    if (k == 0) return 1;
    ll sq = (power(n, k / 2));
    sq = (sq * sq);
    if (k % 2 == 1)
        sq = (sq * n);
    return sq;
}
bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
string to_binary(int x) 
{
    string s;
    while (x > 0) 
    {
        s += (x % 2 ? '1' : '0');
        x /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}
const int N = 2e5 + 4;
ll x[N], y[N];
ll sector(int i, ll z) {
    if (i)return z - x[i - 1];
    else return z;
}

void solve()
{

    int n; cin >> n;

    map<string, int>m;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        m[s]++;
    }

    cout << "AC x " << m["AC"] << "\n";
    cout << "WA x " << m["WA"] << "\n";
    cout << "TLE x " << m["TLE"] << "\n";
    cout << "RE x " << m["RE"] << "\n";
}

int main()
{
    IOS;
    solve();
    /*
    int tt; cin >> tt;
    while (tt--)
    {

    }
    */
    
}
       

Measured memory_bytes: 3204
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
    long long i,j,k,x,y,z,n,m,w;
    scanf("%lld",&n);
    long long a[n];
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    long long s[n+1];
    s[0]=0;
    for(i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
    sort(s,s+n+1);
    y=0;x=1;w=s[0];
    for(i=1;i<n+1;i++){
        if(s[i]==w){
            x++;
        }
        else{
            if(x>1){y+=x*(x-1)/2;}
            x=1;
            w=s[i];
        }
        if(i==n&&x>1)y+=x*(x-1)/2;
    }
    printf("%lld\n",y);
}


Measured memory_bytes: 3328
#include <iostream>

int n;

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; ++i) sum += (long long)i * (n + 1 - i);
    for (int i = 1, x, y; i < n; ++i) {
        std::cin >> x >> y;
        if (x > y) std::swap(x, y);
        sum -= (long long)x * (n - y + 1);
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
int main(void)
{
	char S[100001];
	int count[26];
	scanf("%s", S);
	for (int i = 0; i < 26; i++) {
		count[i] = 0;
	}
	for (int i = 0; i < 100000; i++) {
		if (S[i] == '\0')
			break;
		for (int  j =0; j < 26;j++) {
			if (S[i] ==j + 'a')
				count[j]++;
		}
	}
	for (int i = 0; i < 26; i++) {
		if (count[i] == 0) {
			printf("%c", i + 'a');
			return 0;
		}
	}
	printf("None");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
long a[1<<17],b[1<<17];
main()
{
	cin>>n;
	long suma=0,sumb=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		suma+=a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
		sumb+=b[i];
	}
	if(suma<sumb)
	{
		cout<<-1<<endl;
		return 0;
	}
	int cnt=0;
	long sum=0;
	vector<long>ret;
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i])continue;
		else if(a[i]>b[i])
		{
			ret.push_back(a[i]-b[i]);
		}
		else
		{
			cnt++;
			sum+=b[i]-a[i];
		}
	}
	sort(ret.begin(),ret.end());
	reverse(ret.begin(),ret.end());
	int id=0;
	while(sum>0)
	{
		cnt++;
		sum-=ret[id];
		id++;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;


const int MAX_n = 100000;
int n,a[MAX_n];
int k;


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


signed main(){



    cin >> n;
    cin >> k;


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

        if(a[i] == k){
            cout<< "POSSIBLE"<< endl;
            return 0;
        }
    }

    if( * max_element(a,a+n) < k){
        cout<< "IMPOSSIBLE"<< endl;
        return 0;
    }


    int before_res=a[0];
    for(int i = 1;i < n;i++){
        before_res = gcd(before_res,a[i]);
    }

    if(k%before_res == 0){
        cout<< "POSSIBLE"<< endl;
    }else{
        cout<< "IMPOSSIBLE"<< endl;
    }



    return 0;
}

Measured memory_bytes: 1024
N = int(input())
dig = []
def dmod(a, b):
  if a % b < 0:
    return [1, a//b+1]
  else:
    return [a%b, a//b]
while abs(N) > 1 :
  d, N = dmod(N, -2)
  dig.append(d)
if N == -1:
  dig += [1, 1]
else:
  dig.append(N)
dig.reverse()

n = ''.join(map(str, dig))
print(int(n))

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

int main()
{
	long long x,k,d;
	cin>>x>>k>>d;
	if(x<0)
		x=-x;
	if(x/d>=k)
		cout<<x-k*d; 
	else if(x/d%2!=k%2)
		cout<<d-x%d;
	else
		cout<<x%d;
	return 0;
}

Measured memory_bytes: 3612
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {


    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
        }
        BigInteger res = lcm(arr);
        BigInteger result = BigInteger.ZERO;
        for (long anArr : arr) {
            result = result.add((res.subtract(BigInteger.ONE)).mod(BigInteger.valueOf(anArr)));
        }
        out.println(result);
    }



    private static BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply((b.divide((a.gcd(b)))));
    }

    private static BigInteger lcm(long[] input) {
        BigInteger result = BigInteger.valueOf(input[0]);
        for (int i = 1; i < input.length; i++) result = lcm(result, BigInteger.valueOf(input[i]));
        return result;
    }

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        @Override
        public void close() {

        }
    }

}


Measured memory_bytes: 43796
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;
  string S[2005];
  for (int i = 0; i < H; i ++)
    cin >> S[i];
  
  int L[2005][2005], U[2005][2005];
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      if (S[h][w] == '#')
      {
        L[h][w] = 0;
        U[h][w] = 0;
      }
      else
      {
        if (h == 0)
          U[h][w] = 1;
        else
          U[h][w] = U[h - 1][w] + 1;
        if (w == 0)
          L[h][w] = 1;
        else
          L[h][w] = L[h][w - 1] + 1;
      }
    }
  }
  
  int R[2005][2005], D[2005][2005];
  for (int h = H - 1; h >= 0; h--)
  {
    for (int w = W - 1; w >= 0; w--)
    {
      if (S[h][w] == '#')
      {
        R[h][w] = 0;
        D[h][w] = 0;
      }
      else
      {
        if (h == H - 1)
          D[h][w] = 1;
        else
          D[h][w] = D[h + 1][w] + 1;
        if (w == W - 1)
          R[h][w] = 1;
        else
          R[h][w] = R[h][w + 1] + 1;
      }
    }
  }
  
  int ans = 0;
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 67200
N, T = map(int, input().split())
table = [[0] * (N + 1) for _ in range(T + 1)]
dish = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda t: t[0])
for t in range(T + 1):
    for n in range(N):
        minutes_to_take, deliciousness = dish[n]
        now = table[t][n]
        if t < T:
            table[min(T, t + minutes_to_take)][n + 1] = max(table[min(T, t + minutes_to_take)][n + 1], now + deliciousness)
        if n < N:
            table[t][n + 1] = max(table[t][n + 1], now)
print(table[T][N])

Measured memory_bytes: 120028
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> ord(n), xs(n), ys(n);
    double f = 1;
    for (int i = 0; i < n; i++)
    {
        ord[i] = i;
        cin >> xs[i] >> ys[i];
        f *= (i + 1);
    }
    double ans = 0;
    do
    {
        double res = 0;
        for (int i = 0; i < n - 1; i++)
        {
            res += sqrt(pow(xs[ord[i + 1]] - xs[ord[i]], 2) + pow(ys[ord[i + 1]] - ys[ord[i]], 2));
        }
        ans += res / f;
    } while (next_permutation(ord.begin(), ord.end()));
    cout << setprecision(15) << ans << endl;
}

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int c[50];
	vector<int> e[50];
	queue<int>a;
	int s,t;
	int n, m;
	int x[50];
	int y[50];
	int z;
	int ans;

	scanf("%d %d",&n,&m);
	for (int i = 0; i < m; i++){
		scanf("%d %d", &x[i],&y[i]);
		x[i]--;
		y[i]--;
		e[x[i]].push_back(y[i]);
		e[y[i]].push_back(x[i]);
	}
	ans = 0;
	for (int cc = 0; cc < m; cc++){
		for (int i = 0; i < n; i++)c[i] = 0;
		s = x[cc];
		t = y[cc];
		c[t] = 1;
		a.push(t);
		while (a.empty() == 0){
			z = a.front();
			for (int i = 0; i < e[z].size(); i++){
				if (c[e[z][i]] == 0){
					if (z != t || e[z][i] != s){
						c[e[z][i]] = 1;
						a.push(e[z][i]);
					}
				}
			}
			a.pop();
		}
		if (c[s] == 0)ans++;
	}

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

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int MAXM = 1e3 + 5;
const int MAXN = 15;

int n, m;
int f[1 << MAXN];
int vis[MAXN];
int a[MAXM], b[MAXM], c[MAXM][MAXN];
int num[MAXM];

int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
		for (int j = 1; j <= b[i]; j++) {
			cin >> c[i][j];
			vis[c[i][j]] = 1;
			num[i] |= 1 << (c[i][j] - 1);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			cout << "-1\n";
			return 0;
		}
	}
	memset(f, 0x3f, sizeof(f));
	f[0] = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < (1 << n); j++) {
			f[j | num[i]] = min(f[j | num[i]], f[j] + a[i]);
		}
	}
	cout << f[(1 << n) - 1] << "\n";
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int employee = sc.nextInt();
		int[] results = new int[employee];
		for (int i = 0; i < employee - 1; i++) {
			int boss = sc.nextInt();
			results[boss - 1]++;
		}
		sc.close();
		for (int result : results) {
			System.out.println(result);
		}
	}

}


Measured memory_bytes: 61832
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:49:24 2020

@author: NEC-PCuser
"""

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

A = list(map(int, input().split()))

A.sort()

minus_list = []
plus_list = []
for i in range(len(A)):
    if (A[i] <= 0):
        minus_list.append(A[i])
    else:
        plus_list.append(A[i])

ans = 1
mod = 10 ** 9 + 7   
if N == K:
    for i in A:
        ans = (ans * i) % mod
elif 0 == len(plus_list) and  K % 2 == 1:
    minus_list.sort(reverse=True)
    for i in range(K):
        ans = (ans * minus_list[i]) % mod
else:
    minus_list.sort(reverse=True)
    plus_list.sort()
    if K % 2 == 1:
        ans = plus_list.pop()
    for i in range(K // 2):
        if (len(plus_list) < 2):
            ans = (minus_list.pop() * ans) % mod
            ans = (minus_list.pop() * ans) % mod
        elif (len(minus_list) < 2):
            ans = (plus_list.pop() * ans) % mod
            ans = (plus_list.pop() * ans) % mod
        elif (plus_list[len(plus_list) - 1] * plus_list[len(plus_list) - 2] > minus_list[len(minus_list) - 1] * minus_list[len(minus_list) - 2]):
            ans = (plus_list.pop()* ans) % mod
            ans = (plus_list.pop() * ans) % mod
        else:
            ans = (minus_list.pop() * ans) % mod
            ans = (minus_list.pop()* ans) % mod
print(ans)
        

Measured memory_bytes: 31904
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

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

    if(sum%10!=0){
        cout << sum << endl;
        return 0;
    }

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

    bool ans=false;
    for(int i=0;i<n;i++){
        if(s[i]%10==0)continue;
        sum-=s[i];
        if(sum%10!=0){
            ans=true;
            break;
        }
    }

    if(ans)cout << sum << endl;
    else cout << 0 << endl;

    return 0;
}


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

public class Main{
    public static void main(String args[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	int n=Integer.parseInt(br.readLine());

	int matrix[][]=new int[n][n];

	for(int i=0;i<n;i++){
	    String str[]=br.readLine().split(" ");

	    int u=Integer.parseInt(str[0])-1;
	    int k=Integer.parseInt(str[1]);
	    for(int j=2;j<2+k;j++){
		int v=Integer.parseInt(str[j])-1;
		matrix[u][v]=1;
	    }

	    for(int j=0;j<n;j++){
		if(j==0)
		    System.out.print(matrix[i][j]);
		else
		    System.out.print(" "+matrix[i][j]);
	    }
	    System.out.println();
	}
    }
}



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

int main() {
    int a, b, h, m;
    scanf("%d%d%d%d", &a, &b, &h, &m);

    double pos_s = h * 5 + m / 12.0;
    double pos_l = m;
    double rad = (pos_s - pos_l) / 30.0 * M_PI;
    
    double ans = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 2544
var arr = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/);
var caseCount = arr.length;
for (var i = 1; i < caseCount; i++) {
	var balls = arr[i].trim().split(/\s/);
	var course = [0,0];
	for (var j = 0; j < balls.length; j++) {
		var ballNum = parseInt(balls[j], 10);
		var courseDeff = [(ballNum - course[0]),(ballNum - course[1])];
		if((courseDeff[0] < 0) && (courseDeff[1] < 0)){
			console.log("NO");
			break;
		}
		if((courseDeff[0] <= courseDeff[1]) && (courseDeff[0] > 0)){
			course[0] = ballNum;
		}else{
			course[1] = ballNum;
		}
		if(j==9){
			console.log("YES");
		}
	}
}

Measured memory_bytes: 15480
#include<stdio.h>

int main(void){
  int a,b,c,d,t,i,s=0;

  scanf("%d %d %d %d",&a,&b,&c,&d);

  if(a>c){
    t=a;a=c;c=t;
    t=b;b=d;d=t;
  }

  for(i=a;i<b;i++){
    if(i>=c&&i<d)
      s++;
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

ll a,b;

int main(){
  cin>>a>>b;
  if(a<=8&&b<=8)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
    long long n, m, k;
    cin >> n >> m >> k;
    long long sa[n + 1], sb[m + 1];
    sa[0] = 0;
    sb[0] = 0;
    long long sum = 0;
    long num;
    for (int i = 1; i <= n; i++) {
        cin >> num;
        sum += num;
        sa[i] = sum;
    }
    sum = 0;
    for (int i = 1; i <= m; i++) {
        cin >> num;
        sum += num;
        sb[i] = sum;
    }
    
    sum = 0;
    int max = 0;
    int j = m;
    for (int i = 0; i <= n; i++) {
        if (sa[i] > k) {
            break;
        }
        while (j > 0 && sb[j] > k - sa[i]) {
            j--;
        }
        if (i + j > max) {
            max = i + j;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 6740
"""
Writer: SPD_9X2
https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_e
Mの時、 a1<=a2<=a3…aN
を満たす通り数 X[M] が分かれば解ける(全ての順N!は等しいため)

当然、次のMにはa1から順に更新していくことになる(M+?にね)
Dの時
X[M] = (X[M-1] + X[M-2] +　… + X[M-D]) * N
が成立かな
X[0] = 1

N=2
X[0]=1
X[1]=2
X[2]=6

N=3
X[0]=1
X[1]=9

X[M]の更新式
→これが間違ってそう
X[M] = (X[M-1] + X[M-2] +　… + X[M-D]) * (1!+2!+3!+…N!)
→エスパーだけどなんか正しそう

X[H-1]を求めてN!を掛ければそれが答え
→サンプル合った！！
"""
import math
N,H,D = map(int,input().split())
mod = 10**9+7

mul = 0
fac = 1
for i in range(1,N+1):
    fac *= i
    fac %= mod
    mul += fac
    mul %= mod

X = [1]
nsum = 1
for i in range(H-1):

    #print (i,nsum,mul)
    X.append(nsum*mul%mod)

    nsum += X[-1]
    nsum %= mod
    if i >= D-1:
        nsum -= X[i-D+1]
        

#print (X)
print (nsum * fac % mod)


Measured memory_bytes: 79512
#include<stdio.h>  
#include<algorithm>  
#include<string.h>  
#include<queue>  
using namespace std;  
   
int vis[100009];  
typedef pair<int, int> P;  
   
   
int main()  
{  
    int k;  
    scanf("%d", &k);  
    deque<P> q;  
    memset(vis, 0, sizeof(vis));  
    q.push_back(make_pair(1, 1));  
    while(!q.empty())  
    {  
        P x = q.front(); q.pop_front();  
        if(vis[x.first]) continue;  
        vis[x.first] = 1;  
        if(x.first == 0)  
        {  
            printf("%d\n", x.second);  
            break;  
        }  
        q.push_front(make_pair(x.first*10 % k, x.second));  
        q.push_back(make_pair((x.first+1) % k, x.second+1));  
   
    }  
    return 0;  
} 

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
//
int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	scanf("%d",&n);
	cout<<n*n;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll N,M;
vector<ll> dp;
vector<ll> a;

int main()
{
    cin >> N >> M;
    a.resize(M);
    for(int i = 0; i < M; i++) cin >> a[i];
    dp.resize(N + 1);
    for(int i = 0; i < N + 1; i++) dp[i] = 0;
    dp[0] = 1;
    vector<bool> safe(N,true);
    for(int i = 0;i < M; i++) safe[a[i]] = false;

    for(int i = 1; i < N + 1; i++)
    {
        if(safe[i - 1]) dp[i] += dp[i - 1];
        if(i > 1)
        {
            if(safe[i - 2]) dp[i] += dp[i - 2];
        }
        dp[i] %= MOD;
        // cout <<"dp["  << i << "] = "<< dp[i] << endl;
    }
    cout << dp[N] << endl;
}

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

int main()
{
	int n,s;
	cin >> n>>s;
	vector<int> a(n);
	for(int i = 0;i<n;i++)cin >> a[i];
	queue<int> Q;
	int ans = n+1;
	int sum = 0;
	for(int i = 0;i<n;)
	{
		if(sum<s)
		{
			sum += a[i];
			Q.emplace(a[i++]);
		}
		else
		{
			ans = min(ans,(int)Q.size());
			sum -= Q.front();
			Q.pop();
			
		}
	}
	// /cout<<sum<<endl;
	while(sum>=s)
	{
		ans = min(ans,(int)Q.size());
		sum -= Q.front();
		Q.pop();
	}

	cout<<(ans==n+1?0:ans)<<endl;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;

int main()
{
   FAST/**/
   
   ll n,k,q;
   cin>>n>>k>>q;
   
   ll arr1[q];
   for(ll i=0;i<q;i++)
        cin>>arr1[i];
   ll arr[n];
   memset(arr,0,sizeof(arr));
   for(ll i=0;i<q;i++)
        arr[arr1[i]-1]++;
   
   ll pref[n+2];
   for(ll i=1;i<n+1;i++)
        pref[i] = 0;
   
   for(ll i=0;i<n;i++)
   {
       if(i == 0)
       {
           pref[i+2]-=arr[i];
           continue;
       }
       
       if(i == n-1)
       {
           pref[1]-=arr[i];
           pref[i+1]+=arr[i];
           continue;
       }
       
       pref[1]-=arr[i];
       pref[i+1]+=arr[i];
       pref[i+2]-=arr[i];
   }
   
   ll curr = k;
   for(ll i=1;i<=n;i++)
   {
       curr+=pref[i];
       if(curr<=0)
            cout<<"No"<<"\n";
       else cout<<"Yes\n";        
   }
   
   return 0;
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CompProgLib;

namespace ALDS1_11_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            
            int n = ReadInt();
            Graph gr = new Graph();

            for (int i = 0 ; i < n ; i++)
            {
                int[] line = ReadIntAr();
                gr.SetGraph(line[0], line.Skip(2).ToArray());
            }
            
            foreach (var key in gr.Adj.Keys)
            {
               if(!gr.Adj[key].IsVisited) gr.DFS(key);
            }

            foreach (var item in gr.Adj)
            {
                Console.WriteLine("{0} {1} {2}", item.Key, item.Value.D, item.Value.F);
            }
        }


        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}

namespace CompProgLib
{
    public class Graph
    {
        public class Node
        {
            public List<int> Vartex { get; internal set; }
            public int D { get; internal set; }
            public int F { get; internal set; }
            public bool IsVisited { get; internal set; }

            public Node(List<int> v)
            {
                Vartex = v;
            }
        }

        public Dictionary<int, Node> Adj { get; set; }

        public Graph()
        {
            Adj = new Dictionary<int, Node>();
        }

        /// <summary>
        /// 隣接行列の指定したインデックスに値をセットする
        /// </summary>
        /// <param name="index">頂点u</param>
        /// <param name="item">頂点uに接続する頂点</param>
        public void SetGraph(int index, int[] item)
        {
            Adj.Add(index, new Node(item.ToList()));
        }

        /// <summary>
        /// 行列を0で初期化する
        /// </summary>
        public void Clear() { Adj.Clear(); }

        /// <summary>
        /// 深さ優先探索
        /// </summary>
        private int Time = 0;
        public void DFS(int v)
        {
            Adj[v].D = ++Time;
            Adj[v].IsVisited = true;
            foreach (int vartex in Adj[v].Vartex)
            {
                if (!Adj[vartex].IsVisited) DFS(vartex);                
            }
            Adj[v].F = ++Time;
        }
    }
}



Measured memory_bytes: 18304
n = gets.to_i

def koch(n, a, b)
  return if n == 0
  th = Math::PI * 60.0 / 180.0

  s = {
    x: (2.0 * a[:x] + 1.0 * b[:x]) / 3.0,
    y: (2.0 * a[:y] + 1.0 * b[:y]) / 3.0
  }
  t = {
    x: (1.0 * a[:x] + 2.0 * b[:x]) / 3.0,
    y: (1.0 * a[:y] + 2.0 * b[:y]) / 3.0
  }
  u = {
    x: (t[:x] - s[:x]) * Math.cos(th) - (t[:y] - s[:y]) * Math.sin(th) + s[:x],
    y: (t[:x] - s[:x]) * Math.sin(th) + (t[:y] - s[:y]) * Math.cos(th) + s[:y]
  }

  koch(n - 1, a, s)
  puts sprintf("%.8f %.8f", s[:x], s[:y])
  koch(n - 1, s, u)
  puts sprintf("%.8f %.8f", u[:x], u[:y])
  koch(n - 1, u, t)
  puts sprintf("%.8f %.8f", t[:x], t[:y])
  koch(n - 1, t, b)
end

a = {x: 0, y: 0}
b = {x: 100, y: 0}

puts sprintf("%.8f %.8f", a[:x], a[:y])
koch(n, a, b)
puts sprintf("%.8f %.8f", b[:x], b[:y])


Measured memory_bytes: 7176
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][4][2];
string S;
int calc(int x, int k, int smaller) {
    //cout << x << " " << k << " " << smaller << endl;
    if(k < 0) return 0;
    if(x < 0 && k == 0) return 1;
    else if(x < 0 && k != 0) return 0;
    if(dp[x][k][smaller] != -1) return dp[x][k][smaller];
    if(smaller) {
        return dp[x][k][smaller] = calc(x - 1, k, smaller) + calc(x - 1, k - 1, smaller) * 9;
    } else {
        //cout << S[x] << endl;
        if(S[x] == '0')
            return dp[x][k][smaller] = calc(x - 1, k, 0);
        else
            return dp[x][k][smaller] = calc(x - 1, k - 1, 0) + calc(x - 1, k - 1, 1) * (S[x] - '0' - 1) + calc(x - 1, k, 1);
    }
    return -1;
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    reverse(S.begin(), S.end());
    int K; cin >> K;
    rep(i, 110) rep(k, 4) rep(j, 2) dp[i][k][j] = -1;
    cout << calc((int)S.length() - 1, K, 0) << endl;
    //cout << calc(0, 1, 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int64_t> ns(n + 1);
	int64_t sum = 0;
	FOR_LE(i, 0, n) {
		cin >> ns[i];
		sum += ns[i];
	}

	int64_t ans = 0;
	int64_t v = 1;
	FOR_LE(i, 0, n) {
		if (v < ns[i]) {
			cout << -1 << endl;
			return 0;
		}

		ans += v;
		v -= ns[i];
		sum -= ns[i];
		v = min(v * 2, sum);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
int n,f[10003],x,y,a[10003];
vector<int>l[10003];
void dfs(int x1,int fa)
{
	f[x1]=0;
	for(int j=0;j<l[x1].size();j++)
		if(l[x1][j]!=fa)
		{
			dfs(l[x1][j],x1);
			if(f[l[x1][j]]==0&&a[x1]>a[l[x1][j]])
				f[x1]=1;
		}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		l[x].push_back(y),l[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(f[i]==1)
			cout<<i<<" ";
	}
	return 0;
}


Measured memory_bytes: 768
import math
int_line = input().split(" ")
int_list = [float(a) for a in int_line]
num1 = int_list[2] - int_list[0]
num2 = int_list[3] - int_list[1]
if num1 < 0:
    num1 *= -1
if num2 < 0:
    num2 *= -1
num3 = num1 ** 2 + num2 ** 2
num4 = math.sqrt(num3)
print(round(num4,5))


Measured memory_bytes: 5660
N=int(input())
t=0
x=0
y=0
hantei=True
for i in range(N):
  t_,x_,y_=map(int,input().split())
  if abs(x-x_)+abs(y-y_)>t_-t or abs(abs(x-x_)+abs(y-y_)-(t_-t))%2==1:
    hantei=False
    break
  else:
    t=t_
    x=x_
    y=y_
print('Yes' if hantei else 'No')

Measured memory_bytes: 3064
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;

immutable long MOD = 1000000007;

auto solve(string S) {
    auto dp = new long[][](2, 13);
    auto units = iota(10).map!(to!int).array;
    auto digits = iota(10).array;

    foreach (i; to_digits(S[$ - 1]))
        dp[0][i] = 1;

    int i;
    foreach (c; S.retro.drop(1)) {
        foreach (ref u; units)
            u = (u * 10) % 13;

        dp[i ^ 1].fill(0);
        foreach (pre_m; 0 .. 13) foreach(d; to_digits(c)) {
            dp[i ^ 1][(pre_m + units[d]) % 13] += dp[i][pre_m];
            dp[i ^ 1][(pre_m + units[d]) % 13] %= MOD;
        }
        
        i ^= 1;
    }

    return dp[i][5];
}

auto to_digits(dchar c) {
    if (c == '?')
        return iota(10).array;
    return [(c - '0').to!int];
}

void main(){
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(S);
    else
        solve(S).writeln;
}


Measured memory_bytes: 1560
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int sum = 0;
		for(int i = 0; i <= a; i++) {
			for(int j = 0; j <= b; j++) {
				for(int k = 0; k <= c; k++) {
					int way = i*500 + j*100 + k*50;
					if(way == x) sum++;
				}
			}
		}
		System.out.println(sum);
		sc.close();
	}
}

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

class Program
{
    static void Main()
    {
        var nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var ans = new int[nm[0] + 1];
        for (int i = 0; i < nm[1]; i++)
        {
            var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            ans[inp[0]]++;
            ans[inp[1]]++;
        }
        ans.Where((x, y) => y != 0).ToList().ForEach(Console.WriteLine);
    }
}


Measured memory_bytes: 13396