akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, K;
int a, b;
vector<vector<int>> G;

ll count(int now, int from) {
    ll n_cand, n_case;
    if(from == -1) {
        n_case = K;
        n_cand = K - 1;
    } else {
        n_case = 1;
        n_cand = K - 2;
    }
    if(K < G[now].size()) return 0;
    for(auto dst : G[now]) {
        if(dst == from) continue;
        n_case = (n_case * count(dst, now)) % MOD;
        n_case = (n_case * n_cand) % MOD;
        n_cand--;
    }
    for(auto dst : G[now]) {
        if(dst == from) continue;
    }
    return n_case;
}

int main() {
    fastio();
    cin >> N >> K;
    G.resize(N);
    REP(i, N - 1) {
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i, N) sort(ALL(G[i]));
    ll ans = count(0, -1);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9984
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		HashSet<Integer> set = new HashSet<>();
		for(int i=1;i<10;i++) {
			for(int j=1;j<10;j++) {
				set.add(i*j);
			}
		}
		if(set.contains(N)) {
			out.println("Yes");
		}
		else {
			out.println("No");
		}

		out.flush();
	}
}

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

int main(){
  int N;
  cin >> N;
  double A[N];
  double ans = 0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    A[i] = 1.0/A[i];
    ans += A[i];
  }
  cout << fixed << setprecision(10);
  cout << 1.0/ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main() {
    int n,k,s;
    cin>>n>>k>>s;
    if(n-k<s){
        REP(i,n){
            if(i<k)cout<<s;
            else cout<<1;
            if(i==n-1)cout<<endl;
            else cout<<" ";
        }
    }else{
        REP(i,n){
            if(i<k)cout<<s;
            else cout<<1000000000;
            if(i==n-1)cout<<endl;
            else cout<<" ";
        }
    }
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define N 200010
using namespace std;
int a[N],b[N];
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int main()
{
	int n=inn();
	for(int i=1;i<=n;i++) a[i]=b[i]=inn();
	sort(b+1,b+n+1);int k=n/2;
	for(int i=1;i<=n;i++)
		if(a[i]>=b[k+1]) printf("%d\n",b[k]);
		else printf("%d\n",b[k+1]);
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	FOR(i,0,5)cout<<s[i];
	cout << ' ';
	FOR(i,6,13)cout<<s[i];
	cout << ' ';
	FOR(i,14,19)cout<<s[i];
	cout << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
HashMap<Integer,Integer> dic=new HashMap<Integer,Integer>();
ArrayList<Integer> array1=new ArrayList<Integer>();
ArrayList<Integer> array2=new ArrayList<Integer>();
boolean flag=false;
while((line=br.readLine())!=null){
if(line.isEmpty()){
flag=true;
continue;
}
String[] words=line.split(",");
int num=Integer.parseInt(words[0]);
if(!flag){
array1.add(num);
}
else{
if(array1.indexOf(num)>=0){
array2.add(num);
}
}
if(!dic.containsKey(num)){
dic.put(num,1);
}
else{
dic.put(num,dic.get(num)+1);
}
}
Collections.sort(array2);
for(int i=0;i<array2.size();i++){
System.out.println(array2.get(i)+" "+dic.get(array2.get(i)));
}
}
}

Measured memory_bytes: 16916
package main

import (
	. "fmt"
)
func main(){
	X:=0
	Y:=0
	Z:=0
	ct:=0
	Scan(&X,&Y,&Z)
	X=X-Z
	for {

		X=X-(Y+Z)
		if X<0 {
			
			break
		}else{
			ct++
		}
	}
	Println(ct)
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
//#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
 
int32_t main()
{
	fastio();
	int n;
	cin>>n;
	map<int,int> mp;
	int sum=0;

	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		mp[x]++;
		sum+=x;
	}
	int q;
	cin>>q;
	while(q--)
	{
		int a,b;
		cin>>a>>b;
		int c=mp[a];
		sum-=a*c;
		sum+=b*c;
		mp[a]=0;
		mp[b]+=c;
		cout<<sum<<endl;
	}
}


Measured memory_bytes: 9520
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // ll INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;
 
// const int N = 2e5 + 5;


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      // ifstream cin("input.txt");

      int k;
      cin>>k;
      if (k%2==0 || k%5==0){
        cout<<"-1\n";
        return 0;
      }
      if (k%7==0) k/=7;
      int t = 1;
      ll now = 10;
      now%= 9*k;
      while (now != 1){
        // cout<<now<<endl;
        now*=10;
        t++;
        now%= 9*k;

      }
      cout<<t<<"\n";
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    int m = n/2;
    vector<vector<int>> v(n, vector<int> (n, 1));
    for (int i = 0; i < m; ++i) {
        v[i][m*2-i-1] = v[m*2-i-1][i] = 0;
    }
    cout << n*(n-1)/2 - m << "\n";
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            if(v[i][j]) cout << i+1 << " " << j+1 << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vll a(n);
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    vector<bool> dp(k+1,0);
    for (int i = 0; i <= k; ++i)
    {	
    	bool cur=1;
    	for (int j = 0; j < n; ++j)
    	{
    		if(a[j]<=i){
    			cur&=dp[i-a[j]];
    		}
    	}
    	dp[i]=(!cur);
    }
    if(dp[k])
    	cout<<"First"<<endl;
    else
    	cout<<"Second"<<endl;

    

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

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

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

