akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
line = input().split()
n = int(line[0])
m = int(line[1])
a = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]
ans = [0 for i in range(n)]
for i in range(n):
    a[i] = input().split()
    for j in range(m):
        a[i][j] = int(a[i][j])
for i in range(m):
    b[i] = int(input())
    
for i in range(n):
    for j in range(m):
        ans[i] += a[i][j]*b[j]
    print(ans[i])


Measured memory_bytes: 5800
#include<stdio.h>
int main(void){
    int a,b,c;//a,b,cは家1,2,3の座標
    scanf("%d %d %d",&a,&b,&c);
    if((a<b && a<c && c<b) || (b<a && b<c && c<a) ){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

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

    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int x = scanner.nextInt();

    int count = 0;

    for (int aCount = 0; aCount <= a; aCount++) {
      for (int bCount = 0; bCount <= b; bCount++) {
        for (int cCount = 0; cCount <= c; cCount++) {
          int result = aCount * 500 + bCount * 100 + cCount * 50;


          if (result == x) {
            count++;
          }
        }
      }
    }

    System.out.println(count);
    scanner.close();
  }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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


const int MAX = 1000000;
bool is_prime[MAX + 10];
//int key(int n)
//{
//	vector<int> p;
//	for (int i = 2; i <= n; ++i)
//		if (is_prime[i] && n % i == 0)
//			p.push_back(i);
//	return 2 * p.back() - accumulate(all(p), 0);
//}
int memo[MAX + 10];
int key(int n)
{
	if (~memo[n])
		return memo[n];

	int sum = 0, last;
	for (int i = 2; i <= n; ++i)
		if (is_prime[i] && n % i == 0)
			sum += i, last = i;

	return memo[n] = 2*last - sum;
}
int main()
{
	fill_n(is_prime, MAX, true);
	for (int i = 2; i*i <= MAX; ++i)
		if (is_prime[i])
			for (int j = 2*i; j <= MAX; j += i)
				is_prime[j] = false;

	fill_n(memo, MAX, -1);
	int a, b;
	while (scanf("%d%d", &a, &b), a | b)
		puts(key(a) > key(b) ? "a" : "b");
}

Measured memory_bytes: 5720
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int ans = 0;
  rep(i, 0, n) {
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    a, b, c = [int(e) for e in input().split()]

    if a >= c or b >= c:
        print('No')
    elif a**2 + b**2 + c**2 - 2*(a*b + b*c + c*a) > 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


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

int main(){
        int n,q,i,b,c,tmp;
        long long sum=0,t;
        cin >> n;
        vector<int> a(n);
        vector<int> cnt(1000000);
        vector<long long> ans;
        for(i=0;i<n;++i){
                cin >> tmp;
                ++cnt.at(tmp);
                a.at(i) = tmp;
        }
        sum = accumulate(a.begin(),a.end(),0LL);
        cin >> q;
        for(i=0;i<q;++i){
                cin >> b >> c;
                t = (c-b)*cnt.at(b);
                cnt.at(c) += cnt.at(b);
                cnt.at(b) = 0;
                sum += t;
                ans.push_back(sum);
        }
        i = 0;
        while(true){
                cout << ans.at(i) << endl;
                ++i;
                if(i==q) break;
        }
        return 0;
}

Measured memory_bytes: 8544
N,M = map(int,input().split())
import numpy as np
A = list(map(int,input().split()))
A.sort(reverse = True)
B = list(map(int,np.floor(np.log2(np.array(A)))))
BB = B
C = [0]*len(A)
MM = M
for i in range(max(B),-1,-1):
  k = BB.count(i)
  if MM < k:
    break
  else:
    MM -= k
    for j in range(k):
      C[j]+=1
      BB[j]-=1

for i in range(N):
  if C[i]==0:
    break
  else:
    A[i] = A[i]//2**C[i]

A.sort(reverse = True)
for i in range(min(MM,len(A))):
  A[i] = A[i]//2

print(sum(A))

Measured memory_bytes: 23104
import sys
a=int(input())
c=0
i=0
if a==26:
  print("z")
  sys.exit()
if a==26+26**2:
  print("zz")
  sys.exit()
if a==26+26**2+26**3:
  print("zzz")
  sys.exit()
if a==26+26**2+26**3+26**4:
  print("zzzz")
  sys.exit()
if a==26+26**2+26**3+26**4+26**5:
  print("zzzzz")
  sys.exit()
if a==26+26**2+26**3+26**4+26**5+26**6:
  print("zzzzzz")
  sys.exit()
if a==26+26**2+26**3+26**4+26**5+26**6+26**7:
  print("zzzzzzz")
  sys.exit()
if a==26+26**2+26**3+26**4+26**5+26**6+26**7+26**8:
  print("zzzzzzzz")
  sys.exit()
if a==26+26**2+26**3+26**4+26**5+26**6+26**7+26**8+26**9:
  print("zzzzzzzzz")
  sys.exit()
if a==26+26**2+26**3+26**4+26**5+26**6+26**7+26**8+26**9+26**10:
  print("zzzzzzzzzz")
  sys.exit()
while c<=a:
  i+=1
  c+=26**i
l=[0]*i
p=0
for k in range(i):
  p+=26**k
a-=p
for j in range(i):
  l[j]=a//(26**(i-j-1))
  a=a%(26**(i-j-1))
for n in l:
  print(chr(n+97),end='')

Measured memory_bytes: 62024
import java.util.*;

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

		while(true){
			long n = sc.nextLong(), m = sc.nextLong();
			if(n == 0 && m == 0) break;

			long i;
			for(i=0;i<=n;i++){
				long comb = c(n,i);
				if(m - comb > 0) m -= comb;
				else{
					if(m - comb == 0) m = comb;
					break;
				}
			}
			printAnswer("",n,i,m);
		}
	}
	
	static void printAnswer(String s,long n,long m,long rem){
		long comb = c(n-1,m);
		
		if(n == m){
			for(long i=0;i<m;i++) s += "1";
			System.out.println(s);
			return;
		}
		
		if(rem <= comb) printAnswer(s+"0",n-1,m,rem);
		else printAnswer(s+"1",n-1,m-1,rem-comb);			
	}
	
	static long c(long n, long r){
		long res = 1;
		for(long i=1;i<=r;i++) res = (res * (n-i+1)) / i;
		return res;
	}
}

