akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};


int main(void){
	int x;
	scanf("%d",&x);
	printf("%d\n",x^1);
	return 0;
}


Measured memory_bytes: 3812
def main():

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

    def gcd(a, b):
        if a > b: a, b = b, a
        if a == 0: return b
        return gcd(b%a, a)

    g = gcd(A, B)
    p = A // g
    q = B // g
    # print(g, p, q)
    return int(p * min(N, B-1) // q)



if __name__ == '__main__':
    print(main())


Measured memory_bytes: 61872
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 200006;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int area = a * b;
    area -= a;
    area -= b;
    cout << area + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int check(int n) {
    bool e = 0, f = 0, g = 0;
    while (n > 0) {
        if (n % 10 == 7) e = 1;
        else if (n % 10 == 5) f = 1;
        else if (n % 10 == 3) g = 1;
        n /= 10;
    }
    if (e && f && g) return 1;
    else return 0;
}
int main() {
    int n, m = 0, ans = 0;
    cin >> n;
    queue<int> q;
    q.push(3); q.push(5); q.push(7);
    while (m <= n) {
        m = q.front(); q.pop();
        q.push(m * 10 + 3);
        q.push(m * 10 + 5);
        q.push(m * 10 + 7);
        if (check(m)) ans++;
    }
    cout << ans-check(m) << endl;

}

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

int main(){
  int x,n;
  cin>>x>>n;
  vector<int> p(101);
  rep(i,n){
    int q;
    cin>>q;
    p[q]=1;
  }
  int res=101;
  int res2=0;
  for(int i=x;i<=100;i++){
    if(p[i]==0){
      res=i;
      break;
    }
  }
  for(int i=x;i>=0;i--){
    if(p[i]==0){
      res2=i;
      break;
    }
  }
  if(res-x>=x-res2) cout<<res2<<endl;
  else cout<<res<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
 
  if (N % 500 == 0)
    cout << "Yes" << endl;
  else if ( (N % 500) < A )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
    int N,M,X;
    cin >> N >> M >> X;
    int a[110]={0};
    for (int i=0;i<M;i++){
	int c;
	cin >> c;
	a[c]++;
    }

    int cnt=0;
    for (int i=X;i<N;i++){
	cnt+=a[i];
    }
    int res=cnt;

    cnt=0;
    for (int i=X;i>0;i--){
	cnt+=a[i];
    }
    res=min(res,cnt);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

ll n,k; 
vector<ll> a;

//任意の丸太の長さをd以下とできるか？
bool C(ll d){
    ll cnt=0;
    rep(i,n) cnt+=(a[i]-1)/d;
    return k>=cnt;
}

int main(){
    cin >> n >> k;
    rep(i,n){ll aa; cin >> aa; a.push_back(aa);}
    ll ub=10000000000LL,lb=1; //解の範囲は(lb,ub]
    while(ub-lb>1){
        ll mid=(ub+lb)/2;
        //cout << lb << " " << ub << " " << mid << endl;
        if(C(mid)) ub=mid;
        else lb=mid;
    }
    if(C(ub-1)) cout << ub-1 << endl;
    else cout << ub << endl;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(3,0);
    vector<bool> b(3,false);
    bool flag = false;
    for(int i = 0; i < m; i++){
        int c,d;
        cin >> c >> d;
        if(a[c - 1] != d && b[c - 1] == true)
        flag = true;
        a[c - 1] = d;
        b[c - 1] = true;
    }
    if(flag){
        cout << -1 << endl;
        return 0;
    }
    if(n == 1 && a[0] == 0){
        cout << 0 << endl;
        return 0;
    }
    if(n != 1 && a[0] == 0 ){
        if(!b[0])
        a[0] = 1;
        else
        {
            cout << -1 << endl;
            return 0;
        }
        
    }
    int k = pow(10, n - 1) - 1;
    int l = pow(10, n);
    for(int i = k; i < l; i++){
        bool ans = true;
        int op = i;
        for(int i = 0; i < n; i++){
            if(op % 10 != a[n - 1 - i])
                ans = false;
            op /= 10;
        }
        if(ans){
        cout << i << endl;
        return 0;
        }
    }
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N,M;
  ll L;
  cin >> N >> M >> L;


  vector<vector<ll>> dist(N, vector<ll>(N, MAX));
  vector<vector<ll>> dist_after(N, vector<ll>(N, MAX));

  for(int i = 0; i < M; i++){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;

    dist[a][b] = c;
    dist[b][a] = c;
  }


  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(dist[i][j] <= L){
        dist_after[i][j] = 1;
      }
    }
  }

  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist_after[i][j] = min(dist_after[i][j], dist_after[i][k] + dist_after[k][j]);
      }
    }
  }

  int Q; cin >> Q;
  cerr << "Q: " << Q << endl;
  while(Q--){
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    tmp1--; tmp2--;

    ll ans = dist_after[tmp1][tmp2];
    if(ans == MAX){
      cout << -1 << endl;
    } else { 
      cout << ans - 1 << endl;
    }
  }



}


