akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int INF = 1e9+1;
const int MOD = 1e9+7;

int mod_pow(int x, int n){
  int res = 1;
  while ( n ) {
    if ( n & 1 ) (res *= x) %= MOD;
    (x *= x) %= MOD;
    n >>= 1;
  }
  return res;
}

int N;
vector<int> h;
vector<vector<int> > dp1, dp2;

void dfs(int l, int r) {
  int mi = INF;
  for ( int i = l; i < r; i++ ) mi = min(mi, h[i]);
  for ( int i = l; i < r; i++ ) h[i] -= mi;  
  int cnt_mi = 0;
  vector<int> p{l-1};  
  for ( int i = l; i < r; i++ ) {
    if ( h[i] == 0 ) {
      cnt_mi++;
      p.emplace_back(i);      
    }
  }
  p.emplace_back(r);  

  //cnt_mi = max(1LL, cnt_mi);  
  int mpow1 = mod_pow(2, cnt_mi);
  int mpow2 = mod_pow(2, mi);  
  dp1[l][r] = dp2[l][r] = 1;  
  for ( int i = 0; i < (int)p.size()-1; i++ ) {    
    if ( p[i]+1 >= p[i+1] ) continue;    
    dfs(p[i]+1, p[i+1]);
    (dp1[l][r] *= (dp1[p[i]+1][p[i+1]]+dp2[p[i]+1][p[i+1]])) %= MOD;    
    (dp2[l][r] *= dp2[p[i]+1][p[i+1]]) %= MOD;
  }
  (dp1[l][r] = mpow1*dp1[l][r]%MOD + (mpow2+MOD-2)*dp2[l][r]%MOD) %= MOD;
  (dp2[l][r] *= mpow2) %= MOD;

  for ( int i = l; i < r; i++ ) h[i] += mi;
}

