akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<functional>
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 2e5 + 5;
set<int>a[2];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j, k, m, n;
	cin >> n >> m;
	
	for (int i = 1; i <= m; ++i)
	{
		cin >> k >> j;
		if (k > j)swap(k, j);
		if (k == 1)a[1].insert(j);
		else if (j == n)a[0].insert(k);
	}
	for (auto it : a[1])
	{
		if (a[0].count(it))
		{
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 9600
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
from collections import deque

def main():
    n, m = map(int, input().strip().split())
    nei = [[] for _ in range(n)]
    for _ in range(m):
        s, t = map(int, input().strip().split())
        nei[s].append(t)
        nei[t].append(s)

    nodes = [-1] * n
    color = 1
    for i in range(n):
        if nodes[i] > 0:
            continue
        d = deque()
        d.append(i)
        # print(nei)
        while len(d) != 0:
            k = d.popleft()
            nodes[k] = color
            for j in nei[k]:
                if nodes[j] == -1:
                    d.append(j)
            # print(len(d))
        color += 1

    q = int(input().strip())
    for _ in range(q):
        s, t = map(int, input().strip().split())
        if nodes[s] == nodes[t]:
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    main()



Measured memory_bytes: 24296
S = list(input())
odd = ['R','U','D']
even = ['L','U','D']
ans = 'Yes'

for i in range(len(S)):
  if (i+1) % 2 == 1:
    if S[i] not in odd:
      ans = 'No'
  else:
    if S[i] not in even:
      ans = 'No'
      
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int n1 = n / 100;
		n = n -  n1 * 100;
		int n2 = n / 10;
		n = n - n2 * 10;
		if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
			System.out.println("hon");
		}else if(n == 0 || n == 1 || n == 6 || n == 8) {
			System.out.println("pon");
		}else {
			System.out.println("bon");
		}

	}

}

