akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  ll n; cin>>n;
  vector<ll> a(n),s(n+1);
  s[0]=0;
  for(ll i=0;i<n;i++){
    cin>>a[i];
    s[i+1]=s[i]+a[i];
  }
  
  sort(s.begin(),s.end());
  
  ll ans=0; 
  
  for(ll i=0;i<=n;i++){
    ll cp = s[i];
    ll res=1;
    while(cp==s[i+1]&&i<n){
      i++;
      res++;
    }
    ans+=res*(res-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+5,mod=998244353;
inline LL powmod(LL a,LL b){LL c=1;while(b){if(b&1)c=c*a%mod;a=a*a%mod;b>>=1;}return c;}
inline LL inv(LL x){return powmod(x,mod-2);}
inline void transform(int n,LL*x,int type)
{
	static LL w[N];
	for(int i=0,j=0;i<n;i++)
	{
		if(i>j)swap(x[i],x[j]);
		for(int k=n>>1;(j^=k)<k;k>>=1);
	}
	for(int i=2;i<=n;i<<=1)
	{
		int m=i>>1;LL wn=powmod(3,(mod-1)/i);if(type)wn=inv(wn);
		w[0]=1;for(int j=1;j<m;j++)w[j]=w[j-1]*wn%mod;
		for(int j=0;j<n;j+=i)
			for(int k=0;k<m;k++)
			{
				LL z=x[j+k+m]*w[k]%mod;
				x[j+k+m]=(x[j+k]-z+mod)%mod;
				x[j+k]=(x[j+k]+z)%mod;
			}
	}
	if(type)
	{
		LL nn=inv(n);
		for(int i=0;i<n;i++)x[i]=x[i]*nn%mod;
	}
}
inline void FFT(int n,int m,LL*x,LL*y)
{
	int p=1;while(p<n+m-1)p<<=1;
	for(int i=n;i<p;i++)x[i]=0;
	for(int i=m;i<p;i++)y[i]=0;
	transform(p,x,0);transform(p,y,0);
	for(int i=0;i<p;i++)x[i]=x[i]*y[i]%mod;
	transform(p,x,1);transform(p,y,1);
}
inline void FFT(int n,LL*x)
{
	int p=1;while(p<n+n-1)p<<=1;
	for(int i=n;i<p;i++)x[i]=0;
	transform(p,x,0);
	for(int i=0;i<p;i++)x[i]=x[i]*x[i]%mod;
	transform(p,x,1);
}
inline void get_pow(int n,LL*f,int m)
{
	static LL ans[N];
	memset(ans,0,sizeof(ans));
	ans[0]=1;
	while(m)
	{
		if(m&1)FFT(n,n,ans,f);
		FFT(n,f);
		m>>=1;
	}
	for(int i=0;i<n;i++)f[i]=ans[i];
}
LL fac[N],caf[N],x[N];
int n,num0,num1;
char s[N],t[N];
inline LL C(int n,int m){return fac[n]*caf[m]%mod*caf[n-m]%mod;}
inline LL update(LL&x,LL y){x=(x+y)%mod;}
int main()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='1'&&t[i]=='1')num0++;
		else if(s[i]=='1'&&t[i]=='0')num1++;
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	caf[n]=inv(fac[n]);for(int i=n-1;i>=0;i--)caf[i]=caf[i+1]*(i+1)%mod;
	for(int i=0;i<=num0;i++)x[i]=caf[i+1]%mod;
	int p=1;while(p<=num0)p<<=1;
	get_pow(p,x,num1);
	for(int i=0;i<=num0;i++)x[i]=x[i]*fac[num0]%mod*caf[num0-i]%mod;
	LL ans=0;
	for(int i=0;i<=num0;i++)update(ans,x[i]*fac[num0-i]%mod);
	printf("%lld\n",ans*fac[num0+num1]%mod*fac[num1]%mod);
	return 0;
}

Measured memory_bytes: 2688
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	if(n%10==9||n/10==9)cout<<"Yes"; else cout<<"No";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3584
n, m = list(map(int, input().split()))
k = []
a = []
for i in range(n):
    tmp = list(map(int, input().split()))
    k.append(tmp[0])
    a.append(tmp[1:])

ans = set(a[0])
for i in range(1, n, 1):
    ans = set(ans) & set(a[i])
print(len(ans))


Measured memory_bytes: 38256
n = int(input())
a = list(map(int, input().split()))
d = {}

