akhauriyash/Code-Regression huggingface dataset:
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second)
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto &i : a)
#define umap unordered_map
#define fileio(in, out) freopen("in", "r", stdin); freopen("out", "w", stdout)
const int mod = (int)(1e9) + 7;
//endregion

ll num_groups, p[100005], grpsize[100005];
int par(int x) { return (p[x]==x)? x:par(p[x]); } //No compression
bool isSameGroup(int a, int b) { return par(a) == par(b); }
void merge(int a, int b) {
    a = par(a), b = par(b);
    num_groups -= (!isSameGroup(a, b));
    if (grpsize[a] < grpsize[b]) {
        p[a] = b;
        grpsize[b] += grpsize[a];
    }
    else {
        p[b] = a;
        grpsize[a] += grpsize[b];
    }
}

int main() {
    io();
    ll n, m, t, x, y;
    vll ans;
    in2(n, m);
    fori (i, n) p[i] = i, grpsize[i] = 1;
    num_groups = n;
    vii arr(m);
    viin(arr, m);
    reverse(all(arr));
    t = n*(n-1)/2;
    fori (i, m) {
        ans.eb(t);
        x = par(arr[i].first-1), y = par(arr[i].second-1);
        if (x == y) continue;
        t -= (grpsize[x] * grpsize[y]);
        merge(x, y);
    }
    ford (i, m) outn(ans[i]);
}


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    int i,tp=0,w=0,l=0;
    for (i=0;i<s.size();i++)
    {
        if (s[i]=='g')
        {
            if (tp>0)
            {
                tp--;
                w++;
            }
            else
                tp++;
        }
        else
        {
            if (tp>0)
                tp--;
            else
            {
                tp++;
                l++;
            }
        }
    }
    cout<<w-l<<endl;
}

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

def main():
    import sys
    import math

    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))

    for i in range(len(A_list)):
        A_list[i] = math.log10( A_list[i] )


    point_K = 0
    
    for i in range(K):
        point_K += A_list[i]


    prev = point_K

    for i in range(K, len(A_list)):
        current = prev - A_list[i-K] + A_list[i]

        if current > prev:
            print("Yes")
        else:
            print("No")
        
        prev = current


if __name__ == "__main__":
    main()


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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a, y = d - b;
	cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{string S,T; cin >> S >> T;
 
 bool flag = false;
 
 for(int i = 0; i < S.size(); i++){
   if( S == T){ flag = true; break;}
   S = S.back() + S.substr(0,S.size() - 1);}
 
 if(flag){cout << "Yes" << endl;}
 else{ cout << "No" << endl;}
 
 return 0;}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC089_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var arare = Console.ReadLine().Split(' ').ToList();
            if (arare.Contains("P") && arare.Contains("W") && arare.Contains("G") && arare.Contains("Y"))
            {
                Console.WriteLine("Four");
            }
            else
            {
                Console.WriteLine("Three");
            }
        }
    }
}


Measured memory_bytes: 13152
#include <iostream>
#include <string>
#include <math.h>
#include<cstdlib>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int ans=0x3f3f3f3f;
int ar[22][22]={0};
int cr[22],dr[22];
long long int br[22]={0};
int n,m,x;
void dfs(int s,int sum)
{
    if(s==n+1)
    {
        for(int i=1;i<=m;i++) {if(dr[i]<x) return;}
        ans=min(ans,sum);
        return;
    }
    dfs(s+1,sum);
    for(int i=1;i<=m;i++)
    {
        dr[i]+=ar[s][i];
    }
    dfs(s+1,sum+cr[s]);
    for(int i=1;i<=m;i++)
    {
        dr[i]-=ar[s][i];
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&x);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&cr[i]);
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&ar[i][j]);
            br[j]+=ar[i][j];
        }
    }
    int flag=0;
    for(int k=1;k<=m;k++)
    {
        if(br[k]<x) {printf("-1\n");flag=1;break;}
    }
    if(flag==0)
    {
        dfs(1,0);
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3788
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
#define MOD 1000000007

int main(){
    ll N,M;
    cin>>N>>M;
    vector<ll> a(N+1,0);
    for(ll i=1;i<=M;i++){
        ll temp;
        cin>>temp;
        a[temp]=-1;
    }
    a[0]=1;
    if(a[1]!=-1){
        a[1]=1;
    }
    for(ll i=2;i<=N;i++){
        if(a[i]==-1){
            continue;
        }
        a[i]=0;
        if(a[i-1]!=-1){
            a[i]+=a[i-1];
            a[i]=a[i]%MOD;
        }
        if(a[i-2]!=-1){
            a[i]+=a[i-2];
            a[i]=a[i]%MOD;
        }
    }
    cout<<a[N]%MOD<<endl;
    return 0;
}

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

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    int cnt = 0;
    rep(i, s.size()){
        if (s[i]!=t[i]) cnt += 1; 
    }
    cout << cnt << endl;
    return 0;
}

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

