akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<ll> v;
    ll cnt = 0;
    ll now = 1;
    rep(i,N){
        if(S[i] - '0' == now){
            cnt++;
        }else{
            v.push_back(cnt);
            cnt = 0;
            now = (now==0?1:0);
            i--;
        }
    }
    v.push_back(cnt);
    if(now==0){
        v.push_back(0);
    }
    //PR(v,v.size());
    ll M = v.size();
    ll ans = 0;
    ll tmp = 0;// v[0];
    ll r = 0;
    rep(l,M){
        if(l > r) r = l;
        while(r < M && r < l+K*2+1 ){
            tmp += v[r];
            r++;
            /*if(r < M && r-l < K*2+1){
                tmp += v[r];
                r++;
            }*/
        }
        //cout << tmp << endl;
        cmax(ans, tmp);
        if(l<r){
            tmp -= v[l];
        }
        l++;
        if(l<r){
            tmp -= v[l];
        }
        //tmp -= v[l];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4452
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] d = new int[N];

        for (int i = 0 ; i < N ; i++) {
            d[i] = scanner.nextInt();
        }

        Arrays.sort(d);

        int low = d[N / 2 - 1];
        int high = d[N / 2];

        System.out.println(high - low);

    }
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N;
	cin >> N;
	int ans;
	if(N % 2 == 0) ans = N;
	else ans = 2 * N;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <queue>   
#include <utility>
#include <stdio.h>
#include <math.h>

using namespace std;
int main(){
  int n;
  cin>>n;
  long long g[100001];
  for (int i=0;i<n;i++){
    cin>>g[i];
  }
  int cur=g[0];
  int a=0;
  int ans=1;
  for (int i=1;i<n;i++){
    int curn=g[i];
    int an;
    if (curn>cur){
        if (a==0 || a==1) an=1;
        if (a==-1) {
            an=0;ans++;
        }
    }
    if (curn<cur){
        if (a==0 || a==-1) an=-1;
        if (a==1) {an=0; ans++;}
    }
    if (curn==cur) an=a;
    
    cur=curn;
    a=an;
    
  }
  cout<<ans;
  return 0;
}
    
    
    
  


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
	long long N;
	cin>>N;
	vector<long long> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	sort(A.begin(),A.end());
	
	int ok = N-1;
	int ng = -1;
	
	while(ok-ng>1){
		int mid = (ok+ng)/2;
		bool f = true;
		long long a = 0;
		
		for(int i=0;i<=mid;i++)a+=A[i];
		
		
		for(int i=mid+1;i<N;i++){
			if(a*2>=A[i]){
				a+=A[i];
			}
			else{
				f=false;
				break;
			}
		}
		
		if(f)ok=mid;
		else ng=mid;
	}
	
	cout<<N-1-ok+1<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
int a,b;
cin>>a>>b;

b=b*2;
if(a<=b){
    cout<<0<<endl;
}else{
    cout<<a-b<<endl;
}

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

import static java.lang.Character.isUpperCase;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a = sc.next().charAt(0);
        if (isUpperCase(a)) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 26924
// Greatest Common Divisor(最大公約数)
#include <stdio.h>

