akhauriyash/Code-Regression huggingface dataset:
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pb push_back
using namespace std;
void solve(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    double a,b;
    a=w,b=h;
    cout<<a*b/2<<" ";
    if(x*2==a && y*2==b)
    cout<<"1";
    else
    cout<<"0";
    
}
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 3792
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n,m;
vp ans;

int main(){
	while(1){
		cin>>n>>m;
		if(!n&&!m) break;
		ans=vp(m);
		bool tmp;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin>>tmp;
				if(tmp) ans[j].first--;
			}
		}
		for(int i=0;i<m;i++) ans[i].second=i+1;
		sort(ans.begin(),ans.end());
		for(int i=0;i<m-1;i++) cout<<ans[i].second<<' ';
		cout<<ans[m-1].second<<endl;
	}
}

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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ld long double
const int MxN = 200001 ; 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
# define RFOR(i,a,b) for(int i = a ; i >= b ; --i)
const int MOD = 1e9 + 7 ; 

/* VARIABLES */
int k ;  
/* END OF VARIABLES */



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

	cin >> k ; 
	if(k % 2 == 0) {
		cout << -1 ;
		return 0 ; 
	}
	bool ok1 = false , ok2 = false ;
	if(k % 7 == 0) 
		ok1 = true ;  
	int powof10 = 1 ; 
	int n = 1e6 ; 
	int r = 0 ; 
	FOR(i,1,n) {
		r += (7 * powof10 ) % k ;
		//cout << r  << " " << powof10 << endl ;
		r = r % k ;  
		if(r == 0 ) {
			cout << i ;
			return 0 ;  
		}
		powof10 = (powof10 * 10) % k ; 

	}

	cout << "-1" ; 
	return 0 ; 
}



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

int main(){
  vector<string>str={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int i,ans;
  i=0;
  ans=0;
  string s;
  cin>>s;
  while(str[i]!=s){
    ans++;
    i++;
  }
  
  cout<<7-ans;  
 
}

Measured memory_bytes: 256
from sys import stdin, stdout
from functools import lru_cache
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()

def num_digs(n):
	return len(str(n))

@lru_cache(None)
def lunlun(n, pos, tight, prev):
	if pos >= len(n):
		return 1
	md = n[pos] if tight else 9
	sd = 1 if pos == 0 else 0
	count = 0
	for d in range(sd, md + 1):
		new_tight = 1 if tight and d == n[pos] else 0
		if (pos == 0) or (d in {prev - 1, prev, prev + 1}):
			count += lunlun(n, pos  + 1, new_tight, d)
	return count 

def lunlun2(n):
	ans = 0
	for i in range(1, num_digs(n)):
		tupn = tuple(9 for _ in range(i))
		pt = lunlun(tupn, 0, 1, 0)
		ans += pt
	tupn = tuple(int(x) for x in str(n))
	ans += lunlun(tupn, 0, 1, 0)
	return ans	

def main():
	k = int(rl())
	n, jump = 10**19, 10**19
	while jump >= 1:
		while n - jump >= 0 and lunlun2(n - jump) >= k:
			n -= jump
		jump //= 2
	stdout.write(str(n));stdout.write("\n")
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 51160
fun main(args: Array<String>){
  val values = readLine()!!.split(" ")
  val a = values[0].toLong()
  val b = values[1].toLong()
  val c = values[2].toLong()
  val d = values[3].toLong()
  val diff: Long = b - a
  val count: Long = diff + 1
  
  // calc e
  val multi: Long = c * d
  var big: Long = c
  var small: Long = d 
  var tmp: Long = 0
  if (big < small) {
    tmp = big
    big = small
    small = tmp
  }
  var e: Long = big % small
  while (e != 0.toLong()) {
    big = small
    small = e
    e = big % small
  }
  e = multi / small

  // c
  var sa_c: Long = 0
  if (a % c == 0.toLong()) {
    sa_c = a
  } else {
    sa_c = a + (c - a % c)
  }
  val ea_c: Long = b - (b % c)
  val da_c: Long = ea_c - sa_c
  val sum_c: Long = da_c / c + 1
  
  // d
  var sa_d: Long = 0
  if (a % d == 0.toLong()) {
    sa_d = a
  } else {
    sa_d = a + (d - a % d)
  }
  val ea_d: Long = b - (b % d)
  val da_d: Long = ea_d - sa_d
  val sum_d: Long = da_d / d + 1
  
  // e(-)
  var sa_e: Long = 0
  if (a % e == 0.toLong()) {
    sa_e = a
  } else {
    sa_e = a + (e - a % e)
  }
  val ea_e: Long = b - (b % e)
  val da_e: Long = ea_e - sa_e
  val sum_e: Long = da_e / e + 1
  
  val result: Long = count - sum_c - sum_d + sum_e
  println(result)
}


Measured memory_bytes: 36136
import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long m = sc.nextLong();
    long[] kai = new long[1000001];
    kai[0] = 1;
    for(int i = 1; i <= 1000000; i++) {
      kai[i] = (kai[i - 1] * (long)i) % MOD;
    }
    HashMap<Long, Long> map = new HashMap<Long, Long>();
    for(long i = 2; (i * i) <= m; i++) {
      if((m % i) == 0) {
        long t = 0;
        while((m % i) == 0) {
          t++;
          m /= i;
        }
        map.put(i, t);
      }
    }
    if(m > 1) map.put(m, (long)1);
    long ans = 1;
    for(long key : map.keySet()) {
      long s = map.get(key);
      long t1 = kai[(int)(s + n - 1)];
      long t2 = kai[(int)s];
      long t3 = kai[(int)(n - 1)];
      t2 = func(t2, MOD - 2);
      t3 = func(t3, MOD - 2);
      ans = (ans * t1) % MOD;
      ans = (ans * t2) % MOD;
      ans = (ans * t3) % MOD;
    }
    System.out.println(ans);
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if((x % 2) == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      long t = func(a, x / 2);
      t = (t * t) % MOD;
      return (a * t) % MOD;
    }
  }
}

