akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur=nil->next;
  while(cur!=nil && cur->key != key) cur=cur->next;
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32956
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    vector<string> f(H);
    for (int i=0;i<H;++i) cin >> f[i];
    int sx,sy;
    for (int i=0;i<H;++i)
        for (int j=0;j<W;++j)
            if (f[i][j]=='%')
                sx=i,sy=j;
    vector<vector<int>> dist(H,vector<int>(W,-1));
    queue<pair<int,int>> que;
    dist[sx][sy]=0; que.emplace(sx,sy);
    int princess,soldiar=INF;
    while(!que.empty()){
        auto p=que.front(); que.pop();
        int x=p.first,y=p.second;
        for (int i=0;i<4;++i){
            int nx=x+dx[i],ny=y+dy[i];
            if (nx<0||H<=nx||ny<0||W<=ny) continue;
            if (f[nx][ny]=='#') continue;
            if (dist[nx][ny]!=-1) continue;
            dist[nx][ny]=dist[x][y]+1;
            que.emplace(nx,ny);
            if (f[nx][ny]=='@') princess=dist[nx][ny];
            if (f[nx][ny]=='$') soldiar=min(soldiar,dist[nx][ny]);
        }
    }
    cout << (princess<soldiar?"Yes":"No") << '\n';
}


