akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll h, w;
vector<string> a;

ll dp[1100][1100];

void add(ll &a, ll b){
    a += b;
    if( a >= mod) a -= mod;
}

int main() {
    cin >> h >> w;
    a.resize(h);
    for(int i = 0; i < h; i++) cin >> a[i];

    dp[0][0] = 1;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i+1 < h && a[i+1][j] == '.') add(dp[i+1][j], dp[i][j]);
            if(j+1 < w && a[i][j+1] == '.') add(dp[i][j+1], dp[i][j]);
        }
    }

    cout << dp[h-1][w-1] << endl;
}

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

void fnInput(vector<int>& rvnSeqB)
{
  int nSeqBSiz;
  cin >> nSeqBSiz;
  rvnSeqB.resize(nSeqBSiz - 1);

  for (int& rnSeqB : rvnSeqB)
    cin >> rnSeqB;
}
  
int fnMaxValueGet(const vector<int>& cnrvnSeqB)
{
  vector<int> vnSeqA(cnrvnSeqB.size() + 1, 100001);

  for (int i = 0; i < cnrvnSeqB.size(); i++)
  {
    if (cnrvnSeqB[i] < vnSeqA[i])     vnSeqA[i]     = cnrvnSeqB[i];
    if (cnrvnSeqB[i] < vnSeqA[i + 1]) vnSeqA[i + 1] = cnrvnSeqB[i];
  }

  int nMaxValue = accumulate(begin(vnSeqA), end(vnSeqA), 0);
  return nMaxValue;
}
  
