akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
    using System.Collections;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System;

    namespace cysharp_test
    {
        class Program
        {
            static void Main (string[] args)
            {
                new Program ().solve ();
            }

            void solve ()
            {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            for (int i = 0; i < S.Length;i++){
                if (S[i] == T[i]) { continue; }
                else {
                    Console.WriteLine("No");
                    return;
                }
            }
             Console.WriteLine("Yes");
                Console.ReadKey();
        }

        }
        struct Vector2
        {
            public Vector2 (long x, long y)
            {
                this.x = x;
                this.y = y;
            }

            public long x, y;

            public static Vector2 operator + (Vector2 a, Vector2 b)
            {
                return new Vector2 (a.x + b.x, a.y + b.y);
            }

            public static Vector2 operator - (Vector2 a, Vector2 b)
            {
                return new Vector2 (a.x - b.x, a.y - b.y);
            }

            public static Vector2 operator * (Vector2 a, long scala)
            {
                return new Vector2 (a.x * scala, a.y + scala);
            }

            public static bool operator == (Vector2 a, Vector2 b)
            {
                return (a.x == b.x) && (a.y == b.y);
            }

            public static bool operator != (Vector2 a, Vector2 b)
            {
                return !(a.x == b.x) && (a.y == b.y);
            }

            public override int GetHashCode ()
            {
                return (int) (x + y);
            }

            public override bool Equals (object obj)
            {
                if (!(obj == null) && obj is Vector2)
                {
                    return (this == (Vector2) obj);
                }
                else return false;
            }

            public override string ToString ()
            {
                return ("(" + x + "," + y + ")");
            }
        }
    }

Measured memory_bytes: 17336
N = int(input())
S1 = list(input())
S2 = list(input())

mod = int(1E9+7)

if S1[0] == S2[0]:
    ans = 3
else:
    ans = 6
for i in range(N-1):
    if S1[i] != S1[i+1] and S1[i] == S2[i]:
        ans *= 2
    elif S1[i] == S2[i] and S1[i+1] == S2[i+1]:
        ans *= 3
    elif S1[i] != S2[i] and S1[i] != S1[i+1] and S2[i] != S2[i+1] and S1[i+1] != S2[i+1]:
        ans *= 3
    ans = ans % mod

print(ans)

Measured memory_bytes: 3064
N = gets.to_i

ar = N.times.map{[]}

abc = (N-1).times.map{gets.split.map(&:to_i).map{|t|t-1}}

abc.each{|t|
  ar[t[0]] << [t[1],t[2]+1]
  ar[t[1]] << [t[0],t[2]+1]
}

Q,K = gets.split.map(&:to_i)
xy = Q.times.map{gets.split.map(&:to_i).map{|t|t-1}}

d = Array.new(N, 611686018427387903)
inQ = Array.new(N, false)

d[K-1] = 0
inQ[K-1] = true

q = [K-1]


while q.size>0 do
  now = q.shift
  inQ[now] = false
  ar[now].size.times{|i|
    nexti = ar[now][i][0]
    nextd = d[now] + ar[now][i][1]
    if nextd < d[nexti] then
      d[nexti] = nextd;
      if !inQ[nexti] then
        inQ[nexti] = true
        q << nexti
      end
    end
  }
end

xy.each{|x,y|
  puts d[x] + d[y]
}
  
  

Measured memory_bytes: 49148
#include "bits/stdc++.h"
 
using namespace std;
 
using ll = long long;
 
