akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    string s;
    int ac = 0, wa = 0, tle = 0, re = 0;
    while (cin >> s) {
        if (s == "AC") ac++;
        else if (s == "WA") wa++;
        else if (s == "TLE") tle++;
        else re++;
    }

    cout << "AC" << " " << "x" << " " << ac << endl;
    cout << "WA" << " " << "x" << " " << wa << endl;
    cout << "TLE" << " " << "x" << " " << tle << endl;
    cout << "RE" << " " << "x" << " " << re << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;


int main()
{
	string ss,ans;
	getline(cin,ss);
	rep(i,ss.size())
	{
		if('a'<=ss[i]&&ss[i]<='z')
		{
			ans+=ss[i]-32;
		}
		else
			ans+=ss[i];
	}

	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 1176
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    int arr[100001] = { };
    int a;
    cin >> n;
    for(int i=0;i<n;i++){
    	cin >> a;
    	arr[a]++;
    	arr[a+1]++;
    	arr[a-1]++;

    }
    sort(arr,arr+n,greater<int>());
    if(n==1) cout << 1;
    else cout << arr[0];

    return 0;
}

Measured memory_bytes: 640
using System;

class Program
{
    static void Main(string[] args)
    {
        string input1 = Console.ReadLine();
        if (input1 == "Sunny")
            Console.WriteLine("Cloudy");
        else if (input1 == "Cloudy")
            Console.WriteLine("Rainy");
        else if (input1 == "Rainy")
            Console.WriteLine("Sunny");
    }
}


Measured memory_bytes: 11092
a,b = map(int, input().split())
l = [1]
for x in range(2, 1000):
    l.append(l[x-2]+x)

for i in l:
    if a < i and b < l[l.index(i) + 1]:
        if i - a == l[l.index(i) + 1] - b:
            print(i - a)
            break

Measured memory_bytes: 3060
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

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

  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF<int>));
  REP(i, n + 1) { dp[i][0] = i; }
  REP(j, m + 1) { dp[0][j] = j; }
  REP(i, n) {
    REP(j, m) {
      if (s[i] == t[j]) {
        chmin(dp[i + 1][j + 1], dp[i][j]);
      }
      chmin(dp[i + 1][j + 1], dp[i][j + 1] + 1);
      chmin(dp[i + 1][j + 1], dp[i + 1][j] + 1);
      chmin(dp[i + 1][j + 1], dp[i][j] + 1);
    }
  }

  cout << dp[n][m] << endl;

  return 0;
}


Measured memory_bytes: 6688
#include<stdio.h>
#include<math.h>
#include<string.h>
#define ll long long int


void sort(ll a[],ll n){

ll i,j,temp;

for(i=0;i<n;i++){

    for(j=0;j<n;j++){

        if(a[i]<a[j]){
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }

}



}


int main(){

char a[100000];
ll i,cnt,n;
cnt=0;

scanf("%s",a);
n=strlen(a);
for(i=0;i<strlen(a)/2;i++)
{
    if(a[i]==a[n-i-1])
    {
        continue;


    }
    else{
        cnt++;
    }



}

printf("%lld",cnt);

return 0;
}


Measured memory_bytes: 128
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
	}

	// 1
	// 6, 6^2=36, 6^3=216, 6^4=1296, 6^5=7776, 6^6=46656 
	// 9, 9^2=81, 9^3=729, 9^4=6561, 9^5=59049

	let mut ans = 999999usize;
	let mut sum = 0;
	for i1 in 0..=1 {	// 59049
		sum = i1 * 59049;
		for i2 in 0..=2 {	// 46656
			sum += i2 * 46656;
			if n < sum {
				sum -= i2 * 46656;
				break;
			}
			for i3 in 0..6 {	// 7776
				sum += i3 * 7776;
				if n < sum {
					sum -= i3 * 7776;
					break;
				}
				for i4 in 0..9 {	// 6561
					sum += i4 * 6561;
					if n < sum {
						sum -= i4 * 6561;
						break;
					}
					for i5 in 0..6 {	// 1296
						sum += i5 * 1296;
						if n < sum {
							sum -= i5 * 1296;
							break;
						}
						for i6 in 0..9 {	// 729
							sum += i6 * 729;
							if n < sum {
								sum -= i6 * 729;
								break;
							}
							for i7 in 0..6 {	// 216
								sum += i7 * 216;
								if n < sum {
									sum -= i7 * 216;
									break;
								}
								for i8 in 0..9 {	// 81
									sum += i8 * 81;
									if n < sum {
										sum -= i8 * 81;
										break;
									}
									for i9 in 0..6 {	// 36
										sum += i9 * 36;
										if n < sum {
											sum -= i9 * 36;
											break;
										}
										for i10 in 0..9 {	// 9
											sum += i10 * 9;
											if n < sum {
												sum -= i10 * 9;
												break;
											}
											for i11 in 0..6 {	// 6
												sum += i11 * 6;
												if n < sum {
													sum -= i11 * 6;
													break;
												}
												if n - sum < 6 {
													//println!("{}", sum + n - sum);
													//println!("{}", i1+i2+i3+i4+i5+i6+i7+i8+i9+i10+i11+n-sum);
													ans = min(ans, i1+i2+i3+i4+i5+i6+i7+i8+i9+i10+i11+n-sum);
												}
												sum -= i11 * 6;	
											}
											sum -= i10 * 9;
										}
										sum -= i9 * 36;
									}
									sum -= i8 * 81;
								}
								sum -= i7 * 216;
							}
							sum -= i6 * 729;
						}
						sum -= i5 * 1296;
					}
					sum -= i4 * 6561;
				}
				sum -= i3 * 7776;
			}
			sum -= i2 * 46656;
		}
	}
	println!("{}", ans);
}


