akhauriyash/Code-Regression huggingface dataset:
H, W, K = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7
dp = Array.new(H + 1) { Array.new(W, 0) }
dp[0][0] = 1
H.times do |h|
  W.times do |w|
    (0...(1 << (W-1))).each do |bit|
      #check
      flag = false
      (1...W).each do |i|
        if bit[i] == 1 && bit[i - 1] == 1
          flag = true
        end
      end
      next if flag
      # fiber
      if w != W - 1 && bit[w] == 1
        target = w + 1
      elsif w != 0 && bit[w - 1] == 1
        target = w - 1
      else
        target = w
      end
      dp[h + 1][target] = (dp[h + 1][target] + dp[h][w]) % MOD
    end
  end
end
puts dp[H][K-1]


Measured memory_bytes: 1788
def In(): return map(int, raw_input().split())

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  x = toll[(i1, i2)]
  if (1050<=h1*60+m1<=1170 or 1050<=h2*60+m2<=1170) and abs(D[i1]-D[i2])<=40:
    x = (x+50)/100*50
  print x

Measured memory_bytes: 4276
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
    p[i]--;
  }
  /*
  要素の差以上の値を足さなければ大小は入れ替わらない
  →要素の差を足す最大値(=19999)より大きくしておく
  */
  vector<int> a(N), b(N);
  rep(i, N) {
    a[i] = 20000*i+1;
    b[i] = 20000*(N-i-1)+1;
  }
  rep(i, N)
    a[p[i]] += i;
  rep(i, N) printf("%d%c", a[i], i<N-1?' ':'\n');
  rep(i, N) printf("%d%c", b[i], i<N-1?' ':'\n');
  return 0;
}

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

using namespace std;

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int dx = tx - sx, dy = ty - sy;
	for (int i = 0; i < dy; i++) {
		cout << 'U';
	}
	for (int i = 0; i < dx; i++) {
		cout << 'R';
	}
	for (int i = 0; i < dy; i++) {
		cout << 'D';
	}
	for (int i = 0; i < dx; i++) {
		cout << 'L';
	}

	
	cout << 'L';
	for (int i = 0; i < dy + 1; i++) {
		cout << 'U';
	}

	for (int i = 0; i < dx + 1; i++) {
		cout << 'R';
	}
	cout << 'D';

	cout << 'R';
	for (int i = 0; i < dy + 1; i++) {
		cout << 'D';
	}

	for (int i = 0; i < dx + 1; i++) {
		cout << 'L';
	}
	cout << 'U' << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) cout<<#v<<": ";for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve(long long a, long long b, long long x){
    ld t = 0;
    if(x>(a*a*b/2)){
        t = atan(2.0*b/a - 2.0*x/(a*a*a));
    }else{
        t = atan((b*b*a*1.0)/(2*x));
    }
    ld arg = t*180/PI;
    sp(arg);
    // arg = t*180/PI;
    // sp(arg);
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    solve(a, b, x);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int a=sc.nextInt();
    	int b=sc.nextInt();
    	int c=sc.nextInt();

    	int l=b-a;
    	int r=c-b;

    	if(l==r) {
    		System.out.println("YES");
    	}else {
    		System.out.println("NO");
    	}
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

 string s;
 cin>>s;
 int red = 0;
 int blue = 0;
 for(int i=0;i<s.length();i++){
  if(s[i]=='0'){
    red++;
  }else{
    blue++;
  }
 }
 cout<<min(red,blue)*2<<endl;


  return 0;
}

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

int main(){
  int N;
  int W[101],sum=0;
  int sub=0;
  
  scanf("%d",&N);
  
  for(int i=0;i<N;i++){
    scanf("%d",&W[i]);
    sum += W[i];
  }


  for(int i=0;i<N;i++){
    if( sum -W[N-1-i] >sub){
      sum-=W[N-1-i];
      sub+=W[N-1-i];
    }else{
    break;
    }
  }

  printf("%d",abs(sum-sub));
  
  return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

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

	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}

	var sum int
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if j <= i {
				continue
			}
			sum += d[i] * d[j]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
def main():
    point_count = int(input())
    sums = set()
    diffs = set()
    for _ in range(point_count):
        x, y = [int(x) for x in input().split()]
        sums.add(x + y)
        diffs.add(x - y)
    pat_sum = max(sums) - min(sums)  # max (Xi + Yi) - (Xj + Yj)
    pat_diff = max(diffs) - min(diffs)  # max (Xi - Yi) - (Xj - Yj)
    return max(pat_sum, pat_diff)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 39440
