akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll N;
    char s[105], t[105];
    in(N); ins(s); ins(t);
    ll ans=N;
    rep(i, N){
        if(strncmp(s+i, t, N-i)) ans++;
        else break;
    }
    put(ans);
    return 0;
}


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

struct TTree
{
private:
	struct TNode
	{
	public:
		int Id;
		TNode* Parent;
		TNode* LChild;
		TNode* RChild;
		TNode(int Value)
		{
			Id = Value;
			Parent = NULL;
			LChild = NULL;
			RChild = NULL;
		}
	};
	TNode* Root;
	void Delete(const TNode* Node)
	{
		if(Node == NULL) return;
		Delete(Node->LChild);
		Delete(Node->RChild);
		delete Node;
	}
	void InorderOutput(const TNode* Node)
	{
		if(Node == NULL) return;
		InorderOutput(Node->LChild);
		cout << ' ' << Node->Id;
		InorderOutput(Node->RChild);
	}
	void PreorderOutput(const TNode* Node)
	{
	    if(Node == NULL) return;
	    cout << ' ' << Node->Id;
	    PreorderOutput(Node->LChild);
	    PreorderOutput(Node->RChild);
	}
	void Insert(TNode* z)
	{
	    assert(z != NULL);
		TNode* y = NULL;
		TNode* x = Root;
		while(x != NULL){
			y = x;
			if(z->Id < x->Id){
				x = x->LChild;
			}else{
				x = x->RChild;
			}
		}
		z->Parent = y;
		if(y == NULL){
			Root = z;
		}else if(z->Id < y->Id){
			y->LChild = z;
		}else{
			y->RChild = z;
		}
	}
public:
	TTree()
	{
		Root = NULL;
	}
	~TTree()
	{
		Delete(Root);
	}
	void Insert(int Id)
	{
		Insert(new TNode(Id));
	}
	void Print()
	{
		InorderOutput(Root);
		cout << endl;
		PreorderOutput(Root);
		cout << endl;
	}
};

int main()
{
	int n;
	cin >> n;
	TTree Tree;
	for(int i = 0; i < n; i++){
		string Command;
		cin >> Command;
		if(Command == "insert"){
			int Id;
			cin >> Id;
			Tree.Insert(Id);
		}else{
			Tree.Print();
		}
	}
    return 0;
}

Measured memory_bytes: 26568
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin>>s;
    REP(i,s.size()){
        cout<<'x';
    }
    cout<<endl;

    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[100100];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  rep(i,n+1) dp[i]=i;
  
  rep(i,n){
    for(ll j=6; i+j<=n; j*=6){
      chmin(dp[i+j],dp[i]+1);
    }
    for(ll j=9; i+j<=n; j*=9){
      chmin(dp[i+j],dp[i]+1);
    }
  }
  cout<<dp[n]<<endl;
}

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

int main(){

    size_t n, m, l;
    std::cin >> n >> m >> l;

    std::vector<std::vector<size_t>> mat1(n, std::vector<size_t>(m));
    std::vector<std::vector<size_t>> mat2(m, std::vector<size_t>(l));
    std::vector<std::vector<size_t>> ans(n, std::vector<size_t>(l, 0));

    for(auto&& v : mat1){
        for(auto&& e : v){
            std::cin >> e;
        }
    }

    for(auto&& v : mat2){
        for(auto&& e : v){
            std::cin >> e;
        }
    }

    for(size_t i = 0; i < n; i++){
        for(size_t j = 0; j < l; j++){
            for(size_t k = 0; k < m; k++){
                ans[i][j] += mat1[i][k] * mat2[k][j];
            }
        }
    }

    for(const auto& v : ans){
        for(size_t i = 0; i < v.size(); i++){
            if(i + 1 != v.size()){
                std::cout << v[i] << ' ';
            }else{
                std::cout << v[i];
            }
        }std::cout << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3208
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=1e2+5;
const ll M=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

ll n,W,w[N],v[N],dp[N][M];

ll F(ll idx,ll val)
{
	if(val==0){return 0;}
	if(val<0||idx==n){return INF;}
	if(dp[idx][val]!=-1){return dp[idx][val];}
	ll x=F(idx+1,val);
	ll y=w[idx]+F(idx+1,val-v[idx]);
	return dp[idx][val]=min(x,y);
}

int main()
{
	cin>>n>>W;
	ll maxi=0;
	ms(dp,-1);
	for(ll i=0;i<n;i++){cin>>w[i]>>v[i];}
	for(ll i=1;i<=M;i++)
	{
		ll ans=F(0,i);
		if(ans<=W){maxi=i;}
	}
	cout<<maxi<<endl;
}


Measured memory_bytes: 82432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int a;
    string s;
    cin >> a >> s;
    
    if (a >= 3200) out(s);
    else out("red");
    
    
}


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

int main() {
  int N;
  cin >> N;
  if (N == 1)
    cout << "Hello World" << endl;
  else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}



Measured memory_bytes: 256
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val aInput =  scala.io.StdIn.readLine()
  val lengthAfterDistinct = aInput.split(" ").toVector.distinct.length

  if (n == lengthAfterDistinct) {
    println("YES")
  } else {
    println("NO")
  }
}