for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1

count = 0
for i in d:
    count += d[i] * (d[i] - 1) // 2


for i in range(n):
    b = d[a[i]]
    print(count-b+1)

Measured memory_bytes: 86476
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
abcd = [[int(i) for i in input().split()] for _ in range(q)]
s = 0
for p in combinations_with_replacement(range(1, m + 1), n):
    t = 0
    for a, b, c, d in abcd:
        t += d * (p[b - 1] - p[a - 1] == c)
    s = max(s, t)
print(s)

Measured memory_bytes: 9116
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    if(B/A > C){
        cout << C << endl;
    }else{
        cout << B/A << endl;
    }

    return 0;
}

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

int S[100000];

bool check(int left,int right,int t){
  if(left+1 == right) return 0;
  int mid = (left+right)/2;
  if(S[mid] == t || S[left] == t) return 1;
  if(S[mid] < t) check(mid,right,t);
  else check(left,mid,t);
}

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n; i++){
    cin >> S[i];
  }
  int q; cin >> q;
  int ans = 0;
  for(int i = 0; i < q; i++){
    int t; cin >> t;
    ans += check(0,n,t);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3876
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int h,w,n,ans,colc;
char cmap[110][110];
bool used[110][110];
static const int dx[4] = {0,1,0,-1};
static const int dy[4] = {1,0,-1,0};

void display(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cout << cmap[i][j] << " ";
    cout << endl;
  }
  cout << endl;
}

void draw(char c,char t,int x,int y){
  cmap[y][x] = t;
  for(int i=0;i<4;i++){
    int nx = x+dx[i],ny = y+dy[i];
    if(0<=nx&&nx<w&&0<=ny&&ny<h&&c==cmap[ny][nx]){
      draw(c,t,nx,ny);
    }
  }
}

bool fin(){
  bool finish = true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(cmap[0][0] != cmap[i][j])return false;
    }
  }
  return true;
}

int search(int x,int y){
  used[y][x] = true;
  for(int i=0;i<4;i++){
    int nx = x+dx[i],ny = y+dy[i];
    if(0<=nx && nx <w && 0<=ny && ny<h && cmap[0][0] == cmap[ny][nx] && !used[ny][nx]){
      colc++;
      search(nx,ny);
    }
  }
}



void rec(int cnt){
  if(cnt >= ans)return;
  if(fin()){
    ans = min(ans,cnt);
    return;
  }
  //display();
  char A,B,erase[110][110];
  if(cmap[0][0] == 'R'){
    A = 'B'; B = 'G';
  }
  else if(cmap[0][0] == 'B'){
    A = 'R'; B = 'G';
  }
  else if(cmap[0][0] == 'G'){
    A = 'B'; B = 'R';
  }
  colc = 0;
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)used[i][j] = false;
  search(0,0);
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)erase[i][j] = cmap[i][j];
  draw(cmap[0][0],A,0,0);
  int precolc = colc;
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)used[i][j] = false;
  colc = 0;
  search(0,0);  
  if(colc != precolc)rec(cnt+1);
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)cmap[i][j] = erase[i][j];
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)used[i][j] = false;
  colc = 0;
  search(0,0);
  draw(cmap[0][0],B,0,0);
  precolc = colc;
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)used[i][j] = false;
  colc = 0;
  search(0,0);
  if(colc != precolc)rec(cnt+1);
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)cmap[i][j] = erase[i][j];

}