Measured memory_bytes: 26980
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		int[][] ab = new int[N][2];
		for(int i=0;i<N;i++) {
			ab[i][0] = sc.nextInt();
			ab[i][1] = sc.nextInt();
		}

		int[][] cd = new int[M][2];
		for(int i=0;i<M;i++) {
			cd[i][0] = sc.nextInt();
			cd[i][1] = sc.nextInt();
		}

		for(int i=0;i<N;i++) {
			int min = Integer.MAX_VALUE;
			int ans = 0;
			for(int j=0;j<M;j++) {
				int dist = Math.abs(ab[i][0] - cd[j][0]) + Math.abs(ab[i][1] - cd[j][1]);
				if(min > dist) {
					min = dist;
					ans = j+1;
				}
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23124
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut map = std::collections::HashMap::<i64, i64>::new();
    map.insert(0, 1);
    let mut now = 0;
    let mut ans = 0;
    for i in 0..n {
        now += a[i];
        let p = map.entry(now).or_insert(0);
        ans += *p;
        *p += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 20632
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define lli unsigned long long int
using namespace std;
#define S second
#define F first
#define pb push_back
#define M1 1000000007
#define M2 998244353
#define pint pair<int,int>
#define setit set<int>::iterator seti
#define mapit map<int,int> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)
{   int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {   if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

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


    lli t, i, j,  b, a, y, n;
    cin >> n;
    if (n == 1) {
        cout << "0\n";
        return 0;
    }
    if (n == 2 || n == 3) {
        cout << "1";
        return 0;
    }
    lli c = 0;
    lli  x = n;
    lli an = 0;
    //j * j <= (x)
    for (j = 2; j*j<=n; j++) {
        if (n % j == 0) {
            c = 0;

            while (n % j == 0) {
                c++;
                n /= j;
            }
            for (lli k = 1;k<=c; k++) {
                if (c <= 0) {
                    break;
                }
                an++;
                c = c - k;
            }
        }
        if (n == 1) {
            break;
        }
    }
    if (n!=1) {
        an++;
    }
    cout <<  an;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

bool testcase_ends() {
    int N;
    if (scanf("%d", &N) == EOF)
        return 1;

    int i;
    for (i=0; i*(i+1)/2<N; ++i);

    for (int j=N; j>0; --i) {
        if (i > j) continue;

        j -= i;
        printf("%d\n", i);
    }

    return 0;
}

int main() {
    bool solved=false;
    while (!testcase_ends())
        solved |= 1;

    return !solved;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int digits(auto& i) {
  int res = 0;
  while (isdigit(*i)) res = 10 * res + *i++ - '0';
  return res;
}
int expr(auto& i);
int num(auto& i) {
  switch (*i) {
    case '+': return num(++i);
    case '-': return -num(++i);
    case '(': {
      int res = expr(++i);
      return ++i, res;
    }
    default: return digits(i);
  }
}
int term(auto& i) {
  int res = num(i);
  while (true) switch (*i) {
    case '*': res *= num(++i); break;
    case '/': res /= num(++i); break;
    default: return res;
  }
}
int expr(auto& i) {
  int res = term(i);
  while (true) switch (*i) {
    case '+': res += term(++i); break;
    case '-': res -= term(++i); break;
    default: return res;
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  while (n--) {
    string s; cin >> s;
    auto i = begin(s);
    cout << expr(i) << '\n';
  }
}


Measured memory_bytes: 3092
#include <stdio.h>

int Check(int X){
  int x, n, n1, n2;
  n1 = X * 0.01;
  n2 = X / 105;
  for(n = n2;n <= n1;n++){
    x = X - n * 100;
    if(x >= 0 && x <= 5 * n) return 1;
  }
  return 0;
}

int main(void){
  int X;
  scanf("%d", &X);
  printf("%d\n", Check(X));
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3

P_NUM = 1000000007


def solv(n, m, a):
    no_hole = [1] * (n+1)
    for i in range(2, n+1):
        no_hole[i] = no_hole[i-1] + no_hole[i-2]

    ans = 1
    start = 0
    for broken in a:
        dist = broken-1-start
        if dist < 0:
            return 0
        ans *= no_hole[dist] % P_NUM
        start = broken+1

    dist = n-start
    if dist < 0:
        return 0
    ans *= no_hole[dist] % P_NUM

    return ans % P_NUM


if __name__ == '__main__':

    n, m = map(int, input().split())
    a = [int(input()) for _ in range(m)]

    ans = solv(n, m, a)

    print(ans)


Measured memory_bytes: 464040
#include <iostream>

using namespace std;

int nums[200001];
int back[20];

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

  for (int i = 1; i <= n; i++) {
    cin >> nums[i];
  }

  for (int i = 0; i < 20; i++) {
    back[i] = 0;
  }

  long long res = 0;
  int sum = 0;
  for (int f = 0; f < 20; f++) {
    if ((1 << f) & nums[1]) {
      back[f] = 1;
    }
  }
  sum += nums[1];
  res += 1;

  int b = 1;
  for (int i = 2; i <= n; i++) {
    if (sum & nums[i]) {
      for (int f = 0; f < 20; f++) {
        if (((1 << f) & nums[i]) && b < back[f] + 1) {
          b = back[f] + 1;
        }
      }
      for (int f = 0; f < 20; f++) {
        if (b > back[f] && (sum & (1 << f))) {
          back[f] = 0;
          sum -= (1 << f);
        }
      }
    }
    for (int f = 0; f < 20; f++) {
      if ((1 << f) & nums[i]) {
        back[f] = i;
      }
    }
    sum += nums[i];
    res += i - b + 1;
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e4+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
int a[maxn];
int b[maxn];
int main()
{
    ios::sync_with_stdio(false);
      int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    long long s=0;
    for(int i=0;i<n;i++)
        s+=a[i];
    for(int i=0;i<n;i++)
        s-=b[i];
    if(s>0)
        printf("No");
    else
    {
        long long ta=-s,tb=-s;
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])
                tb-=a[i]-b[i];
            else if(a[i]<b[i])
            {
                if((b[i]-a[i])&1)
                    ta-=(b[i]-a[i])/2+1,tb--;
                else ta-=(b[i]-a[i])/2;
            }
        }
        if(2*ta==tb&&ta>=0&&tb>=0)
         cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin >> n;
    vector<int> dim(n, 0);
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    for (int i = 0; i < n; i++)
    {
        dim[i] = l[i] - (i + 1);
    }
    sort(dim.begin(), dim.end());
    int mid = dim[n / 2];
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += abs(dim[i] - mid);
    }
    cout <<  ans  << endl;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> count(N, 0);

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

    for (int i = N - 1; 0 <= i; i -= 2)
    {
        if (i == 0)
        {
            if (count[0] != 1)
            {
                cout << "0" << endl;
                return 0;
            }
        }
        else
        {
            if (count[i] != 2)
            {
                cout << "0" << endl;
                return 0;
            }
        }
    }

    long ans = 1;
    for (int i = 0; i < N / 2; i++)
    {
        ans *= 2;
        ans %= (1000000000 + 7);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
MOD = 10 ** 9 + 7
N, M = map(int, input().strip().split())
F = [0, 1]


def fib(n):
  for i in range(len(F), n + 1):
    F.append((F[i - 1] + F[i - 2]) % MOD)

  return F[n]


total = 1
b = 0
for _ in range(M):
  #print('')
  a = int(input().strip())
  if a == b:
    total = 0
    break
  f = fib(a - b)
  #print('f = {}, total = {}'.format(f, total))
  total = total * f % MOD
  #print('f = {}, total = {}'.format(f, total))
  b = a + 1
else:
  f = fib(N - b + 1)
  total = total * f % MOD

print(total)


Measured memory_bytes: 7056
// test.cpp
#pragma warning(disable:4996)
#include<iostream>
#include<string>
using namespace std;
int main()
{
    // 整数の入力
    string s;
	cin >> s;
	int lNum=0;
	int lLen= (int)s.size();
	if( lLen > 1){
		for( int i = 0; i < lLen-1; i++ ){
			if( s[i] != s[ i+1 ] )
				lNum++;
		}	
	}	
	cout << lNum << endl;
	return 0;
}

Measured memory_bytes: 512
#ifndef ___Class_RMQ
#define ___Class_RMQ

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

// ------ RMQ Class ------ //
template<typename Type> class RMQ {
private:
	unsigned size_; std::vector<Type> dat;
	inline Type query_(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return std::numeric_limits<Type>::max();
		if (a <= l && r <= b) return dat[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc);
	}
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RMQ(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
		}
	}
	inline Type query(int l, int r) {
		return query_(l, r, 1, 0, size_);
	}
};

#endif

#include<iostream>
#include<limits>
#include<algorithm>
using namespace std;

long long D[5500][5500], a[5500], b[220][5500], n, m;
RMQ<pair<long long, long long>> E(5500);
void add(long long ax, long long ay, long long bx, long long by, long long c) {
	D[ax][ay] += c; D[bx + 1][by + 1] += c; D[bx + 1][ay] -= c; D[ax][by + 1] -= c;
}
void solve(int r, int p, int q) {
	if (p > q)return;
	pair<long long, long long>T = E.query(p, q + 1);
	add(p, T.second, T.second, q, -T.first);
	solve(r, p, T.second - 1);
	solve(r, T.second + 1, q);
}
int main() {
	cin >> n >> m; for (int i = 1; i <= n - 1; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++)cin >> b[j][i]; }
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++)E.update(j, make_pair(-b[i][j], j));
		solve(i, 1, n);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)D[i][j] += D[i][j - 1];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)D[i][j] += D[i - 1][j];
	}
	long long maxn = 0;
	for (int i = 1; i <= n; i++) {
		long long G1 = 0;
		for (int j = i; j <= n; j++) {
			maxn = max(maxn, D[i][j] - G1);
			G1 += a[j];
		}
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 224000
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	int R[n];
	for (int i = 0; i < n; i++)
		cin >> R[i];

	int minv = R[0];
	int maxv = -1000000001;
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3840
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		class fill implements Comparable<fill> {
			final int count;
			final int value;

			fill(int count, int value) {
				this.count = count;
				this.value = value;
			}

			@Override
			public int compareTo(fill o) {
				return Comparator.<fill>comparingInt(f -> f.value).compare(this, o);
			}
		}
		fill[] fillers = new fill[M];
		for (int i = 0; i < M; i++) {
			fillers[i] = new fill(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(fillers, Comparator.reverseOrder());

		long sum = 0;
		int i = 0;
		f:
		for (fill filler : fillers) {
			for (int j = 0; j < filler.count; j++) {
				if (i >= A.length || A[i] > filler.value) {
					break f;
				}
				sum += filler.value;
				i++;
			}
		}
		for (; i < A.length; i++) {
			sum += A[i];
		}
		System.out.println(sum);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

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

int main(){
	int N,W,v[1001],w[1001];
	int dp[10010];
	cin >> N >> W;
	for(int i=0;i<N;i++){
		cin >> v[i] >> w[i];
	}
	for(int i=0;i<=W;i++){
		dp[i] = -1;
	}
	dp[0] = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			if(j+w[i] > W) break;
			if(dp[j]==-1) continue;
			dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
		}
	}
	int ans = 0;
	for(int i=0;i<=W;i++){
		ans = max(ans,dp[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pq priority_queue<int> 
#define pqs priority_queue<int,vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)  // no of ones in setbit
#define zrobits(x) __builtin_ctzll(x)       //101000 here 3..no of 0 aftrer 1sr right one 
#define mod 1000000007
#define inf 1e18
#define prDouble(x)  cout<<fixed<<setprecision(10)<<x     // ans upto 5 decimal place 
#define mk(ar,n,type) type *arr=new type[n];
#define w(x) int x;cin>>x;while(x--)
double dp[3001][3001]; 



double fn(double  arr[],int i ,int x,   int n)
{

	if(x==0 )
	{
		return 1 ; 
	}

	if(i==n+1)
	{
		return 0 ; 
	}
	if(dp[i][x] > -0.9  )
	{
		return dp[i][x] ; 
	}

	
	return dp[i][x]= arr[i]*fn(arr, i+1,x-1, n)+ (1-arr[i])*fn(arr, i+1, x, n) ; 

	
}

int32_t main()
{
	int n ; 
	cin>>n; 
	double arr[n+1] ; 
	for(int i=1 ; i<=n; i++)
	{
		cin>>arr[i]; 
	}

	int x; 
	x=(n+1)/2 ; 
	memset(dp, -1, sizeof(dp)) ; 
	

	prDouble(fn(arr,0, x,  n));
	


	 

}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#define dbl double
//#define f(0 n) for(int i=0;i<n;i++)
#include <iostream>
using namespace std;
int main() {
	int n;
	cin>>n;
	dbl p[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	double dp[n+1][n+1];
	double s=0;
	memset(dp,0,sizeof(dp));
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i==0&&j==0)dp[i][j]=1;
			else if(j==0)dp[i][j]=(1-p[i-1])*dp[i-1][j];
			else{
				dp[i][j]=((1-p[i-1])*dp[i-1][j])+((p[i-1]*dp[i-1][j-1]));
			}
		}
	}
	for(int i=n/2+1;i<=n;i++){
		s+=dp[n][i];
	}
	cout<<setprecision(9)<<s;
	return 0;
}

Measured memory_bytes: 70528
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static int MOD=1000000007;
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        String s=sc.next();
        char[] d={'m','a','e','r','d'};
        char[] dr={'r','e','m','a','e','r','d'};
        char[] e={'e','s','a','r','e'};
        char[] er={'r','e','s','a','r','e'};
        int dream=0,dreamer=0,erase=0,eraser=0,temp;
        int n=s.length(),count=0;
        for (int i = 0; i < n; i++) {
            temp=dream+erase+dreamer+eraser;
            char p=s.charAt(n-i-1);
            if(p==d[dream])dream++;
            if(p==dr[dreamer])dreamer++;
            if(p==e[erase])erase++;
            if(p==er[eraser])eraser++;
            count++;
            if(temp==dream+dreamer+erase+eraser){
                out.println("NO");
                exit(0);
            }
            if(count!=max(max(dream,dreamer),max(erase,eraser))){
                out.println("NO");
                exit(0);
            }
            if(dreamer==7||dream==5||erase==5||eraser==6){
                dream=dreamer=erase=eraser=count=0;
            }
        }
        out.println("YES");
    }
}

Measured memory_bytes: 24904
# coding: UTF-8
# sample code

v1 = list(map(int, input().split()))
v2 = input()
n, k = v1[0], v1[1]
s = v2
result = ''

for i in range(n):
	if not(i == k-1):
		result += s[i]
	else :
		result += s[i].lower()

print(result)

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

int diffProfits( std::vector<int> A ){
  
  int ans = -1000000001;
  int min_val = A[0];
  for( int i = 1; i < A.size(); i++ ){
    ans = std::max( A[i] - min_val, ans );
    min_val = std::min( A[i], min_val );
  }
  return ans;
}

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> A(N);

  for( auto &a : A ) std::cin >> a;

  std::cout << diffProfits( A ) << std::endl;

}



Measured memory_bytes: 4456
N,A,B=map(int,input().split())
if (B-A)%2==0:
  print((B-A)//2)
elif (B-1)>=(N-A):#Nに近づいたほうが早い時
  #ans+=N-B+1
  #B=N
  #A+=(N-B)+1
  print(((B-A-1)//2)+(N-B+1))
else:#1に近づいたほうが早い時
  #ans=A-1+1
  #A=1
  #B-=A
  print(((B-A-1)//2)+A)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
//Range Sum Query
class Lz_segtree{
public:
    int n,inv=0;
    vector<ll> dat,lz;
    Lz_segtree(int n_):n(n_){
        n=1;
        while(n<n_) n*=2;
        dat.resize(n*2,inv);
        lz.resize(n*2,0);
    }
    void eval(int len,int k){
        if(lz[k]!=0) dat[k]+=lz[k];
        if(len>1){
            lz[k*2+1]+=lz[k]/2;
            lz[k*2+2]+=lz[k]/2;
        }
        lz[k]=0;
    }
    //range [a,b)
    void update(int a,int b,int k,int l,int r,ll x){
        eval(r-l,k);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            lz[k]+=(r-l)*x;
            eval(r-l,k);
        }
        else{
            update(a,b,k*2+1,l,(l+r)/2,x);
            update(a,b,k*2+2,(l+r)/2,r,x);
            dat[k]=dat[2*k+1]+dat[2*k+2];
        }
    }
    //range [a,b)
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return inv;
        if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return vl+vr;
        }
    }
    void update(int a,int b,ll x){
        return update(a,b,0,0,n,x);
    }
    ll query(int a,int b){
        return query(a,b,0,0,n);
    }
};

int main(){
    int n,q,c,s,t,x;
    cin>>n>>q;
    Lz_segtree seg(n);
    rep(i,q){
        cin>>c;
        if(c==0){
            cin>>s>>t>>x;
            seg.update(s-1,t,x);
        }
        else{
            cin>>s>>t;
            ll ans=seg.query(s-1,t);
            cout<<ans<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7064
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */

int main() {
    double R; cin >> R;
    printf("%.5f", 2 * R * M_PI);
}


Measured memory_bytes: 3764
def main():
#    N, X, T = map(int, input().split())
    N = input()
    heights = [int(s) for s in input().split()]

    sum = 0

    max_value = 0

    for i in range(0, len(heights)):
        if max_value < heights[i]:
            max_value = heights[i]
        else:
            sum = sum + max_value - heights[i]


    print(sum)
main()

Measured memory_bytes: 32160
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():

    N=int(input())
    B=list(map(int,input().split()))

    A=[0]*(N)
    A[0]=B[0]
    for i in range(N-1):
        A[i+1]=B[i]
        if B[i]<A[i]:
            A[i]=B[i]
    print(sum(A))

resolve()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
typedef long long ll;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, q;
	cin >> n >> q;
	vector<ll>a(n);
	ll x;
	repp(i, 0, n)cin >> a[i];
	for (int i = 0; i < q; ++i) {
		cin >> x;
		ll sum = 0,cnt=0;
		int right=0;
		for (int left = 0; left < n; ++left) {
			while (right < n && sum + a[right] <= x) {
				sum += a[right++];
			}
			cnt += right - left;//[left,right)の半開区間
			if (left == right)++right;//leftがrightを追い越すことはない
			else sum -= a[left];
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
string s;
llint sum[200005];
map<llint, llint> mp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	reverse(s.begin(), s.end());
	
	llint n = s.size(), mul = 1;
	for(int i = 0; i < s.size(); i++){
		llint c = s[i]-'0';
		sum[i+1] = sum[i] + mul*c%2019;
		sum[i+1] %= 2019;
		mul *= 10, mul %= 2019;
	}
	sort(sum, sum+n+1);
	
	for(int i = 0; i <= n; i++) mp[sum[i]]++;
	llint ans = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		ans += it->second*(it->second-1)/2;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5276
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define st first
#define nd second
#define N 205
#define inf 1000000000
#define MOD 998244353
#define sz(x) ((int)x.size())
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
using namespace std;

int main(int arg,char* argv[]) {

	int a;
	string s;

	cin>>a>>s;

	if(a>=3200) cout<<s;
	else cout<<"red";
 
}

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

int main(){
  int n;
  cin>>n;
  if(n==0){
    cout<<1<<endl;
    return 0;
  }
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  
 
  
  
  

  return 0;
}

 


Measured memory_bytes: 3648
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

struct Combination{
    int MAX_N;
    int MOD;
    int *fac, *finv, *inv;
    Combination(int max_n,int MOD): MAX_N(max_n+1),MOD(MOD){ //make table
        fac = new int[MAX_N];finv = new int[MAX_N];inv = new int[MAX_N];
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for (int i = 2; i < MAX_N; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    int COM(int n,int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    void free_COM(){
        delete[] fac;
        delete[] finv;
        delete[] inv;
    }
    
};

int K,N;
int A[100009];
int B[100009];

signed main(){
    scanf("%lld %lld",&N,&K);
    rep(i,N)scanf("%lld",&A[i]);
    sort(A,A+N);
    int ans=0;
    //sum(minX)とsum(maxX)を求める
    int minXsum=0,maxXsum=0;
    Combination CB(N,mod);
    for(int i=0;i<=N-K;i++){
        minXsum+=(CB.COM(N-i-1,K-1)*A[i])%mod;
        minXsum%=mod;
    }
    for(int i=K-1;i<N;i++){
        maxXsum+=(CB.COM(i,K-1)*A[i])%mod;
        maxXsum%=mod;
    }
    //printf("%lld,%lld\n",maxXsum,minXsum);
    ans=(((maxXsum-minXsum)%mod)+mod)%mod;
    printf("%lld\n",ans);
    CB.free_COM();
    return 0;
}


Measured memory_bytes: 3328
from collections import deque
import sys
sys.setrecursionlimit(10**6)

n=int(input())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
c=[-1]*(1+n)
flg=False
for i in range(n-1):
    a,b,w=map(int,input().split())
    g[a].append((b,w))
    g[b].append((a,w))
    if w%2==1:
        flg=True

def bfs(x):
    if v[x]!=0:
        return
    q=deque()
    q.append(x)
    v[x]=1
    while len(q)>0:
        cur=q.popleft()

        for nei in g[cur]:
            y=nei[0]
            d=nei[1]
            if v[y]==0:
                q.append(y)
                v[y]=1
                if d%2==1:
                    c[y]=1-c[cur]
                else:
                    c[y]=c[cur]
            #print('cur=',cur,'nei=(y,d)=',nei,'c=',c,q,v)

c[1]=0
bfs(1)

for i in range(1,n+1):
    print(c[i])


Measured memory_bytes: 75168
#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()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> t(n+1), x(n+1), y(n+1);
  rep(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1]; 
  rep(i,n) {
    int dt = t[i+1] - t[i];
    int dx = x[i+1] - x[i];
    int dy = y[i+1] - y[i];
    int dis = abs(dx) + abs(dy);
    if (dt < dis || (dt % 2 != dis % 2)) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

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

Measured memory_bytes: 4196
n=int(input())
multi3 = [int(x.strip()) for x in input().split()]
ans=1
flag=True
for i in multi3:
    if ans*i>10**18:
        flag=False
    elif i==0:
        flag=True
        ans=0
        break
    else:
        ans*=i
if(flag):
    print(ans)
else:
    print(-1)


Measured memory_bytes: 84312
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    int64_t N, M, L[(int)1e5], R[(int)1e5];
    int64_t maxl, minr;

    scanf("%"PRId64"%"PRId64, &N, &M);
    for (int i = 0; i < M; i++) {
        scanf("%"PRId64"%"PRId64, &L[i], &R[i]);
    }

    maxl = L[0];
    minr = R[0];

    for (int i = 1; i < M; i++) {
        if (maxl < L[i]) maxl = L[i];
        if (minr > R[i]) minr = R[i];
    }

    if (maxl <= minr) {
        printf("%"PRId64"\n", minr - maxl + 1);
    } else {
        puts("0");
    }
}


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

int N,M;
vector<int>G[5000];

int main(){
    int D[5000]={0};
    scanf("%d%d",&N,&M);
    for(int i=0;i<M;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        G[--a].push_back(--b);
        D[b]++;
    }

    vector<int>ans;

    for(int _=0;_<N;_++){
        for(int i=0;i<N;i++){
            if(D[i])continue;
            ans.push_back(i);
            for(int j=0;j<G[i].size();j++){
                D[G[i][j]]--;
            }
            D[i]=-1;
            break;
        }
    }
    bool flag=false;
    for(int i=0;i<N-1;i++){
        int v=ans[i];
        flag|=find(G[v].begin(),G[v].end(),ans[i+1])==G[v].end();
    }

    for(int i=0;i<N;i++)printf("%d\n",ans[i]+1);
    printf("%d\n",flag);
    return 0;
}

Measured memory_bytes: 2028
K, S= map(int, input().split())

minZ=max(S-2*K,0)
maxZ=min(S,K)

if minZ>=S-K:
  nZ=maxZ-minZ+1
  max_nY=S-minZ+1
  min_nY=S-maxZ+1
  ans=((max_nY+min_nY)*nZ)//2
  print(ans)
elif maxZ>=S-K:
  nZ_u=maxZ-(S-K)
  max_nY_u=K
  min_nY_u=S-maxZ+1
  
  ans_u=((max_nY_u+min_nY_u)*nZ_u)//2
  
  nZ_l=(S-K)-minZ+1
  max_nY_l=K+1
  min_nY_l=2*K+minZ-S+1
  
  ans_l=((max_nY_l+min_nY_l)*nZ_l)//2
  
  print(ans_u+ans_l)
  
  
else:
  nZ=maxZ-minZ+1
  min_nY=2*K+minZ-S+1
  max_nY=2*K+maxZ-S+1
  ans=((max_nY+min_nY)*nZ)//2
  print(ans)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
left = 0
xor = 0
S = 0
ans = 0
for i in range(N):
  while xor^A[i]!=S+A[i]:
    xor ^= A[left]
    S -= A[left]
    left += 1
  xor ^= A[i]
  S += A[i]
  ans += i-left+1
print(ans)

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

int main(){
  long long N;
  cin >> N;
  long long ans=0;
  for(int i=1; i<=N; i++){
    if(i%3 > 0 && i%5 > 0){
      ans = ans + i;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var dn = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int count = 0;
        for (int i = 1; true; i++)
        {
            int divCount = 0;
            var tmpi = i;
            while (tmpi % 100 == 0)
            {
                divCount++;
                tmpi /= 100;
            }
            if (divCount == dn[0])
            {
                count++;
            }
            if (count == dn[1])
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 28260
#include <iostream>
#include <stdio.h>
 
using namespace std;
 
int main()
{
 int H, W;
 while(scanf("%d %d", &H, &W), H!=0)
 {
  for (int i = 0; i < H; i++)
  {
   for (int j = 0; j < W; j++)
   {
    if ((i + j) % 2 == 0)
    {
     cout << "#";
    }
    else
    {
     cout << ".";
    }
   }
   cout << endl;
  }
  cout << endl;
 }
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s[1000],s1,s2;
vvl v;
//vl vis,d;

ll dp1[100001],dp2[100001];

ll dfs2(ll s,ll p);

ll dfs1(ll s,ll p){
    if(dp1[s]!=-1)return dp1[s];
    ll ans=1;
    for(auto u:v[s]){
        if(u==p)continue;
        ans*=dfs1(u,s)+dfs2(u,s);
        ans%=mod;
    }
    return dp1[s]=ans;
}
ll dfs2(ll s, ll p){
    if(dp2[s]!=-1)return dp2[s];
    ll ans=1;
    for(auto u:v[s]){
        if(u==p)continue;
        ans*=dfs1(u,s);
        ans%=mod;
    }
    return dp2[s]=ans;
}

int main() {
    IOS;
    cin>>n;
    v.resize(n);
    fo(i,n-1)cin>>x>>y,x--,y--,v[x].pb(y),v[y].pb(x);
    fo(i,n)dp1[i]=-1,dp2[i]=-1;
    cout<<(dfs1(0,-1)+dfs2(0,-1))%mod;
    return 0;
}


Measured memory_bytes: 14208
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
vector<int>edge[100005];
int dist[2][100005];
void dfs(int v,int u,int d,int id){
	dist[id][v] = d;
	rep(i,edge[v].size()){
		if(edge[v][i] == u) continue;
		dfs(edge[v][i],v,d+1,id);
	}
}
int main(){
	cin >> n;
	repn(i,n-1){
		int a,b; cin >> a >> b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	dfs(1,-1,0,0);
	dfs(n,-1,0,1);
	
	int cnt = 0;
	
	repn(i,n){
		if(dist[0][i] <= dist[1][i]) cnt++;
		else cnt --;
	}
	puts(cnt > 0?"Fennec":"Snuke");
}

Measured memory_bytes: 9856
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int a[100],w,n,d,s;
  char c;
  while(cin>>w>>n&&w+n){
    memset(a,-1,sizeof(a));
    for(h=0;h<n;h++){
      cin>>c>>d;
      if(c=='s'){
	cin>>s;
	for(i=0;i<w;i=j){
	  for(;i<w&&a[i]!=-1;i++);
	  for(j=i;j<w&&a[j]==-1;j++);
	  if(j-i>=s){
	    for(j=0;j<s;j++)
	      a[i+j]=d;
	    break;
	  }
	}
	if(i==w)
	  cout<<"impossible"<<endl;
	else
	  cout<<i<<endl;
      }else if(c=='w'){
	for(i=0;a[i]!=d;i++);
	for(;i<w&&a[i]==d;i++)
	  a[i]=-1;
      }
    }
    cout<<"END"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int max(int a, int b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main()
{
    string s,t;
    cin>>s>>t;
    int i,j,n1,n2;
    n1=s.size();
    n2=t.size();
    int a[n1+1][n2+1];
    for(i=0;i<=n1;i++)
    {
        for(j=0;j<=n2;j++)
        {
            if(i==0 || j==0)
                a[i][j]=0;
            else if(s[i-1]==t[j-1])
                a[i][j]=a[i-1][j-1]+1;
            else
                a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
    }
    int x=a[n1][n2];
    string ans;
    i=n1,j=n2;
    while(i>0 && j>0)
    {
        if(a[i][j]!=a[i-1][j] && a[i][j]!=a[i][j-1])
        {
            ans+=s[i-1];
            i--;
            j--;
        }
        else
        {
            if(a[i][j-1]>a[i-1][j])
            {
                j--;
            }
            else
                i--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


//abracadabra
//avadakedavra


Measured memory_bytes: 35456
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, k; cin>>n>>k;
    string s; cin>>s;
    s[k - 1] += 32;
    cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a=n;
    int sn=0;
    while(1){
        if(n==0)break;
        sn+=n%10;
        n=n/10;
    }
    if(a%sn==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 22;

ll pw[maxn];
int D,dn,d[maxn];
int n,a[maxn];

ll ans;
void calc()
{
	for(int i=1;i*2<=n;i++) a[i]=-a[n-i+1];
	ll now=0;
	for(int i=1;i<=n;i++) now+=pw[n-i]*a[i];
	if(now==(ll)D)
	{
		//printf("%d ",n); for(int i=1;i<=n;i++) printf("%d ",a[i]); puts("");
		ll num=1ll;
		if(n&1) num*=10ll;
		for(int i=1;i*2<=n;i++)
		{
			int tmp=abs(a[i]);
			if(i==1) tmp++;
			num*=(ll)(10-tmp);
		}
		ans+=num;
	}
}
void dfs(const int now,const int las)
{
	if(!(n&1)&&now<=n/2) { calc();return; }
	if((n&1)&&now==(n+1)/2) { a[now]=0;calc();return; }
	int tmp=(d[now-(n-dn)]+las)%10;
	a[now]=tmp; dfs(now-1,las&(!tmp));
	if(tmp!=0) a[now]=-(10-tmp),dfs(now-1,1);
}

int main()
{
	pw[0]=1ll;for(int i=1;i<=18;i++) pw[i]=pw[i-1]*10ll;
	
	scanf("%d",&D);
	int tmp=D;while(tmp) d[++dn]=tmp%10,tmp/=10;
	for(int i=1;i*2<=dn;i++) swap(d[i],d[dn-i+1]);
	
	for(n=dn;n<=2*dn;n++) 
		dfs(n,0);
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-08-25
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] < a[i-1]) {
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3964
import heapq
N,M = map(int,input().split())
ans = [[0,0]for i in range(M)]
cityes = [[]for i in range(N)]
for i in range(M):
    p,y = map(int,input().split())
    heapq.heappush(cityes[p-1],[y,i])
for i in range(N):
    j = 0
    while cityes[i] != []:
        j += 1
        y,n = heapq.heappop(cityes[i])
        ans[n] = [i+1,j]
for a,b in ans:
    out = str(1000000+a)[1:] + str(1000000+b)[1:]
    print(out)

Measured memory_bytes: 42236
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll fun(ll arr[],ll n,ll b){
    ll i,res=0;
    for(i=0;i<n;i++)
        res+=abs(arr[i]-(b+i+1));
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,lar=0,amin,a,amax;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]>lar)
            lar=arr[i];
    }
    ll low=-lar,high=lar;
    while(low<=high){
        ll mid=(low+high)/2;
        amin=fun(arr,n,mid-1);
        a=fun(arr,n,mid);
        amax=fun(arr,n,mid+1);
        if(a<=amax && a<=amin){
            cout<<a<<endl;
            break;
        }
        else if(a<amin && a>amax)
            low=mid+1;
        else if(a>amin && a<amax)
            high=mid-1;
    }
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
void dicemove(char com,int *A);
int main(void)
{
  int i,j,A[6],a,b,q;
  char com[101];
  for(i=0;i<6;i++)
    {
      scanf("%d",&A[i]);
    }
  scanf("%d",&q);
  for(i=0;i<q;i++){
  scanf("%d %d",&a,&b);
  /*??????????????????*/
  for(j=0;j<4;j++){
    if(A[0] == a){break;}
    dicemove('N',A);
  }
  if(A[0]!=a)
    {
   for(j=0;j<4;j++)
     {
    if(A[0] ==a) {break;}
    dicemove('E',A);
     }
    }
  /*??????????????????*/
   for(j=0;j<4;j++)
     {
    if(A[1] ==b) {break;}
    dicemove('M',A);
     }
   printf("%d\n",A[2]);
  }
  /*????????§?????????
    scanf("%s",&com);
    for(i=0;com[i];i++)
      {
	dicemove(com[i],A); 
      }
    ??????*/
 return 0;
}
void dicemove(char comi,int *A){	
  int temp;
  switch(comi){
	case 'E':
	  temp=A[0]; A[0]=A[3]; A[3]=A[5];A[5]=A[2]; A[2]=temp;
	  break;
	case 'N':
	  temp=A[0]; A[0]=A[1]; A[1]=A[5]; A[5]=A[4]; A[4]=temp;
	  break;
	case 'S':
	  temp=A[0]; A[0]=A[4]; A[4]=A[5]; A[5]=A[1]; A[1]=temp;
	  break;
	case 'W':
	  temp=A[0]; A[0]=A[2]; A[2]=A[5]; A[5]=A[3]; A[3]=temp;
	  break;
        case 'M':
          temp=A[1]; A[1]=A[3]; A[3]=A[4]; A[4]=A[2]; A[2]=temp;
	  break;
	}
}

Measured memory_bytes: 596