akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll q, cnt = 0,h,w, ans = 0,a,b; string s;
int dx[9] = { -2,-2,-2,-1,-1,-1,0,0,0 }, dy[9] = { 0,-1,-2,0,-1,-2,0,-1,-2 };
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
}; UnionFind uf(2e5+10);
vector<vector<int>> G;
void dfs(int i) {
    if (uf.same(i, 0))return;
    for (int v : G[i]) {
        if(uf.unite(0,v)) dfs(v);
    }
}
int main(void) {
    int n, m; cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        cin >> h >> w; h--; w--;
        G[h].push_back(w);
        G[w].push_back(h);
        uf.unite(h, w);
    }priority_queue<int,vector<int>,greater<int>>pq;
    pq.push(uf.size(0));
    rep(i, n) {
        if (uf.same(0, i))continue;
        pq.push(uf.size(i));
        dfs(i);
    }int sum = 0;
    while (!pq.empty()) {
        int now = pq.top(); pq.pop();
        if (now <= sum) continue;
        cnt += now - sum; sum = now;
    }cout << cnt << endl;
}

Measured memory_bytes: 15664
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;
const int mod = (int)1e9 + 7;

int main() {
	int n, k;
	cin >> n >> k;

	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long ans = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j && a[i] > a[j]) {
				ans += 1LL * k * (k + 1) / 2;
				if (i > j) {
					ans -= k;
				}
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*********************************************************************************************/
/**                                                                                          //
//                            _ooOoo_                                                        //
//                           o8888888o                                                       //
//                           88" . "88                                                       //
//                           (| -_- |)                                                       //
//                            O\ = /O                                                        //
//                        ____/`---'\____                                                    //
//                      .   ' \\| |// `.                                                     //
//                       / \\||| : |||// \                                                   //
//                     / _||||| -:- |||||- \                                                 //
//                       | | \\\ - /// | |                                                   //
//                     | \_| ''\---/'' | |                                                   //
//                      \ .-\__ `-` ___/-. /                                                 //
//                   ___`. .' /--.--\ `. . __                                                //
//                ."" '< `.___\_<|>_/___.' >'"".                                             //
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |                                          //
//                 \ \ `-. \_ __\ /__ _/ .-` / /                                             //
//         ======`-.____`-.___\_____/___.-`____.-'======                                     //
//                            `=---='                                                        //
//                                                       //                                  //
//         .............................................                                     //
//                  佛祖保佑             永无BUG                                            //
********************************************************************************************/
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const long long MOD=1000000009;
const int mod = 1e5+50;
typedef long long ll;
long long a,b;
int main()
{
    long long n,sum=0;
    long long cnt=0x3f3f3f3f;
    cin>>n;
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a>>b;
        if(a!=b)
            flag=1;
        sum+=a;
        if(a>b)
            cnt=min(b,cnt);
    }
    if(flag)
        cout<<sum-cnt<<endl;
        else
            cout<<'0'<<endl;
    return 0;
}


Measured memory_bytes: 256
key = {}
while n = gets
  n = n.to_i
  unless key[n]
    key[n] = 0
  end
  key[n] += 1
end

max = 0
ans = []
key.each{|k, v|
  if max < v
    ans = [k]
    max = v
  elsif max == v
    ans << k
  end
}

ans.sort.each{|i|
  puts i
}

Measured memory_bytes: 8612
#include <cstdio>
#include <cstring>
int n; char c[50000], d[50000], f[10];
int main() {
	while(scanf("%d", &n), n) {
		scanf("%s", c);
		for(int i = 0; i < n; i++) {
			int l = strlen(c), m = 0, e = 0;
			for(int j = 1; j <= l; j++) {
				if(c[j - 1] != c[j]) {
					sprintf(f, "%d%c", j - e, c[j - 1]);
					int l2 = strlen(f); e = j;
					for(int k = 0; k < l2; k++) d[m++] = f[k]; d[m] = 0;
				}
			}
			strcpy(c, d);
		}
		printf("%s\n", c);
	}
}

Measured memory_bytes: 2660
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int count=0;
    for (int i=0;i<n;i++){
        int min =i;
        for(int j=i;j<n;j++){
            if(a[j]<a[min]){
                min=j;
            }
        }
        if(min!=i){
            int ans=a[i];
            a[i]=a[min];
            a[min]=ans;
            count++;
        }
        
    }
    for (int i=0;i<n-1;i++){
        cout<<a[i]<<" ";
    }cout<<a[n-1]<<endl;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <atcoder/all>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Yes() std::cout << "Yes" << std::endl
#define No() std::cout << "No" << std::endl
#define Say(s) std::cout << s << std::endl
const ll MOD = 1000000007;
const ll INF = 1061109567;

