akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2 * (1e5 + 5);

int main()
{
    fastio;
    ll i, j, k, t, n, m=0;
    ll a[maxn],b[maxn];
    cin>>n>>k;

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

    for ( i = 0; i < k-1; i++)
    {
        b[0]=a[0];
        if(i>0)
        {
            b[i]=b[i-1]*a[i];
        }
    }
    
    for ( i = k; i < n; i++)
    {
        m=0;
        if(a[i-k]>=a[i])
            m=1;
        if (m==0)
        {
            cout<<"Yes"<<endl;
        }
        else 
        {
            cout<<"No"<<endl;
        }   
    }
    
    
    

    return 0;
}

Measured memory_bytes: 5216
import java.util.Scanner;
 
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    int ans = 0;
    if(S.length()%2==0){
      if(S.charAt(S.length() /2 -1) != S.charAt(S.length() /2)){
        System.out.println(S.length() /2);
        return;
      }else{
        S = S.substring(0, S.length() /2) + S.substring(S.length() /2 +1);
        ans =1;
      }
    }
    int mid = S.length() /2;
    for(int i=1;i+mid <= S.length();++i){
      if(i+mid==S.length() || S.charAt(mid+i)!=S.charAt(mid) || S.charAt(mid-i)!=S.charAt(mid)){
        ans += mid + i;
        break;
      }
    }
    System.out.println(ans);
  }
}
      

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

string change(string s) {
	string res = "";
	char c = s.front();
	int count = 1;
	for (auto i = s.begin()+1;i != s.end();++i) {
		if (*i == c) {
			++count;
		} else {
			res += to_string(count) + c;
			c = *i;
			count = 1;
		}
	}
	res += to_string(count) + c;
	return res;
}

int main() {
	while (true) {
		int n;
		cin >> n;
		cin.ignore();
		if (n == 0) {
			break;
		}
		string s;
		cin >> s;
		while (n--) {
			s = change(s);
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a,b;cin>>a>>b;
    if(a%2 && b%2)cout<<"Yes";
    else cout<<"No";
}


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

struct edge {
    ll from, to, cost;
};

ll n, m, d[1009];

vector<edge> e;

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

    cin >> n >> m;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        e.push_back({a, b, -c});
    }
    fill(d, d + 1009, 1e18);
    d[1] = 0;
    rep(i, n - 1) rep(j, m) chmin(d[e[j].to], d[e[j].from] + e[j].cost);
    bool inf[1009] = {};
    rep(i, n) rep(j, m) {
        if(d[e[j].to] > d[e[j].from] + e[j].cost) {
            d[e[j].to] = d[e[j].from] + e[j].cost;
            inf[e[j].to] = true;
        }
        inf[e[j].to] |= inf[e[j].from];
    }
    inf[n] ? cout << "inf" : cout << -d[n];
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AOJ_problem_01
{

    class Program
    {
        static int[] a;
        static int[] countbox;        
        static int maxindex;
        static List<int> result;

        static void CountingSrot(long n)
        {
            

            for(int i = 0; i < a.Length; i++)
            {                
                countbox[a[i]]++;
            }           

            for(int i = 0; i <= maxindex; i++)
            {
                if(countbox[i] != 0)
                {                   
                    for(int j = 1; j <= countbox[i]; j++)
                    {                        
                        result.Add(i);
                    }
                }                
            }

        }
      
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            a = new int[n];           

            string[] str = Console.ReadLine().Split(' ');

            int k = 0;
            maxindex = 0;
            for(long i = 0; i < n; i++)
            {
                k = int.Parse(str[i]);
                if (maxindex < k)
                {
                    maxindex = k;
                }
                a[i] = k;
            }

            countbox = new int[maxindex + 1];
            result = new List<int>();
            
            CountingSrot(n);

            Console.WriteLine(String.Join(" ", result));
            
        }

    }

}




Measured memory_bytes: 170200
N, X, M = map(int, input().split())

exist = [0 for _ in range(M)]


def f(a, m):
  return a % m

