akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  int n,m;

  while(cin>>n>>m,n||m){
    int a[n];
    int b[m];
    int sumA=0,sumB=0;
    rep(i,n){
      cin>>a[i];
      sumA += a[i];
    }
    rep(i,m){
      cin>>b[i];
      sumB += b[i];
    }

    int ansA=99999999,ansB=99999999;
    rep(i,n){
      rep(j,m){
        if(sumA - a[i] + b[j] == sumB - b[j] + a[i] && a[i] + b[j] < ansA + ansB){
          ansA = a[i];
          ansB = b[j];
        }
      }
    }

    if(ansA != 99999999){
      cout<<ansA<<" "<<ansB<<endl;
    }
    else{
      cout<<"-1\n";
    }
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;

int main() {
	int N=0;
	long long A;
	int c = 0, repeat = 1;
	int cmin = 1000000;
	cin >> N;
	//cout << N << endl;
		for (int i = 0; i < N; i++) {
			cin >> A;
			c = 0;
			do {
				if (A % 2 == 0) {
					A /= 2;
					c++;
					repeat = 1;
				}
				else
					repeat = 0;
			}while (repeat == 1);

			cmin = min(cmin, c);
		}
		
		cout << cmin << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};
struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;
  for( i = 0;i<n1;i++) L[i] = A[left + i];
  for( i = 0;i<n2;i++) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k = left;k<right;k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid = (left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x = A[r];
  i = p-1;
  for(j = p;j<r;j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];A[i] = A[j];A[j] = t;
    }
  }
  t = A[i+1];A[i+1] = A[r];A[r] = t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}


int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;

  }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit){
      stable = 0;
    }
  }

  if(stable == 1){
    printf("Stable\n");
  }if(stable == 0){
    printf("Not stable\n");
  }
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);

  }

  return 0;
}



Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

class SqMatrix {
    private:
    int dim;
    vector<vector<ll>> mat;
    
    public:
    /* Identity Matrix*/
    SqMatrix(int n) {
        dim = n;
        mat = vector<vector<ll>>(dim, vector<ll>(dim, 0));
        for (int i = 0; i < n; i++)
            mat[i][i] = 1;
    }

    void gedit() {
        for (int i = 0; i < dim; i++)
            for (int j = 0; j < dim; j++)
                cin >> mat[i][j];
    }

    SqMatrix operator * (SqMatrix const &obj) { 
        assert(dim == obj.dim);
        SqMatrix res(dim); 
        for (int i = 0; i < dim; i++)
            for (int j = 0; j < dim; j++)
                for (int k = 0; k < dim; k++)
                    res.mat[i][k] = (res.mat[i][k] + (mat[i][j] * obj.mat[j][k]) % mod) % mod;
        return res;
    }

    SqMatrix operator *= (SqMatrix const & obj) {
        assert(dim == obj.dim);
        vector<vector<ll>> mat2(dim, vector<ll>(dim, 0));
        for (int i = 0; i < dim; i++)
            for (int j = 0; j < dim; j++)
                for (int k = 0; k < dim; k++)
                    mat2[i][k] = (mat2[i][k] + (mat[i][j] * obj.mat[j][k]) % mod) % mod;
        mat = mat2;
        return *this;
    }

    SqMatrix raise(ll k) {
        SqMatrix tmp = *this;
        SqMatrix res = SqMatrix(dim);
        while (k) {
            if (k & 1) {
                res *= tmp;
            }
            tmp *= tmp;
            k /= 2;
        }
        return res;
    }

    ll sum() {
        ll out = 0;
        for (int i = 0; i < dim; i++)
            for (int j = 0; j < dim; j++)
                out = (out + mat[i][j]) % mod;
        return out;
    }

    void print() {
        for (int i = 0; i < dim; i++) {
            for (int j = 0; j < dim; j++) {
                cout << mat[i][j] << ' ';
            }
            cout << '\n';
        }
    }
};

int main() {
    nfs
    int n;
    ll k;
    cin >> n >> k;
    SqMatrix adjMat(n);
    adjMat.gedit();
    SqMatrix res = adjMat.raise(k);
    cout << res.sum();
}

Measured memory_bytes: 3688
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std; 
int main(){
   char g[6];
    cin >> g;
   
if(g[0]==g[1]&&g[1]==g[2]&&g[2]==g[3]){
  cout <<"No";
}else if(g[0]==g[2]&&g[1]==g[3]){
  cout <<"Yes";
}else if(g[0]==g[3]&&g[1]==g[2]){
  cout <<"Yes";
}else if(g[0]==g[1]&&g[2]==g[3]){
  cout <<"Yes";}
  else cout <<"No";}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int D[10];