Measured memory_bytes: 30164
n,m = map(int,input().split())
lst = [0]
for i in range(n - 1):
  lst.append(lst[-1] + int(input()))
ans = 0
num = 0
for i in range(m):
  a = int(input())
  ans += abs(lst[num] - lst[num + a])
  ans %= 100000
  num += a
print(ans)



Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b,c,d,i,j,sum=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a>>b;
		sum=sum+abs(b-a)+1;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    string S, T;
    cin >> S;
    cin >> T;
    auto same = [](string s, string t) {
        //cout << "比較します. " << s << ", " << t << endl;
        int l = s.length();
        for (int i = 0; i < l; ++i)
        {
            auto c1 = *(s.c_str() + i);
            if (c1 != '?')
            {
                auto c2 = *(t.c_str() + i);
                if (c1 != c2)
                {
                    return false;
                }
            }
        }
        return true;
    };
    if (T.length() > S.length())
    {
    }
    else
    {
        for (int i = S.length() - T.length(); i >= 0; --i)
        {
            if (same(S.substr(i, T.length()), T))
            {
                S.replace(S.begin() + i, S.begin() + i + T.length(), T);
                replace(S.begin(), S.end(), '?', 'a');
                cout << S << endl;
                return 0;
            }
        }
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

ll mod_pow(ll x, ll y, ll p) {
    ll res = 1;
    while (y > 0) {
        if (y & 1) res = res * x % p;
        x = x * x % p;
        y >>= 1;
    }
    return res;
}


int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<string> s(n);
	REPU(i, 0, n) cin >> s[i];

	vector<vector<ll>> hsr(n, vector<ll>(n, 0));
	vector<vector<ll>> hsc(n, vector<ll>(n, 0));

	ll p = 23;
	ll pwn = mod_pow(p, n - 1, MOD);
	REPU(i, 0, n) {
		ll v = 0;
		REPU(j, 0, n) v = (v * p + (s[i][j] - 'a')) % MOD;
		hsr[i][0] = v;
		REPU(j, 1, n) {
			int nc = s[i][j - 1] - 'a';
			v = (hsr[i][j - 1] - pwn * nc) % MOD;
			v = (v * p + nc) % MOD;
			if (v < 0) v += MOD;
			hsr[i][j] = v;
		}
	}
	REPU(j, 0, n) {
		ll v = 0;
		REPU(i, 0, n) v = (v * p + (s[i][j] - 'a')) % MOD;
		hsc[0][j] = v;
		REPU(i, 1, n) {
			int nc = s[i - 1][j] - 'a';
			v = (hsc[i - 1][j] - pwn * nc) % MOD;
			v = (v * p + nc) % MOD;
			if (v < 0) v += MOD;
			hsc[i][j] = v;
		}
	}

	int ans = 0;
	REPU(a, 0, n) REPU(b, 0, n) {
		bool ok(true);
		REPU(i, 0, n) if (hsr[(i + a) % n][b] != hsc[a][(i + b) % n]) {
			ok = false; break;
		}
		if (ok) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1920
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem127a(a, b))
}

