akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        m: i32,
        c: i32,
        b: [i32; m],
        a: [[i32; m]; n]
    }
    let mut ans = 0;
    for avec in a {
        let mut sum = 0;
        for i in 0..avec.len() {
            sum += avec[i] * b[i];
        }
        if sum + c > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

#define int long long
#define MOD 1000000007


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()å
#define rall(i) (i).begin(),(i).end(),greater<int>()


#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
 
//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

 
signed main(){
 
    string S;
    cin >>S;

    int x,y;

    int cnt = 0;

    int ans = S.size();

    for(int i=0;i<2;i++){

        cnt = 0;

        for(int j=0;j<S.size();j++){
            
            if((j%2==0)^(S[j]==(char)(i+'0'))){
                cnt++;
            }
        }

        ans = min(ans,cnt);


    }
 
    cout <<ans <<endl;

    return 0;
 
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	int a,b,t;
	cin>>a>>b>>t;
	if(a>t){
		cout<<0<<endl;
	}
	else{
		int res=0;
		for(int i=a;i<(t+0.5);i+=a){
			res+=b;
		}
		cout<<res<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
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() {
    int N;
    cin >> N;
    vl a(N);
    rep(i, 0, N) {
        cin >> a[i];
    }
    int count = 0;
    int top = 0;
    int loop = 0;
    while(true) {
        count = 0;
        top = 0;
        rep(i, 0, a.size()) {
            if (a[i] % 2 != 0 && top == 0) {
                a.erase(a.begin());
            } else if (a[i] % 2 != 0 && top > 0 && count > 0) {
                a[i] = a[i] * 3;
            }
            if (a[i] % 2 == 0 && count == 0) {
                a[i] = a[i] / 2;
                ++count;
            }
            ++top;
        }
        if (count == 0) {
            break;
        }
        ++loop;
    }
    cout << loop << endl;
    return 0;
}

Measured memory_bytes: 384
x1, y1, x2, y2 = gets.split.map(&:to_i)

dx2, dy2 = x2 - x1, y2 - y1
x3,  y3  = -dy2 + x2, dx2 + y2
x4,  y4  = -dy2 + x1, dx2 + y1

puts [x3, y3, x4, y4].join(' ')


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/


int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll K;
    cin >> K;

    ll mem = 0;

    queue<string> q;
    q.push("1");
    q.push("2");
    q.push("3");
    q.push("4");
    q.push("5");
    q.push("6");
    q.push("7");
    q.push("8");
    q.push("9");

    /*    if (K < 10) {
        cout << mem << endl;
        return 0;
    }*/
    mem = 0;

    while (!q.empty()) {
        string top = q.front();
        q.pop();
        mem++;
        if (mem == K) {
            cout << top << endl;
            return 0;
        }

        char tail = top[sz(top) - 1];

        if (tail != '0') {
            q.push(top + char(tail - 1));
        }
        q.push(top + char(tail));
        if (tail != '9') {
            q.push(top + char(tail + 1));
        }
    }
}



Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vector<string> S(N);
  rep(i,0,N) cin>>S[i];
  int ans=0;
  rep(i,0,N){
    vector<string> T(N);
    rep(j,0,N){
      rep(k,0,N){
        T[j]+=S[j][(k+i)%N];
      }
    }
    bool flag=1;
    rep(j,0,N){
      rep(k,0,N){
        if(T[j][k]!=T[k][j]) flag=0;
      }
    }
    ans+=flag*N;
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 632
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>

using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int L[101];
    ll sum = 0;
    int M = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
        sum += L[i];
        if (M < L[i])
        {
            M = L[i];
        }
    }
    if (M < (sum - M))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    // system("pause");
}

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

int main(void)
{
    char s[3];
    int cnt = 0;
    cin >> s;
    for (int i = 0; i < 3; i++)
    {
        if(s[i] == '1')
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define int long long
using namespace std;

string s[100005];
int32_t main(){

	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	int n;
	cin>>n;
	unordered_map<string ,int > mp;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		mp[s[i]]++;
	}
	int ans = 0;
	for(auto it:mp){
		int x = it.second;
		ans+=x*(x-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 16036
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
struct card{char suit,value;};
void bubbl(struct card a[],int n){
   for(int i=0;i<n;i++){
    for(int j=n-1;j>=i+1;j--){
        if(a[j].value<a[j-1].value){
            card t=a[j];a[j]=a[j-1];a[j-1]=t;
     }
    }
   }
  }
void selectio(struct card a[],int n){
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j].value<a[minj].value)minj=j;
        }card t=a[i];a[i]=a[minj];a[minj]=t;
        }
    }
void prin(struct card a[],int n){
   for(int i=0;i<n;i++){
    if(i>0)cout<<" ";
    cout<<a[i].suit<<a[i].value;
   }cout<<endl;
}
bool isstabl(struct card c1[],struct card c2[],int n){
   for(int i=0;i<n;i++){
    if(c1[i].suit!=c2[i].suit)return false;
   }return true;
}
int main(){
    card c1[100],c2[100];
    int n;
    char ch;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>c1[i].suit>>c1[i].value;
    }
    for(int i=0;i<n;i++)c2[i]=c1[i];
    bubbl(c1,n);
    selectio(c2,n);
    prin(c1,n);
    cout<<"Stable"<<endl;
    prin(c2,n);
    if(isstabl(c1,c2,n)){
        cout<<"Stable"<<endl;
    }else{
    cout<<"Not stable"<<endl;}
return 0;
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
const ll INF = 1e18L + 7;
 
int lcs[3001][3001];
vector<char> res;
 
void GetLCS(string s, string t, int i, int j)
{
    if (i == 0 || j == 0)
        return;
 
    if (lcs[i][j] == lcs[i-1][j-1] + 1)
    {
        res.push_back(s[i-1]);
        GetLCS(s, t, i-1, j-1);
    }
    else if(lcs[i-1][j] >= lcs[i][j-1])
    {
        GetLCS(s, t, i-1, j);
    }
    else
    {
        GetLCS(s, t, i, j-1);
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    string s,t;
 
    cin >> s >> t;
    int l1 = s.length();
    int l2 = t.length();
 
    // base case
    for(int i=0; i<=l2; ++i)
        lcs[0][i] = 0;
    for(int i=0; i<=l1; ++i)
        lcs[i][0] = 0;
 
    for(int i=1; i<=l1; ++i)
    {
        for(int j=1; j<=l2; ++j)
        {
            if(s[i-1] == t[j-1])
                lcs[i][j] = lcs[i-1][j-1] + 1;
            else
                lcs[i][j] = max(lcs[i][j-1], lcs[i-1][j]);
        }
    }
    
    
    
    if (lcs[l1][l2] != 0)
    {
        int i = l1, j=l2;
    
        while(i != 0 && j != 0)
        {
            if(lcs[i][j] == lcs[i - 1][j]) {
                i -= 1;
            } else if (lcs[i][j] == lcs[i][j - 1]) {
                j -= 1;
            } else if (lcs[i][j] == lcs[i - 1][j - 1] + 1) {
                res.push_back(s[i - 1]);
                i -= 1;
                j -= 1;
            }
        }
    
    //    GetLCS(s, t, l1, l2);
        reverse(res.begin(), res.end()); 
        for (auto it = res.begin(); it != res.end(); it++) 
            cout << *it; 
    }
    else
        cout << "";
        
    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true; 
  	if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; 
    return true; 
} 


    
void test_case() {

    int n;
    cin>>n;

    vecl arr(n);
    rep(i,n) {
        cin>>arr[i];
    }

    ll gd = arr[n-1];
    unordered_set<int> st;
    
    bool check = true;

    for(int i=n-2; i>=0; i--) {
        gd = gcd(arr[i], gd);
    }

    if(gd != 1) {
        cout<<"not coprime"<<endl;
        return;
    }

     sort(all(arr));
     reverse(all(arr));

    for(int i=n-1; i>=0; i--) {
        for(int j=2; j<=sqrt(arr[i]); j++) {
            if(arr[i]%j == 0) {
                if(st.find(j) != st.end() ) {
                    // cout<<"cshjvcjh";
                    check = false;
                    break;
                }

                int val = arr[i]/j;
                if(arr[i]%val == 0) {
                   if(st.find(val) != st.end()) {
                      // cout<<"cbshbc";
                       check = false;
                       break;
                   }
                   st.insert(val);
                }

                st.insert(j);
            }
            st.insert(arr[i]);
        }
    }
    // cout<<gd<<endl;
    if(check == true ) {
         cout<<"pairwise coprime"<<endl;
        return;
    }

    if(check == false) {
        cout<<"setwise coprime"<<endl;
        return;
    }



}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 30552
program example
	implicit none

	real(16) a,b,c,d

	read(*,*) a,b,c
    
    d=a+b+2.0q0*sqrt(a*b)
        
    if(c>d) then
    	write(*,*) "Yes"
        goto 1
    else
    	write(*,*) "No"
        goto 1
        
    end if

1 end program example

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a, int b ){
    int r, tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint a(n);
    REP(i,n) cin >> a[i];
    int ans = gcd(a[0],a[1]);
    for(int i=2;i<n;++i){
        ans = gcd(ans,a[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
"use strict"
function Main(input) {
  const total = input.split(' ').map(Number).reduce((acc, cur) => acc + cur, 0);
  const ave = Math.ceil(total / 2);
  console.log(ave);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

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

	vector<int> h(n);
	for (auto &v : h) {
		cin >> v;
	}

	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i + j < n) {
				int score = abs(h[i] - h[i + j]);
				dp[i + j] = min(dp[i + j], dp[i] + score);
			}
		}
	}

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


Measured memory_bytes: 1024
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a=[1,3,5,7,8,10,12]
    b=[4,6,9,11]
    c=[2]
    x,y = INTM()
    if x in a:
        d = 21
    elif x in b:
        d = 22
    elif x==2:
        d = 23
    
    if y in a:
        f = 21
    elif y in b:
        f = 22
    elif y==2:
        f = 23
    
    if d==f:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
	
public class Main {

	/* several useful subroutines */
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	@SuppressWarnings("unused")
	private static long calculateLCM(long a, long b) throws IOException {
		if ( a  < b ) {
			long t = a;
			a = b;
			b = t;
		}
		while ( b > 0 ) {
			long t = b;
			b = a % b;
			a = t;
		}
		return a;
	}

	
	/* main routine */
	
	public static void main(String args[]) throws IOException {
		int n = getInt();
		char s[] = getString().toCharArray();
		for ( int i = 0 ; i < s.length ; i++ ) {
			s[i] += n;
			if ( s[i] > 'Z' ) {
				s[i] -= 26;
			}
		}
			
		System.out.println( s );
	}
}


Measured memory_bytes: 21204
N, M = map(int, input().split())
Pi = list(map(int, input().split()))

for i in range(N):
    Pi[i] = Pi[i] - 1

T = [i for i in range(N)]

def parent(n):
    if T[n] == n:
        return n
    r = parent(T[n])
    T[n] = r
    return r

for _ in range(M):
    p1, p2 = map(int, input().split())
    p1 -= 1
    p2 -= 1
    pr1 = parent(p1)
    pr2 = parent(p2)
    if pr1 == pr2:
        continue
    T[pr2] = pr1

count = 0
for i in range(N):
    p1 = parent(Pi[i])
    p2 = parent(i)
    if p1 == p2:
        count += 1
print(count)

Measured memory_bytes: 13812
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

int n;
ll a[401], dp[401][402];

ll dfs(int left, int right) {
    if(left+1 == right) return 0LL;
    if(dp[left][right] != INF) return dp[left][right];

    for(int k=left+1;k<right;++k) {
        dp[left][right] = min(
            dp[left][right], 
            dfs(left, k)+dfs(k, right)
        );
    }
    dp[left][right] += a[right-1] - a[left-1];
    
    return dp[left][right];
}

int main() {
    cin >> n;
    for(int i=1;i<=n;++i) cin >> a[i];
    for(int i=1;i<=n;++i) a[i] += a[i-1];

    fill(dp[0], dp[400]+402, INF);
    cout << dfs(1, n+1) << endl;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e17;


int ar[ms];



bool go(string s,int n)
{
    int i;
    for(i=1;i<=n;i++)
    {
        if(ar[i])
        {
            if(s[i]=='x')
            {
                ar[i+1]=ar[i-1];
            }
            else{
                ar[i+1]=!ar[i-1];
            }
        }
        else{
            if(s[i]=='x')
            {
                ar[i+1]=!ar[i-1];
            }
            else{
                ar[i+1]=ar[i-1];
            }
        }
    }
    if(ar[0]==ar[n]&&ar[n+1]==ar[1])return true;
    return false;
}


int main()
{
    idfc;

    int  n;
    cin>>n;
    int i,j;
    string s;
    cin>>s;
    s+=s[0];


    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            ar[0]=i;
            ar[1]=j;
            if(go(s,n))
            {
                for(i=0;i<n;i++)
                {
                    if(ar[i])cout<<"W";
                    else cout<<"S";
                }
                return 0;
            }
        }
    }

    cout<<-1;


    return 0;
}

Measured memory_bytes: 4080
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def f(n):
    if n<=1:
        return 1
    sm = 2
    for i in range(1,n-1):
        sm += f(n-i-1)
    #ddprint(f"f({n})={sm}")
    return sm

h,w,k = inm()
d = [[0]*(w+2) for i in range(h+1)]
d[0][1] = 1
for i in range(h):
    d[i][0] = d[i][w+1] = 0
    for j in range(1,w+1):
        x = d[i][j]
        #ddprint(f"i {i} j {j} 0inc {x*f(j-1)*f(w-j)}")
        #ddprint(f"i {i} j {j} minc {x*f(j-2)*f(w-j)}")
        #ddprint(f"i {i} j {j} pinc {x*f(j-1)*f(w-j-1)}")
        d[i+1][j] = (d[i+1][j]+x*f(j-1)*f(w-j))%R
        d[i+1][j-1] = (d[i+1][j-1]+x*f(j-2)*f(w-j))%R
        d[i+1][j+1] = (d[i+1][j+1]+x*f(j-1)*f(w-j-1))%R
if DBG:
    for i in range(h+1):
        print(d[i])
print(d[h][k])


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a.begin(), a.end())

int main(){
    while(1){
        string s;
        cin >> s;
        if(s == "-")return 0;
        int m;
        cin >> m;
        rep(i,m){
            int h;
            cin >> h;

            string tmp = s.substr(h);
            s.erase(h);
            s.insert(0,tmp);
        }

        cout << s << endl;
    }
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,a;
  vector<char> ans;
  cin >> s;
  for (size_t i = 0; i < s.length(); i++) {
    if(s[i] == 'B'){
      if(ans.size() != 0)
        ans.pop_back();
      continue;
    }
    ans.push_back(s[i]);
  }
  for (size_t i = 0; i < ans.size(); i++) {
    a = a+ans[i];
  }
  cout << a;
}


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

int main(){
    int n,A[114514],ans = 0;
    memset(A,0,sizeof(A));
    scanf("%d",&n);
    int l,r;
    for(int i=0;i<n;i++){
        scanf("%d %d",&l,&r);
        for(int k=l-1;k<r;k++){
            A[k]++;
        }
    }
    for(int i=0;i<100000;i++) ans += A[i];
    printf("%d\n",ans);
}

Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] hs) {
    hs.reverse();

    int ans = 0;
    int x = 0;
    for (int i = 1; i < hs.length; i++) {
        if (hs[i-1] <= hs[i]) {
            x++;
            ans = max(ans, x);
        }
        else x = 0;
    }
    return ans;
}