int main() {
    int N, K;
    cin >> N >> K;
    rep(i, K)cin >> D[i];

    for (int i = N; i < 100000; i++) {
        int dimi = i;
        int flag = true;
        while (dimi != 0) {
            rep(j, K) {
                int remi = dimi % 10;
                if (remi == D[j]) {
                    flag = false;
                    break;
                }
            }
            dimi /= 10;
        }
        if (flag) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
function main()
    N,K=parse.(Int64,split(readline()))
    A=parse.(Int64,split(readline()))
    logK::Int64=1
    while ((1<<logK) < K)
        logK+=1
    end
    doubling=zeros(Int64,logK,N)
    for i in 1:N
        global doubling[1,i]=A[i]
    end
    for t=1:logK-1
        for i=1:N
            global doubling[t+1,i]=doubling[t,doubling[t,i]]
        end
    end
    
    now::Int64=1
    k::Int64=1
    
    while K>0
        if K&1==1
            now=doubling[k,now]
            
        end
        K=K>>1
        k+=1
    end
    println(now)
end

main()


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

int main() {

  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a,a+n);
  int t = a[n-1]-a[0];
  int k = abs(a[1])-a[0];
  if(t>k) cout << t << endl;
  else cout << k << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> h(N);
	for (Int i = 0; i < N; i++) {
		cin >> h[i];
	}

	Int res = 0;
	while (true) {

		if (*max_element(h.begin(), h.end()) == 0)break;

		Int i = 0;
		while (i < N) {
			if (h[i] == 0)i++;
			else {
				res++;
				while (i < N && h[i]>0) {
					h[i]--;
					i++;
				}
			}
		}

	}
	cout << res << endl;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
ls=[0]
tmp=0
for i in l:
    tmp+=i
    ls.append(tmp)
import collections
c=collections.Counter(ls)
mc=c.most_common()
ans=0
for i in [i[1] for i in mc if i[1]>1]:
    ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 48272
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

typedef pair<int, int>P;



int cumA[100010], cumB[100010];
signed main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	cumA[0] = 0; cumB[0] = 0;
	m0(cumA); m0(cumB);
	int cntA = 1, cntB = 1;
	if (S[0] == '0')cntB = 2;
	int cnt0 = 0, cnt1 = 0;
	REP(i, N+1) {
		if (i == N) {
			if (S[i] == '0') {
				cumA[cntA] = cnt0;
			}
			else {
				cumB[cntB] = cnt1;
			}
		}
		if (S[i] == '0') {
			if (cnt1 > 0) {
				cumB[cntB] = cnt1;
				cnt1 = 0;
				cntB++;
			}
			cnt0++;	
		}
		else {
			if (cnt0 > 0) {
				cumA[cntA] = cnt0;
				cnt0 = 0;
				cntA++;
			}
			cnt1++;
		}
	}
	REP(i, N+1) {
		cumA[i + 1] += cumA[i];
		cumB[i + 1] += cumB[i];
	}
	/*REP(i, N+1) {
		pe(cumA[i]);
	}
	cout << endl;
	REP(i, N+1) {
		pe(cumB[i]);
	}
	cout << endl;*/
	ll ans = 0;
	REP(i, N - K+2) {
		int res = 0;
		res += cumA[i + K] - cumA[i];
		res += cumB[i + K + 1] - cumB[i];
		ans = max(ans, res);
	}
	print(ans);
}


Measured memory_bytes: 2048
/*
设F[l][r][0 / 1]表示只考虑区间[l, r]中的人，l / r能否最终活下来
如果x可以获得最终的胜利，那么可以发现1 ~ x和x ~ N中的战斗是独立互不干扰的，所以只要F[1][x][1] = F[x][N][0] = 1即可
考虑转移。以F[l][r][1]为例，即r最后获胜的情况。假设最后一次发生的战斗是x和r之间的，分情况讨论：
(1)x = l。这时候需要有A[r][l] = 1，同时一定存在一个l <= mid <= r - 1，使得F[l][mid][0] = F[mid + 1][r][1] = 1
(2)l + 1 <= x <= r - 1，那么同样可以分成两个过程。这样需要有F[l][x][0] = F[x][r][1] = 1
   （事实上，这是最后一次发生战斗是x和r之间同时合法的必要不充分条件。但是只要满足该条件，F[l][r][1]一定为1，就可以不管了）
这个区间dp可以用压位加速 
*/
#include <bitset>
#include <cstdio>

using namespace std;
const int Max_N(2050);

int N, A[Max_N][Max_N], F[Max_N][Max_N][2];
bitset<Max_N> LG[2][Max_N], RG[2][Max_N];
char input[Max_N];

int main()
{
	scanf("%d", &N);
	for (int i = 2;i <= N;++i)
	{
		scanf("%s", input + 1);
		for (int j = 1;j <= i - 1;++j)
			A[j][i] = 1 - (A[i][j] = input[j] - '0');
	}
	for (int i = 1;i <= N;++i)
		F[i][i][0] = F[i][i][1] = 1, LG[0][i].set(i), LG[1][i].set(i), RG[0][i].set(i), RG[1][i].set(i);
	for (int i = 1;i <= N - 1;++i)
		F[i][i + 1][A[i + 1][i]] = 1, LG[A[i + 1][i]][i].set(i + 1), RG[A[i + 1][i]][i + 1].set(i);
	for (int len = 3;len <= N;++len)
	{
		for (int l = 1, r = len;r <= N;++l, ++r)
		{
			if ((LG[1][l] & RG[1][r]).any())
				F[l][r][1] = 1;
			else
				if (A[r][l] && (LG[0][l] & (RG[1][r] >> 1)).any())
					F[l][r][1] = 1;
			if ((RG[0][r] & LG[0][l]).any())
				F[l][r][0] = 1;
			else
				if (A[l][r] && (RG[1][r] & (LG[0][l] << 1)).any())
					F[l][r][0] = 1;
		}
		for (int l = 1, r = len;r <= N;++l, ++r)
		{
			if (F[l][r][0])
				LG[0][l].set(r), RG[0][r].set(l);
			if (F[l][r][1])
				LG[1][l].set(r), RG[1][r].set(l);
		}
	}
	int Ans(0);
	for (int x = 1;x <= N;++x)
		Ans += (F[1][x][1] & F[x][N][0]);
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 51456
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var x = next();
  return 10-(x/200|0);
}

Measured memory_bytes: 29668
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,d,x,y,ans=0;
	scanf("%lld%lld",&n,&d);d*=d;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x,&y);
		ans+=(x*x+y*y<=d);
	}
	printf("%d",ans);
	return 0;
}

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

