akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        char[] s = sc.next().toCharArray();

        int winCnt = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'o')
                winCnt++;
        }
        winCnt += 15 - s.length;

        System.out.println(winCnt >= 8 ? "YES" : "NO");
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
#include<stack>

using namespace std;

#define debug(x) cout<< #x <<" : "<< x << endl;
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define int long long

const int INF = (1<<30);
const int MOD = (int)1e9 + 7;

signed main(){
    int n;
    cin>>n;
    int a[200000];
    int mn=INF;
    int ans=0;
    stack<int> s;
    rep(i,n){
        cin>>a[i];
        if(!s.empty() ){
            while(s.top() > a[i]){
                s.pop();
                ans++;
                if(s.empty()) break;
            }
        }
        if(s.empty() ) s.push(a[i]);
        else if(s.top() != a[i]) s.push(a[i]);
    }
    ans+=s.size();
    cout<<ans<<endl;
  
    return 0;
}



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

int main(){
    int n; cin>>n;
    
    int i=1;
    while(++i<=n){// CHECK_NUM
        int x=i;
        if(x%3==0){
            cout<<" "<<i;
            continue;
        }
        while(x){//INCULDE3
            if(x%10==3){
                cout<<" "<<i;
                break;
            }
            x/=10;
        }
    }
    cout<<endl;
    
    return 0;
}



Measured memory_bytes: 3088
#include<stdio.h>
#include<math.h>
#include<string.h>
#define N 1000

int LCS(char X[], char Y[]){
  int m, n, max, i, j;
  int c[N+1][N+1];

  m = strlen(X);
  n = strlen(Y);
  max = 0;

  X[m+2] = '\0';
  for( i = m+1 ; i > 0 ; i-- ){
    X[i] = X[i-1];
  }
  X[0] = ' ';

  Y[n+2] = '\0';
  for( i = n+1 ; i > 0 ; i-- ){
    Y[i] = Y[i-1];
  }
  Y[0] = ' ';

  for( i = 0 ; i <= m ; i++ ) c[i][0] = 0;
  for( j = 0 ; j <= n ; j++ ) c[0][j] = 0;


  for( i = 1 ; i <= m ; i++ ){
    for( j = 1 ; j <= n ; j++ ){
      if( X[i] == Y[j] ) c[i][j] = c[i-1][j-1] + 1;
      else {
        c[i][j] = fmax(c[i-1][j], c[i][j-1]);
      }
      max = fmax(max, c[i][j]);
    }
  }
  return max;
}

int main(){
  char str1[N], str2[N];
  int n, i;

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%s%s",str1,str2);
    printf("%d\n",LCS(str1,str2));
  }
  return 0;
}



Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
static auto faster_iostream = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }();
typedef long long ll; typedef long double db;
const int N = 1e6 + 5, M = 1e9 + 7;

// #pragma GCC optimize ("trapv")

int main() {
  int a, b = 0, n;
  cin >> a >> n;
  while (n--) {
    cin >> b;
    a -= b;
  }
  if (a <= 0) puts("Yes");
  else puts("No");
}


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

li choose2(li n) {
    return n * (n - 1) / 2;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vector<int> cnt(n);
    rep(i, n) cnt[a[i]]++;
    li tot = 0;
    rep(i, n) {
        tot += choose2(cnt[i]);
    }
    rep(i, n) {
        li ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]] - 1);
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;