int main() {
  int n;
  cin >> n;
  vector<int> v(2 * n);
  for (auto &&x : v) {
    cin >> x;
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2) {
    ans += v[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL a;
    LL b;
    LL ab;
    cin >> a >> b;
    ab=a*b;
    if(ab%2==0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }

    return 0;
}


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

int main(){
    int n,i;
    string S,T;
    cin >> S >> T;
    n = S.size();
    for(i=0;i<n;i++){
        if(S[i]!=T[i]){
            cout << "No" << endl;
            break;
        }
    }
    if(i==n) cout << "Yes" << endl;

}


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

using namespace std;

#define ll long long

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	ll times=1;
	// cin>>times;
	while(times--)
	{
		int x;
		cin>>x;
		cout<<1-x;
	}
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int d, t, s;
    cin >> d >> t >> s;

    double p =(double) d / (double)t;
    if (s >= p)cout << "Yes";
    else cout << "No";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


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

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

    int N, K; cin>>N>>K;
    vector<int> A(N); for (auto& a : A) cin>>a;

    sort(A.begin(), A.end());

    int sum = 0;
    for (auto a : A) sum += a;
    auto check = [&](int x) -> bool {
        vector<int> M(N);
        for (int i = 0; i < N; i++)
            M[i] = A[i]%x;
        sort(M.begin(), M.end());
        vector<int> rcum(N);
        rcum.back() = (x-M.back())%x;
        for (int i = N-2; i >= 0; i--)
            rcum[i] = rcum[i+1]+(x-M[i])%x;
        int cum = 0;
        for (int i = 0; i < N-1; i++) {
            cum += M[i];
            if (cum > K)
                return false;
            if (cum == rcum[i+1])
                return true;
        }
        return false;
    };
    
    int ans = 0;
    for (int n = 1; n < sqrt(sum)+1; n++) {
        if (sum % n)
            continue;
        if (check(sum/n)) {
            ans = sum/n;
            break;
        } else if (check(n)) {
            ans = n;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N, K;
    cin >> N >> K;
    long double N_1 = 1.0/N;
    long double log2K = log2(K);
    long double sum = 0.0;
    FOR(i, N+1, 1){
        ll t = ceil(log2K - log2(i));
        //cout << t << el;
        sum += pow(0.5, max(t, 0ll))*N_1;
    }
    cout << sum << el;
}



Measured memory_bytes: 4192
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




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

    cout << (N+2*D)/(2*D+1) << endl;


}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(){
    int i,j,k;
    string in;

    while(cin >> in){
        string res;

        i = 0;
        while(i < in.size()){
            if(in[i] == '@'){
                int loop = in[i+1] - '0';
                rep(j,loop) res += in[i+2];
                i += 2;
            } else {
                res += in[i];
            }
            i++;
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

const int MAX = 100010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n), w(n);
  rep(i, n) cin >> v[i] >> w[i];
  int sz = (int)sqrt(n);
  vector<vector<int>> dp(sz+1, vector<int>(MAX));
  for (int i = 1; i <= sz; i++) {
    rep(j, MAX) {
      chmax(dp[i][j], dp[i/2][j]);
      if (j-w[i-1] >= 0)
        chmax(dp[i][j], dp[i/2][j-w[i-1]]+v[i-1]);
    }
  }
  int q;
  cin >> q;
  rep(_, q) {
    int x, l;
    cin >> x >> l;
    if (x <= sz) {
      cout << dp[x][l] << '\n';
      continue;
    }
    vector<int> v2, w2;
    while (x > sz) {
      v2.push_back(v[x-1]);
      w2.push_back(w[x-1]);
      x /= 2;
    }
    int ans = 0, sz2 = v2.size();
    rep(i, 1<<sz2) {
      int weight = 0, value = 0;
      rep(j, sz2) {
        if (i>>j & 1) {
          weight += w2[j];
          value += v2[j];
        }
      }
      if (l-weight >= 0)
        chmax(ans, value+dp[x][l-weight]);
    }
    cout << ans << '\n';
  }
  return 0;
}

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

int main() {
    int H, W, K; cin >> H >> W >> K;
    vector<string> grid(H);
    for (int i = 0; i < H; ++i) cin >> grid[i];
    int ans = 0;
    for (int k = 0; k < 1<<(H + W); ++k) {
        int cnt = 0;
        for (int i = 0; i < H; ++i) {
            if ((1<<i)&k) continue;
            for (int j = 0; j < W; ++j) {
                if (1<<(H+j)&k) continue;
                if (grid[i][j] == '#') ++cnt;
            }
        }
        if (cnt == K) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  int n;
  cin>>n;
  getline(cin,s);
  while(n--){
    getline(cin,s);
    r(i,26)r(j,26){
      string t=s;
      r(k,t.size())
        if(t[k]!=' ')t[k]=((t[k]-'a')*i+j)%26+'a';
      if(t.find("that")!=string::npos||t.find("this")!=string::npos){
        cout<<t<<endl;
        goto L;
      }
    }L:;
  }
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	string S;
	cin >> S;
	int L[3000], R[3000];
	rep(i, M) cin >> L[i] >> R[i];

	ll mod = 1e9 + 7;
	ll dp[3001][3001] = {};
	dp[0][0] = 1;
	//jが使ったゼロね
	int k = 0;
	int mae = 0;
	int zero = 0;
	rep(i, N) {
		int k2 = max(mae, i + 1);
		while (k < N && i >= L[k] - 1) {
			k2 = max(k2, R[k]);
			k++;
		}
		for (int x = mae; x < k2; x++) {
			if (S[x] == '0') zero++;
		}
		mae = k2;

		ce(i);
		cesp(mae);
		ce(zero);

		rep(j, N) {
			if (j + 1 <= zero) dp[i + 1][j + 1] += dp[i][j];
			if (i - j + 1 <= mae - zero) dp[i + 1][j] += dp[i][j];
		}
		rep(j, N + 1) dp[i + 1][j] %= mod;
	}

	ll kotae = 0;
	rep(j, N + 1) kotae += dp[N][j];
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 70656
arr=[]
gets.chomp.each_char{|c| arr<<c.to_i}
a,b,c,d=arr

ops_set = [
  ['+','+','+'],
  ['+','+','-'],
  ['+','-','+'],
  ['+','-','-'],
  ['-','+','+'],
  ['-','+','-'],
  ['-','-','+'],
  ['-','-','-']
          ]

ops_set.each do |ops|
  str="#{a}#{ops[0]}#{b}#{ops[1]}#{c}#{ops[2]}#{d}"
  if eval(str)==7
    puts "#{str}=7"
    exit
  end
end


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

int main()
{
  	int a,b,d,r;
	double f;
  
 	cin >> a >> b;
  
    d = a / b;
  	r = a % b;
  	f = (double)a / b;
  
 	cout << d << " " << r << " " << fixed << setprecision(15) << f << endl;
}


Measured memory_bytes: 3244
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            // writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n = sc.read();
        let mut a: Vec<u32> = sc.vec(n);
        a.sort();
        a.dedup();
        let m = sc.read();
        let mut b: Vec<u32> = sc.vec(m);
        b.sort();

        let mut cnt = 0;
        let mut it = a.iter().peekable();
        for &x in b.iter() {
            // println!("{:?}", it);
            while let Some(&y) = it.peek() {
                if y < &x {
                    it.next();
                } else {
                    break;
                }
            }
            while let Some(&y) = it.peek() {
                if y == &x {
                    cnt += 1;
                    it.next();
                } else {
                    break;
                }
            }
        }
        println!("{}", cnt);
    }
}



Measured memory_bytes: 9168
#include <stdio.h>

int main(void)
{
    int n;
    int x;
    int cnt;

    while ( 1 ) {
        scanf("%d %d", &n, &x);
        if ( (n == 0) && (x == 0)) {
            break;
        }
        cnt = 0;
        for ( int i = 1; i <= n; i++ ) {
            for ( int j = i + 1; j <= n; j++ ) {
                for ( int k = j + 1; k <= n; k++ ) {
                    if ( i + j + k == x ) {
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n", cnt);
    }

    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,k,p[5005],c[5005],ans=-1e18;
    bool used[5005]={0};
    cin >> n >> k;
    rep(i,0,n-1){
    	cin >> p[i];
    	p[i]--;
    }
    rep(i,0,n-1){
    	cin >> c[i];
    }
    rep(i,0,n-1){
    	if(!used[i]){
    		ll pv=i,np,cyc,mx=-1e18;
    		vcl gm;
    		while(!used[pv]){
    			//cout << pv << endl;
    			used[pv]=true;
    			gm.pb(pv);
    			pv=p[pv];
    		}
    		np=gm.size();
    		ll dp[np+5][np+5]={0};
    		//cout << np << endl;
    		rep(x,0,np-1){
    			rep(y,1,np){
    				dp[x][y]=dp[x][y-1]+c[gm[(x+y)%np]];
    			}
    		}
    		cyc=dp[0][np];
    		//cout << cyc << endl;
    		if(cyc<0){
    			rep(x,0,np-1){
    				rep(y,1,min(np,k)){
    					chmax(mx,dp[x][y]);
    				}
    			}
    			chmax(ans,mx);
    		} else {
    			rep(y,1,min(k,np)){
    				ll km=k;
    				mx=-1e18;
    				rep(x,0,np-1){
    					chmax(mx,dp[x][y]);
    				}
    				km-=y;
    				chmax(ans,mx+(km/np)*cyc);
    			}
    		}
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 199516
#include<iostream>
#include<algorithm>
#include<string>
#define For(i,A,B) for(i=(A);i<=(B);++i)
using namespace std;
const int P=998244353;
const int bs=29;
const int P2=1000000007;
const int hash_p=1000117;
int p[200050],g[1000050];
char s[1000050];
string st[200050];
inline bool cmp(int x,int y){return st[x].size()>st[y].size();}
struct Hash{
	int hd[hash_p],len[1000050],val[1000050],val2[1000050],nxt[1000050],sz;
	inline void ins(int l,int x,int x2){
		int ps=((1ll*l*P+x)%hash_p*P2+x2)%hash_p;
		len[++sz]=l;val[sz]=x;val2[sz]=x2;nxt[sz]=hd[ps];hd[ps]=sz;
	}
	inline int ask(int l,int x,int x2){
		int i,s=0;
		for(i=hd[((1ll*l*P+x)%hash_p*P2+x2)%hash_p];i;i=nxt[i])if(len[i]==l&&val[i]==x&&val2[i]==x2)++s;
		return s;
	}
}f[26];
int main(){
	ios::sync_with_stdio(0);
	int n,l,i,k,x,x2;
	short j;
	long long ans=0ll;
	cin>>n;
	For(k,1,n){
		cin>>st[k];
		p[k]=k;
	}
	sort(p+1,p+n+1,cmp);
	For(k,1,n){
		fill(g+1,g+(l=st[p[k]].size())+1,0);
		For(i,1,l)s[i]=st[p[k]][i-1];
		For(i,1,l)g[i]=g[i-1]|(1<<s[i]-'a');
		for(i=l,x=x2=0;i>1;--i){x=(1ll*x*bs+s[i]-'a')%P;x2=(1ll*x2*bs+s[i]-'a')%P2;}
		ans+=f[s[1]-'a'].ask(l-1,x,x2);
		for(i=l,x=x2=0;i;--i){
			For(j,0,25)if((g[i]>>j)&1)f[j].ins(l-i,x,x2);
			x=(1ll*x*bs+s[i]-'a')%P;x2=(1ll*x2*bs+s[i]-'a')%P2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512024
from sys import stdin

n = int(stdin.readline().rstrip())

mi = 10**6
li = list(map(int,stdin.readline().rstrip().split()))
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in li:
    lin = prime_factorize(i)
    mi = min(mi,lin.count(2))

print(mi)

Measured memory_bytes: 3064
N , M = [int(i) for i in input().split()]
s  = [[int(j) for j in input().split()] for i in range(M)]
#print(s)
#print(c)
x = 0
#for i in range(N):
s = list(map(list, set(map(tuple, s))))
f = [0] * N

#print(f)
for ss in s:
    if f[ss[0]-1] == 1:
        f = [1] * N
        x = -1
        break
    if ss[0] == 1 and ss[1]==0:
        f[0]=1
        if N == 1:
            x = 0
            break
        else:
            f = [1] * N
            x = -1
            break
        
    f[ss[0]-1] = 1
    x += ss[1] * 10 ** (N-ss[0])
    #for cc in c:


if N == 1 and M == 0:
    print(0)
else:
    if f[0]==0:
        x += 10 ** (N-1)
        print(x)
    else:
        print(x)




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

const int MAX_N = 1e5 + 1;

int A[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    A[0] = -1;
    for (int i = 1; i <= N; i++) cin >> A[i];
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (A[A[i]] == i) {
            ans++;
            A[A[i]] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked

int inp() {
	int x = 0, f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

ll inp_ll() {
	ll x = 0; int f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

template<class T>
bool read(T &x)
{
	x = 0;
	char ch = getchar();
	if (ch == EOF) return 0;
	for(; !isdigit(ch); )
	{
		ch = getchar();
		if (ch == EOF) return 0;
	}
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return 1;
}

template<class T>
void write(T x)
{
	static char s[22];
	static char *it = s+20;
	static char *end = s+20;
	if (!x)
		*-- it = '0';
	while (x)
	{
		*-- it = x%10+'0';
		x /= 10;
	}
	for (; it < end; ++ it)
		putchar(*it);
}

template<class T>
void writeln(T x)
{
	write(x);
	putchar('\n');
}

const int MOD = 1000000007;
const int INF = 100000000;
const int MAXN = 110;
const int MAXV = 500510;
const int K = 3;
const f80 eps = 1e-10;
const f64 alpha = 0.75;

int main()
{
	
	int L, R;
	cin >> L >> R;
	int p = 2019;
	ll ret = 2019;
	for (int a = L; a <= p+L; ++ a)
		for (int b = R-p; b <= R; ++ b)
		{
			if (L <= a && a < b && b <= R)
			{
				freshmin(ret, (ll)a*b%p);
			}
		}
	cout << ret << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

const int cap = 302;
int N, a, tot;
int cnt[4];
double n;
double dp[cap][cap][cap];
double P[cap][cap][cap];

double dfs(int i, int j, int k) {
    if (dp[i][j][k] != -1)
        return dp[i][j][k];
    if (i + j + k > N || j + k > cnt[2] + cnt[3] || k > cnt[3]) {
        dp[i][j][k] = -2;
    }
    else {
        double p1 = 1 / (1 - (n - i - 1 - j - k) / n);
        double p23 = 1 / (1 - (n - i - j - k) / n);
        dp[i][j][k] = 0;
        if (dfs(i + 1, j, k) != -2) {
            // if (i == 1 && !j && !k)
            //     cout << "\t" << i << " " << j << " " << k << " " << n << " " << p1 << endl;
            double p = (i + 1) / n * p1 * P[i + 1][j][k];
            dp[i][j][k] += p1 * (p1 + dp[i + 1][j][k]) * (i + 1) / n * P[i + 1][j][k];
            P[i][j][k] += p;
        }
        if (i && dfs(i - 1, j + 1, k) != -2) {
            double p = (j + 1) / n * p23 * P[i - 1][j + 1][k];
            dp[i][j][k] += (p23 * (p23 + dp[i - 1][j + 1][k]) * (j + 1) / n) * P[i - 1][j + 1][k];
            P[i][j][k] += p;
        }
        if (j && dfs(i, j - 1, k + 1) != -2) {
            double p = (k + 1) / n * p23 * P[i][j - 1][k + 1];
            dp[i][j][k] += (p23 * (p23 + dp[i][j - 1][k + 1]) * (k + 1) / n) * P[i][j - 1][k+ 1];
            P[i][j][k] += p;
        }
    }
    // printf("%d %d %d %.10lf %.10lf\n", i, j, k, dp[i][j][k], P[i][j][k]);
    if (P[i][j][k])
        dp[i][j][k] /= P[i][j][k];
    return dp[i][j][k];
}

int main() {
    scanf("%d", &N);
    n = N;
    fill(cnt, cnt + 4, 0);
    for (int i = 1; i <= N; ++i) {
        scanf(" %d", &a);
        ++cnt[a];
    }

    fill(&dp[0][0][0], &dp[0][0][0] + cap * cap * cap, -1);
    fill(&P[0][0][0], &P[0][0][0] + cap * cap * cap, 0);
    dp[cnt[1]][cnt[2]][cnt[3]] = 0;
    P[cnt[1]][cnt[2]][cnt[3]] = 1;
    dfs(0, 0, 0);
    
    // for (int i = 0; i <= N; ++i)
    //     for (int j = 0; j <= N; ++j)
    //         for (int k = 0; k <= N; ++k)
    //             printf("%d %d %d %.10lf\n", i, j, k, dp[i][j][k]);

    printf("%.10lf\n", dp[0][0][0]);
}









Measured memory_bytes: 430720
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>void chmin(T &a,T b){a=min(a,b);}
using namespace std;

void solve(){
	string s;
	cin>>s;
	int cnt=0;
	stack<int>st;
	rep(i,s.size()){
		if(s[i]=='S')st.push(s[i]);//Sなら何も考えずにpush
		else {
			if(!st.empty()&&st.top()=='S'){
				st.pop();
				++cnt;
			}
			else {
				st.push(s[i]);
			}
		}
	}
	cout<<s.size()-2*cnt<<"\n";
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 1300
#include <cstdio>
using namespace std;
  
int a[4];
int c[8];
int k;
  
int calc(){
    int op = c[k++];
    int ret = 0;
    if(op >= 0){
        ret = op;
    }
    else if(op >= -3){
        int x = calc();
        int y = calc();
        if(op == -1){
            ret = x + y;
        }
        else if(op == -2){
            ret = x - y;
        }
        else{
            ret = x * y;
        }
    }
    else{
        throw 0;
    }
    return ret;
}
  
void print(){
    int op = c[k++];
    if(op >= 0){
        printf("%d", op);
    }
    else{
        char ch;
        if(op == -1){ ch = '+'; }
        else if(op == -2){ ch = '-'; }
        else{ ch = '*'; }
  
        putchar('(');
        print();
        printf(" %c ", ch);
        print();
        putchar(')');
    }
}

const int bnum = 10;
  
void solve(int i, int S, int oprem, int numrem){
    if(i == 6){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[6] = a[j];
            }
        }
        try{
            k = 0;
            if(calc() == 10 && k == 7){
                k = 0;
for(int j=0;j<bnum;++j)putchar('(');
                print();
for(int j=0;j<bnum;++j)putchar(')');
                puts("");
                throw "";
            }
        }catch(int){}
        return;
    }
  
    if(oprem > 0){
        for(int op = -1; op >= -3; --op){
            c[i] = op;
            solve(i + 1, S, oprem - 1, numrem + 1);
        }
    }
  
    if(numrem > 0){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[i] = a[j];
                solve(i + 1, S ^ 1 << j, oprem, numrem - 1);
            }
        }
    }
}
  
int main(){
    while(1){
        for(int i = 0; i < 8; ++i){
            c[i] = -9;
        }
        for(int i = 0; i < 4; ++i){
            scanf("%d", &a[i]);
        }
        if(a[0] == 0){ break; }
        try{
            solve(0, 15, 3, 0);
            puts("0");
        }catch(...){}
    }
}

Measured memory_bytes: 1128
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> r(n);
    int min = 1000000000;
    int prof = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> r[i];
        if (i == 1)
            prof = r[1] - r[0];
        else if (i > 1)
            prof = (r[i] - min) < prof ? prof : r[i] - min;
        min = min < r[i] ? min : r[i];
    }
    cout << prof << endl;
    return 0;
}



Measured memory_bytes: 3612
s = int(input())

mod = 10**9 + 7
dp = [0 for _ in range(s + 5)]
dp[0] = 1

for i in range(1, s + 1):
    for j in range(0, (i - 3) + 1):
        dp[i] += dp[j]
        dp[i] %= mod

# print(dp)
print(dp[s] % mod)


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

bool c[5000+2][5000+2];

bool t(int x,int y){
	if(x<0)return false;
	if(x>5000)return false;
	if(y<0)return false;
	if(y>5000)return false;
	return c[x][y];
}

int main(){
	while(1){
		int n,ans=0;
		pair<int,int> p[3002];
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<5002;i++)for(int j=0;j<5002;j++)c[i][j]=false;
		for(int i=0;i<n;i++){
			scanf("%d%d",&p[i].first,&p[i].second);
			c[p[i].first][p[i].second]=true;
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(t(p[i].first+p[i].second-p[j].second,p[i].second+p[j].first-p[i].first)&&t(p[j].first+p[i].second-p[j].second,p[j].second+p[j].first-p[i].first))ans=max(ans,(p[i].first-p[j].first)*(p[i].first-p[j].first)+(p[i].second-p[j].second)*(p[i].second-p[j].second));
				//if(t(p[i].first-p[i].second+p[j].second,p[i].second-p[j].first+p[i].first)&&t(p[j].first-p[i].second+p[j].second,p[j].second-p[j].first+p[i].first))ans=max(ans,(p[i].first-p[j].first)*(p[i].first-p[j].first)+(p[i].second-p[j].second)*(p[i].second-p[j].second));
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 25644
using System;

class program
{
    public static int Main()
    {
        var str = Console.ReadLine();
        var a = int.Parse(str.Split(' ')[0]);
        var b = int.Parse(str.Split(' ')[1]);
        var c = int.Parse(str.Split(' ')[2]);

        var num = 0;

        for (int i = a; i <= b; i++)
        {
            if (c % i == 0)
            {
                num++;
            }
        }

        Console.WriteLine(num);

        return 0;
    }
}

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

const int Nmax=200010;

int main() {
	int a,b;
	cin >> a >> b;
	int S[1200]={};
	int index[Nmax]={};
int o=0;
	for(int i=1;i <= 999;i++){
		S[i] = S[i-1] + i;
		if(b-a==i) o=S[i]-b;
	}
	
	cout << o << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#define MAX 25
#define NIL -1

using namespace std;

struct Node {
    int parent, left, right;
};
Node T[MAX];

void preParse(int u) {
    if(u == NIL) return;
    printf(" %d", u);
    preParse(T[u].left);
    preParse(T[u].right);
}

void inParse(int u) {
    if(u == NIL) return;
    inParse(T[u].left);
    printf(" %d", u);
    inParse(T[u].right);
}

void postParse(int u) {
    if(u == NIL) return;
    postParse(T[u].left);
    postParse(T[u].right);
    printf(" %d", u);
}

int main()
{
    int n, Root;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) T[i].parent = NIL;

    int v, l ,r;
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }

    for(int i = 0; i < n; i++) {
        if(T[i].parent == NIL) {
            Root = i;
            break;
        }
    }

    printf("Preorder\n");
    preParse(Root);

    printf("\nInorder\n");
    inParse(Root);

    printf("\nPostorder\n");
    postParse(Root);
    printf("\n");
    return 0;
}

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

ll n;
ll v[]={0,0,0,0};
double dp[301][301][301];


double countExpectedThrows(ll a1,ll a2,ll a3){
	if(a1==0 && a2==0 && a3==0)
		return 0;
	if(dp[a1][a2][a3]>=0){
		return dp[a1][a2][a3];
	}	
	double ans=n;
	if(a1)
		ans+=a1*countExpectedThrows(a1-1,a2,a3);
	if(a2)
		ans+=a2*countExpectedThrows(a1+1,a2-1,a3);
	if(a3)
		ans+=a3*countExpectedThrows(a1,a2+1,a3-1);
	ans/=(a1+a2+a3);
	dp[a1][a2][a3]=ans;
	return ans;			
}

int main(){
 cin>>n;
 memset(dp,-1,sizeof (dp));
 for(ll i=0;i<n;i++){
 	ll d;
 	cin>>d;
 	v[d]++;
 }
 cout<<fixed<<setprecision(21)<<countExpectedThrows(v[1],v[2],v[3])<<endl;
 return 0;
}

Measured memory_bytes: 216848
#rooted_tree
class Node
  attr_accessor :myname,:parent,:children,:depth

  def initialize(n)
    @myname = n
    @parent = -1
    @children = Array.new
    @child_count = 0
  end

  def add_child(child)
    children << child
    child.parent = self
  end

  def print_child
    cc = self.children.length
    printf(", [")
    0.upto(cc-1){|i|
      printf("%s",self.children[i])
      printf(", ") if i < cc-1
    }
    printf("]")
  end

  def print_parent
    printf("%s",self.parent)
  end

  def to_s
    "#@myname"
  end

  def set_depth(d)
    self.depth=d
    for c in self.children
      c.set_depth(d+1)
    end
  end

  def shubetu
    if self.parent == -1
      "root"
    elsif children.length == 0
      "leaf"
    else
      "internal node"
    end
  end

  def describe
    printf("node %s: parent = %s,",self.myname,self.parent)
    printf(" depth = %d,",self.depth)
    printf(" %s",self.shubetu)
    self.print_child
    printf("\n")
  end 

end


n = STDIN.gets.split[0].to_i
tree=Array.new(n){|i| Node.new(i)}

0.upto(n-1){|i|
  s = STDIN.gets.split
  id= s[0].to_i
  cc= s[1].to_i
  p=2
  cc.times{
    #puts tree[s[id].to_i]
    tree[id].add_child(tree[s[p].to_i])
    p += 1
  }
}

def findroot(tree,n)
  0.upto(n-1){|i|
    if tree[i].parent == -1 
      return i
    end
  }
end 

tree[findroot(tree,n)].set_depth(0)

0.upto(n-1){|i|
  tree[i].describe
}

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

int check(char s[], int f, int e)
{
	int m = f + (e - f + 1)/2;
	int flag = 1, l = (e - f + 1);
	for(int i = f; i < m; i++)
	{
		if(s[i] != s[2*m - i - (1 - l%2)])
		{
//			cout << "i = " << i << " 2*m - f = " << 2*m-f << " f = " << f << endl;
//			cout << "m = " << m << endl;
			flag = 0;
			break;
		}
	}
	return flag;
}

int main(void)
{
	char s[100];
	cin >> s;
	int x = 0, l;
	l = strlen(s);
	x += check(s, 0, l - 1);
//	cout << x << endl;
	x += check(s, 0, (l - 3)/2);
//	cout << x << endl;
	x += check(s, (l + 1)/2, l - 1);
 //	cout << x << endl;
	if(x == 3)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2005;

int H,W;
char mp[N][N];
int a[N][N];
int h[N];
int sta[N],top;

int main(){
	H=get();W=get();
	fo(i,1,H)scanf("%s",mp[i]+1);
	fo(i,1,H)
		fo(j,2,W)a[i][j]=(mp[i][j]==mp[i][j-1]);
	int ans=0;
	fo(i,1,H){
		fo(j,1,W)
		if (a[i][j]==a[i-1][j])h[j]++;else h[j]=1;
		sta[0]=1;
		sta[top=1]=1;
		fo(j,2,W){
			while(top&&h[sta[top]]>=h[j]){
				ans=max(ans,h[sta[top]]*(j-sta[top-1]));
				top--;
			}
			sta[++top]=j;
		}
		fo(j,1,top)ans=max(ans,h[sta[j]]*(W-sta[j-1]+1));
	}
	printf("%d\n",ans);
	return 0;
}

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

#include <cstdio>

using namespace std;

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

	int N, X;
	cin >> N >> X;

	int min = 1000;
	int count = 0;
	int m;

	for (int i = 0; i < N; i++) {
		cin >> m;

		X = X - m;
		if (m < min) {
			min = m;
		}
	}
	count = N + X / min;

	cout << count << '\n';


	return 0;
}

Measured memory_bytes: 256
import sys
def prime(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    N[0]=2
    return filter(None,N)
PRIMES=prime(105000)
while 1:
    n=input()
    if n==0: break
    print sum(PRIMES[:n])

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

int N,K,Q;
int A[100010];
int main(){
	cin >> N >> K >> Q;
	vector<int> v(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
		v[i] = A[i];
	}
	sort(v.begin(),v.end());
	int ans = v[Q-1]-v[0];
	for(int i=0;i<N;i++){
		vector<int> removed,pre_removed;
		int c = 0;
		for(int j=0;j<=N;j++){
			if(j!=N && A[j]>v[i]){
				pre_removed.push_back(A[j]);
				c++;
			}else{
				if(c>=K){
					sort(pre_removed.begin(),pre_removed.end());
					for(int k=0;k<=c-K;k++){
						removed.push_back(pre_removed[k]);
					}
				}
				pre_removed.clear();
				c = 0;
			}
		}
		if(removed.size()>=Q){
			sort(removed.begin(),removed.end());
			ans = min(ans,removed[Q-1]-removed[0]);
		}
		removed.clear();
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
<?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
//list($A,$B) = explode(" ",trim(fgets(STDIN)));
$N=trim(fgets(STDIN));
$A = explode(" ",trim(fgets(STDIN)));
$ret = 0;
while(1) {
  $flg = true;
  for($i=0;$i<$N;$i++) {
    if ($A[$i]%2==0) {
      $A[$i]=$A[$i]/2;
    }
    else {
      $flg = false;
      break;
    }
  }
  if ($flg == false) break;
  $ret++;
}
printf("%d\n",$ret);


Measured memory_bytes: 3956
#include<iostream>
using namespace std;
int main() {
	long long n; cin >> n;
	long long ans = 0;
	for (int i = 1; i <= 10000; i++) {
		ans += i;
		if (n <= ans) {
			for (int j = 1; j <= i; j++) 
				if (j != ans - n)printf("%d\n", j);
			return 0;
		}
	}
}

Measured memory_bytes: 256
import heapq

N, K = map(int, input().split())
heap = []
types = [0 for _ in range(N)]

class Sushi():
    def __init__(self, neta, aji):
        self.neta = neta - 1
        self.aji = aji

    def __str__(self):
        return "Sushi{0}: {1}".format(self.neta, self.aji)

    def reverse(self):
        self.aji = -self.aji

    def __lt__(self, other):
        return self.aji < other.aji

for _ in range(N):
    t, d = map(int, input().split())
    heap.append(Sushi(t, -d))
heapq.heapify(heap)

variety = 0
basic = 0
choices = []
for _ in range(K):
    sushi = heapq.heappop(heap)
    sushi.reverse()
    basic += sushi.aji
    neta = sushi.neta
    if types[neta] == 0:
        variety += 1
    types[neta] += 1
    choices.append(sushi)
heapq.heapify(choices)

satisfaction = basic + variety * variety
top_satisfaction = satisfaction
while True:
    drop_sushi = None
    while len(choices) > 0:
        choiced_sushi = heapq.heappop(choices)
        if types[choiced_sushi.neta] > 1:
            drop_sushi = choiced_sushi
            types[choiced_sushi.neta] -= 1
            break
    add_sushi = None
    while len(heap) > 0:
        new_sushi = heapq.heappop(heap)
        new_sushi.reverse()
        if types[new_sushi.neta] == 0:
            types[new_sushi.neta] += 1
            add_sushi = new_sushi
            break
    if drop_sushi is None or add_sushi is None:
        break
    else:
        variety += 1
        basic += add_sushi.aji - drop_sushi.aji
        satisfaction = basic + variety * variety
        if satisfaction > top_satisfaction:
            top_satisfaction = satisfaction
print(top_satisfaction)


Measured memory_bytes: 28116
#include <bits/stdc++.h>
#define rep(i,l,n) for(i=l;i<n;i++)
using namespace std;

int main(){
	int d,s,i,n;

	while(scanf("%d",&d)!=EOF){
		s=0;
		n=600/d;
		rep(i,1,n){
			s+=d*i*d*i*d;
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1208
N = int(input())
A = list(map(int,input().split()))
ans = float('inf')
up = -1
count = 0
for i in range(N-1):
    if A[i] > A[i+1]:
        if up == -1:
            up = 0
        elif up == 1:
            up = -1
            count += 1
    elif A[i] < A[i+1]:
        if up == -1:
            up = 1
        elif up == 0:
            up = -1
            count += 1
print(count+1)
            

Measured memory_bytes: 14252
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define dd double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1]=int(s[k-1])+32;
  cout<<s<<endl;
  
  return 0;
}

Measured memory_bytes: 3640
#import sys
#import numpy as np
#from collections import defaultdict



#input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    accept =[0] *(N+1)

    ac = 0
    wa = [0] *(N+1)

    for i in range(M):
        p, s = input().split()
        p = int(p)
        if accept[p] ==0:
            if s =="AC":
                accept[int(p)] =1
                ac +=1
            else:
                wa[p] +=1
    wrong =0
    for i in range(N+1):
        wrong += accept[i] * wa[i]

    print(ac,wrong)



if __name__ == "__main__":
    main()

Measured memory_bytes: 10356
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))


#if 1
//No.2
int main()
{
	INT K;
	string S;
	cin >> K >> S;

	if (S.length() <= K) { cout << S; }
	else {
		string tmp = S.substr(0, K);
		cout << tmp << "...";
	}

	return 0;
}
#endif


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define YES cout << "YES" << endl
#define NO  cout << "NO"  << endl
#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 777777753
using namespace std;
typedef long long ll;

int main(){
  int N;  cin >> N;
  vector<int> p(N);
  rep(i, 0, N)  cin>>p[i];
  sort(all(p));
  cout << accumulate(all(p), 0) - p.back()*0.5 << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC150
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] strs = Console.ReadLine().Split(' ');
			int k = int.Parse(strs[0]);
			int x = int.Parse(strs[1]);
			string result;

			if(k * 500 >= x)
			{
				result = "Yes";
			}
			else
			{
				result = "No";
			}

			Console.WriteLine(result);
		}
	}
}


Measured memory_bytes: 13140
import sys
import bisect


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


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    count = 0

    for j in range(1, N - 1):
        for i in range(j):
            if L[i] == L[j]:
                break

            count += bisect.bisect_left(L[j + 1:], L[i] + L[j]) - bisect.bisect_right(L[j + 1:], L[j])

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#include <numeric>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1N(i,n) for(int i=1;i<=n;i++)
#define pd push_back
#define eb emplace_back
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
typedef unsigned long long ull ;
typedef long long ll ;
using namespace std ;


int main()
{
  ll n ; cin >> n ;
  
  vector<pair<ll, ll>> ab_pair( n ) ;
  REP( i, n ) {
    ll a, b ;
    cin >> a >> b ;
    ab_pair.eb( make_pair( a, b ) ) ;
   

  }

  sort( ab_pair.begin(), ab_pair.end(),
       []( auto& pair1, auto& pair2 ) {
         return pair1.second < pair2.second ; 
       }
      ) ;

  bool bYes = true ;
  ll sum = 0 ;
  for ( const auto& pair : ab_pair ) {
    sum += pair.first ;
    if ( sum > pair.second ) {
      bYes = false ;
      break ;
    }
  }
  cout << (bYes ? "Yes" : "No") << endl ;
  
  return 0 ;
}

Measured memory_bytes: 8576