akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){fastio
    ll a,b,c,d;cin>>a>>b>>c>>d;
    dd ans=(dd)a*b;
    ans/=2.0;
    ll x=0;
    if(a==c*2&&b==d*2)x=1;
    cout<<ans<<" "<<x<<endl;
    
    return 0;
}



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

struct Node{
	int key;
	Node *next, *prev;
};
Node *nil;

Node* listSearch(int key){
	Node *cur=nil->next;
	while(cur!=nil&&cur->key!=key){
		cur=cur->next;
	}
	return cur;
}

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
}


void printList(){
	Node *cur=nil->next;
	int isf=0;
	while(1){
		if(cur==nil)break;
		if(isf++>0)printf(" ");
		printf("%d", cur->key);
		cur=cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if(t==nil)return;
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
}
void deleteFirst(){
	deleteNode(nil->next);
}
void deleteLast(){
	deleteNode(nil->prev);
}
void deleteKey(int key){
	deleteNode(listSearch(key));
}
void insert(int key){
	Node *x=(Node *)malloc(sizeof(Node));
	x->key=key;
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

int main() {
int key,n,i;
int size=0;
char com[20];
int np=0,nd=0;
scanf("%d",&n);
init();
for (int i = 0; i < n; ++i) {
	scanf("%s%d",com,&key);
	if(com[0]=='i'){insert(key);np++;size++;}
	else if(com[0]=='d'){
		if(strlen(com)>6){
			if(com[6]=='F')deleteFirst();
			else if(com[6]=='L')deleteLast();
		}else{
			deleteKey(key);nd++;
		}
		size--;
	}
}
printList();
return 0;
}

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

int main() {
    int n;cin>>n;
    int a;
    map<int,int> m;
    vector<int> v;
    for (int i=0;i<n;i++) {
        cin>>a;
        m[a]++;
        if (m[a]==2) {
            m[a]=0;
            v.push_back(-a);
        }
    }
    sort(v.begin(),v.end());
    if (v.size()>=2)
        cout<<(ll)v[0]*v[1]<<endl;
    else
        cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <utility>
#include <string>

using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;
bool notPrime[1000001]={0};

void era(){
    notPrime[0]=true;notPrime[1]=true;
    for(int i=4;i<=1000000;i+=2){
        notPrime[i]=true;
    }
    for(int i = 3; i <= 4999;i+=2){
        if(notPrime[i]==true)continue;
        for(int j=i+i;j<=1000000;j+=i){
            notPrime[j]=true;
        }
    }
    
}

int main(){
    int a,b,n,tmp,tmp2;
    vector<int> ans;
    cin>>a>>b>>n;
    era();
    while (a!=0){
        tmp=0;
        while (tmp!=n){
            if(!notPrime[a]){
                tmp++;
            }
            a+=b;
        }
        ans.push_back(a-b);
        cin>>a>>b>>n;
    }

    for(int i = 0;i<ans.size();i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 4148
N = int(input())
W_list = [input() for i in range(N)]

pre = ''
for i,w in enumerate(W_list):
    if W_list.count(w) > 1:
        print('No')
        exit(0)
    if i == 0:
        pre = w[-1:]
        #print(pre)
        continue
    if pre != w[0:1]:
        print('No')
        exit(0)
    pre = w[-1:]
    #print(w)
    #print(pre)

print('Yes')

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        primeLib = new ArrayList<>();
        primeLib.add(2);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            System.out.println(primeCountFor(n));
        }
    }

    public static ArrayList<Integer> primeLib;
    public static int checkedMax = 0;

    public static int primeCountFor(int n) {
        if (n == 1) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        int l = primeLib.get(primeLib.size() - 1);
        // System.out.println(n + ":" + l);
        if (n <= l) {
            int i = Arrays.binarySearch(primeLib.toArray(), n);
            // System.out.println("under: " + n);
            // System.out.println(i);
            if (i < 0) {
                return ~i;
            }
            return i + 1;
        }
        int c = primeLib.size();
        for (int i = l + 1; i <= n; i++) {
            if (isPrime(i)) {
                c++;
            }
        }
        return c;
    }

    public static boolean isPrime(int n) {
        if (n <= checkedMax) {
            return primeLib.contains(n);
        }
        if (n == 1) {
            return false;
        }
        if (n == 2) {
            return true;
        }
        if (n % 2 == 0) {
            return false;
        }
        int l = (int) Math.sqrt(n);
        for (int i = 3; i <= l; i += 2) {
            if (n % i == 0) {
                checkedMax = Math.max(checkedMax, n);
                return false;
            }
        }
        primeLib.add(n);
        return true;

    }
}

Measured memory_bytes: 30904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vvc<ll> P(10, vl(10, 0));
    ll ans = 0;
    ll r = 1;
    repe(i, 1, N + 1) {
        if (i / r >= 10) r *= 10;
        P[i / r][i % 10]++;
    }
    // rep(i, 10) rep(j, 10) cout << P[i][j] << endl;
    rep(i, 9) rep(j, 9) ans += P[i + 1][j + 1] * P[j + 1][i + 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]

    min_count = 0
    for i in range(1, N):
        if S[i] != "W":
            min_count += 1
    prev_count = min_count

    for i in range(1, N):

        if S[i - 1] == "E" and S[i] == "E":
            prev_count -= 1
        elif S[i - 1] == "W" and S[i] == "W":
            prev_count += 1
        if prev_count < min_count:
            min_count = prev_count

    print min_count


if __name__ == '__main__':
    main()


Measured memory_bytes: 12804
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n >> m >> k;
  int mx = max(n, m);
  cout << (k + mx - 1) / mx << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<pii> vii;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
multiset<int>ms;
int main(){
    ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int t;
		cin>>t;
		ms.insert(t);
	}
	int ans=0;
	while(!ms.empty()){
		auto it=ms.end();
		it--;
		int x=*it;
		ms.erase(it);
		int i;
		for(i=1;i<=x;i*=2);
		if(ms.find(i-x)!=ms.end()){
			ans++;
			ms.erase(ms.find(i-x));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9748
import std.stdio, std.string, std.conv, std.algorithm, std.array;

struct P { int x, y; }

void main()
{
    int[102][102] m;
    auto f = readln.split.map!(to!int);
    int W = f[0],
        H = f[1];

    foreach(i; 0 .. H)
    {
        foreach(j, n; readln.split.map!(to!int).array)
        {
            m[i + 1][j + 1] = n;
        }
    }

    W += 2;
    H += 2;

    P[] getRin(P p)
    {
        P[] res;
        if(p.x > 0) res ~= P(p.x - 1, p.y);
        if(p.x < W - 1) res ~= P(p.x + 1, p.y);
        if(p.y % 2 == 0)
        {
            if(p.y > 0)
            {
                res ~= P(p.x, p.y - 1);
                if(p.x > 0) res ~= P(p.x - 1, p.y - 1);
            }
            if(p.y < H - 1)
            {
                res ~= P(p.x, p.y + 1);
                if(p.x > 0) res ~= P(p.x - 1, p.y + 1);
            }
        }
        else
        {
            if(p.y > 0)
            {
                res ~= P(p.x, p.y - 1);
                if(p.x < W - 1) res ~= P(p.x + 1, p.y - 1);
            }
            if(p.y < H - 1)
            {
                res ~= P(p.x, p.y + 1);
                if(p.x < W - 1) res ~= P(p.x + 1, p.y + 1);
            }
        }
        return res;
    }

    void dfs(P p)
    {
        if(m[p.y][p.x] == 0)
        {
            m[p.y][p.x] = 2;
            foreach(rin; getRin(p))
            {
                dfs(rin);
            }
        }
    }

    dfs(P(0, 0));

    int res;
    foreach(y; 1 .. H - 1)
    {
        foreach(x; 1 .. W - 1)
        {
            if(m[y][x] == 1) foreach(rin; getRin(P(x, y)))
            {
                if(m[rin.y][rin.x] == 2) ++res;
            }
        }
    }
    res.writeln;
}

Measured memory_bytes: 2296
L = list((input()))
A = L[0]
B = L[1]
C = L[2]
D = L[3]
a = int(L[0])
b = int(L[1])
c = int(L[2])
d = int(L[3])
if a+b+c+d == 7 :
    print("{}+{}+{}+{}=7".format(a,b,c,d))
elif a+b+c-d == 7 :
    print("{}+{}+{}-{}=7".format(a,b,c,d))
elif a+b-c+d == 7 :
    print("{}+{}-{}+{}=7".format(a,b,c,d))
elif a-b+c+d == 7 :
    print("{}-{}+{}+{}=7".format(a,b,c,d))
elif a+b-c-d == 7 :
    print("{}+{}-{}-{}=7".format(a,b,c,d))
elif a-b+c-d == 7 :
    print("{}-{}+{}-{}=7".format(a,b,c,d))
elif a-b-c+d == 7 :
    print("{}-{}-{}+{}=7".format(a,b,c,d))
else :
    print("{}-{}-{}-{}=7".format(a,b,c,d))
    
    

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string arg;

	while (1)
	{
		string tmp;

		getline(cin, tmp);
		arg += tmp;

		if (cin.eof()) { break; }
	}

	
	for (int i2(0), n2(arg.length()); i2 < n2; ++i2)
	{
		if('A' <= arg[i2] && arg[i2] <= 'Z') { arg[i2] = arg[i2] - 'A' + 'a'; } 
	}
		
	for (char i('a'); i <= ('z'); ++i)
	{
		int tmp(0);
		
		for (int i2(0), n2(arg.length()); i2 < n2; ++i2)
		{
			if (arg[i2] == i) { tmp++; }
		}
		
		cout << i << " : " << tmp << endl; 
	}
	
	return 0;
}

Measured memory_bytes: 3180
import sys

import numpy as np
from scipy.sparse.csgraph import dijkstra

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
C = np.array([list(map(int, input().split())) for _ in range(10)], dtype=int)
A = np.array([list(map(int, input().split())) for _ in range(H)], dtype=int)

mp = dijkstra(C, directed=True)[:, 1]
ans = 0
for n in range(10):
    ans += mp[n] * np.sum(A == n)
print(int(round(ans)))


Measured memory_bytes: 14416
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void Main() {
    string S;
    cin >> S;
    stack<int> v1;
    stack<pair<int, int>> v2;
    int area = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '\\') {
            v1.push(i);
        } else if (S[i] == '/' && v1.size() > 0) {
            int i_p = v1.top();
            v1.pop();
            int cur = i - i_p;
            area += cur;
            while (v2.size() > 0 && i_p < v2.top().first) {
                cur += v2.top().second;
                v2.pop();
            }
            v2.push({i_p, cur});
        }
    }
    vector<int> ans;
    while (v2.size()) {
        ans.push_back(v2.top().second);
        v2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << area << "\n";
    cout << ans.size();
    for (auto &e : ans) {
        cout << " " << e;
    }
    cout << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 3308
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A=list(map(int,input().split()))
    N=A[0]
    K=A[1]
    p=list(map(int,input().split()))
    p.sort()
    kingaku=0
    for i in range(K):
        kingaku+=p[i]
    print(kingaku)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cmath>
#include <deque>
#include <bitset>
#define ll long long
#define PI 3.1415926535897932384626433832795
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;
int N,M;

vector<int> path[222000];
bool vis[222000];

int main() {
	ios_base::sync_with_stdio(false);
	cin>>N>>M;
	FOR(i,0,M){
		int x,y;
		cin>>x>>y;
		path[x].push_back(y);
		path[y].push_back(x);
	}
	for (int u: path[1])
		vis[u] = 1;
	for (int i=1;i<N;i++){
		if (!vis[i]) continue;
		for (int u:path[i]){
			if (u == N) {
				cout<<"POSSIBLE"<<endl;
				return 0;
			}
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;

}

Measured memory_bytes: 12656
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
const int N = 1000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
ll arr[n+1];
rep(i,1,n+1)
cin>>arr[i];
ll mn=arr[1];
for(int i=1;i<=n;i++)
{
if(mn<arr[i])
arr[i]--;
//cout<<i<<endl;
if(arr[i]<mn)
{
	cout<<"No";

	return 0;
}
mn=arr[i];
}
cout<<"Yes";
}

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 5e3+10 , mod = 1e9+7;

int c[N] , p[N] , cyc[N];
ll s[N] , sm[N][N] , mx[N][N];

void go(int v , int num , ll sum , int st){
   if(v == st && num != 0){
      cyc[st] = num;
      s[st] = sum;
      return;
   }
   sm[st][num + 1] = sum + c[v];
   if(num == 0)
      mx[st][num + 1] = sm[st][num + 1];
   else
      mx[st][num + 1] = max(mx[st][num] , sm[st][num + 1]);
   go(p[v] , num + 1 , sum + c[v] , st);
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n , k;
   cin >> n >> k;
   for(int i = 0 ; i < n ; i++){
      cin >> p[i];
      p[i]--;
   }
   for(int i = 0 ; i < n ; i++)
      cin >> c[i];

   ll ans = -1ll * mod * mod;
   for(int i = 0 ; i < n ; i++){
      go(i , 0 , 0 , i);
      ll val = mx[i][min(k , cyc[i])];
      int rem = k % cyc[i];
      int m = k / cyc[i];
      if(rem == 0){
         m--;
         rem = cyc[i];
      }
      val = max(val , 1ll * m * s[i] + mx[i][rem]);
      ans = max(ans , val);
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 395160
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef long long ll;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define ALL(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

ll fact(ll x){
	if(x == 1) return (long long)1;
	else{
		return x * fact(x-1)%1000000007;
	}
}

int main(){
	ll n,m;
	ll out;
	cin >> n >> m;
	if(abs(n-m) >1) {
		cout << 0 << endl;
		return 0;
	}
	else if(n == m) {
		out = 2*fact(n)*fact(m)%1000000007;
	}
	else out = fact(n)*fact(m)%1000000007;
	cout << out << endl;

}

Measured memory_bytes: 1792
n = int(input())
h = list(map(int, input().split()))


diff = []
for i in range(n-1):
    d = h[i+1] - h[i]
    if d > 0:
        diff.append(1)
    else:
        diff.append(-1)

ans = -1
tmp = 0
for i in range(len(diff)):
    if diff[i] == 1:
        ans = max(tmp, ans)
        tmp = 0
    else:
        tmp += 1

ans = max(tmp, ans)
print(ans)


Measured memory_bytes: 64228
#include <stdio.h>

#define inf 600000

int h=0,a[10002][2],b[10002];

void mh(int i){//big <- small
  int l,r,big,t;

  l = i*2;
  r = i*2 + 1;

  if(l<=h && a[l][1]<a[i][1])big = l;
  else big = i;
  if(r<=h && a[r][1] < a[big][1])big = r;

  if(big!=i){
    t=b[a[i][0]];
    b[a[i][0]]=b[a[big][0]];
    b[a[big][0]]=t;

    t=a[i][0];
    a[i][0]=a[big][0];
    a[big][0]=t;
    
    t=a[i][1];
    a[i][1]=a[big][1];
    a[big][1]=t;
    
    mh(big);
  }
}

void in(int num,int key){
  int t,tt;
  h++;
  tt=h;
  b[num]=h;
  a[h][0]=num;
  a[h][1] = key;
  while(1<tt && a[tt/2][1]>a[tt][1]){
    t=b[a[tt][0]];
    b[a[tt][0]]=b[a[tt/2][0]];
    b[a[tt/2][0]]=t;

    t=a[tt][0];
    a[tt][0] = a[tt/2][0];
    a[tt/2][0] = t;
    
    t=a[tt][1];
    a[tt][1] = a[tt/2][1];
    a[tt/2][1] = t;
    
    tt = tt/2;
  }
  //b[num]=a[tt][0];
}

/*void delete(int i,int key){
  int j=1;

  printf("\n\n%d %d\n",i,key);
  while(1){
    printf("%d %d\n",j,a[j][1]);
    if(a[j][0]==i){
      break;
    }
    else{
      j=j*2;
    }

    if(a[j][1]<=key){
      j=j+1;
    }
  }
  
  a[j][0]=a[h][0];
  a[j][1]=a[h][1];
  h--;
  mh(j);
}*/

void delete2(int i){
  i=b[i];

  b[a[h][0]]=i;
  a[i][0]=a[h][0];
  a[i][1]=a[h][1];
  h--;
  mh(i);
}

int ex(void){
  int t;

  t=a[1][0];
  b[a[h][0]]=1;
  a[1][0] = a[h][0];
  a[1][1] = a[h][1];
  h--;
  mh(1);

  return t;
}
int v[10002][10002];
int main(){
  int i,j,n,m,d[10002],s[10002],t,tt;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    d[i]=inf;
    s[i]=0;
    for(j=0;j<n;j++){
      v[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&t,&m);
    for(j=0;j<m;j++){
      scanf("%d%d",&t,&tt);
      v[i][t]=tt;
    }
  }
  d[0]=0;
  in(0,0);
  while(h!=0){
    t=ex();
    s[t]=1;
    for(i=0;i<n;i++){
      if(v[t][i]!=-1 && s[i]==0){
	if(d[t] + v[t][i] < d[i]){
	  if(d[i]!=inf){
	    //delete2(i);
	  }
	  d[i] = d[t] +v[t][i];
	  in(i,d[i]);
	}
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}



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

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

    string ans = "";
    ans += S[0];

    for (int i = 1; i < S.length(); i++) {
        if (S[i] != S[i-1]) {
            ans += S[i];
        }
    }

    cout << ans.length() << endl;
    
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        Set<String> hina = new HashSet<>();
        for(int i = 0; i < N; i++) {
            hina.add(sc.next());
        }
        
        String ans = "Three";
        if( hina.size() == 4 ) {
            ans = "Four";
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 35672
n = int(input())
dp = [float("Inf")]*(n+1)
for i in range(n+1):
    if i < 6:dp[i] = i
    power = 1
    while i >= 6 ** power:
        dp[i] = min(dp[i],dp[i-6**power]+1)
        power += 1
    power = 1
    while i >= 9 ** power:
        dp[i] = min(dp[i],dp[i-9**power]+1)
        power += 1
print(dp[n])

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long n; cin >> n;
    vector<int> v, u, w;
    auto f = [&](int i) {
        if (v.empty()) return (1LL << i) - 1;
        return (1LL << i);
    };
    for (int i = 40; i >= 0; i--) {
        while (f(i) <= n) {
            n -= f(i);
            v.emplace_back(i);
        }
    }
    if (v.back() == 0) {
        v.pop_back();
        u.emplace_back(v[0]+1);
        u.emplace_back(v[0]+1);
    }
    for (int i = 0; i < v[0]; i++) {
        u.emplace_back(i+1);
    }
    for (int i = 0; i < v[0]; i++) {
        u.emplace_back(i+1);
    }
    int curr = 100;
    for (int i = 0; i < u.size(); i++) {
        w.emplace_back(u[i]);
        while (v.size() > 1 && w.back() == v.back()) {
            w.emplace_back(curr--);
            v.pop_back();
        }
    }
    while (curr < 100) w.emplace_back(++curr);
    
    cout << w.size() << "\n";
    for (int i = 0; i < w.size(); i++) {
        if (i) cout << " ";
        cout << w[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bitset>
using namespace std;
int n, s, sum;
bitset<2000001> v;
int main() {
	scanf("%d", &n);
	v[0] = 1;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &s);
		sum += s;
		v |= v << s;
	}
	for (int i = sum + 1 >> 1; i <= sum; i++) {
		if (v[i]) {
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
using namespace std;
int main(){   
   string s,t,u;
   int a,b;
   cin>>s>>t>>a>>b>>u;
   if(s==u){a--;}
   else{b--;}
   cout<<a<<" "<<b;
   return 0;
}

Measured memory_bytes: 256
mod = 10**9+7

n = int(input())
k = n.bit_length()

DP = [[0]*3 for i in range(k+1)]
DP[0][2] = 1
bit = [int(i) for i in bin(n)[2:]]
for i in range(k):
    DP[i+1][0] = 3*DP[i][0]
    if bit[i]:
        DP[i+1][1] += DP[i][1]
        DP[i+1][0] += 2*DP[i][1]
        DP[i+1][1] += DP[i][2]
        DP[i+1][2] += DP[i][2]
    else:
        DP[i+1][2] += DP[i][1]
        DP[i+1][1] += DP[i][1]
        DP[i+1][0] += DP[i][1]
        DP[i+1][2] += DP[i][2]

    for j in range(3):
        DP[i+1][j] %= mod

print(sum(DP[-1])%mod)

Measured memory_bytes: 38492
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

    int sol1 = 0, sol2 = 0;
    // if (2*c < a+b)
    // {
    //     sol1 += 2*c*min(x,y);
    //     if (x < y) sol1 += (y-x) * b;
    //     else sol1 += (x-y) * a;
    // }else
    // {
    //     sol2 += a*x + b*y;
    // }

    sol1 += 2*c*min(x,y);
        if (x < y) sol1 += (y-x) * b;
        else sol1 += (x-y) * a;

    sol2 = a*x + b*y;
    int sol3 = 2*c*max(x,y);

    cout << min(min(sol1,sol2),sol3) << endl;

    return 0;
}

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

int main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    int a, b;
    cin >> a >> b;
    string grid[a];
    for(int i = 0;i < a;i++)
        cin >> grid[i];
    for(int i = 0;i < a;i++)
        for(int j = 0;j < b;j++){
            if(grid[i][j] == '.')continue;
            if(i > 0 && grid[i - 1][j] == '#'
            || j > 0 && grid[i][j - 1] == '#'
            || j < b - 1 && grid[i][j + 1] == '#'
            || i < a - 1 && grid[i + 1][j] == '#'
            );else{
                cout << "No";
                return 0;
            }
        }
    cout << "Yes";
}


Measured memory_bytes: 256
# coding=utf-8
import math


def divide_segment(left, right):
    """divide segment

    Args:
        left: left edge coordinate
        right: right edge coordinate

    Returns:
        divided points
    """
    delta_x_quarter = (right[0] - left[0]) / 3.0
    delta_y_quarter = (right[1] - left[1]) / 3.0

    delta_x_quarter_rotated = (delta_x_quarter - math.sqrt(3) * delta_y_quarter) / 2.0
    delta_y_quarter_rotated = (math.sqrt(3) * delta_x_quarter + delta_y_quarter) / 2.0

    s = [left[0] + delta_x_quarter, left[1] + delta_y_quarter]
    t = [left[0] + delta_x_quarter * 2.0, left[1] + delta_y_quarter * 2.0]
    u = [s[0] + delta_x_quarter_rotated, s[1] + delta_y_quarter_rotated]

    return s, t, u


def make_coch_curve(depth, left, right):
    """make coch curve with depth iteration_number between point left, right
    each vertices positions are printed

    Args:
        depth: depth
        left: left edge point
        right: right edge point

    Returns:
        None
    """
    print("{0:2.8f} {1:2.8f}".format(left[0], left[1]))
    if depth == 0:
        print("{0:2.8f} {1:2.8f}".format(right[0], right[1]))
    else:
        make_coch_curve_recursively(depth-1, left, right)


def make_coch_curve_recursively(depth, left, right):
    """recursion part of coch curve

    Args:
        depth: depth
        left: left edge coordinate
        right: right edge coordinate

    Returns:
        None
    """
    # get coordinate of divided points
    s, t, u = divide_segment(left, right)

    if depth == 0:
        print("{0:2.8f} {1:2.8f}".format(s[0], s[1]))
        print("{0:2.8f} {1:2.8f}".format(u[0], u[1]))
        print("{0:2.8f} {1:2.8f}".format(t[0], t[1]))
        print("{0:2.8f} {1:2.8f}".format(right[0], right[1]))
    else:
        make_coch_curve_recursively(depth - 1, left, s)
        make_coch_curve_recursively(depth - 1, s, u)
        make_coch_curve_recursively(depth - 1, u, t)
        make_coch_curve_recursively(depth - 1, t, right)


def main():
    depth = int(input().strip())
    make_coch_curve(depth, left=[0.0, 0.0], right=[100.0, 0.0])


if __name__ == '__main__':
    main()

Measured memory_bytes: 7840
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	long long n, a = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		a = (a % (1000000000 + 7))*i;
	}
	cout << a % (1000000000 + 7) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(9**9)
n=int(input())
T=[[]for _ in"_"*(n+1)]
for _ in range(n-1):a,b=map(int,input().split());T[a]+=b,;T[b]+=a,
def d(v,p):
 r=0
 for s in T[v]:
  if s!=p:r^=d(s,v)+1
 return r
print("ABloibc e"[d(1,1)<1::2])

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

int dp[200005];

int main(void){
	int N;
	cin >> N;
	vector<int> P(N);
	for(int i=0;i<N;i++)cin >> P[i];
	int ans = 0;
	for(int i=0;i<N;i++){
		int p = P[i];
		dp[p] = dp[p-1] + 1;
		ans = max(ans,dp[p]);
	}
	cout << N - ans << endl;
}

Measured memory_bytes: 1792
w,h,n=map(int,input().split())
xya = [map(int, input().split()) for _ in range(n)]
x, y ,a= [list(i) for i in zip(*xya)]
p=[]
q=[]
t=[]
s=[]
for i in range(n):
    if a[i]==1:
        p.append(x[i])
    elif a[i]==2:
        q.append(x[i])
    elif a[i]==3:
        t.append(y[i])
    else:
        s.append(y[i])

l=max(p) if p else 0
r=min(q) if q else w
d=max(t) if t else 0
u=min(s) if s else h

if l>r or d>u:
    print(0)
else:
    print((r-l)*(u-d))


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; 
cin >> n; 
int a[1100]; 
for (int i = 0; i < n; i++){ 
cin >> a[i]; 
}
for (int i = 0; i < n-1; i++){ 
cout << a[n-1-i] << " "; 
}
cout << a[0] << endl; 
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,k;cin>>n>>k;vector<int>ls(n);
	for(int &x:ls)cin>>x;
	sort(ls.begin(),ls.end());
	int sm=0,u=0;
	while(k--){sm+=ls[u];u++;}
	cout<<sm;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll X, ll A) {
  cout << (X<A ? 0 : 10) << endl;
}

int main() {
  ll X;
  cin >> X;
  ll A;
  cin >> A;
  solve(X, A);
  return 0;
}


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

int main() {
  int a,b;
  string s;
  cin >> a >> b >> s;
  for(int i=0; i<a; i++) {
    if(s[i]=='-') {
      cout << "No" << endl;
      return 0;
    }
  }
  if(s[a]!='-') {
    cout << "No" << endl;
    return 0;
  }
  for(int i=0; i<a+b+1; i++) {
    if(s[a+1+i]=='-') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
def count(card)
  return 0 if card.inject(:+) % 3 != 0
  res = 0
  for i in 1..9 do
    if card[i] > 0 && card[i + 1] > 0 && card[i + 2] > 0
      new = card
      new[i] -= 1
      new[i + 1] -= 1
      new[i + 2] -= 1
      res = [res, 1 + count(new)].max
    end
    if card[i] >= 3
      new = card
      new[i] -= 3
      res = [res, 1 + count(new)].max
    end
  end
  res
end

T = gets.to_i
T.times do
  hand = Hash.new
  n = gets.split.map(&:to_i)
  c = gets.split
  for i in 0...9 do
    hand[c[i]] = Array.new(13, 0) unless hand.key?(c[i])
    hand[c[i]][n[i]] += 1
  end
  total = 0
  hand.each do |color, card|
    total += count(card)
  end
  puts total == 3 ? "1" : "0"
end

Measured memory_bytes: 6124
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<int>>lr(M, vector<int>(2));
	int Max = 0,Min = 1000000;
	for (int i = 0;i < M;++i) {
		cin >> lr[i][0] >> lr[i][1];
		Max = max(Max, lr[i][0]);
		Min = min(Min, lr[i][1]);
	}
	int cnt = 0;
	for (int i = 0;i < N;++i) {
		if (Max <= i + 1 && i + 1 <= Min) {
			++cnt;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    long dp[n+1][5002] = {};
    for (int i=0; i<n; i++)
        cin >> x[i], x[i] -= a;
    dp[0][50*n] = 1;
    for (int i=1; i<=n; i++)
        for (int j=0; j<=5000; j++) {
            dp[i][j] = dp[i-1][j];
            if (0<=j-x[i-1]&&j-x[i-1]<=100*n)
                dp[i][j] += dp[i-1][j-x[i-1]];
        }
    cout << dp[n][50*n]-1 << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Painting
            int H = int.Parse(Console.ReadLine());
            int W = int.Parse(Console.ReadLine());
            int N = int.Parse(Console.ReadLine());
            int edge;

            if (H > W)
            {
                edge = H;
            }
            else
            {
                edge = W;
            }

            if (N % edge == 0)
            {
                Console.WriteLine(N / edge);
            }
            else
            {
                Console.WriteLine(N / edge + 1);
            }
        }
    }
}

Measured memory_bytes: 11092
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    H, W = map(int, input().split())
    a = [input() for _ in range(H)]
    m = 10**9 + 7

    dp = [0] * W
    for i in range(H):
        for j in range(W):
            if i == j == 0:
                dp[j] = 1
                continue
            if a[i][j] == '.':
                if j > 0:
                    dp[j] = (dp[j] + dp[j-1]) % m
            else:
                dp[j] = 0
    print(dp[W-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 10272
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}



int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;

    cin >> s >> t;

    for(ll i = 0; i < s.length();i++){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;


    

    return 0;
}

Measured memory_bytes: 3052
/**
 * 
 */
//package AtCoder;
import java.util.*;
/**
 * @author Shivansh Singh
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int t,i,j,n,max=0;
		n=sc.nextInt();
		int [][]arr=new int[n][3];
		for (i=0;i<n;i++) {
			for (j=0;j<3;j++) {
				arr[i][j]=sc.nextInt();
			}
		}
		int [][]dp=new int[n][3];
		for (j=0;j<3;j++)
			dp[n-1][j]=arr[n-1][j];
		for (i=n-2;i>=0;i--) {
			for (j=2;j>=0;j--) {
				if(j==0) {
					dp[i][j]=arr[i][j]+(int)Math.max(dp[i+1][j+1],dp[i+1][j+2]);
				}
				else if(j==1) {
					dp[i][j]=arr[i][j]+(int)Math.max(dp[i+1][j+1],dp[i+1][j-1]);
				}
				else {
					dp[i][j]=arr[i][j]+(int)Math.max(dp[i+1][j-1],dp[i+1][j-2]);
				}
			}
		}
		for (j=0;j<3;j++) {
			if(dp[0][j]>max)
				max=dp[0][j];
		}
		System.out.println(max);
		sc.close();
	}

}


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

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

		if( n == 0 ) {
			break;
		}

		vector<int> s( n );
		double m = 0;

		for( auto& v: s ) {
			cin >> v;
			m += v;
		}

		m /= n;

		double a = 0;
		for( int i = 0; i < n; ++i ) {
			a += pow( s.at( i ) - m, 2 );
		}

		cout << fixed << setprecision( 10 );
		cout << sqrt( a / n ) << endl;
	}
}



Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a==1&&b==1)printf("Draw");
	else if(a==1)printf("Alice");
	else if(b==1)printf("Bob");
	else {
		if(a>b)printf("Alice");
		else if(a<b)printf("Bob");
		else printf("Draw");
	}
}

Measured memory_bytes: 256
/*input
<>>
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    string s;
    cin >> s;
    int n = (int)sz(s);
    vector<int>arr(n + 1, 0);
    arr[0] = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == '<')
            arr[i + 1] = arr[i] + 1;
    }
    for(int i = n - 1; i >= 0; i--)
    {
        if(s[i] == '>')
            arr[i] = max(arr[i], arr[i + 1] + 1);
    }
    ll sum = 0;
    for(int i = 0; i < n + 1; i++)
        sum += arr[i];
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 2844
package main

import (
	"fmt"
	"math"
)

func main() {
	var n float64
	fmt.Scan(&n)
	if int(n)%2 == 0 {
		fmt.Println(1.0 / 2)
	} else {
		fmt.Println(math.Ceil(n/2) / n)
	}
}


Measured memory_bytes: 512
from functools import reduce
from collections import deque
import math
    
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    H, W = (int(_) for _ in input().split())
    a=[]
    for h in range(H):
       a.append(list(int(_) for _ in input().split()))

    ans = []

    for h in range(H):
        for w in range(W-1):
            if a[h][w] % 2 ==1:
                ans.append((h+1,w+1,h+1,w+2))
                a[h][w] += -1
                a[h][w+1] += 1
                
    for h in range(H-1):
        if a[h][W-1] % 2 ==1:
            ans.append((h+1,W,h+2,W))
            a[h][W-1] += -1
            a[h+1][W-1] += 1
                
    print(len(ans))
    for i in ans:
        print(i[0],i[1],i[2],i[3])
    
if __name__ == '__main__':
    main()


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

#define INF 100000010;

int main(void){
  int N,X,Y;
  cin>>N>>X>>Y;
  X--;
  Y--;
  map<int,int> d;
  for(int i=0;i<N;i++){
    d[i]=0;
  }
  vector<int> G[N];
  for(int i=0;i<N;i++){
    G[i].clear();
  }
  G[0].push_back(1);
  for(int i=1;i<N-1;i++){
    G[i].push_back(i-1);
    G[i].push_back(i+1);
  }
  G[N-1].push_back(N-2);
  G[X].push_back(Y);
  G[Y].push_back(X);
  for(int start=0;start<N;start++){
    int dist[N];
    for(int i=0;i<N;i++){
      dist[i]=INF;
    }
    dist[start]=0;
    vector<int> next;
    vector<int> _next;
    next.push_back(start);
    while(next.empty()==false){
      _next.clear();
      for(auto iter=next.begin();iter!=next.end();iter++){
        auto neighbor=G[*iter];
        for(auto iter2=neighbor.begin();iter2!=neighbor.end();iter2++){
          if(dist[*iter2]>dist[*iter]+1){
            dist[*iter2]=dist[*iter]+1;
            _next.push_back(*iter2);
          }
        }
      }
      next=_next;
    }
    for(int i=0;i<N;i++){
      d[dist[i]]++;
    }
  }
  for(int i=1;i<N;i++){
    cout<<d[i]/2<<endl;
  }
  return 0;
}


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

class Dice{
	public:
	int face[6];
	
	Dice(){}
	void direction_side(){ rotate(1,2,4,3);}
	void direction_east(){ rotate(0,2,5,3);}
	void direction_north(){ rotate(0,4,5,1);}

	void rotate(int a,int b,int c,int d){
		int tmp = 0;

		tmp = face[a];
		face[a] = face[b];
		face[b] = face[c];
		face[c] = face[d];
		face[d] = tmp;
	}
};
void input(int face[6]){
		for(int i = 0;i < 6;i++){
				cin >> face[i];
		}
}
int check(int check1[6],int check2[6]){
		int num = 0;
		for(int i = 0;i < 6;i++){
				if(check1[i] == check2[i]){
						num++;
				}
		}
	return num;
}
bool judge_equal_dices(Dice dice1,Dice dice2){
	Dice dice_reset;
	int t_num = 0,f_num = 0;
	
	dice_reset = dice2;
	for(t_num = 0;t_num < 6;t_num++){
			dice2 = dice_reset;
				switch(t_num){
					case 0: break;
					case 1:
							dice2.direction_north();
							break;
					case 2:
							for(int i = 0;i < 3;i++){
									dice2.direction_east();
							}
							break;
					case 3:
							dice2.direction_east();
							break;
					case 4:
							for(int i = 0;i < 3;i++){
									dice2.direction_north();
							}
							break;
					case 5:
							for(int i = 0;i < 2;i++){
									dice2.direction_north();
							}
							break;
				}
			for(f_num = 0;f_num < 4;f_num++){
					 dice2.direction_side();
					if( check(dice1.face,dice2.face) == 6){
							return true;
					}

			}
	}			
	return false;
}

int main(){
	int n;
	cin >> n;
	Dice dice[n];
	
	for(int i = 0;i < n;i++){
		input(dice[i].face);
	}
	
	for(int i = 0;i < n-1;i++){
		for(int j = i + 1;j < n;j++){
			if(judge_equal_dices(dice[i],dice[j]) == true){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define upper_index(v,a) (int)distance(v.begin(), upper_bound((v).begin(),(v).end(),a))
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
typedef long long ll;
const ll INF=1LL<<63-1;
const ll MOD=1e9+7;

struct SegmentTree{
private:
    ll unit=0;
    ll op(ll a,ll b){return a+b;}
    int n;
    vector<ll> node;

public:
    // initialize
    SegmentTree(vector<ll> v){
        int sz=(int)v.size();
        n=1;while(n<sz) n*=2;
        node.resize(2*n-1,unit);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
    }

    void update(int x,int val){
        x+=n-1;
        node[x]+=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=op(node[2*x+1],node[2*x+2]);
        }
    }

    int query(int a,int b,int k=0,int l=0,int r=-1){
        if (r<0) r=n;
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        int vl = query(a,b,2*k+1,l,(l+r)/2);
        int vr = query(a,b,2*k+2,(l+r)/2,r);
        return op(vl,vr);
    }
};

// 区間加算・区間和クエリ
struct LazySegmentTree{
private:
    int n;
    vector<ll> node,lazy;
public:
    // initialize
    LazySegmentTree(vector<ll> v){
        int sz=(int)v.size();
        n=1;while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--) node[i]=node[2*i+1]+node[2*i+2];
    }

    void lazyEval(int k,int l,int r){
        if(lazy[k]!=0){
            node[k]+=lazy[k];
            // r-l==1であるとき、kはleafであるため子を参照してはいけない
            if(r-l>1){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
            lazy[k]=0;
        }
    }
    //　ノードkに適切な値を入れ、遅延情報を初期化する
    void update(int a,int b,ll x,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        // もともと入ってた遅延情報の処理
        lazyEval(k,l,r);
        if(b<=l || r<=a) return;
        if(a<=l && r<=b){
            lazy[k]+=(r-l)*x;
            lazyEval(k,l,r);
        }
        else{
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            // update内で遅延評価が必要なのは多分ここのため
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    ll query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return 0; 

        lazyEval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }
};

int main(){
    int N,Q;cin>>N>>Q;
    LazySegmentTree BIT(vector<ll>(N,0));
    rep(i,Q){
        int q;cin>>q;
        if(q==0){
            int s,t,x;cin>>s>>t>>x;--s;
            BIT.update(s,t,x);
        }else{
            int s,t;cin>>s>>t;--s;
            cout<<BIT.query(s,t)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7608
<?php
list($n, $m) = array_map("intval", explode(" ", trim(fgets(STDIN))));
$aArray = array_map("intval", explode(" ", trim(fgets(STDIN))));
foreach($aArray as $a){
    @$map[$a] ++;
}
for($i = 0; $i < $m; $i++){
    list($b, $c) = array_map("intval", explode(" ", trim(fgets(STDIN))));
    @$map[$c] += $b;
}
krsort($map);
$sum = 0;
foreach($map as $num => $count){
    for($i = 0; $i < $count; $i++){
        $n--;
        $sum+=$num;
        if($n == 0){
            echo $sum;
            exit;
        }
    }
}

Measured memory_bytes: 23540
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;

vector <vector<ll>> List(100005);
ll dist[100005] = {0};

ll dfs(ll node)
{
    if(dist[node] != -1)
        return dist[node];
    ll mx = 0;
    for(auto adj : List[node])
    {
        mx = max(1 + dfs(adj), mx);
    }
    return dist[node] = mx;
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N, M;
    cin >> N >> M;
    for(ll i = 0; i < M; i++)
    {
        ll v1, v2;
        cin >> v1 >> v2;
        List[v1].push_back(v2);
    }    
    ll max = 0;
    for(ll i = 1; i <= N; i++)
        dist[i] = -1;   

    for(ll i = 1; i <= N; i++)
    {
        if(dist[i] == -1)
            dfs(i);
        if(max < dist[i])
            max = dist[i];
    }

    cout << max;
    return 0;
}


Measured memory_bytes: 8576