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

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

const ll MAX=305;
const ll INF=0x3f3f3f3f;
const ll MOD=1e9+7;
struct range{
    ll x,y,c;
};
ll dp[2][MAX][MAX],ans,n,m;
range cst[MAX];
vector<ll> add[MAX],sub[MAX];
int main(){
    scanf("%lld%lld",&n,&m);
    for(ll i=0;i<m;i++){
        scanf("%lld%lld%lld",&cst[i].x,&cst[i].y,&cst[i].c);
        add[cst[i].x].push_back(i);
        sub[cst[i].y].push_back(i);
    }
    dp[0][0][0]=1;
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<i;j++) for(ll k=0;k<=j;k++) dp[i%2][j][k]=0;
        for(ll j=0;j<i;j++) for(ll k=0;k<=j;k++){
            dp[i%2][i-1][k]=(dp[i%2][i-1][k]+dp[(i+1)%2][j][k])%MOD;
            dp[i%2][i-1][j]=(dp[i%2][i-1][j]+dp[(i+1)%2][j][k])%MOD;
            dp[i%2][j][k]=(dp[i%2][j][k]+dp[(i+1)%2][j][k])%MOD;
        }
        for(ll j=0;j<i;j++) for(ll k=0;k<=j;k++){
            for(auto vec:sub[i]){
                if(cst[vec].c!=1+(cst[vec].x<=j)+(cst[vec].x<=k)) dp[i%2][j][k]=0;
            }
        }
    }
    for(ll j=0;j<n;j++) for(ll k=0;k<=j;k++) ans=(ans+dp[n%2][j][k])%MOD;
    printf("%lld\n",ans);
}