fun problem127a(a: Int, b: Int): Int {
    return when {
        a >= 13 -> b
        a >= 6 -> b / 2
        else -> 0
    }
}

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

int main() {
	long long n, m, lcm = 1;
	cin >> n >> m;

	vector < long long > a(n);

	for ( auto &i: a ) {
		cin >> i;
		i /= 2;
		lcm = lcm / __gcd( lcm, i ) * i;
		if ( lcm > m ) {
			cout << 0;
			return 0;
		}
	}
	for ( auto i: a ) {
		if ( lcm / i % 2 == 0 ) {
			cout << 0;
			return 0;
		}
	}
	cout << 1 + (m - lcm) / (2 * lcm);
}


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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int w, h, n;
  cin >> w >> h >> n;

  int left = 0, right = w, bottom = 0, top = h;
  for(int i = 0; i < n; ++i){
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1){
      left = max(left, x);
    }
    else if(a == 2){
      right = min(right, x);
    }
    else if(a == 3){
      bottom = max(bottom, y);
    }
    else{
      top = min(top, y);
    }
  }

  if(bottom < top && left < right){
    cout << (right - left) * (top - bottom) << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}

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


int main(){
	int a,l,x;
	while(cin>>a>>l>>x&&a){
		double h=sqrt((l+x)*(l+x)-l*l)/2;
		double g=sqrt(l*l-(double)a*a/4);
		printf("%.8f\n",a*g/2+h*l);
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main(){
	int i,n;
	cin>>n;
	vector<int> a(n), b(n), c(n);
	for(i=0; i<n; ++i)
		cin>>a[i]>>b[i]>>c[i];
	vector<vector<int>> dp(n,vector<int>(3));
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(i=1; i<n; ++i){
		dp[i][0]=max(dp[i-1][1], dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0], dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0], dp[i-1][1])+c[i];
	}
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<"\n";
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

vector<ll> sosuu(ll x) {
    vector<ll> p(0);
    for(ll j=2; j*j<=x;j++) {
        if(x%j!=0) continue;
        p.push_back(j);
        while(x%j==0) x/=j;
    }
    if(x!=1) p.push_back(x);
    return p;
}

ll gcd(ll a,ll b){
    ll max_=max(a,b);
    ll min_=min(a,b);
    if(min_==0){
        return max_;
    }
    return gcd(min_,max_%min_);
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    ll gcd_=gcd(a,b);
    vector<ll> p=sosuu(gcd_);
    //rep(i,p.size()) cout<<p[i]<<" ";
    //cout<<endl;
    cout<<p.size()+1<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n

dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[n - 1])


Measured memory_bytes: 52208
#include <iostream>

using namespace std;

int main(){
  bool prime[300000];
  for(int i=6;i<3e5;i++){
    if (!(i%7-1)||!(i%7-6)){
      prime[i] = true;
      for(int j=1;j*j<=i;j++)
	if (((7*j-1)<i&&i%(7*j-1)==0)||((7*j+1)<i&&i%(7*j+1)==0))
	  prime[i] = false;
    }
    else
      prime[i] = false;
  }
  
  int n;
  while(true){
    cin >>n;
    if (n==1)
      break;
    cout << n << ":";
    for(int i=1;7*i-1<=n;i++){
      if (prime[7*i-1]&&!(n%(7*i-1)))
	cout <<" "<< 7*i-1; 
      if (prime[7*i+1]&&!(n%(7*i+1)))
	cout <<" " << 7*i+1; 
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		Set<Long> set = new HashSet<>();

		for(int i=0;i<N;i++) {
			set.add(sc.nextLong());
		}
		System.out.println(set.size()==N?"YES":"NO");
	}
}


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

int h,w;
int c[10][10];
int A[201][201];
int min_cost[10];
int sum_cost;

int main(){

    cin>>h>>w;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin>>c[i][j];
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>A[i][j];
        }
    }

    for(int i=0; i<10; i++){
        if(i==1){
            continue;
        }
        int elim_cost[10];
        queue<pair<int,int> > q;
        for(int j=0; j<10; j++){
            elim_cost[j]=100000;
        }
        elim_cost[i]=0;
        q.push(make_pair(i,0));
        while(!q.empty()){
            int cur_num=q.front().first,
                cur_cost=q.front().second;
            //cout<<cur_cost<<endl;
            for(int j=0; j<10; j++){
                //cout<<j<<endl;
                if(elim_cost[j]>cur_cost+c[cur_num][j]){
                    //cout<<'b'<<endl;
                    elim_cost[j]=cur_cost+c[cur_num][j];
                    q.push(make_pair(j,cur_cost+c[cur_num][j]));
                }
            }
            //cout<<'a'<<endl;
            q.pop();
        }
        min_cost[i]=elim_cost[1];
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(A[i][j]!=-1||A[i][j]!=1){
                sum_cost+=min_cost[A[i][j]];
                //cout<<min_cost[A[i][j]]<<endl;;
            }
        }
    }

    cout<<sum_cost<<endl;

    return 0;
}



Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2000000)
n,m=map(int,input().split())
path={i:[] for i in range(n)}
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b)
  path[b-1].append(a)
