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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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 ctoi(char c){
  if(c>='0'&&c<='9') return c-'0';
  return 0;
}


char op(int i){
  if(i==-1) return '-';
  else return '+';
}

int main(){
  string s;vint n(4);
  cin >> s;
  rep(i,4) n[i]=ctoi(s[i]);
  
  for(int i=-1;i<=1;i+=2){
    for(int j=-1;j<=1;j+=2){
      for(int k=-1;k<=1;k+=2){
        int sevenp=n[0]+i*n[1]+j*n[2]+k*n[3];
        if(sevenp==7){
          cout << n[0] << op(i) << n[1] << op(j) << n[2] << op(k) << n[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b, c = 0;
    cin >> n;
    while (n--) cin >> b, a[b]++;
    fr1(99999) c = max(c, a[i - 1] + a[i] + a[i + 1]);
    cout << c;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n,0);
map<ll, ll> buka;
reps(i, n,1){
    cin >> a[i];
    buka[a[i]-1]++;
}
rep(i,n){
    if(buka.count(i)){
        cout << buka[i] << endl;
    }
    else{
        cout << 0 << endl;
    }
}
//system("pause");
return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    ll n;
    cin>>n;
    vector<ll> dp(n,0);
    vector<ll> arr;
    for(ll i=1;i<=n;++i){
        ll x;
        cin>>x;
        arr.push_back(x);
    }
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    //cout<<dp[1]<<endl;
    for(ll i=2;i<n;++i){
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
        //cout<<dp[i-1]+abs(arr[i]-arr[i-1])<<" "<<dp[i-2]+abs(arr[i]-arr[i-2])<<endl;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 5044
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[M];
    int[] b = new int[M]; 
    boolean[] check1 = new boolean[N];
    boolean[] check2 = new boolean[N];
    List<Integer> list = new ArrayList<>();
    for(int i=0;i<M;i++){
      a[i] = sc.nextInt()-1;
      b[i] = sc.nextInt()-1;
      if(a[i]==0){
        check1[b[i]]=true;
      }
      if(b[i]==N-1){
        check2[a[i]]=true;
      }
    }
    String ans = "IMPOSSIBLE";
    for(int i=0;i<N;i++){
      if(check1[i] && check2[i]){
        ans = "POSSIBLE";
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 62112
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	Integer a[] = new Integer[n];
	int x= 0;
	int y= 0;

	for(int i=0;i<n;i++) {
		a[i]  = sc.nextInt();
	}
	Arrays.sort(a, Collections.reverseOrder());
	try{
	for(int i=0;i<n;i+=2) {
		x += a[i];
	}
	for(int i=1;i<n;i+=2) {
		y += a[i];
	}
	}catch(Exception e) {

	}
	System.out.println(x-y);
	}
}

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

#define endl '\n'
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v), greater<int>())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<30
#define v(T) vector<T>
#define vv(T) v(v(T))
#define print(x) cout<<x<<endl
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl
#define printu(v) for(auto i : v){print(i);}
#define readv(v, n) for (int i=0;i<n;i++)cin >> v[i]
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

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 i, j, k;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	vi v;
	cin >> n;
	rep(i, n) {
		int k;
		cin >> k;
		v.push_back(k);
	}
	int ans = INF;
	int index = -100;
	while(index <= 100) {
		int sum = 0;
		rep(i, n) {
			sum += std::pow(v[i] - index,2);
		}
		chmin(ans, sum);
		index++;
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		int w=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int ans;
		if(Math.abs(b-a)<w) {
			ans=0;
		}
		else {
			ans=Math.abs(a-b)-w;
		}
		System.out.println(ans);
		
	}
	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





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

using namespace std;

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

    if (a <= 0 && b >= 0) {
        cout << "Zero" << endl;
    } else if (a >= 0 || (b - a) % 2 == 1) {
        cout << "Positive" << endl;
    } else {
        cout << "Negative" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
class conb{
    public static void Main(){
        String temp = Console.ReadLine();
        while(!temp.Equals("0 0")){
            String[] str = temp.Split(' ');
            int n = int.Parse(str[0]);
            int x = int.Parse(str[1]);
            int count = 0;
            int i,j,k;
            for(i=1; i<=n; i++){
                j=i+1;
                for(j=i+1; j<=n; j++){
                    k=j+1;
                    for(k=j+1; k<=n; k++){
                        if(i!=j || j!=k|| i!=k){
                            if(i+j+k == x){
                                count++;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("{0}",count);
            temp = Console.ReadLine();
        }
    }
}



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

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

    if (b - a <= 0) {
        cout << "delicious" << endl;
    }
    else {
        if (b - a <= x) {
            cout << "safe" << endl;
        }

        else {
            cout << "dangerous" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
class Solution {
  int a[3];
public:
  void run() {
    cin >> a[0] >> a[1] >> a[2];
      if (a[0] == a[1] and a[0] == a[2]) cout << "Yes\n", exit(0);

    cout << "No\n";
  }     
};
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  Solution().run();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	//mapについて調べて反省
	int N;
	cin >> N;

	map<int, int> MAP;
	rep(i, N) {
		int A;
		cin >> A;
		MAP[A]++;
	}

	int hitotu = 0;
	int hutatu = 0;
	for (auto itr : MAP) {
		if (itr.second >= 4) {
			hitotu = itr.first;
			hutatu = itr.first;
		}
		else if(itr.second >= 2){
			hutatu = hitotu;
			hitotu = itr.first;
		}
	}

	co(1ll * hitotu * hutatu);

	Would you please return 0;
}

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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s; cin>>s;
    deque<char> ans;
    for(char x:s) ans.push_back(x);
    bool left=true;
    int t; cin>>t;
    while(t--){
        int q; cin>>q;
        if(q==1) left=!left;
        if(q==2){
            int f; char c; cin>>f>>c;
            if(f==1){
                if(left) ans.push_front(c);
                else ans.push_back(c);
            }
            else{
                if(!left) ans.push_front(c);
                else ans.push_back(c);
            }
        }
    }
    if(!left) reverse(ans.begin(),ans.end());
    for(char x:ans) cout<<x;
    return 0;
}

Measured memory_bytes: 976
var end = false;

var col_small = new Buffer("#.#.#.#.#.");
var col = new Buffer(300);
for (i = 0; i < 300; i += 10) {
	col_small.copy(col, i, 0);
}
col = col.toString();

require('fs').readFileSync('/dev/stdin', 'ascii').split('\n').forEach(main);

function main(line) {
	if (line === '0 0') {
		end = true;
		return;
	}
	if (end) return;
	var hw = line.split(' ').map(Number);
	var h = hw[0];
	var w = hw[1];
	even = col.slice(0, w);
	odd = col.slice(1, w + 1);
	for (j = 0; j < hw[0]; j++) {
		if (j % 2 === 0) console.log(even);
		else console.log(odd);
	}
	console.log("");
}

Measured memory_bytes: 16900
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


void solve() {
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long x, y, x1, y1;
    cin >> x >> y;
    for(int i = 1; i < n; i++){

        cin >> x1 >> y1;
        long long p = x / x1 + (x % x1 > 0), q = y / y1 + (y % y1 > 0);
        p = max(p, q);
        x = p * x1, y = p * y1;

    }

    cout << x + y;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
 
using namespace std;
 
using   ll=long long;
using   ld=long double;
 
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define int            long long 
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define ff              first
#define ss              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323

void solve()
{
	ll n,m;
	
	cin>>n>>m;
	
	string s="",t="";
	
	for(int i=0;i<n;i++)	s+=(m+'0');
	for(int i=0;i<m;i++)	t+=(n+'0');
	
	if(s<t)
	{
		cout<<s;
	}
	else
	{
		cout<<t;
	}
}
 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readInts >>= print . uncurry (-) . ( maximum &&& minimum )

Measured memory_bytes: 508
# coding: utf-8
# Your code here!
m=int(input())
n=input().split(" ")
for i in range(m):
    n[i]=int(n[i])
  
s=sorted(n,reverse=False)
d=0
for i in range(m):
    if not (n[i]==s[i]):
        d=d+1
#print(d)
if(d < 3):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main() {
    ios;
    string s;
    cin >> s;
    int m = 0, d = 0;
    for (int i = 5, k = 0; i < s.size(); ++i) {
        if (s[i] == '/') {
            k = 1;
            continue;
        }
        if (!k)
            m = m * 10 + s[i] - '0';
        else
            d = d * 10 + s[i] - '0';
    }
    if (m <= 4) {
        if (m == 4 && d <= 30)
            cout << "Heisei\n";
        else if (m < 4)
            cout << "Heisei\n";
        else
            cout << "TBD\n";
    } else
        cout << "TBD\n";
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int n,m;
vector<int> g[2*100010];
vector<int> color(2*100010,0);

bool dfs(int x,int c){
    color[x]=c;
    FOR(i,0,len(g[x])){
        if(color[g[x][i]]==c){
            return false;
        }
        if(color[g[x][i]]==0 && !dfs(g[x][i],-c)){
            return false;
        }
    }
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    cout<<count(begin(s),end(s),'1')<<endl;
}

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

int main () {
  int N , M ;
  cin >> N >> M ;
  vector<int> line(M) ;
  
  for(int i = 0 ; i < M ; i++ ) {
    cin >> line[i] ;
  }
  sort(line.begin(),line.end()) ;
  
  vector<int> num(M);
  
  for(int i = 0 ; i < M - 1 ; i++){
    num[i] = line[i + 1] - line[ i ] ;
  }
  sort(num.begin(),num.end()) ;
  
  int ans = 0 ;
  
  for(int i = 0 ; i < M - ( N - 1 ) ; i++ ) {
    ans += num[i] ;
  }
  
  cout << ans << endl ;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 10000 + 10;
vector<int> e[N];
LL v[N];
queue<int> q;
LL c[N];
int main()
{
    LL sum = 0, maxn = -1;
    int n;
    scanf("%d", &n);
    for (int i = 1, a, b; i < n; i++)
    {
        scanf("%d %d", &a, &b);
        e[a].push_back(b);
        e[b].push_back(a);
    }


    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &c[i]);
        sum += c[i];
        maxn = max(maxn, c[i]);
    }
    sort(c + 1, c + n + 1);

    int k = n;
    memset(v, -1, sizeof v);
    q.push(1);
    while (!q.empty())
    {
        int p = q.front();
        q.pop();

        v[p] = c[k--];
        for (int i : e[p])
            if(v[i] == -1) 
                q.push(i);
    }
    
    printf("%lld\n", sum - maxn);
    for(int i = 1; i <= n; i++) {
        printf("%lld ", v[i]);
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30,maxn=2000005;
int i,j,k,n,v[100000005];
int f[maxn],prime[maxn],tot,e[100005];
long long ans[505][505],mx;
map<long long,int> p;
void shai()
{
    tot=0;
    for(int i=2;i<maxn;i++)
    {
        if(!f[i])
            prime[tot++]=i;
        for(int j=0;j<tot&&prime[j]*i<maxn;j++)
        {
            f[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                break;
            }
        }
    }
}
long long gcd(long long a,long long b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
	if(a==0)
		return b;
	if(b==0)
		return a;
	return a/gcd(a,b)*b;
}
int main()
{
	shai();
	scanf("%d",&n);
	int m=0;
	for(i=1;i<=499;i+=2)
		e[i]=++m;
	for(i=2;i<=499;i+=2)
		e[i]=++m;
	for(i=500;i>=1;--i)
		for(j=500;j>=1;--j)
			if((i+j)&1)
			{
				for(k=prime[e[(i+j)/2]-1];v[k];k+=prime[e[(i+j)/2]-1]);
				ans[i][j]=k;
				v[k]=1;
				p[k]=1;
			}
	for(i=1;i<=500;++i)
		for(j=1;j<=500;++j)
			if(ans[i][j]==0)
			{
				long long s=lcm(lcm(ans[i-1][j],ans[i][j-1]),lcm(ans[i+1][j],ans[i][j+1]));
				ans[i][j]=s+1;
				while(p[ans[i][j]])
					ans[i][j]+=s;
				p[ans[i][j]]=1;
			}
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=n;++j)
		{
			printf("%lld ",ans[i][j]);
			//mx=max(mx,ans[i][j]);
		}
		printf("\n");
	}
	//cout<<mx<<endl;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 9999;
  for (int i = 0; i < s.length(); i++)
    if (s.substr(i, 3).length() == 3)
      ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections
c = 0
cc = collections.Counter()
for _ in range(int(raw_input())):
	w = raw_input()
	for u in range(len(w)-1):
		if w[u:u+2] == 'AB': c+=1
	w = w.replace('AB','')
	if len(w) == 1:
		s = (w[0] if w[0] == 'A' or w[0] == 'B' else '')
	if len(w) >= 2:
		s = (w[0] if w[0] == 'A' or w[0] == 'B' else '') + (w[-1] if w[-1] == 'A' or w[-1] == 'B' else '')
	
	if s: cc[s]+=1
q= 0 #max(0,cc['BA'] - 1)
if cc['BA']:
	q += cc['BA'] -1
	if cc['A']:
		cc['A']-=1
		q+=1 
	if cc['B']:
		cc['B']-=1
		q+=1 
print c + q + min(cc['A']+cc['AA'],cc['B']+cc['BB'])
"""
A
AA
B
BB
AB
BA

 A - [BA - BA - BA - BA - BA - BA]  - B 
 A - B 



    [AB - AB - AB - AB - AB - AB ]

    A - B - A  - B  

"""

Measured memory_bytes: 97692
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, h, w;
    cin >> n >> h >> w;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        a /= h;
        b /= w;
        if(a * b != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int s, w; cin >> s >> w;
    if (s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
const int INF = 1e9;
int dp[maxn], val[maxn], w[maxn];
int main()
{
	int h, n;
	scanf("%d%d", &h, &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d%d", &w[i], &val[i]);
	for(int i = 1; i <= h; ++i)
		dp[i] = INF;
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j <= h; ++j)
			dp[j] = min(dp[j], dp[j - w[i] >= 0 ? j - w[i] : 0] + val[i]);
	printf("%d\n", dp[h]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll x, ans = 0;
    cin >> x;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li k,n;

    cin>>k>>n;

    li a[n];

    for(li i=0;i<n;i++)
        cin>>a[i];

    li b[n-1],mx=0,sum=0;

    f(i,1,n-1)
    {
        b[i-1]=a[i]-a[i-1];
        sum+=b[i-1];
        mx=max(mx,b[i-1]);
    }

    li tp=a[0]+k-a[n-1];

    sum+=tp;

    mx=max(mx,tp);

    cout<<sum-mx;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
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); }
/////////////////////////////////////////////////////////////////////
int main()
{int n,w;
	cin>>n>>w;
	vector <int> ni(n),wi(n);
	REP(i,n)
	{
		cin>>wi[i]>>ni[i];
		// cout<<ni[i];
	}
	// REP(i,n)
	// DEBUG(wi[i])
	vector <vector <ll>> dp(n+1,(vector<ll>(w+1,0)));
	FOR(i,1,n)
	{
		FOR(j,1,w)
		{
			if(wi[i-1]<=j){
				// DEBUG(ni[i-1])
				// cout<<ni[i-1]+dp[i-1][j-wi[i-1]]<<endl;
				dp[i][j] = max(ni[i-1]+dp[i-1][j-wi[i-1]],dp[i-1][j]);

			}
			else
				dp[i][j] = dp[i-1][j];
			// DEBUG(dp[i][j])
		}
	}
	cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;


int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int G = max(X, Y);

	long long int R = 100000000000000000;

	for (int i = 0;i<=2*G  ; i += 2) {
		if (((X - i / 2 )<= 0)&&((Y-i/2)<=0)) {
			if (R > i*C) {
				R = i * C;
			}
		}
		if (((X - i / 2) > 0) &&( (Y - i / 2)<=0)) {
			if (R > i*C+A*(X-i/2)) {
				R = (i * C) +( A * (X - i / 2));
			}
		}
		if (((X - i / 2) <= 0) && ((Y - i / 2)>0)) {
			if (R >( i*C+B*(Y-i/2))) {
				R = (i * C )+ (B * (Y - i / 2));
			}
		}
		if (((X - i / 2 )> 0 )&& ((Y - i / 2)>0)) {
			if (R > (i*C+(A*(X-i/2))+((Y-i/2)*B))) {
				R = i * C + (A * (X - i / 2)) + (B*(Y - i / 2));
			}
		}
		
	}
	

	cout << R << endl;
	
	return 0;
}

		

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define ll long long
#define PI acos(-1.0)
#define MAX 0x3fffffff
using namespace std;

int n, a[200005], x;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> x;
		a[x]++;
	}
	for (int i = 1; i <= n; i++)cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 4388
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h<=0:
        break
    h -= bi
    ans += 1
print(ans + ((h + amax - 1) // amax) * (h > 0))


Measured memory_bytes: 87424
#include <stdio.h>
int main(void){
  int a,b,i;
  char s[15];
  scanf("%d%d\n%s",&a,&b,s);
  if (s[a]!='-'){
    printf("No\n");
    return 0;
  }
  s[a]='0';
  for (i=0;s[i];i++){
    if ((int)s[i]<48||(int)s[i]>57){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int n,m,ans;
int main(){
	int i,ans=0,anss=0;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i!=1){
			if(a[i]<=a[i-1])ans++,anss=max(anss,ans);
			else anss=max(anss,ans),ans=0;
		}
	}
	printf("%d\n",anss);
	return 0;
}

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

typedef long long ll;
typedef double db;

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

void test() {
    int n; cin >> n;
    if (360 % n == 0) {
        cout << 360 / n << "\n";
    } else {
        int a = __gcd(360, n);
        cout << 360 / a << "\n";
    }
}

int main() {
      fast_io();
      #ifdef HOME
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif
      cout << fixed << setprecision(15);
      int t = 1;
      // cin >> t;
      for (int i = 1; i <= t; ++i) {
          test();
      }
      #ifdef HOME
          cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
      #endif
      return 0;
}


Measured memory_bytes: 3664
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        x: usize,
        m: usize,
    }

    let mut ans = x;
    let mut sum = 0;
    let mut cnt = 0;
    let mut init = 0;
    let mut ok: bool = true;
    let mut dp: Vec<usize> = Vec::new();
    for i in 0..m {
        dp.push(ans);
        ans = (ans*ans)%m;
        for j in 0..dp.len() {
            if ans==dp[j] {
                cnt = dp.len() - j;
                init = j;
                ok = false;
                break;
            }
        }
        if ok==false {
            break;
        }
    }
    let mut init_sum = 0;
    for i in 0..init {
        init_sum += dp[i];
    }

    for i in init..dp.len() {
        sum += dp[i];
    }

    let d = (n-init) / cnt;
    let r = (n-init) % cnt;
    sum *= d;
    sum += init_sum;
    for i in 0..r {
        sum += ans;
        ans = (ans*ans)%m;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2420
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;


int main(void){
	          int i,j;

	          int a,b;
	          cin >> a >> b;
	          
	          cout << (a+b)%24 << endl;
	

	          return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, m, x, y;
  scanf("%d%d%d%d", &n, &m, &x, &y);
  int a, maxx=-101, miny=101;
  for (int i=0; i<n; i++) {
    scanf("%d", &a);
    maxx = (a>maxx) ? a : maxx;
  }
  for (int i=0; i<m; i++) {
    scanf("%d", &a);
    miny = (a<miny) ? a : miny;
  }
  if (x<=maxx&&maxx<miny&&miny<=y) printf("No War");
  else printf("War");
  return 0;
}


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

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

  int count = 0;
  while (s.size() > 1) {  // 1つだけの要素は回文
    if (s[0] == s[s.size() - 1] ) {
      s.pop_back();  // 末尾削除
      s.erase(s.begin());
      }
    else if (s[0] == 'x' && s[s.size() - 1] != 'x') {
      // s.push_back('x');
      s += 'x';
      count++;
    }
    else if (s[0] != 'x' && s[s.size() - 1] == 'x') {
      s = 'x' + s;
      count++;
    }
    else {
      count = -1;
      break;
    }
  }

  cout << count << endl;

  return 0;
}


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

int main(){
    int num; cin >> num;
    int a,b;
    a = num/100;
    b = num%100;
    
    if((a == 0 || a > 12) && (b == 0 || b > 12)){
        cout << "NA" << endl;
    }
    else if((a <= 12 && a != 0) && (b > 12 || b == 0)){
        cout << "MMYY";
    }
    else if((a > 12 || a == 0) && b <= 12 && b != 0){
        cout << "YYMM";
    }
    else cout << "AMBIGUOUS";
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define long long long // for codeforces

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(a>=b) cout << "delicious" << endl;
  else if(b-a<=x) cout << "safe"<<endl;
  else cout << "dangerous" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector <int> l(m);
    vector <int> r(m);
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i];
    }
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    int ans = 1;
    ans += r[0]-l.back();
    if(ans<0)ans=0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)

int main() {
  int a, b;
  cin >> a >> b;
  if (a >= b) {
    rep(i, a) {
        cout << b;
    }
  }
  if (a < b) {
    rep(i, b) {
        cout << a;
    }
  }
  cout << endl;
}

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

int main() {
  string hi;
  hi = "hi";
  string s;
  cin >> s;
  if(s == hi){
    cout << "Yes" << endl;
    return 0;
  }
  rep(i,4) {
    hi += "hi";
    if(s == hi){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n,l;
    cin >> n >> l;
    vector<int> L(n);
    L[0] = l;
    int cnt = L[0];
    int min_ = inf;
    rep1(i,1,n){
        L[i] = l + i;
        cnt += L[i];
    }
    
    int sa = inf;
    int del;
    rep(i,n){
        int ans = cnt - L[i];
        if(abs(cnt-ans)<sa){
            del = ans;
            sa = abs(cnt-ans);
        }   
    }

    cout << del << endl;
    
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
#define INF (int)1e18


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}


signed main()
{
	fio
	int c[3]={300000,200000,100000};
	inp(a) inp(b)
	if(a==1 && b==1)
	{
		cout<<1000000;
	}
	else
	{
		int ans=0;
		if(a<=3)
			ans+=c[a-1];
		if(b<=3)
			ans+=c[b-1];
		cout<<ans;
	}
	cout<<'\n';
	printclock;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string disp(bool x){
    return x ? "Yes" : "No";
}

int main(){
    string s; cin >> s;
    int q; cin >> q;
    
    rep(i,q){
        string x; cin >> x;
        
        if(x == "replace"){
            int a,b; cin >> a >> b;
            string p; cin >> p;
            
            s = s.replace(a,b-a+1,p);
        }
        
        if(x == "reverse"){
            int a,b; cin >> a >> b;
            reverse(s.begin()+a,s.begin()+b+1);
        }
        
        if(x == "print"){
            int a,b; cin >> a >> b;
            cout << s.substr(a,b-a+1) << endl;;
        }
    
    }
}
    
    







Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(N==i*j){
                cout<<"Yes"<<endl;return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug = false;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

int main()
{
  int n;

  cin >> n;

  vector<int> t(n), a(n);

  rep (i, 0, n) cin >> t[i];
  rep (i, 0, n) cin >> a[i];

  vector<bool> u(n), b(n);

  u[0] = true;
  rep(i, 1, n) u[i] = (t[i] != t[i - 1]);

  b[n - 1] = true;
  rep(i, 1, n) b[n - i - 1] = (a[n - i - 1] != a[n - i]);

  if (debug) {
    rep(i, 0, n) cout << u[i];
    cout << endl;

    rep(i, 0, n) cout << b[i];
    cout << endl;
  }

  ll ans = 1, mod = 1000000007;
  bool okay = true;

  rep (i, 0, n) {
    if ((b[i] && u[i] && a[i] == t[i]) ||
        (b[i] && !u[i] && a[i] <= t[i]) ||
        (!b[i] && u[i] && a[i] >= t[i])) {
      continue;
    } else if (!b[i] && !u[i]) {
      ans = (ans * (ll)min(a[i], t[i])) % mod;
    } else {
      if (debug) {
        cout << i << endl;
      }
      okay = false;
    }
  }

  cout << (okay?ans:0) << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){

	int n,i,j,N;
	char M;
	scanf("%d",&n);
	
	int x[4][13];
	
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			x[i][j]=0;
		}
	}
	
	for(i=0;i<n;i++){
	
		scanf(" %c %d",&M,&N);
	
		if(M=='S'){x[0][N-1]=1;}
		if(M=='H'){x[1][N-1]=1;}
		if(M=='C'){x[2][N-1]=1;}
		if(M=='D'){x[3][N-1]=1;}
	}
	
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(x[i][j]==0 &&i==0){printf("S %d\n",j+1);}
			if(x[i][j]==0 &&i==1){printf("H %d\n",j+1);}
			if(x[i][j]==0 &&i==2){printf("C %d\n",j+1);}
			if(x[i][j]==0 &&i==3){printf("D %d\n",j+1);}
		}
	}
	
	return 0;

}

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

int main()
{
    int n,c=0;
    cin>>n;
    for (int i=1; i<=9; i++)
    {

            if(n%i==0&&n/i<=9)
            {
                c++;

            }

    }

    if(c>0)
        cout<< "Yes"<<endl;
        else
            cout << "No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1,dy = y2 - y1;
    cout << x2 - dy << ' ' << y2 + dx << ' ' << x1 - dy << ' ' << y1 + dx << endl;
}

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

int main() {
  int64_t N;
  cin >> N;
  vector<long double> X(N);
  vector<long double> Y(N);
  
  for(int i=0; i<N; i++){
    cin >> X.at(i) >> Y.at(i);
  }
  
  long double sum=0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      sum += powl((X.at(i)-X.at(j))*(X.at(i)-X.at(j))+(Y.at(i)-Y.at(j))*(Y.at(i)-Y.at(j)), 0.5);
    }
  }
  
  cout << fixed << setprecision(10) << (long double)2*sum/(long double)N << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

map<pair<string, string>, long long> func(string s, int N){
    map<pair<string, string>, long long> mp;
    for(int i=0; i<(1<<N); i++){
        string s0 = "";
        string s1 = "";
        for(int j=0; j<N; j++){
            if(i & (1<<j)) s0 += s[j];
            else s1 += s[j];
        }
        mp[make_pair(s0, s1)]++;
    }
    return mp;
}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;

    string s0 = S.substr(0, N);
    string s1 = S.substr(N, N);
    reverse(s1.begin(), s1.end());

    map<pair<string, string>, long long> mp0 = func(s0, N);
    map<pair<string, string>, long long> mp1 = func(s1, N);

    long long ans = 0;
    for(auto x : mp0){
        auto ss = x.first;
        long long cnt = x.second;
        ans += cnt * mp1[ss];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 108288
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int n, ans = 1;
	cin >> n;
	while (ans * 2 <= n) {
		ans *= 2;
	}
	cout << ans << endl;

	return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

typedef pair<LL,LL> P;
LL check(vector<P>& v){
    int n = v.size();
    LL res=1e18;
    REP(bit,1<<n){
        LL a=1e18,b=0,c=1e18,d=0;
        REP(i,n){
            LL x = v[i].fi;
            LL y = v[i].se;
            if((bit>>i)&1)swap(x,y);
            chmax(b,x);
            chmax(d,y);
            chmin(a,x);
            chmin(c,y);
        }
        chmin(res,(b-a)*(d-c));
    }
    return res;
}

unsigned yy=1145141919;
inline unsigned xorshift(){yy=yy^(yy<<13);yy=yy^(yy>>17);return yy=yy^(yy<<5);}
#define MASK 65535
inline int randInt(){return (int) (xorshift()&MASK);}
inline double randDouble(){return (xorshift()&MASK) /(double)MASK;}

int main(){    
    while(1){
        int N;
        DEBUG N=randInt()%4+2;
        else
            cin>>N;
        
        vector<P> x(N);
        LL bottom=1e12,top=0;
        REP(i,N){
            LL a,b;
            DEBUG a=randInt()%20+1,b=randInt()%20+1;
            else  cin>>a>>b;
            x[i]=minmax(a,b);
            chmin(bottom,x[i].fi);
            chmax(top,x[i].se);
        }
        sort(ALL(x));

        LL res;
        {
            LL latte=1e12,malta=0;
            REP(i,N)chmin(latte,x[i].se);
            REP(i,N)chmax(malta,x[i].fi);
            res=(top-latte)*(malta-bottom);
        }
        {
            set<P> s;
            REP(i,N)s.insert(P(x[i].fi,i));
            while(s.begin()->se>=0){
                LL nxt=x[s.begin()->se].se;
                chmin(res,(top-bottom)*(s.rbegin()->fi-s.begin()->fi));
                s.erase(*s.begin());
                s.insert(P(nxt,-1));
            }
            chmin(res,(top-bottom)*(s.rbegin()->fi-s.begin()->fi));

        }
    
        DEBUG {
            if(res==check(x))continue;
            else {
                REP(i,N){
                    cout<<x[i].fi<<" "<<x[i].se<<endl;
                }
                cout<<check(x)<<endl;
            }
        }
        cout<<res<<endl;
        return 0;
    }
    return 0;
}


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

int main() {
  string a, b;
  cin >> a >> b;
  if (a.size() > b.size()) {
    cout << "GREATER" << endl;
  }
  else if (a.size() < b.size()) {
    cout << "LESS" << endl;
  }
  else {
    if (a > b) {
      cout << "GREATER" << endl;
    }
    else if (a < b) {
      cout << "LESS" << endl;
    }
    else {
      cout << "EQUAL" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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


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

  int h, w;
	cin >> h >> w;

	vector<vector<char>> s(h, vector<char>(w));
	rep(i, h) rep(j, w) {
		cin >> s[i][j];
	}

	vector<vector<int>> t(h, vector<int>(w,0));
	rep(k, h + w - 1) rep(i, k+1) {
		int j = k - i, tij = INF;
		if (i >= h || i < 0 || j >= w || j < 0) continue;

		if (i == 0 && j == 0) {
			t[0][0] = s[0][0] == '.' ? 0 : 1;
			continue;
		}

		if (i - 1 >= 0) {
			if (s[i][j] == '#' && s[i - 1][j] == '.') chmin(tij, t[i - 1][j] + 1);
			else {
				chmin(tij, t[i - 1][j]);
			};
		}

		if (j - 1 >= 0){
			if (s[i][j] == '#' && s[i][j - 1] == '.') chmin(tij, t[i][j - 1] + 1);
			else {
				chmin(tij, t[i][j-1]);
			}
		}
		t[i][j] = tij;
	}

	cout << t[h-1][w-1] << endl;
}


Measured memory_bytes: 384