akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            String S = sc.next();
            int index = S.indexOf("#");
            
            int sCount = 0;
            int dCount = 0;
            for (int i = 0; i < N; i++) {
                if (S.charAt(i) == '#') sCount++;
                else dCount ++;
            }
            int sCountNow = 0;
            int dCountNow = 0;
            int min = dCount;
            for (int i = 0; i < N; i++) {
                if (S.charAt(i) == '#') sCountNow++;
                else dCountNow ++;
                min = Math.min(sCountNow + dCount - dCountNow, min);
            }
            System.out.println(min);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

    if (s == 'A')
        cout << 'T' << endl;
    
    if (s == 'T')
        cout << 'A' << endl;
    
    if (s == 'G')
        cout << 'C' << endl;

    if (s == 'C')
        cout << 'G' << endl;
    
}

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

int main(){
  long r,d,x;
  cin >> r >> d >> x;
  long xx = x;
  for(int i = 1; i<11; i++){
    xx = xx*r-d;
    cout << xx << endl;
  }
}


Measured memory_bytes: 256
v,e,s=map(int,input().split())
edge=[]
inf =1000000100
for i in range(v):
    edge.append([])

for i in range(e):
    vs,vt,d=map(int,input().split())
    edge[vs].append((vt,d))
    
dis=[]
for i in range(v):
    dis.append(inf)

dis[s]=0

for j in range(v):
    update=False
    for i in range(v):
        for (t,d) in edge[i]:
            if dis[i]<inf and d<inf and dis[t]>dis[i]+d:
                dis[t]=dis[i]+d
                update=True
    if update==False: break

for i in range(v):
    if dis[i]>=inf:
        print("INF")
    else:
        print(dis[i])
            

