akhauriyash/Code-Regression huggingface dataset:
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/20/20 21:00:19
// -----------------------------------

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;

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

  ll n; cin>>n;
  ll ans = 1e15;
  auto check = [&](ll x) {
    ll y = 2*n/x;
    auto [a,b] = atcoder::crt({0, y-1}, {x, y});
    if (b == 0) return;
    ans = min(ans, a);
  };
  check(1);
//  check(2*n);
  for (int x = 2, sqrt2n = sqrt(2*n); x <= sqrt2n; ++x) {
    if ((2*n) % x == 0) {
      check(x);
      check(2*n/x);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3668
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC151_a solver = new ABC151_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC151_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char C[] = in.next().toCharArray();
            C[0] += 1;
            String ans = new String(C);
            out.println(ans);
        }

    }
}



Measured memory_bytes: 21204
using System;
public class Hello{
    public static void Main(){
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);
        int D = int.Parse(input[3]);
        
        int bot = Math.Max(A,C);
        int top = Math.Min(B,D);
        
        if(top > bot){
            Console.WriteLine(top - bot);
        }else{
            Console.WriteLine(0);
        }
    }
}


Measured memory_bytes: 11092
#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>
#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--)
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;
int dp[110000];
int main() {
    int N; cin >> N;
    int h[110000];
    rep(i, N) {
        cin >> h[i];
    }
    
    rep(i, N) {
        dp[i] =INF;
    }
    dp[0] = 0;
    rep(i, N) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[N - 1] << endl;
}



   

    
    



    
                

 













































































































































Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t; int q, a, b, c, d;  cin >> s >> t >> q;
    V<> cums(SZ(s) + 1, 0), cumt(SZ(t) + 1, 0);
    REP(i, SZ(s)) cums[i+1] = cums[i] + (s[i] == 'A' ? 1 : 2);
    REP(i, SZ(t)) cumt[i+1] = cumt[i] + (t[i] == 'A' ? 1 : 2);
    while(cin >> a >> b >> c >> d) YES(!((cums[b] - cums[a - 1] - cumt[d] + cumt[c - 1]) % 3));
}

Measured memory_bytes: 5052
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

template<typename T = long long>
struct LCA {
	int n, l, root;
	vector<vector<pair<int, T>>> graph;
	vector<int> dep;
	vector<T> dist;
	vector<vector<int>> par;
	LCA(int n) : n(n) {
		l = 0;
		while ((1 << l) < n) l++;
		graph.assign(n, {});
		dist.assign(n, 0);
		dep.assign(n, 0);
		par.assign(n, vector<int>(l, -1));
	}
	void add_edge(int u, int v, T c = 0) {
		graph[u].emplace_back(v, c);
		graph[v].emplace_back(u, c);
	}
	void init(int _root = 0) {
		root = _root;
		dfs(root, -1, 0, 0);
		for (int i=1; i<l; i++) {
			for (int u=0; u<n; u++) {
				if (par[u][i-1] < 0) continue;
				par[u][i] = par[par[u][i-1]][i-1];
			}
		}
	}
	void dfs(int u, int p, T c, int d) {
		dist[u] = c;
		par[u][0] = p;
		dep[u] = d;
		for (auto e : graph[u]) {
			int v = e.first;
			T cv = e.second;
			if (v==p) continue;
			dfs(v, u, c+cv, d+1);
		}
	}
	int operator() (int u, int v) const {
		if (dep[u]<dep[v]) swap(u, v);
		int gap = dep[u]-dep[v];
		for (int i=0; i<l; i++) {
			if (gap & (1 << i)) u = par[u][i];
		}
		if (u==v) return u;
		for (int i=l-1; i>=0; i--) {
			if (par[u][i]!=par[v][i]) {
				u = par[u][i];
				v = par[v][i];
			}
		}
		return par[u][0];
	}
	T distance(int u, int v) const {
		int c = (*this)(u, v);
		if(c < 0) return -1; // when graph is not connected
		return dist[u]+dist[v]-2*dist[c];
	}
};

