akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    ll k;
    cin>>k;
    vi a(n);
    rep(i,0,n)cin>>a[i],a[i]--;
    vi vis(n,-1);
    int to=0;
    int cnt=0;
    vi visited;
    while(vis[to]==-1){
       visited.push_back(to+1);
       vis[to]=cnt++;
       to=a[to];
    }
    int loopS=cnt-vis[to];
    if(k<visited.size())cout<<visited[k];
    else{
        int epi=vis[to];
        k-=epi;
        k%=loopS;
        cout<<visited[k+epi]<<endl;
    }
    return 0;
}




Measured memory_bytes: 5896
#include<stdio.h>

main(void)
{
  char kurosiro[100001]={2};
  int i,count=0;
  
  scanf("%s",kurosiro);
  
  for(i=0;i<=100000;i++)
  { if(i!=0)
    {
      if(kurosiro[i]==kurosiro[i-1])
      {
        if('1'==kurosiro[i])
        { kurosiro[i]='0';
        	count++;
        }
         else if('0'==kurosiro[i])
         { kurosiro[i]='1';
           count++;
         }
         }
      
    }
  }
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s < t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}




int main(){

  ll N,K;
  cin >> N >> K;
  vector<ll> a(N);
  FOR(i,0,N){
    cin >> a[i];
  }
  ll ng=0,ok=MOD;//
  while(ok-ng>1){
    ll mid = (ok+ng) / 2;
    ll cnt = 0;
    FOR(i,0,N){
      cnt += a[i] / mid;
      if(a[i]%mid==0)cnt--;
    }
    if(cnt<=K){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  cout << ok << endl;
}




Measured memory_bytes: 4808
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  string ans = "";
  REP(i,2*n){
    if(i%2 == 0){
      ans += s[i/2];
    }else{
      ans += t[i/2];
    }
  }
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 256
package  main

import "fmt"

type eachGrade struct {
	mid int
	final int
	re int
}
func main() {
	for {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		if a == -1 && b == -1 && c == -1 {
			break
		}
		x := eachGrade{mid: a, final: b, re: c}
		if x.mid == -1 || x.final == -1{
			// fmt.Println(x)
			fmt.Println("F")
			continue
		}
		if x.mid + x.final >= 80 {
			// fmt.Println(x)
			fmt.Println("A")
			continue
		}
		if x.mid + x.final < 80 && x.mid + x.final >= 65 {
			// fmt.Println(x)
			fmt.Println("B")
			continue
		}
		if x.mid + x.final < 65 && x.mid + x.final >= 50 {
			// fmt.Println(x)
			fmt.Println("C")
			continue
		}
		if x.mid + x.final < 50 && x.mid + x.final >= 30 {
			if x.re >= 50 {
				// fmt.Println(x)
				fmt.Println("C")
				continue
			} else {
				// fmt.Println(x)
				fmt.Println("D")
				continue
			}
		}
		if x.mid + x.final < 30 {
			// fmt.Println(x)
			fmt.Println("F")
			continue
		}
	}
}


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

using namespace std;

int dp[101][101][5],w,h;

int func(int i, int j, int p){
  if(i>h || j>w)return 0;
  if(i==h && j==w)return 1;
  if(dp[i][j][p]>0)return dp[i][j][p];

  int res=0;
  if(p==1)res=func(i,j+1,3);
  else if(p==2)res=func(i+1,j,4);
  else if(p==3)res=func(i+1,j,2)+func(i,j+1,3); 
  else if(p==4)res=func(i+1,j,4)+func(i,j+1,1);
  else if(p==0)res=func(i,j+1,3)+func(i+1,j,4);

  return dp[i][j][p]=res%100000;
}

int main(void){

  while(cin >> w >> h,w|h){
    for(int i=0;i<101;i++)
      for(int j=0;j<101;j++)
	for(int p=0;p<5;p++)
	dp[i][j][p]=0;

    cout << func(1,1,0) << endl;
  }

  return 0;
}

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

int main(int argc, char *argv[]){
  long long N;
  cin>>N;
  long long A,B;
  for(int i=sqrt(N); i>=1; i--){
    if(N%i==0){
      B=N/i;
      A=N/B;
      break;
    }
  }
  int count=0;
  while(B!=0){
    B/=10;
    count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,a,max=0,i,j=0;
  scanf("%d", &N);

  for(i=0;i<N;i++){
    scanf("%d", &a);
    if(a>=max){
      max=a;
      j++;
    }
  }
  printf("%d",j);
  return 0;
}


Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))

ans = sum(p[i] == (p[i + 1] + p[i] + p[i - 1] - max(p[i + 1], p[i], p[i - 1]) - min(p[i + 1], p[i], p[i - 1])) for i in range(1, n - 1))

print(ans)


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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているか(Aの根)を調べる
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    int size(int A){
        return -parent[root(A)];
    }

    bool unite(int A, int B) {
        A = root(A), B = root(B);
        if(A == B) return false; 

        if(size(A) < size(B)) swap(A,B);
        parent[A] += parent[B];
        parent[B] = A;
        return true;
    }

    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n;
    cin>>n;
    UnionFind uni(n);
    array<int,2> a[n],b[n];
    for(int i=0;i<n;i++){
        int c;
        cin>>c;
        a[i] = {c,i};
    }
    for(int i=0;i<n;i++){
        int c;
        cin>>c;
        b[i] = {c,i};
    }
    sort(a,a+n);
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i][0]>b[i][0]){
            cout << "No\n";
            return 0;
        }
        uni.unite(a[i][1],b[i][1]);
    }
    for(int i=1;i<n;i++){
        if(a[i][0] <= b[i-1][0]){
            cout << "Yes\n";
            return 0;
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        if(i==uni.root(i))cnt++;
    }
    if(cnt>1){
        cout << "Yes\n";
    }
    else cout << "No\n";

}