Measured memory_bytes: 1664
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
int main() {
	int N, h[100] = {},ans=0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
		if (i == 0)ans += h[i];
		else if (h[i] - h[i-1] > 0)ans += h[i] - h[i-1];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    string s;
    map<char, int> m;
    cin >> s;
    for (auto &&a : s) if(!m[a]) m[a]++;
    if(!(m['N']^m['S']) && !(m['W']^m['E'])) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	for(int i=1;i<110;++i){
		if(a*i%b==c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    int ans=0;
    for(int i=0;i<=999;i++)
    {
        string pass=to_string(i);
        int len=pass.length();
        rep(j,3-len)
        {
            pass='0'+pass;
        }
        int p=0;
        rep(j,n)
        {
            if(pass[p]==s[j])
            {
                p++;
            }
        }
        if(p>2)ans++;
        
    }
    cout<<ans;
}

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

int main() {

  string input;

  while( getline( cin, input ) ) {

    for ( int i = 0; i < input.size(); i++ ) {

      if ( input[i] != '@' ) {
	cout << input[i];
      }else {
	for ( int j = 0; j < input[i+1] - '0'; j++ ) {
	  cout << input[i+2];
	}
	i+=2;
      }

    }

    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1164
#include <stdio.h>

#define MAX_N 100

int selectionSort(int*,int);
void print(int*,int,int);

int main(){
  int N,A[MAX_N],i,cnt;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }
  cnt = selectionSort(A,N);
  print(A,N,cnt);
  return 0;
}

int selectionSort(int *A,int N){
  int i,j,temp,res = 0,min,idx;
  for(i = 0 ; i < N ; i++){
    min = A[i]; idx = i;
    for(j = i+1 ; j < N ; j++){
      if(A[j] < min){
        min = A[j];
        idx = j;
      }
    }
    if(A[idx] < A[i]){
      temp = A[i];
      A[i] = A[idx];
      A[idx] = temp;
      ++res;
    }
  }
  return res;
}

void print(int *A,int N,int cnt){
  int i;
  for(i = 0 ; i < N ; i++){
    printf("%d%c",A[i],(i < N-1 ? ' ' : '\n'));
  }
  printf("%d\n",cnt);
}

Measured memory_bytes: 600
numbers =input().rstrip().split(" ")
consective =int(numbers[0])
X =int(numbers[1])
minimum =X-consective+1
maximum =X+consective-1
if minimum<=-1000000:
  minimum=-1000000
if maximum>=1000000:
  maximum=1000000
for i in range(minimum,maximum+1):
  print(i ,end=" ")



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5],rfact[fact_table + 5];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

ll x[500005], y[500005];

string s, t;

void solve() {
    cin >> n;
    ll sum = 0;
    for(ll i=0;i<n;i++){
        cin >> x[i];
        sum = sum ^ x[i];
    }
    for(ll i=0;i<n;i++){
        ll ans = x[i] ^ sum;
        pe(ans);
    }
    el;
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 5072
h, w = (int(x) for x in input().split())
s = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
from collections import deque
q = deque()
q.append((1,1))
d = [0,1,0,-1,0]
f = [[False]*(w+2) for _ in range(h+2)]
f[1][1] = True
t = [[0]*(w+2) for _ in range(h+2)]
t[1][1] = 1
while len(q)>0:
    y,x = q.popleft()
    l = t[y][x]
    for i in range(4):
        dx = x+d[i+1]
        dy = y+d[i]
        if not f[dy][dx] and s[dy][dx] == '.':
            q.append((dy,dx))
            f[dy][dx] = True
            t[dy][dx] = l+1
whites = sum(sum(1 if ch == '.' else 0 for ch in ss) for ss in s)
if t[h][w] == 0:
    print(-1)
else:
    print(whites-t[h][w])


Measured memory_bytes: 3380
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 100005
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;

int mp[4005];

void cl(){
    memset(mp, 0, sizeof mp);
}

int main() {
    ll n, res = 0;
    string s;
    cin >> n >> s;
    for(int i=0;i<n;i++){
        if(s[i] == 'R'){
            ll temp;
            // BRG
            cl(); temp = 0;
            for(int j=0;j<i;j++){
                if(s[j] == 'B') {
                    temp ++;
                    mp[i-j] = 1;
                }
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'G'){
                    if(mp[j-i]) res += temp - 1;
                    else res += temp;
                }
            }

            //GRB
            cl(); temp = 0;
            for(int j=0;j<i;j++){
                if(s[j] == 'G') {
                    temp ++;
                    mp[i-j] = 1;
                }
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'B'){
                    if(mp[j-i]) res += temp - 1;
                    else res += temp;
                }
            }
        }

        if(s[i] == 'G'){
            ll temp;
            // BGR
            cl(); temp = 0;
            for(int j=0;j<i;j++){
                if(s[j] == 'B') {
                    temp ++;
                    mp[i-j] = 1;
                }
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'R'){
                    if(mp[j-i]) res += temp - 1;
                    else res += temp;
                }
            }

            //RGB
            cl(); temp = 0;
            for(int j=0;j<i;j++){
                if(s[j] == 'R') {
                    temp ++;
                    mp[i-j] = 1;
                }
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'B'){
                    if(mp[j-i]) res += temp - 1;
                    else res += temp;
                }
            }
        }

        if(s[i] == 'B'){
            ll temp;
            // GBR
            cl(); temp = 0;
            for(int j=0;j<i;j++){
                if(s[j] == 'G') {
                    temp ++;
                    mp[i-j] = 1;
                }
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'R'){
                    if(mp[j-i]) res += temp - 1;
                    else res += temp;
                }
            }

            //RBG
            cl(); temp = 0;
            for(int j=0;j<i;j++){
                if(s[j] == 'R') {
                    temp ++;
                    mp[i-j] = 1;
                }
            }
            for(int j=i+1;j<n;j++){
                if(s[j] == 'G'){
                    if(mp[j-i]) res += temp - 1;
                    else res += temp;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3660
{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    a <- readInt
    op <- getChar
    _ <- getChar
    b <- readInt
    if op == '?'
        then return ()
        else let x = case op of
                        '+' -> a + b
                        '-' -> a - b
                        '*' -> a * b
                        '/' -> a `div` b
             in print x >> main


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main () {
  
  long long N, M;
  cin >> N >> M;
  
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A.begin(), A.end());
  
  set<long long> S;
  map<long long, long long> MAP;
  
  for (long long i = 0; i < M; i++) {
    
    long long B, C;
    cin >> B >> C;
    
    if (S.count(C)) {
      MAP[C] += B;
    }
    
    else {
      S.insert(C);
      MAP[C] = B;
    }
    
  }
  
  long long count = 0;
  
  for (long long i = 0; i < N; i++) {
    
    if (S.empty()) break;
    
    long long C = *rbegin(S);
    if (A[i] >= C) break;
    A[i] = C;
    MAP[C]--;
    
    if (MAP[C] == 0) S.erase(C);
    
  }
  
  long long ans = 0;
  
  for (long long i = 0; i < N; i++) {
    ans += A[i];
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n],b[n];
  rep(i,n) R a[i];
  rep(i,n) R b[i];
  int ans=0;
  rep(t,1<<n) {
    int sum=0;
    rep(i,n) {
      if(t&(1<<i)) {
        sum+=a[i];
        sum-=b[i];
      }
    }
    ans=max(ans,sum);
  }
  pr(ans);

}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int n,AC,TLE,WA,RE;
string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i = 1;i <= n;i++){
		cin>>s;
		if(s == "AC"){
			AC++;
		}
		else if(s == "WA"){
			WA++;
		}else if(s == "TLE"){
			TLE++;
		}else{
			RE++;
		}
	}
	cout<<"AC x "<<AC<<endl;
	cout<<"WA x "<<WA<<endl;
	cout<<"TLE x "<<TLE<<endl;
	cout<<"RE x "<<RE<<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
   int n,m,i,T[100],P[100],X[100],t[100],Sum=0;
   scanf("%d",&n);
   if(1<=n && n<=100)
    {
       for(i=0;i<n;i++) {
        scanf("%d",&T[i]);

       if(1<=T[i] && T[i]<=100000) Sum = Sum + T[i] ;
       }
    scanf("%d",&m);
    if(1<=m && m<=100)
        {
    for(i=0;i<m;i++)  {
            scanf("%d %d",&P[i],&X[i]);
            if(P[i]>=1 && P[i]<=100 && X[i]>=1 && X[i]<=100000) t[i]=Sum - T[P[i]-1] + X[i];
            }
        }
   }
   for(i=0;i<m;i++) printf("\n%d",t[i]);
return 0;
}

Measured memory_bytes: 1732
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	rdr := NewReader(n)
	h := ReadInts(rdr)

	m := make([]int, n)
	m[1] = Abs(h[0] - h[1])

	for i := 2; i < n; i++ {
		a := m[i-1] + Abs(h[i]-h[i-1])
		b := m[i-2] + Abs(h[i]-h[i-2])
		m[i] = Min(a, b)
	}

	fmt.Println(m[n-1])
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


type Reader struct {
	rdr  *bufio.Reader
	size int
	sep  string
}

func NewReader(size int) *Reader {
	return &Reader{
		rdr:  bufio.NewReaderSize(os.Stdin, size),
		size: size,
		sep:  " ",
	}
}

func ReadLine(rdr *Reader) string {
	buf := make([]byte, 0, rdr.size)
	for {
		line, isPrefix, err := rdr.rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func ReadStrs(rdr *Reader) []string {
	return strings.Split(ReadLine(rdr), rdr.sep)
}

func ReadInts(rdr *Reader) (n []int) {
	for _, v := range ReadStrs(rdr) {
		if i, e := strconv.Atoi(v); e == nil {
			n = append(n, i)
		}
	}
	return n
}


Measured memory_bytes: 8192
#include <iostream>
using namespace std;
int main(){
	int n;
	int a, count = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a;
		while(a % 2 == 0){
			a /= 2;
			count++;
		}
	}
	cout << count << 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++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll bfs(vector<string> &maze, vector<vector<bool> > &isVisited, ll i, ll j, ll H, ll W){
    if (isVisited[i][j]){
        return 0;
    }
    vector<ll> dx(4);
    dx[0] = 1;
    dx[1] = 0;
    dx[2] = -1;
    dx[3] = 0;
    vector<ll> dy(4);
    dy[0] = 0;
    dy[1] = 1;
    dy[2] = 0;
    dy[3] = -1;
    queue<pair<ll,ll> > que;
    que.push(pair<ll,ll> (i,j));
    ll black = 0;
    ll white = 0;
    if (maze[i][j] == '#') black++;
    if (maze[i][j] == '.') white++;
    isVisited[i][j] = true;
    while(que.size() != 0){
        pair<ll,ll> p = que.front();
        que.pop();
        rep(a,4){
            ll nx = p.second + dx[a];
            ll ny = p.first + dy[a];
            if (0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != maze[p.first][p.second] && !isVisited[ny][nx]){
                que.push(pair<ll,ll>(ny,nx));
                if (maze[ny][nx] == '#') black++;
                if (maze[ny][nx] == '.') white++;
                isVisited[ny][nx] = true;
            }
        }
    }
    ll ans = black * white;
    return ans;
}
int main(){
    ll H,W;
    cin >> H >> W;
    vector<string> maze(H);
    rep(i,H){
        cin >> maze[i];
    }
    vector<vector<bool> > isVisited(H,vector<bool> (W));
    rep(i,H){
        rep(j,W){
            isVisited[i][j] = false;
        }
    }
    ll ans = 0;
    rep(i,H){
        rep(j,W){
            ans += bfs(maze, isVisited, i, j, H, W);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3836
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");
   //  String nyu=sc.nextLine();

int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu[2]);

int d=Math.max(Math.max(A,B),C);

System.out.println(A+B+C-d);

	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll h, w, n;
    cin >> h >> w >> n;

    ll sx, sy;
    cin >> sx >> sy;

    string s, t;
    cin >> s >> t;

    // 高橋君が左方向に取り除けるか調べる
    ll cnt = 0;
    rep(i, n) {
        if(s[i] == 'L') {
            cnt++;
        }
        if(cnt >= sy) {
            out("NO");
            re0;
        }
        if(t[i] == 'R') {
            cnt--;
            if(cnt == -(w - sy + 1)) {
                cnt++;
            }
        }
    }

    // 高橋君が右方向に取り除けるか調べる
    cnt = 0;
    rep(i, n) {
        if(s[i] == 'R') {
            cnt++;
        }
        if(cnt > w - sy) {
            out("NO");
            re0;
        }
        if(t[i] == 'L') {
            cnt--;
            if(cnt == -sy) {
                cnt++;
            }
        }
    }

    // 高橋君が上方向に取り除けるか調べる
    cnt = 0;
    rep(i, n) {
        if(s[i] == 'U') {
            cnt++;
        }
        if(cnt >= sx) {
            out("NO");
            re0;
        }
        if(t[i] == 'D') {
            cnt--;
            if(cnt == -(h - sx + 1)) {
                cnt++;
            }
        }
    }

    // 高橋君が下方向に取り除けるか調べる
    cnt = 0;
    rep(i, n) {
        if(s[i] == 'D') {
            cnt++;
        }
        if(cnt > h - sx) {
            out("NO");
            re0;
        }
        if(t[i] == 'U') {
            cnt--;
            if(cnt == -sx) {
                cnt++;
            }
        }
    }
    
    out("YES");
    re0;
}

Measured memory_bytes: 776
using System;

public class Test
{
	public static void Main()
	{
		Console.ReadLine();
		var S = Console.ReadLine().ToCharArray();
		int x = 0;
		int max = 0;
		foreach (var ch in S)
		{
			if (ch == 'I')
			{
				++x;
			}
			else
			{
				--x;
			}
			max = Math.Max(max, x);
		}
		Console.WriteLine(max);
	}
}

Measured memory_bytes: 2648
#include<bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define q2(n) (n%2)==0
#define vp vector<pair <$$,$$> >
#define vctr vector<$$>
#define in(a) scanf("%lld",&a)
#define out(a) printf("%lld ",a)
#define loop(i,m,p) for ($$ i = m; i < p; ++i)
#define loopn(i,m,p) for ($$ i = p-1; i >=m; --i)

using namespace std;

int main()
{
  $$ n,sum=0;
  cin>>n;
  $$ v[n],c[n];
  loop(i,0,n) in(v[i]);
  loop(i,0,n) in(c[i]);
  loop(i,0,n)
  {
    if (v[i]>c[i])
    {
          sum+=(v[i]-c[i]);      /* code */
    }
  }
  cout<<sum<<endl;



  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
ll dp[2300000];
const ll MOD=1e9+7;
int n;
bool can[25][25];
int cnt[2300000];
int q[2300000];
int h=0,r=0;
inline void Add(ll &x,ll y){
	x+=y;if (x<0) x+=MOD;if (x>=MOD) x-=MOD;return;
}
int main(){
	ios::sync_with_stdio(false);
	memset(dp,0,sizeof(dp));
	memset(cnt,0,sizeof(cnt));
	dp[0]=1;q[r++]=0;cnt[0]=0;
	cin>>n;
	for (int i=0;i<n;++i) for (int j=0;j<n;++j) cin>>can[i][j];
	while(h<r){
		int state=q[h];++h;
		int cur=cnt[state];// consider this man
		for(int i=0;i<n;++i){// consider women
			if (state&(1<<i)) continue;// this woman is already chosen
			if (!can[cur][i]) continue;// not compatible
			int newstate=state|(1<<i);
			if (!cnt[newstate]){
				cnt[newstate]=cnt[state]+1;// one more man/woman chosen
				q[r++]=newstate;
			}
			Add(dp[newstate],dp[state]);
		}
	}
	cout<<dp[(1<<n)-1];
	return 0;
}

Measured memory_bytes: 36224
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int rdn()
{
  int ret=0;bool fx=1;char ch=getchar();
  while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();}
  while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
  return fx?ret:-ret;
}
const int N=2005;
int n,m,hd[N],xnt,to[N<<1],nxt[N<<1],fa[N][N],dis[N][N];
int p[N<<1],tot,ans; bool vis[N][N];
set<int> cd[N];
set<int>::iterator it;
void add(int x,int y){to[++xnt]=y;nxt[xnt]=hd[x];hd[x]=xnt;}
void ini_dfs(int cr,int rt,int lj)
{
  dis[rt][cr]=lj;
  for(int i=hd[cr],v;i;i=nxt[i])
    if(!fa[rt][v=to[i]])
      { fa[rt][v]=cr; ini_dfs(v,rt,lj+1);}
}
void fnd_path(int x,int y)
{
  tot=0; p[++tot]=x;
  while(x!=y){ x=fa[y][x]; p[++tot]=x;}
}
bool on_path(int cr,int s,int t)
{return dis[s][t]==dis[s][cr]+dis[cr][t];}
void solve(int x,int y)
{
  fnd_path(x,y); int s=x,t=y,tmp=1;
  for(int i=1;i<=tot;i++) if(vis[s][p[i]])s=p[i],tmp=i;
  for(int i=tot;i>=tmp;i--) if(vis[t][p[i]])t=p[i];//>=tmp
  if(s==y||vis[s][t])return;
  int tp[N],tt=0;//here not use p[]!!!
  for(it=cd[s].begin();it!=cd[s].end();it++)
    if(on_path(t,(*it),s))tp[++tt]=(*it);
  int bj=tt;
  for(it=cd[t].begin();it!=cd[t].end();it++)
    if(on_path(s,(*it),t))tp[++tt]=(*it);
  vis[s][t]=vis[t][s]=1;
  cd[s].insert(t); cd[t].insert(s);
  for(int i=1;i<=bj;i++)
    {
      int v=tp[i]; vis[s][v]=vis[v][s]=0;
      cd[s].erase(v); cd[v].erase(s);
      solve(t,v);
    }
  for(int i=bj+1;i<=tt;i++)
    {
      int v=tp[i]; vis[t][v]=vis[v][t]=0;
      cd[t].erase(v); cd[v].erase(t);
      solve(s,v);
    }
}
void dfs(int cr,int rt)
{
  set<int>::iterator it2;//don't use it!!!!!
  for(it2=cd[cr].begin();it2!=cd[cr].end();it2++)
    if(on_path(cr,rt,(*it2))&&!vis[rt][*it2])
      vis[rt][*it2]=1,ans++,dfs((*it2),rt);
}
int main()
{
  n=rdn();m=rdn();
  for(int i=1,u,v;i<n;i++)
    { u=rdn();v=rdn();add(u,v);add(v,u);}
  for(int i=1;i<=n;i++)
    fa[i][i]=-1,ini_dfs(i,i,0);
  for(int i=1,u,v;i<=m;i++)
    { u=rdn();v=rdn();solve(u,v);}
  memset(vis,0,sizeof vis);
  for(int i=1;i<=n;i++) dfs(i,i);
  printf("%d\n",ans/2);
  return 0;
}


Measured memory_bytes: 37376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) {
		if (a[i] == 0) {
			printf("%d\n", 0);
			return 0;
		}
	}
	ll ans = 1;
	const ll d = 1e18;
	rep(i, n) {
		if (a[i] > d / ans) {
			printf("%d\n", -1);
			return 0;
		}
		ans *= a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3948
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <tuple>
#include <iomanip>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

bool sortbysec(const tuple<string,int,int> &a, 
              const tuple<string,int,int> &b) 
{ 
    return (get<1>(a) < get<1>(b)); 
} 

bool sortbyfirst(const tuple<string,int,int> &a, 
              const tuple<string,int,int> &b) 
{ 
    return (get<0>(a) < get<0>(b)); 
} 

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<tuple<string,int,int>> SP(N);
  for(int i=0;i<N;i++){
    string s;
    int p;
    cin>>s>>p;
    SP[i]=make_tuple(s,p,i+1);
  }
  stable_sort(SP.rbegin(),SP.rend(),sortbysec);
  stable_sort(SP.begin(),SP.end(), sortbyfirst);
  for(int i=0;i<N;i++){
    cout<< get<2>(SP[i]) << endl;
  }

}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll N, K;
    cin >> N >> K;
    double res = 0;
    double pn = (double)1/(double)N;
    for (ll i = N; i > 0; --i) {
        if (i >= K) {
            res += pn;
        } else {
            ll j = i;
            double p = 1;
            while (j < K) {
                j <<=1;
                p /= 2;
            }
            res += pn * p;
        }
    }
    cout << setprecision(17) << res << endl;
}


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

int main() {
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  
  	long long n, a, b; cin>>n>>a>>b;
  	
  	cout << (n/(a+b))*a + (n%(a+b)>a?a:n%(a+b)) << endl;
  
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;


int main()
{
    int a,b,c,k;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    int ans=0;
    while (b<=a){
        b*=2;ans++;
    }
    while (c<=b){
        c*=2;ans++;
    }
    if (ans<=k) printf("Yes");
    else printf("No");

}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  string s;
  cin >>s;
  int r[2]={0},l[2]={0};
  
  for(int i=0; i<n; i++){
  	if(s[i]=='W') r[0]++;
    else r[1]++;
  }
  
  
  int ans=300000;
  for(int i=0; i<n; i++){
  	if(s[i]=='W'){
      r[0]--;
      ans=min(r[1]+l[0],ans);
      l[0]++;
    }
    else{
      r[1]--;
      ans=min(r[1]+l[0],ans);
      l[1]++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 900
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
#include<tuple>
#include<utility>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb push_back
#define mp make_pair

int main() {
	vector<int> num(3);
	rep(i, 0, 3) {
		cin >> num[i];
	}
	SORT(num);
	cout << num[0] + num[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

/*ソートの時に使う
int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}
    qsort (data,sizeof(data),sizeof(int),sort); 
*/

int main(void){
    long long n,m,ans=1;
    scanf("%lld%lld",&n,&m);
    if (llabs(n-m)>=2){
        printf("0\n");
        exit(0);
    } else if (n==m){
        while(m>0){
            ans=(ans*m)%1000000007;
            m--;
        }
        while(n>0){
            ans=(ans*n)%1000000007;
            n--;
        }
        ans=(ans*2)%1000000007;
    } else {
        while(n>0){
            ans=(ans*n)%1000000007;
            n--;
        }
        while(m>0){
            ans=(ans*m)%1000000007;
            m--;
        }
    }    
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void)
{
  int i = 0, cnt = 0, tmp, x[3000], y[3000];

  for(i = 0; i < 3000; i++) {
    scanf("%d %d", &x[i], &y[i]);
    if(x[i] == 0 && y[i] == 0) {
      break;
    }
    cnt++;
  }

  for(i = 0; i < cnt; i++) {
    if(x[i] > y[i]) {
      tmp = x[i];
      x[i] = y[i];
      y[i] = tmp;
    }
    printf("%d %d\n", x[i], y[i]);
  }

  return 0;
}

Measured memory_bytes: 620
#include <stdio.h>
int main (void){
    int n, i, j, temp, count = 0, min = 9999999, flag = -1;
    scanf("%d", &n);
    int r[n];

    for(i = 0; i < n; i++){
        scanf("%d", &r[i]);
    }
    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            if(r[j] < min){
                min = r[j];
                flag = j;
            }
            if(min < r[i] && j == n-1){
                temp = r[flag];
                r[flag] = r[i];
                r[i] = temp;
                count = count + 1;
            }
         
        
            
        }
        min = 9999999;
    }
    for(i = 0; i < n; i++){
        printf("%d", r[i]);
        if(i != n-1) printf(" ");
    }
    puts("");
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 616
n, q = map(int, input().split())
s = list(input())
dp = [0]*(n+10)
for i in range(n):
  if i == 0:
    continue
  else:
    if s[i]=='C' and s[i-1]=='A':
      dp[i+1] = dp[i] + 1
    else:
      dp[i+1] = dp[i]
for i in range(q):
  l, r = map(int, input().split())
  if l == 1:
    print(dp[r])
  else:
    if s[l-1]=='C' and s[l-2]=='A':
      print(dp[r]-dp[l-1]-1)
    else:
      print(dp[r]-dp[l-1])

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

using namespace std;

// 入力
int H, W;

// MAP
vector<vector<int>> field;

// 左、上、右、下、左上、右上、右下、左下
vector<int> dx = {-1, 0, 1, 0, -1, 1, 1, -1};
vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1};

// 探索しない条件
// 1, 範囲外の場合
// 2, 海の場合

void dfs(int h, int w) {
    // 探索実行
    field.at(h).at(w) = 0;

    for (int i = 0; i < 8; i++) {  // 行先
        int nx = w + dx.at(i);
        int ny = h + dy.at(i);

        // 1, 範囲外の場合
        if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;

        // 2, 海の場合 + 探索済みの場合
        if (field.at(ny).at(nx) == 0) continue;

        dfs(ny, nx);
    }
}

int main() {
    while (cin >> W >> H) {
        if (H == 0 || W == 0) break;
        field.assign(H, vector<int>(W, 0));
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                cin >> field.at(h).at(w);
            }
        }

        // 探索開始
        int count = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (field.at(h).at(w) == 0) continue;
                dfs(h, w);
                count++;
            }
        }

        cout << count << endl;
    }

    return 0;
}



Measured memory_bytes: 3276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static int maxAbsValExpr(int[] x, int[] y) {
		int res = 0, n = x.length, P[] = { -1, 1 };
		for (int p : P) {
			for (int q : P) {
				int smallest = p * x[0] + q * y[0] + 0;
				for (int i = 1; i < n; ++i) {
					int cur = p * x[i] + q * y[i];
					res = Math.max(res, cur - smallest);
					smallest = Math.min(smallest, cur);
				}
			}
		}
		return res;
	}

	public static void main(String[] args) throws IOException {


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int[] x = new int[n];
		int[] y = new int[n];
		
		for(int i=0; i<n; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine(), " ");
			x[i] = Integer.parseInt(st.nextToken());
			y[i] = Integer.parseInt(st.nextToken());
		}
		
		
		System.out.println(maxAbsValExpr(x, y));
		
	}
}

