akhauriyash/Code-Regression huggingface dataset:
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;


int main(void) {

    vector<vector<int>> bingo(3,vector<int> (3,0));

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin>>bingo[i][j];
        }
    }

    int N; cin>>N;

    vector<vector<bool>> ans(3,vector<bool> (3,false));
    for (int i = 0; i < N; ++i) {
        int b; cin>>b;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if(b==bingo[j][k]){
                    ans[j][k] = true;
                }
            }
        };
    }

    // check
    bool ok = false;
    // 横
    if(ans[0][0] && ans[0][1] && ans[0][2]) ok = true;
    if(ans[1][0] && ans[1][1] && ans[2][2]) ok = true;
    if(ans[2][0] && ans[2][1] && ans[2][2]) ok = true;
    // 縦
    if(ans[0][0] && ans[1][0] && ans[2][0]) ok = true;
    if(ans[0][1] && ans[1][1] && ans[2][1]) ok = true;
    if(ans[0][2] && ans[1][2] && ans[2][2]) ok = true;

    if(ans[0][0] && ans[1][1] && ans[2][2]) ok = true;
    if(ans[0][2] && ans[1][1] && ans[2][0]) ok = true;

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;



    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		List<String> S = new ArrayList<String>();
		for (int i = 0; i < N; i++) {
			S.add(sc.next());
		}
		sc.close();

		// 計算
		Collections.sort(S);
		StringBuffer sb = new StringBuffer(N * L + 1);
		for (String string : S) {
			sb.append(string);
		}

		// 出力
		System.out.println(sb.toString());

		return;
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <stack>
#include <queue>
#include <cstdio>
using namespace std;
int main(void)
{
  stack<int> in;
  queue<int> out;
  int c;
  while(scanf("%d",&c)!=EOF)
  {
    if(c==0){
      out.push(in.top());in.pop();
    }else{
      in.push(c);
    }
  }
  while(!out.empty())
  {
    cout<<out.front()<<endl;
    out.pop();
  }
  return 0;
}

Measured memory_bytes: 1216
import java.io.IOException;
import java.util.Scanner;

/**
 * Created on 2017/10/25 7:00.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String s = sc.next();
            System.out.println(s.contains("9") ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<30);

using namespace std;


int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vi v(n);
    f(i, n) cin >> v[i];
    ll ans = 0;
    f(i, n){
      fo(j, i+1, n){
        ans += v[i] * v[j];
      }
    }
    cout << ans << endl;
    return 0;
}


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

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    ll M;


    cin >> N >> M;
    ll ANSL = 1;
    ll ANSR = N;
    REP(i, M){
        ll L, R;
        cin >> L >> R;
        ANSR = min(ANSR, R);
        ANSL = max(ANSL, L);
    }
    if( ANSL > ANSR ){
        cout << 0 << endl;
    }else{
        cout << ANSR - ANSL + 1 << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  static boolean[] visited;
  static int[] point;
  static List<Integer>[] tree;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    visited = new boolean[n+1];
    point = new int[n+1];
    tree = new List[n+1];
    for(int i=1;i<=n;i++)tree[i]=new ArrayList<Integer>();
    for(int i=1;i<=n-1;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      tree[a].add(b);
      tree[b].add(a);
    }
    for(int i=1;i<=q;i++){
      int p = sc.nextInt();
      int x = sc.nextInt();
      point[p]+=x;
    }
    dfs(1);
    System.out.print(point[1]);
    for(int i=2;i<=n;i++)System.out.print(" "+point[i]);
    System.out.println("");
  }
  public static void dfs(int parent){
    visited[parent]=true;
    for(int child:tree[parent]){
      if(!visited[child]){
        point[child]+=point[parent];
        dfs(child);
      }
    }
  }
}

Measured memory_bytes: 216692
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long h,n,a;
    cin>>h>>n;
    while(n--){
        cin>>a;
        h-=a;
    }
    if(h<=0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ld a,b;
	cin >> a >> b;
	cout << (ll)(a*b) << "\n";
}

Measured memory_bytes: 3756
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M = gets_i_list
sc = []

if M == 0
  puts "100" if N == 3
  puts  "10" if N == 2
  puts   "0" if N == 1
  exit
end

M.times do
  sc.push gets_i_list
end

sc = sc.uniq.sort
s = sc.transpose[0]

if s != s.uniq || s.max > N
  puts "-1"
else
  sch = sc.to_h
  str = []
  if N == 3
    sch[1].nil? ? str.push(" ") : str.push(sch[1].to_s)
    sch[2].nil? ? str.push(" ") : str.push(sch[2].to_s)
    sch[3].nil? ? str.push(" ") : str.push(sch[3].to_s)
  elsif N == 2
    sch[1].nil? ? str.push(" ") : str.push(sch[1].to_s)
    sch[2].nil? ? str.push(" ") : str.push(sch[2].to_s)
  elsif N == 1
    sch[1].nil? ? str.push(" ") : str.push(sch[1].to_s)
  end

  if str[0] == " "
    str[0] = "1"
  end
  ans = str.join.gsub(" ", "0").to_i
  if ans.to_s.length == N
    puts ans
  else
    puts "-1"
  end
end


Measured memory_bytes: 4092
A = [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]
K = int(input())
print(A[K - 1])

Measured memory_bytes: 38256
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())

def solve(s):
    n = len(s)
    t = [-1] * n

    if s[0] == '<':
        t[0] = 0
    if s[-1] == '>':
        t[-1] == 0

    for ind, (prev, after) in enumerate(zip(s, s[1:])):
        if prev + after == '><':
            t[ind + 1] = 0
    ku = 0
    hu = 0
    ans = 0
    for ind, c in enumerate(s):
        if t[ind] == 0:
            max_ = max(ku, hu)
            min_ = min(ku, hu)
            ans += (max_ + 1) * max_ // 2
            ans += (min_ - 1) * min_ // 2
            ku = 0
            hu = 0
        if c == '<':
            ku += 1
        else:
            hu += 1
    max_ = max(ku, hu)
    min_ = min(ku, hu)
    ans += (max_ + 1) * max_ // 2
    ans += (min_ - 1) * min_ // 2
    return ans


if __name__ == '__main__':
    s = input()
    print(solve(s))


Measured memory_bytes: 49224
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl


/*--------------------template--------------------*/


