akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import bisect

n, m, k = map(int, input().split())

a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

sa = np.cumsum(a)
sb = np.cumsum(b)

if sa[-1] + sb[-1] <= k:
    print(len(a)+len(b))
    exit(0)

r = bisect.bisect_right(sb, k)
for i, saa in enumerate(sa):
    if saa > k:
        continue
    j = bisect.bisect_right(sb, k-saa)
    r = max(r, i+j+1)

print(r)


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

int main(void)
{
    string s[10] = {"NA", "YYMM", "MMYY", "AMBIGUOUS"};
    int a,b,y=0;
    scanf("%2d%2d" ,&a,&b);
    if(a>=1 && a<=12)
        y+=2;
    if(b>=1 && b<=12)
        y+=1;
    cout << s[y];
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = (0 until n).map { readLine()!!.toLong() }.toLongArray()
    a.sort()

    (0 until 2)
            .map {
                a.reverse()
                val p = LongArray(n)
                var cur = 0

                for (i in 2 until n - 1 step 2) {
                    p[i] = a[cur++]
                }

                p[0] = a[cur++]
                p[n - 1] = a[cur++]

                for (i in 1 until n - 1 step 2) {
                    p[i] = a[cur++]
                }

                (1 until n).map { i -> Math.abs(p[i] - p[i - 1]) }.sum()
            }
            .max()
            .let { println(it) }
}


Measured memory_bytes: 52376
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Iron Bar Cutting
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

ll ss[MAX_N + 1];

/* subroutines */

/* main */

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

  ss[0] = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    ss[i + 1] = ss[i] + ai;
  }

  int k = lower_bound(ss, ss + n, (ss[n] + 1) / 2) - ss;
  printf("%lld\n", min(ss[k] * 2 - ss[n], ss[n] - ss[k - 1] * 2));
  return 0;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(in.readLine());
    }
    
    int count = 0;
    int currentButton = a[0];
    int[] ary = new int[n];
    boolean hantei = false;
    for(int i=0; i<n; currentButton=a[currentButton-1]) {
      if(currentButton==2) {
        count++;
        System.out.println(count);
        return;
      } else if(ary[currentButton-1]==2){
        System.out.println(-1);
        return;
      } else {
        count++;
        ary[currentButton-1]++;
      }
    }
  }
}