Measured memory_bytes: 3344
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
LL N; 
map<LL,LL> DP; 
LL dp(LL x)
{
    if(DP[x]) return DP[x];
    else
    {
        return DP[x] = ( dp(x/2) + dp((x-1)/2) + dp((x-2)/2) )%mod;
    }
}
int main()
{
    //std::ios::sync_with_stdio(false);
    DP[0] = 1;
    DP[1] = 2;
    cin >> N;
    cout << dp(N) << endl;
   // system("pause");
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[0]==s[1] && s[1]==s[2]) cout << "Yes" << endl;
  else if(s[1]==s[2] && s[2]==s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	int ans=0;
	cin>>b>>a;
	for(int i=0;i<=b;i++)
	{
		for(int j=0;j<=b;j++)
		{
			int k=a-i-j;
			if(k>=0&&k<=b)
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
 } 

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

int main(){
  string s="MARCH";
  long long c[5]={0};//複数の文字の場合には1番最後に'0'が付くため、3文字でも配列を4つ宣言している
  long long n;
  cin >> n;
  for (long long i=0;i<n;++i){
    string t;
    cin >> t;
    for (int j=0;j<5;++j){
      if (t[0]==s[j]){
        c[j]++;
      }
    }
  }
  long long ans=0;
  for (int i=0;i<5;++i){
    for (int j=i+1;j<5;++j){
      for (int k=j+1;k<5;++k){
        ans+=c[i]*c[j]*c[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int mod = 1e9+7;
const int inf = (1<<28);
const ll infl = (1LL<<60);

int main() {
  int N, R; cin >> N >> R;
  int ans = R;
  if (N < 11) {
    ans += 100 * (10 - N);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  char ch;
  cin >> ch;

  if('a' <= ch && ch <= 'z')
    cout << 'a' << endl;
  else if('A' <= ch && ch <= 'Z')
    cout << 'A' << endl;
}

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

int h,w,k;

int ans=0;
char a[10][10];

bool check(int s1,int s2){
    bool f[10][10]={};
    int i,j,tot=0;
    
    for(i=0;i<h;i++)
		if((s1>>i)&1)
			for(j=1;j<=w;j++)
				f[i+1][j]=true;
				
	for(i=0;i<w;i++)
		if((s2>>i)&1)
			for(j=1;j<=h;j++)
				f[j][i+1]=true;
				
	for(i=1;i<=h;i++)
		for(j=1;j<=w;j++)
			if(!f[i][j] && a[i][j]=='#')
				tot++;
				
	return tot==k;
}

int main(){
    cin>>h>>w>>k;
    
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin>>a[i][j];
    
    int s1,s2;
    
    for(s1=0;s1<(1<<h);s1++)
		for(s2=0;s2<(1<<w);s2++)
			if(check(s1,s2))
				ans++;
                
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3636
N, K = gets.split(' ').map(&:to_i)
R, S, P = gets.split(' ').map(&:to_i)
T = gets.chomp

hand_to_score_hash = { 'r' => R, 's' => S, 'p' => P }
win_hand_map = { 'r' => 'p', 's' => 'r', 'p' => 's' }
total_score = 0
N.times do |i|
  win_hand = win_hand_map[T[i]]
  add_score = hand_to_score_hash[win_hand]
  if i >= K && T[i] == T[i - K]
    add_score = 0
    T[i] = 'n'
  end
  total_score += add_score
end
puts total_score


Measured memory_bytes: 2044
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn solve() -> bool {
    let x: i32 = read();
    let n = x / 100;
    x >= 2000 || (100 * n <= x && x <= 105 * n)
}
fn main() {
    println!("{}", if solve() {1} else {0});
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;++i)
#define f2(n) for(int i=1;i<=n;++i)
#define lson(x) x<<1
#define rson(x) x<<1|1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int maxn = 2e3 + 5;
const int mod = 0x3f3f3f3f;
const ll Mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll Inf = (ll)1e15;
int dis[maxn][maxn];
map<int, int>p;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n, x, y;
	cin >> n >> x >> y;

	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
			dis[i][j] = dis[j][i] = j - i;
		}
	}

	dis[x][y] = dis[y][x] = 1;
	int k = x;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (dis[i][j] > dis[i][k] + dis[k][j]) {
				dis[i][j] = dis[i][k] + dis[k][j];
			}
		}
	}
	k = y;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (dis[i][j] > dis[i][k] + dis[k][j]) {
				dis[i][j] = dis[i][k] + dis[k][j];
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			p[dis[i][j]]++;
		}
	}
	for (int i = 1; i < n; ++i) {
		cout << p[i] << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 16000
#include<stdio.h>
int a[100008];
int main()
{
	int n;
	scanf("%d",&n);
	if(n>81)
        printf("No\n");
    else if(n<10)
        printf("Yes\n");
    else{
        for(int i=2;i*i<=n;i++){
            if(n%i==0){
                if(i<10&&(n/i)<10){
                    printf("Yes\n",i,n/i);
                    return 0;
                }
            }
        }
        printf("No\n");
    }
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr int MAX = 2000200;

using namespace std;

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

	cout << 180 * (n - 2) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long double  A,B;
    cin >> A >> B;
    
    int X=-1;
    vector<int> AList(10);
    vector<int> BList(10);
    
    for (int i=0;i<10;i++) {
        AList[i] = 12.5*(A+0.1*i);
        BList[i] = 10*(B+ 0.1*i);
    }
    
    bool end = false;
    for (int i=0;i<10;i++) {
        for (int j=0;j<10;j++) {
            if(AList[i]==BList[j]) {
                X=AList[i];
                int judge = X*0.08;
                if(judge==A) {
                    end=true;
                    break;
                }
                else {
                    continue;
                }
                
            }
        }
        if(end) {
            break;
        }
    }
    cout << X << endl;
   
}

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

using namespace std;

const int N = 200005;
int val[N];
int n, q;
vector <int> e[N];

void dfs(int u, int p) {
    val[u] += val[p];
    for (auto v: e[u]) {
        if (v != p) {
            dfs(v, u);
        }
    }
}

int main() {
    cin >> n >> q;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        e[x].emplace_back(y);
        e[y].emplace_back(x);
    }
    for (int i = 1; i <= n; i++) {
        val[i] = 0;
    }
    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        val[p] += x;
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        cout << val[i] << " ";
    }
    return 0;
}


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

import itertools

li=[]

for i in range(3,11):
  for j in itertools.product("357", repeat=i):
    if "3" in j and "5" in j and "7" in j:
      li.append(int("".join(j)))
i=0
while li[i]<=n:
  i+=1
print(i)

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 H,W,N;
    cin >> H >> W >> N;

    i64 sr,sc;
    cin >> sr >> sc;
    --sr;
    --sc;

    string S,T;
    cin >> S >> T;

    i64 left=0,right=W-1,top=0,bottom=H-1;
    for(i64 i=N-1; i>=0; --i){
        if(T[i]=='L') ++right;
        else if(T[i]=='R') --left;
        else if(T[i]=='U') ++bottom;
        else if(T[i]=='D') --top;

        chmin(right,W-1);
        chmax(left,i64(0));
        chmin(bottom,H-1);
        chmax(top,i64(0));

        if(S[i]=='L') ++left;
        else if(S[i]=='R') --right;
        else if(S[i]=='U') ++top;
        else if(S[i]=='D') --bottom;

        if(left>right or top>bottom){
            cout << "NO" << endl;
            return;
        }
    }

    if(left<=sc and sc<=right and top<=sr and sr<=bottom) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 920
#include <stdio.h>

int main(void) {
    
    int arr[3],i,ans;
    for(i=0;i<3;i++)
        scanf("%d",&arr[i]);
    ans = arr[1]/arr[0];
    if(ans>=arr[2]){
        if(ans<=arr[2])
            printf("%d",ans);
        else
            printf("%d",arr[2]);
    }else if(ans < arr[2]){
        printf("%d",ans);
    }
    
    return 0;
}



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


int main(){
    int x;
    cin >> x;
    int count = 1;
    int a = x;
    while(a!=0){
        a+=x;
        count++;
        a%=360;
    }
    cout << count << endl;

}


Measured memory_bytes: 3612
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable : 4996)  // VSでscanfを使う．
#endif

signed main() {
  int n, x;
  cin >> n >> x;

  int ans = 0;
  int lsum = 0;
  for (int i = 0; i < n; i++) {
    if (lsum > x) {
      break;
    }

    ans++;

    int l;
    cin >> l;
    lsum += l;
  }

  if (lsum <= x) {
    ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int k, s;
  long long int count=0;
  cin >> k >> s;
  for (int i=0; i<=min(k,s); i++) {
    for (int j=0; j<=min(k,s-i); j++) {
      if (s-i-j<=k) count++;
    }
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int n; cin >> n;
    vector<pair<int,int> > v;
    int sum;
    if (n % 2 == 0) sum = n+1;
    else sum = n;

    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < i; j++){
            if (i+j == sum) continue;
            else v.push_back({i,j});
        }
    }
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++){
        cout << v[i].first << " " << v[i].second << endl;
    }
}
  



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <deque>

using namespace std;

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

	list <double> l;
	list <double> ans;
	list <double>::iterator li;
	list <double>::iterator li2;
	list <double>::iterator fromli;
	list <double>::iterator endli;

	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++){
		char c = s[i];
		if (c == '\\'){
			l.push_back(-1);
		}
		else if (c == '/'){
			l.push_back(-2);
		}
		else{
			l.push_back(-3);
		}
	}
	bool flag;
	bool loopflag;
	do{
		loopflag = false;
		flag = false;
		for (li = l.begin(); li != l.end(); li++){
			if (*li == -1){
				fromli = li;
				flag = true;
			}
			else if (*li == -2 && flag){
				loopflag = true;
				endli = li;
				for (li2 = fromli; li2 != endli; li2++){
					if (*li2 == -3){
						*li2 = 1;
					}
					else if (*li2 > 0){
						*li2 += 1;
					}
				}
				*fromli = 0.5;
				*endli = 0.5;
				break;
			}
		}
	}while(loopflag);

	double sum = 0;
	for (li = l.begin(); li != l.end(); li++){
		if (*li > 0){
			sum += *li;
		}
	}
	cout <<(long long int) sum << endl;
	bool start = false;
	for (li = l.begin(); li != l.end(); li++){
		if (*li < 0){
			continue;
		}
		if (*li == 0.5){
			start = !start;
			if (start){
				ans.push_back(*li);
			}
		}
		if (start){
			ans.back() += *li;
		}
	}
	cout << ans.size();
	for (li = ans.begin(); li != ans.end(); li++){
		cout << " " <<(long long int) *li;
	}
	cout << endl;