S = 0
A = X
ls = []
for n in range(1, N + 1):
  if exist[A] == 0:
    exist[A] = n
    ls.append(A)
  else:
    term = n - exist[A]
    loop = ls[-term:]
    res = N - n + 1
    S += (res // term) * sum(loop) + sum(loop[:res % term])
    break
  S += A
  A = f(A**2, M)

print(S)

Measured memory_bytes: 13948
#include <iostream>

using namespace std;

int main() {
    int a, b;   cin >> a >> b;
    int ans = 1;
    for (ans = 1; ans <= 100000; ans++) {
        int xa = ans * 8 / 100;
        int xb = ans * 10 / 100;
        if (a == xa && b == xb) {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ac = [False] * n
wa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC':
        if not ac[p]:
            ac[p] = True
    else:
        if not ac[p]:
            wa[p] += 1

a = 0
b = 0

for i in range(n):
    if ac[i]:
        a += 1
        b += wa[i]

print(*[a, b])

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main()
{
	for(int i=0;i<3;i++)
	scanf("%d",&a[i]);
	sort(a,a+3);
	int sum=0;
	while(a[1]!=a[0])
	{
		if((a[1]-a[0])%2)
		{
			a[2]++;
			a[0]++;
			sum++;
		}
		else
		{
			a[0]=a[0]+2;
			sum++;
		}
	}	
	while(a[0]!=a[2])
	{
		if((a[2]-a[1])%2)
		{
			a[1]++;	
			a[0]++;
			sum++;
		}
		else
		{
			a[0]=a[0]+2;
			sum=sum+2;
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, h[100100], dp[100100];

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < 100100; i++) dp[i] = inf;

    dp[0] = 0;
    for(int i = 1; i < n; i++){
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()

int main() {
    int r, d, x;
    scanf("%d %d %d", &r, &d, &x);
    rep(i,10) {
        printf("%d\n", r*x-d);
        x = r*x-d;
    }
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline().rstrip())
w = [int(i) for i in stdin.readline().rstrip().split(" ")]
sumAll = sum(w)
result = sumAll
for i in range(n):
    tmp = abs(sumAll - 2 * sum(w[i:]))
    if tmp < result:
        result = tmp
print(result)

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

int run() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if (a < b) std::swap(a, b);
  if (a < c) std::swap(a, c);
  if (a == 7 && b == 5 && c == 5) puts("YES");
  else puts("NO");
}

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


Measured memory_bytes: 256
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize
    }
    let p = (1..n + 1).fold(0, |p, a| p + (a & 0x1));

    ((p as f64) / n as f64).to_string()
}
test! {
    "4" => "0.5",
    "5" => "0.6",
    "1" => "1"
}


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

int main() {
  
  int a;
  cin >> a;
  
  if (a%1111 == 0 || a/10%111 == 0 || a%1000%111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int N, M;
bool edges[700][700];



int main(){
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            edges[i][j] = true;
        }
    }
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1][b-1] = edges[b-1][a-1] = false;
    }

    stack<pair<int, int> > stk; // now idx, now color
    int color[700] = {};
    int st[2][700] = {};
    bool is_separable = true;
    for(int i = 0; i < N; i++){
        if(color[i] == 0){
            stk.push(make_pair(i, 1));
            color[i] = 1;
            while(!stk.empty()){
                int now = stk.top().first;
                int now_color = stk.top().second;
                stk.pop();
                st[now_color - 1][i]++;
                for(int j = 0; j < N; j++){
                    if(edges[now][j] && now != j && color[now] == color[j]){
                        is_separable = false;
                    }else if(edges[now][j] && color[j] == 0){
                        color[j] = (color[now] % 2) + 1;
                        stk.push(make_pair(j, color[j]));
                    }
                }
            }
        }
    }
    if(!is_separable){
        cout << -1 << endl;
        return 0;
    }
    bool dp[701][701] = {};
    dp[0][0] = true;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= N; j++){
            if(dp[i][j] && j + st[0][i] <= 700){
                dp[i+1][j + st[0][i]] = true;
            }
            if(dp[i][j] && j + st[1][i] <= 700){
                dp[i+1][j + st[1][i]] = true;
            }
        }
    }
    int  ans = M;
    for(int i = 0; i <= N; i++){
        if(dp[N][i]){
            ans = min(ans, i*(i-1)/2 + (N-i)*(N-i-1)/2);
        }
    }
    cout << ans << endl;
    
}

    


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    int A, B; cin >> A >> B;
    if (A == 1) A = 14;
    if (B == 1) B = 14;
    cout << (A > B ? "Alice" : A == B ? "Draw" : "Bob") << endl;
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