Measured memory_bytes: 2176
n = (int)(input())
ret = "bon"

one = n % 10
if one == 2 or one == 4 or one == 5 or one == 7 or one == 9:
    ret = "hon"
elif one == 0 or one == 1 or one == 6 or one == 8:
    ret = "pon"

print("{}".format(ret))

Measured memory_bytes: 9112
#include<stdio.h>
#include<ctype.h>

main() {
	int count[26] = {0};
	char ch;
	int i, num;

	while (scanf("%c", &ch) != EOF) {
		if (islower(ch)) {
			num = ch - 'a';
		} else if (isupper(ch)) {
			num = ch - 'A';
		} else {
			continue;
		}

		count[num]++;

	}

	for (i = 0; i < 26; i++) {
		printf("%c : %d\n", 'a' + i, count[i]);
	}

	return 0;

}

Measured memory_bytes: 544
#coding: utf-8
import math
import heapq
import bisect

MOD = 2019

L,R = map(int, input().split())

if R-L+1 >= MOD:
    ans=0
else:
    L = L%MOD
    R = R%MOD
    if R < L:
        ans=0
    else:
        ans=MOD
        for l in range(L,R):
            for r in range(l+1,R+1):
                ans=min(ans,l*r%MOD)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M,a,b;
  cin >> N;
  vector<int> G[N];
  for (cin >> M; M; M--) {
    cin >> a >> b;
    G[--a].push_back(--b);
    G[b].push_back(a);
  }
  queue<int> q;
  int d[N];
  vector<bool> visited(N);
  for (q.push(0), d[0] = 0, visited[0] = true; !q.empty(); q.pop()) {
    for (int v : G[q.front()]) {
      if (!visited[v]) {
        visited[v] = true;
        q.push(v);
        d[v] = d[q.front()]+1;
      }
    }
  }
  if (d[N-1] == 2) {
    cout << "POSSIBLE";
  } else {
    cout << "IMPOSSIBLE";
  }
}

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

using namespace std;

vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

  cout << a[K-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);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; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
	int a,b,c,d;	
  	cin>>a>>b>>c>>d;
  
  	int e,f,g,h;
  	int x=c-a,y=d-b;
  	
	cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x<<" "<<endl;
}

Measured memory_bytes: 3624
"use strict";

var processData = function processData(lines) {
  var x = +lines[0];
  var r = Math.floor(x / 500);
  var f = Math.floor(x % 500 / 5);
  console.log(r * 1000 + f * 5);
};