Measured memory_bytes: 41892
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
    char s[15];
    int p;
    int k;
    int f;
} a[105];
int main()
{
    int n;
    scanf("%d",&n);
    int i,j;

    for(i=1; i<=n; i++)
    {
        scanf("%s",a[i].s);
        scanf("%d",&a[i].p);
        a[i].k=i;
    }

    for(i=1; i<n; i++)
    {
        for(j=1; j<=n-i; j++)
        {

            if(strcmp(a[j].s,a[j+1].s)>0)
            {
                node b=a[j];
                a[j]=a[j+1];
                a[j+1]=b;
            }
            else if(strcmp(a[j].s,a[j+1].s)==0)
            {
                if(a[j].p<a[j+1].p)
                {
                    node b=a[j];
                    a[j]=a[j+1];
                    a[j+1]=b;
                }
            }
        }

    }
    for(i=1; i<=n; i++)
    {
       printf("%d\n",a[i].k);
    }


    return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int Maxn = 12;
const int Maxm = 1000;
const int INF = 0x3f3f3f3f;

int N, M;
struct Node {
	int A, C;
};
Node A[100000 + 5];

int f[Maxm + 5][(1 << Maxn) + 5];

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d %d" ,&N, &M);
	for(int i = 1; i <= M; i++) {
		int x;
		scanf("%d %d", &A[i].A, &x);
		int t = 0;
		for(int j = 1; j <= x; j++) {
			int tmp;
			scanf("%d", &tmp);
			t |= (1 << (tmp - 1));
		}
		A[i].C = t;
	}
	memset(f, 0x3f, sizeof f);
	f[0][0] = 0;
	for(int i = 1; i <= M; i++) {
		for(int s = 0; s < (1 << N); s++) {
			int s1 = s | A[i].C;
			f[i][s1] = min(f[i][s1], f[i - 1][s] + A[i].A);
			f[i][s] = min(f[i][s], f[i - 1][s]);
		}
	}
	if(f[M][(1 << N) - 1] != INF)printf("%d\n", f[M][(1 << N) - 1]);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 16512
import sys
from itertools import combinations as combi
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
d = dd(int)
res = 0
for r in range(N + 1):
  for c in combi([x for x in range(N)], r):
    x = []
    y = []
    for i in range(N):
      if i in c: x.append(S[i])
      else: y.append(S[i])
    d["".join(x) + "?" + "".join(y)] += 1

for b in range(N + 1):
  for c in combi([x + N for x in range(N)], b):
    x = []
    y = []
    for i in range(N, N * 2):
      if i in c: x.append(S[i])
      else: y.append(S[i])
    x = x[: : -1]
    y = y[: : -1]
    res += d["".join(x) + "?" + "".join(y)]
print(res)

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

using namespace std;

typedef long long ll;

int main () {
    int N,M; cin>>N>>M;
    priority_queue <ll> A;
    for (int i=1;i<=N;i++) {
        int a; cin>>a;
        A.push(a);
    }

    for (int i=0;i<M;i++) {
        int a = A.top();
        A.pop();
        a /= 2;
        A.push(a);
    }

    ll sum=0;
    for (int i=0;i<N;i++) {
        sum += A.top();
        A.pop();
    }

    cout << sum << endl;

    return 0;
}

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

typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define test cout<<"#";
const ll INF = 1e18L + 5;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll h, w;
	cin>>h>>w;
	char ar[h][w];
	for(ll x = 0; x < h; x++)
	{
		for(ll y = 0; y < w; y++)
		{
			cin>>ar[x][y];
		}
	}
	ll ans[h][w];
	memset(ans, 0, sizeof(ans));
	ans[0][0] = 1;
	for(ll x = 0; x < h; x++)
	{
		for(ll y = 0; y < w; y++)
		{
			if(!(x==0 && y==0) && ar[x][y]!='#')
			{
				if((x-1)>=0)
					ans[x][y] +=ans[x-1][y];
				if((y-1)>=0)
					ans[x][y] +=ans[x][y-1];
				ans[x][y] = ans[x][y]%mod;
			}
		}
	}
	// for(ll x = 0; x < h; x++)
	// {
	// 	for(ll y = 0; y < w; y++)
	// 	{
	// 		cout<<ans[x][y]<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	cout<<ans[h-1][w-1]%mod<<"\n";
}

Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
//1000000000000000000
//   5000000000000000
int main(){
    string s;
    int K;
    cin >> s;
    cin >> K;

    for(size_t i = 0; i < s.length(); i++)
    {
        if(s[i] == '1') {
            K--;
            if (K==0) {
                cout << '1' << endl;
                break;
            }
        }
        else {
            cout << s[i] << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,h;
    cin >> n >> h;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(rall(a));
    vector<ll> power;
    rep(i, n){
        if(b[i] >= a[0]) power.push_back(b[i]);
    }
    sort(rall(power));
    ll ans = 0;
    ll i = 0;
    while(h > 0){
        if(i >= sz(power)){
            ans += rp(h, a[0]);
            print(ans);
            return 0;
        }else{
            ans++;
            h -= power[i];
            i++;
        }
    }
    print(ans);
}


Measured memory_bytes: 5824
#include<iostream>
using namespace std;
int main()
{
    char s[10];
    cin >> s;
        if(s[0]=='S')
        {
            if(s[1]=='U')
                cout << "7";
            else
                cout << "1";
        }
        else if(s[0]=='M')
            cout << "6";
        else if(s[0]=='T')
        {
            if(s[1]=='U')
                cout << "5";
            else
                cout << "3";
        }
        else if(s[0]=='W')
            cout << "4";
        else
            cout << "2";
    return 0;
}

Measured memory_bytes: 256
def main():

    n = input()
    length = len(n)
    mod = 10 ** 9 + 7

    cnt = 1
    j = n.count("1")

    for digit, num in enumerate(n[::-1], 1):
        if num == "1":
            j -= 1
            cnt += (pow(3, digit - 1, mod) + 1) * pow(2, j, mod)
            cnt %= mod

    print(cnt)


main()

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

string s[1000];
int mod = 1e9+7;
int dp[1000][1000];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> s[i];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      dp[i][j] = (i ? dp[i-1][j] : 0) + (j ? dp[i][j-1] : 0) + !(i+j);
      if (dp[i][j] >= mod) dp[i][j] -= mod;
    }
  cout << dp[h-1][w-1] << endl;
}


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

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

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

// Self settings
// clang-format off
#define MAX_N 100
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N, D;
int X[MAX_N][MAX_N];

bool C(double x) { return ceil(x) == floor(x); }

double innerDist(int x, int y) { return abs(x - y) * abs(x - y); }

