akhauriyash/Code-Regression huggingface dataset:
n = int(input())
flowers = list(map(int,input().split()))
ans = 0
if n ==1:
    print(flowers[0])
    exit()
while any(flowers):
    count = 0
    for i in range(n):
        if i ==0:
            if flowers[i]!=0:
                count +=1
        else:
            if (flowers[i] > 0) and (flowers[i-1]==0):
                    count +=1
    ans +=count
    flowers = [x-1 if x>0 else 0 for x in flowers]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int T;
  while(cin >>T && T){
    int ans = 0, N; cin >>N;
    REP(i, N){
      int s, t; cin >>s >>t;
      ans += t - s;
    }
    if(ans >= T) cout <<"OK" <<endl;
    else cout <<T - ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int N,M;
int p[100005];
int par[100005];
int r[100005];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        r[i]=0;
    }
}

int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    
    if(r[x]<r[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(r[x]==r[y]) r[x]++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}

int main(){
    
    cin>>N>>M;
    init(N+1);
    
    for(int i=1;i<=N;i++){
        cin>>p[i];
    }
    
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        unite(x,y);
    }
    
    int ans=0;
    for(int i=1;i<=N;i++){
        if(same(i,p[i])){
            ans++;
        }
    }
    
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//long a = Long.parseLong(sc.next());
		String t = sc.next();
//		String buff="";
		//long b = Long.parseLong(sc.next());
		//int c = Integer.parseInt(sc.next());
		//int n = Integer.parseInt(sc.next());
		//long res=n;
		//int l = Integer.parseInt(sc.next());
		//int sum=0;
		String s = sc.next();
		//String t = sc.next();
		String w = sc.next();
		//int a = Integer.parseInt(sc.next());
		//String t = sc.next();

		if(t.substring(t.length()-1,t.length()).equals(s.substring(0,1))&&s.substring(s.length()-1,s.length()).equals(w.substring(0,1))) {//a、e、i、o、u
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		/*for(int i=0;i<t.length();i++) {
			if(t.substring(i,i+1).equals(",")) {
				buff+=" ";
			}else {
				buff+=t.substring(i, i+1);
			}
		}*/
		//System.out.println(t.substring(0,1).toUpperCase()+s.substring(0,1).toUpperCase()+w.substring(0,1).toUpperCase());
	}
}




Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	String s = sc.next();
    	sc.close();
    	s = s.replaceAll(".", "x");
    	System.out.println(s);
    }
}

Measured memory_bytes: 22996
IDENTIFICATION DIVISION.
      PROGRAM-ID. 129A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(100).
      01 P PIC 9(3).
      01 Q PIC 9(3).
      01 R PIC 9(3).
      
      01 ANS1 PIC 9(3).
      01 ANS2 PIC 9(3).
      01 ANS3 PIC 9(3).
      01 ANSS PIC ZZZ9.
 
      PROCEDURE DIVISION.
      ACCEPT INP.
      UNSTRING INP DELIMITED BY " "
      INTO P Q R.
      
      COMPUTE ANS1 = P + Q. 
      COMPUTE ANS2 = Q + R. 
      COMPUTE ANS3 = R + P.
      
      IF ANS1 < ANS2
      THEN
      	IF ANS1 < ANS3
      	THEN
      		MOVE ANS1 TO ANSS
       	ELSE
      		MOVE ANS3 TO ANSS
      	END-IF
      ELSE
      	IF ANS2 < ANS3
      	THEN
      		MOVE ANS2 TO ANSS
      	ELSE
      		MOVE ANS3 TO ANSS
      	END-IF
      END-IF.

      DISPLAY ANSS.
      
      STOP RUN.


Measured memory_bytes: 636
S = input()