return 0;
}

Measured memory_bytes: 1932
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int
lli N, K;
vector<lli> A, B;
void solve(long long N, long long K, std::vector<long long> A,
           std::vector<long long> B)
{
  // K最上位ビットが立ってないもののみ使う場合はすべて使える
  // Kの最上位ビットがたってるかつ, それ未満の場合
  lli ans = 0;

  rep(j, N) if ((A[j] & ~K) == 0) ans += B[j];
  rrep(i, 31)
  {
    // (i) not use
    lli ret = 0;
    if ((K >> i) & 1)
    {
      // i番目ビットを使わない => iより大きいビットがK（ビットで)以下のものは使える
      rep(j, N) if (((A[j] >> i) & (~(K >> i))) == 0 && ((A[j] >> i) & 1) == 0) ret += B[j];
      //cout << i << " " << ret << endl;
      chmax(ans, ret);
    }
    // (ii) use
  }
  cout << ans << endl;
}
signed main()
{
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, K, std::move(A), std::move(B));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
        var B = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var C = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sum = 0;
        int last= -2;
        for (int i = 0; i < N; i++)
        {
            sum += B[A[i]];
            if (last + 1 == A[i]) sum += C[last];

            last = A[i];
        }
        Console.WriteLine(sum);
    }
}

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

int w,h;

void print(int map[WMAX][HMAX]){
  rep(i,h){
    rep(j,w){
      printf("%d ",map[j][i]);
    }
    putchar('\n');
  }
  putchar('\n');
}

void init_map(int map[WMAX][HMAX]){
  rep(i,HMAX){
    rep(j,WMAX){
      map[j][i]=0;
    }
  }
}

int dd[5]={0,1,0,-1,0};

void dfs_aux(int sx, int sy, int map[WMAX][HMAX],int *min,int count){
  rep(r,4){
    int nx=sx,ny=sy;
    if(map[nx+dd[r]][ny+dd[r+1]]==1)
      continue;
    while(0<=nx+dd[r] && nx+dd[r]<w && 0<=ny+dd[r+1] && ny+dd[r+1]<h){
      nx+=dd[r];
      ny+=dd[r+1];
      
      if(map[nx][ny]==3)
	if(*min > count){
	  *min = count;
	  break;
	}
      
      if(map[nx][ny]==1){
	break;
      }

    }
    
    if(map[nx][ny]==1 && count <10){
      map[nx][ny]=0;
      nx-=dd[r];ny-=dd[r+1];
      /*
	int tmp=map[nx][ny];
	map[nx][ny]=9;
	print(map);
	map[nx][ny]=tmp;
      */
      dfs_aux(nx,ny,map,min,count+1);
      nx+=dd[r];ny+=dd[r+1];
      map[nx][ny]=1;
    }
  }
}  