int main(void)
{
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double d = 0;
      for (int k = 0; k < D; k++) {
        d += innerDist(X[i][k], X[j][k]);
      }
      double dd = sqrt(d);
      if (C(dd)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;
int k;
int n;
int main() {
    while(cin >> k, k != 0) {
        n = k * (k - 1) / 2;
        // cout << n << endl;
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            int c; cin >> c; ans += c;
        }
        ans /= (k - 1);
        cout << ans << endl;
    }
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
#include <iostream>
#include <string> 
using namespace std;
int main(){
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
}


Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int Alice_start = sc.nextInt();
        int Alice_end =sc.nextInt();
        int Bob_start =sc.nextInt();
        int Bob_end =sc.nextInt();
        int low = Math.max(Alice_start,Bob_start);
        int upp = Math.min(Alice_end,Bob_end);
        System.out.println(Math.max(0,upp-low));
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second

const ll mod=1e9+7;
ll bin(ll a, ll b) {
	a%=mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod; //mod
        a = a * a % mod; //mod
        b >>= 1;
    }
    return res%mod;
}
int main()
{
	fast;
	ll n,k,i,j;
	ll a[100005];
	cin>>n>>k;
	ll fans=0;
	for(i=k;i>=1;--i){
	
		a[i]=bin(k/i,n);
		
		for(j=2*i;j<=k;j+=i){
			a[i]=(a[i]-a[j]+mod)%mod;
		}
		fans=(fans+a[i]*i)%mod;
		
	}
	cout<<fans;
}

Measured memory_bytes: 4408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	string s;
	cin >> s;
	int cun = 0;
	int cum = 0;
	int cud = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'a')
			cun++;
		else if (s[i] == 'b')
			cum++;
		else
			cud++;
	}
	if (cun == 1 && cum == 1 && cud == 1)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

Measured memory_bytes: 3624
//package abc124.a;

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int max1 = Math.max(a, b);
        int min1 = Math.min(a, b);
        int max2 = Math.max(max1 - 1, min1);
        System.out.println(max1 + max2);
        sc.close();
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int t1,t2,t3,t4;
    cin>>t1>>t2>>t3>>t4;
    int total=t1+t2+t3+t4;
    int ans_minute=total/60;
    int ans_second=total%60;
    cout<<ans_minute<<endl<<ans_second<<endl;
    return 0;
}


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