Measured memory_bytes: 56456
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,K;
    cin>>A>>B;
    if(A==B){
        cout<<0<<endl;
        return 0;
    }else if((A+B)%2==0){
        cout<<(A+B)/2<<endl;
        return 0;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
}

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

struct data {
  long long x, y, c;
};

long long a, b, m;
vector<long long> va, vb;
vector<data> v;

long long solve();

int main() {
  cin >> a >> b >> m;
  ;
  va.resize(a);
  vb.resize(b);
  v.resize(m);
  for(int i = 0; i < a; ++i) cin >> va[i];
  for(int i = 0; i < b; ++i) cin >> vb[i];
  for(int i = 0; i < m; ++i)
    cin >> v[i].x >> v[i].y >> v[i].c;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 1e17, mina = 1e17, minb = 1e17;
  for(int i = 0; i < a; ++i) mina = min(mina, va[i]);
  for(int i = 0; i < b; ++i) minb = min(minb, vb[i]);
  for(int i = 0; i < m; ++i) {
    res =
        min(res, va[v[i].x - 1] + vb[v[i].y - 1] - v[i].c);
  }
  return min(res, mina + minb);
}

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

using namespace std;

void solve()
{
	for(int i = 0; i < 9; ++i)
	{
		string str;
		cin >> str;
		int am, pm;
		cin >> am >> pm;
		cout << str << " " << am + pm << " " << 200 * am + 300 * pm << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1204
#include <iostream>

using namespace std;

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

    if ((A - C) * (B - C) < 0) {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    

    return 0;
}

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

int main() {
  int H,W,D;
  cin>>H>>W>>D;
  int px[H*W+1],py[H*W+1];
  memset(px,0,sizeof(px));
  memset(py,0,sizeof(py));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      int A;
      cin>>A;
      px[A]=i,py[A]=j;
    }
  }
  int d[H*W+1];
  memset(d,0,sizeof(d));
  for (int i=D+1; i<=H*W; i++) {
    d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
  }
  int Q;
  cin>>Q;
  while (Q--) {
    int L,R;
    cin>>L>>R;
    cout<<d[R]-d[L]<<endl;
  }
  return 0;
}


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if (A+B>C+D) {
    cout<<"Left"<<endl;
  }
  else if (A+B<C+D) {
    cout<<"Right"<<endl;
  }
  else {
    cout<<"Balanced"<<endl;
  }
  
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int N=105;
char a[N],b[N],c[N];
int n,ans;
int main()
{
	scanf("%d",&n);
	scanf("%s%s%s",a+1,b+1,c+1);
	for (int u=1;u<=n;u++)
	{
		if (a[u]==b[u]&&b[u]==c[u]) continue;
		if (a[u]==b[u]) ans++;
		else if (b[u]==c[u]) ans++;
		else if (a[u]==c[u]) ans++;
		else ans+=2;
	}
	printf("%d\n",ans);
	return 0;
}

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


