akhauriyash/Code-Regression huggingface dataset:
L,R = [int(i) for i in input().split()]
mod = 2019
if R-L >= 673:
    print(0)
else:
    ans = []
    for i in range(L,R+1):
        for ii in range(i+1,R+1):
            ans.append((i*ii)%mod)
    ans = sorted(ans)
    print(ans[0])

Measured memory_bytes: 8132
#include <iostream>

using namespace std;

int main(){
    int a[5];
    int k=0;
    cin >> a[0];
    cin >> a[1];
    cin >> a[2];
    cin >> a[3];
    cin >> a[4];
    cin >> k;
    int flag = 0;
    int temp;
    for(int i = 0; i<4;i++){
      for(int j = i+1; j<5;j++){
          temp= a[j]-a[i];
          if(temp>k){
              flag = 1;
              }
            }
       }

    if(flag ==0)
        cout << "Yay!" ;
    else
         cout << ":(" ;

    }




Measured memory_bytes: 256
#include <stdio.h>

int grademe(int mid, int final, int reset)
{
	int point;
	if(mid == -1 || final == -1)
		return (0);

	point = mid + final;
	if(point >= 80)
		return (1);

	if(point >= 65 && point < 80)
		return (2);

	if(point >= 50 && point < 65)
		return (3);

	if(point >= 30 && point < 50)
	{
		if(reset >= 50)
			return (3);
		else
			return (4);
	}

	return (0);
}

int main(void)
{
	int mid, final, reset;		//examinations
	int grade;					//0=F / 1=A / 2=B / 3=C / 4=D

	while(1)
	{
		grade = 0;
		scanf("%d%d%d", &mid, &final, &reset);

		if(mid == -1 && final == -1 && reset == -1)
			return (0);
		
		grade = grademe(mid, final, reset);

		switch(grade)
		{
			case 0:
				printf("F");
				break;
			case 1:
				printf("A");
				break;
			case 2:
				printf("B");
				break;
			case 3:
				printf("C");
				break;
			case 4:
				printf("D");
				break;
		}
		printf("\n");
	}

	return (0);
}



Measured memory_bytes: 2076
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int ball[10];
stack<int> r, l;