int dfs(int sx, int sy, int map[WMAX][HMAX]){
  int min=11;
  dfs_aux(sx,sy,map,&min,1);
  if(min>10)
    return -1;
  return min;
}

int main(){
  for(;;){
    scanf("%d %d",&w,&h);
    if(!(w+h)) break;
    int map[WMAX][HMAX],sx,sy;
    init_map(map);
    rep(i,h){
      rep(j,w){
	scanf("%d",&map[j][i]);
	if(map[j][i]==2){
	  sx=j;
	  sy=i;
	}
      }
    }
    printf("%d\n",dfs(sx,sy,map));
  }
}

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

using namespace std;

map<int, map<int, int> > W;

int getWeight(int left, int top)
{
  return W[left][top]+W[left+1][top]+W[left][top+1]+W[left+1][top+1];
}

int main()
{
  int N; cin >> N;
  vector<int> x(N), y(N);
  for(int i = 0; i < N; i++) {
   cin >> x[i] >> y[i];
   cin >> W[x[i]][y[i]];
  }
  int ans = 0;
  for(int i = 0; i < N; i++) {
    ans = max(ans, getWeight(x[i]-1, y[i]-1));
    ans = max(ans, getWeight(x[i]-1, y[i]));
    ans = max(ans, getWeight(x[i], y[i]-1));
    ans = max(ans, getWeight(x[i], y[i]));
  }
  cout << ans << " / 1" << endl;
  
  return 0;
}

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

int main(){
  int h,n;
  cin >> h >> n;
  int damage=0;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    damage+=x;
  }
  if(h>damage) cout << "No" << endl;
  else cout << "Yes" << endl;
  
}

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

int main(){
    string s;
    cin >> s;
    int N = s.size();
    s += 'D';
    ll a=0;
    ll ans = 0;
    int p = 0;
    while (p < N) {
        if (s[p] == 'A') {
            a++;
        }else if (s[p] == 'B') {
            if (s[p+1] == 'C') {
                ans += a;
                p++;
            }
            else a = 0;
        }else a = 0;
        p++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();

		System.out.println(calc(x, y));
	}

	private static int calc(int x, int y) {
		if (x < y) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		while (y > 0) {
			int r = x % y;
			x = y;
			y = r;
		}

		return x;
	}
}

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

using namespace std;

#define ll long long
#define MAX 100005
#define INF 123456789101112
ll dp[MAX][105];
ll w[105], v[105];

int main()
{
    ll n, cap;
    scanf("%lld %lld", &n, &cap);
    for(ll i=1; i<=n; i++){
		scanf("%lld %lld", &w[i], &v[i]);
    }
    for(ll i=0; i<MAX; i++) for(ll j=0; j<105; j++) dp[i][j] = INF;
    for(ll j=0; j<105; j++) dp[0][j] = 0;
    for(ll i=1; i<=n; i++){
        for(ll j=0; j<MAX; j++){
            if(v[i] > j){
                dp[j][i] = dp[j][i-1];
                continue;
            }
            dp[j][i] = min(dp[j][i-1], dp[j-v[i]][i-1]+w[i]);
        }
    }
    ll ans = 0;
    for(ll i=0; i<MAX; i++) if(dp[i][n] <= cap) ans = i;
    printf("%lld\n", ans);
}


Measured memory_bytes: 82304
using System;

namespace abc96_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int answer = 0;
            string[] inputs = Console.ReadLine().Split(' ');
            int times = int.Parse(Console.ReadLine());
            int[] numbers = Array.ConvertAll(inputs, int.Parse);
            Array.Sort(numbers);
            for (int i = 0; i < times; i++)
            {
                numbers[2] = numbers[2] * 2;
            }
            answer = numbers[0] + numbers[1] + numbers[2];
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11092
import java.io.*;

