akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	
	for(int i=0;i<s.size();i++){
		for(int j=1;j<=n;j++)
		{
			if(s[i]=='Z') s[i]='A';
			else s[i]++;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 102
#define INF 20000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int prim(int matrix[][SIZE], int num){
  int color[SIZE],depth[SIZE],parent[SIZE];
  int v,i,min,sum=0,u;

  for(i=0;i<num;i++){
    depth[i]=INF;
    parent[i]=-1;
    color[i]=WHITE;
  }
  depth[0]=0;
  while(1){
    u=-1;
    min=INF;
    for(i=0;i<num;i++){
      if(color[i]!=BLACK && depth[i]<min){
	    min = depth[i];
	    u=i;
      }
    }
    if(u == -1)break;
    color[u]=BLACK;

    for(v=0;v<num;v++){
      if(color[v]!=BLACK && matrix[u][v]!=INF){
	    if(matrix[u][v]<depth[v]){
	     depth[v]=matrix[u][v];
	     parent[v]=u;
	     color[v]=GRAY;
	    }
      }
    }
    sum=0;
    for(i=0;i<num;i++)
      if(parent[i]!=-1)
	sum+=matrix[i][parent[i]];    
  }
  return sum;
}

int main(){
  int matrix[SIZE][SIZE];
  int i,j,value,num,result;
  scanf ("%d",&num);

  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      scanf("%d",&value);
      matrix[i][j]=(value==-1)?INF:value;
    }
  }
  result = prim(matrix,num);
  printf("%d\n",result);
  return 0;
}


