akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));
    rep(i, 0, H) {
        rep(j, 0, W) cin >> S[i][j];
    }
    rep(i, 0, (W+2)) cout << "#";
    cout << endl;
    rep(i, 0, H) {
        cout << "#";
        rep(j, 0, W) cout << S[i][j];
        cout << "#";
        cout << endl;
    }
    rep(i, 0, (W+2)) cout << "#";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 
  string s;
 
  string get(int pos)
  {
     string res = "";
      for (int i = 0; i <= pos; ++i) res += s[i];
     int len = s.size();
     for (int i = len - (7 - pos - 1); i < len; ++i) res += s[i];
     return res;
 }
 
 bool work()
 {
     for (int i = 0; i < 7; ++i)
     {
        string tmp = get(i);
         if (tmp == "keyence") return 1;
     }
     return 0;
 }
 
 int main()
 {
     if (cin >> s) puts(work() ? "YES" : "NO");
     return 0;
 }

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

map<int,int> brd;
int n,m,a,b;

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<n; i++){
			cin >> m >> a >> b;
			brd[a] += m;
			brd[b] -= m;
		}
		map<int, int>::iterator it = brd.begin();
		int ans = 0;
		bool flag = true;
		while(it != brd.end()){
			ans += (*it).second;
			if(ans > 150){
				cout << "NG\n";
				flag = false;
				break;
			}
			++it;
		}
		if(flag)
			cout << "OK\n";
		brd.clear();
	}
}

Measured memory_bytes: 0
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])  


Measured memory_bytes: 52448
# coding: utf-8
# Your code here!

N = int(input())
D, X = map(int, input().split())
arr = [int(input()) for i in range(N)]
ctr = 0

for i in range(N):
    if D % arr[i] == 0:
        ctr += D // arr[i]
    else:
        ctr += D // arr[i] + 1
print(ctr + X)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main()
{
    long int res = 0;
    int n,a[100002],b[100001],last;
    int i;
    
    scanf("%d",&n);
    
    for(i=0;i<n+1;i++)
    {
        scanf("%d",&a[i]);
    }
    
    a[i] = 0;
    
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    
    last = 0;
    for(i=n;i>0;i--)
    {
//printf(":a[%d]=%d,last=%d,res = %d:\n",i,a[i],last,res);
        
        if(a[i] <= last)
        {
            res = res + a[i];
            last = b[i-1];
        }
        else
        {
            a[i] = a[i] - last;
            res = res + last;
            if(b[i-1] <= a[i])
            {
                res = res + b[i-1];
                last = 0;
            }
            else
            {
                res = res + a[i];
                last = b[i-1] - a[i];
            }
        }
    }

//printf(":res = %d:",res);
//printf("\n a[%d]=%d,last=%d\n",i,a[i],last);
    if(a[i] <= last)
    {
        res = res + a[i];
    }
    else
    {
        res = res + last;
    }
    
    printf("%ld",res);
    
    return 0;
}


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

int main(){
  string S;
  int count=0;
  cin >>S;
  for(int i=0;i<3;i++){
    if(S.at(i)=='1'){
      count++;
    }
  }
  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    map< int, int > mp;
    for( int i = 0; i < n; ++i ) {
        int a;
        cin >> a;
        ++mp[a];

    }

    int m;
    cin >> m;
    bool flg = true;
    for( int i = 0; i < m; ++i ) {
        int a;
        cin >> a;
        --mp[a];
        if( mp[a] < 0 ) {
            flg = false;

        }
    }

    if( flg ) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}



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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int A = cin.nextInt();
        int B = cin.nextInt();

        Console.WriteLine(Math.Max(A + B, Math.Max(A - B, A * B)));
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#define N 10000000
int heap[N];
int last;
unsigned seed=0x12121204;
void push(int n){
    int i=last,j=(i-1)>>1;
    while(i>0&&heap[j]<n){
        heap[i]=heap[j];
        i=j;
        j=(i-1)>>1;
    }
    heap[i]=n;
    last++;
}
int pop(){
    last--;
    int a=heap[0];
    int t=heap[last],i=0,j;
    j=1+(heap[1]<heap[2]);
    while(j<last&&t<heap[j]){
        heap[i]=heap[j];
        i=j;
        if(j*2+1<last&&heap[j*2+1]<heap[j*2+2]){
            j=j*2+2;
        }else{
            j=j*2+1;
        }
    }
    heap[i]=t;
    return a;
}
int main(void){
    int n,a[200000];
    int i,t;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        push(a[i]);
    }
    for(i=0;i<n;i++){
        if(a[i]!=heap[0]){
            printf("%d\n",heap[0]);
        }else{
            t=pop();
            printf("%d\n",heap[0]);
            push(t);
        }
    }
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define rrep(i,n,l) for(int i=n-1;i>=l;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a);
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string changes(int k){
	stringstream ss;
	string s;
	ss<<k;
	ss>>s;
	return s;
}

