akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint dp[100005][2];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	dp[0][0] = 1;
	rep(i,n){
        // a + b = 0
        {
            if(s[i] == '0'){
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            }
            else{
                dp[i+1][1] = dp[i][0] + dp[i][1];
            }
        }
        // a + b = 1
        {
            if(s[i] == '0'){
                dp[i+1][1] += dp[i][1] * 2;
            }
            else{
                dp[i+1][0] += dp[i][0] * 2;
                dp[i+1][1] += dp[i][1] * 2;
            }
        }
	}
    mint ans = dp[n][0].x + dp[n][1].x;
    cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>
int A[100000],A1[1000000],n,flag,cnt;
char C[100000],C1[1000000];
int Partition(int p,int r){
  int i,j,tmpn,x;
  char tmpc;
  x=A[r];
  i=p-1;
 
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
       i=i+1;
      tmpn=A[j];
      A[j]=A[i];
      A[i]=tmpn;
      tmpc=C[j];
      C[j]=C[i];
      C[i]=tmpc;
     }
   }
  tmpn=A[i+1];
  tmpc=C[i+1];
  A[i+1]=A[r];
  C[i+1]=C[r];
  A[r]=tmpn;
  C[r]=tmpc;
  return i+1;
}
void Quicksort(int p,int r){
  int q;
  if(p<r){
    q=Partition(p,r);
    Quicksort(p,q-1);
    Quicksort(q+1,r);
  }
}
 
void merge(int left,int mid,int right){
  int n1,n2,i,j,k;
  double *L,*R;
  char *L1,*R1;
  n1=mid-left;
  n2=right-mid;
  L=(double*)malloc((sizeof(double))*(n1+1));
  R=(double*)malloc((sizeof(double))*(n2+1));
  L1=(char*)malloc((sizeof(char))*(n1+1));
  R1=(char*)malloc((sizeof(char))*(n2+1));
  for(i=0;i<n1;i++){
    L[i]=A1[left+i];
    L1[i]=C1[left+i];
  }
   for(i=0;i<n2;i++){
    R[i]=A1[mid+i];
    R1[i]=C1[mid+i];
  }
  L[n1]=1.0/0.0;
  R[n2]=1.0/0.0;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A1[k]=L[i];
      C1[k]=L1[i];
      i++;
    }
    else {
      A1[k]=R[j];
      C1[k]=R1[j];
      j++;
    }
   }   
  free(L);
  free(R); 
}
void mergeSort(int left,int right){
  int mid;
    if(left+1<right){ mid=(left+right)/2;
    mergeSort(left,mid);
    mergeSort(mid,right);
    merge(left,mid,right);
  }
 }
int main(){
   int i,p=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&C[i],&A[i]);
    A1[i]=A[i];
    C1[i]=C[i];
  }
  mergeSort(0,n);
  Quicksort(0,n-1);
  for(i=0;i<n;i++){
    if(A1[i]==A[i] && C1[i]!=C[i]){
      flag=1;
      break;
    }
  }
  if(flag==0) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",C[i],A[i]);
  }
  return 0;
}

Measured memory_bytes: 11400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const ll INF = 1e17;
// https://atcoder.jp/contests/abc143/submissions/8034843

bool checkIndex(int M, int line, int index, vector<string> vec_A, vector<string> vec_B)
{
    //cout << line << "," << M << endl;
    for (int i =1; i < M; i++)
    {
      //cout <<  vec_A[line+i] << "\n" << vec_B[i] << "\n" << endl;
      auto hoge = vec_A[line+i].find(vec_B[i], index);
      //cout << index << "," << hoge << endl;
        if (vec_A[line+i].find(vec_B[i], index) != index)
        {
            return false;
        }
    }
    return true;
}

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

    vector<string> vec_A;
    vector<string> vec_B;
    vec_A.resize(N);
    vec_B.resize(M);
    for (int i=0; i < N; i++) cin >> vec_A.at(i);
    for (int i=0; i < M; i++) cin >> vec_B.at(i);

    // resolve
    for (int i=0; i < N-M+1; i++)
    {
        auto start=0;
        auto index = vec_A[i].find(vec_B[0], start);
        while(index != string::npos)
        {
            if (checkIndex(M, i, index, vec_A, vec_B))
            {
                cout << "Yes" << endl;
                return 0;
            }
            start=index+1;
            index = vec_A[i].find(vec_B[0], start);
          //cout << "index:" << index << endl;
        }
    }
  
    cout << "No" << endl;

    return 0;
}


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

