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

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

typedef struct node * Node;

Node root; 
Node treeMinimum(Node x)
{ 
}
 
Node treeSearch(Node u, int k)
{ 
}
 
Node treeSuccessor(Node x)
{
}
 
void treeDelete(Node z)
{
  Node y;
  Node x; 
}
 
void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
	{
	  x=x->left;
	}
      else
	{
	  x=x->right;
	}
    }
  
  z->parent=y;
  if(y==NIL)
    {  
      root=z;
    }
  else if(z->key < y->key)
    {    
      y->left=z;
    }
  else
    {  
      y->right=z;
    }
}

void inorder(Node x)
{
  if(x!=NIL)
    {
      inorder(x->left);
      printf(" %d", x->key);
      inorder(x->right);
    }
}
void preorder(Node x)
{
  if(x!=NIL)
    {
      printf(" %d", x->key);
      preorder(x->left);
      preorder(x->right);
    }
}
 
 
int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  root=NIL;
  
  for ( i = 0; i < n; i++ )
    {   
      scanf("%s", com); 
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
	  if ( t != NIL )
	    {
	      printf("yes\n");
	    }
	  else
	    {
	      printf("no\n");
	    }
	}
      else if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      else if ( com[0] == 'd' )
	{
	  scanf("%d", &x);
	  treeDelete(treeSearch(root, x));
	}
    }
  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n), y(n);
  vector<char> c(n);
  rep(i, n) cin >> x[i] >> y[i] >> c[i];

  int s[k + 1][k + 1], d[k + 1][k + 1];
  memset(s, 0, sizeof(s));
  memset(d, 0, sizeof(d));

  rep(i, n) {
    int res = (x[i] / k + y[i] / k) % 2;
    int rx = x[i] % k + 1, ry = y[i] % k + 1;
    if (res == 0 && c[i] == 'W') s[rx][ry]++;
    else if (res == 1 && c[i] == 'B') s[rx][ry]++;
    else d[rx][ry]++;
  }

  FOR(i, 1, k + 1) {
    FOR(j, 1, k + 1) {
      s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
      d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
    }
  }

  int ans = 0;
  rep(i, k) {
    rep(j, k) {
      int res = s[k - i][k - j];
      res += s[k][k] - s[k - i][k] - s[k][k - j] + s[k - i][k - j];
      res += d[k - i][k] - d[k - i][k - j];
      res += d[k][k - j] - d[k - i][k - j];
      res = max(res, n - res);
      ans = max(ans, res);
    }
  }
  cout << ans << endl;



  
  return 0;
}

Measured memory_bytes: 8960
N, M = gets.chomp.split(" ").map(&:to_i)
S = []
N.times{ S << gets.chomp}
T = []
M.times{ T << gets.chomp}

ans = 'No'
(0..(N-M)).each{|i|
  (0..(N-M)).each{|j|
    flg = true
    (0...M).each{|k|
      (0...M).each{|l|
        (flg = false; break) if S[i+k][j+l] != T[k][l]
      }
      break if !flg
    }
    (ans = 'Yes'; break) if flg
  }
}

puts ans


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

int main()
{
	int n,x,y;
	cin>>n;
	cin>>x;
	y=x;
	for(int i=1;i<n;i++)
	{
		cin>>x;
		y=__gcd(x,y);
	}
	cout<<y<<"\n";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
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++)

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

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

int main()
{
    string s;cin>>s;
    int flag=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='C' && !flag)flag=1;
        if(s[i]=='F' && flag)
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
}

Measured memory_bytes: 256
let A = Int(readLine()!)!
    let B = Int(readLine()!)!
    let C = Int(readLine()!)!
    let X = Int(readLine()!)!
    
    if (A == 0) && (B == 0) && (C == 0) {
        //exit(0)
    }
    
    if (50...20000 ~= X) && (X % 50 != 0) {
        //exit(0)
    }
    
    var collectCount = 0
    for _500Coins in 0...A{
        for _100Coins in 0...B{
            for _50Coins in 0...C{
                let totalPrice = _500Coins * 500 + _100Coins * 100 + _50Coins * 50
                if X == totalPrice{
                    collectCount += 1
                }
            }
        }
    }
    
    print(collectCount)

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
const int N = 1e6 + 1;
const int inf = 1e18 + 7;
const int md = 1e9 + 7;
using namespace std;
void sol() {
  int n, a, b;
  int ans = inf;
  cin >> n >> a >> b;
  int d = b - a;
  if(d % 2 == 0) {
    ans = d/2;
  }
  else {
    int a3 = inf;
    int a4 = inf;
    int a1 = n - b;
    int q = (a + n - b);
    q++;
    a1 += (n - q)/2;
    a1++;
    int a2 = a - 1;
    int p = b - (a - 1);
    p--;
    a2 += (p - 1)/2 + 1;
    ans = min(a1, a2);
    //cout << "a = " << a;
    if(a == 1) {
      b--;
      a3 = (b - a)/2 + 1;
    }
    else if(b == n) {
      a++;
      a4 = (b - a)/2 + 1;
    }
    //cout << a1 << a2 << a3 << a4;
    ans = min(ans, a4);
    ans = min(ans, a3);
  }
  cout << ans;
}
int32_t main() {
  int T = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //cin >> T;
  while(T--)
    sol();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,i,j,k;
    scanf("%d",&a);
    int x[a];
    for(i=0;i<a;i++){
        scanf("%d",&x[i]);
    }
    for(i=0;i<a;i++){
        b=x[i];
        j=i-1;
        while(j>=0&&x[j]>b){
            x[j+1]=x[j];
            j--;
            x[j+1]=b;
        }
        for(k=0;k<a;k++){
            if(k==a-1)printf("%d\n",x[k]);
            else printf("%d ",x[k]);
        }
    }
    return 0;
}

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


