akhauriyash/Code-Regression huggingface dataset:
public class Main {


  private static void solve() {
    int n = ni();
    int m = ni();
    
    System.out.println((int)Math.pow(2, m) * (1900 * m + 100 * (n - m)));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
map<ll, vector<P>> mp;
ll INF = __LONG_LONG_MAX__;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll N, X, D;
    cin >> N >> X >> D;
    if(D == 0){
        if(X == 0){
            cout << 1 << endl;
        }else{
            cout << N+1 << endl;
        }
        return 0;
    }
    if(D < 0){
        D *= -1;
        X *= -1;
    }
    for(ll i = 0; i <= N; i++){
        ll m = X*i;
        ll l = D*(i*(i-1))/2;
        ll r = D*(i*(2*N-i-1))/2;
        if(l > r) swap(l, r);
        ll rem = m%D;
        mp[rem].push_back(P(m+l, m+r));
    }
    ll ans = 0;
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        vector<P> v = iter->second;
        sort(v.begin(), v.end());
        ll l = v[0].first;
        ll r = v[0].second;
        // cout << l << ' ' << r << endl;
        for(int i = 1; i < v.size(); i++){
            ll s = v[i].first, t = v[i].second;
            // cout << s << ' ' << t << endl;
            if(s > r){
                ans += ((r-l)/D+1);
                l = s;
                r = t;
            }else{
                r = max(r, t);
            }
        }
        //cout << l << ' ' << r << endl;
        ans += ((r-l)/abs(D)+1);
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const double EPS = 1e-10;

int n;
double x[110], y[110], z[110], r[110];

struct UF{
   vector<int> par;
   vector<int> sz;
   UF(){}
   UF(int n){
       par.resize(n);
       sz.resize(n, 1);
       for(int i = 0; i < n; i++) par[i] = i;
   }
   int find(int x){
       if(x == par[x]) return x;
       return par[x] = find(par[x]);
   }
   void unite(int x, int y){
       x = find(x); y = find(y);
       if(x == y) return;
       if(sz[x] < sz[y]) swap(x, y);
       sz[x] += sz[y];
       par[y] = x;
   }
   bool same(int x, int y){
       return find(x) == find(y);
   }
};

struct edge{
    int u, v;
    double cost;
    bool operator<(const edge &e) const{
        return cost < e.cost;
    }
};

vector<edge> es; 

double kruskal(){
    double res = 0;    
    UF uf(n);
    sort(es.begin(), es.end());
    for(int i = 0; i < es.size(); i++){
        edge e = es[i];
        if(!uf.same(e.u, e.v)){
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

double dist(int i, int j){
    return sqrt((x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i]) + (z[j]-z[i])*(z[j]-z[i]));
}

signed main(){
    while(cin >> n, n){
        es.clear();
        rep(i, 0, n){
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }
        rep(i, 0, n){
            rep(j, i + 1, n){
                double tmp = dist(i, j) - r[i] - r[j];
                if(tmp < EPS) tmp = 0.0;
                es.push_back({i, j, tmp});
            }
        }
        double ans = kruskal();
        printf("%.3f\n", ans);
    }    
}


Measured memory_bytes: 3368
#include<stdio.h>
int main(void)
{
	int n,p[100],i,j,c,cnt;
	c=0;
	cnt=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<=n;i++){
		for(j=0;j<n;j++){
			if(i<=p[j]) c++;
		}
		if(i<=c) cnt=i;
		c=0;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	string t; cin >> t;
	string ans;
	rep(i, 2 * n) {
		if (i % 2 == 0) {
			ans += s[i / 2];
		}
		else {
			ans += t[i / 2];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    boolean[] expo = new boolean[x+1];
    expo[1] = true;
    for(int i = 2; i <=x; i++){
      int v = i * i;
      while(v <= x){
        expo[v] = true;
        v *= i;
      }
    }
    for(int i = x; i >= 1; i--){
      if(expo[i]){
        System.out.println(i);
        break;
      }
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

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

int main() {

  int W, H; cin >> W >> H;
  int N; cin >> N;

  auto outer = make_tuple(0, 0, 0);
  auto inner = make_tuple(0, 1, 0);

  int ans = 0;

  rep(i, N) {

    auto walk = [](int& x, int& y, int& t, int W, int H){
      if(x == W-1) {
        if(y == H-1) {
          x --;
          t = 1;
        }
        else {
          y ++;
        }
      }
      else if(!t) {
        x ++;
      }
      else {
        x --;
      }
    };

    auto next = [](int x, int y, int s, int t) {
      rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        if(nx == s && ny == t) { return true; }
      }
      return false;
    };

    int ox, oy, ot; tie(ox, oy, ot) = outer;
    int ix, iy, it; tie(ix, iy, it) = inner;

    int operation; cin >> operation;
    if(operation) {
      walk(ix, iy, it, W-1, H-1);
    }
    else {
      walk(ox, oy, ot, W, H);
    }

    if(next(ox, oy, ix, iy)) { ans ++; }

    outer = make_tuple(ox, oy, ot);
    inner = make_tuple(ix, iy, it);

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
  cin >> a >> b >> c;
  int i = min(a,b);
  int cnt = 0;
  while(cnt >= 0)
  {
  if(a % i == 0 && b % i == 0)
  cnt++;
  if(cnt == c)
  {
  cout << i << endl;
    break;
  }
    i--;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int n,ans,a[200100];
std::map<int,int>cnt;
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)
		scanf("%d",a+i);
	std::sort(a+1,a+1+n);
	for (register int i=n;i>=1;--i){
		int tem=1,x=a[i],f=0;
		for (register int j=1;j<=30;++j){
			tem<<=1;
			int v=tem-x;
			if (v<0) continue;
			if (!cnt[v]) continue;
			cnt[v]--,ans++,f=1;break;
		}
		if (!f) cnt[x]++;
	}
	printf("%d\n",ans);
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int k,a[5];

    FOR(i,0,5)
        cin >> a[i];
    cin >> k;

    if(a[4]-a[0]<=k)
        cout << "Yay!\n";
    else
        cout << ":(\n";

    return 0;
}


Measured memory_bytes: 256
def sup(A, j):
	if A[0] >= j:
		return 0
	l = 0
	r = len(A) - 1
	while True:
		i = (l+r) // 2
		if i == len(A) - 1 and A[i] < j:
			return len(A)
		elif A[i]<j and A[i+1]>=j:
			return i+1
		else:
			if A[i] >= j:
				r = i-1
			else: # A[i+1] < j
				l = i+1		

def inf(A, j): 
    if A[-1] <= j:
        return 0
    l = 0
    r = len(A) - 1
    while True:
        i = (l+r) // 2
        if i == 0 and A[i]>j:
            return len(A)
        elif A[i]>j and A[i-1]<=j:
            return len(A)-i
        else:
            if A[i] <= j:
                l = i+1
            else: # A[i-1] > j
                r = i-1		

N = int(input())
[A, B, C] = [sorted([int(i) for i in input().split()]) for j in range(3)]
ans = 0
for j in B:
	ans += sup(A, j) * inf(C, j)
print(ans)

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

typedef long long lli;

lli gcd(lli a, lli b) {
  return b == 0 ? a : gcd(b, a%b);
}

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

int main() {
  lli a, b;
  while(cin >> a >> b) {
    cout << gcd(a,b) << " " << lcm(a,b) << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] c = new int[n];
    long MOD = (long)Math.pow(10, 9) + 7;
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      c[a]++;
    }
    long ans = 0;
    int p = 0;
    for(int i = n - 1; i > 0; i -= 2) {
      if(c[i] != 2) p++;
    }
    if(((n % 2) == 1) && (c[0] != 1)) p++;
    if(p == 0) {
      ans = 1;
      for(int i = 0; i < (n / 2); i++) {
        ans = (ans * 2) % MOD;
      }
    }
    System.out.println(ans);
  }
}

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

int main()
{
    double n;
    cin >> n;
    int ni = n;
    if(ni % 2 == 0){
        cout << 0.5;
    }
    else{
        cout << (n + 1) / 2 / n;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--) 
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    string s, t;
    cin >> s >> t;
    rep(i, s.size()) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



   


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

   static int n;
	public static void main( String args[] ) throws IOException {
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         n =  Integer.parseInt( br.readLine() );

         int[][] V = new int[n+1][n+1];

         for(int i = 1; i <= n; i++){
        	 for(int j = 1; j <= n; j++){
        		 V[i][j] = 0;
             }

         }



         for(int i = 1; i <= n; i++){

        	 String[] order =  br.readLine().split(" ");


        	 if( Integer.parseInt( order[1] ) > 0){

        		 for(int j = 0; j < order.length-2; j++){
                        V[i][Integer.parseInt( order[2+j] )] = 1;
        		 }

             }

         }



         for(int i = 1; i <= n; i++){
        	 for(int j = 1; j <= n; j++){
        		 System.out.print( V[i][j]);

        	    if( j != n ){
        	    	System.out.print( " ");
        	    }

        	 }
        	 System.out.println();
         }


	}




}

Measured memory_bytes: 32896
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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


    if(a+b<=c || c+d<=a) p(0)
    else if (a<=c && d<=b) p(d-c)
    else if (c<=a && b<=d) p(b-a)
    else if (a<=c && c<=b && b<=d) p(b-c)
    else if (c<=a && a<=d && d<=b) p(d-a)
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)

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;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD



int main(int argv, char* argc[])
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    int cnt=0;
    string s,t;
    cin>>s>>t;
    int n = s.size();
    rep(i,n)
        if(s[i]!=t[i]) ++cnt;
    cout<<cnt<<"\n";

    return 0;
}


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

typedef struct node {
    int a, b;
    char op;
    struct node *next;
} node;

int main()
{
    node *head = NULL, *cur = NULL;
    while( 1 ){
        node *new = (node *)malloc(sizeof(node));
        if( new == NULL ) exit(-1);
        scanf("%d%*c%c%*c%d%*c", &new->a, &new->op, &new->b);
        new->next = NULL;

        if( new->op == '?' ) break;

        if( head == NULL ) head = new;
        else cur->next = new;
        cur = new;
    }

    cur = head;
    while( cur ){
        switch( cur->op ){
        case '+': printf("%d\n", cur->a + cur->b); break;
        case '-': printf("%d\n", cur->a - cur->b); break;
        case '*': printf("%d\n", cur->a * cur->b); break;
        case '/': printf("%d\n", cur->a / cur->b); break;
        default : printf("default operand\n");
        }
        cur = cur->next;
    }

    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define N 200005
#define inf 1000000007
using namespace std;

int n,a[N],loc[N],st[2][N*4];

struct minh {

  int segval;
  int bas,son;

};

bool operator < (minh x,minh y) {
    return x.segval>y.segval;
}

void build(int node,int bas,int son,int mod) {

  if(bas==son) {
    if(bas%2==mod) {
      st[mod][node]=a[bas];
    }
    else {
      st[mod][node]=inf;
    }
    return ;
  }
  int orta=(bas+son)/2;
  build(node*2,bas,orta,mod);
  build(node*2+1,orta+1,son,mod);
  st[mod][node]=min(st[mod][node*2],st[mod][node*2+1]);

}

int get(int node,int bas,int son,int x,int y,int mod) {

  if(bas>y || son<x) return inf;
  if(bas>=x && son<=y) return st[mod][node];
  int orta=(bas+son)/2;
  return min(get(node*2,bas,orta,x,y,mod),get(node*2+1,orta+1,son,x,y,mod));

}

void solve() {

  priority_queue<minh> q;
  q.push({get(1,1,n,1,n,1),1,n});
  while(!q.empty()) {
    minh top=q.top();
    q.pop();
    int ar[2]={0};
    int vals[2];
    if(top.bas%2) {
      ar[0]=1;
    }
    else {
      ar[1]=1;
    }
    int bas=top.bas;
    for(int i=0;i<2;i++) {
      vals[i]=get(1,1,n,bas,top.son,ar[i]);
      bas=loc[vals[i]]+1;
      printf("%d ",vals[i]);
    }
    int ara[3][2]={top.bas,loc[vals[0]]-1,loc[vals[0]]+1,loc[vals[1]]-1,loc[vals[1]]+1,top.son};
    for(int i=0;i<3;i++) {
      if(ara[i][0]>=1 && ara[i][1]<=n && ara[i][0]<=ara[i][1]) {
        q.push({get(1,1,n,ara[i][0],ara[i][1],ara[i][0]%2),ara[i][0],ara[i][1]});
      }
    }
  }

}



int main() {

  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
    scanf("%d",&a[i]);
    loc[a[i]]=i;
  }
  for(int i=0;i<2;i++) {
    build(1,1,n,i);
  }
  solve();

}



Measured memory_bytes: 9848
#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, x[101], y[101], xy[101], mh = 0, euc = 0, chb = 0, mks = 0;
  long double result1 = 0, result2 = 0, result3 = 0, result4 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
    xy[i] = fabs(x[i] - y[i]);
    mh += xy[i];
    euc += pow(xy[i], 2);
    chb = max(chb, xy[i]);
    mks += pow(xy[i], 3);
  }
  result1 = mh;
  result2 = sqrt(euc);
  result3 = pow(mks, 1.0 / 3.0);
  result4 = chb;
  cout << fixed << setprecision(8);
  cout << result1 << endl;
  cout << result2 << endl;
  cout << result3 << endl;
  cout << result4 << endl;

}


Measured memory_bytes: 3436
_, _, x, y = gets.chomp.split.map(&:to_i)
xc = gets.chomp.split.map(&:to_i)
yc = gets.chomp.split.map(&:to_i)
xc << x
xc.sort!
yc << y
yc.sort!
puts (yc[0] - xc[-1] > 0)? "No War" : "War"

Measured memory_bytes: 1788
#!/usr/bin/env python3


def solv(n, ss):
    a = 0
    b = 0
    ba = 0
    ans = 0
    for s in ss:
        ans += s.count('AB')
        if s[-1] == 'A':
            if s[0] == 'B':
                ba += 1
            else:
                a += 1
        elif s[0] == 'B':
            b += 1
    if ba > 0:
        ans += ba - 1
        if a > 0:
            ans += 1
            a -= 1
        if b > 0:
            ans += 1
            b -= 1
    ans += min(a, b)
    return ans


if __name__ == '__main__':

    n = int(input())

    ss = []
    for _ in range(n):
        ss.append(input())

    ans = solv(n, ss)

    print(ans)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vector<vector<int>>);

// グローバル変数

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	vector<int> A(N+1), B(N+2);
	for (int i=0; i<N+1; i++) cin >> A.at(i);
	for (int i=0; i<N; i++) cin >> B.at(i);
	