var i = '';
process.stdin.on('data', function (c) {
  return i += c;
});
process.stdin.on('end', function () {
  var _require = require('os'),
      EOL = _require.EOL;

  var lines = i.split(EOL);
  /*your input text, split by lines*/

  processData(lines);
});


Measured memory_bytes: 21320
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
using ll=long long;
using vll=vector<ll>;


#define MOD 998244353


ll mod_pow(ll x, ll n, ll m)
{
	ll ret = 1LL;
	for(;n>0;n>>=1)
	{
		if(n&1) ret=(ret*x)%m;
		x=(x*x)%m;
	}
	return ret;
}


ll mod_inv(ll x, ll m)
{
	return mod_pow(x, m-2, m)%m;
}


ll nCr(vll&f, vll&f_i, int n, int r)
{
	return (((f[n]*f_i[r])%MOD)*f_i[n-r])%MOD;
}


int main(void)
{
	ll n, a, b, k;
	vll fact(300000+1);
	vll fact_inv(300000+1);

	{
		fact[0]=fact_inv[0]=1;
		for(int i=1;i<=300000;i++)
		{
			fact[i]=(fact[i-1]*i)%MOD;
			fact_inv[i]=mod_inv(fact[i], MOD);
		}
	}

	while(scanf("%lld%lld%lld%lld", &n, &a, &b, &k)==4)
	{
		ll ans=0;

		for(ll x=min(k/a, n);x>=0;x--)
		{
			ll lans=0;
			ll r=k-a*x;
			if(r%b) continue;

			ll y=r/b;
			if(y>n) break;
/*
			for(ll cn=max(0LL, x+y-n);cn<=x && cn<=y;cn++)
			{
				ll an=x-cn;
				ll bn=y-cn;
				ll dn=n-an-bn-cn;
				lans=fact[n];
				lans=(lans*fact_inv[an])%MOD;
				lans=(lans*fact_inv[bn])%MOD;
				lans=(lans*fact_inv[cn])%MOD;
				lans=(lans*fact_inv[dn])%MOD;
//				printf("an=%lld bn=%lld cn=%lld dn=%lld  lans=%lld\n", an, bn, cn, dn, lans);
				ans=(ans+lans)%MOD;
			}
*/
			ll t=nCr(fact, fact_inv, n, x);
			t=(t*nCr(fact, fact_inv, n, y))%MOD;
//			printf("x=%lld y=%lld  t=%lld\n", x, y, t);
			ans=(ans+t)%MOD;
		}
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 4864
import sys
input = sys.stdin.readline

n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

ans = 0
now = 0
for _ in range(n):
    now = a[now] -1 
    ans += 1
    if(now == 1):
        print(ans)
        exit()

print(-1)

Measured memory_bytes: 7084
#include<stdio.h>
int main(void){
  int n, q, num, i, j;
  int a[2001] = {1};
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &num);
    for(j= 2000-num;j>=0 ; j--){
      if(a[j]) a[j + num] = 1;
    }
  }

  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &num);
    if(a[num]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
		 

Measured memory_bytes: 588
n,m=map(int,input().split())
l=[set() for _ in range(n+1)]

for i in range(m):
  a,b=map(int,input().split())
  l[a].add(b)
  l[b].add(a)

from collections import deque

vi=[0 for _ in range(n+1)]
st=deque([i,i] for i in range(1,n+1))

while st:
  c,d=st.popleft()

  if vi[c]==0 :
    vi[c]=d
    for m in l[c]:
      st.appendleft([m,d])
from collections import Counter
s=Counter(vi)
mx=0
for m in s.values():
  mx=max(mx,m)
print(mx)
  


Measured memory_bytes: 106284
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
const int MOD = 1000000007;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
 
int main(){
  int n,m;cin >> n >> m;
  int sum[m];
  for(int i =0;i<m;i++) sum[i]=0;
  int k,ai;
  rep{
    cin >> k;
    for(int j  =0;j<k;j++){
      cin >> ai;sum[ai-1] += 1;
    }
  }
  int ans = 0;
  for(int i = 0;i<m;i++){
    if(sum[i]==n) ans +=1;
  }
  cout << ans << endl;
}

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 X = sc.nextInt();
      
      if(500*N >= X) {
      	System.out.print("Yes");
      } else {
      	System.out.print("No");
      }
	
	return;

	}
}