int main()
{
    ll n, m;
    std::cin >> n >> m;
    atcoder::dsu G(n);

    rep(i, m)
    {
        ll temp_1, temp_2;
        std::cin >> temp_1 >> temp_2;
        --temp_1;
        --temp_2;
        G.merge(temp_1, temp_2);
    }
    std::vector<std::vector<int>> V = G.groups();
    ll ans = V.size() - 1;
    Say(ans);
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;


int main(){

  int a,b,c,d;cin>>a>>b>>c>>d;

  if(a!=c)out(1);
  else out(0);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
const int MOD = 1000000007;
typedef long long ll;
ll N, D, X;
typedef vector<int> Vec;
typedef vector<Vec> Mat;
void mat_mul(Vec &A, const Vec &B) {
  const int n = A.size();
  Vec col(n);
  REP(j,n) {
    ll s = 0;
    for(int k = 0; k <= j; ++k) {
      ll a = A[j - k];
      ll b = B[k];
      s += a * b;
      s %= MOD;
    }
    col[j] = s;
  }
  A = move(col);
}
Mat mat_pow(Mat A, ll n) {
  Vec col(A.size(),0);
  col[0] = 1;
  Vec a(A.size());
  REP(i,A.size()) a[i] = A[i][0];
  for(; n > 0; n >>= 1) {
    if(n & 1) mat_mul(col,a);
    mat_mul(a,a);
  }
  Mat res(A.size(), Vec(A.size(), 0));
  REP(i,A.size()) REP(j,A.size()) {
    if(i - j >= 0) res[i][j] = col[i - j];
  }
  return res;
}
void mat_print(Mat A) {
  const int n = A.size();
  REP(i,n) {
    REP(j,n) {
      cerr << ' ' << A[i][j];
    }
    cerr << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  while(true) {
    cin >> N >> D >> X;
    if(N == 0 && D == 0 && X == 0) break;
    Mat A(N+1, Vec(N+1, 0));
    REP(i,N+1) {
      for(int j = max<int>(i - X + 1, 0); j <= i; ++j) {
        A[i][j] = 1;
      }
    }
    Mat B = mat_pow(A, D);
    cout << B[N][0] << endl;
  }
}

Measured memory_bytes: 48328
x,k,d=map(int,input().split())
x=abs(x)
a=x//d
if a>=k:
  ans=x-(k*d)
else:
  b=x%d
  c=d-b
  if b<=c:
    if (k-a)%2==0:
      ans=b
    else:
      ans=c
  else:
    if (k-a)%2==0:
      ans=b
    else:
      ans=c
print(ans)

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int x = Integer.parseInt(str[0]);
    int a = Integer.parseInt(str[1]);
    System.out.println(x<a?0:10);
  }
}

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

using namespace std;

bool calc(vector<string> grid,int n)
{
	int h=grid.size(),w=grid[0].size();
	for(;;){
		for(int j=0;j<w;j++)
			for(int i=h-1,k=h-1;i>=0;i--)
				if(grid[i][j]!='.')
					swap(grid[i][j],grid[k--][j]);
		
		bool update=false;
		vector<vector<int>> flg(h,vector<int>(w));
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++){
				if(grid[i][j]=='.') continue;
				bool f1=i+n<=h,f2=j+n<=w;
				for(int k=0;k<n&&f1;k++) f1&=grid[i+k][j]==grid[i][j];
				for(int k=0;k<n&&f2;k++) f2&=grid[i][j+k]==grid[i][j];
				update|=f1||f2;
				for(int k=0;k<n&&f1;k++) flg[i+k][j]=1;
				for(int k=0;k<n&&f2;k++) flg[i][j+k]=1;
			}
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				if(flg[i][j]) grid[i][j]='.';
		if(!update) break;
	}
	return count(begin(grid),end(grid),string(w,'.'))==h;
}

