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

int main() {
    int n; scanf("%d", &n);
    vector<int> u(n - 1), v(n - 1), w(n - 1);
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; ++i) {
        scanf("%d%d%d", &u[i], &v[i], &w[i]);
        u[i]--, v[i]--;
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }

    vector<int> dep(n), sz(n), mk(n);
    function<void(int, int)> Dfs = [&](int x, int p) {
        dep[x] = ~p ? dep[p] + 1 : 0;
        sz[x] = 1;
        for (int u : g[x]) {
            if (u == p) continue;
            Dfs(u, x);
            sz[x] += sz[u];
            mk[x] = max(mk[x], sz[u]);
        }
    };

    Dfs(0, -1);
    long long ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);
        int s = min(sz[v[i]], n - sz[v[i]]);
        ans += 2LL * s * w[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        int s = min(sz[v[i]], n - sz[v[i]]);
        if (s * 2 == n) {
            printf("%lld\n", ans - w[i]);
            return 0;
        }
    }
    int r = -1;
    for (int i = 0; i < n; ++i) {
        int f = max(n - sz[i], mk[i]);
        if (f * 2 <= n) r = i;
    }
    long long res = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (u[i] == r || v[i] == r) res = max(res, ans - w[i]);
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <cstring>
#define MOD 100000
using namespace std;

int w,h;
int dp[101][101][2][2];

int rec(int x,int y,bool ch1,bool ch2){
  if(x >= w || y >= h) return 0;
  if(x == w-1 && y == h-1) return 1;
  if(dp[y][x][ch1][ch2] != 0) return dp[y][x][ch1][ch2];
  int res = 0;
  if(x == 0 || y == 0 || ch1 == ch2) res = (rec(x+1,y,ch2,1) + rec(x,y+1,ch2,0))%MOD;
  else if(ch1 != ch2){
    if(ch2) res = rec(x+1,y,ch2,1)%MOD;
    if(!ch2) res = rec(x,y+1,ch2,0)%MOD;
  }
  return dp[y][x][ch1][ch2] = res;
}
  

int main(){
  while(cin >> w >> h,w||h){
    memset(dp,0,sizeof(dp));
    cout << rec(0,0,1,1) << endl;
  }
}

Measured memory_bytes: 1340
N, M = map(int, input().split())

A = []
for _ in range(N):
  a = input()
  A.append(a)

B = []
for _ in range(M):
  b = input()
  B.append(b)

start_list = []
for i, a in enumerate(A):
  if (len(A) - i < M):
    break

  s_i = a.find(B[0])
  if (s_i == -1):
    continue
  else:
    start_list.append([i, s_i])

existed = False
for sl in start_list:
  checkA = A[sl[0]:sl[0] + M]

  has_b = True
  for i, ca in enumerate(checkA):
    if (ca[sl[1]:sl[1]+M] != B[i]):
      has_b = False
      break
  
  if (has_b == False):
    continue
  else:
    existed = True
    break

result = 'Yes' if (existed == True) else 'No'
print(result)


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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int popcount(int);

int main(){
    int n,m;cin >> n >> m;
    unsigned int v= 0;
    rep(i,30) v |= 1<<i;
    rep(i,n){
        int k;cin >> k;
        unsigned int tmp = 0;
        rep(j,k){
            int a;cin >> a;
            tmp |= 1<<(a-1);
        }
        v &= tmp;
    }
    cout << popcount(v) << endl;
}