int main(void)
{
    int x, y, tmp;
    scanf("%d %d", &x, &y);

    if(x < y){
        tmp = x;
        x = y;
        y = tmp;
    }
    int r = x % y;
    while( r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    printf("%d\n", y);

    return 0;
}


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

int main() {
    char c;
    cin >> c;
    if(c == 'a' | c == 'e' | c == 'i' | c == 'o' | c == 'u') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <list>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define DBG 0

#define MAXN 100000
int main() {
  int n, m, x, y;
  cin >> n >> m;
  vector< list<int> > dest(n);
  vector< list<int> > src(n);
  forr(i,0,m-1) {
    cin >> x >> y;
    dest[x-1].push_back(y-1);
    src[y-1].push_back(x-1);
  }
  list<int> p;
  vector<int> a(n);
  vector<int> srcn(n);
  forr(i,0,n-1) {
    a[i] = 0;
    srcn[i] = src[i].size();
    if (srcn[i] == 0)
      p.push_back(i);
  }

  int dist, found;
  for(dist=1; !p.empty(); dist++) {
    list<int> pp;
    found = 0;
    for (auto it = p.begin(); it != p.end(); ++it)
      for (auto it2 = dest[*it].begin();
               it2 != dest[*it].end(); ++it2) {
         found = 1;
         int d = *it2;
         a[d] = dist;
         srcn[d]--;
         if (srcn[d] == 0)
           pp.push_back(d);
       }
    p.clear();
    for (auto it = pp.begin(); it != pp.end(); ++it)
      p.push_back(*it);
  }

  cout << (dist + found - 2);
}


Measured memory_bytes: 12544
use std::io::{Read, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();

    let _n: i32 = iter.next().unwrap().parse().unwrap();
    let a: Vec<i32> = iter.filter_map(|x| x.parse().ok()).collect();
    let mut max = a[0];
    let mut min = a[0];
    let mut sum = 0i64;
    for t in a.iter() {
        if max < *t  {max = *t}
        if min > *t  {min = *t}
        sum += *t as i64;
    }
    out.write_fmt(format_args!("{} {} {}\n", min, max, sum)).unwrap();

}



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

#pragma region unionfind
class unionfind{
    int *tree;
    size_t length;
public:
    size_t root(size_t v){
        if(tree[v] < 0) return v;
        else return tree[v] = root(tree[v]);
    }
    unionfind(size_t n): length(n){
        tree = new int[n];
        for(size_t i=0;i<n;++i) tree[i] = -1;
    }
    size_t count(size_t v){
        return -tree[root(v)];
    }
    bool is_same(size_t u, size_t v){
        return root(u) == root(v);
    }
    bool merge(size_t u, size_t v){
        u = root(u); v = root(v);
        if(u == v) return false;
        if(u > v) std::swap(u, v);
        tree[u] += tree[v];
        tree[v] = u;
        return true;
    }
};
#pragma endregion

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    static vector<int> edges[100000];
    cin >> n >> m;
    unionfind uf{n};
    for(int i=0;i<m;++i){
        int u, v;
        cin >> u >> v;
        --u; --v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        uf.merge(u, v);
    }
    int64_t conn = 0, isol = 0, nodd = 0;
    vector<int> ps;
    for(int i=0;i<n;++i){
        if(uf.root(i) != i) continue;
        if(uf.count(i) == 1) ++isol;
        else{ ++conn; ps.emplace_back(i); }
    }
    int64_t ans = isol * n * 2 - isol * isol;
    static int col[100000];
    nodd = conn;
    for(int p: ps){
        queue<pair<int, int>> q;
        col[p] = 1;
        q.emplace(p, 1);
        while(!q.empty()){
            auto t = q.front();
            q.pop();
            for(int to: edges[t.first]){
                if(col[to] == 0){ col[to] = -t.second; q.emplace(to, -t.second); }
                else if(col[to] == t.second){ --nodd; goto l_nx; }
            }
        }
        l_nx:;
    }
    ans += conn * conn + nodd * nodd;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7552
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int w, h, cnt;
char field[20][20];

void dfs(int x, int y) {
  if(0 <= x && x < h && 0 <= y && y < w && field[x][y] == '.') { 
    cnt++;
    field[x][y] = '#';
    REP(i, 4) {
      dfs(x+dx[i], y+dy[i]);
    }
  }
}

int main() {
  while(cin >> w >> h, w+h) {
    int px, py;
    REP(i, h) {
      REP(j, w) {
	cin >> field[i][j];
	if(field[i][j] == '@') {
	  px = i;
	  py = j;
	  field[i][j] = '.';
	}
      }
    }

    cnt = 0;
    dfs(px, py);
    cout << cnt << endl;
  } 
}

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

typedef long long ll;
const int N = 2022, mod = 1000000007;
int n, m, fa[N], pw[N];
pair<ll, pair<int, int>> e[N];
vector<pair<int, ll>> G[N];
ll x, s;

ll dfs(int x, int pre, int g) {
  if (x == g) return 0;
  for (auto y : G[x]) if (y.first != pre) {
    ll t = dfs(y.first, x, g);
    if (~t) return max(t, y.second);
  }
  return -1;
}

int F(int x) {while (fa[x] != x) x = fa[x] = fa[fa[x]]; return x;}
int main() {
  scanf("%d%d%lld", &n, &m, &x);
  pw[0] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lld", &e[i].second.first, &e[i].second.second, &e[i].first);
    pw[i] = (pw[i - 1] << 1) % mod;
  }
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    int u = F(e[i].second.first), v = F(e[i].second.second);
    if (u != v) {
      fa[u] = v;
      G[u].emplace_back(v, e[i].first);
      G[v].emplace_back(u, e[i].first);
      s += e[i].first;
      e[i].first = -1;
    }
  }
  if (x < s) return puts("0"), 0;
  int b = 0, c = 0;
  for (int i = 1; i <= m; i++) if (~e[i].first) {
    ll t = e[i].first - dfs(e[i].second.first, 0, e[i].second.second);
    if (t == x - s) b++;
    else if (t > x - s) c++;
  }
  int ans = 0;
  if (n == 1) {
    printf("%d\n", x == s);
    return 0;
  }
  if (x == s) {
    ans = (ll) (pw[n - 1] + mod - 2) * pw[m - n + 1] % mod;
  }
  ans = (ans + 2LL * (pw[b] - 1) * pw[c]) % mod;
  printf("%d\n", ans);
}