int main()
{
	cin >> n;
	string t;
	vi v;
	cin >> s >> t;
	ll i = 0;
	while (i < n) {
		if (s[i] == s[i + 1]) {
			v.push_back(1);
			i++;
		} else {
			v.push_back(0);
		}
		i++;
	}
	if (v[0] == 0) {
		ans = 3;
	} else {
		ans = 6;
	}
	FOR(i, 1, v.size())
	{
		if (v[i - 1] == 0) {
			if (v[i] == 0) {
				ans *= 2;
			} else if (v[i] == 1) {
				ans *= 2;
			}
		} else if (v[i - 1] == 1) {
			if (v[i] == 0) {
				ans *= 1;
			} else if (v[i] == 1) {
				ans *= 3;
			}
		}
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

//a,m=MOD MOD逆元
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll combi(ll a, ll b)
{
    if (a < b)
        return 0;
    ll res = 1;
    for (ll i = a; i >= a - b + 1; i--)
    {
        res *= i;
        res %= MOD;
    }
    rep3(i, 1, b + 1)
    {
        res *= modinv(i, MOD);
        res %= MOD;
    }
    return res;
}
//a,m=MOD MOD逆元
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    if(k>combi(n-1,2)){
        cout << -1 << endl;
        return 0;
    }
    VP vec;
    rep3(i,1,n){
        vec.push_back({i, n});
    }
    ll reg = combi(n - 1, 2) - k;
   // cout<<reg<<endl;
   
    rep3(i,1,n){
        rep3(j,i+1,n){
            if(reg==0)
                break;
            vec.push_back({i, j});
            reg--;
            if(reg==0)
                break;
        }
        if (reg == 0)
            break;
    }
    cout << vec.size() << endl;
    rep(i,vec.size()){
        cout << vec[i].F << " " << vec[i].S << endl;
    }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

//最小公倍数, 複数の時はlcm(a,lcm(b,c))みたいな感じで
template <class T>
T lcm(T a,T b){
    return a*(b/gcd(a,b));//a,bがばかでかい時のために割ってからかける
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,l;
    string s,t;
    cin>>n>>m>>s>>t;
    l=lcm(n,m);
    ll a=l/n,b=l/m;
    vector<ll> c,d;
    rep(i,n) c.push_back(1+i*a);
    rep(i,m) d.push_back(1+i*b);
    //cout_vec(c);
    //cout_vec(d);
    rep(i,n){
      ll cnt=*lower_bound(begin(d),end(d),c[i]);
      if(cnt==c[i] && s[(cnt-1)/a]!=t[(cnt-1)/b]){
        //cout<<cnt<<' '<<s[cnt]<<' '<<t[cnt]<<endl;
        cout<<-1<<endl;
        return 0;
      }
    }
    cout<<l<<endl;
}

Measured memory_bytes: 2804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}


int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        int count = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0)count++;
        }
        if(count == 8 && i % 2 == 1)ans++;
    }
    cout << ans << endl;
    
}
    




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
    int a,b;
    cin >> a >> b;
    if(a>=b+1) cout << 2*a - 1 << endl;
    else if(b>=a+1) cout << 2*b - 1 << endl;
    else if (b == a) cout << a + b << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

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

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

