akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

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

int main()
{
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  // lli d, e, f, h, k, n, w, q, ans = 0, count = 0;
  // string s, t;
  // cin >> q;
  // int l, r;
  // int re[1000010];
  // rep(i, 0, q)
  // {
  //   cin >> l >> r;
  //   ans = 0;
  //   vi b(r - l + 1);
  //   rep(i, 0, b.size())
  //   {
  //     b[i] = l;
  //     if (is_prime(b[i]) && is_prime((b[i] + 1) / 2))
  //       ans++;
  //     l++;
  //   }
  //   re[i] = ans;
  // }
  // rep(i, 0, q)
  // {
  //   cout << re[i] << endl;
  // }
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli d, e, f, h, k, n, w, q, ans = 0, count = 0;
  string s, t;
  cin >> q;
  int l, r;
  int re[1000010];

  // ◆素数判定(エラトステネスの篩)
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i)
  {
    if (!is_prime[i])
      continue;
    for (int j = i * 2; j < MAX; j += i)
      is_prime[j] = 0;
  }

  vi res(MAX, 0);
  rep(i, 0, MAX)
  {
    if (i % 2 == 0)
      continue;
    if (is_prime[i] && is_prime[(i + 1) / 2])
    {
      res[i] = 1;
    }
  }

  vi z(MAX + 1, 0);
  rep(i, 0, MAX)
  {
    z[i + 1] = z[i] + res[i];
  }
  rep(i, 0, q)
  {
    cin >> l >> r;
    r++;
    cout << z[r] - z[l] << endl;
  }
}

Measured memory_bytes: 1792
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

int main(){
    llong N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    S[K-1] = S[K-1] - 'A' + 'a';
    cout << S;
}

Measured memory_bytes: 3100
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10 , mod = 1e9 + 7;
long long a[N];
int n , m;
int main(){
	long long res = mod;
	cin >> a[0] >> a[1] >> a[2]; a[3] = a[0];
	for(int i = 0; i < 3; i ++)
		res = min(res , a[i] + a[i + 1]);
	cout << res << "\n";
}

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

bool is_biparate(const vector<vector<int>>& G, vector<int>& color) {
    queue<int> q;
    color.resize(G.size());
    color[0] = 1; // 0: undef, 1: black, 2: white
    REP(i, G[0].size()) {
        q.push(G[0][i]);
        color[G[0][i]] = 2;
    }

    while (!q.empty()) {
        int p = q.front();
        q.pop();
        REP(i, G[p].size()) {
            int t = G[p][i];
            if (color[p] == color[t]) {
                return false;
            }
            if (color[t] != 0) continue;
            q.push(t);
            color[t] = color[p] == 1 ? 2 : 1;
        }
    }
    return true;
}

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

    int N, M;
    cin >> N >> M;

    vector<vector<int>> G(N);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> color;
    if (is_biparate(G, color)) {
        int b = 0;
        int w = 0;
        REP(i, color.size()) {
            color[i] == 1 ? b++ : w++;
        }
        cout << b * w - M << endl;
    } else {
        int total = N * (N - 1) / 2;
        cout << total - M << endl;
    }
    return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int fact(int n) 
{ 
    return (n <= 1) ? 1 : n * fact(n - 1); 
}
int utility_1(int arr[], int low, int high) 
{ 
    int countRight = 0, i; 
  
    for (i = low + 1; i <= high; ++i) 
        if (arr[i] < arr[low]) 
            ++countRight; 
  
    return countRight; 
} 
int get_rank(int arr[], int n) 
{ 
    int len = n; 
    int mul = fact(len); 
    int rank = 1; 
    int countRight; 
  
    int i; 
    for (i = 0; i < len; ++i) { 
        mul /= len - i; 
        countRight = utility_1(arr, i, len - 1); 
  
        rank += countRight * mul; 
    } 
  
    return rank; 
} 
int main()
{
	SPEED
	int n;
	cin >> n;
	int P[n], Q[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> P[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> Q[i];
	}

    cout << abs(get_rank(P, n)-get_rank(Q, n));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main(){
	double a,s;
	while(cin>>a){
		s=a;
		for(int i=1;i<10;i++){
			if(i%2==1){
				s+=a*2;
				a*=2;
			}
			if(i%2==0){
				s+=a/3;
				a/=3;
			}
		}
		cout<<fixed<<setprecision(10)<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include<stdio.h>

#define NUM 0
#define APIECE 1 //単価
#define QUANT 2 //数量
#define RESULT 3 //販売実績

void initialize(int array[][4], int n);
void calculate(int array[][4], int n);
void output(int array[][4], int n);

main()
{
	int n = 0, i = 0;
	while(scanf("%d", &n), (n != 0))
	{
		//scanf("\n");
		//printf("n = %d\n", n);
		int menber[n][4];
		initialize(menber, n);
		for(i = 0; i < n; i++)
		{
			scanf("\n");
			scanf("%d %d %d", &menber[i][NUM], &menber[i][APIECE], &menber[i][QUANT]);
		}
		/*
		int j = 0;
		for(i = 0; i < n; i++)
		{
			for(j = 0; j < 4; j++)
			{
				printf("%d ", menber[i][j]);
			}
			puts("");
		}
		*/
		calculate(menber, n);
		output(menber, n);
	}
	
	return 0;
}
void initialize(int array[][4], int n)
{
	int i = 0, j = 0;
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < 4; j++)
		{
			array[i][j] = 0;
		}
	}
}
void calculate(int array[][4], int n)
{
	int i = 0, j = 0;
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < array[i][QUANT]; j++)
		{
			array[i][RESULT] += array[i][APIECE];
			if(array[i][RESULT] >= 1000000)
			{
				break;
			}
		}
	}
	for(i = 0; i < n; i++)
	{
		for(j = i + 1; j < n; j++)
		{
			if(array[i][NUM] == array[j][NUM])
			{
				array[i][RESULT] += array[j][RESULT];
				array[j][RESULT] = 0;
			}
		}
	}
	/*
	for(i = 0; i < n; i++)
	{
		printf("array[%d][NUM] = %d array[%d][RESULT] = %d\n", i, array[i][NUM], i, array[i][RESULT]);
	}
	*/
}
void output(int array[][4], int n)
{
	int i = 0, flag = 0;
	for(i = 0; i < n; i++)
	{
		if(1000000 <= array[i][RESULT])
		{
			printf("%d\n", array[i][NUM]);
			flag++;
		}
	}
	if(flag == 0)
	{
		printf("NA\n");
	}
}