Measured memory_bytes: 384
#include <stdio.h>

const char* outList[50]={
	/* 0 */
	"wa","","nn","","wo",
	/* 1 */
	"a","i","u","e","o",
	/* 2 */
	"ka","ki","ku","ke","ko",
	/* 3 */
	"sa","si","su","se","so",
	/* 4 */
	"ta","ti","tu","te","to",
	/* 5 */
	"na","ni","nu","ne","no",
	/* 6 */
	"ha","hi","hu","he","ho",
	/* 7 */
	"ma","mi","mu","me","mo",
	/* 8 */
	"ya","","yu","","yo",
	/* 9 */
	"ra","ri","ru","re","ro",
};

int getID(const char* input) {
	int result=input[0]-'0';
	result*=5;
	switch(input[1]) {
		case 'T': return result;
		case 'L': return result+1;
		case 'U': return result+2;
		case 'R': return result+3;
		case 'D': return result+4;
	}
	return result;
}

int main(void) {
	char input[1004];
	char* ptr;
	scanf("%s",input);
	for(ptr=input;*ptr;ptr+=2) {
		printf("%s",outList[getID(ptr)]);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 536
#!/usr/bin/env python3
x,y = map(int,input().split())
#１つ前より大きくて整数倍になるのでxから２倍ずつになるのが最善
ans = 1
while True:
    if x*2 <= y:
        x *= 2
        ans += 1
    else: break
print(ans)

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll l[100];
    l[0] = 2;
    l[1] = 1;
    if(n==1)
        cout << 1 << endl;
        else{
            int i = 2;
            while(true){
                l[i] = l[i - 1] + l[i - 2];
                if(i==n){
                    cout << l[i] << endl;
                    return 0;
                }
                i++;
            }
        }
}

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

using namespace std;

typedef long long ll;

const int Maxn = 100110;
const int INF = (int) 1e9;

int dp[Maxn], h[Maxn];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    fill(dp, dp + Maxn, INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }

    cout << dp[n - 1] << endl;


    return 0;
}

Measured memory_bytes: 1024
class Dice:
    D = {'E':(3,1,0,5,4,2), 'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1), 'N':(1,5,2,3,0,4)}
    def __init__(self, tp, fwd, rs, ls, bk, bm):
        self.nbrs = [tp, fwd, rs, ls, bk, bm]
        self.RS = [[0, rs, bk, fwd, ls, 0], [ls, 0, tp, bm, 0, rs], [fwd, bm, 0, 0, tp, bk], [bk, tp, 0, 0, bm, fwd],
              [rs, 0, bm, tp, 0, ls], [0, ls, fwd, bk, rs, 0]]
    def rll(self, drctn):
        return [self.nbrs[i] for i in self.D[drctn]]
    def rs(self,tp,fwd):
        return self.RS[tp][fwd]


A = input().split()
dice = Dice(A[0], A[1], A[2], A[3], A[4], A[5])
for _ in range(int(input())):
    tp, fwd = input().split()
    print(dice.rs(dice.nbrs.index(tp), dice.nbrs.index(fwd)))


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long n, a, b; scan(n, a, b);
      std::string ss; scan(ss);
      long p = 0, q = 0;
      for(long i = 0; i < n; ++i) {
         switch( ss[i] ) {
         case 'a' :
            if( p < a + b ) p += 1, puts("Yes");
            else puts("No");
            break;
         case 'b' :
            if( p < a + b and q < b ) p += 1, q += 1, puts("Yes");
            else puts("No");
            break;
         case 'c' :
            puts("No");
         }
      }
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE;
    SetConsoleTextAttribute(hConsole, 7);
    cerr << '\n';
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1> {}(p.first);
        auto h2 = hash<T2> {}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "-1\n";
    exit(0);
}
const int NMAX = 3 * 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;
const int seed = 1e3 + 7;