int main()
{
	for(int h,w,n;cin>>h>>w>>n;){
		vector<string> grid(h);
		for(int i=0;i<h;i++) cin>>grid[i];
		
		bool res=false;
		for(int i=0;i<h;i++)
			for(int j=0;j<w-1;j++){
				swap(grid[i][j],grid[i][j+1]);
				res|=calc(grid,n);
				swap(grid[i][j],grid[i][j+1]);
			}
		cout<<(res?"YES":"NO")<<endl;
	}
}

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  vector<ll> l(n+1,0);
  rep(i,n) {
    cin >> a[i];
    l[i+1] = l[i] + a[i];
  }
  ll ans = INF;
  for(int i = 1; i < n; i++) {
    ans = min(ans,abs(l[n]-2*l[i]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
/*
2020-04-25
atcoder ABC
D - Caracal vs Monster
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

ull solve(ull);

int main() {
    ull H;
    cin >> H;
    cout << solve(H) << endl;
    
    return 0;
}

ull solve(ull H){
    if(H <= 1){
        return 1;
    }
    return solve(H / 2) * 2 + 1;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[] V = new int[N];
		for (int i = 0; i < N; i++) {
			V[i] = sc.nextInt();
		}
		
		int[] C = new int[N];
		for (int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
		}
		
		long ans = 0;
		for (int i = 0; i < N; i++) {
			if (C[i] < V[i]) {
				ans += V[i] - C[i];
			}
		}
		
		System.out.println(ans);
	
	}
	
}



Measured memory_bytes: 23764
#include <stdio.h>

int main(int argc, const char * argv[]){
    int S,h,m,s;
    scanf("%d",&S);
    
    h = S/3600;
    m = (S-h*3600)/60;
    s = S - h*3600 - m*60;
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}



Measured memory_bytes: 2052
#include <stdio.h>

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

    for ( i = 2; i <= (n - 1); i++ ) {
        if ( (p[i - 1] < p[i] && p[i] < p[i + 1]) ||
             (p[i - 1] > p[i] && p[i] > p[i + 1]) ) {
            ans++;
        }
    }
    printf("%d\n", ans);

    return 0;
}

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

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

    int ans = 0;
    for (int i = 0; i < n-2; ++i){
        if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ans+=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <vector>

using namespace std;

int is_arrive(int start, string& ss, vector<pair<char, int>>& qs) {
  int id = start;
  char s =ss[id];
  for (int i = 0; i < qs.size(); ++i) {
    if (s == qs[i].first) {
    	id += qs[i].second;
        s = ss[id];
    }
    if (id == -1) return -1;
    if (id == ss.size()) return 1;
  }
  return 0;
}

int main() {
  int N, Q; 
  string ss;
  cin >> N >> Q;
  cin >> ss;
  vector<pair<char, int>> qs;
  for (int i = 0; i < Q; ++i) {
    char t, d;
    cin >> t >> d;
    qs.emplace_back(make_pair(t, d == 'L' ? -1 : 1));
  }
  int imin = -1;
  int imax = N;
  
  while (imin < imax - 1) {
    int imid = imin + (imax - imin) / 2;
    int ans = is_arrive(imid, ss, qs);  
    if (ans < 0) {
    	imin = imid;
    } else {
        imax = imid;
    }
  }
  int lu = imin;
  
  imin = -1;
  imax = N;
  while (imin < imax - 1) {
    int imid = imin + (imax - imin) / 2;
    int ans = is_arrive(imid, ss, qs);  
    if (ans > 0) { 
    	imax = imid;
    } else {
        imin = imid;
    }
    
  }
  int ru = imax;  
 cout <<  ru - lu -1 << endl;
  return 0;
}

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

#define int long long

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

int N;
int a[100000], b[100000];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] > b[i]) {
            ans -= a[i] - b[i];
        } else if (a[i] < b[i]) {
            ans += (b[i] - a[i]) / 2;
        }
    }
    if (ans >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const double pi=3.141592653589793238462643383279505;

int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double ans;
  ans = pow(abs(a*sin((h+m/60)*2*pi/12)-b*sin(m*2*pi/60)),2);
  ans += pow(abs(a*cos((h+m/60)*2*pi/12)-b*cos(m*2*pi/60)),2);
  ans = sqrt(ans);
  printf("%.20f",ans);
}

Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){

ll n,r; cin >> n >> r;

cout << floor(log(n)/log(r)+1) << endl;

}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 1e5+5;
int N,K;
LL L[maxn];
LL R[maxn];

int main()
{
    scanf("%d %d",&N,&K);
    vector<int> Lc;
    vector<int> Rc;
    _for(i,0,N){
        int num;
        scanf("%d",&num);
        if(num < 0) Lc.push_back(-num);
        else Rc.push_back(num);
    }

    int sz = Lc.size();
    int pos = 1;
    for(int k = sz-1;k>=0;k--){
        L[pos++] = Lc[k];
    }

    pos = 1;
    for(int k = 0;k < Rc.size();k++){
        R[pos++] = Rc[k];
    }

    int ans = 1e9;

    _rep(i,0,K){
        if(Lc.size() >= i && Rc.size() >= K-i){
            int temp = min(2*L[i]+R[K-i],2*R[K-i]+L[i]);
            ans = min(temp,ans);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1656
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    SP=[[i]+list(input().split()) for i in range(N)]
    SP.sort(key=lambda x: int(x[2]), reverse=True)
    SP.sort(key=lambda x: x[1])
    for v in SP:
        print(v[0]+1)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc128","b",main)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define mod 1000000007
using namespace std;
int main(){
    int n,k,sl[51],sr[51],v[50],ans=-1000000000,sum,l,r;
    vector<int> vl[51],vr[51];
    scanf("%d %d",&n,&k);
    sl[0]=sr[0]=0;
    for(int i=0;i<n;i++){
        scanf("%d",&v[i]);
        sl[i+1]=sl[i]+v[i];
        vl[i+1]=vl[i];
        if(v[i]<0){
            vl[i+1].push_back(v[i]);
        }
    }
    for(int i=0;i<n;i++){
        vr[i+1]=vr[i];
        sr[i+1]=sr[i]+v[n-1-i];
        if(v[n-1-i]<0){
            vr[i+1].push_back(v[n-1-i]);
        }
    }
    for(int i=1;i<=n;i++){
        if(vr[i].size()!=0){
            sort(vr[i].begin(),vr[i].end());
        }
        if(vl[i].size()!=0){
            sort(vl[i].begin(),vl[i].end());
        }
    }
    for(int i=0;i<=min(n,k);i++){
        for(int j=0;i+j<=min(n,k);j++){
            sum=sl[i]+sr[j];
            int x=k-(i+j);
            l=r=0;
            while(x&&(l<vl[i].size()||r<vr[j].size())){
                if(r==vr[j].size()){
                    sum-=vl[i][l];
                    l++;
                    x--;
                }
                else if(l==vl[i].size()){
                    sum-=vr[j][r];
                    r++;
                    x--;
                }
                else if(vl[i][l]<vr[j][r]){
                    sum-=vl[i][l];
                    l++;
                    x--;
                }
                else{
                    sum-=vr[j][r];
                    r++;
                    x--;
                }
            }
            ans=max(ans,sum);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	ans := int(1e9)
	for i := 0; i < 26; i++ {
		c := byte('a' + i)

		cnt := 0
		cur := s
		for {
			ok := true
			for j := 0; j < len(cur); j++ {
				if cur[j] != c {
					ok = false
				}
			}
			if ok {
				break
			}

			cnt++
			tmp := ""
			for j := 0; j < len(cur)-1; j++ {
				if cur[j] == c || cur[j+1] == c {
					tmp += string(c)
				} else {
					tmp += string(cur[j])
				}
			}
			cur = tmp
		}

		if ans > cnt {
			ans = cnt
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
	int n,a=0;
	char w[10],r[100][21],cpy[21],tem;
	cin >> w;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r[i];
		strcpy(cpy,r[i]);
		strcat(r[i],cpy);
		if(tem=strstr(r[i],w) != NULL){
			a++;
		}
	}
	cout << a << endl;
	
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    ll n,mx=1000000000,cnt=1;
    cin>>n;
    ll x,ans=0,y;
    cin>>x;
    for(int i=0; i<n-1; i++){
        cin>>y;
        if(y>=x)cnt++,x=y;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
l = sorted(map(int, input().split()))
m = l.pop()
n -= 1
i, res, curr = 1, [], 0
while i < n and l[i] <= 0: i += 1
a, b = l[:i], l[i:]
while b:
    res.append(str(a[0]) + ' ' + str(b[-1]))
    a[0] -= b.pop()
while a:
    res.append(str(m) + ' ' + str(a[-1]))
    m -= a.pop()
print(m)
print('\n'.join(res))

Measured memory_bytes: 19860
n,m = map(int,input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(n)
for i in range(m):
    x,y,z = map(int,input().split())
    uf.union(x-1,y-1)
print(uf.group_count())

Measured memory_bytes: 7880
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
#print(a)
b=[]
c=[]
for i in range(n):
  if i%2==0:
    b.append(a[i])
  else:
    c.append(a[i])
print(sum(b)-sum(c))

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
  }
  vector<int> p(n), mark(n);
  int cs = -1;
  function<void(int)> dfs = [&](int v) {
    mark[v] = 1;
    for (int to : g[v]) {
      if (cs != -1) {
        return;
      }
      if (mark[to] == 1) {
        cs = to;
        p[to] = v;
      } else if (!mark[to]) {
        p[to] = v;
        dfs(to);
      }
    }
    mark[v] = 2;
  };
  for (int i = 0; i < n and cs == -1; ++i) {
    if (!mark[i]) {
      dfs(i);
    }
  }
  if (cs == -1) {
    cout << -1;
    return 0;
  }
  vector<int> cycle = {cs}, pos(n);
  mark[cs] = 3;
  for (int j = p[cs]; j != cs; j = p[j]) {
    cycle.push_back(j);
    mark[j] = 3;
  }
  reverse(cycle.begin(), cycle.end());
  n = cycle.size();
  for (int i = 0; i < n; ++i) {
    pos[cycle[i]] = i;
  }
  pair<int, int> best(0, n - 1);
  auto dist = [&](int a, int b) {
    return (b - a + n) % n + 1;
  };
  for (int v : cycle) {
    for (int to : g[v]) {
      if (mark[to] != 3) {
        continue;
      }
      if (dist(pos[to], pos[v]) < dist(best.first, best.second)) {
        best = {pos[to], pos[v]};
      }
    }
  }
  cout << dist(best.first, best.second);
  for (int i = best.first; ; i = (i + 1) % n) {
    cout << '\n' << cycle[i] + 1;
    if (i == best.second) {
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] A = new int[2][N];
		int[] sum = {0,0};
		int a = 0;
		for(int i=0;i<2;i++){
			for(int j = 0;j<N;j++){
				A[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(i==j){
					sum[0] += A[a][j];
					a = 1;
				}
				sum[0] += A[a][j];
			}
			if(sum[1]<sum[0]){
				sum[1]=sum[0];
			}
			sum[0] = 0;
			a = 0;
		}
		System.out.print(sum[1]);
	}
}

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

typedef long long LL;
#define MAXN 210
#define MOD 761238923

pair<int, int> R[MAXN], B[MAXN];
int graph[MAXN][MAXN];
int parent[MAXN ];
int visited[MAXN];

int main() {
#ifdef OJ
    //    freopen("input.txt", "rt", stdin);
    //    freopen("output.txt", "wt", stdout);
#endif
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        R[i] = {a, b};
    }

    for (int i = 1; i <= N; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        B[i] = {a, b};
    }

    for (int i = 1; i <= N; i++) {
        graph[0][i] = 1;
        graph[i + N][2 * N + 1] = 1;
        for (int j = 1; j <= N; j++) {
            if (R[i].first < B[j].first && R[i].second < B[j].second) {
                graph[i][N + j] = 1;
            }
        }
    }

    int ans = 0;
    int s = 0;
    int t = 2 * N + 1;

    while (1) {
        for (int i = 0; i <= t; i++)
            visited[i] = 0;

        queue<int> q;
        q.push(s);
        visited[s] = 0;

        while (!q.empty()) {
            int n = q.front();
            q.pop();

            for (int i = 0; i <= 2 * N + 1; i++) {
                if (graph[n][i] > 0 && !visited[i]) {
                    q.push(i);
                    visited[i] = 1;
                    parent[i] = n;
                }
            }
        }

        if (!visited[t])
            break;

        int v;
        for (v = t; v != s; v = parent[v]) {
            int u = parent[v];
            graph[u][v]--;
            graph[v][u]++;
        }

        ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 384
// calc 内の添字を修正

#include<map>
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;
#define sign(a) ((((a)>0)?1:0)-(((a)<0)?1:0))
#define abs(a) (((a)>0)?a:-(a))

template<typename T>
void print_item(T x) {cout << x;}

template<typename F,typename S>
void print_item(pair<F,S> x) {
  printf("(");
  print_item(x.first);
  printf(",");
  print_item(x.second);
  printf(")");
}

template<typename T>
void print(vector<T>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(T x: vec) {print_item(x); cout << " ";}
  cout << endl;
}
template<typename T>
void print(vector<vector<T>>& vec,string str=""){
  if(str!="") cout << str << ":\n";
  int n=vec.size();
  rep(i,n){
    print(vec.at(i),(string){(char)(i+'0')});
  }
}
template<typename F,typename S>
void print(map<F,S>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(auto x: vec) {print_item(x); cout << " ";}
  cout << endl;
}





int main(){
  if(df) printf("*debug mode*\n");
  int n,k; cin >>n >>k;
  map<pair<int,int>,int> mp;
  int ans=0;
  rep(i,n){
    int x,y; char c; cin >>x >>y >>c;
    int f=(c=='B');
    x%=2*k; y%=2*k;
    if(df)printf("%d(%d,%d)->",f,x,y);
    f=f^(x/k)^(y/k);
    f=f*2-1;
    if(df)printf("%d\n",f);

    x%=k; y%=k;
    pair<int,int> p(x,y);
    if(sign(mp[p])*f<0) ans++;
    mp[p]+=f;
  }
  if(df)print(mp,"map");
  if(df){
    printf("temp:%d\n",ans);
  }

  vector<vector<int>> w(k,vector<int>(k,0)),b(k,vector<int>(k,0));
  for(auto m:mp){
    pair<int,int> p=m.first;
    ((m.second>0)?b:w).at(p.first).at(p.second)=abs(m.second);
  }

  vector<vector<int>> ws(k+1,vector<int>(k+1,0)),bs(k+1,vector<int>(k+1,0));
  rep(i,k){
    rep(j,k){
      ws.at(i+1).at(j+1)=ws.at(i).at(j+1)+w.at(i).at(j);
      bs.at(i+1).at(j+1)=bs.at(i).at(j+1)+b.at(i).at(j);
    }
  }
  rep(j,k){
    rep(i,k){
      ws.at(i+1).at(j+1)+=ws.at(i+1).at(j);
      bs.at(i+1).at(j+1)+=bs.at(i+1).at(j);
    }
  }
  if(df){
    print(w,"Wht");
    print(ws,"ws");
    print(b,"Blc");
    print(bs,"bs");
  }

  auto sum=[&](int si,int sj,int i,int j,const vector<vector<int>>& S){
	     return S.at(i).at(j)-S.at(si).at(j)
	       -S.at(i).at(sj)+S.at(si).at(sj);
	   };
  auto calc=[&](int i,int j){
	      return sum(0,0,i,j,bs)+sum(i,j,k,k,bs)
		+sum(0,j,i,k,ws)+sum(i,0,k,j,ws);
	    };
  if(df)printf("%d\n",k);
  int m=0,inv=sum(0,0,k,k,bs)+sum(0,0,k,k,ws);
  if(df)printf("sum:%d\n",inv);
  rep(i,k+1){
    rep(j,k+1){
      int temp=calc(i,j);
      if(df)printf("%d ",temp);
      if(inv-temp>temp)temp=inv-temp;
      if(m<temp)m=temp;
    }
    if(df)cout << endl;
  }

  printf("%d",ans+m);
  
}

/// confirm df==0 ///


Measured memory_bytes: 22016
n=int(input())
S=input()
sflag=0
a=0
b=0
c1=0
c2=0

d=0
for i in S:
    if i==".":
        a+=1
    if i=="#":
        b+=1
out=min(a,b)
siro=0
kuro=0
for i in S:
    if i==".":
        siro+=1
        a-=1
    else:
        kuro+=1
        b-=1
    if kuro+a < out:
        out=kuro+a
    #print(kuro+a)
print(out)

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


int main(){


    int n, l, r, i;

    int a = 0;
   

    cin >> n;


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

         cin >> l >> r;

         a += r - l + 1;

         }


    cout << a << endl;


    return 0;

    }


Measured memory_bytes: 256
A, B, C, K = map(int, input().split())
ans = 0

if A > 0 and K > 0:
    ans += min(A, K) * 1
    K -= min(A, K)
if B > 0:
    K -= min(B, K)
if C > 0:
    ans += min(C, K) * (-1)
    K -= min(C, K)

print(ans)


Measured memory_bytes: 9016
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	l := make([]string, n)
	for i := 0; i < n; i++ {
		c := nextInt() - 1
		l[c] = strconv.Itoa(i + 1)
	}
	fmt.Println(strings.Join(l, " "))
}


Measured memory_bytes: 5760
n, m = map(int, input().split())
is_ac = [False]*n
ac = 0
was = [0]*n
for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s=='AC' and (not is_ac[p]):
        ac += 1
        is_ac[p] = True
    if s=='WA' and (not is_ac[p]):
        was[p] += 1
wa = 0
for i in range(n):
    if is_ac[i]:
        wa += was[i]
print(ac, wa)

Measured memory_bytes: 4596
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, D, Q;
vi d, q;
vll dcur, emin;

int main() {
    cin >> N >> D;
    d.resize(N);
    rep(i, N) cin >> d[i];
    cin >> Q;
    q.resize(Q);
    rep(i, Q) cin >> q[i];

    dcur.resize(N + 1);
    dcur[0] = D;
    rep(i, N) {
        if (d[i] > 2 * dcur[i]) dcur[i + 1] = dcur[i];
        else if (d[i] > dcur[i]) dcur[i + 1] = d[i] - dcur[i];
        else dcur[i + 1] = dcur[i] - d[i];
    }

    emin.resize(N + 1);
    emin[N] = 1;
    for (int i = N - 1; i >= 0; --i) {
        if (d[i] >= 2 * emin[i + 1]) {
            emin[i] = emin[i + 1];
        }
        else {
            emin[i] = emin[i + 1] + d[i];
        }

        //if (d[i] <= 2 * dmax[i + 1]) {
        //    dmax[i] = dmax[i + 1] + d[i];
        //}
        //else if (d[i] == 1) {
        //    dmax[i] = dmax[i + 1] + 1;
        //}
        //else {
        //    dmax[i] = dmax[i + 1];
        //}
    }

    rep(i, Q) {
        //if (dcur[q[i] - 1] > dmax[q[i]]) write("YES");
        if (dcur[q[i] - 1] >= emin[q[i]]) write("YES");
        else write("NO");
    }
}

Measured memory_bytes: 13696
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;

int n,m;
long long a[100005],b[100005],c[100005];
long long s,cur,cnt,ans;

inline void init(long long x,long long y)
{
	if (x<y-1)
	{
		b[x+2]++;
		b[y+1]--;
		c[y+1]-=y-x-1;
	}
	else if (x>y)
	{
		if (x<m-1)
		{
			b[x+2]++;
		}
		long long dist=y+m-x;
		if (dist>=2)
		{
			if (x==m)
			{
				b[2]++;
			}
			else
			{
				b[1]++;
				c[1]+=m-x-1;
			}
			b[y+1]--;
			c[y+1]-=dist-1;
		}
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<n;i++)
	{
		int from=a[i];
		int to=a[i+1];
		init((long long)from,(long long)to);
//		for (int i=1;i<=m;i++) cout<<i<<" "<<b[i]<<" "<<c[i]<<endl;
//		system("pause");
		if (to<from)
			s+=(long long)(to+m-from);
		else
			s+=(long long)(to-from);
	}
	ans=0LL;
	for (int i=1;i<=m;i++)
	{
		cur+=c[i];
		cnt+=b[i];
		cur+=cnt;
//		cout<<cnt<<" "<<s-cur<<endl;
		ans=max(ans,cur);
	}
//	cout<<endl;
	cout<<s-ans;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=1010;
int n,tot,vis[maxn*10];
ll prime[maxn],ans[maxn][maxn];
void init() {
	int tmp;
	for (int i=2;i<=8000;i++) {
		if (!vis[i]) prime[++tot]=i;
		if (tot==1000) break;
		for (int j=1;j<=tot;j++) {
			tmp=i*prime[j];
			if (tmp>=maxn*10) break;
			vis[tmp]=1;
			if (i%prime[j]==0) break;
		}
	}
}
ll gcd(ll x,ll y) {
	if (!x||!y) return x+y;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y) {
	return x/gcd(x,y)*y;
}
int main() {
	//freopen("1.txt","r",stdin);
	init();
	read(n);
	if (n==2) {
		printf("4 7\n23 10\n");
		return 0;
	}
	for (int i=0;i<=n+1;i++)
		ans[0][i]=ans[i][0]=ans[n+1][i]=ans[i][n+1]=1;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
		if ((i+j)%2==0)
			ans[i][j]=prime[(i+j)/2]*prime[n+(i-j)/2+(n+1)/2];
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
		if ((i+j)%2==1)
			ans[i][j]=lcm(lcm(ans[i-1][j],ans[i][j-1]),lcm(ans[i+1][j],ans[i][j+1]))+1;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++)
			printf("%lld ",ans[i][j]);
		printf("\n");
	}
	return 0;
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            // 文字列の入力
            string s = Console.ReadLine();

            // 整数の入力
            //long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            int a = s.Length;

            string result = "";

            for (int i = 0; i <= s.Length - 1; i++)
            {
                if (s[i] == '0')
                {
                    result += s[i];
                }
                else if (s[i] == '1')
                {
                    result += s[i];
                }
                else
                {
                    if (result.Length > 0)
                    {
                        result = result.Remove(result.Length - 1, 1);
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>

using namespace std;

int main(void){

    int n, k;
    double ans = 0;

    cin >> n >> k;

    vector<int> dp;
    dp.push_back(k);

    int count = 1;
    int tmp = k;
    while(tmp != 1){
        tmp = (tmp+1)/2;
        dp.push_back(tmp);
        count++;
    }

    tmp = n;
    for(int i = 0;i < count;i++){
        if(tmp >= dp[i]){
            ans += (1.0/n)*pow((0.5),i)*(tmp-dp[i]+1);
            //cout << "ans:" << (1.0/n)*pow((0.5),i+1)*(tmp-dp[i]+1) << endl; 
            //cout << "1.0/n:" << 1.0/n << " pow((0.5),i+1):" << pow((0.5),i+1) << " (n-dp[i]+1):" << (tmp-dp[i]+1) << endl;
            tmp = dp[i]-1;
            
        }
    }

    /*
    cout << "-------------------" << endl;

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


    cout << "-------------------" << endl;

    cout << count << endl;

    cout << "-------------------" << endl;
    */
    cout << setprecision(12) << fixed << ans << endl;

    return 0;
}

Measured memory_bytes: 512
// 反転数
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 200000
const int INFTY = 2147483647;

typedef long long llong;

int cmp_count = 0;

llong mergeSort(int A[], int n, int left, int right);
llong merge(int A[], int n, int left, int mid, int right);

int main(void)
{
    llong flip_count;

    int A[MAX_N];
    int n;

    scanf("%d", &n);

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

    // マージソートを実施
    flip_count = mergeSort(A, n, 0, n);

/*
    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        if( i )
        {
            printf(" ");
        }

        printf("%d", A[i]);
    }

    printf("\n%d\n", cmp_count);

*/
    printf("%lld\n", flip_count);

    return 0;
}

// マージソートを実施する関数
llong mergeSort(int A[], int n, int left, int right)
{
    llong c1, c2, c3, cnt = 0;

    // 最小単位まで分割する
    if ( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        c1 = mergeSort(A, n, left, mid);
        c2 = mergeSort(A, n, mid, right);
        c3 = merge(A, n, left, mid, right);

        cnt = c1 + c2 + c3;
  }

  return cnt;
}

// 分割された要素を並び替える関数
llong merge(int A[], int n, int left, int mid, int right)
{

    // 反転数
    llong flip_count = 0;

    vector<int> L, R;

    int n1 = mid - left;
    int n2 = right - mid;

    // L[0...n1], R[0...n2] を生成
    for(int i = 0; i < n1; i++)
    {
        // 前半部分の配列を作成する
        L.push_back(A[left + i]);
    }

    for(int i = 0; i < n2; i++)
    {
        // 後半部分の配列を作成する
        R.push_back(A[mid + i]);
    }

    // 前半と後半の配列の最後の要素に最大値を入れておく
    // ( 比較時の番兵として使用 )
    L.push_back(INFTY);
    R.push_back(INFTY);

    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++)
    {
        // 前半部分の配列と後半部分の配列を比較する
        if ( L[i] <= R[j] )
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
            // 反転数の計算
            flip_count += n1 - i;
        }

        cmp_count++;
    }

    return flip_count;
}