int popcount(int bits)
{
    int num;
    num = (bits >> 1) & 03333333333;
    num = bits - num - ((num >> 1) & 03333333333);  
    num = ((num + (num >> 3)) & 0707070707) % 077;

    return num;
}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int n,m;
  while(cin>>n>>m,n||m){
    int a[400000],b=0,c=0;
    for(i=0;i<n;++i){
      int p,q;
      cin>>p>>q;
      if(0){
      }else if(p==0){
	a[c]=q;
	++c;
	while(c-b>m)
	  ++b;
      }else if(p==1){
	copy(a+b+q,a+c,a+b+q-1);
	--c;
      }else if(p==2){
	cout<<a[b+q-1]<<endl;
      }else if(p==3){
	for(j=0;a[b+j]!=q;++j);
	copy(a+b+j+1,a+c,a+b+j);
	--c;
      }
    }
    cout<<"end"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
mod = 10**9+7

N = int(input())
a = 1
b = 1
c = 1
for _ in range(N):
    a *= 10
    b *= 9
    c *= 8
    a %= mod
    b %= mod
    c %= mod

ans = (a -2*b + c)%mod
print(ans)

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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int n, w, d;
  
  while ( cin >> n >> w >> d, n || w || d ) {
    int p[101], s[101];
    Rep(i, n) cin >> p[i] >> s[i], p[i]--;
    
    vector<Pii> cake;
    cake.pb(Pii(d, w));

    Rep(i, n) {
      //Rep(j, (int)cake.size()) cout << cake[j].sc << " " << cake[j].fr << endl;
      //cout << endl;
      d = cake[p[i]].fr;
      w = cake[p[i]].sc;
      cake.erase(cake.begin() + p[i]);
      int mi;
      s[i] %= 2*w + 2*d;
      if ( s[i] < w ) {
	mi = min(s[i], w - s[i]);
	cake.pb(Pii(d, mi));
	cake.pb(Pii(d, w - mi));
      } else if ( s[i] < w + d ) {
	s[i] -= w;
	mi = min(s[i], d - s[i]);
	cake.pb(Pii(mi, w));
	cake.pb(Pii(d - mi, w));
      } else if ( s[i] < 2*w + d ) {
	s[i] -= w + d;
	mi = min(s[i], w - s[i]);
	cake.pb(Pii(d, mi));
	cake.pb(Pii(d, w - mi));
      } else {
	s[i] -= 2*w + d;
	mi = min(s[i], d - s[i]);
	cake.pb(Pii(mi, w));
	cake.pb(Pii(d - mi, w));
      }
    }

    vector<int> ans;
    Rep(i, (int)cake.size()) ans.pb(cake[i].fr * cake[i].sc);
    sort(All(ans));
    Rep(i, (int)ans.size()-1) cout << ans[i] << " ";
    cout << ans[ans.size()-1] << endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

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

void Main()
{
  ll n, k; cin >> n >> k;
  vpll c(n); rep(i, n) {ll a, b; cin >> a >> b; c[i] = mp(a, b);}
  sort(all(c));
  rep(i, n)
  {
    k -= c[i].second;
    if(k <= 0) fin(c[i].first);
  }
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

long long dp[1005][1005];

vector<string>vec;

int main()
{
    int n, m;
    string s;

    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        vec.push_back(s);
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1 and j==1)
            {
                if(vec[i-1][j-1]=='.') dp[i][j] = 1;
            }

            else if(vec[i-1][j-1]=='.'){
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] = dp[i][j] % 1000000007;
            }
        }
    }

    cout<<dp[n][m]<<endl;

    return 0;
}


Measured memory_bytes: 12508
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

struct list {
    int dst;
    struct list *next;
};

#define VERTEXES_MAX 100000

struct list *create_graph(int vs) {
    static struct list graph[VERTEXES_MAX];
    int i;
    for(i = 0; i < vs; i++) {
        graph[i].next = &graph[i];
    }
    return graph;
}
void add_list(struct list *head, int v) {
    struct list *elem = malloc(sizeof(struct list));
    elem->dst = v;
    elem->next = head->next;
    head->next = elem;
}

#define max(a,b) ((a) > (b) ? (a) : (b))

int dst_cnt[VERTEXES_MAX];
int dp[VERTEXES_MAX];
void dfs(struct list *graph, int v) {
    struct list *head = &graph[v];
    struct list *elem;
    for(elem = head->next; elem != head; elem = elem->next) {
        int dst = elem->dst;
        dst_cnt[dst]--;
        dp[dst] = max(dp[v]+1, dp[dst]);
        if(!dst_cnt[dst]) dfs(graph, dst);
    }
}