sign=[0]*n

def bfs(poslist,sign):
  if len(poslist)==0:
    return sign
  nex=[]
  for pos in poslist:
    lis = [x for x in path[pos-1] if sign[x-1]==0]
    for i in lis:
      sign[i-1]=pos
      nex.append(i)
  return bfs(nex,sign)
      
  
sign=bfs([1],sign)
print('Yes')
for i in range(1,n):
  print(sign[i])

Measured memory_bytes: 311804
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    int sum  = 0;
    for (int i = 0; i < 3; i++)
    {
        if(s[i ] == 'R') sum ++;
    }
    if(sum == 1 || sum == 3 || sum == 0) cout << sum;
    else{
        if(s[1] == 'R') cout << 2;
        else cout << 1;
    }    
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = 0;
    for(int i=1;i<=N;i++) if(i & 1) if(divisor(i).size() == 8) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

inline ll f(ll a) {
  if(a % 2 == 0) return a / 2;
  return a * 3 + 1;
}

int main(void) {
  ll s;
  cin >> s;
  set<ll> ss;
  for(int i = 1; ; ++i) {
    if(ss.count(s)) {
      cout << i << endl;
      break;
    }
    ss.insert(s);
    s = f(s);
  }
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010];
int B[200010];
int num[200010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
		if(i+A[i]-1<=N-1){
			num[i+A[i]-1]++;
		}
	}
	REP(i,N){
		DEB(num[i])END
	}
	int ans=0;
	for(int i=N-1;0<=i;i--){
		int l=i+1;
		if(i-A[i]-1<0){
			continue;
		}
		DEB(num[i-A[i]-1])DEB(i)END
		ans+=num[i-A[i]-1];
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long double ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

int main()
{

    ll a, b, c;
    cin >> a >> b >> c;

    if (a+b+2*sqrt(a*b)<c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

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

#define int long long

typedef pair<int, int> ii;

const int N = 3e3 + 5;

int lcs[N][N];
ii tr[N][N];

string s, t;

vector<int> vec;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> s >> t;
    s = "+" + s;
    t = "+" + t;
    for(int i = 1; i < s.length(); i++) {
        for(int j = 1; j < t.length(); j++) {
            if(s[i] == t[j]) {
                if(lcs[i - 1][j - 1] + 1 > lcs[i][j]) {
                    tr[i][j] = {i - 1, j - 1};
                }
                lcs[i][j] = max(lcs[i - 1][j - 1] + 1, lcs[i][j]);
            }
            if(lcs[i - 1][j] > lcs[i][j]) {
                tr[i][j] = {i - 1, j};
                lcs[i][j] = lcs[i - 1][j];
            }
            if(lcs[i][j - 1] > lcs[i][j]) {
                tr[i][j] = {i, j - 1};
                lcs[i][j] = lcs[i][j - 1];
            }
            lcs[i][j] = max(lcs[i][j], max(lcs[i - 1][j], lcs[i][j - 1]));
        }
    }
    int m = s.length() - 1, n = t.length() - 1, sum = lcs[m][n];
    while(m > 0 || n > 0) {
        ii frt = tr[m][n];
        if(sum == 0) break;
        if(abs(frt.fi - m) + abs(frt.se - n) == 2) {
            vec.pb(m);
            sum--;
        }
        m = frt.fi;
        n = frt.se;
    }
    reverse(vec.begin(), vec.end());
    for(int i = 0; i < vec.size(); i++)
        cout << s[vec[i]];
}


Measured memory_bytes: 211968
#include <stdio.h>

int main(){
    int n, m, l, r, i, min=0, max=100001;

    scanf("%d %d", &n, &m);

    for(i=0; i<m; i++){
        scanf("%d %d", &l, &r);

        if(min < l)
            min = l;
        if(max > r)
            max = r;
    }

    if(min <= max)
        printf("%d\n", max-min+1);
    else
        printf("0\n");
    
    return 0;
}

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

int main()
{
    std::string s;
    std::cin >> s;

    std::reverse(s.begin(), s.end());

    int pos = 1;
    const int mod = 1000000007;
    std::vector<long long> reminders(13, 0);
    reminders[0] = 1;
    for (auto c : s) {
        std::vector<long long> new_reminders(13, 0);
        if (c == '?') {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 13; j++) {
                    new_reminders[(i * pos + j) % 13] += reminders[j];
                    new_reminders[(i * pos + j) % 13] %= mod;
                }
            }
        } else {
            int i = c - '0';
            for (int j = 0; j < 13; j++) {
                new_reminders[(i * pos + j) % 13] += reminders[j];
                new_reminders[(i * pos + j) % 13] %= mod;
            }
        }

        pos *= 10;
        pos %= 13;
        reminders = new_reminders;
    }

    std::cout << reminders[5] << std::endl;
}


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

