akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  // vector<vector<int>> v(n, vector<int> (n-1));
  int v[1010][1010];
  rep(i, n) rep(j, n-1){
    cin >> v[i][j];
    v[i][j]--;
  }
  // vector<int> index(n, 0);
  int index[1010];

  for (int i = 1; i <= ((n-1) * n) / 2; i++) {
    // vector<bool> battled(n, false);
    bool battled[1010];
    rep(j, 1010) battled[j] = false;
    // cout << "===" << endl;
    // cout << i << endl;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if(index[j] >= n-1) continue;
      int enemy = v[j][index[j]];
      if(index[j] >= n-1 || index[enemy] >= n-1) continue;
      if(v[enemy][index[enemy]] == j && !battled[j] && !battled[enemy]){
        flag = false;
        battled[j] = true;
        battled[enemy] = true;
        index[enemy]++;
        index[j]++;
      }
    }
    if(flag) break;

    flag = true;
    rep(j, n){
      if(index[j] < n-1) {
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

}


Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,k;
    cin >> a >> b >> k;

    vector<ll> ax(1,1);
    ll count = 1;
    ll ans = 1;

    while(ans <= a && ans <= b){
        ans++;
        if(a%ans == 0 && b%ans == 0){
            ax.push_back(ans);
            count++;
        }
    }


    cout << ax[count - k] << endl;
    
    return 0;
}

Measured memory_bytes: 384
$n=<>;
@a=glob<>;
@b=glob<>;
$ans=0;
for(my$i=0;$i<$n;$i++){
    $d=$a[$i]-$b[$i];
    $s+=$d;
    push(@p,$d) if($d>0);
    if($d<0){
        $t-=$d; 
        $ans++;
    }
}
if($s<0){
    print -1;
    exit;
}
@p=sort{$b<=>$a}@p;
while($t>0){
    $t-=shift(@p);
    $ans++;
}
print$ans

Measured memory_bytes: 36544
#include <iostream>
using namespace std;
    int n,q;
    int a[30];
    bool solve(int i, int m){
        if(m==0) return true;
        if(i>=n) return false;
        bool res=solve(i+1,m) || solve(i+1,m-a[i]);
        return res;
    }
    
    int main(void){
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    cin>>q;
    for(int i=0;i<q;i++){
        int m;
        cin>>m;
        if(solve(0,m)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }

    }    
    // Your code here!

Measured memory_bytes: 3092
#include <cstdio>
#include <queue>
#define MAX 1000
#define INF 100000

using namespace std;

struct Node {
    int x, y;
};
const int dir[4][2] = {
    {1, 0}, {-1, 0}, {0, 1}, {0, -1}
};
Node start;
char map[MAX + 5][MAX + 5];
int dis[MAX + 5][MAX + 5];
int h, w, n;

int BFS(char cheap);

int main(void)
{
    int step = 0;
    scanf("%d%d%d", &h, &w, &n);
    for (int i = 0; i < h; ++i)
        scanf("%s", map[i]);
    
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            if (map[i][j] == 'S') {
                start.x = i;
                start.y = j;
                break;
            }

    for (int i = 1; i <= n; ++i) {
        step += BFS('0' + i);
    }

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

int BFS(char cheap)
{
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            dis[i][j] = INF;

    dis[start.x][start.y] = 0;

    Node now, next;
    queue<Node> q;

    q.push(start);

    while (!q.empty()) {
        now = q.front();
        q.pop();

        if (map[now.x][now.y] == cheap) {
            start.x = now.x;
            start.y = now.y;
        } else {
            for (int i = 0; i < 4; ++i) {
                next.x = now.x + dir[i][0];
                next.y = now.y + dir[i][1];

                if (next.x >= 0 && next.x < h &&
                        next.y >= 0 && next.y < w &&
                        map[next.x][next.y] != 'X' &&
                        dis[next.x][next.y] == INF) {
                    dis[next.x][next.y] = dis[now.x][now.y] + 1;
                    q.push(next);
                }
            }
        }
    }

    return dis[start.x][start.y];
}

Measured memory_bytes: 5984
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
s=input()
t=input()
ans=[]
for a in range(len(s)-len(t)+1):
    temp=list(s)
    f=True
    for b in range(len(t)):
        if(temp[a+b]!="?" and t[b]!=s[a+b]):f=False
        temp[a+b]=t[b]
    if f:
        ans.append(join(temp,"").replace("?","a"))
if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])


Measured memory_bytes: 6252
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;

int rot[] = {0,4,5,1,3,7,6,2};
vector<vi> rots;

void next(vi &x){
  rep(i,3){
    swap(x[i],x[i+1]);
    swap(x[i+4],x[i+5]);
  }
}

bool t[1<<24];