Measured memory_bytes: 4660
#include <bits/stdc++.h>
#define F(i,a,b) for(ll i=a;i<=(b);++i)
#define dF(i,a,b) for(ll i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-7
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 998244353;
const int maxn = 2e5+10;
const int N = 1e5+10;
const int E = 1e6+10; 

ll n,k;
ll l[15],r[15];
ll sum[maxn<<2],lazy[maxn<<2];

void pushup(int rt) {
	sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
	sum[rt]%=mods;
}

void pushdown(int ln, int rn, int rt) {
	if (lazy[rt]) {
		sum[rt << 1] += ln * lazy[rt]%mods;
		sum[rt << 1]%mods;
		sum[rt << 1 | 1] += rn * lazy[rt]%mods;
		sum[rt << 1 | 1]%=mods;
		lazy[rt << 1] += lazy[rt];
		lazy[rt << 1 | 1] += lazy[rt];
		lazy[rt] = 0;
	}
}

void update(int L, int R, int l, int r, int rt, int C) {
	if (L <= l && r <= R) {
		sum[rt] += (r - l + 1) * C;
		sum[rt]%=mods;
		lazy[rt] += C;
		lazy[rt]%=mods;
		return;
	}
	int mid = (l + r) >> 1;
	pushdown(mid - l + 1, r - mid, rt);
	if (L <= mid) update(L, R, l, mid, rt << 1, C);
	if (R > mid) update(L, R, mid + 1, r, rt << 1 | 1, C);
	pushup(rt);
}

