akhauriyash/Code-Regression huggingface dataset:
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var s = next(1);
  var map = xArray(0,2020);
  var x = 0, ans = 0, k = 1;
  map[0] = 1;
  for(var i = s.length; i--;){
    x += +s[i] * k;
    x %= 2019;
    k = k*10%2019;
    ans += map[x]++;
  }
  return ans;
}


Measured memory_bytes: 32640
import java.util.*;

public class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int T = sc.nextInt();
		int[] a = new int[T];
		for(int i = 0; i < T; i++) a[i] = sc.nextInt();
		sc.close();
		int max = a[0];
		for(int i = 1; i < T; i++)
		{
			if(a[i] > max) max = a[i];
		}
		int result = 0;
		if(2 * max > K + 1)
		{
			result = 2 * max - K - 1;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 9936
// ------------------------------------
// Date:2018/ 3/25
// Problem:_ _ _ b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N, D, X);
  vector< int > a(N);
  REP(i, N)
    cin >> a[i];

  ll ans = X;
  FOR(i, 1, D + 1) {
    REP(j, N) {
      if (i == 1) ans++;
      else {
	if ((i - 1) % a[j] == 0) ans++;
      }
    }
  }

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



Measured memory_bytes: 256
def main():
    n=int(input())
    A=tuple(map(int,input().split()))
    ans=1000
    num=0
    for i in range(n-1):
        ans+=num*A[i]
        num=0
        if A[i]<A[i+1]:
            num=ans//A[i]
            ans%=A[i]
    ans+=num*A[-1]
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 61964
#include <stdio.h>

int main(void){
	int n, a, b, c, x, y, count, i, j;
	while(1){
		scanf("%d%d%d%d%d",&n,&a,&b,&c,&x);
		if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
			break;
		count = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&y);
			while(x != y && count <= 10000){
				x = (a * x + b) % c;
				count++;
			}
			if(i != n - 1){
				x = (a * x + b) % c;
				count++;
			}
		}
		if(count > 10000)
			printf("-1\n");
		else
			printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 1040
/*
    Created by Rahul Goel.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*******************************************************************************/
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template < typename T, typename... Args >
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%MOD + MOD)%MOD; }
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template< typename T, typename... Args >
T mod_prod(T a, Args... args) { return (a * mod_prod(args...))%MOD; }
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
    Code begins after this.
*/

ll solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -LINF;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
    return 0;
}