Measured memory_bytes: 77408
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10],b[111];
int main()
{
    int s=0;
    for(int i=1;i<=3;i++)
    {
        cin>>a[i];//输入颜色
        b[a[i]]++;//标记入桶
    }
    for(int i=0;i<=111;i++)
    {
        if(b[i]>0)//判断
        {
            s++;//计数
        }
    }
    cout<<s;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
using namespace std;

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

    int a[110];
    int sum = 0;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + N, greater<int>());

    int alice = 0;
    for (int i = 0; i < N; i += 2) {
        alice += a[i];
    }
    cout << alice - (sum - alice) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sum = 0;
        for(int i = 0; i < n - 1; i++)
        {
            for(int j = i + 1; j < n; j++)
            {
                sum += d[i] * d[j];
            }
        }

        Console.WriteLine(sum);

    }
}


Measured memory_bytes: 13396
M, D  = list(map(int, input().split()))

"""
d10 = D // 10
d1  = D %  10
ans = 0

for i in range(2,d10+1):
    for j in range(2,d1+1):
        if i*j <= M:
            ans += 1
"""
ans = 0
for d in range(D+1):
    d10 = d // 10
    d1 = d % 10
    if d10 * d1 <= M:
        if d10 >= 2 and d1 >= 2:
            ans += 1
    

print(ans)


Measured memory_bytes: 3060
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,h,m = mi()

rad_m = m
rad_h = h*5+5*(m/60)

r = min(abs(rad_m-rad_h),360-abs(rad_m-rad_h))
rad = 360*r/60

print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(rad))))

Measured memory_bytes: 9520
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	l := make([]int, 2*n)
	for i := 0; i < 2*n; i++ {
		fmt.Scan(&l[i])
	}
	sort.Ints(l)
	ans := 0
	for i := 0; i < 2*n; i += 2 {
		if l[i] < l[i+1] {
			ans += l[i]
		} else {
			ans += l[i+1]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
def main():
    N = int(input())
    D, X = map(int, input().split())
    ans = 0
    for _ in range(N):
        A = int(input())
        for i in range(105):
            if i*A+1 <= D:
                ans += 1
            else:
                break
    ans += X
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
//package cf;
import java.io.*;
import java.util.*;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    static int p=1000000007;
    static int dp[]=new int[100000];
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();
        int tc=sc.nextInt();
        int ar[]=new int[tc];
        for(int i=0;i<tc;i++)
            ar[i]=sc.nextInt();

        Arrays.fill(dp,-1);

        //System.out.println(frog(ar,0)+" "+Arrays.toString(dp));

        out.write(""+((frog(ar,0))));
        out.flush();
    }
    public static  int frog(int ar[],int i)
    {
        if(i==ar.length-1)
            return 0;
        if(i>=ar.length)
            return Integer.MAX_VALUE;
        if(dp[i]!=-1)
            return dp[i];

        int r1=Math.abs(ar[i]-ar[i+1])+frog(ar,i+1);
        int r2=i+2>=ar.length?Integer.MAX_VALUE:(Math.abs(ar[i]-ar[i+2])+frog(ar,i+2));

            dp[i]=Math.min(r1,r2);
            //System.out.println(i+" "+dp[i]+" "+frog(ar,i+1));
            return dp[i];
    }






    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }


}