int main(){

  while(true){
    cin >> w >> h;
    if(w+h == 0)break;
    ans = (1<<29);
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> cmap[i][j];
      } 
    }

    rec(0);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		double total = 0;

		for(int i = 0; i < n; i++){
			double x = sc.nextDouble();
			String u = sc.next();

			if(u.equals("JPY")){
				total += x;
			}
			else {
				total += 380000.0*x;
			}
		}

		System.out.printf("%f\n",total);
	}

}


Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int search(int N, int M, vector<vector<int>> &s, vector<int> &p) {
    int count = 0;

    for(int i=0; i<pow(2, N); i++) {
        bitset<10> b(i);
        vector<int> q(M);
        for(int j=0; j<N; j++) {
            if(b[j]==1) {
                for(int k=0; k<M; k++) {
                    q[k] += s[k][j];
                }
            }
        }

        bool f = true;
        for(int j=0; j<M; j++) {
            f = f && ((p[j]+q[j]) % 2 == 0);
        }

        if(f)
            count++;
    }

    return count;
}

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

    vector<vector<int>> s(M);
    for(int i=0; i<M; i++) {
        int k;
        cin >> k;
        s[i] = vector<int>(N);
        for(int j=0; j<k; j++) {
            int si;
            cin >> si;
            s[i][si-1] = 1;
        }
    }

    vector<int> p(M);
    for(int i=0; i<M; i++)
        cin >> p[i];


    auto count = search(N, M, s, p);

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
moji=str(input())
lst=["A", "B", "D", "E", "F", "G", "H", "I", "J", "K"< "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
cnt = 0
temp = 0
for i in range(len(moji)):
  if i==0:
    if moji[i]=="A":
      continue;
    else:
      cnt+=1
      break;
  if 2<=i<=len(moji)-2:
    if moji[i] in lst:
      cnt +=1
      break;
    elif moji[i] == "C":
      temp += 1
      lst.append("C")
      continue;
  if i==1 or i==len(moji)-1:
    if moji[i] in lst or moji[i] == "C":
      cnt+=1
if cnt==0 and temp == 1:
  print("AC")
else:
  print("WA")
      
      

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,j,N,M,MIN;
int S[1000][2]={{},{}};
int C[50][2]={{},{}};
int F[1000]={};

scanf("%d %d",&N,&M);
for(i=0;i<N;i++){
scanf("%d %d",&S[i][0],&S[i][1]);
}

for(i=0;i<M;i++){
scanf("%d %d",&C[i][0],&C[i][1]);
}

for(i=0;i<N;i++){
MIN=abs(S[i][0]-C[0][0])+abs(S[i][1]-C[0][1]);
F[i]=1;
for(j=1;j<M;j++){
if(MIN>(abs(S[i][0]-C[j][0])+abs(S[i][1]-C[j][1]))){
MIN=abs(S[i][0]-C[j][0])+abs(S[i][1]-C[j][1]);
F[i]=j+1;
}
}
}

for(i=0;i<N;i++){
printf("%d\n",F[i]);
}
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    string color;
    
    cin >> N;
    cin >> color;
    
    int current_num = N;
    
    for (int i = 0; i < N; i++){
        if (N - 1 == i){
            break;
        }
        char current_color = color.at(i);
        char next_color = color.at(i + 1);
        if(current_color == next_color){
            current_num -= 1;
            continue;
        }
    }
    cout << current_num << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int fun(vector<int> &v)
{
	sort(v.begin(),v.end());

	if(v.size()%2 == 1)
	{
		int ans = 0;
		int m = v[(v.size()/2)];

		for(int i = 0; i < v.size(); i++)
		{
			ans += abs(v[i]-m);
		}
		return ans;
	}
	else
	{
		int ans1 = 0,ans2 = 0;
		int m1 = v[v.size()/2];
		int m2 = v[v.size()/2 - 1];
		for(int i = 0; i < v.size(); i++)
		{
			ans1 += abs(v[i]-m1);
			ans2 += abs(v[i]-m2);
		}
		return min(ans1,ans2);
	}
}
int32_t main()
{

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

    IOS


    char ch;
    cin >> ch;

    if(ch >='A' and ch <= 'Z')cout << 'A';
    else cout << 'a';




    return 0;
}


Measured memory_bytes: 3616
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
typedef long long ll;

using namespace std;

int main() {
	int N;
	cin >> N;
	vector <int> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d.at(i);
	}

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

	int ans = d.at(N / 2) - d.at(N / 2 - 1);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> v(H);
  for (int i = 0; i < v.size(); i++)
  	cin >> v.at(i);

  
  for (int i = 0; i < H+2; i++){
       if(i == 0 || i == H+1){
         for (int j = 0; j < W+2; j++)
          cout << "#";
       }else {
          cout << "#" <<v.at(i-1)<< "#" ;
       }
       cout << endl;
     }
  
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

struct Node{
    int key;
    Node *right,*left,*parent;
};

Node *root,*NIL;

Node *find(Node *u, int k){
    while(u!=NIL&&k!=u->key){
        if(k<u->key)u=u->left;
        else u=u->right;
    }
    return u;
}

void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else {
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preoder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preoder(u->left);
    preoder(u->right);
}
int main(){
    int i,n,x;
    string com;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        cin>>com;
        if(com[0]=='f'){
            scanf("%d",&x);
            Node *t=find(root,x);
            if(t!=NIL)printf("yes\n");
            else printf("no\n");
        }else if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }else if(com=="print"){
            inorder(root);
            printf("\n");
            preoder(root);
            printf("\n");
        }
    }
    return 0;
}



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

