akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

ll H, W;
ll Ch, Cw;
ll Dh, Dw;
std::string S[1010];
ll dist[1010][1010];

using Tup = std::tuple<ll, ll, ll>;

int main() {
  std::cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  --Ch; --Cw; --Dh; --Dw;

  rep( i, H )
    std::cin >> S[i];

  rep( i, H ) rep( j, W ) 
    dist[i][j] = INF;

  std::priority_queue<Tup, std::vector<Tup>, std::greater<Tup>> que;
  que.emplace( 0, Ch, Cw );
  dist[Ch][Cw] = 0;

  while( !que.empty() ) {
    auto [d, i, j] = que.top(); que.pop();

    if( dist[i][j] < d )
      continue;

    rep( d, 4 ) {
      ll ni = i+dy[d], nj = j+dx[d];

      if( ni >= 0 && ni < H && nj >= 0 && nj < W && S[ni][nj] != '#' ) {
        if( chmin( dist[ni][nj], dist[i][j] ) ) {
          que.emplace( dist[ni][nj], ni, nj );
        }
      }
    }

    repi( d1, -2, 3 ) repi( d2, -2, 3 ) {
      ll ni = i+d1, nj = j+d2;

      if( ni >= 0 && ni < H && nj >= 0 && nj < W && S[ni][nj] != '#' ) {
        if( chmin( dist[ni][nj], dist[i][j]+1 ) ) {
          que.emplace( dist[ni][nj], ni, nj );
        }
      }
    }
  }

  std::cout << (dist[Dh][Dw]==INF ? -1 : dist[Dh][Dw]) << endl;

  return 0;
}

Measured memory_bytes: 13652
n = int(input())
a_l = [ int(input()) for _ in range(n)]

l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))

Measured memory_bytes: 20156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n,k;cin>>n>>k;
  vector<P> dt(n);
  rep(i,n){
    int t,d;cin>>t>>d;
    --t;
    dt[i]=P(d,t);
  }
  sort(all(dt),greater<P>());
  int used[n];rep(i,n)used[i]=0;
  ll sum=0;
  priority_queue<int,vector<int>,greater<int>> Q;
  rep(i,k){
    sum+=dt[i].first;
    if(used[dt[i].second]==0)used[dt[i].second]=dt[i].first;
    else if(used[dt[i].second]>=dt[i].first){
      Q.push(dt[i].first);
    }
    else{
      Q.push(used[dt[i].second]);
      used[dt[i].second]=dt[i].first;
    }
  }
  ll tmp=0;
  rep(i,n)if(used[i])tmp++;
  ll res[n+1];rep(i,n+1)res[i]=0;
  res[tmp]=sum+tmp*tmp;
  rep(i,k,n){
    if(used[dt[i].second])continue;
    if(Q.empty())break;
    int qtop=Q.top();Q.pop();
    sum-=qtop;sum+=dt[i].first;
    tmp++;
    res[tmp]=sum+tmp*tmp;
    used[dt[i].second]=dt[i].first;
  }
  sort(res,res+n+1);
  cout<<res[n]<<endl;
}