signed main() {
    fastio;

    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N=1e5+50;
ll s[N];
ll a[N];
int main()
{
	ll a,b,n;cin>>a>>b>>n;
	if(b > n)
	{
		cout<<floor((1ll)*a*n/b);
	}
	else
	{
		
		cout << floor((1ll)*a*(b-1)/b);
	}
    return 0;
}


Measured memory_bytes: 3772
S = input()
n = len(S)

prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    
if cand:
    print(min(cand))
else:
    print(n)

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;typedef vector<int> vi;typedef vector<ll> vll;
typedef pair<int,int> ii;typedef map<int,int> mii;
inline void rvi(vi &v, int n){int temp; rep(i,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll &v, int n){ll temp;rep(i,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline vll prefixsum(vi &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
void solve();int main(){ios;solve();return 0;}
//--------SOLVE--------------------------------------------------------------------
int dp[102][100005];
void solve()
{
	int n,we;cin>>n>>we;
	vi w(n+1),v(n+1);
	ll sum=0;
	rep(i,n)
	{
		cin>>w[i+1]>>v[i+1];
		sum+=v[i+1];
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=sum;j++)
		{
			dp[i][j]=inf;
		}
	}
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=sum;j++)
		{
			if(j<v[i])
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
		}
	}
	ll ans=-1;
	for(int j=0;j<=sum;j++)
	{
		if(dp[n][j]!=inf && dp[n][j]<=we)
		{
			if(j>ans) ans=j;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 39680
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
  ($line:expr, $name:ident, $t:tt) => {
    let $name = value!($line, $t);
  };
}

macro_rules! values_def {
  ($lines:expr, $n:expr, $name:ident, $t:tt) => {
    let $name = {
      let mut vec = Vec::new();
      for i in 0..$n {
        let mut next = $lines.next().unwrap().split_whitespace();
        vec.push(value!(next, $t));
      }
      vec
    };
  };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn gcd(a: i64, b: i64) -> i64 {
  if b == 0 {
    a
  } else {
    gcd(b, a % b)
  }
}

fn main() {
  let mut input = String::new();
  io::stdin().read_to_string(&mut input).unwrap();
  let output = solve(input.trim().to_string());
  println!("{}", output);
}

fn solve(input: String) -> String {
  input!(input=>(n:usize)(list:[i64]));
  let mut res = list[0];
  for x in list {
    res = gcd(res, x);
  }
  res.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "4\n2 10 8 40\n" => "2\n",
    test2: "4\n5 13 8 1000000000\n" => "1\n",
    test3: "3\n1000000000 1000000000 1000000000\n" => "1000000000\n",
}


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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;
ll gcd(ll a,ll b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans=0;
    ll gc;
    gc=c*d/gcd(c,d);
    if(a%c==0){
        ans-=1;
    }
    
    if(a%d==0){
        ans-=1;
    }
        
    if(a%gc==0){
        ans+=1;
    }
        
    ans+=(b-a+1)-(b/c+b/d-a/c-a/d-b/gc+a/gc);
    cc(ans);
}

Measured memory_bytes: 256
/*
    Those who cannot remember the past are condemned to repeat it.
                                            - Dynamic Programming
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int[] a = new int[n];

        st = new StringTokenizer(br.readLine());
        for(int i=0 ; i<n ; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(a);

        long sum = 0;
        for(int i=0 ; i<n-k ; i++) {
            sum += a[i];
        }

        pw.println(sum);
        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


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

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

    bool exsits[26] = {};
    for (int i = 0; i < S.size(); i++)
    {
        exsits[S[i] - 'a'] = true;
    }

    bool nothing = true;
    for (int i = 0; i < 26; i++)
    {
        if (!exsits[i])
        {
            cout << (char)('a' + i) << endl;
            nothing = false;
            break;
        }
    }

    if (nothing)
        cout << "None" << endl;

    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>

using namespace std;


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */
#define MAX_M	1001
#define DP_SIZE	1024 * 5
#define INF		0x7fffffff

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N; 				// 宝箱の個数
int M;				// キーの数
int Key[MAX_M];		// キーが開けられる宝箱
int Price[MAX_M];	// キーの値段
int dp[DP_SIZE];	// 費用

int main () {

	int NN;

	// 宝箱の個数，キーの個数
	scanf("%d %d", &N, &M);
	NN = (1 << N) - 1; 

	//	各鍵の値段，開けられる箱を設定．
	for(int i = 0; i < M; i++) {
		int b, c;
		scanf("%d %d", Price + i, &b);
		Key[i] = 0x000;
		for(int j = 0; j < b; j++) {
			scanf("%d", &c);
			Key[i] |= 1 << (c-1);
		}
	}

	//	dp初期化
	dp[0] = 0;
	for(int i = 1; i <= NN; i++) dp[i] = INF;

	//  pow_Nは最大4096
	for(int i = 0; i < M; i++) {
		for(int j = 0; j <= NN; j++) {
			if(dp[j] == INF) continue;
			dp[j | Key[i]] = min(dp[j | Key[i]], dp[j]+Price[i]);
		}
	}

	// 結果出力
	if(dp[NN] == INF) printf("%d\n", -1);
	else printf("%d\n", dp[NN]);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int IINF = INT_MAX;
const ll MAX_N = ll(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
    int n, k, x[MAX_N], dmin = IINF;
    cin>>n>>k;
    REP(i,n) cin>>x[i];
    REP(i,n-k+1)dmin = min(dmin, x[i+k-1]-x[i] + min(abs(x[i+k-1]),abs(x[i])));
    cout<<dmin<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;   //long型よりも使用できる桁数が増える

// 座標 corrdinate とゴールまでのマス目の数を保持するための構造体
struct Corr {
    ll y;
    ll x;
    ll sum;
};

ll H, W;
ll sy, sx, gy, gx;
ll y, x, sum;  // キューから取り出した座標
vector<string> vec;  // 座標を受け取る配列
queue<Corr> q;   //構造体Corr型を格納するキューの生成

vector<ll> dy = {0, 0, -1, +1};  // 進む方向の簡便化，テクニックとして覚えておく．
vector<ll> dx = {-1, +1, 0, 0};  // ループで回すことで上下左右に移動できるようになっている

ll bfs() {
  while ( !q.empty() )  {
    Corr now = q.front(); q.pop();   //キューの先頭を取り出す
    y = now.y, x = now.x, sum = now.sum;
    
    if (y == gy && x == gx) return sum;   //現在の座標がゴールの場合深さを返却
    
    //上下左右4方向を探索、#ではないかつまだ訪れていない場合キューに追加
    for ( ll i = 0; i < 4; ++i) {
      Corr next = {y + dy[i], x + dx[i], sum + 1};
      if (0 <= next.y && next.y <= H-1 && 0 <= next.x && next.x <= W-1 && vec[next.y][next.x] == '.') {
                vec[next.y][next.x] = '#';  // 同じ場所を探索しないようにする
                q.push(next);
            }
    }
  }
  return -1;
}

int main() {
  cin >> H >> W;
  sy = 0, sx = 0, gy = H - 1, gx = W - 1;
  vec.resize(H); for ( ll i = 0; i < H; ++i ) cin >> vec[i];
  
  int count_all = 0; 
  int count_w = 0;
  int count_b = 0;
  count_all = (H)*(W);           //全体のマス目の数
  for ( ll y = 0; y < H; y++ ) {
    for ( ll x = 0; x < W; x++ ) {
      if( vec[y][x] == '#' ) {
        count_b++;                   //黒いマス目の数
      }
    }
  }
  
  Corr start = {sy, sx, 1};
  q.emplace(start);   //初期位置をキューに格納
  
  int count_x = count_all - count_b;
  
  count_w = bfs();    //スタートからゴールまでのマス目の数
  if ( count_w == -1 ) {
    cout << -1 << endl;
  } else {
    cout << count_x - count_w << endl;
  }
  
  return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline void pretty(T& a,int n){int i;rep(i,n){cout<<a[i];if(n-1==i)cout<<endl;else cout<<" ";}}
template<class T> inline void pretty(T& c){foreach(it,c){cout<<*it;if(distance(it,c.end())!=1)cout<<" ";else cout<<endl;}}


int main(){
  int i,j,k,n;
  vector<int> in(10);

  rep(i,10) cin >> in[i];
  sort(in.begin(),in.end(),greater<int>());
  rep(i,3) cout << in[i] << endl;

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define MAXN 300010
using namespace std;

int n, pre[MAXN], suf[MAXN], ans1, ans2 = 0x3f3f3f3f;
char s[MAXN];

int main() {
  scanf("%d%s", &n, s + 1);
  for (register int i = 1; i <= n; ++i)
    pre[i] = pre[i - 1] + (s[i - 1] == 'W' ? 1 : 0);
  for (register int i = n; i; --i)
    suf[i] = suf[i + 1] + (s[i + 1] == 'E' ? 1 : 0);
  for (register int i = 1; i <= n; ++i)
    pre[i] + suf[i] < ans2 && (ans1 = i, ans2 = pre[i] + suf[i]);
  printf("%d", ans2);
  return 0;
}


Measured memory_bytes: 2944
h,w=[int(x) for x in input().split()]
slist=[list(input()) for _ in range(h)]

h_marume=lambda x: min(h-1, max(x, 0))
w_marume=lambda x: min(w-1, max(x, 0))

for i in range(h):
  for j in range(w):
    if slist[i][j]==".":
      t_set=[(h_marume(i-1),w_marume(j-1)),
             (h_marume(i-1),w_marume(j)),
             (h_marume(i-1),w_marume(j+1)),
             (h_marume(i),w_marume(j-1)),
             (h_marume(i),w_marume(j+1)),
             (h_marume(i+1),w_marume(j-1)),
             (h_marume(i+1),w_marume(j)),
             (h_marume(i+1),w_marume(j+1))
            ]
      t_set=list(set(t_set))
      print(sum([slist[t[0]][t[1]]=="#" for t in t_set]),end="")
    else:
      print("#",end="")
  print("\n",end="")

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

int N,M,s[5],c[5];
string S;

int main(){
	cin>>N>>M;
	S=string(N,0);
	for(int i=0;i<M;i++){
		cin>>s[i]>>c[i];
		s[i]--;
		if(N!=1&&s[i]==0&&c[i]==0){
			cout<<-1<<endl;
			return 0;
		}
		if(S[s[i]]==0||S[s[i]]=='0'+c[i]){
			S[s[i]]='0'+c[i];
		}
		else{
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=0;i<N;i++){
		if(S[i]==0){
			if(i==0&&N!=1)cout<<1;
			else cout<<0;
		}
		else cout<<S[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
def check v
	return true if (v&v).count == 1
	return true if v[0]+1==v[1] && v[1]+1==v[2]
	return false
end

gets.to_i.times{
	an=gets.split(" ").map{|e|e.to_i}
	ac=gets.split(" ")
	count=0
	c=[[],[],[]]
	ac.each_with_index{|v,i|
		c[0].concat [an[i]] if v == "R"
		c[1].concat [an[i]] if v == "G"
		c[2].concat [an[i]] if v == "B"
	}
	max=0
	3.times{|i|
		maxCount=0
		c[i].permutation{|pset|
			count=0
			(pset.length/3).times{|t|
				break if !check(pset[3*t..3*t+2])
				count += 1
			}
			maxCount = count if maxCount < count
			break if max+maxCount >= 3
		}
		max += maxCount
		break if max >= 3
	}
	p 1 if max >= 3
	p 0 if max < 3
}

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, M;
    cin >> N >> M;
    VL a(M+1), b(M+1), c(M+1, 0);
    rep(i, 1, M+1){
        cin >> a[i] >> b[i];
        rep(j, 0, b[i]){
            ll d;
            cin >> d;
            d--;
            c[i] += (1<<d);
        }
    }

    VVL dp(M+1, VL((1<<N), 1e18));
    rep(m, 0, M+1) dp[m][0] = 0;
    rep(m, 1, M+1){
        rep(bit, 0, (1<<N)){
            dp[m][bit] = min(dp[m][bit], dp[m-1][bit]);
            dp[m][bit | c[m]] = min(dp[m][bit | c[m]], dp[m-1][bit] + a[m]);
        }
    }

    if(dp[M][(1<<N)-1] == 1e18) cout << -1 << endl;
    else cout << dp[M][(1<<N)-1] << endl;
    return 0;
}

Measured memory_bytes: 32384
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
 long long n,m;
 bool c[100001];
 scanf("%lld%lld ",&n,&m);
 vector<pair<long long,long long>> pairs(m);
 long long i,j;
 long long x,y;
  
 for(i=0;i<m;i++){
  scanf(" %lld%lld",&x,&y);
   pairs[i]={y,x};
  c[i]=1;
 }
  
 //小さい順sort
 sort(pairs.begin(),pairs.end());
  
 long long ans=m;
 c[0]=1;
 for(i=0;i<m;i++){
  if(c[i]){
   for(j=i+1;j<m;j++){
    if(pairs[j].second<pairs[i].first&&c[j]){
     ans--;
     c[j]=0;
     //printf("ans %lld i %lld j %lld\n",ans,i,j);
    }
   }
  }
 }
 printf("%lld\n",ans);
return 0;}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='x'){
      cnt++;
    }
  }
  if(cnt<=7){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

typedef db T;
const db eps = 1e-8;
int sgn(T x){return (x>eps)-(x<-eps);}
struct P{
    T x,y;
    P(){} P(T x,T y):x(x),y(y){}
    void read(){scanf("%lf%lf",&x,&y);}
    P operator - (const P&b) const {return P(x-b.x,y-b.y);}
    P operator + (const P&b) const {return P(x+b.x,y+b.y);}
    T operator * (const P&b) const {return x*b.x+y*b.y;}
    P operator * (const T&k) const {return P(x*k,y*k);}
    P operator / (const T&k) const {return P(x/k,y/k);}
    T operator ^ (const P&b) const {return x*b.y-y*b.x;}
    bool operator < (const P&b) const {return sgn(x-b.x)?x<b.x:y<b.y;}
    bool operator == (const P&b) const{return !sgn(x-b.x)&&!sgn(y-b.y);}
    P rot90() {return P(-y,x);}
};
db abs(P x){return sqrt(x*x);}
struct L{
    P s,t;
    void read(){s.read();t.read();}
};
bool onPS(P p,L a){
    return sgn((p-a.s)^(p-a.t))==0&&sgn((p-a.s)*(p-a.t))<=0;
}
db disPL(P p,L a){return fabs((a.t-a.s)^(p-a.s)) / abs(a.t-a.s);}
db disPS(P p,L a){
    if(sgn((a.t-a.s)*(p-a.s)) == -1) return abs(p-a.s);
    if(sgn((a.s-a.t)*(p-a.t)) == -1) return abs(p-a.t);
    return disPL(p,a);
}
bool isSS(L a,L b){ // seg x seg , replace x->y to accelerate
    T c1=(a.t-a.s)^(b.s-a.s),c2=(a.t-a.s)^(b.t-a.s);
    T c3=(b.t-b.s)^(a.s-b.s),c4=(b.t-b.s)^(a.t-b.s);
    return sgn(c1) * sgn(c2) <= 0 && sgn(c3) * sgn(c4) <= 0 &&
        sgn(max(a.s.x,a.t.x) - min(b.s.x,b.t.x)) >= 0 &&
        sgn(max(b.s.x,b.t.x) - min(a.s.x,a.t.x)) >= 0 &&
        sgn(max(a.s.y,a.t.y) - min(b.s.y,b.t.y)) >= 0 &&
        sgn(max(b.s.y,b.t.y) - min(a.s.y,a.t.y)) >= 0;
}
db disSS(L a,L b){
    if(isSS(a,b)) return 0;
    return min(min(disPS(a.s,b),disPS(a.t,b)),min(disPS(b.s,a),disPS(b.t,a)));
}

int main(){
    int n;scanf("%d",&n);
    rep(i,0,n){
        L a,b;a.read();b.read();
        printf("%.10f\n",disSS(a,b));
    }
    return 0;
}

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

struct Win {
    string number;
    int prize;
};

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if ((n | m) == 0) {
            break;
        }
        Win* wins = new Win [n];
        for (int i = 0; i < n; i++) {
            cin >> wins[i].number >> wins[i].prize;
        }
        string* lotteriesNum = new string [m];
        for (int i = 0; i < m; i++) {
            cin >> lotteriesNum[i];
        }
        int sum = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                bool isWin = true;
                for (int k = 0; k < 8; k++) {
                    if (wins[j].number[k] != '*' && wins[j].number[k] != lotteriesNum[i][k]) {
                        isWin = false;
                        break;
                    }
                }
                if (isWin) {
                    sum += wins[j].prize;
                    break;
                }
            }
        }
        cout << sum << endl;
    }
}

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


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

	int n;
	cin>>n;
	int h,w;
	cin>>h>>w;
	cout<<(n-h+1)*(n-w+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a,s,b;
  cin >> a >> s >> b;
  cout << "A" << s[0] << "C" << endl;

  return 0;
}


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

int a[200001];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);


    int k, n; cin >> k >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int mx = (k + a[0]) - a[n - 1];
    for (int i = 0; i < n - 1; i++) {
        mx = max(mx, a[i + 1] - a[i]);
    }

    cout << k - mx << '\n';

    return 0;
}


Measured memory_bytes: 1024
X, Y, A, B, C = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)[: X]
q = sorted(map(int, input().split()), reverse=True)[: Y]
r = list(map(int, input().split()))

all = p + q + r
all.sort(reverse=True)
print(sum(all[:X + Y]))

Measured memory_bytes: 22548
#include <iostream>
#include <string>

using namespace std;

int main(){
 string S;
 cin >> S;
 int sum_l[200001];
  sum_l[S.length()]=0;
  int m =1;
 for(int i=S.length()-1; i>=0; i--){
 sum_l[i] =  (m*(S[i]-'0')+sum_l[i+1])%2019;
   m*=10;
   m%=2019;
 }
 int count[2019] = {0};
 for(int i=0; i<=S.length(); i++){
 	count[sum_l[i]]++;
 }
  int sum = 0;
  for(int i=0; i<2019; i++){
  
    sum+= count[i]*(count[i]-1)/2;
  }
  cout << sum <<endl;
  
  
 return 0;
}


Measured memory_bytes: 4428
#include <iostream>
using namespace std;
int main(){
	int d;
	while(cin>>d){
		int sum=0;
		for(int i=1; i*d<=600-d; i++){
			sum+=(i*d)*(i*d)*d;
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
small_x = [-1, 0, 0, 1]
small_y = [0, -1, 1, 0]
middle_x = [-1, -1, -1, 0, 0, 1, 1, 1]
middle_y = [-1, 0, 1, -1, 1, -1, 0, 1]
big_x = [-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2]
big_y = [0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0]
dx = [[], small_x, middle_x, big_x]
dy = [[], small_y, middle_y, big_y]

field = [[0] * 10 for _ in range(10)]
while 1:
    try:
        x1, y1, size = map(int, raw_input().split(','))
        field[y1][x1] += 1
        for k in range(len(dx[size])):
            ny = y1 + dy[size][k]
            nx = x1 + dx[size][k]
            if nx < 0 or ny < 0 or nx >= 10 or ny >= 10:
                continue
            field[ny][nx] += 1
    except:
        break
ret, mx = 0, 0
for i in range(10):
    for j in range(10):
        if field[i][j] == 0:
            ret += 1
        mx = max(mx, field[i][j])
print ret
print mx

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

int main()
{
    int H, W;
    while (true)
    {
        cin >> H >> W;
        for (int h = 0; h < H; h++)
        {
            int w;
            for (w = 0; w < W; w++)
            {
                cout << "#";
            }
            cout << endl;
            w = 0;
        }
        if (H == 0 && W == 0)
            break;
        cout << endl;
        }
}


Measured memory_bytes: 3072
#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 K,l,r,mn,mx,mA=0;
	cin >> K;
	vector<ll> A(K);
	rep(i,K) {
		cin >> A.at(i);
		mA = max(mA, A.at(i));
	}
	
	l=0, r=mA*K+10;
	while(r-l > 1) {
		ll m=(l+r)/2, t=m;
		rep(i,K) {
			t = t-t%A.at(i);
			if(t == 0)
				break;
		}

		if(t < 2)
			l = m;
		else
			r = m;
	}
	mn = r;

	l=0, r=mA*K+10;
	while(r-l > 1) {
		ll m=(l+r)/2, t=m;
		rep(i,K) {
			t = t-t%A.at(i);
			if(t == 0)
				break;
		}

		if(t <= 2)
			l = m;
		else
			r = m;
	}
	mx = l;

	if(mn > mx)
		cout << -1;
	else
		cout << mn << " " << mx;
	cout << endl;
}

Measured memory_bytes: 1024
H, W = map(int, input().rstrip().split())
N = int(input())
A = list(map(int, input().rstrip().split()))

muki = 1
m = [[-1] * W for _ in range(H)]
yoko = 0
tate = 0
for i, a in enumerate(A):
    for j in range(a):
        m[tate][yoko] = i + 1
        if yoko + muki >= W or yoko + muki < 0:
            muki *= (-1)
            tate += 1
        else:
            yoko += muki
        
for i in range(H):
    print(' '.join(list(map(str, m[i]))))

Measured memory_bytes: 40048
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 1000000007;
signed main(){
    ll n; cin >> n;
    vector<ll> c(n);
    rep(i,n) cin >> c[i];
    sort(ALL(c));
    if(n==1){
        cout << (2*c[0])%MOD << endl;
        return 0;
    }
    ll ans=0;
    ll pow2=1;
    rep(i,n-2){
        pow2*=2;
        pow2%=MOD;
    }
    rep(i,n){
        ans+=(n-i+1)*c[i];
        ans%=MOD;
    }
    ans*=pow2; ans%=MOD;
    pow2*=4; pow2%=MOD;
    ans*=pow2; ans%=MOD;
    cout << ans << endl;
}


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

int main() {
	int h, w;
	cin >> h >> w;
	int a[30][30] = { 0 };
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	int res = 100000000;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int cnt = 0;
			for (int k = 0; k < h; k++) {
				for (int m = 0; m < w; m++) {
					int l = min(abs(k - i), abs(m - j));
					cnt += a[k][m] * l;
				}
			}
			res = min(res, cnt);
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


// 順番が決まっているなら
// dp[w] = 重さwの最大価値
// for each w <= si; do chmax(dp[w + wi], dp[w] + vi);


int main() {
    int n; std::cin >> n;
    std::vector<int> w(n), s(n), v(n);
    for (int i = 0; i < n; i++) std::cin >> w[i] >> s[i] >> v[i];
    std::vector<int> id(n);
    std::iota(id.begin(), id.end(), 0);
    std::sort(id.begin(), id.end(), [&](int i, int j) {
        return w[i] + s[i] < w[j] + s[j];
    });
    std::vector<long long> dp(1e5, -1e18);
    dp[0] = 0;
    for (int i : id) {
        for (int j = s[i]; j >= 0; j--) {
            dp[j + w[i]] = std::max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
    std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include "stdio.h"

int main(int argc, char const *argv[]) {
  int i,A,B,K;
  scanf("%d%d%d",&A,&B,&K);
  int N=0;
  int X[200];
  for (i = 1; i < 101; i++) {
    if (A%i==0 && B%i==0) {
      X[N]=i;
      N++;
    }
  }
  printf("%d", X[N-K]);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define out(x) cout<<(x?"Yes":"No")<<endl;
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    ll n,g;cin>>n>>g;
    ll a[20],b[20];lol(i,n)cin>>a[i]>>b[i];
    ll ans=mod;
    lol(i,(1<<n)){
	bool t[20];
	lol(j,n)t[j]=(i%(1<<(j+1))>=(1<<j));
	//lol(j,n)cout<<t[j]<<" ";cout<<endl;
	vector<int> v;v.clear();
	ll sum=0,cnt=0;
	lol(j,n){
	    if(t[j])sum+=(j+1)*100*a[j]+b[j],cnt+=a[j];
	    else lol(k,a[j])v.push_back((j+1)*100);
	}
	sort(v.begin(),v.end(),greater<int>());
	lol(j,v.size()){
	    if(sum>=g)break;
	    sum+=v[j],cnt++;
	}
	if(sum>=g)ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll sum[n+1];
  sum[0] = 0;
  rep(i,n){
    ll a;
    cin >> a;
    sum[i+1] = sum[i] + a;
  }
  ll ans = INF;
  for(int i = 1; i < n; i++) ans = min(ans, abs(sum[n]-2*sum[i]));
  cout << ans << endl;
  return 0;
}


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

struct data {
  int x, y, cnt;
  bool state;
};

int d[4] = {0, 1, 0, -1};
long long h, w;
vector<string> s;
long long memo[105][105][2] = {};
queue<data> qu;

long long solve();
bool isvalid(data now) {
  return now.x >= 0 && now.x < h && now.y >= 0 && now.y < w;
}

int main() {
  cin >> h >> w;
  s.resize(h);
  for(int i = 0; i < h; ++i) cin >> s[i];

  cout << solve() << endl;
  return 0;
}

long long solve() {
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      for(int k = 0; k < 2; ++k) memo[i][j][k] = 1e18;
  qu.push({0, 0, s[0][0] == '#', s[0][0] == '#'});
  memo[0][0][0] = memo[0][0][1] = s[0][0] == '#';
  while(!qu.empty()) {
    data now = qu.front(), nextp;
    qu.pop();
    nextp = now;
    nextp.x += 1;
    if(isvalid(nextp)) {
      nextp.state = (s[nextp.x][nextp.y] == '#');
      if(nextp.state != now.state && nextp.state)
        ++nextp.cnt;
      if(nextp.cnt < memo[nextp.x][nextp.y][now.state]) {
        memo[nextp.x][nextp.y][now.state] = nextp.cnt;
        qu.push(nextp);
      }
    }
    nextp = now;
    nextp.y += 1;
    if(isvalid(nextp)) {
      nextp.state = (s[nextp.x][nextp.y] == '#');
      if(nextp.state != now.state && nextp.state)
        ++nextp.cnt;
      if(nextp.cnt < memo[nextp.x][nextp.y][now.state]) {
        memo[nextp.x][nextp.y][now.state] = nextp.cnt;
        qu.push(nextp);
      }
    }
  }
  return min(memo[h - 1][w - 1][0], memo[h - 1][w - 1][1]);
}

Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


int dp[2020][2020][2];
int m, n;
string s, t;

int main() {
	cin >> m >> n;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			if (i < m) {
				if (s[i] == 'I')dp[i + 1][j][0] = max(dp[i][j][1] + 1, dp[i + 1][j][0]);
				else if (s[i] == 'O' && dp[i][j][0])dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][0] + 1);
			}
			if (j < n) {
				if (t[j] == 'I')dp[i][j + 1][0] = max(dp[i][j + 1][0], dp[i][j][1] + 1);
				else if (t[j] == 'O' && dp[i][j][0]) dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i][j][0] + 1);
			}
			ans = max(ans, dp[i][j][0]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 34780
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long A; long long B; long long C;
  cin>>A>>B>>C;
   long long N; cin>>N;
  if(abs(A-B)>1000000000000000000)
    cout<<"Unfair"<<endl;
  else if(N%2==0)
    cout<<A-B<<endl;
  else cout<<B-A<<endl;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int l;

int main(void){
    cin >> l;
    cout << fixed << l*l*l/27.0 << endl;
    return 0;
}


Measured memory_bytes: 256
M = [int(input()) for i in range(5)]
li = []

total = 0

for i in M:
    if i % 10 == 0:
        total += i
    else:
        total += i
        total += 10 - (i%10)
        li.append(i%10)

print(total - (10 - (10 if not li else min(li))))

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

int main() {
    int n, c;
    cin >> n >> c;
    vector<vector<int>> d(c, vector<int>(c));
    vector<vector<int>> s(n, vector<int>(n));
    for (int i = 0; i < c; ++i) {
        for (int j = 0; j < c; ++j) {
            cin >> d[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> s[i][j];
            --s[i][j];
        }
    }
    vector<vector<int>> cost(3, vector<int>(c, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < c; ++k) {
                cost[(i + j) % 3][k] += d[s[i][j]][k];
            }
        }
    }
    int ans = 1e9;
    for (int i = 0; i < c; ++i) {
        for (int j = 0; j < c; ++j) {
            if (i == j) continue;
            for (int k = 0; k < c; ++k) {
                if (i == k || j == k) continue;
                ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1280
N = int(input())
As = [int(x) for x in input().split()]
n = 0
k = 0
mac = 0
while n < len(As) - 1:
 if As[n]<As[n + 1]:
  #print(As[n] ,"<",As[n + 1],k)
  k = 0
 if As[n]>As[n + 1]:
  #print(As[n] ,">",As[n + 1],k)
  k = k + 1
 if As[n]==As[n + 1]:
  #print(As[n] ,"=",As[n + 1],k)
  k = k + 1
 mac = max(k,mac)
 n = n + 1

print(mac%1000000007)
    


Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define N 705
using namespace std;
bool f[N][N];int col[N],white,black,cnt,n,m,x,y;
struct node{int x,y;}p[N];
inline void godie(){puts("-1");exit(0);}
void dfs(int u,int c){
	if (col[u]){
		if (col[u]!=c) godie();
		return;
	}
	if (c==1) white++;
	else black++;
	col[u]=c;
	for (int i=1;i<=n;i++){
		int v=i;
		if(!f[u][i])continue;
		dfs(v,3-c);
	}
}
inline int calc(int x){return x*(x-1)/2;}
bitset<N*N>dp,tmp;
int main(){
	scanf("%d%d",&n,&m);int tot=0;
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		f[x][y]=f[y][x]=1;
	}
	for (int i=1;i<=n;i++) f[i][i]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) f[i][j]^=1;
	for (int i=1;i<=n;i++)
		if (!col[i]){
			white=0;black=0;
			dfs(i,1);
			p[++cnt].x=white;
			p[cnt].y=black;
			tot+=white+black;
		}
	//for (int i=1;i<=cnt;i++) printf("%d %d\n",p[i].x,p[i].y);
	dp[0]=1;
	for (int i=1;i<=cnt;i++){
		tmp=dp;
		tmp=tmp<<p[i].x;
		dp=dp<<p[i].y;
		dp|=tmp;
	}
	for (int i=tot/2;i;i--){
		if (dp[i]){
			printf("%d\n",calc(i)+calc(n-i));
			return 0;
		}
	}
	return 0;
}

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

int main(){
  ll N,M;cin >> N >> M;
  vector<ll> A(N,0);
  ll sum=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    sum += A[i];
  }
  ll count = 0;
  for(int i=0;i<N;i++){
    if(4*M*A[i]>=sum){
      count ++;
    }
  }
  if(count >= M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
  int N;
  int num[9]={};
  cin >> N;
  for(int i=0; i<N; i++){
    int a; cin >> a;
    if(a>=3200) num[8]++;
    else num[a/400]++;
  }
  int count=0;
  for(int i=0; i<8; i++){
    if(num[i]!=0) count++;
  }
  int min=count;
  if(min==0) min=1;
  cout << min << " " << count+num[8] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k;
	cin>>a>>b>>k;
	vector<int> vi;
	for(int i=min(a,b);i;i--)
	{
		if(a%i==0&&b%i==0)
			vi.push_back(i);
	}
	cout<<vi[--k]<<endl;
 } 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

int num(int n,int s,int a);
//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);


int main(){
	
	int n,s,i,wa;
	while(scanf("%d %d",&n,&s)!=EOF){
		if(n==0&&s==0)
			break;
		printf("%d\n",num(n,s,0));
	}
	return 0;
}

int num(int n,int s,int a){

	int result;
	int i;
	if(n==1){
		if(s>=a&&s<=9)
			return 1;
		else 
			return 0;
	}
	result=0;
	for(i=a;i<=9&&i<s;i++)
		result+=num(n-1,s-i,i+1);
	return result;
}

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

using namespace std;
typedef long long ll;

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

  ll ans = 0;
  set<ll> stl, str;
  stl.insert(0); str.insert(0);
  stl.insert(-(n + 1)); str.insert(n + 1);
  for (int i = 1; i <= n; i++) {
    ll l = *stl.upper_bound(-b[i]), r = *str.upper_bound(b[i]);
    ans += (b[i] + l) * (r - b[i]) * (ll)i;
    stl.insert(-b[i]); str.insert(b[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    int K;
    cin >> K;
    queue<ll> x;
    rep(i,9){
        x.push(i+1);
    }
    ll answer;
    int mod;
    rep(i,K){
        answer = x.front();
        mod = answer%10;
        x.pop();
        if(mod != 0){
            x.push(answer*10 - 1 + mod);
            //cout << i << ' ' << (answer*11 - 1) << endl;
        }
        x.push(10*answer + mod);
        if(mod != 9){
            x.push(answer*10 + 1 + mod);
        }
    }
    cout << answer << endl;
}

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

using namespace std;

int main() {
    int n = 0, l = 0, r = 0, ans = 0;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> l >> r;
        ans += (r - l + 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628