akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int t = 1;
    int res = N;
    char pre = S[0];
    while(t < N) {
        int tcnt = 1;
        if(S[t] == pre) {
        while(S[t] == pre) {
            tcnt++;
            pre = S[t];
            t++;
            if(t == N) {
                res -= tcnt-1;
                cout << res << endl;
                return 0;
            }      
        }} else {
            pre = S[t];
             t++;
        }
        res -= tcnt-1; 
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;
ll n;

void solve() {
  for (ll i = sqrt(n) + 1;i>0;i--) {
    if (n % i == 0) {
      cout << (i + n / i - 2) << endl;
      return;
    }
  }
}

int main() {
  cin >> n;
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
string f[100];

int main() {
	int i;
	
	while (cin >> n) {
		if (!n) break;
		rep(i, n) cin >> f[i];
		
		int ans = 0;
		for (i = 0; i + 1 < n; i += 2) {
			if (f[i][0] != f[i + 1][0]) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i,k,sum=0;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  sort(a,a+n);

  for(i=0;i<k;i++)
  {
      sum=sum+a[i];
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int N;
  pair<pair<string, int>, int> p[110];

  cin >> N;
  rep(i, N){
    //一回一回nameとscoreを代入した後pairにぶち込む
    string name;
    int score;
    cin >> name >> score;
    p[i] = make_pair(make_pair(name, -score), i);
  }
  sort(p, p + N);//左から順に昇順ソート
  rep(i, N)cout << p[i].second + 1 << endl;//<入れ子になってる要素>から+1して脱出
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		Map<Character, int[]> memo = new HashMap<Character, int[]>();
		memo.put('N', new int[] { 1, 5, 2, 3, 0, 4 });
		memo.put('E', new int[] { 3, 1, 0, 5, 4, 2 });
		memo.put('W', new int[] { 2, 1, 5, 0, 4, 3 });
		memo.put('S', new int[] { 4, 0, 2, 3, 5, 1 });
		memo.put('R', new int[] { 0, 2, 4, 1, 3, 5 });
		memo.put('L', new int[] { 0, 3, 1, 4, 2, 5 });
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] dice = new int[6];
			for (int i = 0; i < 6; i++)
				dice[i] = i + 1;
			int ans = 1;
			for (int i = 0; i < n; i++) {
				char c = scanner.next().charAt(0);
				int[] tmp = new int[6];
				for (int j = 0; j < 6; j++) {
					tmp[j] = dice[memo.get(c)[j]];
				}
				dice = tmp;
				ans += dice[0];
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	string inp;
	
	while (getline(cin, inp), inp != ".")
	{
		stack<char> stk;
		
		rep(i, inp.length())
		{
			if (inp[i] == '(' || inp[i] == '[')
			{
				stk.push(inp[i]);
			} else if (inp[i] == ')') {
				if (stk.empty())
				{
					cout << "no" << endl;
					break;
				}
				char kakko = stk.top(); stk.pop();
				if (kakko != '(')
				{
					cout << "no" << endl;
					break;
				}
			} else if (inp[i] == ']') {
				if (stk.empty())
				{
					cout << "no" << endl;
					break;
				}
				char kakko = stk.top(); stk.pop();
				if (kakko != '[')
				{
					cout << "no" << endl;
					break;
				}
			}
			
			if (i == inp.length() - 1)
			{
				if (stk.empty())
				{
					cout << "yes" << endl;
					break;
				} else {
					cout << "no" << endl;
					break;
				}
			}
		}
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1176
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

int n,a[6005],dp[2005][2005],mx,f[2005],three;

int main(){

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

    cin>>n;
    for(int i=1;i<=n*3;i++){
        cin>>a[i];
    }
    memset(dp,0x80,sizeof(dp));
    memset(f,0x80,sizeof(f));
    dp[a[1]][a[2]]=mx=f[a[1]]=f[a[2]]=0;
    for(int i=3;i+2<=n*3;i+=3){
        if(a[i]==a[i+1]&&a[i]==a[i+2]){
            three++;
            continue;
        }
        vector<pair<pair<int,int>,int>> op;
        if(a[i]==a[i+1]||a[i+1]==a[i+2]||a[i]==a[i+2]){
            const int &p=a[i]==a[i+1]?a[i]:a[i+2],&q=a[i]+a[i+1]+a[i+2]-p*2;
            for(int k=1;k<=n;k++){
                op.emplace_back(make_pair(k,q),max(dp[p][k],dp[k][p])+1);
            }
        }
        const int &p=a[i],&q=a[i+1],&r=a[i+2];
        op.emplace_back(make_pair(q,r),max(mx,dp[p][p]+1));
        op.emplace_back(make_pair(p,r),max(mx,dp[q][q]+1));
        op.emplace_back(make_pair(p,q),max(mx,dp[r][r]+1));
        for(int k=1;k<=n;k++){
            op.emplace_back(make_pair(k,p),f[k]);
            op.emplace_back(make_pair(k,q),f[k]);
            op.emplace_back(make_pair(k,r),f[k]);
        }
        for(pair<pair<int,int>,int> &p:op){
            dp[p.first.first][p.first.second]=max(dp[p.first.first][p.first.second],p.second);
            mx=max(mx,p.second);
            f[p.first.first]=max(f[p.first.first],p.second);
            f[p.first.second]=max(f[p.first.second],p.second);
        }
    }
    int ans=dp[a[n*3]][a[n*3]]+1;
    for(int i=1;i<=n;i++){
        ans=max(ans,*max_element(dp[i]+1,dp[i]+1+n));
    }
    cout<<ans+three<<endl;

    return 0;
}

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

#define lint long long int
#define INF 99999999



int main()
{
    int n, a[200001];
    lint k;
    int n_tel[200001]; //目的地->回数
    
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        n_tel[i] = -1;
    }
    
    int dest[200001]; //回数->目的地
    int cur_town = 1, i = 0;
    lint r_beg, r_end;
    while(1) {
        dest[i] = cur_town;
        n_tel[cur_town] = i++;
        
        cur_town = a[cur_town];
        if (n_tel[cur_town] >= 0) {
            r_beg = n_tel[cur_town];
            r_end = i-1;
            
            if (r_beg <= k) {
                lint mod_k = ((k-r_beg) % (r_end-r_beg+1)) + r_beg;
                cout << dest[mod_k] << endl;
            } else {
                cout << dest[k] << endl;
            }
            return 0;
        }
    }
}





Measured memory_bytes: 5924
def num2alpha(num):
    if num<=26:
        return chr(64+num+32)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90+32)
    else:
        return num2alpha(num//26)+chr(64+num%26+32)
      
N=int(input())
ans=num2alpha(N)
print(ans)

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

using Graph=vector<vector<int>>;
enum Color{NONE,WHITE,BLACK};
int main(){
    int n,m;
    while(cin>>n>>m,n){
        Graph g(n);
        for(int i=0;i<m;i++){
            int u,v;
            cin>>u>>v;
            u--,v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        try{
            vector<int> flag(n);
            auto flip=[](Color c){
                if(c==WHITE) return BLACK;
                if(c==BLACK) return WHITE;
                assert(false);
            };
            function<void(int,Color)> dfs=[&](int v,Color c){
                if(flag[v]!=NONE){
                    if(flag[v]!=c) throw "non-bin";
                    return;
                }
                flag[v]=c;
                for(int i=0;i<g[v].size();i++){
                    dfs(g[v][i],flip(c));
                }
            };
            dfs(0,BLACK);
            int wcnt=0;
            int bcnt=0;
            for(int i=0;i<n;i++){
                if(flag[i]==WHITE){
                    wcnt++;
                }
                else if(flag[i]==BLACK){
                    bcnt++;
                }
                else{
                    assert(false);
                }
            }
            set<int> res;
            if(wcnt%2==0) res.insert(wcnt/2);
            if(bcnt%2==0 ) res.insert(bcnt/2);
            
            cout<<res.size()<<endl;
            for(auto &e:res) cout<<e<<endl;
        }catch(const char* er){
            cout<<0<<endl;
        }
        
    }

    return 0;
}


Measured memory_bytes: 3292
#include<stdio.h>
typedef long long ll;
int main()
{
    ll i,s,l;
    char str[200005]={'\0'};
    scanf("%s",&str);
    s=0;
    l=strlen(str);
    for(i=0;i<l;i++)
    {
    	s+=(str[i]-48);
    }
    if(s%9==0)
    {
    	printf("Yes\n");
    }
    else
    {
    	printf("No\n");
    }
	return 0;
}

Measured memory_bytes: 1844
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;

int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);
 
  ll x,n;
  cin>>x>>n;
  map<ll,ll>m;
  for(int i=0;i<n;i++){
    ll k;
    cin>>k;
    m[k]=1;     
  }
  ll dp[x+1];
  dp[0]=1;
  if(m[1]) dp[1]=0;
  else dp[1]=1;
  for(int i=2;i<=x;i++){  
    if(m[i]) dp[i]=0;
    else {
      dp[i]=dp[i-1]+dp[i-2];
      dp[i]=dp[i]%1000000007;;
    }
    
    //cout<<dp[i]<<' ';
  }
  cout<<dp[x];
  }

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define INF (int)1e9
int N;
char s[5050],t[5050];
vector<int> sa, ta;
int ans = 0;
int main(){
    scanf("%d%s%s", &N, s, t);

    if(N<3){
        ans = 0;
        for (int i = 0; i < N;i++){
            ans+=s[i] != t[i] ? 1 : 0;
        }
        printf("%d",ans);
        return 0;
    }


    char sss = s[0],ttt=t[0];
    if(s[0]!=t[0]){
        sa.push_back(0);
    }
    for (int i = 1; i < N;i++)
    {
        if(sss!=s[i]){
            sa.push_back(i);
            sss = s[i];
        }
        if(ttt!=t[i]){
            ta.push_back(i);
            ttt = t[i];
        }
    }
    /*
    for (int i = 0; i < sa.size();i++){
        printf("%d ", sa[i]);
    }
    printf("\n");
    for (int i = 0;i<ta.size();i++){
        printf("%d ", ta[i]);
    }
    printf("\n");
*/
    ans = INF;
    for (int i = 0; i < sa.size(); i += 2)
    {
        int ct = 0;
        for (int j = 0; j < i; j++)
        {
            ct += sa[j];
        }
        for (int j = i; j < sa.size() && j - i < ta.size(); j++)
        {
            ct +=abs(sa[j] - ta[j - i]);
        }
        for (int j = sa.size(); j - i < ta.size(); j++)
        {
            ct += N - ta[j - i];
        }
        for (int j = ta.size() + i; j < sa.size(); j++)
        {
            ct += N - sa[j];
        }
        //printf("%d,%d\n", i, ct);
        if(ct<ans){
            ans = ct;
        }
    }
    for (int i = 0; i < ta.size(); i += 2)
    {
        int ct = 0;
        for (int j = 0; j < i; j++)
        {
            ct += ta[j];
        }
        for (int j = i; j < ta.size() && j - i < sa.size(); j++)
        {
            ct +=abs(ta[j] - sa[j - i]);
        }
        for (int j = ta.size(); j - i < sa.size(); j++)
        {
            ct += N - sa[j - i];
        }
        for (int j = sa.size() + i; j < ta.size(); j++)
        {
            ct += N - ta[j];
        }
        if(ct<ans){
            ans = ct;
        }
        //printf("%d,%d\n", i, ct);
    }
    printf("%d", ans);
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Dice {
 public:
  void rotate(char c, int *n) {
    int m[6];
    rep(j, 6) m[j] = n[j];
    if (c == 'N') {
      m[0] = n[1];
      m[1] = n[5];
      m[4] = n[0];
      m[5] = n[4];
      rep(j, 6) n[j] = m[j];
    } else if (c == 'S') {
      m[0] = n[4];
      m[1] = n[0];
      m[4] = n[5];
      m[5] = n[1];
      rep(j, 6) n[j] = m[j];
    } else if (c == 'W') {
      m[0] = n[2];
      m[2] = n[5];
      m[3] = n[0];
      m[5] = n[3];
      rep(j, 6) n[j] = m[j];
    } else if (c == 'E') {
      m[0] = n[3];
      m[2] = n[0];
      m[3] = n[5];
      m[5] = n[2];
      rep(j, 6) n[j] = m[j];
    } else if (c == 'R') {
      m[1] = n[3];
      m[2] = n[1];
      m[3] = n[4];
      m[4] = n[2];
      rep(j, 6) n[j] = m[j];
    } else {
      m[1] = n[2];
      m[2] = n[4];
      m[3] = n[1];
      m[4] = n[3];
      rep(j, 6) n[j] = m[j];
    }
  }

  bool is_tf(int t, int f, int *n) {
    if (t == n[5]) {
      rep(i, 2) {
        rotate('N', n);
      }
    } else if (t != n[0]) {
      rep(i, 4) {
        rotate('R', n);
        if (t == n[1]) {
          break;
        }
        if (i == 3) {
          return false;
        }
      }
      rotate('N', n);
    }
    rep(i, 4) {
      rotate('R', n);
      if (f == n[1]) {
        break;
      }
      if (i == 3) {
        return false;
      }
    }
    return true;
  }

  bool isMatch(int t, int f, int *n, int *m) {
    if (is_tf(t, f, n)) {
      int cnt = 0;
      for (int i = 2; i < 6; ++i) {
        if (m[i] == n[i]) {
          ++cnt;
        }
      }
      if (cnt == 4) {
        return true;
      } else
        return false;
    } else
      return false;
  }
};

int main() {
  int num;
  cin >> num;
  int l[num][6];
  rep(i, num) rep(j, 6) cin >> l[i][j];

  int n[6], m[6];
  Dice d;
  rep(i, num - 1) {
    for (int j = i + 1; j < num; ++j) {
      rep(k, 6) {
        m[k] = l[i][k];
        n[k] = l[j][k];
      }
      rep(k, 5) {
        if (d.isMatch(m[k], m[k + 1], n, m)) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3108
//edpc-c
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    long long dp[n+1][3];
    //a=0,b=1,c=2
    dp[0][0]=0;dp[0][1]=0;dp[0][2]=0;
    for(int i=0;i<n;i++)
    {
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i];
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b[i];
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c[i];
    }
    long long res=0;
    for(int i=0;i<3;i++)
    res=max(dp[n][i],res);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int t;
vector<int> a;
for(int i=0;i<3;i++){
cin >> t;
a.push_back(t);
}
sort(a.begin(),a.end());
cout << a[0]<< " " << a[1] << " "<<a[2]<<endl;
return 0;
}

Measured memory_bytes: 3104
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    string s;
    cin >> s;
    if(s.sz < 4 || s.substr(0, 4) != "YAKI"){
        cout << "No" << endl;
        return 0;
    }
    else cout << "Yes" << endl;
}



Measured memory_bytes: 2996
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static int GCD(int x,int y)
    {
        if (x < y)
            return GCD(y, x);
        if (x % y == 0)
            return y;
        else
            return GCD(y, x % y);
    }
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int X = int.Parse(s[1]);
        int[] x = new int[N];
        Queue<int> q = new Queue<int>();
        s = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
            q .Enqueue(Math.Abs(int.Parse(s[i]) - X));
        while (q.Count > 1)
            q.Enqueue(GCD(q.Dequeue(), q.Dequeue()));
        Console.WriteLine(q.Dequeue());
    }
}

Measured memory_bytes: 19552
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    long int a, b, x;
    cin >> a >> b >> x;
    long int ans;
    if(a == 0){
        ans = (b / x) + 1;
    }else{
        ans = (b / x) - (a - 1) / x;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n, d int
	fmt.Scanf("%d %d", &n, &d)

	count := 0
	nums, _ := scanLongIntSlices(n, 1000)
	for i := 0; i < n; i++ {
		co := nums[i]
		x := co[0]
		y := co[1]
		if x*x+y*y <= d*d {
			count++
		}
	}
	fmt.Printf("%d\n", count)
}

func scanLongIntSlices(lines int, maxBufSize int) ([][]int, error) {

	res := [][]int{}

	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, maxBufSize)

	for sc.Scan() {
		line := sc.Text()
		strs := strings.Split(line, " ")
		ints := make([]int, len(strs))
		for i, c := range strs {
			n, err := strconv.Atoi(c)
			if err != nil {
				return nil, err
			}
			ints[i] = n
		}
		res = append(res, ints)
	}

	if err := sc.Err(); err != nil {
		return nil, err
	}

	return res, nil
}


Measured memory_bytes: 25520
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

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


Measured memory_bytes: 256
operator fun String.times(time: Int): String{
    return (0 until time).joinToString(""){this}
}
fun main(args:Array<String>):Unit {
    val (w, h, c) = readLine()!!.trim().split(' ').let{val (w, h, c) = it; Triple(w.toInt(), h.toInt(), c)}
    val str = Array(h){("." * w).toCharArray()}
    str[0][0] = '+'; str[0][w - 1] = '+'; str[h - 1][0] = '+'; str[h - 1][w - 1] = '+'
    for (i in 1 until w - 1) {
        str[0][i] = '-'; str[h - 1][i] = '-'
    }
    for (i in 1 until h - 1) {
        str[i][0] = '|'; str[i][w - 1] = '|'
    }
    str[h / 2][w / 2] = c.toCharArray()[0]
    println(
            str.joinToString("\n"){it.joinToString("")}
    )
}


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

int main() {
    int N;
    cin >> N;
    vector<int> card(N);
    for(int i = 0; i < N; i++) {
        cin >> card.at(i);
    }
    sort(card.begin(), card.end());
    reverse(card.begin(), card.end());

    int alice_p = 0, bob_p = 0;
    for(int i = 0; i < N; i += 2) {
        alice_p += card.at(i);
    }
    for(int i = 1; i < N; i += 2) {
        bob_p += card.at(i);
    } 

    cout << alice_p - bob_p << endl;
}


Measured memory_bytes: 256
import heapq

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

Q = []
heapq.heappush(Q, (-1*(A[0]+B[0]+C[0]), 0, 0, 0))
registered = set()
registered.add((0, 0, 0))
for t in range(K):
    s, ai, bi, ci = heapq.heappop(Q)
    print(-s)

    if ai+1 < X and (ai+1, bi, ci) not in registered:
        heapq.heappush(Q, (-1*(A[ai+1]+B[bi]+C[ci]), ai+1, bi, ci))
        registered.add((ai+1, bi, ci))
    if bi+1 < Y and (ai, bi+1, ci) not in registered:
        heapq.heappush(Q, (-1*(A[ai]+B[bi+1]+C[ci]), ai, bi+1, ci))
        registered.add((ai, bi+1, ci))
    if ci+1 < Z and (ai, bi, ci+1) not in registered:
        heapq.heappush(Q, (-1*(A[ai]+B[bi]+C[ci+1]), ai, bi, ci+1))
        registered.add((ai, bi, ci+1))


Measured memory_bytes: 57564
// Problem : C - Maximal Value
// Contest : AtCoder Beginner Contest 140
// URL : https://atcoder.jp/contests/abc140/tasks/abc140_c
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define f first
#define se second
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
cin>>n;
vi b(n-1);
cin>>b;
vi a(n);
a[0]=b[0];
for(int i=1;i<n-1;i++)
a[i]=min(b[i],b[i-1]);
a[n-1]=b[n-2];
int sum=0;
for(int i : a)
sum+=i;
cout<<sum;
}

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


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

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
bool scan(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (string s; scan(s);) {
		int joi = 0, ioi = 0, st = 0;
		auto start = [](char c) {return c == 'J' ? 1 : c == 'I' ? 3 : 0;};
		for (char c : s) {
			switch (st) {
				case 0:
					st = start(c);
					break;
				case 1:
					st = c == 'O' ? 2 : start(c);
					break;
				case 2:
					if (c == 'I')
						joi++;
					st = start(c);
					break;
				case 3:
					st = c == 'O' ? 4 : start(c);
					break;
				case 4:
					if (c == 'I')
						ioi++;
					st = start(c);
					break;
			}
		}
		out(joi, '\n', ioi, '\n');
	}
}


Measured memory_bytes: 2552
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (!(a % 3) || !(b % 3) || !((a + b) % 3))
		printf("Possible\n");
	else
		printf("Impossible\n");

	return 0;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a != b && b != c && c != a) {
        cout << 3 << endl;
    }
    else if (a == b && b == c && c == a) {
        cout << 1 << endl;
    }
    else {
        cout << 2 << endl;
    }
}



Measured memory_bytes: 3568
#include <iostream>
#include <string>

using namespace std;

struct logical
{
	virtual int eval(int p, int q, int r) = 0;
};

struct l_lit : public logical
{
	const int val;

	l_lit(int v) : val(v) { }
	int eval(int p, int q, int r) { return val; }
};

struct l_var : public logical
{
	const char name;

	l_var(char name) : name(name) { }
	int eval(int p, int q, int r)
	{
		return name == 'P' ? p : (name == 'Q' ? q : r);
	}
};

struct l_not : public logical
{
	logical *x;

	l_not(logical *x) : x(x) { }
	~l_not() { delete x; }
	int eval(int p, int q, int r)
	{
		return 2 - x->eval(p, q, r);
	}
};

struct l_or : public logical
{
	logical *x, *y;

	l_or(logical *x, logical *y) : x(x), y(y) { }
	~l_or() { delete x; delete y; }
	int eval(int p, int q, int r)
	{
		return max(x->eval(p, q, r), y->eval(p, q, r));
	}
};

struct l_and : public logical
{
	logical *x, *y;

	l_and(logical *x, logical *y) : x(x), y(y) { }
	~l_and() { delete x; delete y; }
	int eval(int p, int q, int r)
	{
		return min(x->eval(p, q, r), y->eval(p, q, r));
	}
};

static string s;
static int p;

bool end() { return p >= (int)s.length(); }
char peek() { return s[p]; }
void succ() { if (!end()) p++; }

logical *fomula()
{
	char c = peek();
	if ('0' <= c && c <= '2')
	{
		succ();
		return new l_lit(c - '0');
	}
	else if ('P' <= c && c <= 'R')
	{
		succ();
		return new l_var(c);
	}
	else if (c == '-')
	{
		succ();
		return new l_not(fomula());
	}
	else if (c == '(')
	{
		succ();
		logical *x = fomula();
		char op = peek(); succ();
		logical *y = fomula();
		succ(); // ')'
		if (op == '+') return new l_or(x, y);
		else return new l_and(x, y);
	}
	return NULL;
}

logical *parse_fomula()
{
	p = 0;
	return fomula();
}

int main()
{
	while(cin>>s, s != ".")
	{
		logical *e = parse_fomula();

		int c = 0;
		for (int p = 0; p <= 2; p++)
		{
			for (int q = 0; q <= 2; q++)
			{
				for (int r = 0; r <= 2; r++)
				{
					if (e->eval(p, q, r) == 2) c++;
				}
			}
		}
		cout << c << endl;

		delete e;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  vector<lint> P(N);
  REP(i, N) cin >> P[i];
  vector<lint> idx(N);
  REP(i, N) idx[P[i]-1] = i;
  multiset<lint> st;
  st.insert(-1);
  st.insert(-1);
  st.insert(N);
  st.insert(N);
  lint ans = 0;
  IREP(i, N) {
    st.insert(idx[i]);
    auto itr = st.find(idx[i]);
    lint l2 = *prev(itr, 2);
    lint l1 = *prev(itr, 1);
    lint r1 = *next(itr, 1);
    lint r2 = *next(itr, 2);
    //cout << l2 << " " << l1 << " " << idx[i] << " " << r1 << " " << r2 << endl;
    ans += ((l1-l2) * (r1-idx[i]) + (r2-r1) * (idx[i]-l1)) * (i+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      cout << "No" << endl;
      break;
    }
    if(i==s.size()-1 && s.at(i)==t.at(i)){
      cout << "Yes" << endl;
    }
  }
}

    

Measured memory_bytes: 3636
program main
  
  
  implicit none
  integer :: k,n
  integer, allocatable :: a(:), b(:)
  integer :: i, tmp, ans ,tmp1
  
  read(*,*) k,n
  allocate( a(n) )
  allocate( b(n) )
  read(*,*) b 

  call quicksort1( b, 1, n)

  a(1) = b(1) 
  do i = 2, n 
    a(i) = b(i) - b(i-1)
  end do

  tmp = k - b(n) + b(1)
  
  call quicksort1( a, 1, n)

  if ( a(n) > tmp ) then
    print*, k - a(n)
  else
    print*, k - tmp
  end if
  
end program main

recursive subroutine quicksort1(a, first, last)
  implicit none
  integer(4),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(4)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1


Measured memory_bytes: 2304
N=int(input())
A=list(map(int,input().split()))
A.sort()

I=A[N-1]

motometai=I/2

J=10**10

for i in range(N-1):
    if abs(I/2- A[i])<abs(I/2-J):
        J=A[i]
    

        


print(I,J)

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

int main() {
  string n;
  cin >> n;
  if (n[0]==n[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

int main(){
    ll N;
    cin >> N;
    if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
        cout << "hon" << endl;
    }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
} 


Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define rep(index,num) for(int index=0;index<num;index++)
#define eps 1e-15
typedef long long ll;
int main(){
	int n,count5=0,count7=0;
	rep(i,3){
		scanf("%d",&n);
		if(n==5) count5++;
		if(n==7) count7++;
	}
	if(count5==2&&count7==1) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

const int MAX = 100000;

int main(){

  int A[MAX],B[MAX];
  char Operators[MAX];

  int length = 0;
  for(int i=0;i<MAX;i++){
    scanf("%d",&A[i]);
    scanf(" %c",&Operators[i]);
    scanf("%d",&B[i]);
    if(Operators[i] == '?'){
      break;
    } else {
      length++;
    }
  }

  int ans;
  for(int i=0;i<length;i++){
    switch (Operators[i])
    {
      case '+': ans=A[i]+B[i]; break;
      case '-': ans=A[i]-B[i]; break;
      case '*': ans=A[i]*B[i]; break;
      case '/': ans=A[i]/B[i]; break;
      default: break;
    }
    printf("%d\n",ans);
  }
  return 0;
}


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

int main() { 
  int A,B;
  cin >> A >> B;
  
  int ans = -1;
  for(int i=1; i<1010; i++){
    if( 12.5*A <= i && i<12.5*(A+1) && 10*B<= i && i<10*(B+1) ){
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3644
n, k = map(int, input().split())
p    = list(map(int, input().split()))

L = 0
R = k

def expected(pi):
    return (pi+1)/2

value = 0.0
sans  = 0.0
for i in range(0, k):
    sans += expected(p[i])
ans   = sans

while R < n:
    sans -= expected(p[L])
    sans += expected(p[R])

    ans = max(ans, sans)

    L += 1
    R += 1
print("%.7f" % ans)


Measured memory_bytes: 25060
# -*- coading: utf-8 -#-

A = raw_input()
B = A.split()
C, D = int(B[0]), int(B[1])

if C == 1:
  if D == 1:
    print 'Draw'
  else:
    print 'Alice'
else:
  if D == 1:
    print 'Bob'
  else:
    if C > D:
      print 'Alice'
    elif C < D:
      print 'Bob'
    else:
      print 'Draw'

Measured memory_bytes: 2568
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
string a,b;
int main(){
    cin>>a>>b;
    reverse(a.begin(),a.end());
    if(a==b)cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i
ans = 0

(A + 1).times  do |a|
    (B + 1).times  do |b|
        (C + 1).times  do |c|
            if 500 * a + 100 * b + 50 * c == X
                ans += 1
            end
        end
    end
end

puts ans




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

using namespace std;

int main()
{
	int a[3];
	int b[3];
	int n=0;
	for (int i=0;i<3;i++)
	{
		cin>>a[i];
	}
	while (!(a[0]%2 || a[1]%2 || a[2]%2))
	{
		for (int i=0;i<3;i++)
		{
			b[i]=(a[0]+a[1]+a[2]-a[i])/2;
		}
		for (int i=0;i<3;i++)
		{
			a[i]=b[i];
		}
		n++;
		if (a[0]==a[1]&& a[1]==a[2])
		{
			n=-1;
			break;
		}
	}
	cout<<n<<endl;
	return 0;
}

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

int main(){
    int N; cin >> N;
    ll ans=0;
    for(int j=1; j<=N; j++){
        for(int i=1; i<=N; i++){
            if(i*j>N)break;
            ans += i*j;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
import sys
input=lambda :sys.stdin.readline().rstrip()

mod = 10**9+7

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

d = [0] * (k+1)
for i in range(1, k+1):
    d[i] = pow(k//i, n, mod)

for i in range(k, 0, -1):
    for j in range(2*i, k+1, i):
        d[i] -= d[j]
        d[i] %= mod
ans=0
for i in range(1, k+1):
    ans += d[i]*i
    ans %= mod

print(ans)

Measured memory_bytes: 11324
#include<iostream>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int d = 0 ;

	for (int i = a; i <= b;i++){
		if (c % i == 0) {
			d++;
		}
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int main(){
  int n;
  std::cin >> n;
  std::vector<int> c(9,0);
  rep(i,n){
    int a;
    std::cin >> a;
    if(a<=399)c[0]++;
    else if(a<=799)c[1]++;
    else if(a<=1199)c[2]++;
    else if(a<=1599)c[3]++;
    else if(a<=1999)c[4]++;
    else if(a<=2399)c[5]++;
    else if(a<=2799)c[6]++;
    else if(a<=3199)c[7]++;
    else c[8]++;
  }
  int counter=0,acounter=0;
  rep(i,8)if(c[i]!=0)counter++;
  acounter=counter;
  if(counter==0&&c[8]!=0)acounter++;
  std::cout << acounter  <<' '<< counter+c[8]<< std::endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,i,a[20],b[20],result;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
  
  result=0;
  for(i=0;i<n;i++){
    if(a[i]>b[i]){
      result+=(a[i]-b[i]);
    }
  }
  
  printf("%d",result);
}


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

typedef long long int in; 

in dp[3005][3005];

int main() 
{
    in n;
    cin>>n;
    
    in a[n],i,j,k=0;
    
    for(i=0;i<n;++i)
    {
        cin>>a[i];
        dp[i][i]=a[i];
    }
    
    for(i=0;i<n;++i)
    {
        ++k;
        for(j=0;j<n;++j)
        if(j+k<n)
        dp[j][j+k]=max(a[j]-dp[j+1][j+k],a[j+k]-dp[j][j+k-1]);
    }
    
    cout<<dp[0][n-1];
    
	return 0;
}


Measured memory_bytes: 70016
(defun split-string (str)                                                                     
  (let ((string-position (position #\Space str)))
    (cond
      ((null string-position) (list str))
      (t (cons (subseq str 0 string-position) (split-string (subseq str (1+ string-position)))))
      )))

(defun readline-to-list ()
  (let ((str (read-line *standard-input* nil)))
    (cond
      ((null str) nil)
      ((string= str "") nil)
      (t (cons str (readline-to-list))))))


(defun takahashi (a b)
  (let ((result (+ (parse-integer a) (if (>= (parse-integer b) (parse-integer a)) 0 -1))))
    (format t "~A~%" result)))

(apply #'takahashi (split-string (read-line)))


Measured memory_bytes: 4964
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,m,a[N];
ll s[N],f[N];
int findmax(int x,int k)
{
	int l=1,r=n;
	while (l+1<r)
	{
		int mid=l+r>>1;
		if (mid+k-1>n) r=mid;
		else if (x-a[mid]>a[mid+k-1]-x) l=mid;
		else r=mid;
	}
	int ans=l;
	for (int i=l+1;i<=r;i++)
	if (r+k-1<=n&&max(x-a[i],a[i+k-1]-x)<max(x-a[ans],a[ans+k-1]-x)) ans=i;
	return a[ans+k-1];
}//和x最接近的数中取k个后最大的 
bool check(int k,int x)
{
	if (k*2-1>n) return 0;
	//cout<<k<<' '<<x<<endl;
	//cout<<findmax(x,1)<<' '<<a[n-k+1]<<endl;
	return findmax(x,k-1)<a[n-k+1];
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	s[1]=a[1];
	for (int i=2;i<=n;i++) s[i]=s[i-2]+a[i];
	for (int i=n;i>=1;i--) f[i]=f[i+1]+a[i];
	for (int i=1;i<=m;i++)
	{
		int x=read();
		int l=1,r=n,t=0;
		while (l<=r)
		{
			int mid=l+r>>1;
			if (check(mid,x)) t=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<t<<endl;
		ll ans=f[n-t+1];int y=n-t*2;
		if (y>0) ans+=s[y];
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 3712
fun main(args: Array<String>) {
    val mod = 998244353L
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(' ').map(String::toInt)
    if (d[0] != 0 || d.count { it == 0 } != 1) {
        println(0)
        return
    }
    val da = IntArray(n)
    d.forEach { da[it]++ }
    var ans = 1L
    val max = d.max()!!
    for(i in 1..max){
        for (j in 1..da[i]) {
            ans *= da[i - 1].toLong()
            ans %= mod
        }
    }
    println(ans)
}

Measured memory_bytes: 51552
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 1000001
#define rep(i, l, r) for(int i=l; i<=r; ++i)
using namespace std;
int t;
int n;
int prime[N], tot=0;
bool iscmp[N];   
int c[N];
void init(){
	c[1]=1;
	rep(i, 2, N-1){
		if(!iscmp[i]) prime[++tot]=i, c[i]=2;
		for(int j=1; j<=tot && i*prime[j]<N; ++j){
			iscmp[i*prime[j]]=true;
			int tmp=0, x=i;
			while(x%prime[j]==0) x/=prime[j], ++tmp;
			c[i*prime[j]]=c[i]/(tmp+1)*(tmp+2);
			if(i%prime[j]==0) break;
		}
	}
	//rep(i, 1, 100) printf("%d ", prime[i]);
	rep(i, 2, N-1) c[i]+=c[i-1];
}
int main(){
	init();
	
	scanf("%d", &n);
	printf("%d", c[n-1]);
	return 0;
}
	

Measured memory_bytes: 6928
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
long long a[200005],b[200005],c[200005];
int main()
{
    int n;
    long long sum = 0,sum1 = 0;
    long long ans = 1000000000000000;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        scanf("%lld",&a[i]);
        sum1 += a[i];
    }
    for(int i = 1; i < n; i++){
        sum += a[i];
        b[i] = sum;
        c[i] = sum1 - b[i];
    }
    for(int i = 1; i < n;  i++){
        ans = min(ans,abs(b[i] - c[i]));
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4864
#include <iostream>
using namespace std;
class DICE{
	int tmp , tmp2;
	public:
	int s[6];
	void turnE();
	void turnN();
	void turnS();
	void turnW();
	void turnR();
	void turnL();
	void SetT(int a , int b);
	void SetS(int a);
} ;

void DICE::turnE(){
	tmp=s[0];
	s[0]=s[3];
	s[3]=s[5];
	s[5]=s[2];
	s[2]=tmp;
}

void DICE::turnN(){
	tmp=s[0];
	s[0]=s[1];
	s[1]=s[5];
	s[5]=s[4];
	s[4]=tmp;
}

void DICE::turnS(){
	tmp=s[0];
	s[0]=s[4];
	s[4]=s[5];
	s[5]=s[1];
	s[1]=tmp;
}

void DICE::turnW(){
	tmp=s[0];
	s[0]=s[2];
	s[2]=s[5];
	s[5]=s[3];
	s[3]=tmp;
}

void DICE::turnR(){
	tmp=s[1];
	s[1]=s[2];
	s[2]=s[4];
	s[4]=s[3];
	s[3]=tmp;
}

void DICE::turnL(){
	tmp=s[1];
	s[1]=s[3];
	s[3]=s[4];
	s[4]=s[2];
	s[2]=tmp;
}

void DICE::SetS(int a){
	if(s[2]==a) {
		turnR();
	} else if (s[3]==a){
		turnL();
	} else if (s[4]==a){
		turnR();
		turnR();
	}
}

void DICE::SetT(int a , int b){ //?????¢??¨?????¢??????????????¢????¨??????????
	tmp=a;
	tmp2=b;
	for(int i=0;i<6 ; i++){
		if(s[i]==a){
			switch(i){
				case 0:
					SetS(b);
					break;
				case 1:
					turnN();
					SetS(b);
					break;
				case 2:
					turnW();
					SetS(b);
					break;
				case 3:
					turnE();
					SetS(b);
					break;
				case 4:
					turnS();
					SetS(b);
					break;
				case 5:
					turnN();
					turnN();
					SetS(b);
				
			}
		}
	}	
}



int main(){
	DICE d;
	int q;
	int top,s1;
	cin>>d.s[0]>>d.s[1]>>d.s[2]>>d.s[3]>>d.s[4]>>d.s[5];
	cin>>q;
	int *a = new int[q];
	for(int i=0 ; i<q ; i++){
		cin >> top >> s1;
		d.SetT(top , s1);
		a[i]=d.s[2];
	}
	for(int i=0 ; i<q ; i++){
		cout << a[i] << endl;
	}
	delete [] a;
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    string n;
    cin >> n;
    if (n[0] == n[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  vector<int> vec;
  rep(i, 5){
    int x;
    cin >> x;
    vec.pb(x);
  }
  sort(vec.begin(), vec.end());
  rep(i, 5){
    cout << vec[4 - i];
    if(i != 4)cout << " ";
    else cout << endl;
  }
	return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  string S;
  cin >> S;
  string ans;  
  string a;
  a = S.at(0);

  int first = stoi(a);
  int sum = 0;

  for (int i = 0; i < (1 << 3); i++) {
    bitset<4> bs(i);
    ans = S.at(0);
    sum = first;
    string tmp;
    
    for (int j = 0; j < 3; j++) {
      if (bs.test(2-j) == 0) {
        tmp = S.at(j+1);
        sum += stoi(tmp);
        ans += "+" + tmp;
      }
      else {
        tmp = S.at(j+1);
        sum -= stoi(tmp);
        ans += "-" + tmp;
      }
    }

    if (sum == 7) break;
  }
  
  cout << ans + "=7" << endl;

}

Measured memory_bytes: 256