Measured memory_bytes: 22228
#include <stdio.h>

int main(void)
{
    int N;
    scanf("%d", &N);

    if (N % 10 == 7)
        printf("Yes");
    else
    {
        if ((N / 10) % 10 == 7)
            printf("Yes");
        else
        {
            if ((N / 100) % 10 == 7)
            printf("Yes");
            else
            {
                printf("No");
            }
            
        } 
    }
    return 0;
    
}

Measured memory_bytes: 1728
#coding: utf-8
N = int(input())
ans = 0
for num in range(1, N+1):
    cnt = 0
    for i in range(1, num+1):
        if num % i == 0 and num % 2 == 1:
            cnt += 1
    if cnt == 8:
        ans += 1
print(ans)

Measured memory_bytes: 2940
s=input()
a = s
isum=0
k=0
for i in range(2**(len(s)-1)):
    for j in range(len(s)-1):
        if ((i>>j) & 1):
            #print(bin(i))
            a = a[:j+k+1] + "+" + a[j+k+1:]
            k +=1
            #print(a,j)
    k=0
    isum += sum(list(map(int, a.split("+"))))
    a=s
print(isum)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int minN = sc.nextInt()-1;
        for(int i=0;i<n-1;i++){
            int h = sc.nextInt();
            if( minN == h){
                minN = h;
            }else if(minN == h-1){
                minN = h-1;
            }else if(minN < h-1){
                minN = h-1;
            }else if(minN > h){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 48252
from math import floor
import numpy as np

N = int(input())
K = floor((N * 2) ** 0.5)
if K * (K + 1) // 2 != N:
    print('No')
    exit()
else:
    print('Yes')
    print(K + 1)

grid = np.ones((K, K), np.int64)
grid[1:, 0] = np.arange(1, K)
grid[:, 0] = np.cumsum(grid[:, 0])
grid = np.cumsum(grid, axis=1).astype(str)
answer = []
k = str(K)
answer.append([k] + np.diag(grid).tolist())
answer.append([k] + grid[:, 0].tolist())
for i in range(1, K):
    answer.append([k] + grid[i, :i].tolist() + grid[i:, i].tolist())

print('\n'.join(map(' '.join, answer)))


Measured memory_bytes: 49180
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	char X, Y;
	cin >> X >> Y;

	if (X == Y) {
		cout << "=" << endl;
	}
	else if (X < Y) {
		cout << "<" << endl;
	}
	else {
		cout << ">" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 15;
const ll LINF = 1e18 + 5;
int x[N][N], n, d;
int ans;
int sqr(int a) { return a*a; }
bool check(int a, int b)
{
	int dis = 0;
	for(int i=1;i<=d;i++)
		dis += sqr(x[a][i]-x[b][i]);
	int tmp = sqrt(dis);
	return tmp*tmp==dis;
}	
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> d;
 	for(int i=1; i<=n; i++)
 		for(int j=1; j<=d; j++)
 			cin >> x[i][j];
 	for(int i=1; i<=n; i++)
 		for(int j=i+1; j<=n; j++)
 			if(check(i, j)) ans++;
 	cout << ans;
	return 0;
}


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

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

typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll A,B; cin >> A >> B;
    cout << lcm(A,B) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[n-i-1] = sc.nextInt();
        }
        for(int i=0;i<n-1;i++){
            int tmp = a[i+1] - a[i];
            if(tmp > 1){
                System.out.println("No");
                return;
            }
            if(tmp > 0){
                a[i+1]--;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 49864
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    try {
      Scanner sc = new Scanner(is);
      String s = sc.next();
      int begin = Integer.parseInt(s.substring(0, 2));
      int end = Integer.parseInt(s.substring(2, 4));
      boolean isYYMM = isYYMM(begin, end);
      boolean isMMYY = isYYMM(end, begin);
      if (isYYMM && isMMYY) {
        pw.println("AMBIGUOUS");
        return;
      }
      if (!isYYMM && !isMMYY) {
        pw.println("NA");
        return;
      }
      if (isYYMM) {
        pw.println("YYMM");
        return;
      }
      if (isMMYY) {
        pw.println("MMYY");
        return;
      }
    } catch (RuntimeException e) {
      pw.println("NA");
      return;
    }
  }

  static boolean isYYMM(int yy, int mm) {
    return isYear(yy) && isMonth(mm);
  }

  static boolean isYear(int yy) {
    return yy >= 0;
  }

  static boolean isMonth(int mm) {
    return 1 <= mm && mm <= 12;
  }
}


Measured memory_bytes: 23892
def main():
    N, x = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    ans = 0
    if A[0] > x:
        ans = A[0] - x
        A[0] = x
    for i in range(N-1):
        if A[i] + A[i + 1] > x:
            ans += A[i] + A[i + 1] - x
            A[i + 1] = A[i + 1] - (A[i] + A[i + 1] - x)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 63984
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------

int main(void)
{
  double n = 100;
  LL y;
  double x;
  int ans = 1;
  scanf("%lf",&x );
  while (1) {
    n *= 1.01;
    y = (LL)n;
    n = (double)y;
    if (n >= x) {
      printf("%d", ans);
      return 0;
    }
    ans++;
  }
}


Measured memory_bytes: 1748
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
struct node {
	int a,b,id;
	node (int a=0,int b=0,int id=0): a(a),b(b),id(id) {}
	friend bool operator <(node A,node B) { return A.b<B.b; }
};
int n;
priority_queue<node> q;
int a[N],b[N];
int main() {
	rd(n);
	for(int i=1;i<=n;++i) rd(a[i]);
	for(int i=1;i<=n;++i) rd(b[i]);
	for(int i=1;i<=n;++i) {
		if(b[i]<a[i]) {
			printf("-1");
			exit(0);
		}
		if(a[i]!=b[i]) q.push(node(a[i],b[i],i));
	}
	ll ans=0;
	while(!q.empty()) {
		int u=q.top().id; q.pop();
		int pre=u==1?n:u-1;
		int suf=u==n?1:u+1;
		int tmp=b[u]-a[u];
		if(b[pre]+b[suf]>tmp) { printf("-1"); exit(0); }
		ans+=tmp/(b[pre]+b[suf]);
		b[u]-=(b[pre]+b[suf])*(tmp/(b[pre]+b[suf]));
		if(b[u]!=a[u]) q.push(node(a[u],b[u],u));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6388
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#define pb push_back

typedef long long LL;

const int N=100005;

int n,size[N],id[N],ans1[N],ans2[N];
LL tot,a[N];
std::map<LL,int> num;
std::vector<int> vec[N];

bool cmp(int x,int y)
{
	return a[x]>a[y];
}

void dfs(int x,int fa,int d)
{
	tot+=(LL)d;
	for (int i=0;i<vec[x].size();i++)
		if (vec[x][i]!=fa) dfs(vec[x][i],x,d+1);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),num[a[i]]=i;
	for (int i=1;i<=n;i++) size[i]=1,id[i]=i;
	std::sort(id+1,id+n+1,cmp);
	for (int i=1;i<n;i++)
	{
		int x=id[i];LL w=a[x]-(n-size[x])+size[x];
		if (!num[w]||w>=a[x]) {puts("-1");return 0;}
		int y=num[w];
		ans1[i]=x;ans2[i]=y;
		vec[x].pb(y);vec[y].pb(x);
		size[y]+=size[x];
	}
	dfs(id[n],0,0);
	if (tot!=a[id[n]]) {puts("-1");return 0;}
	for (int i=1;i<n;i++) printf("%d %d\n",ans1[i],ans2[i]);
	return 0;
}

Measured memory_bytes: 18560
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
vector<int>a[200010];
int sum[200010] = {};
bool b[200010] = {};
void ki(int n) {
	rep(i, a[n].size()) { 
		if (b[a[n][i]]==false) {
			sum[a[n][i]] += sum[n];
			b[a[n][i]] = true;
			ki(a[n][i]);
		}
	}
	return;
}
int n, ans;
int dfs(int a, bool b3, bool b5, bool b7) {
	if (a > n)return ans;
	if (b3 && b5 && b7)ans++;
	dfs(a * 10 + 3, true, b5 , b7);
	dfs(a * 10 + 5, b3, true, b7);
	dfs(a * 10 + 7, b3, b5, true);
	return ans;
}
signed main() {
	cin >> n;
	cout << dfs(0, false, false, false) << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

int main(){
  int a,b;
  cin>>a>>b;
  bool flg=true;
  if(a%3&&b%3&&(a+b)%3)flg=false;
  cout<<(flg?"Possible":"Impossible")<<endl;
  return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}
	
	vector<string> s(3);
	s[0] = "Sunny";
	s[1] = "Cloudy";
	s[2] = "Rainy";

	string x;
	cin >> x;

	if(s[0].compare(x) == 0){
		cout << s[1];
	}else if(s[1].compare(x) == 0){
		cout << s[2];
	}else{
		cout << s[0];
	}

    return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> T(N);
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> T.at(i);
        sum += T.at(i);
    }
    
    int M; cin >> M;
    for(int i = 0; i < M; i++){
        int p, x; cin >> p >> x;
//        cout << T.at(p - 1) << endl;
        int ans = sum - T.at(p - 1) + x;
        cout << ans << endl;
        
    }    
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,m,k; cin >> n >> m >> k;

    UnionFind uft(n);

    std::vector<int> friend_count(n,0);

    rep(i,m){
        int a,b; cin >> a >> b; --a; --b;
        friend_count[a]++;
        friend_count[b]++;
        uft.unionSet(a,b);
    }

    std::vector<std::vector<int>> blocking(n, std::vector<int>(0));

    rep(i,k){
        int c,d; cin >> c >> d; --c; --d;
        blocking[c].push_back(d);
        blocking[d].push_back(c);
    }


    rep(i,n){

        int ans = uft.size(i) - friend_count[i];

        rep(j, blocking[i].size()){
            int x = blocking[i][j];
            if(uft.root(x)==uft.root(i)) ans--;
        }

        cout << ans-1 << " ";

    }

    cout << '\n';
    
    

    return 0;
}

Measured memory_bytes: 6784
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    if(num%1000 == 0)
      System.out.println(0);
    else
      System.out.println(1000-num%1000);
  }
}

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

