akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S = in<string>();
    string answer = "";
    REP(i,S.size()){
        if(S[i] != 'B'){
            answer += S[i];
        }else if(answer != ""){
            answer.erase(answer.size()-1);
        }
    }
    cout << answer << "\n";
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

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 () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int k;
	cin >> k;
	cout << a[k - 1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    cin >> a;
    cin >> op;
    cin >> b;
    
    while(true){
        if ( op == '+' ){
            cout << a + b;
        }
        else if ( op == '-' ){
            cout << a - b;
        }
        else if ( op == '*' ){
            cout << a * b;
        }
        else if( op == '/'){
            cout << a / b;
        }
        else{
            break;
        }
        cin >> a;
        cin >> op;
        cin >> b;
        cout << endl;
    }
    
}


Measured memory_bytes: 3084
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BRACK 2
void dfs_init(int);
void dfs();
int n,M[N][N];
int color[N],d[N],f[N],time;


int main(){
  int i,j,u,v,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}

void dfs_init(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(color[v] == WHITE){
      dfs_init(v);
    }
  }
  color[u] = BRACK;
  f[u] = ++time;
}
void dfs(){
  int u;
  for(u=0;u<n;u++)color[u] = WHITE;
  time = 0;
  
  for(u=0;u<n;u++){
    if(color[u] == WHITE) dfs_init(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}



Measured memory_bytes: 2060
package main

import (
	"fmt"
)

func main() {
	var A int
	var B int
	var C int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&C)
	for i := 1; i <= B; i++ {
		if (A*i)%B == C {
			fmt.Println("YES")
			break
		}
		if i == B {
			fmt.Println("NO")
		}
	}
}


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

int main(){
  ll A,B,C,D;cin>>A>>B>>C>>D;A--;
  ll dc=0;
  if(C<D)swap(C,D);
  ll c=C,d=D,e;
  while(c%d){
    e=d;d=c%d;c=e;
  }
  dc=C*D/d;
/*  while(1){
    dc+=C;
    if(dc%D==0)break;
    else if(dc>B){dc=0;break;}
  }
*/ 
  ll ans=B-B/C-B/D;
  if(dc)ans+=B/dc;
  ans-=A-A/C-A/D;
  if(dc)ans-=A/dc;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

// 0:kと一致、1:k未満が確定
ll dp[41][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    for(int i = 0; i <= 40; ++i){
        for(int j = 0; j < 2; ++j){
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;
    
    // 40bit
    for(int i = 0; i < 40; ++i){
        ll mask = (1LL << (39 - i));
        
        int cnt = 0;
        for(int j = 0; j < n; ++j){
            if(a[j] & mask)     ++cnt;
        }
        
        ll cost0 = mask * cnt;          // Xの左から(i+1)桁目を0にする
        ll cost1 = mask * (n - cnt);    // Xの左から(i+1)桁目を1にする
        
        // i桁目までで(X < k)が確定している
        if(dp[i][1] != -1){
            // 制約がない
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + max(cost0, cost1));
        }
        
        // (i+1)桁目でk未満に確定させる
        if(dp[i][0] != -1){
            if(k & mask){   // kの(i+1)桁目が1ならば、Xの(i+1)桁目を0にする
                dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + cost0);
            }
        }
        
        // (i+1)桁目までkと一致させる
        if(dp[i][0] != -1){
            // (i+1)桁目までkと完全に一致させる
            if(k & mask){   
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + cost1);
            }
            else{
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + cost0);
            }
        }
    }
    
    cout << max(dp[40][0], dp[40][1]) << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
    int a,b,c,d=0;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    printf("%d %d %d %d",c+b-d,d+c-a,a+b-d,b+c-a);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {


	//final int MOD = 1000000007;


	public static void main(String[] args) {

		double ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int n = sc.nextInt();
//		int k = sc.nextInt();

		//-------------------------------------------------------------------------------------

		ans = 2 * Math.PI * n;


		//-------------------------------------------------------------------------------------

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mod = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s,t;
    cin>>s>>t;
    int n = (int)s.size();
    int m = (int)t.size();
    string ret("z",n);
    for(int i=0;i<n-m+1;++i){
        bool ok = true;
        for(int j=0;j<m;++j){
            if(s[i+j] != '?' and s[i+j] != t[j]){ok=false;break;}
        }
        if(ok){
            string tmp;
            tmp = s;
            for(int j=0;j<m;++j)tmp[i+j] = t[j];
            for(int j=0;j<n;++j)if(tmp[j] == '?')tmp[j] = 'a';
            if(tmp < ret)ret = tmp;
        }
    }
    if(ret == string("z",n)){
        cout << "UNRESTORABLE" << endl;
    }else cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3656
import java.util.*;


public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        
        int a = s.nextInt();
        int b[] = new int[a];

        int count = 0;

        for (int i = 0; i < a; i++) {
            b[i] = s.nextInt();
            
            if (b[i] != (i+1)) {
                count++;
            }
        }

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const int INF = 1e9;

int main() {
    int N, M;
    string S;
    cin >> N >> M >> S;
    reverse(all(S));
    vl pos_zero(1,0);
    rep(i,N) {
        if (S[i+1] == '0') {
            pos_zero.push_back(i+1);
        }
    }
    int pre = 0, isOk = 1;
    vl ans;
    while (pre < N) {
        int now = *(upper_bound(all(pos_zero), pre+M) - 1);
        if (now - pre == 0) {
            isOk = 0;
            break;
        }
        ans.push_back(now - pre);
        pre = now;
    }
    reverse(all(ans));
    if (isOk) {
        int n = ans.size();
        rep(i,n) {
            cout << ans[i] << " \n"[i==n-1];
        }
    } else {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5692
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const ll maxn=(3*1e3)+5;
const int N = 1e5;
int main()
{
    ll n;
    cin>>n;
    ll c=1;
    ll s=0;
    ll x=n;
    while(c<n)
    {
        x=n/c;
        if(n%c==0)
            s=s+x-1;
        else
            s=s+x;
        c++;
    }
    cout<<s<<"\n";
    cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3536
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

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

int w;
int h;
char gr[N][N];
int dp1[2][N][N];
int dp2[2][N][N];

int main(){
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> gr[i][j];
        }
    }
    for(int i = h; i >= 1; i--){


        for(int j = w; j >= 1; j--){
            if(gr[i][j] == '.')
                dp1[0][i][j] = dp1[0][i][j + 1] + 1;
            else
                dp1[0][i][j] = 0;
        }
        for(int j = 1; j <= w; j++){
            if(gr[i][j] == '.')
                dp1[1][i][j] = dp1[1][i][j - 1] + 1;
            else
                dp1[1][i][j] = 0;
        }


    }
    for(int j = 1; j <= w; j++){
        for(int i = 1; i <= h; i++){
            if(gr[i][j] == '.')
                dp2[0][i][j] = dp2[0][i - 1][j] + 1;
            else
                dp2[0][i][j] = 0;
        }
        for(int i = h; i >= 1; i--){
            if(gr[i][j] == '.')
                dp2[1][i][j] = dp2[1][i + 1][j] + 1;
            else
                dp2[1][i][j] = 0;
        }
    }
    int best = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            int a = dp1[0][i][j] + dp1[1][i][j] - 1;
            int b = dp2[0][i][j] + dp2[1][i][j] - 2;
            best = max(best , a+b);
        }
    }
    cout << best << endl;
}

Measured memory_bytes: 66944
#include <iostream>
#include <vector>

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

int max(int a,int b){
    if(a>b)return a;
    else return b;
}
int mac(int a,int b,int c){
    if(a>b&&a>c){
        return a;
    }else if(b>a&&b>c){
        return b;
    }else 
        return c;
}
int main (){
    int N;
    cin >> N;
    //N = 100000;
    vector<int> a(N+2);
    vector<int> b(N+2);
    vector<int> c(N+2);
    //vector<vector<ll> > dp(N+2,vector<ll>(N+2));
    ll dp[100002][5];

    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i] >> c[i];
        //a[i] = 10000;
        //b[i] = 10000;
        //c[i] = 10000;
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    int i;
    for(i=1;i<N;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][2],dp[i-1][0])+b[i];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout << mac(dp[N-1][0],dp[N-1][1],dp[N-1][2])<<endl;
    return 0;

}