Measured memory_bytes: 45316
user = int(input())
sum = 0
for i in range(1,user+1):
    if i%3==0 or i%5==0:
        i = "Fizzbuzz"
    elif(i%3==0):
        i = "Fizz"
    elif(i%5==0):
        i = "Buzz"
    elif(i%3!=0 or i%5!=0):
        sum = sum+i
print(sum)



Measured memory_bytes: 9184
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int H,W,D; cin >> H >> W >> D;
    vector<vector<int>> A(H,vector<int>(W));
    rep(i,H) rep(j,W) cin >> A[i][j];

    map<int, pii> dic;
    rep(i,H) {
        rep(j,W) {
            dic[A[i][j]-1] = make_pair(i,j);
        }
    }
    vector<ll> dist(H*W);
    rep(i,H*W) {
        if (i < D) dist[i] = 0;
        else {
            ll x,y,px,py;
            tie(y,x) = dic[i];
            tie(py,px) = dic[i-D];
            dist[i] = dist[i-D]+abs(y-py)+abs(x-px);
        }
    }
    int Q; cin >> Q;
    while (Q--) {
        int L,R; cin >> L >> R;
        L--; R--;
        cout << dist[R] - dist[L] << ln;
    }
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int n, t, a;
  cin >> n >> t >> a;
  vector<pair<double,int>> h(n);
  rep(i,n) {
    h.at(i).second = i;
    cin >> h.at(i).first;
    h.at(i).first = abs(a - t+h.at(i).first*0.006);
  }
  sort(h.begin(),h.end());
  cout << h.at(0).second + 1;
}

Measured memory_bytes: 256
l, r = map(int, input().split())
if r - l >= 2018:
    print(0)
else:
    min_ij = 2018
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            min_ij = min(min_ij, ((i % 2019) * (j % 2019)) % 2019)
    print(min_ij)

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

int main(){

	int n,m,l;
	cin >>n >>m >>l;

	int vA[n][m],vB[m][l];
	unsigned long ans[n][l];

//	初期化
	for(int i=0;i<n;i++)
		for(int k=0;k<l;k++)
			ans[i][k] = 0;
//	数列の入力
	for(int i=0;i<n;i++)
		for(int k=0;k<m;k++)
			cin >> vA[i][k];
	for(int i=0;i<m;i++)
			for(int k=0;k<l;k++)
				cin >> vB[i][k];
//	計算処理
	for(int i=0;i<n;i++)
		for(int t=0;t<l;t++)
			for(int k=0;k<m;k++)
				ans[i][t] += vA[i][k] * vB[k][t];
//	表示
	for(int i=0;i<n;i++)
		for(int k=0;k<l;k++)
			if(k != l-1)
				cout << ans[i][k] <<" ";
			else
				cout << ans[i][k] <<endl;;
	return 0;
}



Measured memory_bytes: 3236
#include<stdio.h>
int nationalbudget(){
	int xsize=0,ysize=0,k=0;
	char x[101],y[101];
	scanf("%s",x);
	scanf("%s",y);
	for(int i=0;x[i]!='\0';i++){
		xsize++;
		if(i>79){
			printf("overflow\n");
			return 0;}}
	for(int i=0;y[i]!='\0';i++){
		ysize++;
		if(i>79){
			printf("overflow\n");
			return 0;}}
	if(xsize>=ysize){
		for(int i=0;i<xsize;i++){
			if(ysize-1-i>=0){
				int t=(x[xsize-1-i]-'0')+(y[ysize-1-i]-'0')+k;
				if(t>=10){
					if(i==79){
						printf("overflow\n");
						return 0;}
					else{
						k=1;
						t%=10;}}
				else k=0;
				x[xsize-1-i]=t+'0';}
			else{
				int t=(x[xsize-1-i]-'0')+k;
				if(t>=10){
					if(i==79){
						printf("overflow\n");
						return 0;}
					else{
						k=1;
						t%=10;}}
				else k=0;
				x[xsize-1-i]=t+'0';}}
		if(k==1)printf("1");
		for(int i=0;i<xsize;i++)printf("%c",x[i]);}
	else{
		for(int i=0;i<ysize;i++){
			if(xsize-1-i>=0){
				int t=(x[xsize-1-i]-'0')+(y[ysize-1-i]-'0')+k;
				if(t>=10){
					if(i==79){
						printf("overflow\n");
						return 0;}
					else{
						k=1;
						t%=10;}}
				else k=0;
				y[ysize-1-i]=t+'0';}
			else{
				int t=(y[ysize-1-i]-'0')+k;
				if(t>=10){
					if(i==79){
						printf("overflow\n");
						return 0;}
					else{
						k=1;
						t%=10;}}
				else k=0;
				y[ysize-1-i]=t+'0';}}
		if(k==1)printf("1");
		for(int i=0;i<ysize;i++)printf("%c",y[i]);}
	printf("\n");}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)nationalbudget();
	return 0;}