//read_kaisetsu
int main() {
    int n,k;cin>>n>>k;
    ll a[n];rep(i,n)cin>>a[i];
    ll ans = 40000000007;
    rep(i,n-k+1){
        ans = min(ans,abs(a[i])+abs(a[i+k-1]-a[i]));
        ans = min(ans,abs(a[i+k-1])+abs(a[i+k-1]-a[i]));
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4368
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int d;
  cin >> d;
  if(d == 25) cout << "Christmas" << endl;
  if(d == 24) cout << "Christmas Eve" << endl;
  if(d == 23) cout << "Christmas Eve Eve\n";
  if(d == 22) cout << "Christmas Eve Eve Eve\n";
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, x, k;
	cin >> x;
	k = x % 100;
	x /= 100;
	x -= k / 5;
	k %= 5;
	if (k > 0)
		x--;
	if (x >= 0)
		printf("1\n");
	else
		printf("0\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1])

if counter[2] + 1 >= counter[0]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 79176
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;

namespace AtCoder {
    public class TestCode {
        static void Main(string[] args) {
            var (N,X,T) = ReadValue<double,double,double>();
            var Z = Math.Ceiling(N / X);
            Console.Write(Z * T);
        }

        static T1 ReadValue<T1>() {
            var t1 = TypeDescriptor.GetConverter(typeof(T1));
            return (T1)t1.ConvertFromString(Console.ReadLine());
        }

        static (T1, T2) ReadValue<T1, T2>() {
            var rl = Console.ReadLine().Trim().Split().ToArray();
            var t1 = TypeDescriptor.GetConverter(typeof(T1));
            var t2 = TypeDescriptor.GetConverter(typeof(T2));
            return ((T1)t1.ConvertFromString(rl[0]),
                    (T2)t2.ConvertFromString(rl[1]));
        }

        static (T1, T2, T3) ReadValue<T1, T2, T3>() {
            var rl = Console.ReadLine().Trim().Split().ToArray();
            var t1 = TypeDescriptor.GetConverter(typeof(T1));
            var t2 = TypeDescriptor.GetConverter(typeof(T2));
            var t3 = TypeDescriptor.GetConverter(typeof(T3));
            return ((T1)t1.ConvertFromString(rl[0]),
                    (T2)t2.ConvertFromString(rl[1]),
                    (T3)t3.ConvertFromString(rl[2]));
        }

        static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
            var rl = Console.ReadLine().Trim().Split().ToArray();
            var t1 = TypeDescriptor.GetConverter(typeof(T1));
            var t2 = TypeDescriptor.GetConverter(typeof(T2));
            var t3 = TypeDescriptor.GetConverter(typeof(T3));
            var t4 = TypeDescriptor.GetConverter(typeof(T4));
            return ((T1)t1.ConvertFromString(rl[0]),
                    (T2)t2.ConvertFromString(rl[1]),
                    (T3)t3.ConvertFromString(rl[2]),
                    (T4)t4.ConvertFromString(rl[3]));
        }

        static (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
            var rl = Console.ReadLine().Trim().Split().ToArray();
            var t1 = TypeDescriptor.GetConverter(typeof(T1));
            var t2 = TypeDescriptor.GetConverter(typeof(T2));
            var t3 = TypeDescriptor.GetConverter(typeof(T3));
            var t4 = TypeDescriptor.GetConverter(typeof(T4));
            var t5 = TypeDescriptor.GetConverter(typeof(T5));
            return ((T1)t1.ConvertFromString(rl[0]),
                    (T2)t2.ConvertFromString(rl[1]),
                    (T3)t3.ConvertFromString(rl[2]),
                    (T4)t4.ConvertFromString(rl[3]),
                    (T5)t5.ConvertFromString(rl[4]));
        }

        static string[] stringArray => Console.ReadLine().Split().ToArray();
        static int[] intArray => Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
        static long[] longArray => Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
        static double[] doubleArray => Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
        static decimal[] decimalArray => Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
    }
}


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

int main() {
    int N, M;
    cin >> N >> M;
    if (M == 0) {
        if (N == 1) cout << 0 << endl;
        else if (N == 2) cout << 10 << endl;
        else cout << 100 << endl;
        return 0;
    }
    vector<int> s(M), c(M);
    for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
    if (N == 1) {
        for (int i = 1; i < M; i++) {
            if (c[i] != c[0]) {
                cout << -1 << endl;
                return 0;
            }
        }
        cout << c[0] << endl;
        return 0;
    }
    vector<int> ans(N, -1);
    for (int i = 0; i < M; i++) {
        if (ans[s[i]-1] == -1) ans[s[i]-1] = c[i];
        else {
            if (ans[s[i]-1] != c[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (ans[i] == -1) {
            if (i == 0) ans[i] = 1;
            else ans[i] = 0;
        }
        if (ans[0] == 0) {
            cout << -1 << endl;
            return 0;
        }
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const int INF=1e7;
int h,w,n;
char m[1001][1001];
pii c[11];
int d[1001][1001];
int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};
int ans=0;

void bfs(){
	rep(i,0,h){
		rep(j,0,w){
			if(m[i][j]=='S'){
				c[0].fi=i; c[0].se=j;
			}else if('1'<=m[i][j] && m[i][j]<='9'){
				c[m[i][j]-'0'].fi=i;
				c[m[i][j]-'0'].se=j;
			}
		}
	}
	rep(i,0,n){
		rep(j,0,h) rep(k,0,w) d[j][k]=INF;
		d[c[i].fi][c[i].se]=0;
		int gy=c[i+1].fi;
		int gx=c[i+1].se;
		//o("    "<<i<<" "<<c[i].fi<<c[i].se);
		queue<pii> q;
		q.push(c[i]);
		while(q.size()){
			pii t=q.front(); q.pop();
			if(t.fi==gy && t.se==gx){
				ans+=d[gy][gx];
				//o("ok");
				break;
			}
			rep(j,0,4){
				int ny=t.fi+dy[j];
				int nx=t.se+dx[j];
				if(0<=ny && ny<h && 0<=nx && nx<w){
					if(m[ny][nx]!='X' && d[ny][nx]==INF){
						d[ny][nx]=d[t.fi][t.se]+1;
						//o(i<<" "<<ny<<" "<<nx<<" "<<d[ny][nx]);
						q.push(pii(ny,nx));
					}
				}
			}
		}
	}
}

signed main(){
	cin>>h>>w>>n;
	rep(i,0,h){
		rep(j,0,w){
			cin>>m[i][j];
		}
	}
	bfs();
	o(ans);
}

Measured memory_bytes: 10020
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define ll long long int
#define inf 999999999
#define maxn 100003
const ll mod = 1e9+7;
using namespace std;
int n, ar[maxn];
void code()
{
	int d, s , t;
	cin >> d >> s >> t;
	d <= s*t ? cout << "Yes" : cout << "No";
}
int main()
{
	SPEED
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	int t = 1;
	while(t--)
	{
		code();
	}
}

Measured memory_bytes: 3576
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String W = sc.next();
		String temp = null;
		List<String> list = new LinkedList<>();
		int ans = 0;
		String END_OF_TEXT = "END_OF_TEXT";

		while(true){
			temp = sc.next();
			if(temp.equals(END_OF_TEXT)){
				break;
			}
			list.add(temp.toUpperCase());
		}
		for(String data: list){
			if(data.equals(W.toUpperCase())){
				ans ++;
				}
		}
		System.out.println(ans);
	}
}




Measured memory_bytes: 26336
fun main(args : Array<String>) {
  val l = Array(1000) { 1 }
  (2..readLine()!!.toInt()).forEach {
    var n = it
    (2..999).forEach {
      while (n != 1 && n % it == 0) { n /= it; l[it]++ }
    }
  }
  print(l.map { it.toLong() }.reduce { a, b -> a * b % 1000000007 })
}

Measured memory_bytes: 33740
import java.util.*;
 
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt(); 
      
      List<Integer> split = new ArrayList<>();
        for (int i = 0; i < n; i++) {
	        int buf = sc.nextInt();
	        split.add(buf);
        }
        
        int resultsA = 0;
        int resultsB = 0;
        int max = 0;
        int index = 0;
        int size = split.size();
        String current = "A";
        int count = 0;
        Boolean boo = true;
        
        while(boo){
            for(int i = 0; i < size ; i++ ){
                if(max<=split.get(i)){
                    max = split.get(i);
                    index = i;
                }
            }
            split.remove(index);
            size -= 1;
            if(current.equals("A")){
                resultsA += max;
                current = "B";
            }else{
                resultsB += max;
                current = "A";
            }
            max = 0;
            if(size==0){
                boo = false;
            }
        }
        
        count = resultsA - resultsB;
	    
    System.out.println(count);
  }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string N; cin >> N;
    if(N[0] == '9' || N[1] == '9') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void){
  int h,a;
  scanf("%d%d",&h,&a);
  if(h<a)
    printf("1");
  else if(h%a==0)
    printf("%d\n",h/a);
  else
    printf("%d\n",h/a+1);
  return 0;
}


Measured memory_bytes: 128
// #pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
const int N = 1e5+5;
int dp[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin >> n >> k;
	k=min(n-1,k);
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<=k;i++)
	{
		dp[i]=abs(arr[i]-arr[0]);
		for(int j=0;j<i;j++)
		{
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
		}
	}
	for(int i=k+1;i<n;i++)
	{
		dp[i]=1e9;
		for(int j=(i-k);j<i;j++)
		{
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);	
		}
	}
	cout << dp[n-1];
}

