akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


struct SegmentTree{
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1,INF);
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,int val){
        x += n-1;
        node[x] = val;
        while(x > 0){
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1){
        if (r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = getmin(a, b, 2*k+1, l , (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2,r);
        return min(vl, vr);
    }
};



int main(){
    int n,m;cin >> n >> m;
    string s;cin >> s;
    vector<int> x(n+2,-1);
    SegmentTree seg(vector<int> (n+2,INF));
    seg.update(0,0);
    for (int i = 1; i <= n; i++) {
        if(s[i]=='1') continue;
        int t = seg.getmin(max(0,i-m),i);
        seg.update(i,t+1);
        int l = max(0,i-m);
        while(seg.getmin(l,l+1)!=t) l++;
        x[i] = l;
    }
    if(seg.getmin(n,n+1) >= INF){
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    int t = n,now=n;
    while(now != 0){
        t = x[now];
        ans.pb(now-t);
        now = t;
    }
    reverse(ALL(ans));
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << (i+1==ans.size()?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
#define FORN(i,n) for(int i=1;i<=n;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=c.begin();i!=(c).end();i++)
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
using namespace std;
int a[100010];
int b[100010];
vector<int> gr[100010];
vector<int> Root;
bool vis[100010];
int n;
bool flag=false;
void dfs(int x,int y){
	if(vis[x])return ;
	vis[x]=true;
	if(x==y){
		flag=true;
		return ;
	}
	REP(i,gr[x].size()){
		Root.push_back(gr[x][i]);
		dfs(gr[x][i],y);
		if(flag)return ;
		else if(Root.size())Root.erase(Root.begin()+Root.size()-1);
	}
	return ;
}
int answer=0,result=0;
void dfs2(int k,int x,int y,int z){
	if(vis[x])return ;
	vis[x]=true;
	answer+=(k==1);
	result+=(k==2);
	REP(i,gr[x].size()){
		if(x==y&&z==gr[x][i])continue;
		dfs2(k,gr[x][i],y,z); 
	}
} 
int main(){
	cin>>n;
	REP(i,n-1){
		cin>>a[i]>>b[i];
		gr[a[i]].push_back(b[i]);
		gr[b[i]].push_back(a[i]);
	}
	if(n==1){
		cout<<"Fennec"<<endl;
		return 0;
	}
	Root.push_back(1);
	dfs(1,n);
	memset(vis,false,sizeof(vis));
	if(Root.size()%2==1){
		dfs2(1,1,Root[Root.size()/2],Root[Root.size()/2+1]);
		dfs2(2,Root[Root.size()/2+1],n,Root[Root.size()/2]);
	}
	else{
		dfs2(1,1,Root[Root.size()/2-1],Root[Root.size()/2]);
		dfs2(2,Root[Root.size()/2],n,Root[Root.size()/2-1]);
	}
	if(answer>result){
		cout<<"Fennec"<<endl;
	}
	else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}

Measured memory_bytes: 11768
#include<bits/stdc++.h>
#include <string>
#include <unordered_map>
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Zero(dp) memset(dp,0,sizeof(dp))
using namespace std;
bool check(string s)
{
    string t=s;
    reverse(all(t));
    return s==t;
}
int32_t main(){
ios
int t=1;
//cin>>t;
while(t--)
{ 
    int n;cin>>n;
    double l=(1.0*n)/3;
    double ans=l*l*l;
    cout<<fixed<<setprecision(10)<<ans;

}
}


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

const int MAXN = 10;
char s[MAXN][MAXN];
char w[MAXN][MAXN];


int main() {
    int x, y, k;
    scanf("%d%d%d", &x, &y, &k);
    for (int i = 0; i < x; i++) {
        scanf("%s", s[i]);
    }
    int ans = 0;
    for (int i = 0; i < (1 << x); i++) {
        for (int j = 0; j < (1 << y); j++) {
            for (int u = 0; u < x; u++) {
                for (int v = 0; v < y; v++) {
                    w[u][v] = s[u][v];
                }
            }
            for (int u = 0; u < x; u++) {
                if ((i >> u) & 1) {
                    for (int v = 0; v < y; v++) {
                        w[u][v] = '.';
                    }
                }
            }
            for (int v = 0; v < y; v++) {
                if ((j >> v) & 1) {
                    for (int u = 0; u < x; u++) {
                        w[u][v] = '.';
                    }
                }
            }
            int cnt = 0;
            for (int u = 0; u < x; u++) {
                for (int v = 0; v < y; v++) {
                    if(w[u][v] == '#') {
                        cnt++;
                    }
                }
            }
            if (cnt == k) {
                ans++;
            }
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 3808
#include <stdio.h>
#include <math.h>

int main(void) {
	int n,l, max = 0, sum = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		scanf("%d", &l);
		sum += l;
		max = fmaxf(max, l);
	}
	if (sum > 2 * max) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int i, j, H, W;
	scanf("%d %d", &H, &W);
	while((H!=0)||(W!=0)){
		for(i=0; i<H ;i++){
			for(j=0; j<W; j++){
				printf("#");
				if(j == (W-1))
					printf("\n");
			}
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}

Measured memory_bytes: 572
N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = float('inf')
dp = [inf] * N
dp[0] = 0

for i in range(N-1):
  for j in range(1, K+1):
    if i+j < N:
      dp[i+j] = min(dp[i]+abs(h[i]-h[i+j]), dp[i+j])

print(dp[N-1])

Measured memory_bytes: 85712
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			StringBuilder sb = new StringBuilder("Christmas");
			IntStream.range(0, 25 - n).forEach(i -> sb.append(" Eve"));
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 35848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC136A
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int A = int.Parse(word[0]);
            int B = int.Parse(word[1]);
            int C = int.Parse(word[2]);
            if (A>=B+C)
           {
                Console.WriteLine(0);
           }
           else if(A<B+C)
           {
                Console.WriteLine(B + C - A);
           }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = __int64_t;

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

//約数列挙(1を含む)
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i*i != n) res.push_back(n/i);
        }
    }
    return res;
}

void solve(){
    ll n, res=0;
    cin >> n;

    vector<ll> v = divisor(n);
    for(ll i = 0; i < v.size(); i++){
        ll t = v[i]-1;
        if(t != 0 && n/t == n%t){
            res += t;
        }
    }
    cout << res << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod  10000007
#define pii pair<int, int>
#define PI 2*acos(0.0)
#define forn(i, n) for(int i = 0; i < n; i++)


ll dp[105][100005];
vi wgt, val;

ll wolf(int n, int rem)
{
    if(n < 0 || rem <=  0)
        return 0;
    if(dp[n][rem] != -1)
        return dp[n][rem];
    ll p1 = INT_MIN, p2 = INT_MIN;
    p1 = wolf(n-1, rem);
    if(rem - wgt[n] >= 0)
        p2 = wolf(n-1, rem - wgt[n]) + val[n];
    return dp[n][rem] = max(p1, p2);
}

int main()
{
    io;
    int n, w;
    cin>>n>>w;
    for(int i = 0; i < n;i++)
    {
        int x, y;
        cin>>x>>y;
        wgt.pb(x);
        val.pb(y);
    }
    memset(dp, -1, sizeof(dp));
    cout<<wolf(n-1, w);
    return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 100;
  int l[max_n + 1];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];

  sort(l, l+n);

  int ans = 0;
  // for(int i = 0; i < n; i++) cout << l[i] << endl;

  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      for(int k = j+1; k < n; k++){
        if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
        if(l[i] + l[j] > l[k]) ans ++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
/*THERE'S ALWAYS SOMETHING , NOT THAT YOU WOULD UNDERSTAND . YOU ARE LIKE MY SISTER ,
 EVERYTHING ALWAYS CAME EASY TO HER .
 SHE'S A FIRE BENDING PRODIGY AND EVERY ONE ADORE HER . MY FATHER SAYS
 SHE WAS BORN LUCKY ,HE SAYS I WAS LUCKY TO BE BORN . I DON'T NEED LUCK THOUGH .
 I DON'T WANT IT . I'VE ALWAYS HAD TO STRUGGLE AND FIGHT
 AND THAT'S MADE ME STRONG . IT MADE ME WHO I AM .*/
#include<bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];  //dp[i] = length of longest path starting at i;
int solve(int src)
{
    if(dp[src]!=-1)return dp[src];
    bool leaf =1;
    int bestchild=0;
    for(int child:graph[src])
    {
        leaf=0;
        bestchild=max(bestchild,solve(child));
    }
    return dp[src]=leaf?0:1+bestchild;
}
main()
{
    int n,m;
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        graph[u].push_back(v);
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans=max(solve(i),ans);

    cout<<ans;
}






















































































































/* WHATEVER DOESNT KILL ME ONLY MAKES ME STRONGER .*/


Measured memory_bytes: 11408
#include<bits/stdc++.h>
using namespace std;
string a;
long long ans;
int main()
{
	cin>>a;
	if(a[0]!='C')
	ans++;
	if(a[1]!='O')
	ans++;
	if(a[2]!='D')
	ans++;
	if(a[3]!='E')
	ans++;
	if(a[4]!='F')
	ans++;
	if(a[5]!='E')
	ans++;
	if(a[6]!='S')
	ans++;
	if(a[7]!='T')
	ans++;
	if(a[8]!='I')
	ans++;
	if(a[9]!='V')
	ans++;
	if(a[10]!='A')
	ans++;
	if(a[11]!='L')
	ans++;
	if(a[12]!='2')
	ans++;
	if(a[13]!='0')
	ans++;
	if(a[14]!='1')
	ans++;
	if(a[15]!='6')
	ans++;
	cout<<ans<<endl;

	
 }

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

int x[1005];
int y[1005];
int r[1005];
double dp[1005];
int n;

double getDist(int i, int j) {
  double xx = x[i] - x[j];
  double yy = y[i] - y[j];
  double ret = sqrt(xx*xx + yy*yy);
  ret -= r[i];
  ret -= r[j];
  ret = max(0., ret);
  return ret;
}

void relax() {
  priority_queue<pdi> q;
  q.push({0, 0});
  while(!q.empty()) {
    pdi curr = q.top();
    q.pop();
    if(-curr.first != dp[curr.second]) continue;
    for(int i = 0; i < n; i++) {
      double nw = dp[curr.second] + getDist(curr.second, i);
      if(nw < dp[i]) {
        dp[i] = nw;
        q.push({-dp[i], i});
      }
    }
  }
}

void solve() {
  cin >> x[0] >> y[0] >> x[1] >> y[1] >> n;
  n += 2;
  for(int i = 2; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
  }
  for(int i = 1; i < n; i++) dp[i] = 1e18;
  relax();
  cout << fixed << setprecision(10) << dp[1] << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 6512
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N=nextInt();
		int T=nextInt();
		int A =nextInt();

		int[] H  = nextInts();

		int[] x = new int[N];
		for(int i=0;i<N;i++){
			x[i]=H[i];
		}
		Arrays.sort(x);

		double df=10000;
		int h =x[0];
		for(int i=0;i<N;i++){
			double tmp = T-x[i]*0.006;
			double d = Math.abs(A-tmp);
			if(df < d){
				break;
			}else{
				df=d;
				h=x[i];
			}
		}
		int ans = 0;
		for(ans=0;ans<N;ans++){
			if(H[ans]==h){
				break;
			}
		}


		System.out.println(ans+1);




	}




	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
const static int INT_INF = 2147483647;
const static int MOD_NUM = 1000000007;
static string S[2005] = { "" };

int main()
{
	int x, a;
	cin >> x >> a;
	int result;

	if (x >= a) result = 10;
	else result = 0;

	cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = pow(10, 9) + 7;
//const int mod = 998244353;
//const int mod = ;
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
  {
    cin >> V.at(i);
  }
  
  int ans = -INF;
  for (int a = 0; a <= K; a++)
  {
    for (int b = 0; b <= K; b++)
    {
      if (a + b > K) break;
      int aa = min(a, N);
      int bb = min(b, N - aa);
      int cd = min(K / 2, K - a - b);
      
      vector<int> hv;
      for (int i = 0; i < aa; i++)
      {
        hv.push_back(V.at(i));
      }
      for (int i = 0; i < bb; i++)
      {
        hv.push_back(V.at(N - i - 1));
      }
      
      sort(hv.begin(), hv.end(), greater<int>());
      //cout << hv.size() << " " << a << " " << b << " " << cd << endl;
      //cout << cd << " " << hv.size() << " ";
      cd = min((int)cd, (int)hv.size());
      
      int val = 0;
      for (int i = 0; i < hv.size(); i++)
      {
        if (hv.at(i) < 0 && i >= hv.size() - cd) break;
        val += hv.at(i);
      }
      chmax(ans, val);
      //cout << a << " " << b << " " << cd << " " << val << endl;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define N 100001
 
void degree(int);
int depth(int);
 
struct Node {
  int parent;
  int left;
  int right;
};
 
struct Node nodes[N];
int counter = 0;
 
int main(void) {
 
  int i, j, n, m, new_node, child, left, right;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++) {
    nodes[i].parent = -1;
    nodes[i].left = -1;
    nodes[i].right = -1;
  }
 
  for(i = 0; i < n; i++) {
    scanf("%d%d", &new_node, &m);
 
    for(j = 0; j < m; j++) {
      scanf("%d", &child);
  
      nodes[child].parent = new_node;
 
      if(j != 0) {
        nodes[left].right = child;
      } else {
        nodes[new_node].left = child;
      }
 
      left = child;
 
    }
  }
 
  for(i = 0; i < n; i++) {
 
    counter = 0;
 
    printf("node %d: parent = %d, depth = %d, ", i, nodes[i].parent, depth(i));
 
    if(nodes[i].parent == -1) {
      printf("root, [");
    } else if (nodes[i].left == -1) {
      printf("leaf, [");
    } else {
      printf("internal node, [");
    }  
 
    counter = 0;
    degree(nodes[i].left);
    printf("]\n");
  }
  return 0;
}
 
int depth(int node_num) {
 
  if(nodes[node_num].parent == -1) {
    return counter;
  } else {
    counter++;
    return depth(nodes[node_num].parent);
  }
 
}
 
void degree(int node_num) {
 
  if(node_num != -1) {
 
    if(counter != 0) {
      printf(", ");
    }
 
    printf("%d", node_num);
    counter++;
    degree(nodes[node_num].right);
     
  }
}

Measured memory_bytes: 1784
#include <stdio.h>

int main(){
  long long int x1, y1, x2, y2;
  scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
  int slope[] = {y1-y2, x2-x1};
  long long int x3, y3, x4, y4;
  x3 = x2 + slope[0], y3 = y2 + slope[1], x4 = x1 + slope[0], y4 = y1 + slope[1];
  printf("%lld %lld %lld %lld\n", x3, y3, x4, y4);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;

    if (a >= k) ans += k;
    else {
        if (a + b >= k) ans += a;
        else {
            ans += a;
            k -= a;
            k -= b;
            ans -= k;
        }
    }
    

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int h, w;
vector<string> s(2222);
vector<vector<ll>> a(2222, vector<ll>(2222, 0)), l(a), r(a), u(a), d(a);

void dbg(vector<vector<ll>>* v)
{
    FOR(i,1,h+1) {
        FOR(j,1,w+1) {
            cout<<(*v)[i][j];
        }
        putchar('\n');
    }
    putchar('\n');
}

int main()
{
    cin>>h>>w;
    REP(i,h) {
        cin>>s[i];
        REP(j,w) {
            a[i+1][j+1] = s[i][j] == '.' ? 1ll : s[i][j] == '#' ? 0ll : -INF;
        }
    }
    FOR(i,1,h+1) {
        FOR(j,1,w+1) {
            l[i][j] = a[i][j] * (l[i-1][j] + 1);
            //r[i][j] = a[i][j] * (r[i+1][j] + 1);
            u[i][j] = a[i][j] * (u[i][j-1] + 1);
            //d[i][j] = a[i][j] * (d[i][j+1] + 1);
        }
    }
    RFOR(i,h+1,1) {
        RFOR(j,w+1,1) {
            //l[i][j] = a[i][j] * (l[i-1][j] + 1);
            r[i][j] = a[i][j] * (r[i+1][j] + 1);
            //u[i][j] = a[i][j] * (u[i][j-1] + 1);
            d[i][j] = a[i][j] * (d[i][j+1] + 1);
        }
    }

    ll ans = 0ll;
    //dbg(&l); dbg(&r); dbg(&u); dbg(&d);
    FOR(i,1,h+1) {
        FOR(j,1,w+1) {
            int tmp = max(l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3, 0ll);
            //cout<<tmp;
            ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
        }
        //putchar('\n');
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 197632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
ans=0
for i in range(n):
  for j in range(i,n):
    #特定区間の配列要素の1つずつについて、所定の文字列にその1要素があるか。
    if all('ACGT'.count(c)==1 for c in s[i:j+1]):
      ans=max(ans,j-i+1)
print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		String op = sc.next();
		int b = Integer.parseInt(sc.next());

		if(op.equals("+")) {
			System.out.println(a + b);
		}else{
			System.out.println(a - b);
		}
	}
}

Measured memory_bytes: 21844
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h:usize = read();
    let w:usize = read();
    let mut grid:Vec<Vec<char>> = Vec::with_capacity(h);
    let mut b = 1;
    for _ in 0..h {
        let s:Vec<char> = read::<String>().chars().collect();
        b += s.iter().filter(|&&x| x == '#').count();
        grid.push(s);
    }
    if grid[0][0] == '#' {
        b -= 1;
    }
    if grid[h-1][w-1] == '#' {
        b -= 1;
    }

    let mut que = VecDeque::new();
    que.push_back((0, 0));

    let mut dist = vec![vec![0; w+1]; h+1];
    dist[0][0] = 0;

    let dy = vec![-1i64, 1, 0, 0];
    let dx = vec![0, 0, -1i64, 1];
    while !que.is_empty() {
        let v = que.pop_front().unwrap();

        for dir in 0..4 {
            let ny = (v.0 as i64 + dy[dir]) as usize;
            let nx = (v.1 as i64 + dx[dir]) as usize;

            if ny < 0 || ny >= h || nx < 0 || nx >= w {
                continue;
            }

            if grid[ny][nx] == '#' {
                continue;
            }

            if dist[ny][nx] != 0 {
                continue;
            }
            dist[ny][nx] = dist[v.0][v.1] + 1;
            que.push_back((ny, nx));
        }
    }
    if dist[h-1][w-1] == 0 {
        println!("-1");
    } else {
        println!("{}", h*w - dist[h-1][w-1] - b);
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m, sum = 0, ans = 0;
  cin >> n >> m;
  vector<ll> a(n);

  rep(i, n) cin >> a[i], sum += a[i];
  rep(i, n) if (sum <= a[i] * (4 * m)) ans++;

  cout << (ans >= m ? "Yes" : "No") << endl;
  return 0;
}


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

int main()
{
    string s;
    int n;
    bool flag = true;
    cin>>s>>n;
    for(int i = 0;i< n;i++)
    {
        int a,b;
        string add;
        cin>>a;
        if(a == 1)
        {
            flag = (!flag);
        }
        else
        {
            cin>>b>>add;
            if(flag)
            {
                if(b == 1)
                    s.insert(0,add);
                else
                    s.insert(s.length(),add);
            }
            else
            {
                if(b == 1)
                    s.insert(s.length(),add);
                else
                    s.insert(0,add);
            }


        }
    }

    if(!flag)
    {
        for(int i = s.length()-1;i>=0;i--)
        {
            cout<<s[i];
        }
    }
    else
        cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 900
mod = 10 ** 9 + 7
h, w, k = map(int, input().split())
k -= 1

dp = [0] * w
dp[0] = 1
ndp = [0] * w

for _ in range(h):
    for bits in range(1 << w - 1):
        if '11' in bin(bits): continue
        to = list(range(w))
        for i in range(w - 1):
            if (bits >> i) & 1:
                to[i], to[i + 1] = to[i + 1], to[i]
        for i in range(w):
            ndp[to[i]] += dp[i]
            ndp[to[i]] %= mod
    dp = ndp
    ndp = [0] * w
print(dp[k])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,t;
  cin>>n>>t;
  vll a(n);
  ll ans=0;
  rep(i,n) cin>>a[i];
  for(int i=1;i<n;i++){
    if(a[i]-a[i-1]<t){
      ans+=a[i]-a[i-1];
    }
    else{
      ans+=t;
    }
  }
  ans+=t;
  COUT(ans);
}


Measured memory_bytes: 1792
import copy

def partition(A,p,r):
    x = A[r][1]
    i = p-1
    # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く
    for j in range(p,r):
        if A[j][1] <= x:
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

def quickSort(A,p,r):
    if p < r:
        q = partition(A,p,r)
        quickSort(A,p,q-1)
        quickSort(A,q+1,r)

N = int(input())
card = [input().split() for i in range(N)]
for i in range(N):
    card[i][1] = int(card[i][1])

card2 = copy.deepcopy(card)
card2.sort(key=lambda x: x[1])

quickSort(card,0,N-1)
#print(card)
#print(card2)

ans = 'Stable'
for i in range(N):
    if card[i][0] != card2[i][0]:
        ans = 'Not stable'
        break
print(ans)
for i in range(N):
    print(' '.join(map(str,card[i])))



Measured memory_bytes: 47392
#include<iostream>
int main(){
	int nod[1001];
	int N;
	int m;
	int i;
	int j;
	long long int total_of_divisor=1; 

	for(i=0;i<=1000;i++)
		nod[i] = 0;
	
	std::cin >> N;

	// N以下の整数の約数の個数をそれぞれ求める
	for(i=2;i<=N;i++){
		// std::cout << i << '\n';
		j=2; // 調べる約数
		m=i;
		while(1){
			// iがjで割り切れなくなるまで割り算をする
			while(1){
				if(m%j!=0) break;
				else{
				m=m/j;
				nod[j]++;
				// std::cout << m << ' ' << j << '\n';
				}
			}
			j++;
			if(m == 1) break;
		}
	}

	for(i=1;i<=N;i++){
		total_of_divisor *= (nod[i] + 1);
		total_of_divisor = total_of_divisor % 1000000007;
		// std::cout <<i << ' ' << nod[i] << '\n';
		//std::cout << total_of_divisor << '\n';
	}

	std::cout << total_of_divisor << '\n';
	return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    ll ans=0;
    map<ll,ll> m;
    for (int i=0;i<N;++i) ans+=m[A[i]-i],++m[-A[i]-i];
    cout << ans << '\n';
}

Measured memory_bytes: 26692
#include<bits/stdc++.h>
#define LL long long
#define ffor(i,s,n) for(int i=(s);i<(n);i++)
#define efor(i,s,n) for(int i=(s);i<=(n);i++)
using namespace std;

LL inn;

int main(){
	
	cin>>inn;
	if(!(inn%2)){
		cout<<inn<<endl;
	}else 
		cout<<(inn<<1)<<endl;

    
    return 0;

}


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

using namespace std;

typedef int in;
#define int long long

in main(){
    int n,m,mn = INT_MAX,mx = 0;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i ++){
        int x,y;
        cin >> x >> y;
        mx = max(x,mx);
        mn = min(mn,y);
    }
    cout << max((int)0,mn - mx + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    string s; cin >> s;
    int win = 0;
    for(int i=0; i<s.size(); i++) if(s[i] == 'o') win++;

    if(win + 15-s.size() >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
# %% constants
# ------------

# %% body
# -------

function main(io = stdin)
    readto(target = '\n') = readuntil(io, target)
    readnum(T::Type{<:Number} = Int; dlm = isspace, kwargs...) =
        parse.(T, split(readto(), dlm; kwargs...))

    # handle IO and and stuff
    N, = readnum()
    c = readto()
    println(solve(N, c))
end

function solve(N, c)
    s = IOBuffer(c)
    rs = IOBuffer(reverse(c))

    wf = 1 + length(readuntil(s, 'W'))
    rl = N - length(readuntil(rs, 'R'))
    cnt = 0

    while rl > wf
        wf += 1 + length(readuntil(s, 'W'))
        rl -= 1 + length(readuntil(rs, 'R'))
        cnt += 1
    end
    return cnt
end

@static if @isdefined(Juno) || @isdefined(VSCodeServer)
    main(open(replace(@__FILE__, r"(.+)\.jl" => s"\1.in")))
else
    main()
end


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int mod[200001];
ll a[2020];

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

    int p = 2019, t = 0, b = 1, l = s.size();
    a[0] = 1;
    for (int i = l - 1; i >= 0; --i) {
        t += (s[i] - '0') * b;
        t %= p;
        b *= 10;
        b %= p;
        a[t]++;
    }

    ll ans = 0;
    for (int i = 0; i <= p; ++i) {
        ans += (a[i] * (a[i] - 1) / 2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3780
n = int(input())
ans = 0
if n == 1 or n == 2 or n == 3:
    ans = 1
for i in range(2, 10001):
    b = i
    c = i
    cnt = 0
    while True:
        if c*b > n:
            break
        cnt += 1
        c *= b
    if cnt != 0:
        ans = max(ans, c)

print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.q = l
        heapq.heapify(self.q)
        return

    def push(self, n):
        heapq.heappush(self.q, n)
        return

    def pop(self):
        return heapq.heappop(self.q)


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    X = Scanner.int()
    ans = (X // 500) * 1000
    X %= 500
    ans += (X // 5) * 5
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62444
from itertools import permutations
n=int(input())
x=list(permutations([list(map(int,input().split())) for _ in range(n)]))
c=0.0
for i in x:
  a=i[0][0]
  b=i[0][1]
  for j in i[1:]:
    c+=((j[0]-a)**2+(j[1]-b)**2)**.5
    a=j[0]
    b=j[1]
print(c/len(x))

Measured memory_bytes: 74184
#include <bits/stdc++.h>
using namespace std;
struct Tree{
  Tree *left, *right;
  int32_t *key;
  Tree(): left(nullptr), right(nullptr), key(nullptr){}
  void insert(int32_t x){
    if(Tree::key==nullptr) Tree::key=new int32_t(x);
    else{
      if(x<*Tree::key){
        if(Tree::left==nullptr) Tree::left=new Tree;
        Tree::left->insert(x);
      } else{
        if(Tree::right==nullptr) Tree::right=new Tree;
        Tree::right->insert(x);
      }
    }
  }
  bool find(int32_t x){
    if(Tree::key==nullptr) return false;
    if(x<*Tree::key){
      if(Tree::left==nullptr) return false;
      return Tree::left->find(x);
    } else if(x>*Tree::key){
      if(Tree::right==nullptr) return false;
      return Tree::right->find(x);
    } else{
      return true;
    }
  }
  void preorder(){
    if(Tree::key!=nullptr){
      cout<<' '<<*Tree::key;
      if(Tree::left!=nullptr) Tree::left->preorder();
      if(Tree::right!=nullptr) Tree::right->preorder();
    }
  }
  void inorder(){
    if(Tree::key!=nullptr){
      if(Tree::left!=nullptr) Tree::left->inorder();
      cout<<' '<<*Tree::key;
      if(Tree::right!=nullptr) Tree::right->inorder();
    }
  }
};

int32_t main(){
  size_t n; cin>>n;
  Tree tree;
  string cmd;
  int32_t key;
  for(int i=0; i<n; ++i){
    cin>>cmd;
    switch(cmd[0]){
      case 'i': cin>>key; tree.insert(key); break;
      case 'f': cin>>key; cout<<(tree.find(key)?"yes\n":"no\n"); break;
      default: tree.inorder(); cout<<'\n'; tree.preorder(); cout<<'\n';
    }
  }
}


Measured memory_bytes: 28068
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll d, s, t;
    cin >> d >> s >> t;
    cout << (d <= s * t ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3648
N,K = map(int,input().split())

res = 0

if K == 0:
	res = N * N
else:
	for b in range(1,N+1):
		p = N // b
		r = N % b
		res += p * max(0,b-K)
		res += max(0,r - K + 1)

print(res)

Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * 解説通り実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long nowT = 1, nowA = 1;
			for (int i = 0; i < n; i++) {
				int t = scanner.nextInt(), a = scanner.nextInt();
				long m = Math.max((nowT - 1 + t) / t, (nowA - 1 + a) / a);
				nowT = m * t;
				nowA = m * a;
			}
			System.out.println(nowT + nowA);
		}
	}
}


Measured memory_bytes: 39828
#include <stdio.h>
#include <string>
void foobar(bool b[], char foo) {
  for (int k = 0; k < 13; k++) {
    if (b[k]) printf("%c %d\n", foo, k+1);
  }
}
int main() {
    bool sCard[13],hCard[13],cCard[13],dCard[13];
    for (int i = 0; i < 13; i++) sCard[i] = hCard[i] = cCard[i] = dCard[i] = true;
    int n;
    char ch;
    int num;
    scanf("%d", &n);
    while (scanf("%s %d", &ch, &num) != EOF) {
        int tmp = num - 1;
        if (ch == 'S') sCard[tmp] = false;
        if (ch == 'H') hCard[tmp] = false;
        if (ch == 'C') cCard[tmp] = false;
        if (ch == 'D') dCard[tmp] = false;
    }
    foobar(sCard,'S');
    foobar(hCard,'H');
    foobar(cCard,'C');
    foobar(dCard,'D');
    return 0;
}



Measured memory_bytes: 2756
from collections import defaultdict

class UnionFind:
    def __init__(self, N):
        # negative value: represents the root of a tree; its absolute value is the size of the tree
        # positive value: the parent's index
        self.vertices = [-1 for _ in range(N)]
        self.rank = [0] * N
        
    def find(self, v):
        if self.vertices[v] < 0: # v is a root
            return v
        else:
            # path compression: reconnect v to the root
            self.vertices[v] = self.find(self.vertices[v])
            return self.vertices[v]
        
    def union(self, u, v):
        s1 = self.find(u) # the root of the tree including vertex u
        s2 = self.find(v) # the root of the tree including vertex v
        
        if s1 == s2: # u and v is in the same tree
            return False
        
        if self.rank[s1] > self.rank[s2]: # the tree including u is taller
            self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree
            self.vertices[s2] = s1
        else: # the tree including v is taller
            self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree
            self.vertices[s1] = s2
            if self.rank[s1] == self.rank[s2]:
                self.rank[s2] += 1
        return True
        
    def is_connected(self, u, v):
        return self.find(u) == self.find(v)
    
    def size(self, v):
        return -self.vertices[self.find(v)]

N, K, L = map(int, input().split())
road = UnionFind(N)
rail = UnionFind(N)
for _ in range(K):
    p, q = map(int, input().split())
    road.union(p-1, q-1)
for _ in range(L):
    r, s = map(int, input().split())
    rail.union(r-1, s-1)
comp = defaultdict(int)
tpls = []
for i in range(N):
    t = (road.find(i), rail.find(i))
    comp[t] += 1
    tpls.append(t)
print(*[comp[t] for t in tpls])

Measured memory_bytes: 46524
from collections import defaultdict
from operator import itemgetter
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 1000
for n in range(2**N):
    n = bin(n)[2:]
    if n.count('1')%2!=0:
        continue
    n = '0'*(N-len(n))+n
    l = []
    for i in range(N):
        if n[i]=='0':
            l.append([A[i],i])
        else:
            l.append([B[i],i+1])
    inversion = 0
    for i in range(N):
        if inversion>=ans:
            break
        for j in range(i+1,N):
            if l[i][0]>l[j][0]:
                inversion += 1
    if inversion>=ans:
        continue
    l.sort(key=itemgetter(0))
    d = defaultdict(list)
    for i in range(N):
        v,j = l[i]
        if (i-j)%2==1:
            d[v].append(i)
    possible = True
    for v in d:
        if len(d[v])%2==1:
            possible = False
        else:
            for i in range(len(d[v])//2):
                if (d[v][2*i+1]-d[v][2*i])%2==1:
                    inversion += d[v][2*i+1]-d[v][2*i]
                else:
                    possible = False
                    break
        if not possible:
            break
    if possible:
        ans = min(ans,inversion)

if ans == 1000:
    ans = -1
print(ans)

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

using namespace std;

int main(){
	int a, b, c, k;
	cin>>a>>b>>c>>k;
	int ans=0;
	if(k>0){
		ans+=min(k,a);
		k=max(k-a,0);
	}
	if(k>0){
		k=max(k-b,0);
	}
	if(k>0){
		ans-=min(k,c);
		k=max(k-c,0);
	}
	cout<<ans<<"\n";
}



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

int main() {
	int n; cin >> n; vector<stack<int>> vec(n); int temp;
	for (int i = 0; i < n; i++) {
		cin >> temp; vec[temp - 1].push(i);
	}
	vector<int> ans(n, -1); stack<int> st;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < n; j++) {
			while (!vec[j].empty()) {
				st.push(vec[j].top()); vec[j].pop();
			}
			if (ans[j] == -1 && !st.empty()) {
				ans[j] = st.top(); st.pop();
			}
		}
	for (int i = 0; i < n; i++) cout << ans[i] + 1 << endl;
	return 0;
}


Measured memory_bytes: 70956
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	const vector<string> S = { "AC", "WA", "TLE", "RE" };

	int N;
	cin >> N;
	vector<int> ans(4);
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < 4; j++) {
			if (S[j] == s) ans[j]++;
		}
	}

	for (int i = 0; i < 4; i++) {
		cout << S[i] << " x " << ans[i] << "\n";
	}

	return 0;
}



Measured memory_bytes: 3648
n = input()
s = int(n[len(n)-1])
if s == 2 or s == 4 or s == 5 or s == 7 or s == 9:
    print('hon')
elif s == 0 or s == 1 or s == 6 or s == 8:
    print('pon')
elif s == 3:
    print('bon')

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define ll long long
using namespace std;
pair<int,int> M1[400009],M2[400009],ans[400009];
int a[400009];
main(){
   int n;
   cin >> n;
   for(int i = 0 ; i < (1<<n); i++){
        cin >> a[i];
        M1[i] = {a[i],i}, M2[i] = {-1,-1};

   }
   for(int k = 0; k < n; k++)
   for(int i = 0; i < (1<<n); i++)
        if( i & (1 << k) ){
            int j = (i ^ (1 << k));
            vector<pair<int,int> > v = {M1[i], M2[i], M1[j], M2[j]};
            sort(v.begin(),v.end());
            M1[i] = v[3];
            if(v[2] != v[3]) M2[i] = v[2];
            else if(v[1] != v[3]) M2[i] = v[1];
            else M2[i] = v[0];
        }
    int ans = 0;
    for(int i = 1; i < (1<<n); i++){
        ans = max(ans, M1[i].first + M2[i].first);
        cout << ans <<endl;
    }

}


Measured memory_bytes: 10240
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<ctime>
#include<map>
#include<vector>
#include <tr1/unordered_map>
using namespace std;
#define N 200005
#define REP(i,a,b)	for(int i=a;i<=b;i++)
#define DOW(i,a,b)	for(int i=a;i>=b;i--)
#define MOD 998244353
#define Mod(x)	((x)>=MOD?(x)-MOD:(x))
#define INF 0x3f3f3f3f
#define size_int (sizeof(int)) 
#define SP 1664515
#define magicnum 2147483647
using namespace std::tr1;


int f[90005],g[90005],s[90005];

int Pow(int i,int k){
	int ans=1;
	for(;k;k>>=1,i=1ll*i*i%MOD)if(k&1)ans=1ll*ans*i%MOD;
	return ans;
}


int main(){
//	freopen("read.in","r",stdin);
//	freopen("my.out","w",stdout);
    int n,sum=0;
    scanf("%d",&n);
    f[0]=1;s[0]=1;
    REP(i,1,n){
    	int v;
    	scanf("%d",&v);
    	REP(j,0,sum)g[j]=Mod(2*f[j]);
    	DOW(j,sum,0)s[j+v]=Mod(s[j+v]+s[j]);
    	DOW(j,sum,0)g[j+v]=Mod(g[j+v]+f[j]);
    	sum+=v;
    	REP(j,0,sum)f[j]=g[j];
    }
//    printf("%d ???\n",f[2]);
    int ans=Pow(3,n),tmp=0;
    REP(i,(sum+1)/2,sum)tmp=Mod(tmp+3ll*f[i]%MOD);
    if(sum%2==0)tmp=Mod(tmp-3ll*s[sum/2]%MOD+MOD);
    printf("%d",(ans-tmp+MOD)%MOD);
    return 0;
} 

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


int main() {
  
  int N;
  long long x,y,z;
  long long M = 1000000007;

  cin >> N;
  x = 1, y = 1, z = 2;
  for(int i=0;i<N;++i){
    x = ((x % M) * 10) % M;
    y = ((y % M) * 8) % M;
    z = ((z % M) * 9) % M;
  }

  cout << (x - z + y + M) % M<< endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

//B - Card Game for Two
//ソート問題
//Greedy(貪欲算法)
int main(){
    int N;
    int a[110];
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }

    sort(a, a + N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for(int i = 0; i < N; ++i){
        if(i%2 == 0){
            Alice += a[i];
        }else{
            Bob += a[i];
        }
    }

    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int M=998244353;
const int maxn=3e5+6;
int n,a[maxn],c[3];
ll ans;
vector <int> r,g,b;
char s[maxn];
int main(){
    cin >> n >> s+1;
    for (int i=1;i<=n*3;i++) {
        if (s[i]=='R') r.pb(i);
        if (s[i]=='G') g.pb(i);
        if (s[i]=='B') b.pb(i);
    }
    for (int i=0;i<n;i++){
        c[0]=r[i]; c[1]=g[i]; c[2]=b[i];
        sort(c,c+3);
        for (int j=0;j<3;j++) a[c[j]]=j;
    }
    c[0]=c[1]=c[2]=0;
    ans=1;
    for (int i=1;i<=n*3;i++){
        c[a[i]]++;
        if (a[i]==0) ans=ans*c[a[i]]%M; else ans=ans*(c[a[i]-1]-c[a[i]]+1)%M;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  long long X;
  cin >> X;
  for (long long A = -200; A <= 200; ++A) {
    for (long long B = -200; B <= 200; ++B) {
      if (A * A * A * A * A - B * B * B * B * B == X) {
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;


int n;
string ans;

int main(){
  cin >> n;
  if(n == 0){
    cout << "0"<<endl;
    return 0;
  }
  while(n!=0){
    if(n%2){
      ans = "1" + ans;
      n--;
    }else{
      ans = "0" + ans;
    }
    n /= -2;
  }
  cout << ans <<endl;
}
  

Measured memory_bytes: 256