Measured memory_bytes: 5032
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	sum := 0
	if a < b {
		sum += b
		b--
	} else {
		sum += a
		a--
	}
	if a < b {
		sum += b
		b--
	} else {
		sum += a
		a--
	}
	fmt.Println(sum)
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    int n; cin >> n;
    if (n == 0) cout << 1 << endl;
    else if (n == 1) cout << 2 << endl;
    else if (n == 2) cout << 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int ans = 0;
        for (int i = 0; i < 3; i++) {
            if (str.charAt(i) == 'o') {
                ans++;
            }
        }
        System.out.println(ans * 100 + 700);

    }
}

Measured memory_bytes: 23124
#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 repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

class UnionFind {
public:
	vector<int> par, rank;

	void init(int n) {
		par = vector<int>(n);
		rank = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	// 木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}

	// xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind uf1, uf2;
	uf1.init(N), uf2.init(N);

	rep(i, K) {
		int p, q;
		cin >> p >> q;
		p--, q--;
		uf1.unite(p, q);
	}
	rep(i, L) {
		int p, q;
		cin >> p >> q;
		p--, q--;
		uf2.unite(p, q);
	}
	vector<P> g(N);
	map<P, int> m;
	rep(i, N) {
		g[i] = mp(uf1.find(i), uf2.find(i));
		if (m.count(g[i]) == 0) {
			m[g[i]] = 1;
		}
		else {
			m[g[i]]++;
		}
	}
	rep(i, N) {
		cout << m[g[i]];
		if (i != N - 1) {
			cout << ' ';
		}
		else {
			cout << endl;
		}
	}

	return 0;
}

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

using ll = long long;

int N, M;
vector<vector<int>> A;
vector<int> s;

int solve() {
	vector<int> cnt(M);
	for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) {
		if (s[A[i][j]]) {
			cnt[A[i][j]]++; break;
		}
	}
	auto r = max_element(cnt.begin(), cnt.end());
	s[r - cnt.begin()]--;
	return *r;
}

int main() {
	cin >> N >> M;
	int res = N;
	A.resize(N, vector<int>(M));
	s.resize(M, 1);
	for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) cin >> A[i][j], A[i][j]--;
	for (int i = 0; i < M-1; i++) {
		res = min(res, solve());
	}
	cout << res << endl;
}

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

const int mxN = 100, mxW =1e9;
long long wt[mxN],v[mxN] ,n,W;

const long long inf =1e18l+7;

int main(){
    cin >> n >> W;
    long long sm = 0;
    for(int i=0 ; i< n ; ++i){
        cin  >> wt[i] >> v[i];
        sm+=v[i];
    } 
    
    vector<long long> dp(sm+1 , inf);
    dp[0]=0;
    for(int i = 0 ; i< n ; ++i){
        for(long long va = sm-v[i] ; va>=0 ; --va){
            dp[va+v[i]] = min(dp[va+v[i]] , dp[va]+wt[i]);
        }
    }

    long long res = 0 ;
    for(long long i=0 ;i< sm+1 ; ++i){
        if(dp[i]<=W){
            res = max((long long)i,res);
        }
    }
    cout <<res;
    
       
}

