akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        int w = sc.nextInt();
     	int h = sc.nextInt();
        int n = sc.nextInt();
        int x[] = new int[n];
        int y[] = new int[n];
        int a[] = new int[n];
        int ans;
        int yoko0 = 0,yoko = w,tate0 = 0,tate = h; 
        for(int i = 0;i < n; i++){
          x[i] = sc.nextInt();
          y[i] = sc.nextInt();
          a[i] = sc.nextInt();
        }
        
      
        for(int i = 0;i < n;i++){
        	if(a[i] == 1 && yoko0 < x[i]){
              yoko0 = x[i];
            }else if(a[i] == 2 && yoko > x[i]){
              yoko = x[i];
            }else if(a[i] == 3 && tate0 < y[i]){
              tate0 = y[i];
            }else if(a[i] == 4 && tate > y[i]){
              tate = y[i];
            }
        }
        ans = (yoko - yoko0) * (tate - tate0);
        if(yoko0 > yoko || tate0 > tate){ans = 0;}
        System.out.println(ans);
    }
}

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

signed main(){
	int n,k;cin>>n>>k;
	vector<int> x(n),y(n);
	vector<char> c(n);
	rep(i,n)cin>>x[i]>>y[i]>>c[i];
	rep(i,n){
	x[i]%=2*k;
	y[i]%=2*k;
	if(c[i]=='B')(x[i]+=k)%=2*k;
	}
	vector<vector<int>>s(4*k+10,vector<int>(4*k+10,0));
	rep(i,n){
		s[x[i]+1][y[i]+1]++;
		s[x[i]+2*k+1][y[i]+1]++;
		s[x[i]+1][y[i]+2*k+1]++;
		s[x[i]+2*k+1][y[i]+2*k+1]++;
	}

	rep(i,4*k+1)rep(j,4*k+1)s[i+1][j]+=s[i][j];
	rep(i,4*k+1)rep(j,4*k+1)s[i][j+1]+=s[i][j];
	int ret=0;
	rep(i,2*k)rep(j,2*k){ret=max(ret,s[i+k][j+k]-s[i+k][j]-s[i][j+k]+s[i][j]+s[i+2*k][j+2*k]-s[i+k][j+2*k]-s[i+2*k][j+k]+s[i+k][j+k]);}
	cout<<ret<<endl;
}


Measured memory_bytes: 127744
import Control.Applicative

main = do
  [w,h,x,y,r] <- map read . words <$> getLine
  putStrLn $ yesOrNo [w,h,x,y,r]

yesOrNo :: [Int] -> [Char]
yesOrNo [w,h,x,y,r]
  |x - r < 0 = "No"
  |x + r > w = "No"
  |y - r < 0 = "No"
  |y + r > h = "No"
  |otherwise = "Yes"

Measured memory_bytes: 3652
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    for(int i = 1; i <= a; i++){
      int x = i;
      if(x % 3 == 0 || x % 10 == 3 || x / 10 == 3) System.out.print(" " + i);
      else{
        while(x != 0) {
          x /= 10;
          if(x % 10 == 3) {
            System.out.print(" " + i);
            break;
          }
        }
      }
    }
    System.out.println("");
  }
}

Measured memory_bytes: 28692
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():
    a, b = LI()
    ans = 0
    b -= 1
    while b > 0:
        b -= a - 1
        ans += 1
    print(ans)

    return

#C
def C():
    n = II()
    h = LI()
    i = 0
    ans = 0
    while i < n:
        down = i+1
        while down < n:
            if h[down - 1] >= h[down]:
                down += 1
            else:
                break
        ans = max(ans, down - i - 1)
        i = down
    print(ans)
    return

#D
def D():
    n = II()
    print(n * (n - 1) // 2)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			long cnt = 0;
			for (int i = 0; i < s.length() / 2; i++) {
				if (s.charAt(i) != s.charAt(s.length() - i - 1)) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
	}
}


Measured memory_bytes: 21844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,k;
  cin >> n >> k;
  
  cout << min(n%k, k-n%k) << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll c[51][51];