Measured memory_bytes: 1024
import java.util.Scanner;

//  B - Coins

public class Main {
  public static void main(String[] args ) throws Exception {
	final int GOHYAKU = 500;
	final int HYAKU = 100;
	final int GOJU = 50;

    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    int D = Integer.parseInt(sc.next());
    int count = 0;

    for(int i = 0; i <= A; i++) {
    	if(i*GOHYAKU == D) {
//    		System.out.println();
    		count++;
    	}
    	for(int m = 0; m <= B; m++) {
    		if((i*GOHYAKU + m * HYAKU == D) && m != 0) {
				count++;
    		}
    		for(int n = 0; n <= C; n++) {
				if((i*GOHYAKU + m * HYAKU + n * GOJU == D) && n != 0) {
					count++;
				}
    		}
    	}
    }

    System.out.println(count);

  }
}

Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<algorithm>
#include<sstream>
#include<set>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    multiset<int> ms;
    multiset<int>::iterator it;
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end());
    for(int i=0; i<min(n, 5); i++) {
        for(int j=0; j<min(n, 5); j++) {
            if(i==j) continue;
            stringstream ss;
            int add;
            ss<<a[i]<<a[j];
            ss>>add;
            ms.insert(add);
        }
    }
    it = ms.begin();
    advance(it, 2);
    cout<<*it<<endl;
}

Measured memory_bytes: 1260
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<tuple>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;


