akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef pair<P,P> PP;
typedef long long ll;


int W,H;
string roomL[55],roomR[55];

bool range_check(int y,int x) {

    return 0<=y&&y<H && 0<=x&&x<W;
}

bool visited[55][55][55][55];
bool ok(P len,P rin) {
    memset(visited,0,sizeof(visited));
    visited[len.fr][len.sc][rin.fr][rin.sc]=true;
    queue<PP> que;
    que.push(PP(len,rin));

    while(que.size()) {
        PP pp=que.front(); que.pop();
        P next_len=pp.fr;
        P next_rin=pp.sc;

        //printf("[debug] %d %d %d %d\n",next_len.fr,next_len.sc,next_rin.fr,next_rin.sc);

        rep(i,4) {
            next_len=pp.fr;
            next_rin=pp.sc;
            next_len.fr+=dy[i];
            next_len.sc+=dx[i];
            next_rin.fr+=dy[i];
            next_rin.sc-=dx[i];
            
            if(!range_check(next_len.fr,next_len.sc) || roomL[next_len.fr][next_len.sc]=='#') {
                next_len=pp.fr;
            }

            if(!range_check(next_rin.fr,next_rin.sc) || roomR[next_rin.fr][next_rin.sc]=='#') {
                next_rin=pp.sc;
            }

            if((roomL[next_len.fr][next_len.sc]=='%')&&(roomR[next_rin.fr][next_rin.sc]=='%')) return true;
            if((roomL[next_len.fr][next_len.sc]=='%')||(roomR[next_rin.fr][next_rin.sc]=='%')) continue;
            if(visited[next_len.fr][next_len.sc][next_rin.fr][next_rin.sc]) continue;

            visited[next_len.fr][next_len.sc][next_rin.fr][next_rin.sc]=true;
            que.push(PP(next_len,next_rin));

        }
    }

    return false;
}