class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int n = Integer.parseInt(line);
			line = reader.readLine();
			char[] s = line.toCharArray();
			int count_ABC = 0;

			for(int i = 0; i < n-2; i++){
				if((s[i] == 'A') && (s[i+1] == 'B')){
					if((s[i+2] == 'C') && (s[i+1] == 'B')){
						count_ABC ++;
					}
				}
			}
			System.out.println(count_ABC);
		}catch(IOException e){

			System.out.println(e);
			System.exit(0);

		}catch(NumberFormatException e){

			System.out.println(e);
			System.exit(0);
		}
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(void) {
    while(true) {
        int N;
        cin>>N;
        if(N==0) break;
        vector<vector<bool> > map(21, vector<bool>(21, false));
        int set = 0;
        REP(i, N) {
            int x, y;
            cin>>x>>y;
            map[x][y] = true;
        }
        int nx = 10, ny = 10;
        int ans = 0;
        if(map[nx][ny]) {
            ++ans;
            map[nx][ny] = false;
        }
        int M;
        cin>>M;
        REP(i, M) {
            char dir;
            int l;
            cin>>dir>>l;
            if(dir == 'E') {
                REP(j, l) {
                    nx = nx + dx[0];
                    ny = ny + dy[0];
                    if(map[nx][ny]) {
                        ++ans;
                        map[nx][ny] = false;
                    }
                }
            }
            if(dir == 'N') {
                REP(j, l) {
                    nx = nx + dx[1];
                    ny = ny + dy[1];
                    if(map[nx][ny]) {
                        ++ans;
                        map[nx][ny] = false;
                    }
                }
            }
            if(dir == 'W') {
                REP(j, l) {
                    nx = nx + dx[2];
                    ny = ny + dy[2];
                    if(map[nx][ny]) {
                        ++ans;
                        map[nx][ny] = false;
                    }
                }
            }
            if(dir == 'S') {
                REP(j, l) {
                    nx = nx + dx[3];
                    ny = ny + dy[3];
                    if(map[nx][ny]) {
                        ++ans;
                        map[nx][ny] = false;
                    }
                }
            }
        }
        if(ans == N) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}




Measured memory_bytes: 3072
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N, K = map(int, inp().split())
R, S, P = map(int, inp().split())
T = inpS()

#r, s, pで勝つ時のスコア
dp = [[0] * 3 for _ in range(K)]

for i in range(K):
  if T[i] == "s":
    dp[i][0] = R
  elif T[i] == "p":
    dp[i][1] = S
  else:
    dp[i][2] = P
    
for i in range(K, N):
  k = i%K
  if T[i] == "s":
    dp[k][0], dp[k][1], dp[k][2] = max(dp[k][1], dp[k][2])+R, max(dp[k][0], dp[k][2]), max(dp[k][0], dp[k][1]) 
  elif T[i] == "p":
    dp[k][0], dp[k][1], dp[k][2] = max(dp[k][1], dp[k][2]), max(dp[k][0], dp[k][2])+S, max(dp[k][0], dp[k][1]) 
  else:
    dp[k][0], dp[k][1], dp[k][2] = max(dp[k][1], dp[k][2]), max(dp[k][0], dp[k][2]), max(dp[k][0], dp[k][1])+P
    
ans = 0
for tmp in dp:
  ans += max(tmp)
print(ans)  
    
  

Measured memory_bytes: 12484
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
 
  // 入力
  long long int n;
  scanf("%lldd",&n);
  long long int cnt=0;

  for(long long int i=1;i<n;i++){
    cnt+=i;
  }
  
  printf("%lld\n",cnt);
 
  return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    cout << fixed << setprecision(5);

    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int norm = 0;
            for (int k = 0; k < D; ++k) {
                int diff = abs(X[i][k] - X[j][k]);
                norm += diff * diff;
            }
            // check whether norm = k for some k
            bool flag = false;
            for (int k = 0; k <= norm; ++k) {
                if (k * k == norm) {
                    flag = true;
                }
            }
            if (flag) ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque

#幅優先探索でラベリング
def bfs(x, graph, people):
    #people[x] is None -> まだ訪問していない．訪問していたらなラベルがつくので，
    if people[x] is not None:
        return
    unvisited = deque([x])
    people[x] = 0
    while unvisited:
        now = unvisited.popleft()
        for Next, d in graph[now]:
            if people[Next] is None:
                people[Next] = people[now] + d
                unvisited.append(Next)

def main():
    N, M = list(map(int, input().split()))
    graph = [ [] for i in range(N+1)]
    people = [None] * (N+1)

    #グラフの作成
    for i in range(M):
        L, R, D = list(map(int, input().split()))
        graph[L].append((R, D))
        graph[R].append((L, -D))
    #全ての頂点でサーチ ->ラベリングを行う
    for i in range(1,N+1):
        bfs(i, graph, people)

    for i in range(1,N+1):
        for j,d in graph[i]:
            if people[j] - people[i] != d:
                print("No")
                exit()
    print("Yes")
if __name__ == '__main__':
    main()


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define RE(i,n) FOR(i,1,n)
#define R(i,n) REP(i,n)
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define VI vector<int>
#define PII pair<int,int>
#define LD long double

template<class C> void mini(C& a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  string z;
  cin >> z;
  int n = SZ(z);
  map<char,int> il;
  for(int el:z){
    il[el]++;
  }
  int res = n * (n-1) / 2 + 1;
  for(auto el:il){
    res -= el.SE * (el.SE - 1) / 2;
  }
  cout << res << "\n";
}


Measured memory_bytes: 720
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(a+b==c||b+c==a||c+a==b)
    {
        cout<<"Yes"<<endl;
    }
else
{
    cout<<"No"<<endl;
}



return 0;
}


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