public class Main
{
  
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s1 = r.readLine();
    String s2 = r.readLine();
    String s3 = r.readLine();
    
    System.out.print(s1.charAt(0));
    System.out.print(s2.charAt(1));
    System.out.print(s3.charAt(2));
  }
  
}

Measured memory_bytes: 21204
/**Bismillahir Rahmanir Rahim.**/
#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long int            ll;
typedef long double              ld;
#define Faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi                 acos(-1);
#define test        int t; cin>>t; while(t--)
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//cin.getline(array,size);
int main()
{
    ll a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a)<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a <= b) {
      System.out.println(a);
    } else {
      System.out.println(a - 1);
    }

  }
}

Measured memory_bytes: 35628
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


  
int main(){
    int n;cin >> n;
    string s="";
    rep(i,n){
        s+="ACL";
    }
    cout << s << endl;
  }

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int count = 0;

    for(int j=1;j<n;j++){
        int rt = sqrt(j);
        for(int i=1;i<=rt;i++){
            if(j%i==0){
                count += 2;
            }
        }if(rt*rt==j){
            count--;
        }
    }
    cout<<count<<"\n";
    return 0;
}


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

typedef long long LL;
const int N = 16;
int xsel[1 << 15][N], ysel[1 << 15][N];
int x[N], y[N], p[N];
LL res[N];

void solve() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d%d%d", &x[i], &y[i], &p[i]);
    }
    memset(res, 0x3f, sizeof res);

    for(int i = 0; i < (1 << n); i++) {
        for(int j = 1; j <= n; j++) {
            xsel[i][j] = abs(x[j]);
            ysel[i][j] = abs(y[j]);
            for(int k = 0; k < n; k++) {
                if((i >> k) & 1) {
                    xsel[i][j] = min(xsel[i][j], abs(x[j] - x[k + 1]));
                    ysel[i][j] = min(ysel[i][j], abs(y[j] - y[k + 1]));
                }
            }
        }
    }

    for(int i = 0; i < (1 << n); i++) {
        int cnt = 0;
        for(int j = 0; j < n; j++) {
            if((i >> j) & 1) cnt++;
        }
        for(int j = i; j >= 0; j--) {
            j &= i;
            LL sum = 0;
            for(int k = 0; k < n; k++) {
                if(!((i >> k) & 1)) {
                    sum += (LL)min(xsel[j][k + 1], ysel[i - j][k + 1]) * p[k + 1];
                }
            }
            res[cnt] = min(res[cnt], sum);
        }
    }

    for(int i = 0; i <= n; i++) {
        printf("%lld\n", res[i]);
    }
}

int main() {
//    freopen("in.txt", "r", stdin);
    solve();
    return 0;
}


Measured memory_bytes: 7924
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll M = 1000000007;

int a[105];

ll fastpow(int a,int p) {
	ll base = a, res = 1;
	while (p) {
		if (p & 1)res = res * base % M;
		base = base * base % M;

		p >>= 1;
	}

	return res;

}
ll c(int n, int a) {
	ll res = 1;
	for (int i = n; i >= n - a + 1; i--) {
		res = res * i % M;
	}
	for (int i = 1; i <= a; i++) {
		ll in = fastpow(i, M - 2);
		res = res * in % M;
	}

	return res;



}