int main(){
	int N; cin >> N;
	vector<vector<int>> graph(N);
	LCA<int> lca(N);
	for(int i=0; i<N-1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
		lca.add_edge(a, b, 1);
	}

	lca.init();
	int M; cin >> M;
	vector<pair<int, int>> path(M);
	for(int i=0; i<M; i++){
		cin >> path[i].first >> path[i].second;
		path[i].first--; path[i].second--;
	}
	vector<vector<bool>> used(M, vector<bool>(N));
	for(int i=0; i<M; i++){
		int anc = lca(path[i].first, path[i].second);
		int u = path[i].first;
		while(u != anc){
			used[i][u] = true;
			u = lca.par[u][0];
		}
		u = path[i].second;
		while(u != anc) {
			used[i][u] = true;
			u = lca.par[u][0];
		}
	}

	ll ans = 0;
	for(int s=0; s<1<<M; s++){
		vector<bool> used_or(N);
		int ns = 0;
		for(int i=0; i<M; i++){
			if(((s>>i)&1)==0) continue;
			for(int j=0; j<N; j++){
				used_or[j] = used_or[j] || used[i][j];
			}
			ns++;
		}
		int ne = 0;
		for(int j=0; j<N; j++) if(used_or[j]) ne++;
		debug(s, ns, ne, 1<<(N-1-ne));
		ans += (1-2*(ns%2))*(1ll<<(N-1-ne));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// 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();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;

  bool flag = true;
  rep(i, s.size()) {
    if ((i + 1) % 2 == 0) {
      if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) flag = false;
    } else {
      if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) flag = false;
    }
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;



int main(int argc, char *argv[]) {
    int n;
    cin >> n;
    vector<long long int> v;
    for (int i = 0; i < n; i++) {
    	long long int t;
    	cin >> t;
    	v.push_back(t);
    }
    long long int total = accumulate(v.begin(), v.end(), (long long int)0);
    long long int res = -1;
    long long int t = 0;
    for (int i = 0; i < n; i++) {
    	t += v[i];
    	long long int r = abs(total - t - t);
    	if (res == -1 || r < res)
    		res = r;
    }
    cout << res << endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
using namespace std;
int solve(int n){
    int res=0;
    while(n%2==0){
        n/=2;
        res++;
    }
    return res;
}
int main(void){
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        ans+=solve(num);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(int i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7 

using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
const ll mod = 1e9+7;

ll dp[100001][13];
int main(){
    string s;
    cin>>s;
    int n=s.size();
    rep(i,13)rep(j,100001){
        dp[i][j]=0;
    }
   
    dp[0][0]=1;
    rep(i,n){
        if(s[i]=='?'){
            rep(j,13){
                rep(k,10){
                    dp[i+1][(j*10+k)%13]+=dp[i][j];
                    dp[i+1][(j*10+k)%13]%=mod;
                }
            }
        }
        else{
            rep(j,13){
                int k=s[i]-'0';
                dp[i+1][(j*10+k)%13]+=dp[i][j];
                dp[i+1][(j*10+k)%13]%=mod;
            }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
}

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

void insertionSort(int A[], int N){
    int v, j;
    for(int i=1; i <= N-1; i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int i=0; i < N-1; i++){
            cout << A[i] << " ";
        }
        cout << A[N-1] << endl;
    }
    
}


int main(){
    int N;
    cin >> N;
    int A[100];
    for(int i=0; i< N; i++){
        cin >> A[i];
    }
    for(int i=0; i < N-1; i++){
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;
    insertionSort(A, N);
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
long long a[1010];
long long b[1010];
long long dp[10010];
int main(){
	long long h,n;
	cin>>h>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	for(int i=0;i<=10000;i++)dp[i]=1000000000;
	dp[h]=0;
	for(int i=h;i>=1;i--){
		for(int j=0;j<n;j++){
//			cout<<i<<" "<<j<<endl;
			dp[max(0LL,i-a[j])]=min(dp[max(0LL,i-a[j])],dp[i]+b[j]);
		}
	}
	cout<<dp[0]<<endl;
	return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
 
typedef long long ll;
typedef std::pair<int,int> pii;
 
using namespace std;
 
ll memo[100005];
vector<ll> g[100005];

ll dfs(ll v){
    if(memo[v] != -1)return memo[v];

    ll rec = 0;
    REP(i,g[v].size()){
        rec = max(rec,dfs(g[v][i])+1);
    }

    return memo[v] = rec;
}

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

    ll n,m;
    cin >> n >> m;
    REP(i,m){
        ll x,y;
        cin >> x >> y;
        x--,y--;
        g[x].push_back(y);
    }

    REP(i,n){
        memo[i] = -1;
    }

    ll ans = 0;
    REP(i,n){
        ans = max(ans,dfs(i));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8576
using System;
using System.Linq;
namespace AtCoder
{
    class Abc142E
    {
        public static void Main()
        {
            var nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var n = nm[0];
            var m = nm[1];

            var a = new int[m];
            var c = new int[m][];
            var b = new int[m];
            for (int i = 0; i < m; i++)
            {
                a[i] = int.Parse(Console.ReadLine().Split(' ').First());
                c[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                foreach (var j in c[i])
                    b[i] |= 1 << (j - 1);
            }

            var dp = Enumerable.Repeat(int.MaxValue, 1 << n).ToArray();
            dp[0] = 0;
            for (int i = 0; i < 1 << n; i++)
            {
                if (dp[i] == int.MaxValue)
                    continue;

                for (int j = 0; j < m; j++)
                {
                    var l = i | b[j];
                    if (l == i)
                        continue;
                    dp[l] = Math.Min(dp[l], dp[i] + a[j]);
                }
            }
            Console.WriteLine(dp.Last() == int.MaxValue? -1 : dp.Last());
        }
    }
}


Measured memory_bytes: 13524
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUFSIZ 8

int main (int ac, char **av) {
  char readline[BUFSIZ] = {0};
  int mountains[3] = {0};
  while (fgets(readline, BUFSIZ, stdin) != NULL) {
    int x = atoi(readline);
    if (mountains[0] == 0) {
      mountains[0] = x;
    } else {
      int idx = 0;
      for (idx = 0; idx < 3; idx++) {
	if (mountains[idx] < x) {
	  memmove(mountains+idx+1, mountains+idx, sizeof(int) * (2-idx));
	  mountains[idx] = x;
	  break;
	}
      }
    }
  }
  int i=0;
  for (i = 0; i < 3; i++) {
    fprintf(stdout, "%d\n", mountains[i]);
  }
      

  return 0;
}

Measured memory_bytes: 972
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int l = sc.nextInt();
    int r = sc.nextInt();
    int d = sc.nextInt();
    int ans=0;
    for(int i=l;i<=r;i++){
      if(i%d==0){
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35572
n,a,b = map(int,input().split())
all_sum = 0

for i in range(n+1):
    sum = 0
    n_list = list(str(i))
    for j in range(len(n_list)):
        sum += int(n_list[j])
    
    if (sum >= a) and (sum <= b):
        all_sum += i
    else:
        pass

print(all_sum)

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

using namespace std;

int main(){
    int N;
    int A[111111];
    int i;
    cin >> N;
    for(i=0;i<=N-1;i++)
        cin >> A[i];
    int lgcd[i],rgcd[i],gcd[i];
    lgcd[0] = A[0];
    rgcd[N-1] = A[N-1];
    int max = 1;
    
    for(i=1;i<=N-1;i++)
        lgcd[i] = __gcd(lgcd[i-1],A[i]);
    for(i=N-2;i>=0;i--)
       rgcd[i] = __gcd(rgcd[i+1],A[i]);
        
    gcd[0] = rgcd[1];
    gcd[N-1] = lgcd[N-2];
    
    for(i=1;i<=N-2;i++)
        gcd[i] = __gcd(lgcd[i-1],rgcd[i+1]);
    for(i=0;i<=N-1;i++)
        if(gcd[i] > max) max = gcd[i];
    cout << max << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int h;
	int m;
	int s;
	scanf("%d", &s);
	h = s/3600;
	m = s/60-h*60;
	s = s-h*3600-m*60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}


Measured memory_bytes: 2104
//********** ANKIT KESARWANI **********//
#include <bits/stdc++.h>/
using namespace std;
#define   FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define   vi vector<int>
#define   pii pair<int,int>
#define   all(a) (a).begin(), (a).end()
#define   rep(i,a,b)  for(int  i=a;i<b;i++)
#define   tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define   pb push_back
#define   endl  "\n"
#define   dbg(x,y) cout<<(x)<<" -->  "<<(y)<<endl
#define   F first
#define   S second
#define   int  long long
const int  N=1e5+20;
const int  inf=1e13;
const int  ninf=-1e9 ;
const int  mod=1e9+7;
/*------------------------------------------------------------------------------------------------------------------------*/

vector<int>g[N];
int dp[N][5];
int n;

int dfs(int src,int par,int color)
{

    int res=1;

    if(dp[src][color]!=-1)
    {
        return dp[src][color];
    }
    for(auto nbr:g[src])
    {
        if(nbr==par)
            continue;
        if(color==0)
        {
            res=(res %mod * (dfs(nbr,src,0)+dfs(nbr,src,1))%mod)%mod;
        }
        else
        {
            res=((res%mod)*(dfs(nbr,src,0)%mod))%mod;
        }
    }
   // cout<<res<<endl;
    return dp[src][color]=res;

}

void solve()
{
    cin>>n;

    int x,y;
    rep(i,0,n-1)
    cin>>x>>y,g[x].pb(y),g[y].pb(x);

    // 0->white,1->black

    memset(dp,-1,sizeof(dp));
    int ans=(dfs(1,0,0)+dfs(1,0,1))%mod;

    cout<<ans;


}
signed main()
{
   FASTIO;
  int T=1;
 // cin>>T;
   while (T--)
    solve();
   return 0;
}


Measured memory_bytes: 17920
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

INF = float('inf')
MOD = 1000000000 + 7

def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]

def check(n):
    l = len(str(n))
    for ele in list(str(n)):
        if ele != "9":
            return False

    return True

def Sum(n):
    L = list(str(n))
    sum = 0
    for ele in L:
        sum += int(ele)

    return sum

def solve():
    while 1:
        try:
            n = int(input())
            if 1 <= n <= 9:
                print(n)
                raise EndLoop

            l = len(str(n))

            tmp = str(n)[0]

            if check(n):
                print(9 * l)
            else:
                print(max(Sum(n), 9 * (l - 1) + int(tmp) - 1))
            break
        except:
            break

solve()

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad

compute :: Int -> Int
compute n = n^3

solver :: Int -> Int -> Int
solver n k
    | odd k     = compute $ length [x | x <- [1..n], x `mod` k == 0]
    | otherwise = h + j
        where m  = k `div` 2
              xs = [x | x <- [1..n], x `mod` k == m]
              ys = [y | y <- [1..n], y `mod` k == 0]
              h  = compute $ length xs
              j  = compute $ length ys

main :: IO ()
main = do
    [n, k] <- (map read) . words <$> getLine
    print $ solver n k


Measured memory_bytes: 508
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
A = list(map(int, input().split()))

A_ = [i for i in A if i % 2 == 0 ]
B_ = [i for i in A_ if i % 3 == 0 or i % 5 == 0]


if len(A_) == len(B_):
	print("APPROVED")
else:
	print("DENIED")
	


Measured memory_bytes: 38384
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<functional>
#include<vector>
#include<math.h>
using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int data[M][2];
  for(int i=0;i<M;i++){
    cin>>data[i][0]>>data[i][1];
  }
  //N個の都市を並べ替えて、それが通れるかチェック
  int  order[N];
  for(int i=1;i<=N;i++) order[i-1]=i;
  int ans=0;
  do{ //チェック
    for(int i=0;i<N-1;i++){
      bool judge=false;
      for(int j=0;j<M;j++){
     	 if((order[i]==data[j][0]&&order[i+1]==data[j][1])||(order[i]==data[j][1]&&order[i+1]==data[j][0])){
          judge=true;
          break;
         }
      }
      if(!judge)  break;
      if(i==N-2) ans++;
    }
  }while(next_permutation(order+1, order+N));
    
  cout<<ans<<endl;

}

Measured memory_bytes: 3596
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 998244353;

int main()
{
	int N, M;
	cin >> N >> M;

	vec H(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> H[i];
	}

	vec Good(N, 1);

	for (int i = 0; i < M; ++i)
	{
		int A, B;
		cin >> A >> B;
		--A; --B;

		if (H[A] == H[B])
		{
			Good[A] = Good[B] = 0;
		}
		else if (H[A] < H[B])
		{
			Good[A] = 0;
		}
		else
		{
			Good[B] = 0;
		}
	}

	int cnt = 0;
	for (int i = 0; i < N; ++i)
	{
		cnt += (Good[i] == 1);
	}

	cout << cnt << endl;

	return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n; cin >> n;
    lol m; cin >> m;
    lol x; cin >> x;

    int a[13][13];
    REP(i, n)
    {
        cin >> a[i][0];
        FOR(j, 1, m)
        {
            cin >> a[i][j];
        }
    }

    result = INF;

    for (int tmp = 0; tmp < (1 << 12); tmp++)
    {
        bool fl = true;
        bitset<12> s(tmp);  // 最大20個なので20ビットのビット列として扱う
        vector<lol> b(13);
        // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
        for (int i = 0; i < n; i++) {
            if (s.test(i))
            {
                FOR(j, 0, m)
                {
                    b[j] += a[i][j];
                }
            }
        }
        //cout << "b[0] = " << b[0] << endl;
        FOR(i, 1, m)
        {
            if(b[i] < x)
            {
                fl = false;
                break;
            }
        }
        if(fl)
        {
            if(b[0] < result)
                result = b[0];
        }
        b.clear();
    }
    if(result == INF)
    {
        cout << -1 << endl;
        return 0;
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  string s,t;
  cin >> s >> t;
  int n=s.size();
  int m=t.size();
  if(n<m){ cout << "UNRESTORABLE" << endl; return 0;}
  for(int i=n-m; i>=0; i--){
    bool flag=true;
    for(int j=0; j<m; j++){
      if(s[i+j]==t[j] || s[i+j]=='?'){}else{flag=false; break;}
    }
    if(flag){
      rep(j,i){ cout << (s[j]!='?'?s[j]:'a'); }
      cout << t;
      for(int j=i+m; j<n; j++){ cout << (s[j]!='?'?s[j]:'a'); }
      cout << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b)swap(a,b);
	if(b<c)swap(b,c);
	if(a<b)swap(a,b);
	if(a*a==b*b+c*c)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }
int main(){
  int R;
  cin >> R;
  cout << 2 * 3.14159265 * R << endl;
}

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

int main(){
   string s;
   cin >> s;
   bool flag = true;
   int count = 0;
   if(s[0]!='A') flag = false;
   for(int i=2;i<s.size()-1;i++){
      if(s[i]=='C') count++;
   }
   if(count!=1) flag = false;
   for(int i=1;i<s.size();i++){
      if(s[i]=='C') continue;
      else{
         if('a'<=s[i]&&s[i]<='z') continue;
         else{
            flag = false;
            break;
         }
      }
   }
   if(flag) cout << "AC" << endl;
   else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <map>
 
using namespace std;

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

    int N;
    cin >> N;

    int most;
    int count = 1;
    vector<int> H(N);

    for(int i = 0; i < N; i++)
    {
        cin >> H[i];
    }

    most = H[0];

    for(int i = 1; i < N; i++)
    {
        if(H[i] >= most)
        {
            most = H[i];
            count++;
        }
    }

    cout << count;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  int c[10][10];
  REP(i,10)REP(j,10)cin >> c[i][j];

  REP(k,10)REP(i,10)REP(j,10){
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  }

  int ans=0;
  REP(i,H)REP(j,W){
    int a;
    cin >> a;
    if(a==-1)continue;
    ans+=c[a][1];
  }
  cout << ans << endl;
}



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


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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int ans=a[0];
    rep(i,n){
        ans=gcd(ans,a[i]);
    }
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 3696
#include <unordered_map>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using LL = long long;

#define MOD 1000000007

class RollingHash {
private:
	using LL = long long;
	static LL mod(LL x) {
		const LL ret = x % MOD;
		return (ret >= 0) ? ret : (ret + MOD);
	}
	LL h = 0, w = 0;
public:
	template <class I>
	RollingHash(I first, I last) {
		for (auto it = first; it != last; ++it)
			h = mod(h * 256 + *it), w = w ? mod(w * 256) : 1;
	}
	void roll(char L, char R) { h = mod((h - w * L) * 256 + R); }
	operator int() const { return h; }
};

class Solution {
private:
	template <class T, class F>
	static T lowestTrue(T low, T high, F cond) {
		while (low < high) {
			const T mid = low + (high - low) / 2;
			if (cond(mid))
				high = mid;
			else
				low = mid + 1;
		}
		return low;
	}
public:
	/* time: O(n*log(n)), space: O(n) */
	int whoSaysAPun(const string& S) {
		const int n = S.size();
		auto cond = [&](int len) {
			unordered_map<int, int> h;
			/*
			 * Use Rabin-Karp algorithm to achieve O(n) expected time
			 * See LeetCode 28 - Implement strStr()
			 */
			RollingHash curr(S.begin(), S.begin() + len);
			for (int L = 0, R = len - 1; R < n; ++L, ++R) {
				const auto it = h.find(curr);
				if (it != h.end() && L - it->second >= len && !S.compare(it->second, len, S, L, len))
					return false; /* found */
				if (it == h.end())
					h[curr] = L;
				if (R != n - 1)
					curr.roll(S[L], S[R + 1]);
			}
			return true; /* not found */
		};
		return lowestTrue(1, n, cond) - 1;
	}
};

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

	string S;
	cin >> S;

	Solution sol;
	int ans = sol.whoSaysAPun(S);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 544
//https://atcoder.jp/contests/abc143/tasks/abc143_a

#include<iostream>
using namespace std;

int main (){
    int A, B;
    cin >> A >> B;

    if(A > B*2){
        cout << A - B*2 << endl;
        return 0;
    
    }else{
        cout << 0 << endl;
        return 0;
    }

}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
sunuke = []
diff = []
total = sum(a)
for i, x in enumerate(a[0:-1]):
    if(i==0):
        sunuke.append(x)
    else:
        sunuke.append(x + sunuke[i-1])
for i in sunuke:
    diff.append(abs((i * 2) - total))
print(min(diff))


Measured memory_bytes: 29440
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	ios::sync_with_stdio(false);
	string str; cin >> str;
	int n = str.size(), add = 0, one = 0;
	string cur = "";
	rep(i, n){
		if( (cur.size() && cur.back() == '1') && str[i] == '1' ){
			cur.pop_back(); add+=2;
		}
		else cur.pb(str[i]);
	}
	ll ans = 0;
	rep(i, cur.size()){
		if(cur[i] == '1'){
			int num = i+1;
			//num -> one+1
			ans -= ( num/2 - (one+2)/2 + 1);
			one++;
		}
	}
  	ans += 1LL * one * (n-add-one+1);
	ans += 1LL*add/2*(n-add-one+1);
	for(int i=1;i<add+one;i++) ans += (i+1)/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n,k;
    cin >> n >> k;
    int i1;
    int A,B;
    REP(i, n){
        int a;cin >> a;
        if(a == 1){
            A = i;
            B = n-i-1;
        }
    }
    if(n==k) {
        pr(1);
        return 0;
    }
    int A_ = A / (k-1) + (A%(k-1)?1:0);
    int B_ = B / (k-1) + (B%(k-1)?1:0);
    if(((A%k)+(B%k)+1) <= k && k>2 && A!=0 && B!=0) A_-=1;
    pr(A_+B_);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
const int INF=2e5+5;
int n,m,a[INF],b[INF],k,ans,o;
long long sum;
int main(){
        cin>>n>>m>>k;
        for (int i=1; i<=n; i++) {
                cin>>a[i];
                sum+=a[i];
        }
        o=n;
        for (int i=1; i<=m; i++)
                cin>>b[i];
        for (int j=0; j<=m; j++) {
                while (sum+b[j]>k && o>=1) {sum-=a[o]; o--;}
                sum+=b[j];
                if (sum>k) break;
                ans=max(ans,j+o);
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 5064
from collections import Counter
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print('0')
    exit()
counter = Counter(D)
if counter[0] != 1:
    print('0')
    exit()
counter = sorted(counter.items())
# print(counter)
keys = []
values = []
for i in range(len(counter)):
    keys.append(counter[i][0])
    values.append(counter[i][1])
for i in range(len(keys)):
    if i != keys[i]:
        print('0')
        exit()
ans = 1
for i in range(1, len(counter) - 1):
    ans *= pow(values[i], values[i + 1], mod)
    ans %= mod
print(ans)

Measured memory_bytes: 25784
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    ll N, A, B; cin >> N >> A >> B;
    ll up = B * (N - 1) + A;
    ll bottom = A * (N - 1) + B;
    ll possible_count = max((ll)0, up - bottom + 1);
    cout << possible_count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

const int mod = 1000000007;

const int N = 555555;
long long fact[N];
long long invfact[N];
long long inv[N];

struct Fenwick{
	int n;
	vector<int> a;

	Fenwick(int nn): n(nn) {
		a.resize(n);
	}

	void add(int pos, int x) {
		while (pos < n) {
			a[pos] += x;
			pos = pos | (pos + 1);
		}
	}

	int get(int pos) {
		int res = 0;
		while (pos >= 0) {
			res += a[pos];
			pos = (pos & (pos + 1)) - 1;
		}
		return res;
	}
};

inline long long C(int n, int k) {
	return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

long long waycount(int num_places, int num_left, int num_cand, int first) {
	long long res = 0;
	for (int i = 0; i <= num_cand && i <= num_left; i++) {
		res += 1ll * (first - i) * C(num_left, i) % mod * C(num_places - num_left, num_cand - i) % mod *
			   fact[num_left] % mod * fact[num_places - num_left] % mod;
	}
	return res % mod;
}

int main(){

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

	inv[1] = 1;
	for (int i = 2; i < N; i++) {
		inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;
	}
	for (int i = 1; i < 100; i++) {
		assert(1ll * i * inv[i] % mod == 1);
	}
	fact[0] = 1;
	invfact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = fact[i - 1] * i % mod;
		invfact[i] = invfact[i - 1] * inv[i] % mod;
	}

	long long ans = 0;
	Fenwick fenv(n + 1);
	Fenwick free_f(n + 1);
	for (int i = 0; i < n; i++) {
		free_f.add(i + 1, 1);
	}
	long long total_sum = 0;
	for (int i = 0; i < n; i++) {
		if (a[i]) {
			free_f.add(a[i], -1);
			total_sum -= a[i];
		}
		total_sum += i + 1;
	}
	int total_free = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			total_free += 1;
		}
	}
	int free_places = 0;
	long long xuita = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			long long tmp = (total_sum % mod * fact[total_free - 1] % mod - fact[total_free] % mod -
					  xuita % mod * fact[total_free - 1] - fact[total_free] % mod * free_places % mod * inv[2] % mod) % mod + mod;
			tmp %= mod;
			ans += tmp * fact[n - i - 1] % mod;
			free_places += 1;
		} else {
			xuita += total_free - free_f.get(a[i]);
			long long tmp = (a[i] - 1 - fenv.get(a[i])) * fact[total_free] % mod - 1ll * free_f.get(a[i]) * free_places % mod * fact[total_free - 1] % mod;
			tmp %= mod;
			tmp += mod;
			ans += tmp * fact[n - 1 - i] % mod;
			fenv.add(a[i], 1);
		}
	}

	cout << (ans + fact[total_free]) % mod << "\n";

	return 0;
}

Measured memory_bytes: 19072
S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]

if len(S)<26:
    alp="".join([chr(i) for i in range(97,97+26)])
    s = "".join([chr(i+97) for i in S])
    for i in alp:
        if i not in s:
            print(s+i)
            exit()
    """
    for s in S:
    appeared[s] = True
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    print("".join([chr(i+97) for i in S]))
    exit()
    """
    
else:
    s = "".join([chr(i+97) for i in S])
    if s=="".join([chr(i) for i in range(97,97+26)][::-1]):
        print(-1)
        exit()
    
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    for i in range(24,-1,-1):
        for j in range(25,i,-1):
            if S[i]<S[j]:
                S = S[:i]+[S[j]]
                print("".join([chr(i+97) for i in S]))
                exit()
    """
    string = S[i+1:]
    for j in range(len(string)):
        if string[j] < S[i]:
            string[j] = 100
    S = S[:i]+[min(string)]
    """


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <climits>
#define mk make_pair
#define pb push_back
#define scanf scanf_s
#define printf printf_s
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pos;
const ll N = 200010, MOD = 998244353;
ll dp[N],n,x[N],fi[N];
pos xd[N];


ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}

const int SIZE = (1 << 18);
struct SegTree {
	int nn, dat[2 * SIZE - 1], PLACE;
	void init(int n_) {
		nn = 1;
		while (nn < n_)nn *= 2;
		PLACE = INT_MAX;
		for (int i = 0; i < 2 * nn - 1; i++)dat[i] = PLACE;
	}
	void update(int k, int a) {//k is 0-indexed
		k += nn - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	int query(int a, int b) {//[a,b)
		return query(a, b, 0, 0, nn);
	}
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return PLACE;
		if (a <= l && r <= b)return dat[k];
		int v1 = query(a, b, k * 2 + 1, l, (l + r) / 2), v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(v1, v2);
	}

};
SegTree sg;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> xd[i].first >> xd[i].second;
	sort(xd + 1, xd + n + 1);
	sg.init(n);
	for (int i = 1; i <= n; i++)x[i] = xd[i].first;
	for (int i = n; i >= 1; i--) {
		int bd = xd[i].first + xd[i].second, bdi = lower_bound(x + 1, x + n + 1, bd) - x;
		int v1 = -sg.query(i + 1, bdi);
		fi[i] = max(bdi - 1, v1);
		sg.update(i, -fi[i]);
	}
	ll ans = 0;
	dp[1] = 1;
	for (int i = 1; i <= n; i++) {
		dp[fi[i] + 1] = (dp[fi[i] + 1] + dp[i]) % MOD;
		dp[i + 1] = (dp[i] + dp[i + 1]) % MOD;
	}
	cout << dp[n + 1] << endl;
	return 0;
}


Measured memory_bytes: 10112
#include <iostream>

int main() {
	int a[20];
	int b[20];

	int N = 0, M = 0, C = 0,T=0,A=0;

	std::cin >> N >> M >> C;

	for (int j = 0; j < M; j++)
		std::cin >> b[j];

	for (int i = 0; i < N; i++) {
		T = 0;
		for (int j = 0; j < M; j++) {
			std::cin >> a[j];
			T += a[j] * b[j];
		}
		if ((T + C) > 0)
			A++;
	}
	std::cout << A << std::endl;
	return 0;
}

Measured memory_bytes: 256
//id:miiifa (AOJ,PEどちらも)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int m=0;
    int i=1;
    while(1){
        m+=(i%7==0)?a+b:a;
        // cout << m << endl;
        if(m>=c){
            cout << i << endl;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N];

		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextLong();
		}

		long ans = A[0];
		for (int i = 0; i < N; i++) {
			ans = gcd(ans, A[i]);
		}

		System.out.println(ans);
	}

	private static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	}

}

Measured memory_bytes: 63024
num_list = list(map(int, input().split()))


if num_list[0] == 0:
  print(1)
elif num_list[1] == 0:
  print(2)
elif num_list[2] == 0:
  print(3)
elif num_list[3] == 0:
  print(4)
elif num_list[4] == 0:
  print(5)

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

int main() {
    int H,W,K; cin >> H >> W >> K;
    vector<vector<char>> c(H,vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> c.at(i).at(j);
        }
    }
    int ans=0;
    for(int bit1=0; bit1<(1<<H); bit1++){
        for(int bit2=0; bit2<(1<<W); bit2++){
            int cnt=0;
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    if((bit1 & (1<<i)) && (bit2 & (1<<j))){
                        if(c.at(i).at(j)=='#') cnt++;
                    }
                }
            }
            if(cnt==K) ans++;
            
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s;
int sum = 0;

int changei(string s){
	int res;
	stringstream ss;
	ss << s;
	ss >> res;
	return res;
}

int main(){
	while (cin >> s){
		string t;
		int co = 0, st = -1;
		REP(i, s.size()){
			if (st < 0 && s[i] >= '0'&&s[i] <= '9'){
				st = i;
				co++;
			}
			else if (st >= 0){
				if (s[i] >= '0'&&s[i] <= '9'){
					co++;
				}
				else {
					t = s.substr(st, co);
					sum += changei(t);
					st = -1;
				}
			}
			if (i == s.size() - 1&&st>=0){
				t = s.substr(st, co);
				sum += changei(t);
				st = -1;
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 1228
n = input()
x = list(map(int,raw_input().split()))
y = list(map(int,raw_input().split()))
gap = []
gap1 = 0.0
gap2 = 0.0
gap3 = 0.0
a = 0.0

for i in range(n):
    gap.append(abs(x[i]-y[i]))

for i in range(n):
    gap1 += gap[i]
print gap1

for i in range(n):
    gap2 += gap[i] ** 2  

print pow(gap2,0.5)

for i in range(n):
    gap3 += gap[i] ** 3
print pow(gap3,0.3333333333)

print max(gap)

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int x;
	cin >> x;

	int count = 0;
	while(1){
		count ++;
		if(count * x % 360 == 0){
			cout << count << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3624
from itertools import combinations_with_replacement as comb
n, m, q = map(int, input().split())
query = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    query.append((a-1, b-1, c, d))
ans = 0
for p in comb(list(range(1, m+1)), n):
    res = 0
    for a, b, c, d in query:
        if p[b]-p[a]==c:
            res+=d
    ans = max(ans, res)
print(ans)


Measured memory_bytes: 73516
from collections import deque
n = int(input())
c = list(input())
if c.count("W")*c.count("R") == 0:
    print(0)
    exit()
ans = 0
d = deque(c)
while d:
    flag = False
    while d:
        if flag:
            break
        lef = d.popleft()
        if lef == "W":
            while d:
                rig = d.pop()
                if rig == "R":
                    ans += 1
                    flag = True
                    break
print(ans)

Measured memory_bytes: 12264
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a));
	
	bool ans = true;
	int A = 0, B = 0;
	for(int i = 0; i < n; i++) {
		A += (a[i] == a[0]);
		B += (a[i] == a[0] + 1);
	}
	if(A + B != n or (B and !(n % a.back() * (n / a.back() + 1) == B) and B + (a.back() - 1) != n)) ans = false;
	if(!B and a[0] != n - 1 and a[0] * 2 > n) ans = false;
	
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        
        Arrays.sort(s);
        Arrays.sort(t);
        for (int i = 0; i < t.length/2; i++) {
        	char c = t[i];
        	t[i] = t[t.length-1-i];
        	t[t.length-1-i] = c;
        }
        
        if (new String(s).compareTo(new String(t)) < 0) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
        
    }
    
}

Measured memory_bytes: 23252