int N, D, X;

int main() {
  cin >> N >> D >> X;
  for(int i = 0; i < N; ++i) {
    int a; cin >> a;
    X += (D - 1) / a + 1;
  }
  cout << X << endl;
  return 0;
}


Measured memory_bytes: 256
// Maximum Sum

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int num[3], K;
	cin >> num[0] >> num[1] >> num[2] >> K;

	sort(num, num+3);

	cout << num[0] + num[1] + (int)pow(2, K) * num[2] << endl;

	return 0;
}

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

#define rep(i,n) for(int i = 0; i<(n); i++)
using namespace std;
using ll = long long;

int main (){
   int n, k;
   vector<vector<int>> A(100, vector<int>(100));
   vector<int> d(100);
   cin >> n >> k;
  rep(i,k) {
     cin >> d[i];
    rep(j,d[i]){
       cin >> A[i][j];
     }
   }
  vector<int> sunuke(n);
  rep(i,n){
    sunuke[i] = 0;
  }
  rep(i,n){
    rep(j,d[i]){
      sunuke[A[i][j]-1] = 1;
    }
  }
  int count = 0;
  rep(i,n){
    if (sunuke[i] == 0) count += 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 3668
import math
M,D=map(int,input().split())
days=[]
count = 0
divisors = []
for k in range(1,M+1):
    for i in range(22,D+1):
        if int(str(i)[0])>=2 and int(str(i)[1])>=2:
            if k==int(str(i)[0])*int(str(i)[1]):
                count += 1
print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef pair<int, int> P;
vector<P> sg;
vector<P> edge[1501];
int leng[1501][1501], f[1501][1501], flg[1501];
vector<int> fl;
int main(void){
	int n, r;
	cin >> n >> r;
//	cout << n << endl;
	for(int i = 0; i < r; i++){
		int a, b, c;
		cin >> a >> b >> c;
		edge[a].push_back(P(b, c)); edge[b].push_back(P(a, c));
	}
	fill(leng[0], leng[n + 1], INF);
	int mx = -1;
	for(int i = 1; i <= n; i++){
		leng[i][i] = 0;
		priority_queue<P, vector<P>, greater<P> > que;
		que.push(P(0, i));
		while(!que.empty()){
			P p = que.top(); que.pop();
			int cost = p.first, from = p.second;
			if(leng[i][from] < cost) continue;
			for(int j = 0; j < edge[from].size(); j++){
				int to = edge[from][j].first, cost = edge[from][j].second;
				if(leng[i][to] > leng[i][from] + cost){
					leng[i][to] = leng[i][from] + cost;
					que.push(P(leng[i][to], to));
				}
			}
		}
		for(int j = 1; j <= n; j++) if(leng[i][j] != INF) mx = max(mx, leng[i][j]);
	}
/*	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++) cout << leng[i][j] << ' ';
		cout << endl;
	}*/
	fill(f[0], f[n + 1], 1);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(f[i][j]){
				if(leng[i][j] == mx){
					sg.push_back(P(i, j));
					f[i][j] = 0; f[j][i] = 0;
				}
			}
		}
	}
//	cout << sg.size() << endl;
	fill(flg, flg + n + 1, 1);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++) if(!f[i][j]) flg[i] = 0, flg[j] = 0;			
	}
	for(int i = 1; i <= n; i++) if(flg[i]) fl.push_back(i);
//	cout << "コアダンブ" << endl;
	for(int i = 0; i < sg.size(); i++){
		int start = sg[i].first, goal = sg[i].second;
		for(int j = 0; j < fl.size(); j++){
			int via = fl[j];
			if(leng[start][via] + leng[via][goal] == mx) flg[via] = 0;
		}
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++) if(flg[i]) cnt++;
	cout << cnt << endl;
	for(int i = 1; i <= n; i++) if(flg[i]) cout << i << endl;
	return 0;
}


Measured memory_bytes: 37072
<?php

$alphabet = array_combine(range('a', 'z'), array_fill(0, 26, 0));

while (($line = trim(fgets(STDIN))) !== '') {
    $line = strtolower($line);
    for ($i = 0, $len = strlen($line); $i < $len; $i++) {
        $c = $line[$i];
        if (isset($alphabet[$c])) {
            $alphabet[$c]++;
        }
    }
}

foreach ($alphabet as $key => $val) {
    printf("%s : %d\n", $key, $val);
}

Measured memory_bytes: 6624
#include<iostream>
using namespace std;
 