int query_sum(int L, int R, int l, int r, int rt) {
	if (L <= l && r <= R) {
		return sum[rt];
	}
	int mid = (l + r) >> 1;
	pushdown(mid - l + 1, r - mid, rt);
	ll ans = 0;
	if (L <= mid) ans += query_sum(L, R, l, mid, rt << 1);
	ans%=mods;
	if (R > mid) ans += query_sum(L, R, mid + 1, r, rt << 1 | 1);
	ans%=mods;
	return ans;
}

int main(){
	cin>>n>>k;
	F(i,1,k){
		cin>>l[i]>>r[i];
	}
	update(1,1,1,n,1,1);
	F(i,1,n){
		ll tmp = query_sum(i,i,1,n,1);
		//cout<<tmp<<endl;
		F(j,1,k){
			if(i+l[j]>n) continue;
			update(i+l[j],min(n,i+r[j]),1,n,1,tmp);
			//cout<<i+l[j]<<" "<<min(n,i+r[j])<<endl;
		}
		//cout<<query_sum(n,n,1,n,1)<<endl;
		//cout<<endl;
	}
	ll ANS = query_sum(n,n,1,n,1);
	ANS%=mods;
	cout<<ANS<<endl;
	return 0;
}


Measured memory_bytes: 11832
s = input()