void main() {
    readint;
    auto hs = readints;
    writeln(calc(hs));
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
 
void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}
 
const int N=2e5+3,M=5e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;
 
int n,m,k,tc,ans,a[N],cnt;
 
char s[N];

bool check(int x){
    ll cuts = 0;
    for(int i = 0 ; i < n ; i++)
        cuts += (a[i] - 1) / x;
    return cuts <= k;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
        scanf("%d",&a[i]);
    int l = 1, r = 1e9;
    while(l <= r){
        int mid = (l + r) >> 1;
        if (check(mid))
            r = mid - 1, ans = mid;
        else
            l = mid + 1;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 4548
#include <iostream>

using namespace std;

int main()
{
  int N;
  cin >> N;
    if((N>100000)||(N==1)){
      return 0;
    }

  int i;
  int A[N-1];
  for(i=0; i<N; i++){
    cin >> A[i];
    }

  int s=0;
  for(i=0; i<N; i++){
    if(A[i]%2!=0){
      s=s+1;
    }
  }

  if(s%2==0){
     cout << "YES";
    }
  if(s%2!=0){
     cout << "NO";
    }
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

int H,W,N;
char fld[1010][1010];


int sy,sx,gy,gx;
int dist[1010][1010];
int bfs(int s,int g){
    rep(i,H)rep(j,W){
        if(fld[i][j]==s+'0')sy=i,sx=j;
        if(fld[i][j]==g+'0')gy=i,gx=j;
    }
    fill_n(*dist,1010*1010,1001001001);
    dist[sy][sx]=0;

    queue<pint>que;que.push(pint(sy,sx));
    while(que.size()){
        int y,x;
        tie(y,x)=que.front();
        que.pop();
        rep(i,4){
            int ny=y+dy[i],nx=x+dx[i];
            if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]=='X'||dist[ny][nx]!=1001001001)continue;
            dist[ny][nx]=dist[y][x]+1;
            que.push(pint(ny,nx));
        }
    }

    return dist[gy][gx];
}

signed main(){
    scanf("%lld%lld%lld",&H,&W,&N);
    rep(i,H)rep(j,W){
        scanf(" %c",&fld[i][j]);
        if(fld[i][j]=='S')fld[i][j]='0';
    }

    int ans=0;
    rep(i,N)ans+=bfs(i,i+1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12084
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d", &a,&b);
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1000000007;
signed main(){
  int N,K,ans=0;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A)
    cin>>i;
  for(int i=0;i<N;i++){
    int k=0,l;
    for(int j=0;j<i;j++)
      if(A[j]>A[i])
        k++;
    l=k;
    for(int j=i;j<N;j++)
      if(A[j]>A[i])
        l++;
    ans=(ans+k*K%M+K*(K-1)/2%M*l%M)%M;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<set>
#include<algorithm>
#include<cstdio>
using namespace std;
int a[3][100005];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(j=0;j<3;j++)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[j][i]);
		}
	}
	sort(a[0],a[0]+n);
	sort(a[1],a[1]+n);
	sort(a[2],a[2]+n);
	int *q,*p;long long sum=0;
	for(i=0;i<n;i++)
	{
		q=lower_bound(a[0],a[0]+n,a[1][i]);
		p=upper_bound(a[2],a[2]+n,a[1][i]);
		sum+=((q-a[0])*(&a[2][n-1]-p+1));
	}
	printf("%lld\n",sum);
	
}