const int MAX = 510000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();

    long long S;
    std::cin >> S;
    long long ans = 0LL;

    if (S<3LL)
        ans=0LL;
    else
    {
        ans=0LL;
        for(long long n=1LL; n < S/3LL+1LL; n++)
        {
            long long o = S-3LL*n;
            long long s= o+n-1;

            ans += COM(s,o);
            ans %= MOD;
        }
    }
    
    std::cout << ans << std::endl;

}

Measured memory_bytes: 15528
#include <iostream>

using namespace std;
int main(){
	int i,x;
	cin >> x;
	for(i=1;i<=50000;i++){
		double y = (double)i;
		y *= 1.08;
		int z = (int)y;
		if(z==x){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}

Measured memory_bytes: 256
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function ceillog2(x:number){
  if(x<=1)return 0;
  return ceillog2(x/2)+1;
}
function solve(x:number,K:number){
  return Math.pow(0.5, ceillog2(K/x));
}
function Main(_: NormalInput) {
  const [N,K]=[_.int(),_.int()];
  let sum=0;
  for(let i=1;i<=N;i++){
    sum+=solve(i,K);
  }
  console.log(sum/N);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


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

typedef long long LL;
const int weight[4] = {1, 1000, 1000000, 1000000000};
const int N = 505;

std::unordered_map<LL, int> num;
LL q[N], ans;

inline int get(LL s, int b) { return s / weight[b] % 1000; }
inline void insert(LL s, int v = 1) {
	for (int i = 0; i < 4; ++i)
		num[s] += v, s = s % 1000 * weight[3] + s / 1000;
}
inline void remove(LL s) { insert(s, -1); }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	int n; std::cin >> n;
	for (int i = 0; i < n; insert(q[i++]))
		for (int j = 0, x; j < 4; ++j) std::cin >> x, q[i] += (LL) x * weight[j];
	for (int i = 0; i < n; ++i) {
		remove(q[i]);
		for (int j = i + 1; j < n; ++j) {
			remove(q[j]);
			int up[5], down[5]; LL s[4];
			for (int k = 0; k < 4; ++k) up[3 - k] = get(q[i], k); up[4] = up[0];
			for (int k = 0; k < 4; ++k) down[k] = get(q[j], k); down[4] = down[0];
			for (int shift = 0; shift < 4; ++shift) {
				LL prod = 1;
				for (int k = 0; k < 4; ++k) {
					s[k] = up[k] + up[k + 1] * 1000 + down[k + 1] * 1000000 + down[k] * 1000000000LL;
					prod *= num[s[k]], remove(s[k]);
				}
				ans += prod;
				for (int k = 0; k < 4; ++k) insert(s[k]);
				int t = up[3]; up[3] = up[2], up[2] = up[1], up[1] = up[0], up[4] = up[0] = t;
			}
			insert(q[j]);
		}
		insert(q[i]);
	}
	std::cout << ans / 3 << '\n';
	return 0;
}

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

class Program
    {
static void Main(string[] args)
        {
            var HWK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var A = HWK[0];
            var B = HWK[1];
            
            if(B%A ==0 ){
              Console.WriteLine(A+B);
            }else{
              Console.WriteLine(B-A);
            }
            
        }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, M;
    cin >> N >> M;
    int ans = 0;
    map<int, int> mp;

    for(int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for(int j = 0; j < K; j++) {
            int a;
            cin >> a;
            if(mp.count(a)) {
                mp[a]++;
            } else {
                mp[a] = 1;
            }
        }
    }

    for(int i = 1; i <= M; i++) {
        if(mp[i] == N) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
s=input()
y=int(s[:4])
m=int(s[5:7])
d=int(s[8:])
      
if y<2019:
  print('Heisei')
else:
  if y==2019 and m<4:
    print('Heisei')
  else:
    if y==2019 and m==4 and d<=30:
      print('Heisei')
    else:
      print('TBD')

Measured memory_bytes: 3060
import sys
from math import sqrt

[nstr] = sys.stdin.readline().split(" ")
n = int(nstr)

for i in range(int(sqrt(n)), 0, -1):
    r = float(n) / float(i)
    if not r.is_integer():
        continue
    j = int(r)
    print(i-1 + j-1)
    exit()


Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var s = Console.ReadLine();
        var k = int.Parse(Console.ReadLine());
        //var n = int.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var dic = new Dictionary<string, string>() { };
        for (int i = 0; i < s.Length; i++)
        {
            for (int t = i + 1; t <= s.Length; t++)
            {
                if (t - i> k)
                {
                    break;
                }
                if (!dic.ContainsKey(s.Substring(i, t - i)))
                {
                    dic.Add(s.Substring(i, t - i), s.Substring(i, t - i));
                }
            }
        }

        var ans = dic.OrderBy(val => val.Value).Skip(k - 1).First().Value;
        // 出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 14944
from collections import deque

import sys
input = sys.stdin.buffer.readline

N = int(input())
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

dist = [10**10] * N
que = deque([(0, 0)])
while que:
    now, d = que.popleft()

    if dist[now] <= d:
        continue
    dist[now] = d

    for to in edges[now]:
        que.append((to, d + 1))

A = [i for i, d in enumerate(dist) if d % 2 == 0]
B = [i for i, d in enumerate(dist) if d % 2 == 1]

if len(A) > len(B):
    A, B = B, A

ans = [-1] * N
nums = set(range(1, N + 1))

if len(A) <= N // 3:
    mul = 1
    for i in A:
        ans[i] = 3 * mul
        nums.remove(3 * mul)
        mul += 1
    nums = list(nums)
    for i, n in zip(B, nums):
        ans[i] = n
else:
    mul = 1
    for c, i in enumerate(A):
        if c * 3 + 1 > N:
            ans[i] = mul * 3
            mul += 1
        else:
            ans[i] = c * 3 + 1
    for c, i in enumerate(B):
        if c * 3 + 2 > N:
            ans[i] = mul * 3
            mul += 1
        else:
            ans[i] = c * 3 + 2

print(*ans)


Measured memory_bytes: 78172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[] sum = new int[m];
		
		int ans = 0;
		
		for (int i=0;i<m;i++) {
			sum[i] = sc.nextInt();
			ans+=sum[i];
		}

		if(n-ans < 0) {
			System.out.println(-1);
		} else {
			System.out.println(n-ans);
		}
		

	}
}



Measured memory_bytes: 46328
#include <stdio.h>
#define MAX 2000000000
#define INFTY (1 << 30)

void maxHeapify(int);
void insert(int);
void increaseKey(int, int);
int heapExtractMax(void);

int H, A[MAX];

void maxHeapify(int i)
{
  int l, r, largest, keep;
  l = 2 * i;
  r = 2 * i + 1;
  if (l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if (r <= H && A[r] > A[largest])
    largest = r;
  if (largest != i)
  {
    keep = A[i];
    A[i] = A[largest];
    A[largest] = keep;
    maxHeapify(largest);
  }
}

void insert(int key)
{
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

void increaseKey(int i, int key)
{
  int c;
  if (key < A[i])
    return;
  A[i] = key;
  while (i > 1 && A[i / 2] < A[i])
  {
    c = A[i / 2];
    A[i / 2] = A[i];
    A[i] = c;
    i = i / 2;
  }
}

int heapExtractMax()
{
  int max;
  if (H < 1)
    return -INFTY;
  max = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  return max;
}

int main()
{
  int key;
  A[H] = -INFTY;
  char com[10];

  while (1)
  {
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n')
      break;
    if (com[0] == 'i')
    {
      scanf("%d", &key);
      insert(key);
    }
    else
    {
      printf("%d\n", heapExtractMax());
    }
  }

  return 0;
}



Measured memory_bytes: 5764
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin>>x;
    if(x>=30)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(){
    string a;
    int b[26] = {0};

    while(getline(cin, a)){
        for(int i = 0; i < a.length(); i++){
            if(a[i] >= 'a' && a[i] <= 'z') a[i] -= 32;
            if(a[i] >= 'A' && a[i] <= 'Z') b[a[i] - 'A']++;
        }
    }
    for(int i=0; i < 26; i++){
        printf("%c : %d\n", 'a'+i, b[i]);
    }
    return 0;
}


Measured memory_bytes: 3272
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

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

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

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  vector<int> n(3); cin >> n[0] >> n[1] >> n[2];
  sort(n.begin(),n.end());
  if (n[0]==5&&n[1]==5&&n[2]==7){cout << "YES";}
  else {cout << "NO";}

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;

  ll sum = 0;
  rep(i, 1000000000) {
    sum += i;
    if (sum >= N) {
      RETURN(i);
    }
  }
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	ll a, b;
	cin >> a >> b;
	cout << a * b / __gcd(a, b);
}


Measured memory_bytes: 256
s=input()
n=len(s)-1
a=0
for i in range(1<<n):
  l=[]
  for x,y in zip(s,[''for _ in[0]*10]):
    l.append(x)
    l.append(y)
  for j in range(n):
    if i>>j&1:
      l[j*2+1]='+'
  a+=eval(''.join(l))
print(a)

Measured memory_bytes: 3060
mod = 10**9 +7

L = input()
N = len(L)
#dp[i][j][k] => 左からi桁目までみる。i桁目がjになるような場合のa,bの組み合わせの数。kは未満フラグ。
dp = [[[0]*2 for _ in range(2)]for _ in range(N)]

dp[0][1][0] = 2
dp[0][0][1] = 1

for i in range(N-1):
    x = int(L[i+1])
    for j in range(2):
        for k in range(2):
            if k == 0:
                r = x+1
            else:
                r = 2
            for l in range(r):
                if k==0 and l==x:
                    f = 0
                else:
                    f = 1
                if l==0:
                    dp[i+1][l][f] += dp[i][j][k]
                else:
                    dp[i+1][l][f] += dp[i][j][k]*2
                dp[i+1][l][f] %= mod
ans = sum(dp[-1][0])+sum(dp[-1][1])
ans %= mod
print(ans)

Measured memory_bytes: 101768
it = lambda: list(map(int, input().strip().split()))

def solve():
    X, K, D = it()
    X = abs(X)
    if X - K * D >= 0:
        return X - K * D
    K = K - X // D
    X = X - X // D * D
    assert K >= 0
    assert X >= 0
    return abs(X) if K % 2 == 0 else abs(X - D)


if __name__ == '__main__':
    ans = solve()
    print(ans)

Measured memory_bytes: 9076
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ull_t = unsigned long long;


template <class It> string join(It i1, It i2)
{
    ostringstream ss;
    for (auto it = i1; it != i2; ++it)
        ss << ((it == i1) ? "" : ", ") << (*it);
    return ss.str();
}

#ifdef DEBUG
#define Dump(x) cerr << #x << " = " << x << endl;
#define Dumps(x) cerr << #x << " : { " << join(x.begin(), x.end()) << " }" << endl;
#else
#define Dump(x)
#define Dumps(x)
#endif


int main()
{
    string S;
    long Q;
    cin >> S;
    cin >> Q;

    int r = 0;
    string s1;
    string s2;
    for (int i = 0; i < Q; ++i)
    {
        int t, f;
        char c;
        cin >> t;
        switch (t)
        {
        case 1:
            ++r;
            break;
        case 2:
            cin >> f >> c;
            switch ((f + r) % 2)
            {
            case 1:
                s1 += c;
                break;
            case 0:
                s2 += c;
                break;
            }
            break;
        }
    }
    Dump(s1);
    Dump(s2);

    if (r % 2 != 0)
    {
        reverse(S.begin(), S.end());
        reverse(s2.begin(), s2.end());
        S = s2 + S + s1;
    }
    else
    {
        reverse(s1.begin(), s1.end());
        S = s1 + S + s2;
    }

    cout << S << endl;
}


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

int main(){
    char s[10];


    scanf("%s",s);

    if((strcmp(s,"hi")==0))
        printf("Yes\n");
    else if((strcmp(s,"hihi")==0))
        printf("Yes\n");
    else if((strcmp(s,"hihihi")==0))
        printf("Yes\n");
    else if((strcmp(s,"hihihihi")==0))
        printf("Yes\n");
    else if((strcmp(s,"hihihihihi")==0))
        printf("Yes\n");
    else
        printf("No\n");



    return 0;
}


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

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {

    int n, k;
    cin >> n >> k;
    long long a[15];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    // combinationループ。NからKをとる通り数で調べる。
    long long minCost = LLONG_MAX;
    for (int bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit)) {
        // bitが立っている位置に対して、建物が見えるようにする時のコストを調べ、その最大値を取得する。
        long long maxHeight = 0;
        long long cost = 0;
        for (int i = 0; i < n; i++) {
            long long upHeight = 0;
            if (bit & (1 << i)) {
                upHeight = std::max(0ll, maxHeight + 1 - a[i]);
            }
            cost += upHeight;
            maxHeight = std::max(maxHeight, a[i] + upHeight);
        }
        minCost = std::min(minCost, cost);
    }
    cout << minCost << endl;

}

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

int main(void) {
	int A, B, K;
	scanf("%d %d %d", &A, &B, &K);
	for (int i = A; i < min(A + K, B + 1); i++) {
		printf("%d\n", i);
	}
	for (int i = max(A + K, B - K + 1); i <= B; i++) {
		printf("%d\n", i);
	}

	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, sum = 0, ans = 0;
  cin >> n;
  int a[n], b[n];
  rep(i,n)
    cin >> a[i];
  sum += a[0];
  rep(i,n)
  {
    cin >> b[i];
    sum += b[i];
  }
  ans = sum;
  rep(i,n-1)
  {
    sum += a[i + 1] - b[i];
    ans = max(ans, sum);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vs a;

void dfs(int id,int d){
	int t=id;
	for(int i=id+1;i<n&&d<a[i].size()&&a[i][d]=='.';i++){
		if(isalpha(a[i][d+1])){
			dfs(i,d+1);
			a[i][d]='+';
			t=i;
		}
	}
	for(int i=id+1;i<t;i++) if(a[i][d]=='.') a[i][d]='|';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		cin>>n;
		if(n==0) break;
		a=vs(n);
		for(int i=0;i<n;i++) cin>>a[i];
		dfs(0,0);
		for(int i=0;i<n;i++){
			for(auto c:a[i]) cout<<(c=='.'?' ':c);
			cout<<endl;
		}
	}
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7,N=100005;
inline int ksm(int x,int y)
{
	int ans=1;
	for (;y;y/=2,x=(ll)x*x%mod)
		if (y&1)
			ans=(ll)ans*x%mod;
	return ans;
}
void read(int &x)
{
    x=0;
    int y=1;
    char c=getchar();
    while (c>'9'||c<'0')
    {
        if (c=='-')
            y=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
    x*=y;
}
inline void gg()
{
	putchar('0');
	exit(0);
}
int n,x,a[N];
int main()
{
	read(n);
	for (int i=1;i<=n;++i)
	{
		read(x);
		++a[x];
	}
	if (n&1)
	{
		for (int i=2;i<=n;i+=2)
			if (a[i]!=2)
				gg();
		if (a[0]!=1)
			gg();
	}
	else
	{
		for (int i=1;i<=n;i+=2)
			if (a[i]!=2)
				gg();
	}
	cout<<ksm(2,n/2);
}

Measured memory_bytes: 764
/*
    Stay motivated and keep working hard
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
ll dp[1000007][3];
ll a[100007][3];
// ll rec(ll n, ll k){
//     if(n == 1){
//         ll ta = 0;
//         for(ll i=0;i<3;i++){
//             if(i == k){
//                 continue;
//             }
//             ta = max(ta, a[n][i]);
//         }
//         return ta;
//     }
//     if(dp[n][k]){
//         return dp[n][k];
//     }
//     ll ans = 0;
//     for(ll i=0;i<3;i++){
//         if(i == k){
//             continue;
//         }
//         ans = max(ans, a[n][i] + rec(n-1, i));
//     }
//     return dp[n][k] = max(dp[n][k], ans);
// }
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> n;
    for(ll i=1;i<=n;i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    // cout << max(rec(n, 0), max(rec(n, 1), rec(n, 2))) << "\n";
    dp[1][0] = a[1][0], dp[1][1] = a[1][1], dp[1][2] = a[1][2];
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(k == j){
                    continue;
                }
                dp[i][j] = max(dp[i][j], a[i][j] + dp[i-1][k]);
            }
        }
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << "\n";


    return 0;
}

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

using namespace std;


int main()
{
    int n,k,x;
    cin >> n >> k;
    vector<int> v;
    for(int i=0;i<n;i++) cin >> x,v.push_back(x);
    sort(v.rbegin(),v.rend());
    int s(0);
    for(int i=0;i<k;i++) s+=v[i];
    cout << s;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<char> c;
  c.push_back('K');
  for(int i=0;i<n-1;i++){
    if(s.at(i) == 'B' && s.at(i+1) == 'C'){
      c.push_back('S');
      i++;
      continue;
    }
    if(s.at(i) == 'A'){
      c.push_back('A');
      continue;
    }
    c.push_back('K');
  }
  int m = c.size();
  int count;
  long answer = 0;
  for(int i=0;i<m;i++){
    if(c.at(i) == 'K'){
      count = 0;
    }
    if(c.at(i) == 'A'){
      count++;
    }
    if(c.at(i) == 'S'){
      answer += count;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 772