void solve() {
    rep(y,H) cin>>roomL[y]>>roomR[y];
    P len,rin;
    rep(y,H) rep(x,W) {
        if(roomL[y][x]=='L') len=P(y,x);
        if(roomR[y][x]=='R') rin=P(y,x);
    }
    if(ok(len,rin)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main() {
    while(cin>>W>>H) {
        if(!W) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 11088
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int[] memo=new int[10];
		for(int s=0;s<10;s++)memo[s]=in.nextInt();
		Arrays.sort(memo);
		for(int i=9;i>=7;i--)System.out.println(memo[i]);
	}
}

Measured memory_bytes: 17364
# 上位ノードほど @rank が大きい数字となる
class Node
  attr_accessor :parent, :rank

  # 親は自分自身、ランクは 0 として初期化する
  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFind
  # 0 から n - 1 までのノードを初期化する
  def initialize(n)
    @nodes = (0...n).map { |i| Node.new(i) }
  end

  # 再帰で最も上位の親を探し、その値を返す（更新しないため少し遅い）
  def root(x)
    return x if @nodes[x].parent == x
    root(@nodes[x].parent)
  end

  # a と b を仲間にする
  def unite(a, b)
    a_root = root(a)
    b_root = root(b)
    # a 及び b の親が同じ場合は何もしない
    return if a_root == b_root

    # a親ランク < b親ランク の場合は、b親をa親の親とする
    # なお、ランクをいじる必要はなし
    if @nodes[a_root].rank < @nodes[b_root].rank
      @nodes[a_root].parent = b_root
    # その他の場合は、a親をb親の親とする
    else
      @nodes[b_root].parent = a_root
    # a親、及びb親のランクが同じ場合は、a親のランクを +1 する
      @nodes[a_root].rank += 1 if @nodes[a_root].rank == @nodes[b_root].rank
    end
  end

  # a と b の最も上位の親が同じかどうかを返す
  def same?(a, b)
    root(a) == root(b)
  end

  # 各ノードの親を全て出力する確認用
  def parents
    @nodes.map(&:parent)
  end

  # 各ノードの最も上位の親を全て出力する確認用
  def roots
    @nodes.size.times.map { |i| root(i) }
  end
end

n, m = gets.split.map(&:to_i)
uf = UnionFind.new(n)
edges = []
m.times do
  a, b = gets.chomp.split.map(&:to_i)
  edges << [a, b]
end
edges.each do |a, b|
  uf.unite(a - 1, b - 1)
end
roots = uf.roots
puts roots.tally.values.max


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    LL N;
    cin >> N;
    LL M;
    cin >> M;

    LL ans = 1;

    for (LL x = 1; x * x <= M; x++)
    {
        if (M % x == 0)
        {
            if (M / x >= N)
                ans = max(ans, x);

            if (x >= N)
                ans = max(ans, M / x);
        }
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
2 60
10 10
100 100
---+/
/+---test
3 60
10 10
10 20
10 30
---+/
/+---test
3 60
30 10
30 20
30 30
---+/

void main(string[] args) {
  int N, T;
  readf(" %d %d ", &N, &T);

  struct Item { long c, v; }
  auto items = new Item[N];
  foreach (ref item; items) readf(" %d %d ", &item.c, &item.v);

  auto dp0 = new long[T], dp1 = new long[T];
  foreach (i; 0..N) {
    foreach_reverse (t; 0..T) if (t + items[i].c < T) {
      dp1[t+items[i].c].amax(dp1[t] + items[i].v);
    }

    foreach (t; 0..T) dp1[t].amax(dp0[t] + items[i].v);

    foreach_reverse (t; 0..T) if (t + items[i].c < T) {
      dp0[t+items[i].c].amax(dp0[t] + items[i].v);
    }
  }
  long ans;
  chain(dp0, dp1).maxE.writeln;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string a;
	cin >> a;

	ll n = a.size();

	ll b[26][n+1];
	rep(i,26) rep(j,n+1) b[i][j] = 0;

	rep(i,n) b[a[i]-'a'][0]++;

	rep(i,n-1){
		rep(j,26) b[j][i+1] = (a[i]-'a' == j ? b[j][i]-1:b[j][i]);
	}

	ll ans = 1;
	rep(i,n-1){
		rep(j,26) if(j != a[i]-'a') ans += b[j][i+1];
	}

	cout << ans << endl;
}

Measured memory_bytes: 41236
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,ac=0,re=0,tle=0,wa=0;
	string s;
	cin>>n;
	while(n--)
	{
		cin>>s;
		if(s=="AC")
		{
			ac++;
		}
		else if(s=="WA")
		{
			wa++;
		}
		else if(s=="TLE")
		{
			tle++;
		}
		else
		{
			re++;
		}
	}
	cout<<"AC"<<" x "<<ac<<"\n";
	cout<<"WA"<<" x "<<wa<<"\n";
	cout<<"TLE"<<" x "<<tle<<"\n";
	cout<<"RE"<<" x "<<re;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define cons 1000001
using namespace std;
int main(){
long long X;
cin>>X;
bool arr[cons]={0};
arr[0]=1;
arr[1]=1;
//cout<<arr[2];
//for(int i=0;i<cons;i++)
//cout<<arr[i];
for(long long i=2;i<=pow(cons-1,0.5);i++){
   // cout<<arr[i]<<endl;
    if(arr[i]==0){
            //cout<<i;
        long long c=2;
        while(i*c<=cons){
            arr[i*c]=1;
            c++;
        }
    }
}
//cout<<"yo";
for(long long i=X;i<cons;i++){
        //cout<<"yo";
if(arr[i]==0){
    cout<<i<<"\n";
    break;
    }
}
}


Measured memory_bytes: 1280
#!/usr/bin/env python3
n = int(input())
s = [input() for _ in range(n)]
ans = 0
xa = 0
bx = 0
bxa = 0
for c in s:
    ans += sum(c[i:i + 2] == 'AB' for i in range(len(c) - 1))
    if c[0] == 'B':
        bx += 1
    if c[-1] == 'A':
        xa += 1
    if c[0] == 'B' and c[-1] == 'A':
        bx -= 1
        xa -= 1
        bxa += 1
ans += max(0, bxa - 1)
bxa = 0 + (bxa > 0)
ans += min(xa, bxa)
ans += min(bxa, bx)
rxa = max(0, xa - bxa)
rbx = max(0, bx - bxa)
ans += min(rxa, rbx)
print(ans)


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

using namespace std;
#define ll unsigned long long
ll n,curA,curT,sum,x;
const ll lim=1e18;

ll bin(ll L,ll R,ll k,ll lim)
{
  if(R-L<=2)
    {
      if(L*k>=lim)
	return L;
      else if((L+1)*k>=lim)
	return L+1;
      return R;
    }
  ll mid=(R+L)/2;
  if(mid*k<=0)
    return bin(L,mid,k,lim);
  
  if(mid*k<lim)
    return bin(mid+1,R,k,lim);
  return bin(L,mid,k,lim);
}
int main()
{
  cin>>n;
  curA=1;
  curT=1;
  sum=2;
  for(int i=1;i<=n;i++)
    {
      ll T,A;
      cin>>T>>A;
      //ll x=ceil((double)(curA+curT)/(T+A));
      //cout<<T<<A<<endl;
      ll x=0;
      //x=max(x,(ll)ceil((double)(curA)/A));
      //x=max(x,(ll)ceil((double)(curT)/T));
      //x=max(x,bin(1,lim,A,curA));
      //x=max(x,bin(1,lim,T,curT));
      x=max((curA-1)/A+1,(curT-1)/T+1);
      sum=x*(T+A);
      curA=x*A;
      curT=x*T;
    }
  cout<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 256
def paintout_graph(s, g, color):
    cnt, pre_color = 0, s[0]
    que = [0]
    for pos in que:
        if s[pos] == pre_color:
            s[pos] = color
            cnt +=1
            que.extend(g[pos])
    return cnt
def bfs(s, graph):
    que = deque([(s,0,0)])
    while True:
        s,pre_cnt,depth = que.popleft()
        pre_color = s[0]
    
        colors = ['R','G','B']
        colors.remove(pre_color)

        for si, color in zip((s,s[:]),colors):
            cnt = paintout_graph(si,graph,color)
            if cnt == len(si):
                return depth
            if cnt == pre_cnt:
                break
            que.append((si,cnt,depth + 1))
from collections import deque
def paintout_sq(s, color,w,h,x,y):
    neighbor, pre_color = set(), s[y*w+x]

    que = deque([(x, y)])
    while len(que):
        x, y = que.pop()
        pos = y * w + x
        if s[pos] == pre_color:
            s[pos] = color
            if 0 < x:que.append((x-1,y))
            if 0 < y:que.append((x,y-1))
            if x + 1 < w:que.append((x+1,y))
            if y + 1 < h:que.append((x,y+1))
        elif s[pos] != color and isinstance(s[pos], int):
            neighbor.update([s[pos]])

    return neighbor

import sys
f = sys.stdin

while True:
    w, h = map(int, f.readline().split())
    if w == h == 0:
        break
    s = [f.readline().split() for _ in range(h)]
    s = [y for x in s for y in x]
    p = []
    graph = {}
    for y in range(h):
        for x in range(w):
            pos = y*w+x
            if s[pos] in ('R','G','B'):
                k = len(p)
                p.append(s[pos])
                neighbor = paintout_sq(s,k,w,h,x,y)
                neighbor = list(neighbor)
                try:
                    graph[k].expand(neighbor)
                except KeyError:
                    graph[k] = neighbor
                for ni in neighbor:
                    try:
                        graph[ni].append(k)
                    except KeyError:
                        graph[ni] = [k]
    print(bfs(p,graph))

Measured memory_bytes: 66228
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

if N < M:
    print('NO')
    exit()

D.sort()
T.sort()
i = 0
j = 0
while i < N and j < M:
    if D[i] == T[j]:
        i += 1
        j += 1
    else:
        i += 1

if j == M:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 39300
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll N, D;
    cin >> N >> D;
    vector<ll> X(N), Y(N);
    REP(i, N) { cin >> X[i] >> Y[i]; }
    ll D2 = D * D;
    int cnt = 0;
    REP(i, N) {
        if(X[i] * X[i] + Y[i] * Y[i] <= D2) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6424
#include<cstdio>
int main(){
	char a[10]={};
	char b[10]={};
	char c[10]={};
	scanf("%s%s%s",a,b,c);
	char s[4]={};
	s[0]=a[0]+'A'-'a';
	s[1]=b[0]+'A'-'a';
	s[2]=c[0]+'A'-'a';
	printf("%s",s);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

const int MAX_N = 160010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) {
        cin >> S[i];
    }
    init(H * W);
    rep(i, H - 1) {
        rep(j, W) {
            if (S[i][j] == '#' && S[i + 1][j] == '.') unite(i * W + j, i * W + W + j);
            if (S[i][j] == '.' && S[i + 1][j] == '#') unite(i * W + j, i * W + W + j);
        }
    }
    rep(i, H) {
        rep(j, W - 1) {
            if (S[i][j] == '#' && S[i][j + 1] == '.') unite(i * W + j, i * W + 1 + j);
            if (S[i][j] == '.' && S[i][j + 1] == '#') unite(i * W + j, i * W + 1 + j);
        }
    }
    vector<ll> b(H * W, 0), w(H * W, 0);
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '#') b[find(i * W + j)]++;
            if (S[i][j] == '.') w[find(i * W + j)]++;
        }
    }
    ll ans = 0;
    rep(i, H * W) {
        ans += b[i] * w[i];
        //cout << b[i] << " " << w[i] << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
H, W = gets.split.map(&:to_i)
M = H.times.map{ gets.split.map(&:to_i) }
T = []

path = Enumerator.new do |it|
  (1 .. H).each do |y|
    if y.odd?
      (1 .. W).each do |x|
        it << [y, x]
      end
    else
      (1 .. W).reverse_each do |x|
        it << [y, x]
      end
    end
  end
end

path.each_cons(2) do |u,v|
  sy,sx = u
  ty,tx = v
  
  if M[sy-1][sx-1].odd?
    T << "#{sy} #{sx} #{ty} #{tx}"
    M[ty-1][tx-1] += 1
  end
end

puts T.size
puts T

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

int main(){
	string a;
	int count =0;

	cin>>a;

	for(int i=0;i<3;i++){
		if (a.at(i) == '1'){
			count =count+1;
		}
		
	} 
	cout<<count;

}

Measured memory_bytes: 256
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef  long long int  ll;
typedef long double ld;
/*
cin>>str;
getline(cin,str);
*/
/*
ifstream f("data.in");
ofstream g("data.out");
*/


///*******Define******///
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define mid(s,e)   (s+(e-s)/2)
///******************///

///******Constants****///
const long long mod = 1e9+7;
const long long MODP = 998244353;
const long long mini = INT_MIN;
const long long maxi = 0x3f3f3f3f;
///********************///

///*****Utility*******///
inline ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
inline ll power(ll a, ll n, ll mod){ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
inline ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
inline ll lcm(ll a,ll b) { return ((a*b)/gcd(a,b)); }
inline ll modinverse(ll a,ll m) { ll m0 = m;ll y = 0, x = 1; if (m == 1) return 0; while (a > 1){ ll q = a / m; ll t = m; m = a % m, a = t;t = y; y = x - q * y; x = t; }if (x < 0) x += m0; return x; }
///*******************///

///*******************///
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>PBDS;
#define p(i,n,vect) for(ll i=0;i<(ll)n;++i) {cout<<vect[i]<<" ";} cout<<"\n";
///******************///

///******Variable Declarations***///
ll K;
///******************************///

void solve()
{
    cin>>K;
    ll ulti=0;
    for(ll i=1;i<=1e7;i++)
    {
        ulti=(ulti*10+7)%K;
        if(ulti==0)
        {
            cout<<i<<"\n";return;
        } 
    }
    cout<<"-1"<<"\n";
}

signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   
    solve();
}
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*****END*****<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/

Measured memory_bytes: 3668
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]

    def __str__(self):  # print 表示用
        return '\n'.join('{}: {}'.format(r, self.group_members(r)) for r in self.roots())


N, M = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(M)]
ans = [0]*M

uf = UnionFind(N)

# うしろからつないでいく
ans[M-1] = N*(N-1)//2
for i in range(1, M):
    A, B = bridge[M-i]

    if uf.is_same(A-1, B-1):
        ans[M-i-1] = ans[M-i]
    else:
        ans[M-i-1] = ans[M-i] - uf.group_size(A-1) * uf.group_size(B-1)

    uf.unite(A-1, B-1)


for a in ans:
    print(a)


Measured memory_bytes: 36436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;
int main(){
   ll n,a,b;
   cin >> n >> a >> b;
   priority_queue<ll> pq;
   int tmp;
   int now;
   ll ans=0;
   cin >> tmp;
   for(int i=1;i < n;i++){
     cin >> now;
     ans+=min(b,(now-tmp)*a);
     //printf("now-tmp %d\n",now-tmp);
     tmp=now;
     //printf("ans: %lld\n",ans);
   }
   cout << ans << endl;

   

   return 0;
}



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

int solve(int n) {
  int cnt = 0;
  for (int i = 1;i <= n / 2; i++) {
    int m = 0;
    int j = i;
    while(m < n) m += j++;
    if (m == n)  cnt++;
  }
  return cnt;
}

int main() {
  int n;
  while(cin >> n, n) {
    cout << solve(n) << endl;
  }
  return 0;
}


Measured memory_bytes: 2988
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << min(A,B) + min(C,D) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [0]+list(map(int, input().split()))
box = [None]+[0]*(N)
cnt = 0
   
for i in range(N, 0, -1):
    mult = [j for j in range(i,N+1,i)]
    sm = 0
    for m in mult:
        if box[m]:
            sm += 1
    if sm%2 != a[i]:
        box[i] = 1
        cnt += 1
        #print(box)
print(cnt)        
print(" ".join(map(str,[i for i,b in enumerate(box) if b])))

Measured memory_bytes: 26540
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

ll H, W;
ll sy, sx, gy, gx;
char a[52][52];
int d[52][52];

void bfs(){
	queue<P> que;

	for (int h = 1; h <= H; h++)
		for (int w = 1; w <= W; w++) d[h][w] = INF;

	que.push(P(sy, sx));
	d[sy][sx] = 0;

	while (que.size()>0){
		P p = que.front();
		que.pop();

		if (p.first == gy && p.second == gx) break;

		for (int i = 0; i < 4; i++){
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (1<=ny && ny<=H && 1<=nx && nx <= W && 
				a[ny][nx] == '.' && d[ny][nx] == INF){
				que.push(P(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
}

signed main(){

	cin >> H >> W;

	sx = sy = 1;
	gx = W; gy = H;

	int wall = 0;
	for (int h = 1; h <= H; h++)
		for (int w = 1; w <= W; w++){
			cin >> a[h][w];
			if (a[h][w] == '#') wall++;
		}

	bfs();

	if (d[gy][gx] == INF) cout << -1 << endl;
	else
		cout << H*W - wall - d[gy][gx]-1 << endl;

	return 0;
}


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

#define LIMIT 1205

int main() {
    char ss[LIMIT];
    int ary[26] = {
        0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,
    };

    while (1) {
        for (int i=0; i<LIMIT; ++i) {
            ss[i] = '\0';
        }
        fgets(ss, LIMIT, stdin);
        char *ln = strchr(ss, '\n');
        if (ln != NULL) {
            *ln = '\0';
        }
        if (ss[0] == '\0') {
            break;
        }

        int len = strlen(ss);
        for (int i=0; i<len; ++i) {
            char c = ss[i];
            if (c >= 'a' && c <= 'z') {
                ary[(int)c - (int)'a'] += 1;
            } else if (c >= 'A' && c <= 'Z') {
                ary[(int)c - (int)'A'] += 1;
            }
        }
    }
    for (int i=0; i<26; ++i) {
        printf("%c : %d\n", (int)'a' + i, ary[i]);
    }
    return 0;
}



Measured memory_bytes: 2060
#include<iostream>
#include<algorithm>
using namespace std;
int D=365;
int K=26;
int main()
{
  int d,cc=0,m=0,i,j,r,rj,res=0;
  int c[K],s[D][K],t[D],l[K];
  cin >> d;
  for(i=0;i<K;i++){
    cin >> c[i];
    cc+=c[i];
  }
  for(i=0;i<d;i++)
    for(j=0;j<K;j++)
      cin >> s[i][j];
  for(i=0;i<d;i++){
    cin >> t[i];
    t[i]--;
  }
  fill(l,l+K,-1);
  for(i=0;i<d;i++){
    r=0;
    rj=-1;
    for(j=0;j<K;j++)
      if(c[j]*(i-l[j])>r){
        r=c[j]*(i-l[j]);
        rj=j;
      }
    m+=cc-c[rj]*(i-l[rj]);
    t[i]=rj;
    l[rj]=i;
    res+=s[i][rj]-m;
  }
  for(i=0;i<d;i++)
    cout << t[i]+1 << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int arr[1010];
int main()
{
  int n, k;
  cin>>n>>k;
  for(int i = 0;i<n;i++)
    cin>>arr[i];
   sort(arr,arr+n);
    int total=0;
  for(int i=0;i<k;i++)total+=arr[i];
    cout<<total<<endl;
  }
 

Measured memory_bytes: 3600
import Control.Applicative

search :: Eq a => [a] -> [a] -> Int
search xs ys = length [y | y <- ys, elem y xs]

main :: IO ()
main = do
  _  <- getLine
  xs <- words <$> getLine
  _  <- getLine
  ys <- words <$> getLine
  putStrLn $ show $ search xs ys



Measured memory_bytes: 6316
import copy

S = input()
T = input()

def change(string, c1, c2):
    ret = []
    for s in string:
        if s is c1:
            ret.append(c2)
        elif s is c2:
            ret.append(c1)
        else:
            ret.append(s)
    return ret

S_ = copy.deepcopy(S)
history = []

while True:
    if S_ in history:
        print('No')
        exit()
    for i, s in enumerate(S_):
        history.append(S_)
        if s is not T[i]:
            S_ = copy.deepcopy(''.join(change(S_, s, T[i])))
            break
        if i == len(S_)-1:
            print('Yes')
            exit()


Measured memory_bytes: 9236
var n,m,j,i,a,b:longint;
    x:array[1..1000]of longint;
begin
 readln(n,m);
 for i:=1 to n do
  read(x[i]);
 for i:=1 to n-1 do
  for j:=i+1 to n do
   if x[i]<x[j] then
    begin
     a:=x[i];
     x[i]:=x[j];
     x[j]:=a;
    end;
 for i:=1 to m do
  b:=b+x[i];
 writeln(b);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define fi first
#define se second
const int inf = 1e9;
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)

int a[4][104], dp[4][104];
int main(){
	int n;
	scanf("%d", &n);
	rrep(i,2)rrep(j,n)scanf("%d", &a[i][j]);
	for(int i = 1;i <= 2;i++){
		for(int j = 1;j <= n;j++){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1])+a[i][j];
		}
	}
	printf("%d\n", dp[2][n]);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
x = sorted(list(map(int, input().split())))
t = 1
for num in x:
    t = t * num
    if t > 10 ** 18:
        print(-1)
        sys.exit()

if (t > 10 ** 18): 
    print(-1)
else:
    print(t)


Measured memory_bytes: 21600
N=int(input())
A=list(map(int,input().split()))
a=1
if 0 in A:
    print(0)
else:
    for i in range(N):
        a*=A[i]
        if a>1000000000000000000:
          print(-1)
          break
    else:
        print(int(a))

Measured memory_bytes: 87904
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int b[maxn], k, n, m, sum;
double c, r;
string s, t;


int main(){
    ios_base::sync_with_stdio(0);
    cin>>s;
    if(s == "ABC")
        cout<<"ARC";
    else cout<<"ABC";
    return 0;
}


Measured memory_bytes: 3104
N = int(input())
S = [0] * 5
for _ in range(N):
  s = input()
  if s[0] == "M": S[0] += 1
  elif s[0] == "A": S[1] += 1
  elif s[0] == "R": S[2] += 1
  elif s[0] == "C": S[3] += 1
  elif s[0] == "H": S[4] += 1
 
import itertools
ans = 0
for v in itertools.combinations(S, 3):
  ans +=  v[0] * v[1] * v[2]
print(ans)

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

int main(){
    ll n,a,b;
    cin>>n;
    vector<vector<ll>> adj(n);
    map<pair<ll,ll>,ll> mp;
    rep(i,n-1){
        cin>>a>>b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        mp[make_pair(a,b)]=i;
        mp[make_pair(b,a)]=i;
    }
    vector<ll> col(n-1,-1);
    queue<pair<ll,ll>> q;
    q.push(make_pair(0,-1));
    ll cmx=0;
    while(!q.empty()){
        ll now=q.front().first,pcol=q.front().second;
        q.pop();
        ll ccnt=0;
        rep(i,adj[now].size()){
            if(col[mp[make_pair(now,adj[now][i])]]==-1){
                if(ccnt==pcol) ccnt++;
                col[mp[make_pair(now,adj[now][i])]]=ccnt;
                q.push(make_pair(adj[now][i],ccnt));
                cmx=max(cmx,ccnt);
                ccnt++;
            }
        }
    }
    cout<<cmx+1<<endl;
    rep(i,n-1) cout<<col[i]+1<<endl;
    return 0;
}

Measured memory_bytes: 19968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())



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



// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }




int main() {


  ll N;
  cin >> N;
  vint H(N);
  ll ans=0;
  ll tmp=0;
  rep(i,N){
    cin >> H[i];
    if(tmp<=H[i]){
      ans++;
      tmp=max(tmp,H[i]);
    }
  }

  cout << ans << endl;



}

















//


Measured memory_bytes: 256
import numpy as np
N, D = map(int, input().split())
X = [0] * N 
counter = 0

for i in range(N):
  X[i] = np.array(list(map(int, input().split())))

for i in range(N):
  for j in range(N):
    distance = np.linalg.norm(X[i] - X[j])
    if distance.is_integer():
      counter += 1

print(int((counter-N)/2))

Measured memory_bytes: 12500
N = int(input())

tx, ax = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    fac = max(tx//T, ax//A)
    if T * fac < tx or A * fac < ax:
        fac += 1
    tx = T * fac
    ax = A * fac

print(tx + ax)

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

C = list()
A = list()

for i in range(N):
  L = list(map(int,input().split()))
  C.append(L[0])
  A.append(L[1:])
now_cost = 10**10

import itertools

for cm in itertools.product([0,1], repeat=N):
  c = 0
  a = [0 for i in range(M)]
  for i, j in enumerate(cm):
    if j == 1:
      flag = 1
      c += C[i]
      for k in range(M):
        a[k] += A[i][k]
        if a[k] < X:
          flag = 0
      if flag == 1:
        now_cost = min(now_cost, c)
        continue
      
if now_cost == 10**10:
  print(-1)
else:
  print(now_cost)
      

Measured memory_bytes: 9224
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
	
        // 出力
        if(a%3 == 0){
            System.out.println("Possible");
        }else if(b%3 == 0){
            System.out.println("Possible");
        }else if((a+b)%3 == 0){
            System.out.println("Possible");
        }else{
            System.out.println("Impossible");
        }
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

bool allSame(int n){
	return (n / 100) == ((n / 10) % 10) && ((n / 10) % 10) == (n % 10);
}

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

	int res = N;
	for (int i = N; i <= 999; ++i){
		if (allSame(i)){
			res = i;
			break;
		} // end if
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;

int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    sort(all(a));
    std::cout << a[n/2]-a[n/2-1] << std::endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define N_MAX 5000
int array[N_MAX];
int main(){
	int n;
	int num;
	while(cin>>n&&n){
		int ans=-100000*5000;
		for(int i=0;i<n;i++){
			cin>>num;
			if(i==0)array[i]=num;
			else{
				array[i]=max(array[i-1]+num,num);
			}
			ans=max(ans,array[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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


int main(){
  float h,l,m;
  cin>>m;
  h=l=m;
  while(cin>>m){
    if(h<m) h=m;
    else if(l>m) l=m;
  }
  cout<<fixed<<setprecision(1)<<h-l<<endl;
  return 0;
}

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

template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

const int MOD = 1e9 + 7;

ll sum (ll x, ll y) {
    return (x+y) * (y - x + 1) / 2;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);


    int n, k;
    cin >> n >> k;

    ll l, r = 0;
    ll ans = 0;

    for(int i = k; i <= n+1; ++i) {
        l = sum(0, i-1);
        r = sum(n-i+1, n);
        l %= MOD;
        r %= MOD;
        ll v = r - l;
        if(v < 0) v += MOD;
        ans = (ans + (v + 1)) % MOD; 
    }

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

Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <vector>

int main() {
	int X;
	int N;
	int p[100];
	int ans = 0;
	std::cin >> X >> N;

	if (N == 0) {
		printf("%d", X);
		return 0;
	}

	for (int i = 0;i < N;i++) {
		std::cin >> p[i];
		p[i] -= X;
	}

	for (int i = 0;i < N;i++) {
		if (i % 2 == 0) {
			ans += i;
		}
		else {
			ans -= i;
		}
		int flag = 0;
		for (int j = 0;j < N;j++) {
			if (ans == p[j]) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			ans += X;
			printf("%d", ans);
			return 0;
		}
	}

	if (N % 2 == 0) {
		ans += N;
	}
	else {
		ans -= N;
	}
	ans += X;
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 3752
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long dp[(1 << 14)];
int main() {
#define int long long
	int n, m;
	cin >> n >> m;
	REP(i, 1 << 14) {
		dp[i] = LONG_INF;
	}
	dp[0] = 0;
	REP(i, m) {
		long long a, b;
		cin >> a >> b;
		long long tmp = 0;
		REP(q, b) {
			long long c;
			cin >> c;
			tmp += (1 << (c - 1));
		}
		for (int q = 0; q < (1 << n); ++q) {
			dp[(q | tmp)] = min(dp[(q | tmp)], dp[q] + a);
		}
	}
	long long ans = dp[(1 << n) - 1];
	if (ans == LONG_INF) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);
 
int main() {
    optimizar_io

    string s, t;

    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == t[i])
            cnt++;
    cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
data = []
a=0
b=1
c=2
dp = [[0 for i in range(3)] for j in range(n)]
for i in range(n):
    data.append(list(map(int, input().split())))

dp[0][a]=data[0][a]
dp[0][b]=data[0][b]
dp[0][c]=data[0][c]
for i in range(1,n):
    dp[i][a]=data[i][a]+max(dp[i-1][b],dp[i-1][c])
    dp[i][b]=data[i][b]+max(dp[i-1][a],dp[i-1][c])
    dp[i][c]=data[i][c]+max(dp[i-1][a],dp[i-1][b])
print(max(dp[-1][a],dp[-1][b],dp[-1][c]))


Measured memory_bytes: 51956
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int, int> P;

const int INF = 1001001001;
int dist[100010][3];

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> u(M), v(M);
    for(int i = 0; i < M; i++){
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }
    int S, T;
    cin >> S >> T;
    S--;
    T--;
    
    vector<vector<int>> to(N);
    for(int i = 0; i < M; i++){
        to[u[i]].push_back(v[i]);
    }
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            dist[i][j] = INF;
        }
    }
    
    queue<P> que;
    dist[S][0] = 0;
    que.push(P(S, 0));
    
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int nv = p.first;       // 現在いる頂点
        int nm = p.second;      // 現在のmod3
        
        for(int i = 0; i < to[nv].size(); i++){
            if(dist[to[nv][i]][(nm+1) % 3] != INF)  continue;
            
            dist[to[nv][i]][(nm+1) % 3] = dist[nv][nm] + 1;
            que.push(P(to[nv][i], (nm+1) % 3));
        }
    }
    
    if(dist[T][0] == INF)   dist[T][0] = -1;
    else                    dist[T][0] /= 3;
    cout << dist[T][0] << endl;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  for (int i = 0; i < a.size() - 1; i++) {
    if ("AC" == a.substr(i, 2)) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

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

static const int MAX_WEIGHT = 50;	/* セミ地図の最大幅 */
static const int MAX_HEIGHT = 50;	/* セミ地図の最大高さ */

int ctoi(char c)
{
	return c - '0';
}

void cicada(void)
{

	/* -------------------- */
	/* 地図の幅、高さを取得 */
	/* -------------------- */
	int  weight, height;	/* input 幅、input 高さ */
	std::cin >> height >> weight;
	
	/* -------------------------- */
	/* 最小セミ遭遇数の一覧を作成 */
	/* -------------------------- */
	std::string      in_line;					/* input セミマップ 1行分 */
	std::vector<int> min_encount(weight, 0);	/* メモ用最小遭遇数 */

	/* 左上 */
	std::cin >> in_line;
	min_encount[0] = ctoi( in_line[0] );
	
	/* 一番上の一列 */
	for (int w = 1; w < weight; ++w)
	{
		min_encount[w] = min_encount[w - 1] + ctoi( in_line[w] );
	}

	/* 二列目以降 */
	for (int h = 1; h < height; ++h)
	{
		std::cin >> in_line;

		/* 一番左 */
		min_encount[0] += ctoi( in_line[0] );

		/* 左から2番目以降 */
		for (int w = 1; w < weight; ++w)
		{
			int left = min_encount[w - 1];
			int up   = min_encount[w];

			min_encount[w] = std::min(left, up) + ctoi( in_line[w] );
		}
	}

	/* -------------------------- */
	/* 出会う蝉の数の最小値を出力 */
	/* -------------------------- */
	std::cout << min_encount[weight - 1] << std::endl;

	return;
}

int main()
{
	cicada();
	return 0;
}



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

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
ll K;
vector <ll> neg;
vector <ll> pos;
ll n0;

ll csolve (vector <ll> v, ll M)
{
    ll res = 0;
    int cpos = (int) v.size() - 1;
    for (int i = 0; i < v.size(); i++)
    {
        while (cpos > i && v[i] * v[cpos] > M)
            cpos--;
        res += max (0, cpos - i);
    }
    return res;
}

ll ncnt (ll M)
{
    // # of values <= M
    ll res = 0;
    if (M >= 0)
    {
        res += n0 * (N - n0);
        res += (n0 * (n0 - 1)) / 2;
        res += neg.size() * pos.size();
        res += csolve (neg, M) + csolve (pos, M);
    }
    else
    {
        M = -M;
        int cpos = (int) pos.size() - 1;
        for (int i = 0; i < neg.size(); i++)
        {
            while (cpos >= 0 && neg[i] * pos[cpos] >= M)
                cpos--;
            res += (int) pos.size() - 1 - cpos;
        }
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        ll x; cin >> x;
        if (x < 0)
            neg.push_back(-x);
        else if (x > 0)
            pos.push_back(x);
        else
            n0++;
    }
    sort (neg.begin(), neg.end());
    sort (pos.begin(), pos.end());

    ll lo = 0, hi = 4e18;
    ll Y = 2e18;
    while (lo < hi)
    {
        ll mid = (lo + hi) / 2;
        if (ncnt (mid - Y) >= K)
            hi = mid;
        else
            lo = mid + 1;
    }
    cout << lo - Y << "\n";
}

Measured memory_bytes: 3308
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N;
    cin >> N;
    vector<pair<long long, long long>> A;
    for (int i = 0; i < N; i++) {
        long long a, b;
        cin >> a >> b;
        A.emplace_back(a+b, a-b);
    }
    
    sort(A.begin(), A.end());
    int ans = 1;
    long long now = A[0].first;
    for (int i = 1; i < N; i++) {
        int s, t; tie(t, s) = A[i];
        if (now <= s) {
            ans ++;
            now = t;
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n;
char s[103];

int main()
{
	cin >> n;
  	scanf("%s", s + 1);
  	if (n & 1) {puts("No"); return 0;}
  	for (int i = 1; i <= n / 2; i+=1)
    {
    	if (s[i] != s[i + n / 2]) {puts("No"); return 0;}
    }
  	puts("Yes");
  	return 0;
}

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

int main() {
	int n, s;
	cin >> n;
	
	int num = n;
	while (num) {
		s += num % 10;
		num /= 10;
	}

	if (n % s == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<long long, long long> P;

bool greaterOrdered(P pre, P post) {
  if(pre.second > post.second) return true;
  else return false;
}

int main() {
  long long N, H; cin >> N >> H;
  long long hp = H;
  long long maxAttackPoint = 0;
  long long cnt = 0LL;
  vector<P> vec;
  for(long long i = 0LL; i < N; ++i) {
    long long A, B; cin >> A >> B;
    vec.push_back(P(A, B));
    maxAttackPoint = max(maxAttackPoint, A);
  }
  sort(vec.begin(), vec.end(), greaterOrdered);
  for(int i = 0; i < vec.size(); ++i) {
    if(hp <= 0) {
      cout << cnt << endl;
      return 0;
    }
    if(maxAttackPoint < vec[i].second) {
      hp -= vec[i].second;
      cnt++;
    } else {
      cnt += (hp % maxAttackPoint == 0) ? hp/maxAttackPoint : hp/maxAttackPoint + 1;
      cout << cnt << endl;
      return 0;
    }
  }
  if(hp <= 0) {
    cout << cnt << endl;
    return 0;
  }
  cnt += (hp % maxAttackPoint == 0) ? hp/maxAttackPoint : hp/maxAttackPoint + 1;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 2420
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    static int mod=1000000007;
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        List<int>[]graph=Enumerable.Range(0,n)
            .Select(_=>new List<int>()).ToArray();
        for(int i=0;i<n-1;i++){
            int[]uv=Console.ReadLine().Split().Select(int.Parse).ToArray();
            int u=uv[0]-1;
            int v=uv[1]-1;
            graph[u].Add(v);
            graph[v].Add(u);
        }

        long[,]dp=new long[n,2];
        for(int i=0;i<n;i++){
            dp[i,0]=1;
            dp[i,1]=1;
        }
        Action<int,int>dfs=null;
        dfs=(x,p)=>{
            foreach(int y in graph[x]){
                if(y==p)continue;
                dfs(y,x);
                Mul(ref dp[x,0], dp[y,0]+dp[y,1]);
                Mul(ref dp[x,1], dp[y,0]);
            }
        };
        dfs(0,0);
        long ans=dp[0,0]+dp[0,1];
        if(mod<=ans)ans-=mod;
        Console.WriteLine(ans);
    }
    public static void Mul(ref long x, long y){
        x=x*y%mod;
    }
}


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

int main(){
   int N,M,C,score=0,sum=0,count=0;
   cin>>N>>M>>C;
   vector<int> B(M);
   vector<vector<int>> A(N,vector<int> (M));
   for(int i=0;i<M;i++){
       cin>>B.at(i);
   }
   for(int i=0;i<N;i++){
       for(int j=0;j<M;j++){
           cin>>A.at(i).at(j);
       }
   }
   
    for(int i=0;i<N;i++){
       for(int j=0;j<M;j++){
            score+=B.at(j)*A.at(i).at(j);
          count++;
          if(score+C>0 && count==M){
          sum++;
          }
          if(count==M){
              score=0;
              count=0;
          }
       }
   }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <memory.h>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <complex>
#include <cstring>

using namespace std;

#define FILE_PREFIX "../../../../../../../../CompetitiveProgramming/CF/CF/"
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR((i), 0, (n))
#define ll unsigned int
#define pb push_back

const int N = 3e5*32;
const int MOD = 1e9 + 7;

int n, k;

int main() {
//        freopen(FILE_PREFIX"input.txt", "r", stdin);
    ios :: sync_with_stdio(false);
    cin >> n >> k;
    
    if (k == 0) {
        cout << 1LL * n * n << endl;
        return 0;
    }
    
    long long res = 0;
    for (int b = k + 1; b <= n; ++b) {
        res += (n / b) * (b - k);
        int m = n % b;
        if (m >= k) res += m - k + 1;
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256