Measured memory_bytes: 12000
N = int(input())
T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def solve() :
    if T[-1] != A[0] :
        return 0
        
    for i in range(N) :
        if T[i] == T[-1] :
            break
    for j in range(N - 1, -1, -1) :
        if A[j] == A[0] :
            break
            
    if i > j :
        return 0
        
    ok = [False] * N
    ok[0] = ok[-1] = True
    for i in range(1, N) :
        if T[i] != T[i-1] :
            ok[i] = True
        if A[N-1-i] != A[N-i] :
            ok[N-1-i] = True

    ret = 1
    for i in range(N) :
        if ok[i] : continue
        ret = ret * min(T[i], A[i]) % mod   
    
    return ret
    
print(solve())

Measured memory_bytes: 82532
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<endl
using namespace std;

int n,t;
ll s[100001],sum[100001];
                  
int main(){
 ios::sync_with_stdio(false);
 cin.tie(0);
 cout.precision(10);
 cout<<fixed;
#ifdef LOCAL_DEFINE
  freopen("in", "r", stdin); 
  freopen("out","w",stdout);
#endif
 cin>>n>>t;
 for(int i=0;i<n;i++){
  int r,l;cin>>l>>r;
  s[l]++;
  s[r]--;
 } 
 sum[0]=s[0];
 for(int i=1;i<=t;i++){
  sum[i]=s[i]+sum[i-1];
 }
 ll ans=0;
 for(int i=0;i<=t;i++){
  ans=max(ans,sum[i]);
 }
 cout<<ans<<endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
 return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;


	int main(int argc, char* argv[]){

		int A, B;
		scanf("%d %d", &A, &B);
		printf("%d\n", A*B);

		return 0;
	}







Measured memory_bytes: 3764
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;

int main() {
	int n, m, c=0;
	int k[10];
	int s[10][10];
	int p[10];
	int sw[10];
	int allON;

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++)
			cin >> s[i][j];
	}
	for (int k = 0; k < m; k++)
		cin >> p[k];

	for (int i = 0; i < pow(2, n); i++) {
		int l = i;
		allON = 0;
		for (int j = 0; j < n; j++) {
			sw[j] = l % 2;
			l /= 2;
		}

		for (int j = 0; j < m; j++) {
			int swOnN = 0;
			for (int a = 0; a < k[j]; a++)
				swOnN += sw[s[j][a] - 1];
			if (swOnN % 2 != p[j])
				allON = 1;
		}

		if (allON == 0)
			c++;
	}

	cout << c;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;

