akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node
{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

int maxh;
Node root,NIL;

void preorder(Node u)
{
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

void inorder(Node u)
{
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

Node tree(Node u,int k)
{
  while(u != NIL && k != u->key)
    {
      if(k<u->key) u=u->left;
      else u= u->right;
    }
  return u;
}

void insert(int k)
{
  int H;
  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;
	}
    }
}

int main()
{
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  maxh=0;
  for(i=0;i<n;i++)
    {
      scanf("%s",com);
      if(com[0]=='f' )
	{
	  scanf("%d",&x);
	  Node t=tree(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: 20492
N,K=input().split()
N=int(N)
K=int(K)
if (1<=N<=2*10**5)and(1<=K<=N+1):
    a=(N+1)*(N+1)*(N+2)/2-(1/6)*(N+1)*(N+2)*(2*N+3)+N-K+2-(N+1)*(K-1)*K/2+(K-1)*(2*K-1)*K/6
    a=int(a)
    a=a%(10**9+7)
    print(a)

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

const int INF =1e9;
const int MOD =1e9+7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
int n;
cin>>n;
set<string> ss;
REP(i,n){
    string s;
    cin>>s;
    ss.insert(s);
}
cout<<ss.size()<<endl;
}

Measured memory_bytes: 19036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#define F first
#define S second
using namespace std;
typedef long long ll;
#define PR pair<ll, ll>

int n, d[200005], M=998244353;
PR a[200005];
stack<PR> st;
int main() {
	int i;
	cin >> n;
	d[n] = 1;
	st.push({1e9, n});
	for(i=0; i<n; i++) scanf("%lld%lld", &a[i].F, &a[i].S);
	sort(a, a+n);
	for(i=n-1; i>=0; i--) {
		while(a[i].F + a[i].S > st.top().F) st.pop();
		d[i] = (d[i+1] + d[st.top().S]) % M;
		st.push({a[i].F, i});
	}
	cout << d[0];
	return 0;
}

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

int main(){
  string s1, s2;
  cin >> s1 >> s2;
  for(int i=0; i<(int)s1.size(); ++i){
    if(s1 == s2){
      cout << "Yes" << endl;
      return 0;
    }
    char x = s2[0];
    for(int j=0; j<(int)s1.size()-1; ++j){
      s2[j] = s2[j+1];
    }
    s2[s2.size()-1] = x;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
main(){
  int a[28],b,i;
  a['I'-'A']=1;
  a['V'-'A']=5;
  a['X'-'A']=10;
  a['L'-'A']=50;
  a['C'-'A']=100;
  a['D'-'A']=500;
  a['M'-'A']=1000;
  char s[128];
  while(scanf("%s",s)!=-1){
    b=0;
    s[strlen(s)+1]=0;
    s[strlen(s)]='I';
    for(i=0;i<strlen(s)-1;i++)
      if(a[s[i]-'A']<a[s[i+1]-'A'])
	b-=a[s[i]-'A'];
      else
	b+=a[s[i]-'A'];
    printf("%d\n",b);
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();

        out.println(a - b >= c ? 0 : c - (a - b));
    }

}


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

int main(){
    int n;
    int a[110];
    int b[110];
    int c[110];

    cin >> n;

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

    for(int i = 0;i < n;i++) cin >> b[i];
    for(int i = 0;i < n-1;i++) cin >> c[i];

    int old = -1719;
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(old+1 == a[i]){
            ans += c[old];
        }

        ans += b[a[i]];
        old = a[i];
    }

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


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

int main(){
  int n, k, s;
  while(cin >> n >> k >> s, n){
    int sum = 0;
    for(int i = 0; i < 1<<n; i++){
      int tmp = 0, cnt = 0;
      for(int k = 0; k < n; k++){
        if(i >> k & 1) tmp++;
      }
      if(tmp != k) continue;
      for(int j = 0; j < n; j++){
        if(i >> j & 1) cnt += j + 1;
      }
      if(cnt == s) sum++;
    }
    cout << sum << endl;
  }
  return 0;
}



Measured memory_bytes: 3080
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long long x,sum=100.0,cnt=0;
	cin>>x;
	while(sum<x)
	{
		sum=sum*1.01;
		cnt++;
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3624
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#繰り返し自乗法だよ
#これはnのp乗をmで割ったあまりをだすよ
def modular_w_binary_method (n,m,p):
    ans=1 if n>0 else 0
    while(p>0):
        if p%2==1:
            ans=(ans*n)%m
        n=(n**2)%m
        p//=2
    return ans
#mod上でのaの逆元を出すよ
"""
    フェルマーの小定理より a**(p)%p==a isTrue
    これを利用すれば a**(p-2)%p==a**(-1) isTrue
    元と逆元とをかけてpで割れば1が余るよ！
"""
def modular_inverse(a,prime):
    return(modular_w_binary_method(a,prime,prime-2))



def conbination(n,a,mod=0):
    #cはイラない
    res=1 
    for s in range(a):
        res=(res*(n-s)*(modular_inverse(s+1,mod)))%mod

        
    return res
"""
"""

#solution:

#input
bigmod=(10**9)+7
#print(modular_w_binary_method(bigmod+10,bigmod,2))#modular_w_binary_methodはバグってない


n,a,b=pin()
an=0

allcombination=modular_w_binary_method(2, bigmod,n)
ans= allcombination -1 %bigmod
A=conbination(n,a,bigmod)
B=conbination(n,b,bigmod)
print((ans-A-B)%bigmod)

#print(["No","Yes"][cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

Measured memory_bytes: 72424
input1 = str(input())
if input1[0] == "7":
    print("Yes")
    exit()
else:
    if input1[1] == "7":
        print("Yes")
        exit()
    else:
            
        if input1[2] == "7":
            print("Yes")
            exit()
        else:
            print("No")

Measured memory_bytes: 9112
#include<stdio.h>
#define N 1000000

int A[N],n;

int binarySearch(int key){
  int left=0;
  int right=n;
  int center;

  while(left<right){
    center=(left+right)/2;
    if(key==A[center])return 1;
    if(key>A[center])left=center+1;
    else if(key<A[center])right=center;
  }
  return 0;
}


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

  scanf("%d",&j);
for(i=0;i<j;i++){
 scanf("%d",&k);
 if( binarySearch(k))sum++;
  }

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


Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	vector<int> a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	put(a[k - 1]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <numeric>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int K, S;
    cin >> K >> S;

    int cnt = 0;
    for (int x = 0; x <= K; ++x)
    {
        if (S < x)
        {
            break;
        }
        for (int y = 0; y <= K; ++y)
        {
            if (S < (x + y))
            {
                break;
            }
            for (int z = (S - x - y); z <= K; ++z)
            {
                auto sum = x + y + z;
                if (S < sum)
                {
                    break;
                }
                else if (x + y + z == S)
                {
                    ++cnt;
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<x<<" "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 200005, maxn = 1666666;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
const int mod = 3600;

int n, m;
ll sum[N], a[N], dp[N];

void solve()
{
    scanf("%d", &n);
    for(int i = 1;i <= n; ++i) {
        scanf("%lld", &a[i]);
        sum[i] = (i>=2?sum[i-2]:0)+a[i];
    }
    for(int i = 2; i <= n; ++i) {
        if(i&1) dp[i] = max(dp[i-2]+a[i], dp[i-1]);
        else dp[i] = max(dp[i-2]+a[i], sum[i-1]);
    }
    printf("%lld\n", dp[n]);
}


int main()
{

//    int _;scanf("%d", &_);while(_--)
//    while(~scanf("%d", &n))
    solve();
    return 0;
}


Measured memory_bytes: 8464
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;


int main(){
  int h, a;
  cin >> h >> a;
  int ans = 0;
  while(true){
    if(h <= 0) break;
    h -= a;
    ans++;
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
/*
	TRUST THE PROCESS....
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define read(n) scanf("%d",&n)
#define prll int(x) prll intf("%d",x)
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pii pair<ll int,ll int>
#define ff first
#define ss second

int main()
{


	ll int n;
	cin>>n;

	string s;
	cin>>s;

	ll int dp[n+1][n+1];
	memset(dp,0,sizeof(dp));
	ll int predp[n+1][n+1];
	memset(predp,0,sizeof(predp));

	dp[1][1]=1LL;
	predp[1][1]=1LL;
	for(ll int i=1;i<=n;i++)
		predp[1][i]=1LL;

	for(ll int i=2;i<=n;i++)
	{
		for(ll int j=1;j<=i;j++)
		{
			if(s[i-2] == '<')
			{
				dp[i][j] = predp[i-1][j-1];
			}
			else
			{
				dp[i][j] = predp[i-1][n] - predp[i-1][j-1] + md;
			}
			dp[i][j]%=md;
		}
		for(ll int j=1;j<=n;j++)
			predp[i][j] = predp[i][j-1] + dp[i][j] , predp[i][j]%=md;
	}	

	ll int ans=0;
	for(ll int i=1;i<=n;i++)
		ans+=dp[n][i],ans%=md;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 140928
#include <stdio.h>

void core() {
	unsigned int X;
	scanf("%d", &X);
	for (unsigned int i = 1; i >= 1; i++) {
		if ((i + 1) * i / 2 >= X) {
			printf("%d\n", i);
			return;
		}
	}
}

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

Measured memory_bytes: 128
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,i;
  cin >> n;
  vector<int> x(n);
  for(i=0;i<n;i++){
    cin >> x[i];
  }
  sort(x.begin(),x.end());
  cout << x[n/2]-x[n/2-1] << endl;
  return 0;
}

Measured memory_bytes: 3796
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    A, B, C, K = map(int, input().split())

    #output
    #K <= Aの時
        #point = K
    #A < K <= A+Bの時
        #point = A
    # A+B < Kの時
        #point = A -{K-(A+B)}
    if K <= A:
        print(K)
    elif A < K <= A+B:
        print(A)
    elif K > A+B:
        print(2*A + B - K)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
char s[n];
cin >> s;
string ans = "Yes";
if(n%2==0) {
  REP(i,n/2) {
    if(s[i]!=s[i+n/2]) ans = "No";
  }
} else {
  ans = "No";
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int[] a=new int[N];
        int ab=0;
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
            ab+=a[i];
        }
        if(ab%N==0){
        ab=ab/N;
        }else{
            ab=ab/N+1;
        }
        long ans=0;
        for(int i=0;i<N;i++){
            ans+=(long)Math.pow(a[i]-ab,2);
        }
        long an1=0;
        ab--;
        for(int i=0;i<N;i++){
            an1+=(long)Math.pow(a[i]-ab,2);
        }
        System.out.println(Math.min(an1,ans));
    }
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll fac[1000010],finv[1000010];

ll npk(ll n,ll k){
  return fac[n]*finv[n-k]%mod;
}

ll N,D,H;
ll dp[1000010];

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

  fac[0]=1;
  rep(i,1000000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,1000001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>N>>H>>D;

  ll tot=0;
  repl(i,1,N+1){
    tot+=fac[i];
    tot%=mod;
  }

  dp[0]=1;
  ll sum=dp[0];
  repl(i,1,H){
    if(i-D-1>=0){
      sum=(sum-dp[i-D-1]+mod)%mod;
    }
    dp[i]+=sum*tot%mod;
    dp[i]%=mod;
    sum+=dp[i];
    sum%=mod;
  }
  sum=(sum-dp[H-D-1]+mod)%mod;
  cout<<sum*fac[N]%mod<<endl;

  return 0;
}


Measured memory_bytes: 23680
#include <iostream>

using namespace std;

#define YES  1
#define NO   0


int main()
{
    int N, A, B;
    int result;

    cin >> N >> A;

    if( N < 500 )
    {
        if( A >= N )
            result = YES;
        else
            result = NO;
    }
    else
    {
        B = N / 500;
        if( A >= N - B*500 )
            result = YES;
        else
            result = NO;
    }

    if( result == YES )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

/*
あなたは、500 円玉を A 枚、100 円玉を B 枚、50 円玉を C 枚持っています。
これらの硬貨の中から何枚かを選び、合計金額をちょうど X 円にする方法は何通りありますか。

同じ種類の硬貨どうしは区別できません。
2 通りの硬貨の選び方は、ある種類の硬貨についてその硬貨を選ぶ枚数が異なるとき区別されます。
*/
public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int fivehunds = s.nextInt();
        int hunds = s.nextInt();
        int fifth = s.nextInt();

        int sum = s.nextInt();

        int count = 0;
        for (int i = 0; i <= fifth; i++) {
            for (int j = 0; j <= hunds; j++) {
                for (int k = 0; k <= fivehunds; k++) {
                    int temp = i * 50 + j * 100 + k * 500;
                    if (sum == temp) {
                        count++;
                    }
                }
            }
        }

        System.out.println(count);
    }
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> X(N);
  rep(i, N) {
    std::cin >> X[i];
  }

  int ans = 100 * 100 * 100;
  for(int P = 1; P <= 100; ++P) {
    int sum = 0;
    rep(i, N) {
      sum += (X[i] - P) * (X[i] - P);
    }
    ans = std::min(ans, sum);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define abs(n) ( (n) < 0 ) ? -(n) : (n)

int main(void){

  //入力
  int N, X;
  cin >> N >> X;
  
  //配列
  int m[N];
  int min = INF;	//一番小さいｍ
  rep(i, N){
    cin >> m[i];
    X -= m[i];
    if(m[i] < min) min = m[i];
  }

  //残ってるXがminより少なくなるまで
  int ans = N;
  
  while(X >= min){
    X -= min;
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;


namespace ConsoleApplication22
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string[] tmp = Console.ReadLine().Split(" ".ToCharArray());
                int height, Wide;

                height = int.Parse(tmp[0]);
                Wide = int.Parse(tmp[1]);
                if (height == 0 && Wide == 0)
                    break;

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < Wide; j++)
                    {
                        Console.Write(((i + j) % 2 == 0) ? "#" : ".");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");

            }
        }

    }
}

Measured memory_bytes: 9008
#include <stdio.h>
     
    int main(void) {
    		int no,d1,d2,i,ii,mno,md;
    		while(scanf("%d",&ii), ii != 0){
    			md = 0;
    			for(i = 1;i <= ii;i++){
    				scanf("%d%d%d",&no,&d1,&d2);
    				if (md <(d1 + d2)){
    					md =(d1 + d2);
    					mno = no;
    				}
    			}
    			printf("%d %d\n",mno,md);
    		}
    	return 0;
    }

Measured memory_bytes: 600
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

count = 0
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        count += C[A[i]-1]
print(sum(B) + count)




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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    double r; cin >> r;

    double ans = 2 * r * M_PI;

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3784
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
struct node{int to,nxt;}sq[220];
int all=0,head[120];
int n,m,col,tp=0,sta[120],dfn[120],low[120],tim=0,bcc[120];
bool in[120],vis[120];
ll fac[N+10],invfac[N+10],ans;

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void add(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;
}

ll qpow(ll x,int y)
{
	ll ans=1;
	while (y)
	{
		if (y&1) ans=ans*x%maxd;
		x=x*x%maxd;y>>=1;
	}
	return ans;
}

ll C(int n,int m)
{
	if ((n<m) || (n<0) || (m<0)) return 0;
	return fac[n]*invfac[m]%maxd*invfac[n-m]%maxd;
}

ll polya(int n)
{
	ll ans=0;
	rep(i,0,n-1) ans=(ans+qpow(col,__gcd(i,n)))%maxd;
	ans=ans*qpow(n,maxd-2)%maxd;
	return ans;
}

void tarjan(int u,int fu)
{
	dfn[u]=low[u]=(++tim);
	sta[++tp]=u;in[u]=1;int ch=0;
	go(u,i)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		if (!dfn[v])
		{
			tarjan(v,0);ch++;
			low[u]=min(low[u],low[v]);
			if (low[v]>=dfn[u])
			{
				int tot=0;
				while (1)
				{
					int now=sta[tp];tp--;in[now]=0;
					bcc[++tot]=now;
					if (now==v) break;
				}
				bcc[++tot]=u;
				memset(vis,0,sizeof(vis));
				rep(j,1,tot) vis[bcc[j]]=1;
				int edge=0;
				rep(j,1,tot)
				{
					int x=bcc[j];
					go(x,k)
					{
						int y=sq[k].to;
						if (vis[y]) edge++;
					}
				}
				edge>>=1;
				if (tot>edge) ans=ans*qpow(col,edge)%maxd;
				else if (tot==edge) ans=ans*polya(tot)%maxd;
				else ans=ans*C(edge+col-1,col-1)%maxd;
			}
		}
		else if (in[v]) low[u]=min(low[u],dfn[v]);
	}
}

int main()
{
	fac[0]=invfac[0]=1;
	rep(i,1,N) fac[i]=fac[i-1]*i%maxd;
	invfac[N]=qpow(fac[N],maxd-2);
	per(i,N-1,1) invfac[i]=invfac[i+1]*(i+1)%maxd;
	n=read();m=read();col=read();
	rep(i,1,m)
	{
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	ans=1;
	rep(i,1,n)
		if (!dfn[i]) tarjan(i,0);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int H,W,K;
    cin >> H >> W >> K;

    vector<vector<char>> c(6, vector<char>(6));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> c.at(i).at(j);
        }
    }
    int ans=0;
    for (int tmp = 0; tmp < (1 << 12); tmp++) {
        bitset<12> s(tmp);
        int count=0;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(s.test(i) && s.test(6+j)){
                    if(c.at(i).at(j)=='#') count++;
                }
            }
        }
        if (count == K) ans++;
    }
  	ans=ans/(pow(2,(12-H-W)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4000
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C
    # https://atcoder.jp/contests/abc064/tasks/abc064_d

    X = str(input())
    N = len(X)
    stack_rem = 0
    need_left = 0
    pop_cnt = 0

    for i in range(N):
        if X[i] == 'S':
            stack_rem += 1
        elif stack_rem > 0:
            stack_rem -= 1
            pop_cnt += 1
    print(N-pop_cnt*2)


resolve()

Measured memory_bytes: 40048
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

const int MAXN = 2e5 + 10;
int N;
int A[MAXN], B[MAXN];
int fa[MAXN], tot;
map<int, int> mp;
int ans;

inline int gf(int x) {return x == fa[x] ? x : fa[x] = gf(fa[x]);}

int main() {
	register int i;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i) scanf("%d", A + i), A[0] ^= A[i];
	for(i = 1; i <= N; ++i) scanf("%d", B + i), B[0] ^= B[i];
	for(i = 1; i <= N; ++i) fa[i] = i;
	for(i = 0; i <= N; ++i)
		if(A[i] != B[i] || i == 0) {
			++ans;
			if(!mp[A[i]]) mp[A[i]] = ++tot;
			if(!mp[B[i]]) mp[B[i]] = ++tot;
			fa[gf(mp[A[i]])] = gf(mp[B[i]]);
		}
	--ans;
	for(i = 1; i <= tot; ++i) if(fa[i] == i) ++ans;
	sort(A, A + N + 1); sort(B, B + N + 1);
	for(i = 0; i <= N; ++i) if(A[i] != B[i]) return puts("-1"), 0;
	printf("%d\n", ans - 1);
	return 0;
}

Measured memory_bytes: 7040
n = int(input())
a = list(map(int, input().split()))

def chk(x,t):
  ans=0
  s=0
  for i in x:
    s += i
    if t == True and s < 1:
      ans += 1 - s
      s = 1
    elif t == False and s > -1:
      ans += 1 + s
      s = -1
    t = not t
    
  return ans

print(min(chk(a,True),chk(a,False)))

Measured memory_bytes: 14332
fn main() {
	proconio::input!{
		h: usize,
		w: usize,
		s: [String; h],
	}

	for _i in 0..w+2 {
		print!("#");
	}
	println!("");

	for i in 0..h {
		print!("#");
		print!("{}", s[i]);
		println!("#");
	}

	for _i in 0..w+2 {
		print!("#");
	}
	println!("");
}



Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll ans;
    exrep(i, 1, 40000) {
        if(i*i <= n) {
            ans = i*i;
        }
        else {
            break;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
using namespace std;
int main(int argc, char const *argv[]) {
    std::vector<int> a;
    for (size_t i = 0; i < 4; i++) {
        a.push_back(0);
    }
    int tmp1,tmp2;
    for (size_t i = 0; i < 3; i++) {
        std::cin >>tmp1>>tmp2 ;
        a[tmp1-1]++;
        a[tmp2-1]++;
    }
    if(*min_element(a.begin(), a.end())>=1 && *max_element(a.begin(),a.end())<=2){
        std::cout << "YES" << '\n';
    }else{
        std::cout << "NO" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val adj = Array(n) { mutableSetOf<Int>() }
    for (i in 0 until m) {
        val u = sc.nextInt() - 1
        val v = sc.nextInt() - 1
        adj[u].add(v)
        adj[v].add(u)
    }
    val ans = Array(n) { -1 }
    val que: Queue<Pair<Int, Int>> = ArrayDeque()
    val visited = Array(n) { false }
    visited[0] = true
    que.add(0 to -1)
    while (que.count() > 0) {
        val (v, prev) = que.poll()
        ans[v] = prev
        for (w in adj[v]) {
            if (!visited[w]) {
                visited[w] = true
                que.add(w to v)
            }
        }
    }
    println("Yes")
    for (i in 1 until n) {
        println(ans[i] + 1)
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

using ll = long long;
const int INF = 1e9+100;

vector<string> s;
vector<vector<int>> dist;

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

queue<pair<int,int>> q;
int n, m;
inline bool inBound(int x, int y){
	return x >= 0 && x < n && y >= 0 && y < m;
}
void dfs(int x, int y, int c){
	if (!inBound(x,y) || s[x][y] == '#' || dist[x][y] != -1){
		return;
	}
	dist[x][y] = c;
	q.emplace(x, y);
	for (int d = 0; d < 4; d++){
		dfs(x + dx[d], y + dy[d], c);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin>>n>>m;
	s.resize(n);
	dist.assign(n, vector<int>(m, -1));
	pair<int,int> st;
	pair<int,int> en;
	cin>>st.first>>st.second>>en.first>>en.second;
	st.first--; st.second--; en.first--; en.second--;
	for (int i = 0; i < n; i++){
		cin>>s[i];
		s[i] += '#';
	} 
	s.push_back(string(m+1, '#'));
	// for (auto &r: s){
	// 	cout<<r<<'\n';
	// }
	// dist[st.first][st.second] = 0;
	dfs(st.first, st.second, 0);
	while (!q.empty()){
		int x, y;
		tie(x, y) = q.front();
		q.pop();
		for (int dx0 = -2; dx0 <=2; dx0++){
			for (int dy0 = -2; dy0 <= 2; dy0++){
				int nx = x + dx0;
				int ny = y + dy0;
				if (inBound(nx, ny) && dist[nx][ny] == -1 && s[nx][ny] =='.' && (nx != x || ny != y)){
					dfs(nx, ny, dist[x][y] + 1);
				}
			}
		}
	}
	// for (int i = 0; i < n; i++){
	// 	for (int j = 0; j < m; j++){
	// 		cout<<dist[i][j]<<' ';
	// 	}
	// 	cout<<'\n';
	// }
	cout<<dist[en.first][en.second]<<'\n';
	return 0;
}

Measured memory_bytes: 9656
import os
import sys

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


t1, t2 = list(map(int, sys.stdin.buffer.readline().split()))
a1, a2 = list(map(int, sys.stdin.buffer.readline().split()))
b1, b2 = list(map(int, sys.stdin.buffer.readline().split()))

da1 = t1 * a1
da2 = t2 * a2
db1 = t1 * b1
db2 = t2 * b2
if da1 + da2 > db1 + db2:
    a1, b1 = b1, a1
    a2, b2 = b2, a2
    da1, db1 = db1, da1
    da2, db2 = db2, da2
# b のほうがはやい

# 無限
if da1 + da2 == db1 + db2:
    print('infinity')
    exit()
# 1回も会わない
if da1 < db1:
    print(0)
    exit()

# t1 で出会う回数
cnt = abs(da1 - db1) / abs(da1 + da2 - db1 - db2)
ans = int(cnt) * 2 + 1
if cnt == int(cnt):
    ans -= 1
print(ans)


Measured memory_bytes: 3064
def comb(n,r):
    if (n<r): return 0
    a,b=1,1
    r = min(r,n-r)
    for i in range(r):
        a = a*(n-i)
        b = b*(r-i)
    return a // b

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
count_a = Counter(a)
ans = 0
for x,y in count_a.items():
    ans += comb(y,2)

for i in a:
    print(ans-count_a[i]+1)

Measured memory_bytes: 26780
import sys
input = sys.stdin.readline
def print_ans(a,s):
    """Test Case
    >>> print_ans(3200,"pink")
    pink
    >>> print_ans(3199,"pink")
    red
    >>> print_ans(4049, "red")
    red
    """
    if a >= 3200:
        print(s)
    else:
        print("red")


if __name__ == '__main__':
    a = int(input().rstrip())
    s = input().rstrip()
    print_ans(a,s)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  
  vector<bool> fg(N, true);
  vector<int> ans;
  for( int i = 0; i < N; i++ ){
    int cnt = 0;
    int num = -1;
    for( int j = 0; j < N; j++ ){
      if( fg.at(j) ) cnt++;
      if( A.at(j) == cnt ) num = j;
    }
    if( num != -1 ){
      fg.at(num) = false;
      ans.push_back(A.at(num));
    }
  }
  
  for( int i = 0; i < N; i++ ){
    if( fg.at(i) ){
      cout << -1 << endl;
      return 0;
    }
  }
  
  reverse(ans.begin(), ans.end());
  for( int i = 0; i < N; i++ ) cout << ans.at(i) << endl;
       
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=1;i<=(n);i++)
#define rep3(i,i0,n) for(ll i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool comparex(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<1>(a) < get<1>(b);
        
}
bool comparey(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<2>(a) < get<2>(b);
        
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

/*vector<Pi> pf(ll N){
    vector<Pi> res;
    for(ll a= 2; a*a <= N; ++a){
        if(N%a != 0) continue;
        ll ex= 0;

        while(N%a == 0){
            ++ex;
            N /= a;
        }

        res.pb(mp(a,ex));
    }
    if(N!=1) res.pb(mp(N,1));
    return res;
}*/


bool pf(ll N){

    for(ll a= 2; a*a <= N; ++a){
        if(N%a == 0) return 1;
    }

    return 0;
}

int main() {

    ll Q;
    cin >> Q;
    vector<ll> l(Q);
    vector<ll> r(Q);
    vector<ll> sum(100010);
    rep(i,Q){
        cin >>l[i]>>r[i];
    }

    sum[0] = 0;
    sum[1] = 0;
    for(ll i = 3;i < 100006;i++){
        if(i%2){
            ll k = (i+1)/2;
            if(!pf(i) && !pf(k)){
                sum[i] = sum[i-1] + 1;
            }else{
                sum[i] = sum[i-1] ;
            }
        }else{
            sum[i] = sum[i-1] ;
        }
        
    }


    rep(i,Q){
        cout<<sum[r[i]]-sum[l[i]-1]<<endl;
    }

    
  
    return 0;
    

}


Measured memory_bytes: 5552
int main(void)
{
	int a,b,c,x,y=0;
	
	scanf("%d %d %d", &a, &b, &c);
	
	for(x=a; x<=b; x++) {
		if (c % x == 0) {
			y += 1;
		}
	}
	printf("%d\n",y);
	
	return 0;
}

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

int main() {

	int n, T; cin >> n >> T;
	int ans = 2147483647;
	for (int i = 0; i < n; i++) {
		int c, t; cin >> c >> t;
		if (t <= T) {
			ans = min(ans, c);
		}
	}
	if (ans == 2147483647) cout << "TLE" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

// aaaxa aaaxa

ll solve(){
  string s; cin>>s;
  ll N = s.size();
  ll K; cin>>K;
  ll ans;
  ll a = 0;
  ll b = 0;
  bool flag = (s[0]==s[N-1]);
  if(flag){
    REP(i,N){
      if(s[i]==s[0]){++a;}
      else{ break;}
    }
    REPR(i,N-1){
      if(s[i]==s[N-1]){ ++b;}
      else{ break;}
    }
  }
  if(a==N){ ans = N*K/2; }
  else{
    string t = s;
    ans = 0;
    for(int i= a;i<N-b;++i){
      if(t[i+1]==t[i]){ t[i+1] = '0'; ++ans; }
    }
    ans *= K;
    ans += a/2;
    ans += b/2;
    if(flag){
      ans += ((a+b)/2)*(K-1);
    }
  }
  return ans;
}

int main(){
  cout << solve()<<"\n";
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int n, d, x;
	cin >> n >> d >> x;

	vector<int> a(n, 0);
	for (auto& ai : a)
		cin >> ai;

	int count = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 1; j <= d; j += a[i])
			count++;

	cout << count + x << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int k=0,ba,min,n[105],i,j,a;
  scanf("%d",&a);
  for(i=0;i<a;i++)scanf("%d",&n[i]);
  for(i=0;i<a;i++){
    min=1000000;
    for(j=i;j<a;j++){
      if(min>n[j]){
	min=n[j];
	ba=j;
      }
    }
    if(ba!=i){
      n[ba]=n[i];
      n[i]=min;
      k++;
    }
  }
  for(i=0;i<a-1;i++)printf("%d ",n[i]);
  printf("%d\n",n[a-1]);
  printf("%d\n",k);
  return 0;
}

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

using namespace std;

int main()
{
    int n,d,x;
    cin >>n;
    cin>>d>>x;
    int ans=0;
    for(int i=0;i<n;i++){
        int hoge;
        cin>>hoge;
        ans+=(d-1)/hoge+1;
    }
    ans+=x;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import scala.io.Source

object Main {

  def isPrime(n: Int): Boolean = {
    // TODO: Make it declarative
    if (n == 1) return false
    for(i <- 2 to Math.sqrt(n).toInt) {
      if(n % i == 0) return false
    }
    true
  }

  def main(args: Array[String]): Unit = {
    // Get interator of stdin
    val stdinIterator = Source.stdin.getLines()

    // Skip the first line
    stdinIterator.next()

    // Get input
    val numbers: Seq[Int] = stdinIterator.toSeq.map(_.toInt)

    // The number of primes in the numbers
    val nPrimes = numbers.count(isPrime(_))

    // Print the number of primes
    println(nPrimes)
  }
}


Measured memory_bytes: 56920
# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_A
# AtCoderの解説がわかりやすい https://youtu.be/zV3Ul2pA2Fw?t=1425
# この解説を見た上で本を読むとより理解が深まる

# 本とはやや違う実装だがこちらのほうがスマート(だとおもってる)


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。
        # rankは親ノードの負の数の大きさに対応している

    def root(self, A):  # 本で言うfindset
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):  # 本で言うrank
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


N, Q = list(map(int, input().split()))
ds = UnionFind(N)
for q in range(Q):
    com, x, y = list(map(int, input().split()))
    if com == 0:
        # unite
        ds.unite(x, y)
    elif com == 1:
        # same?
        print(1 if ds.is_in_same(x, y) else 0)



Measured memory_bytes: 5728
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    int T;
    cin >> T;
    rep(t,T) {
        int N;
        cin >> N;
        ll ans = 0;
        vector<int> K(N), L(N), R(N);
        rep(i,N) cin >> K[i] >> L[i] >> R[i];
        multiset<P> left, right, left2, right2;
        rep(i,N) {
            if (L[i] > R[i]) left.emplace(K[i], L[i] - R[i]);
            else if (L[i] < R[i] && K[i] < N) right.emplace(K[i] + 1, R[i] - L[i]);
            ans += min(L[i], R[i]);
        }
        
        auto it_left = left.begin();
        auto it_right = right.rbegin();

        for (int i = 1; i <= N; i++) {
            while (it_left != left.end() && (*it_left).first <= i) {
                left2.emplace((*it_left).second, (*it_left).first);
                it_left++;
            }
            while (left2.size() > i) left2.erase(left2.begin());
        }

        for (int i = N; i >= 1; i--) {
            while (it_right != right.rend() && (*it_right).first >= i) {
                right2.emplace((*it_right).second, (*it_right).first);
                it_right++;
            }
            while (right2.size() > (N - i + 1)) right2.erase(right2.begin());
        }

        for (auto it = left2.begin(); it != left2.end(); it++) ans += (*it).first;
        for (auto it = right2.begin(); it != right2.end(); it++) ans += (*it).first;

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

Measured memory_bytes: 24112
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > P;
int main()
{
  ll n,m,ans=0;
  cin>>n>>m;

  cout<<(1900*m+100*(n-m))*pow(2,m)<<endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "6", "1 2 3 4 5 6" ].parse.expand.solve == 1 );
	assert( [ "2", "10 -10" ].parse.expand.solve == 20 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto x = as[ 0 ];
	auto y = as[ 1 .. $ ].sum;
	auto d = ( x - y ).abs;
	foreach( a; as[ 1 .. $ - 1 ] )
	{
		x += a;
		y -= a;
		d = min( d, ( x - y ).abs );
	}
	return d;
}


Measured memory_bytes: 10880
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int len;
  scanf("%d", &len);
  unordered_map<int64, int> cnt;
  while (len--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    for (int u = max(0, x - 2); u <= x && u + 3 <= n; ++u) {
      for (int v = max(0, y - 2); v <= y && v + 3 <= m; ++v) {
        cnt[(int64)u * m + v]++;
      }
    }
  }
  vector<int64> ret(10);
  for (auto& it : cnt) {
    ret[it.second]++;
  }
  ret[0] = (int64)(n - 2) * (m - 2) - accumulate(ret.begin() + 1,
                                                 ret.end(), 0);
  for (int i = 0; i < 10; ++i) {
    printf("%lld\n", ret[i]);
  }
  return 0;
}


Measured memory_bytes: 36624
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        _k: usize,
        ss: [Chars; h],
    }

    let mut ans = vec![vec![0; w]; h];
    let mut id = 1;
    let mut vec = vec![0; w];
    let mut line = vec![];

    for i in 0..h {
        line.clear();
        for j in 0..w {
            if ss[i][j] == '#' {
                line.push(j);
            }
        }
        if line.len() > 0 {
            line.push(w);
            for i in 0..line[0] {
                vec[i] = id;
            }
            for i in 1..line.len() {
                let (l, r) = (line[i - 1], line[i]);
                for i in l..r {
                    vec[i] = id;
                }
                id += 1;
            }
        }
        if vec[0] != 0 {
            for i in (0..=i).rev() {
                if ans[i][0] != 0 {
                    break;
                }
                for (j, &e) in vec.iter().enumerate() {
                    ans[i][j] = e;
                }
            }
        }
    }

    for line in ans.iter() {
        let line = line
            .into_iter()
            .map(|e| e.to_string())
            .collect::<Vec<_>>()
            .join(" ");
        println!("{}", line);
    }
}


Measured memory_bytes: 3004