akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    string s;
    cin >> s;
    ll sum =0;
    for (ll i = 0;i <s.size();i++) {
        sum += s[i] - '0';
    }
    if (sum %9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3484
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
 
public class Main {
	public static final int TARO=0;
	public static final int HANAKO=1;
	public void exec() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        char[] strCA = br.readLine().toCharArray();
        int q = Integer.parseInt(br.readLine());
        for(int i=0; i<q; i++) {
        	String[] cmd = br.readLine().split(" ");
        	int arg1 = Integer.parseInt(cmd[1]);
        	int arg2 = Integer.parseInt(cmd[2]);
        	if("print".equals(cmd[0])) {
        		out.println(new String(strCA,arg1,arg2-arg1+1));
        	} else if("reverse".equals(cmd[0])) {
        		char[] arg3 = Arrays.copyOfRange(strCA,arg1,arg2+1);
        		for(int j=0; j<=arg2-arg1; j++) {
        			strCA[arg2-j] = arg3[j];
        		}
        	} else if("replace".equals(cmd[0])) {
        		char[] arg3 = cmd[3].toCharArray();
        		for(int j=0; j<=arg2-arg1; j++) {
        			strCA[arg1+j] = arg3[j];
        		}
        	}
        }
        out.flush();
    }
  
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}

Measured memory_bytes: 24524
#include<stdio.h>

int main(){
  int n;
  int count = 0;
  scanf("%d\n", &n);

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

  for(int i=0; i<n; i++){
    int minj = i;
    for(int k=i; k<n; k++){
      if(nums[minj]>nums[k]){
        minj = k;
      }
    }
    if(nums[i] > nums[minj]){
      int tmp = nums[minj];
      nums[minj] = nums[i];
      nums[i] = tmp;
      count += 1;
    }
  }

  for(int i=0; i < n-1; i++){
    printf("%d ", nums[i]);
  }
  printf("%d", nums[n-1]);
  printf("\n");
  printf("%d\n", count);
}



Measured memory_bytes: 2144
#include <iostream>
    #include <algorithm>
    using namespace std;
     
    int main(){
        long N;
        cin >> N;
        int A[N], B[N], C[N];
        for(int i = 0; i < N; i++){
            cin >> A[i];
        }
        for(int i = 0; i < N; i++){
            cin >> B[i];
        }
        for(int i = 0; i < N; i++){
            cin >> C[i];
        }
        sort(A, A + N, greater<int>());
        sort(B, B + N, greater<int>());
        sort(C, C + N, greater<int>());
        long B_can_use_C[N];
        long can_use = 0;
        for(int i = 0; i < N; i++){
            while(B[i] < C[can_use] && can_use != N){
                can_use++;
            }
            B_can_use_C[i] = can_use;
        }
        long ans = 0;
        can_use = 0;
        long can_use_pattern = 0;
        for(int i = 0; i < N; i++){
            while(A[i] < B[can_use] && can_use != N){
                can_use_pattern += B_can_use_C[can_use];
                can_use++;
            }
            ans += can_use_pattern;
        }
        cout << ans << endl;
    }

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
// typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 998244353;
const lli e3 = 1 << 12;
const lli INF = 1ll << 63;

lli n;
lli a[e5],b[e5];
vll ab[e5];
lli cnt[e5];
lli ans[e5];

lli vaccumulate(){
  lli ret = 0;
  for(lli i = 0;i < n;i++){
    // cerr << ab[i][0] << endl;
    ret += ab[i][0];
  }
  return ret;
}

int main(){
  cin >> n;
  for(lli i = 0;i < n;i++) cin >> a[i] >> b[i];
  for(lli i = 0;i < 2*n;i+=2){
    ab[i] = vll({a[i/2],i/2});
    ab[i+1] = vll({b[i/2],i/2});
  }
  // for(lli i = 0;i < 2*n;i++) cerr << ab[i][0] << endl;

  sort(ab,ab+(2*n));
  // for(lli i = 0;i < 2*n;i++) cerr << ab[i][0] << endl;
  for(lli i = 0;i < n;i++){
    cnt[ab[i][1]]++;
  }
  lli baka = vaccumulate();
  for(lli i = 0;i < n;i++){
    if(cnt[i] == 2){
      cout << min({accumulate(a,a+n,0ll),accumulate(b,b+n,0ll),baka}) << endl;
      return 0;
    }
  }
  for(lli i = 0;i < n;i++){
    if(ab[i][1] != ab[n][1])
      ans[i] = baka-ab[i][0]+ab[n][0];
    else
      ans[i] = baka-ab[i][0]+ab[n+1][0];
  }
  cout << min({accumulate(a,a+n,0ll),accumulate(b,b+n,0ll),*min_element(ans,ans+n)}) << endl;


}