void comb_table(int n) {
  for (int i = 0; i <= n; i++) {
    c[i][0] = 1LL;
    c[i][i] = 1LL;
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
}
int main(void) {
  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<ll>());
  double sum = 0.0;
  for (int i = 0; i < a; i++) {
    sum += v[i];
  }
  cout.precision(20);
  cout << sum / a << endl;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == v[a - 1]) {
      cnt1++;
      if (i < a) {
        cnt2++;
      }
    }
  }
  comb_table(n);
  ll ans = 0LL;
  if (cnt2 != a) {
    ans = c[cnt1][cnt2];
  } else {
    for (int i = a; i <= b; i++) {
      ans += c[cnt1][i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll N;
  cin >> N;
  string ans;
  while (N) {
    N--;
    ans += char('a' + N % 26);
    N /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stack>
#include <utility>
#include <string>
using namespace std;

string area;
int main(){
	while(cin >> area){
		stack<pair<int,int> > result;
		stack<int> lake;
		for(int i=0;i<area.size();i++){
			if(area[i]=='\\'){
				lake.push(i);
			}
			if(area[i]=='/'){
				if(!lake.empty()){
				int lake_start = lake.top();
				lake.pop();
				int square = i-lake_start-1+1;	//面積を計算
				if(!result.empty()){	//水面が隠れているか判定
					pair<int,int> late = result.top();
					while(lake_start<late.first){	//隠れているなら
						result.pop();	//消去
						square += late.second;	//面積を追加
						if(!result.empty()){ 	//まだ調べるか？
							late = result.top();
						}
						else{	//while文止める用
							late = make_pair(lake_start,0);
						}
					}
				}
				pair<int,int> result0;
				result0 = make_pair(lake_start,square);
				result.push(result0);
				}
			}
		}
		int k = result.size();
		stack<int> square_result;
		int sum = 0;
		if(result.empty()){ //水たまりが0個
			cout << 0 << endl;
			cout << 0 << endl;
		}else{
			while(!result.empty()){
				pair<int,int> a = result.top();
				result.pop();
				int square_part = a.second;
				square_result.push(square_part);
				sum += square_part;
			}
			cout << sum << endl;
			cout << k << " ";
			while(square_result.size()!=1){
				int s = square_result.top();
				square_result.pop();
				cout << s << " ";
			}
			int s = square_result.top();
			cout << s << endl;
		}
	}
}

#if 0
所要時間が考察を自力で1時間，テキストのヒントを見てから実装，バク取りしてACまで100分程度。おおまかな方針の理解は
早かったと思うが，実装，特に隠れている水たまりを消去する部分に苦戦した。また，stackが空なのにtop
しようとするなどバグを取るのも大変だった。実装方針に問題があったのだろうか(コードも長くなった)。
#endif


Measured memory_bytes: 3320
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))


a, b, c = na()
if (c - a - b)**2 - 4*a*b > 0 and (c - a - b) > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int Y = scan.nextInt();
		int sum = 0;

		for (int i = 0; i < 2; i++) {

			if (X >= Y) {

				sum += X;
				X = X - 1;

			} else {

				sum += Y;
				Y = Y - 1;
			}

		}

		
		System.out.println(sum);
		
	}

}


Measured memory_bytes: 23252
D, G = [int(n) for n in input().split(' ')]

p = []
c = []
for _ in range(D):
    temp = [int(n) for n in input().split(' ')]
    p += [temp[0]]
    c += [temp[1]]

ans = 10**9
for flag in range(1<<D):
    score = 0
    cnt = 0
    
    for i in range(D):  # コンプリートボーナス
        if flag & 1<<i:
            score += c[i] + 100*(i+1)*p[i]
            cnt += p[i]
            
    if score >= G:
        if cnt < ans:
            ans = cnt
    
    for i in range(D, 0, -1):
        if flag & 1<<(i-1):
            continue    
        for n in range(p[i-1]):
            score += 100*i
            cnt += 1
            if cnt == 3:
                pass
            if score >= G:
                if cnt < ans:
                    ans = cnt

print(ans)



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    cin >>N;
    if(N<105){
        cout <<0<<endl;
    }
    if(N>=105 &&N<135){
        cout <<1<<endl;
    }
  	if(N>=135 &&N<165){
        cout <<2<<endl;
    }
    if(N>=165 &&N<189){
        cout <<3<<endl;
    }
  	if(N>=189 &&N<195){
      cout<<4<<endl;
    }
  	if(N>=195){
      cout<<5<<endl;
    }
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1e9 +7;
ll fact[202020], frev[202020];//階乗,逆元
ll C(int p, int q)
{
	if (q < 0 || p < q) return 0;
	return fact[p] * frev[q] % MOD * frev[p - q] % MOD;
}
ll modpow(ll a, ll b) {//a^b%mod
	ll res = 1;
	for (; b > 0; a = a * a % MOD, b /= 2) if (b & 1) res = res * a % MOD;
	return res;
}
int main(){
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	fact[0] = frev[0] = 1;
	for (int i = 1; i <= 200000; ++i) {
		fact[i] = (fact[i - 1] * i) % MOD;
		frev[i] = modpow(fact[i],MOD-2);
	}
	ll ans=0;
	for(int i=0;i<=min(h-a,w-b)-1;i++){
		ans=(ans + (C(h-a+b-1,b+i)*C(w-b+a-1,a+i))%MOD)%MOD;
	}
	cout<<ans<<endl;
	
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;cin>>n;

	vector<double> v(n);
	double sum=0.0;
	for(int i=0; i<n; i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());


	sum = (v[0]+v[1])/2;

	for(int i=2; i<n; i++){
		sum = (sum+v[i])/2;
	}

	printf("%0.10f",sum);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<int, int>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    cout << (d2 == 1) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

int f[100000];
vector <int> v[100000];

int dfs(int x, int y) {
    int c = 0, i;
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        
        c += dfs(v[x][i], x);
    }
    
    if (c > 1) {
        puts("First");
        
        exit(0);
    }
    
    return f[x] = 1 - c;
}