int main() {
  int N;
  cin >> N;
  vector<int> ans(N);
  for(int i = 0; i < N-1; i++){
    int a;
    cin >> a;
    ans.at(a-1) += 1;
  }
  
  for(int i = 0; i < N; i++){
   cout << ans.at(i) << endl;
  }
 
  return 0;
}

Measured memory_bytes: 4064
/*
*  Author: windystreet
*  Date  : 2019-08-05 20:51:35
*  Motto : Think twice, code once.
*/
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    int res = max(c-(a-b),0);
    cout<<res<<endl;
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
   // freopen("F:/in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
#ifndef ONLINE_JUDGE
    //printf("%.10f\n",1.0*clock()/CLOCKS_PER_SEC);
#endif
    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++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i] /= 2;
    }
    ll l=a[0];
    for(int i=1;i<n;i++){
        l = lcm(l,a[i]);
    }
    for(auto t : a){
        if((l/t)%2==0){
            cout << 0 << endl;
            return 0;
        }
    }
    //cout << "l=" << l << endl;
    int g = m/l;
    //cout << "g=" << g << endl;
    int ans = g/2 + g%2;
    cout << ans << endl;
}

Measured memory_bytes: 768
#!/usr/bin/env python3
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
ans = []
c = 1
for i in s:
    if i == "." * w:
        if ans:
            ans.append(ans[-1])
        else:
            ans.append([0]*w)
    else:
        f = i.index("#")
        ans.append([c] * (f + 1))
        for j in i[f + 1:]:
            if j == "#":
                c += 1
            ans[-1].append(c)
        c += 1