res = 0
i = 0
while (i < len(s)):
    a, b = 0, 0
    while (i < len(s) and s[i] == '<'):
        i += 1
        a += 1
    while (i < len(s) and s[i] == '>'):
        i += 1
        b += 1
    c = min(a, b)
    d = max(a, b)
    res += (c * (c - 1)) // 2
    res += (d * (d + 1)) // 2

print(res)


Measured memory_bytes: 44104
#include <stdio.h>

int main(void){

 int i, a, b, c, e;

 scanf("%d%d%d", &a, &b, &c);

  for(i = a, e = 0; i < (b + 1); i++){

   if(c % i == 0){
   e++;
   }

  }

 printf("%d\n", e);

}

Measured memory_bytes: 1828
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()
    Q = il()
    pt, qt = [], []

    for p in itertools.permutations(P):
        pt.append(p)
    for q in itertools.permutations(Q):
        qt.append(q)
    pc = sorted(pt).index(tuple(P)) + 1
    qc = sorted(qt).index(tuple(Q)) + 1
    print(abs(pc - qc))


if __name__ == '__main__':
    main()


Measured memory_bytes: 13512
#include <stdio.h>

int main(void){
  int N, i, min = 100;
  scanf("%d",&N);
  for(i=1; i<N; i++){
    if(i%10 + i/10%10 + i/100%10 + i/1000%10 + i/10000%10 +
       (N-i)%10 + (N-i)/10%10 + (N-i)/100%10 + (N-i)/1000%10 + (N-i)/10000%10
       < min)
      min = i%10 + i/10%10 + i/100%10 + i/1000%10 + i/10000%10 +
            (N-i)%10 + (N-i)/10%10 + (N-i)/100%10 + (N-i)/1000%10 + (N-i)/10000%10;
  }
  printf("%d",min);
  return 0;
}

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