	vector<int> F1(N+1), F2(N+1);
	F1.at(0) = min(A.at(0), B.at(0));
	F2.at(0) = min(A.at(1), B.at(0)-F1.at(0)); 
	for (int i=1; i<N; i++) {
		F1.at(i) = min(A.at(i)-F2.at(i-1), B.at(i));
		F2.at(i) = min(A.at(i+1), B.at(i)-F1.at(i));
	}

	int ans = 0;
	for (int i=0; i<N; i++) {
		ans += F1.at(i)+F2.at(i);
	}

	cout << ans << endl;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll P[104];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> P[i];
    }
    int a = 0;
    FOR(i, N - 1, 1)
    {
        ll x = P[i - 1];
        ll y = P[i];
        ll z = P[i + 1];
        if ((y < z && y > x) || (y < x && y > z))
            a++;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;
int main(){
    vector<pair<long long int,int>> v;
    long long int n; cin >> n;
    for(long long int i=2;i<=1000000;i++){
        if(n%i == 0){
            int c = 0;
            while(n%i==0){ n = n/i; c++;}
            v.pb(mp(i, c));
        }
    }
    if(n!=1) v.pb(mp(n, 1));
    int ans = 0;
    for(auto x: v){
        int p = x.first;
     //   cout << p << endl;
        int e = x.second;
        int ts = 0;
        int tc = 0;
        for(int i=1; i+ts <= e; i++){
            ts += i;
            tc++;
        }
        ans += tc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
template<typename T>
inline void in(T &x)
{
	x=0;
	char c=getchar();
	bool fu=0;
	while(c<'0'||c>'9'){if(c=='-')fu=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x=fu?-x:x;
}
int n,has[N];
bool not_prime[N],pairwise=1,setwise=1;
void produce(int lim)
{
	not_prime[1]=1;
	for(int i=2;i<=lim;++i)
	{
		if(!not_prime[i])
		{
			int cnt=0;
			cnt+=has[i];
			for(int j=i+i;j<=lim;j+=i)
			{
				not_prime[j]=1;
				cnt+=has[j];
			}
			if(cnt>1)pairwise=0;
			if(cnt==n)setwise=0;
		}
	}
}
int main()
{
	in(n);
	for(int i=0;i<n;++i)
	{
		int t;
		in(t);
		++has[t];
	}
	produce(N-1);
	if(pairwise)puts("pairwise coprime");
	else if(setwise)puts("setwise coprime");
	else puts("not coprime");
	return 0;
}

Measured memory_bytes: 8444
use std::io;
use std::collections::BTreeSet;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.trim().split(" ");
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let mut v: Vec<(u32, u32)> = Vec::with_capacity(m);
    for _ in 0..m {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.trim().split(" ");
        let a: u32 = iter.next().unwrap().parse().unwrap();
        let b: u32 = iter.next().unwrap().parse().unwrap();
        v.push((a, b));
    }
    v.sort_by_key(|&x| x.1);
    let mut s: BTreeSet<u32> = BTreeSet::new();
    for (a, b) in v {
        if s.iter().any(|&x| { a <= x && x < b }) {
            continue;
        }
        s.insert(b - 1);
    }
    println!("{}", s.len());
}


Measured memory_bytes: 4352
import math
Q=int(input())
for _ in range(Q):
  A,B=map(int,input().split())
  if abs(A-B)<2:
    print(min(A,B)*2-2)
  else:
    s=int(math.ceil(math.sqrt(A*B)))-1
    if s**2+s<A*B:
      print(2*s-1)
    else:
      print(2*s-2)

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

void run() {
    int n, k;
    cin >> n >> k;
    set<int> q;
    int g = 0;
    rep(i, 0, n) {
        int x;
        cin >> x;
        q.insert(x);
        g = __gcd(g, x);
    }
    if (sz(q) == 1) {
        cout << (*q.begin() == k ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    } else {
        cout << (k <= *q.rbegin() && k % g == 0 ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    }
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    double l;
    cin>>l;
    double ans=(l/3)*(l/3)*(l/3);
    cout<<setprecision(8)<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef double db;
typedef long double ld;
using namespace std;
ll n,i,k,f[70];
int main()
{
	cin>>n;
	f[0]=1;
	for (i=1;i<=60;i++)
	f[i]=f[i-1]*2;
	for (i=60;i>=0;i--)
	{
		if (n>=f[i]) break;
	}
	cout<<f[i+1]-1<<endl;
}

Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if w == h == 0:
        break
    
    for i in range(h):
        print("#", end="")
        for j in range(w - 2):
            if i == 0 or i == h - 1:
                print("#", end="")
            else:
                print(".", end="")
        print("#")
    print()


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  double a,b,h,m;cin>>a>>b>>h>>m;

  h = h/12.0;
  h += m/720.0;
  m = m/60.0;

  double diff = m-h;
  double rad = min<double>( abs(M_PI*2*(diff)), 2*M_PI-abs(M_PI*2*(diff)) );

  double result = a*a+b*b-2*a*b*cos(rad);
  result = pow(result, 0.5);
  cout<<fixed<<setprecision(12)<<result<<endl;

//  cout<<h<<' '<<m<<endl<<rad<<endl<<M_PI*2*m<<endl<<M_PI*2*h<<endl;

  return 0;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) drop(-1);
  if (k == 7) drop(1);
  ll x = 7;
  rep2(i, 1, 10000000) {
    if (x % k == 0) drop(i);
    x = x*10 + 7;
    x %= k;
  }
  cout << -1 << endl;
  return 0;
}

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

const int mod = 1e9 + 7;

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> a(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}
	vector<int> dp(1 << N);
	dp[0] = 1;
	for (int i = 0; i < (1 << N) - 1; i++) {
		int c = __builtin_popcount(i);
		for (int j = 0; j < N; j++) if ((i & (1 << j)) == 0 && a[c][j]) {
			int to = i | (1 << j);
			dp[to] += dp[i];
			if (dp[to] >= mod) dp[to] -= mod;
		}
	}
	cout << dp.back() << endl;
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int l;
  cin>>l;
  int r=0,num=1;
  while(l>= num*2) num*=2,r++;
  vector<pair<pair<int,int>,int>> v;
  int n=r+1;
  rep(i,1,r+1){
    v.pb({{i,i+1},(1<<(i-1))});
    v.pb({{i,i+1},0});
  }
  int st=num,en=l-1;
  int idx=r,dicsrd;
  int left= en-st+1;
  for(idx=idx;idx>=1;idx--){
    if(left>=1<<(idx-1)) dicsrd= 1<<(idx-1);
    else continue;
    left-=dicsrd;
    v.pb({{idx,n},st});
    st+= dicsrd;
  }
  cout<<n<<" "<<v.size()<<endl;
  rep(i,0,v.size()) cout<<v[i].f.f<<" "<<v[i].f.s<<" "<<v[i].s<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3664
N = int(input())
A =  [list(map(int, input().split())) for _ in range(2)]

max_total = 0
for i in range(N):
    total = sum(A[0][:i+1]) + sum(A[1][i:])
    if max_total < total:
        max_total = total

print(max_total)

Measured memory_bytes: 9164
public class Main {
  private static void solve() {
    int n = ni();
    long[] a = nal(n);

    long ret = 0;
    while (true) {
      long s = 0;
      for (int i = 0; i < n; i ++) {
        s += a[i] / n;
      }
      if (s == 0) break;
      ret += s;

      for (int i = 0; i < n; i ++) {
        a[i] += -(a[i] / n) * n + (s - a[i] / n);
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, t; cin >> n >> t;
  V<> a(t + 1);
  for (int i = 0; i < n; ++i) {
    int l, r; cin >> l >> r;
    ++a[l], --a[r];
  }
  for (int i = 0; i < t; ++i) a[i + 1] += a[i];
  cout << *max_element(begin(a), end(a)) << '\n';
}


Measured memory_bytes: 3368
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x)
#define rmax(r, x) r = max(r, x)
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 998244353;
const int maxn = 2e5 + 10;
const int maxk = 15;

int n, k, l[maxk], r[maxk], s[maxk];
ll d[maxn];

int main(void) {
    fastio;
    cin >> n >> k;
    for(int i = 1; i <= k; ++i) cin >> l[i] >> r[i];

    d[1] = 1;
    for(int i = 2; i <= n; ++i) {
        for(int j = 1; j <= k; ++j) {
            if(i - r[j] - 1 >= 0)  s[j] -= d[i - r[j] - 1];
            if(i - l[j] >= 0)      s[j] += d[i - l[j]];
            s[j] = (s[j] + mod) % mod;
            (d[i] += s[j]) %= mod;
        }
    }
    cout << d[n];
    return 0;
}

Measured memory_bytes: 5204
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;



int main()
{
    long long n, k;
    cin >> n >> k;

    long long x;
    x = n / k;

    long long a = n - (k * x);

    long long a2 = abs(a - k);
    if (a2 < a) {
        cout << a2 << endl;
    }
    else {
        cout << a << endl;
    }
}



Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(){

    int n, k;
    cin >> n >> k;
    vector<int> sunuke(n, 0);

    int d = 0;
    int a = 0;
    for (int i = 0; i < k; ++i)
    {
        cin >> d;
        for (int j = 0; j < d;++j){
            cin >> a;
            ++sunuke[a - 1];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if(sunuke[i]==0){
            ++ans;
        }
    }

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


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

int main()
{
    int fenpei;
    int i;
    int j;
    int L=1;
    int jishu=0;
    scanf("%d",&fenpei);
    int shuru[fenpei];
    int lao[fenpei];
    for (j=0;j<fenpei;j++)
    {
        lao[j]=L;
        L++;
    }
    for(i=0;i<fenpei;i++)
    {
        scanf("%d",&shuru[i]);
    }
    for(i=0;i<fenpei;i++){
    if (lao[i]%2 !=0)
    {
        if (shuru[i]%2 !=0)
        {
            jishu++;
        }
    }
    }
    printf("%d",jishu);
    return 0;
}


Measured memory_bytes: 1728
x, n = map(int, input().split( ))
if n == 0:
  print(x)
  exit()
P = list(map(int, input().split( )))

if x not in P:
  print(x)
  exit()
i,c = 1, 0
while i <= n:
  m = x - i
  l = x + i
  if m not in P:
    print(m)
    break
  elif l not in P:
    print(l)
    break
  i += 1


Measured memory_bytes: 9124
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  int n,m,p[100000],p2[100000],pp,w,a,i;
  string s;
  cin>>n>>m;
  w=0;a=0;
  for(i=0;i<n;i++){p[i]=0;p2[i]=0;}
  
  for(i=0;i<m;i++)
  {
    cin>>pp>>s;
    if(p2[pp-1]==0&&s=="WA"){p[pp-1]++;}
    if(p2[pp-1]==0&&s=="AC"){a++;p2[pp-1]=1;}
  }
  for(i=0;i<n;i++)
  {
  if(p2[i]==1){w+=p[i];}
  }
  cout<<a<<" "<<w;
  return 0;
}

Measured memory_bytes: 4372
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(), (v).end(),i) ,(v).end())
#define me (*this)
#define INDEX(v,i) (find((v).begin(), (v).end(), i) - (v).begin())

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double PI = 3.14159265358979323;
const double EPS = 1e-10;

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

//function
int gcd(int x, int y) {
	if(y > x)
		swap(x, y);
	while(y != 0) {
		x %= y;
		swap(x, y);
	}
	return x;
}

int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//structure
struct POS {
	int x, y;
};

POS vec[4] = {
	{1, 0}, // right
	{0, -1}, // up
	{-1, 0}, // left
	{0, 1} // down
};

int main() {
	while(1) {
		string p, q;
		cin >> p >> q;
		if(p == "0" && q == "0")
			break;
		int hit = 0, blow = 0;
		rep(i, 4) {
			if(q[i] == p[i]) {
				hit++;
			} else if(EXIST(p, q[i])) {
				blow++;
			}
		}
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

Measured memory_bytes: 920
#include<stdio.h>
int a[1000001];

int Func(int n) {
	if (n == 0)return 0;
	else return a[n] + Func(n - 1);
}

int main() {
	a[0] = 0;
	a[1] = 0;
	a[2] = 1;
	for (int i = 3; i <= 1000000; i++) {
		if (i % 2 == 0)a[i] = 0;
		else {
			int h = 1;
			for (int j = 3; j*j <= i && h == 1; j += 2) {
				if (i%j == 0)h = 0;
			}
			a[i] = h;
		}
	}
	int n;
	while (~scanf("%d", &n)) {
		printf("%d\n", Func(n));
	}
}




Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ts  ll t;cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr ll n,i;cin>>n; ll a[n+1];for(i=0;i<n;i++)
#define ln cout<<"\n"; 
#define maxn 1000000


int main() {
	fast
	string s;
	cin>>s;
	ll k=s.size();
	if(s[k-1]=='s')cout<<s<<"es";
	else cout<<s<<"s";
	
	    

	return 0;}

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

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

    int t;
    t=1;

    while(t--){
        int n;
        cin>>n;

        vector<ll> height(n);
        for(int i=0;i<n;i++)
            cin>>height[i];


        ll ans=0;
        ll currentHeight=0;

        for(int i=0;i<n-1;i++){
            if(currentHeight+height[i]>height[i+1]){
                ll dif = (currentHeight+height[i])-height[i+1];
                ans+=dif;
                currentHeight=dif;
            }
            else
                currentHeight=0;
        }
        cout<<ans<<endl;
    }
    return 0;
}





Measured memory_bytes: 4736
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=1000-n
        i=a%10
        if i>=5:
            i=1+i-5
        else:
            pass
        j=a//10
        j2=j%10
        if j2>=5:
            j2=1+j2-5
        else:
            pass
        h=a//100
        if h>=5:
            h=1+h-5
        else:
            pass
    print(i+j2+h)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 500030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	int ans=0;
	rep(i,0,s.size())
	{
		if(i%2==0)
		{
			if(s[i]=='p')
			ans--;
		}
		else
		{
			if(s[i]=='g')
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 512