int main()
{

 int N, M, C;
 int count = 0;

 cin >> N >> M >> C;
 vector<int> B;

 for (int i = 0; i < M; i++) {
     int tmp;
     cin >> tmp;
     B.push_back(tmp);
 }

 for (int i = 0; i < N; i++) {
     int accum = C, tmp;
     for (int j = 0; j < M; j++) {
         cin >> tmp;
         accum += B[j] * tmp; 
     }
     if (accum > 0) {
         count++;
     }
 }
    cout << count << endl;
 
 return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

LL dp[51][2501];

int main(){
    int N,X;
    cin >> N >> X;
    memset(dp,0,sizeof(dp));
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    dp[0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=N;j>=0;j--){
            for(int s=2500;s>=0;s--){
                if(dp[j][s]>0) dp[j+1][s+a[i]]+=dp[j][s];
            }
        }
    }
    LL ans=0LL;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=2500;j++){
            if(dp[i][j]>0){
                if((double)j/i==X) ans+=dp[i][j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
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;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}


const int n_max = 150005;
int n;
vector<int> Graph[n_max];

double dp1[n_max];
double ans[n_max];


double dfs1(int v, int par){
    dp1[v] = 0.0;
    int cnt = 0;
    itrfor(itr,Graph[v]){
        if( *itr == par) continue;
        dp1[v] += 1.0 +  dfs1(*itr,v);
        cnt ++;
    }
    if(cnt != 0) dp1[v] /= cnt;
    return dp1[v] ;

}

double dfs2(int v, int par, double par_value){
    ans[v] = 0.0;
    itrfor(itr,Graph[v]){
        if( *itr == par) ans[v] += 1.0 + par_value;
        else ans[v] += 1.0 + dp1[*itr];
    }
    itrfor(itr,Graph[v]){
        if( *itr == par) continue;
        else{
            if( Graph[v].size() == 1)dfs2(*itr, v, 0.0);
            else dfs2(*itr, v, (ans[v] - 1.0 - dp1[*itr]) / ( double(Graph[v].size()) - 1) );
        }
    }

    ans[v] /= double(Graph[v].size());
}


signed main(){
    cin >> n;
    REP(i,n - 1){
        int x,y;
        cin >> x >> y;
        x --;
        y --;
        Graph[x].push_back(y);
        Graph[y].push_back(x);
    }

    dfs1(0,-1);

    dfs2(0,-1,0.0);
    REP(i,n){
        cout << fixed << setprecision(10) << ans[i] << endl;
    }



}

Measured memory_bytes: 18560
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define cout1(a) cout<<a<<endl
#define cout2(a,b) cout<<a<<' '<<b<<endl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define coutvp(v,i) cout<<v[i].fi<<" "<<v[i].se<<endl
#define couta(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())
#define all(v) v.begin(),v.end()
#define FASTIO {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setll;
typedef tree<char,null_type,less<char>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setc;

ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}

ll mod = 1e9 + 7;


void solve()
{
	ll a;
	cin>>a;
	cout<<(a + a*a + a*a*a)<<endl;
	return;
}

int main()
{
	FASTIO;
	ll t = 1;
	//cin>>t;
	rep(i, t)
		solve();
	return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
	char a;
	cin>> a;
	if(a >= 'a')
		cout<< "a";
	else
		cout<< "A";
	return 0;
}
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main()
{
    int n, m, x, cost_min = 1e9, cost = 0, flag = 1;
    int c[12] = {}, a[12][12] = {}, s[12] = {};
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        for(int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for(int i = 1; i < (1 << n); i++) {
        for(int j = 0; j < n; j++) {
            if(((i >> j) & 1)) {
                cost += c[j];
                for(int k = 0; k < m; k++) {
                    s[k] += a[j][k];
                }
            }
        }
        for(int j = 0; j < m; j++) {
            if(s[j] < x) {
                flag = 0;
                break;
            }
        }
        if(flag && cost < cost_min) cost_min = cost;
        cost = 0;
        flag = 1;
        for(int j = 0; j < m; j++) {
            s[j] = 0;
        }
        
    }
    cout << (cost_min == 1e9 ? -1 : cost_min) << endl;
    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
	import java.io.*;
import java.lang.reflect.Array;
	public class Main {
		static String a,b;
		static int dp[][],l1,l2;
		public static void main(String[] args) throws IOException{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			int t=1;
	//		Integer.parseInt(br.readLine().trim());
			StringBuilder printans=new StringBuilder();
			while(t-->0)
			{
				a=br.readLine().trim();
				b=br.readLine().trim();
				l1=a.length();
				l2=b.length();
				dp=new int[l1+1][l2+1];
				memset();
			 
			    int aasd=call(l1,l2);
			    int i=l1;
			    int j=l2;
			    
			    while(i>0 && j>0) {
			    	if(a.charAt(i-1)==b.charAt(j-1)) {
			    		printans.append(a.charAt(i-1));
			    		i--;
			    		j--;
			    	}
			    	else if(dp[i][j-1]<dp[i-1][j]) {
			    		i--;
			    	}
			    	else {
			    		j--;
			    	}
			    	
			    }
			    
			    System.out.println(printans.reverse());
			}
			
			
		}
		static void memset() {
			for(int a[]:dp) {
				Arrays.fill(a,-1);
			}
		}
		static int call(int i,int j) {
			if(i==0 || j==0) {
				return 0;
			}
			int ans=0;
			if(dp[i][j]!=-1)return dp[i][j];
			if(a.charAt(i-1)==b.charAt(j-1)) {
				ans+=1+call(i-1,j-1);
			}
			else {
				ans+=Math.max(call(i,j-1),call(i-1,j));
			}
			dp[i][j]=ans;
			return ans;	
		}
					
			
	}


Measured memory_bytes: 85224
def gcd_loop(a,b):
    if a < 0: a = -a
    if b < 0: b = -b
    if b < a: b, a = a, b
    if a == 0:
        return b
    while True:
        if b%a == 0:
            return a
        a, b = b%a, a


x, y = map(int, input().split())
print(gcd_loop(x, y))



Measured memory_bytes: 5600
N, K = map(int, input().split())
d = []
A = []

for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

okashi = [0] * N

for l in range(K):
    for i in A[l]:
        okashi[i-1] += 1

count = 0
for i in okashi:
    if i == 0:
        count += 1

print(count)


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

int main(void){
  int h, w, i, j;
  cin >> h >> w;
  string map[h] = {};
  for(i = 0; i < h; i++){
    cin >> map[i];
  }
  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      if(map[i][j] == '#'){
        if(i-1 >= 0 && j-1 >= 0 && map[i-1][j-1] != '#') map[i-1][j-1] += 1;
        if(i-1 >= 0 && map[i-1][j] != '#') map[i-1][j] += 1;
        if(i-1 >= 0 && j+1 < w && map[i-1][j+1] != '#') map[i-1][j+1] += 1;
        if(j-1 >= 0 && map[i][j-1] != '#') map[i][j-1] += 1;
        if(j+1 < w && map[i][j+1] != '#') map[i][j+1] += 1;
        if(i+1 < h && j-1 >= 0 && map[i+1][j-1] != '#') map[i+1][j-1] += 1;
        if(i+1 < h && map[i+1][j] != '#') map[i+1][j] += 1;
        if(i+1 < h && j+1 < w && map[i+1][j+1] != '#') map[i+1][j+1] += 1;
      } else{
        map[i][j] += '0' - '.'; // convert '.' to '0'
      }
    }
  }
  for(i = 0; i < h; i++){
    cout << map[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
S, T = input().split()
lis = list(input().split())
N1 = int(lis[0])
N2 = int(lis[1])
Z = input()
#print(S,T,lis,Z,N1,N2)

if Z == S:
    print(N1-1,N2)
elif Z == T:
    print(N1,N2-1)
else:
    print(N1,N2)

Measured memory_bytes: 3064
import fractions
a,b,c,d = map(int,input().split())
lcm = (c*d)//fractions.gcd(c,d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = b//lcm - (a-1)//lcm
ans = (b-a+1)-(x+y-z)
print(ans)

Measured memory_bytes: 5432
from collections import deque
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C = sorted(list(map(int,input().split())))
A = [0 for _ in range(N+1)]
hist = [0 for _ in range(N+1)]
que = deque([1])
hist[1] = 1
cur = 0
while que:
    i = que[-1]
    if len(G[i])==1:
        A[i] = C[cur]
        cur += 1
        hist[i] = 2
        que.pop()
    flag = 2
    for j in G[i]:
        if hist[j]==0:
            que.append(j)
            hist[j] = 1
            flag = 1
    if flag==2 and hist[i]==1:
        A[i] = C[cur]
        cur += 1
        hist[i] = 2
        que.pop()
cnt = 0
hist = {(i,j):0 for i in range(1,N+1) for j in G[i]}
for i in range(1,N+1):
    for j in G[i]:
        if hist[(i,j)]==0:
            cnt += min(A[i],A[j])
            hist[(i,j)] = 1
            hist[(j,i)] = 1
print(cnt)
print(*A[1:])

Measured memory_bytes: 57944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
string s;
int n;
long long cj[100005] = { 0 }, ci[100005] = { 0 };
int main() {
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'J') cj[i]++;
		if (i >= 1) cj[i] += cj[i - 1];
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'I') ci[i] = 1;
		if (i <= n - 2) ci[i] += ci[i + 1];
	}
	long long res = 0, cnt = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'O') cnt += (cj[i] + 1)*ci[i];
	}
	res = max(res, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'O') cnt += (cj[i])*(ci[i]+1);
	}
	res = max(res, cnt);
	cnt = 0;
	long long mc = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'O') cnt += cj[i] * ci[i];
		mc = max(mc, cj[i] * ci[i]);
	}
	res = max(res, cnt + mc);
	cout << res << endl;
}