int main(void) {
  int N, K;
  int h[100001];
  int cnt = 0;
  cin >> N >> K;
  for(int i = 1; i <= N; i++) {
    cin >> h[i];
    if( h[i] >= K ) {
      cnt++;
    }
  }
  
  cout << cnt;
    
  return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int H, W;
string field[1005];

int main() {
    //cout.precision(10);
    cin >> H >> W;
    for(int h = 0; h < H; h++) cin >> field[h];
    vector<ll> plus, minus;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(field[h][w] == '.') continue;
            plus.push_back(h+w);
            minus.push_back(h-w);
        }
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end());
    cout << max(abs(plus[0] - plus.back()), abs(minus[0] - minus.back())) << endl;
    return 0;
}



Measured memory_bytes: 3252
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp.array;
  foreach (i;iota(0, s.length, 2)) write(s[i]);
  writeln("");
}


Measured memory_bytes: 920
#include<iostream>
using namespace std;
int main() {
	char a[5];
	char b[5];
	int x;
	int hit[12001];
	int blow[12001];
	for (int i = 0;; i++){
		cin >> a >> b;
		hit[i] = 0;
		blow[i] = 0;
		if (a[0] == '0' && b[0] == '0'){
			x = i;
			break;
		}
		for (int j = 0; j < 4; j++){
			for (int k = 0; k < 4; k++){
				if (a[j] == b[k]){
					if (j == k){
						hit[i] += 1;
					}
					else blow[i] += 1;
				}
			}
		}
	}
	for (int i = 0; i < x; i++){
		cout << hit[i] << " " << blow[i] << endl;
	}
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#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 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())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
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;}
const ll MOD=1e9+7;

const LL INF = 1LL << 51;

int N;
int as[114];
int bs[114];
LL dp[114][114];
bool allowed[114];
int proh;

bool Check() {
  rep(u, 51) {
    rep(v, 51) {
      dp[u][v] = INF;
    }
    dp[u][u] = 0;
    rep(v, u) {
      reps(m, 1, 51) {
        if (!allowed[m] && proh <= m) continue;

        int w = u%m;
        if (w >= v) {
          LL cost = 1LL << m;
          if (allowed[m]) cost = 0;
          dp[u][v] = min(dp[u][v], dp[w][v] + cost);
        }
      }
    }
  }

  rep(i, N) {
    if (dp[as[i]][bs[i]] >= INF) return false;
  }
  return true;
}

