akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const ll mod = 1e9 + 7;

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

  int n;
  cin >> n;

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += i;
  }

  cout << ans << endl;

  return 0;
}


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

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n"
#define show(a,b) cout<<(#a)<<" is "<<(a)<<" "<<(#b)<<" is "<<(b)<<"\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(n) for(auto i=0;i<n;i++) 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<pi,pi> ppi;

void solve()
{
    int n;
    cin>>n;
    vi h(n);
    f(n)
    cin>>h[i];
    vi dp(n);
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<"\n";
}

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

Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules ! vec_md { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }

#[allow(unused_macros)]
macro_rules! chmax {
    ( $ x : expr , $ y : expr ) => {
        if $x < $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize,
        wsv: [(usize, usize, u64); n]
    }
    const W: usize = 20_000;
    let mut cap = wsv;
    cap.sort_by(|&(w_a,s_a,_), &(w_b,s_b,_)|
        (s_a + w_a).cmp(&(s_b + w_b)));
    let mut dp = vec_md![0u64;n+1;W+1];
    for i in 0..n {
        let (w,s,v) = cap[i];
        for j in 0..dp[0].len() {
            chmax!(dp[i+1][j], dp[i][j]);
            if j <= s && j + w < dp[0].len() {
                chmax!(dp[i+1][j+w], dp[i][j] + v);
            }
        }
    }
    let mut ret = 0;
    for j in 0..dp[0].len() {
        chmax!(ret, dp[n][j]);
    }
    println!("{}", ret);
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, k, x, s;

int main() {
	cin >> n >> k;
	rep(i,n) {
		cin >> x;
		s += min(x, abs(k-x))*2;
	}
	cout << s << ln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
long long  n,k;
int freq[200];
int main() {
	IO
    cin>>n>>k;
    for(int i=0;i<k;i++)
    {
        int d;
        cin>>d;
        for(int j=0;j<d;j++)
        {
            int x;
            cin>>x;
            freq[x]=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        if(freq[i]==0)ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
struct RollingHash{
  string S;
  ull B;
  vector<ull> hash,p;
  int len;
  RollingHash(){}
  RollingHash(string S,ull B=1000000007LL):S(S),B(B){init();};
  void init(){
    len=S.length();
    hash.resize(len+1);
    p.resize(len+1);
    hash[0]=0;p[0]=1;
    for(int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};
signed main(){
  string t,p;
  cin>>t>>p;
  RollingHash rt(t),rp(p);
  for(int i=0;i<(int)(t.size()-p.size())+1;i++){
    if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<endl;
  }
  return 0;
}
/*
verified on 2017/04/28
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B
*/

Measured memory_bytes: 20532
(let* ((n (read))
       (m (read))
       (edges (make-array n :initial-element 0)))
  (loop repeat m
     do
       (let ((a (read))
	     (b (read)))
	 (incf (elt edges (- a 1)))
	 (incf (elt edges (- b 1)))))
  (format t "~:[NO~;YES~]" (every #'evenp edges)))

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

using namespace std;
long long city[333999];
int main()
{
	long long n,a,b,ans = 0;
	cin >> n >> a >> b;
	for(int i = 1; i <= n; ++i)
		cin >> city[i];
	for(int i = 2; i <= n; ++i)
		ans+=min((city[i]-city[i-1])*a,b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n][3],i;
    for(i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    ll dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}

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

signed main(){
  int N,K;
  cin>>N>>K;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  std::vector<int> w(N+1);
  w[0]=0;
  for(int i=0;i<N;i++)w[i+1]=w[i]+v[i];

  std::vector<int> p[2];
  for(int i=0;i<N;i++)for(int j=i+1;j<N+1;j++)p[0].push_back(w[j]-w[i]);

  int Q=pow(2,40);
  int ans=0;
  int c=0;
  while(Q){
    c=0;
    for(auto x:p[0]){
      if(x&Q){c++;p[1].push_back(x);}
    }
    if(c>=K){
      ans+=Q;
      p[0]=p[1];
    }
    p[1].clear();
    Q/=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6388
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, m; cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> l(n);
  ll sum = 0;
  REP(i, n) {
    cin >> l[i];
    sum += l[i];
  }
  sum -= *max_element(ALL(l));
  if (*max_element(ALL(l)) < sum) cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

import itertools

N, M = map(int, input().split())
switch_list = []
joken_list = []

for i in range(M):
    switch = list(map(int, input().split()))[1:]
    switch_list.append(switch)
joken_list = list(map(int, input().split()))

switch_pattern_list = []
for i in itertools.product((0,1), repeat=N):
    switch_pattern_list.append(i)

output = 0

for switch_pattern in switch_pattern_list:
    for i in range(len(switch_list)):
        on = 0
        for switch_number in switch_list[i]:
            if switch_pattern[switch_number - 1] == 1:
                on += 1
        if on % 2 != joken_list[i]:
            break
        if i == len(switch_list) - 1:
            output += 1

print (output)

Measured memory_bytes: 3188
import java.util.*;

public class Main{
	public static void main(String[] args){
		int[][][] people = new int[4][3][10];
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					people[i][j][k] = 0;
				}
			}
		}

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int h = 0; h < n; h++){
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			people[b - 1][f - 1][r - 1] += v;
		}

		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					System.out.printf(" %d", people[i][j][k]);
				}
				System.out.println("");
			}
			if(i != 3){
				StringBuilder sb = new StringBuilder();
				for(int k = 0; k < 20; k++){
					sb.append("#");
				}
				String str = sb.toString();
				System.out.println(str);
			}
		}
	}
}

Measured memory_bytes: 30476
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
char s[MAX];

int main(int argc, char ** argv) {
	scanf(" %s", s);
	int sz = strlen(s);
	rep(i, 0, sz) {
	    if(i >= 1 && s[i] == s[i-1]) printf("%d %d\n", i, i+1), exit(0);
	    if(i >= 2 && s[i] == s[i-2]) printf("%d %d\n", i-1, i+1), exit(0);
	}
	puts("-1 -1");
	return 0;
}


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

#define ALL(a)  a.begin(),a.end()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define debug(x) cerr << #x << ": " << x << endl

using LL = long long; template<class T> using V = vector<T>;
int Euler_Phi(int n) {
	int res = n;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			res = res / i * (i - 1); // n (1 - 1/pk) = n - n/pk
			while (n /= i, n % i == 0); //n を素因数分解
		}
	}
	if (n != 1) res = res / n * (n - 1);
	return res;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N; cin >> N;
	cout << Euler_Phi(N) << endl;


	return 0;
}


Measured memory_bytes: 3196
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

A,B,N = FLI()

def f(x):
  return (A*x)//B - A * (x//B)
max = 0
x = min(B-1,N)

print(f(x))

Measured memory_bytes: 27172
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int n, m;
    cin >> n >> m;
    Int start = 0;
    Int end = n - 1;
    for (Int i = 0; i < m; ++i) {
        Int l, r;
        cin >> l >> r;
        --l; --r;
        if (l > start) {
            start = l;
        } 
        if (r < end) {
            end = r;
        } 
    }
    if (start > end) {
        cout << 0 << endl;
    } else {
        cout << end - start + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
    int n,k,cnt,ans;
    cin >> n >> k;
    
    cnt = (n%k);
    if(cnt == 0){
        cout << cnt << endl;
    }
    else{
    ans = 1;
    cout << ans << endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        if(D == 25) {
            System.out.println("Christmas");
        } else if(D == 24) {
            System.out.println("Christmas Eve");
        } else if(D == 23) {
            System.out.println("Christmas Eve Eve");
        } else if(D == 22) {
            System.out.println("Christmas Eve Eve Eve");
        }
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
string s;
cin>>s;
if(s.at(0)==s.at(2)){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}

}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename F>
class SegmentTree{
private:
    int sz;
    vector<Monoid> seg;
    const F op;
    const Monoid e;
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<=n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] += x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
    template<typename C>
    int find_subtree(int a,const C &check,Monoid &M,bool type) {
        while(a<sz) {
            Monoid nxt = type ? op(seg[2*a+type],M) : op(M,seg[2*a+type]);
            if(check(nxt)) a = 2*a+type;
            else M = nxt, a = 2*a+1-type;
        }
        return a - sz;
    }

    template<typename C>
    int find_first(int a,const C &check) {
        Monoid L = e;
        if(a <= 0) {
            if(check(op(L,seg[1]))) return find_subtree(1,check,L,false);
            return -1;
        }
        int b = sz;
        for(a+=sz,b+=sz;a<b;a>>=1,b>>=1) {
            if(a&1) {
                Monoid nxt = op(L,seg[a]);
                if(check(nxt)) return find_subtree(a,check,L,false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }

    template<typename C>
    int find_last(int b,const C &check) {
        Monoid R = e;
        if(b >= sz) {
            if(check(op(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for(b+=sz; a<b; a>>=1,b>>=1) {
            if(b&1) {
                Monoid nxt = op(seg[--b],R);
                if(check(nxt)) return find_subtree(b,check,R,true);
                R = nxt;
            }
        }
        return -1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    SegmentTree seg(N,[](ll a,ll b){return a+b;},0LL);
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        seg.set(i,a);
    }
    seg.build();
    while(Q--){
        int t;
        cin >> t;
        if(t==0){
            int p,x;
            cin >> p >> x;
            seg.update(p,x);
        }else{
            int l,r;
            cin >> l >> r;
            cout << seg.query(l,r) << "\n";
        }
    }
}

Measured memory_bytes: 12556
import java.util.Scanner;

/**
 * A - Duplex Printing
 * 高橋君は、全 N ページから成る書類を両面印刷します。
 * 両面印刷では、1 枚の紙に 2 ページ分のデータを印刷することが出来ます。
 * 最小で何枚の紙が必要か求めてください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 書類の枚数
        int n = sc.nextInt();
        // 両面印刷したときのプリント枚数
        double result = ( double ) n / 2;
        System.out.println( ( int ) Math.ceil( result ) );

        sc.close();
    }
}

Measured memory_bytes: 23124
#include<stdio.h>
int solve(int ,int );
int a[2000],n;
int main()
{
  int i,q,mi[2000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }
  
  for(i=0;i<q;i++){
    if(solve(0,mi[i])) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}
int solve(int i,int m){
  int ans;
  if(m==0)return 1;
  if(i>=n)return 0;
  if(solve(i+1,m) || solve(i+1,m-a[i]))return 1;
     }

Measured memory_bytes: 588
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
#define ull unsigned ll
#define uint unsigned
#define pai pair<int,int>
#define pal pair<ll,ll>
#define IT iterator
#define pb push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);++i)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);--i)
#define endl '\n'
#define ll long long
ll mo = 1e9+7;
ll mod;
int dp[man][100];
char p[man];

int dfs(int pos,int pre,bool limit,int sum){
	if(!pos)return sum%mod==0;
	int &x = dp[pos][sum];
	if(!limit&&x!=-1)return x;
	int ans = 0;
	int up = limit ? p[pos]-'0' : 9;
	For(i,0,up){
		ans = (1ll*ans + dfs(pos-1,i,limit&&i==up,(sum+i)%mod))%mo;
	}
	if(!limit)x = ans;
	return ans;
}

int slove(){
	int len = strlen(p+1);
	For(i,1,len/2)swap(p[i],p[len-i+1]);
	return dfs(len,-1,1,0);
}

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	memset(dp,-1,sizeof(dp));
	scanf("%s%d",p+1,&mod);
	printf("%d\n",(slove()-1+mo)%mo);
	return 0;
}

Measured memory_bytes: 79232
/*
[aising2019] B - Contests
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 100;

int N;
int A, B;
int P[MAX_N];
int cnt[3];

ll solve() {
    for (int i = 0; i < N; i++) {
        if (P[i] <= A) {
            cnt[0]++;
        } else if (P[i] <= B) {
            cnt[1]++;
        } else {
            cnt[2]++;
        }
    }

    return min(min(cnt[0], cnt[1]), cnt[2]);
}

int main() {
    cin >> N;
    cin >> A >> B;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define NMAX    110
#define WMAX    100010
#define MAX     UINT_MAX

long long dp[NMAX][WMAX];

long long min(long long x, long long y) {
    return (x < y) ? x : y;
}
     
int main() {

    long long i, j, n, w;
    scanf("%lld %lld", &n, &w);
    long long weights[n], values[n];
    
    for (i = 0; i < n; i++) {
        scanf("%lld %lld", &weights[i], &values[i]);
     
    }
     
    for (i = 0; i < NMAX; i++) {
        for (j = 0; j < WMAX; j++) {
            dp[i][j] = MAX;
        }
    }
    
    dp[0][0] = 0;
    for (i = 0; i < n; i++) {
        for (j = 0; j < WMAX; j++) {
            if (j >= values[i]) dp[i + 1][j] = min(dp[i][j], dp[i][j - values[i]] + weights[i]);
            else dp[i + 1][j] = dp[i][j];
        }
    }
     
    for (int i = WMAX - 1; i >= 0; i--) {

        if (dp[n][i] <= w) {
            printf("%d\n", i);

            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 86144
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N,M;

	cin >> N >> M;

	vector<int> number(N, -1);

	bool ans = true;
	for (int i = 0; i < M; i++)
	{
		int s, c;
		cin >> s >> c;
		if (number[s-1] != c && number[s - 1] != -1) ans = false;
		else number[s - 1] = c;
	}


	if (N > 1) {
		if (number[0] == 0) ans = false;
		if (number[0] == -1) number[0] = 1;
	}


	if (ans) {
		for (int i = 0; i < N; i++) {
			if (number[i] == -1)
				cout << 0;
			else
				cout << number[i];
		}
		cout << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int x=stoi(a+b);
	for(int i=0;i<1000;i++){
		if(i*i==x){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
	
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,a,b,p[110];
	cin >> n >> a >> b;
	int sumlow = 0, summid = 0, sumhigh = 0;
	for(int i=0; i<n; i++){
		cin >> p[i];
		if(p[i] <= a)
			sumlow++;
		else if(p[i] <= b)
			summid++;
		else
			sumhigh++;
	}
	int ans;
	ans = min(sumlow,summid);
	ans = min(ans,sumhigh);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	int i, j, k;
	int a[88][88], b[88][88];
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			scanf("%d", &a[i][j]);
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			scanf("%d", &b[i][j]);
	int d[88][88];
	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			if (a[i][j] > b[i][j])
				d[i][j] = a[i][j] - b[i][j];
			else
				d[i][j] = b[i][j] - a[i][j];
		}
	}
	int dp[2][88][26000];
	for (i = 0; i < w; i++)
		for (k = 0; k < 26000; k++)
			dp[0][i][k] = dp[1][i][k] = 0;
	int m = 13000;
	dp[0][0][m + d[0][0]] = dp[0][0][m - d[0][0]] = 1;
	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
			for (k = 0; k < 26000; k++)
				dp[1][j][k] = 0;
		for (j = 0; j < w; j++)
		{
			for (k = 0; k < 26000; k++)
			{
				if (dp[0][j][k] > 0)
				{
					if (i < h - 1)
						dp[1][j][k + d[i + 1][j]] = dp[1][j][k - d[i + 1][j]] = 1;
					if (j < w - 1)
						dp[0][j + 1][k + d[i][j + 1]] = dp[0][j + 1][k - d[i][j + 1]] = 1;
				}
			}
		}
		if (i < h - 1)
			for (j = 0; j < w; j++)
				for (k = 0; k < 26000; k++)
					dp[0][j][k] = dp[1][j][k];
	}
	int ans = 1000000009;
	for (k = 0; k < 26000; k++)
	{
		if (dp[0][w - 1][k] > 0)
		{
			if (k > m)
			{
				if (ans > k - m)
					ans = k - m;
			}
			else
			{
				if (ans > m - k)
					ans = m - k;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 17920
monster_num, spattack_num = input().split()

monster_num = int(monster_num)

spattack_num = int(spattack_num)

hplist = list(input().split())

hplist = list(map(int, hplist))

hplist = sorted(hplist, reverse=True)

value = 0

if spattack_num >= monster_num:
    print(0)
else:
    for i in range(spattack_num):
        hplist[i] = 0

    for i in range(monster_num):
        value = value + hplist[i]

    print(value)

Measured memory_bytes: 26764
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
    cin >> s;
    int n = 0;
    if(s == "SUN") {
        n = 7;
    }else if(s == "MON") {
        n = 6;
    }else if(s == "TUE") {
        n = 5;
    }else if(s == "WED") {
        n = 4;
    }else if(s == "THU") {
        n = 3;
    }else if(s == "FRI") {
        n = 2;
    }else {
        n = 1;
    }

    cout << n << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main()
{
    char a[5],b[5], s[5];
    gets(a);
    gets(b);
    int len=3;
    for(int i=0;i<len;i++)
    {
        s[i]=a[len-i-1];
    }
    for(int i=0;i<len;i++)
    {
        if(s[i]!=b[i])
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

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

const int MAX_N = 1<<17;
const int INF = 1<<29;


class RMQ{
  int n,dat[2*MAX_N-1];
 
public:
  RMQ(int _n = MAX_N){
    n = 1;
    while(n < _n) n *= 2;
    fill(dat, dat+2*n-1, 0);
  }
 
  void add(int k, int a){
    k += n - 1;
    dat[k] += a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = dat[k*2+1] + dat[k*2+2];
    }
  }
 
  int query(int a, int b){ return query(a, b, 0, 0, n);}
  int query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return dat[k];
    else{
      int vl = query(a, b, k*2+1, l, (l+r)/2);
      int vr = query(a, b, k*2+2, (l+r)/2, r);
      return vl + vr;
    }
  }
};


int main(){
  int n,q;
  while(cin >> n >> q){
    RMQ rmq(n+1);
    for(int i=0;i<q;i++){
      int a,x,y;
      cin >> a >> x >> y;
      if(a){
        cout << rmq.query(x, y+1) << endl;
      } else {
        rmq.add(x, y);
      }
    }
  }
}

Measured memory_bytes: 2188
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll,ll>;

int cnt[10][10];
int main(){
    int n;cin>>n;
    REP(i,1,n){
        string s = to_string(i);
        int l = (s[0]-'0'),r = (s[s.size()-1]-'0');
        cnt[l][r]++;
    }
    ll res = 0;
    REP(i,1,n){
        string s = to_string(i);
        int l = (s[0]-'0'),r = (s[s.size()-1]-'0');
        res += cnt[r][l];
    }
    cout<<res;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>     
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)5e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
 
int n, k, m, b[maxn];
vi g[maxn], gr[maxn];
int deg[maxn], degr[maxn];
string comp;
main () {
	cin >> comp;
	n = sz(comp) + 1;
  forn(i, 1, n - 1){
    int u, v;
    char s = comp[i - 1];
    u = i, v = i + 1;
    if(s == '<'){
      swap(u, v);
    }
    g[v].pb(u);
    gr[u].pb(v);
    deg[u]++;
    degr[v]++;
  }
  queue<int> q;
	forn(i, 1, n){
    if(!sz(gr[i]))
      q.push(i), b[i] = 0; 
  }
  while(sz(q)){
    int v = q.front();
    q.pop();
    for(auto to : g[v]){
      deg[to]--;
      if(!deg[to])
        b[to] = b[v] + 1, q.push(to);
    }   
  }
  int ans = 0;
  forn(i, 1, n){
  	//cout << b[i] << " ";
		ans += b[i];
	}
  cout << ans;
}

Measured memory_bytes: 67204
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


string s;

int main(){
	cin >> s;
	
	for(int i = 0; i < s.size()-8; i++){
		cout << s[i];
	}
	cout << endl;
	
	return 0;
}

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

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

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

    int maxA = a[a.size() - 1];
    std::vector<bool> dp(maxA + 1, true);
    int ans = 0;
    for (int i = 0; i < a.size(); i++)
    {
        int currentA = a[i];
        if (true == dp[currentA])
        {
            for (int j = currentA; j <= maxA; j += currentA)
            {
                dp[j] = false;
            }

            if (i == a.size() - 1)
            {
                ans++;
            }
            else
            {
                if (a[i] != a[i + 1])
                {
                    ans++;
                }
            }
        }
    }



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

Measured memory_bytes: 4036
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int dis[2020][2020];
int ans[2020];
int main()
{
	ios::sync_with_stdio(0);
	int n,x,y;
	cin>>n>>x>>y;
	x--,y--;
	rep(i,n)
		rep(j,n)
			dis[i][j]=abs(i-j);
	rep(i,n)
		rep(j,n)
			dis[i][j]=min(min(abs(x-i)+abs(y-j)+1,abs(x-j)+abs(y-i)+1),dis[i][j]);
	rep(i,n)
		rep(j,n)
			ans[dis[i][j]]++;
//	rep(i,n)
//	{
//		rep(j,n)
//			cout<<dis[i][j]<<" ";
//		cout<<endl;
//	 } 
	forn(i,1,n-1)
	{
		cout<<ans[i]/2<<endl;
	}
	return 0;
}



Measured memory_bytes: 16000
#include<iostream>
 
using namespace std;
typedef long long ll;
 
int main() {
	ll I, O, T, J, L, S, Z;
	cin >> I >> O >> T >> J >> L >> S >> Z;
	ll ans = 0;
	ans += O * 1;
	ans += (I / 2) * 2;
	ans += (J / 2) * 2;
	ans += (L / 2) * 2;
	if (I % 2 == 1 && J % 2 == 1 && L % 2 == 1)ans += 3;
	else if (I % 2 == 0 && J % 2 == 1 &&I>0&& L % 2 == 1)ans += 1;
        else if (I % 2 == 1 && J % 2 == 0 &&J>0&& L % 2 == 1)ans += 1;
        else if (I % 2 == 1 && J % 2 == 1 && L % 2 == 0&&L>0)ans += 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = [0 for _ in range(100000)]
for i in range(1, 100000):
    ans[i] = c[i] + c[i - 1] + c[i + 1]
print(max(ans))


Measured memory_bytes: 14564
#include<bits/stdc++.h>
using namespace std;
int f(int n,int A[])
{
    if(n<0)
        return 100000000;
    return A[n];
}
int func(int n,int A[],int dp[])
{
    if(n<0)
        return 100000000;
    if(n==0)
        return dp[0] = 0;
    if(dp[n]!=-1)
        return dp[n];
    return (dp[n] = min(abs(f(n,A)-f(n-1,A))+func(n-1,A,dp),abs(f(n,A)-f(n-2,A))+func(n-2,A,dp)));
}
int main()
{
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++)
        cin>>A[i];
    int dp[n];
    for(int i=0;i<n;i++)
        dp[i] = -1;
    dp[n-1] = func(n-1,A,dp);
    cout<<dp[n-1]<<endl;
}

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

int N, h[100 + 1];

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

    int ans = 0;
    int p = 0;
    for (int i = 0; i < N + 1; ++i){
        if (p > h[i]) ans += p - h[i];
        p = h[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

template<int MOD> struct Fp{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD){ if(val<0) v += MOD; }
    constexpr int getmod(){ return MOD; }
    constexpr Fp operator - () const noexcept{ return val ? MOD - val : 0; }
    constexpr Fp operator + (const Fp& r) const noexcept{ return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept{ return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept{ return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept{ return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept{ val += r.val; if(val>=MOD) val -= MOD; return *this; }
    constexpr Fp& operator -= (const Fp& r) noexcept{ val -= r.val; if(val<0) val += MOD; return *this; }
    constexpr Fp& operator *= (const Fp& r) noexcept{ val = val*r.val%MOD; return *this; }
    constexpr Fp& operator /= (const Fp& r) noexcept{
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) { long long t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        val = val*u%MOD; if(val<0) val += MOD; return *this; }
    constexpr bool operator == (const Fp& r) const noexcept{ return this->val == r.val; }
    constexpr bool operator != (const Fp& r) const noexcept{ return this->val != r.val; }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept{ return os << x.val; }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept{ return is >> x.val; }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept{
        if (n == 0) return 1; auto t = modpow(a, n/2); t = t*t; if(n & 1) t = t*a; return t; }
};
const int MOD = MODV;
using mint = Fp<MOD>;

int main(){
    Init();
    string s; cin >> s;
    mint ans = 0;
    ll cnt = 0, n = s.size();
    rep(i, n){
        if(s[i] == '0') continue;
        ans += modpow(mint(2), cnt) * modpow(mint(3), n-1-i);
        cnt++;
    }
    ans += modpow(mint(2), cnt);
    cout << ans << endl;
}

Measured memory_bytes: 3764
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import queue

def main():
    mod=10**9+7
    N=I()
    adj=[[] for _ in range(N)]
    for i in range(N-1):
        a,b=MI()
        a-=1
        b-=1
        adj[a].append(b)
        adj[b].append(a)
    bit=[-1]*N#未確認,F,S    
    bit[0]=0
    bit[-1]=1
    pL=[0]*N
    dS=0
    
    q=queue.Queue()
    q.put((0,0,0))#v.pare,depth
    
    #深さを調べる
    while not q.empty():
        v,p,d=q.get()
        pL[v]=p
        if v==N-1:
            dS=d
            break
        for i in range(len(adj[v])):
            nv=adj[v][i]
            if nv!=p:
                q.put((nv,v,d+1))
    
    #主要なところを塗る            
    v=N-1            
    for _ in range((dS-1)//2):
        v=pL[v]
        bit[v]=1
        
    q2=queue.Queue()
    q2.put((0,0))#v.pare
    while not q2.empty():
        v,p=q2.get()
        if bit[v]==-1:
            bit[v]=bit[p]

        for i in range(len(adj[v])):
            nv=adj[v][i]
            if nv!=p:
                q2.put((nv,v))
        
        
                    
    s=sum(bit)#sunukeが塗れる
    if s>=N-s:
        print("Snuke")
    else:
        print("Fennec")
     
        
    
    

main()


Measured memory_bytes: 83484
#!/usr/bin/env python3
#ABC146 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lst = list(alpha+alpha)
ans = ''
for i in range(len(s)):
    ans += lst[alpha.index(s[i])+n]
print(ans)

Measured memory_bytes: 41324
# -*- coding: utf-8 -*-
"""
A - Snuke's favorite YAKINIKU
https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_a

"""
import sys


def solve(S):
    if S.startswith('YAKI'):
        return 'Yes'
    return 'No'


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
vector<P> v;
vector<int> a;


void f(int x,int y){
  rep(i,a.size()){
    if(abs(x)>abs(y)){
      if(x>0){
        x-=a[i];
        cout<<'R';
      }else{
        x+=a[i];
        cout<<'L';
      }
    }else{
      if(y>0){
        y-=a[i];
        cout<<'U';
      }else{
        y+=a[i];
        cout<<'D';
      }
    }
  }
  cout<<endl;
//  cout<<x<<' '<<y<<endl;
}


main(){
  cin>>n;
  rep(i,n){
    int x,y;
    cin>>x>>y;
    v.PB(P(x,y));
  }

  int r=2;
  rep(i,32){
    a.PB(r);
    r*=2;
  }

  int b=(abs(v[0].F)+abs(v[0].S))%2;

  rep(i,n){
    if((abs(v[i].F)+abs(v[i].S))%2!=b){
      cout<<-1<<endl;
      return 0;
    }
  }

  a.PB(1);
  a.PB(1);

  if((abs(v[0].F)+abs(v[0].S))%2)
    a.erase(a.end()-1);

  sort(all(a));
  reverse(all(a));

  cout<<a.size()<<endl;
  rep(i,a.size()){
    if(i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;

  rep(i,n){
    f(v[i].F,v[i].S);
  }

}



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

using namespace std;

int main() {
  int N;
  
  cin >> N;
  
  vector<int> A;
  vector<long long> A_num(N + 1, 0);
  
  for (int i = 0; i < N; i++) {
    int in;
    
    cin >> in;
    
    A.push_back(in);
    A_num[in]++;
  }
  
  long long sum = 0;
  
  for (int i = 0; i < N + 1; i++) {
    sum += A_num[i] * (A_num[i] - 1) / 2;
  }
  
  vector<long long> A_num_2(N + 1, sum);
  
  for (int i = 0; i < N + 1; i++) {
    if (A_num[i] > 1) {
      A_num_2[i] = sum - (A_num[i] - 1);
    }
  }
  
  for (int i = 0; i < N; i++) {
    cout << A_num_2[A[i]] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 6644
#include <stdio.h>

int main(void){
  int a[20];
  int i,c,n;

  for(i=0;i<20;i++){
    a[i]=-1;
  }
  i=0;
  c=getchar();
  while(c != '\n'){
    a[i]=c;
    c=getchar();
    i++;
  }
  n=i;
  for(i=n-1;i>=0;i--){
    printf("%c",a[i]);
  }
  printf("\n");

  return 0;

}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)

int main() {
  int n, d;
  string s;
  cin >> s;
  if(s.at(0) == s.at(1) && s.at(0) == s.at(2) && s.at(0) == s.at(3)) cout << "No" << endl;
  else if(s.at(0) == s.at(1) && s.at(2) == s.at(3) || s.at(0) == s.at(2) && s.at(1) == s.at(3) || s.at(0) == s.at(3) && s.at(1) == s.at(2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mxn=21;
string arr[mxn];
int dp[mxn][mxn];
int h,w;
int ans=0;
int dis[mxn+1][mxn+1];
int solve(int u,int v)
{
queue<pair<int,pair<int,int>>> q;
memset(dis,0,sizeof dis);
q.push({u,{v,0}});
int t=14;

while(!q.empty())
{
	int i=q.front().first;
	int j=q.front().second.first;
	int d=q.front().second.second;
	ans=max(ans,d);
	dis[i][j]=1;
	q.pop();
//	cout<<i<<" "<<j<<" "<<q.size()<<"\n";
	if(i+1<h and dis[i+1][j]==0 and  arr[i+1][j]=='.')
	{
		q.push({i+1,{j,d+1}});
		dis[i+1][j]=1;
	}
		if(j+1<w and dis[i][j+1]==0 and  arr[i][j+1]=='.')
	{
		q.push({i,{j+1,d+1}});
		dis[i][j+1]=1;
	}
	if(i-1>=0 and dis[i-1][j]==0 and arr[i-1][j]=='.')
	{
			q.push({i-1,{j,d+1}});
		dis[i-1][j]=1;
	}
		if(j-1>=0 and dis[i][j-1]==0 and  arr[i][j-1]=='.')
	{
		q.push({i,{j-1,d+1}});
		dis[i][j-1]=1;
	}
}
return 0;
}
int main() {
	// your code goes here
	cin>>h>>w;
	for(int i=0;i<h;i++)
	cin>>arr[i];
//	int ans=0;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
		if(arr[i][j]=='.')
			solve(i,j);
	//	break;
		}
		//break;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256