string s;
int sol;
int l, r;
int main()
{
    FASTIO;
    cin >> s;
    r = s.size() - 1;
    while(l < r)
    {
        if(s[l] == s[r])
        {
            l++;
            r--;
            continue;
        }
        sol++;
        if(s[l] == 'x')
        {
            l++;
            continue;
        }
        if(s[r] == 'x')
        {
            r--;
            continue;
        }
        return cout << -1, 0;
    }
    cout << sol;
    return 0;
}




Measured memory_bytes: 512
use itertools::Itertools as _;
use proconio::*;
macro_rules! p {
    ($x:expr) => {
        println!("{}", $x);
    };
}
fn main() {
    input! {
        n:usize,
        s:[usize;n],
        t:[usize;n],
        u:[u64;n],
        v:[u64;n],
    }
    let mask = std::u64::MAX;
    let (or, and) = (1, 0);
    // 1確定
    let mut one = vec![vec![0u64; n]; n];
    // 0確定
    let mut zero = vec![vec![0u64; n]; n];

    // 自明
    for i in 0..n {
        for j in 0..n {
            if s[i] == and {
                one[i][j] |= u[i];
            } else {
                zero[i][j] |= !u[i];
            }
            if t[j] == and {
                one[i][j] |= v[j];
            } else {
                zero[i][j] |= !v[j];
            }
            if one[i][j] & zero[i][j] != 0 {
                p!(-1);
                return;
            }
        }
    }
    let mut ans = one.clone();

    let ch = |ans: &[Vec<u64>]| {
        let mut u_check = (0..n)
            .map(|i| if s[i] == or { 0 } else { mask })
            .collect_vec();
        let mut v_check = (0..n)
            .map(|j| if t[j] == or { 0 } else { mask })
            .collect_vec();

        for i in 0..n {
            for j in 0..n {
                if s[i] == and {
                    u_check[i] &= ans[i][j];
                } else {
                    u_check[i] |= ans[i][j];
                }
                if t[j] == and {
                    v_check[j] &= ans[i][j];
                } else {
                    v_check[j] |= ans[i][j];
                }
            }
        }
        let check = u
            .iter()
            .zip(&u_check)
            .chain(v.iter().zip(&v_check))
            .map(|(x, y)| x ^ y)
            .fold(0, |x, y| x | y);
        check
    };
    for i in 0..n {
        for j in 0..n {
            ans[i][j] |= !zero[i][j] & mask * (i ^ j) as u64;
        }
    }
    let check = ch(&ans);
    for i in 0..n {
        for j in 0..n {
            ans[i][j] &= !check;
            ans[i][j] |= check & (u[i] | v[j]) & !zero[i][j];
        }
    }
    let check = ch(&ans);

    for i in 0..n {
        for j in 0..n {
            ans[i][j] &= !check;
            ans[i][j] |= check & ((u[i] & v[j]) | one[i][j]);
        }
    }
    let check = ch(&ans);
    if check != 0 {
        p!(-1);
        return;
    }

    ans.iter().for_each(|x| p!(x.iter().join(" ")));
}


Measured memory_bytes: 11508
n = int(input())
s = input()
dp = [[0]*(n+1) for i in range(n+1)]
for i in reversed(range(n)):
    for j in reversed(range(0, i, 1)):
        if s[i] == s[j]:
            dp[j][i] = dp[j+1][i+1] + 1
ans = 0
for i in reversed(range(n)):
    for j in reversed(range(0, i, 1)):
        ans = max(min(dp[j][i], i-j), ans)
print(ans)