using namespace std;

class Dice
{
  public:
    vector<int> diceNum;
    Dice(vector<int>& inputs);
    void toW();
    void toS();
    void ParallelRotation();
};

Dice::Dice(vector<int>& inputs)
{
  diceNum=inputs;
}

void Dice::toW()
{
  swap(diceNum[0],diceNum[3]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[2]);
}

void Dice::toS()
{
  swap(diceNum[0],diceNum[1]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[4]);
}

void Dice::ParallelRotation()
{
  swap(diceNum[1],diceNum[2]);
  swap(diceNum[2],diceNum[4]);
  swap(diceNum[4],diceNum[3]);
}

bool Judge(Dice& dice1,Dice& dice2)
{
  int count=0;
  for(int i=0;i<6;i++)
  {
    if(dice1.diceNum[i]==dice2.diceNum[i]) count++;
  }
  if(count==6)return true;
  else return false;
    
}

bool preJudge(Dice& dice1,Dice& dice2)
{
  int count=0;
  bool flag=false;
  while(1)
  {
    dice2.toS();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    if(flag==true) break;
    dice2.toW();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    count++;
    if(flag==true) break;
    if(count==3)break;
  } 
  return flag;
}

int main(int argc,char* argv[])
{
  vector<int> inputs(6);
  int number;
  int count =0;
  cin >> number;
  bool flag=false;
  
  vector<Dice> Dices;
  for(int i=0;i<number;i++)
  {
    for(int j=0;j<6;j++)
    {
      cin >> inputs[j];
    }
    Dices.push_back(Dice(inputs));
  }
  for(int i=0;i<number-1;i++)
  {
    for(int j=i+1;j<number;j++)
    {
      flag = preJudge(Dices[i],Dices[j]);
      if(flag==true) break;
    }
    if(flag==true) break;
  }
  if(flag==true) cout << "No" << endl;
  else if(flag==false) cout << "Yes" << endl;
}

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

using namespace std;

int count;

void selectionSort(vector<int>& a) {
    for(int i=0; i<a.size(); i++) {
        int minj = i;
        for (int j=i; j<a.size(); j++) {
            if(a[j] < a[minj]) minj = j;
        }
        if(minj!=i){
            swap(a[i], a[minj]);
            count++;
        }
    }
}