signed main() {
  cin >> N;

  h = vector<int>(N);
  for ( int i = 0; i < N; i++ ) cin >> h[i];
  
  dp1 = dp2 = vector<vector<int> >(N+1, vector<int>(N+1, 0));

  dfs(0, N);

  cout << dp1[0][N] << endl;  
  
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
 
public class Main {
    public static void main(String args[]) {
        
       Scanner sc = new Scanner(System.in);
       double A = sc.nextInt();
       double B = sc.nextInt();
       double C = sc.nextInt();
       double D = sc.nextInt();
       double E = sc.nextInt();
       
       double AX =Math.ceil(A/10) * 10;
       double BX =Math.ceil(B/10) * 10;
       double CX =Math.ceil(C/10) * 10;
       double DX =Math.ceil(D/10) * 10;
       double EX =Math.ceil(E/10) * 10;
       
       int a=(int)AX -(int)A;
       int b=(int)BX -(int)B;
       int c=(int)CX -(int)C;
       int d=(int)DX -(int)D;
       int e=(int)EX -(int)E;
       
       int [] last = {a,b,c,d,e};
       
       int intMax =last[0];
       int total =(int)AX+(int)BX+(int)CX+(int)DX+(int)EX;
       
       for(int i = 1; i < last.length; i++) {
           if(intMax <= last[i]) {
               intMax = last[i];
               
           }
           
       }
       System.out.println(total-intMax);
       
    
        
    }
    
}

Measured memory_bytes: 35648
// review
#include <iostream>

using namespace std;
typedef long long ll;
const int MOD = 1e9+7;

int n;
string s1, s2;

void solve() {
  ll cnt = 1;
  int prev = -1;
  for (int i=0;i<n;i++) {
    if (s1[i] == s2[i]) {
      if (prev == -1) {
        cnt *= 3;
      } else if (prev == 0) {
        cnt *= 2;
      } else {
        cnt *= 1;
      }
      cnt = cnt % MOD;
      prev = 0;
    } else {
      if (prev == -1) {
        cnt *= 6;
      } else if (prev == 0) {
        cnt *= 2;
      } else {
        cnt *= 3;
      }
      cnt = cnt % MOD;
      prev = 1;
      i++;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> n;
  cin >> s1 >> s2;
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll a[2005];

int sm(int a, int b)
{
	return ((b - a + 1)*(a + b) / 2);
}

int main()
{
	while (1) {
		cin >> n;
		if (n == 0) {
			return 0;
		} else {
			cnt = 0;
			FOR(i, 1, n)
			{
				FOR(j, i + 1, n)
				{
					if (sm(i, j) == n) {
						cnt++;
					}
				}
			}
			cout << cnt << endl;
		}
	}
}

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

int main() {
  int h,w;
  string frame,x;
  cin >> h >> w;
  for(int i=0;i < w+2;i ++){
    frame += "#";
  }
  cout << frame << endl;
  for(int i=0;i < h;i ++){
    cin >> x;
    cout << "#" << x << "#" << endl;
  }
  cout << frame << endl;
}

Measured memory_bytes: 256
N = int(input())
P = []

for _ in range(N):
    x, l = map(int,input().split())
    P.append((x - l, x+l))

P.sort(key=lambda x: x[1])

ans = 0
last = -1e9
for ix in range(0, N):
    if last <=  P[ix][0]:
        ans += 1
        last = P[ix][1]

print(ans)


Measured memory_bytes: 23728
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

i64 solve(i64 X) {
  i64 ans = 0;
  while(X > 0) {
    X %= __builtin_popcountll(X);
    ans++;
  }
  return ans;
}

int main() {
  i64 N;
  cin >> N;
  string X;
  cin >> X;
  reverse(all(X));

  i64 pc = 0;
  for(auto x: X) {
    if(x == '1') pc++;
  }

  vector<i64> up;
  i64 up_value = 0;
  {
    i64 now = 1;
    rep(i,0,N) {
      up.push_back(now % (pc + 1));
      if(X[i] == '1') {
        up_value += now;
        up_value %= (pc + 1);
      }
      now *= 2;
      now %= (pc + 1);
    }
  }
  vector<i64> down;
  i64 down_value = 0;
  if(pc <= 1) {
    down.assign(N, -1);
    down_value = -1;
  }
  else {
    i64 now = 1;
    rep(i,0,N) {
      down.push_back(now % (pc - 1));
      if(X[i] == '1') {
        down_value += now;
        down_value %= (pc - 1);
      }
      now *= 2;
      now %= (pc - 1);
    }
  }
  vector<i64> vec(N);
  vector<i64> ans(N, -1);
  rep(i,0,N) {
    if(X[i] == '0') {
      //up
      vec[i] = (up_value + up[i]) % (pc + 1);
      ans[i] = solve(vec[i]) + 1;
    }
    else if(X[i] == '1') {
      if(down_value == -1) {
        ans[i] = 0;
      }
      else {
        vec[i] = (down_value - down[i] + (pc - 1)) % (pc - 1);
        ans[i] = solve(vec[i]) + 1;
      }
    }
  }
  reverse(all(ans));
  rep(i,0,N) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 9716
#include "bits/stdc++.h"

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

	std::vector<int> a(n);
	for (auto &v : a) {
		std::cin >> v;
	}

	std::vector<int> dp = a;
	for (int i = 1; i < n; i++) {
		dp[i] = (dp[i - 1] ^ dp[i]);
	}

	std::cout << (dp.back() == 0 ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 1024
//Contest ---Atcoder

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){

int n;
cin>>n;
int count=0;
for(int i=1;i<=n;i++){
    if(i%2!=0)
     count++;
}
double div=(count*1.00000/n*1.00000);
cout<<div;


}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
min_abs=float("inf")
ans=0;cnt=0
for i in range(N):
    if A[i]<0:
        cnt+=1
    min_abs=min(min_abs,abs(A[i]))
    ans+=abs(A[i])
if cnt%2==0:
    print(ans)
else:
    print(ans-2*min_abs)

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

int main(){
    int n;
    cin>>n;
    vector<int> W(n, 0);
    vector<int> E(n, 0);

    string s;
    cin>>s;

    if(s[0] == 'W'){
        W[0]++;
    }
    if(s[0] == 'E'){
        E[0]++;
    }

    for(int i=1; i<n; i++){
        if(s[i] == 'W'){
            W[i] = W[i-1] + 1;
        }else{
            W[i] = W[i-1];
        }
        if(s[i] == 'E'){
            E[i] = E[i-1] + 1;
        }else{
            E[i] = E[i-1];
        }
    }

    int ans = E[n-1] - E[0];
    for(int i=1; i<n; i++){
        ans = min(ans, E[n-1]-E[i] + W[i-1]);      
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6248
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

///////////////////////////////////////////////////////////////////////

ll N, M;

void solve() {
	cin >> N >> M;
	if(N > M / 2) cout << M / 2 << "\n";
	else cout << N + (M - N * 2) / 4 << "\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()

int main() {
  int s;
  cin >> s;
  map<ll, ll> mp;
  auto calc = [&](int a) {
    for (int i = 1;; ++i) {
      if (i * (i + 1) / 2 > a) break;
      int tmp = (a - i * (i + 1) / 2);

      if (tmp % i == 0) {
        mp[a]++;
      }
    }
  };
  ll ans = 0;
  for (int i = 1; i * i <= s; ++i) {
    if (s % i == 0) {
      calc(i);
      if (i * i != s) calc(s / i);
      ans += mp[i] * mp[s / i];
      if (i * i != s) ans += mp[i] * mp[s / i];
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3136
def d_sum(x):
    res = 0
    while x > 0:
        res += x % 10
        x //= 10
    return res

n = int(input())

ans = float('inf')
for a in range(1, n // 2 + 1):
    b = n - a
    ans = min(ans, d_sum(a) + d_sum(b))

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using v = vector<int>;
using ll = long long;
int main(){ 
    int n;
    cin >> n;
    string p("",n),q("",n);

    for(int i=0;i<n;i++){
        cin >>p[i]; 
    }
    
    for(int i=0;i<n;i++){
        cin >>q[i]; 
    }
	auto pp = p;
  	sort(pp.begin(),pp.end());
  	bool fp=false,fq=false;
  	int c=1,ansa=0,ansb=0;
    do{
        if(pp == p){
          fp =true;
          ansa=c;
        }
        if(pp == q){
          fq =true;
          ansb=c;
        }
        if(fp && fq) break;
        c++;
    }while(next_permutation(pp.begin(),pp.end()));
	cout << abs(ansa-ansb);
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		List <Integer> pos = new ArrayList <Integer>();
		List <Integer> neg = new ArrayList <Integer>();
		
		for(int i = 0 ; i < n ; i++) {
			int a = Integer.parseInt(sc.next());
			if(a >= 0) {
				pos.add(a);
			}
			else {
				neg.add(a);
			}
		}
		
		Collections.sort(pos);
		Collections.sort(neg);
		
		int [][]ope = new int [n][2];
		int max = -1;
		int min = -1;
		
		if(!pos.isEmpty() && !neg.isEmpty()) {
			 max = pos.get(pos.size()-1);
			 min = neg.get(0);
			
			pos.remove(pos.size()-1);
			neg.remove(0);
			
			int m = neg.size();
			int l = pos.size();
			
			for(int i = 0 ; i < m ;i++) {
				ope[i][0] = max;
				ope[i][1] = neg.get(i);
				max = ope[i][0] - ope[i][1];
			}
			
			for(int i = 0 ; i < l ;i++) {
				ope[i+m][1] = pos.get(i);
				ope[i+m][0] = min;
				min = ope[i+m][0] - ope[i+m][1];
			}
			
			ope[n-2][0] = max;
			ope[n-2][1] = min;
			
		}
		
		else if(pos.isEmpty()) {
			min = neg.get(0);
			max = neg.get(neg.size()-1);
			neg.remove(neg.size()-1);
			neg.remove(0);
			
			int m = neg.size();
			
			for(int i = 0 ; i < m ;i++) {
				ope[i][0] = max;
				ope[i][1] = neg.get(i);
				max = ope[i][0] - ope[i][1];
			}
			
			ope[n-2][0] = max;
			ope[n-2][1] = min;
		}
		else {
			min = pos.get(0);
			max = pos.get(pos.size()-1);
			pos.remove(pos.size()-1);
			pos.remove(0);
			
			int m = pos.size();
			for(int i = 0 ; i < m ;i++) {
				ope[i][0] = min;
				ope[i][1] = pos.get(i);
				min = ope[i][0] - ope[i][1];
			}
			ope[n-2][0] = max;
			ope[n-2][1] = min;
			
		}
		
		System.out.println(max - min);
		for(int i = 0 ; i < n-1 ;i++) {
			System.out.println(ope[i][0]+" "+ope[i][1]);
		}
	}

}


Measured memory_bytes: 77080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000

bool isPrime(ll x){
    double y = sqrt((double)x);
    ll b = y;
    FOR(i,2,b){
        if (!(x%i)) return false;
    }
    return true;
}//mod6で1,5でさがす

int main(){
    ll q, l, r; cin >> q;
    vector<ll> a(110000,0);
    a[3]=1;
    for (ll i=5; i<=100000;i+=6){
        if (isPrime(i)&&isPrime((i+1)/2)) a[i]=1;
        else a[i]=0;
        if (isPrime(i+2)&&isPrime((i+3)/2)) a[i+2]=1;
        else a[i+2]=0;
    }
    FOR(i,1,109999) a[i]=a[i-1]+a[i];
    REP(i,q){
        cin >> l >> r;
        cout << a[r]-a[l-1] << endl;
    }
}

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

#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int

using namespace std;

inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int gcd(int x, int y){
	while (y){
		x %= y;
		swap(x, y);
	}
	return x;
}

const int mod = 1000000007;

long long pw(long long a, long long b){
	long long res = 1;
	while (b){
		if (b & 1ll)
			res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int main(){

	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		a[i] = nxt();

	long long A = 0, B = 0, C = 0;
	for (int i = 0; i < n; i++){
		A++;
		B -= 2 * a[i];
		C += a[i] * a[i];
	}

	int q = -B / (2 * A);
	int res = q;
	for (int i = -2; i < 3; i++){
		if (A * (q + i) * (q + i) + B * (q + i) + C < A * res * res + B * res + C){
			res = q + i;
		}
	}

	cout << A * res * res + B * res + C << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, y ;
  cin >> x >> y ;

  if ((x<y) && ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x ==12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)) ){
    cout << "Yes" << endl;
  }
    else if((x<y) && ((x == 4 || x == 6 || x == 9 || x == 11 ) && (y == 4 || y == 6 || y == 9 || y == 11))){
      cout << "Yes" << endl;
    }
      else {
        cout << " No " << endl;
}
                      }
      
    
  


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


int main(){
int a, b;
cin >> a >> b;

if (b%a == 0) cout << a+b << endl;
else cout <<b-a << endl;
}

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

int main()
{
int i;
long long N;
long long X;
long long Y;
long long Z;
long long iMax;

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

	cin >> N;

	iMax = 0;
	for( i = 0; i < 5; i++ )
	{
		cin >> X;

		Z = N / X;
		if( N % X > 0 ) Z++;
		if( iMax < Z ) iMax = Z;
	}

	cout << iMax + 4 << endl;

	return 0;
}

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

//??????????????????????????????
void solve(int n){
	int treasure[25];//????????????
	int endurance[25];//????????°??????????????¨??????????????§???????????§???????????????
	int sumTreasure = 0;
	bool used[25];
	for(int i=0;i<n;i++){
		scanf("%d %d", &treasure[i], &endurance[i]);
		sumTreasure += treasure[i];
		used[i] = false;
	}
	
	//??¨????????????????????£???????????¶?????§??????????????¶???????????¶?????§???
	//???????????????????????¶????????£???????????????????????????????????????
	for(int i=0;i<n;i++){//n?????????????????????
	
		//????????????????????????????????¶????????§????????????????????§?????¶?????¢??????
		int island = -1;//?????¢?????¶
		int maxEndurance = -1;
		for(int j=0;j<n;j++){
			if(!used[j]){
				if(maxEndurance < endurance[j]){
					maxEndurance = endurance[j];
					island = j;
				}
			}
		}
		if(endurance[island] >= sumTreasure){
			used[island] = true;
			sumTreasure -= treasure[island];
		}else{
			printf("No\n");
			return;
		}
		
	}
	printf("Yes\n");
}

int main() {
	bool first = true;
	while(true){
		int n;//??¶?????°
		scanf("%d\n", &n);
		if(n==0){
			break;
		}
		solve(n);
	}
	
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n;
string a[N];
map<string, int> m;

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sort(a[i].begin(), a[i].end());
		m[a[i]]++;
	}
	int ans = 0;
	for(auto &it:m)
	{
		int cur = it.second;
		ans += (cur * (cur - 1)) / 2;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 16640
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int a,b,c;
    cin >> a >> b >> c;

    set<int> check;
    int count=1;
    while(check.size()<=b){
        ll now=a*count;
        if(check.count(now%b))break;
        check.insert(now%b);
        if(now%b==c){
            cout << "YES" << endl;
            return 0;
        }
        count++;
    }

    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

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

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

  ll cur = n;
  while (true) {
    if(isPrime(cur)) {
      cout << cur << endl;
      return 0;
    }
    cur++;
  }

  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L > R){
    cout << "Left" << endl;
  }
  else if (L == R){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
  
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  bool ans = true;
  
  sort(a.begin(), a.end());
  
  for (int i = 1;i < n;i++){
    if (a.at(i - 1) == a.at(i)){
      ans = false;
      break;
    }
  }
  
  if (ans){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

int calc(int a,int b,char c){
  switch(c){
  case'+':
    return a+b;
  case'-':
    return a-b;
  case'*':
    return a*b;
  }
}


int main(){
  int n[4];
  char s[3] = {'+','-','*'};
	int ans = 0;
	bool findans;
  while(true){
    cin>>n[0]>>n[1]>>n[2]>>n[3];
		if(n[0]==0)break;
    sort(n,n+4);
		findans = false;
    do{
      for(int j=0;j<27;j++){
				ans = calc(calc(calc(n[0],n[1],s[j/9]),n[2],s[j/3%3]),n[3],s[j%3]);
				if (ans == 10){
					cout << "((" << n[0] << s[j/9] << n[1] << ")" << s[j/3%3] << n[2] << ")" << s[j%3] << n[3] << endl;
					findans = true;
					break;
				}
				ans = calc(calc(n[0],n[1],s[j/9]),calc(n[2],n[3],s[j%3]),s[j/3%3]);
				if (ans == 10){
					cout << "(" << n[0] << s[j/9] << n[1] << ")" << s[j/3%3] << "(" << n[2] << s[j%3] << n[3] << ")"<< endl;
					findans = true;
					break;
				}
				ans = calc(calc(n[0],calc(n[1],n[2],s[j/3%3]),s[j/9]),n[3],s[j%3]);
				if (ans == 10){
					cout << "(" << n[0] << s[j/9] << "(" << n[1] << s[j/3%3] << n[2] << "))" << s[j%3] << n[3] << endl;
					findans = true;
					break;
				}
				
				ans = calc(n[0],calc(calc(n[1],n[2],s[j/3%3]),n[3],s[j%3]),s[j/9]);
				if (ans == 10){
					cout << n[0] << s[j/9] << "((" << n[1] << s[j/3%3] << n[2] << ")" << s[j%3] << n[3] << ")=" << endl;
					findans = true;
					break;
				}
				ans = calc(n[0],calc(n[1],calc(n[2],n[3],s[j%3]),s[j/3%3]),s[j/9]);  
				if (ans == 10){
					cout << n[0] << s[j/9] << "(" << n[1] << s[j/3%3] << "(" << n[2] << s[j%3] << n[3] << "))"<< endl;
					findans = true;
					break;
				}
      }
			if(findans) break;
    }while(next_permutation(n,n+4));
		if(!findans)
			cout<<"0"<<endl;
		
		findans = false;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int L[210000];
int R[210000];
int sum[510][510];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<b;i++){
		scanf("%d%d",L+i,R+i);L[i]--;R[i]--;
		sum[L[i]][R[i]]++;
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			sum[i][j+1]+=sum[i][j];
		}
	}
	for(int i=0;i<c;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		int ret=0;
		for(int j=p;j<=q;j++){
			ret+=sum[j][q];
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 4864
#include <iostream>

using namespace std;

int n;
int x;

int main() {
	cin >> n;
	bool ok = false;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (x%2 == 1) ok = true;
	}
	if (ok) cout << "first\n";
	else cout << "second\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] coins = {500, 100, 50};
        int[] coin = new int[3];

        coin[0]=scanner.nextInt();
        coin[1]=scanner.nextInt();
        coin[2]=scanner.nextInt();
        int sum = scanner.nextInt();

        int count=0;
        for(int i=0;i<=coin[0];i++){
            for(int j=0;j<=coin[1];j++){
                for(int k=0;k<=coin[2];k++){
                    if((coins[0]*i + coins[1]*j + coins[2]*k)==sum){
                        count++;
                    }
                }
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21588
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,M=pin()
    ps=[tupin(str) for _ in range(M)]

    WA=[0]*N
    AC=[0]*N
    for m in range(M):
        p,s=ps[m]
        p=int(p)-1#0-indxd
        if AC[p]==0:
            if s=="WA": 
                WA[p]+=1
            else:
                AC[p]=1
    wa=0
    for Wa in range(N):
        if AC[Wa]==1:wa+=WA[Wa]
    print(sum(AC),wa)
        
#%%submit!
resolve()

Measured memory_bytes: 67420
#include <algorithm>
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <vector>
template <typename T> class SegmentTree {
  using F = std::function<T(T, T)>;

private:
  F updater, operation; // 葉ノード更新時処理、区間に対する処理
  T e;                  // 単位元
  std::vector<T> node;
  size_t n; // 管理している要素数

  T query(size_t a, size_t b, size_t k, size_t l, size_t r) {
    // a,b := クエリ範囲[a,b)
    // k := 今見ているノードの番号
    // l,r := 今見ているノードに対応する範囲
    if (r <= a || b <= l) {
      // 交差しない
      return e;
    }
    if (a <= l && r <= b) {
      // クエリ範囲に完全に含まれる
      return node[k];
    }
    size_t m = (l + r) / 2;
    return operation(query(a, b, 2 * k + 1, l, m),
                     query(a, b, 2 * k + 2, m, r));
  }

public:
  SegmentTree(size_t N, T e, F operation, F updater)
      : e(e), operation(std::move(operation)), updater(std::move(updater)) {
    n = 1;
    while (n < N)
      n <<= 1;
    node.assign(2 * n - 1, e);
  }

  template <typename Iterator>
  SegmentTree(size_t N, T e, F operation, F updater, Iterator start,
              Iterator end)
      : e(e), operation(std::move(operation)), updater(std::move(updater)) {
    n = 1;
    while (n < N)
      n <<= 1;
    node.assign(2 * n - 1, e);
    init(start, end);
  }
  template <typename Iterator> void init(Iterator start, Iterator end) {
    for (auto i = start; i < end; i++) {
      int idx = i - start + n - 1;
      node[idx] = *i;
    }
    for (int i = n - 2; i >= 0; i--) {
      node[i] = operation(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  void update(int idx, T x) {
    // idxの値をxに更新
    idx += n - 1;
    node[idx] = updater(node[idx], x);
    while (idx > 0) {
      idx = (idx - 1) / 2;
      node[idx] = operation(node[idx * 2 + 1], node[idx * 2 + 2]);
    }
  }

  T query(size_t a, size_t b) {
    // [a,b)の処理
    return query(a, b, 0, 0, n);
  }

  const T &operator[](size_t idx) { return node[idx + n - 1]; }
};

#include <iostream>
using namespace std;

int main() {
  int n, q;
  string s;
  cin >> n;
  cin >> s;
  cin >> q;
  vector<int> dat(n, 0);
  for (int i = 0; i < n; i++) {
    dat[i] = 1 << (s[i] - 'a');
  }
  auto st = SegmentTree<int>(
      n, int(0), [](int a, int b) { return a | b; },
      [](int a, int b) { return b; }, dat.begin(), dat.end());
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      int idx;
      char c;
      cin >> idx >> c;
      idx--;
      st.update(idx, 1 << (c - 'a'));
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      int res = st.query(l, r);
      cout << __builtin_popcount(res) << endl;
    }
  }
}


Measured memory_bytes: 6916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAXN = 201+5;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	string s;
	cin >> s;
	if(s == "RRR"){
		cout << 3 << endl;
	}else if(s=="RRS"||s=="SRR"){
		cout << 2 << endl;
	}else if(s == "SSS"){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
	}
    return 0;
}




Measured memory_bytes: 3644
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int cnt = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        
        for(int i = 1; i <= cnt; i++){
            int sum = 0;
            for (String str : String.valueOf(i).split("")) {
                sum += Integer.parseInt(str);
            }
            if (a <= sum && b >= sum){
                ans += i;
            }
        }
        
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 36180
/* ex5_3
   moka223711 */

#include <stdio.h>
int main(void){
    int row, col, i, j, br[101]={0}, bc[101]={0};
    char sq[101][101];
    scanf("%d %d", &row, &col);
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        if(br[i] == 1){
            for(j = 0; j < col; j++){
                if(bc[j] == 1)
                    printf("%c", sq[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
import math
import sys

A, B = list(map(lambda x: int(x), input().split()))
ten_pats = [i for i in range(B*10, B*10 + 10)]

for num in ten_pats:
  if int(num * 0.08) == A:
    print(num)
    sys.exit()

print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <map>

using namespace std;

int main() {
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    string a;
    cin >> a;
    map<char, int> alphabet_map;

    for(int i = 0; i < a.size(); i++) {
        if (alphabet_map.count(a[i]) == 0) {
            alphabet_map[a[i]] = 1;
        }
    }
    char min_alphabet;
    for (int i = 0; i < alphabet.size(); i++) {
        if (alphabet_map.count(alphabet[i]) == 0) {
            min_alphabet = alphabet[i];
            cout << min_alphabet << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
# A - 和風いろはちゃんイージー / Iroha and Haiku (ABC Edition)
# https://atcoder.jp/contests/abc042/tasks/abc042_a

nums = list(map(int,input().split()))

for i in [5,7,5]:
    if i in nums:
        nums.remove(i)
    else:
        print("NO")
        exit()

if len(nums) == 0:
    print("YES")
else:
    print("NO")

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

 int main(){
    string s;
    cin >> s;
    if(s[s.size()-1]=='s'){
        cout << s << 'e' << 's'<< endl;
        
    }
    else{
    
        cout << s << 's' << endl;
    }
    return 0;
 }

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  for (int i = 0; i < s.length(); i++) s[i] = 'x';

  cout << s << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> X;
  int n;
  for (int i = 0; i < N; i++) {
    cin >> n;
    X.push_back(n);
  }
  int point;
  int minPoint = -1;
  for (int P = 0; P < 100; P++) {
    point = 0;
    for (int x : X) {
      point += (x - P) * (x - P);
    }
    if (minPoint == -1) {
      minPoint = point;
    } else if (point < minPoint) {
      minPoint = point;
    }
  }
  cout << minPoint << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int MN = 1000005;

int N, Ans;
char S[MN], T[MN];
int bias, que[MN], head, tail;

int main() {
	scanf("%d%s%s", &N, S + 1, T + 1);
	int ok = 1;
	for (int i = 1; i <= N; ++i) if (S[i] != T[i]) ok = 0;
	if (ok) return puts("0"), 0;
	head = 1, tail = 0;
	for (int i = N, j = N; i >= 1; --i) {
		if (j > i) j = i;
		while (head <= tail && que[head] + bias > i) ++head;
		Ans = std::max(Ans, tail - head + 2);
		if (i == 1 || T[i - 1] != T[i]) {
			while (j && S[j] != T[i]) --j;
			if (!j) return puts("-1"), 0;
			--bias;
			que[++tail] = j - bias;
			--j;
		}
	}
	printf("%d\n", Ans);
	return 0;
}

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

struct Node {
  int id;
  Node *left;
  Node *right;
  Node *parent;
  Node *sibling;
  int depth;
  int height;

  Node(int id) : id(id), left(NULL), right(NULL), parent(NULL), sibling(NULL), depth(-1), height(-1) {};

  ~Node() {
    delete left;
    delete right;
  }
};

Node* getNode(map<int, Node*> &nodes, int id) {
  map<int, Node*>::iterator it = nodes.find(id);
  if (it == nodes.end()) {
    Node *node = new Node(id);
    nodes[id] = node;
    return node;
  } else {
    return it->second;
  }
}

Node *findRoot(Node *node) {
  Node *p = node;
  while (p->parent) {
    p = p->parent;
  }
  return p;
}

int parse(Node *node, int depth) {
  int height = 0;
  node->depth = depth;
  if (node->left) {
    int leftHeight = parse(node->left, depth + 1);
    if (leftHeight + 1 > height) {
      height = leftHeight + 1;
    }
  }
  if (node->right) {
    int rightHeight = parse(node->right, depth + 1);
    if (rightHeight + 1 > height) {
      height = rightHeight + 1;
    }
  }
  node->height = height;
  return height;
}

void printNode(Node *node) {
  cout << "node " << node->id << ": parent = ";
  if (!node->parent) {
    cout << -1;
  } else {
    cout << node->parent->id;
  }
  cout << ", sibling = ";
  if (!node->sibling) {
    cout << -1;
  } else {
    cout << node->sibling->id;
  }
  int degree = 0;
  if (node->left) {
    ++degree;
  }
  if (node->right) {
    ++degree;
  }
  cout << ", degree = " << degree <<", depth = " << node->depth << ", height = " << node->height << ", ";
  if (!node->parent) {
    cout << "root";
  } else if (degree) {
    cout << "internal node";
  } else {
    cout << "leaf";
  }
  cout << endl;
}

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

  int N;
  cin >> N;

  map<int, Node*> nodes;
  for (int i = 0; i < N; ++i) {
    int id, leftId, rightId;
    cin >> id >> leftId >> rightId;

    Node *n = getNode(nodes, id);
    Node *l = leftId == -1 ? NULL : getNode(nodes, leftId);
    Node *r = rightId == -1 ? NULL : getNode(nodes, rightId);

    n->left = l;
    n->right = r;
    if (l) {
      l->parent = n;
      l->sibling = r;
    }
    if (r) {
      r->parent = n;
      r->sibling = l;
    }
  }

  Node *root = findRoot(nodes.begin()->second);

  // attach depth and height
  parse(root, 0);

  for (map<int, Node*>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
    printNode(it->second);
  }

  delete root;

  return 0;
}



Measured memory_bytes: 3220
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int Aplace =0;
    int Zplace =0;
    int len = S.length();
    for(int i=0;i<len;i++){
      if(S.substring(i,i+1).equals("A")){
        Aplace=i;
        break;
      }
    }
    for(int i=len;i>0;i--){
      if(S.substring(i-1,i).equals("Z")){
        Zplace=i;
        break;
      }
    }
    System.out.println(Zplace-Aplace);
  }
  

  
}

Measured memory_bytes: 32232
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--d >= 0){
        vector<int> a(9), b(9);
        for(int i=0; i<9; ++i)
            cin >> a[i];
        for(int i=0; i<9; ++i)
            cin >> b[i];
        sort(a.begin(), a.end());

        int win = 0;
        int lose = 0;
        do{
            int x = 0;
            int y = 0;
            for(int i=0; i<9; ++i){
                if(a[i] > b[i])
                    x += a[i] + b[i];
                else
                    y += a[i] + b[i];
            }
            if(x > y)
                ++ win;
            else
                ++ lose;
        }while(next_permutation(a.begin(), a.end()));

        printf("%.5f %.5f\n", (double)win/(win+lose), (double)lose/(win+lose));
    }

    return 0;
}

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

using namespace std;

int main() {
	string s, k = "keyence";
	cin >> s;
	for (int i = 0; i < 8; i++) {
		if (s.substr(0, i) == k.substr(0, i) && s.substr(s.length() + i - 7) == k.substr(i)) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int ans = 0;
  if (N > 1) {
    ans += N * (N - 1) / 2;
  }
  if (M > 1) {
    ans += M * (M - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
s = input()

ans = [0] * len(s)

cnt = 0

for i in range(len(s)):
    if s[i] == 'R':
        cnt += 1
    else:
        ans[i] += cnt // 2
        ans[i-1] += (cnt+1) // 2
        cnt = 0

ans.reverse()
#print(ans)
#exit()

s_list = list(reversed(s))
#s.reverse()

cnt = 0

for i in range(len(s_list)):
    if s_list[i] == 'L':
        s_list[i] = 'R'
    else:
        s_list[i] = 'L'

for i in range(len(s_list)):
    if s_list[i] == 'R':
        cnt += 1
    else:
        ans[i] += cnt // 2
        ans[i-1] += (cnt+1) // 2
        cnt = 0

ans.reverse()

print(*ans)

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e9;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, K; cin >> N >> K;
    vi sum(N+1, 0); REP(i, N+1) sum[i] = i;
    REP(i, N) sum[i+1] += sum[i];
    int ans = 0;
    for(int i = K; i <= N; i++)
    {
        ans += (sum[N]-sum[N-i]) - sum[i-1]+1;
        ans %= MOD;
    }
    cout << ans +1 << endl;
}

Measured memory_bytes: 4724
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int arr[105];
int arre[105];

int main(){
	int n;
	cin>>n;
	
	for(int i=0;i<n-1;i++){
		cin>>arr[i];
	}
	arre[1]=arr[0];
	arre[0]=arr[0];
	for(int i=0;i<n;i++){
		if(i==n-1){
			arre[i+1]=arr[i];
			//printf("1");
		}else{
			if(arr[i]<arre[i]){
				arre[i]=arr[i];
				//printf("3");
			}
			arre[i+1]=arr[i];
			//printf("2");
		}
	}
	
	long long int sum=0;
	for(int i=0;i<n;i++){
		sum+=arre[i];
		//printf("%d",arre[i]);
	}
	
	printf("%d",sum);
	return 0;
}










Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

surviver = As[0]
break_number = []

for i in range(N):
    monster_num = As[i+1] + surviver
    hero_num = Bs[i]
    if hero_num > monster_num:
        break_number.append(monster_num)
        surviver = 0
    else:
        break_number.append(hero_num)
        surviver = min(monster_num - hero_num, As[i+1])

print(sum(break_number))

Measured memory_bytes: 18624
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>

using namespace std;

const double EPS = 1.0e-9;
const double INF = 1.0e20;

int dsign(double d) {
    if (fabs(d) < EPS) {
        return 0;
    } else {
        return d < 0 ? -1 : 1;
    }
}

struct Point {
    int x, y;

    Point(int x = 0, int y = 0) : x(x), y(y) {
    }

    bool operator<(const Point& other) const {
        return x < other.x || (x == other.x && y < other.y);
    }
};

double dist(const Point& a, const Point& b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

struct BiTSP {
    int n;
    vector<vector<double>> memo;
    vector<vector<double>> d;
    
    double solve(vector<Point>& points, int n) {
        this->n = n;
        sort(points.begin(), points.end());
        
        d.assign(n, vector<double>(n, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                d[i][j] = dist(points[i], points[j]);
            }
        }
        memo.assign(n, vector<double>(n, -1));
        return search(0, 0);
    }

    double search(int i, int j) {
        if (i < j) {
            return search(j, i);
        }
        if (memo[i][j] != -1) {
            return memo[i][j];
        }
        double result = INF;
        if (i == n - 1) {
            result = d[j][n - 1]; 
        }
        else {
            result = min(search(i + 1, j) + d[i][i + 1], search(i, i + 1) + d[j][i + 1]); 
        }
        memo[i][j] = result;
        return result;
    }
};

int main() {
    int n;
    cin >> n;
    vector<Point> a;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        a.push_back(Point(x, y));
    }
    BiTSP tsp;
    double ans = tsp.solve(a, n);

    cout << fixed << setprecision(9) << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  vll a(n),b(n);
  REP(i,n)cin>>a[i];
  REP(i,n)cin>>b[i];

  ll dp[1<<n][55];
  REP(i,1<<n)REP(j,55)dp[i][j]=LLINF;
  dp[0][0]=0;

  REP(bit,1<<n){
    ll cnt=0;
    REP(i,n){
      if((1<<i)&bit)
        cnt++;
    }

    vpl ord;
    ll now=cnt;
    REP(i,n){
      if((1<<i)&bit)
        continue;

      ord.push_back(pll(i,now));
      now++;
    }


    for(auto o:ord){
      ll dist=abs(o.FI-cnt);
      ll o_value;
      if(dist%2==0)
        o_value=a[o.FI];
      else
        o_value=b[o.FI];

      REP(j,55){
        if(dp[bit][j]==LLINF)
          continue;
        if(o_value<j)
          continue;

        dp[bit|(1<<o.FI)][o_value]=min(dp[bit|(1<<o.FI)][o_value], dp[bit][j]+abs(o.SE-cnt));
      }
    }
  }

  ll ans=LLINF;
  REP(j,55)ans=min(ans,dp[(1<<n)-1][j]);

  if(ans==LLINF)
    cout<<-1<<endl;
  else
    cout<<ans<<endl;


}



Measured memory_bytes: 116240
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n,k;
  std::cin >> n >> k;
  vt<int> h(n);
  rep(i,n)
    std::cin >> h[i];

  sort(h.begin(),h.end());
  int ans = 1e9;
  for (size_t i = 0; i < n - k + 1; i++) {
    if(ans > h[i+k-1] - h[i])
      ans = h[i+k-1] - h[i];
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيم
/*
*Aurthor : @SahimSalem
*Date : 8/12/2020
*/


#include <bits/stdc++.h>
using namespace std;


#define I64 long long
#define el cout << '\n';
#define lcm(a, b) a / __gcd(a, b) * b
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Int(x)  (int)( x - '1' )
#define Max(a,b,c) max(max(a,b),max(a,c))
#define mod 1000000007

//debug
template <class... Args>auto &see(const Args &... args){return ((cerr << " " << args), ...) << '\n';}
#define bug(...)   cerr << "[ " #__VA_ARGS__ " ] = "; see(__VA_ARGS__) << '\n';

void solve( )
{
   int n ; cin >> n ;
  
  if(n%10 == 7 || (n/10)%10 == 7 || (n/100)%10 == 7 ) cout <<"Yes\n" ;
  
  else cout << "No\n" ;

}


int main(){
    IOS
    
    int t = 1  ;

    while(t--) solve(  ) ;

}


Measured memory_bytes: 3604
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF =  1e17;
int k, m, t;ll  sum = 0, ans = 0; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
ll n,dp[110][100100],weight[110],value[10010];
int main(void) {
    cin >> n >> m;
    rep(i, n) cin >> weight[i] >> value[i];
    Fill(dp, INF);
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, 100100) {
            if (j - value[i] >= 0) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - value[i]] + weight[i]);
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    rep(i, 100100) {
        if (dp[n][i] <= m) ans = i;
    }cout <<ans <<endl;
}

Measured memory_bytes: 86272