int changei(string s){
	stringstream ss;
	int k;
	ss<<s;
	ss>>k;
	return k;
}

int main(){
	int n,l;
	while(1){
		cin>>n>>l;
		if(n+l==0) break;
		int d[100]={0};
		bool f=false;
		d[0]=n;
		rep(i,1,21){
			string s=changes(n);
			while(s.size()<l){
				s+="0";
			}
			string t1=s;
			sort(all(t1));
			string t2=t1;
			reverse(all(t2));
			int MAX,MIN;
			MAX=changei(t2);
			MIN=changei(t1);
			n=MAX-MIN;
			d[i]=n;
			rep(j,0,i){
				if(d[i]==d[j]){
					cout<<j<<" "<<d[i]<<" "<<i-j<<endl;
					f=true; break;
				}
			}
			if(f) break;
		}
	}
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
long long tot[2105],z[200010];
int main()
{
	string s;
	int i;
	long long x=1,ans;
	cin>>s;
	for(i=s.size()-1;i>=0;i--)
	{
		z[i]=(z[i+1]+(s[i]-'0')*x)%2019;
		x=x*10%2019;
		tot[z[i]]++;
	}
	ans=tot[0];
	for(i=0;i<2019;i++)
		ans+=tot[i]*(tot[i]-1)/2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second

int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
vector<vec> ans(1e6 + 5);
//vec val1;
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    swap(a, b);
    swap(a, c);
    cout << a <<" "<< b<<" " << c;

}


Measured memory_bytes: 23680
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    let mut b: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    let mut c: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    a.sort();
    b.sort();
    c.sort();

    let mut ans: usize = 0;
    for i in 0..n {
        let bi = b[i];

        let mut ok: isize = -1;
        let mut ng: isize = n as isize;
        while (ok - ng).abs() > 1 {
            let mid = (ok + ng) / 2;
            if a[mid as usize] < bi {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        let ac = if ok >= 0 && ok < n as isize {
            ok as usize + 1
        } else {
            0
        };

        let mut ok: isize = n as isize;
        let mut ng: isize = -1;
        while (ok - ng).abs() > 1 {
            let mid = (ok + ng) / 2;
            if c[mid as usize] > bi {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        let cc = if ok >= 0 && ok < n as isize {
            n - ok as usize
        } else {
            0
        };

        ans += ac * cc;
    }
    ans.to_string()
}


Measured memory_bytes: 7692
#include <stdio.h>

int main() {
    int n, xs[52], r;
    char c, *s = "SHCD";
    for(int i=0; i<52; i++) xs[i] = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("\n%c %d", &c, &r);
        for(int j=0; j<4; j++) if(s[j] == c) xs[j*13+r-1] = 1;
    }
    for(int i=0; i<52; i++) if(xs[i] == 0) printf("%c %d\n", s[i/13], i%13+1);
}


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

int main(){
  int N,M;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int A;
    cin>>A;
    N-=A;
  }
  if(N<0)
    cout<<-1<<endl;
  else
    cout<<N;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int N;
string s;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> N >> s;
	int ans = 0;
	int sum = 0;
	rep (i, s.size()) {
		if (s[i] == 'I') {
			sum++;
		} else {
			sum--;
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 384
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b;

int main(){
    INIT;
    cin >> a >> b;
    if(b % a == 0){
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);

		int w = scan.nextInt();		
		int a = scan.nextInt();		
		int b = scan.nextInt();		

		if(b > a+w){
			System.out.println(b-(a+w));
		}
		else if(a > b+w){
			System.out.println(a-(b+w));
		}
		else {
			System.out.println("0");
		}
	}
}


Measured memory_bytes: 23892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Day of Week
 */
public class Main {

	static final String[] DAY = {
			"sat",
			"sun",
			"mon",
			"tue",
			"wed",
			"thu",
			"fri",
	};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int X = parseInt(br.readLine());

		System.out.println(DAY[(((X - 9) % 7) + 7) % 7]);
	}
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define MAX 100001

using namespace std;

vector<int> _map[MAX];
int n,m;
bool bfs_m[MAX];
int ans[MAX];

void bfs(int pi) {
	queue<int> q;
	q.push(pi);
	int ql,mi;bfs_m[1]=true;
	while(!q.empty()) {
		ql=q.size();
		for(int i=0;i<ql;i++) {
			mi = q.front();
//			cout <<mi <<"\n";
			q.pop();
			for(int j=0;j<_map[mi].size();j++) {
				if(bfs_m[_map[mi][j]] == true) continue;
				q.push(_map[mi][j]);
				bfs_m[_map[mi][j]] = true;
				ans[_map[mi][j]] = mi;
			}
		} 
	} 
}

int main(int argc,char ** argv) {
	int a,b;
	scanf("%d %d",&n,&m);
	memset(bfs_m,false,sizeof(bfs_m));
	for(int i=0;i<m;i++) {
		scanf("%d %d",&a,&b);
		_map[a].push_back(b);
		_map[b].push_back(a);
	}
	bfs(1);
	cout <<"Yes\n";
	for(int i=2;i<=n;i++)
		cout << ans[i] <<"\n";
	
	return 0;
}

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

const int maxn = 50;
typedef long long LL;

int A[maxn], B[maxn], C[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &B[i]);
    for (int i = 1; i <= n - 1; i++) scanf("%d", &C[i]);

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += B[A[i]];
        if (i != 1 && A[i] == A[i - 1] + 1) ans += C[A[i - 1]];
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll n,m;
  cin>>n>>m; 

  vector<ll> p(n+1);
  p[0]=0;
  rep(i,n){
    cin>>p[i+1];
  }

  map<ll,ll> q;
  q[0]=1;
  repo(i,n+1){
    p[i]+=p[i-1];
    p[i]%=m;
    if(q.count(p[i])) q.at(p[i])++;
    else q[p[i]]=1;
  }

  ll ans=0;
  for(auto z : q){
    ans+=z.se*(z.se-1)/2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 7868
n = int(input())
v = [int(s) for s in input().split(" ")]

v.sort()

while True:
    head = v.pop(0)
    next = v.pop(0)

    avg = (head + next) / 2

    if len(v) == 0:
        print(avg)
        break
    else:
        v.append(avg)
        v.sort()

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

int dx[5]={0, -1, 0, 1, 0};
int dy[5]={1, 0, 0, 0, -1};
string f[12];

void is(int y, int x){
	f[y][x]='0';
	for(int i=0; i<5; i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(0<=nx&&nx<12&&0<=ny&&ny<12&&f[ny][nx]=='1')is(ny, nx);
	}
	return;
}

int main(){

	while(cin>>f[0]){
		int ans=0;
		for(int i=1; i<12; i++)cin>>f[i];
		for(int y=0; y<12; y++){
			for(int x=0; x<12; x++){
				if(f[y][x]=='1'){
					is(y, x);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n,m,x;
    while(scanf("%d %d %d",&n,&m,&x)==3)
    {
        if(n<=x&&(n+m)>=x)
           printf("YES\n");
        else
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');

            Console.WriteLine(S[1] + S[0]);
        }
    }
}


Measured memory_bytes: 11092
#!/usr/bin python3
# -*- coding: utf-8 -*-

def pc(x):
    return format(x, 'b').count('1')

N = int(input())
X = input()
Xn = int(X,2)
p = pc(Xn)
X = list(X)

Xp = Xn%(p+1)
if p==1:
    Xm = 0
else:
    Xm = Xn%(p-1)

def f(i):
    if p==1 and X[i]=='1':
        #Xi == 0 > POPcount ==0
        return 0
    else:
        if X[i]=='1':
            # p->p-1
            ret = Xm - pow(2, N-1-i, p-1)
            ret %= p-1
        else:
            # p->p+1
            ret = Xp + pow(2, N-1-i, p+1)
            ret %= p+1
        cnt = 1
        while ret > 0:
            ret %= pc(ret)
            cnt += 1
        return cnt

def main():
    for i in range(N):
        ret = f(i)
        print(ret)

if __name__ == '__main__':
    main()


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

map<int,vector<int>> graph;
//map<int,bool> visited;
const ll mod=1e9+7;

void dfs(int node,vector<pair<ll,ll>> &dp)
{
    dp[node].first=1;
    dp[node].second=1;
    //visited[i]=1;
    for(auto i:graph[node])
    {
        if(dp[i].first==0&&dp[i].second==0){
        dfs(i,dp);
        dp[node].second=(dp[node].second*(dp[i].first+dp[i].second)%mod)%mod;
        dp[node].first=(dp[node].first*dp[i].second)%mod;
        }
    }

    
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<pair<ll,ll>> dp(n+1);
    dfs(1,dp);
    cout<<(dp[1].first+dp[1].second)%mod<<endl;
    
}

Measured memory_bytes: 21120
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;

	vector <int> a(n), b(n);
	forn(i, n)
		cin >> a[i];
	forn(i, n)
		cin >> b[i];

	vector <int> arr(n);
	forn(i, n)
		arr[i] = i + 1;


	int x = -1, y = -1, p = 1;
	do {
		if (arr == a)
			x = p;
		if (arr == b)
			y = p;
		p++;
	} while (next_permutation(arr.begin(), arr.end()));

	cout << abs(x - y);

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(){
	int hi[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	string youbi[7] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};

	int m, d;
	while(cin >> m >> d){
		if(m==0 && d==0)
			break;

		int ad = 0;
		for(int i=1;i<m;i++){
			ad+=hi[i-1];
		}
		cout << youbi[(ad+d-1)%7] << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct LCS{
    int n, m;
    string s, t;
    vector<vector<int> > dp, prev;
    LCS(string s, string t): s(s), t(t){
        n = s.size();
        m = t.size();
        dp.resize(n + 1, vector<int>(m + 1));
        prev.resize(n + 1, vector<int>(m + 1));
    }
    string build(){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(s[i] == t[j] && dp[i + 1][j + 1] <= dp[i][j] + 1){
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                    prev[i + 1][j + 1] = 1;
                }
                if(dp[i + 1][j + 1] <= dp[i][j + 1]){
                    dp[i + 1][j + 1] = dp[i][j + 1];
                    prev[i + 1][j + 1] = 2;
                }
                if(dp[i + 1][j + 1] <= dp[i + 1][j]){
                    dp[i + 1][j + 1] = dp[i + 1][j];
                    prev[i + 1][j + 1] = 3;
                }
            }
        }
        string res = "";
        int y = n, x = m;
        for(int i = 0;; i++){
            if(prev[y][x] == 1){
                y--; x--;
                res += s[y];
            }else if(prev[y][x] == 2){
                y--;
            }else if(prev[y][x] == 3){
                x--;
            }
            if(y == 0 || x == 0) break;
        }
        reverse(res.begin(), res.end());
        return res;
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    LCS l(s, t);
    cout << l.build() << endl;
}

Measured memory_bytes: 141184
import java.io.*;
import java.util.*;

import static java.lang.Integer.*;

public class Main {

    public static void main(String[] args) throws IOException {
        PrintWriter prnt = new PrintWriter(System.out);
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(read.readLine());
        int N = parseInt(st.nextToken()), X = parseInt(st.nextToken()), T = parseInt(st.nextToken());
        int D = N / X;
        if (N % X != 0) {
            D += 1;
        }
        prnt.println(D * T);
        prnt.close();
    }
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e16;
const int N = 3e3 + 5;

LL a[ N ];
LL dp[ N ][ N ];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];

  for (int i = n; i >= 1; i--) {
    for (int j = i; j <= n; j++) {
      if (i == j) {
        dp[i][j] = a[i];
      }
      else {
        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}


Measured memory_bytes: 70016
/*
  最大の利益（ある通貨について、時刻 t における価格 Rt (t=0,1,2,,,n−1)が入力とし
  　　　　　　て与えられるので、価格の差 Rj−Ri (ただし、j>i とする) の最大値）
  2018/04/09
*/

#include<stdio.h>

#define MAX 200000

#if 0
int Judge_Max(unsigned int *Rt,int i,int j,int max)
{
  int temp;
  temp = Rt[j] - Rt[i];
  if(temp > max)
    max = temp;

  return max;
}
#endif

int main(void)
{
  int Rt[MAX];
  int i,j;
  int n;/*Rtの数*/
  int max,min;
  /*
    max：Rt[j] - Rt[i]の最大
    min：jより前のRt[j]の最小値
  */

  fscanf(stdin,"%d",&n);
  for(i=0;i<n;i++)
    fscanf(stdin,"%d",&Rt[i]);

  min = Rt[0];
  for(j=1;j<n;j++){
    if((Rt[j] - min) > max || j == 1)
      max = Rt[j] - min;
    if(Rt[j] < min)
      min = Rt[j];
  }
  printf("%d\n",max);
  
  return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  
  int jump = 1;
  
  for(int i;i < N;i++){
    int L, p;
    cin >> L;
    p += L;
    
    if(p > X){
      break;
    }
    jump = jump + 1;
  }
  cout << jump << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
counter = 0

def Num_of_even(list):
    num = 0
    for i in list:
        if i % 2 == 0:
            num += 1
        else:
            continue
    return num

all = 3 ** N
Not = 2 ** (Num_of_even(A))
print(all - Not)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
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 long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}


int main(){
	string s;
	cin >>s;
	for(int i=0;i<s.size();i++){
	
	cout<<'x';
}
cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int n,x;
  cin >> n >> x;
  vector<int> l(n+10,0);
  for(int i = 0;i < n;i++){
    cin >> l[i];
  }

  int res = 0;
  int cnt = 1;
  for(int i = 0;i < n;i++){
    res += l[i];
    if(res > x) {
      break;
    }
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
/**
*   @Author : MeGaCrazy
*   @InitTime : Sat Jan 05 02:46:43 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
  int n;
  cin>>n;
  vector<int>v(n);
  for(int i=0;i<n;i++){
  	cin>>v[i];
  }
  int i,j;
  if(n%2==1){
         i=n-1;
         j=1;
  }else{
  	i=n-1;
  	j=0;
  }
  for(;i>=0;i-=2){
  	
  	cout<<v[i]<<" ";
  }
  for(;j<n;j+=2){
  //	cerr<<"helo "<<j<<endl;
  	cout<<v[j]<<" ";
  }
  

  



}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    ll h, w, n;
    cin >> h >> w >> n;
    map<pii, ll> mp;
    rep(r, n)
    {
        int a, b;
        cin >> a >> b;
        rep(i, 3)
        {
            rep(j, 3)
            {
                if (1 <= a - i && a - i <= h - 2 && 1 <= b - j && b - j <= w - 2)
                    mp[pii(a - i, b - j)]++;
            }
        }
    }

    OP((h - 2) * (w - 2) - (ll)mp.size());
    for (int i = 1; i <= 9; i++)
    {
        ll cnt = 0;
        for (auto x : mp)
        {
            if (x.second == i)
                cnt++;
        }
        OP(cnt);
    }

    return 0;
}

Measured memory_bytes: 56448
import sys
from collections import Counter

n = int(sys.stdin.readline().strip())

ss = []
counter = Counter()
for i in range(n):
    s = sys.stdin.readline().strip()
    counter[s] += 1
    ss.append(s)

count_items = counter.most_common()
count_max = count_items[0][1]
ans = []


for count_item in count_items:
    if count_max == count_item[1]:
        ans.append(count_item[0])
    else:
        break

ans.sort()
for word in ans:
    print(word)


Measured memory_bytes: 119768
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 50
using namespace std;
int n;
long long a[szxb]={2};
signed main()
{
	scanf("%d",&n);
	for(register int i(1);i^(n+1);i++){a[i]=((a[i-1]*2)+2);}
	printf("%lld",a[n]);
	return putchar(10),0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		while(true){
			int H = in.nextInt();
			int W = in.nextInt();

			if(H == 0 && W== 0){break;}

			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if(i % 2 == 0){
						if(j % 2 == 0){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}else{
						if(j % 2 == 0){
							System.out.print(".");
						}else{
							System.out.print("#");
						}
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 33396
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 1000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    ll i,j,k,l,n;
    cin>>n>>k;
    ll ar[n+1];
    for(i=1;i<=n;i++){
    	cin>>ar[i];
    }

    i=1; j=k+1;
    while(j<=n){
    	if(ar[j]>ar[i]){
    		cout<<"Yes"<<endl;
    	}
    	else{
    		cout<<"No"<<endl;
    	}
    	i+=1; j+=1;
    }
    return 0;   
}

Measured memory_bytes: 5212
N,M=map(int,input().split())
NG=[]
for _ in range(M):
    a,b=map(int,input().split())
    NG.append((a-1,b-1))
NG.sort(key=lambda x:x[1])
x=0
Ans=0
for i in range(M):
    if NG[i][0]>=x:
        x=NG[i][1]
        Ans+=1
print(Ans)

Measured memory_bytes: 18192
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int n,ans,x;
int main(){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>x;
        if(m[x]==0)v.push_back(x);
        m[x]++;
    }
    for(int i=0;i<v.size();++i)
        if(m[v[i]]>=v[i])
            ans+=m[v[i]]-v[i];
        else
            ans+=m[v[i]];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5112
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var S = ReadLine();
		WriteLine(S[0] == S[2] ? "Yes" : "No");
	}
}
static class Func
{
	public static void Add<T>(this Stack<T> q, T x) => q.Push(x);
	public static void Add<T>(this Queue<T> q, T x) => q.Enqueue(x);
}

Measured memory_bytes: 11092
def rerooting(n, edges, identity, merge, add_node):
    # 全方位木 dp
    # 参考: https://qiita.com/keymoon/items/2a52f1b0fb7ef67fb89e
    G = [[] for _ in range(n)]
    G_idxs = [[] for _ in range(n)]  # 自分を指すノードのインデックス
    for a, b in edges:
        G_idxs[a].append(len(G[b]))
        G_idxs[b].append(len(G[a]))
        G[a].append(b)
        G[b].append(a)
    # step 1
    parents = [0] * n
    order = []  # 行きがけ順
    stack = [0]
    parents[0] = -1
    while stack:
        v = stack.pop()
        p = parents[v]
        order.append(v)
        for u in G[v]:
            if p != u:
                stack.append(u)
                parents[u] = v
    subtree_res = [[0]*len(Gv) for Gv in G]
    # 下から登る
    for v in order[:0:-1]:
        p = parents[v]
        result = identity
        for idx_Gv, (u, subtree_res_v_i) in enumerate(zip(G[v], subtree_res[v])):
            if p == u:
                parent_idx = idx_Gv
            else:
                result = merge(result, subtree_res_v_i)
        idx_p2v = G_idxs[v][parent_idx]
        subtree_res[p][idx_p2v] = add_node(result, v)
    # step 2
    # 上から降りる
    results = [0] * n
    for v in order:
        subtree_res_v = subtree_res[v]
        cum = identity
        cum_from_tail = [identity]
        for r in subtree_res_v[:0:-1]:
            cum = merge(r, cum)
            cum_from_tail.append(cum)
        cum_from_tail.reverse()
        cum = identity
        for r, cum_t, u, idx_u2v in zip(subtree_res_v, cum_from_tail, G[v], G_idxs[v]):
            result = add_node(merge(cum, cum_t), v)
            subtree_res[u][idx_u2v] = result
            cum = merge(cum, r)
        results[v] = add_node(cum, v)
    return results


class Combination:
    def __init__(self, n_max, mod=10**9+7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

def main():
    N = int(input())
    AB = [list(map(lambda x: int(x)-1, input().split())) for _ in range(N-1)]
    mod = 10**9 + 7
    comb = Combination(202020)
    identity = (1, 0)
    merge = lambda a, b: (a[0] * b[0] % mod * comb(a[1]+b[1], a[1]) % mod, a[1] + b[1])
    add_node = lambda value, idx: (value[0], value[1]+1)
    Ans = rerooting(N, AB, identity, merge, add_node)
    print("\n".join(str(ans) for ans, _ in Ans))

main()


Measured memory_bytes: 202484
//created by pyoxiao on 2020/04/12
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int n;
char s[4005];
vector<int> R,G,B;
void solve() {
    scanf("%d %s", &n, s + 1);
    for(int i = 1; i <= n; i ++) {
        if(s[i] == 'R') R.emplace_back(i);
        if(s[i] == 'G') G.emplace_back(i);
        if(s[i] == 'B') B.emplace_back(i);
    }
    int sz1 = R.size(), sz2 = G.size(), sz3 = B.size();
    LL ans = 1LL * sz1 * sz2 * sz3;
    //cout << sz1 << ' ' << sz2 << ' ' << sz3 << ' ' << ans << '\n';
    for(int i = 0; i < sz1; i ++) {
        for(int j = 0; j < sz2; j ++) {
            int pos1 = R[i], pos2 = G[j];
            if(pos1 > pos2) swap(pos1, pos2);
            if((pos2 + pos1) % 2 == 0 && s[(pos2 + pos1) / 2] == 'B') ans --;
            if(2 * pos1 - pos2 >= 1 && s[(2 * pos1 - pos2)] == 'B') ans --;
            if(2 * pos2 - pos1 <= n && s[(2 * pos2 - pos1)] == 'B') ans --;
        }
    }
    printf("%lld\n", ans);
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3856
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main() {
    int n, tmp; 
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; ++i){
        cin >> tmp;
        s.insert(tmp);
    }

    cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int s,A[1000010]={},i=2,ans=0;
    cin>>s;

    A[1]=s;

    while(1){
        //A[i]を計算
        if(A[i-1]%2==0){
            A[i]=A[i-1]/2;
        }else{
            A[i]=A[i-1]*3+1;
        }

        int f=0;
        for(int j=1;j<i;j++){
            if(A[i]==A[j]){
                ans=i;
                f=1;
                break;
            }
        }
        if(f==1)break;
        i++;
    }

    cout<<ans<<endl;

    return 0;
}

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

int main() {
	int S;
	int h;
	int m;
	int s;
	cin >> S;
	s = S % 60;
	S /= 60;
	m = S % 60;
	h = S / 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;

}


Measured memory_bytes: 3100
#!/usr/bin/env python3
#ABC131 B
import sys
import math

n,l = map(int,input().split())

taste = []
for i in range(n):
    taste.append(i + l)
s = sum(taste)
m = 100000000
for i in range(n):
    tmp = 0
    for j in range(n):
        if i != j:
            tmp += taste[j]
    if abs(s - tmp) < m:
        m = abs(s - tmp)
        t = tmp

print(t)


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

vector<int> a,b;
map<int,int>mp;
int main()
{
    int n,m;
    scanf("%d",&n);
    for(int i = 0; i <n;i ++){
        int x;scanf("%d",&x);a.push_back(x);
        mp[x]++;
    }
    scanf("%d",&m);
    for(int i = 0; i < m; i++){
        int x;scanf("%d",&x);b.push_back(x);
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i = 0; i < m; i++){
        bool exist =binary_search(a.begin(),a.end(),b[i]);
        if(!exist||(exist && !mp[b[i]]) ){
            printf("NO");
            return 0;
        }
        mp[b[i]]--;
    }
    printf("YES");
    return 0;
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

const int M = 3e6;

ll n, A;
ll ans;

ll up(ll x, ll y) {
  return (x + y - 1) / y;
}

void read() {
  cin >> n >> A;
  ans = n;
}

void uin(ll &x, ll y) {
  x = min(x, y);
}

void kill() {
  for (int m = 1; m <= 45; ++m) {
    ll p = 1;
    ll sum = m;
    ll a = 1;

    while (true) {
      uin(ans, m * A + sum + up(n, p));
      if (p >= n)
        break;

      if (a >= M)
        break;


      sum++;
      p /= a;
      p *= a + 1;
      if (sum % m == 0)
        ++a;
    } 

  }

  cout << ans << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();

}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

struct Info{
  static const int Height = 4;
  static const int Width = 8;
  short field[Height][Width];
 
  bool operator < (const Info& info) const{
    for(int i = 0; i < Height; i++)
      for(int j = 0; j < Width; j++)
	if(field[i][j] != info.field[i][j]) return field[i][j] < info.field[i][j];
    return false;
  }
};

struct State{
  int t;
  Info info;
  bool operator < (const State& s) const {
    return t > s.t;
  }
};

Info Goal;
Info Start;

void print(const Info& info){
  for(int i = 0; i < Info::Height; i++){
    for(int j = 0; j < Info::Width; j++) cout << info.field[i][j] << " ";
    cout << endl;
  }
  cout << endl;
}
void input(){
  for(int i = 0; i < Info::Height; i++) Start.field[i][0] = 0;

  for(int i = 0; i < Info::Height; i++)
    for(int j = 1; j < Info::Width; j++){
      cin >> Start.field[i][j];
      if(Start.field[i][j]%10 == 1){
	int pos = Start.field[i][j]/10;
	swap(Start.field[i][j], Start.field[pos-1][0]);
      }
    } 
  // print(Start);
  // exit(0);
}

int find(const Info& info, int x, int skip){

  int come = 0;
  for(int i = 0; i < Info::Height; i++)
    for(int j = 0; j < Info::Width; j++)
      if(info.field[i][j] == x){
	come++;
	if(come > skip) return i*Info::Width+j;
      }
  return -1;
}


bool isInside(int h, int w){return 0<=h&&h<Info::Height&&0<=w&&w<Info::Width;}

void solve(){

  map<Info,int> M;
  M.clear();
  priority_queue<State> Q;
  Q.push((State){0,Start});
  M[Start] = 0;

  while(!Q.empty()){
    const State now = Q.top();
    Q.pop();
    
    if(M[now.info] < now.t) continue;

    for(int i = 0; i < 4; i++){
      int blank = find(now.info, 0, i);
      const int h = blank/Info::Width;
      const int w = blank%Info::Width;
    
      if(!isInside(h,w-1)) continue;

      int nexpos = find(now.info, now.info.field[h][w-1]+1, 0);
      
      if(nexpos == -1) continue;

      State nex = now;
      nex.t++;
      swap(nex.info.field[h][w], nex.info.field[nexpos/Info::Width][nexpos%Info::Width]);

      if(M.count(nex.info) == 0 || M[nex.info] > nex.t){
	M[nex.info] = nex.t;
	Q.push(nex);
      }
    }
  }

  if(M.count(Goal) == 0) cout << "-1" << endl;
  else cout << M[Goal] << endl;
}

int main(){
  for(int i = 0; i < Info::Height; i++)
    for(int j = 0; j < Info::Width; j++){
      if(j == Info::Width-1) Goal.field[i][j] = 0;
      else Goal.field[i][j] = (i+1)*10+j+1;
    }

  int tc;
  cin >> tc;
  while(tc--){
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 8496