int main() {


	int n, m;
	cin >> n >> m;

	auto s = make_v<int>(m,0);
	vector<int> p(m);

	fill_v(s, 0);

	for (int i = 0; i < m; i++)
	{
		int k;
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int tmp;
			cin >> tmp;
			s[i].push_back(tmp);
		}
	}

	for (int i = 0; i < m; i++)
	{
		cin >> p[i];
	}

	int ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		bool ok = true;

		for (int j = 0; j < m; j++)
		{
			//m個の電球
			int cnt = 0;
			for (int k = 0; k < s[j].size(); k++)
			{
				//
				int tmp = s[j][k];
				tmp--;
				if ((i >> tmp) & 1) {
					//スイッチがオン
					cnt++;
				}
			}

			if ((cnt % 2) != p[j]) {
				//全部つかない
				ok = false;
				break;
			}
		}
		if (ok) {
			//cout << "i = " << i << endl;
			ans++;
		}
	}


	cout << ans << endl;



	return 0;

}


Measured memory_bytes: 256
N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())
print(N[K-1])

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

inline bool is_in(const int x, const int a, const int b) {
    return a <= x && x <= b;
}

int main() {
    int n;
    cin >> n;
    vi a(n + 1), b(n);
    REP(i, n + 1) {
        cin >> a[i];
    }
    REP(i, n) {
        cin >> b[i];
    }

    ll ans = 0;
    for(int i = 0; i - (n - i - 1) <= 1; i++) {
        ans += min(a[i], b[i]);
        if(a[i] < b[i]) {
            b[i] -= a[i];
            a[i] = 0;
        }
        else {
            a[i] -= b[i];
            b[i] = 0;
        }
        ans += min(a[i + 1], b[i]);
        if(a[i + 1] < b[i]) {
            b[i] -= a[i + 1];
            a[i + 1] = 0;
        }
        else {
            a[i + 1] -= b[i];
            b[i] = 0;
        }
        // DBG(ans); // 4debug
        ans += min(a[n - i], b[n - i - 1]);
        if(a[n - i] < b[n - i - 1]) {
            b[n - i - 1] -= a[n - i];
            a[n - i] = 0;
        }
        else {
            a[n - i] -= b[n - i - 1];
            b[n - i - 1] = 0;
        }
        ans += min(a[n - i - 1], b[n - i - 1]);
        if(a[n - i - 1] < b[n - i - 1]) {
            b[n - i - 1] -= a[n - i - 1];
            a[n - i - 1] = 0;
        }
        else {
            a[n - i - 1] -= b[n - i - 1];
            b[n - i - 1] = 0;
        }
        // DBG(ans); // 4debug
    }

    cout << ans << "\n";

    return 0;
}


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

