akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define for_(i,n) for(int i=0;i<n;++i)
const int mod= 1e9 +7;
const int inf=1e7;
int n;



void updateTreeNode(vector<int> & tree,int p, int value)  
{  
    // set value at position p 
    tree[p+n] = value; 
    p = p+n; 
      
    // move upward and update parents 
    for (int i=p; i > 1; i >>= 1) 
        tree[i>>1] = max(tree[i],tree[i^1]); 
} 
  
// function to get sum on interval [l, r) 
int query(vector<int> & tree,int l, int r)  
{  
    int res = -inf; 
      
    // loop to find the sum in the range 
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) 
    { 
        if (l&1)  
            res = max(res,tree[l++]); 
      
        if (r&1)  
            res = max(res,tree[--r]); 
    } 
      
    return res; 
} 


main()
{  
 cin>>n;
int h[n],a[n];
for_(i,n) cin>>h[i];
for_(i,n) cin>>a[i];
int dp[n];
//vector<int> dp(n+1, inf);
/*
LIS::
dp[i] = length of increasing subsequence when it ends at arr[i]
		     	Recurrence relation:	dp[i] = max(1,  max(dp[j] +1));
 where j: 0,1… i-1 and arr[j]<arr[i]
Modify LIS to accomodate beauty value

*/
vector<int> tree(2*n+2, -inf);
int ans=dp[0]= a[0];
updateTreeNode(tree,h[0],dp[0]);                                  

for(int i=1;i<n;++i)
{   
dp[i] = max(a[i],query(tree,1,h[i])+a[i]);
updateTreeNode(tree,h[i],dp[i]);
ans=max(ans,dp[i]);
  
}
cout<<ans<<endl;

    
}























/*
typedef struct structure{
    int x,y;
} pt;
pt p0;
bool cmp(pt a, pt b)
{
    return cw(p0,a,b);
}
bool cw(pt a, pt b, pt c){
    return ((c.y-a.y)*(b.x-a.x)-(b.y-a.y)*(c.x-a.x))>=0
}



convex_hull(vector<pt>& points)
{
   // sort(points.begin(),points.end, cmp);// sorted according to y cordinate
    p0=points[0];
    sort(points.begin(),points.end, cmp);
    vector<pt> convexHull;
    stack<pt> temp;
    convexHull.push_back(points[0]);
    
    temp.push(points[0]);temp.push(points[1]);//temp.push(points[2]);
    pt top,top0;
    for(int it=2;it<points.size();++it)
    {   
        top=temp.top(); temp.pop(); top0=temp.top();
        pt next=points[it];
        if(cw(top0,top,next))
        {
            convexHull.push_back(top);
            temp.push(top);
            top0=top;
            top=next;
        }
        else
        {
          temp.push(next);  
        }
        
    }
    
}*/












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

using Size = int;
using Vertex = int;
using Weight = long long;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

using LL = long long;
const LL M = 1e9 + 7;

LL combination(LL n, LL r) {
  if(n < r) return 0;
  if(n < 0 || r < 0) return 0;
  static std::vector<LL> fact{1, 1}, inv{1, 1}, finv{1, 1};
  for(LL i = fact.size(); i <= n; ++i) {
    fact.emplace_back(fact.back() * i % M);
    inv.emplace_back(inv.at(M % i) * (M - M / i) % M);
    finv.emplace_back(finv.back() * inv.back() % M);
  }
  return (fact[n] * finv[n - r] % M) * finv[r] % M;
}

void rerooting(const Graph& G) {
  struct DP {
    LL val=1, size=0;
    const DP operator+(const DP& o) const {return {(val*o.val%M)*combination(size+o.size,o.size)%M, size+o.size};}
    const DP addRoot() const {return {val, size+1};}
  };
  std::unordered_map<Vertex, std::unordered_map<Vertex, DP>> dp;
  std::function<DP(Vertex, Vertex)> dfs = [&](Vertex v, Vertex p) {
    const int N = G[v].size();
    DP res;
    for(const auto& e: G[v]) if(e.to != p) res = res + (dp[v][e.to] = dfs(e.to, v));
    return res.addRoot();
  };
  std::function<void(Vertex, Vertex)> rev = [&](Vertex v, Vertex p) {
    const int N = G[v].size();
    std::vector<DP> suml(N+1), sumr(N+1);
    for(auto i=0; i<N; ++i) suml[i+1] = suml[i] + dp[v][G[v][i].to];
    for(auto i=N; 0<i; --i) sumr[i-1] = sumr[i] + dp[v][G[v][i-1].to];
    for(auto i=0; i<N; ++i) {
      auto nex = G[v][i].to;
      if(nex == p) continue;
      dp[nex][v] = (suml[i] + sumr[i+1]).addRoot();
      rev(nex, v);
    }
  };
  dfs(0, -1); rev(0, -1);
    for(auto v=0; v<G.size(); ++v) cout << std::accumulate(std::begin(dp[v]), std::end(dp[v]), DP(), [](auto s, auto p) {return s+p.second;}).addRoot().val << endl;
}