class DisjointSet {
public:
  vector<int> rank, p, size;

  DisjointSet() {}
  DisjointSet(int s) {
	rank.resize(s, 0);
	p.resize(s, 0);
	size.resize(s, 0);
	rep (i, s) init(i);
  }

  void init(int x) {
	p[x] = x;
	rank[x] = 0;
	size[x] = 1;
  }

  bool isSame(int x, int y) {
	return root(x) == root(y);
  }

  void makeSet(int x, int y) {
	if (isSame(x, y)) return;
	link(root(x), root(y));
  }

  void link(int x, int y) {
	if (rank[x] > rank[y]) {
	  p[y] = x;
	  size[x] += size[y];
	} else {
	  p[x] = y;
	  size[y] += size[x];
	  if (rank[x] == rank[y]) {
		rank[y]++;
	  }
	}
  }

  int root(int x) {
	if (x != p[x]) {
	  p[x] = root(p[x]);
	}
	return p[x];
  }

  int getSize(int x) {
	return size[root(x)];
  }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
	cin >> n >> m;
	DisjointSet dj = DisjointSet(n);
	rep (i, m) {
	  int a, b;
	  cin >> a >> b;
	  dj.makeSet(a - 1, b - 1);
	}
	int res = 0;
	rep (i, n) res = max(res, dj.getSize(i));
	cout << res << endl;
	
    return 0;
}


Measured memory_bytes: 5584
def cal(x): return (x+1)/2
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=sum([cal(p[i]) for i in range(k)])
cnt=ans
for i in range(k,n):
  cnt=cnt-cal(p[i-k])+cal(p[i])
  ans=max(ans,cnt)
print(ans)

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

using namespace std;

void print_f(vector< vector<int> > v,int h){
  for(int i=0;i<h;i++){
    cout << "node " << v[i][0] << ": key = " << v[i][1] << ", ";
    if(v[i][2]!=0)cout << "parent key = " << v[v[i][2]-1][1] << ", ";
    if(v[i][3]<=h) cout << "left key = " << v[v[i][3]-1][1] << ", ";
    if(v[i][4]<=h) cout << "right key = " << v[v[i][4]-1][1] << ", ";
    cout << endl;
  }
}