bool dfs(int n){
    if(n==10) return true;
    bool ret = false;
    // r?????\??????
    int rt = r.top();
    r.push(ball[n]);
    if(r.top()>rt){
        ret |= dfs(n+1);
        r.pop();
    }
    else r.pop();

    int lt = l.top();
    l.push(ball[n]);
    if(l.top()>lt){
        ret |= dfs(n+1);
        l.pop();
    }
    else l.pop();
    return ret;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        while(!r.empty()) r.pop();
        while(!l.empty()) l.pop();
        r.push(0);
        l.push(0);
        FOR(i,0,10) cin >> ball[i];
        if(dfs(0)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3092
#include<stdio.h>
#include<math.h>
#define ORDINATE(r,t) r*cos(t*M_PI/180)
#define ABSCISSA(r,t) r*sin(t*M_PI/180)
main(){
  int r=0,t=0,a=90;
  int x=0,y=0;
  double dx=0,dy=0;
  while(1){
    scanf("%d,%d",&r,&t);
    if(r==0 && t==0)
      break;
    dx+=ORDINATE(r,a);
    dy+=ABSCISSA(r,a);
    a-=t;
  }
  x=dx;
  y=dy;
  printf("%d\n%d\n",x,y);
  return 0;
}

Measured memory_bytes: 604
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BCanYouSolveThis solver = new BCanYouSolveThis();
        solver.solve(1, in, out);
        out.close();
    }

    static class BCanYouSolveThis {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int c = in.nextInt();
            int[] b = new int[m];
            for (int i = 0; i < m; i++) {
                b[i] = in.nextInt();
            }

            int[] a = new int[m];
            int ct = 0;
            for (int i = 0; i < n; i++) {
                int ans = 0;
                for (int h = 0; h < m; h++) {
                    a[h] = in.nextInt();
                    ans += a[h] * b[h];
                }
                ans += c;
                if (ans > 0) {
                    ct++;
                }
            }
            out.println(ct);
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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



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

int main()
{
    string S;
    cin >> S;
    int n=S.size();
    rep(i,n){
        cout << "x";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    //solve(K, A, B);
    bool f=false;
    for (long long i = 0; i <= 1000; i++) {
        if(i>=A && i<=B) {
            if(i%K==0) {
                f=true;
                break;
            }
        }
    }
    if(f){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3692
package main

import (
	"bufio"
	"fmt"
	"os"
)

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - March
	var N int
	fmt.Scan(&N)

	sc.Split(bufio.ScanWords)
	S := make(map[int]int, N)
	var temp string
	for i := 0; i < N; i++ {
		temp = nextStr()
		if temp[0:1] == "M" {
			S[0]++
		} else if temp[0:1] == "A" {
			S[1]++
		} else if temp[0:1] == "R" {
			S[2]++
		} else if temp[0:1] == "C" {
			S[3]++
		} else if temp[0:1] == "H" {
			S[4]++
		}
	}

	var n int = 5
	var sum int
	var ans int
	var count int
	if len(S) < 3 {
		fmt.Println("0")
	} else {
		for i := 0; i < (1 << n); i++ {
			count = 1
			sum = 0
			for j := 0; j < n; j++ {
				if i>>j&1 == 1 {
					count *= S[j]
					sum++
				}
			}

			if sum == 3 {
				ans += count
			}
		}
		fmt.Println(ans)
	}

}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define pb push_back
#define f first
#define s second
#define INF 1000000000000
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 100100, MAXK = 25;
const ll MOD = 1e9+7;

ll dp[MAXN];
ll w[MAXN];
int v[MAXN];

int main()
{
    FAST_IO;

    int n, W; cin >> n >> W;
    FOR(i, 1, n) cin >> w[i] >> v[i];

    FOR(i, 1, MAXN-1) dp[i] = INF;
    FOR(j, 1, n) for (int i = MAXN-1-v[j]; i >= 0; i--)
        dp[i+v[j]] = min(dp[i+v[j]], dp[i]+w[j]);

    int ans = 0;
    FOR(i, 0, MAXN-1) {
        if (dp[i] <= W)
            ans = i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] dArr = new int[N];

        for (int i=0; i< N; i++) {
            dArr[i] = scanner.nextInt();
        }

        int sum = 0;
        for (int i=0; i< N; i++) {
            for (int k=i+1; k< N; k++) {
                sum += dArr[i] * dArr[k];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::rational::Ratio;
use std::f64;

#[fastout]
fn main() {
    input!{
        A: f64,
        B: f64,
        H: f64,
        M: f64,
    }

    let H_theta = 30.0 * H + 0.5 * M;
    let M_theta = 6.0 * M;

    let theta = if (H_theta - M_theta).abs() > 180.0 {(H_theta - M_theta).abs()} else {360.0 - (H_theta - M_theta).abs()};

    let mut ans = (A * A + B * B - 2.0*A*B*theta.to_radians().cos()).sqrt();

    // if theta == 0.0 || theta == 180.0 {
    //     ans = 0.0;
    // }


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


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

string s;
int a,b;

int32_t main(){
    /*seed_seq seq{
        (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
        (uint64_t) __builtin_ia32_rdtsc(),
        (uint64_t) (uintptr_t) make_unique<char>().get()
    };
    mt19937 rng(seq);*/
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> s >> s;
    for(char i : s){
        if(i=='R') a++;
        else b++;
    }
    if(a>b) cout << "Yes";
    else cout << "No";

}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        st: [(String, i64); n],
        x: String
    }
    let sum: i64 = st.iter().map(|(_, t)| t).sum();
    let mut sleep = 0;
    for (s, t) in st {
        sleep += t;
        if *s == x {
            break;
        }
    }

    println!("{}", sum - sleep);
}


Measured memory_bytes: 2176
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Union-Find -- START --
class UnionFind():
  def __init__(self,sz):
    self.sz=sz
    self.data=[-1]*sz

  def unite(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return False
    if self.data[x]>self.data[y]:
      x,y=y,x
    self.data[x]+=self.data[y]
    self.data[y]=x
    return True

  def find(self,k):
    if self.data[k]<0:
      return k
    self.data[k]=self.find(self.data[k])
    return self.data[k]

  def size(self,k):
    return -self.data[self.find(k)]
# Union-Find --- END ---

def main():
  n,q=LI()
  uf=UnionFind(n)
  ans=[]
  for _ in range(q):
    a,b,c=LS()
    b=int(b)
    c=int(c)
    if a=='0':
      uf.unite(b,c)
    else:
      ans.append(1 if uf.find(b)==uf.find(c) else 0)

  for x in ans:
    print(x)

main()
# print(main())


Measured memory_bytes: 14072
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	while (1) {
		int N, P; cin >> N >> P;
		if (!N)break;
		vector<int>aa(100);
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			while (a--) {
				int c; cin >> c;
				aa[c]++;
			}
		}
		int amax = 0;
		int ans = 0;
		for (int i = 99; i >=0; --i) {
			if (amax <= aa[i]) {
				amax = aa[i];
				ans = i;
			}
		}
		if (amax <P)ans = 0;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define MOD     1000000007
#define pb      push_back
#define mp      make_pair
#define all(v)  (v).begin(),(v).end();
#define T		int t;cin>>t;while(t--)
#define IOS     ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {




	//coding a recursive Solution :
	string s, t;
	cin >> s >> t;

	int l1 = s.length();
	int l2 = t.length();

	int dp[l1 + 1][l2 + 1];

	for (int  i = 0 ; i <= l1 ; i++) {
		for (int j = 0 ; j <= l2 ; j ++) {
			dp[i][j] = 0;
		}
	}

	string ans = "";
	for (int i = 1; i <= l1; i ++) {

		for (int j = 1; j <= l2 ; j ++) {

			if (s[i - 1] == t[j - 1]) {

				dp[i][j] = 1 + dp[i - 1][j - 1];
				ans.append(s.substr(i - 1, 1));
			}

			else {

				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

			}


		}
	}


	int index = dp[l1][l2];
	char lcs[index + 1 ];

	lcs[index] = '\0'; // Set the terminating character

	// Start from the right-most-bottom-most corner and
	// one by one store characters in lcs[]
	int i = l1, j = l2;
	while (i > 0 && j > 0)
	{
		// If current character in X[] and Y are same, then
		// current character is part of LCS
		if (s[i - 1] == t[j - 1])
		{
			lcs[index - 1] = s[i - 1]; // Put current character in result
			i--; j--; index--;     // reduce values of i, j and index
		}

		// If not same, then find the larger of two and
		// go in the direction of larger value
		else if (dp[i - 1][j] > dp[i][j - 1])
			i--;
		else
			j--;
	}

	cout << lcs << endl;

}




Measured memory_bytes: 53764
/*

*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define MAXIN 300000
//#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
#define mod 1000000007
#define Mod(x) x>=mod&&(x-=mod)
typedef long long LL;
const int N=5005;

int Enum,H[N],nxt[N<<1],to[N<<1],f[N][N],sz[N],g[N];
char IN[MAXIN],*SS=IN,*TT=IN;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}
inline void AE(int u,int v)
{
	to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
	to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum;
}
void DFS(int x,int fa)
{
	static int tmp[N];

	sz[x]=1;
	int *fx=f[x]; fx[1]=1;
	for(int i=H[x],v; i; i=nxt[i])
		if((v=to[i])!=fa)
		{
			DFS(v,x);
			for(int j=0,sv=sz[v]; j<=sz[x]; ++j)
				for(int k=0; k<=sv; ++k)
					tmp[j+k]+=1ll*fx[j]*f[v][k]%mod, Mod(tmp[j+k]);
			for(int j=0,l=sz[x]+sz[v]; j<=l; ++j)
				fx[j]=tmp[j], tmp[j]=0;
			sz[x]+=sz[v];
		}
	LL t=0;
	for(int i=1; i<=sz[x]; ++i) t+=mod-1ll*fx[i]*g[i]%mod;
	f[x][0]=t%mod;
}

int main()
{
	int n=read();
	for(int i=1; i<n; ++i) AE(read(),read());
	g[0]=1;
	for(int i=2; i<=n; i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
	DFS(1,1), printf("%d\n",mod-f[1][0]);

	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	vector<int>dp(n);
	for(int i = 0 ; i < n - 1 ; i ++)
	{
		int x;
		cin>>x;
		dp[x-1]++;
	}
	for(int i = 0 ; i < n ; i ++)
	{
		cout<<dp[i]<<endl;
	}
	return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
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; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

ll d;
ll ans = 0;
vector<ll> ex10(19);

void dfs(int i, int l, ll res, ll now) {
  if (l-i < i) {
    if (res==0) {
      debug(l, i, now);
      ans += now;
    }
    return;
  } else if (l-i == i) {
    if (res==0) {
      debug(l, i, now);
      ans += now*10;
    }
    return;
  }
  ll p = ex10[l-i]-ex10[i];
  auto k = res/p;
  dfs(i+1, l, res-(p*k), now*max(0LL, 10-abs(k)));
  if (res >= 0) {
    k++;
  } else {
    k--;
  }
  dfs(i+1, l, res-(p*k), now*max(0LL, 10-abs(k)));
}

void check(int l) {
  ll p = ex10[l] - ex10[0];
  ll now = 1;
  if (d%p==0) {
    auto k=d/p;
    now *= max(0LL, 9-k);
    dfs(1, l, 0, now);
  } else {
    auto k=d/p;
    dfs(1, l, d-(p*k), max(0LL, 9-k));
    k++;
    dfs(1, l, d-(p*k), max(0LL, 9-k));
  }
}

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

  ex10[0] = 1;
  for(int i=1; i<=18; i++) {
    ex10[i] = ex10[i-1]*10;
  }

  cin >> d;
  for(int i=1; i<18; i++) {
    check(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

ll pow(ll a, ll b, ll m)
{
    ll  ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
const ll INF=1e15;
int a[405];
ll pre[405];
ll dp[405][405];

ll solve(int ini,int fin){
    //if(inf>fin) return INF;
	if(dp[ini][fin] != -1) return dp[ini][fin];
	if(ini==fin) return dp[ini][fin] = 0;
	if(ini + 1 == fin) return dp[ini][fin] = a[ini]+a[fin];

	ll best = INF;

	for(int i = ini;i<fin;i++){
		ll cand = solve(ini,i) + solve(i+1,fin)+pre[fin]-pre[ini-1];
		best = min(best,cand);
	}

	return dp[ini][fin] = best;

}

int main()
{
	IOS;
	int t=1; //cin>>t;
	while(t--){
	    memset(dp,-1,sizeof(dp));
	    int n; cin>>n;
	    for(int i=1;i<=n;i++) cin>>a[i];
	    pre[0]=0;
	    for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
	    cout<<solve(1,n);
	    cout<<endl;
	}  
}

Measured memory_bytes: 4808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n,a;cin >> n >> a;
	vector<int> x(n);
	REP(i,n) cin >> x[i];
	ll dp[n+1][n+1][2501]={};
	dp[0][0][0]=1;
	REP(i,n){
		REP(j,n){
			REP(k,2501){
				if(!dp[i][j][k]) continue;
				dp[i+1][j][k]+=dp[i][j][k];
				dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
			}
		}
	}
	ll ans=0;
	FOR(i,1,n+1){
		ans+=dp[n][i][i*a];
	}
	cout << ans << endl;
}

Measured memory_bytes: 54452
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,c,k,t[110000];

signed main(){
  cin>>n>>c>>k;rep(i,n)cin>>t[i];
  sort(t,t+n);
  int ans = 0, last = -INF, cnt = 0;
  rep(i,n){
    if(t[i] > last || last > t[i]+k || cnt >= c){
      ans++;last = t[i]+k;cnt = 1;
    }else{
      cnt++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
// Solution by ** Abhishek Mittal **
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>

#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 1000000007
#define ll long long
#define vll vector<long long>  

#define all(c) c.begin(), c.end()

// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())

// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO
    
    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];

    ll curr_money = 1000;
    ll stocks = 0;
    ll rem_money = 0;
    stocks = curr_money/arr[0];
    rem_money = curr_money%arr[0];

    for(int i=1;i<n;i++){
        if(arr[i-1] > arr[i]){
            stocks = curr_money/arr[i];
            rem_money = curr_money%arr[i];
        }
        else{
            curr_money = rem_money + stocks*arr[i];
            // stocks = 0;
            // rem_money = 0;
        }
    }
    cout<<curr_money<<endl;


    return 0;

}

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

int N;
const int MAX_N = 3.0e5 + 100;
ll A[MAX_N];

int main() {
    cin >> N;
    int M = 3*N;
    for (int i = 0; i < M; i++) cin >> A[i];

    sort(A, A+M, greater<>());

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

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;

// * XY座標
#define X real()
#define Y imag()

// * 点の表現
typedef complex<double> P;

// * 許容する誤差ε
const double EPS = 1e-10;
// * Infinity
const double INF = 1e12;
// * 円周率
const double PI = acos(-1.0);
// * Infinity 2
const P INF_P(INF,INF);

// * complex<double> の順序を定義する
namespace std {
	bool operator < (const P& a, const P& b) {
		return (real(a) != real(b))? real(a) < real(b) : imag(a) < imag(b);
	}
}

// * 2乗する
double sq(double x) {
	return x * x;
}

// * 2点間の距離
double dist(P p1, P p2) {
	return abs(p1 - p2);
}

// * 2つのスカラーが等しいかどうか
bool equal(double a, double b) {
	return ( fabs( a - b ) < EPS );
}
// * 2つのベクトルが等しいかどうか
bool eq_v(P a, P b) {
	return ( equal( a.X, b.X ) && equal( a.Y, b.Y ) );
}

// * 内積 (dot product) : a・b = |a||b|cosΘ
double dot(P a, P b) {
	return real( conj(a) * b );
}

// * 外積 (cross product) : a×b = |a||b|sinΘ
double cross(P a, P b) {
	return imag( conj(a) * b ) ;
}

// 三角形の表現
struct Triangle{
private:
	// 余弦定理から 3 つの角の角度を求める (内部の関数で使用)
    double law_of_cos(double a, double b, double c) {
        return acos( (b*b + c*c - a*a) / (2.0 * b * c) );
    }
public:
	// 3 つの頂点
	P a, b, c;
    // 3 つの辺の長さ
    double edgeA, edgeB, edgeC;
    // 3 つの角の角度 (ラジアン)
    double angleA,angleB,angleC;
    
    // コンストラクタで初期化
    Triangle(P p1, P p2, P p3) {
        a = p1;
        b = p2;
        c = p3;
        edgeB = abs(c-a);
        edgeA = abs(b-c);
        edgeC = abs(a-b);
        angleA = law_of_cos( edgeA, edgeB, edgeC );
        angleB = law_of_cos( edgeB, edgeC, edgeA );
        angleC = law_of_cos( edgeC, edgeA, edgeB );
    }
	// 点 p が三角形の内部にあるかどうか ( AOJ 0012 で検証済み )
	// 点 p が三角形の辺上 or 頂点上 にあるときは誤差で正しい結果が返ってこないので注意!!!
	bool is_inside(P p) {
		
		Triangle t1( a , b , p );
		Triangle t2( b , c , p );
		Triangle t3( c , a , p );
		// 角APB + 角BPB + 角CPA が 360度なら 点 p は三角形の内部にある
		return equal( t1.angleC + t2.angleC + t3.angleC , 2.0*PI );
	}
};

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		P p1(xp1,yp1), p2(xp2,yp2), p3(xp3,yp3), K(xk,yk), S(xs,ys);
		Triangle t( p1 , p2, p3 );
		int a = t.is_inside(K)? 1 : 0 ;
		int b = t.is_inside(S)?	1 : 0 ;
		cout << ((a^b)? "OK" : "NG") << endl;
	}
}

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


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

using namespace std;

#define intt long long 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n;

int main() {

	FAST;

	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 1; i <= 100; i ++) {
		if ((a * i) % b == c) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
# 最短ルートでいける、左上開始、右上終了ゆえに#の数数えればいけるぞ
H, W = map(int, input().split(" "))
A = [input() for _ in range(H)]

print(["Impossible", "Possible"]["".join(A).count("#")==H+W-1])

Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_N (2010LL)
#define MAX_X (1000000010LL)
#define MAX_C (MAX_N * MAX_X)

int N;
ll cost[MAX_N][MAX_N];
ll x;
ll a[MAX_N];
int b[MAX_N][MAX_N]; // b[i][j] : [i-k, i]までで最小のaのindex
int main()
{
    ll ans = MAX_C;

    scanf("%d %lld", &N, &x);
    for ( int i = 0; i < N; i++ ) {
	scanf("%lld", &a[i]);
	b[i][0] = i;
    }
    
    for ( int i = 0; i < N; i++ ) {
	for ( int j = 1; j < N; j++ ) {
	    if ( a[(i-j+N)%N] < a[b[i][j-1]] ) {
		b[i][j] = (i-j+N)%N;
	    }
	    else {
		b[i][j] = b[i][j-1];
	    }
	}
    }

    for ( ll i = 0; i < N; i++ ) {
	ll tmp = i * x;
	for ( int j = 0; j < N; j++ ) {
	    tmp += a[b[j][i]];
	}
	ans = min( ans, tmp );
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 16000
#include<stdio.h>
int main()
{
    int num[3000][2] , i ,a ,p;
		
	for(i = 0 ; ; i ++)
	{
		scanf("%d%d",&num[i][0],&num[i][1]);
		if (num[i][0] == 0 && num[i][1] == 0 )
		{
			a = i;
			break;
		}
	}
	for(i = 0 ; i < a ; i ++)
	{
		if(num[i][0] > num[i][1])
		{
			p = num[i][0];
			num[i][0] = num[i][1];
			num[i][1] = p;
		}
	}
	for(i = 0 ; i < a ; i ++)
	{
		printf("%d %d\n",num[i][0],num[i][1]);
	}
	return 0;
}


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

int n, u, k, v;
int G[101][101] = {0};

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		while (k --) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i=1; i<=n; ++i) {
		for (int j=1; j<=n; ++j) {
			cout << (j==1 ? "" : " ") << G[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void) {

  int h,w;
  scanf("%d %d", &h, &w);
  char s[h][w+1];
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  int white = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        white++;
      }
    }
  }
  int path[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      path[i][j] = 0;
    }
  }
  path[0][0] = 1;
  int move = 1;
  int flag;
  while (1) {
    flag = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (path[i][j] == move) {
          if (i > 0 && s[i-1][j] != '#' && path[i-1][j] == 0) {
            flag = 1;
            path[i-1][j] = move+1;
          }
          if (i < h-1 && s[i+1][j] != '#' && path[i+1][j] == 0) {
            flag = 1;
            path[i+1][j] = move+1;
          }
          if (j > 0 && s[i][j-1] != '#' && path[i][j-1] == 0) {
            flag = 1;
            path[i][j-1] = move+1;
          }
          if (j < w-1 && s[i][j+1] != '#' && path[i][j+1] == 0) {
            flag = 1;
            path[i][j+1] = move+1;
          }
        }
      }
    }
    if (flag == 0) {
      break;
    }
    move++;
  }
  if (path[h-1][w-1] == 0) {
    printf("-1\n");
  } else {
    printf("%d\n", white-path[h-1][w-1]);
  }

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#define INF 0x3f3f3f
int max(int a,int b)
{
	return a>b?a:b;
}
int map[110][110],visit[110],vis[110];
int n,m;
int dijkstra(int a)
{
	memset(visit,0,sizeof(visit));
	int i,j,next,sum,min;
	for(i=0;i<m;i++)
	vis[i]=map[a][i];
	visit[a]=1;
	for(i=0;i<m;i++)
	{
		min=INF;
		for(j=0;j<m;j++)
		{
			if(!visit[j]&&min>vis[j])
			{
				next=j;
				min=vis[j];
			}
		}
		visit[next]=1;
		for(j=0;j<m;j++)
			if(!visit[j]&&vis[j]>vis[next]+map[next][j])
			vis[j]=vis[next]+map[next][j];
	}
	sum=0;
	for(i=0;i<m;i++)
	sum+=vis[i];
	return sum;
}
int main()
{
	int i,j,sum;
	int a,b,c;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<110;i++)
		for(j=i;j<110;j++)
		{
			if(i==j)
			map[i][j]=map[j][i]=0;
			else
			map[i][j]=map[j][i]=INF;
		}
		m=0;
		while(n--)
		{
			scanf("%d%d%d",&a,&b,&c);
			map[a][b]=map[b][a]=c;
			m=max(m,max(a,b)+1);
		}
		sum=INF;
		for(i=0;i<m;i++)
		{
			if(sum>dijkstra(i))
			{
				j=i;
				sum=dijkstra(i);
			}			
		}
		printf("%d %d\n",j,sum);
	}
	return 0;
}

Measured memory_bytes: 1076
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int k , r;
    cin >> k >> r;
    if(k >=10){
        cout << r << endl;
    }else{
        cout << r + 100 * (10 - k) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll a, b, k; cin >> a >> b >> k;
    set<ll> s;
    Rep(i, a, min(a+k, b+1)) s.insert(i);
    Rep(i, max(a, b-k+1), b+1) s.insert(i);
    for(auto x : s) cout << x << endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

string s1,s2;
char str[5];

bool query(string A,string B)
{
	printf("%s\n%s\n",A.c_str(),B.c_str()); fflush(stdout);
	scanf("%s",&str);
	return str[0]=='T'||str[0]=='e';
}
int main()
{
	int n;
	scanf("%d",&n);
	bool up=true;
	string T="..##",S="#.#.";
	for(int i=0;i<n;i++)
	{
		if(up)
		{
			bool nxt=false;
			for(int j=0;j<4;j++)
			{
				string a=s1,b=s2;
				a+=T[j],b+=S[j];
				if(query(a,b))
				{
					s1=a,s2=b;
					nxt=true;
					break;
				}
			}
			up=nxt;
		}
		if(!up)
		{
			for(int j=0;j<4;j++)
			{
				string a="",b="";
				a+=T[j],b+=S[j];
				a+=s1,b+=s2;
				if(query(a,b))
				{
					s1=a,s2=b;
					break;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 596
#include <stdio.h>
#define N 100000

int n,S[N];

int binarySearch(int key){
  int left=0,right=n,mid;
  while(left < right){
    mid = (left+right)/2;
    if(key == S[mid]) return 1;
    if(key > S[mid]) left = mid+1;
    else if(key < S[mid]) right = mid;
  }
  return 0;
}

int main(){
  int i,q,k,count=0;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&k);
    if(binarySearch(k)) count++;
  }

  printf("%d\n",count);
  return 0;
}

    

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

vector <int> from[100010], circle;
int size[100010], vis[100010], fa[100010], val[100010];
int s, e;

void dfs(int x, int last, int p){
	fa[x] = last;
	if (p != 0) val[x] = size[x] = p;
	else size[x] = val[x];
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		if (v == last) continue;
		if (x == s && v == e || v == s && x == e) continue;
		dfs(v, x, -p), size[x] += size[v];
	}
}

void find_circle(int x, int last){
	vis[x] = 1, fa[x] = last;
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		if (v == last) continue;
		if (x == s && v == e || v == s && x == e) continue;
		if (vis[v]){
			int now = x;
			while (now != v){
				circle.push_back(now);
				now = fa[now];
			}
			circle.push_back(v);
			return ;
		}
		find_circle(v, x);
		if (circle.size()) return ;
	}
}

int main(){
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int u, v; scanf("%d%d", &u, &v);
		from[u].push_back(v);
		from[v].push_back(u);
	}
	if (m == n - 1){
		dfs(1, 1, 1);
		if (size[1] != 0){
			printf("-1\n");
			return 0;
		}
		long long ans = 0;
		for (int i = 1; i <= n; i++){
			ans += abs(size[i]);
		}
		printf("%lld\n", ans);
		return 0;
	}
	find_circle(1, 1);
	if (circle.size() & 1){
		s = circle[0], e = circle[1];
		dfs(s, s, 1);
		if (size[s] & 1){
			printf("-1\n");
			return 0;
		}
		val[s] -= size[s] / 2, val[e] -= size[s] / 2;
		long long ans = abs(size[s] / 2);
		dfs(s, s, 0);
		for (int i = 1; i <= n; i++){
			ans += abs(size[i]);
		}
		printf("%lld\n", ans);
	} else {
		s = circle[0], e = circle[1];
		dfs(s, s, 1);
		if (size[s]){
			printf("-1\n");
			return 0;
		}
		vector <int> all;
		int now = e;
		memset(vis, 0, sizeof(vis));
		while (now != s){
			all.push_back(size[now]);
			vis[now] = 1, now = fa[now];
		}
		vis[s] = 1, all.push_back(size[s]);
		sort(all.begin(), all.end());
		int pos = all[all.size() / 2];
		long long ans = 0;
		for (int i = 1; i <= n; i++){
			if (vis[i]) ans += abs(size[i] - pos);
			else ans += abs(size[i]);
		}
		printf("%lld\n", ans);
		return 0;
	}
	return 0;
}


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

int main(){
  int a,b;
  string op;
  while(cin >> a >> op >> b && op!="?"){
    if(op=="+")cout << a+b << endl;
    if(op=="-")cout << a-b << endl;
    if(op=="*")cout << a*b << endl;
    if(op=="/")cout << a/b << endl;
  }

  return 0;

  
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  int arr[m+1];
  memset(arr, 0, sizeof(arr));
  for(int i = 0;i<n;i++)
  {
    int k;
    cin >> k;
    while(k--)
    {
    	int u;
      	cin >> u;
      arr[u]++;
    }
  }
  int count = 0;
  for(int i =0 ;i<m+1;i++)
  if(arr[i] == n)
    count++;
  cout << count;
  return 0;
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
g = [[] for x in range(N+1)]
for i in range(N - 1):
  (a, b, c) = map(int, input().split())
  g[a].append([b, c])
  g[b].append([a, c])

(Q, K) = map(int, input().split())
d = [-1] * (N+1)
d[K] = 0
r = deque()

r.append(K)
while len(r) > 0:
  i = r.popleft()
  for v in g[i]:
    if(d[v[0]] == -1):
      d[v[0]] = d[i] + v[1]
      r.append(v[0])

q = list()
for i in range(Q):
  q.append(input())
for i in range(Q):
  (x, y) = map(int, q[i].split())
  print(d[x] + d[y])


Measured memory_bytes: 57132
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 21;

int T[maxN];

void solve()
{
	int a, b, c;
	scanf ("%d%d%d", &a, &b, &c);
	
	swap(a, b);
	swap(a, c);
	printf("%d %d %d\n", a, b, c);
}

int main()
{
	int t;
t=1;////	scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}


Measured memory_bytes: 768
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.container.dlist;

alias DL = DList!char;

class P {
  DL l;
  void add (int f, char c) {
    if (!f) {
      l.insertFront (c);
    } else {
      l.insertBack (c);
    }
  }
}

class S {
  string s;
  int rev;
  P prefix;
  P suffix;
  this (string _s) { 
    s = _s; 
    prefix = new P ();
    suffix = new P ();
  }
  void reverse () {
    ++rev;
  }
  void add (int f, char c) {
    if (!(rev & 1)) {
      if (f == 1) prefix.add (0, c);
      else suffix.add (1, c);
    } else {
      if (f == 2) prefix.add (0, c);
      else suffix.add (1, c);
    }
  }
  void dump () {
    if (!(rev & 1)) {
      foreach (c; prefix.l) write (c);
      write (s);
      foreach (c; suffix.l) write (c);
    } else {
      foreach_reverse (c; suffix.l) write (c);
      foreach_reverse (c; s) write (c);
      foreach_reverse (c; prefix.l) write (c);
    }
    writeln;
  }
  
}


void main() {
  auto s = readln.stripRight;
  auto z = readln.stripRight;
  const int nt = z.to!int;
  auto res = new S (s);
  foreach (tid; 0 .. nt) {
    z = readln.stripRight;
    auto w = z.splitter;
    const int t = w.front.to!int;
    w.popFront ();
    if (t == 1) {
      res.reverse ();
    } else {
      int f = w.front.to!int;
      w.popFront ();
      char c = w.front[0]; 
      res.add (f, c);
    }
    //res.dump ();
  }
  res.dump ();
}



Measured memory_bytes: 9112
members_count = int(input())

belong_map = {}

belongings = [int(x) for x in input().split(' ')]

for b in belongings:
    if b - 1 in belong_map:
        belong_map[b - 1] += 1
    else:
        belong_map[b - 1] = 1

for i in range(members_count):
    if i in belong_map:
        print(belong_map[i])
    else:
        print(0)


Measured memory_bytes: 38668
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
 
using namespace std;

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

    int N;

    cin >> N;

    vector<int> L(N);

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

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

    int count = 0;

    for(int i = 0; i < N - 2; i++) {
        int a = L[i];
        for(int j = i + 1; j < N - 1; j++) {
            int b = L[j];

            int left = b - a > a - b ? b - a + 1 : a - b + 1;
            int right = a + b;

            int l = lower_bound(L.begin() + j + 1, L.end(), left) - L.begin();
            /*
            if(l == 0) {
                l = j + 1;
            }*/
            int r = lower_bound(L.begin() + j + 1, L.end(), right) - L.begin();
            /*
            if(r == 0) {
                r = N + 1;
            }*/
            //cerr << left << " " << right << endl;
            //cerr << l << " " << r << endl;
        
//            if(r > l) {
                count += r - l;
//            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair < int, int > pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 1005;

int n, m, deg[MAXN], ans = 1, f[MAXN], v[MAXN], e[MAXN];

inline int Find(int x) { while (x ^ f[x]) x = f[x] = f[f[x]]; return x; }

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	for (int i = 1; i <= 1000; i ++)
		f[i] = i;
	while (n --)
	{
		int a = Read(), b = Read(), c = Read(), d = Read(), x = (!c ? a : -c) + 500, y = (!d ? -b : d) + 500;
		f[Find(x)] = Find(y);
		deg[x] ++; deg[y] --; v[x] = 1;
	}
	for (int i = 0; i < 500; i ++)
		if (deg[i] > 0)
			ans = 0;
	for (int i = 501; i <= 1000; i ++)
		if (deg[i] < 0)
			ans = 0;
	for (int i = 1; i <= 1000; i ++)
		v[Find(i)] |= v[i], e[Find(i)] |= deg[i] != 0;
	for (int i = 1; i <= 1000; i ++)
		if (Find(i) == i && v[i] && !e[i])
			ans = 0;
	return puts(ans ? "YES" : "NO"), 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;



int main() {
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	map<int, int> m;

	priority_queue<pii> pq;
	pq.push(make_pair(0, 0));
	vector<int> d(n, BIG_INT);

	d[0] = 0;

	while (!pq.empty()) {
		int v = pq.top().second;
		pq.pop();
		for (int u : g[v]) {
			if (d[u] == BIG_INT) {
				d[u] = min(d[u], d[v] + 1);
				pq.push(make_pair(d[u], u));
			}
		}
	}


	int cnt0 = 0;
	int cnt1 = 0;
	for (int i = 0; i < n; i++) {
		if ((d[i] & 1) == 0) {
			cnt0++;
		}
		else {
			cnt1++;
		}
	
	}
	vector<int> ans(n,-1);
	if (cnt0 * 3 < n) {
		int num = 3;
		for (int i = 0; i < n; i++) {
			if ((d[i] & 1) == 0) {
				ans[i] = num;
				num += 3;
			}
		}
		
		for (int i = 0; i < n; i++) {
			if ((d[i] & 1) == 1) {
				if (num <= n) {
					ans[i] = num;
					num += 3;
				}
				else {
					break;
				}

			}
		}
		num = 1;
		for (int i = 0; i < n; i++) {
			if (ans[i] == -1) {
				ans[i] = num;
				num++;
				if (num % 3 == 0) {
					num++;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			cout << ans[i] << " ";
		}
		return 0;
	}
	if (cnt1 * 3 < n) {
		int num = 3;
		for (int i = 0; i < n; i++) {
			if ((d[i] & 1) == 1) {
				ans[i] = num;
				num += 3;
			}
		}

		for (int i = 0; i < n; i++) {
			if ((d[i] & 1) == 0) {
				if (num <= n) {
					ans[i] = num;
					num += 3;
				}
				else {
					break;
				}

			}
		}
		num = 1;
		for (int i = 0; i < n; i++) {
			if (ans[i] == -1) {
				ans[i] = num;
				num++;
				if (num % 3 == 0) {
					num++;
				}
			}
		}


		for (int i = 0; i < n; i++) {
			cout << ans[i] << " ";
		}
		return 0;
	}

	int num1 = 1;
	int num2 = 2;
	int num = 3;
	for (int i = 0; i < n; i++) {
		if ((d[i] & 1) == 0 && num1 <= n) {

			ans[i] = num1;
			num1 += 3;

			continue;
		}
		if ((d[i] & 1) == 1 && num2 <= n) {

			ans[i] = num2;
			num2 += 3;
			continue;

		}

		ans[i] = num;
		num += 3;
	}

	for (int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	return 0;
}



Measured memory_bytes: 15984
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A,B;
  cin >> A >> B;
  cout << (A*B) - A - B + 1 << endl;
  return 0;
}

Measured memory_bytes: 3636
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(input())

    g = tuple(set() for _ in range(M * 2))
    ps = set()
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)
        ps.add(x)
        ps.add(y + M)

    visited = [0] * (M * 2)
    ans = 0
    for s in ps:
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x

    ans -= N

    print(ans)


if __name__ == '__main__':
    main()

# 連結成分ごとに
# x,yの二部グラフを完全二部グラフにする
# cnt(x)*cnt(y)-既存の辺数の総和

# 最後にN引けばよい


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

using namespace std;

typedef long long ll;

#define f first
#define s second

string t, s;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> s >> t;
  string aux = t + s;
  cout << aux;
  return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int dp[101][4][4][4];

const ll mod = 1e9+7;
int main()
{
	int n;
	cin >> n; 

	dp[0][3][3][3] = 1;
	rep(len,n){
		rep(i,4){//最後から1文字目
			rep(j,4){ // 最後から二文字目の文字
				rep(k,4){ // 最後から3文字目の文字
					// 条件に当てはまるものがない場合はcontinue;
					if(dp[len][i][j][k] == 0) continue;

					// 新しく追加する文字がない場合はcontinue;
					// aたらしく追加するも文字
					rep(a,4){
						if(a == 2 && i == 1 && j == 0) continue;
						if(a == 2 && i == 0 && j == 1) continue;
						if(a == 1 && i == 2 && j == 0) continue;
						if(a == 2 && i == 1 && k == 0) continue;
						if(a == 2 && j == 1 && k == 0) continue;

						dp[len+1][a][i][j] += dp[len][i][j][k];
						dp[len+1][a][i][j] %= mod;
					}
				}
			}
		}
	}
	int ans = 0;
	rep(c1,4){
		rep(c2,4){
			rep(c3,4){
				ans += dp[n][c1][c2][c3];
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3588
S = input()
T = input()
num = len(S)
C = ''
count = 0
if S == T:
    count += 1
    print('Yes')
else:
    for n in range(num):
        S = str(S[-1] + S[:num-1])
        if T == S:
            count += 1
            print('Yes')
            break

if count == 0:
    print('No')

Measured memory_bytes: 3064