Measured memory_bytes: 2040
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String line = scanner.nextLine();
    String[] str = line.split(" ");
    String maxLengthStr = "";
    int maxLength = -1;
    Map<String, Integer> strMap = new HashMap<String, Integer>();
    String maxWordCountStr = "";
    int maxWorkCount = -1;
    for (int ii = 0; ii < str.length; ii++) {
      if (str[ii].length() > maxLength) {
        maxLength = str[ii].length();
        maxLengthStr = str[ii];
      }
      if (strMap.get(str[ii]) == null) {
        strMap.put(str[ii], 1);
      } else {
        strMap.put(str[ii], strMap.get(str[ii]) + 1);
      }
    }

    for (String key : strMap.keySet()) {
      int value = strMap.get(key);
      if (value > maxWorkCount) {
        maxWorkCount = value;
        maxWordCountStr = key;
      }
    }

    System.out.println(maxWordCountStr + " " + maxLengthStr);
  }
}

Measured memory_bytes: 17140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define fi first
#define se second

int main()
{
	ll x,a=100,y=0;
	cin >> x;
	while(a<x)
	{
		a+=a*0.01;
		y++;
	}
	cout << y << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int cnt = 0;
    rep(i,n){
        if(a[i] == cnt+1) cnt++;
    }
    if(cnt == 0) cout << -1 << endl;
    else cout << n-cnt << endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

m = 0

mae = -1
for a in A:
  m += B[a - 1]
  if a - mae == 1:
    m += C[mae - 1]
  mae = a

print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int N,M;
vector<int> edge[200010];
vector<int> visited(200010);

void dfs(int x, int ad, int count){
    visited[x] = 1;
    for(int i = 0; i < edge[x].size(); i++){
        if(count == 2) continue;
        int nx = edge[x][i];
        if(nx == ad) continue;
        if(visited[nx]) continue;
        dfs(nx, x, count + 1);
    }
}

int main(void){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(0, -1, 0);
    if(visited[N-1]){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 12784
from itertools import accumulate
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
a_acc = list(accumulate(a))
ans = 0
for i in range(n):
    ans += (a[i] * (a_acc[-1] - a_acc[i])) % mod
    ans %= mod
print(ans)

Measured memory_bytes: 107484
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    ll n,m;cin >> n >> m;
    rep(i,m){
        ll x;cin >> x;
        n -= x;
    }
    if(n >= 0)cout << n << '\n';
    else cout << -1 << '\n';

}

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

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

	int x, A, B;
	cin >> x >> A >> B;
	if (abs(A - x) > abs(B - x)) {
		cout << "B";
	}
	else cout << "A";
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int INF = 1<<29;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

int main(){
	char s[12],t[12];
	cin>>s;
	int n;
	n = strlen(s);
	int i,x=0;
	for(i=0;i<n;i++){
		if(s[i]=='0'){
			t[x]='0';
			x+=1;
		}else if(s[i]=='1'){
			t[x]='1';
			x+=1;
		}else{
			x=max(x-1,0);
		}
	}
	for(i=0;i<x;i++){
		cout<<t[i];
	}
	return 0;
}

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


int main (void)
{
	int h, w;
	int i, j;

	while (scanf("%d %d", &h, &w) != EOF && h != 0 || w != 0){
		for (i=0; i<h; i++){
			for (j=0; j<w; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}


	return 0;
}

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

int main(void) {
  int i,num,ac,wa,tle,re;
  char AC,WA,TLE,RE;
  char str = 'a';
  i = 0;
  num = 0;
  ac = 0;
  wa = 0;
  tle = 0;
  re = 0;
  while(1){
    char buf[128];
    fgets(buf, 128, stdin);
    sscanf(buf, "%d", &num);
    while(i<num){
      int a;
      char line[256];
      char *str;
      scanf("%s",line);
      str = (char*)line;
      if(strcmp(str,"AC")==0){
        ac ++;
      }else if(strcmp(str,"WA")==0){
        wa ++;
      }else if(strcmp(str,"TLE")==0){
        tle ++;
      }else if(strcmp(str,"RE")==0){
        re ++;
      }
      i++;
    }
    printf("AC x ");
    printf("%d\n",ac);
    printf("WA x ");
    printf("%d\n",wa);
    printf("TLE x ");
    printf("%d\n",tle);
    printf("RE x ");
    printf("%d\n",re);
    break;
  }
}


Measured memory_bytes: 1748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h) cin >> a[i];
    vector<string> ans(h+2);
    rep(i, h+2) {
        rep(j, w+2) {
            if (i==0 || i==h+1 || j==0 || j==w+1) {
                ans[i] += '#';
                continue;
            }
            ans[i] += a[i-1][j-1];
        }
    }
    rep(i, h+2) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int X, t;
    cin >> X >> t;
    
    if (X < t) cout << "0" << endl;
    else cout << X - t << endl;
    
    return 0;
}


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

int main(){
 int N,K,cnt=0;
 cin>>N>>K;
 int a[N];
 for(int i=0;i<N;i++) a[i]=0;
 for(int i=0;i<N;i++){
   int A;
   cin>>A;
   a[A-1]++;
 }
 for(int i=0;i<N;i++){
   if(a[i]>0) cnt++;
 }
 sort(a,a+N);
 if(cnt<=K) cout<<"0"<<endl;
 else{
   int b=0;
   for(int i=0;cnt>K;i++){
     if(a[i]!=0){
       b+=a[i];
       cnt--;
     }
   }
   cout<<b<<endl;
 }
}

Measured memory_bytes: 1024
while True:
    n=int(input())
    if n==0:
        break
    x=[]
    for i in range(n):
        y=int(input())
        x.append(y)
    for j in range(10):
        a=x.count(j)
        if a==0:
            print("-")
        else:
            print(a*"*")


Measured memory_bytes: 5704
#include <stdio.h>

int n, A[50];

// ????????\???M???????????????????´???????
int Solve( int i, int m ) {
    if ( m == 0 ) return 1;
    if ( i >= n ) return 0;
    int res = Solve( i+1, m ) || Solve( i+1, m-A[i] );
    return res;
}

int main() {
    int q, t, i;
    scanf( "%d", &n );
    for ( i = 0; i < n; i++ ) {
        scanf( "%d", &A[i] );
    }
    
    scanf( "%d", &q );
    for ( i = 0; i < q; i++ ) {
        scanf( "%d", &t );
        if ( Solve(0, t) ) {
            printf( "yes\n" );
        } else {
            printf( "no\n" );
        }
    }
    
    return 0;
}

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

const int INF = 1145141919;
const long long INFL = 1LL<<60;

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()
{
	int N, W;
	cin >> N >> W;
	int w[110], v[110];
	for (int i = 0; i < N; ++i)
	{
		cin >> w[i] >> v[i];
	}
	int dp[110001];
	for (int i = 0; i <= 110000; ++i)
	{
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 110000; j >= 0; --j)
		{
			if(dp[j] != INF && j+v[i] <= 110000)
			{
				dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
			}
		}
	}
	int ans = INF;
	for (int i = 110000; i >= 0; --i)
	{
		if(dp[i] <= W)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Result{
	string name;
	int score;
	Result(){}
	Result(string n,int s):name(n),score(s){}
	bool operator>(const Result& r)const{return score>r.score;}
};

int main()
{
	bool first=true;
	for(int n;cin>>n,n;){
		if(!first)
			cout<<endl;
		first=false;
		
		vector<Result> rs(n);
		rep(i,n){
			int a,b,c;
			cin>>rs[i].name>>a>>b>>c;
			rs[i].score=a*3+c;
		}
		stable_sort(allof(rs),greater<Result>());
		rep(i,n)
			cout<<rs[i].name<<","<<rs[i].score<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
S = gets.chomp!

split_s = []
count = 1

S.each_char.with_index do |c, i|
  if S[i + 1] != c
    split_s << c * count
    count = 1
  else
    count += 1
  end
end

students = Array.new(S.size, 0)
i = 0
split_s.each do |sequence|
  #binding.irb
  if sequence.include? 'R'
    students[i + sequence.size] += sequence.size / 2
    students[i + sequence.size - 1] +=  sequence.size - sequence.size / 2
  else
    students[i - 1] +=  sequence.size / 2
    students[i] += sequence.size - sequence.size / 2
  end

  i += sequence.size
end

puts students.join(' ')


Measured memory_bytes: 11132
H, W, D = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]
target = [[0,0] for _ in range(H*W+1)]
ruiseki = [[i+1] for i in range(D)]
ans = 0
for i in range(H):
    for j in range(W):
        target[grid[i][j]][0] = i+1
        target[grid[i][j]][1] = j+1
for i in range(D):
    tmp = ruiseki[i][0]
    ruiseki[i][0] = 0
    cnt = 0
    while tmp+D <= H*W:
        dist = abs(target[tmp][0]-target[tmp+D][0])+abs(target[tmp][1]-target[tmp+D][1])
        ruiseki[i].append(ruiseki[i][cnt]+dist)
        cnt += 1
        tmp += D
for i in range(Q):
    current = LR[i][0]
    tmp = D if current%D == 0 else current%D
    tmp -= 1
    print(ruiseki[tmp][((current-1)//D)+((LR[i][1]-current)//D)]-ruiseki[tmp][((current-1)//D)])

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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

const int N = 111111;
vii G(N);
int ans = 0;
int n, k;

int dfs(int now, int par) {
    int res = 0;
    for (int v: G[now]) {
        if (v == par) continue;
        chmax(res, dfs(v, now));
    }
    res++;
    if (res == k) {
        if (now != 0 and par != 0) {
            ans++;
            res = 0;
        }
    }
    return res;
}

signed main() {
    fio();
    
    cin >> n >> k;
    rep (i, n) {
        int to;
        cin >> to;
        to--;
        if (i == 0) {
            if (to != 0) ans++;
        }
        else {
            G[to].push_back(i);
        }
    }


    dfs(0, -1);
    cout << ans << endl;
}

Measured memory_bytes: 13740
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    static int N;
    static int Q;
    static ArrayList<Integer>[] G;
    static long[] counter;
    static long[] ans;

    public static void init() {
        InputStream inputStream = System.in;
        InputReader in = new InputReader(inputStream);

        N = in.nextInt();
        Q = in.nextInt();

        G = new ArrayList[N];
        for(int i = 0; i < N; i++) G[i] = new ArrayList<>();
        for(int i = 0; i < N - 1; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            G[from].add(to);
            G[to].add(from);
        }

        counter = new long[N];
        for(int i = 0; i < Q; i++) {
            int target = in.nextInt() - 1;
            int count = in.nextInt();
            counter[target] += count;
        }

        ans = new long[N];

    }

    public static void dfs(int cur, int prev, long prop) {
        ans[cur] += counter[cur] + prop;

        for(int to: G[cur]) {
            if(to != prev) dfs(to, cur, counter[cur] + prop);
        }

    }

    public static void main(String[] args) {
        init();

        dfs(0, 0, 0);
        
        for(int i = 0; i < N; i++) {
            System.out.print(ans[i] + " ");
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


Measured memory_bytes: 151764