Measured memory_bytes: 4060
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib> 
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
#define For(i, m, n) for(int i = m;i < n;i++)

using namespace std;


int main(){
    string s;
    cin >> s;
    int count = 0;

    for(int i = 0; i < s.size() -1 ; i++){
        if(s[i] == s[i + 1]){
            if(s[i + 1] == '0'){
                s[i+1] = '1';
                count++;
            } else {
                s[i + 1] = '0';
                count++;
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 512
n, k = map(int,input().split())

mod = 10**9+7
MOD = 10 ** 9 + 7
MAX = 2*n+1


fact = [1] * (MAX + 1)  # i!
finv = [1] * (MAX + 1)  # (i!)^{-1}
iinv = [1] * (MAX + 1)  # i^{-1}

for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD


def c(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD


ans = 0
for m in range(1,min(n-1,k)+1):
    # print((c(n,m) * c(n-1,m)) % mod)
    ans += (c(n,m)%mod * c(n-1,m)%mod) % mod

if k == 1:
    print(ans % mod)

else:
    print((ans+1) % mod)




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

typedef long long ll;

ll mod = 1e9 + 7;

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

    ll accum = 0;
    if(abs(n-m) < 2){
        accum = 1;
        for(int i = 2; i <= n; i++){
            accum *= i;
            accum %= mod;
        }
        for(int i = 2; i <= m; i++){
            accum *= i;
            accum %= mod;
        }
    }

    if(n == m)  accum = (2 * accum) % mod;

    cout << accum << endl;

    return 0;
}

Measured memory_bytes: 256
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

c = Array.new(N, 0)
A.each{|a| c[a] += 1}
ans = 0
if N.even? then
  if c.select.with_index{|a, i| i.odd?}.all?{|a| a == 2} then
    ans = pow(2, N/2, MOD)
  end
else
  c[0] += 1
  if c.select.with_index{|a, i| i.even?}.all?{|a| a == 2} then
    ans = pow(2, N/2, MOD)
  end
end

puts ans


Measured memory_bytes: 9876
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

// kの値を超えるために必要なx2乗算の回数を返す
fn count_2x_multiplication(v: u64, k: u64) -> u64 {
    let mut vmut = v;
    let mut count = 1_u64;

    loop {
        vmut *= 2;
        if vmut >= k { break; }

        count += 1;
    }

    return count;
}

fn main() {
    let nk: Vec<u64> = read_vec();
    let n = nk[0] + 1_u64;
    let k = nk[1];
    let mut p: f64 = 0.0;
    let n_inv = 1.0 / nk[0] as f64; // 出目の確率

    for i in 1..n
    {
        // そもそも出目がk以上である場合
        if i >= k {
            p += n_inv;
            continue;
        }

        // k未満の出目の場合はコイン試行
        let count = count_2x_multiplication(i, k);
        p += n_inv * 0.5_f64.powf(count as f64);
    }

    println!("{}", p);
}


Measured memory_bytes: 4352
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] str1Ary = str.split(" ");
		int W = Integer.parseInt(str1Ary[0]);
		int H = Integer.parseInt(str1Ary[1]);
		int x = Integer.parseInt(str1Ary[2]);
		int y = Integer.parseInt(str1Ary[3]);
		int r = Integer.parseInt(str1Ary[4]);
		if((W >= x + r) && (H >= y + r) && (0 <= x - r) && (0 <= y - r)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

    for (int i = 1;; i++) {
        int d = i * (i - 1) / 2;
        if (d == N) {
            int D = i;
            int c = 1;
            vector<vector<int>> ans(D, vector<int>());
            for (int j = 0; j < D; j++) {
                for (int k = j + 1; k < D; k++) {
                    ans[j].push_back(c);
                    ans[k].push_back(c);
                    c++;
                }
            }
            cout << "Yes" << endl;
            cout << D << endl;
            for (int j = 0; j < D; j++) {
                cout << ans[j].size() << " ";
                for (int k = 0; k < ans[j].size(); k++) {
                    cout << ans[j][k] << " ";
                }
                cout << endl;
            }
            return 0;
        }
        if (d > N) break;
    }

    cout << "No" << endl;

}













































Measured memory_bytes: 2304
W,H,x,y=gets.split.map(&:to_f)
xm=W/2.0
ym=H/2.0
if x==xm && y==ym
  puts "#{sprintf("%.10f", H*W/2)} #{1}"
else
  puts "#{sprintf("%.10f", H*W/2)} #{0}"
end

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<cmath>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	vector<int>b(n);
	b = a;
	sort(all(a));
	reverse(all(a));
	rep(i, n) {
		if (b[i] == a[0]) {
			cout << a[1] << endl;
		}
		else {
			cout << a[0] << endl;
		}
	}
	
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int i = 1;
		int x;
		while (i <= n) {
			x = i;
			while (true){
				if (x % 3 == 0) {
					System.out.printf(" %d", i);
					break;
				}
				while (x >= 1) {
					if (x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
				break;
			}
			i++;
		}
		System.out.printf("\n");
	}
}



Measured memory_bytes: 38636
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 165, task, 2020/05/02
//ms,
/*
*/

int main(void){
  int N, M, Q;
  vector<int> a(50);
  vector<int> b(50);
  vector<int> c(50);
  vector<int> d(50);

  vector<int> A(10);
  int ans=0;
  int tmp_score;

  //input, initialize
  cin >>N >>M >>Q;
  for(int i=0;i<Q;i++) cin >>a[i] >>b[i] >>c[i] >>d[i];
  for(int i=0;i<N;i++) A.at(i)=1;

  while(true){
    //for curent A, culculate score
    tmp_score=0;
    for(int i=0;i<Q;i++){
      if(A[b[i]-1]-A[a[i]-1]==c[i]){
        tmp_score += d[i];
      }
    }
    ans = max(ans, tmp_score);

    //renew A
    if(A[N-1]!=M) A[N-1]++;
    else{
      int counter=N;
      while(counter){
        if(A[counter-1] !=M){
          A[counter-1]++;
          for(int i=counter;i<N;i++){
            A[i] = A[counter-1];
          }
          goto NEXT_LOOP;
        }else{counter--;}
      }
      goto FIN;
    }
    NEXT_LOOP:continue;
  }

  FIN:cout <<ans <<endl;
  return 0;
}
/*
数列AはA_all={1,2,3,4,5,6,7,8,9,10}のうちいくつかを選んだものとみなせる。
bit全探索だ。
ごめん、間違いだ。重複あるじゃん。
いやでも、制約が強いから全探索で多分通るのは間違いない。
*/


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

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

using Graph = vector<vector<char>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  ll N,K,R,S,P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  map<char,char> ma;
  ma['r'] = 'p';
  ma['s'] = 'r';
  ma['p'] = 's';

  map<char,ll> score;
  score['r'] = R;
  score['s'] = S;
  score['p'] = P;

  Graph G(K);//G[mod]はT[i%K]の集合
  for(int i = 0;i<N;i++){
    G[i%K].push_back(T[i]);
  }
 
  ll ans = 0;

  for(int i = 0;i<K;i++){
    char c = '#';//前回の手
    for(int j = 0;j<G[i].size();j++){
       if(c != ma[G[i][j]]){//前回の手と今回の勝ち手が異なる
          c = ma[G[i][j]];
          ans += score[c];
       }
       else if(j != G[i].size()-1){//前回の手と今回の勝ち手が同じ時　次回の勝ち手以外
          for(auto p : ma){
             auto key = p.first;
             auto value = p.second;
             if(ma[key] != ma[G[i][j+1]] && ma[key] != c){
               c = value;
               break;
             }
          }
       }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a>0) cout << "Positive" << endl;
  else if (b<0){
    if ((b-a)%2 != 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }
  else if (a<=0&&b>=0) cout << "Zero" << endl;
}


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

int main(){
	ll s,c; cin>>s>>c;
	if(s>=c) {cout<<c/2<<endl; return 0;}
	ll r=min(s,c/2);
	if(c-2*r>=4) r+=(c-2*r)/4;
	cout<<r<<endl;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define For(i,n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
int main()
{





int i=0;
 int h,a;
 cin>>h>>a;
 while(h>0)
 
 {h=h-a;
  i++;
     
 }



cout<<i;




return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		char[] s_chars = s.toCharArray();
        Arrays.sort(s_chars);
        String s_asc = new String(s_chars);
		
		String t = in.next();
		char[] t_chars = t.toCharArray();
		Arrays.sort(t_chars);
		String t_asc = new String(t_chars);
		String t_desc = new StringBuilder(t_asc).reverse().toString();
		
		if (s_asc.compareTo(t_desc) < 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


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

int main(){
    int N;
    int H[1000];

    cin >> N;
    for (int i = 0; i < N; ++i ) cin >> H[i];
    
    int max_h = H[0];
    int c = 1;

    for (int i = 1; i < N; ++i) {
        if (max_h <= H[i]) {
            ++c;
            max_h = H[i];
        }
    
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
p=list(map(int,input().split()))
pa = []
cnt = 0
for i in range(N):
    if i+1 == p[i]:
        cnt +=1
    elif i+1 != p[i] and cnt>0:
        pa.append(cnt)
        cnt =0
if cnt >0:
    pa.append(cnt)
cnt = 0
for cn in pa:
    cnt += cn//2+cn%2
print(cnt)


Measured memory_bytes: 20652
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    string S; cin >> S;
    int K; cin >> K;
    rep(i,S.size()){
        if(i<S.size()-1){
            if(26-(S[i]-'a')<=K && S[i]!='a'){
                K-=(26-(S[i]-'a'));
                S[i]='a';
            }
        }
        else S[i]=(char)'a'+(S[i]-'a'+K)%26;
    }
    cout << S << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
//#define int long long
signed main() {
	/*
	int a, b, c;
	cin >> a >> b >> c;
	int sum1 = a * 10 + b + c;
	int sum2 = a + b * 10 + c;
	if (sum1 > sum2) {
		cout << sum1 << endl;
	}
	else {
		cout << sum2 << endl;
	}
	return 0;int>
	*/
	vector<int>v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	cout << v[2] * 10 + v[0] + v[1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
 int n,k,up,down ;
 string s;
 cin >> s;
   up=0;down=0;
   if(s.at(0)=='1')
   {
     if(s.at(1)>'2')
       up=1;
   }
   if(s.at(0)=='0'&&s.at(1)=='0')
     up=1;
   if(s.at(0)>='2')
     up=1;
    if(s.at(2)>='2')
     down=1;
     if(s.at(2)=='1')
   {
     if(s.at(3)>'2')
       down=1;
   }
    if(s.at(2)=='0'&&s.at(3)=='0')
     down=1;
   if(up==0&&down==0)
     cout << "AMBIGUOUS" << endl;
    if(up==0&&down==1)
     cout << "MMYY" << endl;

    if(up==1&&down==0)
     cout << "YYMM" << endl;


    if(up==1&&down==1)
     cout << "NA" << endl;
       
   
 }

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace cswork
{
    class Program
    {
        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);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

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

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

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            long X = cin.nextLong();

            long yen500 = X / 500;
            X %= 500;
            long yen5 = X / 5;
            X %= 5;

            Console.WriteLine(yen500 * 1000 + yen5 * 5);
        }

    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> pint;
const int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
pint Start, Goal;
int W, H;
bool range_out(int x, int y){
    return x < 0 || y < 0 || W <= x || H <= y;
}
int solve(mat fld, pint now, int turn){
    if(turn >= 10) return INF;
    int res = INF;
    //cout << "now" << now.first << ' ' << now.second << endl;
    rep(i, 4){
        int nx = now.first + dx[i], ny = now.second + dy[i];
        if(range_out(nx, ny) || fld[ny][nx] == 1) continue;
        mat temp = fld;
        bool out = false;
        while(true){
            if(range_out(nx, ny)){
                out = true;
                break;
            }
            if(fld[ny][nx] == 1){
                temp[ny][nx] = 0;
                nx -= dx[i]; ny -= dy[i];
                break;
            }
            if(fld[ny][nx] == 3) return turn + 1;
            nx += dx[i]; ny += dy[i];
        }
        //cout << nx << ' ' << ny << endl;
        if(!out) res = min(res, solve(temp, pint(nx, ny), turn + 1));
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> W >> H && W){
        mat fld(H, vec(W));
        rep(i, H) rep(j, W){
            cin >> fld[i][j];
            if(fld[i][j] == 2)
              Start = pint(j, i);
            if(fld[i][j] == 3)
                Goal = pint(j, i);
        }
        int ans = solve(fld, Start, 0);
        if(ans == INF || ans > 10) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1356
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

H,W=rl()
a = [rl() for y in range(H)]

ans = []
cnt = 0
for y in range(1,H+1):
    odd = 0
    for x in range(1,W):
        if a[y-1][x-1]%2: odd ^= 1
        if odd == 1:
            cnt += 1
            ans.append([y,x,y,x+1])
    if odd==1:
        a[y-1][W-1] += 1

odd = 0
for y in range(1,H):
    if a[y-1][W-1]%2: odd ^= 1
    if odd == 1:
        cnt += 1
        ans.append([y,W,y+1,W])

print(cnt)
for i in range(cnt):
    print(*ans[i], sep=' ')

Measured memory_bytes: 26428
def conbination_2(n):
  if n <= 1:
    return 0
  else:
    return int(n * (n - 1) / 2)


N = int(input())
A = list(map(int,input().split()))
S = 0
Count = [0] * N

for i in range(N):
  Count[A[i] - 1] += 1
  
for i in range(N):
  S += conbination_2(Count[i])
  
for i in range(N):
  Ans = S - (Count[A[i] - 1] - 1)
  print(Ans)

Measured memory_bytes: 26268
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize
    }
    let mut ans = 1;
    for _ in 0..n {
        if ans + k < ans * 2 {
            ans += k;
        } else {
            ans = ans * 2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
// Created by abhay
#include <bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define allc c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(allc,x) != c.end())
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
const double pi=3.14;
using namespace std;

int main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll r;
	cin>>r;
	cout<<setprecision(6)<<(2*pi*r);
}

Measured memory_bytes: 3772
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine();
        var m = ReadLine();
        var s = new StringBuilder();
        for(int i = 0; i < n.Length; i++)
        {
            s.Append(n[i]);
            if(i < m.Length)
                s.Append(m[i]);
        }
        WriteLine(s.ToString());
    }
}


Measured memory_bytes: 17252
#include<stdio.h>
#define N 100

main(){
  int i,j,a[N],b,n,minj,count=0,c,d;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n-1;i++){
    minj = i;    
    for(j=i;j<n;j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
    if(a[i]!= a[minj]){
    b = a[minj];
    a[minj] = a[i];
    a[i] = b;
    count++;
    }
  }
  
  printf("%d",a[0]);
  for(i=1;i<n;i++){
    printf(" %d",a[i]);
  }
  printf("\n%d\n",count);
  return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> p(n);
	for (auto& e: p) scanf("%d", &e);
	int count{};
	for (int i{1}; i < n - 1; i++)
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]))
			count++;
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 256
#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;
	cout << s.substr(0, 4) << " " << s.substr(4) << endl;
}


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

int A, B;

int main (){
    cin>>A>>B;
    if (A==B) {cout<<"Draw"<<endl;}
    else if (A==1){cout<<"Alice"<<endl;}
    else if (B==1) {cout<<"Bob"<<endl;}
    else if (A>B) {cout<<"Alice"<<endl;}
    else if (A<B) {cout<<"Bob"<<endl;}
    }

Measured memory_bytes: 3580
#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() {
  int n;
  cin >> n;
  vector<int> f(n * 2 + 1);
  for (ll i = 2; i <= 2 * n; i++) {
    if (f[i]) continue;
    // primes.push_back(i);
    if (i >= n) {
      cout << i << endl;
      break;
    }
    f[i] = i;
    for (ll j = i + i; j <= n * 2; j += i)
      if (!f[j]) f[j] = i;
  }
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();

        //double d = Math.toDegrees(Math.atan(2.0 * (x - a * a * b) / (a * a * a)));
        //double d2 = Math.toDegrees(Math.atan((a * b * b) / (2 * x)));

        if(x >= a * a * b / 2) System.out.println(Math.abs(Math.toDegrees(Math.atan(2.0 * (x - a * a * b) / (a * a * a)))));
        else System.out.println(Math.abs(Math.toDegrees(Math.atan((a * b * b) / (2 * x)))));


    }

}


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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;
const int MN = 1'000'000;

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int H, W, M;
    cin >> H >> W >> M;
    map<int, map<int, int>> G;
    int h, w;
    unordered_map<int,int> Hc, Wc;
    int Hmax = 0, Wmax = 0;
    REP(i, 0, M){
        cin >> h >> w;
        assert(h > 0 && h <= H);
        assert(w > 0 && w <= W);
        G[h-1][w-1] = 1;
        Hc[h-1]++;
        Hmax = max(Hmax, Hc[h-1]);
        Wc[w-1]++;
        Wmax = max(Wmax, Wc[w-1]);
    }
    int ans = Hmax + Wmax - 1;
    vector<int> Hcand, Wcand;
    for(auto& item : Hc){
        if(item.second == Hmax) Hcand.push_back(item.first);
    }
    for(auto& item : Wc){
        if(item.second == Wmax) Wcand.push_back(item.first);
    }
    for(auto& h : Hcand){
        for(auto& w : Wcand){
            if(G[h][w] == 0){
                ans++;
                goto fim;
            }
        }
    }
    fim: cout << ans << endl;    
}

Measured memory_bytes: 76712
#include <stdio.h>

int A[105];

int main() {

	int N,D,X;

	scanf("%d",&N);
	scanf("%d %d",&D,&X);

	int i,j;

	for(i=0;i<N;i++){
	scanf("%d",&A[i]);
	}

	int ans=X;

	for(i=0;i<N;i++){
		for(j=1;j<=D;j+=A[i]){
		ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.nextLine().toCharArray();
		if (s[0] == s[s.length - 1]) {
			if (s.length % 2 == 0) {
				System.out.println("First");
			} else {
				System.out.println("Second");
			}
		} else {
			if (s.length % 2 == 0) {
				System.out.println("Second");
			} else {
				System.out.println("First");
			}
		}
	}
}


Measured memory_bytes: 27836
#include <iostream>
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
const int p = 1e9 + 7;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<vector<pair<int,int>>> cond(n+1, vector<pair<int,int>>(3, {-1, n+1}));
    for(int i=0;i<m;i++){
        int l,r,x;
        cin>>l>>r>>x;
        --x;
        cond[r][x].first = max(cond[r][x].first, l);
        cond[r][x].second = min(cond[r][x].second, l);
    }
    vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(n+1, vector<int>(n+1, 0)));
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++){
        if(cond[i][1].first!=-1 || cond[i][2].first!=-1){
            break;
        }
        dp[i][0][0] = 3;
    }
    for(int i=1;i<=n;i++){
        if(cond[i][2].first!=-1){
            break;
        }
        for(int j=1;j<i;j++){
            if(j>=cond[i][0].second){
            continue;
            }
            if(j<cond[i][1].first){
                continue;
            }
            if(j==i-1){
                dp[i][j][0]+=2*dp[i-1][0][0];
                dp[i][j][0]>=p ? dp[i][j][0]-=p : 0;
                for(int l=1;l<i-1;l++){
                    dp[i][j][0]+=dp[i-1][l][0];
                    dp[i][j][0]>=p ? dp[i][j][0]-=p : 0;
                }
            }
            else{
                dp[i][j][0] = dp[i-1][j][0];
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<i;j++){
            for(int k=1;k<j;k++){
                dp[i][j][k] = 0;
                if(j>=cond[i][0].second){
                    continue;
                }
                if(j<cond[i][1].first){
                    continue;
                }
                if(k>=cond[i][1].second){
                    continue;
                }
                if(k<cond[i][2].first){
                    continue;
                }
                if(j==i-1){
                    for(int l=0;l<i-1;l++){
                        if(l==k){
                            continue;
                        }
                        dp[i][j][k]+=dp[i-1][max(k,l)][min(k,l)];
                        dp[i][j][k] >= p ? dp[i][j][k]-=p : 0; 
                    }
                }
                else{
                    dp[i][j][k]=dp[i-1][j][k];
                }
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            ans+=dp[n][i][j];
            ans>=p ? ans-=p : 0;
        }
    }
    ans+=dp[n][0][0];
    ans>=p ? ans-=p : ans;
    cout<<ans<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

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

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

    // all the code goes here
    int n;cin>>n;
    vector<int> a(n);
    for(int &i : a)
    {
        cin>>i;
    }

    ll dp[n][n];
    for(int l = n-1; l >= 0; l--)
    {
        for(int r = l; r < n; r++)
        {
            if(l == r)
                dp[l][r] = a[l];
            else
            {
                dp[l][r] = max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
            }
            
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}

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

using namespace std;

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

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

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<int> a;
vector<int> x;

int main(void){
  int n;
  int ans = 0;
  int r = 0;

  cin >> n;
  a.resize(n);
  rep(i,n-1) cin >> a[i];
  r = a[0];
  rep(i,n-1){
    ans += min(r, a[i]);
    r = a[i];
  }
  ans += r;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // ll t;
    ll t=1;
    // cin >> t;
    while(t--){
        int n; cin >> n;
        int d[n];
        for(int i=0;i<n;i++){
            cin >> d[i];
        }
        ll ans=0;
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                ans += d[i]*d[j];
            }
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc054b()
}

fun abc054b() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val image = Array<String>(n) { "" }
    val template = Array<String>(m) { "" }
    repeat(n) { image[it] = readLine()!! }
    repeat(m) { template[it] = readLine()!! }
    for (i in 0..n - m) {
        for (j in 0..n-m) {
            var h = 0
            var w = 0
            var count = 0
            while (image[i + h][j + w] == template[h][w]) {
                count++
                w++
                if (w == m) {
                    w = 0
                    h++
                    if (h == m) {
                        break
                    }
                }
            }
            if (count == m * m) {
                println("Yes")
                return
            }
        }
    }
    println("No")
}

Measured memory_bytes: 36008
#include <bits/stdc++.h>
using namespace std;
using Int = int64_t;
using Float = double;

int main() {
  Int N, K;
  cin >> N >> K;

  auto X = N;
  if (X == K) {
    cout << 0 << endl;
  } else if (X > K) {
    X = X - (Int((Float)(X-K)/K) + 10) * K;
    while (X < K) {
      X += K;
    }
    cout << min({X, X-K, K-(X-K)}) << endl;
  } else {
  	cout << min(X, K-X) << endl;  
  }
    
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e9;
char s1[MaxN];
char s2[MaxN];

int main() {
	while(~scanf("%s %s", s1, s2)) {
		int l1 = strlen(s1);
		int l2 = strlen(s2);
		bool flag = 0;
		if(l2 > l1) {
			flag = 1;
			puts("LESS");
		}
		else if(l1 > l2) {
			flag = 1;
			puts("GREATER");
		}
		else {
			for(int i = 0; i < l1; i++) {
				if(s1[i] > s2[i]) {
					flag = 1;
					puts("GREATER");
					break;
				}
				else if(s1[i] < s2[i]) {
					flag = 1;
					puts("LESS");
					break;
				}
				else continue;
			}
		}
		if(!flag) puts("EQUAL");
	}
	return 0;
}

Measured memory_bytes: 2176