akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
using namespace std;

#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define dbg(x) cerr << #x << " = " << (x) << endl;
typedef long long ll;
typedef vector<int> vi;

void solve_small(vi);

const int dy[] = {-1, -1, 1, 1}, dx[] = {-1, 0, 0, 1};
map<ll, int> M;
int n, num[5][5];

inline ll hash(const vi &v){
	ll res = 0;
	rep(i,v.size()) res *= 17, res += v[i];
	return res;
}
inline void push(const vi &v, int c, queue<pair<int,vi> > &q){
	ll h = hash(v);
	if(M.count(h))return;
	M[h] = c;
	if(c <= 22) q.push(make_pair(c+1, v));
}

int main(){
	
	queue<pair<int,vi> > q;
	vi goal;
	int k = 0;
	rep(i,5) rep(j,i+1){
		num[i][j] = k;
		goal.push_back(++k);
	}
	push(goal, 0, q);
	
	while(!q.empty()){
		vi v = q.front().second;
		int c = q.front().first; q.pop();
		
		int idx = -1, y, x;
		for(y = 0; y < 5; y++) for(x = 0; x <= y; x++)
			if(v[++idx] == 1) goto OUT;
		OUT:;
		rep(d,4){
			int ny = y + dy[d], nx = x + dx[d];
			if(ny < 0 || nx < 0 || ny >= 5 || nx > ny) continue;
			swap(v[num[ny][nx]], v[idx]);
			push(v, c, q);
			swap(v[num[ny][nx]], v[idx]);
		}
	}
	int cs = 0;
	
	while(cin >> n, n){
		
		cout << "Case " << ++cs << ": ";
		
		vi v(n*(n+1)/2);
		k = 0;
		rep(i,n) rep(j,i+1) cin >> v[k++];
		if(n <= 4){
			solve_small(v);
			continue;
		}
		
		ll h = hash(v);
		if(M.count(h)){
			cout << M[h] << endl;
			continue;
		}
		
		queue<pair<int,vi> > q;
		set<ll> s;
		s.insert(h);
		q.push(make_pair(0, v));
		while(!q.empty()){
			v = q.front().second;
			int c = q.front().first; q.pop();
			
			int idx = -1, y, x;
			for(y = 0; y < 5; y++) for(x = 0; x <= y; x++)
				if(v[++idx] == 1) goto OUT2;
			OUT2:;
			rep(d,4){
				int ny = y + dy[d], nx = x + dx[d];
				if(ny < 0 || nx < 0 || ny >= 5 || nx > ny) continue;
				swap(v[num[ny][nx]], v[idx]);
				ll h = hash(v);
				if(M.count(h)){
					cout << M[h] + c + 1 << endl;
					goto END;
				}
				if(!s.count(h)) q.push(make_pair(c+1, v)), s.insert(h);
				swap(v[num[ny][nx]], v[idx]);
			}
		}
		END:;
	}
	return 0;
}