int main() {
	int n,a,b;
	cin >> n>>a>>b;
	ll ans = 0;
	ans += fastpow(2,n) + (M - 1) % M;
	ans += (M - c(n, a)) % M + (M - c(n, b)) % M;
	ans = ans % M;

	cout << ans;


	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin >> s;

  ll n = s.size();
  ll ans = 0;
  for(ll i = 0; i < n/2; i++){
    if(s[i] != s[n-1-i])
      ans++;
  }

  cout << ans << endl;
}


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

using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<int> a,b;
    for(int i =0; i < n; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
        b.push_back(tmp);
    }
    
    std::sort(a.begin(),a.end());
    int sum = 0;
    for(int i =0; i < n; i++){
        if(a[i] != b[i]){
            sum ++;
        }
    }
    if(sum ==2 || sum == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    
    
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
answer = 0
while sum(h):
    min = 1000
    sta = 0
    for i, hi in enumerate(h):
        if hi != 0:
            if hi < min:
                min = hi
            if i == N-1:
                if sta <= i:
                    for j in range(sta, i+1):
                        h[j] -= min
                    answer += min
        else:
            if sta < i:
                for j in range(sta, i):
                    h[j] -= min
                answer += min
                min = 1000
            sta = i+1
print(answer)

Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
//#include <vector>
#include <string>
typedef long long LL;
using namespace std;

int main(){
    string s;
    LL k;
    LL tmp;
    char ans;
    cin >> s >> k;
    tmp=min((LL)s.size(),k);
    for(int i=0; i<tmp; i++){
        ans=s[i];
        if(s[i]!='1'){
            break;
        }
    }
    cout << ans << endl;
}


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

mt19937 rr(random_device{}());

signed main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  //n = rr() % 10;
  //m = rr() % 10;
  //a = rr() % 50;
  //b = rr() % 50;
  //cerr << n << ' ' << m << ' ' << a << ' ' << b << '\n';
  int mxa = (n % 2) * (m / 2);
  int mxb = (m % 2) * (n / 2);
  int sq = (n / 2) * (m / 2);

  int ca = min(mxa, a);
  int cb = min(mxb, b);
  int sqa = (a - ca + 1) / 2;
  int sqb = (b - cb + 1) / 2;
  vector<string> s(n, string(m, '.'));
  if (n % 2 && m % 2 && (a + b) * 2 == n * m - 1 && (a - ca) % 2 && (b - cb) % 2 && sqa + sqb == sq + 1 && a >= 2 && b >= 2) {
    s[n - 1][m - 1] = '>';
    s[n - 1][m - 2] = '<';
    s[n - 1][m - 3] = 'v';
    s[n - 2][m - 3] = '^';
    s[n - 3][m - 3] = '<';
    s[n - 3][m - 2] = '>';
    s[n - 3][m - 1] = '^';
    s[n - 2][m - 1] = 'v';
    a -= 2;
    b -= 2;
    ca -= 1;
    cb -= 1;
  } else if (sqa + sqb > sq) {
    cout << "NO\n";
    return 0;
  }
  for (int i = 0; i < ca; ++i) {
    s[n - 1][i * 2] = '<';
    s[n - 1][i * 2 + 1] = '>';
  }
  for (int i = 0; i < cb; ++i) {
    s[i * 2][m - 1] = '^';
    s[i * 2 + 1][m - 1] = 'v';
  }
  a -= ca, b -= cb;
  for (int x = 0; x + 1 < n; x += 2) {
    for (int y = 0; y + 1 < m; y += 2) {
      if (a > 0) {
        s[x][y] = '<';
        s[x][y + 1] = '>';
        --a;
        if (a > 0) {
          s[x + 1][y] = '<';
          s[x + 1][y + 1] = '>';
          --a;
        }
      } else if (b > 0) {
        s[x][y] = '^';
        s[x + 1][y] = 'v';
        --b;
        if (b > 0) {
          s[x][y + 1] = '^';
          s[x + 1][y + 1] = 'v';
          --b;
        }
      }
    }
  }
  assert(a == 0 && b == 0);
  cout << "YES\n";
  for (int i = 0; i < n; ++i) {
    cout << s[i] << '\n';
  }
}


Measured memory_bytes: 2304
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)