int main(){
	long long n,x,m;
	cin >> n >> x >> m;
	vector<long long> ar;
	set<long long> st;
	ar.push_back(x);
	st.insert(x);
	long long nx = (x*x)%m;
	while(!st.count(nx)){
		ar.push_back(nx);
		st.insert(nx);
		nx = (nx*nx)%m;
	}
	long long l;
	for(l=0;l<ar.size();l++){
		if(ar[l] == nx){
			break;
		}
	}
	long long ans = 0;
	for(int i=0;i<min(n,l);i++){
		ans += ar[i];
	}
	n -= min(n,l);
	long long sum = 0;
	int left = n%(ar.size()-l);
	for(int i=0;i<(ar.size()-l);i++){
		if(i < left){
			ans += ar[i+l];
		}
		sum += ar[i+l];
	}
	ans += (n/(ar.size()-l))*sum;
	cout << ans << '\n';
}

Measured memory_bytes: 5928
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    ll distance=llabs(a-b);
    ll speed=v-w;
    if(distance<=(speed*t)){
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    }


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

bool operator< (const pair<int,int> &p1, const pair<int,int> &p2){
    return p1.first < p2.second;
};
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
int main(){
    std::priority_queue<
      int,                // 要素の型はint
      std::vector<int>,   // 内部コンテナはstd::vector (デフォルトのまま)
      std::greater<int>   // 昇順 (デフォルトはstd::less<T>)
    > pq;
    priority_queue<
    pair<int,int>
    > Q;
    long long ans=0;
    int n,m,b,c;
    cin>>n>>m;
    REP(i,n){
        int a;
        cin>>a;
        pq.push(a);
    }
    REP(i,m){
        cin>>b>>c;
        Q.push(make_pair(c,b));
    }
    pair<int,int> p;
    while(Q.size()>0){
        p=Q.top();
        Q.pop();
        while(p.second>0 && pq.top()<p.first){
            p.second--;
            pq.pop();
            pq.push(p.first);
        }
    }
    REP(i,n){
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1784
n=gets.to_i
xi=gets.split.map(&:to_f)
yi=gets.split.map(&:to_f)
d1=0.0
d2=0.0
d3=0.0
d4=[]
n.times do |i|
  d1=d1+(xi[i]-yi[i]).abs
  d2=d2+((xi[i]-yi[i]).abs)**2
  d3=d3+((xi[i]-yi[i]).abs)**3
  d4<<(xi[i]-yi[i]).abs
end
puts sprintf("%.6f",d1)
puts sprintf("%.6f",d2**(1/2.0))
puts sprintf("%.6f",d3**(1/3.0))
puts sprintf("%.6f",d4.max)


Measured memory_bytes: 8924
k = int(input())
s = input()
n = len(s)
MOD = 10**9+7
ans = 0

def comb(n, r, MOD):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % MOD

N = 2 * (10 ** 6) + 100
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

for i in range(k+1):
    b = pow(26, k-i, MOD)
    b *= pow(25, i, MOD)
    b *= comb(i+n-1, n-1, MOD)
    ans += (b % MOD)
    
print(ans%MOD)

Measured memory_bytes: 227172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

std::vector<int> z_algorithm(const std::string& S) {
    const int N = S.size();
    std::vector<int> res(N);

    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i + j < N && S[j] == S[i + j]) ++j;
        res[i] = j;

        if (j == 0) {
            ++i;
            continue;
        }

        int k = 1;
        while (i + k < N && k + res[k] < j) {
            res[i + k] = res[k];
            ++k;
        }
        
        i += k;
        j -= k;
    }

    return res;
}

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        std::string T = S.substr(i);
        auto v = z_algorithm(T);

        for (int j = 0; j < v.size(); j++) {
            ans = std::max(ans, std::min(j, v[j]));
        }
    }
    std::cout << ans << "\n";
}

Measured memory_bytes: 256
D = int(input())
c = [0] + list(map(int, input().split()))
s = [0] + [[0] + list(map(int, input().split())) for _ in range(D)]
last = [0]*27

SL = 0

for d in range(1, D+1):
    t = int(input())
    last[t] = d
    SL += s[d][t]
    for i in range(1, 27):
        SL -= c[i] * (d - last[i])
    
    print(SL)      

Measured memory_bytes: 9256
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;         
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        Arrays.sort(a);
        int q = input.nextInt();
        for (int i = 0; i < q; ++i) {
            int m = input.nextInt();            
            if (canSumTo(m, a, 0)) System.out.println("yes");
            else System.out.println("no");
        }
    }                
    
    static boolean canSumTo(int x, int[] a, int fromIndex) {
        if (x == 0) return true;        
        for (int i = fromIndex; i < a.length; ++i) {
            if (a[i] <= x) {
                boolean ok = canSumTo(x - a[i], a, i + 1);
                if (ok) return true;
            }
        }
        return false;
    }
}