Measured memory_bytes: 38016
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static int testN=3;
	static long mod = 1000000007;
	//static long mod =998244353; 
	static System.IO.StringReader sr;
	static void Main(string[] args) {
		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res = "";
		long res = 0 ;

		
		long[] vals = parseAryL(Console.ReadLine().Split(cs));

		long n = vals[0];
		long a = vals[1];
		long b = vals[2];

		long div = n / ( a + b );
		long mod = n % ( a + b );

		res = div * a;
		if ( mod >= a ) {
			res += a;
		} else {

			res += mod;
		}


		Console.WriteLine(res);

		return;

	}



	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}



}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    for(int i = 0; i < 3; i++){
        int num = N % 10;
        if (num == 7){
            cout << "Yes";
            return 0;
        }
        N /= 10;
    }
    cout << "No";
}


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

#define ll long long
#define mod 1000000007


int main()
{
    int n;
    cin>>n;
    string s,ss="",sss="";
    cin>>s;

    for(int i=0;i<n;i++)
    {
        if(i<n/2)ss+=s[i];
        else sss+=s[i];
    }

    if(ss==sss)
    {
        cout<<"Yes\n";
    }
    else cout<<"No\n";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
#define ll long long
using namespace std;

int main()
{
    int k, a,b;
    cin >> k >> a >> b;
    int result =0 ;
    for(int i=1; i<=b; i++){
        if(i*k>=a && i*k<=b){
            result =1 ;
            break;
        }
    }
    if(result==1){
        cout << "OK";
    }
    else{
        cout << "NG";
    }
    return 0;
}


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

int main(void)
{
    long long a,b;
    cin>>a>>b;

    if((a*a - b*b)% (2*a - 2*b) == 0)
    {
        ll k = (a*a - b*b)/(2*a - 2*b);
        cout<<k<<endl;
    }
    else
    {
        cout<<"IMPOSSIBLE"<<endl;
    }



}


Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
long long n;
deque<int> q;
int k,a[210];
int main()
{
	scanf("%lld",&n);
	while (n)
	{
		//cout<<n<<endl;
		if (n&1)
		{
			k++;
			a[k]=1;
			n=(n-1)>>1;
		}
		else
		{
			k++;
			a[k]=0;
			n--;
		}
	}
	for (int i=k;i;i--)
	{
		if (a[i])
		{
			q.push_back(k-i+1);
		} 
		else
		{
			q.push_front(k-i+1);
		}
	}
	printf("%d\n",k*2);
	while (!q.empty())
	{
		int x=q.front();
		q.pop_front();
		printf("%d ",x);
	}
	for (int i=1;i<=k;i++)
	{
		printf("%d ",i);
	}
    return 0;
}
//西窗外,钩月悬,云起落,慢拂面。

Measured memory_bytes: 256
#include <stdio.h>
 
int main () {
	int n;
	scanf("%d", &n);
	if (n%10 == 7 || (n/10) %10 == 7 || n/100 == 7) {
		puts("Yes\n");
		
	}
	else {
		puts("No\n");
		
	}
	return 0;
}

Measured memory_bytes: 1644
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


void solve() {
	int N; cin >> N;
	string S; cin >> S;
	REP(i, S.size()) {
		int num = S[i] - 'A';
		num += N;
		num %= 26;
		S[i] = 'A' + num;
	}
	print(S);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//test();
	solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200000+10;
int n,m,to[MAXN],nex[MAXN],beg[MAXN],e;
inline void read(int &x)
{
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<3)+(data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
inline void insert(int x,int y)
{
	to[++e]=y;
	nex[e]=beg[x];
	beg[x]=e;
}
int main()
{
	read(n);read(m);
	for(register int i=1;i<=m;++i)
	{
		int u,v;
		read(u);read(v);
		insert(u,v);
	}
	for(register int i=beg[1];i;i=nex[i])
	{
		int u=to[i];
		for(register int j=beg[u];j;j=nex[j])
			if(to[j]==n)
			{
				printf("POSSIBLE\n");
				return 0;
			}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int key[500001];
int parent[500001];
int left[500001];
int right[500001];
int root;
int head;

void printpre(int i){
    if(i == -1) return;
    printf(" %d", key[i]);
    printpre(left[i]);
    printpre(right[i]);
}

void printin(int i){
    if(i == -1) return;
    printin(left[i]);
    printf(" %d", key[i]);
    printin(right[i]);
}

int find(int r, int v){
    if(r == -1)
        return -1;
    if(v < key[r])
        return find(left[r], v);
    else if(v == key[r])
        return r;
    else
        return find(right[r], v);
}

int next(int t){
    int r = right[t];
    while(1){
        if(left[r] == -1)
            return r;
        r = left[r];
    }
}

void insert(int z){
    int y = -1;
    int x = root;
    while(x != -1){
        y = x;
        if(z < key[x])
            x = left[x];
        else
            x = right[x];
    }

    if(y == -1) {
        root = head;
    } else if(z < key[y]) {
        left[y] = head;
    } else {
        right[y] = head;
    }
    key[head] = z;
    parent[head] = y;
    left[head] = -1;
    right[head] = -1;
    head++;
}

void delete(int i){
    int p = parent[i];
    if(left[i] == -1 && right[i] == -1){
        if(key[i] < key[p])
            left[p] = -1;
        else
            right[p] = -1;
    } else if(left[i] == -1){
        if(key[i] < key[p])
            left[p] = right[i];
        else
            right[p] = right[i];
        parent[right[i]] = p;
    } else if(right[i] == -1){
        if(key[i] < key[p])
            left[p] = left[i];
        else
            right[p] = left[i];
        parent[left[i]] = p;
    } else {
        int n = next(i);
        key[i] = key[n];
        delete(n);
    }
}

int main(void){
    int n;
    scanf("%d", &n);
    root = -1;
    while(n--){
        char cmd[8];
        scanf("%s", cmd);
        if(cmd[0] == 'i'){
            int z;
            scanf("%d", &z);
            insert(z);
        } else if(cmd[0] == 'f') {
            int z;
            scanf("%d", &z);
            printf("%s\n", find(root, z) == -1 ? "no" : "yes");
        } else if(cmd[0] == 'd'){
            int z;
            scanf("%d", &z);
            delete(find(root, z));
        } else {
            printin(root);
            puts("");
            printpre(root);
            puts("");
        }
    }
}



Measured memory_bytes: 8060
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N, K;
    in(N); in(K);
    int d;
    vector<bool> has(N, false);
    rep(i, K) {
        in(d);
        rep(i, d) {
            int tmp;
            in(tmp);
            has[tmp-1] = true;
        }
    }

    int cnt = 0;
    rep(i, N) {
        if (!has[i]) cnt++;
    }
    out(cnt);

	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>

int main(){
	int n,a,b,c;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		if(a[0]==3 && a[1]==4 && a[2]==5)puts("YES");else
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define Impossible return printf("Impossible\n"),0;
#define Possible return printf("Possible\n"),0;

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 105;

int n;
int a[N];
int cnt[N],now[N];

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	sort(a+1,a+1+n);
	if (a[n]!=a[n-1])Impossible;
	fo(i,1,n)cnt[a[i]]++;
	int l=a[n];
	if (l%2==0){
		fd(i,l,l/2+1){
			if (cnt[i]<2)Impossible;
			cnt[i]-=2,now[i]+=2;
		}
		if (!cnt[l/2])Impossible;
		cnt[l/2]--,now[l/2]++;
	}
	else{
		fd(i,l,l/2+1){
			if (cnt[i]<2)Impossible;
			cnt[i]-=2,now[i]+=2;
		}
	}
	fo(i,1,n)
	if (cnt[i]){
		if (now[i-1]){now[i]+=cnt[i];cnt[i]=0;}
		else Impossible;
	}
	Possible;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int LIMIT = 1e4;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int ct = 0,t = 0,time =0;
	while(true){
		int minute = time % 60;
		if(minute <= c && c <= a + minute){
			time += c - minute;
			break;
		}else{
			time += a+b;
		}
		if(time > LIMIT){
			time = -1;
			break;
		}
	}
	cout << time << endl;
  return 0;
}

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

int main()
{
    map<string, int> memo;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        memo[s]++;
    }

    int maxv = 0;
    
    for(auto x: memo){
        maxv = max(maxv, x.second);
    }
    for(auto x: memo){
        if(x.second == maxv) cout << x.first << endl;
    }
}

Measured memory_bytes: 26112
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0; i<3; i++){
		if(s[i]=='1'){
			s[i]='9';
		}
		else{
			s[i]='1';
		}
	}
	cout<<s<<endl;
}


Measured memory_bytes: 384
N , M = map(int,input().split())
drink = [0] * N

for i in range(N) :
    a , b = map(int,input().split())
    drink[i] = [a,b] # 価格 , 本数

drink.sort(key=(lambda A : A[0])) # 安いもの順

now = 0
ans = 0

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


print(ans)

Measured memory_bytes: 21208
def edit_distance(a,b):
    n = len(a)
    m = len(b)
    L = [i for i in range(m+1)] #0행  (i행j열 요소:)
    for i in range(1,n+1):
        copy = L[:]     ##(i-1)행
        L[0] = i   ## i행 0열 (초기값) 값 설정
        for j in range(1,m+1):
            if (a[i-1] == b[j-1]):
                cost = 0
            else:
                cost = 1
            L[j] = min(copy[j] + 1,L[j-1] + 1,copy[j-1] + cost)
            ##점화식의 정확한 이해를 위해서 윗줄 식 공책에 써보기
    return L[-1]
    
    
    
a = input()
b = input()
print(edit_distance(a,b))


Measured memory_bytes: 5588
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int main(){

  while(1){

  int n;

  int ans = 1;

  int s[7] = {0,1,2,3,4,5,6};

  scanf("%d",&n);

  if(n == 0) break;

  for(int i = 0;i < n;i++){
    char sai[10];
    cin >> sai;
    int t1=s[1],t2=s[2],t3=s[3],t4=s[4],t5=s[5],t6=s[6];
    if(!strcmp(sai, "North")){
      s[1]=t2;
      s[2]=t6;
      s[5]=t1;
      s[6]=t5;
    }else if(!strcmp(sai, "East")){
      s[1]=t4;
      s[3]=t1;
      s[4]=t6;
      s[6]=t3;
    }else if(!strcmp(sai, "West")){
      s[1]=t3;
      s[3]=t6;
      s[4]=t1;
      s[6]=t4;
    }else if(!strcmp(sai, "South")){
      s[1]=t5;
      s[2]=t1;
      s[5]=t6;
      s[6]=t2;
    }else if(!strcmp(sai, "Right")){
      s[2]=t3;
      s[3]=t5;
      s[4]=t2;
      s[5]=t4;
    }else{
      s[2]=t4;
      s[3]=t2;
      s[4]=t5;
      s[5]=t3;
    }
    ans += s[1];
  }

  cout << ans << endl;

  }

  return 0;


}


Measured memory_bytes: 1224
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        if(a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)){
            System.out.print("YES"); 
        }else{
            System.out.print("NO");
        } 
    }
}