#define input(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    long double a;cin>>a;
    long double b=a/(long double)3.0;
    cout<<fixed<<setprecision(12)<<(long double)(b*b*b)<<"\n";
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

string output(vector<int> z){
    string s,st;
    int zs = z.size() - 1;
    REP(k, zs){
        st = to_string(z[k]);
        s = s + st + " ";
      }
      st = to_string(z[zs]);
      s = s + st;
      return s;
  }
int main(){
  int n,at,v,j;
  vector<int> a;
  string ans;
  cin >> n;
  REP(c, n){
      cin >> at;
      a.pb(at);
    }
    REP(i, n){
        j = i - 1;
        v = a[i];
        while(j >= 0 && a[j] > v){
            a[j + 1] = a[j];
            j--;
          a[j+1] = v;
        }
     ans = output(a);
     cout << ans << endl;
     
    }
    }



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;cin>>N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin>>L[i];
    }sort(L.begin(),L.end());
    int sum=0;
    for(int j=0;j<=N-2;j++){
        sum+=L[j];
    }if(sum>L[N-1]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <functional>
template<typename T>
class SegmentTreeAllOne {
    using Func = function<T(T, T)>;

public:
    vector<T> data;
    int n;
    T init;
    Func update_func;
    SegmentTreeAllOne(int _n, T _init, Func up) {
        init = _init;
        update_func = up;
        for (n = 1; n < _n; n *= 2)
            ;
        data.resize(2 * n - 1, init);
    }
    void update(int l, int r, T val) {
        for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) {
            if (!(l & 1)) {
                data[l] = update_func(data[l], val);
            }
            if (!(r & 1)) {
                data[r - 1] = update_func(data[r - 1], val);
            }
        }
    }
    T query(int pos) {
        pos += n - 1;
        T res = data[pos];
        while (pos > 0) {
            pos = (pos - 1) / 2;
            res = update_func(res, data[pos]);
        }
        return res;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, q;
    cin, n, q;
    ll ans = 0;
    auto mn = [&](ll a, ll b) {
        return min(a, b);
    };
    SegmentTreeAllOne<ll> seg1(n, n - 1, mn), seg2(n, n - 1, mn);
    REP(i, 0, q) {
        int a, x;
        cin, a, x;
        x--;
        if (a == 1) {
            int b = seg1.query(x);
            ans += b - 1;
            seg2.update(0, b, x);
        } else {
            int b = seg2.query(x);
            ans += b - 1;
            seg1.update(0, b, x);
        }
    }
    print((n - 2) * (n - 2) - ans);
    return 0;
}


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

int main(){
  int w,h;
  cin>>w>>h;
  vector<P>v;
  rep(i,w){
    int x; cin>>x;
    v.push_back(P(x,0));
  }
  rep(i,h){
    int x; cin>>x;
    v.push_back(P(x,1));
  }
  sort(v.begin(),v.end());
  w++; h++;
  ll ans=0;
  rep(i,v.size()){
    if(v[i].second==1)ans+=(ll)w*v[i].first,h--;
    else ans+=(ll)h*v[i].first,w--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5372
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"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) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

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()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	allDone := false
	min := int(1e+10)
	for !allDone {
		allDone = true
		sort.Ints(A)
		min = A[0]
		for i := 1; i < N; i++ {
			if A[i]%min != 0 {
				A[i] = A[i] % min
				if A[i] < min {
					min = A[i]
				}
				allDone = false
			}
		}
	}
	fmt.Println(min)
}


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

int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<std::vector<bool>> hen(n,std::vector<bool>(n));
    for(int i = 0; i < m; i++){
        int a,b; std::cin >> a >> b; a--; b --;
        hen[a][b] = true;
        hen[b][a] = true;
    }
    int cnt = 0;
    std::vector<int> path(n);
    std::iota(path.begin(),path.end(),0);
    do{
        if(path[0] != 0)continue;
        bool res = true;
        for(int i = 1; i < n; i++){
            if(!hen[path[i - 1]][path[i]])res = false;
        }
        if(res)cnt++;
    }while(std::next_permutation(path.begin(),path.end()));
    std::cout << cnt << std::endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  
  int base = h.at(0), cnt = 0;
  for (int i = 0; i < n; i++) {
    if (base - h.at(i) >= 2) {
      cout << "No" << endl;
      return 0;
    }
    
    if (base < h.at(i)) {
      base = h.at(i);
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		double n = sc.nextDouble();
		double k = sc.nextDouble();
		double cnt = k * Math.pow(k - 1, n-1);
		System.out.println((int)cnt);
	}
}

Measured memory_bytes: 25044
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1)

int w,h;
int c[50][50];

void dfs(int i, int j){
  c[i][j] = 0;
  for(int dx = -1; dx <= 1; dx++){
    for(int dy = -1; dy <= 1; dy++){
      int nx = i + dx, ny = j + dy;
      if(0 <= nx && nx < h && 0 <= ny && ny < w && c[nx][ny] == 1){
        dfs(nx, ny);
      }
    }
  }
}

void solve(){
  int cnt = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(c[i][j] == 1){
        dfs(i, j);
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

int main(){
  while(cin >> w >> h && w, h){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> c[i][j];

      }
    }
    solve();
  }
}

Measured memory_bytes: 1348
#include <stdio.h>
#include <stdlib.h>
 
 
int main(){
    int score;
    int A,B,C,K;
    scanf("%d %d %d %d",&A,&B,&C,&K);
    if(K<=A){
        score = K;
    }else if(K<=A+B){
        score = A;
    }else{
        score = 2*A+B-K;
    }
 
    printf("%d\n",score);
    return 0;
}

Measured memory_bytes: 1732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int m = in.nextInt();
			List<Integer> list1 = new ArrayList<>();
			boolean[] listn = new boolean[200001];
			for (int i = 0; i < m; i++) {
				int[] path = in.nextIntArray(2);
				if (path[0] == 1) {
					list1.add(path[1]);
				} else if (path[1] == 1) {
					list1.add(path[0]);
				} else if (path[0] == n) {
					listn[path[1]] = true;
				} else if (path[1] == n) {
					listn[path[0]] = true;
				}
			}

			for (int i2x : list1) {
				if (listn[i2x]) {
					out.print("POSSIBLE");
					return;
				}
			}
			out.println("IMPOSSIBLE");

		}

	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 47128
