akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

int main() {
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> S(H);
  vector<vector<int>> cnt(H,vector<int>(W,0));
  rep(i,H) cin >> S[i];
  rep(i,H){
    rep(j,W) {
      if (S[i][j]=='1') cnt[i][j]=1;
      if (j>0) cnt[i][j] += cnt[i][j-1];
    }
  }

  int res=H*W,tmp=0;
  for (int i=0;i<1<<(H-1);i++) {
    tmp=0;
    vector<int> memo(H,0);
    rep(j,H-1) {
      memo[j+1]=memo[j];
      if (i>>j&1) {
        memo[j+1]++;
        tmp++;
      }
    }
    vector<int> count(memo[H-1]+1,0);
    int flag=-1;bool f2=false;
    rep(j,W) {
      rep(k,H) {
        if (S[k][j]=='1') count[memo[k]]++;
        if (count[memo[k]]>K) {
          tmp++;
          vector<int> c2(memo[H-1]+1,0);
          swap(count,c2);
          j--;
          if (flag==j) {
            f2=true;
          }
          flag=j;
          break;
        }
      }
      if (f2) break;
    }
    if (f2==false) chmin(res,tmp);
  }
  cout << res << endl;
} 

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

using ll = long long;

using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i=a; i<=b; i++) {
        if (i % k == 0) {
            cout << "OK" << '\n';
            return 0;
        }
    }
    cout << "NG" << '\n';
    return 0;
}

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

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

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

using namespace std;

typedef pair<int ,int > P;

int n;
vector<int> vec;