int main(){
  int h;cin >> h;
  vector< vector<int> > v(h);
  for(int i=0;i<h;i++){
    int k;cin >> k;
    v[i].push_back(i+1);
    v[i].push_back(k);
    int p = -int(-(i+1)/2);
    v[i].push_back(p);
    int l = 2*(i+1);
    v[i].push_back(l);
    int r = 2*(i+1)+1;
    v[i].push_back(r);
  }
  print_f(v,h);


}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define ll long long
#define exp 0.001
#define sqr(x) ((x) * (x))
using namespace std;
ll read() {ll x = 0;char f = 1, ch = getchar();while(ch < '0' || ch > '9') {if(ch == '-')f = -1;
ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();}return x * f;}
void write(ll x) {if(x < 0) x = -x, putchar('-');if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
const int N = 210000;
int n, ans = 0x3f3f3f3f;
int cal(int x) {
	int res = 0;
	while(x) {
		res += x % 10;
		x /= 10;
	}
	return res;
}
int main() {
	n = read();
	for(int i = 1; i < n; ++i)
		ans = min(ans, cal(i) + cal(n - i));
	writeln(ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
//#define _USE_MATH_DEFINES
#include <cmath>

int main(){
    
    double r,s,l;

    std::cin >> r;

    s = M_PI * r * r;
    l = 2 * M_PI * r;

    printf("%f %f",s,l); //coutだと6桁しか表示してくれない？

    return 0;
}



Measured memory_bytes: 3212
#include"bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	int ans;
	if (N < 2) {
		ans = 1;
	}
	else if (N < 4) {
		ans = 2;
	}
	else if (N < 8) {
		ans = 4;
	}
	else if (N < 16) {
		ans = 8;
	}
	else if (N < 32) {
		ans = 16;
	}
	else if (N < 64) {
		ans = 32;
	}
	else {
		ans = 64;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007 
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        ll m1=1e18;
        if(a[0]==0){
            cout<<"0\n";
        }
        else{
            long long ans=1;
            for(long long i=0;i<n;i++){
                if(ans<=m1/a[i]){
                    ans*=a[i];
                }
                else{
                    ans=-1;
                    break;
                }
            }
            cout<<ans<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 4440
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		int result = 0;
		TreeSet<Integer> ts = new TreeSet<Integer>();
		int tmp = 1;
		while(tmp <= n){
		    ts.add(tmp);
		    tmp *= 6;
		}
		tmp = 1;
		while(tmp <= n){
		    ts.add(tmp);
		    tmp *= 9;
		}
		int[] dp = new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 0; i < n+1; i++){
		    for(Integer j : ts){
		        if(i + j > n) break;
		        dp[i + j] = min(dp[i] + 1, dp[i + j]);
		    }
		}
		result = dp[n];
		
		// 出力
		System.out.println(result);
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll X, A, B;
    cin >> X >> A >> B;

    string res;
    if(B-A<=0){
    	res = "delicious";
    }else if(B-A<=X){
    	res = "safe";
    }else{
    	res = "dangerous";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n ,x;
	while(1){
	scanf("%d %d",&n,&x);
	if (n == 0 && x == 0)
	break;
	int i, j, k, t;
	t = 0;
	for(i = 1;i < n-1;i++){
		for(j = i+1; j < n;j++){
			for(k = j+1;k <= n;k++){
				if (i + j + k == x){
					t++;
				}
			}
		}
	}
	printf("%d\n",t);
	}
	return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for (i=a; i<=b; i++)
#define ll long long
using namespace std;

const int N=200005;
int n, i, t;
ll ans;
int a[N];

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]), a[i]-=i;
	sort(a+1,a+n+1), t=a[(n+1)>>1];
	fo(i,1,n) ans+=abs(t-a[i]);
	printf("%lld",ans);
}

Measured memory_bytes: 1024
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readStr() -> [String] {
  let str:String = readLine()!
  let arr:[String] = str.components(separatedBy: " ")
  return arr
}

let nb=readInts()
let n=nb[0]
let strs=readStr()
let S=strs[0]

var ans=0

for i in 0..<n-2{
  let c1=S[S.index(S.startIndex,offsetBy:i)]
  let c2=S[S.index(S.startIndex,offsetBy:i+1)]
  let c3=S[S.index(S.startIndex,offsetBy:i+2)]
  if (c1=="A")&&(c2=="B")&&(c3=="C"){ans+=1}
}

print(ans)

Measured memory_bytes: 14296
from itertools import compress

import numpy as np

N, M, X = [int(x) for x in input().split()]
CA = np.array([[int(x) for x in input().split()] for _ in range(N)])

minimal_cost = None
for bought_book in range(1, 2**N):
    bought_book = [int(b) for b in ("{:0" + str(N) + "b}").format(bought_book)]

    CA_filtered = np.array(list(compress(CA, bought_book)))

    total_cost = sum(CA_filtered[:, 0])
    total_understanding = np.sum(CA_filtered[:, 1:], axis=0) >= X
    if np.all(total_understanding):
        minimal_cost = min(minimal_cost or total_cost, total_cost)

print(minimal_cost if minimal_cost is not None else "-1")


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

int main() {
  int a, b, c, cnt=0;
  cin >> a >> b >> c;
  if (a==b && b==c) {
  	cout << 1;
    return 0;
  }
  if (a!=b) cnt++;
  if (a!=c) cnt++;
  if (b!=c) cnt++;
  cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char s[200],n;
char ans[]={0,'k','e','y','e','n','c','e'};
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n<7){
		printf("NO");
		return 0;
	}
	bool done=0;
	for(int i=1;i<=8;i++){
		int t=1,ok=1;
		for(int j=1;j<i;j++,t++)if(ans[t]!=s[j])ok=0;
		for(int j=i+(n-7);j<=n;j++,t++)if(ans[t]!=s[j])ok=0;
		if(ok==1){
			done=1;
			break;
		}
	}
	if(done)printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<ll> v(n+1);
    v[0] = 2;
    v[1] = 1;
    for(int i = 2; i <= n; i++){
        v[i] = v[i-1] + v[i-2];
    }
    cout << v[n] << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>A(N+1);
  vector<int>B(N);
  for(int i=0; i<N+1; i++)cin >> A.at(i);
  for(int i=0; i<N; i++)cin >> B.at(i);
  
  int64_t ans=0;
  int m;
  for(int i=N-1; i>=0; i--){
    m = min(A.at(i+1), B.at(i));
    ans += m;
    B.at(i) -= m;
    
    m= min(A.at(i), B.at(i));
    ans += m;
    A.at(i) -=m;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
    using namespace std;
     
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    #define int long long
     
    const int N=1e5+5;
     
    int n, k, cur=0;
    int a[N];
     
    int32_t main()
    {
    	IOS;
    	cin>>n>>k;
    	for(int i=1;i<=n;i++)
    		cin>>a[i];
    	for(int i=50;i>=0;i--)
    	{
    		int cnt=0;
    		for(int j=1;j<=n;j++)
    		{
    			if((a[j]>>i)&1)
    				cnt++;
    		}
    		if(cnt*2<n && (cur+(1LL<<i)<=k))
    			cur+=(1LL<<i);
    	}
    	int ans=0;
    	for(int i=1;i<=n;i++)
    		ans+=(cur^a[i]);
    	cout<<ans;
    	return 0;
    }

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    if (accumulate(v.begin(), v.end(), 0ll) < x) {
        cout << n - 1 << endl;
        ret();
    }

    sort(v.begin(), v.end());
    int ans = 0;
    rep(i, n) {
        if (v[i] <= x) {
            x -= v[i];
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char str[256];
  while(1){
    scanf("%s", str);
    if(str[0] == '-') break;
    int strlen;
    for(strlen = 0; str[strlen] != '\0'; strlen++){}
    int m;
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
      int h;
      scanf("%d", &h);
      char temp[h];
      for(int j = 0; j < h; j++){
        temp[j] = str[j];
      }
      for(int j = 0; j < strlen - h; j++){
        str[j] = str[j + h];
      }
      for(int j = 0; j < h; j++){
        str[strlen - h + j] = temp[j];
      }
    }
    printf("%s\n", str);
  }
}



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

void Yn(bool b) {
	if (b)cout << "Yes" << endl;
	else cout << "No" << endl;
}

signed main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)cin >> a[i];
	sort(a.begin(), a.end());
	if (n % 3 != 0)Yn(a.back() == 0);
	else {
		int nn = n / 3;
		for (int i = 0; i < nn; ++i) {
			if ((a[i] ^ a[i + nn] ^ a[i + 2 * nn]) != 0) {
				Yn(false);
				return 0;
			}
		}
		Yn(true);
	}
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

const int md = 1000000007;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int sub(int a, int b) 
{
	a -= b;
	if (a < 0) a += md;
	return a;
}
inline int mul(int a, int b) 
{
	return (int)((long long)a * b % md);
}
inline int po(int a, int b) 
{
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

vector<int> g;
int n;
map<pair<long long, long long>, int> m;
vector<int> v;

int main() 
{
	for (int bit = 0; bit < 16; ++bit) 
		if (!((bit & 1) && (bit & 2)) && !((bit & 2) && (bit & 4)) && !((bit & 4) && (bit & 8)) && !((bit & 8) && (bit & 1))) g.push_back(bit);
	scanf("%d", &n);
	pair<int, int> z(0, 0);
	int both = 0;
	long long a, b;
	for (int i = 0; i < n; ++i) {
		scanf("%lld%lld", &a, &b);
		if (!a || !b) {
			if (!a && b) ++z.first;
			else if (a && !b) ++z.second;
			else ++both;
			continue;
		}
		long long gcd = __gcd(a, b);
		a /= gcd;
		b /= gcd;
		++m[make_pair(a, b)];
	}
	v.push_back(sub(po(2, z.first) + po(2, z.second), 1));
	for (map<pair<long long, long long>, int>::iterator it = m.begin(); it != m.end(); ++it) if (it->second != -1) {
		pair<long long, long long> t = it->first;
		int s[4] = {0};
		for (int i = 0; i < 4; ++i) {
			if (m.count(t)) {
				s[i] = m[t];
				m[t] = -1;
			}
			else s[i] = 0;
			t.first *= -1;
			swap(t.first, t.second);
		}
		v.push_back(0);
		for (int i = 0; i < g.size(); ++i) {
			int cur = 1;
			for (int j = 0; j < 4; ++j) if ((g[i] >> j) & 1) cur = mul(cur, sub(po(2, s[j]), 1));
			v.back() = add(v.back(), cur);
		}
	}
	int ans = 1;
	for (int i = 0; i < v.size(); ++i) ans = mul(ans, v[i]);
	printf("%d\n", sub(ans, 1) + both);
	return 0;
}


Measured memory_bytes: 16224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a,b,q;cin>>a>>b>>q;
    ll s[a+1];for(ll i=0;i<a;i++)cin>>s[i];
    s[a]=1e15;
    ll ns[a+1];for(ll i=0;i<a;i++)ns[i]=-1*s[i];
    sort(ns,ns+a);
    ns[a]=1e15;
    ll t[b+1];for(ll i=0;i<b;i++)cin>>t[i];
    t[b]=1e15;
    ll nt[b+1];for(ll i=0;i<b;i++)nt[i]=-1*t[i];
    sort(nt,nt+b);
    nt[b]=1e15;
    while(q--){
        ll x;cin>>x;

        ll rs = lower_bound(s,s+a+1,x) - s;
        ll ls = lower_bound(ns,ns+a+1,-1*x) - ns;

        rs = s[rs];
        ls = ns[ls]*(-1);

        ll rt = lower_bound(t,t+b+1,x) - t;
        ll lt = lower_bound(nt,nt+b+1,-1*x) - nt;

        rt=t[rt];
        lt=nt[lt]*(-1);


        ll op1 = max(rs-x,rt-x);
        ll op2 = max(x-ls,x-lt);
        ll op3 = rt - ls + min(x-ls , rt-x);
        ll op4 = rs - lt + min(rs-x , x-lt);

        //cout<<ls<<" "<<lt<<" "<<x<<" "<<rs<<" "<<rt<<" "<<op1<<" "<<op2<<" "<<op3<<" "<<op4<<"\n";
        cout<<min({op1,op2,op3,op4})<<"\n";
    }
}

Measured memory_bytes: 4480
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

struct process {
	string name;
	int time;
};

int main() {

	int n, q;
	scanf("%d %d", &n, &q);

	queue<process> Q;
	for (int i = 0; i < n; ++i) {
		process p;
		cin >> p.name >> p.time;
		Q.push(p);
	}

	int past = 0;
	while (!Q.empty()) {
		process p = Q.front();
		Q.pop();
		if (p.time <= q) {
			cout << p.name << " " << p.time + past << endl;
			past += p.time;
		} else {
			p.time -= q;
			Q.push(p);
			past += q;
		}
	}

	return 0;
}

Measured memory_bytes: 6284
/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
*/
/*
*/
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010];
vector<int> vis(100010,0);
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
bool cmp(pair<ll,ll>p1,pair<ll,ll>p2)
{
    return p1.ss<p2.ss;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //let's fuck dp
    int n;
    cin>>n;
    vector<pair<ll,ll>>v;
    f(i,n)
    {
        ll a,b;
        cin>>a>>b;
        v.pb({a,b});
    }
    sort(all(v),cmp);
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        if(sum+v[i].ff<=v[i].ss)
        {
            sum=sum+v[i].ff;
        }
        else
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 9072
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

A,B,C,D=[int(i) for i in input().split()]
A=A-1
CD=lcm(C,D)
AC=A//C;BC=B//C
AD=A//D;BD=B//D
ACD=A//CD;BCD=B//CD
#print(AC,BC,AD,BD,ACD,BCD)
print(B-A-(BC-AC+BD-AD-(BCD-ACD)))


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    string S;
    cin >> S;
    int N = S.length();
    bool ans = true;
    for (int i = 0; i < N / 2; i++) {
        if (S[i] != S[N - i - 1]) {
            ans = false;
        }
    }
    for (int i = 0; i < (N - 1) / 4; i++) {
        if (S[i] != S[(N - 1) / 2 - i - 1]) {
            ans = false;
        }
    }
    string str = S.substr((N + 3) / 2 - 1);
    for (int i = 0; i < str.length() / 2; i++) {
        if (str[i] != str[str.length() - i - 1]) {
            ans = false;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main(void)
{
    int n, m, l;

    scanf("%d %d %d", &n, &m, &l);

    int matrix1[n][m];
    int matrix2[m][l];
    long long int matrix3[n][l];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &matrix1[i][j]);
        }
    }

    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            scanf("%d", &matrix2[i][j]);
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            matrix3[i][j]=0;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {
            for(int k=0;k<m;k++){
                matrix3[i][j]+=matrix1[i][k]*matrix2[k][j];
            }

            printf("%lld",matrix3[i][j]);
            if(j==l-1)printf("\n");
            else printf(" ");
        }
    }
    return 0;
}