n = len(S)
ans = "No"
if S[:n//2] == S[n//2+1:][::-1]:
    S1 = S[:(n-1)//2]
    n1 = len(S1)
    if S1[:n1//2] == S1[(n1+1)//2:][::-1]:
        S2 = S[(n+3)//2-1:]
        n2 = len(S2)
        if S2[:n2//2] == S2[(n2+1)//2:][::-1]:
            ans = "Yes"

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if (W >= x && H >= y && x >= r && y >= r && W >= (x + r) && H >= (y + r)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (long long i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

/**
 * 1. 探索する範囲を小さくする
 *     (A ~ Bの範囲)
 * 2. 数字の規則性はあるか
 *   A~Bの範囲
 *     Aが偶数 偶数、奇数、偶数、奇数。。。という並び
 *     Aが奇数 奇数、偶数、奇数、偶数。。。という並び
 *   割り切れるということ
 *     AがCで割り切れる、とはA%C==0であるということ
 *     これはAがCの倍数であるときに成り立つ
 *     　　CでAを割ると
 */

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

long long lcm(long long a, long long b)
{
    long long g = gcd(a, b);
    return a / g * b;
}

int main()
{
    long long A, B, C, D; cin >> A >> B >> C >> D;

    long long bc = B/C, bd = B/D;
    long long g = gcd(C, D);
    long long bu = B / ((C*D)/g);
    long long ac = (A-1)/C, ad = (A-1)/D;
    long long au = (A-1) / ((C*D)/g);

    long long l = B - bc - bd + bu;
    long long r = (A-1) - ac - ad + au;

    cout << l - r << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        Tree tree = new Tree();
        for (int i = 0; i < n; i++) {
            String line = in.readLine();
            String[] split = line.split(" ");
            if (split[0].equals("insert")) {
                tree.insert(Integer.parseInt(split[1]));
            } else {
                System.out.println(tree.print());
            }
        }
    }
}

class Tree {
    Node root;

    private class Node {
        Node parent;
        Node left;
        Node right;
        int data;

        public Node(int data) {
            this.data = data;
            parent = null;
            left = null;
            right = null;
        }

        boolean isLeaf() {
            return left == null && right == null;
        }

        String preorder() {
            if (isLeaf()) {
                return " " + data;
            } else if (left == null) {
                return " " + data + right.preorder();
            } else if (right == null) {
                return " " + data + left.preorder();
            } else {
                return " " + data + left.preorder() + right.preorder();
            }
        }

        String inorder() {
            if (isLeaf()) {
                return " " + data;
            } else if (left == null) {
                return " " + data + right.inorder();
            } else if (right == null) {
                return left.inorder() + " " + data;
            } else {
                return left.inorder() + " " + data + right.inorder();
            }
        }
    }

    public Tree() {
        root = null;
    }

    public void insert(int data) {
        Node y = null;
        Node x = root;
        Node z = new Node(data);
        while (x != null) {
            y = x;
            if (data < x.data) {
                x = x.left;
            } else {
                x = x.right;
            }
        }

        z.parent = y;

        if (y == null) {
            root = z;
        } else if (z.data < y.data) {
            y.left = z;
        } else {
            y.right = z;
        }
    }

    public String print() {
        return inorder() + "\n" + preorder();
    }

    public String preorder() {
        return root.preorder();
    }

    public String inorder() {
        return root.inorder();
    }
}



Measured memory_bytes: 410668
#include "bits/stdc++.h"
    using namespace std;
    #define MOD 1000000007
    //#define MOD 998244353
    const double EPS = 1e-9;
    #define INF (1LL<<60)
    #define D double
    #define fs first
    #define sc second
    #define int long long
    #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
    #define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
    #define REP(i,n)  FOR(i,0,(n))
    #define RREP(i,n) RFOR(i,0,(n))
    #define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
    #define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
    #define range(i,a,b) ((a)<=(i) && (i)<(b))
    #define debug(x)  cout << #x << " = " << (x) << endl;
    #define SP << " " << 
    typedef pair<int,int> P;
    typedef vector<int> vec;
    typedef vector<vector<int>> mat;
     
    signed main(){
      ios::sync_with_stdio(false);
      cin.tie(0);
      cout.precision(20);
     
      int n, k;
      cin >> n >> k;
      vec d(k);
      mat a(k);
      REP(i, k) {
        cin >> d[i];
        REP(j, d[i]){
          int t;
          cin >> t;
          t--;
          a[i].push_back(t);
        }
      }
     
      vec b(n, 0);
      REP(i, a.size()) REP(j, a[i].size()){
        b[a[i][j]]++;
      }
     
      int ans = 0;
      REP(i, n){
        if(b[i] == 0) ans++;
      }
     
      cout << ans << endl;
     
      return 0;
    }

Measured memory_bytes: 3672
import java.util.Scanner;

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

		boolean tadashii=false;
		for(int i=0; i<moto.length(); i++) {
			for(int j=0; j<moto.length(); j++) {
				if(answer.charAt(j)!=moto.charAt((i+j)%moto.length())){
					break;
				}
				if(j==moto.length()-1) {
					System.out.println("Yes");
					System.exit(0);
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int x = sc.NextInt();
        int a = sc.NextInt();
        Console.WriteLine(x < a ? 0 : 10);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)

    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092
import math
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = set([int(input()) for _ in range(M)])
    dp = [0] * (N + 1)
    dp[0] = 1
    if 1 not in A:
        dp[1] = 1
    mod = 10 ** 9 + 7
    for i in range(2, N + 1):
        if i in A:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % mod
    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 91324
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;

int main(void){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		ans+=a-1;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;


ll fac[100005], inv[100005], finv[100005];
const ll mod = 1e9 + 7;

void cominit(int n) {
    int i;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (i = 2; i < n + 2; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
    return;
}

ll com(int n, int r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return (fac[n] * finv[r]) % mod * finv[n - r] % mod;
}

int main(void) {
    int n, i, a[100003], an[100003] = {}, k, s1, s2;

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

    cominit(n);

    for (i = 1; i <= n; i++) {
        if (an[i] == 2) {
            k = i;
            break;
        }
    }

    s1 = s2 = -1;
    for (i = 0; i < n + 1; i++) {
        if (a[i] == k) {
            if (s1 == -1) s1 = i;
            else s2 = i;
        }
    }

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

    ll kans;
    for (i = 2; i <= n + 1; i++) {
        kans = com(n - 1, i);
        kans = (kans + com(n - 1, i - 1) * 2 + mod - com(n + s1 - s2, i - 1)) % mod;
        kans = (kans + com(n - 1, i - 2)) % mod;
        printf("%lld\n", kans);
    }

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;

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

  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  multiset<ll> s;

  for (ll i = 0; i < n; ++i) {
    ll now = a[i];
    auto itr = s.lower_bound(now);
    if (itr != s.begin()) s.erase(--itr);
    s.insert(now);
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 8712
import math
 
number = 123
 
def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            return 0
    print(target)
    return 1

X = int(input())
flag = True
while flag:
    res = trial_division(X)
    if res == 1:
        flag = False
    X = X + 1

Measured memory_bytes: 3060
//16, 03, 2019, 09:15:25 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int N = int(2e5 + 100);
ll dp[N];
ll carry[N];
ll match[N];
ll rr[N];
const ll mod = ll(1e9) + 7;
vector< ll > c;

ll MOD(ll x){
    if(x >= mod){
        return x - mod;
    }

    return x;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll last = -1LL;

    cin >> n;

    int idx = 1;

    for(int i = 1 ; i <= n ; i++){
        ll ci;

        cin >> ci;

        if(ci == last){
            continue;
        }

        last = ci;
        match[idx] = rr[ci];
        // cout << idx << " -> " << rr[ci] << endl; 
        rr[ci] = idx;

        c.push_back(ci);
        idx++;
    }

    dp[1] = 1LL;

    // cout << c.size() << endl;
    for(int i = 2LL ; i <= c.size() ; i++){
        dp[i] = MOD(dp[match[i]] + dp[i - 1]);
    }

    cout << dp[c.size()] << endl;

    return 0;
}

Measured memory_bytes: 8176
n = int(input())
l = list(map(int,input().split()))
counter = 0
for i in range(n-2):
	for k in range(n-2-i):
		for s in range(n-i-k-2):
			ak = k+i+1
			sa = k+i+s+2
			if l[i]+l[ak]>l[sa] and l[i]+l[sa]>l[ak] and l[sa]+l[ak]>l[i]:
				if l[i] != l[ak] and l[i] != l[sa] and l[ak] != l[sa]:
					counter += 1
print(counter)

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

int main(){

 int num,oturi,m = 0;

while(1){
 
cin>>num;

      if(num==0){
         break;
  }else{
    
  oturi=1000-num;

   
 
    m = oturi/500;
 
    m = m+oturi%500/100;
 
    m = m+oturi%500%100/50;
  
    m = m+oturi%500%100%50/10;
 
    m = m+oturi%500%100%50%10/5;

    m = m+oturi%500%100%50%10%5/1;

    num = 0;

     
   }
  cout<<m<<'\n';
  
}

return 0;
}

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

int a[10000000];
vector<int> vc;

void sieve()
{
    int i,j;
    a[1]=1;

    vc.push_back(2);

    for(i=4; i<=1000000; i+=2)a[i]=1;
    for(i=3; i<=1000000; i+=2)
    {
        if(a[i]==0)
        {
            for(j=3*i; j<=1000000; j=j+i*2)a[j]=1;
            vc.push_back(i);
        }
    }
}
int main()

{
    sieve();
    int i,j,k,l=0,n;
    scanf("%d",&n);
    printf("%d:",n);
    for(i=0;n!=1&&i<vc.size();i++)
    {
       for(;n%vc[i]==0;)
        {
            printf(" %d",vc[i]);
            n=n/vc[i];
            l++;

        }

    }
    if(l==0)printf(" %d",n);
    printf("\n");
    return 0;
}

Measured memory_bytes: 7272
# ABC062C - Chocolate Bar (ARC074C)
from itertools import accumulate


def divide_bar(A: int, B: int) -> int:
    # x: one of partial rectangles
    # y: another one -> (y1, y2), (y2, y3): divide to updown, left-right
    ret = set()
    area = A * B
    for i, x in enumerate(accumulate([A] * (B // 2)), 1):
        y = area - x
        y1 = y * (A // 2) // A
        y2 = y - y1
        y3 = y * ((B - i) // 2) // (B - i)
        y4 = y - y3
        ret |= {max(x, y1, y2) - min(x, y1, y2)}
        ret |= {max(x, y3, y4) - min(x, y3, y4)}
    return min(ret)


def main():
    H, W = tuple(map(int, input().rstrip().split()))
    ans = min(divide_bar(H, W), divide_bar(W, H))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9648
#!/usr/bin/env python3
import sys


def solve(N: int, T: "List[int]", M: int, P: "List[int]", X: "List[int]"):
    ans = []
    ttl = sum(T)
    for i in range(M):
        ans.append(ttl-T[P[i]-1]+X[i])

    for i in ans:
        print(i)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    X = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        X[i] = int(next(tokens))
    solve(N, T, M, P, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
const int N = 20;

int ball[N];

bool dfs(int n, int l, int r)
{
    if (n == 10)    return true;
    if (ball[n] < l && ball[n] < r) return false;
    if (ball[n] > l)
    {
        if(dfs(n+1, ball[n], r))   return true;
    }
    if (ball[n] > r)
    {
        if (dfs(n+1, l, ball[n]))    return true;
    }
    return false;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        for (int i = 0; i < 10; ++i)
            cin >> ball[i];
        bool flag = dfs(0 , 0, 0);
        if (flag)   cout << "YES" << endl;
        else    cout << "NO" << endl;
    }
    return 0;
}

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

int main(){
int N,M;
  cin>>N>>M;
  char A[N][N], B[M][M];
  for(int i=0; i<N; i++){
   for(int j=0; j<N; j++){
   cin>>A[i][j];}}
  for(int i=0; i<M; i++){
   for(int j=0; j<M; j++){ 
   cin>>B[i][j];}}
  
  for(int i=0; i+M<=N; i++){
   for(int j=0; j+M<=N; j++){
      bool ans=true;
       for(int x=0; x<M; x++){
        for(int y=0; y<M; y++){
         if(A[i+x][j+y]!=B[x][y]){ans=false;}
        }
       }
      if(ans){cout<<"Yes"; return 0;} 
   }
  }
  
  cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int r,c,sum=0,a,b;
  scanf("%d%d",&r,&c);
  int h[101][101] = {};
  for(a=1;a<=r;a++){
    for(b=1;b<=c;b++){
	scanf("%d",&h[a][b]);
	h[a][0]=h[a][0]+h[a][b];
    }
  }
  for(a=1;a<=r;a++){
    for(b=1;b<=c;b++){
	printf("%d ",h[a][b]);
	h[0][b]=h[0][b]+h[a][b];
    }
    printf("%d\n",h[a][0]);
    h[0][0]=h[0][0]+h[a][0];

  }
  for(b=1;b<=c;b++){
    printf("%d ",h[0][b]);
  }	
  printf("%d\n",h[0][0]);
  return 0;
}



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

#define ll long long
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int N;
    cin >> N;

    vector<int> d(N);
    REP(i, N) cin >> d[i];

    int total = 0;
    REP(i, N) {
        REPD(j, N) {
            if (i >= j) {
                continue;
            } else {
                total += d[i] * d[j];
            }
        }
    }

    print(total);
}

signed main() {
    solve();
}


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

int main(){
    array<int64_t, 3> a;
    int K;
    for(int i = 0; i < 3; ++i){
        cin >> a[i];
    }
    cin >> K;
    sort(a.begin(), a.end());
    int64_t sum = a[0] + a[1];
    while(K > 0){
        a[2] *= 2;
        --K;
    }
    cout << sum + a[2] << endl;
}

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

string alphabet="abcdefghijklmnopqrstuvwxyz";
const ll MOD = 1000000007;
int main(){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	map<char,int> mp;
	rep(i,s.size()){
		mp[s[i]]++;
	}
	ll ans = 1;
	rep(i,26){
		ans *= mp[alphabet[i]] + 1;
		ans %= MOD;
	}
	ans--;
	cout << ans % MOD << endl;
    return 0;
}



Measured memory_bytes: 512
def resolve():
    a,b,c = list(map(int, input().split()))
    k = int(input())

    # a < b < c
    cnt = 0

    while a >= b:
        b *= 2
        cnt += 1
    
    while b >= c:
        c *= 2
        cnt += 1
    
    if cnt <= k:
        print('Yes')
    else:
        print('No')

resolve()

Measured memory_bytes: 61704
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1000000
using namespace std;

string s1, s2;
int M, N;
vector< vector<int> > C;

int rec(int i, int j){
  int t=0;
  if (i == M)
	  return N - j;
  else if (j == N)
	  return M - i;
  else{
    if(C[i][j] < 0){
      t = (s1[i] == s2[j]) ? 0 : 1;
	  C[i][j] = min( t + rec(i+1, j+1), min(1 + rec(i+1, j), 1 + rec(i, j+1) ));
    }
    return C[i][j];
  }
}

int main(){
  cin >> s1 >> s2;
  M = s1.length(), N = s2.length();
  C.assign(M, vector<int>(N, -1));
  int X = rec(0, 0);
  cout << X << endl;
}



Measured memory_bytes: 7176
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, m; cin >> n >> m;
  vector<vector<int>> g(n);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> ans(n, -1), visited(n, 0);
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int u = q.front(); q.pop();
    if(visited[u] == 1) continue;
    visited[u] = 1;
    for(int v : g[u]){
      if(ans[v] == -1) ans[v] = u;
      if(!visited[v]) q.push(v);
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < n; i++){
    cout << ans[i]+1 << endl;
  }

  return 0;
}

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

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define _parr(a, n) for(int __i = 0; __i < (int )n; __i++) cout << a[__i] << ' '; cout << '\n'
#define fr(i, p, n) for(int i = (int )p; i < (int )n; i++)
#define frn(i, p, n) for(int i = (int )p; i <= (int )n; i++)
#define rev(i, n, p) for(int i = (int )n; i >= (int )p; i--)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).begin(), (c).end()
#define sci(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define prin(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define mp make_pair
#define F first
#define S second
#define pb push_back

typedef long long int LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef pair< int, int> ii;
typedef vector< int> vi;

const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 2e5 + 22;
const double eps = 1e-10;

int n, m;

void _solve() {
    cin >> n;
    cout << (1LL * n * (n - 1)) / 2;
}
int main() {
    fastio;
    //t_times
    _solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include"prettyprint.hpp"
typedef long long ll;
typedef double db;

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

void test() {
    ll n, mxw;
    cin >> n >> mxw;
    vector<pair<ll, ll>> v(n);
    ll sum = 0;
    for (ll i = 0; i < n; ++i) {
        ll l, k;
        cin >> l >> k;
        v[i] = {l, k};
        sum += k;
    }
    sort(v.begin(), v.end());
    // debug(arr(w, n));
    // debug(arr(v, n));
    ll dp[sum + 1] = {0};
    dp[v[0].second] = v[0].first;
    // debug(arr(dp, sum + 1));
    for (ll i = 1; i < n; ++i) {
        // debug(i);
        for (ll j = sum; j >= 1; --j) {
            if (dp[j]) {
                // debug(j);
                ll sum_v = j + v[i].second;
                ll sum_w = dp[j] + v[i].first;
                // debug(sum_v, sum_w);
                if (sum_w <= mxw) {
                    if (dp[sum_v] != 0) dp[sum_v] = min(sum_w, dp[sum_v]);
                    else dp[sum_v] = sum_w;
                }
            }
        }
        if (v[i].first <= mxw) dp[v[i].second] = v[i].first;
        // debug(arr(dp, sum + 1));
    }
    ll ans = v[0].second;
    for (ll i = sum; i >= 1; --i) {
        if (dp[i]) {
            ans = i;
            break;
        }
    }
    cout << ans << "\n";
}

int main() {
      fast_io();
      #ifdef HOME
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif
      cout << fixed << setprecision(15);
      int t = 1;
      // cin >> t;
      for (int i = 1; i <= t; ++i) {
          test();
      }
      #ifdef HOME
          cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
      #endif
      return 0;
}


Measured memory_bytes: 4332
N = int(input())
A = [int(i) for i in input().split()]

flag = 0
for elem in A:
    if elem%2 == 0:
        if elem%3 != 0 and elem%5 != 0:
            flag = 1
            break
        
if flag == 0:
    print("APPROVED")
else:
    print("DENIED")

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


void solve(){
    ll d,t,s;
    cin>>d>>t>>s;
    ll res = d/s;
    if(res <= t) cout<<"Yes";
    else cout<<"No";


}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}


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

bool search(int*, int, int);

int main()
{
	int s[100000], t, n, q, count = 0;

	cin >> n >> s[0];
	for (int i = 1; i < n; i++)
	{
		cin >> s[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> t;
		count += search(s, n, t);
	}

	cout << count << endl;

	return 0;
}

bool search(int* s, int n, int t)
{
	int right, left = 0, mid;
	right = n;
	while (left < right)
	{
		mid = (left + right) / 2;
		if (s[mid] == t)
			return true;
		else if (s[mid] < t)
			left = mid + 1;
		else
			right = mid;
	}
	return 0;
}


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

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}


int ans[200005];

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

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

    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
    }

    sort(a+1,a+n+1);
    sort(b+1,b+n+1,greater<>());
    vector<int>madar;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==b[i])
            madar.push_back(i);
    }
    int x=1;
    for(auto i:madar)
    {
        while(x<=n && (a[x]==a[i]||b[x]==b[i]))
        {
            x++;
        }
        if(x>n)
        {
            cout<<"No";
            return 0;
        }
        swap(b[x],b[i]);
        x++;
    }

    cout<<"Yes\n";
    for(int i=1;i<=n;i++)
            cout<<b[i]<<" ";
}

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

int main() {
	int n,tmp;
	vector<pair<int,int>> a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		a.push_back(make_pair(tmp,i));
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		cout << a.at(i).second+1;
		if (i != n - 1) {
			cout << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 4312
import math
k=int(input())
[a,b]=list(map(int, input().split()))
A=math.floor(a/k)
B=math.floor(b/k)
if A!=B:
  print("OK")
elif k==1:
  print("OK")
elif a%k==0 or b%k==0:
  print("OK")
else:
  print("NG")

Measured memory_bytes: 9124
#ABC126C-DiceAndCoin.py

from sys import stdin
import random

N,K = list(map(int, stdin.readline().split()))

result = 0

for n in range(N):
    n = n + 1
    x = 0
    while True:
        if 2 ** x * n >= K:
            break
        x += 1
    result += 1/N * 0.5 ** x

print(result)


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

#define ll long long
#define INF INT_MAX
#define mod 1000000007ll
#define forn(i,n) for(int i=0;i<n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define forba(i,b,a) for(int i=b;i>=a;i--)
#define debx(x) cout << #x << ": " << x << endl
#define debxy(x,y) cout << #x << ": " << x << ' ' << #y << ": " << y << endl
#define YESp cout << "YES" << endl
#define NOp cout << "NO" << endl
#define Yesp cout << "Yes" << endl
#define Nop cout << "No" << endl
#define write(a) cout << a << endl
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pq priority_queue

ll fast_exp(ll base, ll power){ll ans=1;while(power){if(power&1)ans=(ans*base)%mod;base=(base*base)%mod;power=power>>1;}return ans%mod;}
ll modInv(ll a,ll p){return fast_exp(a,p-2)%p;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b,b%a);}

pii moves[] = {{-1, 0}, {1, 0}, {0 ,-1}, {0, 1}};

/****** S ****** X ****** T ****** Y ****** A ****** M ******/


int main() {
    int t = 1;
    while(t--) {
        int l, r, d;
        cin >> l >> r >> d;
        int a = l/d, b = r/d;
        if(l%d == 0) cout << b-a+1 << endl;
        else cout << b-a << endl;
    }
}

Measured memory_bytes: 3564
#include <iostream>
#include<vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main(void)
{
	int A, B, C;
	cin >> A >> B>>C;

	int ans = C - (A - B);
	if (ans <0 )
	{
		ans = 0;
	}
		cout << ans << endl;
	
}

Measured memory_bytes: 256
#include<stdio.h> 
const int maxn=1e5+6;
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int x=1,cnt=0;
	for(int j=1;j<=n;j++)
	{
		x=a[x];
		cnt++;
		if(x==2)break;
	}
	if(x==2)printf("%d\n",cnt);
	else printf("-1\n");
	return 0;
}

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

using namespace std;

typedef long long lint;
const lint N = 330, INF = 1e17+7;

lint n, m, l, dist[N][N], fuel[N][N], ans[N][N];


int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif
	scanf("%lld %lld %lld", &n, &m, &l);

	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			if (i==j)
				continue;
			dist[i][j] = INF;
			fuel[i][j] = INF;
		}
	}

	for (lint i = 0; i < m; i++){
		lint a, b, c;
		scanf("%lld %lld %lld", &a, &b, &c);
		dist[a][b] = dist[b][a] = c;
	}


	for (int k = 1; k <= n; k++){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				if (i == j)
					continue;
				if (dist[i][k] + dist[k][j] < dist[i][j]){
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (i == j)
				continue;
			if (dist[i][j] <= l)
				fuel[i][j] = 1;
		}
	}

	for (int k = 1; k <= n; k++){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				if (fuel[i][k] + fuel[k][j] < fuel[i][j])
					fuel[i][j] = fuel[i][k] + fuel[k][j];
			}
		}

	}

	lint q;

	scanf("%lld", &q);

	while (q--){
		lint s, t;
		scanf("%lld %lld", &s, &t);
		
		if (fuel[s][t] < INF)
			printf("%lld\n", fuel[s][t] - 1);
		else
			printf("-1\n");

	}

	return 0;
}

Measured memory_bytes: 2176
fun main(arr:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    setDic(n)
    val brokenStepList = (1..m).map { readLine()!!.toInt() }.toMutableList()
    brokenStepList.add(n+1)
    var current = 0
    var ans = 1L
    for(broken in brokenStepList) {
        if(current >= broken) {
            println(0)
            return
        }
        val tmp = broken - current - 1
        if(tmp > 0) {
            ans *= dic[tmp]
            ans %= md
        }
        current = broken + 1
    }
    println(ans)
}

val dic = mutableListOf<Long>()
val md = 1000000000 + 7
fun setDic(num:Int) {
    dic.add(0)
    dic.add(1)
    dic.add(2)
    (3..num+1).forEach { dic.add((dic[it-1] + dic[it-2])%md) }
}

Measured memory_bytes: 50308
#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;

vector<int> divisor(int n){
	vector<int> res; res.clear();
	for (int i = 1; i * i <= n; ++i){
		if (n % i == 0){
			res.push_back(i);
			if (i * i < n){
				res.push_back(n / i);
			} // end if
		} // end if
	} // end for

	sort(ALL(res));

	return res;
}

int correct(int N, int M){
	vector<int> d = divisor(M);
	int res = 0;
	rep (i, (int)d.size()){
		if (d[i] <= M / N){
			res = d[i];
		} // end if
	} // end rep
	return res;
}

int wrong(int N, int M){
	vector<int> d = divisor(M / N);
	int res = 0;
	rep (i, (int)d.size()){
		if (M % d[i] == 0){
			res = d[i];
		} // end if
	} // end rep
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M; cin >> N >> M;

	int res = correct(N,M);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = list(input())
t = list(input())
le = len(s)
for i in range(le):
    if t == (s[le-i:]+s[:le-i]):
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 10308
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
	int main() {
		int a, b, c;
		std::cin >> a >> b >> c;
		std::cout << (a - c) / (b + c) << std::endl;
		return 0;
	}

Measured memory_bytes: 256
n = int(input())
s = "abcdefghij"
a = [[] for i in range(10)]
a[0] = [[0]]
def add_word(n):
    temp = a[n-1]
    for i in range(len(temp)):
        for j in range(len(set(temp[i])) + 1):
            a[n].append(temp[i] + [j])
for i in range(1,n):
    add_word(i)

for i in a[n-1]:
    ans = ""
    for j in i:
        ans += s[j]
    print(ans)

Measured memory_bytes: 27460
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<ll> G[201];
bool can=true;
ll col[201];
bool used[201]={};
void paint(ll v,ll val){
  if(col[v]!=-1){
    if(col[v]!=val){
      can=false;
    }
    return;
  }
  col[v] = val;
  val = (val+1)%2;
  for(auto nv:G[v]){
    paint(nv,val);
  }
}
signed main(){
  ll n,ans=0;
  ll d[201][201];
  cin >> n;
  fill(col,col+201,-1);
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
    for(int j=0;j<n;j++){
      if(s[i][j]=='1'){
        G[i].push_back(j);
        d[i][j] = 1;
      }else{
        d[i][j] = INF;
      }
      if(i==j){
        d[i][j] = 0;
      }
    }
  }
  paint(0,0);
  if(!can){
    cout <<"-1\n";
    return 0;
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(d[i][j]<INF){
        ans = max(ans,d[i][j]);
      }
    }
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 1024
def tree_height(T, w):
    N = len(T)
    # Consider T to be rooted at r = 0
    downward = [0] * N # the height of the subtree rooted at each v
    upward = [-1] * N # the height of the subtree which contains the root r and is rooted at each v
    height = [-1] * N
    def dfs1(r):
        nonlocal downward
        stack = [(r, -1, 0)] # (vertex, parent, status)
        while stack:
            v, p, st = stack.pop()
            if st == 0: # visited v for the first time
                n_children = 0
                for u in T[v]:
                    if u == p: continue
                    if n_children == 0:
                        stack += [(v, p, 2), (u, v, 0)]
                        n_children += 1
                    else:
                        stack += [(v, p, 1), (u, v, 0)]
                        n_children += 1
                if n_children == 0: # v is a leaf
                    if p != -1:
                        downward[p] = max(downward[p], downward[v] + w[p][v])
            elif st == 1: # now searching
                continue
            else: # search finished
                if p != -1:
                    downward[p] = max(downward[p], downward[v] + w[p][v])
    
    def dfs2(r):
        nonlocal upward, height
        stack = [(r, -1, 0)] # (vertex, parent, status)
        while stack:
            v, p, st = stack.pop()
            if p == -1:
                upward[v] = 0
                height[v] = max(upward[v], downward[v])
            if st == 0: # visited v for the first time
                max1, max2 = sorted([0, -1] + [downward[child] + w[child][v] for child in T[v] if child != p], reverse=True)[:2]
                n_children = 0
                for u in T[v]:
                    if u == p: continue
                    temp = max1
                    if downward[u] + w[u][v] == max1: temp = max2
                    if n_children == 0:
                        stack += [(v, p, 2), (u, v, 0)]
                        upward[u] = max(upward[v], temp) + w[u][v]
                        height[u] = max(upward[u], downward[u])
                        n_children += 1
                    else:
                        stack += [(v, p, 1), (u, v, 0)]
                        upward[u] = max(upward[v], temp) + w[u][v]
                        height[u] = max(upward[u], downward[u])
                        n_children += 1
                if n_children == 0:
                    continue
            elif st == 1: # now searching
                continue
            else: # search finished
                continue
    dfs1(0)
    dfs2(0)
    return height
    
N = int(input())
E = [[] for _ in range(N)]
weight = [{} for _ in range(N)]
for _ in range(N-1):
    s, t, w = map(int, input().split())
    E[s].append(t); E[t].append(s)
    weight[s].setdefault(t, w); weight[t].setdefault(s, w)
height = tree_height(E, weight)
print(*height, sep='\n')


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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<pii>> PY(N);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    PY[--p].push_back(make_pair(y, i));
  }
  vector<pii> res(M);
  for (int i = 0; i < N; i++) {
    if (PY[i].empty()) continue;
    sort(PY[i].begin(), PY[i].end());
    for (int j = 0; j < PY[i].size(); j++)
      res[PY[i][j].second] = make_pair(i, j + 1);
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << res[i].first + 1;
    cout << setfill('0') << right << setw(6) << res[i].second;
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 7808
#include<stdio.h>
int main()
{
   double w;
   double h;
   double x;
   double y;
   double s;
    while(~scanf("%lf%lf%lf%lf",&w,&h,&x,&y)){
    	printf("%lf\n",s=w*h/2);
    	if(w/2==x&&h/2==y){
    		printf("1\n");
		}
		else{
			printf("0\n");
		}
	
}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };



ll n;
ll dist_1[305][305];
ll dist_2[305][305];
ll mincost[305];
bool used[305];


int main() {
	cin >> n;
	ll sum = 0;
	rep(i, 0, n)rep(j, 0, n) {
		ll x;
		cin >> x;
		dist_1[i][j] = x;
		dist_2[i][j] = x;
		if (i > j)sum += x;
	}

	rep(k, 0, n)rep(i, 0, n)rep(j, 0, n) {
		dist_1[i][j] = min(dist_1[i][j], dist_1[i][k] + dist_1[k][j]);
	}

	bool ok = 1;
	rep(i, 0, n)rep(j, 0, n) {
		if (dist_1[i][j] != dist_2[i][j])ok = 0;
	}

	if (!ok) {
		cout << "-1" << endl;
		exit(0);
	}

	rep(i, 0, n)rep(j, 0, n) {
		bool fl = 0;
		rep(k, 0, n) {
			if (i < j && k != i && k != j) {
				if (dist_1[i][j] >= dist_1[i][k] + dist_1[k][j] && fl == 0) {
					sum -= dist_1[i][j];
					fl = 1;
				}
			}
		}
	}

	cout << sum << endl;


	return 0;
}

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

#define reps(i,a,b) for(int i=a; i<b; i++)
#define rep(i,n) reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int main(){
  int N;
  ll A,B,ans=0;
  cin >> N >> A >> B;
  ll X[100010];
  rep(i,N){
    cin >> X[i];
  }

  rep(i,N-1){
    ans += min((X[i+1]-X[i])*A,B);
  }

  cout << ans << endl;
}

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

#define ll long long

int tc, n;

void solve(int kk)
{
   ll a, b, c, d;
   cin >> a >> b >> c >> d;
   ll mm = max({a*c, a*d, b*c, b*d});
   cout << mm << "\n";

}

int main(){
//   #ifndef ONLINE_JUDGE
//freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
//freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
//#endif
	ios::sync_with_stdio(0), cin.tie(0);
	int t=1;
    //cin >> t;
    while(++tc<=t)
        solve(tc);
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

int main(){
 int x;
 cin >> x;
 cout << x*x*x << endl;
}

Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int f[3][3];
int main()
{
  scanf("%d%d%d",&f[0][0],&f[0][1],&f[1][1]);
  for(int i=0;;i++)
  {
    f[0][2]=i-f[0][0]-f[0][1];
    f[2][0]=i-f[0][2]-f[1][1];
    f[2][1]=i-f[0][1]-f[1][1];
    f[2][2]=i-f[0][0]-f[1][1];
    f[1][0]=i-f[0][0]-f[2][0];
    f[1][2]=i-f[0][2]-f[2][2];
    if(f[0][0]+f[0][1]+f[0][2]==i&&f[1][0]+f[1][1]+f[1][2]==i&&f[2][0]+f[2][1]+f[2][2]==i&&f[0][0]+f[1][0]+f[2][0]==i&&f[0][1]+f[1][1]+f[2][1]==i&&f[0][2]+f[1][2]+f[2][2]==i&&f[0][0]+f[1][1]+f[2][2]==i&&f[0][2]+f[1][1]+f[2][0]==i)
    {
      printf("%d %d %d\n%d %d %d\n%d %d %d\n",f[0][0],f[0][1],f[0][2],f[1][0],f[1][1],f[1][2],f[2][0],f[2][1],f[2][2]);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto DP1 = new int[](10^^6+1);
    auto DP2 = new int[](10^^6+1);

    foreach (x; 1..10^^6+1) {
        auto r = int.max/3, s = int.max/3;
        foreach (n; 1..181) {
            auto d = n*(n+1)*(n+2)/6;

            if (x-d >= 0) r = min(r, DP1[x-d] + 1);
            if (d%2 == 1 && x-d >= 0) s = min(s, DP2[x-d] + 1);
        }
        DP1[x] = r;
        DP2[x] = s;
    }

    for (;;) {
        auto N = readln.chomp.to!int;
        if (N == 0) return;

        writefln("%d %d", DP1[N], DP2[N]);
    }
}


Measured memory_bytes: 10028
w,h,n=map(int, input().split()) #初期値
lx=0
ly=0
rx=w
ry=h

for i in range(n):
   x,y,a=map(int, input().split())
   
   if a==1:
       if lx<x:
           lx=x
   elif a==2:
       if rx>x:
           rx=x
           
   elif a==3:
       if ly<y:
           ly=y
   
   else:
       if ry>y:
           ry=y
# 出力
print(max(rx-lx,0)*max(ry-ly,0))
        

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	
	string s;
	cin >> s;
	
	if(s.size() == a + b + 1)
	{
		if(s[a] == '-')
		{
			bool flag = true;
			for(int i = 0; i < s.size(); i++)
			{
				if(i == a)
				{
					continue;
				}
				
				if(s[i] < '0' || s[i] > '9')
				{
					flag = false;
				}
			}
			
			if(flag == true)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
}

Measured memory_bytes: 256