akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
typedef std::vector<pl> vpl;
const long double EPS = 1e-9;

#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c) 
#define rsort(a,n) sort(a,a+n,greater<>())

const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 200;

int main(void){
    ll x,y,z;

    in1(x);
    ll answer = 1;

    while (answer * answer <= x){
        if ((answer + 1) * (answer + 1) > x) prl(answer * answer);
        answer ++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c,l=0,r=0;
    
    while(scanf(("%d,%d,%d"),&a,&b,&c) != EOF){
        if(a*a+b*b==c*c)l++;
        if(a==b)r++;
    }
    printf("%d\n%d\n",l,r);
    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int x[2020];
int main(void){
  int n,ans=0;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",s);
  for(int i=1;i<n;i++){
    if(s[i]!=s[i-1]){
      ans++;
      i++;
    }
  }
  PRN(ans);
  return 0;
}



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

using namespace std;

int main(void){
    string S;
    cin >> S;
    if(S[2]== S[3] && S[4] == S[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(){
  long long a,b;
  int k,i;
  scanf("%lld%lld%d",&a,&b,&k);
  if((b-a)>=2*k){
    for(i=a;i<a+k;i++){
      printf("%d\n",i);
    }
    for(i=b-k+1;i<=b;i++){
      printf("%d\n",i);
    }
  }else{
    for(i=a;i<=b;i++){
      printf("%d\n",i);
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
const long long mod=1e9+7;
long long dfs(int k,int pa ,int now)
{

    int c=1;
    long long res=1;;
    if(pa==-1)
        c=k-1;
    else
        c=k-2;
    if(G[now].size()>k)
        return 0;
    for(auto u:G[now])
    {
        if(u==pa) continue;
        res*=c;
        --c;
        res%=mod;
    }
    for(auto u:G[now])
    {
        if(u==pa)
            continue ;
        res*=dfs(k,now,u);
        res%=mod;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,k;
    cin>>n>>k;
    G.resize(n);
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;--v,--u;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    cout<<k*dfs(k,-1,0)%mod;
    return 0;
}


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

int main(){long A, B, C, D;
cin >> A >> B >> C >> D;
long zero = 0;
long ans = max(zero, min(B, D) - max(A, C));


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

Measured memory_bytes: 256
a, b = map(int, input().split()) 

min = b - (a - 1)
max = b + (a - 1)

if min < -1000000:
  min = -1000000

if max > 1000000:
  max = 1000000

for i in range(2 * a -1):
  print(min, end=" ")
  min += 1

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

    if (N <= A){
        cout << "Yes" << endl;
        return 0;
    }

    for (int i = 0; i <= A; i++){
        if (N % 500 == 0){
            cout << "Yes" << endl;
            return 0;
        }else{
            N -= 1;
        }
    }
    cout << "No" << endl;

}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int r,d,x,temp;
    cin >> r >> d >> x;
    temp = x;
    for(int i=0;i<10;i++)
    {
        temp = r*temp - d;
        cout << temp<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
class Array
  def bubble_sort
    data = self
    n = data.size
    cnt = 0
    0.upto(n - 2) do |i|
      (n - 1).downto(i + 1) do |j|
        if data[j] < data[j - 1]
          tmp = data[j - 1]
          data[j - 1] = data[j]
          data[j] = tmp
          cnt += 1
        end
      end
    end
    return [data,  cnt]
  end
end

n = gets.to_i
nums = gets.chomp.split(" ").map(&:to_i)
sorted_nums, cnt = nums.bubble_sort
puts "#{sorted_nums.join(" ")}\n#{cnt}"

Measured memory_bytes: 8716
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
using namespace std;
int n;

class point{
public:
  double x, y;
};

void func(point p1, point p2, int id){
  if(id == n) return;
  point s, t, u;
  s.x = (2 * p1.x + p2.x) / 3;
  s.y = (2 * p1.y + p2.y) / 3;
  t.x = (p1.x + 2 * p2.x) / 3;
  t.y = (p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * cos(M_PI / 3.0) - (t.y - s.y) * sin(M_PI / 3.0) + s.x;
  u.y = (t.x - s.x) * sin(M_PI / 3.0) + (t.y - s.y) * cos(M_PI / 3.0) + s.y;
  func(p1, s, id + 1);
  cout << s.x << " " << s.y << endl;
  func(s, u, id + 1);
  cout << u.x << " " << u.y << endl;
  func(u, t, id + 1);
  cout << t.x << " " << t.y << endl;
  func(t, p2, id + 1);
  return;
}

void solve(){
  cin >> n;
  point p1, p2;
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  cout << p1.x << " " << p1.y << endl;
  func(p1, p2, 0);
  cout << p2.x << " " << p2.y << endl;
  return;
}

int main(){
  solve();
  return 0;
}



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



bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int fib(int n)
{
    if (n <= 1)
        return n;
    return fib(n-1) + fib(n-2);
}





int main()

{

double n;
 double count=0.00;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
     if(i%2!=0)
     {
         count++;
     }

 }
 printf("%0.9lf\n",(count/n));


}



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

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

  map<int, int> WACount;
  set<int> AC;
  
  int WASum = 0;
  for( int i = 0; i < M; i++){
    int P;
    string S;    
    cin >> P >> S;
    bool found = AC.count(P);
    if (!found) {
      if (S == "AC"){
        AC.insert(P);
        WASum += WACount[P];
      } else {
        WACount[P] += 1;
      }
    }
  }  
  cout << AC.size() << " " << WASum << endl;  
}

Measured memory_bytes: 9600
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()
k = ii()

#dp[keta][not0nokosuu]
n = len(s)
dp = [[0]*(n) for _ in range(4)]
dp[0][0] = 1
for i in range(1,n):
    #のこり0のやつ
    dp[0][i] = dp[0][i-1] 
    #のこり1のやつ
    dp[1][i] = dp[0][i-1] * 9 + dp[1][i-1]
    #のこり2のやつ
    dp[2][i] = dp[1][i-1]*9 + dp[2][i-1]
    dp[3][i] = dp[2][i-1]*9 + dp[3][i-1]

ans = 0
for i in range(n):
    ima = int(s[i])
    if i ==-1 :
        ans += (ima -1) * dp[k-1][n-1-i]
        k -= 1
    else:
        if ima != 0:
            ans += (ima -1) * dp[k-1][n-1-i] + dp[k][n-1-i]
            k -= 1
    if k == 0:
        ans += 1
        break
print(ans)



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

int main(){
 int n,t;
    string s;
    cin >> n;
   t=n%10;
  if(t==2||t==4||t==5||t==7||t==9){cout<<"hon"<<endl;}
  if(t==0||t==1||t==6||t==8){cout<<"pon"<<endl;}
if(t==3){cout<<"bon"<<endl;}
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    vector<int> dp(N+5, INF32);
    dp[0] = 0;

    for(int i = 1; i < N; i++){
        for(int k= 1; k <= K; k++){
            if(i-k>=0) dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]));
        }
    }

    cout << dp[N-1] << endl;
 }

Measured memory_bytes: 3976
N=int(input())

g=[[-1 for n in range(N)] for m in range(N)]

for n in range(N):
    A=int(input())
    for m in range(A):
        x,y=map(int,input().strip().split())
        g[x-1][n]=y

def c(n,N,base):
    S=[0 for i in range(N)]
    for i in range(N):
        S[i]=n%base
        n=n//base
    return S


def honest_judge(S,g):
    honest=True
    for n in range(len(S)):
        if S[n]==1:
            for i in range(N):
                if g[i][n]!=-1 and g[i][n]!=S[i]:
                    honest=False
        if honest==False:
            break
    return honest

MAX=0
for n in range(2**N):
    S=c(n,N,2)
    if honest_judge(S,g)==True:
        if sum(S)>=MAX:
            MAX=sum(S)

print(MAX)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919

typedef tuple<long long, long long, long long> Hash;
const long long B = 54321;
const long long MOD1 = 1000000007;
const long long MOD2 = 1000000009;
const long long MOD3 = 1132193131;

string S, T;
map<Hash, int> mp;
long long powB1[300001], powB2[300001], powB3[300001];

int norm(char c) {
  if ('a' <= c && c <= 'z') return c-'a';
  else return 26+c-'A';
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S >> T;
  rep(i, S.length()) S[i] = norm(S[i]);
  rep(i, T.length()) T[i] = norm(T[i]);

  powB1[0] = 1;
  powB2[0] = 1;
  powB3[0] = 1;
  for (int i=1; i<=300000; i++) powB1[i] = (1LL * powB1[i-1] * B) % MOD1;
  for (int i=1; i<=300000; i++) powB2[i] = (1LL * powB2[i-1] * B) % MOD2;
  for (int i=1; i<=300000; i++) powB3[i] = (1LL * powB3[i-1] * B) % MOD3;

  long long h1 = 0, h2 = 0, h3 = 0;
  for (int i=0; i<T.length(); i++) {
    h1 = (B*h1 + S[i]) % MOD1;
    h2 = (B*h2 + S[i]) % MOD2;
    h3 = (B*h3 + S[i]) % MOD3;
  }
  mp[Hash(h1, h2, h3)]++;
  for (int i=T.length(); i<S.length(); i++) {
    h1 = (B*h1 + S[i]) % MOD1;
    h2 = (B*h2 + S[i]) % MOD2;
    h3 = (B*h3 + S[i]) % MOD3;
    //del i-|T|
    h1 -= (powB1[T.length()]*S[i-T.length()]) % MOD1;
    h2 -= (powB2[T.length()]*S[i-T.length()]) % MOD2;
    h3 -= (powB3[T.length()]*S[i-T.length()]) % MOD3;
    h1 %= MOD1; h1 += MOD1; h1 %= MOD1;
    h2 %= MOD2; h2 += MOD2; h2 %= MOD2;
    h3 %= MOD3; h3 += MOD3; h3 %= MOD3;
    mp[Hash(h1, h2, h3)]++;
  }

  long long base1 = 0, base2 = 0, base3 = 0;
  rep(i, T.length()) {
    base1 = (base1*B + T[i]) % MOD1;
    base2 = (base2*B + T[i]) % MOD2;
    base3 = (base3*B + T[i]) % MOD3;
  }

  long long ctr = 0;
  for (int i=0; i<T.length(); i++) {
    rep(c, 52) {
      if (T[i] == c) continue;
      int p = (int)T.length()-1-i;
      long long diff = c-T[i];
      long long h1 = (base1 + powB1[p] * diff) % MOD1;
      long long h2 = (base2 + powB2[p] * diff) % MOD2;
      long long h3 = (base3 + powB3[p] * diff) % MOD3;
      h1 %= MOD1; h1 += MOD1; h1 %= MOD1;
      h2 %= MOD2; h2 += MOD2; h2 %= MOD2;
      h3 %= MOD3; h3 += MOD3; h3 %= MOD3;
      Hash h = Hash(h1, h2, h3);
      if (mp.find(h) != mp.end()) ctr += mp[h];
    }
  }
  cout << ctr << "\n";
  return 0;
}

Measured memory_bytes: 32608
N, K = map(int, input().split())
*A, = map(int, input().split())
dp = [[0]*N for _ in range(60)]

for i in range(N):
    dp[0][i] = A[i] - 1

for k in range(1, 60):
    for n in range(N):
        dp[k][n] = dp[k - 1][dp[k - 1][n]]

res = []
for i in range(60):
    if (K>>i)&1:
        res.append(i)
    
pos = 0
for i in res:
    pos = dp[i][pos]
print(pos + 1)

Measured memory_bytes: 191520
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
typedef long long ll;
//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
/*
vector<int> d(100000);
vector<int> b(100000);
class UnionFind{
	public:
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	signed find(signed x){
		if(d[x]==x){
			return x;
		}else{
			return d[x]=find(d[x]);
		}
	}
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(b[x]<b[y]){
			d[x]=y;
		}else{
			d[y]=x;
			if(b[x]==b[y])b[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
};
*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(min(a+b,c+a),b+c)<<"\n";
	return 0;
}

Measured memory_bytes: 256
// author - shreyanshjn (Shreyansh Jain)
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
/* #define input 1 */
#define INF 100000000000000000
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define rep(a,b,c) for(int a=b; a<c; a++)
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
const int mod = 1e9 + 7;
int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
string trim(const string& str) {
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() { 
    #ifdef input
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(15);
    int n, k; cin >> n >> k;
    int h[n]; 
    fori(0, n) cin >> h[i];
    int cost[n];
    cost[0] = 0;
    fori(1, n) {
        cost[i] = INT_MAX;
        for(int p = i - 1; p >= max(0, i - k); p--) {
            cost[i] = min(cost[i], cost[p] + abs(h[i] - h[p]));
        }
    }
    cout << cost[n - 1] << endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}

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

int main(){
 int a,b,c;
cin>>a>>b>>c;
    if(a==b){
      if(a==c){
      cout<<1<<endl;
    }
      else{
        cout<<2<<endl;
      }
    }
  else if(a==c||b==c){
  cout<<2<<endl;
  }
  else{
    cout<<3<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <deque>
#include <climits>
#define scanf scanf_s
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 500010;

ll min2(ll v1, ll v2) { if (v1 == -1)return v2; if (v2 == -1)return v1; return min(v1, v2); }
ll pw(ll v1, ll v2, ll mod = 1000000007) {
	ll v3 = 1;
	for (; v2 != 0; v1 = (v1 * v1) % mod, v2 = (v2 >> 1))
		if (v2 & 1)v3 = (v3 * v1) % mod;
	return v3;
}

ll ans, n,ct[3];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		for (int j = 0; j < s.size(); j++) {
			if (j != 0 && s[j - 1] == 'A' && s[j] == 'B')ans++;
		}
		if (s[0] == 'B' && s[s.size() - 1] == 'A')ct[0]++;
		else if (s[0] == 'B')ct[1]++;
		else if (s[s.size() - 1] == 'A')ct[2]++;
	}
	ans += max((ll)0, ct[0] - 1);
	if (ct[1] > 0 && ct[0] > 0) { ans++; ct[1]--; }
	if (ct[2] > 0 && ct[0] > 0) { ans++; ct[2]--; }
	ans += min(ct[1], ct[2]);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
int dp[11][2001],n,K,a1,a2,ans;
vector<int>v[11];
main(){
  cin>>n>>K;
  r(i,n){
    cin>>a1>>a2;
    v[a2-1].push_back(a1);
  }
  r(i,10){
    sort(v[i].begin(),v[i].end(),greater<int>());
    r(j,v[i].size())if(j)v[i][j]+=v[i][j-1]+j*2;
  }
  r(i,10)r(j,K+1){
    for(int k=0;k<v[i].size();k++){
      dp[i+1][k+j+1]=max(dp[i+1][k+j+1],dp[i][j]+v[i][k]);
    }
    dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
  }
  r(i,11)r(j,K+1)ans=max(ans,dp[i][j]);
  cout<<ans<<endl;
}

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

int main(){
  int n, m; cin >> n >> m;
  int per[n];
  for(int i = 0; i < n; i++){
    per[i] = i + 1;
  }
  int edge[m][2];
  for(int i = 0; i < m; i++){
    for(int j = 0; j < 2; j++){
      cin >> edge[i][j];
    }
  }
  int ans = 0; 
  do{
    if(per[0] != 1) break; //スタートが１
    bool ok;
    for(int i = 0; i < n - 1; i++){ //perのindex
      ok = false;
      for(int j = 0; j < m; j++){
        if(edge[j][0] == per[i] && edge[j][1] == per[i+1]){
          ok = true;
          break;
        }
        else if(edge[j][1] == per[i] && edge[j][0] == per[i+1]){
          ok = true;
          break;
        }
      }
      if(!ok) break; //あるiで違うなら順列組み替え
    }
    if(ok) ans++;//最後までok = trueならカウント
  }while(next_permutation(per, per + n));
  cout << ans << endl;
}
      

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

int main(){
  int N;
  cin >> N;
  
  vector<int> V(N);
  vector<int> C(N);
  
  for (int i = 0; i < N; i++){
    cin >> V[i];
  }
  for (int i = 0; i < N; i++){
    cin >> C[i];
  }
  
  int revenue = 0;
  for (int i = 0; i < N; i++){
    if (V[i] - C[i] > 0){
      revenue += V[i] - C[i];
    }
  }
  
  cout << revenue;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d %d", $n, $t);
  $ans = 99999999;

  for ($i=0; $i<$n; $i++) {
    fscanf(STDIN, "%d %d", $c, $ttmp);
    if ($t >= $ttmp) {
      $ans = min($ans, $c);
    }
  }
  
  if ($ans < 99999999) {
	echo $ans . "\n";
  } else {
    echo "TLE" . "\n";
  }
?>

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

int main() {
  long long n; cin >>n;
  vector<long long>a(n);
  for(long long i=0;i<n;i++)cin>>a[i];
  map<long long,long long>mp;
  for(long long i=0;i<n;i++){
    if(mp.count(a[i]))mp.at(a[i])++;
    else mp[a[i]]=1;
  }
  long long kotae=0;
  long long sum=0;
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    long long kazu=iter->second;
    sum+=kazu*(kazu-1)/2;
  }
  for(long long i=0;i<n;i++){
    kotae=sum;
    long long kazu=mp[a[i]];
    kotae-=kazu*(kazu-1)/2;
    kazu--;
    kotae+=kazu*(kazu-1)/2;
    cout<<kotae<<endl;
  }
  return 0;
}


Measured memory_bytes: 12768
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int n, x;
    cin>>n>>x;
    int a[n];
    rep(i, n){
        cin>>a[i];
    }
    int d=0;
    int ans=1;
    rep(i, n){
        d+=a[i];
        if(d>x){
            break;
        }
        ans++;
    }
    cout<<ans<<endl;
}

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

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

const double EPS = 1e-10;

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

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(m/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline long long fac(int n){return _fac[n];}
    inline long long inv(int n){return _inv[n];}
    inline long long finv(int n){return _finv[n];}

    long long comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }

    long long perm(int n,int k){
      if(n < k) return 0;
      if(n < 0 || k < 0) return 0;
      return _fac[n]*_finv[n-k]%m;
    }
};


int main(){
  Combination C(1000000);
  int n,m; cin >> n >> m;
  ll ans = C.perm(m,n)*C.perm(m,n)%MOD;
  repr(i,1,n+1){
    ll now = C.comb(n,i)*C.perm(m,i)%MOD*C.perm(m-i,n-i)%MOD*C.perm(m-i,n-i)%MOD;
    if(i%2 == 1){
      ans -= now;
      ans %= MOD;
      if(ans < 0) ans += MOD;
    }
    else{
      ans += now;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 26544
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>  
#define pii pair<int,int>
#define vpi vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define ___(a) for(auto &i:a) cin>>i
#define __(a)  for(auto i:a) cout<<i<<" "
#define nl cout<<"\n";
#define momo(k) memset(k,0,sizeof(k))
#define momi(k) memset(k,-1,sizeof(k))
/* 
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
*/
int power(int x, int y,int mod){
    int res = 1;
    while (y)
    {
        if (y & 1)
        res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}
int modInverse(int a, int m){
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
int binomial(int n,int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}

// vector<int> prime;
// void sieve(){
//     bool arr[300000]={0};
//     prime.pb(2);
//     for(int i=3;i<300000;i+=2){
//         if(arr[i])continue;
//         for(int j=i*i;j<300000;j+=i) arr[j]=1;
//         prime.pb(i);
//     }
// }
// const int N=1e18+2;
const int mod = 1e9+7;
const int N = 1e3+2;
int n,m;
int dp[N][N];

int32_t main() {
    IOS;
    momo(dp);
    cin>>n>>m;
    char a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i == 0 and j == 0) continue;
            if(a[i][j] == '#') continue;
            if(i == 0){
                dp[i][j] = dp[i][j-1];
            }else if(j == 0){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = ( dp[i][j-1] + dp[i-1][j] )%mod;
            }
        }
    }
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<m;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     nl;
    // }
    cout<<dp[n-1][m-1];
    return 0;
}

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

bool prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}


int main() {
	int n;
	cin >> n;
	cout << 11;
	int cnt = 1;
	int now = 31;
	while (cnt < n) {
		if (prime(now)) {
			cout << " " << now;
			cnt++;
		}
		now += 10;
	}
	cout << endl;
}

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

int n , m , x , c[12] , a[12][12] , ans = -1 , skill[12] , sum;
bool f;

void dfs(int book){
    if(book == n){
        f = true;
        for(int i=0 ;i<m ;i++ ){
            if(skill[i] < x){
                f = false;
            }
        }
        if(f){
            if(ans == -1){
                ans = sum;
            } else {
                ans = min(ans , sum);
            }
        }
    } else {
        dfs(book+1);
        
        sum+=c[book];
        for(int i=0 ;i<m ;i++ ){
            skill[i] += a[book][i];
        }  
        
        dfs(book+1);
        
        sum-=c[book];
        for(int i=0 ;i<m ;i++ ){
            skill[i] -= a[book][i];
        }
    }
}

signed main(){
    cin >> n >> m >> x;
    for(int i=0 ;i<n ;i++ ){
        cin >> c[i];
        for(int j=0 ;j<m ;j++ ){
            cin >> a[i][j];
        }
    }
    
    dfs(0);
    
    cout << ans << endl;
    
    return(0);
}

Measured memory_bytes: 3624
H, W, K = map(int, input().split())
mod = 10 ** 9 + 7
F = [1, 1, 2, 3, 5, 8, 13, 21, 34]
inv_F = pow(F[W], mod - 2, mod)
P = [[0 for w in range(W + 2)] for h in range(H + 1)]
P[0][1] = 1

if W > 1:
    for h in range(1, H + 1):
        for w in range(1, W + 1):
            P[h][w] = (P[h - 1][w - 1] * F[w - 2] * F[W - w] % mod
                       + P[h - 1][w] * F[w - 1] * F[W - w] % mod
                       + P[h - 1][w + 1] * F[w - 1] * F[W - w - 1] % mod) * inv_F % mod

    print(P[H][K] * pow(F[W], H, mod) % mod)
else:
    print(1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top+1];
}

int main(void){
	int a, b;
	top = 0;
	char s[100];

	while( scanf("%s",s) != EOF) {
		if ( s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		}else if ( s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		}else if ( s[0] == '*'){
			a = pop();
			b = pop();
			push(a * b);
		}else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());
	return 0;
}

Measured memory_bytes: 548
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];

  vector<vll> dp(n, vll(2));
  //dp[i][0] : a[i] まで見て floor((i + 1) / 2) 個取る
  //dp[i][1] :               ceil((i + 1) / 2) 個取る
  dp[0][0] = 0;
  dp[0][1] = a[0];
  dp[1][0] = max(a[0], a[1]);
  dp[1][1] = max(a[0], a[1]);

  vll v(n, 0); //奇数項目まで見て切り上げ，のときの選び方は1通りなので先に求めておく --- (*)
  v[0] = a[0];
  for (ll i = 2; i < n; i += 2) v[i] = v[i - 2] + a[i];

  for (ll i = 2; i < n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 2][0] + a[i]);
    if (i % 2 == 0) dp[i][1] = v[i]; // ------------------------------------ (*)
    else dp[i][1] = dp[i][0]; //偶数項目まで見たときは切り上げも切り捨ても変わらない
  }
  cout << dp[n - 1][0] << endl;
}


Measured memory_bytes: 17212
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 5050;

int n;
int d[MAXN];
int qn, len, x, m;

int main() { 

  scanf("%d %d", &n, &qn);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i]);
  }

  while (qn--) {
    scanf("%d %d %d", &len, &x, &m);
    long long ans = len - 1;

    long long last = x;

    for (int i = 0; i < n; i++) {
      if (i + 2 > len) {
        break;
      }
      long long curUse = 1 + (len - (i + 2)) / n;
      if (d[i] % m == 0) {
        ans -= curUse;
      }
      last += curUse * (d[i] % m);
    }

    ans -= (last / m - (x / m));

    printf("%lld\n", ans);
  }

  return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct BIT_tree{
    int n;  // 配列の要素数(数列の要素数+1)
    vector<T> bit; // データの格納先(1-indexed)。初期値は0
    BIT_tree(vector<T> v){
        n = v.size() + 1;
        bit.assign(n, 0);
        int i;
        for(i = 0;i < v.size();++i){
            add(i, v.at(i));
        }
    }
    
    //0-indexedで受け取り, 内部は1-indexedで作動
    void add(int i, T x){
        ++i;
        int ind;
        for(ind = i;ind < n;ind += (ind & -ind)){
            bit.at(ind) += x;
        }
    }
    
    //1-indexedで作動
    T sum_sub(int i){
        T s = 0;
        int idx;
        for(idx = i;idx > 0;idx -= (idx & -idx)){
            s += bit.at(idx);
        }
        return s;
    }
    
    //0-indexedで受け取り, [l, r)に加算, 1-indexedで渡す
    T sum(int l, int r){
        return sum_sub(r) - sum_sub(l);
    }
    
    ll lower_bound(T w){
        if(w < 0) return -1;
        int x = 0, r = 1;
        while(r < n) r = r<<1;
        int len;
        for(len = r;len > 0;len = len >> 1){
            if(x + len < n && bit.at(x + len) < w){
                w -= bit.at(x+len);
                x += len;
            }
        }
        return x;
    }
};

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    BIT_tree<ll> bit(a);
    rep(i,q){
        ll c;
        cin >> c;
        if(c == 0){
            ll p,x;
            cin >> p >> x;
            bit.add(p, x);
        }else{
            ll l,r;
            cin >> l >> r;
            cout << bit.sum(l,r) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 14792
n=int(input())

A = [[[0] * 10 for i in range(3)] for j in range(4)]

cnt = 1

while cnt <= n:
    b,f,r,v = map(int, input().split())
    A[b-1][f-1][r-1] += v
    cnt += 1

for bb in range(4):
    for ff in range(3):
        for rr in range(10):
            print(" {}".format(A[bb][ff][rr]), end="")
        print("")
    if bb != 3:
        print("#" * 20)


Measured memory_bytes: 5628
#include <cstdio>  
#include <iostream>  
#include <cstring>  
#include <string>  
#include <cmath>  
#include <algorithm>  
#include <cstdlib>  
#include <utility>  
#include <map>  
#include <stack>  
#include <set>  
#include <vector>  
#include <queue>  
#include <deque>  
#include <sstream>  
#include <bitset>
#include<bits/stdc++.h>      
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a-b>=1) cout<<a-b;
	else 
	cout<<0;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[i for i in input().split()]
#print(a[0]+' '+a[1])
if n%2==0:
    for i in range(n-1,0,-2):
        print(a[i],end=' ')
    for i in range(0,n-1,2):
        print(a[i],end=' ')
else:
  if n==1:
    print(a[0])
  else:
    for i in range(n-1,-1,-2):
        print(a[i],end=' ')
    for i in range(1,n-1,2):
        print(a[i],end=' ')    

Measured memory_bytes: 21828
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
vector<ll>g[10010];
bool visited[10010];
int main(void){
    int n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    map<ll,ll>m;
    sort(a.begin(),a.end(),greater<ll>());
    for(int i=0;i<n;i++){
        m[a[i]]++;
    }
    ll f = 0;
    for(auto itr = m.rbegin();itr!=m.rend();++itr){
        ll v = itr->first;
        ll num = itr->second;
        if(f==0){
            if(num>=4){
                cout<<v*v<<endl;
                return 0;
            }
            else{
                if(num>=2){
                    f = v;
                }
            }
        }
        else{
            if(num>=4){
                cout<<max(f*v,v*v)<<endl;
                return 0;
            }
            else{
                if(num>=2){
                    cout<<f*v<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 7552
#include "bits/stdc++.h"
#define lpa(i,a,b) for(i=a; i<b; ++i)
#define lp(i,n) lpa(i,0,n)
typedef long long ll;
using namespace std;
ll ff(int n)
{
	ll ways=1;
	while(n)
	{
		ways*=2;
		n--;
	}
	return ways;
}
int main()
{
	int n,p,q,i;
	cin>>n>>p;
	int bag[n];
	lp(i,n){ cin>>q; bag[i]=q%2; }
	sort(bag,bag+n);
	for(i=0;i<n && bag[i]==0;i++);
	if(p==1 && i==n) cout<<0;
	else if(p==0 && i==n) cout<<ff(n);
	else cout<<ff(n-1);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        if(a + b == c || b + c == a || a + c == b){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26964
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
    if(i==0||i==h-1||j==0||j==w-1)
      cout << "#";
    else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


Measured memory_bytes: 3008
#!/usr/bin/env python3
#AGC4 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
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,x = LI()
a = LI()
ans = sum(a)
b = a[:]
for k in range(1,n):
    for i in range(n):
        b[i] = min(b[i],a[i-k])
    ans = min(ans,k*x + sum(b))
print(ans)

Measured memory_bytes: 44216
# include <iostream>
using namespace std;
int main()
{
	int a,b,c,k,x,y,z;
	cin>>a>>b>>c>>k;
	if(a>=k)
	{
		cout<<k;
		return 0;
	}
	if(a<k && a+b>=k)
	{
		cout<<a;
		return 0;
	}
	if(a+b<k)
	{
		cout<<a-(k-(a+b));
		return 0;
	}
	
}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  double l = 0.0000005, r = 1e9 + 1.0;
  while (r - l > 0.0000005) {
    double m = (r + l) / 2.0;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
      cnt += ceil(A[i] / m) - 1;
    }
    if (cnt <= K) r = m;
    else l = m;
  }

  cout << (ll) ceil(l) << '\n';
  return 0;
}

Measured memory_bytes: 4648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

const int MAX = 510'000;
const int MOD = 1'000'000'007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    ll n, k;
    cin >> n >> k;
    ll total = 0;
    // 空の部屋が0個からn-1個までの場合を集計する
    for (int i = 0; i <= min(n - 1, k); i++)
    {
        total = (total + COM(n, i) * COM(n - 1, i)) % MOD;
    }
    cout << total << endl;
    return 0;
}


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

int main() {
  int g, b;
  //4の倍数なら、100の位は25*4より無視し、下2桁が4の倍数か見れば良い
  cin >> g >> g >> b;
  //100の位は使わないので変数を削ってメモリを節約する
  if((g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

lst = list(itertools.permutations(range(1, n + 1), n))

a, b = 0, 0
for i, v in enumerate(lst):
    if v == p:
        a = i + 1
    if v == q:
        b = i + 1

print(abs(a - b))

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

int main() {
  long long n,m,x,t,ans=10000000,sum;
  bool tf;
  cin>>n>>m>>x;
  int a[n][m+1];
  for(int i=0;i<n;i++){
    for(int j=0;j<m+1;j++){
      int l;
      cin>>l;
      a[i][j]=l;
    }
  }
  int b[n],c[m];
  for(int i=0;i<pow(2,n);i++){
    for(int k=0;k<m;k++)c[k]=0;
    t=i;
    tf=true;
    sum=0;
    for(int j=0;j<n;j++){
      b[j]=t%2;
      t=t/2;
    }
    for(int j=0;j<n;j++){
      if(b[j]==0){
        sum+=a[j][0];
        for(int k=0;k<m;k++){
          c[k]+=a[j][k+1];
        }
      }
    }
      for(int j=0;j<m;j++){
        if(c[j]<x)tf=false;
      }
    if(tf)ans=min(ans,sum);
  }
  if(ans==10000000)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  vector<set<int>> cnt(26);
  for( int i = 0; i < 26; i++ ) cnt.at(i).insert(INF);
  for( int i = 0; i < S.size(); i++ ) cnt.at(S.at(i)-'a').insert(i);
  
  int Q;
  cin >> Q;
  
  for( int i = 0; i < Q; i++ ){
    int num;
    cin >> num;
    if( num == 1 ){ //タイプ1のとき
      int X;
      char C;
      cin >> X >> C;
      X--;
      cnt.at(S.at(X)-'a').erase(X);
      cnt.at(C-'a').insert(X);
      S.at(X) = C;
    }else{ //タイプ2のとき
      int ans = 0;
      int L, R;
      cin >> L >> R;
      L--;
      for( int j = 0; j < 26; j++ ){ //その文字が範囲内に含まれているか
        int l = *cnt.at(j).lower_bound(L);
        if( l < R ) ans++;
      }
      cout << ans << endl;
    }
  }
  
}


Measured memory_bytes: 24196
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
#include<set>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N, K, Q;
vector<int> A;
int P[200000] = { 0 };
int main() {
	cin >> N >> K >> Q;
	for (int i = 0; i < Q; i++) {
		int a;
		cin >> a;
		a--;
		A.push_back(a);
		P[a]++;
	}
	for (int i = 0; i < N; i++) {
		if (P[i] >= Q - K + 1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;

}

Measured memory_bytes: 1528
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int N;
	cin >> N;
	string ans = "";
	while (N != 0) {
		if (N % 2 != 0) {
			N--;
			ans = "1" + ans;
		}
		else ans = "0" + ans;
		N /= -2;
	}
	if (ans == "")ans = "0";
	cout << ans << endl;

}
	

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


int dp[55][2],num[55][2];

int calc(int N){
    memset(dp,0,sizeof(dp));
    memset(num,0,sizeof(num));
    dp[0][0]=dp[0][1]=0;
    num[0][0]=num[0][1]=1;

    for(int i=1;i<55;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                if(!j&&(N>>(i-1)&1)<k)continue;

                int nj=j|((N>>(i-1)&1)>k);
                dp[i][j]^=dp[i-1][nj];
                if(num[i-1][nj]&1)dp[i][j]^=k<<(i-1);
                num[i][j]+=num[i-1][nj];
            }
        }
    }
    return dp[54][0];
}

signed main(){
    int A,B;
    cin>>A>>B;
    if(A)A--;

    cout<<(calc(B)^calc(A))<<endl;
}


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

#define int long long

bool isprime[200000];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  fill_n(isprime, 200000, true);
  isprime[0] = isprime[1] = false;  
  for ( int i = 2; i*i < 200000; i++ ) {    
    for ( int j = 2; i*j < 200000; j++ ) {
      isprime[i*j] = false;      
    }
  }

  int N, P;
  while ( cin >> N >> P, N != -1 ) {
    int cnt = 0;
    vector<int> p;    
    for ( int i = N+1; i < 200000; i++ ) {
      if ( isprime[i] ) {
	p.push_back(i);
	// cout << i << endl;
	if ( cnt++ >= 100 ) break;
      }
    }

    // cout << p.size() << endl;

    vector<int> ans;
    for ( int i = 0; i < (int)p.size(); i++ ) {
      for ( int j = i; j < (int)p.size(); j++ ) {
	ans.push_back(p[i]+p[j]);	
      }
    }

    sort(ans.begin(), ans.end());
    // for ( int i = 0; i < 10; i++ ) cout << ans[i] << " ";
    cout << ans[P-1] << endl;    
  }
  
  return 0;
}



Measured memory_bytes: 3344
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8,cnt;


int main(){
	ll n;
	cin>>n;
	n--;
	ll a[n];
	ll b[n+1];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	if(a[0]<=a[1]) {
		b[0]=a[0];
		b[1]=a[0];
	}
	else {
		b[0]=a[0];
		b[1]=a[1];
	}
	for(ll i=1; i<n; i++){
		if(a[i]>a[i+1] && i<n-1){
			b[i+1]=a[i+1];
		}
		else{
			b[i+1]=a[i];
		}
	}
	for(ll i=0; i<n+1; i++){
		sum+=b[i];
	}
	cout<<sum<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#define N 500

static const int A=0;
static const int B=1;
static const int C=2;

int a,T[N][N];
int b[N],c[N],d[N],e;

void X(int x){
  int p;
  b[x]=B;
  e++;
  c[x]=e;
  for(p=0;p<a;p++){
    if(T[x][p]==0){
      continue;
    }
    if(b[p]==A){
      X(p);
    }
  }
  b[x]=C;
  d[x]=++e;
}

void Y(){
  int x,y;
  for(x=0;x<a;x++){
    b[x]=A;
  }
  e=0;
  for(y=0;y<a;y++){
    if(b[y]==A){
      X(y);
    }
  }
    for(x=0;x<a;x++){
      printf("%d %d %d\n",x+1,c[x],d[x]);
    }
  }

int main(){
  int x,y,z,i,j;

  scanf("%d",&a);

  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      T[i][j]=0;
    }
  }

  for(i=0;i<a;i++){
    scanf("%d %d",&x,&y);
    x--;
    for(j=0;j<y;j++){
      scanf("%d",&z);
      z--;
      T[x][z]=1;
    }
  }

  Y();

  return 0;
}



Measured memory_bytes: 2108