Measured memory_bytes: 5376
N = int(input())
A, B = map(int, input().split())

p = list(map(int, input().split()))
p.sort()
a = 0
b = 0
c = 0
for tmp in p:
    if tmp <= A:
        a += 1
    elif A + 1 <= tmp <= B:
        b += 1
    else:
        c += 1

ans = min(a, b)
ans = min(ans, c)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a,b;
  int f=0;
  cin >> a >> a >> a >> b;
  if(a!=b) f=1;
  cin >> a >> b;
  if(a!=b) f=1;
  if(f==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

#define MAXN 100
int N,M;
string str;
multiset<string> Blue,Red;

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        cin>>str;
        Blue.insert(str);
    }
    scanf("%d",&M);
    for(int i=1;i<=M;i++){
        cin>>str;
        Red.insert(str);
    }
    int Ans=0;
    for(multiset<string>::iterator i=Blue.begin();i!=Blue.end();i++)
        Ans=max(Ans,int(Blue.count(*i)-Red.count(*i)));
    printf("%d",Ans);
}


Measured memory_bytes: 256
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main() {
    int x, y,w;
    cin >> x >> y;
    double z = double (x + y) / 2;double a;
    w = int(z);
   
    a = z - w;
    
    if (a >= .5)
        cout << w + 1;
    else
        cout << w;


}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  vector<int>pri;
  pri.push_back(2);
  for(int i=3;;i+=2){
    int flag=1;
    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0){
	flag=0;
	break;
      }
    }
    if(flag)
      pri.push_back(i);
    if(pri.size()==10000)
      break;
  }
  int n;
  while(cin>>n,n){
    long long ans=0;
    for(int i=0;i<n;i++){
      ans+=pri[i];
      //cout<<pri[i]<<endl;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3240
#include<stdio.h>

int main(){
		int n,y;
		scanf("%d %d",&n,&y);
		y=y/1000;
		int man=0,fs=0,s=0,sa=0;
		man=y/10;
		fs=(y-man*10)/5;
		s=(y-man*10-fs*5);
		if(man+fs+s>n){
				puts("-1 -1 -1");
				return 0;
		}
		if(man+fs+s==n){
				printf("%d %d %d\n",man,fs,s);
				return 0;
		}
		else{
				sa=n-man-fs-s;
				int i,j,k;
				for(i=0;i<=sa;i+=9){
						for(j=0;j<=sa-i;j++){
								if((sa-i-j)%4==0&&man-(i/9)-j>=0&&(fs+j*2)-(sa-i-j)/4>=0){
										printf("%d %d %d\n",man-(i/9)-j,fs+j*2-(sa-i-j)/4,s+i*10+(sa-i-j)/4*5);
										return 0;
								}
						}
				}		
		}
		puts("-1 -1 -1");
		return 0;
}				


Measured memory_bytes: 128
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    print(n*(n+1)//2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);

ll m;
vector<ll> b(100005);
vector<ll> q(100005);

vector<ll> calc() {
  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }
  return score;
}

int main()
{
  cin>>d;
  rep(i, 26) cin>>c[i];
  rep(i, d) rep(j, 26) cin>>s[i][j];
  rep(i, d) {
    cin>>t[i]; t[i]--;
  }
  ll m; cin>>m;

  vector<ll> ans;
  rep(i, m) {
    cin>>b[i]>>q[i];
    q[i]--;
    t[b[i]-1] = q[i];
    vector<ll> score = calc();
    ans.push_back(score[d-1]);
  }

  for (auto v:ans) {
    cout << v << endl;
  }

  return 0;
}


Measured memory_bytes: 5980
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
const int NICO = 1000000 + 10;
typedef long long LL;
int a[NICO], b[NICO], deg[NICO], root;
int n, vis[NICO], ok = 1;
LL val[NICO];
vector<int> vec[NICO];
void dfs(int x)
{
    vis[x] = 1; 
    LL sum = 0, mx = 0;
    if(deg[x] == 1) return;
    for(int i=0;i<vec[x].size();i++)
    {
        int cur = vec[x][i];
        if(vis[cur]) continue;
        dfs(cur); mx = val[cur] > mx ? val[cur] : mx;
        sum += val[cur];
    }
    LL tmp = 2 * val[x] - sum;
    if(x == root)
    {
        if(tmp != 0 || val[x] > sum - mx) ok = 0;
    } else
    if(vec[x].size() == 2)
    {
        if(sum != val[x]) ok = 0;
    } else
    if(tmp > val[x] || tmp < 0 || (val[x] - tmp) > sum - mx)
    {
        ok = 0;
    }
    val[x] = tmp;
    return;
}
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> val[i]; 
    }
    for(int i=1;i<=n-1;i++)
    {
        cin >> a[i] >> b[i];
        deg[a[i]]++,  deg[b[i]]++;
        vec[a[i]].push_back(b[i]);
        vec[b[i]].push_back(a[i]);
    }
    root = -1;
    for(int i=1;i<=n;i++)
    {
        if(deg[i] > 1 && root == -1)
        {
            root = i; break;
        }
    }
    if(root == -1)
    {
        cout << ((val[1] == val[2])?"YES":"NO") << endl;
    } else {
        dfs(root);
        cout << (ok?"YES":"NO") << endl;
    }
}

