akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, A: "List[List[int]]"):
    ret = []
    for r, R in enumerate(A):
        for c in range(len(R) - 1):
            val = R[c]
            if val % 2 == 1:
                ret.append([r, c, r, c + 1])
                R[c + 1] += 1
    for j in range(H - 1):
        val = A[j][W - 1]
        if val % 2 == 1:
            ret.append([j, W - 1, j + 1, W - 1])
            A[j + 1][W - 1] += 1
    print(len(ret))
    for r in ret:
        print(r[0] + 1, r[1] + 1, r[2] + 1, r[3] + 1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [ [ int(next(tokens)) for _ in range(W) ] for _ in range(H) ]  # type: "List[List[int]]"
    solve(H, W, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26284
import sys

def main():
  n = int(input())
  h = list(map(int, input().split()))
  h = h[::-1]
  for i in range(0, n-1):
    if h[i] < h[i+1]:
      h[i+1] -= 1
      if h[i] < h[i+1]:
        print('No')
        sys.exit()
  else:
    print('Yes')


if __name__ == '__main__':
  main()


Measured memory_bytes: 14224
from heapq import heappop, heappush

T = int(input())
ans = []
for _ in range(T):
    N, A, B, C, D = map(int, input().split())

    Q = [(0, N)]
    # already processed
    S = set()
    an = D * N
    while Q:
        cost, num = heappop(Q)
        if num in S:
            continue
        an = min(an, cost + num * D)
        if num == 1:
            break
        S.add(num)

        q, r = divmod(num, 2)
        if r < 2:
            heappush(Q, (cost + A + r * D, q))
        if r > 0:
            heappush(Q, (cost + A + (2 - r) * D, q + 1))

        q, r = divmod(num, 3)
        if r < 2:
            heappush(Q, (cost + B + r * D, q))
        if r > 1:
            heappush(Q, (cost + B + (3 - r) * D, q + 1))

        q, r = divmod(num, 5)
        if r < 3:
            heappush(Q, (cost + C + r * D, q))
        if r > 2:
            heappush(Q, (cost + C + (5 - r) * D, q + 1))
    ans.append(an)

print(*ans, sep="\n")


Measured memory_bytes: 84272
N, M = map(int, input().split())
lst = list(map(int, input().split()))
lst2 = []
for i in lst:
  lst2.append((i*(i+1)//2)/i)
ans = sum(lst2[:M])
max_ans = ans
num = 0
for i in range(M, N):
  ans = ans - lst2[num] + lst2[i]
  num += 1
  if ans > max_ans:
    max_ans = ans
print(max_ans)



Measured memory_bytes: 24808
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,i,a;
pair<int,int>w[1000];
int main(){
  while(1){
    cin>>n>>m>>a;if(n==0)break;
    for(i=0;i<m;i++)cin>>w[i].first>>w[i].second>>n;
    sort(w,w+m);
    for(i=m-1;i>=0;i--){
      n=w[i].second;
      if(n==a)a++;
      else if(n+1==a)a--;
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
package main

import "fmt"

func main() {
	var w, h, x, y, r int
	fmt.Scan(&w, &h, &x, &y, &r)
	if r <= x && x <= w-r && r <= y && y <= h-r {
		fmt.Println("Yes")
	} else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 1160
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())


def lmp(): return list(map(int, input().split()))

x,y = mp()
for i in range(101):
    for j in range(101):
        if i + j == x and 2*i + 4*j == y:
            print("Yes")
            exit()
print("No")




Measured memory_bytes: 63004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    string color;
    cin >> color;
    if ( color == "Y" ){
      cout << "Four" << endl;
      break;
    }
    if ( i == N-1 ){
      cout << "Three" << endl;
      break;
    }
  }
  
}

Measured memory_bytes: 256
using System;

class Program{
    static void MaxHeapify(int[] A, int i){
        var l=i*2+1;
        var r=(i+1)*2;
        int largest;
        if(l<A.Length && A[l]>A[i]){
            largest=l;
        } else{
            largest=i;
        }
        if(r<A.Length && A[r]>A[largest]){
            largest=r;
        }
        if(largest!=i){
            var tmp=A[largest];
            A[largest]=A[i];
            A[i]=tmp;
            MaxHeapify(A, largest);
        }
    }

    static void BuildMaxHeap(int[] A){
        for(var i=(A.Length-1)/2; i>=0; i--){
            MaxHeapify(A, i);
        }
    }

    public static void Main(){
        var H=int.Parse(Console.ReadLine());
        var nodes=new int[H];
        var s=Console.ReadLine().Split(' ');
        for (var i=0; i<H; i++) {
            nodes[i]=int.Parse(s[i]);
        }

        BuildMaxHeap(nodes);

        for(var i=0; i<H; i++){
            Console.Write(" "+nodes[i]);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 49244
#include <iostream>

using namespace std;

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

	if (n == 1) {
		if (a == b) {
			cout << 1;
		} else {
			cout << 0;
		}

		return 0;
	} else {
		if (a > b) {
			cout << 0;
		} else {
			cout << (b - a) * (n - 2) + 1;
		}

		return 0;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int X, Y, Z, K;
    vi A, B, C;
    cin >> X >> Y >> Z >> K;
    A.resize(X);
    B.resize(Y);
    C.resize(Z);
    REP(i, X)
    cin >> A[i];
    REP(i, Y)
    cin >> B[i];
    REP(i, Z)
    cin >> C[i];

    vi AB;

    REP(i, A.size())
    REP(j, B.size())
    AB.push_back(A[i] + B[j]);

    sort(ALL(AB));

    vi ABC;
    REP(i, C.size())
    REP(j, AB.size())
    {
        if (j == K)
            break;
        ABC.push_back(C[i] + AB[AB.size() - 1 - j]);
    }

    sort(ALL(ABC));
    REP(i, K)
    cout << ABC[ABC.size() - 1 - i] << endl;
}

Measured memory_bytes: 43368
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    int a;
    input(a);

    cout << a + a * a + a * a * a << endl;
    return 0;
}

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

 int main(){
  int i,j;
  char C[2][3]={};

  cin >> C[1][1] >> C[1][2] >> C[1][3];
  cin >> C[2][1] >> C[2][2] >> C[2][3];

  if (C[1][2]==C[2][2] && C[1][3]==C[2][1] && C[1][1]==C[2][3]) {
    cout << "YES" << endl;
   } 
  else cout << "NO" << endl;


 return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    map<int, int> mp;
    REP(i, n) mp[a[i]]++;
    int ans = 0;
    for(auto x : mp){
        if(x.second % 2 == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
long s,l;
string a[10001],kq="";
int main()
{
    cin>>s>>l;
    for(long i=1;i<=s;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+s);
    for(long i=1;i<=s;i++)
    {
        kq+=a[i];
    }
    cout<<kq<<endl;
    return 0;
}


Measured memory_bytes: 384
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

# 01ナップサック問題
N,W = map(int,readline().split())
AB = [list(map(int,readline().split())) for i in range(N)]
AB.sort(key=lambda x: (x[0],x[1]))
dp = [0]*(W+1)

for (w,v) in AB:
    dpnew = dp[::]
    for j in range(W):
        dpnew[min(j+w,W)] = max(dp[min(j+w,W)],dp[j] + v)
    dp = dpnew

print(max(dp))


Measured memory_bytes: 75324
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	ll N, M;
	cin >> N >> M;

	ll X[MAX];

	
	repn(i, M) cin >> X[i];

	sort(X + 1, X + M + 1);


	ll dis[MAX];

	repn(i, M - 1) dis[i] = X[i + 1] - X[i];

	sort(dis + 1, dis + M);

	ll ans = X[M] - X[1];

	repn(i, min(M - 1, N - 1)) {
		ans -= dis[M - i];
	}

	cout << ans;

	

	system("PAUSE");
}

Measured memory_bytes: 6784
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ans;
int n,m;
vector<int> v[111];

int f[111];
int cnt;
void dfs(int i,int be,int en){
    if(f[i])return;
    f[i]=1;cnt++;
    for(auto x:v[i]){
        if((be==x && en==i)||(be==i && en==x))continue;
        dfs(x,be,en);
    }
}

int a[111],b[111];
signed main(){
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }

    rep(i,m){
        rep(j,n)f[j]=0;
        dfs(0,a[i],b[i]);
        if(cnt<n)ans++;
        cnt=0;
    }
    cout<<ans<<endl;
    


}

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

signed main(){
  
  int n;
  cin>>n;
  
  for(int i=1;i<10;i++){
    for(int j=i;j<10;j++){
      if(i*j==n){
	cout<<"Yes"<<endl;
	return 0;
      }
    }
  }
  
  cout<<"No"<<endl;
  
  return 0;
}


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

using namespace std;

#define fto(i, s, e) for(int i = s; i <= e; ++i)
#define fto1(i, s, e) for(int i = s; i < e; ++i)
#define fdto(i, s, e) for(int i = s; i >= e; --i)
#define fit(var, it) for(__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define frit(var, it) for(__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it)

#define newl '\n'
#define debugt cerr << 0.001*clock() << newl
#define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl
#define debug(v, l, r) fto(_i, l, r) debug1(v, _i)
#define debug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl
#define debug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << newl

#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define glen(v) int((v).size())

template<typename T1, typename T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.ff << ", " << v.ss << ')';
}

#define eps 1e-15
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003

int n;
int h[maxn], f[maxn];

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("main.inp", "r", stdin);
		//freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	fto (i, 1, n) scanf("%d", &h[i]);

	f[0] = oo;

	fto (i, 2, n) f[i] = min(f[i-1] + abs(h[i] - h[i-1]), f[i-2] + abs(h[i] - h[i-2]));

	printf("%d\n", f[n]);

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll mypow(ll m, ll p) {
    if (p == 0) return 1;
    ll tmp = mypow(m, p / 2);
    if (p & 1) return tmp * tmp * m;
    else return tmp * tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll tmp = 1;
    ll dig = 0;
    bool is_yes = true;
    for (; dig < 11; dig++) {
        cout << "? " << tmp << endl;
        char c; cin >> c;
        if (c == 'N') {
            is_yes = false;
            break;
        }
        tmp *= 10;
    }
    dig--;

    if (is_yes) {  // 10^p の時
        ll tmp = 9999999999;
        dig = 10;
        for (; dig > 0; dig--) {
            cout << "? " << tmp << endl;
            char c; cin >> c;
            if (c == 'N') {
                break;
            }
            tmp /= 10;
        }
        cout <<  "! " << mypow(10, dig) << endl;
        return 0;
    } else {
        ll low = mypow(10, dig), high = mypow(10, dig + 1);
        while (low < high) {
            ll mid = (low + high) >> 1;
            cout << "? " << mid * 10 << endl;
            char c; cin >> c;
            if (c == 'Y') {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        cout << "! " << low << '\n';
    }
    return 0;
}


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

def main():
    #入力
    S = str(input())
    w = int(input())

    for i in range(len(S)):
        #print(S[count], end="")
        if i % w == 0:
            print(S[i], end='')

    print('\n', end = '')

if __name__ == '__main__':
    main()
    

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

int main(){
    string str;
    char color;
    int ans=0;

    cin>>str;
    color=str[0];
    for(int i=1; i<str.length(); i++){
        if(color!=str[i]){
            color=str[i];
            ans++;
        }
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <complex>
#include <cstdio>
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;

double dot(point a,point b){
  return a.x*b.x+a.y*b.y;
}

point projection(point a,point b,point c){
  point base = b - a;
  double r = dot(c-a,base)/(abs(base)*abs(base));
  return a+base*r;
}

point reflection(point a,point b,point c){
  return 2.0*projection(a,b,c)-c;
}

int main(){
  point a,b,c;
  cin >>a.x>>a.y>>b.x>>b.y;
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> c.x >> c.y;
    point res = reflection(a,b,c);
    printf("%.10f %.10f\n",res.x,res.y);
  }
  return 0;
}

Measured memory_bytes: 1264
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 510
#define MAXM 250010
int a[MAXM],f[MAXN],x[MAXN],n,ls=1;
bool cmp(int a,int b)
{
	return x[a]<x[b];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
		a[x[i]]=i;
		f[i]=i;
	}
	sort(f+1,f+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		int k=f[i];
		for(int j=1;j<k;j++)
		{
			while(a[ls]) ls++;
			if(ls>x[k])
			{
				printf("No\n");
				return 0;
			}
			a[ls]=k;
		}
	}
	for(int i=1;i<=n;i++)
	{
		int k=f[i];
		for(int j=1;j<=n-k;j++)
		{
			while(a[ls]) ls++;
			if(ls<x[k]||ls>n*n)
			{
				printf("No\n");
				return 0;
			}
			a[ls]=k;
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n*n;i++)
		printf("%d ",a[i]);
}

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

int main(void) {
    int n, i, j, t;
    cin >> n;
    int A[n];

    for (i = 0; i < n; i++) {
        cin >> A[i];
        cout << A[i];
        if (i == n - 1) cout << endl;
        else cout << ' ';
    }

    for (i = 1; i < n; i++) {
        t = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > t) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = t;

        for (j = 0; j < n; j++) {
            cout << A[j];
            if (j == n-1) cout << endl;
            else cout << ' ';
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int a,b,c,d,t;
int main() {
 
 scanf("%d %d %d %d",&a,&b,&c,&d);
 if(a<b){ 
   if(c<d){
     t=a+c;
     printf("%d",t);}
   
   else{
     t=a+d;
     printf("%d",t);} 
 }
 else{
   if(c<d){
     t=b+c;
     printf("%d",t);}
   
   else{
     t=b+d;
     printf("%d",t);} 
  }
 
 return 0;
 
  }

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int minimum = 200;
    int ans;
    for(int i = -100; i < 200; i++){
      bool can = true;
        for(int j = 0; j < n; j++){
            if(i == p[j]){
              can = false;
              break;
            }
        }
		if(can && abs(x - i) < minimum){
                minimum = abs(x - i);
                ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

void Zero()
{
    puts("Zero");
    exit(0);
}

int main()
{
    lint a, b;
    cin >> a >> b;
    if (a * b <= 0) Zero();
    else if (a < 0 and b < 0 and (b - a) % 2 == 0) puts("Negative");
    else puts("Positive");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

template <typename X>
X BinSearch(X left, X right, function<bool(X)> judge, bool lower = true, X eps = 1) {
    while (right - left > eps) {
        X mid = (right + left) / 2;
        if (judge(mid) == lower) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return lower ? right : left;
}

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for(auto &x : L) cin >> x;
    sort(WHOLE(L));
    i64 ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N - 1; j++) {
            int k_lower = BinSearch<int>(j, N, [&](int k) -> bool {
                return L[j] - L[i] < L[k];
            }, true);
            int k_upper = BinSearch<int>(j, N, [&](int k) -> bool {
                return L[k] < L[i] + L[j];
            }, false);
            ans += max(0, k_upper - k_lower + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
board = []
for _ in range(h):
    row = input()
    if '#' in row:
        board.append(row)
result = [''] * len(board)
for i in range(w):
    if any(row[i] == '#' for row in board):
        result = [result[j] + board[j][i] for j in range(len(board))]
for rrow in result:
    print(rrow)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <vector>
#include <iomanip>
using namespace std;


int main(){
    // input
    int N, L; cin >> N >> L;

    // compute
    int tmp = 500;
    int del_index;
    vector<int> A(N);
    for (int i = 0; i < N; ++i){
        A.at(i) = i + L;
        if (tmp >= abs(i + L)){
            tmp = abs(i + L);
            del_index = i;
        }
    }
    A.erase(A.begin() + del_index);
    cout << accumulate(A.begin(), A.end(), 0) << endl;

    // output
}



Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_4-D: Allocation

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

using uint = unsigned int;

static pair<uint, uint> sum_max(const vector<uint>& ws)
{
  auto ws_sum = 0u;
  auto max_w = 0u;
  for (auto w : ws) {
    ws_sum += w;
    max_w = max(max_w, w);
  }
  return make_pair(ws_sum, max_w);
}

static bool is_loaded(uint max_load, uint num, const vector<uint>& ws)
{
  const auto last = ws.end();
  auto it = ws.begin();
  for (auto i = 0u; i < num; ++i) {
    auto capacity = max_load;
    while (it < last && *it <= capacity) {
      capacity -= *it++;
    }
    if (it == last) return true;
  }
  return false;
}

static uint min_load_capacity(uint num, const vector<uint>& ws)
{
  const auto sum_max_ws = sum_max(ws);
  const auto ws_sum = sum_max_ws.first; // accumulate(ws.begin(), ws.end(), 0);
  const auto max_w = sum_max_ws.second; // max_element(ws.begin(), ws.end());

  auto left = max(max_w, (ws_sum-1)/num+1);
  auto right = ws_sum;
  while (left < right) {
    const auto middle = (left+right)/2;
    if (is_loaded(middle, num, ws)) {
      right = middle;
    } else {
      left = middle+1;
    }
  }
  return right; // right == left;
}

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

  vector<uint> ws(n);
  for (auto i = 0u; i < n; ++i) {
    cin >> ws[i];
  }

  auto c = min_load_capacity(k, ws);
  cout << c << endl;
}

// eof

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> p(N, 0);
	rep (i, N){
		cin >> p[i];
	} // end rep

	sort(ALL(p), greater<int>());
	
	int res = p[0] / 2;
	for (int i = 1; i < N; ++i){
		res += p[i];
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
const int maxn = 1000100;
const int INF = 0x3f3f3f3f;
long long res[100];
int main() {
    res[0] = 2;
    res[1] = 1;
    int n;
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        res[i] = res[i - 1] + res[i - 2];
    }
    cout << res[n] << endl;
}

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

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for (int(i) = a; (i) <= (b); ++(i))
#define rep(i, n) FOR(i, 0, n-1 )
#define FFOR(i, a, b) for (int(i) = a; (i) > (b); --(i))
#define rrep(i, n) FFOR(i, 0, n)
#define vsort(v) sort((v).begin(), (v).end());           //小さい順
#define rvsort(v) sort(v.begin(), v.end(), greater<>()); //大きい順
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define all(c) (c).begin(), (c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout << (p) << endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 123456789012345
#define int ll
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn = 1e5 + 10;
int a[maxn];
map<int,int> mp;

signed main() {

  int n,m;cin>>n>>m;
  a[0] = 0;
  rep(i,n) 
  {
    cin >> a[i+1];
    a[i+1] += a[i];
    a[i+1] %= m;
  }

  sort(a,a+n+1);

  int ans = 0;
  int cnt = 1;
  FOR(i,1,n)
  {
    if(a[i] == a[i-1])cnt++;
    else 
    {
      ans += cnt*(cnt-1)/2;
      cnt =1;
    }
  }

  ans += cnt*(cnt-1)/2;
  cout << ans << endl;

 
}


Measured memory_bytes: 1024
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def recur(num, i, a, b, c):
    if num == i:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A-a) + abs(B-b) + abs(C-c)
    return min([
        recur(num, i + 1, a, b, c),
        recur(num, i + 1, a + l[i], b, c) + (10 if a > 0 else 0),
        recur(num, i + 1, a, b + l[i], c) + (10 if b > 0 else 0),
        recur(num, i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)
    ])


print(recur(n, 0, 0, 0, 0))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

ll ans=0;
int a[maxn];
ll sum[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum[i]=(sum[i-1]+a[i])%MOD;
    }
    ll ans=0;
    for(int i=n;i>1;i--)
    {
        ans=(ans+sum[i-1]*a[i])%MOD;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6092
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll isp(ll n){
	for(ll i=2;i*i<=n;i++) if(n%i==0)return 0;
	return 1;
}
ll fox(ll n){
	ll lo=1;
	ll hi=n;
	ll ans=0;
	while(hi>=lo){
		ll m=(hi+lo)/2ll;
		ll s=(m*m+m)/2ll;
		if(s>n)hi=m-1ll;
		else lo=m+1ll,ans=m;
	}
	return ans;
	
}
map<ll,ll> help;
int main(){
    ll n;
    cin>>n;
    for(ll i=2;i*i<=n;i++){
    	if(isp(i)==1 && n%i==0){
    		ll c=0;
    		while(n%i==0){
    			c++;
    			n/=i;
			}
			help[i]=c;
		}
	}
	if(n>1)help[n]++;
	ll ans=0;
	map<ll,ll> ::iterator it;
	for (it=help.begin();it!=help.end();it++){
		ll u=it->ss;
		
		ans+=fox(u);
	}
	cout<<ans<<endl;
	
	
	
	
	  	  
    
}

Measured memory_bytes: 3640
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>


double dis(double x1 , double y1 , double x2 , double y2){
	return sqrt(pow(x2-x1 , 2) + pow(y2-y1 , 2));
}

int main(void){
	double xa , ya , ra , xb , yb , rb , d;
	int i , n;
	scanf("%d" , &n);
	for(i=1;i<=n;i++){
		scanf("%lf %lf %lf %lf %lf %lf" , &xa , &ya , &ra , &xb , &yb , &rb);
		d = dis(xa , ya , xb , yb);
		if(d > ra+rb) printf("0");
		else if(rb > ra){
			if(d < rb-ra) printf("-2");
			else printf("1");
		}else if(ra > rb){
			if(d < ra-rb) printf("2");
			else printf("1");
		}else printf("1");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  int n = sc.nextInt();
	  int m = sc.nextInt();
	  int x = sc.nextInt();
	  int y = sc.nextInt();
	  
	  int[] numX = new int[n];
	  int[] numY = new int[m];
	  
	  for (int i = 0; i < n; i++) {
		  numX[i] = sc.nextInt();
	  }
	  
	  for (int i = 0; i < m; i++) {
		  numY[i] = sc.nextInt();
	  }
	  
	  Arrays.sort(numX);
	  Arrays.sort(numY);
	  
	  for (int i = x + 1; i <= y; i++) {
		  if (numX[n-1] < i && i <= numY[0]) {
			  System.out.println("No War");
			  System.exit(0);
		  }
	  }
	  System.out.println("War");
	  System.exit(0);
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

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

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

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 21204
N=int(input())
L=input().split()
for i in range(len(L)):
    x=int(L[i])
    L[i]=x
#一番長い辺を求める。
#辺の長さの和を求める。
max=0
s=0
for i in range(len(L)):
    s+=L[i]
    if max<L[i]:
        max=L[i]
S=s-max
#判定
if max<S:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, P, Q;
            cin >> A >> P;
                Q = 3 * A + P;
                if(Q % 2 == 0){
                    cout << Q / 2 << endl;
                }else{
                    cout << (Q - 1) / 2 << endl;
                }
    return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n = 6;
int h, w, c;
int p[10][10];
int prv[10][10];
bool connect[10][10];
bool visited[10][10];
int ans;
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

void dfs2(int y, int x, int color, int change){
    visited[y][x] = true;
    if(p[y][x] != color) return;
    connect[y][x] = true;
    p[y][x] = change;
    rep(i, 0, 4){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(!contain(ny, nx)) continue;
        if(visited[ny][nx]) continue;
        dfs2(ny, nx, color, change);
    }
}

void dfs(int times){
    int sv[10][10];
    rep(i, 0, h) rep(j, 0, w) sv[i][j] = p[i][j];
    rep(i, 0, n){
        rep(j, 0, h) rep(k, 0, w){
            connect[j][k] = false;
            visited[j][k] = false;
        }
        dfs2(0, 0, p[0][0], i);
        if(times <= 4) dfs(times + 1);
        else{
            if(sv[0][0] != c) continue;
            int cnt = 0;
            rep(j, 0, h) rep(k, 0, w) if(connect[j][k]) cnt++;
            chmax(ans, cnt);
        }
        rep(j, 0, h) rep(k, 0, w) p[j][k] = sv[j][k];
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1){
        cin >> h >> w >> c;
        if(h + w + c == 0) break;
        c--;
        rep(i, 0, h){
            rep(j, 0, w){
                cin >> p[i][j];
                p[i][j]--;
            }
        }
        ans = 0;
        dfs(0);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3140
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        List<Integer> aa = Arrays.asList(new Integer[]{a, b});

        List<Integer> c = Arrays.asList(new Integer[]{1, 3, 5, 7, 8, 10, 12});
        List<Integer> d = Arrays.asList(new Integer[]{2});
        List<Integer> e = Arrays.asList(new Integer[]{4, 6, 9, 11});

        if (c.containsAll(aa) || d.containsAll(aa) || e.containsAll(aa)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	string s,t,ans="";
  int i,j,n,m;
  cin>>n;
  cin>>s>>t;
  for(i=0;i<n;i++){
    cout<<s[i];
    cout<<t[i];
  }
	return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	string a, b;
	cin >> a >> b;
	double n=stoi(a+b);
	if(sqrt(n) == (int)sqrt(n))
		cout<< "Yes" << endl;
	else
		cout << "No" << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> D(N);
    repeat(i, N) cin >> D[i].first >> D[i].second;

    repeat(i, N - 2) {
        if (D[i].first == D[i].second and
            D[i + 1].first == D[i + 1].second and
            D[i + 2].first == D[i + 2].second) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
  using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if (N * A >= B){
    cout << B << endl;
  }
  if (N * A < B){
    cout << N * A << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

ll dis[100005][3];
vector<ll> v[100005];
ll s,t;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m; cin >> n >> m;
  rep(i,m){
      ll a,b; cin >> a >> b;
      a-- ; b--;
      v[a].push_back(b);
  }
  rep(i,n){
      rep(j,3){
          dis[i][j] = LINF;
      }
  }
  cin >> s >> t;
  s--; t--;
  priority_queue<PP> pq;
  pq.push(mp(0,mp(s,0)));
  while(pq.size()){
      auto tmp = pq.top();
      pq.pop();
      ll d = -tmp.first;
      ll pos = tmp.second.first;
      ll mo = tmp.second.second;
      if(d < dis[pos][mo]){
          dis[pos][mo] = d;
          rep(i,v[pos].size()){
              ll to = v[pos][i];
              pq.push(mp(-(d+1),mp(to, (mo+1)%3)));
          }
      }
  }
  if(dis[t][0]!=LINF){
      cout << dis[t][0]/3 << endl;
  }else{
      cout << -1 << endl;
  }
}

Measured memory_bytes: 10992
from functools import reduce
from fractions import gcd
def gcds(a):
  return reduce(gcd, a)

n,k = map(int,input().split())
a = list(map(int,input().split()))
if k%gcds(a) == 0 and max(a)>=k:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 16204
object Main {
	def main(A:Array[String]){
		val s = new java.util.Scanner(System.in)
		val c=Ordering[Iterable[Int]]
		val d=s.next.split("/").map(_.toInt)
		println(if(c.lt(Seq(1989,1,7),d)&&c.lt(d,Seq(2019,5,1))) "Heisei" else "TBD")
	}
}

Measured memory_bytes: 25516
#include <stdio.h>
 
int main (void) {
    long long N, a[5];
    scanf("%lld %lld %lld %lld %lld %lld", &N, &a[0], &a[1], &a[2], &a[3], &a[4]);
    long long min = a[0];
    for (int i = 1; i < 5; i++) {
        if(min > a[i]) min = a[i];
    }
    printf("%lld", (N + min - 1)/min + 4);
    return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static class Data implements Comparable<Data>{
		public String str;
		public int point;
		
		public Data(String str,int p){
			this.str = str;
			point = p;
		}

		@Override
		public int compareTo(Data o) {
			// TODO Auto-generated method stub
			Data another = (Data) o;

			return (this.point > another.point) ? -1
					: this.point == another.point ? 0 : 1;
		}
		
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		boolean is_first = true;
		
		while(true){
			int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			if(is_first == false){
				System.out.println();
			}
			
			Data[] array = new Data[n];
			for(int i = 0; i < n; i++){
				String name = sc.next();
				int win = sc.nextInt();
				int lose = sc.nextInt();
				int drow = sc.nextInt();
				
				array[i] = new Data(name,win*3 + drow);
			}
			
			Arrays.sort(array);
			
			for(Data d : array){
				System.out.println(d.str + "," + d.point);
			}
			
			if(is_first == true){
				is_first = false;
			}
			
		}
		
	}
	
}

Measured memory_bytes: 12000
#include <iostream>
#include <cmath>

using namespace std;

long xyz(long h) {
    if(h == 1) {
        return 1;
    }
    
    return 1 + xyz((long)floor(h / 2.0)) * 2;
}

int main() {
    long h;
    cin >> h;
    cout << xyz(h) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=1e5+500;
const ll inf=1e9+800;
const ll mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	ll n;
	cin>>n;
	vector<pair<ll,pii> > vec;
	for(ll i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		vec.pb(mp(a+b,mp(a,b)));
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	ll ans=0;
	bool nobat=1;
	for(auto r:vec){
		if(nobat){
			ans+=r.S.F;
		}else{
			ans-=r.S.S;
		}
		nobat=!nobat;
	}
	cout<<ans;
}




















Measured memory_bytes: 4980
main = do
  z <- readLn
  xs <- map read . words <$> getLine
  print $ solve z (1, 0) xs

solve z (_, m) [] = if z == m then -1 else m
solve z (n, m) (x:xs) =
  if n == x then
    solve z (n+1, m) xs
  else
    solve z (n, m+1) xs

Measured memory_bytes: 65532
#include <iostream>

using namespace std;

int main()
{
	int r, c;
	cin >> r >> c;

	int** a = new int*[r + 1];
	for (int i = 0; i <= r; i++)
	{
		a[i] = new int[c + 1];
	}

	for (int i = 0; i < r; i++)
	{
		int sum = 0;
		for (int j = 0; j < c; j++)
		{
			cin >> a[i][j];
			sum += a[i][j];
		}
		a[i][c] = sum;
	}

	for (int i = 0; i <= c; i++)
	{
		int sum = 0;
		for (int j = 0; j < r; j++)
		{
			sum += a[j][i];
		}
		a[r][i] = sum;
	}


	for (int i = 0; i <= r; i++)
	{
		for (int j = 0; j <= c; j++)
		{
			cout << (j == 0 ? "" : " ") << a[i][j];
		}
		cout << endl;
	}

}


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

int m, n;
const int MAX_N = 7400000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
void sieve(){
   int p = 0;
   for(int i = 0; i < MAX_N; i++) is_prime[i] = true;
   is_prime[0] = is_prime[1] = false;
   for(int i = m; i <= MAX_N; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j = i; j <= MAX_N; j += i) is_prime[j] = false;
        }
        if(p == n) break;
    }
}

int main() {
    while(1){
        cin >> m >> n;
        if(m + n == 0) break;
        sieve();
        for(int i = m; i <= MAX_N; i++){
            if(is_prime[i] == true){
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 12244