akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int N, Q;
vector<vector<int>> graph(0);
struct node {
    int parent;
    int c;
};
vector<node> tree(0);
queue<int> q;

void make_tree() {
    int par;
    q.push(0);
    tree[0].parent = INT_MAX;
    while (!q.empty()) {
        par = q.front();
        q.pop();
        for (int i = 0; i < (int)graph[par].size(); i++) {
            if (tree[graph[par][i]].parent != -1) continue;
            tree[graph[par][i]].parent = par;
            tree[graph[par][i]].c += tree[par].c;
            q.push(graph[par][i]);
        }
    }
}

int main() {
    cin >> N >> Q;
    graph.resize(N);
    tree.assign(N, {-1, 0});
    int a, b;
    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b;
        a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int p, x;
    for (int i = 0; i < Q; i++) {
        cin >> p >> x;
        p--;
        tree[p].c += x;
    }
    make_tree();
    for (int i = 0; i < N; i++) {
        cout << tree[i].c;
        if (i != N - 1)
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}

Measured memory_bytes: 17256
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	string a, b;
	cin >> a >> b;
	a += b;
	int c = atoi(a.c_str());
	for (int i = 1; i * i <= c; i++) {
		if (i * i == c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

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

    std::cin >> S;

    int res = 700 + 100 * std::count(S.begin(), S.end(), 'o');
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	while(1){
		if(x==0&&y==0){break;}
		if(x>y){
			cout<<y<<" "<<x<<endl;
		}else{
			cout<<x<<" "<<y<<endl;
		}
		cin>>x>>y;
	}
	
	
	return 0;		
}

Measured memory_bytes: 1160
#include<iostream>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
    string number;
    cin >> number;
    int numberF = number.find("7");
    if (numberF == string::npos){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
   return 0;

} 

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int MAXN = 21;
const int MAX = (1<< 21);
const ll MOD = 1e9 + 7;

ll dp[MAX];
bool can[MAXN][MAXN];
int N;

bool is_ok(int number, int i)
{
	return (number & (1<<i)) == 0;
}

ll run(int mask, int i)
{
	if (i == N)
		return 1;
	if (dp[mask] != -1)
		return dp[mask];
	dp[mask] = 0;
	for (int j(0); j < N; ++j)
		if( is_ok(mask, j) && can[i][j])
		{
			dp[mask] += run(mask + (1<<j), i+1);
			dp[mask] %= MOD;
		}
	return dp[mask];
}

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	read(N);
	for (int i(0); i < MAX; ++i)
		dp[i] = -1;
	FOR(i,0,N) FOR(j,0, N)
		read(can[i][j]);
	cout << run(0, 0) << endl;
}



Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(ll i=0;i<N;++i)
const ll INF = 1LL<<60;

ll N,M;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    cin >> N >> M;
    vector<ll> a(M),b(M);
    rep(i,M){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    rep(i,M){
        UnionFind tree(N+1);
        rep(j,M){
            if(i!=j){
                tree.unite(a[j],b[j]);
            }
        }
        if(tree.unite(a[i], b[i])){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int ans=0;
    int r,g,b,n; cin>>r>>g>>b>>n;
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            if((n-r*i-j*g)%b==0&&n-r*i-j*g>=0) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n;
  vector<int>arr(n);
  for(int i=0;i<n;i++)
  cin>>arr[i];
  sort(arr.begin(),arr.end());
  int size=arr[n-1];
  vector<int>sum(size+1);
  for(int i=1;i<=size;i++)
  {
      int tsum=0;
      for(int j=0;j<n;j++)
      tsum+=(arr[j]-i)*(arr[j]-i);
      sum[i]=tsum;
  }
  int min_val=INT_MAX;
  int ans=0;
  for(int i=1;i<=size;i++)
  if(min_val>=sum[i])
  {
      min_val=sum[i];
      ans=i;
  }
  cout<<min_val;
  return 0;
}

Measured memory_bytes: 256
/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is quite cool.It becomes cooler when you enjoy learning new things
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n;
  cin>>n;
  ll dp[n+1][3]={0},a[3][n+1];
  
  rep(i,n)
  {
    cin>>a[0][i+1]>>a[1][i+1]>>a[2][i+1];
  }

  dp[1][0]=a[0][1];
  dp[1][1]=a[1][1];
  dp[1][2]=a[2][1];


  for(int i=2;i<=n;i++)
  {
    for(int j=0;j<=2;j++)
    {
      int x=(j+1)%3,y=(j+2)%3;
      dp[i][j]+=(a[j][i]+max(dp[i-1][x],dp[i-1][y]));
    }
  }

  ll mx=0;
  rep(i,3)
    mx=max(mx,dp[n][i]);

  cout<<mx<<endl;

} 

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


Measured memory_bytes: 8284
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College

'''
import sys
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]



def solve():
    
    
    
    # for _ in range(ii()):
    
    
    n = ii()
    a = li()
    f = 1
    freq = [0]*1000005
        
    for i in a:
        x = i
        for j in range(2,int(sqrt(x))+1):
            c = 0
            while(x%j==0):
                x//=j
                c=1
            if(c > 0):
                if freq[j]>0:
                    f = 0
                    break
                freq[j] = 1
        if(x>1):
            freq[x]+=1
            if(freq[x]>1):
                f = 0
                break
        if(f==0):
            break
        
    if(f):
        print('pairwise coprime')
    else:
        x = a[0]
        for i in range(1,n):
            x = gcd(x,a[i])
        if(x==1):
            print('setwise coprime')
        else:
            print('not coprime')
    
    
    
    
    
    
    
if __name__ =="__main__":
    # read()
    solve()
    

Measured memory_bytes: 187068
while True:
    a = []
    b = [0]
    c = []
    n, k = map(int, input().split())
    if n == k == 0:
        break

    for i in range(n):
        x = int(input())
        a.append(x)
        b.append(b[i] + x)

    for i in range(n - k + 1):
        c.append(b[k + i] - b[i])

    print(max(c))


Measured memory_bytes: 15348
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    
    if(A<=8 && B<=8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int dp[110][4][2];

int main() {
    string S;
    cin >> S;
    int K;
    cin >> K;
    int M = S.size();
    dp[0][0][0] = 1;
    for(int i = 0;i < M;i++) {
        for(int j = 0;j < 4;j++) {
            for(int k = 0;k < 2;k++) {
                int x = S.at(i) - '0';
                for(int l = 0;l < 10;l++) {
                    int ni = i + 1;
                    int nj = j;
                    int nk = k;
                    if(l != 0) {
                        nj++;
                    }
                    if(nj > K) {
                        continue;
                    }
                    if(k == 0) {
                        if(l > x) {
                            continue;
                        }
                        else if(l < x){
                            nk = 1;
                        }
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[M][K][0] + dp[M][K][1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n,m; cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  for (int i = 0; i <= n-m; i++) for (int j = 0; j <= n-m ; j++) {
    bool ok = true;
    rep(s, m) rep(t, m){
      if(a[i+s][j+t] != b[s][t]) ok = false;
    }
    if(ok){
      std::cout << "Yes" << '\n';
      return 0;
    }
  }

  std::cout << "No" << '\n';
}


Measured memory_bytes: 256
import fractions
from functools import reduce

n, *a = map(int, open(0).read().split())

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

lcm = lcm_list(a)

ans = 0
for a_i in a:
  ans += lcm // a_i

ans = ans % (10**9 + 7)
print(ans)

Measured memory_bytes: 6140
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
S = input()
c = 0
for i in range(1000):
    if 0 <= i and i <= 9:
        s0 = "0"
        s1 = "0"
        s2 = str(i)
    elif 10 <= i and i <= 99:
        s0 = "0"
        s = str(i)
        s1 = s[0]
        s2 = s[1]
    else:
        s = str(i)
        s0 = s[0]
        s1 = s[1]
        s2 = s[2]
    i0 = -1
    i1 = -1
    i2 = -1
    for k in range(N-2):
        if S[k] == s0:
            i0 = k
            break
    if i0 == -1:
        continue
    for j in range(i0+1,N-1):
        if S[j] == s1:
            i1 = j
            break
    if i1 == -1:
        continue
    for l in range(i1+1,N):
        if S[l] == s2:
            i2 = l
            break
    if i2 != -1:
        c +=1
print(c)


    
    








Measured memory_bytes: 43996
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector <int> a(N);
    int e;
    int count = 0;
    while (cin >> e) {
        
        a[count] = e;
        ++count;
    }
    for (int i=N-1; i >= 0; i--){
        if (i != 0) cout << a[i] << " ";
        if (i == 0) cout << a[i];
    }
    cout << endl;

}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/



Measured memory_bytes: 3092
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	while(cin >> s){
		int n = SZ(s);
		int cp = 0, cg = 0;
		int ans = 0;
		REP(i,n){
			if(s[i] == 'g'){
				if(cp+1 <= cg){
					cp++;
					ans++;
				}else{
					cg++;
				}
			}else{
				if(cp+1 <= cg){
					cp++;
				}else{
					cg++;
					ans--;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define rep(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>(x.size())
#define mp make_pair
#define fi first
#define se second

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod(ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T> inline void remin(T& x, const T& y) { x = min(x, y); }
template<typename T> inline void remax(T& x, const T& y) { x = max(x, y); }

template<typename T> ostream& operator<<(ostream &os, const vector<T>& v) {
    os << "{"; string sep; for(const auto& x : v) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename T, size_t size> ostream& operator<<(ostream& os, const array<T, size>& arr) {
    os << "{"; string sep; for(const auto& x : arr) os << sep << x, sep = ", "; return os << "}"; 
}

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

int main() {
    buff();
    int n;
    cin >> n;
    vector<long long> v(n);
    for(auto& x : v) cin >> x;
    long long res = 0ll; 
    long long SUM = accumulate(all(v), 0ll, [&] (long long& a, long long& b) { return a + b; } );
    SUM %= MOD;
    for(int i = 0; i < n; ++i) {
        SUM = (SUM - v[i] + MOD) % MOD;
        long long inc = (v[i] * SUM) % MOD;
        res = (res + inc) % MOD;
    }
    cout << res << '\n';
    return 0;
}



Measured memory_bytes: 4780
#include<iostream>

using namespace std;

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

int a[110][110], b[110][110];

void dfs(int y, int x) {
  if (b[y][x] == 1) return;
  if (a[y][x] == 1) return;
  b[y][x] = 1;
  if (y % 2 == 0) {
    dfs(y - 1, x);
    dfs(y - 1, x + 1);
    dfs(y, x - 1);
    dfs(y, x + 1);
    dfs(y + 1, x);
    dfs(y + 1, x + 1);
  } else {
    dfs(y - 1, x - 1);
    dfs(y - 1, x);
    dfs(y, x - 1);
    dfs(y, x + 1);
    dfs(y + 1, x - 1);
    dfs(y + 1, x);
  }
}

int main() {
  int w, h;
  cin >> w >> h;
  rep (i, h + 4) a[i][0] = 1;
  rep (i, h + 4) a[i][w + 3] = 1;
  rep (i, w + 4) a[0][i] = 1;
  rep (i, w + 4) a[h + 3][i] = 1;
  rep (i, h) rep (j, w) cin >> a[i + 2][j + 2];
  dfs(1, 1);
  rep (i, h + 4) a[i][0] = 0;
  rep (i, h + 4) a[i][w + 3] = 0;
  rep (i, w + 4) a[0][i] = 0;
  rep (i, w + 4) a[h + 3][i] = 0;
  int res = 0;
  rep (i, h + 4) rep (j, w + 4) if (b[i][j] == 1) {
    if (i % 2 == 0) {
      if (a[i - 1][j] == 1) ++res;
      if (a[i - 1][j + 1] == 1) ++res;
      if (a[i][j - 1] == 1) ++res;
      if (a[i][j + 1] == 1) ++res;
      if (a[i + 1][j] == 1) ++res;
      if (a[i + 1][j + 1] == 1) ++res;
    } else {
      if (a[i - 1][j - 1] == 1) ++res;
      if (a[i - 1][j] == 1) ++res;
      if (a[i][j - 1] == 1) ++res;
      if (a[i][j + 1] == 1) ++res;
      if (a[i + 1][j - 1] == 1) ++res;
      if (a[i + 1][j] == 1) ++res;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1648
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	int n,i,j;cin>>n;vector<vector<ld> >d(n+1,vector<ld>(n+1,0));
	ld v[n];for(i=0;i<n;i++) cin>>v[i];d[0][0]=1;
	for(i=1;i<=n;i++) d[i][0]=d[i-1][0]*(1-v[i-1]);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			d[i][j]+=(1-v[i-1])*d[i-1][j];
			d[i][j]+=v[i-1]*d[i-1][j-1];
		}
	}ld s=0;for(i=n;2*i>=n;i--) s+=d[n][i];
	printf("%.10Lf\n",s);
}


Measured memory_bytes: 141056
#include <cstdio>

int main () {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    //W = 2, H = 4, x = 2, y = 2, r = 1;
    int c_left = x - r;
    int c_right = x + r;
    int c_up = y + r;
    int c_bottom = y - r;

    if (0 <= c_left && 0 <= c_bottom && c_right <= W && c_up <= H) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n;
  cin >> n;
  ll even = 0;
  for (int i = 1; i <= n; ++i) {
    if (i%2 == 1) {
      even++;
    }
  }
  cout << fixed << setprecision(10) << (double)even/(double)n << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 510000;
const int MOD = 1e9;

const double PI=3.14159265358979323846;

/*
long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}*/

int length(vector<int> v, int u, int HW){
    if(v.size() == 0) return HW;
    if(v[0] > u) return v[0];
    if(v[v.size() - 1] < u) return HW - v[v.size()- 1] -1;
    else{
        int i = lower_bound(ALL(v), u)- v.begin();
        return v[i] - v[i-1] -1;
    }
}

int st[200001], t[10000];

int main(){
    cin >> N >>M;
    vector<pair<int, int>> v;
    priority_queue<int> q;
    REP(i,N) {
        int a, b; cin >> a >> b;
        v.push_back(make_pair(a,b));
    }

    sort(ALL(v));

    int i = 0;
    ll ans = 0;

    for(int cnt = M; cnt >= 0; --cnt){
        while(v[i].first == M-cnt and i < N){
            q.push(v[i].second);
            ++i;
        }
        if(!q.empty()) {ans += q.top(); q.pop();}
    }
    cout << ans ;

    return 0;
}

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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


struct BIT{
    vector<i64> elm;
    BIT(i64 n) : elm(n + 1, 0){}
    i64 sum(i64 x){
        i64 val = 0;
        for(; x > 0; x -= x & -x)
            val += elm[x];
        return val;
    }
    void add(i64 x, i64 val){
        for(++x; x < elm.size(); x += x & -x)
            elm[x] += val;
    }
};


signed main(){

    string s;
    i64 k;
    cin >> s >> k;
    i64 n = s.size();
    vector<pair<i64,i64>> sorted;
    for(i64 i = 0; i < n; ++i)
        sorted.emplace_back(s[i] - 'a', i);

    BIT bit(n);
    sort(sorted.begin(), sorted.end());

    i64 border = 0;
    for(border = 0; border < n; ++border){
        i64 idx = sorted[border].second;
        i64 cnt = idx - bit.sum(idx);
        if(k < cnt)
            break;
        k -= cnt;
        bit.add(idx, 1);
    }
    if(border == n){
        sort(s.begin(), s.end());
        cout << s << endl;
        return 0;
    }
    string t = s;
    s.clear();
    vector<i64> flag(n, 0);
    for(i64 i = 0; i < border; ++i){
        s.push_back(sorted[i].first + 'a');
        flag[sorted[i].second] = 1;
    }
    for(i64 i = 0; i < n; ++i)
        if(!flag[i])
            s.push_back(t[i]);

    vector<set<i64>> v(26);
    for(i64 i = border; i < n; ++i)
        v[s[i] - 'a'].emplace(i);

    flag.assign(n, 0);
    for(i64 i = 0; i < border; ++i)
        flag[i] = 1;

    BIT bit2(n);
    string kakutei = s.substr(0, border);

    auto solve = [&]{
        if(flag[border]){
            ++border;
            return ;
        }
        // [border, n)    k
        for(i64 i = 0; i < 26; ++i){
            if(!v[i].empty()){
                i64 pos = *v[i].begin();
                i64 dist = pos - border - (bit2.sum(pos) - bit2.sum(border));
                if(dist <= k){
                    k -= dist;
                    flag[pos] = 1;
                    v[i].erase(v[i].begin());
                    bit2.add(pos, 1);
                    kakutei.push_back(s[pos]);
                    return ;
                }
            }
        }
        kakutei.push_back(s[border]);
        ++border;
    };

    while(border != n){
    // while(k > 0 && border != n){
        solve();
    }

    for(i64 i = 0; i < n; ++i)
        if(!flag[i])
            kakutei.push_back(s[i]);

    cout << kakutei << endl;
}



Measured memory_bytes: 20208
#include <bits/stdc++.h>
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;

int sum(int x)
{
    if (x < 10) return x;
    return (x % 10) + sum(x / 10);
}

int main()
{
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x = sum(i);
        if (x >= a && x <= b) ans += i;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
n = int(input())

div = [1 for _ in range(n + 1)]
for num in range(2, n + 1):
    for i in range(2, int(num ** 0.5) + 1):
        while num % i == 0:
            div[i] += 1
            num //= i
    if num != 1:
        div[num] += 1

ans = 1

for num in div:
    ans *= num
    ans %= MOD
print(ans)

Measured memory_bytes: 9452
(n,),*q=$<.map{|l|l.split.map &:to_i}

fact = (1..n).each_with_object([1]){|i,o|o << o[-1]*i}

p q.inject(0){|s,r|
  left = *1..n
  r.each.with_index{|ai,i|
    s -= left.index(ai)*fact[n-1-i]
    left.delete(ai)
  }
  s.abs
}


Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

double d;

int main() {
    vector<double> vec;
    while (cin >> d) {
        vec.PB(d);
    }
    sort(ALL(vec));
    cout << vec[vec.size()-1] - vec[0] << endl;
    
    return 0;
}


Measured memory_bytes: 1304
//14:07:00 

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m; cin>>n>>m;
	vector<string> v(n);
	for(auto &i:v) cin>>i;
	For(u,0,m+1) cout<<'#'; cout<<"\n";
	For(i,0,n-1) cout<<"#"<<v[i]<<"#\n";
	For(u,0,m+1) cout<<'#'; cout<<"\n";
	return 0;
}











Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        int M = in.nextInt();
        if(N == M){
            println("Yes");
        }
        else{
            println("No");
        }
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    }
    else if (r < 2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
//	cin >> T;
	ll t=0;
	while(t++<T){
    ll N,D;
    cin >> N >> D;
    vector<pair<ll,ll>> v(N);
    fo(i,N) cin >> v[i].F >> v[i].S;
    ll c=0;
    fo(i,N){
        if((v[i].F)*(v[i].F) + (v[i].S)*(v[i].S) <= D*D) c++;
    }
    cout << c << endl;
	}
return 0;
}


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

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	if(abs(b-a)%2==0){
		ll ans=abs(a-b)/2;
		puts(ans);
		return 0;
	}
	ll ans=min(2*n-a-b,a+b-2);
	puts((ans+1)/2);
}

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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

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

int main(void){
	double W,H,x,y,maxi,mini[2],ans;
	scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
	if(W / x == 2 && H / y == 2) printf("%lf %d\n",H * W / 2,1);else{
		printf("%lf %d\n",W * H / 2,0); 
	}
	return 0;
}

Measured memory_bytes: 128
let [| N; M |] = stdin.ReadLine().Split() |> Array.map int

let rec solver l r i =
    if i = M then max 0 (r - l + 1)
    else
        let [| L; R |] = stdin.ReadLine().Split() |> Array.map int
        solver (max l L) (min r R) (i + 1)

solver 1 N 0 |> stdout.WriteLine


Measured memory_bytes: 15304
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  3 21:02:18 2019

@author: doppe
"""

N = int(input())
L = [int(i) for i in input().split()]

L.sort()
sum = 0
for i in range(0, len(L) - 1):
    sum += L[i]
if (L[len(L) - 1] >= sum):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main{
    public static void main(String[] args)
    {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        int i = 1;
        do{
            int x = i;
            if ( x % 3 == 0 )
            {
                System.out.print(" "+i);
                continue;
            }
            while(true)
            {
                if ( x % 10 == 3 )
                {
                    System.out.print(" "+i);
                    break;
                }
                x /= 10;
                if (x!=0) continue;
                else break;
            };

        }while ( ++i <= n);
        System.out.println();



    }
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
  ll x, y; cin >> x >> y;
  ll ans = INF;
  (y >= x) ? chmin(ans, y - x) : chmin(ans, x - y + 2);
  chmin(ans, abs(x + y) + 1);
  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    a, b = map(int, input().split())

    if a % 3 == 0:
        print("Possible")
        return

    if b % 3 == 0:
        print("Possible")
        return

    if (a + b) % 3 == 0:
        print("Possible")
        return

    print("Impossible")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
	int H,W;
	int i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0)break;
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				if(i%2==1){
					if(j%2==1){
						printf("#");
					}
					else{
						printf(".");
					}
				}
				else{
					if(j%2==1){
						printf(".");
					}
					else{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2524
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll ar[100001];
ll dp[100001];
ll func(ll idx)
{
	if(idx<=0)
	return 0;
	if(dp[idx]!=-1)
	return dp[idx];
	ll ret=min(func(idx-1)+abs(ar[idx]-ar[idx-1]),func(idx-2)+abs(ar[idx]-ar[idx-2]));
	return dp[idx]=ret;
}
int main()
{
	cin>>n;
	for(ll i=0;i<n;i++)
	cin>>ar[i];
	dp[0]=0;
	dp[1]=abs(ar[0]-ar[1]);
	for(ll i=2;i<100001;i++)
	{
		dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1792
from collections import deque
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
x = deque(a)
y = deque(a)


def align(a, fromLeft=1):
    if fromLeft:
        p = a.popleft()
    else:
        p = a.pop()
    q = p

    res = 0
    fromLeft = 1 - fromLeft
    while a:
        p1 = a.popleft() if fromLeft else a.pop()
        if a:
            q1 = a.popleft() if fromLeft else a.pop()
            res += abs(p - p1) + abs(q - q1)
            p = p1
            q = q1
        else:
            res += max(abs(p - p1), abs(q - p1))
        fromLeft = 1 - fromLeft
    return res


ans = max(align(x, 1), align(y, 0))
print(ans)


Measured memory_bytes: 8932
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for(char c : s.toCharArray()){
            c = (char)(((c-65)+n)%26+65);
            sb.append(c);
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
const int N=4000002;
char s[N],t[N];
int a,b,ne[N],ans,g[N],i,j;
int main(){
	scanf("%s%s",s+1,t+1),a=strlen(s+1),b=strlen(t+1);
	for (;a<b*2;a*=2)
		for (i=1;i<=a;i++) s[i+a]=s[i];
	for (i=1;i<=a;i++) s[i+a]=s[i];
	a*=2;
	ne[1]=1;
	for (i=2,j=1;i<=b;i++){
		while (j>1 && t[i]!=t[j]) j=ne[j-1];
		if (t[i]==t[j]) j++;
		ne[i]=j;
	}
//	for (i=1;i<=b;i++){
//		j=i;
//		while (j>1 && t[ne[j-1]]!=t[i]) j=ne[j-1]-1;
//		ne[i]=ne[j-1]+1;
//	}
//	for (i=1;i<=b;i++) printf("%d\n",ne[i]);
	for (i=1,j=1;i<=a;i++){
		while (j>1 && s[i]!=t[j]) j=ne[j-1];
		if (s[i]==t[j]) j++;
		if (j==b+1) ans=max(ans,g[i]=g[i-b]+1);
	}
	printf("%d",ans>=a/b-1?-1:ans);
}
/*
aa
aaaaaaa
*/

Measured memory_bytes: 23040
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << (char)(s1[0] - 'a' + 'A') << (char)(s2[0] - 'a' + 'A') << (char)(s3[0] - 'a' + 'A') << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    c = Counter(S)
    print('AC x %d'% c['AC'])
    print('WA x %d' % c['WA'])
    print('TLE x %d' % c['TLE'])
    print('RE x %d' % c['RE'])


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    (slv(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 85260
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n,m;
    cin>>n>>m;
    vector<P> sc(m);
    rep(i,m){
        cin>>sc[i];
    }
    rep(i,1000){
        if(to_string(i).size()!=n)continue;
        rep(j,m){
            if(to_string(i)[sc[j].first-1]!=sc[j].second+'0')goto tekitou;
        }
        cout<<i<<endl;
        return 0;
        tekitou:;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S = input()

if 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)
elif S == "SUN":
  print(7)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  cin >> N >> A >> B;
  vector<int>P(N);
  int count1 = 0;
  int count2 = 0;
  int count3 = 0;
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
    if (P.at(i) <= A){
      count1++;
    }
    else if (P.at(i) <= B){
      count2++;
    }
    else {
      count3++;
    }
  }
  
  cout << min(count1,min(count2,count3)) << endl;
}
  

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, counter, counter2;
  cin >> N;
  for (int i=0; i<N; i++) {
    counter = 0;
    int l;
    cin >> l;
    while(l>1){
      if(l%2 == 0){
        counter++;
      }
      else{
        break;
      }
      l /= 2;
    }
    if (i == 0){
      counter2 = counter;	
    }
    else if (counter == 0){
      counter2 = 0;
      break;
    }
    else if(counter2 > counter){
      counter2 = counter;
    }
  }
  cout << counter2 << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int N,sum=0;
	scanf("%d",&N);
	int i,j,a[N];
	for(i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<N-1;i++)
	{
		for(j=i+1;j<N;j++)
		{
			sum+=a[i]*a[j];
		}
	}
	printf("%d",sum);
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxm=100+2;
int n,m,odd1,odd2;
int a[maxm];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d",&a[i]);
		if (a[i]&1){
			if (!odd1) odd1=i;
			else if (!odd2) odd2=i;
			else{
				printf("Impossible\n");
				return 0;
			}
		}
	}
	if (odd1) swap(a[1],a[odd1]);
	if (odd2) swap(a[odd2],a[m]);
	for (int i=1;i<=m;i++) printf("%d ",a[i]);
	if (m==1) m++;
	a[1]--,a[m]++;
	int pos=a[1]?1:2;
	printf("\n%d\n",m-pos+1);
	for (int i=pos;i<=m;i++) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 128