from collections import Counter

N,X,Y = map(int,input().split())
#print(N)
X,Y = X-1, Y-1

lst = list(range(1,N+1))
d_lst = []
for left in range(0,N-1):
    for right in range(left+1,N):
        dis = min(right - left, abs(X-left) + abs(right-Y) +1)
        d_lst.append(dis)
c = Counter(d_lst)
            
for i in range(1,N):
    if i in c:
        print(c[i])
    else:
        print(0)
            
    

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

int main()
{
    int N;
    int s[1000], p[1000], q[1000], r[1000], c[1000];
    int P, Q, R, C;
    
    while(cin >> N, N){
        
        bool check = false;
        
        for(int i = 0; i < N; i++){
            cin >> s[i] >> p[i] >> q[i] >> r[i];
            c[i] = (4 * p[i]) + (9 * q[i]) + (4 * r[i]);
        }
        
        cin >> P >> Q >> R >> C;
        
        for(int i = 0; i < N; i++){
            if(p[i] <= P && q[i] <= Q && r[i] <= R && c[i] <= C) {
                check = true;
                cout << s[i] << endl;
            }
        }
        
        if(!check) cout << "NA" << endl;
    }
    
}


Measured memory_bytes: 3116
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

string solve(string s) {
    int w = read();
    string r;
    foreach (i, c; s) if (i % w == 0) r ~= c;
    return r;
}