Measured memory_bytes: 24020
n, m = map(int, input().split())
H = list(map(int, input().split()))
good_towers = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    a_height = H[a-1]
    b_height = H[b-1]
    if a_height > b_height:
        good_towers[b-1] = False
    elif a_height < b_height:
        good_towers[a-1] = False
    else:
        good_towers[a-1] = False
        good_towers[b-1] = False
print(good_towers.count(True))


Measured memory_bytes: 86308
#include <stdio.h>
int time[101][2]={},g[101][101]={},n,cnt=1;
int flag[101]={};
void dfs(int);
int main(){
    int i,j,q,p,tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&q,&p);
        for(j=0;j<p;j++){
            scanf("%d",&tmp);
            g[q][tmp]=1;
        }
    }
    for(i=1;i<=n;i++){
        if(time[i][0]==0){
            dfs(i);
        }
    }
    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,time[i][0],time[i][1]);
    }
    return 0;
}
void dfs(int x){
    int i;
    if(time[x][0]==0){
        time[x][0]=cnt;
        cnt++;
    }
    for(i=1;i<=n;i++){
        if(g[x][i]!=0 && flag[i]==0){
            flag[x]=1;
            dfs(i);
        }
    }
    if(time[x][1]==0){
        time[x][1]=cnt;
        cnt++;
    }
}