void dfs2(int x, int y, int z) {
    int i;
    
    if (f[x] == 0 && z == 1) {
        puts("First");
        
        exit(0);
    }
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        
        if (f[x] == 1 || f[v[x][i]] == 1) {
            dfs2(v[x][i], x, 1 - z);
        } else {
            dfs2(v[x][i], x, 0);
        }
    }
}

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    dfs(0, -1);
    dfs2(0, -1, 0);
    
    puts("Second");
    
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
constexpr int inf{ numeric_limits<int>::max() / 3 };
int K, dist[100001];
int main() {
    cin >> K;
    fill_n(dist, 100001, inf);
    using P = pair<int, int>;
    deque<P> d;
    dist[1] = 1;
    d.emplace_back(1, 1);
    while(d.size()) {
        int w, n;
        tie(w, n) = d.front(); d.pop_front();
        if(dist[n] < w) continue;
        int m{ (n + 1) % K };
        if(dist[m] > w + 1)
            dist[m] = w + 1, d.emplace_back(w + 1, m);
        m = (n * 10) % K;
        if(dist[m] > w)
            dist[m] = w, d.emplace_front(w, m);
    }
    cout << dist[0] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define loop(i,a,b) for(i=a;i<b;i++)
#define mod   998244353
#define INF 1000000000000
#define pb push_back
#define lim 200001
using namespace std;

int main()
{ll i,j,n,s=0;
	cin>>n;
	ll a[n];

	loop(i,0,n) {
		cin>>a[i];
	}

	ll cnt=2;i=n-2;
	sort(a,a+n);
	s=a[n-1];

	while(cnt<n)
	{
		ll rem=min((ll)2,n-cnt);

		s+=rem*a[i];
		cnt+=rem;
		i--;
	}


	cout<<s<<endl;
	return 0;}


Measured memory_bytes: 5208
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;


int main(){
	int N,M,A,B,ok[200001]={};
	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>A>>B;
		if(A==1){
			ok[B]++;
		}
		if(B==N){
			ok[A]++;
		}
	}
	for(int i=1;i<=N;i++){
		if(ok[i]==2){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}

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

int main() {
  ll N,Y;
  cin >> N >> Y;
  Y /= 1000;
  bool flag = false;
  for(ll yukiti = 0;yukiti<=N;yukiti++){
    for(ll itiyou = 0;itiyou <= N-yukiti;itiyou++){
      ll hideyo = N-yukiti-itiyou;
      if(yukiti*10+itiyou*5+hideyo == Y){
        flag = true;
        cout << yukiti << " " << itiyou << " " << hideyo << endl;
        break;
      }
    }
    if(flag){
      break;
    }
  }
  if(!flag){
    cout << "-1 -1 -1" << endl;
  }
}
    

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

#define N 100123
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

bool vis[N];
vector<int> adj[N];

void dfs(int u){
	vis[u] = true;
	for(auto i : adj[u]){
		if(!vis[i]) dfs(i);
	}
}

int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.in", "r", stdin);
    //     freopen("output.out", "w", stdout);
    // #endif

    int n, u, v, m, w, ans = 0;
    cin >> n >> m;

    for(int i = 0 ; i < m ; i++){
    	cin >> u >> v >> w;
    	adj[u].pb(v);
    	adj[v].pb(u);
    }

    memset(vis, false, sizeof(vis));

    for(int i = 1; i <= n ; i++){
    	if(!vis[i]){
    		ans++;
    		dfs(i);
    	}
    }
    
    cout << ans << endl;


    return 0;
}

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

int main() {
  int k,s;
  cin>>k>>s;
  int count=0;
  rep(x,k){
    rep(y,k){
      if(s-x-y>=0 && s-x-y<=k){
        count++;
      }
    }
  }
  cout<<count<<endl;
}  
  




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

int main()
{
  string s, t, h;
  cin >> s >> t;
  int c, d;
  cin >> c >> d;
  cin >> h;
  if(s == h) {
    c--;
  } else {
    d--;
  }
  printf("%d %d", c, d);
}

Measured memory_bytes: 3692
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(){
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
 
vector < pair<int,int> > v[105];
int in[105][105],dp[105][105];
 
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
 
    int N,M,n,m,i,j,C,a,b,c;
    while(scanf(" %d %d %d",&N,&M,&C)==3 && (M+N+C)){
        for(n=1;n<=N;n++)
            v[n].clear();
        for(m=0;m<M;m++){
            scanf(" %d %d %d",&a,&b,&c);
            v[a].push_back(make_pair(b,c));
        }
        memset(in,0,sizeof(in));
        queue <int> q;
        for(i=0;i<105;i++)
            for(j=0;j<105;j++)
                dp[i][j] = 1e9;
        q.push(1);
        q.push(0);
        dp[1][0] = 0;
        while(!q.empty()){
            int now = q.front();    q.pop();
            int cnt = q.front();    q.pop();
            in[now][cnt] = 0;
            /*if(now==10 && cnt==0){
                printf("==%d\n",dp[N][cnt]);
            }*/
            if(now==N)
                continue;
            if(cnt==N)
                continue;
            for(i=0;i<v[now].size();i++){
                if(dp[now][cnt] + v[now][i].second < dp[v[now][i].first][cnt]){
                    dp[v[now][i].first][cnt] = dp[now][cnt] + v[now][i].second;
                    //printf("-> %d %d %d\n",v[now][i].first,cnt,dp[v[now][i].first][cnt]);
                    if(in[v[now][i].first][cnt] == 0){
                        in[v[now][i].first][cnt] = 1;
                        q.push(v[now][i].first);
                        q.push(cnt);
                    }
                }
                if(dp[now][cnt] < dp[v[now][i].first][cnt+1]){
                    dp[v[now][i].first][cnt+1] = dp[now][cnt];
                    //printf("==> %d %d %d\n",v[now][i].first,cnt+1,dp[v[now][i].first][cnt+1]);
                    if(in[v[now][i].first][cnt+1] == 0){
                        in[v[now][i].first][cnt+1] = 1;
                        q.push(v[now][i].first);
                        q.push(cnt+1);
                    }
                }
            }
        }
        //printf("N = %d %d\n",N,dp[N][0]);
        for(i=0;i<=N;i++)
            if(dp[N][i] <= C)
                break;
        printf("%d\n",i);
    }
 
    return 0;
}

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

int main() {

  int N;
  cin >> N;

  int a[N];

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

  // ----------

  int lighted[N];

  int lighting = 1;
  int cnt = 0;

  int flg = 1;

  while (flg == 1) {

	int next_light = a[lighting-1];


	lighted[cnt] = lighting;

	lighting = next_light;
	cnt++;

	if (lighting == 2) {
	  flg = 2;
	}

	if (cnt > N) {
	  flg = 3;
	}
  }

  if ( flg == 2 ) {
	cout  << cnt << endl;
  } else if ( flg == 3 ) {
	cout << "-1" << endl;
  }	  
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int i;
    int j;

    // 整数の入力
    scanf("%d", &i);
    
    if (i % 2 == 0)
        printf("%d\n", i / 2);
    else
        printf("%d\n", i / 2 + 1);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(ll i=(x);i<=(y);i++)
#define FDW(i,x,y) for(ll i=(x);i>=(y);i--)
#define MAXN 300010
#define INF 0x7fffffff
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
ll read(){
    ll w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x<y?x:y;}
ll abs(ll x){return x<0?(-x):x;}
ll n,x,a[MAXN],m,cnt[100][2],base=1,ans;
int main(){
	n=read();
	FUP(i,1,n)
	{
		x=read();
		a[i]=x;
		ll k=1;
		while(x)
		{
			//cnt[k][x&1]++;
			k++;
			//prllf("%d",x&1);
			x>>=1;
		}
		m=max(m,k-1);
		//puts("");
	}
	FUP(i,1,n)
	{
		FUP(j,1,m)
		{
			cnt[j][a[i]&1]++;
			a[i]>>=1;
		}
	}
	FUP(i,1,m)
	{
		//prllf("%d,%d\n",cnt[i][0],cnt[i][1]);
		cnt[i][0]=cnt[i][0]*(cnt[i][0]-1)/2;
		cnt[i][1]=cnt[i][1]*(cnt[i][1]-1)/2;
		//prllf("%d,%d,%d\n",cnt[i][0],cnt[i][1],n*(n-1)/2-cnt[i][0]-cnt[i][1]);
		ans=(ans+(n*(n-1)/2-cnt[i][0]-cnt[i][1])%MOD*base%MOD)%MOD;
		
		base*=2;
		base%=MOD;
	}
	printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
int main()
{
    int n,m,a[100009],flag=1;
    long long dp[100009],ans,mod=(long long)(1000000007);
    dp[0]=1;
    dp[1]=1;
    dp[2]=2;
    scanf("%d%d",&n,&m);
    for(int i=3; i<=100000; i++)
        dp[i]=(dp[i-1]+dp[i-2])%mod;
    for(int i=1; i<=m; i++)
        scanf("%d",&a[i]);
    if(!m)
    {
        printf("%lld",dp[n]);
        return 0;
    }
    ans=dp[a[1]-1];
    for(int i=2; i<=m; i++)
    {
        ans=(ans*(dp[a[i]-a[i-1]-2]))%mod;
        if(a[i]-a[i-1]<2)
        {
            flag=0;
            break;
        }
    }
    if(!flag)
    {
        printf("0");
        return 0;
    }
    ans=(ans*(dp[n-a[m]-1]))%mod;
    printf("%lld",ans);
    return 0;
}


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

int main() {
    ll n, a[5];
    cin >> n;
    n--;
    rep(i, 5) cin >> a[i];

    ll ans = n / *min_element(a, a + 5) + 5;

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


Measured memory_bytes: 256
use proconio::{fastout, input};

fn pow(mut x: u64, mut y: u64, z: u64) -> u64 {
    let mut r = 1;
    while y > 0 {
        if y & 1 == 1 {
            r = r * x % z;
        }
        x = x * x % z;
        y >>= 1;
    }
    r
}

#[fastout]
fn main() {
    let inv = |x| pow(x, M - 2, M);
    input! {
        s: u64,
    }
    const M: u64 = 1_000_000_007;
    let mut f = vec![1; 10_000];
    for i in 1..f.len() {
        f[i] = f[i - 1] * i as u64 % M;
    }
    let mut ans = 0;
    for k in 1..=s / 3 {
        let t = s - k * 3;
        let sub = f[(t + (k - 1)) as usize] * inv(f[(k - 1) as usize]) % M * inv(f[t as usize]) % M;
        ans += sub;
        ans %= M;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2276
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n){
    cout << (n + 1) / 2 << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define reb(i, a, b) for (ll i = a; i >= (b); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
ll ch[3002][3002];
string ans;
void lcs(string s, string t)
{
   rep(x, 0, s.size())
   {
      rep(y, 0, t.size())
      {
         ll i = x + 1;
         ll j = y + 1;
         if (s[x] == t[y])
         {
            ch[i][j] = ch[i - 1][j - 1] + 1;
         }
         else
         ch[i][j] = max(ch[i - 1][j], ch[i][j - 1]);
      }
   }
}
void printlcs(string s, string t)
{
   int i = s.size(), j = t.size();
   while (i > 0 && j > 0)
   {
      if (s[i-1] == t[j-1])
      {
         ans=s[i-1]+ans;
         i--;
         j--;
      }
      else
      {
         if (ch[i - 1][j] > ch[i][j - 1])
            i--;
         else
         {
            j--;
         }
      }
   }
  cout<<ans;
}
int main()
{
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif
   rep(i, 0, 3002)
   {
      ch[i][0] = 0;
      ch[0][i] = 0;
   }
   string s, t;
   cin >> s >> t;
   lcs(s, t);
//   rep(i,0,s.size()+1)
//   {
//       rep(j, 0, t.size() + 1)
//               cout
//           << ch[i][j] << " ";
//       cout << endl;
//   }
   printlcs(s, t);
}

Measured memory_bytes: 70656
n = input()
if n[0] == n[1] and n[1] == n[2] and n[2] == n[0]:
    print(n)
else:
    n1 = int(n)
    n_tmp = int(n[0])
    n2 = n_tmp*100 + n_tmp*10 + n_tmp
    n3 = (n_tmp+1)*100 + (n_tmp+1)*10 + n_tmp+1
    if n2 >= n1:
        print(n2)
    else:
        print(n3)


Measured memory_bytes: 3060
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = map(int, input().split())

a.sort()
b.sort()
c.sort()

ans = 0
a = [0]+a
c = c+[10**10]
ai, ci = 0, 0
for i in range(n):
    while ai < n and a[ai+1] < b[i]:
        ai += 1
    while ci < n and c[ci] <= b[i]:
        ci += 1
    ans += ai*(n-ci)
print(ans)


Measured memory_bytes: 108952
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int a,b,x;
  cin>>x>>a>>b;
  x-=a;
  x%=b;
  ou(x);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21588
n = int(input())
s = [input() for i in range(n)]

ac=0
wa=0
tle=0
re=0
for x in s:
    if x == "AC":
        ac += 1
    elif x == "WA":
        wa += 1
    elif x == "TLE":
        tle += 1
    elif x == "RE":
        re += 1
        
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N,K;
  cin>>N>>K;

  if(N<=K){
    cout<<0<<endl;
    return 0;
  }

  priority_queue<long long> pque;

  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    pque.push(x);
  }

  for(int i=0;i<K;i++){
    pque.pop();
  }

  long long ans=0;

  while (!pque.empty()) {
    ans += pque.top();
    pque.pop();
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 2420
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		 int n = sc.nextInt();
	        int[] x = new int[n];
	        int[] y = new int[n];
	        for (int i = 0 ; i < n ; i++) {
	            x[i] = sc.nextInt();
	            y[i] = sc.nextInt();
	        }
	        double sum = 0;
	 
	        for (int i = 0 ; i < n ; i++) {
	            for (int j = i ; j < n ; j++) {
	                sum += Math.sqrt(Math.pow(x[i] - x[j], 2) + Math.pow(y[i] - y[j], 2));
	            }
	        }
	 
	 
	       out.println((double) sum * 2 / n);
	    
	 
		 
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
#define test ll t;cin >> t; while(t--)
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"

    
int main()
{
   std::ios::sync_with_stdio(false);
   ll n;cin>>n;
   ll a[n][3];
   ll dp[n][3];
   rep(i,n)
   {
       rep(j,3)
       {
           cin>>a[i][j];
           dp[i][j]=inf;
       }
   }
   rep(i,3)dp[0][i]=a[0][i];
   f(i,1,n)
   {
       dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
       dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
       dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
   }
   
   cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
   
}







Measured memory_bytes: 4992
#include <stdio.h>
int n, q;
long long p = 10000000;
long long v[1024 * 256 + 1];
long long w[1024 * 256 + 1];
long long u[100000];
long long l[100000];
int s[1024];
int ss, uu;
long long e[1024];
long long ee[1024];
long long ef[1024];
long long d[1024][1024];
long long te, ans;
int ar, br;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", v + i, w + i);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld", u + i, l + i);
	}
	d[1][0] = 0;
	d[1][1] = w[1] * p + v[1];
	s[1] = 2;
	for (int i = 2; i < 1024; i++) {
		te = w[i] * p + v[i];
		ss = s[i / 2];
		for (int j = 0; j < s[i / 2]; j++) {
			e[j] = d[i / 2][j] + te;
		}
		ar = 0, br = 0;
		d[i / 2][ss] = p * p;
		e[ss] = p * p;
		while (ar < ss || br < ss) {
			if (d[i / 2][ar] < e[br]) {
				d[i][ar + br] = d[i / 2][ar];
				ar++;
			}
			else {
				d[i][ar + br] = e[br];
				br++;
			}
		}
		s[i] = 2 * ss;
		for (int j = 1; j < s[i]; j++) {
			if (d[i][j - 1] % p > d[i][j] % p) {
				d[i][j] += (d[i][j - 1] % p - d[i][j] % p);
			}
		}
	}
	for (int i = 0; i < q; i++) {
		uu = u[i];
		if (uu >= 1024) {
			ss = 1;
			e[0] = 0;
			while (uu >= 1024) {
				te = w[uu] * p + v[uu];
				for (int k = 0; k < ss; k++) {
					ee[k] = e[k];
					ef[k] = e[k] + te;
				}
				ar = 0, br = 0;
				ee[ss] = p * p;
				ef[ss] = p * p;
				while (ar < ss || br < ss) {
					if (ee[ar] < ef[br]) {
						e[ar + br] = ee[ar];
						ar++;
					}
					else {
						e[ar + br] = ef[br];
						br++;
					}
				}
				uu /= 2;
				ss *= 2;
			}
			for (int j = 1; j < ss; j++) {
				if (e[j - 1] % p > e[j] % p) {
					e[j] += (e[j - 1] % p - e[j] % p);
				}
			}
			ar = ss - 1;
			ans = 0;
			for (int j = 0; j < s[uu]; j++) {
				while (ar >= 0 && (d[uu][j] + e[ar]) / p > l[i])ar--;
				if (ar == -1)break;
				if ((d[uu][j] + e[ar]) % p > ans) {
					ans = (d[uu][j] + e[ar]) % p;
				}
			}
			printf("%lld\n", ans);
		}
		else {
			ans = 0;
			for (int j = 0; j < s[u[i]]; j++) {
				if (d[u[i]][j] / p <= l[i]) {
					if (d[u[i]][j] % p > ans) {
						ans = d[u[i]][j] % p;
					}
				}
			}
			printf("%lld\n", ans);
		}
	}
}

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

using namespace std;

int main(){

    string s;
    cin >> s;
    int tmp = 0;
    int cnt = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            tmp++;
            cnt = max(cnt,tmp);
        }else tmp = 0;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long divs = 1000000007;

int main()
{
	long n, k;
	cin >> n >> k;
	vector<int> a(n);

	long answer = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 0; j < i; j++) {
			if (a[i] < a[j]) answer = (answer + ((k * (k+1))/ 2) % divs) % divs;
			else if(a[i] > a[j]) answer = (answer + ((k * (k - 1)) / 2) % divs) % divs;
		}
	}

	cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool a,b,c;
int main(void)
{
    string s;
    int cnt=0,sum=0;
    cin >> s;
    if(s[0]=='A') a=true;
    for(int i=2;i<=s.size()-2;i++)
        if(s[i]=='C')
            cnt++;
    if(cnt==1) b=true;
    for(int i=0;i<s.size();i++)
        if(s[i]<=90)
            sum++;
    if(sum==2) c=true;
    if(a==true && b==true && c==true)
        cout << "AC";
    else
        cout << "WA";
    return 0;
}


Measured memory_bytes: 256
// wake me up, wake me up inside. I cant wake up.
// save me , save me from the nothing ive become;

#include <bits/stdc++.h>

#define s second
#define f first
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define int int64_t

using namespace std;

const int MAX=1e6+20,INF=1e9+1,mod=1e9+7;

int n,m,d,ans,a[MAX],c,b,t[MAX],dis[MAX],del,x,cnt,c2,mn2=INF,mx1=-MAX,mx2=-MAX,l,r,color,sum2,fn,mx=-1,mn=INF,k,y,z;
string s,str,sans;
//set <int> st;
//vector <pii> adj[MAX];
bool mark,ark2;
vector <int> adj[MAX];
vector<int> vec;
queue <int> q;
long double a1,a2;
map <int,int> mp;

int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};

main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for(int i=0;i<m;i++)
    {
        cin >> x >> y;
        adj[y].pb(x);
        adj[x].pb(y);
    }
    for(int i=1;i<=n;i++)
    {
        cout << adj[i].size() << '\n';
    }
}




Measured memory_bytes: 24832
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define all(A) A.begin(), A.end()
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

int A[100][100];
int B[100][100];
bool dp[100][100][40000];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, 0, H) rep(j, 0, W) cin >> A[i][j];
    rep(i, 0, H) rep(j, 0, W) cin >> B[i][j];

    rep(i, 0, H) rep(j, 0, W) rep(k, 0, 40000) dp[i][j][k] = 0;
    
    int N = (H+W) * 80;
    int d = A[0][0] - B[0][0];
    dp[0][0][d+N] = 1;
    dp[0][0][-d+N] = 1;

    rep(i, 0, H) {
        rep(j, 0, W) {
            d = A[i][j] - B[i][j];
            rep(k, 0, 40000) {
                if (i != 0) {
                    dp[i][j][k] |= dp[i-1][j][k-d] | dp[i-1][j][k+d];
                }
                if (j != 0) {
                    dp[i][j][k] |= dp[i][j-1][k-d] | dp[i][j-1][k+d];
                }
            }
        }
    }

    int ans = inf;
    
    rep(k, 0, 40000) {
        if (dp[H-1][W-1][k]) {
            ans = min(ans, abs(k-N));
        }
    }

    cout << ans << endl;    
}