using namespace std;

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

int n, x, ans;
vector<int> a = {1};
int dp[100003];
int main() {
    cin >> n;

    x = 6;
    while (x < 100000) {
        a.push_back(x);
        x *= 6;
    }
    x = 9;
    while (x < 100000) {
        a.push_back(x);
        x *= 9;
    }
    sort(a.begin(), a.end(), greater<int>());

    REP(i,100001){
        dp[i]=iinf;
    }

    dp[0]=0;

    REP(i,100001){
        for(auto ite=a.begin();ite!=a.end();ite++){
            if(i+*ite<100003){
                dp[i+*ite]=min(dp[i+*ite],dp[i]+1);
            }
        }
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 640
using System;

namespace AtCoder.Abcdef
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input integer
            long n = long.Parse(Console.ReadLine());
            Console.WriteLine((n + n * n + n * n * n));

            Console.Out.Flush();
        }
    }
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


ll dp[3010][3010];
ll a[3010];

ll solve(int head, int tail) {
    if(dp[head][tail] != -1) return dp[head][tail];
    if(head == tail) return a[head];
    
    return dp[head][tail] = max(a[head]-solve(head+1, tail), a[tail]-solve(head, tail-1));
}


int main() {
    int n; cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, 3010) rep(j, 3010) dp[i][j] = -1;
    
    cout << solve(0, n-1) << endl;

    return 0;
}


Measured memory_bytes: 71296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,a,b,k;
	cin>>a>>b>>k;
	for (i=0;i<k;i++)
	{
		if (i%2==0)
		{
			if (a%2==1)
			a--;
			b+=a/2;
			a/=2;
		}
		else
		{
			if (b%2==1)
			b--;
			a+=b/2;
			b/=2;
		}
	}
	cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)