Measured memory_bytes: 35840
#include <iostream>
#include <iomanip>

using namespace std;

int w,h,x,y;

int main(){
    cin >> w >> h >> x >> y;
    cout << (double)w * (double)h / 2.0 << " ";
    if(x == 0 || y == 0){
        cout << 0 << endl;
        return 0;
    }
    if(w/2 == x && h/2 == y && w%x==0 && h%y==0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define ull unsigned long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pul pair<ull,LL> 
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int N=(1<<14)-1,mod=998244353;
const LL inf=1e18;
template<typename T> void chkmin(T &x,T y) {if(y<x) x=y;}
template<typename T> void chkmax(T &x,T y) {if(y>x) x=y;}
template<typename T> void upd(T &x,T y) {if((x+=y)>=mod) x-=mod;}
int n,X,Y,sl,fh,ans[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	ios::sync_with_stdio(false);
	n=rd();X=rd();Y=rd();
	for(int d,i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			if(i<=X&&Y<=j)
			{
				d=X-i+j-Y+1;
				ans[d]++;
			}
			else if(X<i&&Y<=j)
			{
				d=min(j-i,i-X+j-Y+1);
				ans[d]++;
			}
			else if(i<=X&&j<Y)
			{
				d=min(j-i,X-i+Y-j+1);
				ans[d]++;
			}
			else
			{
				d=min(j-i,i-X+Y-j+1);
				ans[d]++;
			}
	for(int i=1;i<n;++i) printf("%d\n",ans[i]);
	return 0;
}

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

int main() {
  int n,w;
  cin>>n>>w;
  vector<int>wt(n,1),val(n,1);
  int rsum = 0;
  for(int i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
    rsum +=val[i];
  }
  //cout<<rsum<<endl;
  vector<ll> dp(rsum+1,BIG);
  dp[0] = 0;
  for(int i=0;i<n;i++)
  {
    for(int j=rsum;j>=val[i];j--)
    {
      dp[j] = min(dp[j-val[i]]+wt[i],dp[j]);
    }
  }
  int t = -1;
  for(int i=0;i<=rsum;i++)
  {
    //cout<<i<<" "<<dp[i]<<endl;
    if(dp[i]<=w)
      t = i;
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MAXN (110)
int n;
int x[MAXN], y[MAXN], h[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d%d", x + i, y + i, h + i);
    }
    for (int cx = 0; cx <= 100; ++cx) {
        for (int cy = 0; cy <= 100; ++cy) {
            bool flag = true;
            int ans = 0, max = INT32_MAX;
            for (int i = 1; i <= n; ++i) {
                int t = std::abs(x[i] - cx) + std::abs(y[i] - cy);
                if (h[i] == 0) {
                    max = std::min(max, t);
                } else {
                    if (ans == 0) {
                        ans = t + h[i];
                    } else if (ans != t + h[i]) {
                        flag = false;
                        break;
                    }
                }
                if (ans > max) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                printf("%d %d %d\n", cx, cy, ans);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
s = input()
s = s[::-1]
n = len(s)
mod = 10**9 + 7

dp = [[0 for j in range(13)] for i in range(n)]
if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    num = int(s[0])
    dp[0][num] = 1

mul = 1
for i in range(1, n):
    mul = (mul*10) % 13
    if s[i] == '?':
        for m in range(10):
            num = (m * mul) % 13
            for j in range(13):
                dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod
    else:
        num = (int(s[i]) * mul) % 13
        for j in range(13):
            dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod

print(dp[n-1][5])

Measured memory_bytes: 66012
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
    char s[200];
    char p[100];
    char c[100];
   
    scanf("%s %s",s, p);
    strcpy(c, s);
    strcat(s, c);
    
    if(strstr(s, p) == NULL){
        printf("No\n");
    } else {
        printf("Yes\n");
    }
        
    return 0;
}


Measured memory_bytes: 3152
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	a := make([]int, n)

	for i := range a {
		a[i] = scanInt()
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}

	ans := 1
	for _, v := range a {
		ans *= v
		if ans > 1000000000000000000 || ans < v {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5836
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim K, X as Integer
        Dim arr(2) as String
        arr = Split(Console.ReadLine())
        K = arr(0) : X = arr(1)
        Console.WriteLine(if(X <= K * 500, "Yes", "No"))
    End Sub
End Class


Measured memory_bytes: 13408
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

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

	int N,K,X,Y;

	cin >> N >> K >> X >> Y;

	if(N>K){
		cout << K*X+(N-K)*Y << endl;
	}else{
		cout << N*X << endl;
	}

	return 0;

}

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

int main(){
	double x1,x2,x3,x4,y1,y2,y3,y4,EPS=1e-12;
	while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4){
		if(fabs(((x2-x1)*(x4-x3))+((y2-y1)*(y4-y3)))<=EPS)cout<<"YES";
		else cout<<"NO";
		cout<<endl;
	}
}

Measured memory_bytes: 1224
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    cout << s << endl;
  } else {
    reverse(all(s));
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
ll MOD = 1000000007;
#define INF (1e9)

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    char a, b;
    cin >> a >> b;
    bool flag = a == 'H' ^ b == 'H';
    if (!flag) cout << "H" << endl;
    else cout << "D" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <vector>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
int n,ans;
bool dead[1000005];
vector<int> v[1000005];
inline int dfs(int dp){
	dead[dp]=1;
	int res=0;
	vector<int> gss;
	for(int i=0;i<v[dp].size();i++){
		if(dead[v[dp][i]]) continue;
		int t=dfs(v[dp][i]);
		gss.push_back(t);
	}
	sort(gss.begin(),gss.end());
	for(int i=0;i<v[dp].size();i++){
		res=max(int(gss[i]+v[dp].size()-i-1),res);
	}	
	res++;
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	int i,j,t;
	cin>>n;
	for(i=2;i<=n;i++){
		cin>>t;
//		if(i==a[i]) exit(41234);
		v[t].push_back(i);
	}
//	if(v[1].size()==0) exit(1);
	cout<<dfs(1)-1<<endl;
//	for(i=1;i<=n;i++) cout<<gs[i]<<" ";
//	cout<<endl;
	return 0;
}

Measured memory_bytes: 33920
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let s: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let mut res = vec![];
    for &c in &s {
        if c == 'B' { res.pop(); }
        else { res.push(c); }
    }
    let ans = res.iter().map(|&c| c.to_string()).collect::<String>();

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

Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int Alice = 0;
		int Bob = 0;
		for(int i = 1; i < N+1; i++) {
			if(i % 2 == 1) {
				Alice += a[N-i];
			}else {
				Bob += a[N-i];
			}
		}
		System.out.println(Alice - Bob);
	}

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

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

    vi A(n), B(n), C(n);
    rep(i,n) cin >> A[i];
    rep(i,n) cin >> B[i];
    rep(i,n) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    rep(i,n){
        ll x = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll y = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        ans += x * y;
        //cout << ans << endl;
    }

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


Measured memory_bytes: 4580
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[100];

int main()
{
	int N, ans = 0;

	cin >> N;
	rep(i, N) cin >> a[i];

	repc(i, 1, N - 1) {
		if (a[i] == a[i - 1]) {
			a[i] = 500;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N, std::vector<long long> L)
{
    sort(L.begin(), L.end());
    int ans = 0;
    rep(b, N) rep(a, b)
    {
        int ab = L[a] + L[b];
        int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
        int l = b + 1;
        ans += r - l;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> L(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  vector<int> f(N+1, 0);
  for (int x=1; x<=100; x++) {
    for (int y=1; y<=100; y++) {
      for (int z=1; z<=100; z++) {
        if (x*x+y*y+z*z+x*y+y*z+z*x<=N) f[x*x+y*y+z*z+x*y+y*z+z*x]++;
      }
    }
  }
  for (int i=1; i<=N; i++) cout << f[i] << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main () {
    int A, B, C;
    cin >> A >> B >> C;
    int X;
    cin >> X;
    int ans = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                if (X == 500*i+100*j+50*k) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
h = list(map(int,input().split()))
v = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
visited = [0]*n
ans = 0

for i in range(n):
    if visited[i] != 0:
        continue
    if v[i] == []:
        ans += 1
        visited[i] = 1
    else:
        for j in v[i]:
            visited[j] = 1
            if h[j] >= h[i]:
                visited[j] = 0
                break
        else:
            ans += 1
        visited[i] = 1
print(ans)

Measured memory_bytes: 30268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=INF;

int main() {
    ll n;
    cin >> n;
    ll ans=0;
    for (ll i=1;i<=n-1;i++){
        ans+=(n-1)/i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#!/usr/bin/env python
s = input()
m_bit=0
y_bit=0
if int(s[:2]) <= 12 and int(s[:2]) >= 1:
	m_bit = 1 # MMYY is acceptable
if int(s[2:]) <= 12 and int(s[2:]) >= 1:
	y_bit = 1 #YYMM is acceptable
if m_bit and y_bit:
	print("AMBIGUOUS")
elif m_bit:
	print("MMYY")
elif y_bit:
	print("YYMM")
else:
	print("NA")		
	 


Measured memory_bytes: 3060
N,L = list(map(int,input().split()))
if L < 0 and N+L-1 < 0:
    print(L*N+(N-1)*N//2-(N+L-1))
elif L < 0 and N+L-1 >= 0:
    print(L*N+(N-1)*N//2)
else:
    print(L*N+(N-1)*N//2-L)

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());
      System.out.println((n + 1) / 2);
    }
  }
}


Measured memory_bytes: 32692
import sys, math
from operator import itemgetter
from bisect import bisect_left, bisect_right

f_i = sys.stdin

def main():
    n = int(f_i.readline())
    
    lx = []
    ly = []
    li = []
    for i in range(n):
        x, y = map(int, f_i.readline().split())
        lx.append(x)
        ly.append(y)
        li.append(i)

    x_width = max(lx) - min(lx)
    y_width = max(ly) - min(ly)
    if x_width > y_width:
        P = list(zip(lx, ly, li))
    else:
        P = list(zip(ly, lx, li))
    P.sort()

    interval = int(math.sqrt(n))

    low = [v1 for v1, v2, i in P[::interval]]
    high = [v1 for v1, v2, i in P[interval - 1::interval]] + [float('inf')]

    S = []
    v2_sec_list = []
    for i in range(0, n, interval):
        si = P[i:i + interval]
        si.sort(key=itemgetter(1))
        v2_s = [p[1] for p in si]
        v2_sec_list.append(v2_s)
        S.append(si)

    A = []

    q = f_i.readline()

    for l in f_i:
        sx, tx, sy, ty = map(int, l.split())
        a = []
        if x_width > y_width:
            for i in range(bisect_left(high, sx), bisect_right(low, tx)):
                v = S[i]
                k = v2_sec_list[i]
                for j in range(bisect_left(k, sy), bisect_right(k, ty)):
                    if sx <= v[j][0] <= tx:
                        a.append(v[j][2])
        else:
            for i in range(bisect_left(high, sy), bisect_right(low, ty)):
                v = S[i]
                k = v2_sec_list[i]
                for j in range(bisect_left(k, sx), bisect_right(k, tx)):
                    if sy <= v[j][0] <= ty:
                        a.append(v[j][2])
        
        if a:
            a.sort()
            A.extend(a)
        A.append('')

    print('\n'.join(map(str, A)))

main()

Measured memory_bytes: 158876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	unsigned long long a;cin >> a;
    string b;cin >> b;
    cout << (a*(b[0]-'0')*100+a*(b[2]-'0')*10+a*(b[3]-'0'))/100 << endl;
}

Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int X;
    cin >> X;
    int nax = 1;
    for (int b=1; b<=X; b++){
        for (int p=2; p<X; p++){
            if (pow(b,p) <= X)chmax(nax, (int)pow(b,p));
            else break;
        }
    }

    cout << nax << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
   ll a,b,c,k,l,ans;
   cin >> a>> b>> c;
   if(a%2==0||b%2==0||c%2==0) cout<< 0<<endl;
   else{
       ans=min(a*b,a*c);
       ans=min(ans,b*c);
       cout << ans<<endl;
   }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        k: i32,
        x: i32,
    );
    let mut v: Vec<i32> = Vec::new();
    for i in (x-k+1)..(x+k) {
        v.push(i);
    }
    // println!("{:?}", v);
    let v: Vec<String> = v.iter().map(|&e| e.to_string()).collect();
    println!("{}", v.join(" "));

}


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

int main(){
    string s,t;
    cin >> s >> t;
    int num=s.size();
    map<pair<char,char>,int> mp;
    map<char,int> mp_s;
    map<char,int> mp_t;
    for(int i=0;i<num;i++){
        mp[{s[i],t[i]}]++;
        mp_s[s[i]]++;
        mp_t[t[i]]++;
    }

    if(mp.size()==mp_s.size()&&mp.size()==mp_t.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3904
fn main() {
    let n: u32 = read();
    let data_list: Vec<Vec<u32>> = read_vec2(n);

    let mut counter = 0;

    for data in data_list.iter() {
        let v1 = data[0];
        let v2 = data[1];
        if v1 == v2 {
            // ゾロ目
            counter += 1;

            if counter == 3 {
                println!("Yes");
                return;
            }
        } else {
            counter = 0;
        }
    }

    println!("No")
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
int h,w,c,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
vector<int> p(64);

int nu(int x,int y,int cl,int t){
  int res=1;
  p[y*w+x]=cl;
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||w<=nx||ny<0||h<=ny||p[ny*w+nx]!=t||p[ny*w+nx]==cl)continue;
    res+=nu(nx,ny,cl,t);
  }
  return res;
}

int dfs(int d){
  vector<int> tp=p;
  int res=0;
  if(d==4){
    nu(0,0,c,p[0]);
    return nu(0,0,7,p[0]);
  }
  for(int j=1;j<7;j++){
    nu(0,0,j,p[0]);
    res=max(res,dfs(d+1)),p=tp;
  }
  return res;
}

int main(){
  while(cin>>h>>w>>c,h){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin>>p[i*w+j];
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3036
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define int 		long long
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

void solve(){
	int N;
	cin>>N;
	vi x(N);
	rep(i,0,N){
		int temp;
		cin>>temp;
		temp--;
		x[temp]=i;
	}
	set<int>p;
	p.insert(-1);
	p.insert(N);
	ll ans=0;
	rep(i,0,N){
		auto it=p.upper_bound(x[i]);
		auto it2=it;
		it2--;
		ll temp=(x[i]-*it2)*(*it-x[i]);
		ans+=(i+1)*(temp);
		p.insert(x[i]);
	}
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string S; ll K;
//---------------------------------------------------------------------------------------------------
int solve() {
    K--;
    fore(c, S) {
        if (c == '1') {
            if (K == 0) return 1;
            else K--;
        }
        else return c - '0';
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S >> K;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    int A, B;
    int P[N], Q[N]; F0R(i, N) cin >> P[i];
    F0R(i, N) cin >> Q[i];
    vi data(N); F0R(i, N) data[i] = i+1;
    int pos = 1;
    do {
        F0R(i, N) {
            if (P[i] != data[i]) goto badP;
        }
        A = pos;
        badP:;
        F0R(i, N) {
            if (Q[i] != data[i]) goto badQ;
        }
        B = pos;
        badQ:;
        pos++;

    } while (next_permutation(all(data)));
    cout << abs(A-B) << endl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 3e5+100;

ll a[MAX];
int main(){
	fastio;
	ll n,k,x,y,ans=0;
	cin>>n>>x>>y;
	f(i,1,n+1){
		f(j,i+1,n+1){
			a[min(j-i,abs(i-x)+abs(j-y)+1)]++;
		}
	}  
	f(i,1,n) cout<<a[i]<<endl;
	return 0;	
}

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


def solve(X: int, Y: int, Z: int):
    print(str(Z) + ' ' + str(X) + ' ' + str(Y))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def irohas_obsession(N: int, K: int, D: list) -> int:
    # D に含まれない最小の値
    min_not_d = min(d for d in range(10) if d not in D)
    min_not_d_and_not_zero = min(d for d in range(10) if d not in D and d != 0)

    # 数字を各桁に分解する。
    nums = []
    while N > 0:
        nums = [N % 10] + nums
        N //= 10

    # 上位の桁から見ていって最初に D に含まれる数字を探す。
    convert_idx = -1
    for i, n in enumerate(nums):
        if n not in D:
            # 変換の必要がない
            continue

        convert_idx = i
        break
    # print(convert_idx)
    for i in range(convert_idx, -1, -1):
        n = nums[i]
        if n > 9:
            n %= 10
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

        for d in range(n, 10):
            # 変換先が n 以上 9 以下
            if d in D:
                # NG
                continue

            nums[i] = d
            break
        else:
            # 変換先が n 未満
            for d in range(n, 10):
                if d in D:
                    # NG
                    continue

                nums[i] = d

            # 上位の桁に繰り上がりを伝搬
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

    # 残りの桁は D に含まれない最小の値に変換する。
    nums = [min_not_d if n in D else n for n in nums]

    ret = 0
    digit = 1
    # print(nums)
    for n in reversed(nums):
        ret += n * digit
        digit *= 10

    return ret


if __name__ == "__main__":
    N, K = map(int, input().split())
    D = [int(s) for s in input().split()]
    ans = irohas_obsession(N, K, D)
    print(ans)


Measured memory_bytes: 3064
import std.stdio;
import std.array;
import std.algorithm;
import std.conv;

int gcd (int x, int y) {
    if(x < y) swap(x, y);
    if(y == 0) return x;
    return gcd(y, x % y);
}

void main () {
    int a, b;
    while(true) {
        string[] input = split(readln());
        if(input.length == 0) break;
        a = to!int(input[0]);
        b = to!int(input[1]);
        int gcd_ab = gcd(a, b);
        int lcm_ab = a / gcd_ab * b;
        writeln(gcd_ab, " ", lcm_ab);
    }
}

Measured memory_bytes: 1048