Measured memory_bytes: 2112
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
As = [0]*(N+1)
for i in range(N):
    As[i+1] = As[i] + A[i]
A.reverse()

import bisect

def flag(x):
    ans = 0
    for i in range(N):
        a = x - A[i]
        res = bisect.bisect_left(A, a)
        ans += (N-res)
    return bool(ans >= M)

def an(x):
    ans = 0
    m = 0
    for i in range(N):
        a = x - A[i]
        res = bisect.bisect_left(A, a)
        m += (N-res)
        ans += As[N-res]
        ans += A[i] * (N-res)
    ans -= (m - M) * x
    return ans


low = 0
high = 10**6

while low <= high:
    mid = (low + high) // 2
    if flag(mid):
        if not flag(mid+1):
            ans = mid
            break
        else:
            low = mid + 1
    else:
        high = mid - 1

print(an(ans))

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

const int MAX = 510000;
const int MOD = 1000000007;


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

    vector<ll> V(N), MV, PV; 
    for(int i = 0; i < N; i++) {
        cin >> V[i];
        V[i] -= (i+1);
        if(V[i] < 0) MV.push_back(V[i]);
        else PV.push_back(V[i]);
    }
    sort(PV.begin(), PV.end());
    sort(MV.rbegin(), MV.rend());
    ll pn=PV.size(), mn = MV.size(), zn = N-pn-mn;
    vector<ll> B;
    B.push_back(0);
    if(pn+zn < mn){
        ll num = mn-(N/2);
        B.push_back(MV[num-1]);
        B.push_back(MV[num]);
    }
    else if(mn+zn < pn){
        ll num = pn-(N/2);
        B.push_back(PV[num-1]);
        B.push_back(PV[num]);
    }
    ll ans = 1e18;
    for(auto b : B){
        ll temp=0;
        for(int i = 0; i < N; i++){
            temp += abs(V[i]-b);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;


}






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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "No";
    if ((abs(a - b) <= d && abs(c - b) <= d) || abs(a - c) <= d)
    {
        ans = "Yes";
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define mod 1000000007
typedef long long ll;

ll mpow(ll a, ll b) {
  ll ans = 1;
  while( b ) {
    if(b & 1) ans *= a, ans %= mod;
    a *= a, a %= mod, b >>= 1;
  }
  return ans;
}

ll rev(ll a) {
  return mpow(a, mod - 2);
}

int main(void) {
  ll i, j, k, n, a, b, ans;
  scanf("%lld%lld%lld", &n, &a, &b);
  ll fact[b + 1], rfact[b + 1];
  fact[0] = rfact[0] = 1;
  for(i = 1; i <= b; ++i) {
    fact[i] = fact[i - 1] * i, fact[i] %= mod;
    rfact[i] = rfact[i - 1] * (n - i + 1), rfact[i] %= mod;
  }
  ans = mpow(2, n) - 1 + 2 * mod;
  ans -= (rfact[a] * rev(fact[a])) % mod;
  ans -= (rfact[b] * rev(fact[b])) % mod;
  printf("%lld", ans % mod);
  return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085A
{
    class Program
    {
        static void Main(string[] args)
        
        {
            string s; 
            
             s = Console.ReadLine();

            char[] cs = s.ToCharArray();

            cs[3] = '8';

            Console.WriteLine(cs);

            Console.ReadKey();
        }


    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
vector<long long> mf;
long long modfact(long long n){
	if (n < mf.size()){
		return mf[n];
	} else {
		if (mf.empty()) mf.push_back(1);
		long long res = mf.back();
		for (int i = mf.size(); i <= n; i++){
			res = res * i % MOD;
			mf.push_back(res);
		}
		return res;
	}
}
int main(){
  cout << fixed << setprecision(1);
  int N;
  cin >> N;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x[i];
  }
  vector<int> p(N + 1, 0);
  vector<int> x2(N);
  p[0] = 0;
  x2[0] = 1;
  int curr = 0;
  for (int i = 1; i < N; i++){
    if (x[i] >= x2[i - 1] + 2){
      x2[i] = x2[i - 1] + 2;
      p[i] = curr;
    } else {
      x2[i] = x2[i - 1];
      p[i] = curr;
      curr++;
    }
  }
  /*
  for (int i = 0; i < N; i++){
    cout << x2[i] << ' ';
  }
  cout << endl;
  for (int i = 0; i < N; i++){
    cout << p[i] << ' ';
  }
  cout << endl;
  */
  vector<int> count(N, 0);
  for (int i = 0; i < N; i++){
    count[p[i]]++;
  }
  for (int i = 1; i < N; i++){
    count[i] = count[i] + count[i - 1] - 1;
  }
  long long ans = 1;
  for (int i = 0; i < N; i++){
    ans = ans * count[i] % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
vector <char> v;
vector<int>ans;
string s;

int main(){
  int N;
  int d_n = 5*20+19*5, d_ur = 200;

  cin >>N;

  for (int i = 0;i<N;i++){
    int y,m,d;
    int Num = 0;

    cin >>y>>m>>d;
    if(y%3 == 0){
      Num += d_ur-20*(m-1)-d+1;
    }else{
      Num += d_n-d-39*((m-1)/2)-20*((m-1)%2)+1;
    }

    for(int j = y+1;j<=999;j++){
      if(j%3 == 0){
        Num += d_ur;
      }else{
        Num += d_n;
      }
    }
    ans.push_back(Num);
  }

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

  return 0;
}



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

using namespace std;
#define int long long
const int mod = 1e9 + 7;

int mul(int a, int b) {
  return ((a) % mod * (b) % mod) % mod;
}

int power(int n, int p) {
  int res = 1;
  while(p) {
    if(p & 1) res = mul(res, n);
    p >>= 1; n = mul(n, n);
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  const int N = 1.01e6;
  vector<int> fact(N), inv(N);
  fact[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < N; ++i) {
    fact[i] = mul(i, fact[i - 1]);
    inv[i] = power(fact[i], mod - 2);
  } 
  auto C = [&](int n, int r) {
    if(n < 0 || r > n || r < 0) return 0LL;
    return mul(mul(fact[n], inv[r]), inv[n - r]);
  };
  int x, y;
  cin >> x >> y;
  if((x + y) % 3 != 0) cout << 0 << '\n';
  else {
    int p = (x + y) / 3;
    cout << C(p, (2 * x - y) / 3) << '\n';
  }
  return 0;
}


Measured memory_bytes: 16000
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

	int K;
	cin >> K;

	//先頭から1文字ずつaに近づける。
	int idx = 0;
	while (idx < s.size() && K > 0)
	{
		if (s[idx] != 'a')
		{
			int d = 'z' - s[idx] + 1;

			//zから1周してaにできる文字のみ行う。
			if (K >= d)
			{
				s[idx] = 'a';
				K -= d;
			}
		}
		
		idx++;
	}

	//Kが余っている場合は最後の文字に押し付け
	K %= 26;

	while (K > 0)
	{
		int d = 'z' - s[s.size() - 1] + 1;

		//zから1周してaにできる文字のみ行う。
		if (K >= d)
		{
			s[s.size() - 1] = 'a';
			K -= d;
		}
		else
		{
			s[s.size() - 1] += K;
			K = 0;
		}

		idx++;
	}


	cout << s << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll x = lin();
    int ans = 0;
    REP(i,33){
        if (x >= (1LL << i) - 1) ans = i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n,a,b;
cin >> n>>a>>b;
ll t[n] = {};
rep(i, n){
    cin >> t[i];
}
rep(i,n-1){
    if((t[i+1]-t[i])*a>b)ans+=b;
    else ans+=(t[i+1]-t[i])*a;
}


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


Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int vis[MAXN];
int used[MAXN];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        memset(vis,0,sizeof(vis));
        memset(used,0,sizeof(used));
        int acnum=0,wanum=0;
        int num=0;
        for(int i=1;i<=m;i++)
        {
            int p;
            string s;
            cin>>p>>s;
            if(s=="AC"&&vis[p]==0)
            {
                vis[p]=1;
                acnum++;
                wanum+=used[p];
            }
            if(s=="WA"&&vis[p]==0)
            {
                used[p]++;
            }
        }
        cout<<acnum<<" "<<wanum<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    string s; cin>>s;
    ll N = s.size();
    map<char, ll> mp;
    for(char c:s){
        ++mp[c];
    }
    
    ll num = 0;
    for(char c='a';c<='z';++c){
        num += mp[c]*(mp[c]-1)/2;
    }
    
    ll ans = N*(N-1)/2 -num + 1;
    cout << ans << "\n";
    
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (){
    int h[1000000];
    cin >> h[0];
    int i = 0;
    bool a = false;
    while (true){
        if (h[i] % 2 == 0) h[i+1] = h[i]/2;
        else h[i+1] = h[i]*3+1;
        i++;
        for (int j = 0; j < i; j++){
            if (h[j] == h[i]) a = true;
        }
        if (a == true) break;
    }
    cout << i+1 << endl;
    return 0;
    
    }
    


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>


int myStrcmp(const char *s1, const char *s2)
{
    char ss1[11] = {0};
    char ss2[11] = {0};
    
    for ( int i = 0; s1[i] != '\0'; i++ ) {
        ss1[i] = tolower(s1[i]);
    }
    
    for ( int i = 0; s2[i] != '\0'; i++ ) {
        ss2[i] = tolower(s2[i]);
    }
    
    return strcmp(ss1, ss2);
}

int main(void)
{
    char w[11] = {0};
    int cnt = 0;

    fgets(w, sizeof(w), stdin);
    if ( w[strlen(w) - 1] == '\n' ) {
        w[strlen(w) - 1] = '\0';
    }

    while ( 1 ) {
        char line[1001] = {0};
        fgets(line, sizeof(line), stdin);
        if ( line[strlen(line) - 1] == '\n' ) {
            line[strlen(line) - 1] = '\0';
        }
        if ( strcmp(line, "END_OF_TEXT") == 0 ) {
            break;
        }
        char *tp;
        tp = strtok(line, " ");
        while ( 2 ) {
            if ( tp == NULL ) {
                break;
            } else if ( myStrcmp(tp, w) == 0 ) {
                cnt++;
            }
            tp = strtok(NULL, " ");
        }
    }

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


Measured memory_bytes: 2112
#include <iostream>
using namespace std;
using int64 = long long;
int main() {
  int64 n, k;
  cin >> n >> k;

  int64 m = n / k;
  int64 ret = m * m * m;
  if (k % 2 == 0) {
    m = (n + k / 2) / k;
    ret += m * m * m;
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
    


ll bs(ll n , vector<ll> &v){
    ll ok = -1;
    ll ng = v.size();
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng)/2;
        if(v[mid] <= n)ok = mid;
        else ng = mid;
    }
    return v[ok];
}

//ミョ(-ω- ?)
int main() {
    vector<ll> six;
    ll b = 1;
    while(b < 100000){
        b *= 6;
        six.emplace_back(b);
    }
    sort(all(six));
    vector<ll> nine;
    b = 1;
    while(b < 100000){
        b *= 9;
        nine.emplace_back(b);
    }
    sort(all(nine));
    ll n;cin >> n;
    static vector<vector<ll>> dp(100010,vector<ll>(3,INF));//dp[i][0] = 1を選ぶ,[1] = 6^n,[2] = 9^n
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    repp(i,1,n+1){
        dp[i][0] = min({dp[i-1][0],dp[i-1][1],dp[i-1][2]}) + 1;
        if(i >= 6){
            dp[i][1] = min({dp[i - bs(i,six)][0],dp[i - bs(i,six)][1],dp[i - bs(i,six)][2]})+1;
        }
        if(i >= 9){
            dp[i][2] = min({dp[i - bs(i,nine)][0],dp[i - bs(i,nine)][1],dp[i - bs(i,nine)][2]})+1;
        }
    }
    cout << min({dp[n][0],dp[n][1],dp[n][2]}) << "\n";
    return 0;
}

Measured memory_bytes: 8812
#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 < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


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


int main(){
  string s;
  cin >> s;
  bool flagF = false,flagC = false;
  rep(i,s.size()){
    if(s[i] == 'C')flagC = true;
    if(flagC && s[i] == 'F') flagF = true;
  }
  cout << (flagF?"Yes":"No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define R(i,n) for(int (i)=0;(i)<=(n);(i)++)
using namespace std;int a,H,W,A;main(){int c[10][10];cin>>H>>W;R(i,9)R(j,9)cin>>c[i][j];R(k,9)R(i,9)R(j,9)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);R(i,H-1)R(j,W-1){cin>>A;a+=c[A>=0?A:1][1];}cout<<a<<endl;}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::input;
use std::cmp::min;

const WIDTH: usize = 41;

fn main() {
    input!(n: usize, orig: [u64; n]);
    let make_seq = |x| (0..WIDTH).map(|i| (x >> i & 1) as usize).collect_vec();
    let a = make_seq(orig[0]);
    let b = make_seq(orig[1]);
    let c = make_seq({
        let mut x = 0;
        for y in orig.iter().skip(2) {
            x ^= y;
        }
        x
    });
    // eprintln!("{:?}", a);
    // eprintln!("{:?}", b);
    // eprintln!("{:?}", c);

    let mut dp = vec![vec![[std::u64::MAX; 2]; 2]; WIDTH + 1];
    dp[0][0][0] = 0;
    for i in 0..WIDTH {
        let x = a[i];
        let y = b[i];
        let z = c[i];
        // eprintln!("(i, x, y, z) = {:?}", (i, x, y, z));
        // eprintln!("dp[i] = {:?}", dp[i]);
        for ((j, k), l) in (0..2)
            .cartesian_product(0..2)
            .cartesian_product(0..2)
            .filter(|&((j, k), _)| x ^ y ^ z ^ j ^ k == 0)
        {
            if dp[i][j][k] != std::u64::MAX {
                let nj = (x < j + l) as usize;
                let nk = (2 <= y + l + k) as usize;
                dp[i + 1][nj][nk] = min(dp[i + 1][nj][nk], dp[i][j][k] + l as u64 * (1 << i));
            }
        }
    }
    let ans = *dp[WIDTH]
        .iter()
        .map(|v| v.iter().min().unwrap())
        .min()
        .unwrap();
    println!("{}", if orig[0] <= ans { -1 } else { ans as i64 });
}


Measured memory_bytes: 2172
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL N,A,B;
    R(N,A,B);
    if((B-A)%2==0)W((B-A)/2);
    else{
        W(min((A+B-1)/2,(2*N-A-B+1)/2));
    }
    return 0;
}


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

int main() {
	int n, k, x[1000],ans=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		if (x[i] * x[i] > (x[i] - k)*(x[i] - k)) {
			if (x[i] - k < 0)
				ans += -(x[i] - k);
			else
				ans += x[i] - k;
		}
		else
			if (x[i] < 0)
				ans += -(x[i]);
			else
				ans += x[i];
	}
	cout << ans*2 << endl;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))


result = 10**4


for i in range(1, N):
    sum1 = sum(W[:i])
    sum2 = sum(W[i:])
    
    if abs(sum1 - sum2) < result:
        result = abs(sum1 - sum2)
    else:
        break
    
print(result)

Measured memory_bytes: 38512
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final String s = scanner.next();

        final List<Integer> list = IntStream.range(0, n)
                .mapToObj(i -> s.charAt(i) - '0')
                .collect(Collectors.toList());

        final int[] bitArray = new int[n];
        for (int i = n - 2; i >= 0; i--) {
            bitArray[i] = bitArray[i + 1] | 1 << list.get(i + 1);
        }

        final boolean[] isAnswer = new boolean[1000];
        for (int i = 0; i < list.size(); i++) {
            final boolean[] isUsed = new boolean[10];
            for (int j = i + 1; j < list.size(); j++) {
                if (isUsed[list.get(j)]) {
                    continue;
                }
                isUsed[list.get(j)] = true;

                int bit = bitArray[j];
                for (int k = 0; k < 10; k++) {
                    if ((bit & 1) == 1) {
                        isAnswer[100 * list.get(i) + 10 * list.get(j) + k] = true;
                    }
                    bit >>= 1;
                }
            }
        }

        final long answer = IntStream.range(0, 1000)
                .mapToObj(i -> isAnswer[i])
                .filter(Boolean::booleanValue)
                .count();
        System.out.println(answer);
    }
}


Measured memory_bytes: 31176
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1;i<(int)(n);i++)
#define rep(j,m) for(int j=1;j<(int)(m);j++)
# define ALL(x) (x).begin(), (x).end()
using namespace std;
int main()
{int N;
 cin>>N;
  rep(i,10){rep(j,10){
	if(i*j==N){cout<<"Yes"<<endl;
              return 0;}
  }}
    
cout<<"No"<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
    cin.tie(0); cin.sync_with_stdio(false);
    string s;
    cin >> s;
    sort(all(s));
    cout << (s[0] == s[1] && s[1] != s[2] && s[2] == s[3] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,k;
int x[100001];
int ans=2e9;
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&x[i]);
	for (int i=1;i<=n-k+1;i++)
	{
		if (x[i+k-1]<=0) ans=min(ans,abs(x[i]));
		else if (x[i]>=0) ans=min(ans,x[i+k-1]);
		else
		{
			ans=min(ans,abs(x[i])*2+x[i+k-1]);
			ans=min(ans,abs(x[i])+x[i+k-1]*2);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}


int main(){
    char a,b;
    cin >> a >> b;
    if(a=='H'){
        if(b=='H'){
            cout << "H";
        }
        else{
            cout << "D";
        }
    }
    else{
        if(b=='H'){
            cout << "D";
        }
        else{
            cout << "H";
        }
    }
}

Measured memory_bytes: 256