int main(){
  scanf("%d", &N);
  rep(i, N) {
    scanf("%d", &as[i]);
  }

  rep(i, N) {
    scanf("%d", &bs[i]);
  }

  proh = 52;
  if (!Check()) {
    puts("-1");
    return 0;
  }

  LL ans = 0;
  rrep(i, 51) {
    proh = i;
    if (!Check()) {
      allowed[i] = true;
      ans += 1LL << i;
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
n = int(input())
al = list(map(int, input().split()))

n0, n2, n4 = 0, 0, 0

for a in al:
    if a % 4 == 0:
        n4 += 1
    elif a % 2 == 0:
        n2 += 1
    else:
        n0 += 1

print('Yes' if n4+1 >= n0+n2%2 else 'No')


Measured memory_bytes: 20124
var h = [],hs = 0;
h[0] = new Array(2);
h[0][0] = -1;h[0][1] = -1;
 
function insert(key){
    h[++hs] = key;
 
    var i = hs;
 
    while(h[i][1] < h[Math.floor(i / 2)][1]){
        var ex = h[i];
        h[i] = h[Math.floor(i / 2)];
        h[Math.floor(i / 2)] = ex;
        i = Math.floor(i / 2);
    }
}
 
function extract(){
    if(hs <= 0)
        return;
 
    var ret = h[1];
 
    h[1] = h[hs--];
 
    i = 1;
    while((i * 2 <= hs && h[i][1] > h[i * 2][1]) || (i * 2 + 1 <= hs && h[i][1] > h[i * 2 + 1][1])){
        var l = i * 2;var r = i * 2;
        if(i * 2 + 1 <= hs)
            r++;
        var m = h[l][1] <= h[r][1] ? l : r;
        var ex = h[i];
        h[i] = h[m];
        h[m] = ex;
        i = m;
 
    }
    return ret;
}


function Main(input){
    input = input.split("\n");
    var n = parseInt(input[0],10);

    var graph = new Array(n);

    for(var i = 0;i < n;i++){
        input[i + 1] = input[i + 1].split(" ");
        var u = parseInt(input[i + 1][0],10);
        var k = parseInt(input[i + 1][1],10);
        graph[u] = new Array(k);
        for(var j = 0;j < k;j++)
            graph[u][j] = new Array(2);
        for(var j = 0;j < k;j++){
            graph[u][j][0] = parseInt(input[i + 1][j * 2 + 2],10);
            graph[u][j][1] = parseInt(input[i + 1][j * 2 + 3],10);
        }
    }

    var count = 1;
    var sum = Array(n);
    for(var i = 0;i < n;i++)
        sum[i] = 1000000000;
    sum[0] = 0;
    for(var i = 0;i < graph[0].length;i++){
        insert(graph[0][i]);
    } 
    while(count < n){
        var aa = extract();
        if(sum[aa[0]] < 1000000000)
            continue;

        sum[aa[0]] = aa[1];
        count++;

        for(var i = 0;i < graph[aa[0]].length;i++){
            graph[aa[0]][i][1] += sum[aa[0]];
            insert(graph[aa[0]][i]);
        }
    }

    for(var i = 0;i < n;i++){
        console.log(i + " " + sum[i]);
    }
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

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

int main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=0;
    for(int a=0; a<10; a++){
        for(int b=0; b<10; b++){
            for(int c=0; c<10; c++){
                int k=0;
                for(int i=0; i<n; i++){
                    int x = stoi((string)(s.substr(i,1)));
                    if((k==0 & a==x)|(k==1 & b==x)|(k==2 & c==x)) k++;
                    if(k==3){
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> dp(n + 1, 1);
  for (int i = 2; i <= n; i++) dp[i] = dp[i - 1] + dp[i - 2];
  cout << dp[n] << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2020;
const int M = 2e5 + 10;
ll dp[2][N];
ll pre[N][10];
void init(vector<vector<vector<int>>> & query) {
    for(int i = 0; i < 2019; i ++) {
        for(int j = 1; j <= 9; j ++) {
            pre[i][j] = (i * 10 + j) % 2019;
        }
    }
    for(int i = 0; i < 2019; i ++) {
        for(int j = 1; j <= 9; j ++) {
            int curr = pre[i][j];
            query[curr][j].push_back(i);
        }
    }
}

int main() {
    string s;
    cin >> s;
    vector<vector<vector<int>>> query(2019, vector<vector<int>> (10));
    init(query);
    ll sum = 0;
    for(int i = 1; i <= s.size(); i ++) {
        
        int bit = s[i-1] - '0';
        for(int j = 0; j < 2019; j ++) {
            dp[i%2][j] = 0;
            for(auto num: query[j][bit]) {
                dp[i%2][j] += dp[(i-1)%2][num];
            }
        }
        dp[i%2][bit] ++;
        sum += dp[i%2][0];
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 4928
#include<stdio.h>
int main()
{

	int n, i, a, b, c;

	scanf("%d", &n);

	for(i=0;i<n;i++){
		scanf("%d%d", &a, &b);
		c = b - a + 1 + c;
		}
	printf("%d\n", c);

	return 0;
}

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

using namespace std;

const int maxn = 100;
int m, n, on[maxn], k[maxn], p[maxn], s[maxn][maxn];

void Enter()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> k[i];
        for (int j = 1; j <= k[i]; j++)
            cin >> s[i][j];
    }
    for (int i = 1; i <= m; i++)
        cin >> p[i];
}

bool Check()
{
    for (int i = 1; i <= m; i++)
    {
        int cnt = 0;
        for (int j = 1; j <= k[i]; j++)
            if (on[s[i][j] - 1] == 1)
                cnt++;
        if ((cnt & 1) != p[i])
            return false;
    }
    return true;
}

void Solve()
{
    int res = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        for (int j = 0; j <= n - 1; j++)
            if (i & (1 << j))
                on[j] = 1;
            else
                on[j] = 0;
        if (Check())
            res++;
    }
    cout << res;
}

int main()
{
    Enter();
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

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

int main()
{
    ll n,k,a;
    cin >> n >> k;
    rep(i,n) cin >> a;
    n--;
    k--;
    cout << (n%k?n/k+1:n/k) << endl;
    return 0;
}

Measured memory_bytes: 256
class UF():
  def __init__(self, N):
    self.parents = [-1] * N

  def find(self, n):
    if self.parents[n] < 0:
      return n
    else:
      self.parents[n] = self.find(self.parents[n])
      return self.parents[n]

  def union(self, u,v):
    p1,p2 = self.find(u),self.find(v)
    if p1==p2: return
    if p1 > p2:
      p1,p2 = p2,p1
    self.parents[p1] += self.parents[p2]
    self.parents[p2] = p1

  def same(self, u,v):
    return self.find(u) == self.find(v)

  def weight(self, u):
    p = self.find(u)
    return -self.parents[p]

N,M = map(int,input().split())
uf = UF(N+1)
for _ in range(M):
  a,b = map(int,input().split())
  uf.union(a,b)

print(max([ abs(u) for u in uf.parents if u<0 ]))

Measured memory_bytes: 88344
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <set>
#define MAX 100000
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	lli A, B; cin >> A >> B;
	int K; cin >> K;

	if (K >= (B - A) / 2 + 1) {
		rep(i, A, B + 1)cout << i << endl;
	}
	else {
		rep(i, A, A + K)cout << i << endl;
		rep(i, B - K + 1, B + 1)cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int A = min(k, a);
	k -= A;
	int B = min(k, b);
	k -= B;
	int C = min(k, c);
	cout << A - C << endl;
}


Measured memory_bytes: 3628
Imports System.Console
Module Module1
    Dim n As Int64
    Dim ans As Int64
    Dim ii, iii As Integer
    Sub Main()
        n = ReadLine()
        Dim f(n) As Integer
        For i = 1 To Math.Round(Math.Pow(n, 1 / 2))
            For ii = i To Math.Round(Math.Pow(n, 1 / 2))
                For iii = ii To Math.Round(Math.Pow(n, 1 / 2))
                    Dim w As Integer = (i + ii + iii) ^ 2 - (i * ii + ii * iii + iii * i)
                    If w >= 1 And w <= n Then
                        If i <> ii And ii <> iii And iii <> i Then
                            f(w) += 6
                        ElseIf i = ii And ii = iii Then
                            f(w) += 1
                        Else
                            f(w) += 3
                        End If
                    End If
                Next
            Next
        Next
        For i = 1 To n
            WriteLine(f(i))
        Next
        ReadLine()
    End Sub
End Module


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

using namespace std;

int main(void)
{
    int         u, v;
    vector<int> deg(5, 0);

    for (int i = 0; i < 3; ++i)
    {
        cin >> u >> v;
        ++deg[u], ++deg[v];
    }

    int ones  = 2;
    int evens = 2;
    for (int i = 1; i < 5; ++i)
    {
        if (deg[i] == 1)
            --ones;
        else if (deg[i] % 2 == 0)
            --evens;
    }
    if (ones == 0 and evens == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3608
#x, y, a, b, c = gets.split.map(&:to_i)

s = gets.chomp
k = gets.to_i

n = s.size

ans = ""
for i in 0..n-1
    if i == n - 1
        k %= 26
        ans += ((s[i].ord - "a".ord + k) % 26 + "a".ord).chr
    else 
        if s[i] == "a"
            ans += s[i]
            next
        end
        co = s[i].ord - "a".ord
        if 26 - co <= k
            ans += "a"
            k -= 26 - co
        else
            ans += s[i]
        end
    end
end

puts ans

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

int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      int map[n+1];
      for(int i=1;i<=n;i++)
	{
	  cin>>map[i];
	}
      int now=1;
      int ans=m;
      for(int i=1;i<=m;i++)
	{
	  int tmp;
	  cin>>tmp;
	  now+=tmp;
	  if(ans==m)
	    {
	      if(now>=n)
		{
		  ans=i;
		  continue;
		}	  
	      now+=map[now];
	      if(now>=n)
		{
		  ans=i;
		  continue;
		}
	    }
	}
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 1164
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
using namespace std;

// JAI SHREE KRISHNA

// 1.25H Dude!!! 1.25 H

//!!!C***

//Remember the Past,Play the Future

vector<pii>v1;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    v1.clear();
    ll n;
    cin>>n;
   loop(i,n)
    {
        ll a,b;
        cin>>a>>b;
        v1.push_back({a,b});
    }
    ll ans  =0  ;
    ll curr = 0 ;
    for(ll j = v1.size()-1;j>=0;j-=1)
    {
        v1[j].first+=curr;
        if(v1[j].first%v1[j].second==0)
            continue;
        ll x = v1[j].first/v1[j].second;
        curr+=(((x+1)*v1[j].second)-v1[j].first);
        ans+=(((x+1)*v1[j].second)-v1[j].first);
    }
    cout<<ans<<endl;
    
    
    
    
      return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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

int main() {
    vector<ll> m(100001,0); 
    ll n;
    cin >> n;
    ll ans = 0;
    REP(i, n){
        ll a;
        cin >> a;
        m[a] += 1;
        ans += a;
    }
    ll q;
    cin >> q;
    REP(i, q){
        ll b,c;
        cin >> b >> c;
        ans += (c - b) * m[b];
        m[c] += m[b];
        m[b] = 0;
        cout << ans << endl;
    }
    

}



Measured memory_bytes: 3864
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  queue<ll> q;
  for(ll i=1;i<=9;i++) q.push(i);
  int N=n;
  while(1){
    N--;
    ll x=q.front();
    q.pop();
    if(N==0){
      cout << x << endl;
      return 0;
    }
    int y=x%10;
    if(y!=0) q.push(10*x+y-1);
    q.push(10*x+y);
    if(y!=9) q.push(10*x+y+1);
  }
  
}

Measured memory_bytes: 1792
N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

tmp = T[0]
for i in range(1, N):
    tmp = T[i]//gcd(tmp, T[i])*tmp
    
print(int(tmp))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a[5],ans;
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  ans=a[2]*10;
  ans+=a[0]+a[1];
  cout<<ans<<"\n";
  
  return 0;
}

Measured memory_bytes: 3672
N, K = map(int, input().split())
R = [0] * N
for _ in range(K):
    d, = map(int, input().split())
    X = list(map(int, input().split()))
    for x in X:
        R[x-1] = 1
c = 0
for i in range(N):
    if R[i] == 0:
        c += 1
print(c)


Measured memory_bytes: 67776
#include <iostream>

using namespace std;

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}
		int pp, max=0;
		for(int i=0; i<n; i++) {
			int p, d1, d2;
			cin >> p >> d1 >> d2;
			if(d1+d2>max) {
				max=d1+d2;
				pp=p;
			}
		}
		cout << pp << " " << max << endl;
	}

	return 0;

}

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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long
#define pii pair <int, int>
#define ld long double

using namespace std;

ld fontana = (((ld) 20.0 * (ld) 3.141592653589793238462643383279) / (ld) 4.0);

vector <pii> ve;
bool flag;

bool cmp(pii a, pii b) {
  if (flag) return a.first > b.first;
  return a.first < b.first;
}

unordered_map <int, int> loga;

void add(int x, int v) {
  for (x; x <= 1e8; x += x & -x) {
    loga[x] = max(loga[x], v);
  }
  return;
}

int val(int x) {
  int tr = 0;
  for (x; x; x -= x & -x) {
    tr = max(tr, loga[x]);
  }
  return tr;
}

int main() {
  ios_base::sync_with_stdio(false);

  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1++; y1++; x2++; y2++;

  if (x1 > x2) {
    swap(x1, x2);
    swap(y1, y2);
  }
  if (y1 > y2) flag = 1;

  int n;
  cin >> n;
  REP(i, n) {
    int x, y;
    cin >> x >> y;
    x++; y++;
    if (x < min(x1, x2) || x > max(x1, x2)) continue;
    if (y < min(y1, y2) || y > max(y1, y2)) continue;
    ve.push_back({x, y});
  }
  sort(ve.begin(), ve.end(), cmp);

  ld out = ((ld)(abs(x2 - x1)) * (ld) 100) + ((ld)(abs(y2 - y1)) * (ld) 100);

  int ma = 0;
  REP(i, ve.size()) {
    int x = ve[i].first;
    int y = ve[i].second;

    int tr = val(y);
    ma = max(ma, tr + 1);
    add(y, tr + 1);
  }
  out -= (ld) ma * (ld) 20;
  out += (ld) ma * fontana;
  if (ma > min(abs(x2 - x1), abs(y2 - y1))) {
    out += fontana;
  }


  cout << fixed << setprecision(15) << out << "\n";

  return 0;
}


Measured memory_bytes: 69240
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N, R;
    cin >> N >> R;
    if(N >= 10) cout << R << endl;
    else cout << R + 100 * (10 - N) << endl;
}


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

int compar(const int *val1, const int *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}

int main(){
  int i,j,k;
  int N;
  scanf("%d",&N);
  int P[N];
  for(i=0;i<N;i++)
    scanf("%d",&P[i]);
  
  int size = sizeof(P)/sizeof(int);
  
  qsort(P, size, sizeof(int),
        (int (*)(const void *, const void *))compar
    );
  
  P[N-1]/=2;
  int sum =0;
  for(i=0;i<N;i++)
    sum+=P[i];
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 128
N,K = list(map(int,input().split()))
A = input()
A = list(A)
A = list(map(int,A))
l = [0]
s = []

for i in range(N-1):
    if A[i] != A[i+1]:
        l.append(i+1)
        s.append(l[len(l)-1]-l[len(l)-2])
l.append(N)
s.append(l[len(l)-1]-l[len(l)-2])
a = 0
right = 0
left = 0
g = 0
su = 0
if A[0] == 0:
    for i in range(len(s)):
        su +=s[right]
        if right%2==0:
            g += 1
        right +=1
        if g<=K:
            a = max(a,su)
        else:
            while g>K:
              su -= s[left]
              if left%2==0:
                  g -=1
              left +=1
        a = max(a,su)
else:
    for i in range(len(s)):
        su +=s[right]
        if right%2==1:
            g += 1
        right +=1
        if g<=K:
            a = max(a,su)
        else:
            while g>K:
              su -= s[left]
              if left%2==1:
                  g -=1
              left +=1
        a = max(a,su)

print(a)



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

Measured memory_bytes: 572
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int x;
    cin >> x;
    cout << !x;
    return 0;
}




Measured memory_bytes: 3580
#include <iostream>
#include <math.h>
#include<stdio.h>
using namespace std;

int main()
{
    int h,m;
    double ja,jb;
    double jiao;
    double a,b,c;
    cin>>a>>b>>h>>m;
    ja=h*30+30*(m/60.0);
    jb=360*(m/60.0);
    //cout<<ja<<jb<<endl;
    jiao=fabs(ja-jb);
    if(jiao>180)
        jiao=360-jiao;

    jiao = jiao*3.141592653589793/180;
   // cout<<cos(jiao)<<endl;
    c = a*a+b*b-2*a*b*cos(jiao);
    printf("%.9lf",sqrt(c));

}


Measured memory_bytes: 4220
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	int n;
	cin>>n;
	vi s(n),t(n);
	rep(i,n)cin>>s[i];
	rep(i,n)cin>>t[i];

	int out=0;
	rep(i,30){
		vi a=s,b=t;
		int q=1<<(i+1);
		rep(i,n)a[i]%=q,b[i]%=q;
		q>>=1;
		sort(all(b));
		int co=0;
		rep(j,n){
			co+=lower_bound(all(b),2*q-a[j])-lower_bound(all(b),q-a[j]);
			co+=lower_bound(all(b),4*q-a[j])-lower_bound(all(b),3*q-a[j]);
		}
		if(co%2)out|=q;
	}
	cout<<out<<endl;
}










Measured memory_bytes: 6552
#include <string>
#include <iostream>

using namespace std;

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

	for (int i=0; i < s.size(); ++i)
	{
		int diff = ('z'-s[i]) + 1;
		if (i == s.size()-1)
		{
			K = K % 26;
			//cout << "changing from " << s[i] << " ";
			s[i] = ((s[i]-'a' + K)%26) + 'a';
			//cout << "to " << s[i] << " in " << (K) << endl;
		}
		else if (s[i] != 'a' && diff <= K)
		{
			//cout << "Changing from " << s[i] << " to a in " << diff << endl;
			K -= diff;
			s[i] = 'a';
		}
		
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  char A;
  while(scanf("%c",&A)!=EOF){
    if('A'<=A&&A<='Z'){
      A=tolower(A);
    }
    else if('a'<=A&&A<='z'){
      A=toupper(A);
    }
    printf("%c",A);
  }
  return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	multiset<ll> ls, rs;
	int Q; cin >> Q;
	ll sum = 0;	
	ls.insert(-LLINF);
	rs.insert(LLINF);
	while (Q--) {
		ll q, a, b; cin >> q;
		if (q == 1) {	
			cin >> a >> b; sum += b;
			if (a < *ls.rbegin()) sum += *ls.rbegin() - a;
			if (*rs.begin() < a) sum += a - *rs.begin();

			if (a < *ls.rbegin()) {
				rs.insert(*ls.rbegin());
				ls.erase(--end(ls));
				ls.insert(a);
				ls.insert(a);
			}
			else if (*rs.begin() < a) {
				ls.insert(*rs.begin());
				rs.erase(begin(rs));
				rs.insert(a);
				rs.insert(a);
			}
			else {
				ls.insert(a);
				rs.insert(a);
			}
		} else {
			cout << *ls.rbegin() << " " << sum << endl;
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 19072
K = int(input())

if(7%K == 0):
    print(1)
else:
    mod = 7%K
    for i in range(2, K+1):
        if(mod * 10 + 7)%K == 0:
            print(i)
            break
        mod = (mod * 10 + 7)%K
    else:
        print(-1)

Measured memory_bytes: 9172
N,M,X=map(int,input().split())
import numpy as np
list=[list(input().split()) for _ in range(N)]
for i in range(N):
  for j in range(M+1):
    list[i][j]=int(list[i][j])

def bin(x):
  lists=[]
  k=0
  while x!=0:
    t=x%2
    lists.append(t)
    x=x//2
    k+=1
  for i in range(N-k):
    lists.append(0)
  return (lists)

def price(x):
  lists=list[:]
  listt=[]
  for i in range(N):
    lists[i]=lists[i]*bin(x)[i]
  for m in range(1,M+1):
    s=0
    for n in range(N):
      try:
        s+=lists[n][m]
      except IndexError:
        continue
    listt.append(s)
  p=1
  for i in range(M):
    if listt[i]<X:
      p=0
    else:
      continue
  S=0
  for k in range(N):
    try:
      S+=lists[k][0]
    except IndexError:
      continue
  return (S*p)

pr=0
for i in range(1,2**N):
  if pr==0:
    pr=max(pr,price(i))
  else:
    if price(i)>0:
      pr=min(pr,price(i))
    else:
      continue

if pr==0:
  print (-1)
else:
  print (pr)

Measured memory_bytes: 26988
#include<iostream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

long long n;

long long sc(long long a) {
    long long r = 0;

    while(a) {
        r += a % 10;
        a /= 10;
    }

    return r;
}

int main() {
    //freopen("ttt", "r", stdin);

    cin >> n;

    long long r = 0, c = 0, t = n, aa = 0;

    while(t) {
        ++c;
        t /= 10;
    }

    r = (c - 1) * 9;
    r = max(sc(n), r);

    t = n;

    while(t) {
        r = max(r, sc(t - 1) + 9 * aa);
        ++aa;
        t /= 10;
    }

    cout << r;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

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

    if ( (s[2] == s[3])  & (s[4] == s[5]) ){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a=list(map(int,input().split()))
if n%2:
    for i in a[::2][::-1]:
        print(i,end=' ')
    for i in a[1::2]:
        print(i,end=' ')
    print()
else:
    for i in a[1::2][::-1]:
        print(i,end=' ')
    for i in a[::2]:
        print(i,end=' ')
    print()

Measured memory_bytes: 26020
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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

const ll mod = 1e9 + 7;

char maze[1005][1005];
int dist[1005][1005];
bool done[1005][1005];
int w,h;
queue<pair<int,int>>p;
int dir_x[4] = {1,0,-1,0};
int dir_y[4] = {0,1,0,-1};

void search(int a,int b,int k){
    
    if(done[a][b])return;
    if(a < 0 || b < 0 || a >= h || b >= w)return;
    if(maze[a][b] == '.'){
        dist[a][b] = k;
        done[a][b] = true;
        p.push(make_pair(a,b));
        rep(i,4){
            search(a+dir_x[i],b+dir_y[i],k);
        }

    }

}




int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll ch,cw,dh,dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    --ch;--cw;--dh;--dw;

    rep(i,h)rep(j,w){
        cin >> maze[i][j];
        done[i][j] = false;
    }
    int k = 1;
    queue<pair<int,int>>b;
    b.push(make_pair(ch,cw));
    while(1){
        while(!b.empty()){
            auto pr = b.front();b.pop();
            search(pr.first,pr.second,k);
        }
        while(!p.empty()){
            auto pr = p.front();p.pop();
            for(int i = -2; i <= 2; ++i)for(int j = -2; j <= 2; j++){
                if(!done[pr.first+i][pr.second+j] && maze[pr.first+i][pr.second+j] == '.'){
                    b.push(make_pair(pr.first+i,pr.second+j));
                }
            }
        }
        if(b.empty())break;
        k++;

    }

    rep(i,h){
        rep(j,w){
            cerr << dist[i][j];
        }
        cerr << "\n";
    }
    if(dist[dh][dw] == 0){
        cout << -1 << endl;
    }else{
        cout << dist[dh][dw]-1 << endl;
    }
    return 0;


}


Measured memory_bytes: 9516
mp = [list("X" * 10)] + [list("X" + input() + "X") for _ in range(8)] + [list("X" * 10)]
vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1))
#mami...o, witch...x

def search(target, another, x, y, dx, dy):
  nx, ny = x + dx, y + dy
  cnt = 0
  while mp[ny][nx] == another:
    nx += dx
    ny += dy
    cnt += 1

  if mp[ny][nx] == target:
    return cnt
  else:
    return 0

def score(target, another, x, y):
  ret = 0
  for dx, dy in vec:
    ret += search(target, another, x, y, dx, dy)
  return ret

def locate(target, another, x, y):
  mp[y][x] = target
  for dx, dy in vec:
    if search(target, another, x, y, dx, dy):
      nx, ny = x + dx, y + dy
      while mp[ny][nx] == another:
        mp[ny][nx] = target
        nx += dx
        ny += dy

def temp(target, another, flag):
  max_score = 0
  max_x, max_y = 100, 100
  loop = range(1, 9) if flag else range(8, 0, -1)
  for y in loop:
    for x in loop:
      if mp[y][x] != ".":continue
      new_score = score(target, another, x, y)
      if new_score > max_score:
        max_score = new_score
        max_x, max_y = x, y
  
  if max_score != 0:
    locate(target, another, max_x, max_y)
    return True
  return False

def mami():
  return temp("o", "x", True)

def witch():
  return temp("x", "o", False)

def play():
  while True:
    flag = False
    flag = mami() or flag
    flag = witch() or flag
    if not flag:break
play()
[print("".join(lst[1:-1])) for lst in mp[1:-1]]


Measured memory_bytes: 5588
// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  cout << n + n * n + n * n * n << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

int main() {
	ll a = 0, b = 0, k = 0;
	cin >> a >> b >> k;

	rep(i, k) {

		if (i % 2 == 0) {
			//taka
			if (a % 2 == 1) {
				a--;
			}
			b += a / 2;
			a /= 2;
		}
		else {
			//ao
			if (b % 2 == 1) {
				b--;
			}
			a += b / 2;
			b /= 2;
		}
	}
	cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

void YesNo(bool x) {
    if (x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    ll D, T, S; cin >> D >> T >> S;
    YesNo(D <= T*S);
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

class UnionFind{
    vector<ll> par; vector<ll> r_size;
    public:
        UnionFind(ll N) : par(N),r_size(N){
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

        //Nの大きさで初期化
        void init(ll N){
            par.resize(N); r_size.resize(N);
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

        ll find(ll x){
            if(par[x] == x)return x;
            return par[x]=find(par[x]);
        }

        //xとyとが所属する集合を併呑する
        void unite(ll x,ll y){
            ll rx = find(x); ll ry = find(y);
            if(rx == ry) return;
            if(r_size[rx]<r_size[ry]) swap(rx,ry);
            r_size[rx] += r_size[ry];
            par[ry] = rx;
        }

        bool same(ll x, ll y){
            ll ry = find(x); ll rx = find(y);
            return rx == ry;
        }

        //素集合の大きさを返す
        ll el_size(ll x){
            return r_size[find(x)];
        }
};

int main(){
	int N,M,x,y;
	cin>>N>>M;
	UnionFind un(N);
	vector<int> p(N);
	rep(i,N)cin>>p[i];
	rep(i,M){
		cin>>x>>y;
		--x; --y;
		un.unite(x, y);
	}
	vector<set<int>> cnt(N);
	rep(i,N){
		cnt[un.find(i)].insert(p[i]);
	}
	int ans = 0;
	rep(i,N){
		if(cnt[un.find(i)].count(i+1) == 1) ++ans;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0){
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>ret(n, 0);
  for(int i=1; i<n; i++){
    cin >> a[i];
    a[i]--;
  }
  for(int i=n-1; i>=1; i--){
    ret[a[i]]++;
  }
  for(int i=0; i<n; i++){
    cout << ret[i] << endl;
  }
  return 0;
}
  

Measured memory_bytes: 4364
while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print() 


Measured memory_bytes: 7000
N = int(input())
NSP = [[i] + input().split() for i in range(1,N+1)]
M = {}
for nsp in NSP:
    if nsp[1] in M:
        M[nsp[1]].append(nsp)
    else:
        M[nsp[1]] = []
        M[nsp[1]].append(nsp)
for m in sorted(M):
    m2 = sorted(M[m], key=lambda x: -int(x[2]))
    for m3 in m2:
        print(m3[0])

Measured memory_bytes: 3064
def check(a, b, lst):
  for s, f in lst:
    if not(b <= s or f <= a):
      return 1
  return 0

a, b = map(int, input().split())
n = int(input())
lst = [tuple(map(int, input().split())) for _ in range(n)]
print(check(a, b, lst))


Measured memory_bytes: 5604