for i in range(h):
    if ans[i] != [0]*w:
        for j in range(i):
            ans[j] = ans[i]
        break
for i in ans:
    print(*i)


Measured memory_bytes: 12700
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
/*Fast I/O goes here*/
const double EPS = 1e-8;
const ll PR = 19260817;
const ll inv2 = 500000004;
const ll inv3 = 333333336;
int main() {
	int n, m, k;
	cin>>n>>m>>k;
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=m; j++) {
			int res=i*m+j*n-i*j*2;
			if(res==k) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
bool func(ll a[],ll k,ll n)
{
  if(k<0) return 1;
  if(k==0) return 0;

  fr(i,0,n)
    if(!func(a,k-a[i],n))
      return 1;
  return 0;
}
int main()
{
  ll n,k; cin>>n>>k;
  ll a[n];
  fr(i,0,n)
    cin>>a[i];

  ll dp[k+1]={0};

  fr(i,1,k+1)
  {
    fr(j,1,n+1)
    {
      if(i-a[j-1]>=0 && dp[i-a[j-1]]==0) dp[i]=1;
      if(dp[i]==1) break;
    }
  }

  if(dp[k]) cout<<"First";
  else cout<<"Second";


  //if(func(a,k,n)) cout<<"First";
  //else cout<<"Second";
}

Measured memory_bytes: 4456
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//typedef complex<double> P;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
const int MAX_V = 1005;
const int MAX_E = 2005;
 
struct edge { int from, to, cost; };
edge es[MAX_E];
int d[MAX_V], V, E;
 
bool bellman_ford(int s){
  REP(i, V) d[i] = INF;
  d[s] = 0;
  REP(i, V + 1){
    bool update = false;
    REP(j, E){
      edge e = es[j];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(i == V) return false;
        update = true;
      }
    }
  }
  return true;
}
 