int main(){
	int a,b,h,m;
	cin >> a >> b >> h >> m;
    double pi = 3.1415926535897932384626433832795;
    double t = 60*h+m;
	double c = cos(t*5.5*pi/180);
	double  d = 0.00000000000000001;
	d = sqrt(a*a+b*b-2*a*b*c);
    cout <<setprecision(12)<< d << endl;
}



Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define f first
#define s second

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x, ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {if (ex & 1ll) ans = (ans * x) % md; ex >>= 1ll;x = (x * x) % md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 1e7 + 2;
const ll mX = 1e7 + 2;
// finding shortest prime factor//SPF -- Nlog(n)
ll spf[mX] , a[N];
void seive (){
    spf[1] = 1;
    for (ll i = 2; i < mX; i++){
        if (spf[i] == 0){
            spf[i] = i;
            for (ll j = 1ll * i * i; j < mX; j += i){
                if (spf[j] == 0) spf[j] = i;
            }
        }
    }
}
void solve(){
    ll n;
    cin >> n;
    seive();
    // return;
    a[1] = 1;
    for(ll i = 2; i <= n ; i++){
        ll temp = i;
        ll div = spf[i];
        ll ct = 0 ;
        while(temp%div == 0){
            temp /= div;
            ct++;
        }
        a[i] = (ct + 1)*a[temp];
        
    }
    ll ans = 0;
    for(ll i = 1 ; i <= n ; i++){
        ans += i*(a[i]);
    }
    cout << ans << endl;
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC=1;
    // cin>>NTC;
    ll PTC=0;
    while(PTC++<NTC){
        // cout<<"Case #"<<PTC<<":"<<' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 160044
#include <iostream>
#include <string>
#include<iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int N;
    cin >> N;
    double A[N];
    rep(i,N) cin >> A[i];
    double B[N], B_sum;
    int i, j;
    for(i=0; i < N; i++){
        B[i] = 1;
        for(j=0; j < N; j++){
            if(j!=i) B[i] = B[i]*A[j];
        }
        B_sum += B[i];
    }
    double c;
    double ans;
    c = 1;
    rep(i,N) c = c*A[i];
    
    ans = c / B_sum;
    
    cout << fixed << setprecision(10) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

    char c;
    cin >> c;
    if (c == 'z') cout << 'a';
    else cout << (char)(c + 1) << endl;
}   

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

	int x = 0;	scanf("%d", &x);
	int y = 0;	scanf("%d", &y);

	while (1) {
		if ((x == 0) && (y == 0)) {
			return 0;
		}

		if (x > y) {
			int temp = x;
			x = y;
			y = temp;
		}

		printf("%d %d\n", x, y);
		scanf("%d %d", &x, &y);
	}

	return 0;
}


Measured memory_bytes: 2100
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	long name_cnt[5] = {};

	cin >> N;

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

		if (s[0] == 'M') name_cnt[0]++;
		if (s[0] == 'A') name_cnt[1]++;
		if (s[0] == 'R') name_cnt[2]++;
		if (s[0] == 'C') name_cnt[3]++;
		if (s[0] == 'H') name_cnt[4]++;
	}

	long ans = 0;

	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += name_cnt[i] * name_cnt[j] * name_cnt[k];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC80 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,C = LI()
stc = [LI() for _ in range(n)]
L = []
for i in range(C):
    lst = []
    for j in range(n):
        s,t,c = stc[j]
        if i+1 == c:
            lst.append([s,t])
    lst.sort(key = itemgetter(0))
    lst2 = []
    j = 0
    while j < len(lst):
        if j < len(lst)-1:
            if lst[j][1] == lst[j+1][0]:
                lst2.append((lst[j][0],lst[j+1][1]))
                j += 2
                continue

        lst2.append(tuple(lst[j]))
        j += 1
    L.append(lst2)
x = [[0]*100002 for _ in range(C)]
for i in range(C):
    for j,k in L[i]:
        x[i][j] += 1
        x[i][k+1] -= 1
    x[i] = list(accumulate(x[i]))
ans = 0
for i in range(1,10**5+1):
    s = 0
    for j in range(C):
        if x[j][i] == 1:
            s += 1
    ans = max(ans,s)