Measured memory_bytes: 313600
#include <stdio.h>

static const unsigned char TABLE_BITS_COUNT[] = {
  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6
};

static const unsigned char TABLE_TRAILING_ZEROS[] = { 0, 1, 6, 2, 7, 5, 4, 3 };

static int
parse_int(int delim) {
  int neg = 0;
  int c = getc_unlocked(stdin);

  if (c == '-') {
    c = getc_unlocked(stdin);
    neg = 1;
  } else if (c == '+') {
    c = getc_unlocked(stdin);
  }

  int n = 0;
  while (c != delim && c != EOF) {
    n = (n * 10) + (c - '0');
    c = getc_unlocked(stdin);
  }

  if (neg != 0) {
    return -n;
  }

  return n;
}

static void
read_until(
  int delim,
  void (*func)(int, int, void*),
  void *args)
{
  int c = getc_unlocked(stdin);
  for (int i = 0; c != delim && c != EOF; i++) {
    func(i, c, args);
    c = getc_unlocked(stdin);
  }
}

static void
read_until_func(int i, int c, void *args) {
  unsigned char *x = args;
  if (c == '#') {
    *x |= (1 << i);
  }
}

static unsigned int
fold_bitflag(
  unsigned int  n,
  unsigned int  init,
  unsigned int  (*func)(unsigned int, unsigned int, void*),
           void *args)
{
  unsigned int flg;

  while (1) {
    flg = n & ((~n) + 1);
    if (flg == 0) {
      break;
    }
    init = func(init, flg, args);
    n ^= flg;
  }

  return init;
}