int main(){
  ll i,j,cnt;
  int n;
  ll t=1,a=1;
  cin>>n;
  ll T[n],A[n];
  for(i=0;i<n;i++)cin>>T[i]>>A[i];
  for(i=0;i<n;i++){
    j=max((t+T[i]-1)/T[i],(a+A[i]-1)/A[i]);
    while(a>A[i]*j || t>T[i]*j)j++;
    t=j*T[i];
    a=j*A[i];
  }
  cout<<t+a;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

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

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    ll x;
    cin >> x;
    cout << (x / 500 * 1000) + ((x % 500) / 5 * 5) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS vector<string>
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<ll,ll>
LL facctorialMethod(int k);
int main(){
    string s,ans;
    LL s_len;
    cin >> s;
    s_len = s.size();
    for(int i = 0; i < s_len; i++) {
        ans += "x";
    }
    cout << ans << endl;


    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int N,K,A[1<<18],M;
int main(){
  cin>>K>>N;
  for(int i=0;i<N;i++)cin>>A[i];
  M=A[N-1]-A[0];
  for(int i=1;i<N;i++)M=min(M,K-A[i]+A[i-1]);
  cout<<M<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    double w, h;
    cin >> w >> h;
    double x, y;
    cin >> x >> y;
    cout << fixed;
    int f = 0;
    if(2*x == w && 2*y == h){
        f= 1;
    }
     cout << w*h/2. << " " << f << endl;

}


Measured memory_bytes: 256
from bisect import bisect_left as bl
def I(a): return [-1<<50] + [int(input()) for i in range(a)] + [1<<50]
A, B, Q = map(int, input().split())
S, T = I(A), I(B)

for _ in range(Q):
    x = int(input())
    k, l = bl(S, x), bl(T, x)
    a, b, c, d = x-S[k-1], x-T[l-1], S[k]-x, T[l]-x
    print(min(max(a, b), max(c, d), 2*a+d, 2*d+a, 2*b+c, 2*c+b))

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

int main(){
  int N;cin>>N;
  std::vector<int> A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  std::vector<int> B(N);
  for(int i=0;i<N;i++)cin>>B[i];
  std::vector<int> C(N-1);
  for(int i=0;i<N-1;i++)cin>>C[i];
  int ans=0;
  for(int i=0;i<N;i++)ans+=B[i];
  for(int i=0;i<N-1;i++){
    if(A[i]+1==A[i+1])ans+=C[A[i]-1];
  }
cout<<ans<<endl;
}


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

int main(){
    char n[10];
    int ans=0;
    for(int i=0;i<10;i++){
        n[i]='x';
    }
    for(int i=0;i<10;i++){
        cin>>n[i];
    }
    for(int i=0;i<10;i++){
        if(n[i]=='A' or n[i]=='C' or n[i]=='G' or n[i]=='T'){
            int p=i+1;
            int k=1;
            for(;p<10 and (n[p]=='A' or n[p]=='C' or n[p]=='G' or n[p]=='T');p++){
                k++;
            }
            ans=max(ans,k);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
p = 10**9+7
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
cnt=0
for i in range(n):
  cnt+=ans//a[i]
print(cnt%p)



Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t n;
  cin >> n;
  bool f = false;
  rep(i,99){
    rep(j,99){
      if((4*i)+(7*j) == n) f = true;
    }
  }
  if(f){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#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()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vector<pair<char, ll>> h ={ { 'M', 0 }, { 'A', 0 },
        { 'R', 0 }, { 'C', 0 }, { 'H', 0 } };
    // set<string> ss;
    rep(i, n) {
        rep(j, h.size()) {
            if (s[i][0] == h[j].first) {
                h[j].second++;
                // ss.insert(s[i]);
                // && !ss.count(s[i])
            }
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= 4; i++) {
        for (ll j = i+1; j <= 4; j++) {
            for (ll k = j+1; k <= 4; k++) {
                ans += h[i].second * h[j].second * h[k].second;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define INF 1001001001

using namespace std;

int main(void){
  unsigned long long n;
  string ans;
  
  cin >> n;
  while (n){
    n--;
    ans += (char)('a'+(n%26));
    //cout << n%26 << " ";
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
        
  return 0;
}

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

int main(int argc, char const *argv[])
{
    int n, flag= 0;
    vector<int> v;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        v.push_back(temp);
    }

    for (int i = 0; i < n; i++)
    {
        if(v[i] != i + 1) {
            flag += 1;
        }
    }

    if(flag <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    string in;
    cin >> in;
    int i=in[0]-'0';
    int j=in[1]-'0';
    int k=in[2]-'0';
    int l=in[3]-'0';
    if(i+j+k+l==7){
        cout << i << "+" << j << "+" << k << "+" << l << "=7" << endl;
    }else if(i+j+k-l==7){
        cout << i << "+" << j << "+" << k << "-" << l << "=7" << endl;
    }else if(i+j-k+l==7){
        cout << i << "+" << j << "-" << k << "+" << l << "=7" << endl;
    }else if(i+j-k-l==7){
        cout << i << "+" << j << "-" << k << "-" << l << "=7" << endl;
    }else if(i-j+k+l==7){
        cout << i << "-" << j << "+" << k << "+" << l << "=7" << endl;
    }else if(i-j+k-l==7){
        cout << i << "-" << j << "+" << k << "-" << l << "=7" << endl;
    }else if(i-j-k+l==7){
        cout << i << "-" << j << "-" << k << "+" << l << "=7" << endl;
    }else if(i-j-k-l==7){
        cout << i << "-" << j << "-" << k << "-" << l << "=7" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int N=105;
int c[N],n,mn=233,mx;
int main(){
	scanf("%d",&n);
	for(R int i=1,x;i<=n;++i)scanf("%d",&x),++c[x],cmin(mn,x),cmax(mx,x);
	if(c[mn]>2)return puts("Impossible"),0;
	fp(i,mn+1,mx)if(c[i]<2)return puts("Impossible"),0;
	if(c[mn]==2&&mn!=mx-mn+1)return puts("Impossible"),0;
	if(c[mn]==1&&mn!=mx-mn)return puts("Impossible"),0;
	return puts("Possible"),0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
 int a[4][4]={0},n,var=0,var1=0,temp=0;
 vector<int> q;
 for(int i=0;i<3;i++)
 {
     for(int j=0;j<3;j++)
     {
         cin>>a[i][j];
     }
 }
 cin>>n;
 for(int k=0;k<n;k++)
 {
     cin>>var;
     for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
                {
                if(var==a[i][j])
                a[i][j]=0;
                }
        }
 }
 for(int i=0;i<3 && temp==0;i++)
 {
     var=0;
     var1=0;
     for(int j=0;j<3;j++)
     {
         var+=a[i][j];
         var1+=a[j][i];
     }
     if(var==0 || var1==0)
     {
         temp=1;
     }
 }
 var=0;
 var1=0;
 for(int i=0;i<3 && temp==0;i++)
 {
     var+=a[i][i];
     var1+=a[i][3-i-1];
 }
 if(var==0 || var1==0)
 {
     temp=1;
 }
 if(temp)
 cout<<"Yes";
 else
 cout<<"No";
 return 0;
}


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

int main(){
    int a,b;
    while(1){
        cin >> a >> b ;
        if (a==0 && b==0) break;
        if (a>b){
            cout<<b<<" "<<a<<endl;
        }else{
            cout<<a<<" "<<b<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
N = int(input())
A = []

for i in range(N):
    A.append(int(input()))

A.sort()

if N % 2 == 0:
    start = N // 2 - 1
    end = start + 1
else:
    start = N // 2
    if A[start] - A[start-1] > A[start+1] - A[start]:
        end = start + 1
    else:
        end = start - 1

result = 0

for i in range(N):
    if i == start or i == end:
        result += abs(A[i] - A[start])
    else:
        result += abs(A[i] - A[start]) * 2

print(result)


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


int main(){
                                                                     

    string w;

    char c;

    int i, t;


    cin >> w;


    for( c = 'a' ; c <= 'z' ; c = c + 1 ){

         for( i = 0 ; i < w.size() ; i = i + 1 ){

              if( w.at(i) == c ) t += 1;

              }

         if( t % 2 != 0 ){

             cout << "No" << endl;

             return 0;

             }

         }


    cout << "Yes" << endl;


    return 0;

    }

Measured memory_bytes: 256
f=lambda:input().split()
n,m=map(int,f())
sa,lw=set(),[0]*n
for _ in range(m):
  p,s=f()
  if p in sa: continue
  if s=='AC': sa.add(p)
  else: lw[int(p)-1]+=1
print(len(sa),sum(lw[int(p)-1] for p in sa))

Measured memory_bytes: 14824
import java.util.*;

public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int N = Integer.parseInt(sc.nextLine());   // データの個数
      String line = sc.nextLine();
      String[] dataInfo = line.split("\\s+");
      
      int counter = 0;
      
      for (int i = 0; i < N; i++) {
      
          int tmpNumber = Integer.parseInt(dataInfo[i]);
          // 2で割り切れなくなったら終了
          while (tmpNumber % 2 == 0) {
              tmpNumber = tmpNumber / 2;
              counter++;
          }
      }

      System.out.println(counter);
      sc.close();
    }

}

Measured memory_bytes: 27288
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){

    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if(x>=r && x<=W-r && y>=r && y<=H-r){
        printf("Yes\n");
    }
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 2656
h, w = map(int, input().split())
ans = float("inf")
for i in range(h):
    choco = [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]
    ans = min(ans, max(choco) - min(choco))
for i in range(w):
    choco = [i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)]
    ans = min(ans, max(choco) - min(choco))
for i in range(h):
    choco = [i * w, w * ((h - i) // 2), w * ((h - i) - (h - i) // 2)]
    ans = min(ans, max(choco) - min(choco))
for i in range(w):
    choco = [i * h, h * ((w - i) // 2), h * ((w - i) - (w - i) // 2)]
    ans = min(ans, max(choco) - min(choco))
print(ans)

Measured memory_bytes: 3064
program Sum_of_Large_Numbers;
uses math;
const
  m: int64 = 1000000007;
  h: int64 = 500000004;
  s: int64 = 166666668;
var
  n, k: int64;
function f(i: int64): int64;
begin
  f := i*(((n+1)*(h*(i+1) mod m)-(s*((i+1)*(i*2+1) mod m) mod m)+1) mod m);
end;
begin
  read(n, k);
  writeln((m+(f(n+1)-f(k-1)) mod m) mod m);
end.

Measured memory_bytes: 1324
n, m = map(int, input().split())
a = [int(x) for x in input().split()]

ok = False
cnt = m
t = sum(a)
for i in range(n):
	if a[i] * 4 * m >= t:
		cnt -= 1
	if cnt == 0:
		ok = True
		break
		
if ok:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064