akhauriyash/Code-Regression huggingface dataset:
//	Author:	Mohib Manva
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int dp[30][111111];
int n, q, l, u, v;
int x[111111];
 
int main(void)
{
	scanf("%d",&n);
	int i, j;
	for(i=0 ; i<n ; i++)
	{
		scanf("%d",&x[i]);
	}
	scanf("%d %d",&l,&q);
	for(i=0 ; i<n ; i++)
	{
		int lo = i+1,high = n-1;
		int last = i+(i!=(n-1));
		while(lo<=high){
			int mi = (lo+high)>>1;
			if(x[mi]-x[i]<=l)
				lo = mi+1,last = mi;
			else
				high = mi-1;
		}
		dp[0][i]=last;
	}
	for(i=1;  i<=29 ; i++)
	{
		for(j=0 ; j<n ; j++)
		{
			dp[i][j]=dp[i-1][dp[i-1][j]];
		}
	}
	while(q--)
	{
		scanf("%d %d",&u,&v);
		u--; v--;
		if(u>v)
		{
			int temp=v;
			v=u;
			u=temp;
		}
		int ans=1e9;
		int cur=0;
		for(i=29 ; i>=0 ; i--)
		{
			if(dp[i][u]>=v)
			{
				ans=min(ans,cur+(1<<i));
			}
			else
			{
				cur+=(1<<i);
				u=dp[i][u];
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 13056
X = int(input())

'''
N**5 - (N-1)**5 <= 1000000000 となるNの絶対値を求めておく

N = 0
while True:
    if N**5 - (N-1)**5 > 1000000000:
        print(N)
        break
    N += 1

N = 120 となるため、-120から120を全探索の範囲にする
'''

for A in range(-120, 120):
    for B in range(-120, 120):
        if A**5 - B**5 == X:
            print(A, B)
            exit()


Measured memory_bytes: 9148
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const int MAX=1e9+7;


void array_show(int *a,int n){
	for(int i=0;i<n;i++)printf("%d%c",a[i],(i!=n-1?' ':'\n'));
}
void array_show(LL *a,int n){
	for(int i=0;i<n;i++)printf("%lld%c",a[i],(i!=n-1?' ':'\n'));
}

bool block[1005][1005];
int dp[1005][1005];

int main(){
	char ca[1005];
	int h,w;
	int i,j,k;
	cin>>h>>w;
	for(i=0;i<h;i++){
		cin>>ca;
		for(j=0;j<w;j++){
			if(ca[j]=='#')block[i][j]=true;
		}
	}
	dp[1][1]=1;
	block[0][0]=true;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(block[i][j])continue;
			dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j];
			if(dp[i+1][j+1]>=MAX)dp[i+1][j+1]%=MAX;
		}
	}
	cout<<dp[h][w]<<endl;
	return 0;
			
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e6+3;

ll d1[1001000],d2[1001000];

ll mult(ll n,ll m){//n^m%modを求める
    if(m==1){
        return n%mod;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%mod;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%mod;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin>>q;
    d1[0]=1;
    d2[0]=1;
    FOR(i,1,1000011){
      d1[i]=d1[i-1]*i;
      d1[i]%=mod;
      d2[i]=mult(d1[i],mod-2);
    }
    rep(i,q){
      ll x,d,n;
      cin>>x>>d>>n;
      if(d==0){
        cout<<mult(x,n)<<endl;
        continue;
      }
      ll ans=mult(d,n);
      ll a=x*mult(d,mod-2);
      a%=mod;
      ll b=a-1;
      a+=n-1;
      if(a/mod-b/mod>=1) ans=0;
      else{
        a%=mod;
        (ans*=d1[a])%=mod;
        (ans*=d2[b])%=mod;
      }
      cout<<ans<<endl;
    }
}

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

int dy[6] = {0, -1, -1, 0, 1, 1};
int dx[2][6] = {{-1,-1,0,1,0,-1},{-1,0,1,1,1,0}};
int a[110][110], f[110][110], w, h;

bool check(int y, int x){
	if(y < 0 || h+1 < y)return 1;
	if(x < 0 || w+1 < x)return 1;
	return 0;
}

int solve(int y, int x){
	if(check(y, x))return 0;
	if(a[y][x])return 1;
	if(f[y][x])return 0;
	f[y][x] = 1;
	
	int ans = 0;
	for(int i = 0;i < 6;i++){
		ans += solve(y+dy[i], x+dx[y%2][i]);
	}
	return ans;
}
int main(){
	scanf("%d%d", &w, &h);
	rrep(i,h)rrep(j,w)scanf("%d", &a[i][j]);
	
	int ans = solve(0, 0);
	/*for(int i = 0;i <= h+1;i++){
		for(int j = 0;j <= w+1;j++)printf("%d ", f[i][j]);
		printf("\n");
	}*/
	printf("%d\n", ans);
	return 0;
}
/*
8 4
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 0
1 0 1 0 1 1 1 1
0 1 1 0 1 0 1 0

8 5
0 1 1 1 0 1 1 1
0 1 0 0 1 1 0 0
1 0 0 1 1 1 1 1
0 1 0 1 1 0 1 0
0 1 1 0 1 1 0 0
*/


Measured memory_bytes: 3440
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    l[i].append(i+1)
l1 = sorted(l)

check = 0
count = 1
for i in range(m):
    if l1[i][0] != check:
        check = l1[i][0]
        count = 1
        l1[i].append(count)
    else:
        count += 1
        l1[i].append(count)
l1.sort(key = lambda x: x[2])
for i in range(m):
    print("{:0>6}{:0>6}".format(l1[i][0],l1[i][3]))


Measured memory_bytes: 36236
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  
  int N;
  while(cin >> N && N) {
    int *arr = new int[N];
    for(int i=0; i<N; i++) {
      cin >> arr[i];
    }
    
    int const S = 32;
    int now = S;
    int counter = 0;
    
    while(1) {
      now -= (now - 1) % 5;
      cout << now << endl;
      if(now == 1) break;
      now -= arr[counter%N];
      counter ++;
      cout << now << endl;
    }
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1188
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

a=int(input())
b=int(input())
h=int(input())

print(int((a+b)*h/2))






Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   //gpgpgpggpgpが最適？？
           string s;
           cin>>s;
           int n=s.size();
           int vic=0,los=0;
           rep(i,0,n){
             if(i%2==0){//gu-
               if(s[i]=='p')los++;
             }
             else{
               if(s[i]=='g')vic++;
             }
           }
           cout<<vic-los<<endl;
}

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

struct Com {
  int x, y, a;
};

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<Com> c(n);
  rep(i, n) cin >> c[i].x >> c[i].y >> c[i].a;

  vector<vector<bool>> r(w, vector<bool>(h, true));
  rep(i, n) {
    if (c[i].a == 1) {
      rep(j, c[i].x) {
        rep(k, h) {
          r[j][k] = false;
        }
      }
    }
    else if (c[i].a == 2) {
      FOR(j, c[i].x, w) {
        rep(k, h) {
          r[j][k] = false;
        }
      }
    }
    else if (c[i].a == 3) {
      rep(k, c[i].y) {
        rep(j, w) {
          r[j][k] = false;
        }
      }
    }
    else if (c[i].a == 4) {
      FOR(k, c[i].y, h) {
        rep(j, w) {
          r[j][k] = false;
        }
      }
    }
  }

  int ans = 0;
  rep(i, w) {
    rep(j, h) {
      if (r[i][j]) ans++;
    }
  }
  cout << ans << endl;


  
  return 0;
}

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

int main() {
  long long int n,k; cin >> n >> k;
  vector<int> a(n); for(long long int i = 0;i < n;i++) { cin >> a[i]; }

  int start,length = 0,point = 0,step = 0, mod;
  vector<int> scheck(n,-1); // start check

  if(k < n) {
    for(int i = 0;i < k;i++) { point = a[point]-1; }
    cout << point+1 << endl;
    return 0;
  }

  point = 0, step = 0;
  while(true) {
    if(scheck[point] == -1) { scheck[point] = step; point = a[point]-1; step++; }
    else if(scheck[point] >= 0) { start = point; step = scheck[point];  break; }
  } // start point and step for start

  length = 0;
  while(true) {
    length++;
    point = a[point]-1;
    if(point == start) { break; }
  } // loop length

  mod = (k-step)%length;

  point = start;
  for(int i = 0;i < length;i++) {
    if(i%length == mod) { break; }
    point = a[point]-1;
  } // solve

  cout << point+1 << endl;

  return 0;
}

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

n,k = mi()
r,s,p = mi()
t = input()
lt = len(t)

ans = 0

for i in range(k):
    idx = i
    dp = [[0]*3 for j in range((n//k)+1)]
    if t[idx] == 'r': dp[0][2] = p
    elif t[idx] == 's': dp[0][0] = r
    elif t[idx] == 'p': dp[0][1] = s

    for j in range(1,n+1):
        idx += k
        if idx > lt-1:
            ans += max(dp[j-1])
            break

        ot = t[idx]
        if ot == 'r': 
            dp[j][2] = p + max(dp[j-1][0], dp[j-1][1])
            dp[j][0] = max(dp[j-1][1], dp[j-1][2])
            dp[j][1] = max(dp[j-1][0], dp[j-1][2])
        elif t[idx] == 's':
            dp[j][0] = r + max(dp[j-1][1], dp[j-1][2])
            dp[j][1] = max(dp[j-1][0], dp[j-1][2])
            dp[j][2] = max(dp[j-1][0], dp[j-1][1])
        elif t[idx] == 'p':
            dp[j][1] = s + max(dp[j-1][0], dp[j-1][2])
            dp[j][0] = max(dp[j-1][1], dp[j-1][2])
            dp[j][2] = max(dp[j-1][0], dp[j-1][1])

print(ans)


Measured memory_bytes: 16420
#include <bits/stdc++.h>
using namespace std;
int maxl = -10000000;
int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		maxl = max(a[i], maxl);
	}
	if (n % 2 == 1) {
		cout << 0 << endl;
	}
	sort(a, a + n);
	int res = a[n / 2] - a[n / 2 - 1];
	cout << res << endl;
}

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

int main() {
  long A, B, C;

  std::cin >> A;
  std::cin >> B;
  std::cin >> C;

  std::vector<long> seq{A, B, C};
  std::sort(seq.begin(), seq.end());

  long diff21 = seq[2] - seq[1];
  long diff10 = seq[1] - seq[0];

  long ans = diff21;
  ans += diff10 / 2;
  ans += diff10 % 2 == 1 ? 2 : 0;

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

  return 0;
}


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

const int MAXN = 2005;
const ll Mod = 1e9+7;
ll dp[MAXN][MAXN];
int N, M;
int S[MAXN], T[MAXN];

void solve() {
  for (int i = N-1; i >= 0; --i) {
    for (int j = M-1; j >= 0; --j) {
      dp[i][j] += dp[i+1][j] + dp[i][j+1];
      dp[i][j] += (S[i] == T[j]) ? 1 : -dp[i+1][j+1];
      dp[i][j] = (dp[i][j] + Mod) % Mod;
    }
  }
  ll ans = (dp[0][0]+1) % Mod;
  cout << ans << endl;
}

int main() {
  cin >> N >> M;
  rep(i, N) cin >> S[i];
  rep(i, M) cin >> T[i];
  solve();
  return 0;
}



Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    int n,m; cin >> n >> m;
    vector<int> road(n,0);
    rep(i,m){
        int a,b; cin >> a >> b;
        road[a-1]++; road[b-1]++;
    }
    rep(i,n){
        cout << road[i] << endl;
    }
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 510;
bool flag[maxn * maxn] = {0};
long long p[maxn * maxn];
int cnt = 0;
void init(int n)
{
	for(int i = 2; i <= n; i ++)
	{
		if(!flag[i])
		{
			flag[i] = 1;
			p[++ cnt] = i;
		}
		for(int j = 1; j <= cnt && p[j] * i <= n; j ++)
		{
			flag[p[j] * i] = 1;
			if(i % p[j] == 0)
				break;
		}
	}
}
int n;
long long v[maxn][maxn];
long long gcd(long long a, long long b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
bool in(int x, int y)
{
	return x > 0 && x <= n && y > 0 && y <= n;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	if(n == 2)
	{
		cout << "4 7" << endl;
		cout << "23 10" << endl;
		return 0;
	}
	init(500 * 500);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if((i + j) % 2 == 0)
				v[i][j] = p[(i + j) / 2];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if((i + j) % 2 == 0)
				v[i][j] *= p[(n - i + j + n * 2) / 2 + 1];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if((i + j) % 2 == 1)
			{
				for(int k = 0; k < 4; k ++)
				{
					int x = i + dir[k][0], y = j + dir[k][1];
					if(in(x, y))
					{
						if(v[i][j] != 0)
							v[i][j] = v[i][j] * (v[x][y] / gcd(v[i][j], v[x][y]));
						else
							v[i][j] = v[x][y];
					}
				}
				v[i][j] ++;
			}
	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= n; j ++)
			cout << v[i][j] << " ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	reus;
	long long int a,b,sum=0;
	cin>>a>>b;
	int i;
	sum=a+b;
	if(sum%2==0)
	{
		cout<<sum/2<<endl;
	}
	else
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
using namespace std;
int main() {
    vector<array<int, 2>> v;
    while (true) {
        int H, W;
        cin >> H >> W;
        if (H < 1 && W < 1) break;
        v.push_back(array<int, 2> { H, W });
    }
    
    for (auto a : v) {
        int H = a[0];
        int W = a[1];
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (i % 2 == 0) {
                    if (j % 2 == 0) {
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                } else {
                    if (j % 2 == 0) {
                        cout << ".";
                    } else {
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3104
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class AAddtion
    {
        public static void Main(string[] args)
        {
            new AAddtion().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var n = cin.ReadInt;
            var dict = new Dictionary<int, int>();

            for (int i=0; i<n; i++){
                var tmp = cin.ReadInt;
                
                if(dict.ContainsKey(tmp)){
                    dict[tmp]++;
                
                }else{
                    dict[tmp] = 1;
                }
            }
            
            var ans = dict.Values.Count(c => c%2 != 0);

            WriteLine(ans);
        }
    }
}
public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

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


int main(){
    ll X,K,D; cin >> X >> K >> D;
    X = abs(X);
    ll mi0=INF,mi1=INF;

    if(X/D>=K){
        cout << X-D*K << endl;
        return 0;
    }
    mi0 = X%D; mi1 = abs(mi0-D);
    if((K-X/D)%2==0){
        cout << mi0 << endl;
    }else cout << mi1 << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#define INF 2e+9
using namespace std;

int main(){
	int n,x[100001],l,q,next[100000][20];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> x[i];
	x[n] = INF;
	cin >> l >> q;
	for(int i = 0;i < n;i++){
		next[i][0] = upper_bound(x,x + n + 1,x[i] + l) - x - 1;
	}
	for(int i = 1;i < 20;i++){
		for(int j = 0;j < n;j++){
			next[j][i] = next[next[j][i - 1]][i - 1];
		}
	}
	for(int i = 0;i < q;i++){
		int a,b,res = 0;
		cin >> a >> b;a--;b--;
		if(a > b){
			int t = a;
			a = b;
			b = t;
		}
		for(int i = 19;i >= 0;i--){
			if(next[a][i] < b){
				res += (1 << i);
				a = next[a][i];
			}
		}
		cout << res + 1 << endl;
	}
	return 0;
}

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

int main()
{
    string s;
    cin >>s;
    int n = s.size();
    bool judge = true;
    if (n == 3 && s.at(0) != s.at(2)){
        judge = false;
    }
    else{
        vector<char> a((n - 1) / 2), b((n - 1) / 2);
        for (int i = 0; i < (n - 1) / 2; i++) {
            a.at(i) = s.at(i); 
        }
        for (int i = 0; i < (n - 1) / 2; i++){
            b.at(i) = s.at(i + (n + 1) / 2);
        }
        for (int i = 0; i < a.size(); i++){
            if (a.at(i) != a.at(a.size() - i - 1)){
                judge = false;
                break;
            }
        }
        if (judge){
            for (int i = 0; i < b.size(); i++)
            {
                if (b.at(i) != b.at(b.size() - i - 1))
                {
                    judge = false;
                    break;
                }
            }
        }
        if (judge) {
            for (int i = 0; i < n; i++) {
                if (s.at(i) != s.at(n - i -1)){
                    judge = false;
                    break;
                }
            }
        }
    }
    if (judge){
        cout <<"Yes" <<endl;
    }
    else{
        cout <<"No" <<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int jadge(int n);

int main(){
  int n, a, b, sum=0, total=0;
  cin >> n >> a >> b;

  for(int i=1; i<=n; i++){
    sum = jadge(i);
    if(a <= sum && sum <= b)  total += i;
  }
  cout << total << endl;
}

int jadge(int n){
  int sum = 0;
  while (n>0){
     sum += n % 10;
     n /= 10;
  }
  return sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << (P + Q + R - max({P, Q, R})) << endl;
}


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

using namespace std;

set<string> ans;
int n;
string s;
vector<set<string>> memo;

void dfs(int i, string t){
    if (t.length() == 3){
        ans.insert(t);
        return;
    }
    if (i == n)
        return;
    if (memo[i].count(t)){
        return;
    }
    memo[i].insert(t);
    dfs(i + 1, t + s[i]);
    dfs(i + 1, t);
}

int main(){
    cin >> n;
    cin >> s;
    memo.resize(n);
    dfs(0, "");

    cout << ans.size() << endl;
}

Measured memory_bytes: 161536
S = int(input())
A=[]
A.append(int(S/1000))
A.append(int((S-A[0]*1000)/100))
A.append(int((S-A[0]*1000-A[1]*100)/10))
A.append(int((S-A[0]*1000-A[1]*100-A[2]*10)))
if (A[0]!=A[1] and A[1]!=A[2] and A[2]!=A[3]):
    print('Good')
else:
    print('Bad')

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BBeautifulStrings {
public:
    void solve(std::istream &in, std::ostream &out) {
        string str;
        in >> str;
        vector<bool> counter(26);
        trav(c, str) {
            counter[c - 'a'] = not counter[c - 'a'];
        }
        bool res = count(all(counter), true) == 0;
        out << (res ? "Yes" : "No") << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BBeautifulStrings solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int h,w;
   cin >> h >> w;
   vector<vector<char>> c(h,vector<char>(w));
   rep(i,h){
     rep(j,w){
       cin >> c.at(i).at(j);
     }
   }
   vector<vector<char>>  cc(2*h,vector<char>(w));
   rep(i,2*h){
     rep(j,w){
       cc.at(i).at(j)=c.at(i/2).at(j);
     }
   }
    rep(i,2*h){
     rep(j,w){
       cout << cc.at(i).at(j);
     }
     cout << endl;
   }
}

Measured memory_bytes: 3668
#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string S; int n;
    
    set<string> T;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> S;
        
        if(i % 20 == 0 || i % 20 == 1 || i % 20 == 2)
        {
            printf("1\n");
        }
        else
        {
            T.clear();
            
            for(int j = 1; j < S.size(); j++)
            {
                string A = S.substr(0, j);
                string B = S.substr(j, S.size() - j);
                
                string C = A; reverse(C.begin(), C.end());
                string D = B; reverse(D.begin(), D.end());
                
                T.insert(A + B);
                T.insert(B + A);
                T.insert(A + D);
                T.insert(D + A);
                T.insert(C + B);
                T.insert(B + C);
                T.insert(C + D);
                T.insert(D + C);
            }
            
            printf("%d\n", T.size());
        }
    }
    
    return 0;
}

Measured memory_bytes: 3264
from sys import stdin
from math import log10
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()
n,a,b = [tmp.pop(0) for _ in range(3)]

ans = 0

for i in range(1,n+1):
    tmp = i
    x = 0
    for _ in range(int(log10(i)+1)):
        d = tmp%10    
        x+=d
        tmp-=d
        tmp = tmp//10
    if a<=x and x<=b:
        ans+=i
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long K = long.Parse(str[1]);
		long[]P = new long[200010];
		long[]NP = new long[200010];
		long mod = 1000000007;
		P[0]=1;
		NP[0]=1;
		for(var i=1;i<200010;i++){
			P[i] = P[i-1]*i%mod;
			NP[i] = NP[i-1]*Mpow(i,mod-2,mod)%mod;
			//Console.Error.WriteLine(P[i]+" "+NP[i]);
		}
		long ans = 0;
		for(var i=0;i<=Math.Min(K,N-1);i++){
			long a1 = P[N-1]*NP[N-1-i]%mod*NP[i]%mod;
			long a2 = P[N]*NP[N-i]%mod*NP[i]%mod;
			ans = (ans + a1 * a2) % mod;
		}
		Console.WriteLine(ans);
	}
	
	public static long Mpow(long x,long n,long m)
	{
		long ans = 1;
		while(n > 0){
			if(n % 2 == 1){
				ans = ans * x % m;
				n -= 1;
			}
			x = x * x % m;
			n /= 2;
		}
		return ans;
	}
	public static long Ncr(long n,long r,long m)
	{
		long ans = 1;
		for(var i=n-r+1;i<=n;i++){
			ans = ans * i % m;
		}
		for(var i=2;i<=r;i++){
			ans = ans * Mpow(i,m-2,m) % m;
		}
		return ans;
	}
}

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[100010],ru[100010],ans=-1e18,t=0;

void init(){
	cin>>n;
	reg(i,1,n)cin>>a[i];
	reg(i,1,n)if(a[i]<0)t++;
	ru[0]=0;
	reg(i,1,n)ru[i]=ru[i-1]+abs(a[i]);
}

int main(void){
	init();
	if(t%2==0){
		ans=ru[n];
	}else{
		reg(i,1,n){
			ans=max({ans,ru[n]-2*abs(a[i])});
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1920
n = int(input())
a_list = list(map(int, input().split()))
a_list_0 = [0] + a_list + [0]
s = sum([abs(a_list_0[i + 1] - a_list_0[i]) for i in range(n + 1)])
for i in range(1, n + 1):
    note = s - (abs(a_list_0[i] - a_list_0[i - 1]) + abs(a_list_0[i] - a_list_0[i + 1]))
    note += abs(a_list_0[i + 1] - a_list_0[i - 1])
    print(note)

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

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


int main(){

    ll n,m;
    cin >> n >> m;
    priority_queue<double, vector<double>, less<double> > q;
    rep(i,n){
        double tmp;
        cin >> tmp;
        q.push(tmp);
    }

    rep(i,m){
        double tmp;
        tmp = q.top();
        q.pop();
        tmp /= 2;
        q.push(tmp);
    }

    ll ans = 0;
    rep(i,n){
        ans += (ll)q.top();
        q.pop();
    }

    cout << ans << endl;

    return 0;
}  

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

using namespace std;
typedef vector<long long int> Row;
typedef vector<Row> Matrix;

Matrix ScanMatrix(int n, int m)
{
    Matrix matrix(n, Row(m));
    for(int r = 0; r < n; ++r){
        for(int c = 0; c < m; ++c){
            cin >> matrix[r][c];
        }
    }
    return matrix;
}
long long int GetElement(const Matrix& a, const Matrix& b, int r, int c)
{
    int s = a[r].size();
    long long int result = 0;
    for(int i = 0; i < s; ++i){
        result += a[r][i] * b[i][c];
    }
    return result;
}
Matrix ProductMatrix(const Matrix& a, const Matrix& b)
{
    int n = a.size();
    int m = b[0].size();
    Matrix matrix(n, Row(m));
    for(int r = 0; r < n; ++r){
        for(int c = 0; c < m; ++c){
            matrix[r][c] = GetElement(a, b, r, c);
        }
    }
    return matrix;
}
void PrintMatrix(const Matrix& a)
{
    int n = a.size();
    for(int r = 0; r < n; ++r){
        int m = a[r].size();
        for(int c = 0; c < m; ++c){
            if(c){
                cout << " ";
            }
            cout << a[r][c];
        }
        cout << endl;
    }
}
int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    Matrix A = ScanMatrix(n, m);
    Matrix B = ScanMatrix(m, l);
    Matrix C = ProductMatrix(A, B);
    PrintMatrix(C);
    return 0;
}

Measured memory_bytes: 3284
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	x := scanInt()
	fmt.Fprintln(wr, 360*x/gcd(360, x)/x)
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}


Measured memory_bytes: 1772
#include <cstdio>
#include <cstring>

int l[40];

bool check(int *p, int n) {
  int i;
  for (i=0;i<n;i+=l[(*p)++]);
  return (i == n);
}

int main() {
  int n;
  while (scanf("%d", &n), n!=0) {
    for (int i=0;i<n;i++) {
      char s[11];
      scanf("%s", s);
      l[i] = strlen(s);
    }
    for (int i=0;i<n-4;i++) {
      int p = i;
      if (!check(&p, 5)) continue;
      if (!check(&p, 7)) continue;
      if (!check(&p, 5)) continue;
      if (!check(&p, 7)) continue;
      if (!check(&p, 7)) continue;
      printf("%d\n", i+1);
      break;
    }
  }
  return 0;
}

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

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";
constexpr LL none = -1e15; 
LL a[2123];
LL dp[2123][2];
LL g(int i,int t);
LL f(int i,int t){
    LL& ret = dp[i][t]; 
    if(ret!=none)return ret;
    ret = abs(a[0] - a[i]);
    FOR(j,1,i)chmax(ret,g(j,1-t));
    return ret;
}
LL g(int i,int t){
    LL& ret = dp[i][t]; 
    if(ret!=none)return ret;
    ret = abs(a[0] - a[i]);
    FOR(j,1,i)chmin(ret,f(j,1-t));
    return ret;
}


int main(){
    int N;
    cin>>N;
    cin>>a[N+1];
    cin>>a[N];
    REP(i,N)cin>>a[i];
    reverse(a,a+N);
    REP(i,N+10)REP(k,2)dp[i][k]=none;
    cout<<f(N,0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

struct edge{ int to,cost;};
vector<vector<edge> > g;
int sum = 0, ma = 0;

void dfs(int now, int par, int d){
    ma = max(ma, d);
    rep(i,g[now].size()){
        int ne = g[now][i].to;
        if(ne == par)continue;
        int cost = g[now][i].cost;
        if(g[ne].size() > 1){
            sum += cost*2;
            dfs(ne, now, d+cost);
        }
    }
}

signed main(void) {
    int n;
    while(cin >> n,n){
        vi p(n-1),d(n-1);
        rep(i,n-1)cin >> p[i];
        rep(i,n-1)cin >> d[i];
        g = vector<vector<edge> > (n);
        int ans = 0;
        rep(i,n-1){
            ans += d[i];
            p[i]--;
            edge e1 = {i+1,d[i]}, e2 = {p[i],d[i]};
            g[p[i]].push_back(e1);
            g[i+1].push_back(e2);
        }
        int tmp = INF;
        rep(i,n){
            sum = ma = 0;
            dfs(i,-1,0);
            tmp = min(tmp, sum-ma);
        }
        cout << ans + tmp << endl;
    }
}



Measured memory_bytes: 3328
class uf_tree:
    def __init__(self, n):
        self._size = n
        self.sizes = [1] * n
        self.par = list(range(n))
 
    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
 
    def unite(self, x, y):
        self._size -= 1
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def size(self, x):
        return self.sizes[self.find(x)]


n, m = map(int, input().split())
p = [ int(x) for x in input().split() ]

uf = uf_tree(n+5)

for _ in range(m):
    x, y = map(int, input().split())
    uf.unite(x, y)    

ans = 0

for item_id, item in enumerate(p):
    if uf.same(item, item_id+1):
        ans += 1

print(ans)

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

int main() {
  int H, W, N;
  cin >> H >> W >> N;

  using P = pair<int, int>;
  auto valid = [&](auto i, auto j) {return 0 <= i && i < H-2 && 0 <= j && j < W-2;};
  auto next = [&](auto i, auto j) {
    vector<P> r;
    for(auto y: {i-2,i-1,i}) for(auto x: {j-2,j-1,j}) if(valid(y,x)) r.emplace_back(y,x);
    return r;
  };
  map<P, int> memo;
  for(auto i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    for(auto p: next(a, b)) ++memo[p];
  }

  using LL = long long;
  vector<LL> sum(10);
  for(auto i: memo) ++sum[i.second];
  for(auto i: sum) sum[0] -= i;
  sum[0] += LL(H-2)*LL(W-2);
  for(auto i: sum) cout << i << endl;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl;
#define pv(v) for(auto a: v){ cout << a << endl; }

int main() {
  string s; cin >> s;
  int m, b; m = 0; b = 0;

  rep(i, s.size()) {
    if (s[i] == 'o') {
      m++;
    } else {
      b++;
    }
  }

  if (m + 15 - (m+b) >= 8) {
    p("YES")
  } else {
    p("NO")
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;
vector < ll > graph[100001];

void solve() {
    ll n, m, i, j, k, a[100001], ans=0;
    cin>>n>>m;
    fo(i,n+1)graph[i].clear();
    Fo(i,1,n+1)cin>>a[i];
    fo(i,m) {
        cin>>j>>k;
        graph[j].pb(k);
        graph[k].pb(j);
    }
    Fo(i,1,n+1) {
        bool stat = true;
        for(auto x:graph[i]) {
            if(a[x]>=a[i]){stat=false;break;}
        }
        if(stat)ans++;
    }
    cout<<ans;
}   

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}


Measured memory_bytes: 10268
import itertools

N,M,X=map(int,input().split())
C=[]*N


A=[]
seq=[]
for i in range(N):
    A.append(list(map(int,input().split())))
    seq.append(i)
rikai=[0 for i in range(M+1)]

min=-1
count=0


for i in range(1,N+1):
    kumi=list(itertools.combinations(seq,i))
    #print(kumi)
    for j in kumi:

        for n in list(j):

            for k in range(M+1):
                rikai[k]=A[n][k]+rikai[k]

        for k in range(1,len(rikai)):
            if(X<=rikai[k]):

                count=count+1

            rikai[k]=0
        if(count==len(rikai)-1):

            if(rikai[0]<min or min==-1):
                min=rikai[0]

        rikai[0]=0
        count=0
print(min)


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

int k[10] = {};
int sum[11][331] = {};

int conbination(int n, int s) {
    int S;
    if(n == 11) return 0;
    for(int i = 0; i < 10; ++i) {
        if(k[i]) continue;
        k[i] = 1;
        S = s + n * i;
        ++sum[n][S];
        conbination(n + 1, S);
        k[i] = 0;
    }
    return 0;
}

int main(void) {
    conbination(1, 0);
    
    int n, s;
    
    while(cin >> n >> s) {
        if(s > 330) s = 0;
        cout << sum[n][s] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int d, n;
    cin >> d >> n;
    n = n * 2 + 1;
    int ans = d / n;
    if (d % n != 0) {
        ans++;
    }

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

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
def main():
    s = input()
    t = input()

    s = sorted(s)
    t = sorted(t)[::-1]

    N = len(s)
    M = len(t)

    if N < M:
        if s == t[:N]:
            print('Yes')
            return
    N = min(N, M)
    i = 0
    while i < N and s[i] == t[i]:
        i += 1
    if i < N and s[i] < t[i]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


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

int main() {
    int64_t X, A, B;
    cin >> X;
    for (int64_t i = 0; i < 3000; i++) {
        for (int64_t j = 0; j < 1000 ; j++) {
            if (pow(i, 5) - pow(j, 5) == X) {
                cout << i << " " << j << endl;
                return 0;
            } else if (pow(i, 5) + pow(j, 5) == X) {
                cout << i << " " << - j << endl;
                return 0;
            } else if (- pow(i, 5) + pow(j, 5) == X) {
                cout << - i << " " << - j << endl;
                return 0;
            } else if (- pow(i, 5) - pow(j, 5) == X) {
                cout << - i << " " << j << endl;
                return 0;
            }
        }        
    }
    
}


Measured memory_bytes: 3968
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    ll x,k,d;
    cin>>x>>k>>d;
    ll time = abs(x)/d;
    ll yv = x%d;
    ll res=0;
    if(time>k)
    {
        if(x<0)
            res=x+k*d;
        else
            res=x-k*d;
    }
    else{
        
        ll shenyu=k-time;
        if(shenyu%2==0)
        {
            res=yv;
        }
        else
        {
            if(abs(yv+d)>abs(yv-d))
                res = abs(yv-d);
            else
                res = abs(yv+d);
        }
        
    }
    cout<<abs(res)<<endl;
    
    
    
}


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

int main()
{

	int H, W;

	while( cin >> H >> W, H || W ) {

		for( int i = 0; i < H; i++ ) {
			for( int j = 0; j < W; j++ ) {

				if( i == 0 || i == H - 1 || j == 0 || j == W - 1 ) cout << "#";
				else cout << ".";

			}
			cout << endl;
		}

		cout << endl;

	}

	return 0;

}

Measured memory_bytes: 1152
N, K = map(int, input().split())
S = input()
LR = {'L':'R', 'R':'L'}
indices = []
T = []
for i in range(N-1):
    s = S[i:i+2]
    base = S[i]+LR[S[i]]
    if s == base:
        indices.append(S[i:].index(base)+i+1)
i = 0
for j in indices:
    T.append(S[i:j])
    i = j
T.append(S[i:])
cnt = 0
for i, t in enumerate(T):
    if i % 2 == 0:
        continue
    T[i] = LR[t[0]]*len(t)
    cnt += 1
    if cnt == K:
        break

T = ''.join(T)
ans = 0
for i in range(N-1):
    t = T[i:i+2]
    if t in ['RR', 'LL']:
        ans += 1
print(ans)

Measured memory_bytes: 7904
n = input()

a = int(n[0]+n[1])
b = int(n[2]+n[3])
if b == 0 or b > 12:
	if 1 <= a <= 12:
		print("MMYY")
	else:
		print("NA")
elif 1 <= a <= 12:
	print("AMBIGUOUS")
else:
	print("YYMM")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--;
    v--;
    vector<vector<int>> g(n);
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> dist1(n, -1);
    dist1[u] = 0;
    queue<int> que1;
    que1.push(u);
    while (!que1.empty()) {
        int now = que1.front();
        que1.pop();
        for (int next : g[now]) {
            if (dist1[next] != -1) continue;
            dist1[next] = dist1[now] + 1;
            que1.push(next);
        }
    }

    vector<int> dist2(n, -1);
    dist2[v] = 0;
    queue<int> que2;
    que2.push(v);
    while (!que2.empty()) {
        int now = que2.front();
        que2.pop();
        for (int next : g[now]) {
            if (dist2[next] != -1) continue;
            dist2[next] = dist2[now] + 1;
            que2.push(next);
        }
    }

    int ans = 0;
    rep(i, 0, n) {
        if (dist1[i] < dist2[i]) ans = max(ans, dist2[i]);
    }
    cout << max(0, ans - 1) << endl;
    return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
bool sr(int a,int b){
    return a>b;
}

int main(){
    int n;
    cin>>n;
    vector<int>num(n*3);
    rep(i,n*3)cin>>num[i];
    sort(all(num),sr);
    ll ans=0;
    rep(i,n*2){
        //cout<<num[i]<<endl;
        if(i%2!=0){
            ans+=num[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408