typedef struct {
  unsigned char *ary;
           int   col;
} fold_bitflag_args_t;

static unsigned int
fold_bitflag_func(
  unsigned int  acc,
  unsigned int  x,
  void *args)
{
  unsigned char *ary = ((fold_bitflag_args_t *)args)->ary;
           int   col = ((fold_bitflag_args_t *)args)->col;
  unsigned char  i   = TABLE_TRAILING_ZEROS[((x * 0x1d) >> 5) & 0x07];
  return acc + TABLE_BITS_COUNT[ary[i] & col];
}

static void
abc173_c(void)
{
  int h, w, k;
  unsigned char ary[6] = {};

  h = parse_int(' ');
  w = parse_int(' ');
  k = parse_int('\n');
  for (int i = 0; i < h; i++) {
    read_until('\n', read_until_func, &ary[i]);
  }

  unsigned int ans = 0;
  for (int row = 0; row < 1 << h; row++) {
    for (int col = 0; col < 1 << w; col++) {
      fold_bitflag_args_t args = { ary, col };
      unsigned int cnt = fold_bitflag(row, 0, fold_bitflag_func, &args);
      if (cnt == k) {
        ans += 1;
      }
    }
  }
  printf("%d\n", ans);
}

int
main(void)
{
  abc173_c();
  return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int dp[N];

void add(int &a, int b){
	a += b;
	if(a >= MOD)
		a -= MOD;
}

void sub(int &a, int b){
	a -= b;
	if(a < 0)
		a += MOD;
}

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

	dp[0] = 1;
	int val;
	for(int i = 1; i <= n; i++){
		cin >> val;
		vector<int> pref(N);
		for(int i = k; i >= 0; i--){
			int l = i + 1;
			int r = i + min(val, k - i);
			if(l <= r){
				add(pref[l], dp[i]);
				if(r + 1 <= k)
					sub(pref[r + 1], dp[i]);
			}
		}
		int sum = 0;
		for(int i = 0; i <= k; i++){
			add(sum, pref[i]);
			add(dp[i], sum);
		}
	}

	cout << dp[k] << "\n";

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int n,k;
	double a,b,ans=0;
	cin >> n >> k;

	b=1;
	rep(i,1,n){
		a=i;
		b=n;
		while(k>a){
			a = a*2;
			b = b*2;
		}
		ans += 1/b;
	}
    printf("%.12f\n",ans);
}

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


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

    for(int i=b-a+1; i<b+a; ++i){
        cout << i <<" ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
A = input()
N = len(A)
for i in range(N):
    if A[i] == "A":
        posA = A.index(A[i])
        break
p = 0
for j in range(0, N):
    if A[j] == "Z" and j > p:
        p = j
p += 1
print(len(A[posA:p]))

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define intt long long
#define pb push_back
#define mk make_pair
#define ii pair<intt,intt>
#define sc second
#define fr first
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  if(x>=13)
   cout<<y<<endl;
  else if(x>=6)
   cout<<y/2<<endl;
  else
    cout<<0<<endl;
   return 0;
}