int main()
{
	while(cin>>n)
	{
		if(!n) return 0;
		int ans=-INF;
		rep(i,n)
		{
			int a;
			cin>>a;
			vec.pb(a);
			ans=max(ans,a);
		}
		rep(i,n)
		{
			int sum=0;
			for(int j=i;j<n;j++)
			{
				sum+=vec[j];
				ans=max(ans,sum);
			}
		}
		cout<<ans<<endl;
		vec.clear();
	}
	return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
const int M  = 100005;
long long int N = 1e9 + 7;
long long int Z = 998244353;
/*int fac[M]={0};*/
//int dp[M]={0};
#define ll long long 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a%b); 
} 
// Use __gcd(int, int) as inbuilt function.
void precompute(){

}
int max3(int x, int y, int z){
    return max(x, max(y,z));
}
long long int power(long long int x, unsigned int y, int p) 
{ 
    long long int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
long long int modinv(long long int x, int p){
    return (power(x, p-2, p));
}
bool compare(const pair<int, int> &p1, const pair<int, int> &p2){
    return (p1.first> p2.first);
}
/*long long int nCrModP(long long int n, long long int r, long long int p) 
{ 
   if (r==0) 
      return 1;  
    return (fac[n] * modinv(fac[r], p) % p * modinv(fac[n-r], p) % p) % p; 
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k, n, x=-1, maxm = -1; cin>>k>>n;
    int prev = 0;
    cin>>prev;
    int ini = prev;
   	for(int i = 0; i<n-1; i++){
   		cin>>x;
   		maxm = max(maxm, x-prev);
   		prev = x;
   	}
   	cin>>x;
   	maxm = max(maxm, ini + k - x);
   	cout<<(k-maxm);
   	return 0;
}


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

using namespace std;

int main()
{
  int n, m;
  cin >> n;
  cin >> m;
  vector<int> foods(m);
  
  for(int i = 0; i < n; i++)
  {
    int k;
  	cin >> k;
    
    for(int j = 0; j < k; ++j)
    {
      int a;
      cin >> a;
      a--;
      foods[a]++;
    }     
  }
  
  int result = 0;
  for(auto food : foods)
  {
  	if(food == n)
    {
      result++;
    }
  }
  
  cout << result;
  
 return 0;
}

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

ll solve(int n) {
    ll begend[10][10] = {};
    rep(i, n+1) if (i) {
        string s = to_string(i);
        int b = s[0] - '0', e = s.back() - '0';
        begend[b][e]++;
    }
    ll ans = 0;
    rep(i, 10) rep(j, 10) ans += begend[i][j] * begend[j][i];
    return ans;
}

int main() {
    int n;
    while (cin >> n) {
        cout << solve(n) << endl;
    }
}


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

int64_t power(int64_t x, int64_t y){
  if(y < 0)
    return 0;
  else{
    int64_t n = 1ll;
    for(int64_t i = 0; i < y; i++)
      n *= x;
    return n;
  }
}

int main() {
    int n; cin >> n;
    vector<vector<int>> a(10,vector<int>(10));
    for(int k = 1; k <= n; k++){
        int p; int q = k%10;
        int pp = k;
        while(pp > 0){
            if(pp < 10) p = pp;
            pp /= 10;
        }
        a[p][q]++;
    }
    int ans = 0;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            ans += a[i][j]*a[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (b), _a = (a); i >= _a; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<"debug : "<<x<<endl
#define debug2(x,y) cout<<"debug : "<<x<<" | "<<y<<endl
#define debug3(x,y,z) cout<<"debug : "<<x<<" | "<<y<<" | "<<z<<endl
#define debug4(x,y,z,w) cout<<"debug : "<<x<<" | "<<y<<" | "<<z<<" | "<<w<<endl
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define M 1000000007          // 1e9+7
#define INF 10000000000       // 1e9
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;
 
bool cus(pair<int,int> a, pair<int,int> b){
    if(a.ff<b.ff)
        return true;
    if(a.ff>b.ff)
        return false;
    return a.ss<b.ss;
}
 
ll gcd(ll a, ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}


void solve(){
 ll n;
 cin >> n;
 vi pw10(n+1);
 vi pw8(n+1);
 vi pw9(n+1);
 pw10[0] = 1;
 fr(i, 1, n) pw10[i] = (10*pw10[i-1]%M)%M;
 pw9[0] = 1;
 fr(i, 1, n) pw9[i] = (9*pw9[i-1]%M)%M;
 pw8[0] = 1;
 fr(i, 1, n) pw8[i] = (8*pw8[i-1]%M)%M;

 ll diff1 = (pw10[n]%M + pw8[n]%M)%M;
 ll diff2 = (2%M * pw9[n]%M)%M;
 ll ans = (diff1%M - diff2%M + M)%M;
 cout << ans%M << endl;

  }

int main () 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);
 
    //ll t = 1;
    //cin>>t;
    //while(t--)
        solve();
 
    return 0;
}
  

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
map<ll, ll> mp;

int main(){
    ll x, ans = 0;
    cin >> x;
    ans += x / 11;
    x -= ans*11;
    if(x == 0) cout << 2*ans << endl;
    else if(x > 0 && x <= 6) cout << ans*2+1 << endl;
    else cout << ans*2+2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 100001
vector<vector<int> > arr(max1);


int main(){	
	char inp;
	cin>>inp;
	if(inp>='a'){
		cout<<'a'<<endl;
	}
	else{
		cout<<'A'<<endl;
	}




}

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


using namespace std;

const int N = 100005;
bool visited[N];
vector<int> adj[N];

void dfs(int node){
	visited[node] = true;
	for(int i = 0 ; i < adj[node].size() ; i++){
		if(!visited[adj[node][i]]){
			dfs(adj[node][i]);
		}
	}
}

int main() {
	int n, m, ans = 0;
	cin >> n >> m;

	for(int i = 0, x, y, z ; i < m ; i++){
		cin >> x >> y >> z;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	for(int i = 1 ; i <= n ; i++){
		if(!visited[i]){
			++ans;
			dfs(i);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 8960
eval'K,X,Y='+gets(p).split*?,
x,y,*s=X.abs,Y.abs
d=x+y
x,y=y,x if f=x<y
K%2-d%2<0&&p(-1)+exit
d!=K&&($.+=[~-d/K,1].max
v=K>(t=K*($.+=1&d-K*$.)-d>>1)?0:t-t=K
a=K-t
2.upto($.){s<<[a,-t]
a+=q=[x+v-a,K].min
t-=K-q})
s<<[x,y]
p$.
s.map{|a,b|a,b=b,a if f
p a*=X<=>0.1,b*=Y<=>0.1}

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

#define sc scanf
#define pf printf
#define CIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull unsigned long long int
#define ll  long long int
#define db double
#define fl float
#define vi vector<int>
#define vl vector<ll>
#define qin queue<int>
#define pb push_back
#define pob pop_back
#define ft front
#define bk back
#define mp make_pair
#define pii pair<int,int>
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define pll __builtin_popcountll
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())



int main()
{
    CIN;

    string s,t;
    cin>>s>>t;

    int cnt=0;

    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3772
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
  
  const lines = input.split('\n')
  
  const map = []
  for (let i = 0; i < 3; i++) {
    map[i] = lines[i].split(' ').map(Number)
  }
  
  let diff1 = 0
  let diff2 = 0

  diff1 = map[0][0] - map[0][1]
  diff2 = map[0][1] - map[0][2]

  
  for (var i = 1; i < 3; i++) {
      if (diff1 !== map[i][0] - map[i][1]) break
      if (diff2 !== map[i][1] - map[i][2]) break
  }
  
  console.log(i === 3 ? 'Yes' : 'No')
 
})(input)


Measured memory_bytes: 29624
#include <stdio.h>

int main(void)
{
	int der,i,tmp,limit,menseki;
	long sum;
	
	while(scanf("%d",&der)!=EOF)
	{
		sum=0;
		tmp=der;
		limit=600/tmp;
		for(i=0;i<limit;i++)
		{
			menseki=tmp*tmp*i*i*tmp;
			sum+=menseki;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 592
a,b = input().split()
C = a + b
number_list =list(range(1,1000))
squared_list =[]
for i in number_list:
        D = i * i
        D2 = str(D)
        squared_list.append(D2)
if C in squared_list:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int a[100005];
int main()
{
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
	//		cout<<pow(2,i)<<endl;
			if(pow(2,i)>n)
			{
//				cout<<"$";
				cout<<pow(2,i-1)<<endl;
				break;
			}
		}
	
	return 0;
 } 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    rep(i, N) cin >> X[i];

    ll ans = 0;
    repd(i, 1, N) {
        ll diff = X[i] - X[i - 1];
        ll tel = diff * A;
        ans += min(tel, B);
    }

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

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

int main(){
    int N, Q; cin >> N >> Q;
    string S; cin >> S;

    vector<int> sum(N + 1, 0);
    for(int i = 2; i < N + 1; i++){
        if(S[i - 2] == 'A' && S[i - 1] == 'C'){
            sum[i] = sum[i - 1] + 1;
        }else{
            sum[i] = sum[i - 1];
        }
    }

    for(int i = 0; i < Q; i++){
        int l, r; cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
}

Measured memory_bytes: 1408
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


### BIT 
def init(bit, values):
    for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn)
def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN)
def update(bit,i,x):
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return

n,d,a = map(int, input().split())
xh = [None]*n
# h = [None]*n
for i in range(n):
    xh[i] = tuple(map(int, input().split()))
xh.sort()

bit = [0] * (n+1)
r = 0
val = 0
done = False
for l,(x,h) in enumerate(xh):
    bound = x+2*d
    while r<n and xh[r][0]<=bound:
        r += 1
    nokori = h + query(bit, l+1)
    if nokori>0:
#         print(nokori, a, l, r, bit)
        num = nokori//a + int(nokori%a!=0)
        val += num
        update(bit, l+1, -num*a)
        if r<n:
            update(bit, r+1, num*a)
print(val)

Measured memory_bytes: 95440
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ABC045_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadLine();
            var b = ReadLine();
            var c = ReadLine();
            var ca = 0;
            var cb = 0;
            var cc = 0;
            var turn = 0;

            while (true)
            {
                if (turn == 0)
                {

                    if (ca == a.Length)
                    {
                        Console.WriteLine("A");
                        break;
                    }

            
                    if (a[ca] == 'a') turn = 0;
                    else if (a[ca] == 'b') turn = 1;
                    else if (a[ca] == 'c') turn = 2;
                    ca++;
                }
                 else if (turn == 1)
                {
                    if (cb == b.Length)
                    {
                        Console.WriteLine("B");
                        break;
                    }
                 
                    if (b[cb] == 'a') turn = 0;
                    else if (b[cb] == 'b') turn = 1;
                    else if (b[cb] == 'c') turn = 2;
                    cb++;
                }
                else if (turn == 2)
                {
                    if(cc == c.Length)
                    {
                        Console.WriteLine("C");
                        break;
                    }
                    if (c[cc] == 'a') turn = 0;
                    else if (c[cc] == 'b') turn = 1;
                    else if (c[cc] == 'c') turn = 2;
                    cc++;
                }
            }
         
        }
    }
}


Measured memory_bytes: 2648
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
    int N;
    cin>>N;
    int A[200010];
    int ans[200010];
    for(int i=2;i<=N;i++)
    {
        cin>>A[i];
    }
    for(int i=2;i<=N;i++)
    {
        ans[A[i]]++;
    }
    for(int i=1;i<=N;i++)
    {
        cout<<ans[i]<<endl;
    }

return 0;


}

Measured memory_bytes: 4704
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 1000
#define INF 30'000'0'000'000'000ll
ll x[N+1], y[N+1], z[N+1];
ll mem[2][2][2][N+1][N+1];
ll opt(bool max_x, bool max_y, bool max_z, int n, int m) {
    ll& ans = mem[max_x][max_y][max_z][n][m];
    if(ans == -1) {
        if(n == 0) {
            ans = m == 0 ? 0 : -INF;
        } else {
            ans = opt(max_x, max_y, max_z, n - 1, m);
            if(m > 0) {
                ll val = (max_x ? x[n] : -x[n])
                       + (max_y ? y[n] : -y[n])
                       + (max_z ? z[n] : -z[n]);
                ans = max(ans, val + opt(max_x, max_y, max_z, n - 1, m - 1));
            }
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }
    memset(mem, -1, sizeof mem);
    cout << max({
        opt(0, 0, 0, n, m),
        opt(0, 0, 1, n, m),
        opt(0, 1, 0, n, m),
        opt(0, 1, 1, n, m),
        opt(1, 0, 0, n, m),
        opt(1, 0, 1, n, m),
        opt(1, 1, 0, n, m),
        opt(1, 1, 1, n, m),
    }) << endl;
    return 0;
}


Measured memory_bytes: 62976
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
t,x,y = [list(i) for i in zip(*l)]
p = 0
q = 0

for i in range(n):
    z = abs(p - (x[i] + y[i]))
    if ((t[i] - q) - z) % 2 == 0 and (t[i] - q) - z >= 0:
        p = x[i] + y[i]
        q = t[i]
    else:
        print('No')
        exit(0)

print('Yes')

Measured memory_bytes: 36620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int a,b;
    cin>>a>>b;
    if(a%500<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    long n, a, b;
    scanf("%ld %ld %ld", &n, &a, &b);

    if (n == 1 || a > b) {
        printf("%d\n", !!(a == b));
    } else {
        printf("%ld\n", (n - 2) * (b - a) + 1);
    }

    return 0;
}

Measured memory_bytes: 128
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for k in range(a+1):
    for l in range(b+1):
        for m in range(c+1):
            total = 500 * k + 100 * l + 50 * m
            if total == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 10000
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, m, a[1000], b[1000], c[1000][12];
int d[1010];
int dp[1010][5000];

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		for (int j = 0; j < b[i]; j++) {
			cin >> c[i][j];
			c[i][j]--;
			d[i] += (1 << c[i][j]);
		}
	}
	for (int i = 0; i < 1010; i++)for (int j = 0; j < 5000; j++)dp[i][j] = INF;
	dp[0][0] = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < (1 << n); j++) {
			dp[i + 1][(j | d[i])] = min(dp[i + 1][(j | d[i])], dp[i][j] + a[i]);
			dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
		}
	}
	if (dp[m][(1 << n) - 1] == INF)cout << -1 << endl;
	else cout << dp[m][(1 << n) - 1] << endl;
}

Measured memory_bytes: 39808
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
#define all(v) ((v).begin()),((v).end())
#define clr(v,val) memset(v,val,sizeof v)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
void Run() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e5 + 20;
/***You***Can***Do***It***/
int main(){


	//Run();
	int x;
	int a, b;
	cin >> x;
	cin >> a >> b;
	

	for (int i = a; i <= b; i++) {
		if (i % x == 0)
		{
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";

}


Measured memory_bytes: 3636
// AtCoder Beginner Contest 999

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    string str = to_string(n);
    for (int i = 0; i < 3; i++) {
        if (str[i] == '1') {
            str[i] = '9';
        } else {
            str[i] = '1';
        }
    }
    cout << str << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,m,RULE;
    while(scanf(" %d %d %d", &n, &m, &RULE),n){
        vector<int> A(n),B(m);
        rep(i,n){
            scanf(" %d", &A[i]);
            --A[i];
        }
        rep(i,m){
            scanf(" %d", &B[i]);
            --B[i];
        }

        vector< pair<vector<int>,int> > rule(RULE);
        rep(i,RULE){
            int k;
            scanf(" %d", &k);

            vector<int> x(k);
            int y;
            rep(j,k){
                scanf(" %d", &x[j]);
                --x[j];
            }
            scanf(" %d", &y);
            --y;

            rule[i] = {x,y};
        }

        auto make_f = [&](vector<int> &v){
            int V = v.size();
            int N = 2*V;
            vector<vector<int>> f(N,vector<int>(N));

            rep(i,N){
                int vv = v[i%V];
                f[i][i] |= (1<<vv);
            }

            for(int b=2; b<=V; ++b){
                for(int l=0; l+b-1<N; ++l){
                    int r = l+b-1;

                    // calc f[l][r]
                    rep(rr,RULE){
                        vector<int> x = rule[rr].fi;
                        int y = rule[rr].se;

                        int X = x.size();
                        vector<vector<bool>> valid(b+1, vector<bool>(X+1));
                        valid[0][0] = true;
                        rep(i,b)rep(j,X)if(valid[i][j]){
                            int val = x[j];
                            for(int k=i; k<b; ++k){
                                if(f[l+i][l+k]>>val&1) valid[k+1][j+1] = true;
                            }
                        }

                        if(valid[b][X]) f[l][r] |= (1<<y);
                    }
                }
            }

            // rep(i,N)rep(j,N) printf("f[%d][%d] = %d\n",i,j,f[i][j]);
            return f;
        };

        vector<vector<int>> fa = make_f(A), fb = make_f(B);
        int ans = -1;
        rep(i,n)rep(j,m){
            // printf("CALC %d %d\n",i,j);
            vector<vector<int>> dp(n+1,vector<int>(m+1,-1));
            dp[0][0]=0;
            rep(ii,n)rep(jj,m)if(dp[ii][jj]>=0){
                for(int ni=ii+1; ni<=n; ++ni)for(int nj=jj+1; nj<=m; ++nj){
                    if(fa[i+ii][i+ni-1]&fb[j+jj][j+nj-1]) dp[ni][nj] = max(dp[ni][nj], dp[ii][jj]+1);
                }
            }
            ans = max(ans, dp[n][m]);
        }

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



Measured memory_bytes: 3288
#include <iostream>
using namespace std;
int dsum(int x)
{
	int sum = 0;
  	while(x > 0){
    	sum += x % 10;
      	x /= 10;
    }
  	return sum;
}

int main()
{
	int n, a, b, ans = 0;
  	cin >> n >> a >> b;
  	for (int i = 1; i <= n; i++){
      	int ds; ds = dsum(i);
    	if (ds >= a && ds <= b){
        	ans += i;
        }
    }
  	cout << ans;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    K = int(input())

    total = 1
    for _ in range(N):
        hoge = total * 2
        fuga = total + K
        if hoge < fuga:
            total = hoge
        elif hoge >= fuga:
            total = fuga

    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<(ll)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
const ll mod=1e9+7;
const ll INF = 1e9;

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b); 
}

bool is_prime(ll x){
    if(x==1) return false;
    for(ll i=2; i*i<=x;i++){
        if(x%i == 0) return false;
    }
    return true;
}

ll S(ll n){
    ll x=0;
    while(n>0){
        x+=n%10;
        n/=10;
    }
    return x;
}

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

    ll sum=0;
    sum=S(n);

    if(n%sum==0){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

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

long gcd(long a, long b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	long A, B;
	cin >> A >> B;
	long c = gcd(A, B);
	unordered_set<long> d;
	for (long i = 2; i * i <= c; i++) {
		while (c % i == 0) {
			c /= i;
			d.insert(i);
		}
	}
	if (c != 1) d.insert(c);
	cout << d.size() + 1 << endl;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int n, m;

int main(){
    IOS;
    cin >> n >> m;
    if(n == m) cout << "Yes";
    else cout << "No";    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>

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

using namespace std;

const int INF=((1<<31)-1)/4;

struct train{ int u,v,t1,t2,cost; };
bool cmp0(const train &T1,const train &T2){ return T1.t1<T2.t1 || T1.t1==T2.t1 && T1.t2<T2.t2; } // (t1,t2) の昇順
bool cmp1(const train &T1,const train &T2){ return T1.t2>T2.t2 || T1.t2==T2.t2 && T1.t1>T2.t1; } // (t2,t1) の降順

int decode(const char *t){
	int hh=(t[0]-'0')*10+(t[1]-'0');
	int mm=(t[3]-'0')*10+(t[4]-'0');
	return 60*hh+mm-8*60;
}

void calc_time(int n,int m,train *T,int dp[2][601][2001],int s){
	rep(i,2) rep(t,601) rep(u,n) dp[i][t][u]=INF;

	sort(T,T+m,cmp0);
	dp[0][0][s]=0;
	int iter=0;
	rep(t,601){
		if(t<600){ // 動かずに一分過ごす
			rep(u,n) dp[0][t+1][u]=min(dp[0][t+1][u],dp[0][t][u]);
		}
		while(iter<m && T[iter].t1==t){ // 電車に乗る
			dp[0][T[iter].t2][T[iter].v]=min(dp[0][T[iter].t2][T[iter].v],dp[0][t][T[iter].u]+T[iter].cost);
			iter++;
		}
	}

	sort(T,T+m,cmp1);
	dp[1][600][s]=0;
	iter=0;
	for(int t=600;t>=0;t--){
		if(t>0){
			rep(u,n) dp[1][t-1][u]=min(dp[1][t-1][u],dp[1][t][u]);
		}
		while(iter<m && T[iter].t2==t){
			dp[1][T[iter].t1][T[iter].u]=min(dp[1][T[iter].t1][T[iter].u],dp[1][t][T[iter].v]+T[iter].cost);
			iter++;
		}
	}
}

int main(){
	for(int m;scanf("%d",&m),m;){
		int n=0;
		map<string,int> f;
		f["Hakodate"]=n++;
		f["Tokyo"]=n++;

		train T[2000];
		rep(i,m){
			char s1[32],t1[8],s2[32],t2[8];
			int cost; scanf("%s%s%s%s%d",s1,t1,s2,t2,&cost);
			if(f.count(s1)==0) f[s1]=n++;
			if(f.count(s2)==0) f[s2]=n++;
			int tt1=decode(t1),tt2=decode(t2);
			if(0<=tt1 && tt2<=600){
				T[i]=(train){f[s1],f[s2],tt1,tt2,cost};
			}
			else{
				i--;
				m--;
			}
		}

		// 頂点が多すぎて MLE するので, 函館と東京の両方からたどり着ける頂点だけに制限する
		vector<int> G[4000];
		rep(i,m) G[T[i].u].push_back(T[i].v);
		bool vis[2][4000]={};
		rep(i,2){
			vis[i][i]=true;
			int Q[4000],head=0,tail=0;
			Q[tail++]=i;
			while(head<tail){
				int u=Q[head++];
				rep(j,G[u].size()){
					int v=G[u][j];
					if(!vis[i][v]) vis[i][v]=true, Q[tail++]=v;
				}
			}
		}
		bool kill[4000]={};
		vector<int> V;
		rep(u,n){
			if(!vis[0][u] || !vis[1][u]) kill[u]=true;
			else                         V.push_back(u);
		}
		rep(i,m){
			if(kill[T[i].u] || kill[T[i].v]){
				swap(T[i],T[m-1]);
				i--;
				m--;
			}
			else{
				T[i].u=lower_bound(V.begin(),V.end(),T[i].u)-V.begin();
				T[i].v=lower_bound(V.begin(),V.end(),T[i].v)-V.begin();
			}
		}

		// dp1[0][t][u] := ( 8:00 に函館にいて, 時刻 t に駅 u にいるときの最小コスト )
		// dp1[1][t][u] := ( 18:00 に函館に戻れて, 時刻 t に駅 u にいるときの最小コスト )
		// dp2 は dp1 の函館を東京に変えただけ.
		static int dp1[2][601][2001],dp2[2][601][2001];
		calc_time(n,m,T,dp1,0);
		calc_time(n,m,T,dp2,1);

		int ans=INF;
		rep(u,n) rep(t,600-30+1) {
			ans=min(ans,dp1[0][t][u]+dp1[1][t+30][u]+dp2[0][t][u]+dp2[1][t+30][u]);
		}
		printf("%d\n",ans<INF?ans:0);
	}

	return 0;
}

Measured memory_bytes: 18896
import math
def isPrimeNum(num):
    sqrtNum = int(math.sqrt(num)) + 1
    if(num == 2 or num == 3):
        return True
    elif(num % 2 == 0):
        return False
    else:
        for i in range(3, sqrtNum , 2):
            if(num % i == 0 ):
                return False
        return True
    
count = 0
N = int(input())
for i in range(N):
    num = int(input())
    if(isPrimeNum(num)):
        count += 1

print(count)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = (1 << 18) + 10;
int A[MAX_N];
multiset<int> S, have;

bool solve(int N, multiset<int>& S, multiset<int>& have) {
  REP(age, N) {
    vector<int> nxt;
    for (int x : have) {
      auto it = S.lower_bound(x);
      if (it == S.begin()) return false;
      --it;
      nxt.push_back(*it);
      S.erase(it);
    }
    for (int x : nxt) have.insert(x);
  }
  return true;
}

int main2() {
  S.clear();
  have.clear();
  int N = nextInt();
  int T = 1 << N;
  REP(i, T) A[i] = nextInt();
  sort(A, A+T);

  REP(i, T-1) S.insert(A[i]);
  have.insert(A[T-1]);

  cout << (solve(N, S, have) ? "Yes" : "No") << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,p[100100],r[100100],s[100100];
vector<int> v[100100];
vector<int> graph[100100];
bool vis[100100];

void dfs(int u){
	if(vis[u]) return;
	vis[u]=1;
	for(int i=0;i<graph[u].size();i++){
		int v = graph[u][i];
		dfs(v);
	}
}


int main() {
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		p[i]=i;
		r[i]=1;
		s[i]=1;
		scanf("%d",&o);
		for(int j=0;j<o;j++){
			scanf("%d",&x);
			v[x].pb(i);
		}
	}
	for(int i=1;i<=m;i++){
		if(v[i].size()>1) x = v[i][0];
		for(int j=1;j<v[i].size();j++){
			y = v[i][j];
			graph[x].pb(y);
			graph[y].pb(x);
		}
	}
	dfs(1);
	bool check=true;
	for(int i=1;i<=n;i++){
		if(!vis[i]) check=false;
	} 
	if(check) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 10240
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int now = 1;
        int result = 0;
        while(now < B){
            now--;
            now += A;
            result++;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21716
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    
    int i = 0;
    for (i = 0; ; i++) {
      int n = (a * i) - (i - 1);
      if (b <= n) { break; }
    }
    Console.WriteLine(i);
  }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N;
  cin>>N;
  vi a(N);
  rep(i,N)cin>>a[i];
  bool ok=true;
  rep(i,N){
   if(a[i]%2==0){
     if(a[i] %3 !=0 &&a[i]%5 !=0){
      ok=false;break;
     }
   }
  }
  if(ok)cout<<"APPROVED"<<endl;
  else cout<< "DENIED"<<endl;
}





Measured memory_bytes: 256
/*
 * pursuit
 * Created Time:  2011/8/24 12:51:23
 * File Name: 824a.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n,st;
int a[60];

int main() {
    while (scanf("%d",&n) && n){
        for (int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        st=0;
        for (int i=1;i<=n;i++){
            if (st==0){
                printf("%d",a[i]);
                st=1;
            }
            else if (a[i]==a[i-1]+1 && st==1){
                printf("-");
                st=2;
            }
            else if (a[i]!=a[i-1]+1 && st==2){
                printf("%d %d",a[i-1],a[i]);
                st=1;
            }
            else if (a[i]!=a[i-1]+1 && st==1){
                printf(" %d",a[i]);
            }
        }
        if (st==2 && a[n]==a[n-1]+1) printf("%d",a[n]);
        printf("\n");
    }   
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b; cin>>a>>b;
    if(b%a==0) cout<<a+b<<endl;
    else cout<<b-a<<endl;
}

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

int n;
typedef long long ll;
#define MOD 1000000007

ll powr(ll x, ll p){
    ll ans = 1;
    for (int i = 0; i < p; ++i){
        ans *= x;
        ans %= MOD;
    }
    return ans;
}

int main(){
    scanf("%d", &n);
    ll ans = powr(10, n);
    ans += MOD - powr(9, n);
    ans %= MOD;
    ans += MOD - powr(9, n);
    ans %= MOD;
    ans += powr(8, n);
    ans %= MOD;
    printf("%lld\n", ans);
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1)%mod;
}
//nCr
long long Comb (long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

ll calc(ll a,ll N){
  ll X=1, Y=1;
  rep(i,a){
    X=X*(N-i)%mod;
    Y=Y*(i+1)%mod;
  }
  
  return X*repeat_squaring(Y,mod-2)%mod;
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);lin(a);lin(b);
  
  ll A=repeat_squaring(2,N)-1;
  
  cout<<(A+2*mod - calc(a,N) -calc(b,N))%mod;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main() {
  unsigned int ans,i,n,s,d;	
  priority_queue<int> qu;
  while(cin >> n && n!=0) {
	  s=0; 
	  for (i=0;i<n;i++) { cin >> d; s+=d;}
	  for (i=0;i<n-1;i++) {cin >> d; qu.push(d);}
	  ans=s*n;
	  while(!qu.empty()) {
		s+=qu.top();  
		if (ans>=s*(n-1)) break;
		n--; ans=s*n;
		qu.pop();
	}
	while(!qu.empty()) qu.pop();
	cout << ans << endl;	    
  } 
	  

return 0;
} 

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

namespace abc047
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            
            List<int> list = new List<int>();
            list.Add(Convert.ToInt32(str[0]));
            list.Add(Convert.ToInt32(str[1]));
            list.Add(Convert.ToInt32(str[2]));

            int avg = (from item in list select item).Sum() / 2;
            int mod = (from item in list select item).Sum() % 2;


            if (mod == 0)
            {
                if ((from item in list where item == avg select item).Count() > 0)
                {
                    Console.WriteLine("Yes");
                }
                else if ((from item in list where item < avg select item).Sum() == avg)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 3032
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		_, _ = fmt.Scan(&tmp)
		arr[i] = tmp
	}
	sort.Sort(sort.IntSlice(arr))
	max := arr[len(arr) - 1]
	sum := 0
	for i := 0; i < n - 1; i++ {
		sum += arr[i]
	}
	if max >= sum {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#define INF 100000000;

int heapExtractMax();
void maxHeapify(int);
void buildMaxHeap();
void heapIncreaseKey(int, int);
void maxHeapInsert(int);

int length = 1;
int A[2000001];
 
int main()
{
  char order[8];
  int data, i = 1;
  
  while(order[0] != 'e' || order[1] != 'n')
    {
      scanf("%s", order);
     
      if(order[0] == 'i')
	{
	  scanf("%d", &data);
	  maxHeapInsert(data);
	}
      else if(order[0] == 'e' && order[1] == 'x') printf("%d\n", heapExtractMax());
    }
  return 0;
}
 
void maxHeapify(int i)
{
  int l, r, largest, a;
  
  l = i*2;
  r = i*2+1;
 
  if(l <= length && A[l] > A[i]) largest = l;
  else largest = i;
 
  if(r <= length && A[r] > A[largest]) largest = r;
 
  if(largest != i)
    {
      a = A[i];
      A[i] = A[largest];
      A[largest] = a;
      maxHeapify(largest);
    } 
}
 
int heapExtractMax()
{
  int max;
  
  if(length < 1) return -INF;
  
  max = A[1];
  A[1] = A[length];
  length--;
  maxHeapify(1);
 
  return max;
}

void maxHeapInsert(int key)
{ 
  length++;
  A[length] =- INF;
  heapIncreaseKey(length, key);
}
 
void heapIncreaseKey(int i, int key)
{
  int a;
  
  if(key < A[i]) return;
  
  A[i] = key;
  
  while(i > 1 && A[i/2] < A[i])
    {
      a = A[i];
      A[i] = A[i/2];
      A[i/2] = a;
      i = i/2;
    }
}

Measured memory_bytes: 4696
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;

int main()
{
	string s,t;
	cin>>s>>t;
	cout<<t<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
# AtCoder Beginner Contest 095
# C - Half and Half
# https://atcoder.jp/contests/abc095/tasks/arc096_a

a, b, c, x, y = map(int, input().split())

if a + b <= 2*c:
    print(a*x+b*y)
else:
    z = min(x, y)
    ans = 2*c*z
    x -= z
    y -= z

    if x == 0:
        if b < 2*c:
            ans += b*y
        else:
            ans += 2*c*y
    else:
        if a < 2*c:
            ans += a*x
        else:
            ans += 2*c*x
    
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    int n,k;
    cin >> n >> k;
    vector<int> a(n,0);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int f;
            cin >> f;
            a[f-1]++;
        }
    }
    int ans=0;
    rep(i,n){
        if (a[i]==0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  set<int>st;
  int k=0;
  for(int i=0;i<n;i++)
  {
    int tmp;
    cin>>tmp;
    if(st.find(tmp)!=st.end())
    {
      k=1;
    }
    else
    {
      st.insert(tmp);
    }
    
  }
  if(k==1)
    cout<<"NO";
  else
  {
    cout<<"YES";
  }
  
  return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;

void solve()
{
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h,h+n);
    int l=lower_bound(h,h+n,k)-h;
    cout<<n-l<<endl;
}
int main()
{
    solve();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int h, w, d; cin >> h >> w >> d;
    vint px(90001), py(90001);
    REP(i,h+1)REP(j,w+1) {
        int x; cin >> x;
        px[x] = j;
        py[x] = i;
    }
    vint dis(90001,0);
    for (int i = d+1; i < 90001; i++) {
        dis[i] = dis[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
    }
    int q; cin >> q;
    rep(i,q) {
        int l, r; cin >> l >> r;
        cout << dis[r]-dis[l] << endl;
    }
}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main(){
     int w,x;
    cin>>w;
    if(w<15){cout<<w*800;}
    else if(w>15){x=w/15;cout<<(w*800)-(x*200);}
    else if(w==15){cout<<(w*800)-200;}


    return 0;

}


Measured memory_bytes: 256
import java.util.*;
 
class Main{
    public static void main(String[] args){
        List<Integer> a = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            a.add(sc.nextInt());
        }
        a.stream().sorted(Comparator.reverseOrder()).limit(3).forEach(System.out::println);
    }
}

Measured memory_bytes: 32144