int main() {
  int r;
  cin >>V >>E >>r;
  REP(i, E) cin >>es[i].from >>es[i].to >>es[i].cost;
  bool is_end = bellman_ford(r);
  if(!is_end) cout <<"NEGATIVE CYCLE" <<endl;
  else{
    REP(i, V){
      if(d[i] == INF) cout <<"INF" <<endl;
      else cout <<d[i] <<endl;
    }
  }
  return 0;
}

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

int main(){
	int cnt[3] = {};
	string s;
	cin >> s;
	for(int i = 0;i < s.length();i++) cnt[s[i] - 'a']++;
	int ma = max({cnt[0],cnt[1],cnt[2]}),mi = min({cnt[0],cnt[1],cnt[2]});
	if(mi + 1 >= ma) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void){

  char s[201];
  scanf("%s", s);
  int length = strlen(s);
  int flag;
  for (int i = length/2; i >= 1; i--) {
    if (i*2 == length) {
      continue;
    }
    flag = 1;
    for (int j = 0; j < i; j++) {
      if (s[j] != s[i+j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      printf("%d\n", i*2);
      break;
    }
  }

  return 0;
}

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

int main(void){
  int n, ans;
  string s, t;
  
  cin >> n >> s >> t;
  for (int i=n; i>=0; i--){
    int flg=1;
    //cout << i << endl;
    for (int j=0; j<i; j++){
      //cout << s[n-i+j] << t[j] << endl;
      flg &= s[n-i+j]==t[j];
    }
    if (flg){
      ans = n+(n-i);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		int total = 0;
		int num = 0;
		int min = 0;
		int a[] = new int[n];

		for (int m=0; m < n; m++) {
			a[m] = scan.nextInt();
			total += a[m];
		}

		min = a[0];
		for (int i=1; i < n; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}

		total = x - total;

		num = total/min;
		num += n;

		System.out.println(num);

		scan.close();

	}

}


Measured memory_bytes: 21844
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#define cout(s) cout<<s<<endl 
using namespace std;

int main()
{
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	if (s[0][s[0].length() - 1] == s[1][0] && s[1][s[1].length() - 1] == s[2][0])
		cout("YES");
	else
		cout("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n;
	cin >> n;
	string s[n];
	int t[n];
	rep(i, n) cin >> s[i] >> t[i];
	string x;
	cin >> x;

	bool f = 0;
	int ans = 0;

	rep(i, n) {
		if(f) ans += t[i];
		if(s[i] == x) f = 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256