Measured memory_bytes: 384
n, m, d = map(int, input().split())
if d == 0:
    print(1 / n * (m-1))
else:
    r = n - d
    l = 1 + d
    X = max(0, r-l+1) / n
    print((m-1) * ((1 / n) * (1-X) + (2 / n) * X))


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

int main() {
    int A, B, coins;
    std : cin >> A >> B;

    if ( abs( A - B ) == 0){
        coins = 2 * A;
    }
    else{
        coins = 2 * std::max(A, B) - 1;
    }

    cout << coins << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int n,m,k;
        cin>>n>>m>>k;
        vector<int> a(n+1),b(m+1);
        fori(i,n) cin>>a[i];
        fori(i,m) cin>>b[i];
        for(int i = 1;i <n;i++) {
            a[i] += a[i-1];
        }
        for(int i = 1; i<m; i++) {
            b[i] += b[i-1];
        }
        a[n] = 1e18;
        b[m] = 1e18;
        int ans = lower_bound(a.begin(), a.end(), k) - a.begin();
        if (a[ans] > k) ans--;
        int x = lower_bound(b.begin(), b.end(), k) - b.begin();
        if (b[x] > k) x--;
        ans = max(ans+1, x+1);
        fori(i,n) {
            if (a[i] > k) break;
            x = lower_bound(b.begin(), b.end(), k-a[i]) - b.begin();
            if(b[x] > k-a[i]) x--;
            ans = max(ans, i+1+x+1);
        }
        cout<<ans;

    }
    
    return 0;
}