int main(){
int a,b;
  int c=2;
  int ans=0;
  cin>>a>>b;
  for(int i=0;i<2;i++){
    if(a<=b){
    ans+=b;
      b--;
      
    }
    else{
    ans+=a;
      a--;
    }
  }
cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util
import java.util.Scanner

object Main {
  def solve(N: Int, K: Int, A: Array[Int]): Int = {
    val counts = Array.ofDim[Int](N + 1)
    util.Arrays.sort(A)

    var i = 0
    while(i < N) {
      val j = i
      while(i < N && A(j) == A(i)) i += 1 // A(j)と同じ値の次までiを進める
      val count = i - j
      counts(count) += 1
    }

    var remain = counts.sum - K
    var res = 0
    for {
      i <- 1 to N
      if remain > 0
    } {
      val used = math.min(remain, counts(i))
      remain -= used
      res += used * i
    }

    res
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val K = sc.nextInt()
    sc.nextLine()
    val A = Array.ofDim[Int](N)
    A.indices foreach (i => A(i) = sc.nextInt())
    System.out.println(solve(N, K, A))
  }
}


Measured memory_bytes: 72180
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
vector < int > adj[1000000];
int dp1[1000000];
int dp2[1000000];
void dfs(int v, int p)
{
	if(p == -1)
	{
		int x = 1;
		int y = 1;
		dp1[1] = 1;
		dp2[1] = 1;
		for(auto z : adj[v])
		{
			dfs(z, v);
			dp1[1] = (dp1[1] * ((dp1[z]%mod) + (dp2[z]%mod) )%mod )%mod;
			dp2[1] = (dp2[1]*(dp1[z]%mod))%mod;
		}
	}
	dp1[v] = 1;
	dp2[v] = 1;
	for(auto z : adj[v])
	{
		if(z != p)
		{
			dfs(z, v);
			dp1[v] = (dp1[v] * ((dp1[z]%mod) + (dp2[z]%mod) )%mod )%mod;
			dp2[v] = (dp2[v] * (dp1[z]%mod))%mod;
		}
	}
}
signed main()
{
	int n, x, y;
	cin >> n;
	for(int i = 0; i < n - 1; i++)
	{
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1, -1);
	cout << (dp1[1] + dp2[1])%mod << endl;
}

Measured memory_bytes: 39936
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 2010
int n,k,u[MAXN],v[MAXN];
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c;
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;
}
int dep[MAXN];
void dfs(int u,int p)
{
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
		{
			dep[V[i]]=dep[u]+1;
			dfs(V[i],u);
		}
}
int main()
{
//	freopen("shorten.in","r",stdin);
//	freopen("shorten.out","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		AddEdge(u[i],v[i]);
		AddEdge(v[i],u[i]);
	}
	int ans=n;
	if(k&1)
	{
		for(int i=1;i<n;i++)
		{
			dep[u[i]]=dep[v[i]]=0;
			dfs(u[i],v[i]);
			dfs(v[i],u[i]);
			int tmp=0;
			for(int j=1;j<=n;j++) if(dep[j]>k/2) tmp++;
			ans=min(ans,tmp);
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			dep[i]=0;
			dfs(i,0);
			int tmp=0;
			for(int j=1;j<=n;j++) if(dep[j]>k/2) tmp++;
			ans=min(ans,tmp);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)b - *(int*)a;
}