print(ans)


Measured memory_bytes: 138632
#include <iostream>
using namespace std;
int main (){
 int a,b,c,d,e;
 a=b=c=d=e=0;
 cin>>a>>b;
 c=a*b;
 d=a+b;
 e=2*d;
 cout<<c<<" "<<e<<endl;
 return 0;



}

Measured memory_bytes: 1164
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcountll(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19;

long long go(long long n)
{
	if (n == 1ll)	return 1;
	return go(n/2)*2 + 1;
}

void solve()
{
	long long n;
	scanf ("%lld", &n);
	printf("%lld\n", go(n));
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}





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

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

void solve(void)
{
	ui N{};	std::cin >> N;

	typedef std::vector<ull> mVector;
	mVector vc(N, 0);
	for (ui i = 0; i < N; ++i) std::cin >> vc[i];

	std::reverse(vc.begin(), vc.end());

	mVector ret;
	ret.reserve(N);
	for (auto value : vc)
	{
		auto it = std::upper_bound(ret.begin(), ret.end(), value);

		if (it == ret.end())
			ret.push_back(value);
		else
			*it = value;
	}

	std::cout << ret.size() << "\n";

	return;
}

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

	solve();

	return 0;
}


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

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 6;
string s[N];

int main() {
  int n, m, len;
  cin >> n >> m >> len;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  int ret = 0;
  for (int S = 0; S < (1 << n); ++S) {
    for (int T = 0; T < (1 << m); ++T) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
          if ((S & (1 << i)) || (T & (1 << j))) continue;
          cnt += s[i][j] == '#';
        }
      }
      if (cnt == len) ++ret;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3196
#include<stdio.h>
int f[10000000];
int main(void)
{
	int n,i,j,flg,w,a,b,c,d,l=0;
	for(i=2;i<10000000;i++) f[i]=1;
	for(i=2;i*i<=10000000;i++){
	    for(j=2;i*j<=10000000;j++){
			f[j*i]=0;
		}
	}
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		a=0;
		b=0;
		c=0;
		d=0;
		for(i=n;i>=5;i--){
			if(f[i]!=0){
				d=c;
				c=b;
				b=a;
				a=i;
			}
			if(a+8==d&&b+6==d&&c+2==d) break; 
		}
		printf("%d\n",d);
	}
	return 0;
}

Measured memory_bytes: 41760
#include<stdio.h>