using lint = long long;

std::vector<lint> divs(lint n) {
    std::vector<lint> ret;
    for (lint p = 1; p * p <= n; ++p) {
        if (n % p != 0) continue;
        if (p != 1) ret.push_back(p);
        if (n / p != 1) ret.push_back(n / p);
    }
    return ret;
}

void solve() {
    lint n;
    std::cin >> n;

    auto ans = divs(n - 1);

    for (auto p : divs(n)) {
        auto m = n;
        while (m % p == 0) m /= p;
        if (m % p == 1) ans.push_back(p);
    }

    std::sort(ans.begin(), ans.end());
    ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
    std::cout << ans.size() << std::endl;
}

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

    solve();

    return 0;
}


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

int n;
long long l[1005],sp[1005];
long long ans;

int main(){

    cin>>n;
    for(int i=1;i<=n;i++){

        int x; cin>>x;
        ++l[x];

    }

    for(int i=1;i<=1000;i++)
        sp[i]=l[i]+sp[i-1];

    for(int i=1;i<=1000;i++){

        ans+=l[i]*(l[i]-1)*(l[i]-2)/6;

        ans+=(l[i]*(l[i]-1)/2)*(sp[min(2*i-1,1000)]-sp[i]);

        for(int j=i+1;j<=1000;j++){

            ans+=l[i]*l[j]*(sp[min(i+j-1,1000)]-sp[j]);

            ans+=l[i]*l[j]*(l[j]-1)/2;

        }

    }

    cout<<ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = long long;

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

void solve(){
    int a, b, x;
    cin >> a >> b >> x;
    if(a == x || (a < x && a+b >= x)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
 
using namespace std;

 
int main(){
    FIN;
    //freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
    int T = 5;
    int ans = 0;
    fore(cases,0,T){
        int val;cin>>val;
        if(!val)ans = (cases+1);
    }
    cout<<ans<<"\n";
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3656
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vvll edges;
vvll dp;
V<bool> visited;

void dfs(ll i, ll p) {
    if (visited[i]) return;
    visited[i] = true;
    dp[i][0] = dp[i][1] = 1;
    for (auto j: edges[i]) {
        if (j == p) continue;
        if (!visited[j]) dfs(j, i);
        dp[i][0] = (dp[i][0] * (dp[j][0] + dp[j][1]) % MOD) % MOD;
        dp[i][1] = dp[i][1] * dp[j][0] % MOD;
    }
    return;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    edges.resize(n);
    REP(i, n-1) {
        ll x, y; cin >> x >> y;
        edges[x-1].push_back(y-1);
        edges[y-1].push_back(x-1);
    }
    dp.resize(n, vll(2, 0));
    visited.resize(n, false);
    dfs(0, -1);
    cout << (dp[0][0] + dp[0][1]) % MOD << '\n';
    return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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; }

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i,n) cin >> a[i];
	int target = 1;
	int sum = 0;
	bool ok = false;
	rep(i,n) {
		if(a[i] != target) {
			sum++;
			continue;
		}
		target++;
		ok = true;
	}
	if(ok)cout << sum << endl;
	else cout << -1 << endl;
}

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

#define int long long

int N;

signed main()
{
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++)
    {
        for(int j = i; j <= N; j += i)ans += j;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Graph = vector<vector<int>>;

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pi = pair<int, int>;

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(), (a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF (int)1e9
#define INFL (long long)1e18
#define MOD (int)(1e9+7) 

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//template 
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}
template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
template<typename T>
string join(vector<T>& vec, string sep = " "){
  stringstream ss;
  for(int i=0; i<vec.size(); i++){
    ss << vec[i] << ( i+1 == vec.size() ? "" : sep );
  }
  return ss.str();
}

template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

template< typename T = ll >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}
template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

int main()
{
  	int k, n;
  	cin >> k >> n;
  	auto v = make_v<int>(n);
  	cin >> v;
    int max = 0;
    REPS(i, n-1){
        chmax(max,v[i]-v[i-1]);
    }
    chmax(max,k-v[n-1]+v[0]);
  	cout << k-max << endl;
    return 0;
}


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

int main() {
    long long x, e; cin >> x;
    int a = x % 11;
    if (a == 0) e = 0;
    else if (a <= 6) e = 1;
    else e = 2;
    cout << (x / 11) * 2 + e << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int>a(n+2); 
	for (int i = 1; i < n + 1; i++) {
		cin >> a[i];
	}
	
	long long sum = 0;
	for (int i = 0; i < n+1; i++) {
		sum += abs(a[i] - a[i + 1]);
	}

	for (int i = 1; i < n + 1; i++) {
		cout << sum + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
using ld = long double;
using ml = boost::multiprecision::cpp_int;

namespace NyaGadget
{
	/*** DFSライブラリ***/

#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)

	struct DFSnode
	{	// DFS NODE
		ll r = 0;  // root node
		ll s = 0;  // self node
	};

	struct DepthFirstSearchSample
	{	// これはテスト構造体なので、新しく定義すること。
		vector<ll> ans;
	};

	void DepthFirstSearchTest(DFSnode n, DepthFirstSearchSample& v)
	{	// これはDFS::Runの第三引数Updateの一例なので、新しく定義すること。
		v.ans[n.s] = v.ans[n.r] + 1;
	}

	struct DFS
	{
		using Edge = vector<ll>;
		vector<Edge> graph;

		DFS(ll size) { graph.resize(size); }
		vector<ll>& operator [](int n) { return graph[n]; }

		/**
		@brief 辺を追加する関数
		@note
		 頂点v1とv2を結ぶ辺を追加する。
		**/
		void CreateEdge(ll v1, ll v2)
		{	// 後戻りも出来るようにv1->v2とv2->v1の両方の辺を追加する
			graph[v1].push_back(v2);
			graph[v2].push_back(v1);
		}

		/**
		@brief 実行関数
		@param snode 開始ノード
		@param v 各ノード処理に必要な変数
		@param Update ノード毎の処理を定義した関数
		@note
		 大抵の場合、開始ノードは{0, 0}で良い。
		 Updateの処理に根と自身の頂点index情報が必要なので第一引数はDFSnodeにする。
		 頂点index情報以外で必要な変数はvで渡し、Updateの第二引数と変数vは同じ型にする。
		**/
		template <class T> void
		Run(DFSnode snode, T& v, function<void(DFSnode, T&)> Update)
		{
			Update(snode, v);

			each(i, e, graph[snode.s])
			{	// 後戻りしないようにする
				if (e == snode.r)
					continue;

				Run<T>({snode.s, e}, v, Update);
			}
		}
	};

#undef fori
#undef each

}

#define all(collection) (collection).begin(), (collection).end()              // begin to end
#define divc(a, b) ceil((ld) a / (ld) b);                                     // div ceiling
#define rep(i, begin, end) for (ll i = begin; i < end; i++)                   // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)                  // repeat reverse
#define size(collection) ((ll) (collection).size())                           // collection size
#define sum(begin, end) accumulate(all(begin, end), 0LL)                      // accumulate 
/********** const value **********/
#define llong_max 9223372036854775807                                         // 9 * 10^18
#define mod 1000000007                                                        // 1e9 + 7
#define pi 3.14159265                                                         // 3.14 ...
/********** for each macro **********/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

using namespace NyaGadget;

struct DFSV
{
	vector<ll> ans;
	vector<ll> memo;
};

void DFSF(DFSnode n, DFSV& v)
{
	v.ans[n.s] = v.ans[n.r] + v.memo[n.s];
}

int main(void)
{ 
	ll m1, d1; cin >> m1 >> d1;
	ll m2, d2; cin >> m2 >> d2;

	if (m1 != m2)
		cout << 1;
	else
		cout << 0;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000002

int beki(long long a,long long b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};


int main(){

	int N;
	cin>>N;
	
	int ans = 0;
	combi C(2000000);
	vector<int> cnt(N,0);
	for(int i=1;i<N;i++){
		int t = C.kaijou[i];
		t = mod(C.kaijou[N-1-i] * t);
		t = mod(C.combination(i-1,N-1-i)*t);
		cnt[i] = t;
		//ans = mod(ans + t);
	}
	
	for(int i=1;i<N;i++){
		ans = mod(ans + mod(cnt[i]-cnt[i-1])*i);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


int main(){fastio
    ll a,b,c;cin>>a>>b>>c;
    if((b-c)*(c-a)>0)cout<<"Yes";
    else cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int n;
long long c[101][101];

int main() {
  cin >> n;
  rep (i, n) rep (j, n) cin >> c[i][j];
  long long res = 0;
  rep (i, n) rep (j, i) res += min(c[i][j], c[j][i]);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1244
#include <algorithm>
#include <cstdio>
int mn[305][305], dis[305][305]; 
int main()
{
	int a, b; 
	scanf("%d%d", &a, &b); 
	for (int i = 1; i <= a; i++)
	{
		for (int j = 1; j <= b; j++)
		{
			scanf("%d", dis[i] + j); 
			for (int x = 0; x <= 100; x++)
			{
				for (int y = 0; y <= 100; y++)
					mn[x][y] = std::max(mn[x][y], dis[i][j] - i * x - j * y); 
			}
		}
	}
	for (int i = 1; i <= a; i++)
	{
		for (int j = 1; j <= b; j++)
		{
			bool f = false; 
			for (int x = 0; x <= 100; x++)
			{
				for (int y = 0; y <= 100; y++)
					f |= mn[x][y] + i * x + j * y == dis[i][j]; 
			}
			if (!f)
			{
				puts("Impossible"); 
				return 0; 
			}
		}
	}
	puts("Possible"); 
	printf("%d %d\n", 202, 101 * 101 + 100 * 2);
	for (int i = 1; i <= 100; i++)
		printf("%d %d X\n", i, i + 1);
	for (int i = 1; i <= 100; i++)
		printf("%d %d Y\n", i + 101, i + 102);
	for (int i = 0; i <= 100; i++)
	{
		for (int j = 0; j <= 100; j++)
			printf("%d %d %d\n", i + 1, 202 - j, mn[i][j]);
	}
	puts("1 202"); 
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

struct Node{ 
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL){
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if (y == NIL) root = z;
    else if (z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node *u){
    if (u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if (u == NIL) return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

int main(void)
{
    int n;
    string s;
    cin >> n;
    rep(i,n){
        cin >> s;
        if (s == "insert"){
            int key; cin >> key;
            insert(key);
        }
        else{
            inorder(root); cout << endl;
            preorder(root); cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26600
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    System.out.println((H-h) * (W-w));
  }
}

Measured memory_bytes: 22100
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

int main()
{
  int n,m;
  cin>>n>>m;
  if(n==m) puts("Yes");
  else puts("No");
  return 0;
}

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

using namespace std;

int main(){
    int size;
    cin >> size;
    int mat[size];
    for(int i=0;i<size;i++){
        cin >> mat[i];
    }
    int max_value=mat[1]-mat[0];
    int min_value=mat[0];
    for(int i=1;i<size;i++){
        max_value=max(max_value,mat[i]-min_value);
        min_value=min(min_value,mat[i]);
    }
    cout<<max_value<<endl;
    return 0;
}

Measured memory_bytes: 1940
/*
 VIVEK UPADHYAY
 MANIT, BHOPAL
 */

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;


#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)

typedef long long ll;
const int MAXN = 1e3 ;
const int MAX = 1e7;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e10 ;

int main(){
    
    int N = 999 ;
    int a,b ;
    cin >>a>>b ;
    int curr=1,next=0 ;
    for(int i=2;i<=999;i++){
        next= curr + i;
        if(curr - a >= 0 && next-b >= 0 && curr-a==next-b){
           // cout<<curr<<endl;
            cout<<(curr-a <= 0? 1 :curr-a )<<endl;
            return 0;
        }
        curr+=i ;
    }
    return 0;
}


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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll x,y;
    cin >> x >> y;
    
    ll ans = 1e12;
    if(y - x >= 0){
        ans = min(ans, y - x);
    }
    if(y + x >= 0){
        ans = min(ans, y + x + 1);
    }
    if(-y - x >= 0){
        ans = min(ans, - y - x + 1);
    }
    if(-y + x >= 0){
        ans = min(ans, -y + x + 2);
    }
    cout << ans << endl;
}


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


struct result {
	bool head_b, tail_a;
	int count;
	result(const std::string&s,int index_)
		:head_b{s[0]=='B'}
		, tail_a{s.back()=='A'}
		,count{}
	{
		auto pos = s.find("AB");
		while (pos != std::string::npos) {
			++count;
			pos = s.find("AB",pos+1);
		}

	}
	friend
		auto operator<<(std::ostream& os, const result& r)->std::ostream& {
		return
			os << (r.head_b ? 'T' : 'F' )<< ", "
				<< (r.tail_a ? 'T' : 'F' )<< ", "
				<< r.count ;
	}

	explicit operator bool()const {
		return this->head_b&& this->tail_a;
	}
};

int main() {
	int n;
	std::cin >> n;
	std::vector<std::string> vs(n);

	std::vector<result> vr;
	vr.reserve(n);


	int ac{}, bc{}, abc{}, count{};
	for (int i{}; i < n; ++i) {
		std::string t;
		std::cin >> t;
		vr.emplace_back(t,i);
	//	std::cout << vr[i]<<"\n";
		ac += vr[i].tail_a ? 1 : 0;
		bc += vr[i].head_b ? 1 : 0;
		abc += vr[i] ? 1 : 0;
		count += vr[i].count;
	}

//	std::cout << ac << " " << bc << " " << abc <<" "<< count<<"\n";
	auto m_ = std::min(ac, bc);
	auto ans = m_ - (abc >0 && abc == ac && bc == abc ? 1 : 0) + count;
	std::cout << ans << "\n";

	return 0; 
}

Measured memory_bytes: 384
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
K = int(input())
cnt = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x = a
            x = gcd(x,b)
            x = gcd(x,c)
            cnt += x
print(cnt)

Measured memory_bytes: 73832
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int ans = solve(S);

        System.out.println(ans);
    }

    private static int solve(String S) {
        int N = 0;

        for (int i=0; i<S.length(); i++) {
            N += S.charAt(i) == '+' ? 1 : -1;
        }

        return N;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define LL long long

int n;
LL W, w[105], v[105];
LL judge;

//int dfs(int now, LL rest, LL value)
//{
//    if(value >= judge) return 1;
//    if(now > n) return 0;
//    int flag1 = 0, flag2 = 0;
//    flag1 = dfs(now + 1, rest, value);
//    if(rest - w[now] >= 0) flag2 = dfs(now + 1, rest - w[now], value + v[now]);
//    if(flag1 + flag2 > 0) return 1;
//    return 0;
//}
//
//int C(LL x)
//{
//    judge = x;
//    if(dfs(1, W, 0)) return 1;
//    else return 0;
//}
//
//int main()
//{
//    while(~scanf("%d %lld", &n, &W))
//    {
//        LL sum = 0;
//        for(int i = 1; i <= n; ++i)
//        {
//            scanf("%lld %lld", &w[i], &v[i]);
//            sum += v[i];
//        }
//        LL l = 0, r = sum, mid;
//        while(l < r)
//        {
//            mid = (l + r) / 2;
//            if(C(mid)) l = mid + 1;
//            else r = mid;
//        }
//        mid = (l + r) / 2;
//        if(!C(mid)) l--;
//        printf("%lld\n", l);
//    }
//}

map<LL, LL> dp[105];

LL dfs(int i, LL cost)
{
    if(cost > W) return -10000000;
    if(i > n) return 0;
    if(dp[i].count(cost)) return dp[i][cost];
    return dp[i][cost] = max(dfs(i + 1, cost + w[i]) + v[i], dfs(i + 1, cost));
}

int main()
{
    while(~scanf("%d %lld", &n, &W))
    {
        for(int i = 1; i <= n; ++i) dp[i].clear();
        for(int i = 1; i <= n; ++i)
            scanf("%lld %lld", &w[i], &v[i]);
        LL ans = dfs(1, 0);
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 6272
import java.util.Scanner;
	public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int X = scanner.nextInt();
			    int A = scanner.nextInt();
			    int B = scanner.nextInt();
			    
			    if (B <= A) {
			    	System.out.println("delicious");
			    } else if ((B-A) <= X) {
			    	System.out.println("safe");
			    } else {
			    	System.out.println("dangerous");
			    }
		}
		}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if(b+c>a){
		ans = b+c-a;
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
N, K, C = map(int, input().split())
S = input()

L = []
lenL = 0
R = []
lenR = 0

c = 0
for i in range(N):
    if S[i] == 'o' and c <= 0:
        L.append(i + 1)
        lenL += 1
        if lenL == K:
            break
        c = C
    else:
        c -= 1

c = 0
for i in list(range(N))[::-1]:
    if S[i] == 'o' and c <= 0:
        R.append(i + 1)
        lenR += 1
        if lenR == K:
            break
        c = C
    else:
        c -= 1

for i in range(K):
    if L[i] == R[K - i - 1]:
        print(L[i])


Measured memory_bytes: 27468
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int a[5];
	for (int i = 1; i <= 4; ++i)
		cin >> a[i];
	sort(a + 1, a + 5);
	if (a[1] * 1000 + a[2] * 100 + a[3] * 10 + a[4] == 1479)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> X(N);
    rep(i,N)cin >> X[i];

    LL ans = INF;
    for(int i = 1;i <= 100;++i){
        LL tmp = 0;
        rep(j,N){
            tmp += abs(X[j] - i)*abs(X[j] - i);
        }
        chmin(ans,tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int n;
  cin>>n;
  cout<<n*n*n;
}


Measured memory_bytes: 256
//             بسم الثالوث الاقدس

#include<iostream>	
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
//********************************************************************************************
//******************************************************************************************** 
/*
jesus help me.......
*/
typedef long long lld;
typedef char c;

				
bool prime(int x)
{
	if (x == 1)
		return false;
	else if (x == 2)
		return true;
	for (int i = 2; i*i <= x; i++)
	{
		if (x%i == 0)
			return false;

	}
	return true;
}
void fun2(int t)
{
	if (t == 1)
	{
		cout << "*";
		return;
	}
	cout << "*";
	return fun2(t - 1);
}

void fun(int s)
{
	map<int, int>asd;
	map<int, int>::iterator ir;
	ir = asd.begin();
	ir->first;
	if (s)
	{
		cout << s % 10 << endl;
		fun(s / 10);
		
	}
}
long long numb(long long i){
	if ( i == 2 || i == 1)
		return 1;
	else{
		long long n = i, z = 0;
		while (n>1){
			if (i%n == 0){
				z++;
			}
			n--;
		}
		return z;
	}

}

/*
jesus help me.......
jesus help me.......
jesus help me.......
*/

int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	char a, b,c;
	cin >> a >> b;
	if (a < b)
	{
		c = '<';
	}
	else if (a > b)
		c = '>';
	else
		c = '=';
	cout << c << endl;
	///system("pause");
	return 0;
}
/*
jesus help me.......
jesus help me.......
jesus help me.......
*/

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int c[5];
  set<int>se;
  rep(i,0,3){
    cin>>c[i];
    se.insert(c[i]);
  }

  out(se.size());

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 610005
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|
  
   
void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}
  
int TREE_MINIMUM(int x){
  while(left2[x] != NIL){
    x = left2[x];
  }
  return x;
}
  
  
int TREE_SUCCESSOR(int x){
  if(right2[x] != NIL)return TREE_MINIMUM(right2[x]);
  int y = p[x];
  while(y != NIL && x == right2[y]){
    x = y;
    y = p[y];
  }
  return y;
}
   
void TREE_DELETE(int z){
  int y,x;
  if(left2[z] == NIL || right2[z] == NIL)y = z;
  else y = TREE_SUCCESSOR(z);
  
  if(left2[y] != NIL)x = left2[y];
  else x = right2[y];
  
  if(x != NIL)p[x]=p[y];
  if(p[y] == NIL)root = x;
  else if(y == left2[p[y]])left2[p[y]] = x;
  else right2[p[y]] = x;
  
  if(y != z)key[z] = key[y];
  
}
  
  
bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}
  
   
void TREE_INSERT(int z){
  int y = NIL; 
  int x = root;
   
  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }
   
}
  
int IndexSearch(int x){
  for(int i=0;i<MAX;i++){
    if(key[i] == x)return i;
  }
  return -1;
}
  
  
void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}
   
void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}
   
   
int main(){
  int val;
  string op;
  long long zr;                    
  
   
  scanf("%d",&n);
  Init(); 
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;        
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
    printf("yes\n");
      }else{
    printf("no\n");
      }
         
   
    }
    else if(op == "delete"){
      scanf("%d",&val);
      int inthis = IndexSearch(val);
      if(inthis != -1){
      TREE_DELETE(inthis);
      }
    }
  
  }
   
  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;
  
  return 0;
}

Measured memory_bytes: 12324
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int x = sc.nextInt();
        int res = 0,flag=1;
        int[] l= new int[n];
        for(int i=0;i<n;i++){
          l[i]=sc.nextInt();
          res+=l[i];
          if(res>x){
            break;
          }
          flag++;
        }
        System.out.println(flag);
    }

}




Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;

int 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;
    return 0;
}


Measured memory_bytes: 256