Measured memory_bytes: 4924
#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 pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;


int main() {
    
	ll n,k;
	cin >> n >> k;
	ll h[n+1];
	rep (i,n) cin >> h[i];
	

	sort(h,h+n);
	int i = 0;
ll mini = INF;
	while (k <= n){
		mini = min(mini,h[k-1]-h[i]);
		//cout << h[k-1] << " " << h[i]<< endl;
		k++;
		i++;
	}

	cout << mini << endl;
	

	
}





Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


void minimization()
{
  int n, k;
  cin >> n >> k;

  cout << ceil((float)(n - 1) / (float)(k - 1)) << "\n";
}


void linear_approximation()
{
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    b[i] = a - (i + 1);
  }

  sort(b.begin(), b.end());

  int mid = b[n / 2];
  long long int ans = 0;
  for (int i = 0; i < n; ++i) ans += abs(mid - b[i]);
  cout << ans << "\n";

}


void modulo_summation()
{
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ans += a - 1;
  }

  cout << ans << "\n";
}


//skip
void all_green()
{
  int d, g;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for (int i = 0; i < d; ++i) cin >> p[i] >> c[i];


}


void base_2_number()
{
  int n;
  cin >> n;

  string s = "";
  if (n == 0) s = '0' + s;
  while (n != 0)
  {
    if (n % 2 != 0)
    {
      --n; //-２進数の整合性
      s = '1' + s;
    }
    else
    {
      s = '0' + s;
    }
    n /= -2;
  }

  cout << s << "\n";
}