int main(){
  vi tmp;
  rep(i,8)tmp.push_back(i);
  rots.push_back(tmp);
  rep(i,3){
    next(tmp);
    rots.push_back(tmp);
  }

  rep(i,4){
    tmp = rots[i];
    reverse(all(tmp));
    rots.push_back(tmp);
  }

  rep(i,16){
    tmp.resize(8);
    rep(j,8)tmp[j] = rots[i][rot[j]];
    rots.push_back(tmp);
  }

  string s;
  while(cin >> s){
    map<string,int> m;
    m[s]++;
    rep(i,7)cin >> s, m[s]++;
    vi v;
    int id=0;
    for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
      rep(i,it->second)v.push_back(id);
      id++;
    }

    int ans = 0;
    rep(i,1<<24)t[i] = false;

    do{
      int h = 0;
      rep(i,8)h*=8,h+=v[i];
      if(!t[h]){
	rep(i,24){
	  h = 0;
	  rep(j,8)h*=8,h+=v[rots[i][j]];
	  t[h] = true;
	}
	ans++;
      }
    }while(next_permutation(all(v)));

    cout << ans << endl;
  }
}

Measured memory_bytes: 17608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;

int main(){

    int n;
    cin >> n;
    string temp;
    int minCnt[26];

    for(int i = 0; i < 26; i++){
        minCnt[i] = 50;
    }

    for(int i = 0; i < n; i++){
        cin >> temp;
        int cnt[26];
        memset(cnt, 0, sizeof(cnt));

        for(int j = 0; j < (int)temp.size(); j++){
            cnt[temp[j] - 'a']++;
        }

        for(int j = 0; j < 26; j++){
            minCnt[j] = min(minCnt[j], cnt[j]);
        }
    }

    string ans = "";
    for(int i = 0; i < 26; i++){
        int tempCnt = minCnt[i];
        while(tempCnt > 0){
            char c = 'a' + i;
            ans += c;
            tempCnt--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 101
int num[N], n, maxn, minn = N;
int main() {
    scanf("%d", &n);
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        num[x]++;
        maxn = max(maxn, x);
        minn = min(minn, x);
    }
    int mid = (maxn + 1) >> 1;
    bool flag = (minn >= mid) && (num[mid] == (maxn & 1) + 1);
    for (int i = maxn; i > mid && flag; i--)
        if (num[i] < 2) flag = false;
    puts(flag ? "Possible" : "Impossible");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
using namespace std;
typedef long long ll;
 
const int maxn = 2005;
 
int digit(int val)
{
  int res = 0;
  while (val){
    res += val % 10;
    val /= 10;
  }
  return res;
}
 
signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  int n; cin >> n;
  int res = 1e9;
  for (int a = 1; a < n; ++a){
    int b = n - a;
    res = min(res, digit(a) + digit(b));
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	
	int n,s;
	while(cin>>n){
			int count=0;	
		for(int a=0;a<=9;a++){
			for(int b=0;b<=9;b++){
				for(int c=0;c<=9;c++){
					for(int d=0;d<=9;d++){
						if(a+b+c+d==n)
							count++;
					}
				}
			}
		}
		cout<<count<<endl;
	}
}

Measured memory_bytes: 1156
import copy


class Dice:
    def __init__(self, eyes: [int]):
        self.__eyes = eyes

    def top(self):
        return self.__eyes[0]

    def roll_s(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[4]
        tmp[1] = self.__eyes[0]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[5]
        tmp[5] = self.__eyes[1]
        self.__eyes = tmp

    def roll_e(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[3]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[0]
        tmp[3] = self.__eyes[5]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[2]
        self.__eyes = tmp

    def roll_n(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[1]
        tmp[1] = self.__eyes[5]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[0]
        tmp[5] = self.__eyes[4]
        self.__eyes = tmp

    def roll_w(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[2]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[5]
        tmp[3] = self.__eyes[0]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[3]
        self.__eyes = tmp

    def roll(self, direction: str):
        if direction == 'N':
            self.roll_n()
        if direction == 'E':
            self.roll_e()
        if direction == 'S':
            self.roll_s()
        if direction == 'W':
            self.roll_w()


def resolve():
    eyes = list(map(int, input().split()))
    directions = list(input())
    dice = Dice(eyes)
    for direction in directions:
        dice.roll(direction)
    print(dice.top())


resolve()



Measured memory_bytes: 6352
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int max1 = 0;
	int max2 = 0;
	for(int i=0;i<n;i++)
	{
		if(max1<arr[i])
		{
			max2 = max1;
			max1 = arr[i];
		}
		else if(max2 < arr[i])
		{
			max2 = arr[i];
		}
	}
	for(int i=0;i<n;i++)
	{
		if(arr[i] == max1)
		{
			cout<<max2<<endl;
		}
		else
		{
			cout<<max1<<endl;
		}
	}
}

Measured memory_bytes: 3200
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long
#define mo 1000000009

int a[6000];
int d[11000];
int d1[11000];

int main()
{
  int i,j,n,k,nn,ans,x,b1;
  scanf("%d%d",&n,&k);
  nn=0;
  for (i=0;i<n;i++)
  {
    scanf("%d",&x);
    if (x<k)
    {
      a[nn]=x;nn++;
    }
  }
  n=nn;
  memset(d,0,sizeof(d));
  d[0]=1;
  for (i=0;i<n;i++)
  {
    for (j=k;j>=0;j--)
    {
      d[j+a[i]]+=d[j];
      if (d[j+a[i]]>=mo) d[j+a[i]]-=mo;
    }
  }
  ans=0;
  for (i=0;i<n;i++)
  {
    memcpy(d1,d,sizeof(d));
    b1=0;
    for (j=0;j<k;j++)
      if (d1[j]>0)
      {
        if (j+a[i]>=k)
        {
          b1=1;break;
        }
        d1[j+a[i]]-=d1[j];
        d1[j]=0;
        if (d1[j+a[i]]<0) d1[j+a[i]]+=mo;
      }
    if (b1==0) ans++;
  }
  printf("%d\n",ans);
  return 0;
}

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

int main(){
    double t,x;
    cin>>t>>x;
    printf("%.12f\n",t/x);
}

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

int main(){
    int N;
    cin>>N;
    int D1[N],D2[N];
    for(int i=0;i<N;i++){
        cin>>D1[i];
        cin>>D2[i];
    }
    for(int i=0;i<N-2;i++){
        if(D1[i]==D2[i]&&D1[i+1]==D2[i+1]&&D1[i+2]==D2[i+2]){
            cout<<"Yes"<<endl;
            exit(0);
        }
    }
    cout<<"No"<<endl;

    
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A + B >= A - B && A + B >= A * B) {
    cout << A + B << endl;
  }
  else if(A - B >= A * B) {
    cout << A - B << endl;
  }
  else {
    cout << A * B << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include<stack>
#include<string>
#include<algorithm> 
#include <set>
#include<list>
using namespace std;
#define F first
#define S second
#define li long long int 
#define ld long double
#define pb push_back
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

li val(li x, li y, li z)
{
	li ans = x * x + y * y + z * z + x * y + y * z + x * z;
	return ans;
}
int main()
{
	li N; cin >> N;
	vector<li> A(N + 1, 0);
	for (int i = 1; i <= 100; i++)
	{
		for (int j = 1; j <= 100; j++)
		{
			for (int k = 1; k <= 100; k++)
			{
				if (val(i, j, k) <= N)
					A[val(i, j, k)]++;
			}
		}
	}
	for (int i = 1; i <= N; i++)
		cout << A[i] << '\n';
	return 0;
}

Measured memory_bytes: 3672
/*
  ID: oodt
  PROG:
  LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>

using namespace std;

const int maxx=1005;
int n,m,k;
int a[maxx][maxx];
int b[maxx][maxx];
int ans = 0,cnt = 0,pos = 0;
int l = 0,r = 0;
const int INF = 0x3f3f3f3f;

int main()
{
#ifdef LOCAL
    freopen("/Users/ecooodt/Desktop/c++ and acm/cf/#423 div2/3.txt","r",stdin);
#endif
    scanf("%d",&n);
//    printf("%d\n",n);
    for(int ii = 0; ii < n; ii++)
    {
        for(int i = 0; i < 10; i++)
        {
            scanf("%d",&a[ii][i]);
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 11; j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    int t = 0;
    int v[12];
//    printf("%d",n);
//    cout<<"ok";
    int temp;
    ans = -INF;
    for(int i = 1; i < 1024; i++)
    {
        t = 0;
        int q = i;
        while(q != 0)
        {
            v[t++] = q % 2;
            q = q >> 1;
//            cout<<t<<endl;
        }
        for(int j = t; j < 10; j++)
        {
            v[j] = 0;
        }
        for(int j = 0; j < 10; j++)
        {
//            cout<<v[j]<<" ";
        }
        for(int j = 0; j < n; j++)
        {
            cnt = 0;
            for(int k = 0; k < 10; k++)
            {
                if(v[k] && a[j][k]) cnt++;
            }
//            cout<<"   "<<cnt;
            if(j == 0) temp = b[j][cnt];
            else temp += b[j][cnt];
        }
//        cout<<"   "<<temp;
        ans = max(ans,temp);
//        cout<<" "<<ans<<endl;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll dp[2020][2020];

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

	int N;
	cin >> N;
	vector<pair<ll,ll>>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first;
		A[i].second = i;
	}
	sort(all(A));
	reverse(all(A));

	for (int tot = 1; tot <= N;tot++) {
		for (int i = 0; i <= tot;i++) {
			int j = tot - i;
			ll c = A[tot - 1].first;
			int k = A[tot - 1].second;
			ll pre1 = (i != 0)?dp[i-1][j]:-inf;
			ll pre2 = (j != 0)?dp[i][j-1]:-inf;
			dp[i][j] = max(pre1 + c*abs(k-i+1),pre2 + c*abs(N-j-k));
		}
	}

	ll ans = -1;
	for (int i = 0; i <= N; i++)ans = max(ans,dp[i][N-i]);
	puts(ans);

	return 0;
}

Measured memory_bytes: 26360
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
double n;
signed main(){
	scanf("%lf",&n);
	printf("%.10lf\n",n*pi*2);
	return 0;
}


Measured memory_bytes: 3812
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace CSharp_Shell
{

    public static class Program 
    {
        public static void Main() 
        {
          int[] DTS = Console.ReadLine().Split(' ').Select(x => int.Parse(x.ToString())).ToArray();
          int D = DTS[0] , T = DTS[1] ,S = DTS[2];
          if(T * S >= D) 
          Console.WriteLine("Yes");
          else
          Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 28276
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;

    while (cin >> n, n) {
        int max_p, max_d;
        int p, d1, d2;

        max_p = max_d = -100;
        for (int i = 0; i < n; i++) {
            cin >> p >> d1 >> d2;
            
            if (d1 + d2 > max_d) {
                max_d = d1 + d2;
                max_p = p;
            }
        }
        cout << max_p << " " << max_d << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;
    string ans(2 * N, '_');
    rep(i, N) {
        ans[2 * i] = S[i];
        ans[2 * i + 1] = T[i];
    }
    write(ans);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int[] tmp =Readint();
    int a=tmp[0], b=tmp[1];
    int hole=a,res=1;
    if(b<2){
      WriteLine("0");
      return;
    }
    while(true){
      if(hole>=b)
        break;
      hole+=a-1;
      res++;
    }
    WriteLine(res.ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}

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

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		
		K--;
		String s = sc.next();
		
		String newS ="";
		newS += s.substring(0,K);
		newS += s.substring(K,K+1).toLowerCase();
		newS += s.substring(K+1);
		
		out.println(newS);
		
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

/*
Nは2〜8なので、
8でも40320通り -> 全探索でいける。問題は辞書順にどう並べるか。
*/

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

    vector<int> C(N);
    for (int i = 0; i < N; i++)
    {
        C[i] = i + 1;
    }

    vector<int> P(N), Q(N);

    for (int i = 0; i < N; i++)
    {
        cin >> P[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> Q[i];
    }

    int i = 1;
    int a, b;
    do
    {

        if (C == P) {
            a = i;
        }
        if (C == Q) {
            b = i;
        }
        i++;

    } while (next_permutation(C.begin(), C.end()));
    
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 1;
        for(;i<20000;i++){
            int x = sc.nextInt();
            if(x == 0){
                break;
            }
            else{
                System.out.println("Case "+i+": "+x);
            }
            
        }
        
    }
}


Measured memory_bytes: 45360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>

using namespace std;

typedef pair<int, int> P;

int main() {
	int m, n;
	
	while (cin >> m && m != 0) {
		P p[200], s[1000];
		map<P, bool> mp;

		for (int i = 0; i < m; ++i) {
			cin >> p[i].first >> p[i].second;
		}
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> s[i].first >> s[i].second;
			mp[s[i]] = true;
		}

		//O(n^2m)
		for (int i = 0; i < m; ++i) { //i??¨
			for (int j = 0; j < n; ++j) { //j???????????????
				int dx = s[j].first - p[i].first;
				int dy = s[j].second - p[i].second;
				bool success = true;
				for (int k = 0; k < m; ++k) { //??????k????????¨?????????
					if (mp[make_pair(p[k].first + dx, p[k].second + dy)] != true) {
						success = false;
						break;
					}
				}
				if (success) {
					cout << dx << " " << dy << endl;
					i = m;
					break;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3192
x1, y1, x2, y2 = list(map(int, input().split())) 

#solve x4y4
x2da = x2 - x1
y2da = y2 - y1

x4da = -y2da  
y4da = x2da

x4 = x4da + x1
y4 = y4da + y1

#solve x3y3
x1da = x1 - x2
y1da = y1 - y2

x3da = y1da
y3da = -x1da

x3 = x3da + x2
y3 = y3da + y2

print(x3, end=" ")
print(y3, end=" ")
print(x4, end=" ")
print(y4)

Measured memory_bytes: 9208
# from collections import defaultdict
# dd = defaultdict(lambda: 0)

N = int(input())
T = [dict() for _ in range(N)]

for i in range(N-1):
    u, v, w = [int(x) for x in input().split()]
    u -= 1
    v -= 1
    T[u][v] = w
    T[v][u] = w

opened = {0}
g0 = {0}
used = {0}

while len(opened) != 0:
    n = opened.pop()
    for n2 in T[n]:
        if n2 in used:
            continue
        if n in g0:
            if T[n][n2] % 2 == 0:
                g0.add(n2)
        else:
            if T[n][n2] % 2 == 1:
                g0.add(n2)
        opened.add(n2)
        used.add(n2)

for i in range(N):
    print(0 if i in g0 else 1)






Measured memory_bytes: 51812
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
#define FOR(i,n) for(int i=0;i<n;i++)
//map<key,value>

int main(){
  int n,d;
  cin >> n >> d;
  int tmp = 2*d + 1;
  if(n%tmp == 0){
    cout << n/tmp;
    return 0;
  }
  else{
    cout << (n/tmp) + 1;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    scan.close();

    int n = N % 10;
    if(n==2 || n==4 || n==5 || n==7 || n==9) {
      System.out.println("hon");
    }
    else if(n==0 || n== 1 || n==6 || n==8) {
      System.out.println("pon");
    }
    else if(n==3) {
      System.out.println("bon");
    }
  }
}

Measured memory_bytes: 27084
function main(input){
  input = input.trim().split("\n");
  var kazu = input[0];
  var list = input[1].split(" ");
  var seki = BigInt(list[0]);
  var limit = Math.pow(10,18);
  
  if(kazu=="0" || list.includes("0")==true){
    seki=0;
  }else{
  	for(var i=1; i<list.length; i++){
  	  seki = BigInt(seki) * BigInt(list[i]);
      if(seki>limit){break;}
  	}
  }
  
  if(seki<=limit){
    console.log(seki.toString());
  }else{
  	console.log(-1);
  }
}main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 39876
l=int(input())
d=l.bit_length()
graph=[]
for i in range(d-1):
  graph.append((i+1,i+2,0))
  graph.append((i+1,i+2,2**(d-i-2)))
s=1<<(d-1)
for i in reversed(range(d-1)):
  if (1<<i)&l:
    graph.append((1,d-i,s))
    s+=1<<i
print(d,len(graph))
for u,v,c in graph:
  print(u,v,c)


Measured memory_bytes: 38512
a, b = map(int,input().split())
cnt = 0
def kaibun(n):
    s = str(n)
    rs = reversed(s)
    for i,j in zip(s,rs):
        if i != j:
            return False
    return True
for i in range(a, b+1):
    if kaibun(i):
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
st = input()
a = int(st[:2])
b = int(st[2:])


if a > 0 and a <=12:
  mm_first = 1
else: mm_first = 0
if b > 0 and b <= 12:
  mm_second = 1
else: mm_second = 0

if mm_first and mm_second:
  print("AMBIGUOUS")
  
elif mm_first :
  print("MMYY")
  
elif mm_second:
  print("YYMM")
  
else:
  print("NA")

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

int main() {
  int d, type = 26;
  vector<int> c;
  vector<vector<int>> s;
  vector<int> t;
  vector<int> v;
  vector<int> last;

  cin >> d;

  for (int i = 0; i < type; i++) {
    int tmp;
    cin >> tmp;
    c.push_back(tmp);
  }

  for (int i = 0; i < d; i++) {
    vector<int> vtmp;
    for (int j = 0; j < type; j++) {
      int tmp;
      cin >> tmp;
      vtmp.push_back(tmp);
    }
    s.push_back(vtmp);
  }

  for (int i = 0; i < d; i++) {
    int tmp;
    cin >> tmp;
    t.push_back(tmp);
  }

  // cout << d << endl;
  // for (int i = 0; i < type; i++) {
  //   cout << c[i] << " ";
  // }
  // cout << endl;

  // for (int j = 0; j < d; j++) {
  //   for (int i = 0; i < type; i++) {
  //     cout << s[j][i] << " ";
  //   }
  //   cout << endl;
  // }

  // for (int i = 0; i < d; i++) {
  //   cout << t[i] << " ";
  // }
  // cout << endl;

  for (int i = 0; i < type; i++) {
    last.push_back(-1);
  }

  for (int day = 0; day < d; day++) {
    last[t[day] - 1] = day;
    int desat = 0;
    for (int j = 0; j < type; j++) {
      desat += c[j] * (day - last[j]);
    }
    // cout << "desat " << desat << endl;
    if (day == 0) {
      v.push_back(s[day][t[day] - 1] - desat);
    } else {
      v.push_back(v[day - 1] + s[day][t[day] - 1] - desat);
    }
    cout << v[day] << endl;
  }
  return 0;
}

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

int main()
{
    int n;
    deque<int> dq;
    cin >> n;

    int head;
    cin >> head;

    dq.push_front(head);

    for (int i = 1; i < n; ++i) {
        int tmp;
        cin >> tmp;
        if ((i - n) % 2 == 0) {
            dq.push_back(tmp);
        } else {
            dq.push_front(tmp);
        }
    }

   for (int i = 0; i < n - 1; ++i) {
        cout << dq[i] << " ";
    }
    cout << dq[n-1] << endl;
    return 0;
}


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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0; i<n; i++) cin >> a[i];
  
  ll ans = 0;
  ll target = 1;
  bool flag = true;
  for(ll i=0; i<n; i++){
  	if(a[i] == target){
      target++;
      flag = false;
    }else{
      ans++;
    }
  }
  
  if(flag){
  	cout << "-1" << endl;
  }else{
  	cout << ans << endl;
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

int prime(int n){
    //int cnt = 0 ;
    for(int i = 2 ; i <= sqrt(n) ; ++i){
        if(n % i == 0) {
           return 1 ;   
        }
    }

    return 0  ; 
}


int fastpower(int n , int m , int tmp = 1e9+7) {
    ll ans = 1 ; 
    while(m > 0) {
        if(m % 2 != 0 ){
            ans = (ans * n) % tmp  ; 
            m--;
        }
        else {
            n = (n * n) % tmp  ; 
            m = m /2 ;
        }
    }
    return ans % tmp ; 
}

void primeFactorization(int n) {
    map<int,int> factors ; 
    while(n % 2 == 0) {
        factors[2]++;
        n = n / 2 ; 
    }

    for(int i = 3 ; n > 1 ; ++i) {
        while(n % i == 0) {
            factors[i]++;
        }
    }
}


void solve() {
    int n, W ; 
    cin >> n >> W ; 
    const ll inf = 1e18 ; 
    vector<int> weights(n) , values(n) ; 
    for(int i = 0 ; i < n ; ++i) 
        cin >> weights[i] >> values[i] ;
    // dp[i] -> contains minimum weight that has value exactly i.

    int sum_values = 0 ;
    for(int x : values) sum_values += x ; 

    vector<ll> dp(sum_values+1, inf) ; 
    dp[0] = 0 ; 
    for(int i =0 ; i < n ; ++i) {
        for(int j = sum_values  ; j - values[i] >=0  ; --j) {
            dp[j] = min(dp[j],(ll) dp[j-values[i]] + weights[i]) ; 
            //cout << "for j = " << j << ": "<< dp[j-values[i]] + weights[i] << endl ; 
        } 
    }

    int ans = 0 ;
    for(int i=0 ; i <= sum_values ; ++i) {
        //cout << dp[i] << " " ; 
        if(dp[i] <= W)
            ans = max(ans, i) ; 
    }

    cout << ans << endl; 

    


}


int main() {
   int t=1; 
   //cin >> t;

   while(t--){
    solve() ; 

   }



    return 0; 
}

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

const int MAX_N = 100000;

int main() {
  int N, ansj;
  string s;
  int r[MAX_N], ans[4][MAX_N];
  bool flag;
  cin >> N >> s;
  for (int i=0; i<N; i++) {
    r[i] = (s[i] == 'o' ? 1 : -1);
  }
  ans[0][0] = ans[1][0] = 1;
  ans[2][0] = ans[3][0] = -1;
  if (r[0] == 1) {
    ans[0][1] = ans[0][N-1] = 1;
    ans[1][1] = ans[1][N-1] = -1;
    ans[2][1] = 1; ans[2][N-1] = -1;
    ans[3][1] = -1; ans[3][N-1] = 1;
  } else {
    ans[0][1] = 1; ans[0][N-1] = -1;
    ans[1][1] = -1; ans[1][N-1] = 1;
    ans[2][1] = ans[2][N-1] = 1;
    ans[3][1] = ans[3][N-1] = -1;
  }
  flag = false;
  for (int j=0; j<4; j++) {
    for (int i=1; i<N-2; i++) {
      ans[j][i+1] = ans[j][i] * ans[j][i-1] * r[i];
    }
    if (ans[j][N-2] == ans[j][N-1] * ans[j][0] * r[N-1]
        && ans[j][N-1] == ans[j][N-3] * ans[j][N-2] * r[N-2]) {
      ansj = j;
      flag = true;
      break;
    }
  }
  if (flag) {
    for (int i=0; i<N; i++) {
      cout << (ans[ansj][i] == 1 ? 'S' : 'W');
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}






Measured memory_bytes: 2560
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
 cout<<fixed<<setprecision(12);
  int n ;
    
 while(1){
  cin >> n ;
  if(n==0)break ;
  double s[n] ;
  double sum = 0.0 ;

  for(int i=0;i<n;i++){
      cin >> s[i] ;
      sum += s[i] ;
  }
  
  double mean = sum/n ;
    sum = 0.0 ;

  for(int i=0;i<n;i++){
     sum+= (s[i]-mean)*(s[i]-mean) ;
  }
  
  cout << sqrt(sum/n) << endl ;
     
 }


    return 0;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    a.at(i) -= k;
  }
  
  vector<int64_t> s(n + 1);
  for (int i = 0; i < n; i++) {
    s.at(i + 1) = s.at(i) + a.at(i);
  }
  
  vector<int64_t> r = s;
  sort(r.begin(), r.end());
  
  vector<int> p(n + 1);
  for (int i = 0; i <= n; i++) {
    p.at(i) = lower_bound(r.begin(), r.end(), s.at(i)) - r.begin();
    assert(p.at(i) <= n);
  }
  
  int64_t ans = 0;
  vector<int> t(n + 2);
  for (int i = 0; i <= n; i++) {
    int index = p.at(i) + 1;
    while (index) {
      ans += t.at(index);
      index -= index & -index;
    }
    index = p.at(i) + 1;
    while (index < t.size()) {
      t.at(index)++;
      index += index & -index;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 8784
#include<stdio.h>

int main()
{
  int x,y,z,r;

  scanf("%d%d",&x,&y);
  if(x<y){
    z = x;
    x = y;
    y = z;
  }

  while(y>0)
    {
      
     if(x>=y)
       {
	 r = x%y;
         x = y;
	 y = r;
       }
    }

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



Measured memory_bytes: 2084
#include<stdio.h>
int kaijo(int k)
{
  if(k>1) return k*kaijo(k-1);
  else if(k<=1) return 1;
}
int main(void)
{
  int n;
  scanf("%d",&n);
  int p[n+1],q[n+1],p_tmp[n+1],q_tmp[n+1];
  for(int i=1;i<=n;i++){
    scanf("%d",&p[i]);
    p_tmp[i]=0;
  }
  for(int i=1;i<=n;i++){
    scanf("%d",&q[i]);
    q_tmp[i]=0;
  }
  int a=1,b=1;
  for(int i=1;i<=n;i++){
    int cnt=0;
    p_tmp[p[i]]=1;
    for(int j=1;j<p[i];j++){
      if(p_tmp[j]==0) cnt++;
    }
    //printf("%d\n",p[i]);
    a+=cnt*kaijo(n-i);
  }
  for(int i=1;i<=n;i++){
    int cnt=0;
    q_tmp[q[i]]=1;
    for(int j=1;j<q[i];j++){
      if(q_tmp[j]==0) cnt++;
    }
    //printf("%d\n",p[i]);
    b+=cnt*kaijo(n-i);
  }
  if(a>b) printf("%d",a-b);
  else printf("%d",b-a);
  
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main(){
  string n;
  cin >> n;
  int digit_sum=0;
  for(unsigned long int i=0;i<n.size();i++){
    digit_sum+=ctoi(n.at(i));
  }
  if(digit_sum%9==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int A, B;
	string S;
	cin >> A >> B;
	cin >> S;

	bool bCheck = true;
	rep(i, A + B + 1) {
		if (i == A) {
			if (S[i] != '-') bCheck = false;
		}
		else {
			if ((int)'0' > (int)S[i] || (int)S[i] > (int)'9') bCheck = false;
		}
	}

	if (bCheck) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	In := readLineInt()
	sort.Ints(In)
	fmt.Println(In[0] + In[1])
}

/////////////////////////////////////////

func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}


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

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

    int n, q;
    cin >> n >> q;

    vector<tuple<int, int, int>> a(n);
    map<int, int> d, f;

    rep(i, n)
    {
        int s, t, u;
        cin >> s >> t >> u;
        a[i] = make_tuple(u, s - u, t - u);
    }
    sort(a.begin(), a.end());

    rep(i, q)
    {
        int e;
        cin >> e;
        d.insert(make_pair(e, -1));
    }

    rep(i, n)
    {
        while (d.lower_bound(get<1>(a[i])) != d.upper_bound(get<2>(a[i]) - 1))
        {
            f.insert(make_pair(d.lower_bound(get<1>(a[i]))->first, get<0>(a[i])));
            d.erase(d.lower_bound(get<1>(a[i])));
        }
    }

    for (auto x : d)
    {
        f.insert(x);
    }
    for (auto x : f)
    {
        cout << x.second << endl;
    }

    return 0;
}


Measured memory_bytes: 21888
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
 
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

//const int mod= 998244353; 

signed main() {
 
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif	
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(x!=i)
			ans++;
	}	
	if(ans==0 || ans==2)
	{
		cout<<"YES"<<endl;
	}else{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
  input!(q:u64, h:u64, s:u64, d:u64, n:u64);
  let s = *[s, 2*h, 4*q].iter().min().unwrap();
  let d = d.min(2*s);
  println!("{}", d*(n/2) + s*(n%2));
}


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

ll kaijo( ll n ){
  if( n == 0 ) return 1;
  return n*kaijo(n-1);
}

ll comb( ll n, ll r ){
  return kaijo(n)/kaijo(r)/kaijo(n-r);
}

int main(){
  ll n;
  cin >> n;
  string m = "MARCH";
  vector<ll> cnt(5);
  vector<string> s(n);
  rep(i,n) cin >> s.at(i);
  rep(i,n){
    rep(j,5){
      if( s.at(i).at(0) == m.at(j) ) cnt.at(j)++;
    }
  }
  ll type_num = 0;
  rep(i,5) if( cnt.at(i) > 0 ) type_num++;
  if( type_num < 3 ){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(ll i=0;i<3;++i){
    if( cnt.at(i) == 0 ) continue;
    for(ll j=i+1;j<4;++j){
      if( cnt.at(j) == 0 ) continue;
      for(ll k=j+1;k<5;++k){
        if( cnt.at(k) == 0 ) continue;
        //cout << cnt.at(i) << " " << cnt.at(j) << " " << cnt.at(k) << endl;
        ans += cnt.at(i)*cnt.at(j)*cnt.at(k);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int n){
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    for (int i = 0; i <= 10000; ++i) {
        int ok = v[0] == 1;
        for (int j = 0; j+1 < v.size(); ++j) {
            ok &= (v[j+1]-v[j] == 1);
        }
        if(ok) {
            cout << i << "\n";
            return;
        }
        for (auto &&j : v) {
            j--;
        }
        int sz = v.size();
        v.erase(remove(v.begin(),v.end(), 0), v.end());
        v.emplace_back(sz);
    }
    puts("-1");
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3236
#include <stdio.h>

int A[100000];
int n;

int partition(int p,int r){
  int x,i,j,s,t;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      s=A[i];
      A[i]=A[j];
      A[j]=s;
    }
  }
    t=A[i+1];
    A[i+1]=A[r];
    A[r]=t;

  return i+1;
}

int main(){

  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 q=partition(0,n-1);
 for(i=0;i<n;i++){
   //   if(i<n-1)printf(" ");                                                   
   if(i==q)printf("[");
   printf("%d",A[i]);
   //   if(i<n-1)printf(" ");                                                   
   if(i==q)printf("]");
if(i<n-1)printf(" ");
 }
 printf("\n");
 return 0;
}




Measured memory_bytes: 2120
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let r=read::<i32>();
    let d=read::<i32>();
    let mut x=read::<i32>();
    for _ in 0..10{
        x=x*r-d;
        println!("{}",x)
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N, K; cin >> N >> K;
  vecll LI(N);
  REP(i, N) cin >> LI[i];
  sort(LI.begin(), LI.end());
  ll mm = *LI.begin();
  ll MM = *(LI.end() - 1);
  ll hi = max(MM*MM, mm*mm)+1;
  ll lo = min(min(mm*mm, MM*mm), MM*MM);
  ll value_mid = 0;
  int zeroIdx = lower_bound(LI.begin(), LI.end(), 0LL) - LI.begin();
  // std::cout << "zero: " << zeroIdx << endl;
  while (hi != lo) {
    value_mid = lo + (hi - lo)/2;    
    ll cnt = 0, lft = 0, rgt = zeroIdx;
    // --
    while (lft < rgt) {
      if (LI[lft]*LI[rgt-1] < value_mid) {
        cnt += rgt - lft - 1;
        rgt -= 1;
      } else {
        lft += 1;
      }
    }

    // -+
    lft = 0;
    rgt = zeroIdx+1;
    while (rgt <= N && LI[lft] < 0 && LI[rgt-1] >= 0) {
      if (LI[lft]*LI[rgt-1] < value_mid) {
        cnt += N - rgt + 1;
        lft += 1;
      } else {
        rgt += 1;
      }
    }

    // ++
    lft = zeroIdx;
    rgt = N;
    while (lft < rgt) {
      if (LI[lft]*LI[rgt-1] < value_mid) {
        cnt += rgt - lft - 1;
        lft += 1;
      } else {
        rgt -= 1;
      }
    }
    if (cnt < K) lo = value_mid + 1;
    else hi = value_mid;
    // std::cout << (lo-1) << " " << hi << endl;
  }
  std::cout << (lo-1) << endl;
  return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
const int N = 1e5 + 11;
bool isprime[N];
int n;
vector<int> primes;

void solve(){
   	fill(isprime + 2, isprime + N, true);
   	for(int i = 2; i < N; i++){
	  if (isprime[i]){
		primes.push_back(i);
		for(int j = 2; i * j < N; j++){
		  isprime[i * j] = false;	
		}  
	  }	
   }
  while(cin >> n){
	  for(int i = n - 1; ; i--) if (isprime[i]) {cout << i << " "; break;}
	  for(int i = n + 1; ; i++) if (isprime[i]) {cout << i << endl; break;}  
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3340