akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextLong();
            var op = cin.next();
            var b = cin.nextLong();
            Console.WriteLine(op=="+"?a+b:a-b);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11220
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        print("Yes");
    }else{
        print("No");
    }
    

}

Measured memory_bytes: 256
class Tree
  attr_accessor(:next, :param)

  def initialize()
    @next = []
    @param = 0
  end

  def next()
    @next
  end

  def param()
    @param
  end

  def setnext(x)
    @next.push(x)
  end

  def plus(x)
    @param += x
  end

end

n,q = gets.chomp.split(" ").map(&:to_i)
tree = Array.new(n).map{Tree.new}
(n-1).times do |i|
  a,b = gets.chomp.split(" ").map(&:to_i)
  tree[a-1].setnext(b-1)
  tree[b-1].setnext(a-1)
end
q.times do |i|
  p,x = gets.chomp.split(" ").map(&:to_i)
  tree[p-1].plus(x)
end

visited = Array.new(n,0)
queue1 = [0]
while !queue1.empty?
  v1 = queue1[0]
  queue1.shift
  visited[v1] = 1
  tree[v1].next.each do |x|
    queue1.push(x) if visited[x] == 0
  end
  queue2 = tree[v1].next
  param = tree[v1].param
  while !queue2.empty?
    v2 = queue2[0]
    queue2.shift
    tree[v2].plus(param) if visited[v2] == 0
  end
end

n.times do |i|
  print "#{tree[i].param()} "
end

Measured memory_bytes: 51576
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val l = sc.nextLong
    var r = sc.nextLong
    r = math.min(r, l + 2019 * 2)

    var ans = 2018L
    for (i <- l to r) {
      for (j <- i + 1 to r) {
        val x = i * j % 2019L
        ans = math.min(ans, x)
      }
    }
    println(ans)
  }
}