int main()
{
  vector<int> vnSeqB;

  fnInput(vnSeqB);
  cout << fnMaxValueGet(vnSeqB) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using order_statistics_tree = tree<T,null_type,less_equal<T>,rb_tree_tag,
  tree_order_statistics_node_update>;
 #define all(x) (x).begin(),(x).end()
vector<int> u, v, dest;
inline void trunc(vector<int>& vec, int t){
   auto it = upper_bound(all(vec), t);
   for(auto&j: vec)j&=t;
   merge(vec.begin(), it, it, vec.end(), dest.begin());
   copy(all(dest), vec.begin());
}
signed main(){
    int n;
    cin >> n;
    u.resize(n); v.resize(n); dest.resize(n);
    for(auto& i: u) cin >> i;
    for(auto& i: v) cin >> i;
    int ans = 0;
    if(n&1){
        for(auto j: v)ans^=j;
        for(auto j: u)ans^=j;
    }
    sort(all(v));
    sort(all(u));
    for(int i = 28, t = (1<<29)-1; i >= 0; i--, t>>=1){
        trunc(v, t);
        trunc(u, t);
        for(int ui = 0, vi = n; ui< n; ui++){
            while(vi>0 && u[ui]+v[vi-1] > t)vi--;
            ans^=((n-vi)&1)<<i+1;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void){
  int a, b;
  char op;


  while(op != '?'){
    scanf("%d %s %d\n", &a, &op, &b);
    
    switch(op){
      case '+':
        printf("%d\n", a + b);
        break;
      case '-':
        printf("%d\n", a - b);
        break;
      case '*':
        printf("%d\n", a * b);
        break;
      case '/':
        printf("%d\n", a / b);
        break;
    }
  }

  return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	rep(i,S.size()){
		printf("x");
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 256
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int L;
    cin >> L;
    double side = L / 3.0;
    printf("%.12lf\n", side * side * side);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
const int mod = 1000000007;

using namespace std;
const int N = 100005;

auto common_range(auto p, auto q){
	return {max(p.first,q.first),min(p.second,q.second)};
}

int n, t[N], a[N], mx;
pair <int,int> A[N], B[N];

void init(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&t[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%d",&a[i]);
	}
	for(int i = 0; i < n; i++){
		if(t[i] > mx){
			mx = t[i];
			A[i] = {t[i], t[i]};
		}
		else if(t[i] < mx){
			puts("0");
			return;
		}
		else{
			A[i] = {1, mx};
		}
	}
	mx = 0;
	for(int i = n - 1; i > -1; i--){
		if(a[i] > mx){
			mx = a[i];
			B[i] = {a[i], a[i]};
		}
		else if(a[i] < mx){
			puts("0");
			return;
		}
		else{
			B[i] = {1, mx};
		}
	}
	long long res = 1;
	for(int i = 0; i < n; i++){
		auto r = common_range(A[i], B[i]);
		if(r.second < r.first) res = 0;
		else res = (res * (r.second - r.first + 1)) % mod;
	}
	printf("%lld\n",res);
}

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

Measured memory_bytes: 2688
use proconio::{fastout, input};

use proconio::marker::Chars;

#[fastout]
fn main() {
    input! {
        n: usize, mut a: [u64; 3],
        mut q: [Chars; n],
    }
    q.push(vec!['X', 'X']);
    let mut ans = vec![];
    let id = |x| match x {
        'A' => 0,
        'B' => 1,
        'C' => 2,
        _ => 3,
    };
    for i in 0..n {
        let x = id(q[i][0]);
        let y = id(q[i][1]);
        if a[x] > 1 || (a[x], a[y]) == (1, 0) {
            a[x] -= 1;
            a[y] += 1;
            ans.push(q[i][1]);
        } else if a[y] > 1 || (a[x], a[y]) == (0, 1) {
            a[x] += 1;
            a[y] -= 1;
            ans.push(q[i][0]);
        } else if (a[x], a[y]) == (0, 0) {
            println!("No");
            return;
        } else {
            if q[i][0] == q[i + 1][0] || q[i][0] == q[i + 1][1] {
                a[x] += 1;
                a[y] -= 1;
                ans.push(q[i][0]);
            } else {
                a[x] -= 1;
                a[y] += 1;
                ans.push(q[i][1]);
            }
        }
    }
    println!("Yes");
    for &s in ans.iter() {
        println!("{}", s);
    }
}


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

ll n,a,b,c;
string s[100001];
vector<string> ans;

int main() {
    cin>>n>>a>>b>>c;
    for(ll i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(ll i=1;i<=n;i++)
    {
        if(s[i]=="AB")
        {
            if(a==1 && b==1 && c==0)
            {
                if(s[i+1]=="BC")
                {
                    a--,b++;
                    ans.push_back("B");
                }
                else
                if(s[i+1]=="AC")
                {
                    a++,b--;
                    ans.push_back("A");
                }
                else
                {
                    a++,b--;
                    ans.push_back("A");
                }
            }
            else
            {
                if(a>b)
                    a--,b++,ans.push_back("B");
                else
                    a++,b--,ans.push_back("A");
            }
        }
        else
        if(s[i]=="AC")
        {
            if(a==1 && b==0 && c==1)
            {
                if(s[i+1]=="BC")
                {
                    a--,c++;
                    ans.push_back("C");
                }
                else
                if(s[i+1]=="AB")
                {
                    a++,c--;
                    ans.push_back("A");
                }
                else
                {
                    a++,c--;
                    ans.push_back("A");
                }
            }
            else
            {
                if(a>c)
                    a--,c++,ans.push_back("C");
                else
                    a++,c--,ans.push_back("A");
            }
        }
        else
        {
            if(a==0 && b==1 && c==1)
            {
                if(s[i+1]=="AC")
                {
                    b--,c++;
                    ans.push_back("C");
                }
                else
                if(s[i+1]=="AB")
                {
                    b++,c--;
                    ans.push_back("B");
                }
                else
                {
                    b++,c--;
                    ans.push_back("B");
                }
            }
            else
            {
                if(b>c)
                    b--,c++,ans.push_back("C");
                else
                    b++,c--,ans.push_back("B");
            }
        }
        if(a<0 || b<0 || c<0)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes\n";
    for(ll i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 10596
#include <iostream>
using namespace std;
int main(){
    int n, i, x, min, max;
    long long sum = 0;
    min = 1000000, max = -1000000;
    cin>>n;
    for(i = 0; i < n; i++){
        cin >> x;
    if(x > max){
        max = x;
}
    if(x < min){
        min = x;
}
    sum += x;
}
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3112
package main

import "fmt"
import "math"

func main() {
	var a, b, c, d float64
	fmt.Scan(&a, &b, &c, &d)
	if math.Abs(a-c) <= d || math.Abs(a-b) <= d && math.Abs(b-c) <= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

int main() {
	int n,sum=0,ans=0,sum1=0,ans1=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	    sum=sum+arr[i];
	}
	sum=sum/n;
	sum1=sum+1;
	sort(arr,arr+n);
	for(int i=0;i<n;i++)
	{
	    ans=ans+(arr[i]-sum)*(arr[i]-sum);
	    ans1=ans1+(arr[i]-sum1)*(arr[i]-sum1);
	}
	cout<<min(ans,ans1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(long long i = (a); i < (b); i++)
#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
 
template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int t, d, l;
	while(cin >> t >> d >> l, t){
		int ans = 0;
		int sum = 0, cur = 0;
		rep(i,t){
			int x;
			cin >> x;

			if(cur <= 0){
				ans += sum;
				sum = 0;
			}else{
				sum++;
			}

			if(l <= x){
				cur = d;
			}else{
				cur--;
			}

		}
		ans = max(ans, sum);
		cout << ans << endl;
	}
}



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

# See:
# http://drken1215.hatenablog.com/entry/2018/06/08/210000
max_value = 500050
mod = 10 ** 9 + 7

fac = [0 for _ in range(max_value)]
finv = [0 for _ in range(max_value)]
inv = [0 for _ in range(max_value)]


def com_init():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, max_value):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    h, w, a, b = map(int, input().split())
    x = h - (a + 1)
    com_init()
    prev = 0
    ans = 0
    com_xy = [0 for _ in range(w - b)]
    com_za = [0 for _ in range(w - b)]
    i = 0
    j = 0

    for y in range(b, w):
        com_xy[i] = com(x + y, y)
        i += 1

    for z in range((w - (b + 1) + a), a - 1, -1):
        com_za[j] = com(z, z - a)
        j += 1

    for xy, za in zip(com_xy, com_za):
        ans += (xy - prev) * za
        ans %= mod
        prev = xy

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

vector<VI> g, re_g;
int num = 0;
vector<pair<int, int>> t;
vector<bool> ever;
void DFS(int now) {
    for (int to : g[now]) {
        if (ever[to])continue;
        ever[to] = true;
        DFS(to);
    }
    t[num++] = { num,now };
}

int main() {
    init();
    
    int n, m;
    cin >> n >> m;

    //正順、逆順のグラフを構成
    g.resize(n); re_g.resize(n);
    FOR(i, 0, m) {
        int s, t;
        cin >> s >> t;
        g[s].push_back(t);
        re_g[t].push_back(s);
    }

    //正順のグラフで行き詰った順に番号付け
    int num = 0;
    t.resize(n);
    ever.resize(n, false);
    FOR(i, 0, n)if (!ever[i]) {
        ever[i] = true;
        DFS(i);
    }
    
    rSORT(t, [](auto a, auto b) {return a.first > b.first; });

    //逆順のグラフでdfs、行き詰るまでに行った点が連結成分
    ever.clear(); ever.resize(n, false);
    vector<VI> ans;
    stack<int> dfs;
    for (auto i : t)if (!ever[i.second]) {
        dfs.push(i.second);
        ever[i.second] = true;
        VI link;
        while (!dfs.empty()) {
            int now = dfs.top(); dfs.pop();
            link.push_back(now);
            for (int to : re_g[now]) {
                if (ever[to])continue;
                ever[to] = true;
                dfs.push(to);
            }
        }
        ans.push_back(link);
    }

    //元から全て強連結
    if (ans.size() == 1) {
        cout << "0\n";
        return 0;
    }

    //何番目の連結成分に属すか
    VI where(n);
    FOR(i, 0, ans.size())for (int j : ans[i])where[j] = i;
    
    //入次数と出次数を数える
    VI in(ans.size(), 0), out = in;
    FOR(now, 0, n)for (int to : g[now]) {
        int a = where[now], b = where[to];
        if (a != b) {
            out[a]++;
            in[b]++;
        }
    }

    SORT(in), SORT(out);
    cout << max(upper_bound(all(in), 0) - in.begin(), upper_bound(all(out), 0) - out.begin()) << "\n";
}


Measured memory_bytes: 5764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  string s;
  cin >> s;
  if(s == "Sunny")cout << "Cloudy" << endl;
  if(s == "Cloudy")cout << "Rainy" << endl;
  if(s == "Rainy")cout << "Sunny" << endl;
  return 0;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

int dist[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	string s;
	cin >> s;
	int n = sz(s);
	s = "!" + s;
	int ans = n - 1;

	for (int i = 1; i <= n; i++) {
		int res = n - i, last = i;
		for (int k = i; k >= 1; k--) {
			if (s[k] == s[i])
				last = k;
			res = max(res, last - k);
		}
		ans = min(ans, res);
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 256
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for __ in range(m)]

no_use = min(A)+min(B)
use=A[xyc[0][0]-1]+B[xyc[0][1]-1]-xyc[0][2]
for i in range(1,m):
    use = min(use,A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2])
print(min(no_use,use))

Measured memory_bytes: 38560
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct {
  int parent;
  int right;
  int left;
} _T;
_T T[MAX];

void print(int u){
 
 int i=T[u].parent, depth=0;
 while(i!=NIL){
   i = T[i].parent;
   depth++;
   }
        if(depth==0){
    printf("node %d: parent = %d, depth = %d, root, ",u,T[u].parent,depth);
    }
	else if(T[u].left==NIL){
    printf("node %d: parent = %d, depth = %d, leaf, ",u,T[u].parent,depth);
    }
	else{
    printf("node %d: parent = %d, depth = %d, internal node, ",u,T[u].parent,depth);
    }
  
	i = T[u].left;
  printf("[");
  if(i!=NIL){
   printf("%d",i);
   }
  
     while (i!=NIL){
       i = T[i].right;
       if(i!=NIL){
	 printf(", %d", i);
       }
     }
     printf("]\n");
}

int main(){
  int i, j, d, v, c, l, n;
 /*d = degreenumber, v = Vertexnumber, c = current*/
 scanf("%d", &n);
  
	for(i=0;i<n;i++){
   T[i].parent = T[i].left = T[i].right = NIL;
   }
  
	   for ( i = 0; i < n; i++ ){
    
    scanf("%d %d",&v,&d);
    
 for(j=0;j<d;j++){
      scanf("%d",&c);
      T[c].parent = v;
      
	       if(j==0){
		 T[v].left = c;
	       }
	       else if(j>0){
		 T[l].right = c;
	       }
      l = c;
      
	       }
    }
		
	for (i=0;i<n;i++){
    print(i);
    }
	
 return 0;
}

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

typedef vector <int> VI;
typedef vector <VI> VVI;

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

int get_x( char c )
{
	if ( c == 'A' || c == 'D' || c == 'G' ) return 0;
	if ( c == 'B' || c == 'E' || c == 'H' ) return 1;
	if ( c == 'C' || c == 'F' || c == 'I' ) return 2;
	return -1;
}

int get_y( char c )
{
	if ( c == 'A' || c == 'B' || c == 'C' ) return 0;
	if ( c == 'D' || c == 'E' || c == 'F' ) return 1;
	if ( c == 'G' || c == 'H' || c == 'I' ) return 2;
	return -1;
}


int main( void )
{
	int n; char s, t, b;
	while ( 1 )
	{
		cin >> n;
		if ( n == 0 ) break;
		cin >> s >> t >> b;

		int sx, sy, gx, gy, ox, oy;
		sx = get_x( s ); sy = get_y( s );
		gx = get_x( t ); gy = get_y( t );
		ox = get_x( b ); oy = get_y( b );

		VVI prev( 3, VI(3,0) ), next;
		prev[sy][sx] = 1;
		for ( int lpc = 0; lpc < n; lpc++ )
		{
			next = VVI( 3, VI( 3, 0 ) );
			for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ )
			{
				if ( i == oy && j == ox ) continue;
				int stop = 0;
				for ( int k = 0; k < 4; k++ )
				{
					int nx = j + dx[k];
					int ny = i + dy[k];
					if ( nx < 0 || nx >= 3 || ny < 0 || ny >= 3 )
					{
						stop++;
						continue;
					}
					else if ( nx == ox && ny == oy )
					{
						stop++;
						continue;
					}
					next[i][j] += prev[ny][nx];
				}
				if ( stop ) next[i][j] += prev[i][j] * stop;
			}
			prev = next;
		}

		int sum = 0;
		// for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ ) sum += next[i][j];
		sum = 1; for ( int i = 0; i < n; i++ ) sum *= 4;

		double answer = (double)next[gy][gx] / (double)sum;

		cout.precision( 8 );
		cout.setf( ios::fixed );
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tmp = L[i]+L[j]
        point = bisect.bisect_left(L,tmp)
        ans += point - j - 1
print(ans)
        

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

class UnionFind {
private:
	vector< int > data;
	int num_of_g;
	
public:
	UnionFind(int n) : data(n, -1), num_of_g(n) {}
	
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		
		if (x == y) return 0;
		
		if (data[y] < data[x]) swap(x, y);
		data[x] += data[y]; data[y] = x;
		--num_of_g;
		
		return 1;
	}
	
	bool sameSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
	int getNumOfG() { return num_of_g; }
};

int main() {
    int N, M;
    cin >> N >> M;

    UnionFind uf(N);
    for_(i,0,M) {
        int x, y, z;
        cin >> x >> y >> z;
        --x; --y;
        uf.unionSet(x, y);
    }

    cout << uf.getNumOfG() << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long h;
	cin>>h;
	long long count = 1;
	long long ans = 0;
	while(h>0)
	{
		ans+=count;
		count*=2;
		h/=2;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int w,h,n,left,bot,right,top,i,ans;
  int x[110],y[110],a[110];

  scanf("%d %d %d",&w,&h,&n);
  left=bot=0,right=w,top=h;

  for(i=0;i<n;i++){
    scanf("%d %d %d",&x[i],&y[i],&a[i]);

    if(a[i]==1){
      if(left<x[i]) left=x[i];
    }else if(a[i]==2){
      if(right>x[i]) right=x[i];
    }else if(a[i]==3){
      if(bot<y[i]) bot=y[i];
    }else if(a[i]==4){
      if(top>y[i]) top=y[i];
    }
  }
  if(left>=right || bot>=top){
    printf("0\n");
  }else{
    ans=(top-bot)*(right-left);
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 128
axises = (1..5).map {gets.to_i}
k = gets.to_i
dists = []
axises.each_with_index do |a, i|
  axises.each_with_index do |b, j|
  	next if i == j
  	dists << (a - b).abs
  end
end
if dists.all? {|x| x <= k}
  puts 'Yay!'
else
  puts ':('
end

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

int n, m;
std::vector<std::vector<int>> edges;

int dfs(int j, int used) {
    if(used == (1 << n) - 1) {
        return 1;
    }
    
    int cnt = 0;
    for(auto& e : edges[j]) {
        if(used & (1 << e)) {
            continue;
        }
        
        cnt += dfs(e, used | (1 << e));
    }
    
    return cnt;
}

int main() {
    std::cin >> n >> m;
    
    int a, b;
    edges.resize(n);
    for(int i = 0; i < m; ++i) {
        std::cin >> a >> b;
        
        --a, --b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    std::cout << dfs(0, 1) << std::endl;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int main(){
    ll a,b;
    cin >> a >> b;
    ll cd = gcd(a, b);
    map<ll, ll> fac;
    ll ans = 1;
    for(ll i=2;i*i<=cd;i++){
        if (cd % i == 0){
        ans++;
        while(cd % i == 0) cd /= i;
        }
    }
    if (cd != 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	long long int n,i,m,ans,a1=1,a2=2,a3;
	int a[100001]={0};
	int temp;
	
	scanf("%lld%lld",&n,&m);
	
	for(i=1;i<=m;i++){
		scanf("%d",&temp);
		a[temp]=1;
		}
		
	if(a[1]==1){
		a1=0;
		a2=1;
		}
	if(a[2]==1)
		a2=0;
	if(n==1){
		printf("1");
		return 0;
		}
	if(n==2){
		printf("%d",a2);
		return 0;
		}

	for(i=0;i<n-2;i++){
		a3=a1+a2;
		if(a[3+i]==1)
			a3=0;
		a1=a2%1000000007;
		a2=a3%1000000007;
	}
		
	ans=a3%1000000007;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 512
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll a,b;
	cin>>a>>b;
	if(a<=5)
	cout<<0;
	else if(a<=12)
	cout<<b/2;
	else
	cout<<b;	
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //arc62 d
    static void solve(InputReader in, PrintWriter out){
        char[] s = in.ns().toCharArray();
        int n = 0, g = 0, p = 0;
        for (int i = 0; i < s.length; i++) {
            if(s[i]=='g'){
                if(g>p){
                    p++;
                    n++;
                }else{
                    g++;
                }
            }else{
                if(g>p){
                    p++;
                }else{
                    g++;
                    n--;
                }
            }
        }
        out.println(n);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int>> graph(n+1);
	vector<ll> distance(n+1,INF);
	vector<bool> check(n+1,false);
	vector<int> mark(n+1);
	distance[1] = 0;

	rep(i,m){
		int a,b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	// for(int i = 1; i<=n;i++){
	// 	cout << i << ":{";
	// 	for(int j=0; j <graph[i].size();j++){
	// 		cout << graph[i][j] << ",";
	// 	}
	// 	cout << "}\n";
	// }

	queue<int> que;
	que.push(1);

	while(!que.empty()){
		int pos = que.front();
		// cout << "pos:" << pos;

		if(check[pos] == true){
			que.pop();
			// cout << "already\n";
		}
		else{
			check[pos] = true;
			// cout << "check\n";
			for(int i = 0;i < graph[pos].size(); i++){
				int next = graph[pos][i];
				que.push(next);

				if(distance[pos] >= distance[next]+1){
					distance[pos] = distance[next]+1;
					mark[pos] = next;
				}
				// cout << "next:" << next << 
				// 		" distance:" << distance[pos] <<
				// 		"mark:" << mark[pos] << endl; 
			}
			que.pop();
		}
	}

	bool flag = true;
	for(int i = 1;i <= n;i++){
		if( check[i] == false){
			flag = false;
			break;
		}
	}

	if(flag){
		cout << "Yes\n";
		for(int i = 2; i<= n;i++){
			cout << mark[i] << endl;
		}
	}
	else cout << "No\n";


	return 0;
}


Measured memory_bytes: 11784
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          
          Console.WriteLine((a[0]+a[1]+1)/2);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string ans = "";
    REP(i, tx - sx) ans += "R";
    REP(i, ty - sy) ans += "U";
    REP(i, tx - sx) ans += "L";
    REP(i, ty - sy) ans += "D";
    ans += "D";
    REP(i, tx - sx + 1) ans += "R";
    REP(i, ty - sy + 1) ans += "U";
    ans += "LU";
    REP(i, tx - sx + 1) ans += "L";
    REP(i, ty - sy + 1) ans += "D";
    ans += "R";
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  
#include <vector>
#include <stack>
#include <cmath>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
using namespace std;

ll t=1,n,m;
ll s=0;
ll a[N]={0};
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]/=2;
		t=a[i]/__gcd(a[i],t)*t;
	}
	for(int i=0;i<n;i++){
		if(t%(a[i]*2)==0){
			cout<<"0"<<endl;
			return 0;
		}
	}
	printf("%lld\n",(m/t+1)/2);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

		String a = scan.next();
		String b = scan.next();

		if(a.compareTo(b)>0)
			System.out.println(">");
		else if(a.compareTo(b)==0)
			System.out.println("=");
		else
			System.out.println("<");


	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }
ll MOD = 1000000007;

int A[1000002] = {0};
map<int, int> primemap;

void era(int n) {
	for (int i = 2; i * i < n; ++i) {
		if (A[i] == 0) {
			for (int j = i; i * j < n; ++j) {
				if (A[i * j] == 0) A[i * j] = i;
			}
		}
	}

	for (int i = 2; i < n; ++i) {
		if (A[i] == 0) {
			primemap[i] = 0;
			A[i] = i;
		}
	}
	A[0] = 1;
	A[1] = 1;
}

int main() {
	int N, maxA=1000000;
	era(maxA + 1);

	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		while(true) {
			if (a == 1) {
				break;
			}
			else if (A[a] == 0) {
				primemap[a]++;
				break;
			}
			else {
				primemap[A[a]]++;
				int waru = A[a];
				while (a % waru == 0) {
					a /= waru;
				}
			}
		}
	}

	int maxW = 0;
	for (auto it = primemap.begin(); it != primemap.end(); it++) {
		maxW = max(maxW, it->second);
	}

	//cout << " *** maxW : "<<maxW << endl;
	if (maxW <= 1 ) {
		cout << "pairwise coprime" << endl;
	}
	else if(maxW == N) {
		cout << "not coprime" << endl;
	}
	else {
		cout << "setwise coprime" << endl;
	}
}

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

using namespace std;
int main(){
    int x[3], buf;
    for(int i = 0; i < 3; i++){
        cin >> x[i];
    }
    for(int i = 2; i > 0; i--){
        for(int j = 0; j < i; j++){
            if(x[j] > x[j+1]) {
                swap(x[j], x[j+1]);
            }
        }
    }
    
    cout << x[0] << " " << x[1] << " " << x[2] << endl;
    return 0;
}


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
char str[55][55];
int h,w;
int nxt[4][2]={
	0,1,
	1,0,
	0,-1,
	-1,0
};

bool pd() {
	int nx,ny;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++) {
			if(str[i][j]=='#') {
				bool flag=false;
				for(int k=0;k<4;k++) {
					nx=i+nxt[k][0];
					ny=j+nxt[k][1];
					if(nx>=0&&nx<h&&ny>=0&&ny<w&&str[nx][ny]=='#')
						flag=true;
				}
				if(!flag)
					return false;
			}
		}
	return true;
}

int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++) {
		cin>>str[i];
	}
	if(pd()) {
		cout<<"Yes"<<endl;
	}else
		cout<<"No"<<endl;
	return 0;
}

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int sta[maxn],top,a[maxn],n;

signed main() {
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    int ans=0,lst=n+1;
    for(int i=n;i;i--) {
        int x=a[lst]-(lst-i);
        if(a[i]==x) continue;
        if(a[i]<x||a[i]>=i) return puts("-1"),0;
        ans+=a[i],lst=i;
    }
    write(ans);
    return 0;
}


Measured memory_bytes: 1792
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200001];

LL ans;

void solve(){
	map<LL,vector<LL>> i_Ai;
	map<LL,vector<LL>> j_Aj;
	for(int i=1;i<=N;i++){
		i_Ai[i+A[i]].push_back(i);
		j_Aj[i-A[i]].push_back(i);
	}
	for(auto iter=i_Ai.begin();iter!=i_Ai.end();iter++){
		LL num = iter->first;
		vector<LL> indexes = iter->second;
		for(int i=0;i<indexes.size();i++){
			if(j_Aj[num].size()==0) continue;
			ans += (j_Aj[num].end() - upper_bound(j_Aj[num].begin(),j_Aj[num].end(),indexes[i]));
		}
	}
}
 
int main(){
    cin >> N;
    for(int i=1;i<=N;i++) cin >> A[i];

    solve();

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

Measured memory_bytes: 59076
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt();
		sc.close();
		if(A<=8&&B<=8) {
			System.out.println("Yay!");
		}
		else {
			System.out.println(":(");
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int prime(int x){
	if (x==1) return 0;
	for(int i=2 ; i*i<=x ; i++){
		if(x%i==0) return 0;
	}
	return 1;
}



int main(){
	int a, d, n;

	while(1){
		cin >> a;
		cin >> d;
		cin >> n;
		if(a==0 && d==0 && n==0) break;

		int i=0;
		int count = 0;
		while(1){
			int flag=0;
			flag = prime(a+d*i);
			if(flag == 1) count++;
			if(count == n){
				cout << a+d*i << endl;
				break;
			}
			i++;
		}

	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	// write your code here
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int x = N%1000;
        int ans = 0;
        if(x!=0) ans = 1000-x;
        System.out.print(ans);
    }
}


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

using ll = long long;

int w[500500], N;
vector<int> e[500500];

bool IsAcyclicDFS(int i) {
    w[i] = 1;
    rep(j, e[i].size()) {
        int x = e[i][j];
        if (w[x] == 1) return false;
        else if (w[x] == 0) {
            if (!IsAcyclicDFS(x)) return false;
        }
    }
    w[i] = 2;
    return true;
}

bool IsAcyclic() {
    rep(i, N * (N - 1) / 2) w[i] = 0;
    rep(i, N * (N - 1) / 2) {
        if (w[i] == 0) {
            if (!IsAcyclicDFS(i)) return false;
        }
    }
    return true;
}

int v(int i, int j) {
    int a = min(i, j);
    int b = max(i, j);
    return b * (b - 1) / 2 + a;
}

int length(int i) {
    if (w[i] > 0) return w[i];
    int ret = 0;
    rep(j, e[i].size()) {
        ret = max(ret, length(e[i][j]));
    }
    w[i] = ret + 1;
    return w[i];
}

int main() {
    int A, B;
    cin >> N;
    rep(i, N) {
        cin >> B;
        B--;
        rep(j, N - 2) {
            cin >> A;
            A--;
            e[v(i, B)].push_back(v(i, A));
            B = A;
        }
    }
    /*
    rep(i, N * (N - 1) / 2) {
        cout << i;
        rep(j, e[i].size()) {
            cout << " " << e[i][j];
        }
        cout << endl;
    }
    */
    if (!IsAcyclic()) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, N * (N - 1) / 2) w[i] = 0;
    int ans = 0;
    rep(i, N * (N - 1) / 2) {
        ans = max(ans, length(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 29568
input = input()
 
nums = input.split(" ")
 
animals = int(nums[0])
legs = int(nums[1])
 
turu = (4*animals -legs)/2.0
kame = (legs-2*animals)/2.0
 
if turu.is_integer() and kame.is_integer() and turu>=0 and kame>=0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C[] = new int[N];
		int S[] = new int[N];
		int F[] = new int[N];

		for (int i = 0; i < N-1; i++) {
			C[i] = sc.nextInt();
			S[i] = sc.nextInt();
			F[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			int time =0;
			for (int j = i; j < N-1; j++) {
				if (time < S[j]) {
					time = S[j];
				} else if (time % F[j]==0) {
				} else {
					time = time + F[j] - time%F[j];
				}
				time += C[j];
			}
			System.out.println(time);
		}
	}
}


Measured memory_bytes: 26796
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n = int(input())
    s = list(input())
    enum = [1 if c == 'E' else 0 for c in s]
    wnum = [1 if c == 'W' else 0 for c in s]
    enuma = tuple(accumulate(enum))
    wnuma = tuple(accumulate(wnum))
    wnumm = wnuma[-1]
    wnuma2 = [wnumm - wn for wn in wnuma]
    num = max(wnuma2[0], enuma[-2])
    for i1 in range(1, n - 1):
        num = max(num, enuma[i1 - 1] + wnuma2[i1])
    r = n - num - 1
    print(r)

if __name__ == '__main__':
    main()

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

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

	string A, B;
	for (int i = 0; i < b; i++) {
		A += to_string(a);
	}

	for (int i = 0; i < a; i++) {
		B += to_string(b);
	}

	if (A < B) {
		cout << A << endl;
	}
	else {
		cout << B << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N, D;
    cin >> N >> D;
vector<vector<int>> vec(N , vector<int>(D));
for(int i = 0; i<N;i++){
    for(int j = 0; j < D ; j++){
        cin >> vec[i][j]; 
    }
}

int cnt = 0;
for(int u = 0; u<N;u++){
   
    for(int v = 0; v < N  ; v++){
        if(u == v) continue;
        else{
        int dist =0;
        for(int k = 0; k < D; k++){
            dist += pow((vec[u][k] -vec[v][k]),  2);
        }
        if(abs(sqrt(dist)) - abs(floor(sqrt(dist)) )== 0){
            cnt += 1;
        } 

        }
        
    }
}
cout << cnt /2;
}


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

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		char s[8];
		int i, j;
		int m[28];
		memset(m, 0, sizeof(m));
		for (i = 0; i < n; i ++) {
			scanf("%s", s);
			m[s[0] - 'A'] ++;
		}
		printf("AC x %d\n", m['A' - 'A']);
		printf("WA x %d\n", m['W' - 'A']);
		printf("TLE x %d\n", m['T' - 'A']);
		printf("RE x %d\n", m['R' - 'A']);
	}
	return (0);
}


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

long long L, R;
int main(){
    cin >> L >> R;
    int ans = 2019;
    if(R - L + 1 >= 2019){
        ans = 0;
    }else if((R % 2019) >= (L % 2019)){
        vector<int> range;
        for(int i = (L % 2019); i <= (R % 2019); i++){
            range.push_back(i);
        }
        for(int i = 0; i < range.size(); i++){
            for(int j = i + 1; j < range.size(); j++){
                ans = min(ans, (range[i] * range[j]) % 2019);
            }
        }
    }else{
        vector<int> range;
        for(int i = 0; i <= (L % 2019); i++){
            range.push_back(i);
        }
        for(int i = (R % 2019); i < 2019; i++){
            range.push_back(i);
        }
        for(int i = 0; i < range.size(); i++){
            for(int j = i + 1; j < range.size(); j++){
                ans = min(ans, (range[i] * range[j]) % 2019);
            }
        }
    }
    cout << ans << endl;
}

        


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define LAST(X) X[X.size()-1]
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int N;
	cin >> N;
	cout << N * (N + 1) / 2;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 10;

int N, rnk[MAX_N], siz[MAX_N], pa[MAX_N], depth[MAX_N];
ll D[MAX_N];
map<ll, int> mp;

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%lld", &D[i]), mp[D[i]] = i;
    for (int i = 1; i <= N; i++) rnk[i] = i, siz[i] = 1;
    sort(rnk + 1, rnk + N + 1, [](int a, int b) { return D[a] > D[b]; });
    for (int i = 1; i < N; i++) {
        int x = rnk[i];
        ll pd = D[x] + 2 * siz[x] - N;
        if (siz[x] * 2 < N && mp.count(pd)) {
            pa[x] = mp[pd];
            siz[pa[x]] += siz[x];
        } else {
            printf("-1\n");
            return 0;
        }
    }
    ll sum = 0;
    for (int i = N - 1; i; i--) {
        int x = rnk[i];
        depth[x] = depth[pa[x]] + 1;
        sum += depth[x];
    }
    if (sum != D[rnk[N]]) {
        printf("-1\n");
        return 0;
    }
    for (int i = 1; i < N; i++) {
        int x = rnk[i];
        printf("%d %d\n", x, pa[x]);
    }
}


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

int main(){
  int A, B;
  cin >> A >> B;
  int Q = 0;
  while ( A <= B ){
    int V, W, X, Y, Z, v, w, x;
    V = A / 10000;
    v = A % 10000;
    W = v / 1000;
    w = v % 1000;
    X = w / 100;
    x = w % 100;
    Y = x / 10;
    Z = x % 10;
    if (V == Z && W == Y){
    Q += 1;
    }
    A ++;
  }
  cout << Q << endl;
}


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

int N;

int main(){
	while(cin >> N && N >1){
		int odd = 0,even = 0, e4 = 0;
		for(int i=0;i<N;i++){
			long long  a;
			cin >> a;
			if(a%4 == 0) e4++;
			else if(a%2 == 0) even++;
			else odd++;;
		}
		if(e4 >= odd || (e4 == odd-1 && even == 0)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 256