akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    int A=in();
    int B=in();
    int n=1;
    int ans=0;
    while(n<B){
        n+=A-1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  map<int, int> mapp;
  for (int i = 0; i < n; i++) {
    pair<int, int> p;
    p.second = i;
    cin >> p.first;
    mapp.insert(p);
  }
  for (auto it = mapp.begin(); it != mapp.end(); it++) {
    cout << it->second + 1 << " ";
  }
  return 0;
}

Measured memory_bytes: 5504
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}

 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    } else{
    x = x->right;
    }
  }
      z->parent = y;
     
    if(y==NIL){
      root = z;
    }
    else if(z->key < y->key){
      y->left =z;
    }
    else y-> right =z;
     
 
}
 
void inorder(Node u){
  if( u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u !=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
 
 
int main(){
  int n, i, x;
   char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
 
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  
  }
 
  return 0;
}

Measured memory_bytes: 19364
import random

n = int(input())
p = [float(i) for i in input().split()]

# dp[i][j] = i番目までのコインを振ったとき、表の数がj枚となる確率
dp = [[0.0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1.0

for i in range(n):
    for j in range(n):
        # 表のとき
        dp[i+1][j+1] += dp[i][j] * p[i]
        # 裏のとき
        dp[i+1][j] += dp[i][j] * (1 - p[i])

ans = sum(dp[-1][n//2+1:])
print(ans)


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

int main() {
	stack<int> s; int n, temp; cin >> n;
	for (int i = 0; i < n; i++) { cin >> temp; s.push(temp); }
	for (int i = 0; i < n; i++) {
		cout << s.top() << (i != n - 1 ? " " : ""); s.pop();
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
using namespace std;
int N,K,A[20];
int S[1<<20];
bool exs[1<<20];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	int ans=0;
	for(int i=0;i<1<<N;i++)
	{
		for(int j=0;j<N;j++)if(i>>j&1)S[i]+=A[j];
		exs[i]=S[i]==K;
		for(int j=0;j<N;j++)
		{
			if(i>>j&1)exs[i]|=exs[i&~(1<<j)];
		}
		if(!exs[i])ans=max(ans,__builtin_popcount(i));
	}
	cout<<N-ans<<endl;
}



Measured memory_bytes: 8220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    bool b=true;
    rep(i,n){
        int a; cin>>a;
        if(a%2==1)b=false;
    }
    cout<<(b?"second":"first")<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;

bool vis[man];
int prime[man],phi[man];

void init(int maxn){
	phi[1] = 1;
	vis[1] = 1;
	int cnt = 0;
	for(int i = 2;i <= maxn;i++){
		if(!vis[i]){
			prime[cnt++] = i;
			phi[i] = i-1;
		}
		for(int j = 0;j < cnt && i * prime[j] <= maxn;j++){
			vis[i*prime[j]] = 1;
			phi[i*prime[j]] = phi[i]*phi[prime[j]];
			if(i%prime[j]==0){
				phi[i*prime[j]] = phi[i]*prime[j];
				break;
			}
		}
	}
	for(int i = 1;i <= maxn;i++){
		phi[i] = (phi[i-1] + phi[i])%mod;
	}
}

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

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	int n,k;
	cin >> n >> k;
	init(k+5);
	ll ans = 0;
	for(int l = 1,r = 0;l <= k;l = r + 1){
		r = k / (k / l);
		ans = (ans + quick_mod(k/l,n)*(phi[r] - phi[l-1] + mod)%mod) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4160
function Main(input) {
    input = input.split("").map(Number);
    var arr = [0,0];
    input.forEach(function(val){
        arr[val]++;
    })
    console.log(arr[0]+arr[1]-Math.abs(arr[0]-arr[1]));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 13772
#!/usr/bin/env python3
 
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,L;
vector<pair<int,int>> E[303];

int dp[303];
int cost[303][303];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>L;
	FOR(i,M) {
		cin>>x>>y>>r;
		if(r<=L) {
			E[x-1].push_back({y-1,r});
			E[y-1].push_back({x-1,r});
		}
	}
	
	FOR(x,N) FOR(y,N) cost[x][y]=(x==y?0:10000);
	
	MINUS(dp);
	FOR(x,N) {
		FOR(y,N) dp[y]=-1;
		dp[x]=L;
		priority_queue<pair<int,int>> PQ;
		PQ.push({-L,x});
		while(PQ.size()) {
			int f=-PQ.top().first;
			int cur=PQ.top().second;
			PQ.pop();
			if(dp[cur]!=f) continue;
			
			FORR(e,E[cur]) if(f-e.second>dp[e.first]) {
				dp[e.first]=f-e.second;
				PQ.push({-dp[e.first],e.first});
			}
		}
		FOR(y,N) if(dp[y]>=0) cost[x][y]=1;
	}
	
	
	FOR(r,N) FOR(x,N) FOR(y,N) cost[x][y]=min(cost[x][y],cost[x][r]+cost[r][y]);
	
	int Q;
	cin>>Q;
	while(Q--) {
		cin>>x>>y;
		x--,y--;
		if(cost[x][y]>=1000) cout<<-1<<endl;
		else cout<<cost[x][y]-1<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int main() {
    int n, k; cin >> n >> k;
    vector<int> v(n); rep(i, n) cin >> v[i];
    int maxval = 0;
    //左端から最大何個取るか
    rep(i, k + 1) {
        //int numi = i;
        
        //残り右端から取れる
        rep(j, k - i + 1) {
            if (i + j > n) continue;
            vector<int> vv;
            //int numj = j;
            //if (numi * numi * (numi + 1) / 2 + numj * numj * (numj + 1) / 2 > k) continue;
            //cout << i << " " << j << endl;
            rep(kk, i) vv.push_back(v[kk]);
            rep(kk, j) vv.push_back(v[n - 1 - kk]);
            sort(vv.begin(), vv.end());
            //rep(kk, vv.size()) cout << vv[kk] << " "; cout << endl;
            int val = 0;
            rep(kk, vv.size()) {
                if (kk < k - (i + j)) {
                    if (vv[kk] < 0) continue;
                }
                //if (vv[kk] < 0) vv.erase(vv.begin());
                //else break;
                val += vv[kk];
            }
            //rep(kk, vv.size()) val += vv[kk];
            /*
            rep(kk, i){
                if (v[kk] > 0) val += v[kk];
            }
            rep(kk, j) {
                if (v[k - 1 - kk] > 0) val += v[k - 1 - kk];
            }
             */
            
            //cout << val << endl;
            chmax(maxval, val);
            
        }
    }
    cout << maxval << endl;
}


Measured memory_bytes: 256
/*

import "core"
import "procon"

fn break() $[importc, patternc "break"]

fn main() {
  sp := read_int()
  cp := read_int()

  sum := 0
  if (sp*2 <= cp) {
    sum += sp
    cp -= sp*2
    sum += cast[Int](cp / 4)
  } else {
    sum += cast[Int](cp / 2)
  }
  println(sum)
}

main()

*/

#include "stdbool.h"
#include "stdint.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "inttypes.h"


struct core_string_String {
char* p;
int64_t len;
};
struct Array1024_core_prelude_Char { char data[1024]; };



bool core_prelude_true;
bool core_prelude_false;
bool core_definitions_is_windows;
bool core_definitions_is_compiletime;
bool core_definitions_is_runtime;
bool core_definitions_is_jscodegen;
float core_math_M_PI;
void* core_pointer_nullGG_() {
void* core_pointer_tmpid27 = ((void*)(0));
return core_pointer_tmpid27;
}
void* core_pointer_null;
char* core_pointer_plusexclGcore_prelude_CharG_core_pointer_Ptr_core_prelude_Char_core_prelude_Int(char* core_pointer_p, int64_t core_pointer_i) {
return ((char*)((((int64_t)(core_pointer_p)) + core_pointer_i)));
}
char core_string_getGG_core_prelude_CString_core_prelude_Int(char* core_string_cs, int64_t core_string_i) {
char core_string_tmpid28 = (*(core_pointer_plusexclGcore_prelude_CharG_core_pointer_Ptr_core_prelude_Char_core_prelude_Int(((char*)(core_string_cs)), core_string_i)));
return core_string_tmpid28;
}
char core_string_charGG_core_prelude_Int(int64_t core_string_c) {
char core_string_tmpid30 = ((char)(core_string_c));
return core_string_tmpid30;
}
char core_string_cr;
char core_string_lf;
int64_t procon_read_intGG_() {
int64_t procon_ret;
scanf("%" PRId64, &procon_ret);
int64_t procon_tmpid46 = procon_ret;
return procon_tmpid46;
}
bool procon_is_debug;
void c_mainGG_() {
int64_t c_sp = procon_read_intGG_();
int64_t c_cp = procon_read_intGG_();
int64_t c_sum = 0;
if (((c_sp * 2) <= c_cp)) {
(c_sum += c_sp);
(c_cp -= (c_sp * 2));
double __floritmp1 = (((double)(c_cp)) / ((double)(4)));
(c_sum += ((int64_t)(__floritmp1)));
} else {double __floritmp2 = (((double)(c_cp)) / ((double)(2)));
(c_sum += ((int64_t)(__floritmp2)));
}printf("%lld", c_sum);
;
;
printf("%s", "\n");
;
;
;
}

void flori_main() {
core_prelude_true = 1;
core_prelude_false = 0;
core_definitions_is_windows = 
#ifdef _WIN32
#define is_windows true
#elif _WIN64
#define is_windows true
#else
#define is_windows false
#endif
  is_windows;
core_definitions_is_compiletime = 
#ifdef FLORI_COMPILETIME
#define is_compiletime true
#else
#define is_compiletime false
#endif
  is_compiletime;
core_definitions_is_runtime = !(core_definitions_is_compiletime);
core_definitions_is_jscodegen = 
#ifdef FLORI_JSCODEGEN
#define is_jscodegen true
#else
#define is_jscodegen false
#endif
  is_jscodegen;
core_math_M_PI = M_PI;
core_pointer_null = core_pointer_nullGG_();
core_string_cr = core_string_charGG_core_prelude_Int(13);
core_string_lf = core_string_charGG_core_prelude_Int(10);
procon_is_debug = core_prelude_true;
c_mainGG_();
}
int main(int argc, char** argv) { flori_main(); }


Measured memory_bytes: 128
N = int(input())
X = [int(x) for x in input().split()]

m = int(sum(X)/len(X))

score1 = 0
score2 = 0
for x in X:
  score1 += (x-m)**2
  score2 += (x-(m+1))**2

print(min(score1,score2))

Measured memory_bytes: 3060
#include <stdio.h>
int main(){

    char ch;

    while(1){
        scanf("%c", &ch);
        if('a' <= ch && ch <= 'z'){
            ch -= 32;
        }
        else if('A' <= ch && ch <= 'Z'){
            ch += 32;
        }
        printf("%c", ch);

        if(ch == '\n') break;
    }

    return 0;
}


Measured memory_bytes: 2052
// think twice code once
// Start:[]
// End  :[]
/*{{{*/
#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for(int i = (x), _ = (y); i <= _; ++ i)
#define per(i, x, y) for(int i = (x), _ = (y); i >= _; -- i)
#define dprintf(...) fprintf(stderr, __VA_ARGS__)
#define disp(x) cout << #x << " = " << x << "; "
#ifdef __linux__
#define getchar getchar_unlocked
#define LLFORMAT "%lld"
#else
#define LLFORMAT "%I64d"
#endif

typedef long long LL;

template <class T> bool chkmin(T& a, T b) { return a > b ? a = b, true : false; }
template <class T> bool chkmax(T& a, T b) { return a < b ? a = b, true : false; }

template <class T> void read(T& a) {
	char c = getchar(); T f = 1; a = 0;
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) a = a * 10 + c - '0';
	a *= f;
}
/*}}}*/

int a, b;

int main()
{
#ifdef Leeson
	freopen("tmp.in", "r", stdin);
	freopen("tmp.out", "w", stdout);
#endif

	read(a); read(b);
	if(a == 1) a = 14;
	if(b == 1) b = 14;
	if(a > b) puts("Alice");
	else if(a == b) puts("Draw");
	else puts("Bob");
	return 0;
}


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

// 互いに交換し合える数字たちを1つのグループにまとめる
// そのグループ内に存在する数字たちの中に，数列のi番目にある数字と数字iが同居していれば，必ず数字iは数列のi番目に到達することができる
// 数字をまとめる・同一グループ判定する => union-find tree

struct UnionFind {
    vector<int> parents;

    UnionFind(int size) : parents(size) {
        for (int i = 0; i < size; i++) parents[i] = i;
    }

    int root(int x) {
        if (parents[x] == x) {
            return x;
        }
        return parents[x] = root(parents[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parents[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M; cin >> N >> M;

    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }

    UnionFind tree(N);

    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        x--; y--;
        tree.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (tree.same(i, P[i]-1)) { // 数列のi番目の数字と数字iが可換なグループにいるなら必ず数列のi番目に数字iを置くことができる
            ans++;
        }
    }

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

Measured memory_bytes: 1024
#include <cstdio>

void bubleSort(int a[],int n){
    int i, j, tmp;
    for(i=0; i <n-1; i++){
        for(j=0; j <n-1; j++){
            if(a[j]>a[j+1]){
                tmp=a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
            }   
        }
    }
}

int main(){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);   
    int ary[3]={a,b,c};
    bubleSort(ary,3);
    printf("%d %d %d\n",ary[0], ary[1], ary[2]);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FU(i,a,b) for(register int i = a ; i <= b ; ++i)
#define FD(i,a,b) for(register int i = a ; i >= b ; --i)
#define set_max(a) memset(a,0x3f,sizeof a)
#define set_min(a) memset(a,~0x3f,sizeof a)
#define clear(a) memset(a,0,sizeof a)

using namespace std;

template<typename T>inline void chkmax(T & a,T b){ if(a < b) a = b ; }
template<typename T>inline void chkmin(T & a,T b){ if(a > b) a = b ; }

template<typename T>
inline T read()
{
	int res = 0 , flag = 1 ;
	char ch = getchar();
	while(!isdigit(ch))
	{
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch))
	{
		res = (res << 3) + (res << 1) + ch - '0';
		ch = getchar();
	}
	return res * flag;
}

template<typename T>
inline void write(T x)
{
	if(x/10) write(x/10);
	putchar(x%10+'0');
}

const int INF=0x3f3f3f3f;
const int N=4e1;
int n,m,hx,hy;
int ice[N+5][N+5],dp[N+5][N+5][N+5][N+5];

inline void Input()
{
	n = read<int>(); m = read<int>();

	char ch;
	for(register int i = 1 ; i <= n ; ++i)
	 for(register int j = 1 ; j <= m ; ++j)
	 {
		cin >> ch;
		ice[i][j] = ice[i-1][j] + ice[i][j-1] -ice[i-1][j-1] + (ch == '#');
		if(ch == 'P') { hx = i ; hy = j ; }
	 }
}

inline int thick(int dx,int dy,int rx,int ry)
{
	//if(dx > rx || dy > ry) return 0;
	return ice[rx][ry] - ice[rx][dy-1] - ice[dx-1][ry] + ice[dx-1][dy-1];
}

inline int MIN(int a,int b,int c,int d)
{
	return min(min(a,b),min(c,d));
}

inline void Solve()
{
	int ans = INF;
	set_max(dp);
	dp[1][1][n][m] = 0;
	for(register int i = 1 ; i <= hx ; ++i)
	 for(register int j = 1 ; j <= hy ; ++j)
	  for(register int k = n ; k >= hx ; --k)
	   for(register int p = m ; p >= hy ; --p)
	   {
			chkmin(ans , dp[i][j][k][p] + MIN(thick(i,j,hx,hy),thick(hx,hy,k,p),thick(hx,j,k,hy),thick(i,hy,hx,p)));
			for(register int s = i ; s <= k ; ++s)
			 for(register int t = j ; t <= p ; ++t)
			 {
				 if(s >= hx && t >= hy) chkmin(dp[i][j][s][t],dp[i][j][k][p] + thick(s+1,j,k,t) + thick(i,t+1,s,p));
				 if(s <= hx && t <= hy) chkmin(dp[s][t][k][p],dp[i][j][k][p] + thick(s,j,k,t-1) + thick(i,t,s-1,p));
				 if(s >= hx && t <= hy) chkmin(dp[i][t][s][p],dp[i][j][k][p] + thick(i,j,s,t-1) + thick(s+1,t,k,p));
				 if(s <= hx && t >= hy) chkmin(dp[s][j][k][t],dp[i][j][k][p] + thick(i,j,s-1,t) + thick(s,t+1,k,p));
			 }
	   }

	write(ans); putchar('\n');
}

inline void File()
{
	freopen("haner.in","r",stdin);
	freopen("haner.out","w",stdout);
}

int main()
{
	//File();

	Input();
	Solve();

	return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
	int N, K;
	cin >> N;
	cin >> K;
	//if(N <= K){
	//	cout << "NO" << endl;
	//	return 0;
	//}

	//int cnt = 0;
	//for(int i=1; i<=N; i+=2){
	//	if(i+2 <= N){ cnt++; }
	//}
	int cnt = 0;
	if(N%2 == 0){
		cnt = N / 2;
	} else {
		cnt = N / 2 + 1;
	}
	if(cnt >= K){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

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

int main(){
        string s;
        getline(cin ,s);

        size_t n = s.length();

        for(int i = 0; i < n; i++){
                if((bool)islower(s[i]) ==true ){
                        s[i] = toupper(s[i]);
                }else if((bool)isupper(s[i] )== true){
                        s[i] = tolower(s[i]);
                }

        cout << s[i];
        }cout << endl;
}


Measured memory_bytes: 3136
def f(n,x):
    if n==0:
        return 1
    elif x==1:
        return 0
    elif x==b_memo[n]//2+1:
        return p_memo[n-1]+1
    elif x<=b_memo[n]//2:
        return f(n-1,x-1)
    else:
        return 1+p_memo[n-1]+f(n-1,x-b_memo[n-1]-2)

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

b_memo=[0]*51
p_memo=[0]*51
b_memo[0]=1
p_memo[0]=1

for i in range(50):
    b_memo[i+1]=b_memo[i]*2+3
    p_memo[i+1]=p_memo[i]*2+1
    
print(f(n,x))

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

int main(void){
	unsigned long long N;
	unsigned long long ans = 0;
	std::cin>>N;

	for(unsigned long long i=1;i<=std::pow(N/2,0.6);i++){
		unsigned long long t = N/i - 1;
		if(N/t == N%t){
			ans += t;
		}
	}
	

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


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
int main(){
  int n;
  while(scanf("%d",&n) && n){
    int s[1000]={},sum=0;
    for(int i=0;i<n;i++){
      scanf("%d",&s[i]);
      sum += s[i];
    }
    double m = (double)sum / (double)n,ssum=0;
    for(int i=0;i<n;i++) ssum += pow((s[i]-m),2);
    printf("%.7f\n",sqrt(ssum/(double)n));
  }
}


Measured memory_bytes: 2700
#include <iostream>

using namespace std;

int main () {
    int n, m, l;
    cin >> n >> m >> l;

    int a[n][m], b[m][l];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) cin >> a[i][j];
    for (int i = 0; i < m; i++)
        for (int j = 0; j < l; j++) cin >> b[i][j];

    long long c[n][l];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            c[i][j] = 0;
            for (int k = 0; k < m; k++) c[i][j] += a[i][k] * b[k][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            if (j) cout << ' ';
            cout << c[i][j];
        }
        cout << endl;
    }
}


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][N];
int weight[105];
int val[105];
int n, w;

int solve(int n, int w) {

	if (w <= 0) return 0;
	if (n < 1) return 0;

	if (dp[n][w] != -1) return dp[n][w];

	int op1 = solve(n - 1, w);
	int op2 = INT_MIN;

	if (weight[n] <= w) op2 = val[n] + solve(n - 1, w - weight[n]);

	return dp[n][w] = max(op1, op2);
}

int32_t main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;

	memset(dp, -1, sizeof dp);
	int n, w;
	cin >> n >> w;

	f(i, 1, n + 1) cin >> weight[i] >> val[i];
	cout << solve(n, w) << nl;
}


Measured memory_bytes: 85652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-b)<=d){
		if(abs(b-c)<=d){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else if(abs(a-c)<=d){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

dic = {}                
for a in A:
    dic[a] = dic.get(a,0) + 1
    
C = []
for k in dic:
    C.append([k,dic[k]])
    
C.sort(key = lambda x: x[1])

if len(C)<=K:
    print(0)
else:
    print(sum([x[1] for x in C[:len(C)-K]]))


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

using namespace std;

#ifndef errOut
#define errOut(s)
#endif

using Value = int64_t;

Value calc(Value a, Value b, Value c, Value k) {
  if (k % 2) {
    return -a + b;
  } else {
    return a - b;
  }
}

int main() {
  Value a, b, c, k;
  std::cin >> a >> b >> c >> k;
  std::cout << calc(a, b, c, k) << std::endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[] for _ in range(8)]
c = []
for i in range(n):
    x,y,z = a[i][0],a[i][1],a[i][2]
    b[0].append(x+y+z)
    b[1].append(x+y-z)
    b[2].append(x-y+z)
    b[3].append(x-y-z)
    b[4].append(-x+y+z)
    b[5].append(-x+y-z)
    b[6].append(-x-y+z)
    b[7].append(-x-y-z)
for i in range(8):
    b[i].sort()
    b[i].reverse()
for i in range(8):
    c.append(sum(b[i][:m]))
print(max(c))
    

Measured memory_bytes: 9664
#include <cstdio>
#include <cstring>

char s[8010];
int x, y;
int d1[8010], d2[8010];
int d1L, d2L;
int n;
int memo[8010][16010];
int jh=0;
int xx=0;

int solve()
{
	int i, j;
	int c=0;
	int ty=0;
	n = strlen(s);
	for(i=0; i<n; i++){
		if(s[i]=='F')
			c ++;
		else{
			if(c>0){
				if(ty==0){
					if(jh==0){
						xx = c;
					}
					else{
						d1[d1L] = c;
						d1L ++;
					}
				}
				else{
					d2[d2L] = c;
					d2L ++;
				}
				c = 0;
			}
			jh = 1;
			ty = 1-ty;
		}
	}
	if(c>0){
		if(ty==0){
			if(jh==0){
				jh = 1;
				xx = c;
			}
			else{
				d1[d1L] = c;
				d1L ++;
			}
		}
		else{
			d2[d2L] = c;
			d2L ++;
		}
		c = 0;
	}
	if(d1L==0){
		d1[0] = 0;
		d1L = 1;
	}
	if(d2L==0){
		d2[0] = 0;
		d2L = 1;
	}
	for(i=0; i<=d1L; i++){
		for(j=0; j<=16000; j++)
			memo[i][j] = 0;
	}
	memo[0][8000+xx] = 1;
	for(i=0; i<d1L; i++){
		for(j=0; j<=16000; j++){
			if(memo[i][j] == 1){
				memo[i+1][j+d1[i]] = 1;
				memo[i+1][j-d1[i]] = 1;
			}
		}
	}
	if(memo[d1L][8000+x] == 0)
		return 0;
	for(i=0; i<=d2L; i++){
		for(j=0; j<=16000; j++)
			memo[i][j] = 0;
	}
	memo[0][8000] = 1;
	for(i=0; i<d2L; i++){
		for(j=0; j<=16000; j++){
			if(memo[i][j] == 1){
				memo[i+1][j+d2[i]] = 1;
				memo[i+1][j-d2[i]] = 1;
			}
		}
	}
	///if(memo[d1L][8000+y] == 0)
	if(memo[d2L][8000+y] == 0)
		return 0;
	return 1;
}

void test()
{
	int i;
	n = 8000;
	for(i=0; i<n; i++)
		s[i] = 'F';
	s[n] = 0;
	x = 8000;
	y = 0;
	if(solve() )
		printf("Yes\n");
	else
		printf("No\n");
}

int main()
{
	//test();
	scanf("%s", s);
	scanf("%d%d", &x, &y);
	if(solve() )
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 168064
#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	long long n, k, a, b;
	scanf("%lld%lld", &n, &k);
	a = n % k;
	b = k - a;
	printf("%lld\n", a < b? a: b);
	return 0;
}

Measured memory_bytes: 128
def binarySearchLeft(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == 0 or target != nums[mid - 1]:
                return mid
            else:
                high = mid - 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return -1

def solve(n, S, q, T):
    counter = 0
    for t in T:
        idx = binarySearchLeft(S, t)
        counter += 1 if 0 <= idx < len(S) else 0
    print(counter)

if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    solve(n, S, q, T)


Measured memory_bytes: 16708
n = int(input())

if n == 0:
    print(0)
else:
    s = ''

    while n != 0:
        s = str(abs(n % -2)) + s
        if n % -2 != 0:
            n //= -2
            n += 1
        else:
            n //= -2

    print(s)


Measured memory_bytes: 2940
s = input()
res = [0 for i in range(len(s))]
stack = 0
before = 'R'
changed_point = 0 
for i, c in enumerate(s):
    if c == before:
        stack += 1
        continue
    elif before == 'R':
        res[i] += stack // 2
        res[i-1] += stack - (stack // 2)
        before = 'L'
        stack = 1
        changed_point = i
        continue
    else:
        res[changed_point-1] += stack // 2
        res[changed_point] += stack - (stack // 2)
        before = 'R'
        stack = 1
        continue
res[changed_point-1] += stack // 2
res[changed_point] += stack - (stack // 2)
print(' '.join(map(str,res)))

Measured memory_bytes: 10492
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	char* S = new char[1024 * 1024];
	scanf("%s", S);

	int len = strlen(S);

	int count = 0;
	long long countSum = 0;
	for (int i = 0; i < len; i++) {
		if (S[i] == 'W') {
			countSum += i - count;
			count++;
		}
	}
	printf("%lld\n", countSum);
	return 0;
}


Measured memory_bytes: 384
s = int(input())
l = []
l.append(s)
i = 1
ans = 2

while True:
    if l[i-1]%2 == 0:
        a = int(0.5*l[i-1])
    else:
        a = 3*l[i-1] +1

    if a in l:
        ans = i + 1
        break
    else:
        i += 1
        l.append(a)
        continue
print(ans)

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

using namespace std;

int main() {
	int n;

	cin >> n;

	vector<int> v1(n);

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

	for (int i = 0; i < n; ++i) {
		cout << v1[n - 1 - i];
		if (i != n - 1) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> goods(n);
    for (int i = 0; i < n;i++) {
        cin >> goods.at(i);
    }
    sort(goods.begin(), goods.end());
    goods.at(n-1) = goods.at(n-1) / 2;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += goods.at(i);
    }
    cout << sum;
}

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n)]
		self.rank = [0] * n
		self.size = [1] * n

	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

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

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

#処理内容
def main():
	N = int(input())
	Lx = []
	Ly = []
	UF = UnionFind(N)
	for i in range(N):
		x, y = getlist()
		Lx.append([x, y, i])
		Ly.append([y, x, i])
	Lx = sorted(Lx)
	Ly = sorted(Ly)
	for i in range(N - 1):
		if Lx[i][0] == Lx[i + 1][0]:
			UF.union(Lx[i][2] , Lx[i + 1][2])
		if Ly[i][0] == Ly[i + 1][0]:
			UF.union(Ly[i][2] , Ly[i + 1][2])
	for i in range(N):
		UF.par[i] = UF.find(i)

	nodeX = [[] for i in range(N)] 
	nodeY = [[] for i in range(N)]
	PAR = UF.par
	for i in range(N):
		nodeX[PAR[Lx[i][2]]].append(Lx[i][0])
		nodeY[PAR[Lx[i][2]]].append(Lx[i][1])
	# print(nodeX)
	# print(nodeY)

	#計算
	ans = 0
	D = defaultdict(int)
	for i in range(N):
		if D[PAR[i]] == 0:
			D[PAR[i]] = 1
			ans += len(set(nodeX[PAR[i]])) * len(set(nodeY[PAR[i]])) - UF.size[PAR[i]]
	print(ans) 



if __name__ == '__main__':
	main()

Measured memory_bytes: 148528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, L;
    cin >> N >> L;
    vector<string> s(N);
    for(int i=0; i<N; i++) {
        cin >> s[i];
    }
    
    sort(s.begin(), s.end());
    cout << accumulate(s.begin(), s.end(), string()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  ll g = gcd(N, M);
  rep(i, 0, g){
    if(S[i*N/g] == T[i*M/g]){
    }
    else{
      cout << -1 << rt;
      return 0;
    }
  }
  cout << N*M/gcd(N,M) << rt;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {                   
    
  public static void main(String[] args) {                     
      
      Scanner sc = new Scanner(System.in);
      
      String S = sc.next();
      
      if(S.length() < 4){
          System.out.println("No");
          return;
      }
      
      if(S.substring(0,4).equals("YAKI")){
          System.out.println("Yes");
          return;
      }else{
          System.out.println("No");
          return;
      }
  
      
  }   
   
}
        

Measured memory_bytes: 21844
N = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)

count = 0
array.combination(3).each do |a, b, c|
  next if a == b || b == c || c == a
  next unless a + b > c && b + c > a && c + a > b

  count += 1
end

puts count

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef pair<int,int> pii;
typedef pair<pii,int> iii;

int N;
set<int> st;
set<int>::iterator ite;
vector<iii> V;
int ans;

int main()
{
    scanf("%d",&N);
    for(int j = 0; j < 2; j++)
    {
        for(int i = 0; i < N; i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            V.push_back(mk(mk(a,b),1 - j));
        }
    }
    sort(V.begin(),V.end());

    for(int i = 0; i < N * 2; i++)
    {
        iii now = V[i];
        if(now.se == 1)st.insert(-now.fi.se);
        else
        {
            ite = st.upper_bound(-now.fi.se);
            if(ite != st.end())
            {
                ans++;
                st.erase(ite);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
  string A,B,C;
  cin>>N>>A>>B>>C;
  int ans=0;
  for(int i=0;i<N;i++){
    if(A.at(i)==B.at(i)&&B.at(i)==C.at(i)){
      ans+=0;
    }else if(A.at(i)==B.at(i)||B.at(i)==C.at(i)||C.at(i)==A.at(i)){
      ans++;
    }else{
      ans+=2;
    }
  }
  cout<<ans<<endl;
}

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

typedef long long ll;
typedef long double ld;

int niz[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    int tren = 1;
    int res = 0;
    for(int i=n-1; i>=1; i--){
        if(niz[i] < niz[i+1]){
            res = max(res, tren-1);
            tren = 0;
        }
        tren++;
    }
    res = max(res, tren-1);
    cout << res;
    return 0;
}


Measured memory_bytes: 640
<?php
    fscanf(STDIN, "%d %d", $n, $m);
    $a = array();
    $b = array();
    $c = array();
    $d = array();
    for($i = 0; $i < $n; $i++){
        fscanf(STDIN, "%d %d", $a[$i], $b[$i]);
    }
    for($i = 0; $i < $m; $i++){
        fscanf(STDIN, "%d %d", $c[$i], $d[$i]);
    }
    for($i = 0; $i < $n; $i++){
        $ans = 0;
        $min_dist = 1000000000;
        for($j = 0; $j < $m; $j++){
            $dist = abs($a[$i] - $c[$j]) + abs($b[$i] - $d[$j]);
            if($dist < $min_dist){
                $min_dist = $dist;
                $ans = $j;
            }
        }
        $ans++;
        echo "$ans\n";
    }
?>


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

int main(){
  int N;
  cin >> N;
  long pi = 1;
  for(int i = 1;i <= N;i++){
    pi = ((pi % 1000000007) * (i % 1000000007)) % 1000000007;
  }
  cout << pi << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


bool solve(){
  int r, n;
  int maxh[50] = {};
  
  scanf("%d%d", &r, &n);

  if(r == 0) return false;
  
  for(int i=0;i<n;i++){
    int l, r, h;
    scanf("%d%d%d", &l, &r, &h);

    for(int j=l+20;j<r+20;j++) maxh[j] = max(maxh[j], h);
  }

  double ans = INF;
  
  for(int i=20-r;i<20+r;i++){
    int x = (i<20) + i - 20;

    ans = min(ans, maxh[i] + r - sqrt(r*r-x*x));
  }

  printf("%.5lf\n", ans);

  return 1;
}

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



Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1310720000;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int N, M;
int C[16], X[20001];
int dp[20001][256];

int main(){
    while(std::cin >> N >> M, N){
        REP(i, M){
            std::cin >> C[i];
        }
    
        FOR(i, 1, N+1){
            std::cin >> X[i];
        }

        REP(i, N+1){
            REP(y, 256){
                dp[i][y] = INF;
            }
        }
        dp[0][128] = 0;

        REP(i, N){
            REP(y, 256){
                REP(j, M){
                    int ny = y+C[j];
                    ny = std::max(ny, 0);
                    ny = std::min(ny, 255);

                    dp[i+1][ny] = std::min(dp[i+1][ny], dp[i][y] + (X[i+1]-ny) * (X[i+1]-ny));
                }
            }
        }

        // FOR(i, 1, N+1){
        //     REP(y, 256){
        //         printf("%d, ", dp[i][y]);
        //     }
        //     puts("");
        // }

        //printf("%d\n", dp[2][136]);

        int min_sum = INF;
        REP(i, 256){
            min_sum = std::min(min_sum, dp[N][i]);
        }

        std::cout << min_sum << std::endl;
    }
}

Measured memory_bytes: 21240
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

long long int dp[1002][1002];
char grid[1002][1002];
int H, W;
long long int lli = 1000000007;

long long int q(int i, int j) {
    if (i >= H || j >= W) return 0;

    if (dp[i][j] != -1) return dp[i][j];
    else if (grid[i][j] == '#') dp[i][j] = 0;
    else if (i == H-1 && j == W-1) dp[i][j] = 1;
    else dp[i][j] = (q(i+1, j) + q(i, j+1)) % lli;

    return dp[i][j];
}

int main() {

    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
            dp[i][j] = -1;
        }
    }

    q(0, 0);
    cout << dp[0][0] << endl;
}

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

int main()
{
  const int INF = 1e9 + 10;
  int N; cin >> N;
  int tmp = INF;
  int ans = 0;
  for (int i = 0; i < N-1; i++)
  {
    int B; cin >> B;
    ans += min(tmp, B);
    tmp = B;
    if (i == N - 2) ans += B;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;

int main(){
    int N,X;
    int x[105];
    int y[105];
    int h[105];
    int C_x,C_y,H;
    int ans;
    int tmp;
    int H_tmp;
    bool flag = true;


    //input
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i];
        cin >> y[i];
        cin >> h[i];
    }

    for(int xx = 0; xx <= 100; xx++){
        for(int yy = 0; yy <= 100; yy++){
            //Hの推定
            for(int i = 0; i < N; i++){
                if(h[i] != 0){
                    H_tmp = h[i] + abs(x[i] - xx) + abs(y[i] - yy);
                }
            }
            flag = true;
            for(int i = 0; i < N; i++){
                tmp = max(H_tmp - abs(x[i] - xx) - abs(y[i] - yy),0);
                if(h[i] != tmp){
                    flag = false;
                }
            }
            // cout << "C_x:" << xx << " C_y:" << yy <<" " << H_tmp;
            if(flag){
                cout << xx <<" " << yy <<" " << H_tmp << endl;
            }
        }
    }
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; ++i) {
			p[i] = sc.nextInt();
			--p[i];
		}
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			if (p[i] != i) {
				continue;
			}
			if (i == n - 1) {
				++ans;
				continue;
			}
			int tmp = p[i];
			p[i] = p[i + 1];
			p[i + 1] = tmp;
			++ans;
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 52884
<?php
//$K = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
 
for($i=0;$i<$M;$i++) {
  list($a,$b) = array_map('intval',explode(" ",trim(fgets(STDIN))));
  $A[]=$a--;
  $B[]=$b--;
  $G[$a][]=$b;
  $G[$b][]=$a;
}
 
$q = new SplQueue();
$q->enqueue(0);
while(!$q->isEmpty()) {
  $v = $q->dequeue();
  foreach($G[$v] as $u) {
    if (isset($dist[$u])) continue;
    $dist[$u]=$dist[$v]+1;
    $pre[$u]=$v;
    $q->enqueue($u);
  }
}
printf("Yes\n");
for($i=1;$i<$N;$i++) {
  $ans = $pre[$i];
  ++$ans;
  printf("%d\n",$ans);
}

Measured memory_bytes: 84652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int ans = 1900 * m + 100 * (n - m);
		for (int i = 0; i < m; i++)
			ans *= 2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
L = [int(input()) for _ in range(5)]

P = []
for i, v in enumerate(L):
    if (v % 10 == 0):
        P.append((0, i))
    else:
        P.append((10 - (v % 10), i))

P.sort()
count = 0
for i, v in enumerate(P):
    if (i == len(P) - 1):
        break
    if (v[0] == 0):
        count += L[v[1]]
    else:
        count += L[v[1]] + v[0]
print(count + L[P[-1][1]])


Measured memory_bytes: 3064