Measured memory_bytes: 77896
#include<stdio.h>
int main(){
  int N,i,flag=1,temp,num=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  /*bubble sort*/
  while(flag){
    flag=0;
    for(i=N-1;i>=1;i--){
      if(A[i]<A[i-1]){
	temp=A[i];
	A[i]=A[i-1];
	A[i-1]=temp;
	flag=1;
	num++;
      }
    }
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i<N-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",num);
  return 0;
}



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

int main()
{
    int a, b;
    cin >> a >> b;
    int count=0;
    for (int i = a; i <= b; i++)
    {
        string s = to_string(i);
        if (s.at(0) == s.at(4) && s.at(1) == s.at(3))
        {
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String[][] array = new String[8][8];
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		int saite = q-k+1;
		//String[] array = new String[n];
		Integer[] count = new Integer[n];
		for(int i=0;n>i;i++) {
			count[i]=0;
		}
		if(saite<=0) {
			for(int i=0;q>i;i++) {
				int a = sc.nextInt();
				count[a-1]++;
			}
			for(int i=0;n>i;i++) {
				System.out.println("Yes");
			}
		}

		else {
			for(int i=0;q>i;i++) {
				int a = sc.nextInt();
				count[a-1]++;
			}
			for(int i=0;n>i;i++) {
				if(count[i]>=saite)
					System.out.println("Yes");
				else {
					System.out.println("No");
				}
			}
		}
	}

}

Measured memory_bytes: 80908
def parseSpaceDivideIntArgs(arg):
    tmpArr = arg.split()
    ret = []
    for s in tmpArr:
        ret.append(int(s))
    return ret


def getArr2SpaceDivideStr(arg):
    ret = ""
    isFirst = True
    for s in arg:
        if not isFirst:
            ret += ' '
        else:
            isFirst = False
        ret += str(s)
    return ret


instr = input()
# instr = "5 4 2 4 1"

instrSpl = parseSpaceDivideIntArgs(instr)
W = instrSpl[0]
H = instrSpl[1]
x = instrSpl[2]
y = instrSpl[3]
r = instrSpl[4]

xcod1 = x - r >= 0
xcod2 = x + r <= W
ycod1 = y - r >= 0
ycod2 = y + r <= H

if xcod1 and xcod2 and ycod1 and ycod2:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5600
#include <algorithm>
#include <bitset>
// #include <boost/algorithm/string/replace.hpp>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, j, n) for (int i = j; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define LIST(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cout << i << ": " << a[i] << endl;
#define PP(label, obj) cout << "[" << label << "] " << obj << endl;

int main() {
  int K, X;
  IN(K >> X);

  FOR(i, X - K + 1, X + K) {
    cout << i << ' ';
  }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();
    println!("ABC{}", n);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>

using namespace std;

int main() {
  int sum = 0;
  string n;

  cin >> n;

  for (int i = 0; i < n.length(); ++i) {
    sum += (n[i] - '0');
    sum %= 9;
  }

  if (sum) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

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

int64_t Q=1000000007;
vector<int64_t> q(200005,1);
vector<int64_t> r(200001,1);

int64_t si(int64_t x,int64_t y){
  int64_t A=x,B=y,C=1;//A、Bを入れる
      C=(q.at(B)*q.at(A-B))%Q;
      C=(C*r.at(A))%Q;
  return C;
}

int main(){
  for(int i=1;i<200005;i++){
    int64_t N=Q-2; //ここから
       int64_t a=1,b=0,c=1;
       while(N>0){
         a*=2;
         if(N%a!=0){
           N-=a/2;
           int64_t d=i;
           for(int j=0;j<b;j++){
            d=d*d;
             d=d%Q;
          }
           c=c*d;
          c=c%Q;
         }
        b++;
      } //ここまで
    q.at(i)=(c*q.at(i-1))%Q;
  }
  for(int i=1;i<=200000;i++){
    r.at(i)=(i*r.at(i-1))%Q;
  }
  int64_t H,W,A,B,Z=0;
  cin>>H>>W>>A>>B;
  for(int i=0;i<H-A;i++){
    Z+=(si(B-1+i,B-1)*si(H-1-i+W-B-1,W-B-1))%Q;
    Z%=Q;
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 6248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

bool check(int mid){
  return false;
}

ll serch(ll ok,ll ng) {
	while (abs(ok-ng) > 1) {
		int mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
  string s,t,u;
  cin>>s>>t;
  u=t+s;
  cout<<u<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n, x, i, j, k;
  while( 1 ) {
    scanf("%d%d", &n, &x);
    if(!n && !x) break;
    int ans = 0;
    for(i = 1; i <= n; ++i) for(j = i + 1; j <= n; ++j) for(k = j + 1; k <= n; ++k) if(i + j + k == x) ++ans;
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 2728
package main

import (
  "fmt"
  "strconv"
)

func main() {
  var s string
  fmt.Scan(&s)
  
  n1, _ := strconv.Atoi(s[0:2])
  n2, _ := strconv.Atoi(s[2:])
  
  fmt.Println(ret(n1,n2))
}
      
func ret(n1, n2 int) string {
  if n1 == 0 {
    switch {
    case n2 == 0:
      return "NA"
    case 1 <= n2 && n2 <= 12:
      return "YYMM"
    case 13 <= n2:
      return "NA"
    }
  }
  if 1 <= n1 && n1 <= 12 {
    switch {
    case n2 == 0:
      return "MMYY"
    case 1 <= n2 && n2 <= 12:
      return "AMBIGUOUS"
    case 13 <= n2:
      return "MMYY"
    }
  }
  if 13 <= n1 {
    switch {
    case n2 == 0:
      return "NA"
   	case 1 <= n2 && n2 <= 12:
      return "YYMM"
    case 13 <= n2:
      return "NA"
    }
  }
  return "NA"
}

Measured memory_bytes: 512
A, B, M = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
M_list = []
for _ in range(M):
  M_list.append(list(map(int, input().split())))

Min_1 = min(A_list) + min(B_list)
Min_2 = []
for m in M_list:
  Min_2.append(A_list[m[0] - 1] + B_list[m[1] - 1] - m[2])
if Min_1 < min(Min_2):
  print(Min_1)
else:
  print(min(Min_2))

Measured memory_bytes: 42408
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
    int n,i,x=0,M=0;
    scanf("%d",&n);
    int num[n],color[9]= {0,0,0,0,0,0,0,0,0};
    for(i = 0; i < n; i++)
        scanf("%d",&num[i]);
    sort(num,num+n);
    for(i = 0; i < n; i++)
    {
        if(num[i]>=1&&num[i]<400)
            color[0]++;
        if(num[i]>=400&&num[i]<800) color[1]++;
        if(num[i]>=800&&num[i]<1200) color[2]++;
        if(num[i]>=1200&&num[i]<1600) color[3]++;
        if(num[i]>=1600&&num[i]<2000) color[4]++;
        if(num[i]>=2000&&num[i]<2400) color[5]++;
        if(num[i]>=2400&&num[i]<2800) color[6]++;
        if(num[i]>=2800&&num[i]<3200) color[7]++;
        if(num[i]>=3200) x++;
    }
    for(i = 0; i < 8; i++)
        if(color[i]!=0)
            M++;
     if(M==0)
            cout<<1<<' '<<x<<endl;
    else
            cout<<M<<' '<<M+x<<endl;
    return 0;
}


Measured memory_bytes: 256
s = str(input())
a = ["+","-"]
for i in a:
    for j in a:
        for k in a:
            if eval(s[0]+i+s[1]+j+s[2]+k+s[3]) == 7:
                print(s[0]+i+s[1]+j+s[2]+k+s[3]+"=7")
                exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int cnt=0;
  int key=1;
  rep(i,n){
    if(a[i]!=key){
      cnt++;
      continue;
    }
    if(a[i]==key){
      key++;
      continue;
    }
  }
  if(key==1){
    cout<<-1<<endl;
    return 0;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 4024
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

int n;
int a[100001],b[100001];

int main(){ int x;
	scanf("%d",&n);
	F(i,1,n) a[i]=30000*i;
	F(i,1,n) b[i]=30000*(n-i+1);
	F(i,1,n) scanf("%d",&x), b[x]+=i;
	F(i,1,n) printf("%d ",a[i]); puts("");
	F(i,1,n) printf("%d ",b[i]); puts("");
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
inline ll abs(ll a){
	return a>0?a:-a;
}
inline ll boom(ll x,ll y){
	return x==y?x:abs(x-y);
}
queue<ll> q;
ll tmp,tmp1,tmp2,n;
int main (){
	scanf("%lld",&n);
	for(int i=1;i<=(1<<n);i++) {
		scanf("%lld",&tmp);
		q.push(tmp);
	}
	tmp1=q.front() ;
	q.pop() ;
	while(q.empty() ==0){
		tmp2=q.front() ;
		q.pop();
		q.push(boom(tmp1,tmp2));
		tmp1=q.front() ;
		q.pop() ;
	}
	printf("%lld",tmp1);
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a*b>c*d){
    cout << a*b;
  }else{
    cout << c*d;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] vO = new int[100001];
		int[] vE = new int[100001];
		int maxO=0,maxE=0,maxNumO=0,maxNumE=0;
		for( int i=1; i<=N/2; i++ ){
			vO[sc.nextInt()]++;
			vE[sc.nextInt()]++;
		}
		for( int i=1; i<=100000; i++ ){
			if( vO[i]>maxO ){
				maxO = vO[i];
				maxNumO = i;
			}
			if( vE[i]>maxE ){
				maxE = vE[i];
				maxNumE = i;
			}
		}
		Arrays.sort(vO);
		Arrays.sort(vE);
		int ans = 0;
		if( maxNumO!=maxNumE ){
			ans = N - vO[100000] - vE[100000];
		}
		if( maxNumO==maxNumE ){
			int a = N - vO[100000] - vE[99999];
			int b = N - vE[100000] - vO[99999];
			ans = Math.min(a,b);          
		} 
		System.out.println(ans);     
	}
}


Measured memory_bytes: 60680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll res = 0;
    res += 60 * (h2 - h1);
    res += m2 - m1;
    res -= k;
    cout << res << endl;
}


Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	S := sc.nextRuneSlice()
	T := sc.nextRuneSlice()
	if len(S) < len(T) {
		fmt.Println("UNRESTORABLE")
		return
	}
	diff := len(S) - len(T)
	strings := []string{}
	for i := 0; i <= diff; i++ {
		matched := true
		for j := 0; j < len(T); j++ {
			if S[i+j] != T[j] && S[i+j] != '?' {
				matched = false
				break
			}
		}
		if matched {
			str := ""
			count := 0
			for k := 0; k < len(S); k++ {
				if k < i || count == len(T) {
					if S[k] == '?' {
						str = str + "a"
					} else {
						str = str + string(S[k])
					}
				} else {
					str = str + string(T[k-i])
					count++
				}
			}
			strings = append(strings, str)
		}
	}
	if len(strings) == 0 {
		fmt.Println("UNRESTORABLE")
		return
	}
	min := strings[0]
	for i := 1; i < len(strings); i++ {
		if strings[i] < min {
			min = strings[i]
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      while(true){
      int N = sc.nextInt();
      int M = sc.nextInt(); sc.nextLine(); //nextIntの後残る改行文字を消す
      if(N==0&&M==0){break;}
      int count=0;
      String[] line = new String[M];
      for(int i=0;i<M;i++){
      	line[i]=sc.nextLine();
      } 
      String[][] a = new String[N][M];
      for(int j=0;j<M;j++){
       for(int k=0;k<N;k++){
        a[k][j]=String.valueOf(line[j].charAt(k));
       }
      }
      for(int t=0;t<60;t++){
       for(int p=0;p<M;p++){
        for(int q=0;q<N;q++){
         if((a[q][p].equals("@"))&&(a[Math.max(0,q-1)][p].equals("."))){
         	a[Math.max(0,q-1)][p]="@";
         }
         if((a[q][p].equals("@"))&&(a[q][Math.max(0,p-1)].equals("."))){
         	a[q][Math.max(0,p-1)]="@";
         }
         if((a[q][p].equals("@"))&&(a[Math.min(N-1,q+1)][p].equals("."))){
         	a[Math.min(N-1,q+1)][p]="@";
         }
         if((a[q][p].equals("@"))&&(a[q][Math.min(M-1,p+1)].equals("."))){
         	a[q][Math.min(M-1,p+1)]="@";
         }
        }
       }
      }
      for(int r=0;r<M;r++){
       for(int s=0;s<N;s++){
         if(a[s][r].equals("@")){
         	count++;
         }
       }
      }
     System.out.println(count);
      }
   }
}


Measured memory_bytes: 52196
#include <stdio.h>
int main(){
    int n, m,i;
    long long int x,y,z;
    long long int sum[4001];
    int q, a[4000];
    while(1){
        scanf("%d ", &n);
        if(n==0) break; 
        m=0;
        q=0;
        for(i=1;i<4001;i++){
            sum[i]=0;
        }
        while(n--){
            scanf("%lld %lld %lld ", &x, &y, &z);
            sum[x] += y *z;
            a[q] = x;
            q++;
        }        
        for(i=0;i<q;i++)
            if(1000000 <= sum[a[i]]){
                printf("%d\n", a[i]);
                m = 1;
                sum[a[i]] = 0;
            }
            if(m==0) printf("NA\n");
    }
    return 0;
} 

Measured memory_bytes: 656
import math
import collections
N=int(input())
# N,M=map(int,input().split())
# S=[[]for i in range(N)]
# # for i in range(Q):
A=list(map(int,input().split()))
# #     S[i]=a
D=dict()
ans=0
for i in range(N):
    a=A[i]+i
    if a in D.keys():
        D[a]+=1
    else:
        D[a] = 1
    b=i-A[i]
    if b in D.keys():
        ans+=D[b]


print(ans)

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


struct LowLink {
    int n, pos;
    vector<vector<int>> G;
    vector<int> ord, low, par, ap;
    vector<pair<int, int>> brg;
    LowLink(int n) : n(n), pos(0), G(n), ord(n, -1), low(n), par(n, -1){}
    void addEdge(int u, int v){
        G[u].push_back(v);
        G[v].push_back(u);
    }
    void dfs(int v){
        ord[v] = low[v] = pos++;
        int dup = 0;
        for(int u : G[v]){
            if(u == par[v]){
                if(dup) low[v] = min(low[v], ord[u]);
                dup = 1;
                continue;
            }
            if(~ord[u]){
                low[v] = min(low[v], ord[u]);
                continue;
            }
            par[u] = v;
            dfs(u);
            low[v] = min(low[v], low[u]);
            if(ord[v] < low[u]) brg.emplace_back(minmax(u, v));
        }
    }
    void build(){
        for(int i = 0;i < n;++i) if(ord[i] < 0) dfs(i);
        vector<int > cnt(n, 0);
        for(int i = 0;i < n;++i){
            int p = par[i];
            if(p < 0) continue;
            if(par[p] < 0) cnt[p]++;
            else if(ord[p] <= low[i]) ap.push_back(p);
        }
        for(int i = 0;i < n;++i) if(cnt[i] > 1) ap.push_back(i);
        sort(begin(ap), end(ap));
        sort(begin(brg), end(brg));
        ap.erase(unique(begin(ap), end(ap)), end(ap));
    }
    bool isBridge(int u, int v){
        if(ord[u] > ord[v]) swap(u, v);
        return ord[u] < low[v];
    }
};


int V, E;


int main(){
    cin >> V >> E;
    LowLink G(V);
    for(int i = 0;i < E;++i){
        int s, t;
        cin >> s >> t;
        G.addEdge(s, t);
    }
    G.build();
    for(auto p : G.brg) cout << p.first << ' ' << p.second << endl;
    return 0;
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int X,Y;
    cin>>X>>Y;
    cout<<X+Y/2<<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n;
ll a[100005];
ll sum;
ll x;
ll cnt;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    if(sum % (n * (n + 1) / 2) > 0)
    {
        printf("NO");
        return 0;
    }
    x = sum / (n * (n + 1) / 2);
    for(ll i = 0; i < n; i++)
    {
        ll t1 = a[i];
        ll t2 = a[(i + 1) % n];
        ll t3 = (t2 - t1);
        ll t4 = x - t3;
        if(t4 < 0)
        {
            printf("NO");
            return 0;
        }
        if(t4 % n > 0)
        {
            printf("NO");
            return 0;
        }
        cnt += t4 / n;
    }
    if(cnt == x)
    {
        printf("YES");
    }
    else printf("NO");
    return 0;
}


Measured memory_bytes: 1024
def main():
    s = input()
    a = int(s[:2])
    b = int(s[2:])
    if a == 0:
        if b == 0:
            ans = 'NA'
        elif b <= 12:
            ans = 'YYMM'
        else:
            ans = 'NA'
    elif b == 0:
        if a <= 12:
            ans = 'MMYY'
        else:
            ans = 'NA'
    elif a <= 12:
        if b <= 12:
            ans = 'AMBIGUOUS'
        else:
            ans = 'MMYY'
    elif b <= 12:
        ans = 'YYMM'
    else:
        ans = 'NA'
    print(ans)

if __name__ == '__main__':
    main()


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

int main()
{
    int n, i;
    scanf("%d ", &n);
    int p[n], ans[n];
    string s[n];

    for (i = 0; i < n; i++)
    {
        cin >> s[i] >> p[i];
        ans[i] = i + 1;
    }

    bool flag = true;
    while (flag)
    {
        flag = false;
        for (i = n - 1; i > 0; i--)
        {
            if (s[i] < s[i - 1])
            {
                string tmp = s[i];
                s[i] = s[i - 1];
                s[i - 1] = tmp;

                int tmp1 = p[i];
                p[i] = p[i - 1];
                p[i - 1] = tmp1;

                int tmp2 = ans[i];
                ans[i] = ans[i - 1];
                ans[i - 1] = tmp2;
                flag = true;
            }
            else if (s[i] == s[i - 1])
            {
                if (p[i] > p[i - 1])
                {
                    string tmp = s[i];
                    s[i] = s[i - 1];
                    s[i - 1] = tmp;

                    int tmp1 = p[i];
                    p[i] = p[i - 1];
                    p[i - 1] = tmp1;

                    int tmp2 = ans[i];
                    ans[i] = ans[i - 1];
                    ans[i - 1] = tmp2;
                    flag = true;
                }
            }
        }
    }

    for (i = 0; i < n; i++)
        cout << ans[i] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		char c3 = S.charAt(2);
		char c4 = S.charAt(3);
		char c5 = S.charAt(4);
		char c6 = S.charAt(5);

		if(c3 == c4 && c5 == c6) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35660
#include <iostream>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>
#define rep0(i, n) for(int i=0; i<(int)(n);i++)
typedef int64_t lint;
using namespace std;

int main(){
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    rep0(i, n){
        cin >> a[i];
    }
    lint kk = k * (k - 1) / 2;
    boost::multiprecision::cpp_int ans = 0;
    for (int i = 0; i < n; ++i) {
        lint left = 0; //外に
        lint right = 0; //外に
        
        for (int j = 0; j < n; ++j) {
            left = 0;
            right = 0;
            if(a[i] > a[j]){
                if(i > j)left ++ ;
                if(i < j)right ++ ;
            }
            ans += (right + left) * kk + k * right; //外に
        }
        ans %= 1000000007; //外に
    }
    cout << ans << endl;
}

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


long long int dp[22][(1<<22)];
long long int mod=1000000007;
long long int solve(vector<vector<int> >&v , int wmsbst, int i,int n)
{
	if(i==n)
	{
		if(wmsbst==0)
		{
			return(1);
		}
		else
			return(0);
	}
	if(dp[i][wmsbst]!=-1)
	{
		return(dp[i][wmsbst]);
	}
	long long int sum=0;
	for(int w=0;w<n;w++)
	{
		if(wmsbst&(1<<w) && v[i][w]==1)
		{
			sum=(sum+solve(v,wmsbst^(1<<w),i+1,n))%mod;
		}
	}
	return(dp[i][wmsbst]=sum);
}
int main()
{
	int n,i,j;
	cin>>n;
	vector<vector<int> >v(n,vector<int>(n)); 
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>v[i][j];
		}
	}
	for(i=0;i<22;i++)
	{
		for(j=0;j<(1<<22);j++)
		{
			dp[i][j]=-1;
		}
	}
	cout<<solve(v,(1<<n)-1,0,n);
}

Measured memory_bytes: 721400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  
  //int ans = 0;
  //string ans = "Yes";
  //string ans = "No";
  //string ans = "YES";
  //string ans = "NO";
  vector<int> c = h;
  sort(all(c));
  rep(i, n){
    if (h[i] == c[n - 1]) cout << c[n - 2] << endl;
    else cout << c[n - 1] << endl;
  }
  
  //cout << ans << endl;
}

Measured memory_bytes: 3200
a,b,c=map(int,sorted(list(map(int,input().split()))))
cnt=0
while True:
  if a==b==c:break
  elif a==b:
    cnt+=c-a
    break
  else:
    a,b,c=map(int,sorted([a+2,b,c]))
    cnt+=1
print(cnt)

Measured memory_bytes: 61944
import numpy as np

def find(x):
    if x == root[x]: return x
    else: root[x] = find(root[x]); return root[x]
def unite(x,y):
    px,py = find(x),find(y)
    if px == py : return
    else: root[px] = py
def same(x,y): return find(x)==find(y)


n,m = map(int,input().split())
ab = np.array([list(map(int,input().split())) for i in range(m)])
a,b = ab.T[0] -1, ab.T[1] -1

ans = 0
for i in range(m): #除外する辺を決める
    connect = 0
    root = list(range(n))
    for j in range(m): #i以外の辺についてuniteしていく
        if i != j and  not same(a[j],b[j]):
            unite(a[j],b[j]) ; connect += 1
    ans += 0 if connect == n-1 else 1
print(ans)




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

int main(void){

  int i, j, n, num, cnt=0;
  bool flag;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    flag=true;
    scanf("%d", &num);
    
    for(j=2; j <= sqrt(num); j++){
      
      if(num%j == 0){
	flag=false;
	break;
      }
    }

    if(flag){
      cnt++;
    }
  }

  printf("%d\n", cnt);
  
  return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
#define mod 1000000007
int main(){
	string a, b;
	cin>>a;
	cin>>b;
	int res = 0;
	forloop(3){
		res += (a[i] == b[i]);
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO "A"
const int N=6e5,MOD=924844033,G=5;

int n,l=1,ans[N],u,v,sz[N],a[N],b[N],c[N],d[N],rev[N],w[2][N];
int fac[N],inv[N],invc[N];
int h[N],to[N],nxt[N],ecnt;

inline void adde(int u,int v){nxt[++ecnt]=h[u];h[u]=ecnt;to[ecnt]=v;}

inline int add(int a,const int &b){if((a+=b)>=MOD)a-=MOD;return a;}
inline int sub(int a,const int &b){if((a-=b)<0)a+=MOD;return a;}
inline int mul(const int &a,const int &b){return 1ll*a*b%MOD;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
inline int C(const int &a,const int &b){return mul(mul(fac[a],invc[b]),invc[a-b]);}

inline void dfs(int u,int fa){
	sz[u]=1;
	for(int i=h[u],v;i;i=nxt[i])if((v=to[i])^fa){
		dfs(v,u);
		c[sz[v]]++;
		sz[u]+=sz[v];
	}
	c[n-sz[u]]++;
}

inline void fft(int *a,int opt){
	for(int i=0;i<l;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<l;i<<=1)
		for(int j=0;j<l;j+=i<<1)
			for(int k=0;k<i;k++){
				int x=a[j+k],y=mul(a[i+j+k],w[opt][i+k]);
				a[j+k]=add(x,y);
				a[i+j+k]=sub(x,y);
			}
	if(opt)for(int i=0,inv=qpow(l,MOD-2);i<l;i++)a[i]=mul(a[i],inv);
}

int main(){
	scanf("%d",&n);
	while(l<=n<<1)l<<=1;
	for(int i=0;i<l;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(l>>1));
	for(int i=1;i<l;i<<=1){
		w[0][i]=w[1][i]=1;
		int wn1=qpow(G,(MOD-1)/(i<<1)),wn0=qpow(wn1,MOD-2);
		for(int j=1;j<i;j++)w[0][i+j]=mul(w[0][i+j-1],wn0),w[1][i+j]=mul(w[1][i+j-1],wn1);
	}
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),adde(u,v),adde(v,u);
	inv[0]=inv[1]=fac[0]=fac[1]=invc[0]=invc[1]=1;
	for(int i=2;i<=n;i++)fac[i]=mul(fac[i-1],i),inv[i]=mul(MOD-inv[MOD%i],MOD/i),invc[i]=mul(invc[i-1],inv[i]);
	dfs(1,0);
	for(int i=0;i<=n;i++)a[i]=mul(c[i],fac[i]),b[n-i]=invc[i];
	/*
	for(int i=1;i<=n;i++)printf("%d%c",a[i],i==n?'\n':' ');
	for(int i=1;i<=n;i++)printf("%d%c",b[i],i==n?'\n':' ');
	for(int i=1;i<=n;i++)printf("%d%c",c[i],i==n?'\n':' ');
	*/
	fft(a,0);fft(b,0);
	for(int i=0;i<l;i++)ans[i]=mul(a[i],b[i]);
	fft(ans,1);
	for(int i=1;i<=n;i++)printf("%d\n",sub(mul(C(n,i),n),mul(invc[i],ans[n+i])));
	return 0;
}


Measured memory_bytes: 40704
N = int(input())

def it(remain,n):
    if remain == 0:
        yield []
    else:
        for x in range(n+1):
            for d in it(remain-1,max(x+1,n)):
                d.append(x)
                yield d


print(*(''.join(chr(x+ord('a')) for x in reversed(d)) for d in it(N,0)), sep='\n')



Measured memory_bytes: 13576
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	char input;

	scanf("%c", &input);

	if (input <= 'Z')
	{
		printf("A\n");
	}

	else
	{
		printf("a\n");
	}

	return 0;
}

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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e5+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

int dp[mx],n,a[mx],k;

int solve (int i)
{
    if ( i >= n )
        return 0;
    if ( dp[i]!= -1 )
        return dp[i];

    int ret1 = INT_MAX;
    for(int j=1; j<=k; j++)
    {
        if (i+j<=n )
            ret1 =min(ret1,abs(a[i]-a[i+j])+ solve (i+j));

    }
    dp[i]= ret1;

    return dp[i];
}

int main()
{
    su;

    mem ( dp, -1 );

    cin>>n>>k;

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

    cout << solve( 1 )<< nl;


    return 0;
}


Measured memory_bytes: 12272
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 x, a, b;
int main() {
  cin >> x >> a >> b;
  if (b <= a) cout << "delicious";
  else if (b <= a + x) cout << "safe";
  else cout << "dangerous";
  cout << endl;
  return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  LL ans = 0;
  cin >> N;
  
  VLL A(N);
  
  REP(i,N){
    cin >> A.at(i);
  }
  
  if(A.at(0) != 0){
    cout << -1 << endl;
    return 0;
  }
  
  FOR(i,1,N){
    if(A.at(i)-A.at(i-1) > 1){
      cout << -1 << endl;
    	return 0;
    }
  }
  
  FOR(i,1,N){
    if(A.at(i)-A.at(i-1) == 1){
      ans++;
    }else{
      ans += A.at(i);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1792
from operator import itemgetter
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
a = sorted(a, key=itemgetter(1))
bridge = [a[0][1]-1]
for i in range(1,m):
    if a[i][0] <= max(bridge):
        continue
    else:
        bridge.append(a[i][1]-1)
print(len(bridge))

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

namespace abc047_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] yoko = new int[] { 0, x[0] };
            int[] tate = new int[] { 0, x[1] };
            for (int i = 0; i < x[2]; i++)
            {
                int[] now = Console.ReadLine().Split().Select(int.Parse).ToArray();
                switch (now[2])
                {
                    case (1):
                        {
                            yoko[0] = Math.Max(yoko[0], now[0]);
                            break;
                        }
                    case (2):
                        {
                            yoko[1] = Math.Min(yoko[1], now[0]);
                            break;
                        }
                    case (3):
                        {
                            tate[0] = Math.Max(tate[0], now[1]);
                            break;
                        }
                    case (4):
                        {
                            tate[1] = Math.Min(tate[1], now[1]);
                            break;
                        }
                }
            }
            Console.WriteLine(yoko[0] <= yoko[1] && tate[0] <= tate[1] ? (yoko[1] - yoko[0]) * (tate[1] - tate[0]) : 0);
        }
    }
}

Measured memory_bytes: 13396
use std::io::BufReader;
use std::io;
use std::io::prelude::*;

fn main() {

    let mut first = true;
    let mut N :i32 = 0;
    let mut M: i32 = 0;
    let mut svec = Vec::new();
    let mut cvec = Vec::new();
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let s: Vec<String> = line.unwrap().split(' ').map(|s| String::from(s)).collect();
        if first {
            N = s[0].parse::<i32>().unwrap();
            M = s[1].parse::<i32>().unwrap();
        } else {
            let sv = s[0].parse::<i32>().unwrap();
            let cv = s[1].parse::<i32>().unwrap();
            svec.push(sv);
            cvec.push(cv);
        }
        first = false
    }

    let mut val = Vec::new();
    for i in 0..N {
        val.push(-1);
    }

    for i in 0..svec.len() {
        let pos = (svec[i as usize] - 1) as usize;
        if val[pos] != -1 && val[pos] != cvec[i as usize] {
            println!("-1");
            return
        }
        val[pos] = cvec[i as usize] ;
    }

    if val[0] == -1 {
        if N > 1 {
            val[0] = 1
        } else {
            val[0] = 0
        }
    } else {
        if N > 1 && val[0] == 0 {
            println!("-1");
            return
        }
    }

    for i in 1..N {
        if val[i as usize] == -1 {
            val[i as usize] = 0
        }
    }

    let ans: String = val.iter().map(|v| v.to_string()).collect();

    println!("{}", ans);
}

Measured memory_bytes: 2192
import io.StdIn._
object Main extends App {
    val Array(a,b,m) = readLine.split(" ").map(_.toInt)
    val as = readLine.split(" ").map(_.toInt)
    val bs = readLine.split(" ").map(_.toInt)
    val xycs = for (_ <- 1 to m) yield readLine.split(" ").map(_.toInt)

    val prices_saled = for (xyc <- xycs) yield {
        val x = xyc.head
        val y = xyc(1)
        val c = xyc.last
        as(x-1) + bs(y-1) - c // return 値引かれた価格
    }

    val all_prices = prices_saled :+ (as.min + bs.min)
    println(all_prices.min)
}

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

struct UnionFind {
private:
	std::vector<int> value;
public:
	UnionFind(int size): value(size, -1){}
	int find(int x){
		return value[x] < 0 ? x : value[x] = find(value[x]);
	}
	int size(int x){
		return -value[find(x)];
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	bool unite(int x, int y){
		if ((x = find(x)) == (y = find(y))) return false;
		if (value[x] > value[y]) std::swap(x, y);
		value[x] += value[y];
		value[y] = x;
		return true;
	}
};

struct Edge {
	int s, t, cost;
	Edge(){}
	Edge(int s, int t, int cost): s(s), t(t), cost(cost){}
};

int n, m;
int h[201];
vector<Edge> es;

long long calc()
{
	vector<pair<int, int>> v;
	for (int i = 0; i < n; i++){
		v.push_back(make_pair(-h[i], i));
	}
	sort(v.begin(), v.end());
	sort(es.begin(), es.end(), [](const Edge &a, const Edge &b){
		return a.cost < b.cost;
	});
	
	long long sum = 0;
	UnionFind uf(n);
	bool f[200] = {};
	for (int i = 0; i < n; i++){
		f[v[i].second] = true;
		if (i + 1 < n && h[v[i].second] == h[v[i + 1].second]) continue;
		for (auto &e : es){
			if (f[e.s] && f[e.t] && uf.unite(e.s, e.t)){
				sum += e.cost;
			}
		}
		if (uf.size(v[0].second) != i + 1){
			uf = UnionFind(n);
			sum = 0;
		}
	}
	
	return sum;
}

int main()
{
	while (scanf("%d %d", &n, &m), n){
		es.clear();
		for (int i = 0; i < n; i++) scanf("%d", h + i);
		for (int i = 0; i < m; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			es.push_back(Edge(--a, --b, c));
		}
		printf("%lld\n", calc());
	}
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
    
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define sz(v) ((int)v.size())   
#define rad(a) a * PI / 180  
 
typedef long long ll;
typedef vector<int> vi;	
typedef pair<ll,ll> ii;
typedef pair<int,char> ic;
typedef pair<ll, bool> llb;
 
const int SIGMA = 20;
const int MAX = 100010;
const int MAXT = 1048576;
const ll INF = 1000000001;
const ll P = 998244353LL; //1000000007;
const double EPS = 1e-6;
const double PI = 3.14159265358979;

vector<ll> d(MAX, 0);

ll expo(ll base, ll ex){
	if(ex == 0) return 1;
	if(ex == 1) return base;
	if(ex & 1LL){
		return (base*expo(base,ex-1))%P;
	}

	ll base2 = expo(base, ex >> 1LL);
	return (base2*base2)%P;
}

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

	int n, mx = 0;

	cin >> n;
	for(int i = 0, j; i < n; i++){
		cin >> j;
		if(i == 0 && j != 0){
			cout << 0 << endl;
			return 0;
		}
		d[j]++;
		mx = max(mx,j);
	}

	if(d[0] != 1) {
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0; i <= mx; i++){
		if(d[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}

	ll trees = 1;
	for(int i = 2; i <= mx; i++){
		trees = (expo(d[i-1], d[i])*trees) % P;
	}
	
	cout << trees << endl;
	
	return 0;
}

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

int main(){
  int k,n;
  cin >> k >> n;
  vector<int> a(n+1);
  for(int i=0; i<n; i++) cin >> a[i];
  a[n]=k+a[0];
  int m=0;
  for(int i=0; i<n; i++) m = max(m,a[i+1]-a[i]);
  cout << k-m;
}

Measured memory_bytes: 4020
#include <cstdio>
#include <cstdlib>
#include <algorithm>

long long dp[100000];

int main()
{
  int n;
  scanf("%d", &n);
  int h[100000];
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", h + i);
  }
  dp[2] = std::abs(h[1] - h[0]);
  for (int i = 3; i <= n; ++i)
  {
    dp[i] = std::min(dp[i - 1] + std::abs(h[i - 1] - h[i - 2]), dp[i - 2] + std::abs(h[i - 1] - h[i - 3]));
  }
  printf("%lld\n", dp[n]);
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> sra(n);
  for(int i=0; i<n; ++i) cin >> sra[i];
  sort(sra.begin(),sra.end());
  int ans = 1;
  ll rui = sra[0];
  for(int i=1; i<n; ++i){
    if(rui *2 >= sra[i]) ++ans;
    else ans = 1;
    rui += sra[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  ll n;
  cin>>n;
  ll sum = 0;
  for (ll i = 1; i*i <= n; ++i) {
    if (n/i == n%i) sum += i;
  }
  double sq = sqrt(n);
  for (ll i = 1; i*i < n; ++i) {
    if ((n%i) == 0) {
      if (n/i-1 > sq) {
        sum += n/i-1;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> C(n);
    Graph A(n,vector<int>(m));
    rep(i,n){
        cin>>C[i];
        rep(j,m) cin>>A[i][j];
    }
    int ans=1e7;
    for(int bit=0;bit<(1<<n);++bit){
        int money=0;
        vector<int> al(m,0);
        rep(i,n){
            if(bit & (1<<i)){
                money+=C[i];
                rep(j,m) al[j]+=A[i][j];
            }
        }
        
        bool ok=true;
        rep(i,m) if(al[i]<x) ok=false;
        if(ok){
            ans=min(ans,money);
        }
    }
    if(ans!=1e7) cout<<ans<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 3640