Measured memory_bytes: 2432
use std::collections::HashSet;
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, k) =  {
        let nk = get_line().split_whitespace()
            .map(|e| e.parse().unwrap())
            .collect::<Vec<i64>>();
        (nk[0], nk[1])
    };

    let mut set = HashSet::new();

    for _ in 0..k {
        let _ = get_line().parse::<i64>().unwrap();
        let aas = get_line().split_whitespace()
            .map(|e| e.parse().unwrap())
            .collect::<Vec<i64>>();
        for a in aas {
            set.insert(a);
        }
    }

    let mut count = 0;
    for i in (1..n + 1) {
        if !set.contains(&i) {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2176
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

ll kaizyou(int n){
  ll ans = 1;
  while(n>=1){
    ans *= n;
    ans %= MOD;
    n--;
  }
  return ans;
}

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

  ll ans;
  if(N==M){
    ans = kaizyou(N) * kaizyou(M) * 2;
    ans %= MOD;
  }
  else if(abs(N-M)==1){
    ans = kaizyou(M) * kaizyou(N);
    ans %= MOD;
  }
  else ans = 0;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int mod = 1e9 + 7;
map<ll, ll> p;
inline ll read() 
{
	ll s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline void print(ll x) 
{
	if(x < 0)	putchar('-'), x = -x;
	if(x > 9)	print(x / 10);
	putchar(x % 10 + '0');
}

inline ll work(ll x) 
{
	if(p[x])	
	return p[x];
	else return p[x] = (work(x >> 1) + work((x - 1) >> 1) + work((x - 2) >> 1))%mod;
}
int main() 
{
//	freopen("string.in","r",stdin);
//	freopen("string.out","w",stdout);
	p[0] = 1;
    p[1] = 2;
	print(work(read()));
    puts("");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  
  UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    uf.unite(x - 1, y - 1);
  }

  set<int> s;
  for (int i = 0; i < N; i++) {
    s.insert(uf.root(i));
  }
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
bool used[310];
int n, m;
int a[310][310];
int cnt[310];
int dfs() {
	REP(i, 310)cnt[i] = 0;
	REP(i, n) {
		REP(j,m) {
			if (used[a[i][j]])continue;
			else{
				cnt[a[i][j]]++;
				break;
			}
		}
	}
	int id = 305;
	int max = 0;
	REP(i,m) {
		if (max < cnt[i]) {
			max = cnt[i];
			id = i;
		}
	}
	used[id] = true;
	return max;
}
int main() {
	REP(i, 310) {
		cnt[i] = 0;
		used[i] = false;
	}
	cin >> n >> m;
	REP(i, n) {
		REP(j, m) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	int ans = INF;
	for (int i = 0; i < m ; ++i) {
		ans = min(ans, dfs());
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = b/x - a/x;
    if (a % x == 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
///////////////////////////////////////////////////////////////////////////////

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

using namespace std;

///////////////////////////////////////////////////////////////////////////////

void intin(int &a)
{
        cin >> a;
}

void intinl1(auto &v, int count)
{
        for (int i = 0; i < count ; ++i) {
                int a;
                cin >> a;
                v.push_back(a);
        }
}

void intinl2(auto &v, int count)
{
        for (int i = 0; i < count ; ++i) {
                int a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

void intinl3(auto &v, int count)
{
        for (int i = 0; i < count ; ++i) {
                int a, b, c;
                cin >> a >> b >> c;
                v.push_back({a, b, c});
        }
}

void intina(auto &v, int count)
{
        intinl1(v, count);
}


///////////////////////////////////////////////////////////////////////////////

int main()
{
        string s;
        cin >> s;

        size_t len = s.size();
        size_t count = 0;
        size_t ans = 0;

        for (int i = 0; i < len; ++i) {
                if ((i & 1) && (s[i] == '0')) count += 1;
                if (!(i & 1) && (s[i] == '1')) count += 1;
        }

        ans = count;
        count = 0;

        for (int i = 0; i < len; ++i) {
                if ((i & 1) && (s[i] == '1')) count += 1;
                if (!(i & 1) && (s[i] == '0')) count += 1;
        }

        cout << min(count, ans);;

        return 0;
}

///////////////////////////////////////////////////////////////////////////////


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(int i = 0; i <N; i++)
using namespace std;


const int MOD = pow(10,9)+7;
const int MAX = 2047483647;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}




int main() {

    int N = in();
    vector<int> L;
    int sum = 0;
    for(auto i = 0; i<N; i++){
        L.push_back(in());
        sum += L.back();
    }
    
    sort(L.begin(),L.end(),greater<int>());
    
    if (L[0] < sum-L[0]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}










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

int main() {
	UL W; cin >> W;
	cout << 32 * W << endl;
	return 0;
}



Measured memory_bytes: 3084
/**
 * C - Sum of gcd of Tuples (Easy)
 * https://atcoder.jp/contests/abc162/tasks/abc162_c
 */
#include <bits/stdc++.h>
using namespace std;

// 最大公約数を求める
int gcd (int a, int b, int c) {
    int minNum = min(min(a, b), c);
    int maxDivisor = 1;
    for (int i = 2; i <= minNum; i++) {
        if (a % i == 0 && b % i == 0 && c % i == 0) {
            maxDivisor = i;
        }
    }

    return maxDivisor;
}

int main() {
    // ∑a=1K∑b=1K∑c=1gcd(a,b,c) を求めてください。
    // ただし、gcd(a,b,c) は a,b,c の最大公約数を表します。
    int K;
    cin >> K;

    int sum = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                sum += gcd(a, b, c);
            }
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3572
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var answer = 0L;
            var dict = new Dictionary<long, long>();
            for (var i = 0; i < A.Length; i++)
            {
                if (dict.ContainsKey(A[i])) dict[A[i]]++;
                else dict[A[i]] = 1;
            }
            var edges = dict.Where(x => x.Value > 1).OrderByDescending(x => x.Key).ToArray();
            if (edges.Length > 0)
            {
                if (edges[0].Value >= 4) answer = edges[0].Key * edges[0].Key;
                else if (edges[0].Value > 1 && edges[1].Value > 1) answer = edges[0].Key * edges[1].Key;
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 43504
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		string str = Console.ReadLine();
		for(var i=0;i<N;i++){
			if(str.Substring(i,1)=="#"){
				A[i] = 1;
			}
		}
		int[,]D = new int[N+1,2];
		for(var i=0;i<N;i++){
			if(A[i]==1){
				D[i+1,1] = Math.Min(D[i,0],D[i,1]);
				D[i+1,0] = D[i,0]+1;
			} else {
				D[i+1,1] = Math.Min(D[i,0]+1,D[i,1]+1);
				D[i+1,0] = D[i,0];
			}
		}
		Console.WriteLine(Math.Min(D[N,0],D[N,1]));
	}
}

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

int main() {

    int r;
    cin >> r;

    long double ans;

    ans = 2 * PI * r;
    cout << ans << endl;
}   

Measured memory_bytes: 3788
s = input()
s = s.replace("BC", "D")
ans = 0
a = 0
d = 0
a_bool = False
for i in range(len(s)):
    if not a_bool:
        if s[i] == "A":
            a += 1
            a_bool = True
        else:
            continue
    elif a_bool:
        if s[i] == "D":
            ans += a
        elif s[i] == "A":
            a += 1
        else:
            a_bool = False
            a = 0
            d = 0
print(ans)

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

int main() {
  int n, i = 1;
  cin >> n;
  while (i <= n) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      int x = i;
      while (x > 0) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      }
    }
    i++;
  }
  cout << endl;
}

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

int main(){
    string S;
    cin>>S;
    int n=S.size();
    
    if(n>9) cout<<"NO"<<endl;
    else if(n==9){
        if(S=="AKIHABARA") cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else if(n==8){
        if(S == "KIHABARA" || S == "AKIHBARA" || S == "AKIHABRA" || S == "AKIHABAR") cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else if(n==7){
        if(S == "KIHBARA" || S == "KIHABRA" || S == "KIHABAR" || S == "AKIHBRA" || S == "AKIHBAR" || S == "AKIHABR") cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else if(n==6){
        if(S == "AKIHBR" || S == "KIHABR" || S == "KIHBAR" || S == "KIHBRA") cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else if(n==5){
        if(S == "KIHBR") cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;
    
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N;
  vector<ull> a;
  ull count = 0;

  cin >> N;
  a.resize(N);

  FOR(i, N) { cin >> a[i]; }

  int last = N - 1;
  for (int i = 0;; i = (i + 1) % N) {
    if (a[i] >= N) {
      FOR(j, N) {
        if (i != j) a[j] += a[i] / N;
      }
      count += a[i] / N;
      a[i] %= N;
      last = i;
    } else if (last == i) {
      break;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
//
// 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")
    };
}

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        X: i64,
        x: [i64; N],
    }
    let ans = x.iter().fold(0, |acc, &x| gcd(acc, (x - X).abs()));
    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    if a == 0 {
        b
    } else if a < b {
        gcd(b % a, a)
    } else {
        gcd(a % b, b)
    }
}


Measured memory_bytes: 4352
#include<stdio.h>

int max(int a,int b){
  if(a > b)return a;
  else return b;
}
 
int min(int a,int b){
  if(a < b)return a;
  else return b;
}
 
int t[1000],n[1000],m[1000],s[1000];
int N,M,r,q,begin,end,id;

int main(){
  int i,j,k;
   
  while(1){
    scanf("%d %d",&N,&M);
    if(N==0&&M==0)break;
    scanf("%d",&r);  
    for(i=0;i<r;i++){
      scanf("%d %d %d %d",&t[i],&n[i],&m[i],&s[i]);
    }
     
    scanf("%d",&q);
    for(i=0;i<q;i++){
       
      scanf("%d %d %d",&begin,&end,&id);
       
      int ans=0,A=0,B;
       
      for(j=0;j<r;j++){
        if(m[j]!=id)continue;
         
        if(s[j]==1){
          //login
          A++;
          if(A==1){
            B=t[j];
          }
           
        }else{
          //logout
          A--;
          if(A==0&&begin<=t[j]&&B<=end){
            ans+=(min(end,t[j])-max(begin,B));
          }
           
        }
      }
       
      printf("%d\n",ans);
    }
  }
  return 0;  
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
int a,b,f;
int main(){
	cin>>a>>b;
	int cnt=0,c=b;
	while(c!=0){
		c/=10;
		a*=10;
	}
	b+=a;
	int d;
	d=sqrt(b);
	if(b==d*d){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int solve()
{
	ll k,n;
    cin>>k>>n;
    ll arr[n];
    rep(i,n)
    {
        cin>>arr[i];
        arr[i] = arr[i]%k;
    }
    sort(arr,arr+n);
    ll maxi = 0;
    rep_a(i,1,n)
    {
        maxi = max(maxi,arr[i]-arr[i-1]); 
    }
    maxi = max(maxi,k-arr[n-1]+arr[0]);
    cout<<k-maxi<<endl;
}
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #endif */
    solve();
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif */
    return 0;
} 

Measured memory_bytes: 1792
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

#define dump1(v) for(auto i:v) std::cout << i << ' '; std::cout << "\n";
#define dump2(v) for(auto i:v) { for(auto j:i) std::cout << j << ' '; std::cout << "\n"; }


signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> v(n);
	rep(i,n) std::cin >> v[i];

	int max = 0;
	for(int a=std::min(n,k);a>0;a--) {
		for(int c=0;c<=a;c++) {
			std::vector<int> take;
			for(int i=0;i<a;i++) take.emplace_back(v[(i-c+n)%n]);
			std::sort(all(take));
			int sum = 0;
			for(auto i:take) sum+=i;
			for(int i=0;i<std::min(a,k-a);i++) if(take[i]<0) sum+=-take[i];
			max = std::max(max,sum);
		}
	}
	print(max);

	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    N = input() + "0"

    dp = [[f_inf] * 2 for _ in range(len(N) + 1)]
    dp[0][0] = 0
    dp[0][1] = 1
    for i in range(1, len(N) + 1):
        n = int(N[i - 1])
        dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (10 - n))
        dp[i][1] = min(dp[i - 1][0] + n + 1, dp[i - 1][1] + (10 - n - 1))

    print(dp[-1][0])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 162332
#include<stdio.h>
#include<algorithm>
using namespace std;
char reg[12];
char str[1100];
int main(){
	scanf("%s",str);
	int at=0;
	for(int i=0;str[i];i++){
		int to=(str[i]-33)/10;
		while(at<to){
			printf(">");at++;
		}
		while(at>to){
			printf("<");at--;
		}
		while(reg[at]<str[i]){
			reg[at]++;
			printf("+");
		}
		while(reg[at]>str[i]){
			reg[at]--;
			printf("-");
		}
		printf(".");
	}
}

Measured memory_bytes: 936
memo = [0] * 4

for i in range(3):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    memo[a] += 1
    memo[b] += 1

for i in range(4):
    if memo[i] == 3:
        print("NO")
        exit()
    if memo[i] == 0:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef queue<int> qi;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//int q; cin >> q;
	//while (q--) {
		
	//}
	int a, b, c, d; cin >> a >> b >> c >> d;
	int cnt = 1;
	while (a > 0 && c > 0) {
		if (cnt&1) {
			c -= b;
		}
		else {
			a -= d;
		}
		cnt ++;
	}
	
	if (a <= 0) cout << "No\n";
	else cout << "Yes\n";
	
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b,sum=0,count=0;
	cin >> a >> b;
	if (b==1) {
		cout << "0" << endl;
		exit(0);
	}

	sum += a;
	count++;
	while (b > sum) {
		sum += a-1;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli a;
   cin>>a;
   cout<< (a+(a*a)+(a*a*a))<<"\n";
   return 0;
}//main


Measured memory_bytes: 3652
list = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
N=int(input())
for x in range(N):
    a,b,c,d=map(int,input().split())
    list[a-1][b-1][c-1]+=d
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(f' {list[i][j][k]}',end="")
        print()
    if int(i)<3: print("#"*20)



Measured memory_bytes: 5636
/*
red blue
3 4
red
*/
// var input ="red blue\n3 4\nred";

function main(input){
  input = input.trim();
  var g1 = input.split("\n")[0];
  var g2 = input.split("\n")[1];
  var g3 = input.split("\n")[2];
  var moji1 =g1.split(" ")[0];
  var moji2 =g1.split(" ")[1];
  var sute = g3;
  var kazu1 = parseInt(g2.split(" ")[0]);
  var kazu2 = parseInt(g2.split(" ")[1]);
  // console.log([moji1,moji2]);
  if(moji1==sute){kazu1--;}
  else if(moji2==sute){kazu2--;}
  console.log(kazu1+" "+kazu2);
}
// main(input);
main(require("fs").readFileSync("/dev/stdin","utf8"));

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

typedef long long ll;
typedef vector<ll> vll;
const ll INF = 1e18;
const ll N = 1e5;
const ll M = 1e9+7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s, t;
	cin >> s >> t;

	vll p[26];
	for (ll i = 0; i < s.size(); ++i)
		p[s[i]-'a'].push_back(i);

	ll a[t.size()];
	if (p[t[0]-'a'].empty())
	{
		cout << -1 << '\n';
		return 0;
	}
	a[0] = p[t[0]-'a'][0];
	for (ll i = 1; i < t.size(); ++i)
	{
		ll ch = t[i]-'a';
		if (p[ch].empty())
		{
			cout << -1 << '\n';
			return 0;
		}
		ll b = upper_bound(p[ch].begin(), p[ch].end(), a[i-1]) - p[ch].begin();
		if (b == p[ch].size()) b = 0;
		a[i] = p[ch][b];
	}

	ll c = 0;
	for (ll i = 0; i < t.size()-1; ++i)
		if (a[i+1] <= a[i]) ++c;

	cout << s.size() * c + a[t.size()-1] + 1 << '\n';
}


Measured memory_bytes: 2256
k, n = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)

max = a[0] - (a[-1] - k)
(a.length - 1).times do |j|
  i = j+1
  diff = a[i] - a[i-1]
  if max < diff then
    max = diff
  end
end

puts k - max


Measured memory_bytes: 15364
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a * b << endl;
}


Measured memory_bytes: 3624
N,L =map(int,input().split())
total = 0
for i in range(N):
  total = total +(i +L)
if ((L<0) and (N + L>0))or (L == 0):
  print(total)
elif L>0 and N+L>0:
   print(total -L)
else:
   print(total-(N+L-1))



Measured memory_bytes: 3060
n,m = list(map(int, input().split()))
height_list = list(map(int, input().split()))
l=[1]*n
for i in range(m):
    a,b = map(int,input().split())
    if height_list[a-1] > height_list[b-1]:
        l[b-1] =0
    elif height_list[a-1] < height_list[b-1]:
        l[a-1]= 0
    else:
        l[a-1]=l[b-1] =0
print(sum(l))

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

int main() {
  int N, K;
  cin >> N >> K;
  int r = 1;
  while (N--) {
    if (2 * r < r + K) {
      r *= 2;
    } else {
      r += K;
    }
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    string b;
    cin>>b;
    for(int i=0; i<b.size(); i++)
    {
        if((b[i]+a)>90)
        {
            printf("%c",'A'+(a-('Z'-b[i])-1));
        }
        else
            printf("%c",b[i]+a);
    }
    cout<<endl;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {

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

        if (S.substring(0, S.length()).equals(T.substring(0, S.length()))
                && S.length() == T.length() - 1) {

            System.out.println("Yes");
            return;
        }

        System.out.println("No");
    }
}

Measured memory_bytes: 35492
import heapq
INF = 10 ** 10


def dijkstra(n, adj, s, t):
    dist = [INF for _ in range(n)]
    dist[s] = 0
    h = [(0, s)]
    while len(h) > 0:
        d, node = heapq.heappop(h)
        for next_node in adj[node]:
            next_d = d + 1
            if next_d < dist[next_node]:
                dist[next_node] = next_d
                heapq.heappush(h, (next_d, next_node))
    return dist[t]


def main():
    N, M = list(map(int, input().split(' ')))
    adj = [[] for _ in range(3 * N)]
    for _ in range(M):
        u, v = list(map(lambda x: int(x) - 1, input().split(' ')))
        adj[3 * u].append(3 * v + 1)
        adj[3 * u + 1].append(3 * v + 2)
        adj[3 * u + 2].append(3 * v)
    S, T = list(map(lambda x: int(x) - 1, input().split(' ')))
    d = dijkstra(3 * N, adj, 3 * S, 3 * T)
    if d == INF:
        print(-1)
    else:
        print(d // 3)


if __name__ == '__main__':
    main()

Measured memory_bytes: 61312
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a, b, c;
    vector<vector<int> > y;
    for(int i = 0; i < n; i++) {
        cin >> a >> b >> c;

        vector<int> x;
        x.push_back(a);
        x.push_back(b);
        x.push_back(c);
        sort(x.begin(), x.end());
        y.push_back(x);
    }
    sort(y.begin(), y.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    cout << n - y.size() << endl;
    return 0;
}


Measured memory_bytes: 3244
#include<stdio.h>
 
int main (void){
 
    int N_num;
    int K_num;
    int dp[258][3][2]={{{0}}};
 
    int i,j,k,l;
    int date,kind;
    int ans=0;
 
    scanf("%d%d",&N_num,&K_num);
 
    for(i=0;i<N_num;i++){
        for(j=0;j<3;j++){
            for(k=0;k<2;k++){
                dp[i][j][k]=0;
            }
        }
    }
    for(i=0;i<3;i++)dp[0][i][0]=1;
 
    for(i=0;i<K_num;i++){
        scanf("%d%d",&date,&kind);
        for(j=0;j<3;j++){
            if(j!=kind-1){
                for(k=0;k<2;k++){
                    dp[date-1][j][k]=-1;
                }
            }
        }
    }
    for(i=0;i<N_num;i++){
        for(j=0;j<3;j++){
            if(dp[i][j][0]!=-1){
                for(k=0;k<2;k++){
                    switch(k){
                    case 0:
                        for(l=0;l<3;l++){
                            if(j==l){
                                if(dp[i+1][l][1]!=-1){
                                    dp[i+1][l][1]+=dp[i][j][0];
                                    dp[i+1][l][1]%=10000;
                                }
                            }else{
                                if(dp[i+1][l][0]!=-1){
                                    dp[i+1][l][0]+=dp[i][j][0];
                                    dp[i+1][l][0]%=10000;
                                }
                            }
                        }
                        break;
                    case 1:
                        for(l=0;l<3;l++){
                            if(j==l){
                            }else{
                                if(dp[i+1][l][0]!=-1){
                                    dp[i+1][l][0]+=dp[i][j][1];
                                    dp[i+1][l][0]%=10000;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
 
 
    /*for(j=0;j<3;j++){
        printf("###");
        for(i=0;i<N_num;i++){
            for(k=0;k<2;k++){
                printf("%3d",dp[i][j][k]);
            }
            printf(" ");
        }
        puts("");
    }*/
 
 
    for(i=0;i<3;i++){
        for(j=0;j<2;j++){
            if(dp[N_num-1][i][j]!=-1){
                ans+=dp[N_num-1][i][j];
                ans%=10000;
            }
        }
    }
    printf("%d\n",ans);
 
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    if (a == 5 && b == 7 && c == 5)
    {
        cout << "YES" << endl;
        return 0;
    }
    else if (a == 7 && b == 5 && c == 5)
    {
        cout << "YES" << endl;
        return 0;
    }
    else if (a == 5 && b == 5 && c == 7)
    {
        cout << "YES" << endl;
        return 0;
    }
    else
    {
        cout << "NO" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "../benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	string s;
	int t;
	cin>>s>>t;
	auto fun=
		[&](ll m){
			return (m)/2;
		};
	{
		auto str=s;
		sort(all(str));
		if(str[0]==str.back()){
			cout<<fun(str.size()*1ll*t)<<endl;
			return 0;
		}
	}
	vector<int> a;
	rep(i,s.size()){
		if(!(i&&s[i-1]==s[i])) a.eb();
		++a.back();
	}
	ll re=0;
	out(a,t,1);
	if(s[0]==s.back()){
		re+=fun(a[0]);
		re+=fun(a.back());
		reps(i,1,a.size()-1) re+=fun(a[i])*t;
		re+=fun(a[0]+a.back())*(t-1);
	}else{
		for(ll x:a) re+=fun(x)*t;
	}
	cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define SZ(a) (int)(a).size()
typedef long long ll;

int main() {
	cin.sync_with_stdio(false);
	int n, c, k;
	cin >> n >> c >> k;
	vector<int> a(n);
	for (auto& x: a) {
		cin >> x;
	}
	sort(begin(a), end(a));
	auto ans = 0;
	auto b = 0;
	auto j = a[0];
	for (auto x: a) {
		if (b == c || x-j > k) {
			ans++;
			b = 0;
		}
		if (b == 0) {
			j = x;
		}
		b++;
	}
	ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

const int kInf = 1e9;

void Solve() {
	string s;
	cin >> s;

	int ans = kInf;

	for (char c = 'a'; c <= 'z'; ++c) {
		int tans = 0;
		int last = s.length();

		for (int j = s.length() - 1; j >= 0; --j) {
			if (s[j] == c) {
				tans = max(tans, last - j - 1);
				last = j;
			}
		}
		tans = max(tans, last);
		ans = min(ans, tans);
	}

	cout << ans << "\n";
}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

ll gcd(ll x,ll y){
    x = x%y;
    return x == 0 ? y : gcd(y,x);
}
ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}



int main(){
 
    string s;
    cin >> s;
    vector<vector<int>> dp(100005,vector<int> (13));
    rep(i,13){
        dp[0][0] = 1;
    }
    rep(i,s.size()){
        if(s[i] == '?'){
            rep(k,10){
                rep(j,13){
                    dp[i+1][((j*10)+k)%13] += dp[i][j];
                    dp[i+1][((j*10)+k)%13] %= mod;
                }
            }
        }else{
            int k = s[i]-'0';
            rep(j,13){
                dp[i+1][((j*10)+k)%13] += dp[i][j];
                dp[i+1][((j*10)+k)%13] %= mod;    
            }
        }
    }
    cout << dp[s.size()][5] << endl;

    return 0;
}


Measured memory_bytes: 11652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int D;
	cin >> D;

	if (D == 22) co("Christmas Eve Eve Eve");
	if (D == 23) co("Christmas Eve Eve");
	if (D == 24) co("Christmas Eve");
	if (D == 25) co("Christmas");

	Would you please return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

  if(isupper(a)){
     cout<<"A";
  }
  else{
     cout<<"a";
  }
return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - AC or WA
            var line = ReadLine();
            int N = line[0];
            int M = line[1];

            if (N == M)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const double EPS=0.00001;
const long double PI = acos(-1.0);



int main(){
    string S;
    cin>>S;
    REP(i,SZ(S))if(S[i]=='9'){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=300300;
typedef pair<int,int> P;
typedef vector<P> VP;
P a[N];
VP ans[N];
int v[N],l[N];
int mxl[N];
int d[N];
const int X=9;
int main(){
	memset(mxl,-1,sizeof(mxl));
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	d[0]=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].second>>a[i].first;
		d[i]=d[i>>1]+1;
	}
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>v[i]>>l[i];
		mxl[v[i]]=max(mxl[v[i]],l[i]);
	}
	for(int i=n;i>=1;i--){
		mxl[i>>1]=max(mxl[i>>1],mxl[i]);
	}
	ans[0].push_back(P(0,0));
	for(int i=1;i<=n;i++){
		P p=a[i];
		VP &ps=ans[i];
		const VP &qaq=d[i]==X+1?ans[0]:ans[i>>1];
		// cerr<<i<<" "<<(d[i]==X+1)<<endl;
		int w=qaq.size();
		ps=qaq;
		for(P tp:qaq){
			if(tp.first+p.first<=mxl[i])ps.push_back(P{tp.first+p.first,tp.second+p.second});
			else break;
		}
		inplace_merge(ps.begin(),ps.begin()+w,ps.end());
		for(int i=0;i+1<(int)ps.size();i++){
			if(ps[i+1].second<=ps[i].second)ps[i+1]=ps[i];
		}
		for(int i=(int)ps.size()-1;i>=1;i--){
			if(ps[i].first==ps[i-1].first)ps[i-1]=ps[i];
		}
		ps.erase(unique(ps.begin(),ps.end()),ps.end());
		assert(is_sorted(ps.begin(),ps.end()));
	}
	for(int i=1;i<=q;i++){
		// cerr<<"query "<<i<<endl;
		int x=v[i];
		const VP &v1=ans[x];
		// cerr<<"v1: "<<x<<endl;
		if(d[x]<=X){
			// cerr<<i<<endl;
			cout<<(--upper_bound(v1.begin(),v1.end(),l[i],[](int l,P p){return l<p.first;}))->second<<endl;
			continue;
		}
		while(d[x]>=X+1)x>>=1;
		const VP &v2=ans[x];
		// cerr<<"v2: "<<x<<endl;
		VP::const_iterator w=--v2.end();
		int ans=0;
		for(P p:v1){
			while(w->first+p.first>l[i]){
				if(w==v2.begin())goto no;
				w--;
			}
			ans=max(ans,w->second+p.second);
		}
		no:;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 544376
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 1e-8
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
	int N, K;
	cin >> N >> K;
	vector<int> A(N, 0);
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < K; i++) {
		vector<int> B(N+1, 0);
		for(int j = 0; j < N; j++) {
			int l = j-A[j], r = j+A[j]+1;
			if(l < 0) l = 0;
			if(r > N) r = N;
			B[l]++, B[r]--;
		}
		for(int j = 0; j < N; j++) B[j+1] += B[j];
		A = B;
		bool br = true;
		for(int j = 0; j < N; j++) if(A[j] != N) br = false;
		if(br) break;
	}
	for(int i = 0; i < N; i++) cout << A[i] << ((i == N-1) ? "\n" : " ");
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 5576
#include <bits/stdc++.h>
using namespace std;
int cnt[2019];
int main() {
	string s; cin >> s;
	int ans = 0, now = 0, p = 1;
	cnt[0] = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		now = (now + (s[i] - '0') * p) % 2019;
		ans += cnt[now]++;
		p = p * 10 % 2019;
	}
	cout << ans;
}

Measured memory_bytes: 3676
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <iostream>
using namespace std;
long long dp[101][21] = { 0 };
int main() {
	int n, m;
	int a[1001] = { 0 };
	int b[1001] = { 0 };
	scanf("%d%d", &n, &m);
	for (int i = 1;i <= n;++i) scanf("%d", &a[i]);
	for (int i = 1;i <= m;++i) scanf("%d", &b[i]);
	int vote[1001] = { 0 };
	for (int i = 1;i <= m;++i) {
		for (int q = 1;q <= n;++q) {
			if (a[q] <= b[i]) {
				vote[q]++;
				goto end;
			}

		}
	end:;
	}
	int finalist = 0;
	int great = 0;
	for (int i = 1;i <= n;++i) {
		if (finalist < vote[i]) {
			finalist = vote[i];
			great = i;
		}
	}
	printf("%d\n", great);
	return 0;
}


Measured memory_bytes: 1200
from fractions import gcd
def get_result(L, N):
    L_abs = [abs(x) for x in L]
    A = sum(L_abs)
    B = min(L_abs)
    neg_count = 0
    for elem in L:
        if elem < 0:
            neg_count += 1
    if neg_count % 2 == 0:
        return A
    else:
        return (A-2*B)


N = int(input())
L = [int(s) for s in input().split(" ")]
result = get_result(L, N)
print(result )


Measured memory_bytes: 16400
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int s[1005],p[1005],q[1005],r[1005];
  int p1,q1,r1,c1;
  int c[1005];
  int count=0;
  int ans[1005][100]={};
  cin>>n;
  while(n!=0){
    for(int i=0;i<n;i++){
      cin>>s[i]>>p[i]>>q[i]>>r[i];
      c[i]=p[i]*4+q[i]*9+r[i]*4;
    }
    cin>>p1>>q1>>r1>>c1;
    for(int i=0;i<n;i++){
      if(p[i]<=p1&&q[i]<=q1&&r[i]<=r1&&c[i]<=c1){
	cout<<s[i]<<"\n";
	count++;
      }
    }
    if(count==0){
      cout<<"NA"<<"\n";
    }
    count=0;
    cin>>n;
  }
  return 0;
}



Measured memory_bytes: 3104