void to_infinity()
{
  string s;
  long long int k;
  cin >> s >> k;

  char digit = '1';
  for (int i = 0; i < k; ++i)
  {
    if (s[i] != '1')
    {
      digit = s[i];
      break;
    }
  }
  cout << digit << "\n";
}


void candles()
{
  int n, k;
  cin >> n >> k;
  vector<long long int> x(n);
  for (int i = 0; i < n; ++i) cin >> x[i];

  long long int ans = 100000000000000000;
  for (int i = 0; i < n - k + 1; ++i)
  {
    long long int tmp = abs(x[i + k - 1] - x[i])+ min(abs(x[i]), abs(x[i + k - 1]));
    ans = min(ans, tmp);
  }

  cout << ans << "\n";
}


void triangular_relationship()
{
  int n, k;
  cin >> n >> k;

  if (k % 2 != 0)
  {
    long long int a = n / k;
    cout << a * a * a << "\n";
  }
  else
  {
    long long int a = n / k;
    long long int b = 2 * n / k;
    cout << a * a * a + (b - a) * (b - a) * (b - a) << "\n";
  }
}


long long int gcd(int a, int b)
{
  if (a < b)
  {
    int tmp;
    tmp = a;
    a = b;
    b = tmp;
  }

  int r = a % b;
  while (r != 0)
  {
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}


void skip()
{
  int n, X;
  cin >> n >> X;
  vector<int> d(n);
  for (int i = 0; i < n; ++i)
  {
    int x_tmp;
    cin >> x_tmp;
    d[i] = abs(X - x_tmp);
  }

  int ans = d[0];
  for (int i = 0; i < n; ++i)
  {
    ans = gcd(ans, d[i]);
  }

  cout << ans << "\n";
}


int main()
{
  //minimization();
  //linear_approximation();
  //modulo_summation();
  //all_green();
  //base_2_number();
  //to_infinity();
  //candles();
  //triangular_relationship();
  skip();
}


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

int main() {
  string S;
  cin>>S;
  
  int X=0;
  
  rep(i,S.length()){
    if(S.at(i)=='1'){X+=1;}
    else if(S.at(i)=='2'){X+=2;}
    else if(S.at(i)=='3'){X+=3;}
    else if(S.at(i)=='4'){X+=4;}
    else if(S.at(i)=='5'){X+=5;}
    else if(S.at(i)=='6'){X+=6;}
    else if(S.at(i)=='7'){X+=7;}
    else if(S.at(i)=='8'){X+=8;}
    else if(S.at(i)=='9'){X+=9;}
  }
  
  if(X%9==0){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int N; cin >> N;
    vector<ll> H(N),A(N,0);
    for(int i = 0; i < N; ++i) cin >> H[i];
    for(int i = 1; i < N; ++i) if(H[i-1]>=H[i]) A[i] = A[i-1] + 1;
    cout << *max_element(ALL(A)) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
using namespace std;

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

    for(int i=1; i<10; i++){
      if(n%i==0 && n/i<10){
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
}




Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;


    int[] A;
    int N;

    void calc()
    {
        cin = new Scanner();
        N = cin.nextInt() + 1;
        int Z = cin.nextInt();
        int W = cin.nextInt();

        A = new int[N];
        A[0] = W;
        for (int i = 1; i < N; i++)
        {
            A[i] = cin.nextInt();
        }

        dp = new long[N, 2];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                dp[i, j] = INF;
            }
        }
        Console.WriteLine(dfs(0, 0));
    }

    long INF = (1L << 40) + 10;
    long[,] dp;

    long dfs(int pos, int p)
    {
        if (dp[pos, p] != INF) return dp[pos, p];
        long ans = Math.Abs(A[pos] - A[A.Length - 1]);
        if (p == 0)
        {
            for (int j = pos + 1; j < N - 1; j++)
            {
                ans = Math.Max(ans, dfs(j, 1 - p));
            }
        }
        else
        {
            for (int j = pos + 1; j < N - 1; j++)
            {
                ans = Math.Min(ans, dfs(j, 1 - p));
            }
        }
        dp[pos, p] = ans;
        return ans;
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    int a,b;
    string s;
    cin >> a >> b >> s;
    rep(i,a){
        if(s[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    if(s[a] != '-'){
        cout << "No" << endl;
        return 0;
    }
    for(int i = a+1; i < a+b+1; i++){
        if(s[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3580
#include<stdio.h>
int main(void){
    int A;
    int B;
    int C;
    int D;
    int E = 0;
    scanf("%d %d %d",&A,&B,&C);
    D = A-B;
    if(D <= C){
        printf("%d\n",C-D);
    }else{
        printf("%d",E);
    }
    return 0;
} 


Measured memory_bytes: 128
#include<stdio.h>

void revers(int a[1000], int n){
	int i,s;
	for (i = 0; i < n / 2; i++){
		s = a[i];
		a[i] = a[n - 1-i];
		a[n - 1 - i] = s;
	}
}

int main(void){
	int n,i;
	int a[1000];
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	revers(a, n);
	for (i = 0; i < n-1; i++){
		printf("%d ", a[i]);
	}
	printf("%d\n",a[i]);


	return 0;
}


Measured memory_bytes: 2116
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	string s; cin >> s;
	string t = "CODEFESTIVAL2016";
	int res = 0;
	rep(i, 16)if (s[i] != t[i])++res;
	cout << res << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d) cout<<"Left"<<endl;
    else if(a+b<c+d) cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int k[123], s[123][123], p[123];
signed main() {
	int n, m, ans = 0; cin >> n >> m;
	for (int h = 0; h < m; h++) {
		cin >> k[h];
		for (int i = 0; i < k[h]; i++) {
			cin >> s[h][i];
		}
	}
	for (int h = 0; h < m; h++) {
		cin >> p[h];
	}
	for (int i = 0; i <= (1 << n); i++) {
		vector<int> sep = { }; int dame = 0;
		for (int j = 0; j <= n - 1; j++) {
			if ((i & (1 << j)) > 0) {
				sep.push_back(j + 1);
			}
		}
		if (i == 0) { continue; }
		for (int h = 0; h < m; h++) {
			int cnt = 0;
			for (int x = 0; x < k[h]; x++) {
				for (int y = 0; y < sep.size(); y++) {
					if (s[h][x] == sep[y]) { cnt++; }
				}
			}
			if (cnt % 2 != p[h]) { dame = 1; }
		}
		if (dame == 0) { ans++; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
def main():
    h,w = map(int,input().split())
    sy,sx = map(int,input().split())
    gy,gx = map(int,input().split())
    S = []
    for _ in range(h):
        S.append(input())
    
    G = [[-1]*w for _ in range(h)]
    G_b = [[False]*w for _ in range(h)]
    v = [(1,0),(0,1),(-1,0),(0,-1)]
    ct = 0

    dq1 = deque([])
    dq1.append((sx-1,sy-1))
    G[sy-1][sx-1] = 0
    G_b[sy-1][sx-1] = True


    while dq1:

        g = set([])
        while dq1:
            x,y = dq1.popleft()
            g.add((x,y))
            for vx,vy in v:
                nx = x+vx
                ny = y+vy
                if nx>=0 and nx<w and ny>=0 and ny<h and (not G_b[ny][nx]) and S[ny][nx]==".":
                    G_b[ny][nx] = True
                    G[ny][nx] = ct
                    dq1.append((nx,ny))

        
        while g:
            x,y = g.pop()
            for i in range(-2,3):
                for j in range(-2,3):
                    if i!=0 or j!=0:
                        nx = x+i
                        ny = y+j
                        if nx>=0 and nx<w and ny>=0 and ny<h and (not G_b[ny][nx]) and S[ny][nx]==".":
                            dq1.append((nx,ny))
                            G_b[ny][nx] = True
                            G[ny][nx] = ct+1


        ct+=1
    
    print(G[gy-1][gx-1])

main()

Measured memory_bytes: 106644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vP p(N);
    vl A(N),B(N);
    rep(i,N){
        cin >> p[i].first >> p[i].second;
        A[i]=p[i].first+p[i].second;
        B[i]=p[i].first-p[i].second;
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    cout << max({A[N-1]-A[0],B[N-1]-B[0]}) << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 9532
#include <stdio.h>
#include <string.h>
 
int stricmp(char* ch1,char* ch2){
    int ch1_length = 0,ch2_length = 0,div;
    for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
    for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
    if(ch1_length != ch2_length) return -1;
    for(int i = 0; ch1[i] != '\0';i++)
    {
        div = ch1[i] -ch2[i];
        if(div != 0 && div != 32 && div != -32)
            return -1;
    }
    return 0;
}
 
int main(){
    char W[11],T[1001];
    int count = 0;
    scanf("%s",W);
    while(true){
        scanf("%s",T);
        if(strcmp("END_OF_TEXT",T) == 0) break;
        if(stricmp(T, W) == 0) count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
int main()
{   string s;
    cin>>s;
    if (s[2]==s[3] && s[4]==s[5]) cout<<"Yes";
    else cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll po = N % 10;
  if (po == 0 || po == 1 || po == 6 || po == 8) {
    cout << "pon" << endl;
  } else if (po == 3) {
    cout << "bon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=150;
//ここまでテンプレ
int main(){
	ll H,W,K;
	cin>>H>>W>>K;
	//DP[i][j]=i本目の縦棒時点でjにたどりつくあみだくじの数
	ll DP[SIZE][SIZE]={};
	DP[0][0]=1;

	int X=W-1;
	for(int i=1;i<=H;i++){
		for(int state=0;state<(1<<X);state++){
			//stateがvalidかどうか判定する
			bool valid=true;
			for(int j=0;j<X;j++)
				if((state&(1<<j)) && (state&(1<<(j+1))))
					valid=false;
			if(!valid)
				continue;
			//cout<<bitset<10>(state)<<endl;
			//DPテーブルを更新する
			for(int j=0;j<W;j++){
				//左に行く
				if(j!=0 && (state&(1<<(j-1)))){
					DP[i][j-1]+=DP[i-1][j];
					DP[i][j-1]%=MOD;
				}
				//右に行く
				else if(j!=W-1 && (state&(1<<j))){
					DP[i][j+1]+=DP[i-1][j];
					DP[i][j+1]%=MOD;
				}
				//そのまま
				else{
					DP[i][j]+=DP[i-1][j];
					DP[i][j]%=MOD;
				}
			}
		}
	}
	cout<<DP[H][K-1]<<endl;
	/*
	for(int i=0;i<=H;i++){
		for(int j=0;j<W;j++){
			cout<<DP[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 384
a,b,c,d = map(int,input().split())
if a <= c <= b <= d:
    print(b - c)
elif c <= a <= d <= b:
    print(d - a)
elif a <= c <= d <= b:
    print(d - c)
elif c <= a <= b <= d:
    print(b - a)
else:
#elif b <= c or d <= a:
    print(0)

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

typedef long long int lli;
const int MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < n; i++)

using namespace std;

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

	int N, K, res; cin >> N >> K;
	if (K == 1 || N == K) {
		cout << "0" << endl;
		return 0;
	}
	if (N > K) {
		res = N - K;
		cout << res << endl;
	}
	else {
		cout << "1" << endl;
		return 0;
	}
}

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

int main(int argc, char const* argv[])
{
	int H, W;
	while ((cin >> H >> W) && (H || W)) {
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (i==0 || i==H-1 || j==0 || j==W-1) {
					cout << "#";
				} else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1152
//2020-04-09 16:20:56
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n,c;cin>>n>>c;
    ll a[n];mem(a,0);
    ll lst=0;
    vector<pair<ll,ll>> vv;
    rep(i,0,n){
        ll x,v;cin>>x>>v;
        vv.pb(mp(x,v));
        a[i]=(v-(x-lst));
        if(i>0)a[i]+=a[i-1];
        lst=x;
    }
    ll sum=0;ll b[n];mem(b,0);
    for(int i=n-1;i>=0;i--){
        b[i]=(sum+vv[i].S-(c-vv[i].F));
        sum+=vv[i].S;
    }
    ll suf[n];mem(suf,0);sum=0;
    for(int i=n-1;i>=0;i--){
        suf[i]=(sum+vv[i].S-2*(c-vv[i].F));
        sum+=vv[i].S;
        if((i+1)<n)
        suf[i]=max(suf[i],suf[i+1]);
    }
    ll pref[n];mem(pref,0);sum=0;
    rep(i,0,n){
        pref[i]=(sum+vv[i].S-2*(vv[i].F));
        sum+=vv[i].S;
        if(i>0)
        pref[i]=max(pref[i],pref[i-1]);
    }
    // rep(i,0,n)cout<<a[i]<<" ";cout<<endl;
    // rep(i,0,n)cout<<pref[i]<<" ";cout<<endl;
    // rep(i,0,n)cout<<b[i]<<" ";cout<<endl;
    // rep(i,0,n)cout<<suf[i]<<" ";cout<<endl;
    ll mx=0;
    rep(i,0,n){
        ll val=a[i];
        if(i<(n-1))val+=max(0ll,suf[i+1]);
        mx=max(mx,val);
    }
    for(int i=n-1;i>=0;i--){
        ll val=b[i];
        if(i>0)val+=max(pref[i-1],0ll);
        mx=max(mx,val);
    }
    cout<<mx;
}

Measured memory_bytes: 5104
import math


def main():
    N, M = map(int, input().split())
    mod = 10 ** 9 + 7
    if abs(N - M) > 1:
        ans = 0
    elif N - M == 1:
        ans = (math.factorial(M)**2 * N) % mod
    elif N - M == -1:
        ans = (math.factorial(N)**2 * M) % mod
    else:
        ans = (math.factorial(N)**2 * 2) % mod

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10696
s = input()
N = 1<<(len(s)-1)

for one in range(N):
    c = int(s[0])
    tmp = s[0]
    for i in range(0,len(s)-1):
        if (one>>i & 1)==1:
            c+=int(s[i+1])
            tmp+='+'
        else:
            c-=int(s[i+1])
            tmp+='-'
        tmp+=s[i+1]
    tmp+='=7'
    if c==7:
        print(tmp)
        break

Measured memory_bytes: 38256
def unbalanced(s: str) -> tuple:
    for i in range(len(s) - 1):
        c1, c2 = s[i], s[i + 1]
        if c1 == c2:
            return i+1, i+2
        if i + 2 < len(s):
            c3 = s[i + 2]
            if c1 == c3:
                return i+1, i+3
    return -1, -1


if __name__ == "__main__":
    s = input()
    a, b = unbalanced(s)
    print(a, b)


Measured memory_bytes: 3188
class BIT:
  def __init__(self, size):
    self.tree = [0] * (size + 1)
    self.size = size
  
  def sum(self, a):
    res = 0
    a += 1
    while a:
      res += self.tree[a]
      a -= a & -a
    return res
  def add(self, a, x):
    a += 1
    while a < len(self.tree):
      self.tree[a] += x
      a += a & -a

import sys

stdin = sys.stdin
na = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())

def main():
  n, q = na()
  bit = BIT(n)
  for _ in range(q):
    t, x, y = na()
    if t == 0:
      bit.add(x - 1, y)
    else:
      print(bit.sum(y - 1) - bit.sum(x - 2))

main()


Measured memory_bytes: 8140
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define int long long
#define ll long long
using namespace std;
int dp[1000010];
int n,k,h[100010];
signed main(){
    cin>>n>>k;
    rep(i,n){
        cin>>h[i];
    }
  rep(i,n)dp[i]=1e18;
    dp[0]=0;
    rep(i,n){
        for (int j= 0; j <= k; j++)
        {
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0

for i in range(N):
	if A[i]>=B[i]:
		ans+=B[i]
	else:
		ans+=A[i]
		B[i]-=A[i]
		if A[i+1]>=B[i]:
			A[i+1]-=B[i]
			ans+=B[i]
		else:
			ans+=A[i+1]
			A[i+1]=0
print(ans)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000000000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll m1=-1,m2=-1;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=m1)
        {
            m2=m1;
            m1=a[i];
        }
        else if(a[i]>=m2)
        {
            m2=a[i];
        }
    }
    for(ll i=0;i<n;i++)
    {
        if(a[i]==m1)
            cout<<m2<<endl;
        else
            cout<<m1<<endl;
    }
}

Measured memory_bytes: 3200