Measured memory_bytes: 20128
/**
 *     author: qodjf
 *     created: 04.18.2020 12:03:50
 */
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;

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

ll mul(ll a, ll b) { return a * b % MOD; }

ll add(ll a, ll b) { return (a + b) % MOD; }

ll sub(ll a, ll b) { return (a - b + MOD) % MOD; }

ll my_pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1) r = mul(r, a);
    a = mul(a, a);
    b >>= 1;
  }
  return r;
}

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

  vector<int> x(K + 1);
  for (int i = 1; i <= K; i++) {
    x[i] = i;
  }
  for (int i = 1; i <= K; i++) {
    for (ll j = 2 * i; j <= K; j += i) {
      x[j] -= x[i];
    }
  }

  ll ans = 0;
  for (int i = 1; i <= K; i++) {
    ans = add(ans, mul(x[i], my_pow(K / i, N)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>

using namespace std;

#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9 + 7;




int main() {
	ll X;
	cin >> X;
	vector<ll> kouho;
	ll A = 0;
	ll B = 0;
	bool frag = false;
	for (int i = 1; i < sqrt(X) + 1; i++) {
		if (X % i == 0) {
			kouho.push_back(i);
		}
	}
	for (ll x : kouho) {
		for (ll i =  0 - x/2  ; i < 130; i++) {
			ll y = pow(i + x, 5) - pow(i, 5);
			if (y == X) { 
				B = i; 
				A = i + x;
				frag = true;
			}
			else if (y > X) break;
		}
		if (frag) break;
	}
	if (!frag) {
		for (ll x : kouho) {
			for (ll i = 0 - x / 2; i >= (-1)*x; i--) {
				ll y = pow(i + x, 5) - pow(i, 5);
				if (y == X) {
					B = i;
					A = i + x;
					frag = true;
				}
				else if (y > X) break;
			}
			if (frag) break;
		}
	}
	cout << A << " " << B << endl;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rn0(const i64 e) noexcept { return ran(e); }
constexpr ran rn0(const i64 b, const i64 e) noexcept { return ran(b, e); }
constexpr ran rn1(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rn1(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 n,m;
  cin >> n >> m;
  vector<i64> led(m);
  for(int i = 0;i < m;i++) {
    int k;
    cin >> k;
    for(int j = 0;j < k;j++) {
      int s;
      cin >> s;
      s--;
      led[i] |= (1 << s);
    }
  }
  vector<i64> p(m);
  i64 ans = 0;
  for(int i: ran(m)) cin >> p[i];
  for(int s = 0;s < (1 << n);s++) {
    bool OK = 1;
    for(int i: ran(m)) {
      if(__builtin_popcount(led[i] & s) % 2 == p[i]) {}
      else OK = 0;
    }
    if(OK) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
	static int[][] list;
	public static void main(String[] args) {
		
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		while(true) {
			int n = sc.nextInt();
			if(n == -1) break;
			out.println(Integer.toString(n, 4));
		}
		out.flush();
	}
	static void solv(int a, int b, boolean[] c) {
		list[a][b]++;
		if(a == 9) return;
		if(b > 1000) return;
		
		for(int i = 0; i < 101; i++) {
			if(a == 8) {
				if(!c[i]) {
					list[a+1][b+i]++;
				}
			}
			
			else if(!c[i]) {
				c[i] = true;
				solv(a+1,b+i,c);
				c[i] = false;
			}
		}
	}
}
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
    

}

Measured memory_bytes: 17016
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int S=0,T=1;
struct bian
{
	int nxt,to,f;
}bi[1000010];
int n,head[200020],num=1,cur[200020],dep[200020],flow,match[200020],f[200020];
vector<int>E[100010];
inline void add(int from,int to,int f){bi[++num]=bian{head[from],to,f};head[from]=num;}
inline void ADD(int from,int to,int f){add(from,to,f),add(to,from,0);}
int q[200020],h,t;
bool bfs()
{
	memset(dep,0,sizeof(dep));
	memcpy(cur,head,sizeof(cur));
	h=0,t=1;q[t]=S;dep[S]=1;
	int x,y;
	while(h<t)
	{
		x=q[++h];
		for(int i=head[x];i;i=bi[i].nxt)
			if(bi[i].f)
			{
				y=bi[i].to;
				if(!dep[y])dep[y]=dep[x]+1,q[++t]=y;
			}
	}
	return dep[T]!=0;
}
int dfs(int v,int last)
{
//	printf("%d %d\n",v,last);
	if(v==T)
	{
		flow+=last;
		return last;
	}
	int now=0;
	for(int &i=cur[v],u;i;i=bi[i].nxt)
		if(bi[i].f)
		{
			u=bi[i].to;
			if(dep[u]!=dep[v]+1)continue;
			int dmin=dfs(u,min(last,bi[i].f));
			bi[i].f-=dmin,bi[i^1].f+=dmin;
			last-=dmin,now+=dmin;
			if(!last)return now;
		}
	return now;
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i)ADD(S,i,1);
	for(int i=1;i<n;++i)ADD(i+n,T,1);
	int x;
	for(int i=1;i<=n-1;++i)
	{
		int cnt;
		scanf("%d",&cnt);
		for(int j=1;j<=cnt;++j)
		{
			scanf("%d",&x);
			E[x].push_back(i);
			if(x>1)ADD(x,i+n,1);
		}
	}
//	for(int i=0;i<=2*n;++i)
//		for(int j=head[i];j;j=bi[j].nxt)
//			printf("%d %d %d\n",i,bi[j].to,bi[j].f);
	while(bfs())
		while(dfs(S,0x3f3f3f3f));
//	printf("%d\n",flow);
	if(flow!=n-1){printf("-1");return 0;}
	for(int i=1;i<=n-1;++i)
		for(int j=head[i+n];j;j=bi[j].nxt)
			if(bi[j].to<=n&&bi[j].f){match[i]=bi[j].to;break;}
//	for(int i=1;i<=n-1;++i)printf("%d ",match[i]);printf("\n");
	memset(dep,0,sizeof(dep));
	h=0,t=1;q[t]=1;
	while(h<t)
	{
		x=q[++h];
		for(auto y:E[x])
			if(!dep[y])
			{
				dep[y]=1;
				q[++t]=match[y];
				f[match[y]]=x;
			}
	}
	if(t!=n){printf("-1");return 0;}
	for(int i=1;i<=n-1;++i)printf("%d %d\n",match[i],f[match[i]]);
	return 0;
}


Measured memory_bytes: 25856
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

// #define int long long

/* cpp template {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  for (int n, k; cin >> n >> k, n || k; ){
    vi sum(n + 1, 0);
    cin >> sum[1];
    REPS(i, 2, n + 1) cin >> sum[i], sum[i] += sum[i - 1];

    int ans = -INF;
    for (int i = k; i <= n; i++){
      ans = max(ans, sum[i] - sum[i - k]);
    }
    print(ans);
  }

  return (0);
}

Measured memory_bytes: 1532
import math

a,b,x = map(int, input().split())
box = a*a*b
ans = 0
if x>=box/2:
    z = a*a
    y = 2*x
    y = y/z
    y -= b
    ans = math.degrees(math.atan2(b-y,a))
else:
    z = a*b
    v = 2*x
    v = v/z
    y = a-v
    ans = math.degrees(math.atan2(b, a-y))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf (ll)(1e18)
#define mod 1000000007




int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        int n;
        cin>>n;

        if( n>=30 )
            cout<<"Yes";
        else
            cout<<"No";
    }

    return 0;
}












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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    vector<P> a(n);
    rep(i,0,n){
        int p; scanf("%d",&p);
        a[i]=P{p,i};
    }
    sort(ALL(a));
    rep(i,0,n)printf("%d\n",a[i].second+1);
    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int a,b,c,x,d;
 
int main()
{
    cin>>a>>b>>c>>x;
    for(int i = 0;i <= a;i ++)
    {
        for(int j = 0;j <= b;j ++)
        {
            for(int k = 0;k <= c;k ++)
                if(i * 500 + j * 100 + k * 50 == x)d ++;
        }
    }
    cout<<d<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
char data[1300];
void proc(){
  char*p=data;
  int t='a'-'A';
  while(*p!=0){
    if('a'<=*p&&*p<='z')*p-=t;
    else if('A'<=*p&&*p<='Z')*p+=t;
    ++p;
  }
  printf("%s\n",data);
}
int main(){
  gets(data);
  proc();
  return 0;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n, a;
      cin >> n >> a;
      int s;
      s = n / 500;
      if(n - s * 500 <= a){
        cout << "Yes" << endl;
      }else {
        cout << "No" << endl;
      }
    }  

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7


import collections

def first_search(graph, root, actions, ans):
    seen, queue = set([root]), collections.deque([[root, 0],])
    while queue:
        vertex, value = queue.pop()  # popleft: 幅優先探索  /  pop: 深さ優先探索
        ans[vertex] = value + actions[vertex]
        for node in graph[vertex]:
            if node not in seen:
                seen.add(node)
                queue.append([node, ans[vertex]])


def main(): 
    N, Q = LI()
    from collections import defaultdict
    edges = defaultdict(list)
    for _ in range(N-1):
        a, b = LI()
        edges[a].append(b)
        edges[b].append(a)
    actions = defaultdict(int)
    for _ in range(Q):
        p, x = LI()
        actions[p] += x

    ans = [0 for _ in range(N+1)]

    first_search(edges, 1, actions, ans)

    print(' '.join([str(i) for i in ans[1:]]))




main()

Measured memory_bytes: 136084
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] numberBox = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			numberBox[i] = sc.nextInt();
			sum = sum + numberBox[i];
		}
		sc.close();
		int c = 0;
		for (int j = 0; j < N; j++) {
			if (c < numberBox[j]) {
				c = numberBox[j];
			}
		}
		String answer = "No";
		if (sum > (2 * c)) {
			answer = "Yes";
		}
		System.out.println(answer);
	}
}


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

const int MOD = 1000000007;
template<typename T1, typename T2> inline void add(T1 &a, const T2 &b) { a = (a + b) % MOD; }

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(4));
    dp[0][0] = 1;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < 4; ++j) {
            if(S[i] == '?') add(dp[i + 1][j], dp[i][j] * 3);
            else add(dp[i + 1][j], dp[i][j]);
        }
        for(int j = 0; j < 3; ++j) {
            if(S[i] == '?' or S[i] == 'A' + j) add(dp[i + 1][j + 1], dp[i][j]);
        }
    }
    cout << dp[N][3] << '\n';
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
 
using namespace std;
 
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
 
 
#define fr(i, n) for(int i=0; i<n;i++)
#define fr1(i, n) for(int i=1; i<=n;i++) 
 
#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
 
void file(){
	readf("in.txt");
    writef("out.txt");
}
 
template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
typedef long long ll;
typedef pair<int,int> pii;

int n, dp[100005][3], ara[100005][3];
 
int main()
{
	//file();
 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
	

	cin>>n;

	int a, b, c;

	fr(i,n)
		fr(j,3)
			cin>>ara[i][j];

	dp[0][0] = ara[0][0];
	dp[0][1] = ara[0][1];
	dp[0][2] = ara[0][2];

	fr1(i,n){

		if(i != n)
			fr(j,3){
				dp[i][j] = ara[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
			}
	}

	int ans = max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]);

	cout<<ans<<nl;


    return 0;
 
}

Measured memory_bytes: 2560
//
//  main.cpp
//  Sum of Interior Angles
//
//  Created by Hashizo on 2019/06/01.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    
    cout << 180 * (n-2) << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
    ll sum=0;
ll x[300000];
int main(){
int n;
cin>>n;

for(int i=0;i<n;i++)
    scanf("%lld",&x[i]);
    if(x[0]>0)
    {
        cout<<-1;
        return 0;
    }
for(int i=0;i<n-1;i++)
{
    if(x[i+1]>x[i]+1)
    {
        cout<<-1;
        return 0;
    }

}
for(int i=0;i<n-1;i++)
{
    if(x[i+1]<=x[i]&&x[i+1]>0)
    {
        sum+=x[i+1]-1;
    }

}

for(int i=0;i<n;i++)
{
    if(x[i]>0)
    {
        sum++;

    }
}cout<<sum;
return 0;
}


Measured memory_bytes: 1792
let id x = x

type v = T | F

let rec slv = function
	| 0 -> T
	| n -> if (Scanf.scanf "%c" id) = 'Y' then F else slv (n-1)

let () =
	let n = Scanf.scanf "%d\n" id in
	match slv n with
	| F -> print_string "Four"
	| T -> print_string "Three"


Measured memory_bytes: 384
N,A,B = map(int, raw_input().split())

if (N+B-1)/B <= A <= N+1-B:
  L = [A] + [1]*(B-1)
  n = N - A - (B-1)
  for i in range(1, B):
    L[i] += min(n, A-1)
    n -= min(n, A-1)
  T = [[] for _ in range(B)]
  p = 0
  for i in range(1,N+1):
    while len(T[p]) >= L[p]:
      p += 1
    T[p] += [i]
  for t in T[::-1]:
    for x in t:
      print x,
  print
else:
  print -1


"""
from itertools import *

# http://wakabame.hatenablog.com/entry/2017/08/27/210846
def LIS(L):
  N = len(L)
  res=0
  dp=[1]*N
  for i in range(N):
    for j in range(i):
      if L[j]<L[i]:
        dp[i]=max(dp[i],dp[j]+1)
    res=max(res,dp[i])
  return res

n = 3
# ..o
# .o.
# o..

n = 4
# ...o
# .oo.
# .o..
# o...

n = 5
# ....o
# ..oo.
# .oo..
# .o...
# o....

n = 6
# .....o
# ..ooo.
# .ooo..
# .oo...
# .o....
# o.....

n = 7
# ......o
# ...ooo.
# ..ooo..
# .ooo...
# .oo....
# .o.....
# o......

n = 8
# .......o
# ...oooo.
# ..oooo..
# .oooo...
# .ooo....
# .oo.....
# .o......
# o.......

n = 9
# ........o
# ....oooo.
# ..ooooo..
# ..oooo...
# .oooo....
# .ooo.....
# .oo......
# .o.......
# o........

n = 10
# .........o
# ....ooooo.
# ...ooooo..
# ..ooooo...
# .ooooo....
# .oooo.....
# .ooo......
# .oo.......
# .o........
# o.........


T = [["."]*(n+1) for _ in range(n+1)]

for x in permutations(range(1,n+1)):
  #print x, LIS(x), LIS(x[::-1])
  T[LIS(x)][LIS(x[::-1])] = "o"

for t in T[1:]:
  print "".join(t[1:])

"""


Measured memory_bytes: 39656
n=int(input())
q=10**9+7

x=[-1]*(n+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=n:
    if x[i]==-1:
        x[i]=i
        prime.append(i)
    for j in prime:
        if i*j>n or j>x[i]:break
        x[j*i]=j
    i+=1

d=[0]*(n+1)
for i in range(1,n+1):
    while x[i]!=1:
        p=x[i]
        d[p]+=1
        i=i//p

ans=1

for i in range(n+1):
    ans=ans*(d[i]+1)%q
print(ans%q)




Measured memory_bytes: 64292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
   ll n;
   cin>>n;
   ll cnt=0;
   ll k=1;
       while((ll)pow(5,k)<=n){
           ll tmp=(ll)n/(ll)pow(5,k);
               cnt+=(tmp)/2;
               k++;
       }
       if(n%2==1){
           cnt=0;
       }
    cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()
MOD = 10**9+7
s = []
if N > 1 and S1[0] == S1[1]:
    ans = 6
    i = 2
    before = 0
else:
    ans = 3
    i = 1
    before = 1
while(i<N):
    if i < N-1 and S1[i] == S1[i+1]:
        ans *= 2 if before else 3
        i += 2
        before = 0
    else:
        ans *= 2 if before else 1
        i += 1
        before = 1
        
    ans %= MOD
print(ans)
        

Measured memory_bytes: 3188
s=input()
if len(s)==2:
  if s[0]==s[1]:
    print(1,2)
  else:
    print(-1,-1)
else:
  for i in range(len(s)-2):
    if len(set((s[i],s[i+1],s[i+2])))!=3:
      print(i+1,i+3)
      break
  else:
    print("-1 -1")

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n1,c,p,n, r,y[50],tmp[50];
	while (cin >> n >> r&&n&&r) {
		n1 = n;
		for (int i = 0; i < n; i++) {
			y[i] = n1--;
			//cout << y[i] << ' ';
		}//cout << endl;
		
		for (int j = 0; j < r; j++) {
			cin >> p >> c;
			for (int k = 0; k < p-1; k++) {
				tmp[k] = y[k];
			}
			for (int i = 0; i < c; i++) {
				y[i] = y[p-1 + i];
			}
			for (int l = 0; l < p-1; l++) {
				y[c + l] = tmp[l];
			}
			//for (int i = 0; i < n; i++)cout << ' ' << y[i]; cout << endl;
		}
		cout << y[0] << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
//#include <math.h>
signed main(void) 
{
    ll h, n, r;
    
    r = 0;
    ll sum = 0;
    cin >>h >>n;
    vll a(n);
    
    rep (i, n) {
        cin >>a[i];
        sum += a[i];
    }
    
    if (sum >= h) {
        cout <<"Yes";
        return 0;
    }
    cout <<"No";
    return 0;
}

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}


int main() {
  long a,b;
  cin>>a>>b;
  cout<<LCM(a,b)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;

ll heights[100005], sums[100005];

int main() {
    ll n, k;
    cin >> n >> k;
    for (ll i = 1; i <= n; ++i) {
        cin >> heights[i];
        if (i > 1) {
            ll minSum = -1;
            for (ll j = i-1; j >= i-k && j; --j)
                if (abs(heights[j] - heights[i]) + sums[j] < minSum || minSum == -1)
                    minSum = abs(heights[j] - heights[i]) + sums[j];
            sums[i] = minSum;
        }
    }
    cout << sums[n];
}


Measured memory_bytes: 5092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int cnt[n][26]={};
	for(int i=0;i<n;i++){
		string s;cin>>s;
		rep(j,s.size()) cnt[i][s[j]-'a']++;
	}
/*	rep(i,n){
		rep(j,26) cout<<cnt[i][j]<<" ";
		cout<<"\n";
	}*/
	for(int i=0;i<26;i++){
		int sum=inf;
		for(int j=0;j<n;j++){
			sum=min(sum,cnt[j][i]);
		}
		
		if(sum!=inf) rep(k,sum) cout<<char('a'+i);
	}
	cout<<"\n";
	
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
	}
	sort(A.begin(), A.end());

	for (int i = 0; i + 1 < N; ++i) {
		if (A[i] == A[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

using namespace std;

long long N, A[305][305], B[305][305];

int main() {
    scanf("%lld", &N);
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= N; ++j)
            scanf("%lld", &A[i][j]);
    memcpy(B, A, sizeof A);
    for (int k = 1; k <= N; ++k)
        for (int i = 1; i <= N; ++i)
            for (int j = 1; j <= N; ++j)
                if (i != k && j != k) {
                    if (A[i][k] + A[k][j] < A[i][j]) {
                        puts("-1"); return 0;
                    }
                    if (A[i][k] + A[k][j] == A[i][j]) {
                        B[i][j] = B[j][i] = 0;
                    }
                }
    long long sum = 0;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= N; ++j)
            sum += B[i][j];
    printf("%lld\n", sum >> 1);
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll T[3][4005][4005];
ll M[3][4005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    memset(T, 0, sizeof(T));
    memset(M, 0, sizeof(M));
    REP(i, N) {
        REP(j, i) {
            if (S[i] == S[j])
                continue;

            ll m = -1;
            if (S[i] == 'R') {
                if (S[j] == 'G')
                    m = 2;
                else if (S[j] == 'B')
                    m = 1;
            }
            else if (S[i] == 'G') {
                if (S[j] == 'R')
                    m = 2;
                else if (S[j] == 'B')
                    m = 0;
            }
            else if (S[i] == 'B') {
                if (S[j] == 'R')
                    m = 1;
                else if (S[j] == 'G')
                    m = 0;
            }

            T[m][i][i - j]++;
            M[m][i]++;
        }
    }
    ll ans = 0;
    REP(i, N) {
        REP(j, 3) {
            M[j][i + 1] += M[j][i];
        }
    }

    for (ll i = 2; i < N; ++i) {
        ll m = 2;
        if (S[i] == 'R')
            m = 0;
        else if (S[i] == 'G')
            m = 1;
        ans += M[m][i - 1];
        REP(j, i) {
            ll n = i - j;
            if (j - n < 0)
                continue;
            if (S[i] != S[j] && S[j] != S[j - n] && S[i] != S[j - n])
                ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 379688
#include "bits/stdc++.h"
using namespace std;

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

	bool flag = true;
	int cnt = 0;
	
	if(s[0] != 'A') flag = false;
	for(int i=2;i<s.size()-1;i++) {
		if(s[i] == 'C') {
			cnt++;
		}
	}
	if(cnt != 1) flag = false;

	cnt = 0;
	
	for(int i=0;i<s.size();i++) {
		if(isupper(s[i])) cnt++;
	}

	if(cnt != 2) flag = false;

	if(flag) cout << "AC" << endl;
	else cout << "WA" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int n, x, a;
    ll ans = 0;
    cin >> n >> x;
    vector<int> A;
    for (int i = 0; i < n; i++) {
        cin >> a;
        A.push_back(a);
    }
    if(A[0] > x){
        ans += A[0] - x;
        A[0] = x;
    }
    for (int i = 0; i < n-1; i++) {
        int sum2 = A[i] + A[i+1];
        if(sum2 <= x) continue;
        A[i+1] -= sum2 - x;
        ans += sum2 - x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::VecDeque;

fn bfs(map: Vec<Vec<char>>, target: (usize, usize)) -> i64 {
    let mut q: VecDeque<(usize, usize, usize)> = VecDeque::new();
    q.push_back((0, 0, 1));
    let mut ans = -1;
    let h = map.len();
    let w = map[0].len();
    let mut done: Vec<Vec<bool>> = vec![vec![false; w]; h];

    while !q.is_empty() {
        let cn = q.pop_front().unwrap();
        if done[cn.0][cn.1] {
            continue;
        }
        if cn.0 == target.0 && cn.1 == target.1 {
            ans = cn.2 as i64;
            break;
        }
        done[cn.0][cn.1] = true;

        if cn.0 != 0 && map[cn.0 - 1][cn.1] != '#' && !done[cn.0 - 1][cn.1] {
            q.push_back((cn.0 - 1, cn.1, cn.2 + 1));
        }
        if cn.0 != h - 1 && map[cn.0 + 1][cn.1] != '#' && !done[cn.0 + 1][cn.1] {
            q.push_back((cn.0 + 1, cn.1, cn.2 + 1));
        }
        if cn.1 != 0 && map[cn.0][cn.1 - 1] != '#' && !done[cn.0][cn.1 - 1] {
            q.push_back((cn.0, cn.1 - 1, cn.2 + 1));
        }
        if cn.1 != w - 1 && map[cn.0][cn.1 + 1] != '#' && !done[cn.0][cn.1 + 1] {
            q.push_back((cn.0, cn.1 + 1, cn.2 + 1));
        }
    }
    ans
}

fn main() {
    let h: usize = read();
    let w: usize = read();

    let mut map: Vec<Vec<char>> = vec![];
    let mut b = 0;

    for _ in 0..h {
        let row: Vec<char> = read::<String>().chars().collect();
        b += row.iter().filter(|&x| *x == '#').count();
        map.push(row);
    }
    let ans = bfs(map, (h - 1, w - 1));

    if ans == -1 {
        println!("{}", ans);
        return;
    }

    println!("{}", ((h * w) - b) as i64 - ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#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 LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#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
#define si short 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;}
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

    int a,b;
    cin>>a>>b;

    if(a < b) cout<<0;
    else cout<<10;

    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

mx = sum(p[:K])
cur = mx
for i in range(N-K):
  cur = cur-p[i]+p[i+K]
  mx = max(mx, cur)
  
ans = (mx+K) / 2
print(ans)

Measured memory_bytes: 32052
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <list>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <ostream>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <iomanip>

#define N 100005
#define INF (1 << 30)
#define NIL -1
using namespace std;
struct Node { int parent, child, sibling; } T[N];
int depth[N];
void setDepth(int root, int d)
{
	depth[root] = d;
	if (T[root].child != NIL)
		setDepth(T[root].child, d + 1);
	if (T[root].sibling != NIL)
		setDepth(T[root].sibling, d);
}
const char *str[3] = { "root", "leaf", "internal node" };
void print(int id)
{
	int status = 0;
	if (T[id].parent == NIL)
		status = 0;
	else if (T[id].child == NIL)
		status = 1;
	else
		status = 2;
	printf("node %d: parent = %d, depth = %d, %s, [", id, T[id].parent, depth[id], str[status]);
	for (int i = 0, child = T[id].child; child != NIL; ++i, child = T[child].sibling)
	{
		if (i)
			printf(", ");
		printf("%d", child);
	}
	printf("]\n");
}


int main()
{
	int n, id, k, child;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		T[i].parent = T[i].child = T[i].sibling = NIL;
	}
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &id, &k);
		for (int j = 0, pre = 0; j < k; ++j)
		{
			scanf("%d", &child);
			if (j == 0)
				T[id].child = child;
			else
				T[pre].sibling = child;
			pre = child;
			T[child].parent = id;
		}
	}
	int root = NIL;
	for (int i = 0; i < n; ++i)
	{
		if (T[i].parent == NIL)
		{
			root = i;
			break;
		}
	}
	setDepth(root, 0);
	for (int i = 0; i < n; ++i)
		print(i);
	return 0;
}

Measured memory_bytes: 4684
from itertools import accumulate
def BC132_F():
    n, k = list(map(int, input().split(' ')))
    mod = 10**9 + 7
    sqt = int(n**0.5)
    cnt = [n // i - n // (i + 1) for i in range(1, n // sqt)] + [1] * sqt
    x = cnt
    for _ in range(k):
        x = [(i * j) % mod for i, j in zip(accumulate(reversed(x)), cnt)]
    return x[-1]
 
 
print(BC132_F())

Measured memory_bytes: 80764
import java.util.HashMap;
import java.util.Scanner;

// https://atcoder.jp/contests/abc065/tasks/abc065_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i=0;i<n;i++) {
			array[i] = sc.nextInt();
		}
		sc.close();

		int tmp = 1;
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();



		int ans = 0;
		while(true) {


			if(map.containsKey(tmp)){
				System.out.println(-1);
				return;
			}else {
				map.put(tmp, array[tmp-1]);
			}
			if(tmp==2) {
				System.out.println(ans);
				return;
			}
			tmp = array[tmp-1];
			ans = ans + 1;
		}

	}
}


Measured memory_bytes: 52480
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            String [] str = sc.next().split("");
            String [] str2 = sc.next().split("");
            for(int i = 0; i < N; i++){
              System.out.print(str[i]);
              System.out.print(str2[i]);
            }
            }
}

Measured memory_bytes: 23380