Measured memory_bytes: 2044
// made by egor <https://pypi.org/project/egor/>
// @author MaxHeap

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <map>

using namespace std;

int main() {
  int n, k; cin >> n >> k;
  vector<int> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 0;
  for(int i = 0; i < (n - k); ++i) {
    ans += v[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import math
import fractions
import sys
import itertools
import numpy as np
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))

def euclid(town,dist):
	#town:[1,2,3]だと，1->2->3の距離を返す
	ans=0
	for i in range(1,len(town)):
		ans+=math.sqrt(( dist[town[i]-1][0] - dist[town[i-1]-1][0] )**2 + ( dist[town[i]-1][1] - dist[town[i-1]-1][1]) **2 )
	return ans

n=input1()
dist=[]
for _ in range(n):
	dist.append(input_array())
town=[i+1 for i in range(n)]
towns=list(itertools.permutations(town))

res=0

for i in towns:
	res+=euclid(list(i),dist)
print(res/len(towns))


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

int v[64];
int ans = - ( 0x3f3f3f3f );

signed main() {

    int n, k;
    scanf("%d %d" , &n, &k);

    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &v[i]);
    }

    for ( int i = 0; i <= n; i++ ) {
        for ( int j = 0; j <= n; j++ ) {
            if ( i + j <= min ( n, k ) ) {
                int r = max(0, k - ( i + j ));
                vector<int> s;
                for ( int k = 0; k < i; k++ ) {
                    s.push_back(v[k]);
                }
                for ( int k = 0; k < j; k++ ) {
                    s.push_back(v[n-k-1]);
                }
                sort(s.begin(), s.end());
                int sum = 0;
                for ( int k = 0; k < s.size(); k++ ) {
                    if ( r > 0 && s[k] < 0 ) {
                        r--;
                    }
                    else {
                        sum += s[k];
                    }
                }
                ans = max ( ans, sum );
            }
            else break;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x - r < 0 || W <x + r || y - r < 0 || H <y + r){
	printf("No\n");
}
else{
	printf("Yes\n");
}
return 0;
}