int main() {
    int n; cin >> n;
    vector<int> a;
    for(int i=0; i<n; i++) {
        int e; cin>>e;
        a.push_back(e);
    }
    selectionSort(a);
    for(int i=0; i<a.size(); i++) {
        if(i==a.size()-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                          \
  cout << #v << "=(" << v[0];                              \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; } \
  cout << ")" << endl;
#define mdebug(m)                                                           \
  cout << #m << "=" << endl;                                                \
  REP(i_debug, m.size())                                                    \
  {                                                                         \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
    cout << endl;                                                           \
  }
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000
const double PI = 3.14159265358979323846;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

int main()
{
  ll A;
  ld B;
  cin >> A >> B;

  ll ans = B * A;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include<stdio.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include<math.h>
using namespace std;
int main()
{
    long long int a,b,n,m,i,j;
    while(scanf("%lld",&n)!=EOF)
    {
        for(i=1;i*i<=n;i++)
        {
            j=0;
            j=i*i;
        }
        printf("%lld\n",j);
    }
    return 0;
}

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

int main() {
  string predict_weather;
  string real_weather;
  char arr1[3];
  char arr2[3];
  int cnt = 0;
  
  cin >> predict_weather >> real_weather;
  //受け取った文字列を分解
  for(int i = 0; i < predict_weather.length(); i++)
  {
  	 arr1[i] = predict_weather[i];
     
  }
   for(int i = 0; i < real_weather.length(); i++)
  {
  	 arr2[i] = real_weather[i];
  }
  
  //配列を比較する(文字列が両方3文字以内なので一方の配列の長さで回す)
  for(int i = 0; i < 3; i++)
  {
     //カウント
     if(arr1[i] == arr2[i])
     {
     	cnt++;
     }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main()  {
	var a, b int
	fmt.Scan(&a, &b)

	ta := int(math.Ceil(float64(a)/0.08))
	tb := int(math.Ceil(float64(b)/0.1))

	tta := int(math.Ceil(float64(a+1)/0.08))
	ttb := int(math.Ceil(float64(b+1)/0.1))

	al := []int{}
	bl := []int{}

	for i:=ta; i<tta; i++ {
		al = append(al, i)
	}
	for i:=tb; i<ttb; i++ {
		bl = append(bl, i)
	}

	ans := -1
	for _, i := range al {
		for _, j := range bl {
			if i == j {
				ans = i
				break
			}
		}
		if ans != -1 {
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
using System;
using System.Linq;
 
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string[] data;
            while((data = Console.ReadLine().Split())[0] != "0" || data[1] != "0") {
                int hit = 0, blow = 0;
                for(int i=0; i < data[0].Length; ++i) {
                    if(data[0][i] == data[1][i]) {
                        ++hit;
                    }
                    else if(data[0].Contains(data[1][i])) {
                        ++blow;
                    }
                }
                Console.WriteLine("{0} {1}", hit, blow);
            }
        }
    }
}

Measured memory_bytes: 6376
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 256
nums = [int(num) for num in input().split()]
n = nums[0]
m = nums[1]
x = nums[2]
y = nums[3]
maxx =-100
miny =100
hogex = [int(num) for num in input().split()]
hogey = [int(num) for num in input().split()]
for i in range(n):
    maxx = max(hogex[i],maxx)
for i in range(m):
    miny = min(miny,hogey[i])

if maxx < y and miny >x and maxx <miny:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll H,W,M;
  cin>>H>>W>>M;
  vector <vector <ll>> a(M,vector<ll>(2));
  vector <ll> hhs(H+1);
  vector <ll> wws(W+1);
  for(ll i = 0;i<M;i++){
    cin>>a[i][0]>>a[i][1];
    hhs[a[i][0]]++;
    wws[a[i][1]]++;
  }
  vector <vector <ll>> hh((H+1),vector<ll>(2));
  vector <vector <ll>> ww((W+1),vector<ll>(2));
  for(ll i = 0;i<M;i++){
    hh[a[i][0]][0]++;
  }
  for(ll i = 0;i<M;i++){
    ww[a[i][1]][0]++;
  }
  for(ll i = 0;i<(H+1);i++){
    hh[i][1] = i;
  }
  for(ll i = 0;i<(W+1);i++){
    ww[i][1] = i;
  }

  sort(hh.begin(),hh.end());
  sort(ww.begin(),ww.end());

  reverse(hh.begin(),hh.end());
  reverse(ww.begin(),ww.end());
  
  vector <ll> hhmax;
  ll hhmaxans = hh[0][0];
  vector <ll> wwmax;
  ll wwmaxans = ww[0][0];
  //cout <<hh[0][0]+ww[0][0] << endl;
  ll lo = 0;
  while(1){
    if(hh[lo][0] == hhmaxans){
      hhmax.push_back(hh[lo][1]);
      lo++;
    }
    else{
      break;
    }
  }
  lo = 0;
  
  while(1){
    if(ww[lo][0] == wwmaxans){
      wwmax.push_back(ww[lo][1]);
      lo++;
    }
    else{
      break;
    }
  }
  ll anstemp = hh[0][0]+ww[0][0];
  ll temp = 0;
  for(ll i = 0;i<M;i++){
    //cout << hhs[a[i][0]] << " " << wws[a[i][1]] << endl;
    if(hhs[a[i][0]]+wws[a[i][1]] == anstemp){
      temp++;
    }
  }

  ll anstemptemp = hhmax.size()*wwmax.size();
  
  
  if(temp != anstemptemp){
    cout << hh[0][0]+ww[0][0] << endl;
  }
  else{
    cout << hh[0][0]+ww[0][0]-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 65524
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int n;
	cin >> n;
	for (int o = 0; o < n; o++) {
		string s;
		cin >> s;
		string ans;
		bool count[1000];
		for (int i = 0; i < 1000; i++)count[i] = false;
		ans += s[0];
		count[s[0]] = true;
		for (int i = 1; i < s.size(); i += 3) {
			if (s[i + 1] == '>' && !count[s[i + 2]])ans = ans + s[i + 2], count[s[i + 2]] = true;
			else if (s[i] == '<' && !count[s[i + 2]])ans = s[i + 2] + ans, count[s[i + 2]] = true;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3084
def main():
    while True:
        w_num = int(input())
        if w_num == 0: break

        w_list = []
        for i in range(w_num):
            w_list.append(input())

        for i in range(len(w_list)):
            #print(w_list)
            leng = 0
            for item in w_list:
                #print("leng" + str(leng))
                if leng < 5:
                    leng += len(item)
                    if leng > 5:
                        leng = 0
                        break
                elif leng < 12:
                    leng += len(item)
                    if leng > 12:
                        leng = 0
                        break
                elif leng < 17:
                    leng += len(item)
                    if leng > 17:
                        leng = 0
                        break
                elif leng < 24:
                    leng += len(item)
                    if leng > 24:
                        leng = 0
                        break
                else:
                    leng += len(item)
                    if leng > 31:
                        leng = 0
                        break
                    
                if leng == 31:
                    print(i + 1)
                    break
            if leng == 31: break
            del w_list[0]
main()



Measured memory_bytes: 5612
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
int n;
ll k;
const int Maxn=5005;
int p[Maxn];
ll c[Maxn];

void calc(int now,vector<ll>&vv){
	ll sum=0;
	int at=now;
	for(int i=1;i<=n;i++){
		sum+=c[p[at]];
		vv.push_back(sum);
		at=p[at];
		if(at==now)return;
	}
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
	}
	for(int i=0;i<n;i++)scanf("%lld",&c[i]);
	ll ans=-1e17;
	for(int i=0;i<n;i++){
		vector<ll>vv;
		calc(i,vv);
		for(int j=1;j<=min((ll)vv.size(),k);j++){
			ans=max(ans,vv[j-1]+(k-j)/(ll)vv.size()*(vv.back()>0?vv.back():0));
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

ll mod = 1e9 + 7;

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

  ll d;
  cin >> d;

  if(d == 25) cout << "Christmas" << endl;
  else if(d == 24) cout << "Christmas Eve" << endl;
  else if(d == 23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;

  return 0;
}


Measured memory_bytes: 256
from fractions import gcd
a,b,c,d=map(int,input().split())

ce=b//c
if a<=ce*c and ce*c<=b:
    cs=1+((a-1)//c)
else:
    cs=ce+1

de=b//d
if a<=de*d and de*d<=b:
    ds=1+((a-1)//d)
else:
    ds=de+1

gg=(c*d)//gcd(c,d)
cde=b//gg
if a<=cde*gg and cde*gg<=b:
    cds=1+((a-1)//gg)
else:
    cds=cde+1

#print(cs,ce,ds,de,cds,cde)
print(int(b-a-ce-de+cs+ds+cde-cds))


Measured memory_bytes: 5076
#include<stdio.h>
#include<iostream>
#include<cctype>
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
using namespace std;

int main()
{
    char ch;
    int alpha[26] = {0};

    while ( cin >> ch ){
        if (isalpha(ch)) {
            alpha[tolower(ch) - 'a']++;
        }
    }
    
    for (int i = 0; i < COUNTOF(alpha); i++) {
        cout << char('a' + i) << " : " << alpha[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

struct city {
  ll id;
  ll ken;
  ll year;
  string id_string;
};

bool a(const city& left, const city& right) {
  return left.id < right.id;
}

bool b(const city& left, const city& right) {
  if (left.ken == right.ken) {
    return left.year < right.year;
  }
  return left.ken < right.ken;
}

signed main() {
  ll N, M;
  cin >> N >> M;

  vector<city> P;
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    P.pb({i, a, b, ""});
  }

  sort(ALL(P), b);
  ll num = 1;
  ll before_ken = INF;
  rep(i, M) {
    if (before_ken != P[i].ken) {
      num = 1;
    }
    string ken = "00000000000" + to_string(P[i].ken);
    string ren = "00000000000" + to_string(num);
    P[i].id_string =
        ken.substr(ken.size() - 6, 6) + ren.substr(ren.size() - 6, 6);
    num++;
    before_ken = P[i].ken;
  }
  sort(ALL(P), a);
  rep(i, M) {
    COUT(P[i].id_string);
  }
  return 0;
}

Measured memory_bytes: 10220
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	A, B, C, X, Y := getInt(), getInt(), getInt(),
		getInt(), getInt()

	sum0 := A*X + B*Y

	m := min(X, Y)
	// out(m)
	sum1 := C * m * 2
	if m == X {
		sum1 += (Y - m) * min(B, C*2)
	} else {
		// out(sum1, X-m, min(A, C*2))
		sum1 += (X - m) * min(A, C*2)
	}
	out(min(sum0, sum1))
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,K;
vector<pll> gv;
ll i,j,k;
int main(){
    scanf("%lld%lld", &N,&K);
    k = (N - 2) * (N - 1) / 2;
    if(k<K){
        printf("-1");
        return 0;
    }
    fornum(i,1,N){
        gv.push_back({1, i + 1});
    }
    i = 2;
    j = 3;
    while(K<k){
        gv.push_back({i, j});
        j++;
        if(j>N){
            i++;
            j=i + 1;
        }
        k--;
    }
    printf("%d\n", gv.size());
    fornum(i,0,gv.size()){
        printf("%lld %lld\n", gv[i].first, gv[i].second);
    }
    
    
    return 0;
}

Measured memory_bytes: 512
def calc(a, b, c)
  a,b = b,a if a > b
  (c-(b-a)+1)/2 + b
end

n, m, k = gets.split.map(&:to_i)
l1 = n.times.map{ [1<<31]*n }
l2 = n.times.map{ [] }
l3 = []
n.times{ |i| l1[i][i] = -1 }
m.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1; b -= 1
  l1[a][b] = l1[b][a] = c
  l2[a] << b; l2[b] << a
  l3 << [a,b,c]
end

visited = n.times.map{ false }
arr = []
dist = n.times.map{ 1<<31 }
k.times do
  visited[i = gets.to_i - 1] = true
  arr << i
  dist[i] = 0
end

until arr.empty?
  s = arr.min{ |a,b| dist[a] <=> dist[b] }
  arr.delete s
  l2[s].each do |t|
    d = dist[s] + l1[s][t]
    if (old = dist[t]) > d
      dist[t] = d
      arr << t if old == 1 << 31
    end
  end
end
ret = 0
m.times{ |i| ret = [ret, calc(dist[l3[i][0]], dist[l3[i][1]], l3[i][2])].max }
p ret

Measured memory_bytes: 88616
#include <stdio.h>

int main(){
int n,min,max;
double sum = 0;
int val;
int n_memoly;


scanf("%d",&n);
n_memoly = n;
while(n != 0){

scanf("%d",&val);
if (n_memoly == n){
max = val;min = val;sum = val;
n--;
continue;
}
sum += val;
if (min > val){
min = val;
}
if (max < val){
max = val;
}
n--;
}

printf("%d %d %.0lf\n",min,max,sum);
return 0;
}

Measured memory_bytes: 1064
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int s1=max(a,c);
  int s2=min(b,d);
  if(s2-s1<0)cout<<0<<endl;
  else cout<<s2-s1<<endl;
}


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

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;
    vector<int> C(N);
    for (int i=0; i<M; i++)
    {
        int b;
        cin>>b;
        for (int j=0; j<N; j++)
            if (A[j]<=b)
            {
                C[j]++;
                break;
            }
    }
    cout<<max_element(C.begin(), C.end())-C.begin()+1<<endl;
}

Measured memory_bytes: 3092
# B - 3人でカードゲームイージー
def main():
    sa = list(input())
    sb = list(input())
    sc = list(input())
    t = sa.pop(0)

    for _ in range(301):
        if t == 'a':
            if len(sa) == 0:
                print('A')
                break
            t = sa.pop(0)
        elif t == 'b':
            if len(sb) == 0:
                print('B')
                break
            t = sb.pop(0)
        elif t == 'c':
            if len(sc) == 0:
                print('C')
                break
            t = sc.pop(0)


if __name__ ==  "__main__":
    main()

Measured memory_bytes: 9000
#include<bits/stdc++.h>
using namespace std;
#define N (200010)
#define ll long long
int n,mx,a[N],now[N];
vector<int>G[N],ans;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		for (int j=2;i*j<=n;j++) G[i*j].push_back(i);
	}
	for (int i=n;i>=1;i--){
		if (now[i]!=a[i]){
			for (int j=0;j<G[i].size();j++) 
				now[G[i][j]]=!now[G[i][j]];	
			ans.push_back(i);
		}
	}
	printf("%d\n",ans.size());
	for (int i=ans.size()-1;i>=0;i--) printf("%d ",ans[i]);
}


Measured memory_bytes: 24312
import java.util.*;
import static java.lang.Math.*;
import java.io.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		for(int count=0;;count++){
			int a=sc.nextInt(),b=sc.nextInt();
			if(a==0&&b==0)break;
			boolean judge=false;
			if(count!=0)System.out.println();
			for(int i=0;i<=b-a;i++){
				int temp=a+i;
				if(temp%4==0&&temp%100!=0||temp%400==0){
					System.out.println(temp);
					judge=true;
				}
			}
			if(!judge){
				System.out.println("NA");
			}
			count++;
		}
		out.flush();
	}
}

Measured memory_bytes: 20580
#include <iostream>
using namespace std;
int A[110][110];
int B[110];
int n,m;
int main(){
	while(cin >> n >> m){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin >> A[i][j];
			}
		}
		for(int i=0;i<m;i++){
			cin >> B[i];
		}
		for(int i=0;i<n;i++){
			int b = 0;
			for(int j=0;j<m;j++){
				b += A[i][j]*B[j];
			}
			cout << b << endl;
		}
	}
}


Measured memory_bytes: 3156
from math import pi
from math import sqrt
from math import cos
from math import sin

def alpha(M,H):
    return (M/H)*2*pi

def point(alpha,B):
    return [B*cos(alpha),B*sin(alpha)]

A, B, H, M  = [int(x) for x in input().split()]

a1 = alpha(M,60)
a2 = alpha(H,12)+alpha(M/60,12)

p1 = point(a1,B)
p2 = point(a2,A)

print(sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2))

Measured memory_bytes: 9448
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  const Int S = lin();

  const Int X1 = 1000000000;
  const Int Y2 = (S + X1 - 1) / X1;
  const Int R = X1 * Y2 - S;

  if (R == 0) {
    printf("0 0 %lld 0 0 %lld\n", X1, Y2);
  } else {
    printf("0 0 %lld %lld 1 %lld\n", X1, R, Y2);
  }
  return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;

void main()
{
	auto input = split(readln());
	auto N = to!int(input[0]);
	long aM, aA, aR, aC, aH; // the number of the names that starts with ...
	foreach(i; 0..N) {
		auto S = split(readln())[0];
		aM += (S[0] == 'M'? 1 : 0);
		aA += (S[0] == 'A'? 1 : 0);
		aR += (S[0] == 'R'? 1 : 0);
		aC += (S[0] == 'C'? 1 : 0);
		aH += (S[0] == 'H'? 1 : 0);
	}
	writeln( aM*aA*(aR+aC+aH) + aM*aR*(aC+aH) + aM*aC*aH + aA*aR*(aC+aH) + aA*aC*aH + aR*aC*aH );
	
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

#define endl '\n'
#define ll long long

using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;
	vector<int> v(n);
	map<int, int> m;
	ll ans = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		m[i + v[i]]++;

		ans += m[i - v[i]];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 20924
from collections import deque

class UnionFind():
  def __init__(self, n):
    self.seg_tree = [-1 for _ in range(n)]
  
  def root(self, i):
    if self.seg_tree[i] < 0:
      return i
    else:
      self.seg_tree[i] = self.root(self.seg_tree[i])
      return self.seg_tree[i]

  def size(self, i):
    return -self.seg_tree[self.root(i)]

  def unite(self, i, j):
    if self.same(i, j):
      return

    if self.size(i) == self.size(j):
      self.seg_tree[self.root(i)] -= self.size(j)
      self.seg_tree[self.root(j)] = self.root(i)
    elif self.size(i) > self.size(j):
      self.seg_tree[self.root(i)] -= self.size(j)
      self.seg_tree[self.root(j)] = self.root(i)
    else:
      self.seg_tree[self.root(j)] -= self.size(i)
      self.seg_tree[self.root(i)] = self.root(j)

  def same(self, i, j):
    return self.root(i) == self.root(j)

N, M = map(int, raw_input().split())
AB = [map(long, raw_input().split()) for _ in range(M)]

uf = UnionFind(N)
rev_res = []

ans = N * (N - 1) / 2
for a, b in reversed(AB):
  rev_res.append(ans)
  if not uf.same(a - 1, b - 1):
    ans -= uf.size(a - 1) * uf.size(b - 1)
  uf.unite(a - 1, b - 1)

for r in reversed(rev_res):
  print r

Measured memory_bytes: 27320
#include <iostream>

using namespace std;

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    for (int i = a + 1; i < c - 1; ++i) {
        if (s[i - 1] == '#' && s[i] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = b + 1; i < d - 1; ++i) {
        if (s[i - 1] == '#' && s[i] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (c > d) {
        bool ok = false;
        for (int i = b - 1; i < d; ++i) {
            if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                ok = true;
                break;
            }
        }
        if (!ok) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;

int X, Y, A, B, C;
priority_queue<pair<int, int>> pq;

int main(){
	scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
	while(A--){int x; scanf("%d",&x); pq.push({x, 1});}
	while(B--){int x; scanf("%d",&x); pq.push({x, 2});}
	while(C--){int x; scanf("%d",&x); pq.push({x, 3});}

	long long ans = 0;
	int Z = 0;
	while(!pq.empty() && X + Y > Z){
		pair<int, int> now = pq.top(); pq.pop();
		if(now.second == 1 && X) ans += now.first, X--;
		if(now.second == 2 && Y) ans += now.first, Y--;
		if(now.second == 3) ans += now.first, Z++;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6512
S = input()
n = len(S)
K = int(input())
dp = [[[0]*2 for _ in range(K+1)] for _ in range(n+1)]
dp[0][0][0] = 1
for i in range(n):          # i:桁
    for j in range(K+1):    # j:非0の数
        for k in range(2):  # k:0->nと同じ数,1->nより小さい数
            nd = int(S[i])  #nd:nのi桁
            for d in range(10):
                ni, nj, nk = i+1, j, k
                if d != 0: nj += 1      # 非0の数が増える
                if nj > K: continue     # 非0の数がKを超えたら計算不要
                if k == 0:              # ここまでnと同じ場合
                    if d > nd: continue # nより大きくなるのでダメ
                    if d < nd: nk = 1   # nより小さくなるのでkは1に
                dp[ni][nj][nk] += dp[i][j][k]
ans = dp[n][K][0] + dp[n][K][1]
print(ans)


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

int main()
{
    ll n; ll k; cin >> n >> k;
    vector<int> v(n);
    vector<pair<int, bool>> t(n);
    //first:最初に来たときのi番目 second:来たかどうか
    rep(i, n){
        t[i] = pair<int, bool>(-1, false);
        int a; cin >> a; a--;
        v[i] = a;
    }
    int now = 0; int loop_cnt = 0;
    if(k <= 2*1e5){
        for(int i = 0; i < k; i++){
            int t = v[now];
            now = t;
        }
        cout << now+1 << endl;
        system("pause");
        return 0;
    }
    t[0].first = 0;    
    for(int i = 0; i < n; i++){
        
        if(t[v[now]].second){
            k -= t[v[now]].first;
            loop_cnt = i - t[v[now]].first+1;
            int l = v[now];
            now = l;
            break;
        }
        else{
            t[v[now]].first = i+1;
            t[v[now]].second = true;
            int l = v[now];
            now = l;
            //cout << "now" << now << endl;
            
        }
    }
    k %= loop_cnt;
    for(int i = 0; i < k; i++){
        int l = v[now];
        now = l;
    }
    cout << now+1 << endl;
    
    system("pause");
}


Measured memory_bytes: 5636
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll N,K;
ll m;
string S,T;
ll d;
ll ans;
ll dp[205][205];
ll M = 1000000007;
vector<ll> so;

int main() {
    cin >> N;
    cout << 999 - (N+999)%1000<< endl;
    
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        String s = scanner.next();
        int count = 0;
        int bCount = 0;
        for (int i = 0; i < n; i++) {
            if (count >= a + b) {
                System.out.println("No");
            } else if (s.charAt(i) == 'a') {
                System.out.println("Yes");
                count++;
            } else if (s.charAt(i) == 'b') {
                if (bCount < b) {
                    System.out.println("Yes");
                    count++;
                } else {
                    System.out.println("No");
                }
                bCount++;
            } else {
                System.out.println("No");
            }
        }
    }
}

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

int main(void) {
	string s;
	long k;
	cin >> s >> k;

	for (int i = 0; i < k; i++) {
		if(s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}

	cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007


vi G[100004];
vector<bool> seen(100004);


void dfs(int v) {
    seen[v] = true;

    for (auto next : G[v]) {
        if (seen[next]) continue;
        dfs(next);
    }

}

int main() {
    int N, M; cin >> N >> M;

    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].push_back(b); //1-origin
        G[b].push_back(a);
    }

    seen.assign(N + 1, false);

    int ans = 0;

    for (int i = 1; i <= N; i++) {
        if (seen[i]) continue;
        dfs(i);
        ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 8832