Measured memory_bytes: 6368
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

long long int dp[16][16];
int gx,gy;
vector<pair<int,int> > mm[16][16];

long long int check(int x,int y)
{
  //  cout<<x<<" "<<y<<endl;
  if(x==gx&&y==gy)
    return 1;

  if(x>gx||y>gy)
    return 0;
  
  //  cout<<"dp"<<endl;
  if(dp[x][y]!=-1)
    return dp[x][y];
  
  long long int ans=0;
  //migi
  if(x+1<=gx)
    {
      bool flag=true;
      for(int i=0;i<mm[x][y].size();i++)
	{
	  if(mm[x][y][i].first==x+1 &&
	     mm[x][y][i].second==y )
	    {
	      flag=false;
	      break;
	    }
	}
      if(flag)
	ans+=check(x+1,y);
    }
  if(y+1<=gy)
    {
      bool flag=true;
      for(int i=0;i<mm[x][y].size();i++)
	{
	  if(mm[x][y][i].first==x &&
	     mm[x][y][i].second==y+1 )
	    {
	      flag=false;
	      break;
	    }
	}
      if(flag)
	ans+=check(x,y+1);
    }
    
  dp[x][y]=ans;
  return ans;

}

int main()
{
  int d;
  cin>>d;
  for(;d--;)
    {
      for(int i=0;i<16;i++)
	for(int j=0;j<16;j++)
	  mm[i][j].clear();
      memset(dp,-1,sizeof(dp));
      cin>>gx>>gy;
      int p;
      cin>>p;
      for(;p--;)
	{
	  int x1,x2,y1,y2;
	  cin>>x1>>y1>>x2>>y2;
	  mm[x1][y1].push_back(make_pair(x2,y2));
	  mm[x2][y2].push_back(make_pair(x1,y1));
	}
      long long int ans=check(0,0);
      if(ans==0)
	cout<<"Miserable Hokusai!"<<endl;
      else
	cout<<ans<<endl;
    }
}

Measured memory_bytes: 1208