int main() {string s;
cin >> s;
int oddsize;
if(s.size() % 2 == 1) oddsize = (s.size() + 1) / 2;
else oddsize = s.size() / 2;
vector<char> sodd(oddsize);
rep(i, oddsize){
  sodd.at(i) = s.at(i * 2);
}
string ans = "";
rep(i, oddsize){
  ans = ans + sodd.at(i);
}

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

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100000;
 
int main(){
    int r;
    cin >> r;
    cout << r * r * 3 << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
a = []
for i in range(n):
    a.append(tuple(map(int, input().split())))
s_list = sorted(a)
x = 0
y = 0
for i in range(n):
    x += s_list[i][1]
    y += s_list[i][0] * s_list[i][1]
    if x >= m:
        y -= s_list[i][0]*(x-m)
        break
print(y)

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

#define pai 3.141592653589

int main()
{
	double r;
	double men,syu;
	cin >> r;
	men=r*r*pai;
	syu=2*r*pai;
	printf("%lf %lf\n",men,syu);
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll a,b,c,d,e,k;
  cin >> a>> b>>c>>d>>e>>k;
  if(e-d>k) cout <<":("<<endl;
  else if(e-c>k) cout <<":("<<endl;
  else if(e-b>k) cout <<":("<<endl;
  else if(e-a>k) cout <<":("<<endl;
  else if(d-c>k) cout <<":("<<endl;
  else if(d-b>k) cout <<":("<<endl;
  else if(d-a>k) cout <<":("<<endl;
  else if(c-b>k) cout <<":("<<endl;
  else if(c-a>k) cout <<":("<<endl;
  else if(b-a>k) cout <<":("<<endl;
  else cout <<"Yay!"<<endl;
  }


Measured memory_bytes: 256
x,n=list(map(int,input().split(" ")))
if 0<n:
    p=list(map(int,input().split(" ")))

    e_min=1000
    r=[]
    for i in range(100):
        if (x-i in p):
            pass
        else:
            print(x-i)
            break
        if (x+i in p):
            pass
        else:
            print(x+i)
            break
else:
    print(x)

Measured memory_bytes: 9200
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define INF 1<<9

int main()
{
	vector<int> v;
	int a, b, c;
	cin >> a >> b >> c;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	cout << v[0] + v[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, K;
    cin>>n>>K;
    vector<int> v(n, 0);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    vector<int> lis(n, 0);
    lis[0] = 0;
    lis[1] = abs(v[1]-v[0]);
    for(int i=2; i<n; i++)
    {
        int x = INT_MAX;
        for(int k=1; k<=K; k++)
        {
            if(i-k<0)
                break;
            x = min(x, abs(v[i]-v[i-k])+lis[i-k]);
        }
        lis[i] = x;
    }
    cout<<lis[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = [int(x) for x in input().split()]
dp = [float("inf")]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
    

Measured memory_bytes: 52208
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(vector<int>& P, vector<int>& Q) {
        int n = P.size();
        vector<int> ord(n, 0);
        iota(ord.begin(), ord.end(), 1);

        int res = 0;
        int idx = 0;
        do {
            if (ord == P) {
                res += idx;
            }
            if (ord == Q) {
                res -= idx;
            }
            ++idx;
        } while (next_permutation(ord.begin(), ord.end()));
        res = abs(res);
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> P(n);
    vector<int> Q(n);

    for (int i = 0; i < n; ++i) {
        cin >> P[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> Q[i];
    }
    Solution sol;

    cout << sol.solve(P, Q) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n, x;
  cin >> n >> x;
  ll a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  ll sum = accumulate(a, a+n, 0ll);
  
  int ans;
  if(x > sum){
    ans = n-1;
  }else if(x == sum){
    ans = n;
  }else{
    sort(a, a+n);
    for(ans = 0;;ans++){
      if(a[ans] > x) break;
      x -= a[ans];
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char str[100];
int v[3];
int eq(int a,int b);
int ter(int a,int b){
	if(str[a]=='(')return eq(a+1,b-1);
	if(str[a]=='-')return 2-ter(a+1,b);
	if(str[a]>'A')return v[str[a]-'P'];
	return str[a]-'0';
}
int fac(int a,int b){
	int now=0;
	int ret=2;
	int las=a;
	for(int i=a;i<b;i++){
		if(str[i]=='(')now++;
		if(str[i]==')')now--;
		if(now==0&&str[i]=='*'){
			ret=min(ret,ter(las,i));
			las=i+1;
		}
	}
	return min(ret,ter(las,b));
}
int eq(int a,int b){
	int now=0;
	int ret=0;
	int las=a;
	for(int i=a;i<b;i++){
		if(str[i]=='(')now++;
		if(str[i]==')')now--;
		if(now==0&&str[i]=='+'){
			ret=max(ret,fac(las,i));
			las=i+1;
		}
	}
	return max(ret,fac(las,b));
}
int main(){
	while(1){
		scanf("%s",str);
		if(str[0]=='.')return 0;
		int n=strlen(str);
		int ret=0;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++){
					v[0]=i;
					v[1]=j;
					v[2]=k;
					ret+=eq(0,n)/2;
				}
		printf("%d\n",ret);
	}
}

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

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

# define pi pair<LL, LL>
# define pb push_back

namespace pre {
  const int N = 100;

  int tot, up;
  LL fib[N];
  pi g[N];
  vector<pi> exce[N];
  
  inline int f(LL a, LL b) {
    if(!a) return 0;
    if(a > b) return f(b, a);
    return f(b % a, a) + 1;
  }
  void dfs(int d, LL x, LL y) {
    if(x > fib[d + 2] || y > fib[d + 2]) return ;
    if(d == up) {
      exce[d].pb(pi(x, y));
      return ;
    }
    dfs(d + 1, y, x + y);
    dfs(d + 1, y, x + 2ll * y);
  }

  void main() {
    fib[0] = fib[1] = 1;
    for(tot = 1; fib[tot] + fib[tot - 1] <= 6e18; ++tot)
      fib[tot + 1] = fib[tot] + fib[tot - 1];
    while(fib[tot] > 1e18) --tot;
    for(int i = 1; i <= tot; ++i) 
      up = i, dfs(0, 1, 1);
  }
}
using namespace pre;

const int mod = 1e9 + 7;

int cas;
LL n, m;

int main() {
  pre :: main();
  for(cin >> cas; cas--; ) {
    read(n), read(m);
    if(n > m) swap(n, m);
    int get = -1;
    for(int i = tot; ~i; --i) 
      if(fib[i] <= n && fib[i + 1] <= m) {
        get = i;
        break;
      }        
    assert(get >= 0);
    if(get <= 1) {
      printf("1 %lld\n", n == 1 ? m % mod : 4ll);
      continue;
    }
    LL ans = 0;
    for(auto p : exce[get - 1]) {
      LL x = p.first;
      LL y = p.second;
      if(y <= n && x + y <= m) ans += (m - x) / y;
      if(y <= m && x + y <= n) ans += (n - x) / y;
    }
    printf("%d %lld\n", get, ans % mod);
  }
}

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

int main() {
	
    long long n,m,x,y;
    cin>>n>>m;
    vector<long long> adj[n+1];
    long long deg[n+1]={0};
    for(long long i=0;i<m;i++){
        cin>>x>>y;
        adj[x].push_back(y);
        deg[y]++;
    }long long ans[n+1];
    list<long long> queue;
    for(long long i=1;i<=n;i++){
        if(!deg[i]){
            queue.push_back(i);
        }ans[i]=1;
    }long long z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    for(long long i=0;i<adj[z].size();i++){
	        ans[adj[z][i]]=max(ans[adj[z][i]],ans[z]+1);
	        deg[adj[z][i]]--;
	        if(!deg[adj[z][i]]){
	            queue.push_back(adj[z][i]);
	        }
	    }
	}long long ma=-1;
	for(long long i=1;i<=n;i++){
	    ma=max(ans[i],ma);
	}cout<<ma-1;
}


Measured memory_bytes: 7424
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  c = 0
  for n in range(1, N+1):
    if len(str(n)) % 2 == 1:
      c += 1
  print(c)

if __name__ == "__main__":
  main()


Measured memory_bytes: 3064
n =int( input() )
a = input().split()
a_list = []
summ = 0
for ai in a:
  summ += int(ai) 
  a_list.append(int(ai))
ave = summ/n
result = 0
min_dis = abs(a_list[0] - ave)
for i,ai in enumerate(a_list):
  dis = abs(ai - ave)
  if dis > min_dis:
    pass
  elif dis == min_dis:
    result = min(result,i)
  else:
    min_dis = dis
    result = i
print(result)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int M = a[0] + k - a[n - 1];
    for (int i = 1; i < n; ++i) {
        M = max(M, a[i] - a[i - 1]);
    }
    cout << k - M << endl;
    return 0;
}



Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

H,W = cin.mapInt()
S = cin.stringList(H)
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            continue
        if h - 1 >= 0 and S[h - 1][w] == "#":
            continue
        if w - 1 >= 0 and S[h][w - 1] == "#":
            continue
        if h + 1 < H and S[h + 1][w] == "#":
            continue
        if w + 1 < W and S[h][w + 1] == "#":
            continue
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
const int TOT = 1 << 15, N = 100010;
int dp[TOT],n,val[N],cnt[16],ans,sta,res[TOT];
int main() {
  int a,b,c,tmp;
  scanf("%d",&n);
  for (int i = 1 ; i < n ; ++ i) {
    scanf("%d%d%d",&a,&b,&c);
    a++, b++;
    val[a] ^= c;
    val[b] ^= c;
  }
  for (int i = 1 ; i <= n ; ++ i)
    ++ cnt[val[i]];
  ans = n;
  ans -= cnt[0];
  for (int i = 1 ; i <= 15 ; ++ i)
    ans -= cnt[i]/2, sta |= (cnt[i]&1) << i >> 1;
  for (int i = 0 ; i < TOT ; ++ i) {
    tmp = 0;
    for (int j = 1 ; j <= 15 ; ++ j)
      if ((i >> j-1)&1) tmp ^= j;
    res[i] = tmp;
  }
  for (int i = 1 ; i < TOT ; ++ i) {
    for (int j = i ; j ; j = (j-1) & i)
      if (!res[j]) dp[i] = max(dp[i],dp[i^j] + 1);
  }
  ans -= dp[sta];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n,k;cin>>n>>k;
  string s;cin>>s;
  int one=0,two=0;
  rep(i,n+1){
    if(i==0){
      if(s[0]=='L')one++;
    }
    else if(i==n){
      if(s[n-1]=='R')one++;
    }
    else if(s[i-1]=='R' && s[i]=='L')two++;
  }
  while(k>0 && one+2*two>2){
    if(two>0)two--;
    else if(one>0)one--;
    k--;
  }
  if(k>0 && (one+2*two)<=2)one=1,two=0;
  cout<<n-(one+2*two)<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
// flow from KACTL
typedef long long LL;
struct Flow{
	int n;
	vector<vector<int> > graph; //list of id's
	vector<int> st, en, back; //back = back edge id
	vector<LL> f, c;
	vector<int> par;
	Flow(int n): n(n), graph(n), par(n){}
	void add_edge(int u, int v, int cap){
		int id1 = st.size();
		int id2 = id1 + 1;
		st.push_back(u); st.push_back(v);
		en.push_back(v); en.push_back(u);
		back.push_back(id2); back.push_back(id1);
		f.push_back(0); f.push_back(0);
		c.push_back(cap); c.push_back(0);
		graph[u].push_back(id1);
		graph[v].push_back(id2);
	}

	void add(int id1, int v){
		f[id1] += v;
		c[id1] -= v;
		f[back[id1]] -= v;
		c[back[id1]] += v;
	}

	LL maxflow(int s, int t){
		LL ans = 0;
		vector<int> bfs;
		if(s == t) return ans;
		while(1){
			for(int i = 0; i < n; i++) par[i] = -1;
			bfs.clear();
			bfs.push_back(s); par[s] = -2;
			int cur = 0;
			while(cur < bfs.size()){
				int u = bfs[cur]; cur++;
				for(int i = 0; i < graph[u].size(); i++){
					int id = graph[u][i];
					if(c[id] == 0) continue;
					if(par[en[id]] != -1) continue;
					par[en[id]] = id;
					bfs.push_back(en[id]);
				}
			}
			if(par[t] == -1) break;
			LL send = 4e18;
			int curv = t;
			while(par[curv] != -2){
				send = min(send, c[par[curv]]);
				curv = st[par[curv]];
			}
			curv = t;
			while(par[curv] != -2){
				add(par[curv], send);
				curv = st[par[curv]];
			}
			ans += send;
		}
		return ans;
	}
};
int main(){
	int n;
	cin >> n;
	int z[n];
	map<int,int> f;
	for(int i = 0; i < n; i++){
		cin >> z[i];
		f[z[i]]++;
		f[z[i]+1]++;
	}
	vector<int> r;
	vector<int> odd, even;
	for(map<int,int>::iterator it = f.begin(); it != f.end(); it++){
		if(it->second == 1){
			r.push_back(it->first);
			if(it->first % 2){
				odd.push_back(it->first);
			} else {
				even.push_back(it->first);
			}
		}
	}
	Flow s(300);
	for(int i = 0; i < 100; i++){
		s.add_edge(200,i,1);
		s.add_edge(i+100,201,1);
	}
	for(int i = 0; i < odd.size(); i++){
		for(int j = 0; j < even.size(); j++){
			int a = odd[i];
			int b = even[j];
			//cout << a << " " << b << endl;
			int p = abs(a-b);
			int ok = 1;
			if(p <= 1) ok = 0;
			for(int c = 2; c*c <= p; c++){
				if(p % c == 0){
					ok = 0;
					break;
				}
			}
			if(ok){
				s.add_edge(i,j+100,1);
			}
		}
	}
	int flow = (int)s.maxflow(200,201);
	int o1 = (int)odd.size() - flow;
	int e1 = (int)even.size() - flow;
	int ans = flow;
	ans += (o1/2)*2;
	ans += (e1/2)*2;
	o1 %= 2;
	e1 %= 2;
	if(o1 >= 1){
		ans += 3;
	}
	cout << ans << endl;
}



Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n, d;
string s[15];
map<char, llint> mp, mp2;
vector<llint> dvec;
vector<P> vec, vec2;
bool cant[15];
llint pop[1<<10];

void dfs(llint pos, llint sum, llint mask)
{
	if(pos == 5){
		vec.push_back(P(mask, sum));
		return;
	}
	for(int i = 0; i < 10; i++){
		if(mask & (1<<i)) continue;
		if(pos == 0 && cant[i]) continue;
		dfs(pos+1, sum+dvec[i]*pos, mask|(1<<i));
	}
}
void dfs2(llint pos, llint sum, llint mask)
{
	if(pos == 10){
		vec2.push_back(P(mask, sum));
		return;
	}
	for(int i = 0; i < 10; i++){
		if(mask & (1<<i)) continue;
		dfs2(pos+1, sum+dvec[i]*pos, mask|(1<<i));
	}
}

int main(void)
{
	for(int i = 1; i < (1<<10); i++) pop[i] = pop[i&(i-1)]+1;
	
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i = 1; i <= n; i++) cin >> s[i];
		
		mp.clear(), mp2.clear();
		for(int i = 1; i <= n; i++){
			if(s[i].size() >= 2) mp2[s[i][0]] = 1;
			reverse(s[i].begin(), s[i].end());
			llint mul = 1;
			for(int j = 0; j < s[i].size(); j++){
				mp2[s[i][j]];
				if(i < n) mp[s[i][j]] += mul;
				else mp[s[i][j]] -= mul;
				mul *= 10;
			}
		}
		
		dvec.clear();
		d = mp.size();
		for(auto it = mp.begin(); it != mp.end(); it++) dvec.push_back(it->second);
		while(dvec.size() < 10) dvec.push_back(0);
		
		
		llint id = 0;
		for(int i = 0; i < 10; i++) cant[i] = false;
		for(auto it = mp2.begin(); it != mp2.end(); it++) cant[id++] = it->second;
		
		vec.clear(), vec2.clear();
		dfs(0, 0, 0);
		dfs2(5, 0, 0);
		
		sort(vec.begin(), vec.end());
		sort(vec2.begin(), vec2.end());
		
		llint ans = 0, D = 1 << 10;
		for(int i = 0; i < vec.size(); i++){
			P p = P(D-1-vec[i].first, -vec[i].second);
			ans += upper_bound(vec2.begin(), vec2.end(), p) - lower_bound(vec2.begin(), vec2.end(), p);
		}
		for(int i = 1; i <= 10-d; i++) ans /= i;
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4028
#include <iostream>
using namespace std;
int main() {
  int i, j, H, W;
  while(cin >> H >> W) {
	if (H == 0 && W == 0) { break; }
	for (i = 0; i < H; i++) {
	  cout << "#";
	  for(j = 0; j < W - 2; j++) {
		if(i == 0 || i == H - 1) { cout << "#"; }
		else { cout << "."; }
	  }
	  cout << "#" << endl;
	}
	cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef pair<ll,P> T;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,K;
int A[100100];
int B[100100];
const int MAX = 30;
ll sum(int k){
	ll s = 0ll;
	for(int i=0;i<N;i++){
		if((k|A[i])==k)s+=B[i];
	}
	return s;
}
int main(){
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++){
		scanf("%d %d",&A[i],&B[i]);
	}
	ll ans = sum(K);
	for(int i=0;i<MAX;i++){
		int k = K;
		if((k>>i)&1){
			k>>=i;
			k^=1;
			k<<=i;
			k^=((1<<i)-1);
			ans = max(ans,sum(k));
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  
  int ans = 0;
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        if(500*i + 100*j + 50*k == X){
          ans++;
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int W, H, N;
    std::cin >> W >> H >> N;
    std::vector<int> p(N);
    for (int i = 0; i < N; i++) {
        std::cin >> p[i];
    }
    
    int ux = 0, uy = 0, ud = 0;
    int rx = 0, ry = 1, rd = 0;


    constexpr int dx[] = {+1, +0, -1, +0};
    constexpr int dy[] = {+0, +1, +0, -1};
    
    int adj_count = 0;
    for (int i = 0; i < N; i++) {
        if (p[i] == 0) {
            ux += dx[ud];
            uy += dy[ud];
            if ((ud == 0 && ux == W - 1) ||
                (ud == 1 && uy == H - 1)) {
                ud++;
            } 
        } else {
            rx += dx[rd];
            ry += dy[rd];
            if ((rd == 0 && rx == W - 2) ||
                (rd == 1 && ry == H - 2)) {
                rd++;
            }
        }
        for (int j = 0; j < 4; j++) {
            int nx = ux + dx[j];
            int ny = uy + dy[j];
            if (nx == rx && ny == ry) {
                adj_count++;
                break;
            }
        }
    }
    
    std::cout << adj_count << std::endl;
    
    return 0;
}

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

int main() {
  unsigned long a, b, r, i, j;
  cin >> a >> b;
  if (a < b) swap(a, b);
  while (a%b != 0) {
    r = a%b; a = b; b = r;
  }
  int ans = 1, lim = sqrt(b);
  for (i = 2; i <= lim; i++) {
    if (b%i == 0) {
      ans++; while (b%i == 0) b /= i;
    }
  }
  if (b > lim) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections
n = int(input())
*a, = map(int, input().split())

cc = collections.Counter(a)
cc = dict(sorted(cc.items(), key=lambda x: x[1], reverse=True))

ans = 0
for k, v in cc.items():
    t = cc[k]
    if k+1 in cc:
        t += cc[k+1]
    if k-1 in cc:
        t += cc[k-1]

    ans = max(ans, t)

print(ans)


Measured memory_bytes: 21088
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int H,W,A[102][102]={0},M[102][102]={0};
bool vi[102][102]={0};
void solve(int r,int c){
	M[r][c]=1000000;
	if(A[r][c]){
		M[r][c]=min(M[r][c-1],M[r-1][c]);
	}else{
		if(!A[r-1][c]){
			M[r][c]=min(M[r-1][c],M[r][c]);
		}else{
			M[r][c]=min(M[r-1][c]+1,M[r][c]);
		}
		if(!A[r][c-1]){
			M[r][c]=min(M[r][c-1],M[r][c]);
		}else{
			M[r][c]=min(M[r][c-1]+1,M[r][c]);
		}
	}
	if(r==1&&c==1)M[r][c]=!A[r][c];
	vi[r][c]=true;
	//if(r+1<=H)solve(r+1,c);
	//if(c+1<=W)solve(r,c+1);
}
int main(){
	char s;
	cin>>H>>W;
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++){
		cin>>s;
		if(s=='#')A[i][j]=0;
		else A[i][j]=1;
	}
	for(int i=0;i<=H+1;i++){
		A[i][0]=true;
		A[i][W+1]=true;
		vi[i][0]=true;
		vi[i][W+1]=true;
		M[i][0]=1000000;
		M[i][W+1]=1000000;
	}
	for(int i=0;i<=W+1;i++){
		A[0][i]=true;
		A[H+1][i]=true;
		vi[0][i]=true;
		vi[H+1][i]=true;
		M[0][i]=1000000;
		M[H+1][i]=1000000;
	}
	solve(1,1);
	
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			solve(i,j);
		}
	}
	cout<<M[H][W];
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

  int a,b ;
  cin >> a >> b ; 
  string s ;
  cin >> s ;
  bool ans = 1 ;

  for(int i=0;i<(a+b+1);++i)
  {
    if(i==a){
        if(s[i]!='-'){
            ans = false ;
            break ;
        }
    }else{
     if(s[i]=='-'){
        ans = false ;
        break ;
    }
  }
  }
  if(ans)
   printf("%s\n","Yes") ;
  else
   printf("%s\n","No") ;
  
 return 0 ;
}  


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

int main() {
  int n,l,sum = 0,min = 100000;
  cin >> n >> l;
  for(int i = 1;i <= n;i++){
    sum += l+i-1;
    if(abs(l+i-1) < abs(min)) min = l+i-1;
  }
  cout << sum-min << endl;
}


Measured memory_bytes: 256
k = 0
s = ''

def format_input(filename = None):
	global k
	global s
	if filename == None:
		k = int(input())
		s = str(input())

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		k = rng(1, 10**2)
		s = ''.join(choices('abcdefghijklmnopqrstuvwxyz', k = rng(1, 10**2)))
		print(k)
		print(s)

def get_answer():
	answer = ''

	if len(s) > k:
		answer = s[:k] + '...'
	else:
		answer = s

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


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

int main() {
    string s;
    cin >> s;
    int len = (int)s.size();

    string other_x;
    for (int i = 0; i < len; i++) {
        if (s.at(i) != 'x') other_x += s.at(i);
    }

    string r_other_x = other_x;
    reverse(r_other_x.begin(), r_other_x.end());

    if (other_x != r_other_x) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> cnt_x(other_x.size() + 1);
    int si = 0;
    int cnt = 0;
    int x_index = 0;
    while (si < len) {
        if (s.at(si) != 'x') {
            cnt_x.at(x_index) = cnt;
            cnt = 0;
            x_index++;
        }
        else cnt++;

        si++;
    }
    if (cnt > 0) cnt_x.at(x_index) = cnt;
    
    int ans = 0;
    int l = (int)cnt_x.size();
    for (int i = 0; i < l / 2; i++) {
        if (cnt_x.at(i) != cnt_x.at(l - i - 1)) ans += abs(cnt_x.at(i) - cnt_x.at(l - i - 1));
    }
    cout << ans << endl;
}   

Measured memory_bytes: 1024
import           Control.Monad

inputN :: IO Int
inputN = readLn

inputDs :: Int -> IO [(Int, Int)]
inputDs n = do
  ns <- replicateM n (map read . words <$> getLine)
  return . map (\[x, y] -> (x, y)) $ ns

check :: [(Int, Int)] -> Bool
check x = func x 0
  where
    func :: [(Int, Int)] -> Int -> Bool
    func [] c = if c >= 3 then True else False
    func (n:ns) c = case fst n == snd n of
      True  -> if c == 2 then True else func ns (c+1)
      False -> func ns 0

main :: IO ()
main = do
  n <- inputN
  ns <- inputDs n
  putStrLn . (\x -> if x then "Yes" else "No") . check $ ns
  return ()


Measured memory_bytes: 4568
#include <bits/stdc++.h>
typedef long long i64;
const int N = 1e5+5, P = 998244353;
int n, c[8]; i64 ans; char s[N*3];
void upd(int &x, int &y) { if(x) --x, ++y; }
int main()
{
    scanf("%d%s", &n, s+1), ans = 1;
    for(int i = 1; i <= 3*n; ++i)
    {
        int w = s[i] == 'R'?1:s[i] == 'G'?2:4; 
        if(c[7^w]) ans = ans*c[7^w]%P, --c[7^w];
        else if(w == 1&&c[2]+c[4]) ans = ans*(c[2]+c[4])%P, upd(c[2], c[3]), upd(c[4], c[5]);
        else if(w == 2&&c[1]+c[4]) ans = ans*(c[1]+c[4])%P, upd(c[1], c[3]), upd(c[4], c[6]);
        else if(w == 4&&c[1]+c[2]) ans = ans*(c[1]+c[2])%P, upd(c[1], c[5]), upd(c[2], c[6]);
        else ++c[w];
    }
    for(int i = 1; i <= n; ++i) ans = ans*i%P;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const int M  = 20;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

int main()
{
    fast
    ll n,l;
    cin>>n>>l;
    
    ll sum1=0;
    forn(i,1,n+1)
    {
        sum1+=(l+i-1);
    }
    
    ll mini=inf;
    ll ans;
    forn(i,1,n+1)
    {
       if(abs(sum1-(sum1-(l+i-1)))<mini)
       {
          mini=abs(sum1-(sum1-(l+i-1)));
          ans=(sum1-(l+i-1));
       }
    }

    cout<<ans;

    return 0;
}

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

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

int main() {
    int H, i, A[MAX+1]; // 1-オリジンのため +1 する

    cin >> H;
    for (i = 1; i <= H; i++) cin >> A[i];

    for (i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	#ifdef FUN
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#else
		#define endl "\n"
	#endif

	int n, m; cin >> n >> m;
	vector<int> cnt(n+1, 1 ), possible(n+1, 0);
	possible[1] = true;
	for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        if(cnt[a] == 0) continue;
        cnt[a]--;
        cnt[b]++;
        if(possible[a]) {
            if(cnt[a] == 0) possible[a] = false;
            possible[b] = true;
//            cout << b << " es posible" << endl;
        } else {

        }
	}

	int ans = 0;
	for(int i = 1; i <= n; i++)
        ans += possible[i];

    cout << ans << endl;
}


Measured memory_bytes: 1024
#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()

const int INF = 1e9;

vector<int> match = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A;
vector<int> memo;

int dp(int N) {
  if(N < 0) return -INF;
  if(memo[N] >= 0) return memo[N];
  if(N == 0) return memo[0] = 0;

  int tmp = -INF;
  for(int a: A) {
    if(dp(N - match[a - 1]) < 0) continue;
    tmp = max(tmp, dp(N - match[a - 1]) + 1);
  }
  return memo[N] = tmp;
}

int main(){
  int N, M;
  cin >> N >> M;
  A.resize(M);
  REP(i, M) cin >> A[i];
  sort(A.rbegin(), A.rend());
  memo.resize(N + 1, -INF);

  string ret = "";
  int tmp = N;
  REP(i, dp(N)){
    for(int a: A) {
      if(dp(tmp - match[a - 1]) == dp(tmp) - 1) {
        ret += to_string(a);
        tmp -= match[a - 1];
        break;
      }
    }
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BShiftOnly solver = new BShiftOnly();
        solver.solve(1, in, out);
        out.close();
    }

    static class BShiftOnly {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = Integer.parseInt(in.next());
            int bit = 0;
            for (int i = 0; i < n; i++) {
                bit = bit | in.nextInt();
            }
            out.println(Integer.numberOfTrailingZeros(bit));
        }

    }
}



Measured memory_bytes: 22996
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    long n=3,x_max =7;
    cin >> n >> x_max;
    vector<long> A;
    for (long i=0;i<n;i++){
        long tmp;
        scanf("%ld",&tmp);
        A.push_back(tmp);
    }

    if(x_max == 0){
        long long sum=0;
        for(int i=0;i<n;i++){
            sum += A.at(i);
        }
        printf("%lld\n",sum);
        return 0;
    }

    int C[40]={};
    for(int l=0;l<40;l++){
        for(long i=0;i<n;i++){
            if(A.at(i) & (long)pow(2,l)){
                C[l]++;
            }
        }
    }

    long sum[40] ={};

    for(long i=0;i<40;i++){
        if(!(x_max+1 & ((long)1<<i))){
            continue;
        }else{
            sum[i] += ((long)1<<i) * C[i];
        }

        for(long j=0;j<i;j++){
            if(C[j] > n - C[j]){
                sum[i] += ((long)1<<j) * C[j];
            }else{
                sum[i] += ((long)1<<j) * (n-C[j]);
            }
        }

        for(long long j=i+1;j<40;j++){
            if((x_max+1 & ((long)1<<j))){
                sum[i] += ((long)1<<j) * (n-C[j]);
            }else{
                sum[i] += ((long)1<<j) * C[j];
            }
        }
    }
    printf("%ld\n",*max_element(sum,sum+40));
}


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

int main(){
	double h;
	double k=1,s=0;
	int n;
	std::cin>>n;

	std::vector<double> v(n);
	for (double& x : v) {
		std::cin >> x;
	}

	for (int i = 0; i < n; i++) {
		s = s + 1 / v[i];
	}

	

	/*
	for (int i = 0; i < n; i++) {
		k = k * v[i];
		s = s + v[i];
	}

	h = k / s;
	*/

	//std::cout << s << std::endl;
	std::cout << 1 / s << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, res;
  rd(A);
  rd(B);
  res =max_L(max_L(A+B, A-B), A*B);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190810-2

// --- original code ---
// {
//   int A, B, res;
//   rd(A,B);
//   res = max(A+B, A-B, A*B);
//   wt(res);
// }


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

ll N,A,B;

int main(){
    cin >> N >> A >> B;
    if((N == 1 && A != B) || A > B){
        cout << 0 << endl;
        return 0;
    }
    ll ans = ((N-1) * B + A) - ((N-1) * A + B) + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256