Measured memory_bytes: 230536
#include<iostream>
#include <bits/stdc++.h>
#include<vector>
#include<cstdlib>

using namespace std;

int main(){
long a,b,x;

  cin>>a>>b>>x;
  long long temp;
  if(a%x==0)temp=a;
  else temp=x*(a/x)+x;

  long long re=(b-temp)/x;
  temp =temp+re*x;
  while(temp<=b){
    temp=temp+x;
    re++;
  }

  cout<<re<<endl;





  return 0;
  }


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val Vector(n, m) = Vector.fill(2)(sc.nextInt)
  val map: mutable.Map[Int, Set[Int]] = mutable.Map.empty
  (1 to n).foreach { i => map.update(i, Set.empty) }

  val es = Vector.fill(m)(Edge(sc.nextInt, sc.nextInt))
  es.foreach { e =>
    map.update(e.v1, map(e.v1) + e.v2)
    map.update(e.v2, map(e.v2) + e.v1)
  }

  println(solve(1, Set(1), "1"))

  def solve(current: Int, already: Set[Int], route: String): Int = {
    val ints: Set[Int] = map(current) -- already
    if (already.size == n) 1 else {
      if (ints.isEmpty) 0
      else ints.toStream.map(n => solve(n, already + n, route + s"->$n")).sum
    }
  }
}

case class Edge(v1: Int, v2: Int)

case class Vertex(index: Int, nexts: Set[Int])


Measured memory_bytes: 61268
#include<stdio.h>

int main(){
  int n,sum,max;
  scanf("%d",&n);
  int l[n];
  sum= 0;
  for(int i =0 ;i < n;i++){
    scanf("%d",&l[i]);
    sum += l[i];
  }
  max =l[0];
  for(int i = 1;i < n;i++){
    if(max < l[i]){
      max = l[i];
    }
  }
  if(max < sum-max){
    printf("Yes");
  }else{
    printf("No");
  }
}
      
    


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

int main()
{
	int  n, w;
	while(1){
		cin >> n >> w;
		if(n == 0 && w == 0) break;
		double height[100] = {0};
		int howmanyranges = 0;
		for(int i = 0; i < n; i++){
			int v;
			cin >> v;
			int j = 0;
			while(1){
				if(v >= j * w && v < (j + 1) * w){
					height[j]++;
					break;
				}
				else j++;
			}
			howmanyranges = max(howmanyranges, (v / w + 1));
		}
		double maxheight = 0;
		double howmanybars = 0;
		for(int i = 0; i < 100; i++){
			if(height[i] != 0) howmanybars++;
			maxheight = max(maxheight, height[i]);
		}
		double ans = 0;
		double color = howmanyranges - 1;
		if(howmanybars == 1) ans = 0;
		for(int i = 0; i < 100; i++){
				ans += ((howmanyranges - 1 - i) * height[i]) / ((howmanyranges - 1) * maxheight);
				
		}
		ans += 0.01;
		cout << setprecision( 6 ) << ans << endl;
	}
}

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

using namespace std;
constexpr int paper_w=10,paper_h=10;
constexpr int ink_w=5,ink_h=5;
int inkarea[3][ink_h][ink_w]={
  0,0,0,0,0,
  0,0,1,0,0,
  0,1,1,1,0,
  0,0,1,0,0,
  0,0,0,0,0,

  0,0,0,0,0,
  0,1,1,1,0,
  0,1,1,1,0,
  0,1,1,1,0,
  0,0,0,0,0,

  0,0,1,0,0,
  0,1,1,1,0,
  1,1,1,1,1,
  0,1,1,1,0,
  0,0,1,0,0
};

int main(){
  int paper[paper_h][paper_w]={0};
  int x,y,size;
  char c;
  while(cin>>x>>c>>y>>c>>size){
    for(int i=0;i<ink_h;i++){
      for(int j=0;j<ink_w;j++){
        int ink_x=x+j-2,ink_y=y+i-2;
        if(ink_y<0||paper_h<=ink_y||ink_x<0||paper_w<=ink_x)
          continue;
        paper[ink_y][ink_x]+=inkarea[size-1][i][j];
      }
    }
  } 
  int white=0,density=0;
  for(int i=0;i<paper_h;i++){
    for(int j=0;j<paper_w;j++){
      if(!paper[i][j])
        white++;
      if(density<paper[i][j])
        density=paper[i][j];
    }
  }
  cout<<white<<endl;
  cout<<density<<endl;

}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{
    int N , A , B ;
    cin >> N >> A >> B ;
    A = A * N ;
    if(A <= B)
    {
        cout << A  << endl;
    }
    else
    {
        cout << B << endl;
    }

    return 0;
}


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