int main(void) {
    int vs, es;
    get_int2(&vs, &es);
    struct list *graph = create_graph(vs);
    static char cands[VERTEXES_MAX];
    memset(cands, 0x01, VERTEXES_MAX);
    int i;
    for(i = 0; i < es; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        // 1-indexed -> 0-indexed
        v1--; v2--;
        add_list(&graph[v1], v2);
        dst_cnt[v2]++;
        cands[v2] = 0;
    }

    for(i = 0; i < vs; i++) {
        // if starting point
        if(cands[i]) dfs(graph, i);
    }
    int ans = 0;
    for(i = 0; i < vs; i++) {
        ans = max(ans, dp[i]);
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 10368
// ABC 153-F
// 2020.1.26 bal4u

#include <stdio.h>
#include <string.h>

typedef long long ll;

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define MAX 200005
typedef struct { int X, H; } T;
T a[MAX]; int N;

void Qsort(T *a, int l, int r) {
	int i, j, m; T t;
	
	i = l, j = r, m = a[(l+r) >> 1].X;
	while (1) {
        // 昇順
		while (a[i].X < m) i++;
		while (m < a[j].X) j--;

		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

// 見つからなければ、一つ小さい要素を返す
int bs(int x) {
	int m, l = 1, r = N+1;

    while (l < r) {
        m = (l+r) >> 1;
        if (a[m].X <= x) l = m + 1; else r = m;
    }
	return l-1;
}

ll imos[MAX];

int main()
{
	int i, j, A, D;
	ll h, t, ans;
	
	N = in(), D = in(), A = in();
	for (i = 1; i <= N; ++i) a[i].X = in(), a[i].H = in();
	Qsort(a, 1, N);

	if ((ll)D*2 > a[N].X) D = a[N].X; else D *= 2;
	
	ans = 0;
	for (i = 1; i <= N; ++i) {
		imos[i] += imos[i-1];
		h = a[i].H - imos[i];
		if (h > 0) {
			t = (h-1)/A + 1;
			ans += t, t *= A;
			j = bs(a[i].X + D);
			imos[i] += t, imos[j+1] -= t;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 998244353;

int n;
int sum[200001];
string s;

int main() {
    cin >> n >> s;
    int ans = 0;
    sum[0] = 0;
    for (int i = n-1; i >= 0; i--) {
        if (i != n-1) sum[i] = sum[i+1];
        if (s[i] == '#') ans++;
        else sum[i]++;
    }
    int hoge = 0;
    rep(i,s.size()) {
        if (s[i] == '#') {
            int cnt = 0;
            ans = min(ans,hoge+sum[i]);
            hoge++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int N;
vector<ll> A;
vector<vector<int>> g;
int V;
const int INF=1e9;
vector<int> ans;

void dfs(int now,int par,vector<int> &v){
    int z=lower_bound(v.begin(),v.end(),A[now])-v.begin();
    int ptx=z;
    int pre=v[z];
    v[z]=A[now];
    ans[now]=lower_bound(v.begin(),v.end(),INF)-v.begin();
    
    for(auto nex:g[now]) if(nex!=par){
        dfs(nex,now,v);
    }
    v[ptx]=pre;
}

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

  cin>>N;
  A.resize(N);
  rep(i,N) cin>>A[i];
  g.resize(N);
  rep(i,N-1){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(b);
      g[b].push_back(a);
  }

  vector<ll> B=A;
  sort(B.begin(),B.end());
  B.erase(unique(B.begin(),B.end()),B.end());
  V=B.size();
  map<int,int> mp;
  rep(i,V) mp[B[i]]=i;

  rep(i,N) A[i]=mp[A[i]];

  vector<int> v(V+2,INF);
  ans.resize(N,1);
  dfs(0,-1,v);

  for(auto n:ans) cout<<n<<endl;


  return 0;
}


Measured memory_bytes: 37784
# -*- coding: utf-8 -*-
"""
D - AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper
https://atcoder.jp/contests/arc062/tasks/arc062_b

"""
import sys


def solve(s):
    rock, paper = 0, 0
    ans = 0
    for h in s:
        if rock > paper:
            paper += 1
            if h == 'g':
                ans += 1
        else:
            rock += 1
            if h == 'p':
                ans -=1
    return ans


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 3316
import java.util.Scanner;


public class Main{

	public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	}


}

Measured memory_bytes: 26592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll l, r, d;
    cin >> l >> r >> d;
    ll ans = 0;
    reps(i, l, r + 1) {
        if (i % d == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

vector<int> Z_algorithm(string S) {
	int c = 0, n = S.size();
	//接頭辞の長さを保存する配列を返す。
	//i = 1からやるとする。
	//Z[1]には赤下線が存在しないので、「溢れるor共通部分がない」のところにまずいく。
	//実装上、上のような挙動をしてもらうため、Z[0]=n;は[1, n - 1]まで計算が終わった後に入れる。
	//cは、赤下線の左端の位置。
	vector<int> Z(n, 0);
	for (int i = 1; i < n; i++) {
		int l = i - c;
		//今着目してる部分が赤下線の左端から何個分離れているかをlに入れる。
		if (i + Z[l] < c + Z[c]) {
			//この条件を満たすのは、「青下線が赤下線に収まる」。
			//この時、すでに計算されてるなのでそれを流用する。
			Z[i] = Z[l];
		} else {
			//この条件を満たすのは、「赤下線から青下線が溢れる」or「赤下線と青下線の共通部分がない」。
			int j = max(0, c + Z[c] - i);
			//c + Z[c] - i > 0の時、これは「溢れる」が該当する。
			//溢れてるのなら、収まる分は計算せずに、溢れた分(j番目から)だけ愚直に突き合わせればよい。
			//そもそも共通部分がないならば、全部突き合わせる。この時、式からj = 0;となるとわかる。
 
			//愚直に突き合せてる部分
			while (i + j < n && S[j] == S[i + j])j++;			
			Z[i] = j;
			//今の見てるiで、赤下線に完全に含まれなくなったので、今のiを赤下線の左端として、次のiをまた計算する。
			c = i;
		}
	}
	//最後にこれを忘れずに
	Z[0] = n;
	return Z;
}
 
int main(){
  string s,T,Q;
  cin >> s >> T;
  int sn = s.size();
  while(Q.size()<T.size()){
    Q += s;
  }
  int n=Q.size(), m=T.size();
  Q += Q;
  auto z = Z_algorithm(T+"+"+Q);
  vector<int> chain(n,-1);
  for(int i=0; i<n; i++){
    if(chain[i]!=-1) continue;
    int pos = i;
    int cnt = 0;
    while(z[m+1+pos]==m){
      cnt++;
      pos = (pos+m)%n;
      if(pos==i){
        cout << -1 << ln; return 0; //loop
      }
      if(chain[pos]>=0){
        cnt += chain[pos];
        break;
      }
      chain[pos] = 0;
    }
    chain[i] = cnt;
  }
  ll ans = *max_element(chain.begin(),chain.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20768
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define MOD 100000

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dp[105][105], dp2[105][105];

int main() {
	int w, h;
	while(cin >> w >> h) {
		if(w == 0 && h == 0) break;

		memset(dp, 0, sizeof(dp));
		memset(dp2, 0, sizeof(dp2));

		dp[0][0] = 1;
		dp2[0][0] = 1;

		rep(i, w) {
			dp[0][i] = 1;
			dp2[0][i] = 1;
		}
		
		rep(i, h) {
			dp[i][0] = 1;
			dp2[i][0] = 1;
		}

		REP(i, 1, h) {
			REP(j, 1, w) {
				dp[i][j] += dp[i][j-1];
				if(i - 2 >= 0) dp[i][j] += dp2[i-2][j];
				dp[i][j] %= MOD;
		
				dp2[i][j] += dp2[i-1][j];
				if(j - 2 >= 0) dp2[i][j] += dp[i][j-2];
				dp2[i][j] %= MOD;
			}
		}

		if(h == 2 || w == 2) cout << 2 << endl;
		else cout << (dp[h-1][w-1] + dp[h-2][w-3]) % MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


ll euclid(ll a, ll b){
  while (b>0){
    a = a % b;
    swap(a, b);
  }
  return a;
}


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

  ll N, M;
  cin >> N >> M;
  vector<ll> a(N);
  REP(i,N){
    ll ai;
    cin >> ai;
    a[i] = ai / 2;
  }

  ll logtwo = 2;
  while (a[0]%logtwo==0){ logtwo *= 2; }

  ll gcd = a[0];
  REP3(i,1,N){
    if ((a[i]%logtwo==0) || (a[i]*2%logtwo!=0)){
      cout << 0 << "\n";
      return 0;
    }
    gcd = gcd * a[i] / euclid(gcd, a[i]);
  }

  ll ans = M/gcd-M/(2*gcd);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main(void)
{
  	ll n,a,res=1,m=1e18;
  	bool flag=false;
  	cin >> n;
  	while(n--)
    {
      	cin >> a;
      	if(a==0)
        {
            cout << 0;
            return 0;
        }
        if(a<=m/res)
            res*=a;
        else
        {
            flag=true;
        }
    }
  	if(flag==false)
        cout << res;
    else
        cout << -1;
  	return 0;
}


Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FOR(i, a, b)    for(int i = a; i <= b; i++)
#define REP(i, a, b)    for(int i = a; i >= b; i--)
#define maxN       200005
#define inf        (int) 1e9
#define mode       (int) 1000000007
#define ll         long long

using namespace std;

int n;
int f[10000005];

void enter() {
    scanf("%d", &n);
    FOR(i, 1, n)
        FOR(j, 1, n / i) {
            int k = i * j;
            f[k]++;
        }
}

void solve() {
    ll ans = 0;
    FOR(i, 1, n)
        ans += 1ll * i * f[i];
    printf("%lld", ans);
}

int main() {
    //freopen("main.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    enter();
    solve();
}


Measured memory_bytes: 42872
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int dp[100005][13];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin>>S;
    int N=S.size();
    dp[0][0]=1;
    REP(i,N){
        if(S[i]!='?'){
            REP(j,13){
                dp[i+1][(j*10+(S[i]-'0'))%13]+=dp[i][j];
                dp[i+1][(j*10+(S[i]-'0'))%13]%=MOD;
            }
        }
        else{
            REP(j,10){
                REP(k,13){
                    dp[i+1][(k*10+j)%13]+=dp[i][k];
                    dp[i+1][(k*10+j)%13]%=MOD;
                }
            }
        }
    }
    cout<<dp[N][5]<<endl;
}

Measured memory_bytes: 5584
<?php
fscanf(STDIN, "%s %s", $N,$Q);
fscanf(STDIN, "%s", $s);
$ppp = [];
mas($s, $ppp);

for ($i = 0; $i<$Q; $i++) {
    fscanf(STDIN, "%s %s",$l,$r);
    $ff = $ppp[$r-1] - $ppp[$l-1];
    echo $ff."\n";
}

function mas($a, &$ppp) {
    $a = preg_split('//', $a, -1, PREG_SPLIT_NO_EMPTY);
    $ss = 0;
    $is_A_flag = 0;
    foreach ($a as $k => $s) {
        if ($s === 'A'){
            $is_A_flag = 1;
        } else {
            if ($s === 'C' && $is_A_flag) $ss++;
            $is_A_flag = 0;
        }
        $ppp[$k] = $ss;
    }
}


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

using ll=long long;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
using data=pair<ll,ll>;

int main(){
  ll i,j=0,N,M,ans=0,a,b,x;
  cin>>N>>M;
  vector<data> v(N);
  priority_queue<ll> que;

  rep(i,N){
    cin>>a>>b;
    v[i]=data(a,b);
  }
  vsort(v);

  rep(i,M){
    while(j<N&&v[j].first<i+2){
      que.push(v[j].second);
      j++;
    }
    if(que.size()>0){
      x=que.top();que.pop();
      ans+=x;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2936
#include <iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main() {
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    int s[n];
    double sum=0;
    for(int i=0;i<n;i++){
      cin>>s[i];
      sum+=s[i];
    }
    double a=0;
    sum/=n;
    for(int i=0;i<n;i++)a+=pow(s[i]-sum,2)/n;
    cout<<setprecision(10)<<sqrt(a)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
import sys

N = int(input())
a = [0] + [int(input()) for _ in range(N)]

current = 1
count = 0
while True:
    current = a[current]
    count += 1
    if current == 2:
        print(count)
        sys.exit(0)

    if count > 20 ** 5:
        break
print(-1)


Measured memory_bytes: 7852
# AOJ ITP1_10_A

import math

def floatinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = float(a[i])
    return a

def main():
    data = floatinput()
    x1 = data[0]; y1 = data[1]; x2 = data[2]; y2 = data[3]
    print(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))

if __name__ == "__main__":
    main()


Measured memory_bytes: 5652
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int x = a/100;
  int y = a%100/10;
  int z = a%10;
  if (x == 1) {
    x = 9;
  }
  else {
  if (x == 9) {
    x = 1;
  }
  }
  if (y == 1) {
    y = 9;
  }
  else {
  if (y == 9) {
    y = 1;
  }
  }
  if (z == 1) {
    z = 9;
  }
  else {
  if (z == 9) {
    z = 1;
  }
  }
  cout << x*100+y*10+z << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        int[] AN = new int[N];
        for (int i = 0; i < N; i++) {
            AN[i] = Integer.parseInt(sc.next());
        }

        divede(AN);

        System.out.println(ANS);
    }

    static int ANS;

    private static void divede(int[] aN) {
        for (int i = 0; i < aN.length; i++) {
            int target = aN[i];
            if (target % 2 != 0) {
                return;
            }
            aN[i] = target / 2;
        }
        ANS++;
        divede(aN);
    }
}


Measured memory_bytes: 21844
n = int(input())
a = list(map(int, input().split()))

min_abs = 10 ** 9 + 1
sum_abs = 0
cnt_neg = 0
for i in range(n):
  a_abs = a[i] if a[i] > 0 else - a[i]
  sum_abs += a_abs
  min_abs = min(min_abs, a_abs)
  if a[i] < 0:
    cnt_neg += 1
if cnt_neg % 2:
  print(sum_abs - 2 * min_abs)
else:
  print(sum_abs)

Measured memory_bytes: 14208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }

    static long GCD(long x,long y)
    {
        if (y == 0) return x;
        return GCD(y, x % y);
    }

    static long LCM(long x,long y)
    {
        return x * y / GCD(x, y);
    }

    static int keta(int x)
    {
        string s = x.ToString();
        return s[s.Length - 1]-'0';
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();


        long ans = INF;
        var x = sc.intarr;
        int D = x[0];
        int G = x[1];
        long[] p = new long[D];
        long[] c = new long[D];
        for(int i = 0; i < D; ++i)
        {
            var y = sc.intarr;
            p[i] = y[0];
            c[i] = y[1];
        }

        for (int bit = 0; bit < (1 << D); ++ bit)
        {
            long sum = 0;
            long num = 0;

            for (int i = 0; i < D; ++i)
            {
                if ((bit & (1 << i)) != 0)
                {
                    sum += c[i] + p[i] * 100 * (i + 1);
                    num += p[i];
                }
                
            }
            if (sum >= G) ans = Math.Min(ans, num);
            else
            {
                for(int i = D - 1; i >= 0; --i)
                {
                    if ((bit& (1 << i)) != 0) continue;
                    for(int k = 0; k < p[i]; ++k)
                    {
                        if (sum >= G) break;
                        sum += 100 * (i + 1);
                        ++num;
                    }
                }
                ans = Math.Min(ans, num);
            }
        }
        wr.wri(ans);
        
    }


}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
# -*- coding:utf-8 -*-
import sys
N = int(input())
a = [ int(input()) for tmp in range(N) ]
ans = 0
index = 0
while ans < len(a):
    sav = index #last index
    index = a[sav]-1 #new index
    ans += 1
    if index == 1:
        print(ans)
        sys.exit()
    if a[index] == sav+1: #Loop
        print("-1")
        sys.exit()
print("-1")

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 1;
    vector<int> vec;
    vector<int> so;
    for(int i = 1; i < n; i++){
        if(s[i] == s[i - 1]){
            cnt++;
        }else{
            vec.push_back(cnt);
            cnt = 1;
        }
    }
    vec.push_back(cnt);
    int ans = 0;
    REP(i,vec.size()){
        ans += vec[i] - 1;
    }
    cout << min(ans + 2 * k, n - 1) << endl;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD 1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }


/*
   -------
         |
    **   |
   -------      
   |
   ------------------------------------------------------------------------------------------------------
*/

void solve(){
  int n;cin>>n;
  vector<int> a(n);
  cin>>a;
  
  bool flag = true;
  REP(i,n){
     if(!(a[i]&1)){
          if (a[i]%3 != 0 && a[i]%5 != 0)  {
          flag = false;
          break;
      }
     }
  } 

  if(flag){
      cout<<"APPROVED"<<endl;
  }else
  {
      cout<<"DENIED"<<endl;
  }
  
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

int n;
ll A[505];
ll DP[505][505];
ll prefs[505];

ll jum(ll a, ll b) {
	ll res = prefs[b];
	if (a) res -= prefs[a - 1];
	return res;
}

ll rek(int a, int b) {
	if (a == b) return 0;
	ll &ret = DP[a][b];
	if (ret != -1) return ret;
	ret = INF;
	FOR(i, a, b - 1) {
		ret = min(ret, jum(a, b) + rek(a, i) + rek(i + 1, b)); 
	}
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, n) {
		cin >> A[i];
		prefs[i] = A[i];
		if (i) prefs[i] += prefs[i - 1];
	}
	//REP(i, n) cout << pref[i] << '\n';
	memset(DP, -1, sizeof DP);
	cout << rek(0, n - 1) << '\n';
}

Measured memory_bytes: 2304
#include<stdio.h>
#define MAX_LIMIT 20
#include<string.h>
int main()
{
  char str[50],temp;
   scanf("%[^\n]%*c",str);
    int length=0,i,j=0;
  while (str[length] != '\0')
{
 length++;
}
    if(length<3)
{
printf("%s",str);
}
      if(length>=3){
   i = 0;
   j = strlen(str) - 1;
 
   while (i < j) {
      temp = str[i];
      str[i] = str[j];
      str[j] = temp;
      i++;
      j--;
   }
     printf("%s", str);
     }
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef	long long ll;

int main() {
	ll a,b;
	cin >> a >> b;
	cout << (((a * b) % 2 != 0) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n; cin >> n;
vl a(n); rep(i,n) cin >> a[i];

vl d(n);
rep(i,n) {
    d[i] = a[i] - (i+1);
}
sort(all(d));

ll mid;
if(n % 2 == 0) {
    mid = (d[n/2] + d[(n-1)/2]) / 2;
}
else {
    mid = d[n/2];
}

ll sum = 0;
rep(i,n) {
    d[i] -= mid;
    sum += abs(d[i]);
}

cout << sum << endl;
return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int cnt=0;
  for(int i=0;i<N;i++){
    int x=a[i];
    while(x%2==0){
      cnt++;
      x/=2;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3608
// Lets go to the next level 
// AIM CM at CF *__* asap 
// Hit A,B,C and D faster and reach Candidate Master
// Remember you were also a novice when you started, 
// hence never be rude to anyone who wants to learn something
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.  


#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
// Big two primes 
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long 
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
const int MAXN = (int)((1e5) + 100);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N =  (int)(1e6+5); 

const int INF = 1 << 29;

void update(int &x, int y){
  x = min(x,y);
}

signed main(){
  fio;
  int n, m;
  cin>>n>>m;
  vector<vector<int>> d(m + 1, vector<int>(2, INF));
  vector<vector<int>> e(m + 1, vector<int>(2, INF));
  d[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    int A, B;
    cin>>A>>B;
    B = -B;
    e = d;
    for (int j = 0; j + 1 <= m; ++j) {
      if (d[j][0] != INF) {
        if (j + A <= m) update(e[j + A][0], d[j][0] + B);
        update(e[j + 1][1], d[j][0] + B);
      }
      if (d[j][1] != INF) {
        if (j + A <= m) update(e[j + A][1], d[j][1] + B);
      }
    }
    swap(d, e);
  }
  int best = 0;
  for (int j = 0; j <= m; ++j) {
    best = min(best, d[j][0]);
    best = min(best, d[j][1]);
  }
  cout<<-best;
  return 0;
  rr;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x1, y1, x2, y2;
  Point() {;}
  Point(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {;}
};

int w, h;
bool in(int x, int y) { return x >= 0 && x < w && y >= 0 && y < h; }
  
char field[2][100][100];
bool visit[60][60][60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
  while (scanf("%d %d", &w, &h), w|h) {
    MEMSET(visit, false);
    int sx1, sy1, sx2, sy2;
    REP(y, h) {
      scanf("%s %s", field[0][y], field[1][y]);
      REP(x, w) {
        if (field[0][y][x] == 'L') { sx1 = x; sy1 = y; }
        if (field[1][y][x] == 'R') { sx2 = x; sy2 = y; }
      }
    }
    queue<Point> que;
    que.push(Point(sx1, sy1, sx2, sy2));
    while (!que.empty()) {
      Point p = que.front();
      que.pop();
      REP(dir, 4) {
        int nx1 = p.x1 + dx[dir];
        int ny1 = p.y1 + dy[dir];
        int nx2 = p.x2 - dx[dir];
        int ny2 = p.y2 + dy[dir];
        if (field[0][ny1][nx1] == '#' || !in(nx1, ny1)) { nx1 -= dx[dir]; ny1 -= dy[dir]; }
        if (field[1][ny2][nx2] == '#' || !in(nx2, ny2)) { nx2 += dx[dir]; ny2 -= dy[dir]; }
        if (field[0][ny1][nx1] == '%' && field[1][ny2][nx2] == '%') { 
          puts("Yes");
          goto next;
        }
        if (field[0][ny1][nx1] == '%' || field[1][ny2][nx2] == '%') { 
          continue;
        }
        if (visit[ny1][nx1][ny2][nx2]) { continue; }
        visit[ny1][nx1][ny2][nx2] = true;
        que.push(Point(nx1, ny1, nx2, ny2));
      }
    }
    puts("No");
next:;
  }
}

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

int main()
{
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as)
        cin >> a;

    map<int, int> mm;
    for (auto& a : as) {
        mm[a]++;
        mm[a + 1]++;
        mm[a - 1]++;
    }

    int ans = 0;
    for (auto& kv : mm) {
        ans = max(ans, kv.second);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
#define down(i,j,k) for (i=j;i>=k;i--)
using namespace std;
const int N=102;
short ans,g[N][N][N][N];
int ex,ey,n,m,i,j,l,r,u,d,L,R,row[N][N],col[N][N];
char a[N][N];
void updata(short &x,short y) { if (y>x) x=y; }
int main()
{
//	freopen("robot.in","r",stdin);
//	freopen("robot.out","w",stdout);
	scanf("%d%d\n",&n,&m);
	rep(i,1,n) scanf("%s",a[i]+1);
	rep(i,1,n)
		rep(j,1,m)
		{
			row[i][j]=row[i][j-1]+(a[i][j]=='o');
			if (a[i][j]=='E') ex=i,ey=j;
		}
	rep(j,1,m)
		rep(i,1,n)
			col[i][j]=col[i-1][j]+(a[i][j]=='o');
	rep(l,0,m-ey)
		down(r,m+1,max(l+1,m+2-ey))
	rep(u,0,n-ex)
		down(d,n+1,max(u+1,n+2-ex))
		{
			ans=max(ans,g[u][d][l][r]);
			i=u+ex+1;
			if (i<d) {
				L=max(l+1,r-(m-ey)-1); R=min(r-1,l+ey);
				if (L<=R) updata(g[u+1][d][l][r],g[u][d][l][r]+row[i][R]-row[i][L-1]);
			}
			i=d-(n-ex)-2;
			if (i>u) {
				L=max(l+1,r-(m-ey)-1); R=min(r-1,l+ey);
				if (L<=R) updata(g[u][d-1][l][r],g[u][d][l][r]+row[i][R]-row[i][L-1]);				
			}
			j=l+ey+1;
			if (j<r) {
				L=max(u+1,d-(n-ex)-1); R=min(d-1,u+ex);
				if (L<=R) updata(g[u][d][l+1][r],g[u][d][l][r]+col[R][j]-col[L-1][j]);				
			}
			j=r-(m-ey)-2;
			if (j>l) {
				L=max(u+1,d-(n-ex)-1); R=min(d-1,u+ex);
				if (L<=R) updata(g[u][d][l][r-1],g[u][d][l][r]+col[R][j]-col[L-1][j]);				
			}
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 207104
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		int[] count = new int[n+1];
		for(int i = 0;i < n;i++){
			int num = saori.saori_hayami();
			count[num]++;
		}
		Arrays.sort(count);
		int roop = 0;
		int ans = 0;
		for(int i = count.length-1;i >=0;i--){
			if(count[i] == 0){
				continue;
			}
			if(roop >= k){
				ans += count[i];
			}
			roop++;
		}
		System.out.println(ans);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 36732
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int n,m,l;
	int a[100][100] = {0};
	int b[100][100] = {0};
	long int c[100][100] = {0};
	
	cin >> n >> m>> l;
	
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			cin >> a[i][j];
	
	for(int i=0; i<m; i++)
		for(int j=0; j<l; j++)
			cin >> b[i][j];
	
	for(int i=0; i<n; i++){
		for(int j=0; j<l; j++){
			for(int k=0; k<m; k++)
				c[i][j] += a[i][k]*b[k][j];
			cout << c[i][j];
			if(j<l-1)	cout << ' ';
		}
		cout << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3276
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
a = 0
b = 0
now = 0
ls = [i+1 for i in range(N)]
for i in itertools.permutations(ls,N):
  now += 1
  if list(i) == P:
    a = now
  if list(i) == Q:
    b = now
print(abs(a-b))

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define cases long long t;cin>>t;while(t--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;

int main()
{
    f_io;
    string s,t;
    cin >> s >> t;
    ll l1 = (ll)s.length(),l2 = (ll)t.length();
    ll ans = l2;
    foi(0,l1-l2+1)
    {
        ll c = 0;
        foj(0,l2)
        {
            if(s[i+j]!=t[j])
                c++;
        }
        ans = min(ans,c);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <utility>

using namespace std;

int a = 1, b = 0, c = 0;

int main()
{
    char c1, c2;
    while (scanf("%c,%c\n", &c1, &c2) != EOF)
    {
        if( (c1 == 'A' && c2 == 'B') || (c1 == 'B' && c2 == 'A') )
        {
            swap( a, b );
        }
        if( (c1 == 'C' && c2 == 'A')||(c1 == 'A' && c2 == 'C') )
        {
            swap( a, c );
        }
        if ((c1 == 'B' && c2 == 'C') || (c1 == 'C' && c2 == 'B'))
        {
            swap( b, c );
        }
    }
   
    if(a) printf( "%c\n", 'A' );
    if(b) printf( "%c\n", 'B' );
    if(c) printf( "%c\n", 'C' );
    return 0;
}


Measured memory_bytes: 2664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define scn(n) scanf("%d", &n)
#define scns(s) scanf("%s", &s)
#define pri(n) printf("%d", n)
#define priln(n) printf("%d\n", n)
#define pris(s) printf("%s", s)
#define prisln(s) printf("%s\n", s)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
  int n, m;
  scn(n);
  scn(m);
  int s[m];
  int c[m];

  for (int i; i < m; ++i) {
    cin >> s[i] >> c[i];
  }

  int d[n];
  rep(i, n) d[i] = -1;

  int check = 0;
  rep(i, m) {
    int pos = s[i] - 1;
    if (d[pos] >= 0 && d[pos] != c[i]) {
      check = 1;
      break;
    }

    d[pos] = c[i];
  }

  if (n > 1 && d[0] < 0) d[0] = 1;
  rep(i, n) {
    if (d[i] < 0) d[i] = 0;
  }
  if (n > 1 && d[0] == 0) check = 1;

  if (check == 1) {
    cout << -1 << endl;
  } else {
    rep(i, n) cout << d[i];
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#coding:utf-8
X,K,D = map(int, input().split())
X = abs(X)

#step1:0を超えない範囲で移動する
n = int(X/D)
if(n>K):
    n=K
p = X-D*n
if((K-n)%2==0):
    print(p)
else:
    print(abs(p-D))


Measured memory_bytes: 9168