int main(){
    int n,k,ans=1;
    cin>>n>>k;

    while (n>0){
        if(ans*2>ans+k){
            ans=ans+k;
            n--;
        }else{
            ans=ans*2;
            n--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i <= n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long LL;
typedef long long int LLI;

int solve(int cnt ,int sum,int now);
 int n=0,s=0;
int main(void)
{
     for(;;){
         cin >> n >> s;
        int ans = solve(0, 0, 0);  
         if(n == 0 && s == 0)break;
        cout << ans << endl;
        }
    return 0;  
}
int solve(int cnt ,int sum,int now)
{
    if(cnt == 10){
        return sum == s && now == n;
    }
    int res1 = solve(cnt+1,sum+cnt,now+1) ;
    int res2 = solve(cnt+1,sum,now);
    return res1+res2;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(){
  int A,B,result;
  int iti,juu,hyaku,sen,man;
  scanf("%d %d",&A,&B);

  for(int i=A;i<=B;i++){
    iti=i%10;
    juu=((i-iti)%100)/10;
    hyaku=((i-iti-juu*10)%1000)/100;
    sen=((i-iti-juu*10-hyaku*100)%10000)/1000;
    man=i/10000;

    if(iti==man&&juu==sen)
    result++;

  }
  printf("%d",result);
  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)
ll N, K,rN;
ll dp[111][101010];

ll i,j,k,l,ans;
int main(){
    scanf("%lld%lld", &N,&K);
    for (rN = 1; rN * rN <= N;rN++)
        ;
    dp[0][1] = 1;
    fornum(j,1,rN){
        dp[1][j] = 1;
    }
    fornum(i,2,K+2){
        ll a=0, b=rN-1, c = 0;
        fornum(j,1,rN){
            a = (a + dp[i - 1][j]) % MOD;
        }
        fornum(j,1,rN){
            c = (c + dp[i - 2][j]) % MOD;
        }
        for (j = rN - 1; j >= 1;j--)
        {
            a = ( a+c * (N / j-b))%MOD;
            dp[i][j] = a;
            b = N / j;
            c = (c + MOD - dp[i - 2][j]) % MOD;
        }
    }
    
    ans = (dp[K + 1][1] +MOD) % MOD;

    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 80640
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll C, ll mod){
  ll ans = 1; C = min(C, N - C);
  for (ll i = 1; i <= C; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

int main(){
  ll N, M; cin >> N >> M;
  if (abs(N - M) > 1){
    cout << 0 << endl;
    return 0;
  }

  if (N == M){
    ll ans = 1;
    for (ll i = 1; i <= N; i++){
      ans *= i; ans %= nmax;
    }
    ans = 2 * ans * ans % nmax;
    cout << ans << endl;
    return 0;
  }


  ll ans = 1;
  for (ll i = 1; i <= N; i++){
    ans *= i; ans %= nmax;
  }
  for (ll i = 1; i <= M; i++){
    ans *= i; ans %= nmax;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    c = max( c - (a - b), 0);
    cout << c << endl;
}

Measured memory_bytes: 3552
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    vector<int> cnt(N);
    rep(i, N) cnt[i] = -1;
    rep(i, N) {
        auto itr = lower_bound(cnt.begin(), cnt.end(), A[i]);
        itr--;
        *itr = A[i];
        
        //rep(j, N) cout << j << " " << cnt[j] << endl;
    }
    int ans = 0;
    rep(i, N) if (cnt[i] >= 0) ans++;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
n,k = map(int,input().split())
bitl = [0 for i in range(50)]
al = map(int,input().split())
ansl = [0 for i in range(50)]

for a in al:
  p = 0
  while a:
    bitl[p] += a % 2
    a //= 2
    p += 1
p=0
while k:
  ansl[p] = k % 2
  k //= 2
  p += 1

ans = 0
for i in range(50):
  tmp = 0
  if ansl[i] != 1:
    continue
  else:
    for j in range(i):
      tmp += 2 ** j * max(bitl[j], n-bitl[j])
    tmp +=2 ** i * bitl[i]
    for j in range(i+1, 50):
      if ansl[j] == 0:
        tmp += 2 ** j * bitl[j]
      else:
        tmp += 2 ** j * (n-bitl[j])
  ans = max(ans, tmp)
else:
  tmp = 0
  for j in range(0, 50):
    if ansl[j] == 0:
      tmp += 2 ** j * bitl[j]
    else:
      tmp += 2 ** j * (n - bitl[j])
  ans = max(ans, tmp)

print(ans)



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> mh(4), mw(4);
  mh = {-1, 0, 1, 0};
  mw = {0, 1, 0, -1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '#') {
        bool b = 0;
        for (int k = 0; k < 4; k++) {
          int nh = i + mh.at(k);
          int nw = j + mw.at(k);
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (S.at(nh).at(nw) == '#') b = 1;
        }
        if (!b) return cout << "No" << "\n", 0;
      }
    }
  }
  cout << "Yes" << "\n";
}

Measured memory_bytes: 3520
import sys
readline = sys.stdin.readline
mod = 998244353
N = int(readline())
D = list(map(int, readline().split()))
cnt = [0]*(N+1)
for d in D:
    cnt[d] += 1

ans = 0
if cnt[0] != 1:
    ans = 0
elif D[0] != 0:
    ans = 0
elif len(set(D)) != 1 + max(D):
    ans = 0
else:
    ans = 1
    for i in range(1, N+1):
        dp = cnt[i-1]
        dn = cnt[i]
        if dn == 0:
            break
        ans = (ans*pow(dp, dn, mod)) %mod
print(ans)


Measured memory_bytes: 61220
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main(){
	dhoom;
	int a, b;
	cin >> a >> b;
	if((a*b)&1)
		cout << "Odd" <<endl;
	else 
		cout << "Even" << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x := nextInt()
	if x >= 30 {
		puts("Yes")
	} else {
		puts("No")
	}
}


Measured memory_bytes: 1780
import java.util.Scanner;

public class Main {
    void run(){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int m = sc.nextInt();
            int a = sc.nextInt();
            if(n+m+a == 0) break;
            boolean horizon[][][] = new boolean[1001][n+1][n+1];
            int hMax = 0;
            for(int i = 0; i<m; i++){
                int h = sc.nextInt();
                int p = sc.nextInt();
                int q = sc.nextInt();
                horizon[h][p][q] = true;
                hMax = Math.max(hMax, h);
            }
            int now = a;
            for(int i=hMax; 0<i; i--){
                if(1 <= now-1 && horizon[i][now-1][now]){
                    now--;
                }
                else if(now+1 < n+1 && horizon[i][now][now+1]){
                    now++;
                }
                else{
                    //nowのまま
                }
            }
            System.out.println(now);
        }
    }
    public static void main(String[] args) {
        //new AOJ2001().run();
        new Main().run();
    }
}

Measured memory_bytes: 193404
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int dp[100001];
int N,M;
vector<int> child[100001];
int cost(int k){
  dp[k]=0;
  if(child[k].size()!=0){
    for(int j=0;j<child[k].size();j++){
      if(dp[child[k][j]]!=-1) dp[k]=max(dp[k],dp[child[k][j]]+1);
      else dp[k]=max(dp[k],cost(child[k][j])+1);
    }
  }
  return dp[k];
}
int main(){
  cin>>N>>M;
  for(int i=1;i<=N;i++){
    dp[i]=-1;
  }
  for(int i=1;i<=M;i++){
    int x,y;
    cin>>x>>y;
    child[x].push_back(y);
  }
  int answer=0;
  for(int i=1;i<=N;i++){
    answer=max(answer,cost(i));
  }
  cout<<answer<<endl;
  
return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>
const int MAX_V = 10000;
int prime[10000];
int main(){
int i, k, v ,n;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]) {
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while(scanf("%d", &n)){
    if(n==0)break;
    int fir=0 , sec=0;
    for(i=n ;i>3 ;i--){
      if(prime[i] && prime[i-2]){
        fir=i-2;
        sec=i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int h, w, cnt = 0;
	cin >> h >> w;
	for (int i = 0; i < h * w; i++) {
		char c;
		cin >> c;
		if (c == '#') {
			cnt++;
		}
	}
	if (cnt == h + w - 1) {
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def digits_sum(x):
    result = 0
    while x > 0:
        result += x % 10
        x //= 10
    return result

N = int(input())

result = 10**5

for A in range(1, N):
    B = N - A
    result = min(result, digits_sum(A) + digits_sum(B))

print(result)


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

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

int main(){
  int x;
  cin >> x;
  cout << 360/gcd(360,x) << endl;
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;
int64_t dp[3005][3005][5];
int main() {
  int R,C,K;
  cin>>R>>C>>K;
  vector<vector<int>>item(R,vector<int>(C));
  for(int i=0;i<K;i++){
    int r,c,v;
    cin>>r>>c>>v;
    r--;c--;
    item[r][c]=v;
  }
  for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
      for(int k=2;k>=0;k--){
        chmax(dp[i][j][k+1],dp[i][j][k]+item[i][j]);
      }
      for(int k=0;k<=3;k++){
        chmax(dp[i+1][j][0],dp[i][j][k]);
        chmax(dp[i][j+1][k],dp[i][j][k]);
      }
    }
  }
  int64_t MAX=0;
  for(int i=0;i<=3;i++){
    chmax(MAX,dp[R-1][C-1][i]);
  }
  cout<<MAX<<endl;
  return 0;  
}

Measured memory_bytes: 390192
<?php
$l1 = fgets(STDIN);
$l2 = fgets(STDIN);
$arr = explode(' ', $l2);

$sum = 0;
for ($i = 0; $i < count($arr); $i++) {
  $sum += $arr[$i];
}
$ave = $sum / $l1;

$min = 99999999999;
$ans = 0;
for ($i = 0; $i < count($arr); $i++) {
  $dis = abs($arr[$i] - $ave);
  if ($min > $dis) {
    $min = $dis;
    $ans = $i;
  }
}

echo $ans . PHP_EOL;

Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N;
    cin >> N;
    int p[N + 2] = {}, temp[2] = {};
    p[N + 1] = 51;
    Fp(i, 1, N + 1) cin >> p[i];
    Fp(i, 1, N){
        if(p[i] > p[i + 1]){
            if(temp[0] != 0){
                if(temp[1] != 0){
                    cout << "NO" << endl;
                    //cout << 1 << endl;
                    return 0;
                }else{
                    temp[1] = i + 1;
                    //cout << "temp[1]: " << i + 1 << endl;
                }
            }
            else{
                temp[0] = i;
                //cout << "temp[0]: " << i << endl;
            }
        }
    }
    if(temp[0] == 0){
        cout << "YES" << endl;
        //cout << 2 << endl;
        return 0;
    }else{
        if(p[temp[0] - 1] < p[temp[1]] && p[temp[1]] < p[temp[0] + 1]){
            if (p[temp[1] - 1] < p[temp[0]] && p[temp[0]] < p[temp[1] + 1])
            {
                cout << "YES" << endl;
                //cout << 3 << endl;
                return 0;
            }else{
                cout << "NO" << endl;
                //cout << 4 << endl;
                return 0;
            }
        }else{
            cout << "NO" << endl;
            //cout << 5 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
  final static private int MAX_DATA_COUNT = 10;
  public static void main(String[] args) throws java.io.IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    Integer[] mountainsHeightArr = new Integer[10];
    for (int i=0; i<MAX_DATA_COUNT; i++)
      mountainsHeightArr[i] = Integer.parseInt(br.readLine());
    Arrays.sort(mountainsHeightArr, Collections.reverseOrder());
    for (int i=0; i<3; i++)
      System.out.println(mountainsHeightArr[i]);
  }
}

Measured memory_bytes: 16872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int H = int.Parse(s[0]);
            int W = int.Parse(s[1]);
            s = Console.ReadLine().Split(' ');
            int h = int.Parse(s[0]);
            int w = int.Parse(s[1]);

            Console.WriteLine(H*W - h*W - H*w + h*w);
        }
    }
}


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

int main(){
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (u == s) cout << a-1 << " " << b << endl;
  else cout << a << " " << b-1;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
maxl=0
minr=1000000
for i in range(m):
  maxl=max(li[i][0],maxl)
  minr=min(minr, li[i][1])
if maxl<=minr:
  print(minr-maxl+1)
else:
  print(0)

Measured memory_bytes: 27332
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<30)

int n, s[101];
signed main(){

	cin >> n;
	int sum = 0;
	int m = INF;
	for (int i = 0; i < n; i++){
		cin >> s[i];
		sum += s[i];

		// 10で割り切れない最小の数
		if (s[i] % 10 != 0 && s[i] < m) m = s[i];
	}

	if (sum % 10 != 0) cout << sum << endl;
	else if(m!=INF) cout << sum - m << endl;
	else cout << 0 << endl;

	return 0;
}


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

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string a, b;
    std::cin >> a >> b;

    int ans = std::atoi((a + b).c_str());
    int root = sqrt(ans);

    std::cout << (root * root == ans ? "Yes" : "No");

    return 0;
}

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

namespace D
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var n = line[0];
			var h = line[1];
			var an = new List<int>(n);
			var bn = new List<int>(n);
			for (var i = 0; i < n; i++)
			{
				line = Console.ReadLine().Split().Select(int.Parse).ToArray();
				an.Add(line[0]);
				bn.Add(line[1]);
			}

			var aMax = an.Max();
			var idxList = new List<int>(n);
			for (var i = n - 1; i >= 0; i--)
			{
				if (bn[i] <= aMax) { idxList.Add(i); }
			}

			foreach (var idx in idxList)
			{
				an.RemoveAt(idx);
				bn.RemoveAt(idx);
			}

			bn.Sort();
			bn.Reverse();
			var sumOfThrowPower = 0;
			for (var i = 0; i < bn.Count; i++)
			{
				sumOfThrowPower += bn[i];
				if (sumOfThrowPower >= h)
				{
					Console.WriteLine(i + 1);
					return;
				}
			}

			var hp = h - sumOfThrowPower;
			Console.WriteLine(bn.Count + hp / aMax + (hp % aMax == 0 ? 0 : 1));
		}
	}
}