int main() {
  int N;
  cin >> N;
  Graph G(N);
  for(auto i=1; i<N; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back({a, b});
    G[b].push_back({b, a});
  }
  rerooting(G);
}


Measured memory_bytes: 73332
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var (
		a  int
		b  int
		bs string
	)
	fmt.Scan(&a, &bs)
	bs = bs[:1] + bs[2:]
	b, _ = strconv.Atoi(bs)
	fmt.Println(a * b / 100)
}


Measured memory_bytes: 1772
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	string str;
	cin >> str;

	lli ans = 0;
	lli count = 0;

	FOR(str.size()) {
		if (str[i] == 'B')
			count++;
		else
			ans += count;
	}

	COUT(ans);

	return 0;
}





Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
pair<pll,pll> p[100];
ll ans[20][20];
void solve()
{
    ll a,b,n;
    cin>>a>>b>>n;
    n=min(n,b-1);
        ll x=(a*n)/b;
        ll y=a*(n/b);
        ll ans=x-y;
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

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

    long ans = 0;
    long d = n/(a+b);
    ans = d*a;
    long s = n%(a+b);
    if(a <= s){
        ans += a;
    }else{
        ans += n-d*(a+b);
    }
    OP(ans);
}


Measured memory_bytes: 256
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a * n, b) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    string S; cin >> S;
    if (S == "AAA" || S == "BBB") {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
    return 0;
}

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

int main() {
  int S, W;
  cin >> S >> W;
  if (S <= W) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int N, Q;
long long B[500010]; 
void add(int idx, long long s){
	int x = idx; 
	while(x <= N){
		B[x] += s; x += x & -x; 
	}
}
long long sum(int idx){
	long long res = 0; 
	int x = idx; 
	while(x > 0){
		res += B[x]; x -= x & -x;
	}
	return res; 
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N >> Q; 
	for(int i = 1; i <= N; i++){
		long long a; cin >> a; 
		add(i, a); 
	}
	while(Q--){
		int a; cin >> a; 
		if(a == 0){
			int p; long long x; cin >> p >> x; 
			add(p + 1, x); 
		}else if(a == 1){
			int l, r; cin >> l >> r; 
			cout << sum(r) - sum(l) << "\n"; 
		}
	}
}

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

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

  set<string> dict;
  for(size_t i=0; i<S.size(); i++){
    for(size_t len=1; len <= S.size()- i; len++){
      string str_ins= S.substr(i, len);
      dict.insert(str_ins);

      if(dict.size() > K){
        string str_tail= *rbegin(dict);
        dict.erase(str_tail);
        if(str_ins==str_tail){ break; }
      }
    }
  }
  string ans= *rbegin(dict);

  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cmath>
#include <cstring>
#include <bitset>

using namespace std;
void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
using ld = long double;


void precalc() {}

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

    set<int> s;

    for (int i = 0; i < n; ++ i){
        int curr;
        cin >> curr;
        s.insert(curr);
    }

    if (s.size() == n)
        cout << "YES\n";
    else
        cout << "NO\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(20);
    precalc();
    solve();

}

Measured memory_bytes: 9600
import java.util.*;

public class Main {

  private long criticalPath = 0; 
  private long people = 0;

  public static void main(String[] args) {
    Main m = new Main();
    m.read();
    m.exec();
  }

  private void read() {
    Scanner scan = new Scanner(System.in);
    people = scan.nextLong();
    criticalPath = people;
    for (int i = 0; i < 5; i++) {
      long path = scan.nextLong();
      if (criticalPath > path) {
        criticalPath = path;
      }
    }
  }

  private void exec() {
    long time = people / criticalPath + 4;
    if (people % criticalPath != 0) {
      time++;
    }
    System.out.println(time);
  }
}

Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;

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

    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
mod = 10**9+7
A=[1] + [0]*(n+3)
G=[1] + [0]*(n+3)
C=[1] + [0]*(n+3)
for i in range(1,n):
    t=(2*A[i-1]+G[i-1]+C[i-1])%mod
    A[i]=t
    G[i]=(t-A[i-2]+G[i-3])%mod
    C[i]=(t-A[i-2]-G[i-2]-3*A[i-3])%mod
print((2*A[n-1]+G[n-1]+C[n-1])%mod)