Measured memory_bytes: 83676
#include <stdio.h>
int main(void){
  int k;
  int array[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  scanf("%d",&k);
  printf("%d",array[k-1]);
  return 0;
}


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

int main() {
  int X;
  cin >> X;
  for (long long i = -121; i <= 121; i++) {
    for (long long j = -121; j <= 121; j++) {
      if (X == pow(i, 5) - pow(j, 5)) {
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define dump(x) cerr << #x << " = " << (x) << endl

using namespace std;

int N;

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

    cin >> N;
    REP(i, 100 / 4 + 1)
    {
        REP(j, 100 / 7 + 1)
        {
            int x = 4 * i + 7 * j;
            if (x == N)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<iterator>
#include<string>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
#define MP make_pair
#define F first
#define S second
#define LL long long
#define INF	int(1e9)
typedef pair<int, int> P;
typedef pair<P, P> PP;
inline int in() {
	int temp;
	scanf("%d", &temp);
	return temp;
}
LL n, ans, ab;
LL a[100000], b[100000];
int main()
{
	n = in();
	for (int i = 0; i < n; i++)
	{
		a[i] = in(); b[i] = in();
	}
	for (int i = n - 1; i >= 0; i--)
	{
		a[i] += ans;
		ab = b[i] - a[i] % b[i];
		if (ab != b[i]) {
			ans += ab;
			a[i] += ab;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

#define ll long long int
#define ld long double

int main(){

    ll n;
    cin >> n;
    vector<ll> a;
    ll i,a1;

    for(i=0;i<n;i++){
        cin >> a1;
        a.push_back(a1);
    }

    ll dp[n][2];

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

    dp[1][0] = abs(a[1]-a[0]);
    dp[1][1] = 10000;

    for(i=2;i<n;i++){
        dp[i][0] = abs(a[i]-a[i-1]) + min(dp[i-1][0],dp[i-1][1]);
        dp[i][1] = abs(a[i]-a[i-2]) + min(dp[i-2][0],dp[i-2][1]);
    }

    cout << min(dp[n-1][0],dp[n-1][1]);

}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
int main(){
  int n;cin >> n;
  vector<pair<int,int>> a(n);
  rep(i,n){
    cin >> a[i].first;
    a[i].second = i+1;
  }
  sort(a.begin(),a.end());
  rep(i,n-1) cout << a[i].second << " ";
  cout << a[n-1].second << endl; 

}


Measured memory_bytes: 1664
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main{ 
public static void main(String[] args){

Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Set<String> ss=new HashSet<String>();

 for(int i=0;i<n;i++){
    ss.add(sc.next());
}
System.out.println(ss.size());

}

}

Measured memory_bytes: 66136
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
    	push(i,&st1);
       
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
    	int j = pop(&st1);
		sum += i - j;
      // st2_j と st2_a を用いて水たまりの水量を更新 
		int a = i - j;   // 更新する水たまりの水量を a に格納していく
		while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく (write your code)
			pop(&st2_j);
			a += pop(&st2_a);
		}
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    	push(j, &st2_j);
    	push(a, &st2_a);
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}


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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> vv(H, vector<int>(W));
  for (int i = 0; i < N; ++i) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      for (int j = 0; j < H; ++j) {
        for (int k = 0; k < x; ++k) {
          vv.at(j).at(k) = 1;
        }
      }
    }
    if (a == 2) {
      for (int j = 0; j < H; ++j) {
        for (int k = x; k < W; ++k) {
          vv.at(j).at(k) = 1;
        }
      }
    }
    if (a == 3) {
      for (int j = 0; j < y; ++j) {
        for (int k = 0; k < W; ++k) {
          vv.at(j).at(k) = 1;
        }
      }
    }
    if (a == 4) {
      for (int j = y; j < H; ++j) {
        for (int k = 0; k < W; ++k) {
          vv.at(j).at(k) = 1;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    ans += count(vv.at(i).begin(), vv.at(i).end(), 0);
  }
  cout << ans << endl;
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "header.h"
#else
    #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
    return;
}
vector<vi> adj;
vi vis;
vi topos;
void dfs1(int x) {
    int h = 0;
    vis[x] = 1;
    for(auto y: adj[x]) {
        if(!vis[y]) dfs1(y);
    }
    topos.pb(x);

}
void topoSorting() { 
    rep(i,1,SZ(vis)) {
        if(!vis[i]) dfs1(i);
    }
    reverse(all(topos));
    return;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preprocess();
    int n, m; cin>>n>>m;
    adj.resize(n+1, vi(0));
    vis.resize(n+1,0);
    vi deg(n+1,0);
    rep(i,0,m) {
        int x, y; cin>>x>>y;
        adj[x].pb(y);
    }
    topoSorting();
    vi dp(n+1);
    rep(i,0,n) {
        for(auto x: adj[topos[i]]) {
            dp[x] = max(dp[x], dp[topos[i]] + 1);
        }
    }
    int ans = 0;
    rep(i,1,n+1) ans = max(ans, dp[i]);
    cout<<ans<<endl;
}



Measured memory_bytes: 9464
import math

def is_prime(n):
	for i in range(2,math.floor(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True
 
cnt = 0
n=int(input())
for i in range(n):
    k=int(input())
    if is_prime(k):
        cnt+=1
print(cnt)


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  string s;
  cin >> s;
  if(s[0]==s[1]||s[2]==s[1]||s[2]==s[3]){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}


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

int a,b;
string s,t,u;

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);

    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if(u==s){
        cout<<a-1<<" "<<b;
    }else{
        cout<<a<<" "<<b-1;
    }
}


Measured memory_bytes: 764
using System;
class program{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int T = int.Parse(input[2]);
         
        if(A <= T){
            Console.WriteLine((T/A)*B);
        } else {
            Console.WriteLine(T/A);
        }
    }
}

Measured memory_bytes: 13140
import java.util.*;

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

    	if (a+b > c+d){
    		System.out.println("Left");
    	}else if (a+b == c+d){
    		System.out.println("Balanced");
    	}else {
    		System.out.println("Right");
    	}

    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;

const int maxn = 100010;
const int mod = 1000000007;

ll x[maxn], y[maxn];

int main()
{
	//freopen("D.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	ll tmp1 = 0, tmp2 = 0;
	for (int i=1;i<=n;i++) 
	{
		scanf("%lld",&x[i]);
		if (i==1) continue;
		tmp1 = (tmp1 + (ll)(i-1) * (ll)(n-(i-1)) * abs(x[i] - x[i-1])) % mod;
	}
	for (int i=1;i<=m;i++) 
	{
		scanf("%lld",&y[i]);
		if (i==1) continue;
		tmp2 = (tmp2 + (ll)(i-1) * (ll)(m-(i-1)) * abs(y[i] - y[i-1])) % mod;
	}
	ll ans = (tmp1 * tmp2) % mod;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define int long long

#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) reps(i, 0, n)

#define MAX_N 500005

using vint = vector<int>;
using Graph = vector<vint>;

int n;
Graph graph;

int dp1[MAX_N];
void dfs1(int root) {
  memset(dp1, -1, sizeof(dp1));
  stack<int> stk;
  stk.push(root);
  while(!stk.empty()) {
    int u = stk.top();
    if(dp1[u] == -1) {
      dp1[u] = 2-graph[u].size();
      for(int v : graph[u]) {
	stk.push(v);
      }
    } else {
      for(int v : graph[u]) {
	dp1[u] += dp1[v];
      }
      stk.pop();
    }
  }
}

int dp2[MAX_N];
int depth[MAX_N];
void dfs2(int root) {
  memset(dp2, -1, sizeof(dp2));
  stack<int> stk;
  stk.push(root);
  while(!stk.empty()) {
    int u = stk.top();
    if(dp2[u] == -1) {
      dp2[u] = dp1[u];
      for(int v : graph[u]) {
	depth[v] = depth[u] + 1;
	stk.push(v);
      }
    } else {
      for(int v : graph[u]) {
	dp2[u] += dp2[v];
      }
      stk.pop();
    }
  }
}

int dp3[MAX_N];
void dfs3(int root) {
  memset(dp3, -1, sizeof(dp3));
  stack<int> stk;
  stk.push(root);
  while(!stk.empty()) {
    int u = stk.top();
    if(dp3[u] == -1) {
      dp3[u] = 0;
      for(int v : graph[u]) {
	stk.push(v);
      }
    } else {
      if(graph[u].size() == 2) {
	int l = graph[u][0], r = graph[u][1];
	dp3[u] = min({dp3[l]+1+dp3[r]+1+depth[u], dp3[l]+1+dp2[r]+dp1[r], dp2[l]+dp1[l]+dp3[r]+1});
      } else if(graph[u].size() == 1) {
	int ch = graph[u][0];
	dp3[u] = min({dp3[ch]+1+1+depth[u], dp3[ch]+1+1, 1+dp2[ch]+dp1[ch]});
      } else {
	dp3[u] = dp1[u];
      }
      stk.pop();
    }
  }
}


signed main() {
  cin >> n;
  graph.resize(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if(a != n-1) graph[i].push_back(a);
    if(b != n-1) graph[i].push_back(b);
  }
  dfs1(0);
  dfs2(0);
  dfs3(0);
  cout << dp3[0] << endl;

  return 0;
}



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

#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(ll i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  ll N;
  cin >> N;
  FOR(h, 1, 3501){
    FOR(n, 1, 3501){
      ll s = (4*h*n - N*n - N*h);
      if(s == 0) continue;
      ll w = N*h*n / s;
      if(w <= 0) continue;
      if(4*h*n*w == N*(n*w+h*w+h*n)){
        cout << h << " " << n << " " << w << endl;
        return 0;
      }
    }
  }
  cout << "finish" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
constexpr int MOD = 1e9 + 7;
int x[605], y[605], pre[605];
long long dp[605][605], fact[605], ans;
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	n <<= 1;
	fact[0] = 1;
	for (int i = 2; i <= n; i++)
		fact[i] = fact[i - 2] * (i - 1) % MOD;
	for (int i = 0; i < k; i++)
	{
		scanf("%d%d", x + i, y + i);
		pre[--x[i]] = pre[--y[i]] = 1;
	}
	for (int i = 0; i < n; i++)
		pre[i] = !pre[i] + (i ? pre[i - 1] : 0);
	for (int l = 0; l < n; l++)
	{
		for (int r = l + 2; r <= n; r += 2)
		{
			auto in = [&] (int t) { return l <= t && t < r; };
			int cnt = pre[r - 1] - (l ? pre[l - 1] : 0);
			bool flg = true;
			for (int i = 0; i < k && flg; i++)
				flg &= in(x[i]) == in(y[i]);
			if (!flg || cnt & 1)
				continue;
			dp[l][r] = fact[cnt];
			for (int i = l + 2; i < r; i += 2)
				(dp[l][r] -= dp[l][i] * fact[pre[r - 1] - pre[i - 1]]) %= MOD;
			(ans += dp[l][r] * fact[n - cnt - (k << 1)]) %= MOD;
		}
	}
	printf("%lld\n", (ans + MOD) % MOD);
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<typename T> vector<T> tensor(int n, T v){ return vector<T>(n, v); }
template<typename... Ts> auto tensor(int n, Ts... ts) {
    return vector<decltype(tensor(ts...))>(n, tensor(ts...));
}

int main() {
  lint H, W, K;
  cin >> H >> W >> K;

  auto C = tensor(H, W, '$');
  for(lint i=0; i<H; i++)
  for(lint j=0; j<W; j++) {
    cin >> C[i][j];
  }

  lint ans = 0;
  lint base = 2;
  lint exp = H;
  for(lint poly = 0; poly < pow(base, exp); poly++) {
    lint tmp = poly;
    vector<lint> coef;
    for(lint i=0; i<exp; i++) {
      coef.push_back(tmp % base);
      tmp /= base;
    }

    lint base2 = 2;
    lint exp2 = W;
    for(lint poly2 = 0; poly2 < pow(base2, exp2); poly2++) {
      lint tmp2 = poly2;
      vector<lint> coef2;
      for(lint i=0; i<exp2; i++) {
        coef2.push_back(tmp2 % base2);
        tmp2 /= base2;
      }

      auto D = C;
      for(lint i=0; i<H; i++)
      for(lint j=0; j<W; j++) {
        if(coef[i] || coef2[j]) D[i][j] = '$';
      }

      lint counter = 0;
      for(lint i=0; i<H; i++)
      for(lint j=0; j<W; j++) {
        counter += (D[i][j] == '#');
      }

      if(counter == K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4068
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstdlib>
using namespace std;

static const  int N = 100;

int main() {

    int n, p[N+1], m[N+1][N+1];
    cin >> n;
    
    for (int i = 1; i <= n; i++) {
        cin >> p[i-1] >> p[i];
    }
    
    for (int i = 1; i <= n; i++) m[i][i] = 0;
    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j-1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3120
#解説参照
import sys
input = sys.stdin.readline
n,m = map(int, input().split( ))
a = [list(map(int, input().split( ))) for _ in range(n)]

M = {i for i in range(1,m+1)}
cnt = [0]*(m+1)
cursor = [0]*n
for i in range(n):
    cnt[a[i][0]]+=1

q = max(cnt)
ans = q
p = cnt.index(q)
for _ in range(m):##qでは不足
    cnt[p]=0
    M.remove(p)
    for i in range(n):
        if a[i][cursor[i]]==p:
            while a[i][cursor[i]] not in M:
                cursor[i]+=1
                if cursor[i]==m:
                    print(ans)
                    exit()
            cnt[a[i][cursor[i]]]+=1
    q2 = max(cnt)
    ans = min(ans,q2)
    p = cnt.index(q2)
print(ans)


Measured memory_bytes: 43356
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
	int ans = 0;
	int m, d; cin >> m >> d;
	for(int i = 1; i <= m; i++) {
		for(int j = 1; j <= d; j++) {
			int d1 = j % 10;
			int d10 = (j - d1) / 10;
			if(d1 * d10 == i && d1 >= 2 && d10 >= 2) ans ++;
		}
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
readline = sys.stdin.readline

N, T = map(int, readline().split())
A = list(map(int, readline().split()))
Amax = [None]*N
Amax[N-1] = A[N-1]
for i in range(N-2, -1, -1):
    Amax[i] = max(Amax[i+1], A[i])

B = [am - a for a, am in zip(A, Amax)]
print(Counter(B)[max(B)])

Measured memory_bytes: 68372
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
 	
int main() {
	int N,M;
	
	cin>>N>>M;
	
	int i=1;
	while(true){
		if(N*(i+1)>M){
			break;
		}else{
i++;
}
	}
	
	if(N*i==M){
		ce(i)
	}else{
		int k=M-N*i;
		while(k%i!=0){
			i--;
			k=M-N*i;
		}
		ce(i)
	}
	
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val arr = readLine()!!.split(" ").map { it.toInt() }

    val A = arr[0].toInt()
    val B = arr[1].toInt()
    val C = arr[2].toInt()
    val X = arr[3].toInt()
    val Y = arr[4].toInt()

    var result = 0

    // 何かロジックが汚いので再考、単発で大きい側の場合と小さい側の場合で処理分けできないか？
    // 単発での組み合わせは、両方、A, Bの3択。その中でA-Xが多いケースと少数派なケースがある。
    if (A > 2 * C && B > 2 * C) {

        result = if (X > Y) X * 2 * C else Y * 2 * C
    } else if (A > 2 * C) {

        result = if (X > Y) X * 2 * C else X * 2 * C + (X - Y) * B
    } else if (B > 2 * C) {

        result = if (X > Y) Y * 2 * C + (X - Y) * A else Y * 2 * C
    } else if (A + B > 2 * C) {

        result = if (X > Y) 2 * C * Y + (X - Y) * A else 2 * C * X + (Y - X) * B
    } else {
        result = X * A + Y * B
    }
    println(result)
}

Measured memory_bytes: 37868
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[200010];
  for(int i=0; i<N; i++) cin >> A[i];
  sort(A,A+N);
  for(int i=0; i<N-1; i++){
    if(A[i]==A[i+1]){
      cout << "NO" << endl;
      break;
    }
    if(i==N-2) cout << "YES" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int d,e;
main()
{
	while(cin>>d>>e,d)
	{
		double ans=1e9;
		for(int x=0;x<=d;x++)
		{
			int y=d-x;
			ans=fmin(ans,fabs(e-hypot(x,y)));
		}
		cout<<fixed<<setprecision(9)<<ans<<endl;
	}
}



Measured memory_bytes: 3280
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const long long mod=1e9+7;
int main()
{
	char s[100005];
	long long dp[3];
	long long pow3[100005];
	pow3[0]=1;
	for(int i=1;i<=100000;i++)
	{
		pow3[i]=(pow3[i-1]*3)%mod;
	}
	while(scanf("%s",s)!=EOF)
	{
		memset(dp,0,sizeof(dp));
		int l=strlen(s);
		int num=0;
		for(int i=0;i<l;i++)
		{
			if(s[i]=='A')
			{
				dp[0]+=pow3[num];

			}
			else if(s[i]=='B')
			{
				dp[1]+=dp[0];

			}
			else if(s[i]=='C')
			{
				dp[2]+=dp[1];

			}
			else
			{
				long long t1=dp[0];
				long long t2=dp[1];
				dp[0]=3*dp[0]+pow3[num];
				dp[1]=3*dp[1]+t1;
				dp[2]=3*dp[2]+t2;
				num++;
			}
				dp[0]%=mod;			
				dp[1]%=mod;	
				dp[2]%=mod;	

		}
		
		cout<<dp[2]<<endl;
	}

	return 0;
}

Measured memory_bytes: 1152
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N, K = li_input()

    if N % K == 0:
        print(0)
    else:
        print(1)


main()


Measured memory_bytes: 5436
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, input().split())
    price = [0]*m
    typesnum = [0]*m
    types = [[] for _ in range(m)]
    for i in range(m):
        price[i], typesnum[i] = map(int, input().split())
        types[i] = list(map(lambda x: int(x)-1, input().split()))
    dp = [10**9]*(1 << n)
    dp[0]=0
    for bit in range(1 << n):
        for i in range(m):
            keybit = 0
            for op in types[i]:
                keybit |= 1 << op
            dp[bit | keybit] = min(dp[bit | keybit], dp[bit]+price[i])
    if dp[-1] == 10**9:
        dp[-1] = -1
    print(dp[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 74460
#include<stdio.h>
int main()
{
    int a[1000],i,j,n,k,temp,m;
        for(m=0;m<10;m++){
            scanf("%d",&a[m]);
        }
     for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            if (a[i]>a[j]){
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
     }
     for(k=0;k<3;k++){
     printf("%d\n",a[k]);}
 return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int n, k;
int h[100100];
int dp[100100];

int main()
{
    cin >> n >> k;
    rep(i, n)
    {
        dp[i] = inf;
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; i++)
    {
        int K = min(k, i);
        for (int j = 1; j <= K; j++)
        {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def ketawa(x):
	return sum(map(int, list(str(x))))

N = input()

if len(N) == 1:
	print(N)
else:
	if N[0] == 1:
		print(max(ketawa(N),9*(len(N)-1)))
	else:
		print(max(ketawa(N), int(N[0])-1+9*(len(N)-1)))


Measured memory_bytes: 5204
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL X;
    R(X);
    FOR(i,-1000,1000){
        FOR(j,-1000,1000){
            LL A=i;
            LL B=j;
            if(A*A*A*A*A-B*B*B*B*B==X){
                W(A,B);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ax = Math.abs(x - a);
        int bx = Math.abs(x - b);
        System.out.println(ax < bx ? "A" : "B");
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <iostream>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N_ = 100500;
int N, K, A[N_];
ll S[N_], T[N_];

int main() {
	scanf("%d%d", &N, &K);
	for(int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		S[i] = S[i-1] + A[i];
		T[i] = T[i-1] + (A[i] > 0 ? A[i] : 0);
	}

	ll ans = 0;
	for(int i = 1, j = K; j <= N; i++, j++) {
		// [i..j]
		ll cur = 0;
		cur += T[N] - (T[j] - T[i-1]);
		if(S[j] - S[i-1] >= 0) cur += S[j] - S[i-1];
		ans = max(ans, cur);
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2304
import math
n = input()
arr = list(map(int, input().split()))
a = sum(arr) // len(arr)
b = a + 1
'''
arr.sort()
if len(arr) % 2 == 0:
    mid = len(arr) // 2
    avg = (arr[mid] + arr[mid-1]) // 2
else:
    mid = len(arr) // 2
    avg = arr[mid]

print(avg)
'''
ans = 0
ans2 = 0
for p in arr:
    ans += (a - p)**2
    ans2  += (b - p)**2
print(min(ans, ans2))


Measured memory_bytes: 9048
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,m,k,a[200100],l[200100][20],r[200100][20],f[270000],g[270000],ans[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()) && ch!='-');
    bool flag=ch=='-';
    if (flag)
        ch=getchar();
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return flag?-x:x;
}

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,1,n)
        a[i]=getint();
    for (k=0; m>>k; ++k);
    a[0]=a[1]-m-1,a[n+1]=a[n]+m+1;
    repu(i,0,k)
        r[n+1][i]=n;
    repu(i,1,n)
        repu(j,0,k)
        {
            l[i][j]=a[i]-a[i-1]>m>>j?i:l[i-1][j];
            for (r[i][j]=max(r[i-1][j],i); a[r[i][j]+1]-a[r[i][j]]<=m>>j; ++r[i][j]);
        }
    repu(i,0,(1<<k)-1)
        g[i]=n+1;
    repu(i,0,(1<<k)-1)
        repu(j,1,k)
            if (!(i&(1<<(j-1))))
            {
                int t=i|(1<<(j-1));
                f[t]=max(f[t],r[f[i]+1][j]);
                g[t]=min(g[t],l[g[i]-1][j]);
            }
    repu(i,0,(1<<k)-1)
    {
        int x=f[i],y=g[(1<<k)-1-i];
        if (x+1>=y)
            ++ans[1];
        else
            if (r[x+1][0]+1>=y)
                ++ans[l[x+1][0]],--ans[r[x+1][0]+1];
    }
    repu(i,1,n)
        puts((ans[i]+=ans[i-1])?"Possible":"Impossible");
    return 0;
}

Measured memory_bytes: 37248
// https://beta.atcoder.jp/contests/abc104/submissions/2952569

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  string s;
  bool flg = false;
  cin >> s;
  int len = s.length();
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }else{
    for(int i = 1; i < len; i++){
       if(s[i] == 'C' && (i > 1 && i <= len - 2)){
        if(flg){
          cout << "WA" << endl;
          return 0;
        }
        flg = true;
        continue;
      }
      if(!(islower(s[i]))){
        cout << "WA" << endl;
        return 0;
      }
    }
  }
  if(flg)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int ans[3][3] =
{
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 0}
};
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

int match(int f[3][3]) {
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (f[i][j] != ans[i][j])
                return 0;
        }
    }
    return 1;
}

int dfs(int f[3][3], int x, int y, int v, int d, int l) {
    if (match(f))
        return d;
    if (d > l)
        return -1;
    for (int i = 0, res; i < 4; ++i) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx > 2 || ny < 0 || ny > 2 || (i + 2) % 4 == v)
            continue;
        f[y][x] = f[ny][nx];
        f[ny][nx] = 0;
        if ((res = dfs(f, nx, ny, i, d + 1, l)) > 0)
            return res;
        f[ny][nx] = f[y][x];
        f[y][x] = 0;
    }
    return -1;
}

int main() {
    int f[3][3], x, y;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            scanf("%d", &f[i][j]);
            if (f[i][j] == 0) {
                y = i;
                x = j;
            }
        }
    }

    int res;
    for (int i = 1; i < 50; ++i) {
        if ((res = dfs(f, x, y, -1, 0, i)) >= 0) {
            break;
        }
    }
    printf("%d\n", res);

    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> d;
    d.assign(n, {});
    for (int q = 0; q < n-1; q++){
        int x, y;
        cin >> x >> y;
        d[x-1].push_back(y-1);
        d[y-1].push_back(x-1);
    }
    for (int q = 0; q < n; q++){
        sort(d[q].rbegin(), d[q].rend());
    }
    int ans = 1, last = 1;
    for (int q = 1; q < n; q++){
        int now = 0, last1 = q;
        for (int q1: d[q]){
            if (q1 < q){
                last -= (last1 - q1) * (now-1);
                now++, last1 = q1;
            }
        }
        last -= (last1+1) * (now-1);
        ans += last;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15784
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    r_cnt = 0
    l_cnt = 0
    flag = True  # counting "R"
    for idx, s in enumerate(S):
        if flag and s == "R":
            r_cnt += 1
        elif flag and s == "L":
            flag = False
            l_cnt += 1
        elif not flag and s == "L":
            l_cnt += 1
        elif not flag and s == "R":
            if r_cnt > 1:
                print(" ".join(["0"] * (r_cnt - 1)), end=" ")
            print((r_cnt // 2) + (r_cnt % 2) + l_cnt // 2, r_cnt // 2 + (l_cnt // 2) + l_cnt % 2, end=" ")
            if l_cnt > 1:
                print(" ".join(["0"] * (l_cnt - 1)), end=" ")
            l_cnt = 0
            r_cnt = 1
            flag = True

    if r_cnt > 1:
        print(" ".join(["0"] * (r_cnt - 1)), end=" ")
    print((r_cnt // 2) + (r_cnt % 2) + l_cnt // 2, r_cnt // 2 + (l_cnt // 2) + l_cnt % 2, end=" ")
    if l_cnt > 1:
        print(" ".join(["0"] * (l_cnt - 1)), end=" ")
    print()


if __name__ == "__main__":
    main()


Measured memory_bytes: 76992
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n)scanf("%d",&a[i]);
  sort(a,a+n);
  int i=0,ans=0;
  while(i<n){
    if(a[i]==a[i+1])
      i+=2;
    else{
      ans++;
      i++;
      }
    }
  printf("%d\n",ans);
  return 0;
  }

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
#endif
  int N, cnt = 0, flag = false;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    int x, y;
    cin >> x >> y;
    if (x == y)
      ++cnt;
    else
      cnt = 0;
    if (cnt >= 3) flag = true;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
input = gets(nil)

input.split("\n").each do |l|
  a, b, c, d, e, f = l.split(" ").map(&:to_f)

  x = ((c*e - b*f) / (a*e - d*b)).round(3)
  x = 0.000 if x.zero?
  y = ((c*d - a*f) / (b*d - a*e)).round(3)
  y = 0.000 if y.zero?
  printf "%.3f %.3f\n", x, y
end

Measured memory_bytes: 6192
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	char s;
	int n,m;
	scanf("%d",&n);
	cin>>s;
	scanf("%d",&m);
	if(s=='+')	printf("%d",n+m);
	if(s=='-')	printf("%d",n-m);
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			u = scanner.nextInt();
			if ((n | u) == 0)
				break;
			need = new int[n];
			int all = 0;
			unit = new int[n];
			num = new int[n];
			for (int i = 0; i < n; i++) {
				unit[i] = num[i] = scanner.nextInt();
				all += unit[i];
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					int x = scanner.nextInt();
					need[i] |= (1 << x);
				}
			}
			if (all == u) {
				System.out.println(n);
				continue;
			}
			Arrays.sort(num);
			int sum = 0;
			for (int i = n - 1; i >= 0; i--) {
				sum += num[i];
				if (sum >= u) {
					m = n - i;
					break;
				}
			}
			v = new boolean[1 << n];
			for (int i = m; i < n; i++) {
				if (slove(0, 0, 0, i)) {
					System.out.println(i);
					break;
				}
				Arrays.fill(v, false);
			}
		}

	}

	private boolean slove(int bit, int one, int have, int depth) {
		if (u <= have)
			return true;
		if (one == depth)
			return false;
		for (int i = 0; i < n; i++) {
			int a = bit | (1 << i);
			if (v[a] || (bit | need[i]) != bit)
				continue;
			v[a] = true;
			if (slove(a, one + 1, have + unit[i], depth))
				return true;
		}
		return false;
	}

	int m;
	int n, u;
	int[] need, unit, num;
	int ans;
	boolean[] v;
}

Measured memory_bytes: 56680
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 5;
int pre[MAXN],other[MAXN],last[MAXN];
long long dis[MAXN],cost[MAXN];
int all,n,q,k;
int seq[MAXN];
bool Inque[MAXN];
void Build(int x, int y, LL w){
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

void Bfs(int x){
	int head = 1, tail = 1, now, dt, dr;
	seq[tail] = x;
	for(int i = 1; i <= n; i++)
	{
		if(i == x) dis[i] = 0;
		else dis[i] = 1LL << 60;
	}
	Inque[x] = 1;
	while(head <= tail){
		now = seq[head];
		dt = last[now];
		while(dt != -1){
			dr = other[dt];
			if(dis[now] + cost[dt] < dis[dr]){
				dis[dr] = dis[now] + cost[dt];
				if(!Inque[dr]){
					Inque[dr] = 1; 
					seq[++tail] = dr;
				}
			}
			dt = pre[dt];
		}
		Inque[now] = 0;
		head++;
	}
}

int main()
{
	all = -1;
	memset(last, -1, sizeof(last));
	scanf("%d",&n);
	
	for(int i = 1; i < n; i++){
		int a,b;
		LL w;
		scanf("%d%d%lld",&a,&b,&w);
		Build(a,b,w);
		Build(b,a,w);
	}
	memset(seq, 0,sizeof(seq));
	memset(Inque, 0, sizeof(Inque));
	scanf("%d%d",&q,&k);
	Bfs(k);
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%lld\n",dis[x]+dis[y]);
	}
}

Measured memory_bytes: 22272
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

template <typename T>
struct WeightedUnionFind{
  vector<Int> rs,ps;
  vector<T> ws;

  WeightedUnionFind(){}
  WeightedUnionFind(Int n):
    rs(n,1),ps(n),ws(n,T(0)){iota(ps.begin(),ps.end(),0);}

  Int find(Int x){
    if(x==ps[x]) return x;
    Int t=find(ps[x]);
    ws[x]+=ws[ps[x]];
    return ps[x]=t;
  }

  T weight(Int x){
    find(x);
    return ws[x];
  }

  bool same(Int x,Int y){
    return find(x)==find(y);
  }

  void unite(Int x,Int y,T w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);y=find(y);
    if(x==y){
      if(w!=T(0)){
        cout<<"No"<<endl;
        exit(0);
      }
      return;
    }
    if(rs[x]<rs[y]) swap(x,y),w=-w;
    rs[x]+=rs[y];
    ps[y]=x;
    ws[y]=w;
  }

  T diff(Int x,Int y){
    return weight(y)-weight(x);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  Int n;
  cin>>n;
  vector<Int> rs(n),cs(n),as(n);
  for(Int i=0;i<n;i++) cin>>rs[i]>>cs[i]>>as[i],rs[i]--,cs[i]--;

  WeightedUnionFind<Int> wuf(h+w);

  for(Int i=0;i<n;i++)
    wuf.unite(rs[i],h+cs[i],as[i]);

  vector< vector<Int> > G(h+w);
  for(Int i=0;i<h+w;i++)
    G[wuf.find(i)].emplace_back(i);

  for(auto vs:G){
    if(vs.empty()) continue;
    vector<Int> ys,xs;
    for(Int v:vs){
      if(v<h) ys.emplace_back(v);
      else xs.emplace_back(v);
    }
    if(ys.empty()) continue;
    if(xs.empty()) continue;

    Int s=ys[0];
    for(Int y:ys)
      if(wuf.diff(y,s)<0) s=y;

    Int t=xs[0];
    for(Int x:xs)
      if(wuf.diff(x,t)>0) t=x;

    //cout<<wuf.diff(s,t)<<endl;

    if(wuf.diff(s,t)<0){
      cout<<"No"<<endl;
      return 0;
    }
  }

  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 18036
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000+1
#define mod 1000000000+7
#define rep(a,b) for(ll i=a;i<b;i++)
#define rep1(a,b) for(ll j=a;j<b;j++)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()
{ios
ll h=0,w=0;
cin>>h>>w;
char grid[h][w];

rep(0,h)
	rep1(0,w)
		cin>>grid[i][j];
ll dp[h][w];

rep(0,h)
	rep1(0,w)
		{
			if(grid[i][j]=='#')
			dp[i][j]=0;

			else dp[i][j]=-1;
		}

dp[h-1][w-1]=1;

for(ll i=h-2;i>=0;i--)
{if(dp[i][w-1]!=0)
	dp[i][w-1]=dp[i+1][w-1];
}

for(ll i=w-2;i>=0;i--)
{if(dp[h-1][i]!=0)
	dp[h-1][i]=dp[h-1][i+1];
}

for(ll i=h-2;i>=0;i--)
	for(ll j=w-2;j>=0;j--)
    {
        if(dp[i][j]!=0)
        dp[i][j]=(dp[i][j+1]+dp[i+1][j]);
        dp[i][j]%=mod;
    }
cout<<dp[0][0];
/*
cout<<endl;
rep(0,h)
{
    rep1(0,w)
		{
		    cout<<dp[i][j]<<' ';
		}
cout<<endl;
}
*/
return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  for (int i = 0; i < S.length(); i++) {
    if (S[i]=='1') cout << "9";
    else if (S[i]=='9') cout << "1";
    else cout << S[i];
  }
  cout << endl;
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0; i<n; i++)cin>>p.at(i);

  int ans=0;
  for(int i=0; i<n-1; i++){
    if(p.at(i)==i+1){
      swap(p.at(i), p.at(i+1));
      ans++;
    }
  }
  if(p.at(n-1)==n)ans++;
  cout<<ans<<endl;
}


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

const ll M = 1e9 + 7;
const ll N  = 1e6+5;
ll f[N], iv[N];

ll binpow(ll a, ll b, ll m = M) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll nCr(ll n, ll r) {
    if (n < r) return 0;
    ll sol = (f[n] % M * iv[r] % M) % M;
    return (sol * iv[n - r] % M) % M;
}

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    f[0] = iv[0] = 1;
    for (int i = 1; i < N; ++i) f[i] = (f[i - 1] * i) % M;
    iv[N - 1] = binpow(f[N - 1], M - 2);
    for (int i = N - 2; i >= 0; --i) iv[i] = (iv[i + 1] * (i + 1)) % M;

    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    ll sol = 0;
    for (int i = b; i < w; ++i) {
        ll p1 = i;
        ll q1 = h - a - 1;
        ll part1 = nCr(p1 + q1, p1);
        ll p2 = w - 1 - i;
        ll q2 = a - 1;
        ll part2 = nCr(p2 + q2, q2);
        part1 %= M;
        part2 %= M;
        sol = (sol + (part1 * part2) % M) % M;
    }
    
    cout << sol << "\n";
    return 0;
}


Measured memory_bytes: 19268