Measured memory_bytes: 2164
#include<cstdio>

int main(int argc, char const *argv[])
{
    int a, b, result;
    char ope[10];
    while(1){
        scanf("%d %s %d", &a, ope, &b);

        if(ope[0] == '+'){
            result = a +b;
        }
        else if(ope[0] == '-'){
            result = a -b;
        }
        else if(ope[0] == '*'){
            result = a *b;
        }else if(ope[0] == '/'){
            result = a /b;
        }else{
            break;
        }
        printf("%d\n", result);
    }
    
    return 0;
}



Measured memory_bytes: 2680
n = int(input())
s = list(input())

m = {'R': 0, 'G': 0, 'B': 0}

for i, c in enumerate(s):
  if c == 'R':
    m['R'] += 1
  elif c == 'G':
    m['G'] += 1
  else:
    m['B'] += 1

result = m['R'] * m['G'] * m['B']

for i in range(1, n - 1):
  for j in range(i + 1, n):
    k = 2 * j - i

    if k > n or not (s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]):
      continue
    result -= 1

print(result)

Measured memory_bytes: 68492
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
long long read(){
	register long long x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
long long n, ans;
int main(){
	n = read(), ans = n - 1;
	for (register int i = 1; 1ll * i * i <= n; ++i)
		if (n % i == 0) ans = std :: min(ans, i + n / i - 2);
	printf("%lld\n", ans);
}

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

int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ans=b-a+1;
	ans-=((b/c)-((a-1)/c));
	ans-=((b/d)-((a-1)/d));
	long long p=(d*c)/__gcd(d,c);
	ans+=((b/p))-((a-1)/(p));
	cout<<ans<<endl;  
}

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