Measured memory_bytes: 1972
#include<stdio.h>
#include<string.h>
int main()
{
  char s[100];
  int a,b,i;
  scanf("%d%d",&a,&b);
    scanf("%s",&s);
  
    if(s[b-1]>='A'&&s[b-1]<='Z'){
      s[b-1]=s[b-1]+32;
    }
    printf("%s",s);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, a[MAXN];
string s;

int next(int i){
	if(a[(i + 1) % n] == 0){ //sheep
		if(s[(i + 1) % n] == 'o') return a[i];
		else return 1 - a[i];
	} else{
		if(s[(i + 1) % n] == 'o') return 1 - a[i];
		else return a[i];	
	}
}

bool go(){
	for(int i = 2; i < n; i++){
		a[i] = next(i - 2);
	}
	if(next(n - 2) != a[0] or next(n - 1) != a[1]) return false;
	for(int i = 0; i < n; i++){
		if(a[i] == 0) cout << "S";
		else cout << "W";
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> s;
    bool b;
    b = go();
    if(b) return 0;
    a[0] = 1;
    b = go();
    if(b) return 0;
    a[1] = 1;
    b = go();
    if(b) return 0;
    a[0] = 0;
    b = go();
    if(b) return 0;
    cout << -1;
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(void){

    int N,M; cin>>N>>M;
    vector<int> ans(N+1);
    for (int i = 1; i <= M; ++i) {
        int a,b; cin>>a>>b;
        ans[a]++;
        ans[b]++;
    }
    for (int i = 1; i <= N; ++i) {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    cout << N - i + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
n=int(input())
c=[]
for _ in range(n): c.append(list(map(int,input().split())))
dic=defaultdict(int)
for i in range(n):
    for j in range(n):
        if i==j: continue
        dic[(c[i][0]-c[j][0],c[i][1]-c[j][1])]+=1
if dict(dic): print(n-max(dic.values()))
else: print(1)

Measured memory_bytes: 9600
def main():
    h, w = map(int, input().split())
    grid = []
    for height in range(0, h):
        grid.append(list(input()))

    replaced = []
    for height in range(0, h):
        replaced.append([0] * w)

    dx = [0, 0, 1, 1, 1, -1, -1, -1]
    dy = [1, -1, 1, -1, 0, 1, -1, 0]

    for height in range(0, h):
        for width in range(0, w):
            if grid[height][width] == '#':
                replaced[height][width] = '#'
                continue
            for i in range(0, 8):
                if (height + dy[i] < 0) or (height + dy[i] >= h) or (width + dx[i] < 0) or (width + dx[i] >= w):
                    continue
                if (grid[height + dy[i]][width + dx[i]]) == '#':
                    replaced[height][width] += 1

    for height in range(0, h):
        for width in range(0, w):
            print(replaced[height][width], end='')
        print()


if __name__ == "__main__":
  main()


Measured memory_bytes: 3572
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
    string x;
    cin >> x;
 
    string a = "";
    for(int i=0;i<x.size();i++){
        a += x[i];
        if(a[a.size()-1] == 'T' && a[a.size()-2] == 'S'){
            a.pop_back();
            a.pop_back();
        }
    }
    cout << a.size();
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int n, m; cin >> n >> m;

	vector <int> a(m);

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

	if(accumulate(a.begin(), a.end(), 0LL) > n){
		cout << -1 << endl;
	}else{
		cout << n - accumulate(a.begin(), a.end(), 0LL) << endl;
	}

	
	
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        String str = sc.next();

        int red = 0;
        int blue = 0;
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == 'R') {
                red++;
            }
            if (chars[i] == 'B') {
                blue++;
            }
        }

        System.out.println((red > blue) ? "Yes" : "No");
    }
}

Measured memory_bytes: 23764
n = int(input())

ans = [0]*(n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if 1 <= val and val <= n:
                ans[val] += 1

for i in range(n):
    print(ans[i+1])


Measured memory_bytes: 73912
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
  	int a[n];
  	for (int i = 0; i < n; i++) a[i] = 0;
  	for (int i = 0; i < n - 1; i++) {
    	int x; cin >> x;
      	a[--x]++;
    }
  	for (int i = 0; i < n; i++) {
     	cout << a[i] << endl; 
    }
}


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

vector<ll> f;

ll modinv(ll a, ll m) {
	ll b=m, u=1, v=0;
	while(b) {
		ll 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 cmb(int n, int r) {
	ll x,y;

	if(r == 0)
		return 0;
	if(n == r)
		return 1;

	x = f.at(n-1) * modinv(f.at(n-r-1),MOD) % MOD;
	y = f.at(r-1);
	return x * modinv(y,MOD) % MOD;
}

int main() {
	int N,K;
	ll r=0;
	cin >> N >> K;

	vector<int> A(N);
	f.resize(N);

	f.at(0) = 1;
	rep(i,N-1) {
		f.at(i+1) = f.at(i)*(i+2);
		f.at(i+1) %= MOD;
	}
	
	rep(i,N)
		cin >> A.at(i);
	sort(A.begin(), A.end());

	rep(i,N) {
		// cout << i << " " << A.at(i) << endl;
		if(i >= K-1) {
			r += A.at(i) * cmb(i,K-1) % MOD;
			// cout << A.at(i) * cmb(i,K-1) << " ";
		}
		if(N-1-i >= K-1) {
			r -= A.at(i) * cmb(N-1-i,K-1) % MOD;
			// cout << -A.at(i) * cmb(N-1-i,K-1);
		}
		r %= MOD;

		// cout << endl;
		// cout << r << endl;
	}

	cout << r << endl;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

ll N, K; 
vector<ll> A, F;

bool ok(ll n){
    ll cur=K;
    for(int i=0; i<N; i++){
        if(A[i]*F[i] > n){
            cur-=((A[i]*F[i]-n)+F[i]-1)/F[i];
        }
    }
    if(cur >= 0) return true;
    else return false;
}

int main(){
    cin >> N >> K;
    A.resize(N), F.resize(N);
    for(auto &x : A){
        cin >> x;
    }
    for(auto &x : F){
        cin >> x;
    }
    sort(all(A));
    sort(all(F), greater<ll>());
    ll l=-1, r=1e12+5;
    while(r-l > 1){
        ll mid=l+(r-l)/2;
        if(ok(mid)) r=mid;
        else l=mid;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 6412
#include<stdio.h>
#include<string.h>
int c[100010];
char s[10];
//#define local
#ifdef local
#include"head.h"
void work(){
#else
	int getn(){
		int n;
		scanf("%d",&n);
		return n;
	}
	int get(int x){
		if(~c[x])return c[x];
		printf("%d\n",x);
		fflush(stdout);
		scanf("%s",s);
		if(s[0]=='V')throw 0;
		return c[x]=s[0]=='M';
	}
int main(){
#endif
	int n,l,r,mid;
	memset(c,-1,sizeof(c));
	n=getn();
	try{
		l=0;
		r=n-1;
		while(r-l>2){
			mid=(l+r)>>1;
			if((mid-l+1)&1){
				if(get(l)^get(mid))
					r=mid;
				else
					l=mid;
			}else{
				if(get(mid+1)^get(r))
					l=mid+1;
				else
					r=mid+1;
			}
		}
		while(l<=r)get(l++);
	}catch(int e){}
}

Measured memory_bytes: 1236
/* */
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
const int MAX_LEN = 1010;
#define GETLINE(x) fgets(x,MAX_LEN,stdin);
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
#ifdef XVENOM
    #define errp(...) fprintf(stderr, __VA_ARGS__)
    #define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
    #define errp(...)
    #define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
    string s_ = "[ ";
    for (const auto& x_ : e_) s_ += to_string(x_) + " ";
    return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
    return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
     errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int n,m;
int main () {
    int ans=0; 
    scanf("%d %d",&n,&m);
    for(int i=1;i*i<=m;i++){
        if(m%i==0){
            if(i>=n)ans=max(ans,m/i);
            if((m/i)>=n)ans=max(ans,i);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] s=br.readLine().split(" ");
        int N=Integer.parseInt(s[0]);
        int M=Integer.parseInt(s[1]);
        int ans=N*(N-1)/2+M*(M-1)/2;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9+7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

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

  vector<ll> dp(s+1,0);
  dp[0] = 1;
  for(int i = 1; i < s+1; i++){
    for(int j = 0; j <= i - 3; j++){
      dp[i] += dp[j];
      dp[i] %= M;
    }
  }
  cout << dp[s] << endl;

  return 0;
}


Measured memory_bytes: 3648
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
S = sr()
# 桁DP, 上から
dp = [0] * 13
dp[0] = 1
for s in S:
    prev = [x for x in dp]
    dp = [0] * 13
    if s != '?':
        s = int(s)
        for j in range(13):
            dp[(10*j+s)%13] = prev[j]
    else:
        for j in range(13):
            for k in range(10):
                dp[(10*j+k)%13] += prev[j]
    dp = [x%MOD for x in dp]

answer = dp[5]
print(answer%MOD)


Measured memory_bytes: 43756
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 200010;
const ll INF = 1e18;
ll a[N];
ll s[N];

int main()
{
	int n;
	scanf("%d", &n);
	s[0] = 0;
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &a[i]);
		s[i] = s[i - 1] + a[i];
	}
	ll ans = INF;
	for (int i=1; i<n; i++)
	{
		ll s1 = s[i];
		ll s2 = s[n] - s[i];
		ans = min(ans, abs(s1 - s2));
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int x[5];
  rep(i, 3) cin >> x[i];

  sort(x, x+3);

  cout << x[0] + x[1] << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//i回目の提出はpi番目の問題への提出
/*ペナルティ数はACを1回以上出した各問題について、初めてACを出すまで
に出したWAの数
*/
//正当数はACを1回以上出した問題の数
//(pi,i,Si)のタプル配列を作り、ソートする
//ソートしたタプル配列に対して、各piについて、初めてACが出るまでのWAをカウント
int main(){
  int N,M;
  cin >> N >> M;
  vector<tuple<int,int,string>> t(M);
  for(int i = 0;i<M;i++){
      cin >> get<0>(t[i]);
      get<1>(t[i]) = i;
      cin >> get<2>(t[i]);
  }

  
 sort(t.begin(),t.end());


  int cw = 0;//ペナルティ数
  int ca = 0;//正当数
  for(int i = 0;i<M;){
      int p = get<0>(t[i]);//各問題番号
      //最初にある問題番号についてACあるか調べる
      bool flag = false;
      int j = i;
      while(get<0>(t[j]) == p){//問題番号が同じ間の処理
        if(get<2>(t[j]) == "AC") flag = true;
        j++;
      }

     if(flag == true){//ACがある時
      while(get<0>(t[i]) == p){//問題番号が同じ間の処理
          if(get<2>(t[i]) == "WA"){
            cw++;
            i++;
          }
          else if(get<2>(t[i]) == "AC"){//初めてACが出たら次の問題番号に移りたい
              ca++;
              while(get<0>(t[i]) == p){
                  i++;
              }
              break;
          }
      }
     }
     else if(flag == false){//ACがない時
       i = j;//iを進める
     }
  }
  cout << ca << " " << cw << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

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

    vector<string> W(N);
    for (int i = 0; i < N; ++i) {
        cin >> W[i];
    }

    for (int i = 1; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            if (W[i] == W[j]) {
                cout << "No" << endl;
                return 0;
            }
        }

        if (W[i].front() != W[i-1].back()) {
            cout << "No" << endl;
            return 0;
        }

    }

    cout << "Yes" << endl;


    return 0;
}



Measured memory_bytes: 256
INF = 10**10
def dijkstra(s):
    dist = [INF]*size
    used = [False]*size
    dist[s] = 0
    while 1:
        v = -1
        for u in range(size):
            if not used[u] and (v == -1 or dist[u] < dist[v]): v = u
        if v == -1: break
        used[v] = True
        for u in range(size):
            dist[u] = min(dist[u],dist[v]+G[v][u])
    return dist

while 1:
    n = int(raw_input())
    if n == 0: break
    abc = [map(int,raw_input().split()) for _ in range(n)]
    size = max(max(a,b) for a,b,c in abc)+1
    G = [[INF for _ in range(size)] for __ in range(size)]
    for a,b,c in abc:
        G[a][b] = G[b][a] = c
    sumdist = 10**10
    town = 0
    for s in range(size):
        tmp = sum(dijkstra(s))
        if tmp < sumdist:
            sumdist = tmp
            town = s
    print town,sumdist

Measured memory_bytes: 4288
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n,y;
  scanf("%d%d",&n,&y);
  y /= 1000;
  int a = 0, b = 0, c = y;
  // while (y-4 >= n && c >= 5) {
  //   y -= 4;
  //   b++; c -= 5;
  // }
  int x = min(c/5, (y-n)/4); maxs(x,0);
  y -= 4*x; b += x; c -= 5*x;
  // while (y-1 >= n && b >= 2) {
  //   y--;
  //   a++; b -= 2;
  // }
  x = min(y-n, b/2); maxs(x,0);
  y -= x; a += x; b -= 2*x;
  if (y == n) {
    cout<<a<<" "<<b<<" "<<c<<endl;
  } else {
    cout<<vi(3,-1)<<endl;
  }
  return 0;
}






















Measured memory_bytes: 256
#include <iostream>
#include <vector>		
#include <algorithm> // sort
#include <functional> //降順ソート


using namespace std;

int main() {
	int N, K;

	cin >> N >> K;

	std::vector<int> l;

	int inp=0;
	for (int i = 0 ; i < N ; i++) {
		cin >> inp;
		// 配列に要素を追加
		l.push_back(inp);
	}
	// 配列のソート
	std::sort(l.begin(), l.end(), std::greater<int>());

	int maxval = 0;
	for (int j = 0; j < K; j++) {
		maxval += l[j];
	}
	cout << maxval << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,string>
int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]==t[i])ans++;
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

	if a % 3 == 0 || b  % 3 == 0 || (a + b) % 3 == 0 {
		fmt.Printf("Possible\n")
	} else {
		fmt.Printf("Impossible\n")
	}
}

Measured memory_bytes: 512
# INF = 10*10

def partition(A, p, r):
   x = A[r][1]
   i = p-1
   for j in range(p, r):
     if A[j][1] <= x:
       i = i+1
       A[i], A[j] =  A[j], A[i]
   A[i+1] , A[r] = A[r], A[i+1]
   return i+1

def quicksort(A, p, r):
   if p < r:
     q = partition(A, p, r)
     quicksort(A, p, q-1)
     quicksort(A, q+1, r)
#
# def merge(A, left, mid,  right):
#   global cnt
#   L = A[left:mid]
#   L.append([0,INF])
#   R = A[mid:right]
#   R.append([0,INF])
#   i = 0
#   j = 0
#   for k  in range(left , right):
#     if L[i][1] <= R[j][1]:
#       A[k] = L[i]
#       i = i + 1
#     else:
#       A[k] = R[j]
#       j = j + 1
#
# def mergeSort(A, left, right):
#   if left+1 < right:
#     mid = (left + right)//2
#     mergeSort(A, left, mid)
#     mergeSort(A, mid, right)
#     merge(A, left, mid, right)
#
n = int(input())
A = [[0 for j in range(3)] for i in range(n)]
# B = [[0 for j in range(2)] for i in range(n)]
for i in range(n):
    A[i][0],A[i][1] = input().split()
    A[i][1] = int(A[i][1])
    A[i][2] = i
    # B[i][1] = int(B[i][1])

quicksort(A, 0, n-1)
# mergeSort(B, 0, n)
#
# if A == B:
#     print("Stable")
# else:
#     print("Not stable")

stable_FLG = True
for i in range(1,n):
    if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]:
        stable_FLG = False
        break

if stable_FLG:
    print("Stable")
else:
    print("Not stable")


for i in range(n):
    print(A[i][0],A[i][1])




Measured memory_bytes: 22832
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    temp=input().split(" ")
    n=int(temp[0])
    a=int(temp[1])
    b=int(temp[2])
    su=0


    for i in range(n+1):
        if  a<=ketanowa(i) and ketanowa(i)<=b:
            su+=i
    print (su)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
x,y = map(int,input().split())
ans = 10**18
dx = [1,1,-1,-1]
dy = [1,-1,1,-1]

for i in range(4):
  tx = x * dx[i]
  ty = y * dy[i]
  if tx <= ty:
    ans = min(ans,ty-tx + (2-dx[i]-dy[i])//2)
print(ans)

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

class BIT{
private:
    int N;
    vector<int> data;
    
public:
    BIT(int N): N(N){
        data.assign(N+1, 0);
    }
    int sum(int i){
        int x = 0;
        while(0 < i){
            x += data[i];
            i -= i & -i;
        }
        return x;
    }
    int sum(int x, int y){
        return sum(y) - sum(x-1);
    }
    void add(int i, int x){
        while(i <= N){
            data[i] += x;
            i += i & -i;
        }
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    
    BIT bit(N);
    for(int i=0; i<Q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0)
            bit.add(x, y);
        if(com == 1)
            cout << bit.sum(x, y) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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

int main()
{
    int n;
    cin >> n;
    map<int , int> ans;

        for(ll i = 1; i*i <= n; i++){
            
            for(ll j = 1; j*j <= n; j++){
                
                for(ll k = 1; k*k <= n; k++){
                    
                    ll tmp = (i+j+k)*(i+j+k);
                    int p = tmp-i*j-i*k-j*k;
                    if(p > 0){
                        if(i == j && j == k){
                            ans[p]++;
                            continue;
                        }else if(i == j && j != k){
                            ans[p]++;
                            continue;
                        }
                        else if(i!= j && j == k){
                            ans[p]++;
                            continue;
                        }
                        else if(i == k && i != j){
                            ans[p]++;
                            continue;
                        }else if(i!=k && j != k && i != j){
                            ans[p]++;
                            continue;
                        }
                    }
                }
            }
        }

    for(int i = 1; i <= n; i ++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5316
#pragma GCC optimize("Ofast",3,"inline")
#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n>>s;
	if(n<3200)cout<<"red";
	else cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

int n;
cin >> n;
string s;
cin >> s;
int count = 1;
for(int i = 1; i < n; ++i){
	if(s[i]!=s[i-1]){
		count++;
	}
}
cout << count;
return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int A[100000];

int partition(int *a, int p, int r)
{
	int x=a[r];
	int i=p-1;
	for(int j=p; j<r; j++) {
		if(a[j]<=x) {
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i+1], a[r]);
	return i+1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0; i<n; i++) cin>>A[i];
	int q=partition(A, 0, n-1);

	for(int i=0; i<n; i++) {
		if(i) cout<<' ';
		if(i==q) cout<<'['<<A[i]<<']';
		else cout<<A[i];
	}
	cout<<'\n';

	return 0;
}



Measured memory_bytes: 3496
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;


#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int



bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }



int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
	map<ll,ll> m;

	int n;
	cin>>n;

	vl v(n);
	ll pro = 1;
	ll sum = 0;
	forn(i,0,n)
	{
		cin>>v[i];
		ll k = v[i];
		sum = (sum + power(k,mod-2,mod))%mod;
		ll j = 2;

		ll count = 0;
		if(k%j == 0)
		{
			while(k%j == 0)
			{
				k = k/j;
				count++;
			}
			if(count)
			{
				m[j] = max(m[j],count);
			}
		}


		j = 3;

		for(; j*j <= k; j += 2)
		{
			count = 0;
			if(k%j == 0)
			{
				while(k%j == 0)
				{
					k = k/j;
					count++;
				}
				if(count)
				{
					m[j] = max(m[j],count);
				}
			}
		}

		if(k > 1)
		{
			m[k] = max(m[k],1LL);
		}
	}

	forv(i,m)
	{
		pro = (pro*power(i.ff,i.ss,mod))%mod;
	}

	pro = (pro*sum)%mod;


	cout<<pro;






    return 0;
}		

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9+21;
const long long LINF = (long long) 1e18;
const long double PI = 2 * acos((long double)0);
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
#define Mahmud main()
#define endl "\n"
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define alla(arr,n) arr,arr+n
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define pb push_back
///Debug
#define dbg1(x) std::cerr<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<','<<#z<<"="<<(z)<<endl;
#define dbgArr(arr,n) cerr<<#arr<<"=["; printArray(arr,n,0,93); cerr<<endl;
///traversing
#define rep(n) for(int i=0;i<n;++i)
#define trv(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();++i)
///necessary functions
inline ll Int()
{
    ll _x=0,_tmp=1;
    char _tc=getchar();
    while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
    if( _tc == '-' ) _tc=getchar(), _tmp = -1;
    while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
    return _x*_tmp;
}
inline long double Double()
{
    long double d;
    scanf("%Lf",&d);
    return d;
}
ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}
int ton(string x)
{
    int y;
    std::istringstream ss(x);
    ss >> y;
    return y;
}
template<typename T>
string tostring(T x)
{
    ostringstream ss;
    ss << x ;
    return ss.str();
}

///Current Code vars
#define N 100010
long long n,k,c,d;
int arr[N+1],brr[N+1];
///Current Code functions

string s;

void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b == c+d)
    {
        cout<<"Balanced"<<endl;
    }
    else if(a+b > c+d)
    {
        cout<<"Left"<<endl;
    }
    else cout<<"Right"<<endl;
}

int Mahmud
{
    // ios_base::sync_with_stdio(0); //cin.tie(0);
  //#ifdef _LOCAL_
    //freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
  //while(1)
    solve();
  //#ifdef _LOCAL_
    //printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
  //#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int h, w, kk; cin >> h >> w >> kk;
    vector<vector<int>> map(h,vector<int>(w));
    rep(i,h) rep(j,w){
        char s; cin >> s;
        map[i][j] = s - '0';
    }

    int ans = 100100;

    rep(i,1<<(h-1)){
        int count = 0;

        vector<vector<int>> mapcopy(h,vector<int>(w));
        rep(j,h) rep(k,w) mapcopy[j][k] = map[j][k];

        vector<bool> div(h);
        rep(j,h-1){
            if(i & 1<<j){
                div[j] = true;
                count++;
            }
            else{
                div[j] = false;
                rep(k,w) mapcopy[j+1][k] += mapcopy[j][k];
            }
        }
        div[h-1] = true;

        bool check1 = true;
        rep(j,h) rep(k,w) if(div[j] && mapcopy[j][k] > kk) check1 = false;

        if(check1){
            loop(j,1,w){
                bool check2 = true;
                rep(k,h) if(div[k] && mapcopy[k][j]+mapcopy[k][j-1] > kk) check2 = false;
                if(check2){
                    rep(k,h) mapcopy[k][j] += mapcopy[k][j-1];
                }
                else { count++; }
            }
        }
        else{ count = 100100; }

        if(ans > count) ans = count;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3740
#include<iostream>
#include<map>
#include<string>
#include<queue>
using namespace std;
const char NIL = -1;

int main(){
    string s;
    cin >> s;
    int ans = 0;

    auto compare = [](int a, int b) {
        return a > b;
    };

    priority_queue<int, vector<int>, decltype(compare)> que {compare};
    map<char, int> mp;
    
    for (int i = 0; i < s.size(); i++)
        mp[s[i]] += 1;
    map<char, int>::iterator head = mp.begin();
    for (int i = 0; i < mp.size(); i++)
        que.push((*(head++)).second);
    int sum;
    if (que.size() == 1)
    {
        cout << que.top() << endl;
        return 0;
    }
    
    while (!(que.size() == 1))
    {
        sum = 0;
        sum += que.top();
        que.pop();
        sum += que.top();
        que.pop();
        ans += sum;
        que.push(sum);
    }
    cout << ans << endl;
}


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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if(0>x-r||0>y-r||W<x+r||H<y+r){
    cout << "No" << endl;
    return 0;
  }
  else {
      cout << "Yes" << endl;
      return 0;
  }
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

int main() {
	string s;
	cin >> s;
	int mode = 0;
	Loop(i, s.length()) {
		if (mode == 0 && s[i]=='C') {
			mode = 1;
		}
		else if (mode == 1 && s[i] == 'F') {
			mode = 2;
		}
	}
	if (mode == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
C = list(map(int, input().split(" ")))
score = 0

for i in range(0,N):
    score += B[A[i]-1]
    if i!=0 and A[i-1]+1 == A[i]:
        score += C[A[i-1]-1]

print(score)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    
    string ans;
    
    rep(i,gy-sy) ans+='U';
    rep(i,gx-sx) ans+='R';
    rep(i,gy-sy) ans+='D';
    rep(i,gx-sx+1) ans+='L';
    
    rep(i,gy-sy+1) ans+='U';
    rep(i,gx-sx+1) ans+='R';
    ans+="DR";
    rep(i,gy-sy+1) ans+='D';
    rep(i,gx-sx+1) ans+='L';
    ans+='U';
    cout1(ans)
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	string a, b;
	getline(cin,a);
	getline(cin,b);
	int k=a.size();
	int p=b.size();
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	if(b>a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
} 

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

struct Edge {
  int to, w;
  Edge(int t, int w) :to(t), w(w) {}
};

struct Graph {
  int N;
  vector<vector<Edge>> edges;

  Graph(int N) :N(N), edges(N) {}

  void addDEdge(int a, int b) { addDEdge(a, b, 1); }
  void addDEdge(int a, int b, int w) { edges[a].emplace_back(b, w); }
  void addEdge(int a, int b) { addEdge(a, b, 1); }
  void addEdge(int a, int b, int w) { 
    edges[a].emplace_back(b, w);
    edges[b].emplace_back(a, w);
  }

  vector<int> parent, dep;
  void setParent(int n) {
    parent = vector<int>(N, -2);
    dep = vector<int>(N, 0);
    queue<int> q;
    parent[n] = -1;
    q.push(n);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for (Edge e : edges[v]) {
        if (parent[e.to] != -2) continue;
        parent[e.to] = v;
        dep[e.to] = dep[v] + 1;
        q.push(e.to);
      }
    }
  }
};

const string YES = "Yes";
int main(){
  int N, M; cin >> N >> M;
  Graph G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    x--; y--;
    G.addEdge(x, y);
  }
  G.setParent(0);

  cout << YES << endl;
  rep(i, N - 1) cout << G.parent[i + 1] + 1 << endl;
}

Measured memory_bytes: 12608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int dp[202020][2];

int main(){
  int N; cin>>N;
  string S; cin>>S;
  rep(i,202020) rep(j,2) dp[i][j]=1e9;
  dp[0][0]=0;
  rep(i,N) rep(j,2) if(dp[i][j]!=1e9){
    if(j==0){
      // 前の石が白
      if(S[i]=='.'){
        dp[i+1][0]=min(dp[i+1][0],dp[i][j]);
        dp[i+1][1]=min(dp[i+1][1],dp[i][j]+1);
      }else{
        dp[i+1][0]=min(dp[i+1][0],dp[i][j]+1);
        dp[i+1][1]=min(dp[i+1][1],dp[i][j]);
      }
    }else{
      // 前の石が黒
      if(S[i]=='.'){
        dp[i+1][1]=min(dp[i+1][1],dp[i][j]+1);
      }else{
        dp[i+1][1]=min(dp[i+1][1],dp[i][j]);
      }
    }
  }
  cout<<min(dp[N][0],dp[N][1])<<endl;
  return 0;
}


Measured memory_bytes: 2180
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main(void) {
  string s;
  cin >> s;
  if(s == "AAA" || s == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


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

using namespace std;

int longestWay(int pos, int N, vector<vector<int> >& edge, vector<vector<int> >& weight, vector<int>& mark){
    if(mark[pos]) return 0;
    int dist = 0;
    mark[pos] = 1;
    for(int i = 0; i < edge[pos].size(); i++){
        if(!mark[edge[pos][i]]){
            dist = max(dist, weight[pos][i] + longestWay(edge[pos][i], N, edge, weight, mark));
        }
    }
    mark[pos] = 0;
    return dist;
}

int solve(int N, vector<vector<int> >& edge, vector<vector<int> >& weight){
    vector<int> mark(N);
    for(int i = 0; i < N; i++){
        if(edge[i].size() == 1){
            mark[i] = 1;
        }
    }
    int longest = 0;
    for(int i = 0; i < N; i++){
        longest = max(longest, longestWay(i, N, edge, weight, mark));
    }
    int result = 0;
    for(int i = 0; i < N; i++){
        for(int k = 0; k < edge[i].size(); k++){
            int j = edge[i][k];
            if(i >= j) continue;
            result += weight[i][k]; // remove a bridge
            if(mark[i] != 1 && mark[j] != 1){
                result += weight[i][k] * 2; // cross around a bridge
            }
        }
    }
    return result - longest;
}

int main(){
    while(true){
        int N;
        cin >> N;
        if(N == 0) break;
        vector<vector<int> > edge(N);
        vector<vector<int> > weight(N);
        for(int i = 1; i < N; i++){
            int v;
            cin >> v;
            edge[i].push_back(v-1);
        }
        for(int i = 1; i < N; i++){
            int v;
            cin >> v;
            weight[i].push_back(v);
        }
        for(int i = 1; i < N; i++){
            edge[edge[i][0]].push_back(i);
            weight[edge[i][0]].push_back(weight[i][0]);
        }
        cout << solve(N, edge, weight) << endl;
    }
    return 0;
}

Measured memory_bytes: 1376
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[1000001];
int sum=0,b=1;
int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			b++;
		}
		else{
			if(b&1)sum++;
			b=1;
		}
	}
	if(b&1)sum++;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N,M = inputIL()
data = inputILL(N)

s = set(i+1 for i in range(M))
for item in data:
  s &= set(item[1:])



print(len(s))

Measured memory_bytes: 65900
S = input()
#SUN,MON,TUE,WED,THU,FRI,SAT
if S == "SUN":
  print(7)
if S == "MON":
  print(6)
if S == "TUE":
  print(5)
if S == "WED":
  print(4)
if S == "THU":
  print(3)
if S == "FRI":
  print(2)
if S == "SAT":
  print(1)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;

int main() {
	int N, X; cin >> N >> X;
	int v = 0;
	int ans = 1;
	rep(i, N) {
		int L; cin >> L;
		v += L;
		if (v <= X)++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    ll p[n];
    rep(i, n){
        cin >> p[i];
    }

    ll vmin = 1e9;
    ll ans = 0;

    rep(i, n){
        if(p[i] < vmin){
            vmin = p[i];
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1e9+7
#define inf 1e18
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}

/*--------Library Zone!--------*/

int n, t, ma, memo;
int a[100005];
set<int>st;
signed main() {
	cin >> n >> t;
	rep(i, n) {
		cin >> a[i];
		st.insert(a[i]);
	}
	rep(i, n - 1) {
		st.erase(a[i]);
		set<int>::reverse_iterator j = st.rbegin();
		if (*j - a[i] > ma) {
			ma = *j - a[i];
			memo = 1;
		}
		else if (ma == *j - a[i]) {
			memo++;
		}
	}
	cout << memo << endl;
	endre;
}


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

int main() {
    string a, b;
    cin >> a >> b;

    if (a.length() > b.length()) {
        cout << "GREATER" << endl;
        return 0;
    }

    if (a.length() < b.length()) {
        cout << "LESS" << endl;
        return 0;
    }

    int cmp = a.compare(b);
    string ans;
    if (cmp == 0) {
        ans = "EQUAL";
    } else if (cmp > 0) {
        ans = "GREATER";
    } else {
        ans = "LESS";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=5,M=1005,mo=1e9+7;

ll lj[N][N],ls[N][N],jz[N][N];

ll w,h,k;

char s[M][M],t[M][M];

inline ll ksm(ll o,ll t)
{
	ll y=1;
	for(;t;t>>=1,o=o*o%mo)
	if(t&1)y=y*o%mo;
	return y;
}

inline void fb()
{
	fo(i,1,3)
	fo(l,1,3){
		ls[i][l]=0;
		fo(j,1,3)ls[i][l]=ls[i][l]+jz[i][j]*jz[j][l];
	}
	fo(i,1,3)fo(l,1,3)jz[i][l]=ls[i][l]%mo;
}

inline void times()
{
	fo(i,1,3)
	fo(l,1,3){
		ls[i][l]=0;
		fo(j,1,3)ls[i][l]=ls[i][l]+lj[i][j]*jz[j][l];
	}
	fo(i,1,3)fo(l,1,3)lj[i][l]=ls[i][l]%mo;
}

int main()
{
	cin>>h>>w>>k;
	fo(i,1,h)scanf("%s",s[i]+1);
	int o1=0,o2=0;
	fo(i,1,h)if(s[i][1]=='#'&&s[i][w]=='#')o1=1;
	fo(i,1,w)if(s[1][i]=='#'&&s[h][i]=='#')o2=1;
	ll x=0;
	fo(i,1,h)fo(l,1,w)x+=(s[i][l]=='#');
	if(o1+o2==2)puts("1");
	else if(o1+o2==0){
		ll ans=ksm(x,k-1);
		cout<<ans<<endl;
	}else{
		if(o2==1){
			fo(i,1,h)fo(l,1,w)t[l][i]=s[i][l];
			swap(h,w);
			fo(i,1,h)fo(l,1,w)s[i][l]=t[i][l];
		}
		--k;
		ll a1=0,a2=0;
		fo(i,1,h)if(s[i][1]=='#'&&s[i][w]=='#'){
			++a2;
			int ok=1;
			fo(l,2,w-1)if(s[i][l]=='.')ok=0;
			a2-=ok; a1+=ok;
		}
		ll p=0;
		fo(i,1,h)fo(l,2,w)if(s[i][l]=='#'&&s[i][l-1]=='#')++p;
		ll ans=ksm(x,k);
		lj[1][1]=lj[2][2]=lj[3][3]=1;
		jz[1][1]=x;
		jz[2][1]=p;
		jz[3][1]=p;
		jz[2][2]=a1;
		jz[3][3]=a2+a1;
		for(;k;k>>=1,fb())
		if(k&1)times();
		ans=(ans-(lj[3][1])%mo+mo)%mo;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2176