Measured memory_bytes: 18484
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 10
#define MAX_M 100000
#define INF 1e9
 
int N,M,coin[MAX_N];
int dp[MAX_M+1];
 
bool c(int x){
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j <= M ; j++){
	    if(dp[j] >= 0){
		dp[j] = x;
	    }else if(j < coin[i] || dp[j-coin[i]] <= 0){
		dp[j] = -1;
	    }else{
		dp[j] = dp[j-coin[i]]-1;
	    }
	}
    }
    return (dp[M] >= 0);
}
 
int main(){
    while(cin >> N >> M,(N|M)){
	for(int i = 0 ; i < N ; i++){
	    cin >> coin[i];
	}
	sort(coin,coin+N);
	int l = 0, r = M+1;
	while(r-l > 0){
	    int m = (l + r) / 2;
	    if(c(m)){
		r = m;
	    }else{
		l = m+1;
	    }
	}
	cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 3476
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static void swap(int[] data, int i, int j) {
        int tmp = data[i];
        data[i] = data[j];
        data[j] = tmp;
    }

    static int toInt(int[] data) {
        int ret = 0;
        for (int i : data) {
            ret *= 10;
            ret += i;
        }
        return ret;
    }

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

        HashMap<Integer, Integer> dist = new HashMap<>();
        int[] firstPuzzle = new int[]{0, 1, 2, 3, 4, 5, 6, 7};

        Queue<int[]> queue = new ArrayDeque<>();
        queue.add(firstPuzzle);
        dist.put(toInt(firstPuzzle), 0);

        while (!queue.isEmpty()) {
            int[] nowPuzzle = queue.poll();
            int nowDist = dist.get(toInt(nowPuzzle));

            int zPos = 0;
            for (int i = 0; i < 8; ++i) {
                if (nowPuzzle[i] == 0) zPos = i;
            }

            int[] directs = new int[3];
            directs[0] = (zPos == 3 || zPos == 7 ? zPos : zPos + 1);
            directs[1] = (zPos == 0 || zPos == 4 ? zPos : zPos - 1);
            directs[2] = (zPos < 4 ? zPos + 4 : zPos - 4);

            for (int j = 0; j < 3; ++j) {
                int[] nextPuzzle = nowPuzzle.clone();

                swap(nextPuzzle, zPos, directs[j]);
                int key = toInt(nextPuzzle);

                if (!dist.containsKey(key)) {
                    dist.put(key, nowDist + 1);
                    queue.add(nextPuzzle);
                }
                if (dist.containsKey(key) && dist.get(key) > nowDist + 1) {
                    dist.put(key, nowDist + 1);
                    queue.add(nextPuzzle);
                }
            }
        }

        while (scanner.hasNext()) {
            int[] puzzle = new int[8];

            for (int i = 0; i < 8; ++i) {
                puzzle[i] = scanner.nextInt();
            }
            System.out.println(dist.get(toInt(puzzle)));
        }
    }
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

int main()
{
    int k;cin >> k;
    int odd = (k+1)/2;
    int even = k/2;
    cout << odd*even << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;

	if (a < b) {
		if (b < c)
			std::cout << "Yes" << std::endl;
		else
			std::cout << "No" << std::endl;
	}
	else
		std::cout << "No" << std::endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
vector<ll> a[4];
map<ll, ll> b;
bool cmp(ll x, ll y){
	return x > y;
}
ll ma = -1e9, n, m, num;
void d(int x, ll num2, ll sum){
	if(num2 == m){
		ma = max(ma, sum);
		return ;
	}
	if(num2 > m){
		return ;
	}
	if(x == 4){
		ma = max(ma, sum);
		return ;
	}
	d(x+1, num2, sum);
	ll num3 = num2, sum2 = sum;
	for(int i = 0; i < a[x].size(); ++i){
		num3 += num+x, sum2 += a[x][i];
		d(x+1, num3, sum2);
	}
}
int main(){
	ll x, y;
	scanf("%lld%lld", &n, &m);
	for(int i = 0; i < n; ++i){
		scanf("%lld%lld", &x, &y);
		if(i == 0) num = x, a[x-num].push_back(y);
		else a[x-num].push_back(y);
	}
	sort(a[0].begin(), a[0].end(), cmp);
	sort(a[1].begin(), a[1].end(), cmp);
	sort(a[2].begin(), a[2].end(), cmp);
	sort(a[3].begin(), a[3].end(), cmp);
	d(0, 0, 0);
	printf("%lld\n", ma);
	return 0;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int n;
    char tmp;
    cin >> n;
    set<char> s;
    rep(i, n)
    {
        cin >> tmp;
        s.insert(tmp);
    }
    cout << (s.size() == 3 ? "Three" : "Four") << endl;
    return 0;
}

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

int main() {

    int A, B, C, D;

    cin >> A >> B >> C >> D;

    if (A + B == C + D)
        cout << "Balanced" << endl;
    else if(A + B < C + D)
        cout << "Right" << endl;
    else
        cout << "Left" << endl;

}

Measured memory_bytes: 256