int main()
{
	int n;
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (4 * i + 7 * j == n) {
				ans++;
				break;
			}
		}
		if (ans != 0) break;
	}
	if (ans != 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int dp[1050][4100];
int main(){
  int n,m;
  cin>>n>>m;
  int max=0;
  int buf;
  int tmp;
  vector<int>a(m+1);
  vector<int>b(m+1);
  vector<int>c(m+1,0);
  for(int i=0;i<n;i++){
    max=max|(1<<i);
  }
  for(int i=1;i<=m;i++){
    cin>>a[i]>>b[i];
    buf=0;
    for(int j=0;j<b[i];j++){
      cin>>tmp;
      buf=buf|(1<<tmp-1);
    }
    c[i]=buf;
  }
  for(int i=0;i<1050;i++){
    for(int j=0;j<4100;j++){
      dp[i][j]=1000000007;
      if(j==0)dp[i][j]=0;
    }
  }
  for(int i=1;i<=m;i++){
    for(int j=0;j<4100;j++){
      dp[i][j|c[i]]=min(dp[i-1][j]+a[i],dp[i][j|c[i]]);
      dp[i][j]=min(dp[i-1][j],dp[i][j]);
    }
  }/*
  for(int i=0;i<m;i++){
    cout<<c[i+1]<<endl;
    }*/
  if(dp[m][max]!=1000000007){
  cout<<dp[m][max]<<endl;
  }
  else{
    cout<<"-1"<<endl;
  }/*
  for(int i=1;i<=m;i++){
    for(int j=1;j<=max;j++){
      cout<<dp[i][j]<<"\t";
    }
    cout<<endl;
    }*/
  //    cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 17024
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b, x;
    cin >> a >> b >> x;

    //cout << a << b << x;

    if ((x - a <= b) && a <= x) 
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d %d %d',$N,$M,$C);

$b = explode(' ', fgets(STDIN));
// echo $b[0];
// echo $b[1];
$result = 0;

for($i=0;$i<$N;++$i){
  $a = explode(' ', fgets(STDIN));
  $sum = 0;
  for($j=0;$j<$M;++$j){
     $sum += $a[$j] * $b[$j];
  }
  if($sum+$C>0) { $result += 1; }
}

echo $result;


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, x=0, t=0;
  cin >> n;
  vecll a(n);
  forll(i, 0, n)
	cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  forll(i, 0, n){
	if (t == a[i] && x == 0){
	  x = a[i];
	  t = 0;
	  continue;
	}
	else if (t == a[i]){
	  cout << x * a[i] << endl;
	  return 0;
	}
    t = a[i];
  }
  cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG

vin dy={-1,0,0,1};
vin dx={0,-1,1,0};
const int inf=1000007;
int h=50;
int w=50;
vvch c(h,vch(w));
int bfs(){
    queue<pair<int,int>> q;
    vvin d(h,vin(w,inf));
    q.push(mp(0,0));
    d[0][0]=0;
    while(q.size()){
        auto p=q.front();
        q.pop();
        if(p.first==h-1&&p.second==w-1)break;
        rep(i,4){
            int ny=p.first+dy[i];
            int nx=p.second+dx[i];
            if(0<=ny&&ny<h&&0<=nx&&nx<w&&c[ny][nx]!='#'&&d[ny][nx]==inf){
                q.push(mp(ny,nx));
                d[ny][nx]=d[p.first][p.second]+1;
            }
        }
    }
    return d[h-1][w-1];
}
int main(){
    cin>>h>>w;
    int white=0;
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
            if(c[i][j]=='.')white++;
        }
    }
    int a=bfs();
    if(a==inf)cout<<-1<<endl;
    else cout<<white-1-a<<endl;
}

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

using namespace std;

int main()
{
    string s, p;
    cin >> s;
    cin >> p;
    s += s;
    if (s.find(p) != string::npos){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<string> a(n, string(n, '.'));
    while (n > 7) {
        vector<string> aa = {
                "aabc",
                "ddbc",
                "bcaa",
                "bcdd"
        };
        for (int i = 0; i < aa.size(); i++) {
            for (int j = 0; j < aa.size(); j++) {
                a[n - 1 - i][n - 1 - j] = aa[i][j];
            }
        }
        n -= 4;
    }
    if (n == 7) {
        vector<string> aa = {
                "....abc",
                "....abc",
                "....def",
                "....def",
                "aabb..g",
                "ccdd..g",
                "aabbhh.",
        };
        for (int i = 0; i < aa.size(); i++) {
            for (int j = 0; j < aa.size(); j++) {
                a[n - 1 - i][n - 1 - j] = aa[i][j];
            }
        }
    } else if (n == 6) {
        vector<string> aa = {
                ".aaffg",
                "b..h.g",
                "b..hzz",
                "ggf.aa",
                "r.fb..",
                "reeb..",
        };
        for (int i = 0; i < aa.size(); i++) {
            for (int j = 0; j < aa.size(); j++) {
                a[n - 1 - i][n - 1 - j] = aa[i][j];
            }
        }
    } else if (n == 5) {
        vector<string> aa = {
                "qaarr",
                "q.eyy",
                "bbeww",
                "eth..",
                "eth..",
        };
        for (int i = 0; i < aa.size(); i++) {
            for (int j = 0; j < aa.size(); j++) {
                a[n - 1 - i][n - 1 - j] = aa[i][j];
            }
        }
    } else if (n == 4) {
        vector<string> aa = {
                "aabc",
                "ddbc",
                "bcaa",
                "bcdd"
        };
        for (int i = 0; i < aa.size(); i++) {
            for (int j = 0; j < aa.size(); j++) {
                a[n - 1 - i][n - 1 - j] = aa[i][j];
            }
        }
    } else if (n == 3) {
        vector<string> aa = {
                ".aa",
                "a..",
                "a..",
        };
        for (int i = 0; i < aa.size(); i++) {
            for (int j = 0; j < aa.size(); j++) {
                a[n - 1 - i][n - 1 - j] = aa[i][j];
            }
        }
    } else {
        cout << "-1";
        return 0;
    }

    for (int i = 0; i < a.size(); i++) {
        cout << a[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, k, a, sum=1, shangxian=1e18;
double total=1;
int main(){
	scanf("%lld", &n);
	for(i=1; i<=n; i++){
		scanf("%lld", &a);
		sum*=a;
		total*=a;
	}
	if(sum>shangxian||total>shangxian) cout << "-1";
	else cout << sum;
	return 0;
}

Measured memory_bytes: 3760