void solve_small(vi v){
	vi goal = v;
	sort(goal.begin(), goal.end());
	queue<pair<int,vi> > q;
	set<ll> s;
	ll ghash = hash(goal);
	q.push(make_pair(0, v));
	
	while(!q.empty()){
		v = q.front().second;
		int c = q.front().first; q.pop();
		ll h = hash(v);
		if(s.count(h)) continue;
		s.insert(h);
		if(h == ghash){
			cout << c <<endl; return;
		}
		int idx = -1, y, x;
		for(y = 0; y < 5; y++) for(x = 0; x <= y; x++)
			if(v[++idx] == 1) goto OUT3;
		OUT3:;
		rep(d,4){
			int ny = y + dy[d], nx = x + dx[d];
			if(ny < 0 || nx < 0 || ny >= n || nx > ny) continue;
			swap(v[num[ny][nx]], v[idx]);
			if(!s.count(hash(v))) q.push(make_pair(c+1, v));
			swap(v[num[ny][nx]], v[idx]);
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define inf 10010011111

int main() {
        int n,k;
        cin >> n >> k;
        int h[n];
        for (int i=0; i<n; ++i) {
                cin >> h[i];
        }
        int dp[n];
        for (int i=0; i<n; ++i) {
                dp[i] = inf;
        }
        dp[0] = 0;
        for (int i=1; i<=n; ++i) {
                for (int j=1; j<=k && i-j >= 0; ++j) {
                        dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
                }
        }
        cout << dp[n-1] << endl;
}

Measured memory_bytes: 4340
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
vector <int> v[30];
int n,Min,Min1,i,j,nr,nr1,r,y,c[30][100004],u[30][100004];
char x,a[100004],s[100004];
bool ok;
int main()
{
    scanf ("%c", &x);
    n=0;
    while (x!='\n')
    {
        s[n]=x;
        n++;
        scanf ("%c", &x);
    }
    for (i=0;i<=(n-1);i++)
        v[s[i]-'a'].push_back(i);
    ok=true;
    Min=2000000000;
    for (i=0;i<=25;i++)
    {
        if (v[i].size()==0)
        {
            ok=false;
            x='a'+i;
            break;
        }
        c[i][1]=v[i].size()-2;
        u[i][1]=v[i][c[i][1]+1];
        if (u[i][1]<Min)
            Min=u[i][1];
    }
    if (ok==false)
        printf ("%c\n", x);
    else
    {
        nr=0;
        nr1=1;
        while (ok==true)
        {
            nr1++;
            Min1=Min;
            for (i=0;i<=25;i++)
            {
                for (j=c[i][nr1-1];j>=0;j--)
                {
                    if (v[i][j]<Min1)
                        break;
                }
                if (j<0)
                {
                    a[++nr]='a'+i;
                    ok=false;
                    r=i;
                    c[i][nr1]=-1;
                    break;
                }
                else
                {
                    c[i][nr1]=j-1;
                    u[i][nr1]=v[i][c[i][nr1]+1];
                    if (u[i][nr1]<Min)
                        Min=u[i][nr1];
                }
            }
        }
        y=v[r][0];
        for (j=(nr1-1);j>=1;j--)
        {
            for (i=0;i<=25;i++)
            {
                if (u[i][j]<=y)
                    break;
            }
            r=i;
            a[++nr]='a'+i;
            if ((c[r][j]+2)<=(v[r].size()-1))
                y=v[r][c[r][j]+2];
            else
                y=n;
        }
    }
    for (i=1;i<=nr;i++)
        printf ("%c", a[i]);
    printf ("\n");
    return 0;
}


Measured memory_bytes: 22016
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int num = scan.nextInt();
		int num2 = scan.nextInt();

		int num3 = num*num2;
		int num4 = num*2+num2*2;

		System.out.println(num3+" "+num4);



	}

}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

using bs = bitset<200010>;

void solve() {
    ll N;
    cin >> N;
    string S;
    cin >> S;

    bs base;
    for (ll i = 0; i < N; i++) {
        if (S[i] == '1') {
            base[N - 1 - i] = true;
        }
    }

    ll pcnt = base.count();
    ll pcnt1 = pcnt + 1;
    ll pcnt2 = pcnt - 1;
    if (pcnt2 == 0) {
        pcnt2 = -1;
    }
    Vl rs1(N), rs2(N);
    ll cur1 = 1;
    ll cur2 = 1;
    for (ll i = 0; i < N; i++) {
        rs1[i] = cur1;
        cur1 *= 2;
        cur1 %= pcnt1;

        rs2[i] = cur2;
        cur2 *= 2;
        cur2 %= pcnt2;
    }

    //+
    ll r1 = 0;
    for (ll i = 0; i < N; i++) {
        if (base[i]) {
            r1 += rs1[i];
        }
    }
    r1 %= pcnt1;

    //-
    ll r2 = 0;
    for (ll i = 0; i < N; i++) {
        if (base[i]) {
            r2 += rs2[i];
        }
    }
    r2 %= pcnt2;

    for (ll i = N - 1; i >= 0; i--) {
        if (pcnt == 1 && base[i]) {
            cout << 0 << "\n";
            continue;
        }

        ll r;
        if (base[i]) {
            r = (r2 - rs2[i] + pcnt2) % pcnt2;
        }
        else {
            r = (r1 + rs1[i]) % pcnt1;
        }

        ll cnt = 1;
        while (r > 0) {
            ll c = __builtin_popcountll(r);
            r %= c;
            ++cnt;
        }

        cout << cnt << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 6752
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;


long long func( long long a, long long b, long long p ) {
    if ( b == 0 ) {
        return 1;
    }
    else if ( b%2 == 0 ) {
        long long temp = func( a, b/2, p );
        return (temp * temp)%p;
    }
    else {
        return ( func( a, b-1, p ) * a ) % p;
    }
    
}

int main() {
    
    long long N;
    cin >> N;
    vector<long long> A(N);
    for ( long long i = 0; i < N; i++ ) {
        cin >> A[i];
        A[i] %= MOD;
    }

    vector<long long> M(N+1);
    long long m = 1;
    for ( long long i = 1; i <= N; i++ ) {
        m *= i;
        m %= MOD;
    }
    
    for ( long long i = 1; i <= N; i++ ) {
        M[i-1] = ( m * func( i, MOD-2, MOD ) )%MOD;
    }

    long long a = 0;
    for ( long long i = 0; i < N; i++ ) {
        a += M[i];
        a %= MOD;
    }

    long long ans = 0;
    ans = (a*A[0])%MOD;

    for ( long long i = 1; i < N; i++ ) {
        a += M[i];
        a %= MOD;
        a = ( (a+MOD) - M[N-i] )%MOD;

        ans += ( a*A[i] )%MOD;
        ans %= MOD;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	while(true){
  int a=0,b=0,N,Card[2];
  cin >> N;
  if(N==0)
 	break;
  for(int i=0;i<N;i++){
  	cin >> Card[0] >> Card[1];
  	int sum=Card[0]+Card[1],truth=(Card[0]>Card[1]);
 	if(Card[0]!=Card[1]){
  	a+=sum*truth;
  	b+=sum*!(truth);
 	}
 	else{
 		a+=sum/2;
 		b+=sum/2;
 	}
  }
  cout << a << " "<< b << endl;
	}
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  bool pred = false;
  int x{A};
  for (auto i = B; i; --i) {
    x %= B;
    if (x == C) pred = true;
    x += A;
  }

  cout << (pred ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AShiritori solver = new AShiritori();
        solver.solve(1, in, out);
        out.close();
    }

    static class AShiritori {
        private static final String YES = "YES";
        private static final String NO = "NO";

        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String a = in.string(), b = in.string(), c = in.string();
            if (a.charAt(a.length() - 1) != b.charAt(0)) {
                out.println(NO);
            } else if (b.charAt(b.length() - 1) != c.charAt(0)) {
                out.println(NO);
            } else {
                out.println(YES);
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

int n;
int a[100004];
int main() {
	cin>>n;
	for(int i = 0; i < n; i++)	cin>>a[i];
	sort(a,a+n);
	int b = a[n-1];
	int l = b/2;
	int idx = lower_bound(a,a+n-1,l)-a;
	if(idx == n-1){
		cout<<a[n-1]<<" "<<a[n-2];
		return 0;
	}
	if(idx == 0){
		cout<<a[n-1]<<" "<<a[0];
		return 0;
	}
	int c = a[idx];
	if(c>l)	c = b-c;
	if(a[idx-1]<c)	cout<<a[n-1]<<" "<<a[idx];
	else	cout<<a[n-1]<<" "<<a[idx-1];
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    string ret;
    rep(i,gy - sy){
        ret += 'U';
    }
    rep(i,gx - sx){
        ret += 'R';
    }
    rep(i,gy- sy){
        ret += 'D';
    }
    rep(i,gx - sx){
        ret += 'L';
    }
    ret += 'L';
    rep(i,gy - sy +1){
        ret +='U';
    }
    rep(i,gx - sx+1){
        ret += 'R';
    }
    ret += 'D';
    ret += 'R';
    rep(i,gy - sy+1){
        ret += 'D';
    }
    rep(i,gx - sx +1){
        ret += 'L';
    }
    ret += 'U';
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(k>=n)cout << x*n << endl;
    else cout << (n-k)*y+x*k << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

const int maxn = 6e5 + 10; 
int a[maxn];
int m[maxn << 2];

#define mid (l + r) / 2
#define lson 2 * rt
#define rson 2 * rt + 1

int query(int rt,int ql,int qr,int l,int r){
    if(l >= ql && r <= qr){
        return m[rt];
    }
    int ans = 0;
    if(ql <= mid)ans = max(ans,query(lson,ql,qr,l,mid));
    if(qr > mid)ans = max(ans,query(rson,ql,qr,mid + 1,r));
    return ans;
}
void update(int rt,int pos,int v,int l,int r){
    if(l == r){
        m[rt] = v;
        return ;
    }
    if(pos <= mid)update(lson,pos,v,l,mid);
    else update(rson,pos,v,mid + 1,r);
    m[rt] = max(m[lson],m[rson]);
}
void solved(){
    int n,k;cin>>n>>k;
    for(int i = 1; i <= n; i++)scanf("%d",&a[i]),a[i]++;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int res = query(1,max(a[i] - k,0),a[i] + k,1,maxn) + 1;
        update(1,a[i],res,1,maxn);
        ans = max(ans,res);
    }
    cout<<ans<<endl;
}
int main(){
    solved();
    return 0;
}

Measured memory_bytes: 8520
using System;


namespace ListofTop3Hills
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            int strint;
            int[] m = new int[10];
            int i;

            for(i = 0; i<10; ++i)
            {
                str = Console.ReadLine();
                strint = int.Parse(str);
                m[i] = strint;
                  
            }

            Array.Sort(m);
            Array.Reverse(m);
            for (i = 0; i < 3; ++i)
            {
                Console.WriteLine(m[i]);
            }
        }
    }
}

Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  double t, x;
  cin >> t >> x;
  double ans = t/x;
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;

void solve(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << min(c,b/a) << '\n';
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll mod = 1e9+7;

main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x = a*c;
    x = max(x,a*d);
    x = max(x,b*c);
    x = max(x,b*d);
    cout<<x;
}

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

#define int long long
#define pb push_back
#define all(a) begin(a), end(a)
#define deb(x) cout << #x << " = " << x << endl
#define debu(x, y) cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl

typedef long long ll;
ll mod=1000000007;

int h, w, n;

bool is_ok(int i, int j) {
    if(i >= 0 && j >= 0 && i < h && j < w && (i+2) < h && (j+2) < w) return true;
    return false;
}

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

    cin >> h >> w >> n;

    vector<ll> ans(10, 0);
    ans[0] = (max(0LL, h-2) * max(0LL, w-2));

    set<pair<int, int>> mark;

    for(int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        int x = a-2, y = b-2;
        for(int top_x = x; top_x < x+3; top_x++) {
            for(int top_y = y; top_y < y+3; top_y++) {
                if(!is_ok(top_x, top_y)) continue;
                int val = 0;

                for(int p=0; p<3; p++) {
                    for(int q=0; q<3; q++) {
                        if(mark.find({top_x+p, top_y+q}) != mark.end()) {
                            val++;
                        }
                    }
                }

                ans[val]--;
                ans[val+1]++;

            }
        }

        mark.insert({a, b});

    }

    for(int i=0; i<10; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 9844
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;

void main(){
	auto N=readln.chomp.to!int;
	auto A=readln.chomp.to!int;
	if(N%500<=A)writeln("Yes");
	else if(N%500>A)writeln("No");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
char S[6000000],T[60000000],*x="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",q[10];
char *t[35]={"100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000",
"0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100",
"10011101","000010","10010010","10010011","10010000","101","010001","000011","10010001","000000","000001"};
int i,j,k,s[128],p;
 
 
int main()
{
    for(j=0;x[j];j++)s[x[j]]=k++;
    for(;gets(S);)
    {
        memset(T,0,sizeof(T));
        for(i=j=0;S[i];i++)
        {
            p=s[S[i]];
            for(k=4;k>=0;k--)
                T[j++]=(p>>k&1)+'0';
        }
        p=0;
        memset(q,0,sizeof(q));
        for(i=0;T[i];i++)
        {
            q[p++]=T[i];
            for(j=0;j<32;j++)
            {
                if(strcmp(q,t[j])==0)
                {
                    putchar(x[j]);
                    memset(q,0,sizeof(q));
                    p=0;
                }
            }
        }
        puts("");
    }
    return 0;
}

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

const ll INF = 1LL << 60;

ll N, A, B;
int main() {
    cin >> N >> A >> B;
    ll dist = abs(A - B) - 1;
    ll ans = INF;
    if (dist % 2 == 1) {
        ans = (dist + 1) / 2;
    } else {
        // A < B 

        ll tmp = 0;
        // A が1にぶつかってから向かう
        // ll base = A - 1; // A が壁にぶつかるまで
        ll base = A; // A が壁にぶつかるまで
        tmp = (dist + base * 2) / 2;
        // cout << tmp << endl;
        ans = min(ans, tmp);

        // B がNにぶつかってから向かう 
        base = N - B + 1;
        // tmp = base + ((N - (A + base)) / 2);
        tmp = (dist + base * 2) / 2;
        // cout << tmp << endl;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100005;
//
//
void solve(){
    int n;
    cin>>n;
    vector<ll> vec(MAX, 0);
    ll sm = 0;
    for(int i = 0; i < n; i++){
        int p;
        cin>>p;
        vec[p]++;
        sm += p;
    }
    int q;
    cin>>q;
    while(q--){
        int b, c;
        cin>>b>>c;
        sm -= vec[b]*b;
        sm += vec[b]*c;
        vec[c] += vec[b];
        vec[b] = 0;
        cout<<sm<<"\n";
    }
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}


template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

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




int main(){

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


    string s, t;
    cin >> s >> t;


    map<char,int> mps;
    map<char,int> mpt;
    int idx = 0;
    int ss[s.size()];
    int tt[t.size()];

    rep(i, s.size()){
        if(mps[s[i]] == 0){
            mps[s[i]] = idx;
            idx++;
            ss[i] = mps[s[i]];
        }
        else{
            ss[i] = mps[s[i]];
        }
    }


    idx = 0;
    rep(i, t.size()){
        if(mpt[t[i]] == 0){
            mpt[t[i]] = idx;
            idx++;
            tt[i] = mpt[t[i]];
        }
        else{
            tt[i] = mpt[t[i]];
        }

        if(tt[i] != ss[i]){
            No();
            return 0;
        }
    }

    Yes();



    return 0;



}


Measured memory_bytes: 2452
def repeat_string(x, y):
    """Return the digit x repeated y times."""
    single_string = str(x)
    repeat_string = single_string*y
    return repeat_string


def compare_strings(a, b):
    if a>b: return(repeat_string(b, a))
    return(repeat_string(a, b))


if __name__ == "__main__":
    test1 = "4 3"
    test2 = "7 7"
    test = test2
    test_input = map(int, input().split())
    print(compare_strings(*test_input))


Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
using namespace std;

long long a[100010];
long long mask[61];

int main()
{
    int n;scanf("%d",&n);
    //ios::sync_with_stdio(false);
    for (int i=0;i<n;++i)
        scanf("%lld",&a[i]);

    long long ans=0;
    long long tmp=0;
    for (int i=0;i<n;++i)
        tmp^= a[i];

    ans=tmp;
    tmp= (1LL << 61)-1-tmp;
    //cout << tmp << endl;
    for (int i=0;i<n;++i)
        a[i]&=tmp;
    //cout << ans <<endl;
    tmp=0;
    for (int i=0;i<n;++i)
    {
        for (int j=60;j>=0;--j)
        {
            if ( (a[i]&(1LL<<j))==0 ) continue;
            if ( !mask[j] ){
                mask[j]=a[i];
                break;
            }
            a[i]^=mask[j];
        }
    }
    for (int i=59;i>=0;--i)
    {
       // cout << i << ' ' << mask[i] << tmp <<endl;
        if (mask[i] && (tmp^mask[i])>tmp)
            tmp^=mask[i];
          //cout << i << ' ' << mask[i] << tmp <<endl;
    }
    printf("%lld\n",ans+(tmp*2));

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair <int,int> pi;
int n,m,d[200005],c[200005];
int INF = 1e9;
set <pi> wi;
multiset <int> mn;

struct lange {
    int l,r;
}a[200005];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= n;i++) cin >> a[i].l >> a[i].r;
    for(int i = 1;i <= m;i++) wi.insert({i,0}), mn.insert(0);
    for(int i = 1;i <= n;i++) {
        auto it = wi.upper_bound({a[i].r,INF});
        if(it != wi.begin()) {
            it--;
            pi val = *it;
            auto itl = wi.lower_bound({a[i].l,0});
            auto itr = wi.upper_bound({a[i].r,INF});
            if(itr != wi.begin()) {
                vector <pi> er;
                for(auto j = itl;j != itr;j++) {
                    er.push_back(*j);
                }
                for(pi j : er) {
                    wi.erase(j);
                    mn.erase(mn.find(j.y));
                }
                if(a[i].r != m) {
                    auto it2 = wi.lower_bound({a[i].r+1,0});
                    if((*it2).x != a[i].r+1) {
                        wi.insert({a[i].r+1,val.y+(a[i].r+1-val.x)});
                        mn.insert(val.y+(a[i].r+1-val.x));
                    }
                }
            }
        }
        if(wi.empty()) cout << "-1\n";
        else cout << *mn.begin()+i << '\n';
    }
    return 0;
}

Measured memory_bytes: 24012
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
//--GLOBAL---------------------------------


//--MAIN-----------------------------------
void Main(){
    
    ll N,M; cin>>N>>M;

    double kitai[N]={};
    ll ct[N]={};
    vector<ll> ve[N];

    rep(i,M){
        ll s,t; cin>>s>>t; --s,--t;
        ve[s].emplace_back(t);
        ++ct[s];
    }

    kitai[N-1]=0;
    repr(i,N-2,0){
        for(auto j:ve[i]){
            kitai[i]+=(1+kitai[j])/ct[i];
        }
    }

    double onkaku[N];
    onkaku[0]=1;

    rep(i,N){
        for(auto j:ve[i]){
            onkaku[j]+=onkaku[i]/ct[i];
        }
    }

    double ans0=kitai[0];
    double ans=ans0;

    rep(i,N-1){
        if(ct[i]==1) continue;
        double MAXX=0;
        ll saki;
        for (auto j : ve[i]) {
            if(maxi(MAXX,kitai[j])) saki=j;
        }
        double buff=0;

        double kita[N]={};
        kita[N-1]=0;
        --ct[i];
        repr(j,N-2,0){
            for(auto k: ve[j]){
                if(j==i and saki==k) continue;
                kita[j]+=(1+kita[k])/ct[j];
            }
        }
        ++ct[i];
/*
        for (auto j : ve[i]) {
            if (j==saki) buff-=(kitai[j]+1)/ct[i];
            else {
                buff-=(kitai[j]+1)/ct[i];
                buff+=(kitai[j]+1)/(ct[i]-1);
            }
        }
        buff*=onkaku[i];
        buff+=ans0;
        */

        mini(ans,kita[0]);
    }

    cout<< ans<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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 long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int a,p;
	cin>>a>>p;
	cout<<(a*3+p)/2<<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 a, b, t;
	cin >> a >> b >> t;

	long long r = 0, x = 0;

	for (long long x = 0; x + a <= t; x += a) r += b;
	
		cout << r<< '\n';




	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.1415926535

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

#define itn int

int main() {
    itn n;
    cin >> n;
    string s;
    map<string, int> m;
    rep(i,n) {
        cin >> s;
        m[s]++;
    }
    int maxv = -INF;
    for (auto x : m){
        int v = x.second;
        chmax(maxv, v);
    }
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second == maxv)
            cout << it->first << endl;
    }
}

Measured memory_bytes: 25216
#include <iostream>
using namespace std;
int main() {
long int N,A,B;
cin>>N>>A>>B;
long int amari,set,ans;
amari=N%(A+B);
set=(N-amari)/(A+B);  
if(amari<=A){ans=set*A+amari;}else{ans=set*A+A;}
cout<<ans;  
}

Measured memory_bytes: 256
// C++ program to find LCM of two numbers
#include <iostream>
using namespace std;
// Recursive function to return gcd of a and b
class gfg
{
public : int gcd(long long int a, long long int b){
	if (a == 0)
		return b;
	return gcd(b % a, a);
}


// Function to return LCM of two numbers
long long int lcm(long long int a, long long int b)
{
	return (a*b)/gcd(a, b);
}
} ;
// Driver program to test above function
int main()
{
	gfg g;
	long long int a,b;
	cin>>a>>b;
	cout<<g.lcm(a, b)<<endl;;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int X, Y;
    cin >> X >> Y;
    double c = static_cast<double>(4 * X - Y) / 2;
    double t = static_cast<double>(Y - 2 * X) / 2;
    if (c >= 0 && t >= 0 && static_cast<int>(c) == c && static_cast<int>(t) == t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3620
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        exit ()
    for i in range(h):
        if i%2 == 0:
            for j in range(w):
                print ("#",end="") if j%2 == 0 else print (".",end="")
        else:
            for j in range(w):
                print (".",end="") if j%2 == 0 else print ("#",end="")
        print ()
    print ()



Measured memory_bytes: 7000
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
a=list(map(int,input().split()))
edge=[[]for _ in range(n)]
for x,y in[list(map(int,input().split()))for _ in range(n-1)]:
  edge[x-1].append(y-1)
  edge[y-1].append(x-1)
def bfs(r,v):
  for i in edge[v]:
    if(r!=i)and(a[v]>a[i])and(not(bfs(v,i))):return True
  return False
print(*[i+1 for i in range(n)if bfs(-1,i)])

Measured memory_bytes: 48988
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	
	if(t < 600) cout<<"8"<<endl;
	else if(t < 800) cout<<"7"<<endl;
	else if(t < 1000) cout<<"6"<<endl;
	else if(t < 1200) cout<<"5"<<endl;
	else if(t < 1400) cout<<"4"<<endl;
	else if(t < 1600) cout<<"3"<<endl;
	else if(t < 1800) cout<<"2"<<endl;
	else
	{
		cout<<"1"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3672
#include<stdio.h>

int main(){
    int N,K,i,j,tmp=0,total=0;
    int p[1000];
    
    scanf("%d %d",&N,&K);
    for(i=0;i<N;i++) scanf("%d ",&p[i]);
    
    for (i=0; i<N; ++i) {
        for (j=i+1; j<N; ++j) {
          if (p[i] > p[j]) {
            tmp =  p[i];
            p[i] = p[j];
            p[j] = tmp;
          }
        }
    }
    //for(i=0;i<N;i++) printf("%d\n",p[i]);
    for(i=0;i<K;i++){
        total+=p[i];
    }
    printf("%d\n",total);
    /*printf("%d %d\n",N,K);
    for(i=0;i<N;i++){
        printf("%d ",p[i]);
    }*/
    return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll x,a,b;
  cin >> x >> a >> b;
  if(a>=b) cout << "delicious" << endl;
  else if(b-a<x+1)cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		int[]A = new int[N];
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str2[i]);
		}
		Array.Sort(A,(x,y)=>y-x);
		int a1 = Math.Min(K,N);
		for(var i=0;i<a1;i++){
			A[i] = 0;
		}
		long ans = 0;
		for(var i=0;i<N;i++){
			ans += A[i];
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 31080
#include<cstdio>
bool is_on(int k,int s[],bool sw[],int p){
    int cnt=0;
    for(int i=0;i<k;i++){
        if(sw[s[i]])cnt++;
    }
    return (cnt%2==p);
}
int main(){
    int n,m,k[10],s[10][10],p[10];
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d",&k[i]);
        for(int j=0;j<k[i];j++){
            scanf("%d",&s[i][j]);
            s[i][j]--;
        }
    }
    for(int i=0;i<m;i++){
        scanf("%d",&p[i]);
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        bool sw[10];
        for(int j=0;j<n;j++){
            sw[j]=((i&(1<<j))!=0);
        }
        bool flg=true;
        for(int j=0;j<m;j++){
            if(!is_on(k[j],s[j],sw,p[j])){
                flg=false;
                break;
            }
        }
        if(flg)ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
using namespace std;



int main()
{
	ios::sync_with_stdio(0);
	string s;
	cin >> s;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}

	cout << s;

    return 0;
}


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


int main(){


    long long n, m, i, b, c, x;

    long long k = 0;

    long long j = 0;


    vector< pair< long long, long long > > a;


    cin >> n >> m;


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

         cin >> x;

         a.push_back( pair< long long, long long >( x, 1 ) );

         }


    for( i = 0 ; i < m ; i = i + 1 ){

         cin >> b >> c;

         a.push_back( pair< long long, long long >( c, b ) );

         }


    sort( a.rbegin(), a.rend() );


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

         if( a[i].second > 0 ){

             k += a[i].first;

             a[i].second -= 1;

             j += 1;

             }

         if( a[i].second == 0 ) i += 1;

         }


    cout << k << endl;


    return 0;

    }


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int K;
    cin >> K;
    int ans = 0;
    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= K; j++) {
            for(int k = 1; k <= K; k++) {
                ans+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
 vector<long int> L;
 int N;
 long int total=0;
 cin >> N;
 for(int i=0;i<N;i++){
     long int A;
     cin >> A;
     total+=A;
     L.push_back(A);
 }
 vector<long int> ans;

 long int tmp=0;
 for(int i=2;i<=N-1;i+=2){
     tmp+=2*L[i-1];
 }
 ans.push_back(total-tmp);
 for(int i=0;i<N-1;i++){
     ans.push_back(2*L[i]-ans[i]);
     cout << ans[i] << " ";
 }
 cout << ans[N-1] << endl;
 return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
LL n,m,i;
vector<pair<LL,LL>>v1,v2;
scanf("%lld %lld",&n,&m);
for(i=0;i<n;++i){
    LL x,y;
    scanf("%lld %lld",&x,&y);
    v1.emplace_back(x,y);
}
for(i=0;i<m;++i){
    LL x,y;
    scanf("%lld %lld",&x,&y);
    v2.emplace_back(x,y);
}
for(i=0;i<n;++i){
    LL x,y,mini=OO;
    x=v1[i].first,y=v1[i].second;
    for(int j=0;j<m;++j){
        LL x1,y1,sum;
        x1=v2[j].first,y1=v2[j].second;
        sum=abs(x-x1)+abs(y-y1);
        mini=min(mini,sum);
    }
    for(int j=0;j<m;++j){
        LL x1,y1,sum;
        x1=v2[j].first,y1=v2[j].second;
        sum=abs(x-x1)+abs(y-y1);
        if(mini==sum){
            printf("%d\n",j+1);
            break;
        }
    }
}




    return 0;
}


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

using namespace std;

bool ascending(vector<int> &v) {
    for (int i = 1; i <= v.size(); i++) {
        if (v[i - 1] != i) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    if (ascending(arr)) {
        cout << "YES\n";
        return 0;
    }
    else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                swap(arr[i], arr[j]);
                if (ascending(arr)) {
                    cout << "YES\n";
                    return 0;
                }
                swap(arr[i], arr[j]);
            }
        }
    }
    cout << "NO\n";
}


Measured memory_bytes: 256
# 正整数 A,B が与えられます。
# A も B も割り切る正整数のうち、K 番目に大きいものを求めてください。
# なお、与えられる入力では、
# A も B も割り切る正整数のうち K 番目に大きいものが存在することが保証されます。

input = gets.chomp.split
a = input[0].to_i
b = input[1].to_i
k = input[2].to_i

max = a > b ? a : b

numbers = []
(1..max).each do |num|
    if a % num == 0 && b % num == 0
        numbers << num
    end
end

puts numbers[(numbers.length - 1) - (k - 1)]

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

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

		while (true) {
			int n = sc.nextInt();
			int r = sc.nextInt();

			if (n == 0 && r == 0) {
				break;
			}

			int[] cards = new int[n];

			for (int i = 0; i < cards.length; i++) {
				cards[i] = cards.length - i;
			}

			for (int i = 0; i < r; i++) {
				int p = sc.nextInt();
				int c = sc.nextInt();

				int[] change1 = new int[p - 1];
				int[] change2 = new int[c];

				for (int j = 0; j < change1.length; j++) {
					change1[j] = cards[j];
				}

				for (int j = 0; j < change2.length; j++) {
					change2[j] = cards[change1.length + j];
				}

				for (int j = 0; j < change2.length; j++) {
					cards[j] = change2[j];
				}

				for (int j = 0; j < change1.length; j++) {
					cards[change2.length + j] = change1[j];
				}
			}
			System.out.printf("%d\n", cards[0]);

		}
		sc.close();
	}
}

Measured memory_bytes: 30652
a=[int(i) for i in input().split()]
s = [input().split() for i in range(a[1])]
al=[[] for i in range(a[0])]
for i in range(a[1]):
    al[int(s[i][0])-1].append(s[i][1])
ac=0
wa=0
for j in range(a[0]):
    if al[j].count('AC')!=0:
        wa+=al[j].index('AC')
        ac+=1
print(ac,wa)

Measured memory_bytes: 44008
#include <stdio.h>

int main(void)
{
	int x=0, h=0, m=0, s=0;
	
	scanf("%d", &x);
	
	h = x/3600;
	
	m = (x - h*3600) /60;
	
	s = (x - h*3600) - m*60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}


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

int main() {
    long N, K, Q;
    cin>>N>>K>>Q;
    int A[N];
    for(int i=0;i<N;++i){
        A[i] = -(Q-K);
    }
    int tmp;
    for(int i=0;i<Q;++i){
        cin>>tmp;
        tmp--;
        A[tmp]++;
    }
    for(int i=0;i<N;++i){
        if(A[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define INF 1000000

void enq(int);
int deq(void);
void bfs(int);

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

void bfs(int s){
  int i,u,v;
  enq(s);
  for(i=0;i<n;i++){
    d[i]=INF;
  }
  d[s]=0;
  while(tail!=head){
    u=deq();
    for(v=0;v<n;v++){
      if(M[u][v]==0){
	continue;
      }
      if(d[v]!=INF){
	continue;
      }
      d[v]=d[u]+1;
      enq(v);
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i+1);
    if(d[i]==INF){
      printf("-1\n");
    }
    else{
      printf("%d\n",d[i]);
    }
  }
}

void enq(int num){
  int next;
  next=(tail+1)%INF;
  if(next==head){
    printf("enq error!!\n");
    exit(1);
  }
  que[tail]=num;
  tail=next;
}

int deq(){
  int val;
  if(tail==head){
    printf("deq error!!\n");
    exit(2);
  }
  val=que[head];
  head=(head+1)%INF;
  return val;
}
/*
void bfs(){
  if((M[][]==0)&&(color[]==W))
}
 */



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

int main()
{
    int N;
    cin >> N;
    int A[2][N+3];
    int sm = 0;
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < N; ++j) {
            cin >> A[i][j];
        }
    }

    for(int i = 0; i < N; ++i) sm += A[1][i];
    sm += A[0][0];
    int ans = sm;
    for(int i = 1; i < N; ++i) {
        int tmp = sm + A[0][i] - A[1][i-1];
        ans = max(ans, tmp);
        sm = tmp;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}


int main(){
  int H, A;
  cin >> H >> A;
  int ans =0;
  while(H > 0){
    H -= A;
    ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll h,w;cin>>h>>w;
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h)rep(j,w) cin>>s[i][j];

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

    bool cant=false;
    rep(i,h){
        rep(j,w){
            bool allwhite=true;
            if(s[i][j]!='#') continue;
            rep(k,4){
                ll ny=i+dy[k],nx=j+dx[k];
                if(!(0<=ny && ny<h && 0<=nx && nx<w)) continue;
                if(s[ny][nx]!='#') continue;
                
                allwhite=false;
            }

            if(allwhite) cant=true;
        }
    }

    if(cant) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3612