Measured memory_bytes: 628
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
struct seg {
	int l,r;
	friend bool operator <(seg A,seg B) {
//		if(A.l==B.l) return A.r>B.r;
		return A.l>B.l;
	}
}s[N],a[N];
int n,m;
int main() {
	rd(n);
	int q=1,p=1;
	for(int i=1;i<=n;++i) {
		rd(s[i].l),rd(s[i].r);
		if(s[i].l>s[p].l||s[i].l==s[p].l&&s[i].r>s[p].r) p=i;
		if(s[i].r<s[q].r||s[i].r==s[q].r&&s[i].l<s[q].l) q=i;
	}
//	cout<<p<<' '<<q<<endl;
	int ans=0;
	for(int i=1;i<=n;++i)
		if(i!=p&&i!=q) ans=max(ans,s[i].r-s[i].l+1);
	ans+=max(0,s[q].r-s[p].l+1);
	if(p!=q) {
		for(int i=1;i<=n;++i) if(i!=p&&i!=q) {
			s[i].l=max(s[i].l,s[q].l+1);
			s[i].l=min(s[i].l,s[q].r+1);
			s[i].r=min(s[i].r,s[p].r);
			s[i].r=max(s[i].r,s[p].l-1);
			a[++m]=s[i];
		}
		sort(a+1,a+m+1);
		a[m+1].l=s[q].l;
		int mi=s[p].r;
		ll tmp=-s[p].l+s[q].r+2;
		for(int i=0;i<=m;++i) {
			if(i) mi=min(mi,a[i].r);
//			cout<<i<<' '<<tmp<<' '<<mi<<' '<<a[i+1].l<<' '<<tmp+mi-a[i+1].l<<endl;
			ans=max((long long)ans,tmp+mi-a[i+1].l);
		}
	}
	printf("%d",ans);
	return 0;
}

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

const int M = 111;
char s[M];

int main () {
    while (scanf("%s", s) == 1) {
        int n = strlen(s);
        int isSPal = 1;
        for (int i = 0; i < n / 2; i++) isSPal &= s[i] == s[n - 1 - i];
        
        int m = n / 2;
        for (int i = 0; i < m; i++) isSPal &= s[i] == s[m - 1 - i];

        printf(isSPal ? "Yes\n" : "No\n");
    }
}


Measured memory_bytes: 256
//Power Socket

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)

int main(){
    double a, b;
    cin >> a >> b;
    b -= 1;
    cout << ceil(b / (a - 1)) << endl;
}