Measured memory_bytes: 9044
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=360;;i+=360){
		if(i%n==0){
			printf("%d",i/n);
			return 0;
		}
	}
}


Measured memory_bytes: 3824
n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort(reverse=True)
    return divisors

D = make_divisors(n)
ans = 0
for d in D:
    m = d-1
    q = n//d
    if m > 0 and 0 <= q < m:
        ans += m
print(ans)


Measured memory_bytes: 65828
import copy
N = int(input())
H = list(map(int,input().split()))
HH = copy.deepcopy(H) 
ans = 0
while HH.count(0) != N:
  for i in range(N):
    if HH[i] == 0:
      pass
    else:
      HH[i] -= 1
      if i == N - 1:
        ans += 1
      else:
        if HH[i+1] == 0:
          ans += 1
print(ans)

Measured memory_bytes: 3444
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
	char buf[100];
	double st[100];
	int sp;
	char *p;
	double x;
	int n;
	while(gets(buf)) {
		sp = 0;
		p = buf;
		while(*p) {
			if(sscanf(p,"%lf%n",&x,&n)==1) {
				st[sp++] = x;
				p+=n;
			}else if(*p==' ') p ++;
			else if(*p=='+') --sp,st[sp-1]+=st[sp], ++p;
			else if(*p=='-') --sp,st[sp-1]-=st[sp], ++p;
			else if(*p=='*') --sp,st[sp-1]*=st[sp], ++p;
			else if(*p=='/') --sp,st[sp-1]/=st[sp], ++p;
			else p ++;
		}
		printf("%.10f\n", st[sp-1]);
	}
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll k;
	cin >> n >> k;
	vector<P> v(n);
	rep(i,n) cin >> v[i].first >> v[i].second;
	sort(v.begin(), v.end());
	rep(i,n){
		if(v[i].second < k) k -= v[i].second;
		else{
			cout << v[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3964
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
//#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    string N;
    cin>>N;
    int a=0;
    long int l=N.size();
    for (long int i=0;i<l;i++){
        a+=(int)N[i]-'0';
        a=a%9;
    }
    if (a==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3676
D = int(input())
c = list(map(int, input().split()))
s = []
for k in range(D):
    s.append(list(map(int, input().split())))

#print(s)
ans = [s[k].index(max(s[k]))+1 for k in range(D)]

p = 0


scheduled = [0 for _ in range(26)]

for k in range(D):
    t = ans[k]
    scheduled[t-1] = -1
    for j in range(26):
        scheduled[j] +=1
        p -= c[j]*scheduled[j]
    p += s[k][t-1]

np = p

for n in range(D):
    op = 0+ np
    oa = 0 + ans[n]
    ans[n] = 0 
    for k in range(D):
        t = ans[k]
        scheduled[t-1] = -1
        for j in range(26):
            scheduled[j] +=1
            np -= c[j]*scheduled[j]
        np += s[k][t-1]
    if np > op:
        continue
    else:
        ans[n] = oa



for k in range(D):
    print(ans[k])

Measured memory_bytes: 9144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int r, g, b;
  cin >> r >> g >> b;
  int wa = 10*g + b;
  if (wa % 4) cout << "NO\n";
  else cout << "YES\n";
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Data.Char (isAlpha)
import qualified Data.ByteString.Char8 as B

f :: B.ByteString -> Bool
f xs = let (as, bs) = B.splitAt (B.length xs `div` 2) xs in as == bs

main :: IO ()
main = do
    ss <- B.takeWhile isAlpha <$> B.getLine
    let xss = tail . reverse $ B.inits ss
    let Just ans = find f xss
    print $ B.length ans

Measured memory_bytes: 508
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   cout << (1000-N%1000)%1000 << endl;
   return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); //整数の入力
		int total = 0;
		int max = 0;
		for (int i = 0; i < n; i++) {
			int tmp = sc.nextInt();
			if (tmp > max) {
				max = tmp;
			}
			total += tmp;
		}
		System.out.println(total - max / 2);
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    long long int N,K;
    cin>>N>>K;
    vector<long long int> v(N);
    for(long long int i=0;i<N;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    long long min=1000000007;
    long long int temp;
    for(long long int i=0;i<=N-K;i++){
        temp=v[i+K-1]-v[i];
        if(temp<min)
            min=temp;
    }
    cout<<min<<endl;
    return 0;}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    vector<int> V(3);
    rep(i,0,3)cin >> V[i];
    sort(V.begin(), V.end());

    cout << V[0] + V[1] + V[2] * 10 << endl;
}

Measured memory_bytes: 256
from functools import reduce

n,a,b=map(int,input().split())

mod=10**9+7
def nCk(n,k):
    if n<k or (n<0 or k<0):
        return 0
    k=min(k,n-k)
    up,down=1,1
    for i in range(k):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod

all=pow(2,n,mod)
nCa=nCk(n,a)
nCb=nCk(n,b)

print((all-nCa-nCb-1)%mod)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class SCCDecomp {
    int n;
    vvi adj;
    
public:
    vvi scc;
    SCCDecomp(int n) : n(n), adj(n) {}
    
    void addArc(int a, int b) {
        adj[a].push_back(b);
    }

    int run() {
        vi num(n), low(n);
        stack<int> S;
        vi inS(n);
        int t = 0;
        function<void(int)> visit = [&](int v) {
            low[v] = num[v] = ++t;
            S.push(v);
            inS[v] = 1;
            for (int s: adj[v]) {
                if (!num[s]) {
                    visit(s);
                    low[v] = min(low[v], low[s]);
                } else if (inS[s]) {
                    low[v] = min(low[v], num[s]);
                }
            }
            if (low[v] == num[v]) {
                scc.push_back(vi());
                while (1) {
                    int w = S.top();
                    S.pop();
                    inS[w] = false;
                    scc.back().push_back(w);
                    if (v == w) {
                        break;
                    }
                }
            }
        };

        for (int i = 0; i < n; i++) {
            if (num[i] == 0) {
                visit(i);
            }
        }

        return scc.size();
    }
};

int main() {
    int v, e;
    cin >> v >> e;
    SCCDecomp s(v);
    for (int i = 0; i < e; i++) {
        int a, b;
        cin >> a >> b;
        s.addArc(a, b);
    }

    int n = s.run();
    vi scc(v);
    for (int i = 0; i < n; i++) {
        for (int v: s.scc[i]) {
            scc[v] = i;
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        cout << (scc[a] == scc[b]) << endl;
    }
}


Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vint a(m);
  int sum=0;
  rep(i,m){
    cin>>a[i];
    sum+=a[i];
  }
  if(sum>n){
    cout<<-1<<'\n';
  }
  else{
    cout<<n-sum<<'\n';
  }
  return(0);
}

Measured memory_bytes: 3660
# seishin.py
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

INF = 10**18

from heapq import heappush, heappop

l0, r0 = P[0]

L = [-l0+1]
R = [l0-1]
s = t = 0

res = 0
for i in range(N-1):
    l0, r0 = P[i]
    l1, r1 = P[i+1]
    s += (r1 - l1); t += (r0 - l0)
    if -s-L[0] <= l1-1 <= t+R[0]:
        heappush(L, -l1+1-s)
        heappush(R, l1-1-t)
    elif l1-1 < -s-L[0]:
        heappush(L, -l1+1-s)
        heappush(L, -l1+1-s)
        p = -heappop(L)-s
        heappush(R, p-t)
        res += (p - (l1-1))
    elif t+R[0] < l1-1:
        heappush(R, l1-1-t)
        heappush(R, l1-1-t)
        p = heappop(R) + t
        heappush(L, -p-s)
        res += (l1-1 - p)
print(res)

Measured memory_bytes: 102488
# -*- coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    n,m,x = map(int, input().split())
    c = []
    a = []
    for i in range(n):
        row = list(map(int, input().split()))
        c.append(row[0])
        a.append(row[1:])
    min_price = -1
    for nbit in range(1<<n): # red row bit h = 2なら 00 ~ 11 100(=2^2)　左ビットシフト 1 -> 100
        sum_price = 0
        sum_a = [0]*m
        for i in range(n):
            if nbit>>i & 1:
                for j in range(m):
                    sum_a[j] += a[i][j]
                sum_price += c[i]
        if sum_price == 0:
            continue
        elif all(value >= x for value in sum_a):
            if min_price == -1:
                min_price = sum_price
            elif sum_price < min_price:
                min_price = sum_price
    
    print(min_price)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
#include <stdio.h>

int main()
{
  int cont, drat, irat;
  scanf("%d%d",&cont,&drat);
  if(cont>=10)
  {
    irat = drat;
  }
  else
  {
    irat = drat + (100 * (10-cont));
  }
  printf("%d\n",irat);
  
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			var xy = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long x = xy[0];
			long y = xy[1];
			int ans = 0;
			while (x <= y) {
				++ans;
				x *= 2;
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {

    ll N; cin >> N;

    for(int i = 1; i <= 3500; i ++){
        for(int j = 1; j <= 3500; j ++){
            if((4*i*j - N*i - N*j) != 0 && (N*i*j)%(4*i*j - N*i - N*j) == 0){
                if(((N*i*j)/(4*i*j - N*i - N*j)) <= 0 ) continue;
                cout << i << " " << j << " " << ((N*i*j)/(4*i*j - N*i - N*j));
                return 0;
            }
        }
    }

}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vi v(n, 0);
        rep(i, n) cin >> v[i];
        sort(all(v), greater<int>());
        int ans =0;
        rep(i, n){
            if((i+1)%m==0) continue;
            ans +=v[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

class UnionFind {
    private:
        vector<int> parent;  // 親
        vector<int> rank;    // 木の深さ
        vector<int> size;    // 根の持つ大きさ

    public:
        UnionFind(int n);          // n要素で初期化
        int find(int x);           // 木の根を返す
        void unite(int x, int y);  // xとyの属する集合を併合
        bool same(int x, int y);   // xとyが同じ集合に属するか否か
        int getSize(int x);        // xの属する集合の大きさ
};

UnionFind::UnionFind(int n) : parent(n), rank(n, 0), size(n, 1) {
    for (int i = 0; i < n; i++) parent[i] = i;
}

int UnionFind::find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        int r = find(parent[x]);
        return parent[x] = r;
    }
}

void UnionFind::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
    size[find(x)] = size[x] + size[y];
}

bool UnionFind::same(int x, int y) { return find(x) == find(y); }

int UnionFind::getSize(int x) { return size[find(x)]; }

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    REP(i, m) cin >> a[i] >> b[i];
    reverse(all(a));
    reverse(all(b));

    UnionFind uf(n+1);
    vector<LL> ans(m);
    ans[0] = n * (n-1) / 2;
    REP(i, m-1){
        if(uf.same(a[i], b[i])){
            ans[i+1] = ans[i];
        }else{
            ans[i+1] = ans[i] - uf.getSize(a[i]) * uf.getSize(b[i]);
            uf.unite(a[i], b[i]);
        }
    }
    reverse(all(ans));
    REP(i, m) cout << ans[i] << endl;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#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 int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    string s, t;
    cin >> s >> t;
    int ls = s.size(), lt = t.size();
    int ans = inf;
    rep(i, 0, ls - lt + 1) {
        int sum = 0;
        rep(j, 0, lt) {
            if (t[j] != s[i + j]) sum++;
        }
        // cout << sum << "\n";
        ans = min(ans, sum);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3632
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int n,a[1 << 17],b[1 << 17],ans;

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i] >> b[i];
	}
	for(int i = n;i >= 1;i--)
	{
		a[i] += ans;
		ans += (b[i] - (a[i] % b[i])) % b[i];
	}
	rc(ans);
}


Measured memory_bytes: 1792
/*input
1010101010
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> v;

int main()
{
	IOS;
	string s;
	cin>>s;
	int n=SZ(s);
	bool flag=1;
	if(s[n-1]=='1') flag=0;
	for(int i=0,j=n-2;i<j;i++,j--){
		if(s[i]!=s[j]) flag=0;
	}	
	if(s[0]=='0') flag=0;

	if(!flag){
		cout<<"-1\n";
		return 0;
	}

	for(int i=1;i+i+2<=n;i++){
		if(s[i]=='1') v.pb(i+1);
	}
	int pre=0;
	int pt=SZ(v)+2;

	REP(i,SZ(v)) cout<<i+1<<' '<<i+2<<'\n';

	REP(i,SZ(v)){
		pre++;
		while(pre<v[i]){
			cout<<i+1<<' '<<pt<<'\n';
			pt++;
			pre++;
		}
	}
	while(pt<=n){
		cout<<SZ(v)+1<<' '<<pt<<'\n';
		pt++;
	}

	return 0;
}


Measured memory_bytes: 1868
def main():
  N=int(input())
  A=list(map(int, input().split()))
  A=sorted(A)
  a=A[0]
  for i in range(1,N):
    if a==A[i]:
      print('NO')
      return
    else:
      a=A[i]
  print('YES')
  return

main()

Measured memory_bytes: 88916
// D - Sum of Divisors
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int N; cin>>N;
	ll s = 0;
	for(int m=1; m<=N; ++m){
		int k = N / m;
		s += (ll)k * (k+1) * m / 2;
	}
	cout<< s <<endl;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args) {
		B();
	}
	
	public static void A() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int ret  = 0;
		for(int i=0;i<s.length();i++) {
			ret += Character.getNumericValue(s.charAt(i));
		}
		System.out.println(ret);
	}
	
	//0...M   2^M > 最小の要素 の範囲で 2^kで全て割り切れるかで２分探索 O(Nloglogminval)
	// 0...Mまで順に確かめると、O(Nlogminval)
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
  		}
		int maxdo = -1;
		boolean cansep = true;
		while(cansep) {
			maxdo++;
			for(int j=0;j<A.length;j++) {
				int sep = (int) Math.pow(2, maxdo);
				if(A[j]%sep != 0) {
					cansep = false;
					break;  
				}
			}
		}
		System.out.println(maxdo-1);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long

int32_t main() {
	_ __

#ifdef LOCAL_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i < n; i++) {
		int val = (n + i - 1) / i - 1;
		ans += val;
	}
	cout << ans << "\n";


#ifdef LOCAL_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 3648
/**
 *      AGC 23 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-11 01:40:56
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int A[N] = {};
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    ll s[N] = {};      // 累積和
    s[0] = A[0];
    for (int i = 1; i < N; ++i) {
        s[i] = A[i] + s[i - 1];
    }

    sort(s, s + N);

    ll answer = 0;     // 配列の連続する同じ要素に対する操作：tourist のコードから拝借
    int begin = 0;

    for (int i = 0; i < N; ++i) {
        if (s[i] == 0){
            ++answer;
        }
    }

    while (begin < N){
        int end = begin;
        while (end + 1 < N && s[end + 1] == s[begin]){
            ++end;
        }
        ll len = end - begin + 1;
        answer += len * (len - 1) / 2;
        begin = end + 1;
    }
    cout << answer << endl;


    return 0;
}

Measured memory_bytes: 2560
#include <string>
#include <iostream>
#include <vector>
#include <algorithm> 
using namespace std;
int main()
{
  int c=0,n=0;
  string s;
  cin>>s;
  n=s.length();
  for(int i=0;i<n/2;i++)
  {
    if(s[i]!=s[n-i-1])
      c++;
  }
  cout<<c;
  
  return 0;
  
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())

# 1_indexにする
dist = [-1] * (n + 1)
roots = [[] for i in range(n + 1)]

for i in range(m):
    a, b = map(int, input().split())
    roots[a].append(b)
    roots[b].append(a)

ans = [-1] * (n + 1)
ans[1] = 0
dist[1] = 0
q = deque()
q.append(1)

while q:
    now = q.popleft()

    for next_v in roots[now]:
        if not dist[next_v] == -1:
            continue
        dist[next_v] = dist[now] + 1
        ans[next_v] = now
        q.append(next_v)

if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in range(2, len(ans)):
        print(ans[i])


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

int main() {
  int a, b;
  cin >> a >> b;
  if (0 < a) cout << "Positive" << endl;
  else if (a <= 0 && 0 <= b) cout << "Zero" << endl;
  else {
    if ((b - a) % 2) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }
}

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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

#define ALL(x) x.begin(),x.end()

#define P pair<ll,ll>

#define F first

#define S second

#define VEC vector

#define V VEC<ll>

signed main(){

  ll N,i,res,ans=0;cin>>N;V A(N,0);

  REP(i,N-1){cin>>res;A.at(res-1)++;}

  REP(i,N)cout<<A.at(i)<<endl;

  return 0;

}

Measured memory_bytes: 4840
#include <iostream>
#include <vector>
using namespace std;
const long long mod=1e9+7;
int main(){
	long long n,k,i,j;
	cin >> n >> k;

	vector< vector<long long> > v(2001);
	for(i=0; i<v.size(); i++){
		vector<long long> vv(2001,0);
		vv[0]=1;
		vv[i]=1;
		v[i]=vv;
	}
	for(i=1; i<v.size(); i++){
		for(j=1; j<i; j++){
			v[i][j]=(v[i-1][j-1]+v[i-1][j])%mod;
		}
	}

	for(i=1; i<=k; i++){
		long long ans;
		long long ab,cd;
		ab=v[k-1][i-1]%mod;
		cd=v[n-k+1][i]%mod;
		ans=ab*cd;
		ans%=mod;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define LL               long long
#define PB               push_back
using namespace std;

int main() {
    int k;
    cin >> k;
    for (LL i=1,n= 7%k; i<=1e7; n=(n*10+7)%k,i++) {
        if (n==0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> h(n);
  rep (i, n) cin >> h[i];
  int  mini = 0;
  bool ok = true, done = false;
  rep (i, 0, n) {
    if (h[i] >= mini) {
      mini = h[i];
      if (h[i] > mini) done = false;
    } else {
      if (h[i] == mini - 1) continue;
      ok = false;
      break;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;


void ABC075D()
{
	int N, K;
	cin >> N >> K;
	vector<pair<ll, ll> > pt;
	vector<ll> x;
	vector<ll> y;
	for (int i = 0; i < N; ++i)
	{
		int a, b;
		cin >> a >> b;
		pt.push_back({ a,b });
		x.push_back(a);
		y.push_back(b);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	ull maxS = 10000000000000000000LL;
	for (int i1 = 0; i1 < N; ++i1)
	{
		for (int i2 = i1 + 1; i2 < N; ++i2)
		{
			for (int j1 = 0; j1 < N; ++j1)
			{
				for (int j2 = j1 + 1; j2 < N; ++j2)
				{
					ull S = (x[i2] - x[i1]) * (y[j2] - y[j1]);
					if (S >= maxS)
						continue;
					int ct = 0;
					for (int k = 0; k < N; ++k)
					{
						if (pt[k].first >= x[i1] && pt[k].first <= x[i2] && pt[k].second >= y[j1] && pt[k].second <= y[j2])
							++ct;
						if (ct >= K)
							break;
					}
					if (ct >= K)
						maxS = S;
				}
			}
		}
	}
	cout << maxS << endl;
}
int main()
{
	ABC075D();
	return 0;
}

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


int main() {
   int N;
   cin >> N;
  vector<int> vec(N);
  for(int i = 0;i < N; i++){
    cin >> vec.at(i);
  }
  
  bool have = true;
  for(int i = 0;i < N; i++){
    if(vec.at(i) % 2 == 0){
      if(vec.at(i) % 3 != 0 && vec.at(i) % 5 != 0){
      have = false;
    }
    }
  }
  
  if(have){
    cout << "APPROVED";
  }
  else{
    cout << "DENIED";
  }
  
  return 0;
}

Measured memory_bytes: 256
INF = int(1e9) + 7
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

dp = [[INF] * w for i in range(h)]
if s[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0
#print(dp)

for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            continue
        val1 = dp[i-1][j]
        if s[i][j] == '#' and s[i-1][j] == '.':
            val1 += 1
        val2 = dp[i][j-1]
        if s[i][j] == '#' and s[i][j-1] == '.':
            val2 += 1
        dp[i][j] = min(val1, val2)
        #print(i, j,val1, val2)
print(dp[h-1][w-1])
#print(dp)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1,x2,y1,y2;
  cin >> x1 >>y1 >>x2 >>y2;
  if(x1>x2 && y1>y2){
    cout <<x2+(y1-y2)<<" "<< y2-(x1-x2)<<" "<< x1+(y1-y2)<< " " << y1-(x1-x2);
  }else if(x1>x2 && y1<y2){
    cout << x2-(y2-y1) <<" "<< y2-(x1-x2) <<" "<< x1-(y2-y1) <<" "<< y1-(x1-x2);
  }else if(x1<x2 && y1>y2){
    cout << x2+(y1-y2) << " "<< y2+(x2-x1) <<" " << x1+(y1-y2) <<" "<< y1+(x2-x1);
  }else{
    cout << x2-(y2-y1) <<" "<< y2+(x2-x1)<<" " << x1+-(y2-y1)<<" " << y1+(x2-x1);
  }
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    string s;
    cin >> s;
    string ans = "";
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A') ans += 'T';
        if (s[i] == 'T') ans += 'A';
        if (s[i] == 'C') ans += 'G';
        if (s[i] == 'G') ans += 'C';
    }

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

Measured memory_bytes: 256
n = int(input())
S = input()
e_sum = [0] * n
w_sum = [0] * n
ew_sum = [0] * n
for i in range(2, n + 1):
    e_sum[-i] = e_sum[-i + 1] + 1 if S[-i + 1] == 'E' else e_sum[-i + 1]
    ew_sum[-i] = e_sum[-i]
for i in range(1, n):
    w_sum[i] = w_sum[i - 1] + 1 if S[i - 1] == 'W' else w_sum[i - 1]
    ew_sum[i] += w_sum[i]

print(min(ew_sum))


Measured memory_bytes: 29500
n,l=map(int,input().split())
if l <= 0 and l+n-1 >= 0:
  ate=0
elif l > 0:
  ate=l
else: # l+n-1 < 0
  ate=l+n-1
  
print((l-1)*n+n*(n+1)//2-ate)

Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int ans = 0;
	vector<int> x(3);
	FOR(i, 3)cin >> x[i];
	SORT(x);
	if (x[0] % 2 != x[1] % 2) {
		x[0]++;
		x[2]++;
		ans++;
	}
	ans += (x[2] * 2 - x[0] - x[1]) / 2;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long Sum[1 << 16];
long A[256];
long DP[1 << 16];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			A[i * 16 + j] = rei();
		}
	}
	for(int i=1;i<1<<16;i++){
		for(int j=0;j<16;j++){
			if(i & (1 << j)){
				long sum = Sum[i - (1 << j)];
				for(int k=0;k<N;k++){
					if(i & (1 << k)){
						sum += A[j * 16 + k];
					}
				}
				Sum[i] = sum;
				break;
			}
		}
	}
	for(int i=1;i<1<<N;i++){
		long ans = Sum[i];
		for(int j=(i-1) & i;j>0;j=(j-1) & i){
			ans = max(ans,DP[i-j]+Sum[j]);
		}
		DP[i] = ans;
	}
	cout << DP[(1 << N) - 1] << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  string s;
  int i, cntn = 0, cnts = 0, cnte = 0, cntw = 0;
  cin >> s;
  
  for(i = 0; i < s.size(); i++)
  {
    if(s.at(i) == 'N') 
    {
        cntn++;
    }
    else if(s.at(i) == 'S')
    {
        cnts++;
    }
    else if(s.at(i) == 'E')
    {
        cnte++;
    }
    else cntw++;
  }
  
  if ((cntn == 0 && cnts != 0) || (cntn != 0 && cnts == 0) || 
      (cnte == 0 && cntw != 0) || (cnte != 0 && cntw == 0))
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int izryt(char* formula, int x)
{
    int num[3] = {0};
    int cnt = 0;
    int i;

    for (i = 0; formula[i]; ++i){
        if (formula[i] == '+' || formula[i] == '=') ++cnt;
        else if (formula[i] == 'X'){
            if (!num[cnt] && (isdigit(formula[i + 1]) || formula[i + 1] == 'X') && !x) return 0;
            num[cnt] = num[cnt] * 10 + x;
        }
        else num[cnt] = num[cnt] * 10 + formula[i] - '0';
    }

    return num[0] + num[1] == num[2];
}

int main(void)
{
    char formula[128];

    while (~scanf("%s", formula)){
        int i;

        for (i = 0; i < 10; ++i){
            if (izryt(formula, i)){
                printf("%d\n", i);
                break;
            }
        }
        if (i == 10) puts("NA");
    }

    return 0;
}

Measured memory_bytes: 552
program AGC025A
    implicit none
    integer(8)::N,A,B,i,ans,dig
    read*,N
    ans=9999999

    do i=1,N-1
        A=i
        B=N-i
        dig=0
        do
            dig=dig+mod(A,10)
            A=A/10
            if(A==0)exit
        end do

        do
            dig=dig+mod(B,10)
            B=B/10
            if(B==0)exit
        end do
        ans=min(ans,dig)
    end do

    print'(i0)',ans
end program AGC025A

Measured memory_bytes: 640
s = [0, 0, 0]
loop = int(raw_input())
for i in range(loop):
    w1, w2 = raw_input().split()
    tmp = 1 - cmp(w1, w2)
    if tmp == 1:
        s[0] += 1
        s[2] += 1
    else:
        s[tmp] += 3
print s[0], s[2]

Measured memory_bytes: 4240
import itertools

N,C =map(int,input().split())
D = [0]+[[0]+list(map(int,input().split())) for i in range(C)]

c = [list(map(int,input().split())) for i in range(N)]

grids = [[],[],[]]#振り分ける
for i in range(N):
    for j in range(N):
        grids[(i+j)%3].append(c[i][j])

iwa = [[0]*(C+1) for i in range(3)]#grids[i]を色jにした時の違和感

for i in range(3):
    for j in range(1,C+1,1):
        for k in range(len(grids[i])):
            iwa[i][j]+=D[grids[i][k]][j]

ans = float("inf")
for bits in itertools.permutations(list(range(1,C+1)),3):
    tmpans = 0
    for i in range(3):
        tmpans +=iwa[i][bits[i]]
    ans = min(tmpans,ans)

print(ans)

Measured memory_bytes: 13668
#include <iostream>
#include <vector>
using namespace std;
const int HMAX = 11000;
const int NMAX = 1100;
#define INF 100000000

int dp[NMAX][HMAX];

int main() {
    int H, N;
    cin >> H >> N;

    vector<int> A, B;
    int a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }

    // DP初期条件: dp[i][0] = 0
    for (int i = 0; i < NMAX; ++i) for (int h = 0; h < HMAX; ++h) dp[i][h] = INF;
    for (int i = 0; i <= N; ++i) dp[i][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int h = 0; h < HMAX; ++h) {
            dp[i + 1][h] = min(dp[i + 1][h], dp[i][h]);
            if (h >= A[i]) dp[i + 1][h] = min(dp[i + 1][h], dp[i + 1][h - A[i]] + B[i]);
        }
    }

    int i = H;
    int ans = INF;
    while (i < HMAX) {
        ans = min(ans, dp[N][i]);
        i += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 47488