Measured memory_bytes: 584
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
#define MOD 1000000007
#define eisiorti sort
using namespace std;
int a[MAXN];
int n;
int dp[MAXN/2][MAXN][MAXN];
int main(){
	SF("%d",&n);
	for(int i=1;i<=2*n-1;i++)
		SF("%d",&a[i]);
	eisiorti(a+1,a+2*n);
	dp[n][1][0]=1;
	for(int i=n;i>=2;i--){
		int al=(a[i-1]!=a[i]);
		int ar=(a[2*n-i+1]!=a[2*n-i]);
		for(int l=0;l<=2*n-1;l++)
			for(int r=0;r+l<=2*n-1;r++)
				if(dp[i][l][r]){
					for(int dl=1;dl<=l+al;dl++)
						(dp[i-1][l+al-dl+1][r+ar+(dl>1)]+=dp[i][l][r])%=MOD;	
					for(int dr=1;dr<=r+ar;dr++)
						(dp[i-1][l+al+1][r+ar-dr]+=dp[i][l][r])%=MOD;	
				}
	}
	int ans=0;
	for(int l=0;l<=2*n-1;l++)
		for(int r=0;r+l<=2*n-1;r++)
			(ans+=dp[1][l][r])%=MOD;
	PF("%d",ans);
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

const int N=100005;

int n,l,r,m,ans;
int a[N],vis[N];
char s[N];
vector<int> lev[N];

void dfs(int k){
	int u,j; ans+=a[k];
	vis[k]=1;
	for (j=0;j<lev[k].size();j++){
		u=lev[k][j];
		if (vis[u]) continue;
		dfs(u);
	}
}

int main(){
	int i;
	scanf("%s",s+1); n=strlen(s+1);
	scanf("%d",&m);
	for (i=1;i<=m;i++){
		scanf("%d%d",&l,&r);
		lev[l-1].push_back(r);
		lev[r].push_back(l-1);
	}
	s[0]=s[n+1]='a';
	for (i=0;i<=n;i++) a[i]=((s[i+1]-s[i])%26+26)%26;
	for (i=0;i<=n;i++) lev[i].push_back(n-i);
	for (i=0;i<=n;i++)
		if (!vis[i]){
			ans=0;
			dfs(i);
			if (ans%26!=0){
				printf("NO\n");
				return 0;
			}
		}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 8320
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define OrderSetTree tree<ll,null_type/*mapped_type*/,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    //OrderSetTree ost;
    ll i,j,t,n,p;
    string s;
    vector<char>v;

    cin>>s;

    for(i=0;s[i];i++)
    {
        if(s[i]=='B')
        {
            if(!v.empty())
                v.pop_back();
        }
        else
            v.push_back(s[i]);
    }

    for(auto i:v)
        cout<<i;

    cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 3620
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    v = 0
    for j in range(m):
        v += a[j]*b[j]
    if v + c > 0:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

inline ll read(){
	int x = 0, f = 1; char ch = getchar();
	while (ch>'9' || ch<'0'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); }
	return x*f;
}

/***********************************************************/

const int maxn = 105;
int a[maxn];

int main() {
	
	string s;
	cin >> s;
	int len = s.size();
	int a1 = 0;
	int b1 = 0;
	for (int i = 0; i < len; i += 2){
		if (s[i] == '0') a1++;
		else b1++;
	}
	int a2 = 0;
	int b2 = 0;
	for (int j = 1; j < len; j += 2){
		if (s[j] == '0') a2++;
		else b2++;
	}

	int ans = a1 + b2;
	ans = min(ans, b1 + a2);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <numeric>
#include <map>
#include <iomanip>
#include <queue>
using namespace std;

const int INF = 1000000000;
void chmin(int &a, int b) {if(a > b) a = b;}

int main(){
	int N; cin >> N;
	vector<string> S(N);
	for(int i  = 0; i < N; i++) cin >> S[i];

	map<char, long long> ma;
	char list[5] = {'M', 'A', 'R', 'C', 'H'};
	for(int i = 0; i < 5; i++) ma[list[i]] = 0;
	for(int i = 0; i < N; i++) ma[S[i].front()]++;
	
	long long res = 0;
	for(int i = 0; i < 3; i++){
		for(int j = i + 1; j < 4; j++){
			for(int k = j + 1; k < 5; k++){
				res += ma[list[i]] * ma[list[j]] * ma[list[k]];
			}
		}
	}
	cout << res << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  while (cin >> s) {
    int n = s.size();
    for (int i = 0; i < n;) {
      if (s[i] == '@') {
        i++;
        int cnt = s[i++] - '0';
        char c = s[i++];
        REP(j, cnt) cout << c;
      } else {
        cout << s[i++];
      }
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 2980
N = int(input())
a = list(map(int, input().split()))

mx_a = 1
mn_a = 10**9
for i in range(N):
    if a[i] > mx_a:
        mx_a = a[i]
    if a[i] < mn_a:
        mn_a = a[i]
print(mx_a-mn_a)


Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  while(true)
  {
    if(b>a) break;
    b*=2;
    k--;
  }
  while(true)
  {
    if(c>b) break;
    c*=2;
    k--;
  }
  if(k<0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3632
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        N: usize,
        M: usize,
    }

    if N*2 > M {
        println!("{}", M/2);
    } else {
        println!("{}", N + (M-N*2)/4);
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
int main(void){
  int n;
  std::vector<int> a,b,c;
  std::cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n-1);
  for(int i = 0; i < n; i++){
  	std::cin >> a[i];
  }
  for(int i = 0; i < n; i++){
  	std::cin >> b[i];
  }
  for(int i = 0; i < n-1; i++){
  	std::cin >> c[i];
  }
  long sum = 0;
  for(int i = 0; i < n; i++){
  	sum += b[a[i]-1];
    if(a[i+1] == a[i] + 1)
      sum += c[a[i]-1];
  }
  std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
int a,b,c,x,y;
cin >> a >> b >> c >> x >> y;
  int  price1,price2,price3;
  price1 = a*x + b*y;
  price2 = c * max(x,y) * 2; //買って余らせる
  price3 = c * min(x,y) * 2;// 買って足りない分を買い足す
  if(x > y){
    price3 += a*(x-y);
  } else if(x < y){
    price3 += b*(y-x);
  }
  cout << min(min(price1,price2),price3) << endl;
  return 0;
}


Measured memory_bytes: 256