#include<bits/stdc++.h>
using namespace std;
int main(void){
  bool tf=true;
  int h,w;
  cin>>h>>w;
  string s[100];
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  const int dx[4]={1,0,-1,0};
  const int dy[4]={0,-1,0,1};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.'){
        continue;
      }
      bool tf2=false;
      for(int k=0;k<4;k++){
        int n1=i+dx[k];
        int n2=j+dy[k];
        if(n1<0 || h<=n1){
          continue;
        }
        if(n2<0 || w<=n2){
          continue;
        }
        if(s[n1][n2]=='#'){
          tf2=true;
        }
      }
      if(tf2==false){
        tf=false;
        goto finish;
      }
    }
  }
  if(tf==true){
    cout<<"Yes"<<endl;
  }
  finish:
  if(tf==false){
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int
void solve(long long N, const std::vector<long long> x, const std::vector<long long> y)
{

  vector<int> idx;
  rep(i, N) if (x[i] != 0 || y[i] != 0) idx.push_back(i);
  sort(vall(idx), [&](int l, int r) -> bool {
    return atan2(y[l], x[l]) < atan2(y[r], x[r]);
  });
  double ans = 0;
  rep(i, 2 * idx.size()) rep(j, i + 1)
  {

    lli X = 0, Y = 0;
    if (i - j + 1 <= idx.size())
    {
      for (int k = j; k <= i; k++)
      {
        X += x[idx[k % idx.size()]];
        Y += y[idx[k % idx.size()]];
      }
      chmax(ans, sqrt(X * X + Y * Y));
    }
  }
  printf("%.10f", ans);
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> x(N);
  std::vector<long long> y(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &x[i]);
    scanf("%lld", &y[i]);
  }
  solve(N, std::move(x), std::move(y));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mod = 1000000007;

signed main()
{
    ll n;
    cin >> n;
    if (n % 2 == 1)
    {
        cout << 0 << endl;
    }
    else
    {
        ll ans = 0;

        n /= 2;
        while (n > 0)
        {
            ans += n / 5;
            n /= 5;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
/**
 *    author:  tourist
 *    created: 23.03.2019 14:09:32       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long A, B;
  cin >> n >> A >> B;
  vector<int> a(n + 2);
  a[0] = 0; a[n + 1] = n + 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<long long> dp(n + 2);
  dp[0] = 0;
  for (int i = 1; i <= n + 1; i++) {
    dp[i] = (long long) 1e18;
    int bigger = 0;
    for (int j = i - 1; j >= 0; j--) {
      if (a[j] < a[i]) {
        dp[i] = min(dp[i], dp[j] + bigger * A + (i - 1 - j - bigger) * B);
      } else {
        bigger++;
      }
    }
  }
  cout << dp[n + 1] << '\n';
  return 0;
}


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

string s;
int main() {
	cin >> s;
	int sum = 0;
	for (auto i = 0; i < 4; i++) {
		if (s[i] == '+') sum++;
		else			 sum--;
	}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] s = new char[h][w];
		for (int i = 0; i < h; i++) {
			String str = sc.next();
			s[i] = str.toCharArray();
		}
		sc.close();

		boolean flg = true;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i][j] == '#') {
					if (i > 0 && s[i - 1][j] == '#') {
						continue;
					}
					if (i < h - 1 && s[i + 1][j] == '#') {
						continue;
					}
					if (j > 0 && s[i][j - 1] == '#') {
						continue;
					}
					if (j < w - 1 && s[i][j + 1] == '#') {
						continue;
					}
					flg = false;
					break;
				}
			}
		}

		if (flg) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22228
v[5],d[4],o[3];C(x,q,y){return(q=o[q]-44)+2?x-q*y:x*y;}O(i,j,t){for(j=3;j--;i?O(i-1):printf(C(C(t=C(d[3],2,d[2]),1,d[1]),0,*d)-10?C(t,1,C(d[1],0,*d))-10?"":"(%d%c%d)%c(%d%c%d)\n":"((%d%c%d)%c%d)%c%d\n",d[3],o[2],d[2],o[1],d[1],*o,*d)&&main(1))o[i]="+-*"[j];}D(i,j){for(j=4;j--;)!d[j]?d[j]=v[i],i<4?D(i+1):O(2),d[j]=0:0;}main(i){for(;scanf("%d",v+i)*v[i];)++i>4?D(i=1),puts("0"):bzero(d,16);exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int a,b,c;cin>>a>>b>>c;
  if(a==b&&b!=c){
    cout<<"Yes"<<endl;
  }
  else if(a!=b&&b==c){
    cout<<"Yes"<<endl;
  }
  else if(c==a&&a!=b){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    


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

int main(){
    int N,tmp,count=0;
    string result = "YES";
    cin >> N;
    vector<int> A;
    for(int i=0;i<N;i++){
      cin >> tmp;
      A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    
    if(N!=A.size()){
      result = "NO";
    }
    cout << result << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

struct data
{
    int t, x, y;
};
int main()
{
    int n;
    cin >> n;
    vector<data> a(n + 1);
    a[0].t = 0;
    a[0].x = 0;
    a[0].y = 0;
    REP(i, 1, n + 1)
    {
        cin >> a[i].t >> a[i].x >> a[i].y;
    }
    int flag = 0;
    rep(i, a.size() - 1)
    {
        int timediff = a[i + 1].t - a[i].t;
        int disdiff = abs(a[i + 1].x - a[i].x) + abs(a[i + 1].y - a[i].y);
        if (timediff >= disdiff && (timediff - disdiff) % 2 == 0)
        {
            flag = 0;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1408
from math import factorial
N, P = map(int, input().split(' '))
biscuits = list(map(int, input().split(' ')))
bis_odd = len([i for i in biscuits if i % 2 != 0])
bis_even = len([i for i in biscuits if i % 2 == 0])

if bis_even == len(biscuits):
    if P == 0: print(2**N)
    else: print(0)
else:
    print(2**(N-1))

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

const int mod = 1e9 + 7;

const int N = 200005;

int n;
int f[N][3];
int pw2[N];
int high[N];
int st[N];
int par[20][N];
int TIME;
vector<int> G[N];
vector<int> rG[N];
vector<int> go[N];

void dfs(int u) {
	st[u] = ++TIME, go[high[u]].push_back(u);
	for (auto v : G[u]) {
		high[v] = high[u] + 1, dfs(v);
	}
}

int lca(int u, int v) {
	if (high[u] > high[v]) swap(u, v);
	for (int i = 18; i >= 0; --i) if (high[par[i][v]] >= high[u]) v = par[i][v];
	for (int i = 18; i >= 0; --i) if (par[i][v] != par[i][u]) v = par[i][v], u = par[i][u];
	return (u == v) ? u : par[0][u];
}

void add(int &x, int y) {
	x = (x + y) >= mod ? (x + y - mod) : (x + y);
}

void solve(int u, int depth) {
	if (high[u] == depth) {
		f[u][0] = f[u][1] = 1, f[u][2] = 0;
	}
	else {
		f[u][0] = 1, f[u][1] = f[u][2] = 0;
	}
	for (auto v : rG[u]) {
		solve(v, depth);
		int g[3];
		for (int j = 0; j <= 2; ++j) g[j] = f[u][j], f[u][j] = 0;
		for (int j = 0; j <= 2; ++j) {
			add(f[u][min(2, j + 1)], 1LL * g[j] * f[v][1] % mod);
			add(f[u][j], 1LL * g[j] * f[v][0] % mod);
			add(f[u][j], 1LL * g[j] * f[v][2] % mod);
		}
 	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> par[0][i], G[par[0][i]].push_back(i);
	}
	dfs(0);
	for (int i = 1; i <= 18; ++i) {
		for (int j = 0; j <= n; ++j) {
			par[i][j] = par[i - 1][par[i - 1][j]];
		}
	}
	pw2[0] = 1;
	for (int i = 1; i <= n; ++i) pw2[i] = 2 * pw2[i - 1] % mod;
	int res = 0;
	for (int i = 0; i <= n; ++i) {
		vector<int> v = go[i];
		int cnt = v.size(), sz = v.size();
		if (!cnt) break;
		sort(v.begin(), v.end(), [&] (int x, int y) {
			return st[x] < st[y];
		});
		for (int i = 1; i < sz; ++i) v.push_back(lca(v[i], v[i - 1]));
		sort(v.begin(), v.end(), [&] (int x, int y) {
			return st[x] < st[y];
		}); 
		v.erase(unique(v.begin(), v.end()), v.end());
		sz = v.size();
		for (int i = 1; i < sz; ++i) {
			int p = lca(v[i - 1], v[i]);
			rG[p].push_back(v[i]);
		}
		solve(v[0], i);
		for (int i = 0; i < sz; ++i) rG[v[i]].clear();
		res = (res + 1LL * pw2[n + 1 - cnt] * f[v[0]][1]) % mod;
	}
	cout << res;
}

Measured memory_bytes: 56576
a, b, m = map(int, input().split())
aLst = list(map(int, input().split()))
bLst = list(map(int, input().split()))

#割引なしの最小金額を設定
aSortedLst = sorted(aLst)
bSortedLst = sorted(bLst)
price = aSortedLst[0] + bSortedLst[0]

#割引を適応
for i in range(m):
    x, y, c = map(int, input().split())
    disPrice = aLst[x - 1] + bLst[y - 1] - c
    if disPrice < price:
        price = disPrice
print(price)

Measured memory_bytes: 18648
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        200005
#define mod         1000000007
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    ll i,x,flag=0;
    cin>>s;
    x=s.size();
    for(i=0;i<x;i++){
        if(i%2==0){
            if(s[i]=='L'){
                flag=1;
            }
        }
        else{
            if(s[i]=='R'){
                flag=1;
            }
        }
    }
    if(flag){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}

Measured memory_bytes: 256
import collections

N=input()

N=int(N)

aaa=[]

for i in range(N):
    a1=input()
    aaa.append(a1)


M=input()

M=int(M)


bbb=[]

for i in range(M):
    a1=input()
    bbb.append(a1)
    
#print(aaa)

#print(bbb)


c = collections.Counter(aaa)

d = collections.Counter(bbb)

#print(c)

#print(d)

#print(c-d)

dic2 = sorted((c-d).items(), key=lambda x:x[1], reverse=True)


#print(len(dic2))

if len(dic2)==0:
    print(0)
else:
    print(dic2[0][1])


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    ll n, m;
    cin >> n >> m;
    ll p[m];
    string s[m];
    int qq[n] = {};
    int qqq[n] = {};
    rep(i, m) {
        cin >> p[i] >> s[i];
        if ( s[i] == "AC" ) {
            qqq[p[i]-1] = 1;
        }
    }

    ll AC = 0;
    ll WA = 0;

    rep(i, m) {
        if ( s[i] == "AC" && qq[p[i]-1] == 0 ) {
            AC++;
            qq[p[i]-1] = 1;
        } else if ( s[i] == "WA" && qq[p[i]-1] == 0 && qqq[p[i]-1] == 1) {
            WA++;
        }
    }
    cout << AC << " " << WA << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 100005

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    ll a,b,n;
    cin>>a>>b>>n;
    ll val = 0;
    if(n>=b-1)
        val = a*(b-1)/b;
    ll nval = a*n/b - (n/b)*a;
    val = max(val, nval);
    cout<<val;
}


Measured memory_bytes: 3636
package main

import (
	"bufio"
	"flag"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"testing"
)

/*-----------Main-----------*/

func main() {
	n := readI()
	pf := primeFactorization(n)
	ans := 0
	for _, p := range pf {
		e := p.exponent
		for i := 1; e >= i; i++ {
			ans++
			e -= i
		}
	}
	fmt.Println(ans)
}

type power struct {
	base     int
	exponent int
}

func primeFactorization(n int) (powers []power) {
	//Trial division
	primes := getPrimes(sqrt(n))
	i := 0
	for _, p := range primes {
		if n < p*p {
			break
		}
		if n%p == 0 {
			powers = append(powers, power{
				base:     p,
				exponent: 0,
			})
		} else {
			continue
		}
		for n%p == 0 {
			n /= p
			powers[i].exponent++
		}
		i++
	}
	if n > 1 {
		powers = append(powers, power{
			base:     n,
			exponent: 1,
		})
	}
	return
}

func getPrimes(upperLimit int) (primes []int) {
	//Sieve of Eratosthenes
	fl := make([]bool, upperLimit+1)
	sqrtUpperLimit := sqrt(upperLimit)
	for i := 2; i <= sqrtUpperLimit; i++ {
		if fl[i] != true {
			primes = append(primes, i)
			for j := i; j <= upperLimit; j += i {
				fl[j] = true
			}
		} else {
			continue
		}
	}
	for i := sqrtUpperLimit + 1; i <= upperLimit; i++ {
		if fl[i] != true {
			primes = append(primes, i)
		}
	}
	return
}

func sqrt(n int) int {
	return int(math.Sqrt(float64(n)))
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	testing.Init()
	if flag.Parse(); flag.Arg(0) == "debug" {
		debug()
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-5.in")
	if err != nil {
		fmt.Println("Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 5968
var s,s1:ansistring;i:longint;ch:char;
begin
  readln(s);s1:=s;
  for i:=1 to length(s) div 2 do
  begin
    ch:=s[i];
    s[i]:=s[length(s)-i+1];
    s[length(s)-i+1]:=ch;
  end;
  for i:=1 to length(s) do
    if s[i]='b' then s[i]:='d'
      else if s[i]='d' then s[i]:='b'
        else if s[i]='p' then s[i]:='q'
          else s[i]:='p';
  if s=s1 then writeln('Yes') else writeln('No');
end.

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int result = 0;
        int min = 10;
        for (int i = 0; i < 5; i++) {
            int a = sc.nextInt();
            if (a % 10 != 0 && a % 10 < min) {
                min = a % 10;
            }
            result += Math.ceil((double) a / 10) * 10;
        }
        sc.close();
        if (min != 10) {
            result -= 10 - min;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	string p[4]={"dream","dreamer","erase","eraser"};
	for(int i=0;i<4;i++)
	{
		reverse(p[i].begin(),p[i].end());
	}
	for(int i=0;i<s.size();)
	{
		bool f=false;
		for(int j=0;j<4;j++)
		{
			if(s.compare(i,p[j].size(),p[j])==0)
			{
				i+=p[j].size();
				f=true;
				break;
			}
		}
		if(!f)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

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

int main() {
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	int aa = s[0].size(), bb = s[1].size(), cc = s[2].size();
	int a = 0, b = 0, c = 0;
	int tern = 'a';
	while (a <= aa && b <= bb && c <= cc) {
		if (tern == 'a') {
			if (a == aa)break;
			tern = s[0][a];
			a++;
		}
		if (tern == 'b') {
			if (b == bb)break;
			tern = s[1][b];
			b++;
		}
		if (tern == 'c') {
			if (c == cc)break;
			tern = s[2][c];
			c++;
		}
	}
	char ans = toupper(tern);
	cout << ans << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    n=length(s)
    ans=0
    before,now="",""
    for i in s
        now*=string(i)
        if before!=now
            before,now=now,""
            ans+=1
        end
    end
    println(ans)
end
main()

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

using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)
 
#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const int N = 2005;
int dp[N][N];

int32_t main() {
	FAST_IO;
		
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	bool turn = true;
	while (true) {
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		
		if (turn) {
			c -= b;
		} else {
			a -= d;
		}
		turn = !turn;
	}
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 400000;



ll seq(int N,ll A[MAX]) {
	vector<ll> dp;//長さiの列の末端の最小値

	repn(i, N) {
		auto j = upper_bound(dp.begin(),dp.end(),A[i]);
		int dist = j - dp.begin();

		if (dist < dp.size()) { dp[dist] = A[i]; }
		else { dp.push_back(A[i]); }

	}

	return dp.size();
}




int main() {

	int N;
	cin >> N;

	ll A[MAX];
	repn(i, N) {
		cin >> A[i];
		A[i] *= -1;
	}

	cout << seq(N, A);

	system("PAUSE");


}

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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>a(k);
  for(int i=0;i<k;i++)cin>>a[i];
  for(int i=n;i<=n*10;i++){
    bool hantei=true;
    int x=i;
    while(x>0){
      int amari=x%10;
      for(int j=0;j<k;j++){
        //cout<<x<<" "<<a[j]<<" "<<amari<<endl;
        if(amari==a[j]){
          hantei=false;
          break;
        }
      }
      x/=10;
      if(hantei==false)break;
    }
    if(hantei==true){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3612
n,m = map(int,input().split())
P = list(map(int,input().split()))

uf = {i:i for i in range(1,n+1)}

def get_parent(i):
  lst = []
  while uf[i] != i:
    lst.append(i)
    i = uf[i]
  for l in lst[:-1]:
    uf[l] = i
  return i

def unite(i,j):
  p = get_parent(i)
  uf[get_parent(j)] = p

def same(i,j):
  return get_parent(i) == get_parent(j)

for _ in range(m):
  x,y = map(int,input().split())
  unite(x,y)

ans = 0
for i in range(1,n+1):
  ans += int(same(P[i-1],uf[i]))
print(ans)



Measured memory_bytes: 20704
N,K = map(int,input().split())
W = []
for _ in range(N):
    W.append(int(input()))


def is_OK(P):
    track_index = 0
    w_index = 0
    while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
    return w_index == N

L = 0
R = 100000*100000
#mid = (L+R)//2
ans = R

while L <= R:
    mid = (L+R)//2
    if is_OK(mid):
        ans = mid
        R = mid-1
    else:
        L = mid+1
    #mid = (L+R)//2

print("%d"%ans)



Measured memory_bytes: 9556
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back;
#define endl "\n";
#define X first;
#define Y second;
#define pii pair<int,int>;
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
ll dp[maxn];
int main(){
	migmig;
	int n;
	cin >> n;
	dp[0]=2;
	dp[1]=1;
	for(int i=2;i<=n;i++){
		dp[i]=dp[i-1]+dp[i-2];
	}
	cout<<dp[n];
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;



int n,k;

int const MAXN = 510000;
int const MOD = 1000000007;

long long fac[MAXN], finv[MAXN], inv[MAXN];
long long A[MAXN];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAXN; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll modcomb( int n, int k, ll MOD ){
	if( n < k )	return 0;
	if( n < 0 || k < 0 )	return 0;
	return fac[n] * ( finv[k] * finv[n-k] % MOD ) % MOD;
}

bool cmp_reverse( int a, int b ){
	return a > b;
}



int main(){
	COMinit();

	std::cin >> n >> k;

	for( int i = 1; i <= n; i++ )
		std::cin >> A[i];

	

	ll maxsum = 0;
	ll minsum = 0;

	std::sort( A+1, A+1+n );
	for( int i = k; i <= n; i++ ){
		maxsum = ( maxsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
		// printf("maxsum = %lld\n", maxsum);
	}

	std::sort( A+1, A+1+n, cmp_reverse );
	for( int i = k; i <= n; i++ ){
		minsum = ( minsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
	}
	
	// printf("maxsum = %lld, minsum = %lld\n", maxsum, minsum );
	std::cout << (maxsum - minsum + MOD) % MOD << std::endl;
}


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

using namespace std;

long d[111][10];
int main() {
	int f[] = { 1,1,2,3,5,8,13,21,34 };
	int p = 1e9 + 7;
	int h, w, k;
	cin >> h >> w >> k;
	d[0][1] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 1; j <= w; j++) {
			d[i + 1][j] = d[i][j] * f[j - 1] * f[w - j] % p;
			if (j > 1) d[i + 1][j] += d[i][j - 1] * f[j - 2] * f[w - j] % p, d[i + 1][j] %= p;
			if (j < w) d[i + 1][j] += d[i][j + 1] * f[j - 1] * f[w - j - 1] % p, d[i + 1][j] %= p;
		}
	}
	cout << d[h][k] << endl;
	return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
table=[[0]*(H+W-1) for i in range(H+W-1)]
for j in range(H):
    for i in range(W):
        if S[j][i]=='#':
            table[i+j][i-j+H-1]=1
yoko=[[0]*(H+W) for i in range(H+W-1)]
for j in range(H+W-1):
    for i in range(1,H+W):
            yoko[j][i]=yoko[j][i-1]+table[j][i-1]
tate=[[0]*(H+W-1) for i in range(H+W)]
for j in range(1,H+W):
    for i in range(H+W-1):
        tate[j][i]=tate[j-1][i]+table[j-1][i]

ans=0
for y in range(H+W-1):
    for x in range((y+H-1)%2,H+W-1,2):
        if table[y][x]!=1:
            continue
        for z in range(x+2,H+W-1,2):
            if table[y][z]==1:
                d=z-x
                if y+d<H+W-1:
                    ans+=yoko[y+d][z+1]-yoko[y+d][x]
                    #print(1,'.',ans,':',x,y,z)
                if y-d>=0:
                    ans+=yoko[y-d][z+1]-yoko[y-d][x]
                    #print(2,'.',ans,':',x,y,z)
        for w in range(y+2,H+W-1,2):
            if table[w][x]==1:
                e=w-y
                if x+e<H+W-1:
                    ans+=tate[w][x+e]-tate[y+1][x+e]
                    #print(3,'.',ans,':',x,y,w)
                if x-e>=0:
                    ans+=tate[w][x-e]-tate[y+1][x-e]
                    #print(4,'.',ans,':',x,y,w)

print(ans)




Measured memory_bytes: 58972
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

auto prime_factorize(long n) {
    vector<pair<int, int>> a;

    for (long i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;

        int cnt = 0;
        while (n % i == 0) {
            cnt++;
            n /= i;
        }

        a.push_back({i, cnt});
    }

    if (n != 1) a.push_back({n, 1});

    return a;
}

int main() {
    long n, ans = 0;
    cin >> n;
    auto a = prime_factorize(n);
    for (auto [i, j] : a) {
        ans += (-1 + floor((sqrt(1 + 8 * j)))) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3720
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

	int L,M,N,sum,ans;
	bool FLG;

	while(true){
		scanf("%d",&L);
		if(L == 0)break;

		sum = 0;
		FLG = false;

		for(int i = 0; i < 12; i++){
			scanf("%d %d",&M,&N);

			if(!FLG){
				sum += M-N;

				if(sum >= L){
					ans = i+1;
					FLG = true;
				}
			}
		}

		if(!FLG)printf("NA\n");
		else{
			printf("%d\n",ans);
		}

	}

    return 0;
}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b ;
    if((a-b)%2 != 0){
        cout <<"IMPOSSIBLE"<<endl;
    }
    else if((a-b)%2 == 0){
        cout<< (a+b)/2 << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;

template <typename T>
inline bool read(T& ret) {
    T x = 0, f = 1; char ch = getchar();
    while(ch!=EOF && (ch > '9' || ch < '0')) { if(ch == '-') f = -1; ch = getchar();  }
    if(EOF==ch)return false;
    do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
    ret = x * f;
    return true;
}


inline char nc() {
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
bool rn(T& v) {
    static char ch;
    while (ch != EOF && !isdigit(ch)) ch = nc();
    if (ch == EOF) return false;
    for (v = 0; isdigit(ch); ch = nc())
        v = v * 10 + ch - '0';
    return true;
}

template <typename T>
void o(T p) {
    static int stk[70], tp;
    if (p == 0) { putchar('0'); return; }
    if (p < 0) { p = -p; putchar('-'); }
    while (p) stk[++tp] = p % 10, p /= 10;
    while (tp) putchar(stk[tp--] + '0');
}


LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }



void Solve(){
}


int main(){
#ifdef L_JUDGE
    freopen("in1.txt","r",stdin);
    //		freopen("out.txt","w",stdout);
#endif
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    int D,T,S;
    while(cin>>D>>T>>S){
        int t=T*S;
        if(D<=t){
            puts("Yes");
        }else{
            puts("No");
        }
    }
    return 0;

#ifdef L_JUDGE
    fclose(stdin);
    fclose(stdout);
    //		system("out.txt");
#endif

	return 0;
}


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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s[10000];
  REP(i,n) {
    cin >> s[i];
  }

  ll ra = 0LL;
  ll lb = 0LL;
  ll po = 0LL;
  ll ans = 0LL;

  REP(i,n) {
    if (s[i][0] == 'B' && s[i][s[i].length() - 1] != 'A') {
      lb++;
    }
    if (s[i][s[i].length() - 1] == 'A' && s[i][0] != 'B') {
      ra++;
    }
    if (s[i][s[i].length() - 1] == 'A' && s[i][0] == 'B') {
      po++;
    }

      FOR(j, 1, s[i].length())
      {
        if (s[i][j - 1] == 'A' && s[i][j] == 'B')
        {
          ans++;
        }
      }
  }

  ans += min(ra,lb);
  if(ra == 0LL && lb == 0LL) {
    ans += max(0LL, po -1LL);
  } else if(abs(ra -lb) < po) {
    ans += abs(ra - lb);
    ans += max(0LL, po - abs(ra-lb));
  } else {
    ans += po;
  }

  cout << ans << endl;

}


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

int N, A[1 << 18], S;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; S += A[i]; A[i] *= N;
	}
	int maxn = (1 << 30), r = 0;
	for (int i = 1; i <= N; i++) {
		if (maxn > abs(S - A[i])) { maxn = abs(S - A[i]); r = i; }
	}
	cout << r - 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long llong;

const int MOD = 1000000007;

struct modint {
  llong val;

  modint () {
    val = 0;
  }

  modint (llong _val) {
    val = _val % MOD;
  }
};

modint operator+ (modint p, modint q) {
  return modint((p.val + q.val) % MOD);
}

modint operator- (modint p, modint q) {
  return modint((p.val - q.val + MOD) % MOD);
}

modint operator- (modint p) {
  return modint(0) - p;
}

modint operator* (modint p, modint q) {
  return modint((p.val * q.val) % MOD);
}

modint operator^ (modint p, int q) {
  modint pows [30];

  pows[0] = p;
  for (int i = 1; i < 30; i++) {
    pows[i] = pows[i - 1] * pows[i - 1];
  }

  modint ans (1);
  for (int i = 0; i < 30; i++) {
    if (q & 1 << i) {
      ans = ans * pows[i];
    }
  }

  return ans;
}

modint operator/ (modint p, modint q) {
  return p * (q ^ (MOD - 2));
}

const int MAX_N = 200005;

modint fact [MAX_N];

modint choose (int n, int k) {
  return fact[n] / (fact[k] * fact[n - k]);
}

int main () {
  fact[0] = modint(1);
  for (int i = 1; i < MAX_N; i++) {
    fact[i] = fact[i - 1] * modint(i);
  }

  int height, width, a, b;
  cin >> height >> width >> a >> b;

  /* we have made b right-moves now */
  modint ans (0);
  for (int i = 0; i < height - a; i++) {
    ans = ans + choose(b - 1 + i, i) * choose(height - 1 + width - 1 - (b + i), width - 1 - b);
  }

  cout << ans.val << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;

	int ans,m=min(x,y),ma=max(x,y);
	if(c*2<a+b){
		ans=m*2*c+(x-m)*a+(y-m)*b;
	}else{
		ans=a*x+b*y;
	}

	if(ans>ma*c*2)
		ans=ma*c*2;

	cout<<ans<<endl;



}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
G = []
ans = []

class Edge:
    def __init__(self, to, id):
        self.to = to
        self.id = id

def dfs(v, fr, frk):
    global ans
    k = 1
    for e in G[v]:
        if e.to != fr:
            if k == frk:
                k += 1
            ans[e.id] = k
            dfs(e.to, v, k)
            k += 1

def main():
    global G, ans
    n = int(input().strip())
    ans = [0] * (n-1)
    G = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = list(map(int, input().strip().split()))
        a -= 1
        b -= 1
        G[a].append(Edge(b, i))
        G[b].append(Edge(a, i))
    dfs(0, -1, -1)
    maxk = 0
    for l in G:
        maxk = max(maxk, len(l))
    print(maxk)
    for p in ans:
        print(p)

if __name__ == '__main__':
    main()


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

typedef long long lll;

int main()
{
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 3; i++) {
        if((a * b * i) & 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;

public class Main {
	MyScanner sc = new MyScanner();

	void run() {
		for (;;) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			if ((N | M) == 0) return;
			int[] sumH = new int[N + 1];
			int[] sumW = new int[M + 1];
			for (int i = 1; i <= N; i++) sumH[i] = sumH[i - 1] + sc.nextInt();
			for (int i = 1; i <= M; i++) sumW[i] = sumW[i - 1] + sc.nextInt();
			HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
			for (int i = 0; i <= N; i++) {
				for (int j = 0; j <= M; j++) {
					int v = sumH[i] - sumW[j];
					map.put(v, map.containsKey(v) ? map.get(v) + 1 : 1);
				}
			}
			long ans = 0;
			for (int key : map.keySet()) {
				int val = map.get(key);
				ans += (val * (val - 1)) / 2;
			}
			System.out.println(ans);
		}
	}
	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 324712
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){
	string s;
	cin >> s;
	if(s[3] == s[2] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc160.contest.atcoder.jp/tasks/abc160_a

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n; string s; cin >> n >> s;
	int cnt = 0;
	for (int i = 2; i < n; i++)
	{
		if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C') cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 256
counter = 0
N = 0
def dfs(cur,use):
    global counter,N
    if(cur > N): return
    if(use == 7): counter += 1

    dfs(cur*10+7,use | 0b001)
    dfs(cur*10+5,use | 0b010)
    dfs(cur*10+3,use | 0b100)


def main():
    global N
    N = int(input())
    dfs(0,0)
    print(counter)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
x, y = gets.split.map(&:to_i)

count = 0
xi = x.abs
yi = y.abs

if x < 0 && y < 0
  if xi < yi
    count = 2
    count += yi - xi
  else
    count += (yi - xi).abs
  end
else
  if 0 <= x && 0 <= y
    if y == 0
      count += 1
      count += x
    elsif x < y
      count += y - x
    else
      count += 1
      count += x - y
      count += 1
    end
  elsif x <= 0 && 0 <= y
    if y == 0
      count += xi
    elsif xi < yi
      count = yi - xi
      count += 1
    elsif xi == yi
      count = 1
    else
      count = xi - yi
      count += 1
    end
  elsif 0 <= x && y <= 0
    if xi < yi
      count = yi - xi
      count += 1
    elsif xi == yi
      count = 1
    else
      count += 1
      count += xi - yi
    end
  end
end

puts count


Measured memory_bytes: 1788
import java.util.*;

public class Main{
    public static void main(String... arg){
        Scanner sc = new Scanner(System.in);
        
        // マス総数squareと白マスwhite受け取り
        int square = (int)Math.pow(sc.nextInt(), 2);
        int white = sc.nextInt();
        
        // 黒マス計算し出力
        System.out.println(square - white);
        
    }

}

Measured memory_bytes: 21716