int main () {
  int N;
  cin >> N;
  
  int a[100];
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  set<int>values; //insert するときに重複を取り除いてくれます。
  for (int i=0; i<N; i++) {
    values.insert(a[i]);
  }
  //set のサイズを出力します。
  cout << values.size() << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

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

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAX = 3005;

bool sugar[MAX];
bool water[MAX];

void mix(int A, int B, bool *x) {
  for (int i = 0; A * i < MAX; ++i)
    for (int j = 0; A * i + B * j < MAX; ++j)
      x[A * i + B * j] = 1;
}

int main(void) 
{
  int A, B, C, D, E, F;
  scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F);

  mix(100 * A, 100 * B, water);
  mix(C, D, sugar);

  int solS = 0, solW = 100 * A;
  REP(S, F + 1) FOR(W, 1, F - S + 1) {
    if (!sugar[S]) continue;
    if (!water[W]) continue;
    if (S + W > F) continue;

    if (100 * S > W * E) continue;
    if (solS * W >= solW * S) continue;
    solS = S;
    solW = W;
  }

  printf("%d %d\n", solW + solS, solS);

  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <string>
//#include <functional>
//#include <cmath>


int main(){
    int32_t A, B;
    std::cin >> A >> B;
    
    int32_t res = std::max(0, A - 2*B);

    std::cout << res;;

    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a > b) swap(a, b);
  if (b > c) swap(b, c);
  if (a > b) swap(a, b);
  if (a == b && c != a || a != b && b == c) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    
int main() {
    int x[5];
    for (int i = 0; i < 5; i++) {
        cin >> x[i];
        if (x[i] == 0) {
            cout << i + 1;
            return 0;
        }
    }

        return 0;
}

Measured memory_bytes: 3584
N,M= map(int, input().split())
AB_list=[]
for i in range(N):
  a,b= map(int, input().split())
  AB_list.append((a,b))
  
AB_list.sort()

ans=0
for i in range(N):
  if(M-AB_list[i][1]>0):
    ans+=AB_list[i][0]*AB_list[i][1]
    M=M-AB_list[i][1]
  else:
    ans+=AB_list[i][0]*M
    break
print(ans)

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

int calc(int x) {
    int ret = 0;
    while(x % 100 == 0) {
        x /= 100;
        ++ret;
    }
    return ret;
}
int main() {
    int D, N;
    cin >> D >> N;
    int cnt = 0, val = 0;
    while(cnt < N) {
        ++val;
        if(calc(val) == D) ++cnt;
    }
    cout << val << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a[4], b[4];
  int sumS = 0, sumT = 0;
  int i;

  scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
  scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);

  for(i = 0; i < 4; i++) {
    sumS += a[i];
    sumT += b[i];
  }

  if(sumS > sumT) printf("%d\n", sumS);
  else            printf("%d\n", sumT);

  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

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


Measured memory_bytes: 256
N= int(input())
a=[0]
for i in range(N):
    a.append(int(input()))

s = set()
v = 1
for i in range(1,N+1):
    if v == 2:
        print(len(s))
        break
    elif v in s or i == N:
        print(-1)
        break
    else:
        s.add(v)
        v = a[v]

        


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

int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
    int ans = 0;
    for (int b = 0; b < n; b++) {
    	for (int a = 0; a < b; a++) {
    		int ab = l[a] + l[b];
    		int r = lower_bound(l.begin(), l.end(), ab) - l.begin();
    		int l = b + 1;

    		ans += max(0, r - l);
    	}
    } 
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
H,W,D=map(int,input().split())
A=[]
for i in range(H):
    a=list(map(int,input().split()))
    A.append(a)
Q=int(input())
L=[]
R=[]

lst=[[]for _ in range(H*W)]
for i in range(H):
    for j in range(W):
        lst[A[i][j]-1].append(i)
        lst[A[i][j]-1].append(j)
#print(lst)
#print(lst[1][1])
d=[]
for i in range(D):
    cnt=[0]
    for j in range(i+D,H*W,D):
        cnt.append(cnt[-1]+abs(lst[j][0]-lst[j-D][0])+abs(lst[j][1]-lst[j-D][1]))
    d.append(cnt)
ans=[]
#print(cnt)
#print(d)
for i in range(Q):
    l,r=map(int,input().split())
    ll=(l-1)%D
    count=d[ll]
    r-=1
    l-=1
    #print(count)
    vall=count[l//D]
    #print(l//D)
    #print(r//D)
    valr=count[r//D]
    val=valr-vall
    #print(val)
    ans.append(val)

for i in range(Q):
    print(ans[i])

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

int main(){
  string s;
  cin >> s;
  map<string, int> d;
  d["SUN"] = 1;
  d["MON"] = 2;
  d["TUE"] = 3;
  d["WED"] = 4;
  d["THU"] = 5;
  d["FRI"] = 6;
  d["SAT"] = 7;

  cout << 8-d.at(s) << endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
const ll inf = pow(2, 31) - 1;
int main()
{
	ll n; cin >> n;
	set<ll> f, g;
	ll cnt = 0;
	if(n == 2){
		cout << 1 << endl;
		return 0;
	}
	REP(i,1,(ll)sqrt(n)+1){
		if((n-1)%i == 0){
			if(i == 1)f.insert(n-1);
			else {
				f.insert((n-1)/i);
				f.insert(i);
			}
		}
		if(n%i == 0){
			g.insert(i);
			//cout << i << " ";
		}
	}
	//cout << endl;
	//cout << sqrt(n) + 1 << endl;

	for(auto it=g.begin();it!=g.end();it++){
		ll tmp1 = n, tmp2 = n, p = *it, q = n / p;
		if(p > 1){
			while(tmp1 % p == 0)tmp1 /= p;
			if(tmp1 % p == 1)cnt++;
		}
		if(p != q){
			while(tmp2 % q == 0)tmp2 /= q;
			if(tmp2 % q == 1)cnt++;
		}
		//cout << *it << " ";
	}
	//cout << endl;
	
	//cout << cnt << " " << f.size() << endl;
	cout << cnt + f.size() << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string c = s.substr(0, 1);
  int ans = 0;

  for (int i=1; i<=n; i++) {
    // cout << c << endl;

    if(c == s.substr(i,1)) {
      c = s.substr(i, 2);
      i++;
    } else {
      c = s.substr(i, 1);
    }
    ans++;
  }  

  cout << ans << endl;
}

/*
a|aa|c|ca|c|a|b|a|ab|a|b|c

*/

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

int main(){
    
    // 1. 入力情報.
    char c[111];
    scanf("%s", c);
    int l = strlen(c);
    
    // 2. 判定.
    // 2-1. 文字列長が, 奇数の場合.
    if(l & 1){
        puts("No");
        return 0;
    }
    
    // 2-2. 文字列長が, 偶数の場合.
    bool ok = true;
    int at = 0;
    while(at < l){
        if(c[at] != 'h' || c[at + 1] != 'i'){
            ok = false;
            break;
        }
        at += 2;
    }
    
    // 3. 出力.
    printf("%s\n", ok ? "Yes" : "No");
    return 0;
    
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  int n; cin >> n;
  vector<lint> x(n); for(int i=0;i<n;i++) { cin >> x[i]; }

  vector<lint> y=x;
  sort(y.begin(),y.end());
  lint med0=y[n/2-1], med1=y[n/2];

  for(int i=0;i<n;i++) {
    if(x[i]>med0) { cout << med0 << endl; }
    else { cout << med1 << endl; }
  }

  return 0;
}

Measured memory_bytes: 5376
#include <iostream>
using namespace std;
long gcd(long a, long b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
  long lcm(long a, long b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
 
int main()
{
  long a,b;
  cin>>a;
  cin>>b;
  cout<<lcm(a,b);
  
}



Measured memory_bytes: 256
N = int(input())
s = [int(input()) for _ in range(N)]

S = sum(s)
if S % 10 != 0:
    print(S)
else:
    num = [n for n in s if n % 10 != 0]
    if len(num) == 0:
        print(0)
    else:
        print(S - min(num))


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}Ret;

Ret Q_s[LEN];
int head, tail,z;

void enqueue_s(Ret x){
  Q_s[tail]=x;
  tail=(tail+1)%LEN;
}

Ret dequeue_s() {
  Ret x=Q_s[head];
  head=(head+1)%LEN;
  return x;
}

int min(int c,int d){return c<d? c:d;}

int main(){
  int times=0,cal;
  int i,y;
  Ret rs;
  
  scanf("%d %d",&z,&y);

  for(i=1;i<=z;i++){
    scanf("%s",Q_s[i].name);
    scanf("%d",&Q_s[i].t);
  }
  head=1;
  tail=z+1;

  while(head!=tail){
    rs=dequeue_s();
    cal=min(y,rs.t);
    rs.t-=cal;
    times+=cal;
    if(rs.t>0)enqueue_s(rs);
    else{
      printf("%s %d\n",rs.name,times);
    }
  }
  return 0;
}



Measured memory_bytes: 11860
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	fill((T*)array, (T*)(array + N), val);
}

const ll INF = 1e18;

int main() {
	IOS;
	int n; cin >> n;
	vector<ll> a(n);
	REP(i, n)cin >> a[i];
	sort(ALL(a));
	ll k = a[n - 1];
	cout << k << ' ';
	ll ans = INF;
	ll tmp = INF;
	if (k % 2 == 0) {
		ll t = k / 2;
		REP(i, n - 1) {
			ll d = min(abs(a[i] - t), abs(a[i] - t - 1));
			if (d < tmp) {
				tmp = d;
				ans = a[i];
			}
		}
		dump(ans);
	}
	else {
		ll t = (k + 1) / 2;
		REP(i, n - 1) {
			ll d = abs(a[i] - t);
			if (d < tmp) {
				tmp = d;
				ans = a[i];
			}
		}
		dump(ans);
	}
	
	return 0;
}

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

inline long int d() {
  long int N, M;
  cin >> N >> M;
  if (N < M) swap(N, M);
  if (N == 1 and M == 1) return 1;
  if (N >= 2 and M == 1) return N - 2;
  if (M == 2) return 0;
  return (N-2) * (M-2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << d() << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)-1
sum=0
for bit in range(1<<n):
	left=0
	right=0
	for i in range(n+1):
		if (bit & (1<<i)):
			left=right
			right=i+1
			sum+=int(s[left:right])
	sum+=int(s[right:n+1])
print(sum)

Measured memory_bytes: 9068
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val li = (1 to n).map(_ => sc.nextLong)

  val ans = Stream.iterate((0, 0, 0L, 0L, 0L)) {
    case (r, l, cnt, sum, xor) =>
      if (l < n && (xor & li(l)) == 0) {
        (r, l + 1, cnt + 1, sum + cnt + 1, xor | li(l))
      } else {
        (r + 1, l, cnt - 1, sum, xor - li(r))
      }
  }
    .dropWhile(_._1 < n)
    .head

  println(ans._4)
}


Measured memory_bytes: 110316
n,q = map(int,input().split())
s = list(input())
mark = [0]*(n+1)
for i in range(2,n+1):
  if s[i-2]=='A' and s[i-1]=='C':
    mark[i] = mark[i-1]+1
  else:
    mark[i] = mark[i-1]

for i in range(q):
  l,r = map(int,input().split())
  l = l-1
  r = r-1
  print(mark[r+1]-mark[l+1])

Measured memory_bytes: 6852
def main():
    sa = list(input())
    sb = list(input())
    sc = list(input())

    c = {"a": sa, "b": sb, "c": sc}
    now = "a"
    while True:
        s = c[now]
        if len(s) == 0:
            print(now.upper())
            break

        now = c[now].pop(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using lint = long long int;
using Graph = std::vector<std::vector<lint>>;

template<class T>
struct edge
{
	T dist;
	lint to;
	edge(){}
	edge(const T &a_dist,const lint &a_to) : dist(a_dist), to(a_to) {}
	~edge(){}
};

template<class T>
T my_binary_search(const int &min,const int &max,const T &key,const std::vector<T> &data)
{
	const int mid = (max - min)/2 + min;

	if(min > max) return -1;

	if(data[mid] == key) return mid;
	if(data[mid] < key)  return my_binary_search<T>(mid+1,max,key,data);
	return my_binary_search<T>(min,mid-1,key,data);
}

int main(int argc,char *argv[])
{
	lint n;
	std::cin >> n;

	std::vector<lint> l(n);
	for(int i = 0;i < n;i++) std::cin >> l[i];
	std::sort(l.begin(),l.end(),std::greater<lint>());

	int num = 0;
	for(int a = 0;a < n;a++)
	{
		for(int b = a+1;b < n;b++)
		{
			for(int c = a+1;c < b;c++)
			{
				if(l[a] < l[b] + l[c] && l[b] < l[c]+l[a]) num++;
			}
		}
	}

	std::cout << num << std::endl;

	return 0;
}


Measured memory_bytes: 256
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;


int main(){	
	fastio;
	int n,m;cin>>n>>m;
	if(n>=m)cout<<"0"<<endl;
	else{
		vector<int>vec(m);
		FER(i,0,m)cin>>vec[i];
		sort(all(vec));
		vector<int>df;
		FER(i,1,m)df.pb(vec[i]-vec[i-1]);
		//for(int val: df)cout<<val<<endl;
		sort(all(df));
		int tot=0;
		FER(i,0,m-n)tot+=df[i];
		cout<<tot<<endl;
	}


	return 0;
}


Measured memory_bytes: 1276
#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
 #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int S) {
    ll x3 = min(pow(S, 0.5)+1, 1e9);
    ll y2 = x3;
    ll x2 = x3 * y2 - S;
    ll y3 = 1;

	stringstream ss;
	ss << 0 << " " << 0 << " " << x2 << " " << y2 << " " << x3 << " " << y3;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int S;
    cin >> S;
    
    solve(S);
    
    return 0;
}



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

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	int l=0,r=n-1;
	while(l<r)
	{
		if(s[l]=='W'&&s[r]=='R')
		{
			ans++;
			l++;
			r--;
		}
		else if(s[l]=='W'&&s[r]=='W')
		{
			r--;
		}
		else if(s[l]=='R'&&s[r]=='W')
		{
			l++;
			r--;
		}
		else if(s[l]=='R'&&s[r]=='R')
		{
			l++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3744
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    
	    int n = sc.nextInt();
	    int s = sc.nextInt();
	    
	    if(n!=0 && s!=0){
		
		int[] m = new int[n];
		for(int i=0; i<n; i++){
		    m[i] = sc.nextInt();
		}

		int ans = 0;
		for(int i=0; i<n; i++){
		    for(int j=i+1; j<n; j++){
			if(m[i]+m[j] > s) ans++;
		    }
		}
	
		System.out.println(ans);
	    }
	}
    }
}

Measured memory_bytes: 64600
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  ll n, k, tmp1, tmp;
  while(cin>>n>>k){
    ll ans=0;
    for(ll i=k+1; i<=n; ++i){
      tmp=n%i;
      tmp1=n/i;
//      cout<<i<<" "<<tmp<<" "<<tmp1<<endl;
      ans+=(max(0ll, tmp-k+1)*tmp1)+max(0ll, i-1-max(k-1, tmp))*(tmp1-1);
//      cout<<"&"<<ans<<endl;
    }
    for(ll i=max(1ll, k); i<=n; ++i){
      ans+=(n-i);
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main(){
    int N;
    int H[1000000];
    cin >> N;
    for(int i=0;i<N;i++)cin >> H[i];
    int count = 0,A = 0 ,ans = 0;
    for(int i=1;i<N;i++){
        if(H[i] <= H[i-1])count++;
        else{
        if(ans < count){
            ans = count;}
        count = 0;
        }

    }
if(ans < count)cout << count << endl;
else cout << ans << endl;
}

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

int main(){
  long long int a, b; cin >> a >> b;
  long long int maxx = max(a, b), minx = min(a, b);
  for(int i = 1; i <= minx; i++){
    if((maxx * i) % minx == 0){
      cout << maxx * i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def check(s):
    for i in range(len(s)):
        if s[i] != '9':
            return False
    return True

s = input()
n = len(s)
res = 0
if check(s[1:]):
    for i in s:
        res += int(i)
else:
    for i,t in enumerate(s):
        if i == 0:
            res += int(t) - 1
            continue
        res += 9

print(res)

Measured memory_bytes: 38680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)

int main()
{
  int N; cin >> N;
  int t[N], x[N], y[N];
  rep(i,N) cin >> t[i] >> x[i] >> y[i];

  bool check = true;
  rep(i,N)
  {
    if(t[i]%2 != (x[i]+y[i])%2 || x[i]+y[i] > t[i])
    {
    check = false;
    }
  }
  
  if(check) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#define maxN 100016

using namespace std;

int par[maxN], rank[maxN];

int find(int x)
{
	if (par[x] == x)
		return x;
	return find(par[x]);
}

int main()
{
	int n, t, i, j, x;
	long long sum;
	char c;
	while (scanf("%d%d", &n, &t) && (n || t))
	{
		par[1] = 1;
		for (i = 2; i <= n; i++)
			scanf("%d", par + i);
		getchar();
		for (i = sum = 0; i < t; i++)
		{
			scanf("%c%d%*c", &c, &x);
			if (c == 'Q')
				sum += find(x);
			else
				par[x] = x;
		}
		printf("%lld\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1584
#if 0
PDFにPythonでの実装例が載っていたので、C++のコードに書き換えて実装したので、コードの意味を理解するのに苦労する部分もあったがなんとか書くことができた。コンテナを関数の引数にできることや、cout << fixed << という構文があることを新たに知ることができた。
#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const double EPS = 1e-11;

double width(vector<pair<int,int>> polygon, double x) {
  vector<double> w;
  for (int i = 0; i < polygon.size() ; i++) {
    pair<int,int> p = polygon[i], q = polygon[(i+1)%polygon.size()];
    if (abs(p.first - x) < EPS)
      w.push_back(1.0*p.second);
    else if ((p.first < x && x < q.first) || (p.first > x && x > q.first)) {
      int x0 = p.first, y0 = p.second;
      int x1 = q.first, y1 = q.second;
      w.push_back(y0 + 1.0*(y1-y0)*(x-x0)/(x1-x0));
    }
  }
  sort(w.begin(), w.end());
  return w[w.size()-1] - w[0];
}

double volume(vector<pair<int,int>> pxy, vector<pair<int,int>> pxz, vector<int> X) {
  double total = 0.0;
  int xmin = max((*min_element(pxy.begin(), pxy.end())).first,
                 (*min_element(pxz.begin(), pxz.end())).first);
  int xmax = min((*max_element(pxy.begin(), pxy.end())).first,
                 (*max_element(pxz.begin(), pxz.end())).first);
  sort(X.begin(), X.end());
  for (int i = 0; i < X.size()-1; i++) {
    int a = X[i], b = X[i+1];
    if (!(xmin <= a && a <= xmax && xmin <= b && b <= xmax))
      continue;
    double m = (a+b)/2.0;
    double va = width(pxy, a)*width(pxz, a);
    double vb = width(pxy, b)*width(pxz, b);
    double vm = width(pxy, m)*width(pxz, m);
    double area = ((b-a)/6.0)*(va + 4.0*vm + vb);
    total += area;
  }
  return total;
}

int main() {
  int M, N;
  while (cin >> M >> N && M > 0) {
    vector<pair<int,int>> PXY, PXZ;
    vector<int> X;
    int x, y, z;
    for (int i = 0; i < M; i++) {
      cin >> x >> y;
      PXY.push_back(make_pair(x,y));
      X.push_back(x);
    }
    for (int i = 0; i < N; i++) {
      cin >> x >> z;
      PXZ.push_back(make_pair(x,z));
      X.push_back(x);
    }
    cout << fixed << volume(PXY, PXZ, X) << endl;
  }
}



Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;


void ABC112C()
{
	int N;
	cin >> N;
	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> x[i] >> y[i] >> h[i];
	}


	for (int Cx = 0; Cx <= 100; ++Cx)
	{
		for (int Cy = 0; Cy <= 100; ++Cy)
		{
			int z = -1;
			int i = 0;
			for (; i < N; ++i)
			{
				int zz = h[i] > 0 ? abs(x[i] - Cx) + abs(y[i] - Cy) + h[i] : z;
				if (z >= 0 && z != zz)
				{
					break;
				}
				z = zz;
			}
			if (i != N || z == 0)
				continue;
			i = 0;
			for (; i < N; ++i)
			{
				int p = max(0, z - abs(x[i] - Cx) - abs(y[i] - Cy));
				if (p != h[i])
					break;
			}

			if (i == N && z > 0)
			{
				cout << Cx << ' ' << Cy << ' ' << z << endl;
				return;
			}
		}
	}


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

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(T a){
	cout << a << '\n';
}
#define all(x) x.begin(),x.end()
int n,p;
string s;
int cnt[10005];
int main(){
	g(n); g(p); g(s);
	if(p == 2 || p == 5){
		ll ans = 0;
		rep(i,n){
			int a = s[i]-'0';
			if(a%p == 0) ans += i+1;
		}
		o(ans);
		return 0;
	}
	cnt[0] = 1;
	ll cur = 0, base = 1, ans = 0;
	for(int i=n-1;i>=0;i--){
		cur += base * (s[i]-'0');
		cur %= p;
		base = base*10%p;
		
		ans += cnt[cur];
		cnt[cur]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29

int main() {
	string s;
    cin >> s;
	sort(s.begin(), s.end());
	rep(i, 26) {
		if (s.find('a' + i) == string::npos) {
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n = 4;
  vector<int> a(n);
  string s;
  cin >> s;
  rep(i,n){
    a.at(i)=s.at(i)-'0';
  }
  for(int bit = 0; bit < (1<<(n-1)); bit++){
    int ans = a.at(0);
    rep(i,n-1){
      if(bit&(1<<i)){
        ans+=a.at(i+1);
      }else{
        ans-=a.at(i+1);
      }
    }
    if(ans==7){
      cout << a.at(0);
      rep(i,n-1){
        if(bit&(1<<i)){
          cout << "+";
        }else{
          cout << "-";
        }
        cout << a.at(i+1);
      }
      cout << "=7" <<  endl;
      return 0;
    }
  }

}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n;
	cin>>n;
	if(n>17){
		cout<<"Yes";
	}
	else if(n==4||n==7||n==8||n==11||n==12||n==14||n==15||n==16){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: usize,
        b: usize
    }
    let result = min(n * a, b);
    println!("{}", result);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(),b = scanner.nextInt();
		int c = scanner.nextInt(),d = scanner.nextInt();
		System.out.println((int)Math.max(a*b, c*d));
	}

}


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

using std::vector;

long long is_greater_than(long long a, long long b)
{
  return a > b;
}

int main()
{
  int x, y, z, k;
  std::cin >> x >> y >> z >> k;
  vector<long long> a(x);
  vector<long long> b(y);
  vector<long long> c(z);
  for (int i = 0; i < x; i++) {
    std::cin >> a.at(i);
  }
  for (int i = 0; i < y; i++) {
    std::cin >> b.at(i);
  }
  for (int i = 0; i < z; i++) {
    std::cin >> c.at(i);
  }

  std::sort(a.rbegin(), a.rend());
  std::sort(b.rbegin(), b.rend());
  std::sort(c.rbegin(), c.rend());

  vector<long long> ab;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      ab.push_back(a.at(i) + b.at(j));
    }
  }
  std::sort(ab.rbegin(), ab.rend());

  vector<long long> abc;
  for (int i = 0; i < k && i < x * y; i++) {
    for (int j = 0; j < z; j++) {
      abc.push_back(ab.at(i) + c.at(j));
    }
  }
  std::sort(abc.rbegin(), abc.rend());

  for (int i = 0; i < k; i++) {
    std::cout << abc.at(i) << '\n';
  }

  return 0;
}


Measured memory_bytes: 43368
n = int(input())
a = [int(x) for x in input().split()]

mi = 10 ** 7
ma = -(10 ** 7)
mi_idx = 0
ma_idx = 0
for i,v in enumerate(a):
  if v < mi:
    mi = v
    mi_idx = i
  if v > ma:
    ma = v
    ma_idx = i

print(2 * n - 1)
if abs(ma) >= abs(mi):
  for i in range(1, len(a) + 1):
    print(ma_idx + 1, i)
  for i in range(1, len(a)):
    print(i, i + 1)
else:
  for i in range(1, len(a) + 1):
    print(mi_idx + 1, i)
  for i in range(len(a), 1, -1):
    print(i, i - 1)


Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	list := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	count := 0
	for i := 1; i <= n; i++ {
		if i != list[i-1] {
			count++
		}
	}
	if count > 2 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)

int main(void){
	int n,m;
	cin>>n>>m;
	vector<int> v(m);
	vector<bool> used(n+1);
	rep(i,m)cin>>v[i];
	reverse(v.begin(), v.end());
	rep(i,m){
		if(!used[v[i]])cout<<v[i]<<endl;
		used[v[i]]=true;
	}
	rep1(i,n)if(!used[i])cout<<i<<endl;
	return 0;
}

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

int main(){
	
	int x,a;
	cin >> x >> a;
	
	if(x<a) cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}

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

const int INF = 10000000;
int n,m;
int data[101][101];

void warshall_floyd() {
  for ( int k = 0; k <= n; k++ ) {
    for (int i = 0; i <= n; i++ ) {
      for ( int j = 0; j <= n; j++ ) {
	data[i][j] = min( data[i][j], data[i][k] + data[k][j] );
      }
    }
  }
}

int main() {
  for ( int i = 0; i < 101; i++ ) {
    for ( int j = 0; j < 101; j++ ) {
      if ( i == j ) data[i][j] = 0;
      else data[i][j] = INF;
    }
  }
  cin >> n;
  cin >> m;
  char ch;
  for ( int i = 1; i <= m; i++ ) {
    int a,b,c,d;
    cin >> a >> ch >> b >> ch >> c >> ch >> d;
    data[a][b] = c;
    data[b][a] = d;
  }
  warshall_floyd();
  int x1,x2,y1,y2; cin >> x1  >> ch >> x2 >> ch >> y1 >> ch >> y2;
  
  cout << y1 - y2 - data[x1][x2] - data[x2][x1] << endl;
  return 0;
}

Measured memory_bytes: 1200
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = double;
using pii = pair<int, int>;
using uint = unsigned int;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
default_random_engine generator;

void solve();

int main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);  
#endif 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;  

    int tests = 1;
    // cin >> tests;

    while (tests--) {
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}

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

void solve() {  
    ll n, a, b;
    cin >> n >> a >> b;
    if (b < a) {
        swap(a, b);
    }

    if ((a + b) % 2 == 0) {
        cout << (b - a) / 2 << endl;
        return;
    }

    ll x = (a - 1 + b - 1 + 1) / 2;
    ll y = (n - a + n - b + 1) / 2;

    cout << min(x, y) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 1001
#define INF 1e9
using namespace std;


int main(){
  while(1){

    int n;
    string str[N];
    cin>>n;
    if(n==0) break;
    long long a[N];
    a[0]=INF*2;
    
    for(int i=1;i<=n;i++)cin>>str[i];
    
    for(int i=1;i<=n;i++){
      if(str[i]=="x")a[i]=INF+1;
      else a[i]=atoi(str[i].c_str());
    }
    
    int f=0;
  
    long long low=-INF*2,upp=INF*2;
    
    for(int i=1;i<=n;i++){
      if(a[i]==INF+1){
	if(i%2){
	  if(a[i-1]==INF+1) f=1;
	  else upp=min(a[i-1],upp);
	  if(i<n) upp=min(a[i+1],upp);	  
	}
	else{
	  if(a[i-1]==INF+1) f=1;
	  else  low=max(low,a[i-1]);
	  if(i<n) low=max(a[i+1],low);
	}
      }else if(a[i-1]<a[i] && i%2 && a[i-1]!=INF+1) f=1;
      else if(a[i-1]>a[i] && !(i%2) && a[i-1]!=INF+1) f=1;
    }
  
        if(upp-low==2 && f==0) cout<<(upp+low)/2<<endl;
       else if(upp-low>2 && f==0) cout<<"ambiguous"<<endl;
     else  cout<<"none"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1332
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

const INF: usize = 1_000_000_000;

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut graph: Vec<Vec<usize>> = vec![vec![INF; n]; n];
    for _ in 0..n {
        let u: usize = iterator.next().unwrap().parse().unwrap();
        let k: usize = iterator.next().unwrap().parse().unwrap();
        for _ in 0..k {
            let v: usize = iterator.next().unwrap().parse().unwrap();
            let c: usize = iterator.next().unwrap().parse().unwrap();
            graph[u][v] = c;
        }
    }

    let mut color: Vec<Color> = vec![Color::WHITE; n];
    let mut d: Vec<usize> = vec![INF; n];
    let mut p: Vec<isize> = vec![-1; n];
    d[0] = 0;

    loop {
        let mut min_cost = INF;
        let mut u = 0;
        for i in 0..n {
            if color[i] != Color::BLACK && d[i] < min_cost {
                min_cost = d[i];
                u = i;
            }
        }

        if min_cost == INF {
            break;
        }

        color[u] = Color::BLACK;

        for v in 0..n {
            if color[v] != Color::BLACK && graph[u][v] != INF {
                if d[u] + graph[u][v] < d[v] {
                    d[v] = d[u] + graph[u][v];
                    p[v] = u as isize;
                    color[v] = Color::GRAY;
                }
            }
        }
    }

    let mut result = String::new();
    for i in 0..n {
        result.push_str(&format!("{} {}\n", i, d[i]));
    }
    return result.trim().to_string();
}

#[derive(Clone, PartialEq)]
enum Color {
    WHITE, GRAY, BLACK
}



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

int main() {
    string S;
    cin >> S;

    string preS = "A";
    string nowS;
    nowS = "";
    long count = 0;
    for(int i = 0; i < S.size(); i++)
    {
        nowS += S[i];
//        cout <<  "now:" << nowS << endl;
        if(preS != nowS)
        {
//            cout <<  "pre:" << preS << "now:" << nowS << endl;
            preS = nowS;
            nowS = "";
            count++;
        }
    }
    cout << count << endl;
    return 0;  

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(void){
  ll n;
  cin >> n;
  vector<int> btn(n,0);
  for(int i=0;i<n;i++){
    cin >> btn.at(i);
  }
  int light=0,count=0;
  for(int i=0;i<n;i++){
    light = btn[light] - 1;
    count++;
    if(light == 1){
      cout << count << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);
ll n;
std::vector<string> ans;
void dfs(ll val,ll index,string& our){
	if(index==n-1) {ans.pb(our); return;}
   char tmp;
	FOR(i,0,val+1){
    tmp='a'+i;
		our=our+(tmp);
		dfs(max(i,val),index+1,our);
		our.pop_back();
	}

}


int main(){
	cin>>n;
	string our="a";
	dfs(0,0,our);
	for(auto j:ans){
		cout<<j<<endl;
	}


    
}

Measured memory_bytes: 9588
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 3005
#define P 1000000007
#define INV 500000004
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, q, ans, a[MAXN], f[MAXN][MAXN];

inline int add(int x, int y) {return x+y>=P?x+y-P:x+y;}
inline int sub(int x, int y) {return x>=y?x-y:x-y+P;}

inline int ksm(int x, int y)
{
    int ans=1;
    while(y)
    {
        if(y&1) ans=1LL*x*ans%P;
        x=1LL*x*x%P, y>>=1;
    }
    return ans;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(rint i=1; i<=n; ++i) scanf("%d", &a[i]);
    for(rint i=1; i<=n; ++i)
        for(rint j=1; j<=n; ++j) if(a[i]>a[j]) f[i][j]=1;
    for(rint i=1, x, y; i<=q; ++i)
    {
        scanf("%d%d", &x, &y);
        int t1, t2;
        for(rint j=1; j<=n; ++j)
        {
            if(j==x || j==y) continue;
            t1=f[x][j], t2=f[y][j];
            f[y][j]=f[x][j]=1LL*add(t1, t2)*INV%P;
            t1=f[j][x], t2=f[j][y];
            f[j][x]=f[j][y]=1LL*add(t1, t2)*INV%P;
        }
        
        t1=f[x][y], t2=f[y][x];
        f[x][y]=f[y][x]=1LL*add(t1, t2)*INV%P;
    }
    int temp=ksm(2, q);
    for(rint i=1; i<=n; ++i)
        for(rint j=i+1; j<=n; ++j)
            ans=add(ans, 1LL*f[i][j]*temp%P);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 35456