int main(){
  	string S;
    cin >> S;
    if(S=="AAA" || S=="BBB"){
      cout <<"No" <<endl;
      return 0;
    }
    cout << "Yes" <<endl;

  	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
int main(){
  long long H;
  cin >> H;
  long long monster_num = 1;
  long long ans = 0;
  while(H != 1){
    H = H / 2;
    ans += monster_num;
    monster_num *= 2;
  }
  cout << ans + monster_num << endl;
  return 0;
}


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

typedef long long ll;

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

    // solve
    ll ans = 1;
    for (int i = 1; i <= N; ++i) {
        ans *= i;
        ans %= 1000000007;
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
	"sort"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type inInfo struct {
	in    int
	after int
}

type inInfoSorter []*inInfo

func (a inInfoSorter) Len() int      { return len(a) }
func (a inInfoSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a inInfoSorter) Less(i, j int) bool {
	me, you := a[i], a[j]
	switch {
	case me.in > you.in:
		return true
	case me.in < you.in:
		return false
	case me.after > you.after:
		return true
	default:
		return false
	}
}

func sum(w []int) int {
	s := 0
	for _, v := range w {
		s += v
	}
	return s
}

type ptr []int

func (x ptr) top(i int) int {
	ptrs := []int(x)
	var his []int
	cur := i
	for ; cur >= 0 && ptrs[cur] != cur; cur = ptrs[cur] {
		his = append(his, cur)
	}
	for _, v := range his {
		ptrs[v] = cur - 1
	}
	if cur >= 0 {
		ptrs[cur] = cur - 1
	}
	return cur
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, m int
	var infos []*inInfo

	fmt.Fscanln(stdin, &n, &m)

	for i := 0; i < n; i++ {
		var info inInfo
		fmt.Fscanln(stdin, &info.after, &info.in)
		infos = append(infos, &info)
	}

	sort.Sort(inInfoSorter(infos))

	var ans = make([]int, m)
	var p = make([]int, m)
	for i := range p {
		p[i] = i
	}

	for _, w := range infos {
		i := ptr(p).top(m - w.after)
		if i >= 0 {
			ans[i] = w.in
		}
	}

	fmt.Fprintln(stdout, sum(ans))

}



Measured memory_bytes: 8704
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>

using namespace std;

int main(void){
    string S;
    int cntR=0,cntL=0,ansR,ansL;
    cin>>S;
    VI ans(S.length());
    rep(i,S.length()-1){
        if(S[i]=='R'){
            cntR++;
            ansR=i;
        }
        else{
            cntL++;
        }
        if(S[i]=='L' && S[i+1]=='R'){
            ans[ansR]=cntR/2+cntL/2;
            ans[ansR+1]=cntR/2+cntL/2;
            if(cntR%2!=0)ans[ansR]++;
            if(cntL%2!=0)ans[ansR+1]++;
            cntR=0,cntL=0;
        }
    }
    cntL++;
    ans[ansR]=cntR/2+cntL/2;
    ans[ansR+1]=cntR/2+cntL/2;
    if(cntR%2!=0)ans[ansR]++;
    if(cntL%2!=0)ans[ansR+1]++;
    rep(i,S.length()){
        cout<<ans[i]<<' ';
    }
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,a[100]; cin>>n;
	rep(i,n) cin>>a[i];

	sort(a,a+n);

	int ans=0;
	rep(i,n) ans+=(i%2==0?1:-1)*a[n-i-1];
	cout<<ans<<endl;

	return 0;
}


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

int main (){
    long double num;
    long double c = 0;
    long double k;
    
    cin >> num;

    for(int i=1;i<=num;i++){
        if(i%2 == 1){
            c++;
        }
    }

    k = c / num;

    cout << fixed << setprecision(10) << k <<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
const ll mod=1e9+7;
ll last[100001];
inline ll fpow(ll a,ll x){
	if(a==0) return 0;
	ll _ans=1;
	for(ll i=x;i>0;(i>>=1),(a*=a)){
		if(a>mod) a%=mod;
		if(i&1)_ans*=a,_ans%=mod;
	}
	return _ans;
}
int main(){
	ll n,k,ans=0;
	cin>>n>>k;
	for(ll p=k;p>=1;--p){
		ll fo=k/p; 
		ll res=fpow(fo,n);
		for(ll j=fo*p;j>p;j-=p){
			if(res<last[j])res+=mod;
			res-=last[j];
		}
		last[p]=res;
	}
	for(ll p=k;p>=1;--p){
		ans+=last[p]*p;
		ans%=mod;
	}
	cout<<ans;
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

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

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

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

void deleteNode(NodePointer t){
  /* your code */
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t = nil->prev;
  if(t == nil) return;
  deleteNode(t);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* your code */
  x->next = nil->next;
  nil->next->prev =x;
  nil->next = x;
  x->prev = nil;

}

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

  printList();
  return 0;
}



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

int main(){
  int r, g, b;
  
  cin >> r >> g >> b;
  
  if((10*g+b) % 4 == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

using namespace std;

void b()
{
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int xl = x2 - x1;
    int yl = y2 - y1;
    int x3, y3, x4, y4 = 0;
    if(xl >= 0 && yl >= 0)
    {
        x3 = x2 - yl;
        y3 = y2 + xl;
        x4 = x3 - xl;
        y4 = y3 - yl;
    }else if(xl >= 0 && yl < 0)
    {
       x3 = x2 - yl;
       y3 = y2 + xl;
       x4 = x3 - xl;
       y4 = y3 - yl;
    }else if(xl < 0 && yl >= 0)
    {
        x3 = x2 - yl;
        y3 = y2 + xl;
        x4 = x3 - xl;
        y4 = y3 - yl;
    }else if(xl < 0 && yl < 0)
    {
        x3 = x2 - yl;
        y3 = y2 + xl;
        x4 = x3 - xl;
        y4 = y3 - yl;
    }
    cout << x3 <<" " << y3 << " " << x4 << " " << y4 << endl;
}

void c()
{
    int n, k;
    cin >> n >> k;
    vector<int> ns(n + 1, 0);

    long long int result = 0;
    if(k % 2 == 0)
    {
        ///k / 2に合同な数の集合を作る
        vector<int> half;
        for (int i = 1; i < n + 1; ++i) {
            if(i % (k / 2) == 0 && i % k != 0)
            {
                half.push_back(i);
            }
        }
        result += half.size() * half.size() * half.size();
    }
    long long int count = n / k;
    result += count * count * count;
    cout << result << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdint.h>

using namespace std;

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

  if (N>M)
    swap(N,M); // always M >= N

  uint64_t ans;
  
  if (N==1)
    if (M==1)
      ans = 1;
    else
      ans = M-2;
  else
    ans = (N-2)*(M-2);

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

Measured memory_bytes: 256
num = input()
num = num.split()
a = int(num[0])
b = int(num[1])
flag = 0

for i in range(b):
    j = i + 1
    if b % j == 0:
        if a == j:
            flag = 1
            print(a + b)
if flag == 0:
    print(b - a)

Measured memory_bytes: 3060
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

void solve()
{
    int n; cin>>n;
    ll a[n+1];
    a[0] = -1;
    rep(i,1,n+1) cin>>a[i];
    ll ans = 0;
    rep(i,1,n+1)
    {
        if(a[i] - a[i-1]>1)
        {
            cout<<-1;
            return;
        }
        if((a[i] - a[i-1] == 1) and a[i]>0) ans++;
        else ans+=a[i];
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; /*cin>>t;*/ t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

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


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

    int arr[m]{};
    ll sum = 0 ;
    rep( i , m) {cin>>arr[i]; sum+= arr[i];}

    ll ans = n - sum ;

    if(ans<0){cout << -1 << endl;}
    else cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
  char S[11];
  int T[11];
  int kazu = 0;
  int max = 0;
  int i;

  scanf("%s",S);
  
    for(i=0;i<11;i++){
    T[i] = 0;
  }

  for(i=0;i<11;i++){
    if(S[i]=='A')T[i]= 1;
    if(S[i]=='C')T[i]= 1;
    if(S[i]=='G')T[i]= 1;
    if(S[i]=='T')T[i]= 1;
  }

  for(i=0;i<11;i++){
    kazu += T[i];
    if(T[i] == 0){
      if(max< kazu){max = kazu;}
      kazu = 0;
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
///
// File:  dpl_1_f.cpp
// Author: ymiyamoto
//
// Created on Fri Dec 22 02:12:37 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

constexpr int32_t VAL = 100;

int32_t main()
{
  int32_t N, W;
  cin >> N >> W;

  vector<pair<int64_t, int64_t>> items(N + 1);
  for (int32_t i = 1; i <= N; i++) {
    cin >> items[i].first;
    cin >> items[i].second;
  }

  vector<vector<int64_t>> dp(N + 1, vector<int64_t>(N * VAL + 1, 1 << 30));
  dp[0][0] = 0;
  for (int32_t i = 1; i <= N; i++) {
    int64_t v = items[i].first;
    int64_t w = items[i].second;
    for (int32_t j = 0; j <= N * VAL; j++) {
      if (j - v >= 0) {
        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + w);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }

  uint32_t max_val = 0;
  for (auto l : dp) {
    for (uint32_t v = 0; v < l.size(); v++) {
      if (l[v] <= W) {
        max_val = max(max_val, v);
      }
    }
  }

  cout << max_val << endl;

  return 0;
}

Measured memory_bytes: 10808
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int h[MAX];
map<int, int>adj[MAX];
set<int>good;
void remove(int i) {
  auto it = good.find(i);
  if(it != good.end())good.erase(it);
}
void solve() {
  int n, m;
  int u, v;
  cin >> n >> m;
  vector< pair<int, int> > order;
  for(int i = 0; i < n; ++i){
    good.insert(i);
    cin >> h[i];
  }
  sort(order.begin(), order.end());
  for(int j = 0; j < m; ++j) {
    cin >> u >> v;
    --u;
    --v;
    auto it = adj[u].find(v);
    if(it != adj[u].end())adj[u][v]++;
    else adj[u][v] = 1;
    auto it2 = adj[v].find(u);
    if(it2 != adj[v].end())adj[v][u]++;
    else adj[v][u] = 1;
  }
  for(int i = 0; i < n; ++i) {
    auto it = good.find(i);
    if(it == good.end())continue;
    int cnt = 0;
    for(auto [j, roads] : adj[i]) {
      // if(roads > 1)continue;
      if(h[j] > h[i])remove(i);
      else if(h[i] > h[j])remove(j);
      else {
        remove(i);
        remove(j);
      }
    }
  }
  cout << (int)good.size() << endl;
  // for(auto x : good)cout << x+1 << " ";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tc = 1;
  // cin >> tc;
  for(int i = 1; i <= tc; ++i) {
    // cout << "Case #" << i <<": ";
    solve();
  }
  return 0;
}

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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e9 + 7;
const int N = 2e6 + 7;
const int M = 26;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve1()
{
    int n,k;
    cin >> n >> k;
    vector < int > a(n);
    int j = -1;
    for( int i = 0; i < n; i++ ){
        cin >> a[i];
        if( a[i] >= 0 && j == -1 )j = i;
    }
    int ans = 2e9;
    if( j != -1 ){
        for( int i = j; i < n; i++ ){
            if( i + 1 < k )continue;
            if( i - j + 1 >= k )ans = min( ans , a[i] );
            int x = a[i] * 2 + abs(a[i - k + 1]);
            int y = abs(a[i - k + 1]) * 2 + a[i];
            ans = min({ ans , x , y });
        }
    }
    if( j == -1 )j = n;
    for( int i = j - 1; i >= 0; i-- ){
        if( j - i >= k )ans = min( ans , -a[i] );
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 3680
#include<stdio.h>

int main()
{
 int H, W,i,j,bl=0;
 scanf("%d %d",&H,&W);
 int C[H][W],A[H][W],top=0,btm=0,D[H*W][2];
 for (i=0;i<H;i++) {
  for (j=0;j<W;j++) {
   C[i][j]=getchar();
   if (C[i][j]==10 ||C[i][j]==32) {
    C[i][j]=getchar();
   }
   if (C[i][j]==35) bl+=1;
   A[i][j]=0;
   D[i*W + j][0]=0;
   D[i*W + j][1]=0;
  }
 }
 
 while (top<=btm) {
  
  if (D[top][0]<H-1 && A[D[top][0]+1][D[top][1]]==0 && C[D[top][0]+1][D[top][1]]==46) {
   btm+=1;
   D[btm][0]=D[top][0]+1;
   D[btm][1]=D[top][1];
   A[D[top][0]+1][D[top][1]]=A[D[top][0]][D[top][1]]+1;
  }
  if (D[top][0]>0 && A[D[top][0]-1][D[top][1]]==0 && C[D[top][0]-1][D[top][1]]==46) {
   btm+=1;
   D[btm][0]=D[top][0]-1;
   D[btm][1]=D[top][1];
   A[D[top][0]-1][D[top][1]]=A[D[top][0]][D[top][1]]+1;
  }
  if (D[top][1]<W-1 && A[D[top][0]][D[top][1]+1]==0 && C[D[top][0]][D[top][1]+1]==46) {
   btm+=1;
   D[btm][0]=D[top][0];
   D[btm][1]=D[top][1]+1;
   A[D[top][0]][D[top][1]+1]=A[D[top][0]][D[top][1]]+1;
  }
  if (D[top][1]>0 && A[D[top][0]][D[top][1]-1]==0 && C[D[top][0]][D[top][1]-1]==46) {
   btm+=1;
   D[btm][0]=D[top][0];
   D[btm][1]=D[top][1]-1;
   A[D[top][0]][D[top][1]-1]=A[D[top][0]][D[top][1]]+1;
  }
  top+=1;
 }
 if (A[H-1][W-1]==0) {
  printf("-1");
 } else {
  printf("%d",H*W-bl-A[H-1][W-1]-1);
 }
 return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

long long N, K;
vector<long long> P, M, Z;

bool judge_m(long long mid) {
    long long sum = 0;
    REP(i, P.size()) {
        long long tmp = (mid - P[i] + 1) / P[i];
        sum += upper_bound(ALL(M), tmp) - M.begin();
    }
    return sum >= K;
}

bool judge_p(long long mid) {
    long long sum = 0;
    REP(i, P.size()) {
        long long d = mid / P[i];
        long long tmp = upper_bound(ALL(P), d) - P.begin();
        if (i < tmp) tmp--;
        sum += tmp;
    }

    REP(i, M.size()) {
        long long d = mid / M[i];
        long long tmp = upper_bound(ALL(M), d) - M.begin();
        if (i < tmp) tmp--;
        sum += tmp;
    }

    sum /= 2;
    return sum >= K;
}

int main() {
    cin >> N >> K;
    vector<long long> A(N);
    REP(i, N) {
        cin >> A[i];

        if (A[i] > 0) {
            P.push_back(A[i]);
        } else if (A[i] < 0) {
            M.push_back(A[i]);
        } else {
            Z.push_back(A[i]);
        }
    }

    long long p = P.size(), m = M.size(), z = Z.size();
    long long minus = p * m, zero = z * (z - 1) / 2 + z * p + z * m,
        plus = p * (p - 1) / 2 + m * (m - 1) / 2;

    if (K <= minus) {
        sort(ALL(M));
        long long ng = -1e18, ok = -1;
        while (abs(ok - ng) > 1) {
            long long mid = (ok + ng) / 2;
            if (judge_m(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << ok << endl;
    } else if (K <= minus + zero) {
        cout << 0 << endl;
    } else {
        K -= (minus + zero);
        REP(i, m) M[i] = abs(M[i]);
        sort(ALL(P));
        sort(ALL(M));
        long long ng = -1, ok = 1e18;
        while(abs(ok - ng) > 1) {
            long long mid = (ok + ng) / 2;
            if (judge_p(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << ok << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    ll N = S.size();
    if (S == "keyence") {
        cout << "YES" << '\n';
        return;
    }
    rep(i, N) {
        rep2(j, i, N) {
            string t = "";
            rep(k, N) {
                if (i <= k && k <= j) continue;
                t += S[k];
            }
            if (t == "keyence") {
                cout << "YES" << '\n';
                return;
            }
        }
    }
    cout << "NO" << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        double r = scanner.nextDouble();
        double pi = 3.141592653589;
        double area = (double)r * r * pi;
        double Circumference = (double)r * 2 * pi;
        
        System.out.println(String.format("%.6f", area) + " " + String.format("%.6f", Circumference));
    }
}


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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n, k;
ll a[mnx];
ll dp[mnx];

int main(){
    cin >> n; k = 2;

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

    dp[1] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            dp[i + j] = min(dp[i] + abs(a[i] - a[i + j]), dp[i + j]);
        }
    }

    cout << dp[n] << '\n';

    return 0;
}























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

int main()
{
    int a,ans;
    for(int i=1;i<=5;i++)
    {

        cin>>a;

        if(a==0)
        {
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {

	string S,T;

	cin >> S >> T;
	
	int cnt=0;

	for (int i=0; i < 3; i++) {
		if (S[i] == T[i])
			cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxHigh = 0;
		int view = 0;
		for(int i = 0; i < N; i++) {
			int High = sc.nextInt();
			if(maxHigh <= High) {
				maxHigh = High;
				view++;
			}
		}
		System.out.println(view);
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int r;
    cin >> r;
    cout << 2*r*3.141592 << endl;
    return 0;
}


Measured memory_bytes: 3780
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(void)
{
	int L = 0,count=0;
	char S[1][20];
	scanf("%s", S);
	L = strlen(S[0]);
	if (S[0][0] != 'A') {
		printf("WA");
		return 0;
	}
	S[0][0] = 'a';
	for (int i = 2; i <= L - 2; i++) {
		if (S[0][i] == 'C') {
			S[0][i] = 'c';
			count++;
		}
	}
	if (count == 0||count>=2) {
		printf("WA");
		return 0;
	}
	for (int i = 0; i < L; i++) {
		if (islower(S[0][i]) == 0) {
			printf("WA");
			return 0;
		}
	}
	printf("AC");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int arr[1005];
int moder = 1000000007;
int main(){
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		int curr = i;
		for(int j=2; j*j<=curr; j++){
			while(curr%j==0){
				curr/=j;
				arr[j]++;
			}
		}
		arr[curr]++;
	}
	long long ret = 1;
	for(int i=2; i<=n; i++){
		ret*=(arr[i]+1);
		ret%=moder;
	}
	cout<<ret;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, U, V, AB):
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)

    s = [U]
    prev = {}
    prev[U] = -1
    while s:
        u = s.pop()
        for v in g[u]:
            if v in prev:
                continue
            prev[v] = u
            s.append(v)

    p = [V]
    v = V
    while v != U:
        v = prev[v]
        p.append(v)
    p.reverse()
    nu = p[len(p)//2-1]
    ans = len(p)//2-1
    if len(p) % 2 == 1:
        ans += 1

    done = set(p[len(p)//2-1:])

    d = {nu: 0}
    s = [nu]
    while s:
        u = s.pop()
        for v in g[u]:
            if v in done:
                continue
            d[v] = d[u] + 1
            done.add(u)
            s.append(v)

    return ans + max(d.values())





def main():
    N, U, V = read_int_n()
    AB = [read_int_n() for _ in range(N-1)]
    print(slv(N, U, V, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 141560
#include<stdio.h>
#include<limits.h>

/* Merge Sort */
int s[500000];
int cnt = 0;

void merge(int *a, int l, int m, int r){
        int i, j, k;
        int n1 = m-l;
        int n2 = r-m;
        int x[n1+1], y[n2+1];
        for(i=0; i<n1; i++){
                x[i] = a[l+i];
        }
        for(i=0; i<n2; i++){
                y[i] = a[m+i];
        }
        x[n1] = INT_MAX;
        y[n2] = INT_MAX;
        i=0;
        j=0;
        for(k=l; k<r; k++){
                cnt++;
                if(x[i] <= y[j]){
                        a[k] = x[i];
                        i++;
                }else{
                        a[k] = y[j];
                        j++;
                }
        }
}

void mergeSort(int *a, int l, int r){
        int m;
        if((l+1) < r){
                m = (l+r) / 2;
                mergeSort(a, l, m);
                mergeSort(a, m, r);
                merge(a, l, m, r);
        }
}

int main(void){
        int i, N;

        scanf("%d", &N);
        for(i=0; i<N; i++){
                scanf("%d", &s[i]);
        }
        mergeSort(s, 0, N);
        for(i=0; i<N-1; i++){
                printf("%d ", s[i]);
        }
        printf("%d\n", s[i]);
        printf("%d\n", cnt);

        return 0;
}

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

long long a,b,n,x;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    x=100;
    cin>>a>>b>>n;
    x=min(b-1,n);
    cout<<(a*x)/b-(a*(x/b))<<'\n';
}


Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=tuple(map(int1,input().split()))
lr=[() for i in range(Q)]
for i in range(Q):
    l,r=map(int1,input().split())
    lr[i]=(l,r,i)
lr.sort(key=lambda t: -t[1])
class BIT:
    def __init__(self,n):
        self.num=n
        self.dat=[0]*(self.num+1)
        self.depth=n.bit_length()
    
    def add(self,i,x):
        i+=1
        while i<=self.num:
            self.dat[i]+=x
            i+=i&-i
    
    def sum(self,i):
        i+=1
        s=0
        while i>0:
            s+=self.dat[i]
            i-=i&-i
        return s
    
    def lower_bound(self,x):
        sum_=0
        pos=0
        for i in range(self.depth,-1,-1):
            k=pos+(1<<i)
            if k<=self.num and sum_+self.dat[k]<x:
                sum_+=self.dat[k]
                pos+=1<<i
        return pos, sum_

b=BIT(N)
lastap=[-1]*N
ans=[-1]*Q
l,r,j=lr.pop()
for i,x in enumerate(a):
    if lastap[x]!=-1:
        b.add(lastap[x],-1)
    b.add(i,1)
    lastap[x]=i
    while r==i:
        ans[j]=b.sum(r)-b.sum(l-1)
        if lr:
            l,r,j=lr.pop()
        else:
            l,r,j=-1,-1,-1
print(*ans,sep='\n')


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

int main(void) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a+b > c+d){
    cout << "Left" << endl;
  }
  else if (a+b < c+d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
  return 0;
}

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

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

int main()
{
  int w, n, i;
  cin >> w >> n;
  int num[w + 1], a[n + 1], b[n + 1];

  REP(i, w) num[i] = i + 1;
  REP(i, n) scanf("%d,%d" ,&a[i], &b[i]);
  REP(i, n) swap(num[a[i] - 1], num[b[i] - 1]);
  REP(i, w) cout << num[i] << endl;
}

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

string s[111];
int xx, yy;
int h, w;

int solve(int x, int y){

  if(s[y][x] == '.'){ xx = x, yy = y; return true; }
  if(x == w || y == h || x < 0 || y < 0) return false;
  if(s[y][x] == '~') return false;

  char c = s[y][x];
  s[y][x] = '~';

  int ret = false;
  if(c == '>') ret |= solve(x+1, y);
  if(c == '<') ret |= solve(x-1, y);
  if(c == 'v') ret |= solve(x, y+1);
  if(c == '^') ret |= solve(x, y-1);

  return ret;

}

int main(){

  while(cin >> h >> w, h){
    
    for(int i=0;i<h;i++) cin >> s[i];
    
    if(solve(0, 0)) cout << xx << " " << yy << endl;
    else cout << "LOOP\n";
  }
  
}

Measured memory_bytes: 1228
N = int(input())
song = []
for i in range(N):
    s, t = map(str, input().split())
    song.append([s, int(t)])
X = input()
start = False
sleep = 0
for i in song:
    if start:
        sleep = sleep + i[1]
    if i[0] == X:
        start = True
print(sleep)


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}


const int MAXN=100001;
int a[MAXN];
int par[MAXN], rnk[MAXN];

void init(int n){
	REP(i,n){
		par[i] = i;
		rnk[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(rnk[x] < rnk[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rnk[x]==rnk[y]) rnk[x]++;
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> p(n+1,0);
	REP(i,n) cin >> p[i+1];
	
	init(MAXN);
	REP(i,m){
		int x,y;
		cin >> x >> y;
		a[x] = 1;
		a[y] = 1;
		unite(x,y);
	}
	
	int ans = 0;
	FOR(i,1,n+1){
		if(a[i]!=0){
			if(same(i, p[i])) ans++;
		}else{
			if(i==p[i]) ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4756
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int[] n = new int[3];
      for(int i = 0; i < 3; i++)
        n[i] = sc.nextInt();
      Arrays.sort(n);
      System.out.println(n[0] + n[1]);
  }
}

Measured memory_bytes: 23636
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> hvec;
    for(int i = 0 ; i < n ; i++){
        int height;
        cin >> height;
        hvec.push_back(height);
    }

    int result = 1;
    for(int i = 1 ; i < n; i++){
        if(hvec[i] == *max_element(hvec.begin(), hvec.begin() + i + 1)){
            result++;
        } 
    }

    cout << result;

    return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N,H;
  cin>>N>>H;
  vector<ll> v1(N),v2(N);
  FOR(i,0,N){
    cin>>v1[i]>>v2[i];
  }
  ll v1max=0;
  ll res=0,sum=0;

  FOR(i,0,N){
    if(v1[i]>v1max){v1max=v1[i];}
  }

  sort(v2.begin(),v2.end());
  reverse(v2.begin(),v2.end());

  FOR(i,0,N){
    if(v2[i]<v1max || sum>=H )break;
    else{
      sum+=v2[i];
      res++;
    }
  }

  if(sum<H){
    res+=(H-sum)/v1max;
    if((H-sum)%v1max!=0) res++;
    //res++;
    //cout<<v1max<<endl;
  }
  cout<<res<<endl;


}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> line(h);
  for(int i = 0; i < h; i++){
    cin >> line.at(i);
  }
  for(int i = 0; i < w+2; i++){
    cout << "#";
  }
  cout << endl;
  for(int i = 0; i < h; i++){
    cout << "#" + line.at(i) + "#" << endl;
  }
  
  for(int i = 0; i < w+2; i++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 3564
import Foundation

func readInts() -> [Int] {
   return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let _ = Int(readLine()!)!
    let numbers = readInts()
    var ans = 1

    if numbers.contains(0){
        print(0)
        return
    }
    for n in numbers {
        let(partia,isOverFlow) = ans.multipliedReportingOverflow(by: n)
        if isOverFlow || partia > 1000000000000000000 {
            print(-1)
            return
        }
        ans *= n
    }
    print(ans)
}
main()



Measured memory_bytes: 20204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
  int n,m,Q; cin >> n >> m >> Q;
  vector<vector<int> > train(n+1,vector<int>(n+1,0));
  rep(i,m){
      int L,R; cin >> L >> R;
      train[L][R]++;
  }

  rep(i,n)rep(j,n){
      train[i+1][j+1]+=train[i+1][j];
  }

  rep(i,n)rep(j,n){
      train[i+1][j+1]+=train[i][j+1];
  }
 
  vector<int> ans(Q,0);

  rep(i,Q){
    int p,q; cin >> p >> q;
    ans[i]=train[q][q]-train[q][p-1]-train[p-1][q]+train[p-1][p-1];
  }

  rep(i,Q) cout << ans[i] << endl;
return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    int cnt[n + 1] = {};

    for (int i = 1; i < n; i++)
    {
        if (s.substr(i - 1, 2) == "AC")
            cnt[i + 1]++;
        cnt[i + 1] += cnt[i];
    }

    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        OP(cnt[r] - cnt[l]);
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
  int n1,n2,a=0;

  cin >> n1;

  n2 = n1;

  while(n1!=0)
    {
      a += n1%10;
      n1 = n1/10;
    }

  if(n2%a==0)cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

listlist = []
result = {}#辞書型配列の作成
for i in range(0,n):
  num = a[i]
  if num in result:
    result[num] = result[num] + 1
  else:
    result[num] = 1
    
vals = list(result.values())
l = len(vals)

count = 0
for j in range(0,l):
  attack = vals[j]
  count = count + attack*(attack-1)//2#組み合わせ総数

for k in range(0, n):
  block = a[k]
  if block in result:
    fighter = result[block]
    listlist.append(count - fighter +1)
  else:
    listlist.append(count)
     
for si in listlist:
  print(si)


Measured memory_bytes: 28792
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
int a[10010];
int main()
{
    int n,m;
    cin>>n>>m;
    ll sum=0;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    if(sum>n)cout<<"-1"<<endl;
    else cout<<n-sum<<endl;
	return 0;
}


Measured memory_bytes: 3248
#include<stdio.h>
int main(void)
{
	int n,a,b,i;
	scanf("%d%d%d",&n,&a,&b);
	i=n*a;
	if(i<=b)
	{
		printf("%d",i);
	}
	else
	{
		printf("%d",b);
	}
return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int dd,mm,yy;
    scanf("%d/%d/%d",&yy,&mm,&dd);
    if(dd<=30&&mm<=04&&yy<=2019)
    {
        printf("Heisei\n");
    }
    else
    {
        printf("TBD\n");
    }
    return 0;

}


Measured memory_bytes: 128