typedef long long int ll;

const ll maxn = 100010;

int main(){
	vector <ll> v,v2;
	ll n;
	scanf("%lld",&n);
	for( ll i = 0; i < n; i++ ){
		ll temp;
		scanf("%lld",&temp);
		v.push_back(temp);
	}
	
	ll all_xor = 0;
	for(ll i = 0; i < n-1; i+=2){
		all_xor = all_xor ^ v[i] ^ v[i+1];
	}
	
	for(ll i = 0; i < n; i++){
		if(i != 0)	printf(" ");
		printf("%lld", all_xor ^ v[i]);
	}
	printf("\n");
}


Measured memory_bytes: 5376
a,b=map(int,input().split())
if a>b:
   c=[]
   for i in range(a):
       c.append(str(b))
   d=''.join(c)
else:
    c = []
    for i in range(b):
        c.append(str(a))
    d = ''.join(c)
print(d)



Measured memory_bytes: 38256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

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

using namespace std;
int a[100];
int c[100],b[100];
int n;
int main()
{
    long long sum=0,p=0;
    cin>>n;
    for (int i=0;i<n;++i) cin>>a[i];
    for (int i=0;i<n;++i) cin>>b[i+1];
    for (int i=0;i<n-1;++i) cin>>c[i+1];
    for (int i=0;i<n;++i){
        sum+=b[a[i]];
        if (a[i]-p==1) {
            sum+=c[p];
        }
        p=a[i];
    }
    cout<<sum;
}


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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

int n;

int main()
{
    cin >> n;
    cout << n / 3 << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  long n;
  long a[200000];
  int i, j, idx;
  long max = 0, submax = 0;
  
  scanf("%ld", &n);
  for (i = 0; i < n; i++)
    scanf("%ld", &a[i]);
  
  for (i = 0; i < n; i++)
    if (max < a[i]) {
      max = a[i];
      idx = i;
    }
  
  for (i = 0; i < n; i++)
    if (i != idx)
      printf("%ld\n", max);
    else {
      for (j = 0; j < i; j++) {
        if(submax < a[j])
          submax = a[j];
      }
      for (j = i+1; j < n; j++) {
        if(submax < a[j])
          submax = a[j];
      } 
      printf("%ld\n", submax);
    }
  
  return 0;
}

Measured memory_bytes: 3072