int main()
{
  int n;
  int count;
  int i,j,k;
  int s = 0;

  while(1){
    count = 0;

    scanf("%d",&n);
    if(n == 0){
      break;
    }
    else if(n == 1){
      count++;
    }
      
    else{
        k = 2*n;
        n = n+1;

        if(n%2 == 0){
            n = n+1;
        }

        for(i = n;i <= k;i = i+2){
            for(j = 3;j*j <= i;j = j+2){
                if(i%j == 0){
                    s = 1;
                    break;
                }
            }
            if(s == 0){
                count++;
            }
            s = 0;
        }
    }
    printf("%d\n",count);
  }
    return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <iostream>
#include <vector>

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


int main(){
        int N;
        scanf("%d",&N);
        long long int a[N];
        rep(i,N){
                scanf("%lld",a+i);
        }
        long long int ans = 0;
        for(;;){
                int cl = 0;
                rep(i,N){
                        if (a[i]>=N){
                                cl = 1;
                                long long int n = (a[i]-a[i]%N)/N;
                                rep(j,N){
                                        if (i!=j){
                                                a[j] += n;
                                        }
                                }
                                ans += n;
                                a[i] = a[i] % N;
                        }
                }
                if (cl == 0){
                        break;
                }
        }
        printf ("%lld\n",ans);
        return 0;
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> order(N), P(N), Q(N);
	for (int i = 0; i < N; i++) order[i] = i + 1;
	for (int i = 0; i < N; i++) cin >> P[i];
	for (int i = 0; i < N; i++) cin >> Q[i];

	int a = 1, b = 1;
	int num = 1;

	do {
		bool same_P = true;
		bool same_Q = true;
		for (int i = 0; i < N; i++) {
			if (order[i] != P[i]) same_P = false;
			if (order[i] != Q[i]) same_Q = false;
		}
		if (same_P) a = num;
		if (same_Q) b = num;
		num++;
	} while (next_permutation(order.begin(), order.end()));

	int ans = abs(a - b);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
mod = 998244353
pr = []
for i in range(2,n+1):
  if n%i == 0:
    pr.append((i,n//i))
num = []
pr = pr[::-1]
for p,q in pr:
  if p%2 == 0:
    continue
  ntmp = 0
  x = s[:q]
  y = ""
  for i in x:
    if i == "0":
      y += "1"
    else:
      y += "0"
  for i in range(q):
    if x[i] == "1":
      ntmp = (ntmp+pow(2,q-1-i,mod))%mod
  k = (x+y)*((p-1)//2)+x
  if s >= k:
    ntmp += 1
  num.append((p,2*q,ntmp))
ans = 2*n
for i in range(n-1,-1,-1):
  if s[i] == "1":
    ans = (ans+pow(2,n-1-i,mod)*2*n)%mod
for i in range(len(num)):
  p1,x,number = num[i]
  for p2,y,number2 in num:
    if x == y:
      continue
    elif p2%p1 == 0 and (p2//p1)%2 == 1:
      number -= number2
  num[i] = p1,x,number
for p1,x,number in num:
  ans = (ans-(2*n-x)*number)%mod
print(ans)

Measured memory_bytes: 3996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<ll> v(n),rui(n);
        rep(i,0,n){
            cin>>v[i];
            if(i==0)rui[0]=v[0];
            else rui[i]=rui[i-1]+v[i];
        }
    
    ll ans=-100000000000000000;
    rep(i,0,n-1){
        rep(j,i+1,n){
           ans=max(ans,rui[j]-rui[i]);
        }
    }
    rep(i,0,n){
        ans=max(ans,rui[i]);
    }
    cout<<ans<<endl;
    }
    
  
    return 0;
}



Measured memory_bytes: 3144
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Peaks
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');

        var number = int.Parse(input[0]);
        var roads = int.Parse(input[1]);

        var heights = Console.ReadLine().Split(' ');

        int[] numberList = new int[number];
        

        for(var i = 0; i < roads; i++)
        {
            var check = Console.ReadLine().Split(' ');
            int first = int.Parse(check[0]) -1;
            int second = int.Parse(check[1]) -1;
           
            if (int.Parse(heights[first])  > int.Parse(heights[second]))
              {
                numberList[second] = 1;
          
            }else if (int.Parse(heights[first]) < int.Parse(heights[second])){
                numberList[first] = 1;

                
            }else
            {
                numberList[first] = 1;
                numberList[second] = 1;
            }
        }

        int intCount = numberList.Count(value => value == 0);


        Console.WriteLine(intCount);



    }
}

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

int main(){
  long long w,h;cin>>w>>h;
  long long int x,y; cin >> x >> y;
  long double area = (long double)w * h / 2;
  int flag = 0;
  if (w == 2LL * x && h == 2LL * y)
  {
    flag = 1;
  }
  cout << fixed << setprecision(10) << area << ' ' << flag << endl;
  
}

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

const int N = 3010;

typedef long long LL;

struct edge {
    int to, next, w, c;
} e[N * 10];

int head[N], ecnt = 1;

inline void adde(int from, int to, int w, int c) {
    e[++ecnt] = (edge){to, head[from], w, -c}, head[from] = ecnt;
    e[++ecnt] = (edge){from, head[to], 0, c}, head[to] = ecnt;
}

int vis[N], cur[N]; LL dis[N];

inline bool SPFA(int s, int t) {
    memset(dis, 0x3f, sizeof(dis)), memset(vis, 0, sizeof(vis));
    queue<int> q; q.push(t), vis[t] = 1, dis[t] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop(), vis[u] = 0;
        for (int i = head[u]; i; i = e[i].next)
            if (e[i ^ 1].w && dis[e[i].to] > dis[u] - e[i].c) {
                dis[e[i].to] = dis[u] - e[i].c;
                if (!vis[e[i].to]) q.push(e[i].to), vis[e[i].to] = 1;
            }
    }
    return dis[s] < 1e17;
}

LL ans;

int DFS(int u, int t, int f) {
    if (u == t || !f) return f;
    int res = 0; vis[u] = 1;
    for (int &i = cur[u], tmp; i; i = e[i].next)
        if (!vis[e[i].to] && e[i].w && dis[u] - e[i].c == dis[e[i].to] && 
            (tmp = DFS(e[i].to, t, min(f, e[i].w)))) {
                res += tmp, f -= tmp, e[i].w -= tmp, e[i ^ 1].w += tmp, ans += (LL)tmp * e[i].c;
                if (!f) break;
            }
    return res;
}

inline LL dinic(int s, int t) {
    while (SPFA(s, t)) memcpy(cur, head, sizeof(head)), DFS(s, t, 1e9);
    return ans;
}

int main() {
    int n, s, t; scanf("%d", &n), s = n * 2 + 5, t = s + 1;
    for (int i = 1; i <= n; i++) {
        int x, y, c; scanf("%d%d%d", &x, &y, &c);
        adde(s, i, c, 0);
        adde(i, 2 * n + 1, 1e9, -x - y), adde(i, 2 * n + 2, 1e9, x + y);
        adde(i, 2 * n + 3, 1e9, y - x), adde(i, 2 * n + 4, 1e9, x - y);
    }
    for (int i = 1; i <= n; i++) {
        int x, y, c; scanf("%d%d%d", &x, &y, &c);
        adde(i + n, t, c, 0);
        adde(2 * n + 1, i + n, 1e9, x + y), adde(2 * n + 2, i + n, 1e9, -x - y);
        adde(2 * n + 3, i + n, 1e9, x - y), adde(2 * n + 4, i + n, 1e9, y - x);
    }
    printf("%lld\n", -dinic(s, t));
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  if(n[1]==n[2]){
    if (n[0]==n[1]||n[3]==n[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
   else cout << "No" << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, x, prime, rewrite=30;
  cin >> N;
  int i=0;
  while(i<N)
  {
    prime=0;
    cin >> x;
    while(x%2==0)
    {
       x/=2;
       prime++;
    }

    if(rewrite>prime)
      rewrite=prime;
    i++;
  }
  cout << rewrite << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5e5+5;
const int mod=998244353;
int n,m,inv[N],jc[N],jcn[N],pn[N],pm[N],ans;
int C(int n,int m){return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;}
int main(){
	scanf("%d%d",&n,&m);
	if(n<m)swap(n,m);
	inv[1]=jc[0]=jcn[0]=1;
	for(int i=2;i<=n;++i)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=1;i<=n;++i){
		jc[i]=1ll*jc[i-1]*i%mod;
		jcn[i]=1ll*jcn[i-1]*inv[i]%mod;
	}
	for(int i=pn[0]=1;i<=m;++i)pn[i]=1ll*pn[i-1]*(n+1)%mod;
	for(int i=pm[0]=1;i<=n;++i)pm[i]=1ll*pm[i-1]*(m+1)%mod;
	for(int i=0;i<=m;++i){
		int res=1ll*C(n,i)*C(m,i)%mod*jc[i]%mod*pn[m-i]%mod*pm[n-i]%mod;
		i&1?ans=(ans-res+mod)%mod:ans=(ans+res)%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 9984
while(<>){
	chomp;
	if($. == 1){
		($n, $m) = split(/ /, $_);
	}else{
		if($. <= $n + 1){
			push(@a, $_);
		}else{
			push(@b, $_);
		}
	}
}

$r = "No";
for ($i = 0; $i < $n; $i++){
	last if($n - $i + 1 < $m) or ($r eq "Yes");
	$start = 0;
	$pos = index($a[$i],$b[0], $start);
	unless($pos == -1){
		if($m == 1){
			$r = "Yes";
		}else{
			while(1){
				last if($r eq "Yes") or ($pos == -1);
				for ($p = 1; $p < $m; $p++){
					last unless(index($a[$i + $p],$b[$p],$start) == $pos);
					$r = "Yes" if($p == $m - 1);
				}
				$start = $pos + 1;
				$pos = index($a[$i],$b[0],$pos+1);
			}
		}
	}
}
print "$r\n";


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	ll dig[4];
	dig[0] = N/1000;
	N %= 1000;
	dig[1] = N/100;
	N %= 100;
	dig[2] = N/10;
	N %= 10;
	dig[3] = N/1000;
	if(dig[0]==dig[1]&&dig[1]==dig[2]){
		cout << "Yes" << endl;
		return 0;
	}
	if(dig[1]==dig[2]&&dig[2]==dig[3]){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
typedef long long ll;
using namespace std;

int main(){
	int N,C,K;
	cin>>N>>C>>K;
	vector<int> vt;
	int t;
	REP(i,0,N){
		cin>>t;
		vt.push_back(t);
	}
	sort(vt.begin(),vt.end());
	ll ans=0,limit;
	REP(i,0,N) {
		limit=vt[i]+K;
		int cnt=1;
		while(cnt<C){
			i++;
			if(i==N) break;
			if(vt[i]<=limit) cnt++;
			if(vt[i]>limit) {
				i--;
				break;
			}
		}
		ans++;
	}
	p(ans);
	return 0;
}


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

sorted=sorted(a,reverse=True)
#print(len(sorted[2:])//2)
ans=sorted[0]

for i in range(len(sorted[2:])//2):
  ans+=sorted[1+i]*2
  #print(ans)
  

if len(a)%2==1:
  ans+=sorted[1 + len(sorted[2:])//2]
  #print(111)
print(ans)

Measured memory_bytes: 31396
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long (int)1e18+1
#define MAX 200001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;
	
int main() {
	int n, k;
	cin >> n >> k;

	vector<pair<int, int>>d(k);
	vector<long long>blocksum(k);
	vector<long long>dp(n + 2, 0);
	rep(i, 0, k) {
		int x, y;
		cin >> x >> y;
		d[i].first = x;
		d[i].second = y;
		blocksum[i] = 0;
		rep(j, x, y + 1)dp[j+1]++;
	}
	rep(i, 1, n + 1) {
		rep(j, 0, k) {
			if (i - d[j].first >= 0)blocksum[j] += dp[i - d[j].first];
			if (i - d[j].second > 0)blocksum[j] -= dp[i - d[j].second - 1];
			dp[i] += blocksum[j];
			dp[i] %= 998244353;
		}
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 4796
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for ( i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for ( i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for ( k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        }else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right) {
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r) {
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for ( j = p; j < r; j++) {
        if (A[j].value <= x.value) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if (p<r) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q+1, r);
    }
}

int main(int argc, char const* argv[])
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);
    for ( i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);

    for ( i = 0; i < n; i++) {
        if(A[i].suit != B[i].suit) stable = 0;
    }

    if(stable == 1) printf("Stable\n");
    else printf("Not stable\n");

    for ( i = 0; i < n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}

Measured memory_bytes: 5072
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>

typedef long long ll;

int main()
{

    ll N;
    std::cin >> N;

    std::vector<ll> A;
    std::vector<ll> B;
    std::vector<ll> C;
    A.resize(N);
    B.resize(N);
    C.resize(N);

    for(ll i=0; i<3; ++i)
    {
        for(ll j=0; j<N; ++j)
        {
            if(i==0)
                std::cin >> A[j];
            else if(i==1)
                std::cin >> B[j];
            else if(i==2)
                std::cin >> C[j];
        }
    }

    std::sort(A.begin(), A.end());
    std::sort(C.begin(), C.end());

    //Bを固定してa, cに対して何種類あるか考える
    ll ans = 0;
    for(ll b :B)
    {
        // Aのなかでb以下のもの
        ll anum = std::lower_bound(A.begin(), A.end(), b) - A.begin();
        // Cのなかでb以上のもの
        ll cnum = C.end() - std::upper_bound(C.begin(), C.end(), b);
        ans += (anum*cnum);
    }

    std::cout << ans << std::endl;

    return 0;
}



/**
int main() {

    ll N, K;
    std::cin >> N >> K;

    std::vector<ll> a(N, 0);
    std::vector<ll> b(N, 0);

    for(int i=0; i<N; ++i)
        std::cin >> a[i];
    for(int i=0; i<N; ++i)
        std::cin >> b[i];

    return 0;
}
 **/


Measured memory_bytes: 2688
k=int(input())
num=1
L=0
ans=-1


if k%7==0:
	L=(9*k)/7
else:
	L=9*k

# if L%2==0 or L%5==0:
# 	ans=-1

for i in range(k+1):
	if (num*10)%L==1:
		ans=i+1
		break
	num=num*10 %L
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N;cin>>N;
    int T[N],A[N],tlH[N],thH[N],alH[N],ahH[N];
  	REP(i,N)tlH[i]=thH[i]=alH[i]=ahH[i]=0;
    REP(i,N)cin>>T[i];
    REP(i,N)cin>>A[i];
    REP(i,N){
        if(i==0)tlH[i]=thH[i]=T[i];
        else{
            if(T[i]==T[i-1]){
                tlH[i]=1;thH[i]=T[i];
            }
            else tlH[i]=thH[i]=T[i];
        }
    }
    REP(i,N){
        if(i==0)alH[N-1-i]=ahH[N-1-i]=A[N-1-i];
        else{
            if(A[N-1-i]==A[N-i]){
                alH[N-1-i]=1;ahH[N-1-i]=A[N-1-i];
            }
            else alH[N-1-i]=ahH[N-1-i]=A[N-1-i];
        }
    }
    int ans=1;
    REP(i,N){
        int d=min(ahH[i],thH[i])-max(alH[i],tlH[i])+1;
        if(d<=0){
            ans=0;
        }
        ans*=d;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    ll N; cin >> N;
    string ans = "";

    while(N) {
        N--;
        ans += 'a' + N % 26;
        N /= 26;
    }
    reverse(ans.begin(), ans.end());

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


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;

	int sum = 0;
	for (auto c: s) {
		sum += c - '0';
	}
	bool ok = sum % 9 == 0;
	cout << (ok ? "Yes": "No") << endl;
	return 0;
}


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

using namespace std;

int gcd(int a,int b){
return b!=0 ? gcd(b,a%b) : a;
}
int a,b;

int main()
{
    while (~scanf("%d%d",&a,&b)) {
        printf("%d %d\n",gcd(a,b),(long long)a*b/gcd(a,b));
    }
    return 0;
}



Measured memory_bytes: 3096
a,s= [0]*100003, [0]*100003
while True:
	n,k=map(int, input().split())
	if n==0:break
	s[0]=a[0]=int(input())
	for i in range(1,n):
		a[i]=int(input())
		s[i]=s[i-1]+a[i]
		if i>=k:s[i]-=a[i-k]
	ans=s[k-1]
	for i in range(k,n):
		if s[i]>ans:ans=s[i]
	print(ans)


Measured memory_bytes: 13320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b, c, d;
  cin >> a;
  cin >> b;
  cin >> c;
 
  
  if(a * b > c) {
    cout << c << endl;
  }
  else {
    cout << a * b << endl;
  }
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	while(1){
		int n; cin >>n;
		if(n==0) break;
		int cnt=0;
		int sum=0;
		int right=1;
		for(int left=1;left<n;left++){
			while(sum<n){
				sum+=right;
				right++;
			}
			if(sum==n){
				cnt++;
			}
			if(sum>=n){
				sum-=left;
			}
		}
		cout << cnt << endl;
	}
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
    char alpha; cin >> alpha;

    if('A' <= alpha && alpha <= 'Z'){
        cout << 'A' << endl;
    }
    else{
        cout << 'a' << endl;
    }
}

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

#define ll long long
#define MAX 310

char a[MAX][MAX],tmp[MAX][MAX];
int n;

int main(){
	cin>>n;
	ll ans = 0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++)
			for(int j=0;j<n;j++)
				tmp[k][j] = a[(k+i)%n][j];
		
		int flag = 1;
		for(int k=0;k<n;k++){
			for(int j=0;j<n;j++){
				if(tmp[k][j]!=tmp[j][k]){
					flag = 0;
					break;
				}
			}
			if(!flag)break;
		}
		ans += flag * n;
		
	}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        int x,y;
        x=a,y=b;
        b=x,a=y;
        x=a,y=b;

    }
        if(a>c){
            int q,r;
            q=a,r=c;
            c=q,a=r;
            q=a,r=c;

        }
            if(b>c){
                int n,m;
                n=b,m=c;
                b=m,c=n;
                n=c,m=b;
            }
                printf("%d %d %d\n",a,b,c);

        return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> v(100001);
    rep(i,n){
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    ll ans = 0;
    priority_queue<ll> pq;
    for(int i = 1; i <= m; ++i){
        for(auto e : v[i]) pq.push(e);
        if(pq.empty()) continue;
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


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

int N, M, Q;
int a[55], b[55], c[55], d[55];

int solve(vector<int> A){
  if(A.size() < N) {
    int maxv = 0;
    for(int i = A.back(); i < M + 1; i++) {
      vector<int> nA;
      copy(A.begin(), A.end(), back_inserter(nA));
      nA.push_back(i);
      maxv = max(maxv, solve(nA));
    }
    return maxv;
  } else {
    int score = 0;
    rep(i, Q) {
      if (A[b[i]-1] - A[a[i]-1] == c[i]) score += d[i];
    }
    return score;
  }
}

int main() {
  cin >> N >> M >> Q;
  rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

  vector<int> A;
  A.push_back(1);
  cout << solve(A) << endl;
  return 0;
}

Measured memory_bytes: 3584
N,A,B,C,D=map(int,input().split())
S=input()
check=1
def check_double(S,L,R):
    count=1
    for i in range(L-1,R-1):
        if S[i]=="#" and S[i+1]=="#":
            count=0
    return count
def check_triple(S,L,R):
    count=0
    for i in range(L-1,R):
        if S[i-1]=="." and S[i]=="." and S[i+1]==".":
            count=1
    return count
if C>D:
    check=check*check_double(S,A,B)*check_triple(S,B,D)*check_double(S,D,C)
else:
    check=check*check_double(S,A,B)*check_double(S,B,D)
if check==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

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

    int dp[50];

    rep(i, n+1){
        if(i == 0 || i == 1)dp[i] = 1;
        else dp[i] = dp[i-1] + dp[i-2];
    }

    cout << dp[n] << endl;
}


Measured memory_bytes: 3132
import math
N = int(input())

a = [13, 23, 43, 53, 73, 83, 103, 113, 163, 173, 193, 223, 233, 263, 283, 293, 313, 353, 373, 383, 433, 443, 463, 503, 523, 563, 593, 613, 643, 653, 673, 683, 733, 743, 773, 823, 853, 863, 883, 953, 983, 1013, 1033, 1063, 1093, 1103, 1123, 1153, 1163, 1193, 1213, 1223, 1283, 1303, 1373, 1423, 1433, 1453, 1483, 1493, 1523, 1543, 1553, 1583, 1613, 1663, 1693, 1723, 1733, 1753, 1783, 1823, 1873, 1913, 1933, 1973, 1993, 2003, 2053, 2063, 2083, 2113, 2143, 2153, 2203, 2213, 2243, 2273, 2293, 2333, 2383, 2393, 2423, 2473, 2503, 2543, 2593, 2633, 2663, 2683, 2693, 2713, 2753, 2803, 2833, 2843, 2903, 2953, 2963, 3023, 3083, 3163, 3203, 3253, 3313, 3323, 3343, 3373, 3413, 3433, 3463, 3533, 3583, 3593, 3613, 3623, 3643, 3673, 3733, 3793, 3803, 3823, 3833, 3853, 3863, 3923, 3943, 4003, 4013, 4073, 4093, 4133, 4153, 4243, 4253, 4273, 4283, 4363, 4373, 4423, 4463, 4483, 4493, 4513, 4523, 4583, 4603, 4643, 4663, 4673, 4703, 4723, 4733, 4783, 4793, 4813, 4903, 4933, 4943, 4973, 4993, 5003, 5023, 5113, 5153, 5233, 5273, 5303]

st = ""
for i in range(N-1):
    st += str(a[i]) + " "
st += str(a[N-1])
print(st)


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

void solve() {
    int N;
    cin >> N;
    vector<ll> v(3*N);
    for(int i=0;i<3*N;i++) cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());
    ll sum=0;
    for(int i=0,j=1;i<N;i++,j+=2) sum+=v[j];
    cout << sum << "\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 2560
import sys

H, W = map(int, sys.stdin.readline().strip().split())
grid = []
for _ in range(H):
    grid.append(sys.stdin.readline().strip())

# (x, y)のx, y方向のscore [a, b]
scores_y = [[0 for _ in range(W)] for _ in range(H)]
scores_x = [[0 for _ in range(W)] for _ in range(H)]
for y in range(H):
    start = 0
    count = 0
    for x in range(W):
        if grid[y][x] == "#" or x == W-1:
            if x == W-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, x+1):
                scores_x[y][i] = count
            count = 0
            start = x + 1
        else:
            count += 1

for x in range(W):
    start = 0
    count = 0
    for y in range(H):
        if grid[y][x] == "#" or y == H-1:
            if y == H-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, y+1):
                scores_y[i][x] = count
            count = 0
            start = y + 1
        else:
            count += 1

# print(scores)
ans = 0
for y in range(H):
    for x in range(W):
        ans = max(ans, scores_x[y][x] + scores_y[y][x] - 1)
print(ans)

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


int main(){
  string a;
  cin >>a;
  if(a.at(3)==a.at(2)&&a.at(2)==a.at(1)){
    cout << "Yes" << endl;
  }
  else if(a.at(0)==a.at(1)&&a.at(1)==a.at(2)){
    cout <<"Yes"<< endl;
  }
  else{
    cout <<"No"<<endl;
  }
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int x;
	cin >> x;
	if(x < 1200) cout << "ABC" << endl;
	else cout << "ARC" << endl;
	return 0;
}

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

int main(){
     char a;
	cin>>a;
	if(a=='T')
     cout<<'A'<<endl;
	else if(a=='A')
	cout<<'T'<<endl;
	else if(a=='G')
	cout<<'C'<<endl;
	else if(a=='C')
	cout<<'G'<<endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
l=[]

for i in range(n,0,-1):
    s=0
    c=n//i
    if c == 1:
        b[i-1]=a[i-1]
    else:
        for j in range(1,c+1):
            s += b[i*j-1]
        if (s+a[i-1]) % 2 == 1:
            b[i-1]=1
for k in range(0,n):
    if b[k]==1:
        l.append(k+1)

print(len(l))
for m in l:
    print(m)

Measured memory_bytes: 12084
#include <bits/stdc++.h>
using namespace std;
char s[100];
int main(){
    int n, ans = 0, t1 = 0, t2 = 0, t3 = 0;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%s", s);
        int m = strlen(s);
        for(int j=1;j<m;j++){
            if(s[j-1] == 'A' && s[j] == 'B') ans++;
        }
        if(s[0] == 'B' && s[m-1] == 'A') t3++;
        else if(s[0] == 'B') t1++;
        else if(s[m-1] == 'A') t2++;
    }
    if(t3 > 0) ans += t3-1;
    if(t3 > 0 && t1 > 0) ans++, t1--;
    if(t3 > 0 && t2 > 0) ans++, t2--;
    ans += min(t1, t2);
    printf("%d\n", ans);
}

Measured memory_bytes: 256
s = raw_input()
flag1, flag2 = False, False
for ch in s:
    if not flag1:
        if ch == 'C':
            flag1 = True
    else:
        if ch == 'F':
            flag2 = True
            break
if flag1 and flag2:
    print 'Yes'
else:
    print 'No'

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	ll m, a, r, c, h;
	m = a = r = c = h = 0;
	for(int i = 0; i < n; i++){
		string s; cin>>s;
		if(s[0] == 'M')m++;
		if(s[0] == 'A')a++;
		if(s[0] == 'R')r++;
		if(s[0] == 'C')c++;
		if(s[0] == 'H')h++;
	}
	ll ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
K = int(input())
nums = list(range(1, 10))
vals = [1] * 9
d = 1
n = 1
m = 9
while len(nums) < 2 * K:
    m += 10**d
    v = m / sum(map(int, str(m)))
    if v < vals[-1]:
        while v < vals[-1]:
            nums.pop()
            vals.pop()
        m = nums[-1]
        d += 1
    else:
        nums.append(m)
        vals.append(v)
print(*nums[:K], sep='\n')

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

const int mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<P> ran(k);
  rep(i, k) cin >> ran[i].first >> ran[i].second;

  vector<ll> dp(n + 1);
  vector<ll> s(n + 2);
  ll cur = 0;
  dp[0] = 1;
  rep(i, n) {
    rep(j, k) {
      int li = i + ran[j].first;
      int ri = i + ran[j].second;
      if (li > n) continue;
      (s[li] += dp[i]) %= mod;
      if (ri < n) (s[ri + 1] -= dp[i] + mod) %= mod;
    }
    (cur += s[i + 1] + mod) %= mod;
    dp[i + 1] = (dp[i + 1] + cur) % mod;
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 6404