Measured memory_bytes: 3724
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, M;
  cin >> N >> M;

  vector<int32_t> lookup(N + 1, -1);
  bool is_okay = true;
  for (int32_t i = 0; i < M; ++i) {
    int32_t s, c;
    cin >> s >> c;
    if (lookup[s] >= 0 && lookup[s] != c) {
      is_okay = false;
      break;
    } else if (N > 1 && s == 1 && c == 0) {
      is_okay = false;
      break;
    } else if (s > N) {
      is_okay = false;
      break;
    } else {
      lookup[s] = c;
    }
  }
  if (is_okay) {
    for (int32_t i = 1; i <= N; ++i) {
      if (lookup[i] > 0) {
        cout << lookup[i];
      } else {
        if (i == 1 && N > 1) {
          cout << 1;
        } else {
          cout << 0;
        }
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


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

int main(void){
	int N;
	cin >> N;
	for (int n = 1; n <= N; n++) {
		int ans = 0;
		int x;
		//int max_i = floor(sqrt(n/6.));
		for (int i = 1; i <= n; i++) {
			x = 6*i*i;
			if (x > n) break;
			for (int j = i; j <= n; j++) {
				x = i*i + 2*i*j + 3*j*j;
				if (x > n) break;
				for (int k = j; k <= n; k++) {
					x = i*i + j*j + k*k + i*j + j*k + k*i;
					if (x < n) continue;
					if (x > n) break;

					if (i==j and j==k) ans += 1;
					if (i==j and j!=k) ans += 3;
					if (i!=j and j==k) ans += 3;
					if (i!=j and j!=k) ans += 6;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll k;
vector<ll> v;

int main(void) {
    cin >> k;
  
    for(ll i=1; i<=9; i++) {
        v.pb(i);
    }

    int i = 0;
    for(int c=0; c<=k+5;c++) {
        ll t = v[i];
        string s = to_string(t);
        ll d = s[(int)s.size()-1]-'0';
        
        for (ll j=d-1; j<=d+1; j++) {
            if (j>=0 && j<=9) {
                v.pb(t*10+j);
            }
        }
        i++;
    }

    ll ans = v[k-1];

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6512
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		if(K==1){
			System.out.println("0");
        }else{
			System.out.println(N-K);
        }
	}
}


Measured memory_bytes: 35624
#include <cstdlib>
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define RS(T) sort(T.rbegin(),T.rend())
#define BS(T, x) binary_search (T.begin(), T.end(), x)
#define U unsigned
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,d,x,a,b;
    cin >>n>>d>>x;
    ll s=x;
    for (int i =0;i<n;i++) {
        cin >>a;
        int j=0;
        while (j*a+1 <= d) {
            s++;
            j++;
        }
    }
    cout <<s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a, b;
void solve()
{
    cin >> a >> b;
    for(int i=1; i<=max(a, b); i++)
    {
        if(abs(a-i)==abs(b-i)){
            cout << i << endl;
            return;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return;
}
int main ()
{
   // FasterIO;
    #ifdef _online
    input
    //output
    #endif // _online
    solve();
}


Measured memory_bytes: 256
nu = gets.to_i
array = gets.chomp.split(' ').map(&:to_i)
count1 = []
count2 = []
(0..nu - 1).each do |i|
  if i.even?
    count1.push(array[i])
  else
    count2.push(array[i])
  end
end
count3 = Array.new(10**5 + 1, 0)
count4 = Array.new(10**5 + 1, 0)

(0..count1.length - 1).each do |i|
  count3[count1[i]] += 1
end
(0..count1.length - 1).each do |i|
  count4[count2[i]] += 1
end

check1 = [0, 0]
check2 = [0, 0]
check3 = [0, 0]
check4 = [0, 0]
(1..10**5).each do |i|
  if check1[1] < count3[i]
    check1[1] = count3[i]
    check1[0] = i
  end
  if check2[1] < count4[i]
    check2[1] = count4[i]
    check2[0] = i
  end
end
(1..10**5).each do |i|
  if check3[1] < count3[i] && i != check1[0]
    check3[1] = count3[i]
    check3[0] = i
  end
  if check4[1] < count4[i] && i != check2[0]
    check4[1] = count4[i]
    check4[0] = i
  end
end

if check1[0] != check2[0]
  puts (count1.length - check1[1]) + (count2.length - check2[1])
  exit
end

if (check1[1] + check4[1]) > (check2[1] + check3[1])
  puts (count1.length - check1[1]) + (count2.length - check4[1])
else
  puts (count1.length - check3[1]) + (count2.length - check2[1])
end


Measured memory_bytes: 11236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = Integer.parseInt(sc.next());
		int sy = Integer.parseInt(sc.next());
		int tx = Integer.parseInt(sc.next());
		int ty = Integer.parseInt(sc.next());

		int sumx = tx-sx;
		int sumy = ty-sy;

		StringBuilder res = new StringBuilder();

		for(int i=0;i<sumy;i++) {
			res.append("U");
		}
		for(int i=0;i<sumx;i++) {
			res.append("R");
		}
		for(int i=0;i<sumy;i++) {
			res.append("D");
		}
		for(int i=0;i<sumx+1;i++) {
			res.append("L");
		}
		for(int i=0;i<sumy+1;i++) {
			res.append("U");
		}
		for(int i=0;i<sumx+1;i++) {
			res.append("R");
		}
		res.append("DR");
		for(int i=0;i<sumy+1;i++) {
			res.append("D");
		}
		for(int i=0;i<sumx+1;i++) {
			res.append("L");
		}
		res.append("U");

		System.out.println(res);

	}

}


Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int A, B, C, D;

int main() {
	cin >> A >> B >> C >> D;
	int taka, ao;
	taka = C / B;
	if (C % B != 0) {
		taka++;
	}
	ao = A / D;
	if (A % D != 0) {
		ao++;
	}
	if (taka <= ao) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
//  Be name khoda
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

#define F first
#define S second
#define MP make_pair

const int MAX = 1e5+9;
const ll MOD = 1e9+7;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	double n, m, d;
	cin >> n >> m >> d;
	double res = 0;
	if (d == 0) {
		res = (m-1) / n;
	} else
	if (d <= n/2) {
		res = (m-1) * (2*d + 2*(n-2*d));
		res /= n; res /= n;
	} else {
		res = (m-1) * 2*(n-d);
		res /= n; res /= n;
	}
	cout << fixed << setprecision(10) << res << "\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN (1<<12)
#define INF 1e18
#define int long long
using namespace std;

int n, m;
int a, b, c, t[20];
int dp[MAXN+5];
bool tf;

signed main() {
	cin >> n >> m;
	for (int i = 1; i < (1<<n); i++) dp[i] = INF;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		memset(t, 0, sizeof(t));
		for (int j = 0; j < b; j++)
			cin >> c, t[c-1] = 1;
		for (int j = 1; j < (1<<n); j++) {
			tf = 1;
			for (int k = 0; k < n; k++) {
				if (((1<<k)&j) && !t[k]) {
					tf = 0;
					break;
				}
			}
			if (tf) dp[j] = min(dp[j], a);
		}
	}
	for (int i = 1; i < (1<<n); i++) {
		for (int j = 0; j <= i; j++) {
			dp[i] = min(dp[i], dp[j&i]+dp[(i-(j&i))&i]);
		}
	}
	if (dp[(1<<n)-1] == INF) cout << -1 << '\n';
	else cout << dp[(1<<n)-1] << '\n';
}

Measured memory_bytes: 256
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;

int n;
ll tot, res;
ll a[maxn], x[maxn];

int main(){
	scanf("%d", &n);
	FOR(i, 0, n) scanf("%lld", a + i), tot += a[i];
	for(int i = 0; i < n - 1 ; i += 2) res += a[i];
	res *= 2;
	x[n - 1] = tot - res;
	for(int i = n - 2; i >= 0; --i) x[i] = a[i] * 2 - x[i + 1];
	FOR(i, 0, n) printf("%lld ", x[i]);
	puts("");
	return 0;
}



Measured memory_bytes: 2816
H, W, K = map(int, input().split(' '))
ls,rst = [], 0

for i in range(H):
    ls.append(list(input()))

for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for s in range(H):
            if i >> s & 1:
                continue
            for t in range(W):
                if j >> t & 1:
                    continue
                if ls[s][t] == '#':
                    cnt += 1
        if cnt == K:
            rst += 1
print(rst)

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

using ll = long long;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

struct ST {
  using T = ll;
  int s;
  vector<T> v;
  ST(int s) : s{s}, v(2 * s) {}
  T f(T a, T b){return max(a, b);}
  void update(int p, T val) {
    v[p += s] = val;
    for (p >>= 1; p >= 1; p >>= 1)
      v[p] = f(v[2 * p], v[2 * p + 1]);
  }
  T query(int l, int r) {
    if (l > r) return 0;
    T acc = 0;
    for (l += s, r += s; l <= r; (++l) >>= 1, (--r) >>= 1) {
      if (l & 1) acc = f(acc, v[l]);
      if (~r & 1) acc = f(v[r], acc);
    }
    return acc;
  }
};

vi sorted;
int getindex(int val) {
  return lower_bound(all(sorted), val) - begin(sorted);
}

void dfs(graph& g, int i, vi& a, ST& st, vi& res, int p = -1) {
  auto index = getindex(a[i]);
  auto old = st.query(index, index);
  res[i] = st.query(0, index - 1) + 1;
  st.update(index, res[i]);
  trav(e, g[i]) if (e.to != p)
    dfs(g, e.to, a, st, res, i);
  st.update(index, old);
}

void push(graph& g, int i, auto& res, int p = -1, int best = 0) {
  res[i] = max(res[i], best);
  trav(e, g[i]) if (e.to != p)
    push(g, e.to, res, i, max(best, res[i]));
}

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

  int n;
  cin >> n;
  vi a(n);
  trav(i, a) cin >> i;

  sorted = a;
  sort(all(sorted));
  sorted.erase(unique(all(sorted)), end(sorted));
  
  graph g(n);
  rep(i, 0, n - 1) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].PB({v});
    g[v].PB({u});
  }

  ST st(n);
  vi res(n);
  dfs(g, 0, a, st, res);
  push(g, 0, res);
  trav(i, res) cout << i << '\n';
}


Measured memory_bytes: 36848
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long ans;
void dg(long long x,long long y){
	if(x>y) swap(x,y);
	ans+=(y/x)*x*2;
	if(y%x==0){
		ans-=x;
		return;
	}
	dg(x,y%x);
}
int main(){
	cin>>n>>x;
	ans+=n;
	dg(x,n-x);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    bool ans = false;
    for (int i=1; i<=9; i++) {
        if (n%i==0 && n/i<=9) {
            ans = true;
            break;
        }
    }

    cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; string s; cin>>n>>s;
	VI x(n); int now=0;
	rep(i,n){
		if(s[i]=='I') now++;
		else now--;
		x[i]=now;
	}
	sort(RALL(x));
	cout<<max(x[0],0)<<endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

N = int(input())
A1 = list(accumulate(map(int, input().split())))
A2 = list(accumulate(map(int, input().split())))

ans = A1[0] + A2[N-1]
for i in range(1,N):
    ans = max(ans,A1[i] + A2[N-1] - A2[i-1])
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int r, D, X;
  scanf("%d %d %d", &r, &D, &X);

  int x[11] = {0};
  x[0] = X;
  int i;
  for(i=1; i<=10; i++) {
      x[i] = r * x[i-1] - D;
      printf("%d\n", x[i]);
  }
  return 0;
}



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

using namespace std;

int a[20][2],n,f[262144][19][2];

int F(int i,int j,int ok)
{
    if(f[i][j][ok]!=-1) return f[i][j][ok];
    else if(i==(1<<n)-1) return 0;
    else
    {
        int res=1e9,sl=0,t=0;
        for(int id=1;id<=n;id++)
        {
            if(((i>>(id-1))&1)==1) sl++;
        }
        //cout<<i<<" "<<j<<" "<<ok<<" "<<sl<<'\n';
        for(int id=1;id<=n;id++)
        {
            if(((i>>(id-1))&1)==0)
            {
                //cout<<id<<'\n';
                int okms=abs(sl-id+1)%2;
                //cout<<id<<" "<<okms<<" "<<abs(id-sl)<<'\n';
                if(a[id][okms]>=a[j][ok]) res=min(res,F(i+(1<<(id-1)),id,okms)+abs(id-t-1));
            }
            else t++;
        }
        f[i][j][ok]=res;
        return res;
    }
}

main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i][0];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>a[i][1];
    }
    memset(f,-1,sizeof(f));
    int ans=F(0,0,0);
    if(ans==1e9) ans=-1;
    cout<<ans;
}


Measured memory_bytes: 39168
N, W = map(int, input().split())
wlst = []
vlst = []
for _ in range(N):
  w, v = map(int, input().split())
  wlst.append(w)
  vlst.append(v)
dp = [0] * (W + 1)
for w, v in zip(wlst, vlst):
  for i in range(W - w, -1, -1):
    dp[i + w] = max(dp[i + w], dp[i] + v)
print(dp[W])

Measured memory_bytes: 42092
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


DIV = 998244353

def main():
    Ss = ssRaw()
    return "".join(Ss[::-1])

if __name__ == "__main__":

    print(main())


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

int p;
int a[3000], s[3000], t[3000], b[3000];

int main()
{
	cin >> p;

	for (int i = 0; i < p; i++)
		cin >> a[i];

	for (int i = 0; i < p; i++)
		b[i] = 0;

	s[0] = 1;
	t[0] = 1;

	for (int i = 1; i < p; i++) {
		s[i] = s[i - 1] * i % p;

		int j = s[i], k = 1;

		while (k < (p - 2) / 2) {
			j = j * j % p;
			k *= 2;
		}

		while (k < p - 2) {
			j = j * s[i] % p;
			k++;
		}

		t[i] = j;
	}

	for (int i = 0; i < p; i++) {
		if (a[i] == 1) {
			b[p - 1] = (b[p - 1] - 1 + p) % p;

			if (i == 0)
				b[0] = (b[0] + 1) % p;
			else {
				int u = i, v = 1;

				while (v < (p - 2) / 2) {
					u = u * u % p;
					v *= 2;
				}

				while (v < p - 2) {
					u = u * i % p;
					v++;
				}

				int w = u;

				for (int j = 1; j < p - 1; j++) {
					if (j % 2 == 0)
						b[j] = (b[j] - s[p - 1] * t[j] % p * t[p - 1 - j] % p * w + p) % p;
					else
						b[j] = (b[j] + s[p - 1] * t[j] % p * t[p - 1 - j] % p * w) % p;

					w = w * u % p;
				}
			}
		}
	}

	for (int i = 0; i < p - 1; i++)
		cout << b[i] << " ";
	cout << b[p - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long



int main(void) {
    long long N, X, A[200009], S, ret;
    cin >> N >> X;
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A, A + N);
    for (int i = 0; i < N; i++) {
        S += A[i];
        if (S <= X) { ret = i + 1; }
    }
    if (S != X && ret == N) ret = N - 1;
    cout << ret << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string s;
void rot() {
  string t;
  for (int i = 0; i < s.size(); i++) t.push_back(s[(i + 1) % s.size()]);
  s = t;
}

int main() {
  cin >> s;
  string t;
  cin >> t;
  bool b = false;
  for (int i = 0; i <= s.size(); i++) {
    rot();
    if (s == t) b = true;
  }
  if (b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 888
def main():
    N = input()
    m = len(N)
    max_v = sum([int(c) for c in N])
    if m > 1:
        v = int(N[0])-1 + 9*(m-1)
        max_v = max(max_v, v)
    return max_v



if __name__ == '__main__':
    print(main())

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
    int N, T;
    cin >> N >> T;
    int ans = 0;
    int before = -1;
    rep(i, N) {
        int t;
        cin >> t;
        if(before == -1) ;
        else if(before + T < t) ans += T;
        else ans += t - before;
        before = t;
    }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

#define MOD (LL)(1e9+7)

//累乗 O(log N)
long long power(long long x, long long N){
	if(N == 0) return 1LL;
	if(N == 1) return x;
	long long tmp = power(x, N/2);
	if(N%2 == 0) return tmp * tmp % MOD;
	else return tmp * tmp % MOD * x % MOD;
}

string S;
LL waA[100001]={}, waC[100001]={}, waQ[100001]={};

int main(){
	cin >> S;
	for(int i=0; i<S.size(); i++){
		waA[i+1] = waA[i];
		waC[i+1] = waC[i];
		waQ[i+1] = waQ[i];
		if(S[i] == 'A') waA[i+1]++;
		if(S[i] == 'C') waC[i+1]++;
		if(S[i] == '?') waQ[i+1]++;
	}

	LL ans = 0;
	for(int i=0; i<S.size(); i++){
		if(S[i] == 'B'){
			ans += waA[i] * (waC[S.size()] - waC[i+1]) % MOD * power(3, waQ[S.size()]);
			ans += waQ[i] * (waC[S.size()] - waC[i+1]) % MOD * power(3, waQ[S.size()]-1);
			ans += waA[i] * (waQ[S.size()] - waQ[i+1]) % MOD * power(3, waQ[S.size()]-1);
			ans += waQ[i] * (waQ[S.size()] - waQ[i+1]) % MOD * power(3, waQ[S.size()]-2);
			ans %= MOD;
		}
		if(S[i] == '?'){
			ans += waA[i] * (waC[S.size()] - waC[i+1]) % MOD * power(3, waQ[S.size()]-1);
			ans += waQ[i] * (waC[S.size()] - waC[i+1]) % MOD * power(3, waQ[S.size()]-2);
			ans += waA[i] * (waQ[S.size()] - waQ[i+1]) % MOD * power(3, waQ[S.size()]-2);
			ans += waQ[i] * (waQ[S.size()] - waQ[i+1]) % MOD * power(3, waQ[S.size()]-3);
			ans %= MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(10**9)
N = int(input())
S = input()

dp1 = [False for i in range(10)]
dp2 = [False for i in range(100)]
dp3 = [False for i in range(1000)]

for i, ss in enumerate(S):
    s = int(ss)
    if i>1:
        for i3 in range(0, 100):
            if dp2[i3]:
                dp3[i3*10+s] = True
    if i>0:
        for i2 in range(0, 10):
            if dp1[i2]:
                dp2[i2*10+s] = True
    dp1[s] = True

# for i, d in enumerate(dp3):
#     if d:
#         print(i)

# print(sum(dp1)+sum(dp2)+sum(dp3))
print(sum(dp3))

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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) __builtin_clzll(x)
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

ll N;

signed main() {
    cin >> N;
    SCIN(S);
    char pre = S[0];
    ll cnt = 0;
    REP(i, N) {
        if(pre != S[i]) {
            cnt++;
            pre = S[i];
        }
    }
    cout << cnt + 1 << "\n";
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int board[1234][1234];
int mark[1234][1234];

int main()
{
	for (;;)
	{
		int h, w, n;
		scanf("%d %d %d", &h, &w, &n);
		if (h == 0 && w == 0 && n == 0)break;
		memset(board, 255, sizeof(board));
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				scanf("%d", &board[i][j]);
			}
		}
		memset(mark, 0, sizeof(mark));
		mark[0][0] = n - 1;
		for (int sum = 0; sum < w + h - 1; ++sum)
		{
			for (int vr = 0; vr <= sum; ++vr)
			{
				if (vr >= h)break;
				int hr = sum - vr;
				if (hr >= w)continue;
				if (hr < 0)break;
				if (board[vr][hr] == 0)
				{
					mark[vr][hr + 1] += mark[vr][hr] / 2;
					mark[vr + 1][hr] += mark[vr][hr] / 2 + (mark[vr][hr] % 2);
				}
				else
				{
					mark[vr][hr + 1] += mark[vr][hr] / 2 + (mark[vr][hr] % 2);
					mark[vr + 1][hr] += mark[vr][hr] / 2;
				}
				if (mark[vr][hr] % 2)
				{
					board[vr][hr] = (board[vr][hr] == 0) ? 1 : 0;
				}
			}
		}
		int py = 0, px = 0;
		while (board[py][px] >= 0)
		{
			if (board[py][px] == 0)
			{
				++py;
			}
			else
			{
				++px;
			}
		}
		printf("%d %d\n", py + 1, px + 1);
	}
	return 0;
}

Measured memory_bytes: 14464
#include <iostream>
using namespace std;
typedef long long ll;

ll b[1002][1002];
bool f[1002][1002];

int main()
{
    int n, k;
    cin >> n >> k;
    ll a[1002];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        b[i][i] = a[i];
        for(int j = i + 1; j < n; j++){
            b[i][j] = b[i][j - 1] + a[j];
        }
    }
    ll p[51];
    p[0] = 1;
    for(int i = 1; i <= 50; i++) p[i] = p[i - 1] * 2;
    ll ans = 0;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) f[i][j] = true;
    for(ll l = 50; l >= 0; l--){
        int r = 0;
        for(int i = 0; i < n; i++) for(int j = i; j < n; j++){
            if(f[i][j] && ((b[i][j] >> l) & 1) == 1) r++;
        }
        if(r >= k){
            ans += p[l];
            for(int i = 0; i < n; i++) for(int j = i; j < n; j++){
                if(((b[i][j] >> l) & 1) == 0) f[i][j] = false;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

int main() {
    int N, M; cin >> N >> M;
    int ans = int(pow(2, M)) * ((N - M) * 100 + M * 1900);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int dp[1005][10005];
const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n+1) {
        rep(j, h+1) {
            dp[i][j] = INF;
            if (j == 0) dp[i][j] = 0;
        }
    }
    rep(i, n) {
        rep(j, h+1) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j], dp[i+1][max(j - a[i], 0)] + b[i]);
        }
    }
    cout << dp[n][h] << endl;
}

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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<ll, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;



int main(int argc, char const *argv[])
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
 //    	freopen("error.txt", "w", stderr);
	// #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin>>n>>m;
    int a =  m-n+1;
    int b =  n+m-1;
    while(a<=b){
    	cout<<a<<" ";
    	a++;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int D[105], L[105];
	int n, x, count = 0;
	scanf("%d%d", &n, &x);
	
	D[0] = 0;
	for(int i = 0; i <= n; ++i) {
		scanf("%d", &L[i]);
	}
	for(int i = 1; i <= n; ++i) {
		D[i] = D[i-1] + L[i-1];
	}
	for(int i = 0; i <= n; ++i) {
		if(D[i] <= x)
			++count;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef const int let;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'

int main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   int n ,a;
   cin >> n >> a;

   n %= 500;

   if (n <= a) outl("Yes");
   else outl("No");
}




Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.Point;

class Main{


      public static void main(String args[])throws IOException
    {
	  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	  while(true)
	      {
		  int N;
		  N = Integer.parseInt(in.readLine());
		  if(N == 0)
		      break;

		  StringBuilder message = new StringBuilder(in.readLine());
		  List<Point> list = new ArrayList<Point>();
		  for(int i=0;i<N;i++)
		      {
			  String ab = in.readLine();
			  int a,b;
			  a = Integer.parseInt(ab.substring(0,ab.indexOf(" ")));
			  b = Integer.parseInt(ab.substring(ab.indexOf(" ")+1));
			  Point p = new Point(a,b);
			  list.add(p);
		      }
		  Collections.reverse(list);

		  for(int i=0;i<N;i++)
		      {
			  int a,b,dif;
			  a = list.get(i).x;
			  b = list.get(i).y;
			  
			  a--;
			  b--;
			  dif = Math.abs(a-b);
			  char ca,cb;
			  ca = message.charAt(a);
			  cb = message.charAt(b);

			  ca = (char)((ca+dif-'a')%26 + 'a');
			  cb = (char)((cb+dif-'a')%26 + 'a');


			  message.replace(a,a+1,String.valueOf(cb));
			  message.replace(b,b+1,String.valueOf(ca));
			 
		      }
		  System.out.println(message);

	      }
      }

}

Measured memory_bytes: 9680
#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; }
//---------------------------------------------------------------------------------------------------
vector<ll> enumdiv(ll n) {
	vector<ll> S;
	for (ll i = 1; i*i <= n; i++) if (n%i == 0) { S.push_back(i); if (i*i != n) S.push_back(n / i); }
	sort(S.begin(), S.end());
	return S;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll N;
//---------------------------------------------------------------------------------------------------
void labo() {
	auto ed1 = enumdiv(N);
	auto ed2 = enumdiv(N - 1);

	set<ll> se;
	fore(d, ed1) se.insert(d);
	fore(d, ed2) se.insert(d);

	rep(K, 2, N + 1) {
		ll n = N;
		while (K <= n) {
			if (n % K == 0) n /= K;
			else n -= K;
		}
		if (n == 1) {
			if (!se.count(K)) {
				cout << "NG by " << N << endl;
				return;
			}
		}
	}
}
//---------------------------------------------------------------------------------------------------
bool check(ll K) {
	ll n = N;
	while (K <= n) {
		if (n % K == 0) n /= K;
		else n -= K;
	}
	return n == 1;
}
int naive() {
	auto ed1 = enumdiv(N);
	auto ed2 = enumdiv(N - 1);

	set<ll> se;
	fore(d, ed1) if (1 < d) se.insert(d);
	fore(d, ed2) if (1 < d) se.insert(d);

	int ans = 0;
	fore(d, se) if (check(d)) ans++;
	return ans;
}
ll opt() {
	set<ll> ans;

	auto ed1 = enumdiv(N);
	fore(d, ed1) if(2 <= d) {
		ll K = d;
		ll n = N;
		while (n % K == 0) n /= K;
		if ((n - 1) % K == 0) ans.insert(K);
	}

	auto ed2 = enumdiv(N - 1);
	fore(d, ed2) if (2 <= d) ans.insert(d);

	return ans.size();
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	cout << opt() << endl;
	return;

	rep(n, 2, 1000) {
		N = n;
		labo();
	}
	return;

	N = 46;

	rep(K, 2, N + 1) {
		ll n = N;
		while (K <= n) {
			if (n % K == 0) n /= K;
			else n -= K;
		}
		if (n == 1) cout << K << endl;
	}
}







Measured memory_bytes: 384
import itertools
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

menu = [a, b, c, d, e]

permutations = list(itertools.permutations(range(5)))

ans = float('inf')
for p in permutations:
    time = 0
    for i in range(5):
        time += menu[p[i]]
        if i != 4:
            time = math.ceil(time / 10) * 10
    ans = min(ans, time)

print(ans)

Measured memory_bytes: 3064