int main(){
	int n,t ;
	cin >> n >> t ;
	int mn = 100000 ;
	for(int i=0;i<n;i++){
		int a,b ;
		cin >> a >> b ;
		if(b>t) continue ;
		if(mn>a) mn = a ;
	}
	if(mn==100000) cout << "TLE" << endl ;
	else cout << mn << endl ;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    string s;
    scan(s);
    auto n = s.length.to!int;

    int ans1, ans2;

    foreach (i ; 0 .. n) {
        int a = s[i] - '0';
        if ((a ^ (i & 1)) == 0) ans1++;
        if ((a ^ (i & 1)) == 1) ans2++;
    }

    int ans = min(ans1, ans2);
    writeln(ans);
}

























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int x; cin >> x;
  for(int i = 1; i * 100 <= x; i++){
    int rem = x - i * 100;
    if(0 <= rem && rem <= 5 * i){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define PI 3.14159265
int main(){
    long double a, b, d;
    cin >> a >> b >> d;
    long double toplam = a*a*b;
    long double bos = toplam - d;
    if(d*2 < toplam){
    	long double y;
    	long double temp = (2*d)/b;
    	y = temp/a;
    
    	long double result = atan (b/y) * 180 / PI;
    	printf("%Lf", result);
	}else{
		long double x;
    	x = (2*bos)/(a*a);
    	x/=a;
    	long double sonuc = atan (x) * 180 / PI;
    	printf("%Lf", sonuc);
	}
    
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long k = sc.nextLong();
    
    
    if (a>k) {
      a -= k;
    }
    else {
      k -= a;
      a = 0;
      if (b>k) {
        b -= k;
      }
      else {
        b = 0;
      }
    }
    
    System.out.println(a + " " + b);
    
  } 
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<vector<int>> A(3, vector<int>(3));
    for (size_t i = 0; i < 3; i++)
    {
        for (size_t j = 0; j < 3; j++)
        {
            cin >> A[i][j];
        }
    }

    int N;
    cin >> N;
    vector<vector<bool>> res(3, vector<bool>(3, false));

    for (size_t i = 0; i < N; i++)
    {
        int b;
        cin >> b;
        for (size_t j = 0; j < 3; j++)
        {
            for (size_t k = 0; k < 3; k++)
            {
                if (A[j][k] == b) {
                    res[j][k] = true;
                }
            }
        }
    }

    bool bingo = false;
    for (size_t i = 0; i < 3; i++)
    {
        if (res[i][0] == true && res[i][1] == true && res[i][2] == true){
            bingo = true;
        }
    }

    for (size_t i = 0; i < 3; i++)
    {
        if (res[0][i] == true && res[1][i] == true && res[2][i] == true) {
            bingo = true;
        }
    }

    if (res[0][0] == true && res[1][1] == true && res[2][2] == true) {
        bingo = true;
    }
    if (res[2][0] == true && res[1][1] == true && res[0][2] == true) {
        bingo = true;
    }
    
    if (bingo) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int h[5];
  while(cin>>h[0],h[0]){
    cin>>h[1]>>h[2]>>h[3]>>h[4];
    for(int i=0;i<5;i++){
      bool f1=0,f2=0;
      for(int j=0;j<5;j++){
	if(i==j) continue;
	if(h[i]==1){
	  f1|=h[j]==2;
	  f2|=h[j]==3;
	}
	if(h[i]==2){
	  f1|=h[j]==3;
	  f2|=h[j]==1;
	}
	if(h[i]==3){
	  f1|=h[j]==1;
	  f2|=h[j]==2;
	}
      }
      cout<<(f1|f2?f1+f2*2:3)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

void Main()
{
	ll A, B; cin >> A >> B;
	ll sum = A + B;
	int div = sum / 2;
	int mod = sum % 2;
	if (mod == 0) {
		cout << div << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Measured memory_bytes: 256
#include <stdio.h>

#define HASHSIZ 25013
int hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(int n)
{
	int *p;
	
	n++; p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return 1;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(int n)
{
	int *p;
	
	n++; p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return;
		if (++p == hashend) p = hash;
	}
	*p = n;
}


//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int n, q, C;

	n = in();
	while (n--) insert(in());

	C = 0;
	q = in();
	while (q--) if (lookup(in())) C++;
	
	printf("%d\n", C);
	return 0;
}



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

int main(){
    int a, b, k; cin >> a >> b >> k;

    for(int i = a; i <= b; i++){
        if(i - a < k || b - i < k){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
L,R=map(int,input().split())
for i in range(M-1):
    newL,newR=map(int,input().split())
    L,R=max(L,newL),min(R,newR)
print(R-L+1) if R-L>=0 else print(0)

Measured memory_bytes: 44776
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e3+10;
long long int dp[2][maxn][maxn];
int n;
int a[maxn];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>n;
     for(int i=0;i<n;i++){
     	cin>>a[i];
	 }
	 for(int i=n-1;i>=0;i--){
	 	for(int j=i;j<n;j++){
	 		if(i==j){
	 			dp[0][i][j]=a[i];
	 			dp[1][i][j]-=a[i];
			 }
			 else{
			 	dp[0][i][j]=max(a[i]+dp[1][i+1][j],a[j]+dp[1][i][j-1]);
			 	dp[1][i][j]=min(dp[0][i+1][j]-a[i],dp[0][i][j-1]-a[j]);
			 }
		 }
	 }
	 cout<<dp[0][0][n-1];
	 }

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

int main(){
    string in;
    int sum = 0;
    while( cin >> in ){
        for( int i=0; i<in.length(); i++ ){
            if( '0' <= in[i] && in[i]<= '9' ){
                int add = 0;
                do{
                    add = add*10 + in[i]-'0';
                    i++;
                }while( i<in.length() && '0' <= in[i] && in[i] <= '9' );
                sum += add;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  long long int front, back;
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A') {
      front = i;
      break;
    }
  }
  for (int i = S.size()-1; i >= 0; i--) {
    if (S[i] == 'Z') {
      back = i;
      break;
    }
  }
  cout << back-front+1 << endl;
  return 0;
}


Measured memory_bytes: 640
NIL = -1


class Node:
    right = NIL
    left = NIL
    parent = NIL


def setHeight(u):
    global T, H
    hr = 0
    hl = 0
    if T[u].right != NIL:
        hr = setHeight(T[u].right) + 1
    if T[u].left != NIL:
        hl = setHeight(T[u].left) + 1
    h = max(hr, hl)
    H[u] = h
    return h


def setDepth(u, d):
    global T, D
    D[u] = d
    if T[u].right != NIL:
        setDepth(T[u].right, d + 1)
    if T[u].left != NIL:
        setDepth(T[u].left, d + 1)


def getSibling(u):
    global T
    if T[u].parent == NIL:
        return NIL
    if T[T[u].parent].left != u and T[T[u].parent].left != NIL:
        return T[T[u].parent].left
    if T[T[u].parent].right != u and T[T[u].parent].right != NIL:
        return T[T[u].parent].right
    return NIL


def getDegree(u):
    global T
    deg = 0
    if T[u].left != NIL: deg += 1
    if T[u].right != NIL: deg += 1
    return deg


def show_info(u):
    global T, D, H
    label = ""
    if T[u].parent == NIL:
        label = 'root'
    elif T[u].left == NIL and T[u].right == NIL:
        label = 'leaf'
    else:
        label = 'internal node'
    print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(u, T[u].parent,
                                                                                                       getSibling(u),
                                                                                                       getDegree(u),
                                                                                                       D[u],
                                                                                                       H[u], label))


if __name__ == "__main__":
    # ????????¨??????
    n = int(input())
    T, D, H = [], [], []
    root_num = NIL
    for i in range(n):
        T.append(Node())
        D.append(NIL)
        H.append(0)
    for i in range(n):
        id, r, l = map(int, input().split())
        T[id].right = r
        T[id].left = l
    for i in range(n):
        if T[i].right != NIL:
            T[T[i].right].parent = i
        if T[i].left != NIL:
            T[T[i].left].parent = i
    for i in range(n):
        if T[i].parent == NIL:
            root_num = i

    setHeight(root_num)
    setDepth(root_num, 0)
    for i in range(n):
        show_info(i)

Measured memory_bytes: 7876
def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(5)]
	# s = list(s)
	ans = 0
	for i in range(1,n+1):
		if i % 2 != 0:
			ans += 1
	print(ans/n)


 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38256
let m = 1_000_000_007
let n = read_int()
let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun i -> i))

let rec f i s =
  if i = 60 then s
  else
    let b = 1 lsl i in
    let rec g j z =
      if j = n then z
      else if a.(j) land b = 0 then g (j + 1) (z + 1)
      else g (j + 1) z in
    let z = g 0 0 in
    f (i + 1) ((s + b mod m * z mod m * (n - z) mod m) mod m)

let () = Printf.printf "%d\n" (f 0 0)


Measured memory_bytes: 8256
n, m = map(int, input().split(' '))

f = []

for _ in range(n):
    # a: cost 
    # b: cans
    a, b = map(int, input().split(' '))

    f.append((a, b))

f = sorted(f)

ans = 0

for tup in f:
    if m >= tup[1]:
        ans += (tup[0] * tup[1])
        m -= tup[1]
    
    else:
        ans += m * tup[0]
        break

print(ans)

Measured memory_bytes: 17788
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
using namespace boost::multiprecision;  
using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    int n;
    cin >> n;

    vector<int> x(n);
    rep(i,n){
        cin >> x[i];
    }

    int res = INF;

    reps(i,100){
        int sum = 0;
        rep(j,n){
            sum += (x[j] - i) * (x[j] - i);
        }
        chmin(res,sum);
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;

int main(){
  double n,m;
  cin >> n >> m;
  ll res = (1900 * m + 100*(n-m)) * pow(2.0,m);
  cout << res << endl;
}

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


int main()
{
	int a,b;
	while(scanf("%d %d",&a,&b) != EOF){
	if(a + b != 0){
		printf("%d\n",(int)log10((double)(a+b)) + 1);
	}else{
		printf("0");
	}
	}
	return 0;
}

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



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

    int n, x, t;
    cin >> n >> x >> t;

    int curr = 0;
    int ans = 0;
    while( n > curr ){
        curr += x;
        ans += t;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    ll t=exp(x,y/2);
    return (t*t);
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

struct unionfind{
  vector<int> par;
  vector<ll> sizes;
  void begin(int n){
    par.resize(n,-1);
    sizes.resize(n,1);
  }
  
  int find(int x){
    if(par[x]==-1)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    par[x]=y;//yが親
    sizes[y]+=sizes[x];
    sizes[x]=0;
  }
};



int main(){
  int n,m;cin >> n >> m;
  unionfind uf;
  uf.begin(n);
  vector<pair<int,int>> stdin(m-1);
  int aa,bb;cin >> aa >> bb;
  rep(i,m-1){
    cin >> stdin[m-i-2].first >> stdin[m-i-2].second;
  }
  ll ans=n*(n-1LL)/2LL;
  vector<ll> answer(m);
  answer[m-1]=ans;
  rep(i,m-1){
    int a=stdin[i].first;int b=stdin[i].second;
    a--;b--;
    if(uf.find(a)!=uf.find(b)){
      ans-=uf.sizes[uf.find(a)]*uf.sizes[uf.find(b)];
      uf.unite(a,b);
    }
    answer[m-i-2]=ans;
  }
  rep(i,m)cout << answer[i] << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;

string str;
string target = "keyence";

int main(){
	cin>>str;
	if(str == target){
		cout << "YES" << endl;
		return 0;
	}
	int n = str.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			string S = "";
			for(int k=0;k<n;k++){
				//除くところの先頭i
				//除くところの末尾j	をきめてるので、
				//除いてないところを取り出してる
				if(i<=k && k<=j){
					continue;
				}
				else S.push_back(str[k]);
			}
			if(S == target){
				cout << ("YES") << endl;;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n;cin>>n;
    vector<char> c(n);
    rep(i,n)cin>>c[i];
    int cw = 0;int cr=0;
    int ans =0;
    rep(i,n){
        if(c[i]=='W')cw++;
        else cr++;
    }

    rep(i,cr){
        if(c[i]=='W')ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3612