void main() {
    writeln(readln.chomp.solve);
}


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

map<int, int> cnts;

int main(){
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		int x; cin >> x; 
		cnts[x]++;
	}
	vector<int> vals;
	//check if vals has size exactly three
	for (auto a: cnts){
		if ((a.second * 3) % n != 0){
			cout << "No" << endl;
			return 0;
		}
		for (int i = 0; i < (a.second * 3) / n; i++){
			vals.push_back(a.first);
		}
	}
	if ((vals[0] ^ vals[1] ^ vals[2]) == 0){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0; 
}


Measured memory_bytes: 3840
n=int(input())
ls=list(map(int,input().split()))
ls.sort(reverse=True)
ans=ls[0]
pls=[ls.pop(0),ls.pop(0)]#入った人を突っ込む
cnt=0#plsの隣使いきりカウント
scnt=0#2人行けるからそこのカウント

for i in ls:
  pls.append(i)
  ans+=pls[cnt+1]
  if scnt==0:
    scnt=1
  else:
    scnt=0
    cnt+=1
print(ans)


Measured memory_bytes: 31568
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;

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

bool b[100010];
unordered_map<ll,int> mp;

int main(){
    ll n;cin>>n;
    ll a[n];
    int c=1;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(mp[a[i]]==0){
            mp[a[i]]=c;
            c++;
        }
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(b[mp[a[i]]]){
            ans--;
            b[mp[a[i]]]=false;
        }else{
            ans++;
            b[mp[a[i]]]=true;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

using ll = long long;
using pii = pair<int, int>;

void solve() {
    string s;
    cin >> s;
    for (int i = 1; i < sz(s); i++) {
        if (s[i - 1] == s[i])
            return void(cout << i << ' ' << i + 1);
        if (i > 1 && s[i - 2] == s[i])
            return void(cout << i - 1 << ' ' << i + 1);
    }
    cout << "-1 -1";
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}



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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int N = ReadInt();
        int[] p = ReadInts();
        int cnt = 0;
        int tmp = 0;
        for (int i = 0; i < N; i++)
        {
            if (p[i] == i + 1)
            {
                continue;
            }
            else
            {
                if (cnt == 0)
                {
                    cnt++;
                    tmp = p[i];
                }
                else if (cnt == 1)
                {
                    if (i + 1 == tmp)
                    {
                        cnt++;
                    }
                    else
                    {
                        return "NO";
                    }
                }
                else
                {
                    return "NO";
                }
            }
        }
        return "YES";
    }

    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 11220