Measured memory_bytes: 2520
fun main(args :Array<String>) {
    val n = readInteger()
    val aArray = readIntegerList().toIntArray()

    var m = 0
    val boxes = IntArray(n)
    for (i in (n - 1) downTo 0) {
        var count = 0
        val s = i + 1
        for (j in i until n step s) {
            count += boxes[j]
        }

        if (count % 2 != aArray[i]) {
            m++
            boxes[i] = 1
        }
    }

    println(m)
    boxes.mapIndexed { index, it ->
        if (it == 1) index + 1 else 0
    }.filter { it > 0 }
    .joinToString(" ")
    .let { println(it) }
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 81204
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vs S(N); REP(i, N) cin >> S[i];
    int ans = 0;
    REP(i, N)
    {
        bool isSymmetry = true;
        REP(j, N)
        {
            REP(k, N)
            {
                if(S[(i+j)%N][k] != S[(i+k)%N][j]) isSymmetry = false;
            }
        }
        if(isSymmetry) ans += N;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
/*input
8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2
*/
/**
    Author: Kristopher Paul
    Date Created: 04-05-2020
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
 
//Uncomment for File I/O
//ifstream fin("input.in")
 
//using namespace __gnu_pbds;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset
 
int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;
 
        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n,m,x;
    cin >> n >> m >> x;
    int c[n];
    int arr[n][m];
    FOR(i,0,n){
        cin >> c[i];
        FOR(j,0,m){
            cin >> arr[i][j];
        }
    }
    int ans = 1e18;
    FOR(mask,1,(1<<n)){
        int cans = 0;
        int val[m] = {};
        FOR(i,0,n){
            if(mask & (1<<i)){
                cans += c[i];
                FOR(j,0,m){
                    val[j] += arr[i][j];
                }
            }
        }
        bool can = true;
        FOR(i,0,m){
            if(val[i] < x){
                can = false;
                break;
            }
        }
        if(!can){
            continue;
        }
        remin(ans,cans);
    }
    if(ans == 1e18){
        ans = -1;
    }
    cout << ans << endl;
}
 
signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}

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

int main(){
	ll n;
	cin>>n;
	string ans="";
	while(n>0){
		ans+= ('a' + (n-1)%26);
		n=(n-1)/26;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<'\n';


	return 0;
}

Measured memory_bytes: 3632
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, w) = i.read2::<usize, usize>();
    let mut wv = Vec::new();
    for _ in 0..n {
        wv.push(i.read2::<usize, usize>());
    }
    writeln!(o, "{}", solve(w, &wv)).unwrap();
}
fn solve(w: usize, wv: &[(usize, usize)]) -> usize {
    fn get(w: usize, wv: &[(usize, usize)], m: &mut Vec<Vec<Option<usize>>>) -> usize {
        if w == 0 || wv.len() == 0 {
            return 0;
        }
        if let &Some(value) = &m[wv.len()][w] {
            return value;
        }
        let mut v = get(w, &wv[1..], m);
        let (w0, v0) = wv[0];
        if w >= w0 {
            v = max(v, get(w - w0, &wv[1..], m) + v0);
        }
        m[wv.len()][w] = Some(v);
        v
    }
    let mut m = vec![vec![None; w + 1]; wv.len() + 1];
    get(w, wv, &mut m)
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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; }
const ll MOD = 1e9+7;

int main(){
    int N;
    ll x;
    cin >> N >> x;
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
    }

    ll last = 0;
    ll ans = 0;
    REP(i,N){
        ll a = A[i];
        if(last + a > x){
            ans += a - (x - last);
            a -= a - (x - last);
        }
        last = a;
    }

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


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    string s; cin >> s;
    int n = s.size();
    if(s[0] != s[n-1]){
        if((n-2) % 2 == 0){
            cout << "Second" << endl;
        }
        else cout << "First" << endl;
    }
    else{
        if((n-2) % 2 == 0){
            cout << "First" << endl;
        }
        else cout << "Second" << endl;
    }
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    string str;
    cin >> str;
    while( str[0] != '-'){
	  int q;
	  cin >> q;
	  for(int i = 0; i < q; i++){
		   int x;
		   cin >> x;
		   string ret = str.substr(0, x);
		   str.erase(0, x);
		   str += ret;
		}
	cout << str << endl;
	cin >> str; 	
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3192
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 3e3 + 111;
     
using namespace std;

int n, q;
ld dp[maxn][maxn], p[maxn], ans;
                           
void solve(){
	cin >> n;  

	for (int i = 1; i <= n; i++)
		cin >> p[i];

	dp[0][0] = 1;

	for (int i = 1; i <= n; i++){
		dp[i][0] = dp[i - 1][0] * (1 - p[i]);
		for (int j = 1; j <= i; j++){
			dp[i][j] = dp[i - 1][j - 1] * p[i] + (1 - p[i]) * dp[i - 1][j];
		}
	}

	int k = n / 2 + ((n + 1) % 2);

	for (int i = n, j = 0; i > j; i--, j++)
		ans += dp[n][i];

	cout << fixed << setprecision(9) << ans;
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}


Measured memory_bytes: 145920
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N;
vector<ll> dfs(vector<vector<ll>>& connect, ll start)
{
  vector<ll> res(N, -1);
  res.at(start) = 0;
  queue<ll> q;
  q.push(start);
  while (!q.empty())
  {
    ll now = q.front();
    q.pop();
    for (ll i = 0; i < connect.at(now).size(); ++i)
    {
      if (res.at(connect.at(now).at(i)) != -1)
      {
        continue;
      }
      res.at(connect.at(now).at(i)) = res.at(now) + 1;
      q.push(connect.at(now).at(i));
    }
  }
  return res;
}

int main()
{
  ll u, v;
  cin >> N >> u >> v;
  vector<vector<ll>> connect(N);
  for (ll i = 0; i < N - 1; ++i)
  {
    ll A, B;
    cin >> A >> B;
    connect.at(A - 1).push_back(B - 1);
    connect.at(B - 1).push_back(A - 1);
  }
  // for (ll i = 0; i < N; ++i)
  // {
  //   for (ll j = 0; j < connect.at(i).size(); ++j)
  //   {
  //     cout << connect.at(i).at(j) << ' ';
  //   }
  //   cout << endl;
  // }
  vector<ll> aoki_time = dfs(connect, v - 1);
  queue<ll> q;
  q.push(u - 1);
  vector<ll> dist(N, -1);
  dist.at(u - 1) = 0;
  ll ans = aoki_time.at(u - 1) - (connect.at(u - 1).size() == 1 ? 1:0);
  while (!q.empty())
  {
    ll now = q.front();
    q.pop();
    for (ll i = 0; i < connect.at(now).size(); ++i)
    {
      if (dist.at(connect.at(now).at(i)) != -1)
      {
        continue;
      }
      ans = max(ans, aoki_time.at(connect.at(now).at(i)) - (connect.at(connect.at(now).at(i)).size() == 1 ? 1:0));
      if (aoki_time.at(connect.at(now).at(i)) <= dist.at(now) + 1)
      {
        continue;
      }
      q.push(connect.at(now).at(i));
      dist.at(connect.at(now).at(i)) = dist.at(now) + 1;
    }
  }
  cout << ans << endl;
  // cout << "dist" << endl;
  // for (ll i = 0; i < N; ++i)
  // {
  //   cout << dist.at(i) << ' ';
  // }
  // cout << endl;
  // cout << "aoki" << endl;
  // for (ll i = 0; i < N; ++i)
  // {
  //   cout << aoki_time.at(i) << ' ';
  // }
  // cout << endl;

}


Measured memory_bytes: 8064
import java.util.*;

//幾何
class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			int a1=sc.nextInt(),a2=sc.nextInt(),b1=sc.nextInt();
			int count=0;
			for(int i=1;i<=10;i++){
				if(a1+a2+i<=20){
					int card=1;
					if(a1==i)card--;
					if(a2==i)card--;
					if(b1==i)card--;
					count+=card;
				}
			}
			ln(count>=7*0.5?"YES":"NO");
		}
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
int dist[300005];

int main() {
  // bfs、各頂点の状態数３
  int N, M;
  cin >> N >> M;
  vector<int> graph[3*N];  // 0-indexed
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    a *= 3; b *= 3;
    rep(j, 3) {
      graph[a+j].push_back(b+((j+1)%3));
      // graph[b+j].push_back(a+((j+1)%3));
    }
  }
  queue<P> que;
  rep(i, 3*N) dist[i] = INF;
  auto push = [&](int x, int d) {
    if (dist[x] < d) return;
    dist[x] = d;
    for (auto next : graph[x]) {
      if (dist[next] == INF) que.push(P(next, d+1));
    }
  };
  int S, T;
  cin >> S >> T;
  --S; --T;
  S *= 3; T *= 3;
  push(S, 0);
  while (!que.empty()) {
    auto p = que.front(); que.pop();
    int x = p.first, d = p.second;
    if (dist[x] == INF) push(x, d);
  }
  int ans = dist[T];
  if (ans == INF) ans = -1;
  else ans /= 3;
  cout << ans << '\n';
  return 0;
}

// 40

Measured memory_bytes: 21108
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2){
		cout<<min(a-1,n-b)+1+(b-1-a)/2<<endl;
	}else{
		cout<<abs((a+b)/2-a)<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    char s[105];
    int n,mx=0,x=0;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I') x++;
        else if(s[i]=='D') x--;
        if(mx<x) mx=x;
    }
    cout<<mx<<endl;
    return 0;
}



Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let v: Vec<i32> = read_vec();
    let (a,b) = (v[0], v[1]);
    println!("{} {} {}",
        a / b,
        a % b,
        a as f64 / b as f64
    );
}



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


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

    int answer = 0;

    for(int j=1; j<n-1; j++){
        if(p[j+1] > p[j] && p[j] > p[j-1]){
            answer++;
        }
        else if(p[j-1] > p[j] && p[j] > p[j+1]){
            answer++;
        }
    }

    cout << answer;
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  string s; cin >> s;
  ll k; cin >> k;
  vector<pair<char, ll> > v;
  ll n = s.size();
  REP(i,n){
    char tmp = s[i];
    ll c = 1;
    while(s[i + 1] == tmp){
      i ++;
      c ++;
    }
    v.push_back(make_pair(tmp,c));
  }
  // REPvec(itr,v){
  //   cout << itr->first << " " << itr->second << endl;
  // }
  if(v.size() == 1){
    cout << (v[0].second*k)/2 << endl;
  }else if(v.front().first == v.back().first){
    ll ans = 0;
    for(int i = 1; i < v.size() - 1; i ++){
      ans += v[i].second/2;
    }
    ans *= k;
    ans += (k - 1)*((v.front().second + v.back().second)/2);
    ans += v.front().second/2;
    ans += v.back().second/2;
    cout << ans << endl;
  }else{
    ll ans = 0;
    REPvec(itr, v){
      ans += itr->second/2;
    }
    cout << k*ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    string tmp="ABC";
    for(int i=0;i+2<n;i++)
        ans+=(s.substr(i,3)==tmp);
    cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > u;
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    u.push_back({a, b});
  }
  sort(u.begin(), u.end());
  long long ans = 0;
  for(int i = 0; i < n; i++){
    int take = min(m, u[i].second);
    ans += 1ll * take * u[i].first;
    m -= take;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    
    if((s[0]=='a')||(s[1]=='a')||(s[2]=='a')){
        if((s[0]=='b')||(s[1]=='b')||(s[2]=='b')){
            if((s[0]=='c')||(s[1]=='c')||(s[2]=='c')){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
unsigned shift(unsigned b, int x)
{
	return x>=0 ? (b>>x) : (b<<-x);
}
#define P(x,y) (fp[y]&shift(fb,x))
#include<stdio.h>
char map[9][11];
int right_wall (int x, int y, int d)
{
	switch (d) {
	case 0: // R
		if (x < 4)
			return map[y*2][x] - '0';
		else
			return 0;
	case 1: // D
		if (y < 4)
			return map[y*2+1][x] - '0';
		else
			return 0;
	case 2: // L
		if (x > 0)
			return map[y*2][x-1] - '0';
		else
			return 0;
	case 3: // U
		if (y > 0)
			return map[y*2-1][x] - '0';
		else
			return 0;
	}
	return 0;
}
int main()
{
	static const int dx[] = {1, 0, -1, 0};
	static const int dy[] = {0, 1, 0, -1};
	int i, x=0, y=0, d=0;
	for (i = 0; i < 9; i ++)
		fgets(map[i], 11, stdin);
	do {
		if (right_wall(x, y, (d+3)%4))
			d = (d+3) % 4;
		else
			while (!right_wall (x, y, d))
				d = (d+1) % 4;
		putchar("RDLU"[d]);
		x += dx[d];
		y += dy[d];
	} while (x || y);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr itr operator * () const { return i; }
    constexpr bool operator != (iterator x) const { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_): l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const { return l; }
  constexpr iterator end() const { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr itr operator * () const { return i; }
    constexpr bool operator != (iterator x) const { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const { return r; }
  constexpr iterator end() const { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

std::vector<i32> calc_next(const std::vector<i32> &vec) {
  i32 N = vec.size();
  std::vector<i32> sum(N + 1);
  for (auto i: range(0, N)) {
    sum[std::max<i32>(0, i - vec[i])]++;
    sum[std::min<i32>(N, i + vec[i] + 1)]--;
  }
  std::vector<i32> res(N);
  for (auto i: range(0, N)) {
    res[i] = sum[i];
    sum[i + 1] += sum[i];
  }
  return res;
}

int main() {
  size_t N, K;
  std::cin >> N >> K;
  std::vector<i32> A(N);
  for (auto &x: A) {
    std::cin >> x;
  }
  for (auto i: range(0, std::min<i32>(K, 100))) {
    A = calc_next(A);
  }
  for (auto i: range(0, N)) {
    std::cout << A[i] << (i + 1 == N ? '\n' : ' ');
  }
  return 0;
}


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

float fourfive(float f);

int main(void){
    float a,b,c,d,e,f;
    float x,y;
    float tmp1,tmp2,tmp3;
    int xx, yy;

    while(1){
        a = 2000;

        scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f);
        if(a == 2000)break;

        tmp1 = c*e - b*f;
        tmp2 = a*e - b*d;
        x = tmp1 / tmp2;
        tmp1 = a*f - c*d;
        tmp2 = a*e - b*d;
        y = tmp1 / tmp2;
        
        x = fourfive(x);
        y = fourfive(y);

        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

float fourfive(float f){

    int ff;

    if(f > 0.0){
        f *= 1000.0;
        f += 0.5;
        ff = (int)f;
        f = (float)ff / 1000.0;
    }
    else {
        f *= -1000.0;
        f += 0.5;
        ff = (int)f;
        f = (float)(-1 * ff) / 1000.0;
    }

    return f;
}

Measured memory_bytes: 648
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    lenV = len(V)

    res = 0
    for k in range(1, K+1):
        if lenV < k: break
        for rk in range(k+1):
            pick_list = V[:k-rk]
            if 0 < rk:
                pick_list.extend(V[-rk:])
            pick_list.sort()

            # remove negative number in pick_list
            not_neg_start_index = 0
            for i, num in enumerate(pick_list):
                if num < 0: continue
                else:
                    not_neg_start_index = i
                    break
            pos_sum = sum(pick_list[i:])
            neg_list = pick_list[:i]
            len_neg_list = len(neg_list)
            if K-k < len_neg_list:
                res = max(res, sum(neg_list[K-k:])+pos_sum)
            else:
                res = max(res, pos_sum)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41068
from bisect import bisect_left
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N = int(input())
LR = []
for _ in range(N):
    x, l = inpl()
    LR.append((x-l,x+l))
LR.sort()
L = [LR[i][0] for i in range(N)]
R = [LR[i][1] for i in range(N)]
minR = [0] * N
minR[N-1] = R[N-1]
for i in range(N-2,-1,-1):
    minR[i] = min(minR[i+1], R[i])
ans = 0
r = minR[0]
while True:
    ans += 1
    i = bisect_left(L, r)
    if i > N-1:
        break
    else:
        r = minR[i]
print(ans)

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

int main() {
  ll n;
  cin >> n;
  ll a[n+1];
  vector<int> v;
  rep(i,n+1) a[i] = 0;
  rep(i,n){
    ll b; cin >> b;
    v.push_back(b);
    ++a[b];
  }
  ll sum = 0;
  for(int i = 1; i <= n; ++i) {
    sum += a[i] * (a[i]-1) /2;
  }

  for(int i = 1; i<=n; ++i){
    int j = i-1;
    cout << sum - a[v[j]]*(a[v[j]]-1)/2 + (a[v[j]]-1)*(a[v[j]]-2)/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 5108
n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

counts = as.each.with_object(Array.new(n + 1, 0)) do |a, arr|
  arr[a] += 1
end.sort!

ans = 0
until counts.size == k
  ans += counts.shift
end

puts ans


Measured memory_bytes: 18432
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<math.h>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 100;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

int hoge[MAXN];

constexpr int power(int b, int i){
  if (i == 1) return b % MOD;
  if (i % 2 == 0) {
    return power(b*b % MOD, i/2) ;
  } else {
    return power(b*b % MOD, i/2)*b % MOD ;
  }
}

constexpr int factseed(int n){
  if (n == 0 ) return 1;
  return (n * (factseed(n-1))) % MOD;
}

constexpr int invMod(int n){
  return power(n,MOD - 2);
}


template<int N>
struct Facts {
    constexpr Facts() : arr() {
        for (auto i = 0; i != N; ++i){
            arr[i] = factseed(i); 
        }
    }
    int arr[N];
};

constexpr auto facts = Facts<MAXN>();
constexpr int fact(int n){
  return facts.arr[n];
}

template<int N>
struct Finv {
    constexpr Finv() : arr() {
        for (auto i = 0; i != N; ++i){
            arr[i] = invMod(fact(i)); 
        }
    }
    int arr[N];
};

constexpr auto finvs = Finv<MAXN>();

int combination(int m, int n){
  if(m<0 || n < 0 || m < n) return 0;
  return (((fact(m)*invMod(fact(n))) % MOD) * invMod(fact(m-n))) % MOD;
}

int perm(int m,int n){
  if (n == 0) return 1;
  return m * (perm (m-1, n-1));
}

signed main(){
    int N, P;
    cin >> N >> P;
    int even_counts = 0;
    int odd_counts = 0;
    for (int i = 0; i < N; i++){
      int a;
      cin >> a;
      if (a % 2 == 0){
       even_counts++;
      }
    }
    odd_counts = N - even_counts;
    if (P == 0){// must be even
      int prod = 0;
      for(int i = 0; i<= odd_counts  ; i += 2){
        prod += combination(odd_counts, i);
      }
      printf("%lld\n",prod *(int)pow(2, even_counts));
    } else {
      int prod = 0;
      for(int i = 1; i<= odd_counts ; i += 2){
        prod += combination(odd_counts, i);
      }
      printf("%lld\n",prod *(int)pow(2, even_counts ));
    }
    return 0;
}


Measured memory_bytes: 256