akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(),v.end())

void solve(ll n)
{
vector<ll>a(n+1,0);
    ll i,j;
for(i=1;i<=n;i++)
{
for(j=0;j<=n;j+=i)a[j]++;
}
    ll t=0;
for(i=1;i<=n;i++)
{
        t+=i*a[i];
}cout<<t<<endl;
}
int main()
{
ll n;cin>>n;
solve(n);
}

Measured memory_bytes: 81404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vec a(n+1),b(m+1);
  for(ll i=0;i<n;i++) {
    cin >> a[i+1];
    a[i+1]+=a[i];
  }
  for(ll i=0;i<m;i++) {
    cin >> b[i+1];
    b[i+1]+=b[i];
  }
  ll ok=0,ng=n+m+1;
  while(ok+1<ng) {
    ll mid=(ng+ok)>>1;
    ll v=inf;
    for(ll i=max(0LL,mid-m);i<=min(n,mid);i++) {
      v=min(v,a[i]+b[mid-i]);
    }
    if(v<=k) ok=mid;
    else ng=mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 6424
import sys
input = sys.stdin.readline
mod = 10**9 + 7
l = input().rstrip()

dp = [[0, 0] for _ in range(len(l))]

for i in range(len(l)):
    s = l[i]
    if i == 0:
        if s == "1":
            dp[i][0] = 2 # ピッタリ
            dp[i][1] = 1 # 未満確定
        else:
            dp[i][0] = 1
            dp[i][1] = 0
        continue
    if s == "1":
        dp[i][0] = (dp[i - 1][0] * 2) % mod
        dp[i][1] = (dp[i - 1][0] * 1 + dp[i - 1][1] * 3) % mod
    else:
        dp[i][0] = dp[i - 1][0] * 1
        dp[i][1] = (dp[i - 1][1] * 3) % mod

ans = (dp[-1][0] + dp[-1][1]) % mod

print(ans)


    

Measured memory_bytes: 54128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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 main() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int ans = 0;
  rep(i, n) {
    int same = 0;
    if (a[i] == b[i])
      same++;
    if (b[i] == c[i])
      same++;
    if (c[i] == a[i])
      same++;
    if (!same)
      ans += 2;
    else if (same == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int m = sc.nextInt();
			if(m==0)break;
			int[] x = new int[m];
			int[] y = new int[m];
				
			for(int i=1;i<m;i++){
				int a = sc.nextInt();
				int b = sc.nextInt();
				x[i] = x[a] + (b-1)*(1-b%2);
				y[i] = y[a] - (b-2)*(b%2);
			}
			Arrays.sort(x);
			Arrays.sort(y);
			System.out.println((x[m-1]-x[0]+1) + " " + (y[m-1]-y[0]+1));
		}
	}
	
}

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

template <int MOD>
struct ModInt {
    using lint = long long;
    using mint = ModInt<MOD>;

    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // assignment
    ModInt& operator=(const ModInt& x) {
        if (this != &x) { this->val = x.val; }
        return *this;
    }

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt operator~() const {
        // non-recursive extended euclidean algorithm
        int s = val, t = MOD;
        mint sx = 1, sy = 0, tx = 0, ty = 1;
        while (s % t != 0) {
            int div = s / t;
            s -= t * div;
            sx -= tx * div;
            sy -= ty * div;

            std::swap(s, t);
            std::swap(sx, tx);
            std::swap(sy, ty);
        }
        return mint(tx);
    }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= ~x; }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

int main() {
    int n;
    std::cin >> n;

    mint ans = 1;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;

        if (x < cnt * 2 + 1) {
            ans *= (cnt + 1);
            --cnt;
        }
        ++cnt;
    }

    while (cnt > 0) {
        ans *= cnt;
        --cnt;
    }

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


Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
counter = 0
for i in range(n-1, -1, -1):
    if(i < n-1):
        if(b_list[i+1] >= a_list[i+1]):
            counter += a_list[i+1]
            a_list[i+1] = 0
        else:
            counter += b_list[i+1]
            a_list[i+1] -= b_list[i+1]
    if(b_list[i] >= a_list[i+1]):
        counter += a_list[i+1]
        b_list[i] -= a_list[i+1]
    else:
        counter += b_list[i]
        b_list[i] = 0
    # print(i, counter, a_list, b_list)
# b1がa1をやるパターンが抜けてる.
counter += min(a_list[0], b_list[0])
print(counter)


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var List = new List<String>();
            String inputNum = null;
            int caseName = 0;

            while (true){
                inputNum = Console.ReadLine();
                if(inputNum.Equals("0"))
                {
                    break;
                }
                caseName++;
                List.Add("Case " + caseName + ": " + inputNum);
            }

            for (int i = 0; i < List.Count(); i++)
            {
               　Console.WriteLine(List[i]);
            }
        }
    }
}



Measured memory_bytes: 16068
# coding: utf-8

def is_keyence(target: str):
    key = "keyence"

    if target == key:
        return True

    for i in range(len(target)):
        for j in range(i, len(target)):
            tmp = ""
            if i > 0:
                tmp += target[0:i]
            if j < len(target) - 1:
                tmp += target[j + 1:]
            if tmp == key:
                return True
    return False


print("YES" if is_keyence(input().rstrip()) else "NO")


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

constexpr ll INF = ll(1e+18) + 1;

ll dist(ll a, ll b, ll c, ll d) {
    return abs(a-c) + abs(b-d);
}

int main() {
    map<string, int> m;
    string buf;
    int N;

    cin >> N;

    rep (i, N) {
        cin >> buf;

        if (m.count(buf) <= 0) {
            m.insert(make_pair(buf, 0));
        } else {
            m.erase(buf);
        }
    }

    cout << m.size() << endl;
}


Measured memory_bytes: 11360
import sys
import itertools
import copy

sys.setrecursionlimit(10**7)
s=input()
n=len(s)-1
a=[]

def dfs(i,arr,j):
    if i==n:
        res=sum(arr+[int(s[j:])])
    else:
        res=dfs(i+1,arr,j)+dfs(i+1,arr+[int(s[j:i+1])],i+1)
    return res

def solve():
    print(dfs(0,a,0))

solve()

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

int main(){
    string s,t;
    cin>>s>>t;
    int c=0;
    for(int i=0; s[i]; i++){
        if(s[i]==t[i])c++;
    }
    if(c==s.length() ) cout<<"Yes";
    else cout<<"No";

}


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

int ans=0;
int a[10][10];

int func(vector<int> &t){
  int res= a[ 0 ][ t[0] ];
  for(int i=1;i<(int)t.size();i++){
    res=a[ res ][ t[i] ];
  }
  return res;
}

int main(){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      cin>>a[i][j];

  map< vector<int> ,int > mp;
  for(int i=0;i<10000;i++){
    int p=i;
    vector<int> t(4);
    for(int j=0;j<4;j++){
      t[j]=p%10;
      p/=10;
    }
    reverse(t.begin(),t.end());
    t.push_back( func(t) );
    bool flg=false;
    int base=func(t);


    //    cout<<t[0]<<' '<<t[1]<<' '<<t[2]<<' '<<t[3]<<' '<<t[4]<<' '<<base<<endl;
      
    vector<int> u;
    for(int j=0;j<5;j++){
      for(int k=0;k<10;k++){
        u=t;
        if(u[j]==k)continue;
        u[j]=k;
        if( func(u) == 0 )flg=true;
      }
    }

    for(int j=0;j<4;j++){
      u=t;
      if(u[j]==u[j+1])continue;
      swap(u[j],u[j+1]);
      if( func(u) == 0 )flg=true;
    }
    if(flg)ans++;
  }

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

Measured memory_bytes: 3152
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower


using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

bool is_prime(int n) {
    if (n == 2)return true;
    if (n < 2 || n % 2 == 0) return false;

    int i = 3;
    while (i * i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 2;
    }
    return true;
}

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


int main() {
    int a, b;
    cin >> a >> b;

    cout << gcd(a, b) << endl;
    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  priority_queue<long long> pq[8]; //ppp, ppm, pmp, mpp, pmm, mpm, mmp, mmm
  for(int i = 0; i < n; i++){
    long long x, y, z;
    cin >> x >> y >> z;
    pq[0].push(x+y+z);
    pq[1].push(x+y-z);
    pq[2].push(x-y+z);
    pq[3].push(-x+y+z);
    pq[4].push(x-y-z);
    pq[5].push(-x-y+z);
    pq[6].push(-x+y-z);
    pq[7].push(-x-y-z);
  }
  long long ans = -1e13;
  for(int i = 0; i < 8; i++){
    long long tmp = 0;
    for(int j = 0; j < m; j++){
      tmp += pq[i].top();
      pq[i].pop();
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
      
    
    

Measured memory_bytes: 3716
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <bitset>

using namespace std;
using ll = long long int;

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll ans = 0;
  while (X <= Y)
  {
    X *= 2;
    ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {cin >> a[i];}
  sortd(a);
  ll ans = 0;
  for (int i = k; i < n; ++i) {
    ans += a[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())

sosu = []
#エラトステネスの篩
primes = list(range(n+1))
primes[1] = 0
for i in range(2,int(n**.5)+1):
    if primes[i]!=0:
        for j in range(i*2,n+1,i):
            primes[j] = 0
primes = [prime for prime in primes if prime!=0]

power = []
for prime in primes:
    p = prime
    tmp = 0
    while p<=n:
        tmp += n // p
        p *= prime
    power.append(tmp)
#print(power)

res = 1
mod = 10**9+7
for i in power:
    res *= i + 1
    res %= mod

print(res)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const char *data[10]={
  "* = *****",
  "* =* ****",
  "* =** ***",
  "* =*** **",
  "* =**** *",
  " *= *****",
  " *=* ****",
  " *=** ***",
  " *=*** **",
  " *=**** *",
};

int main(){
  int n;
  int cc = 0;
  while(cin>>n){
    char buff[8][6] = {{0}};
    if(cc++ != 0) puts("");
    REP(i,5){
      int d = n % 10;
      //printf("d = %d, data[d] = %s\n",d,data[d]);
      REP(j,8){
        buff[j][4-i] = data[d][j];
        //printf("buff = %c\n",buff[j][5-i]);
      }
      n/=10;
    }
    REP(i,8) puts(buff[i]);
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b-a<0&&c-b<0&&c-a<0)
    {
        cout<<"No";
    }
    
    else if(b-a<=d&&c-b<=d||c-a<=d)
    {
        cout<<"Yes";
    }

    else
    cout<<"No";
 
 
   return 0;
}

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

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;


int main() {
	lli n,numnum=0;
	cin>>n;
	
	vector<lli> vec(n);
	vector<lli>temp(3);
	rep0(i,n){
		cin>>vec[i];
	}
	
	sort(all(vec));
	vec.emplace_back(-1);
	int i=0,k=0;
	while(i<n){
		int num=0;
		if(k>2){
			cout << "No";
			return 0;
		}
		numnum^=vec[i];
		do
		{
			num++;
		}while(vec[i+num]>=0&&vec[i]==vec[i+num]);
		temp[k]=num;
		k++;
		i+=num;
	}
	if((k==2&&temp[1]==2*temp[0]&&vec[0]==0)||(k==1&&numnum==0)||(k==3&&temp[0]==temp[1]&&temp[0]==temp[2]&&numnum==0))cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <math.h>
#include <numeric>
#include <math.h>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

const int MOD = 1000000007;

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

	unsigned long long n, k;
	cin >> n >> k;
	vector<unsigned long long> a(n);
	for (unsigned long long i = 0; i < n; i++)
		cin >> a[i];
	unsigned long long inv = 0;
	for (unsigned long long i = 0; i < n; i++)
		for (unsigned long long j = i + 1; j < n; j++)
			if (a[i] > a[j]) inv++;
	map<unsigned long long, unsigned long long> cnt;
	for (unsigned long long i = 0; i < n; i++)
	{
		for (unsigned long long j = 0; j < n; j++)
			if (a[i] > a[j]) cnt[i]++;
	}
	inv *= k;
	inv %= MOD;
	for (unsigned long long i = 0; i < n; i++)
	{
		inv += ((k * (k - 1) / 2) % MOD) * cnt[i];
		inv %= MOD;
	}
	cout << inv % MOD;
}

Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;
    vector<int> vs = { -1, 0, 1, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0 };

    cout << (vs[x] == vs[y] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
char b[100]="AKIHABARA";
scanf("%s",a);
int h1,h2;
int number1=0,number2=0;
h1=strlen(a);
h2=strlen(b);
int w;
for(w=0;w<h1;w++)
if(a[w]!='A')
number1++;
for(w=0;w<h2;w++)
if(b[w]!='A')
number2++;
if(number1!=number2)
{printf("NO\n");
return 0;
}
int q=0;
int u;
for( u=0;u<h2;u++)
if(a[q]==b[u])
q++;
if(q==h1)
printf("YES\n");
else
printf("NO\n");
return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int K,X;
  cin >>K>>X;
  
  for (int i = 0; i < 2*(K-1)+1; i++) {
 
cout <<X-K+1+i<<' ';
 
}
cout <<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100005
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pii;

vector<pii> graph[MAX];
int color[MAX];

void dfs(int u, int par)
{
    for(int i = 0; i < graph[u].size(); i++){
        int v = graph[u][i].first;
        if(v == par)
            continue;
        if(graph[u][i].second % 2 == 0){
            color[v] = color[u];
        }
        else
            color[v] = !color[u];
        dfs(v, u);
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n, u, v, w;

    cin>>n;

    for(int i = 0; i < n - 1; i++){
        cin>>u>>v>>w;
        graph[u].pb(mp(v, w));
        graph[v].pb(mp(u, w));
    }

    color[1] = 0;
    dfs(1, - 1);

    for(int i = 1; i <= n; i++){
        cout<<color[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 9216
main = interact $ unlines . map tic_tac_toe . lines
tic_tac_toe board
 | judge 'o' = "o" 
 | judge 'x' = "x"
 | otherwise = "d"
  where 
   win = ["111000000","000111000","000000111","100100100","010010010","001001001","100010001","001010100"]
   judge c = or $ map ((==3) . length . filter (== (c,'1')) . zip board) win

Measured memory_bytes: 3592
import java.util.Scanner;


public class Main{

	static int[] dp = new int[1000001];
	static int[] dp_odd = new int[1000001];
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		solve();

		while(true){
			int input = Integer.parseInt(s.nextLine());
			if(input == 0)
				return;
			System.out.println(dp[input] + " " + dp_odd[input]);
		}
	}

	@SuppressWarnings("unchecked")
	public static void solve() {
		for(int i=1 ; i<1000001 ; i++) {
			dp[i] = i;
			dp_odd[i] = i;
		}

		for(int i=2 ; (i*(i+1)*(i+2)/6) < 1000000 ; i++) {
			int n = i*(i+1)*(i+2)/6;
			for(int j=n ; j < 1000000 ; j++) {
				dp[j] = Math.min(dp[j], dp[j-n]+1);
				if((n%2) != 0)
					dp_odd[j] = Math.min(dp_odd[j], dp_odd[j-n]+1);
			}
		}
	}
}

Measured memory_bytes: 35420
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A.at(i);
    ll step[2] = {0,0};
    ll sum[2] = {0,0};

    rep(i,2) {
        rep(j, N) {
            sum[i] += A[j];
            if ((i+j)%2 == 0) {
                if (sum[i] <= 0) {
                    step[i] += abs(sum[i] - 1);
                    sum[i] = 1;
                }
            } else {
                if (sum[i] >= 0) {
                    step[i] += sum[i] + 1;
                    sum[i] = -1;
                }
            }
        }
    }
    cout << min(step[0], step[1]) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
const int N=550;
const int M=1LL<<30;
const int inf=1e9+7;
const LL INF=1e18;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//for(int mask=i;mask>0;mask=(mask-1)&i)
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){int s=0;while(x){s+=BIT[x];x-=x&-x;}return s;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//cout<<fixed<<setprecision(12)<<ans<<endl;
//__builtin_popcount(mask)

int n,m;
int p[8000];//prime
LL g[N][N];
int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
LL gcd(LL a,LL b){
	return b?gcd(b,a%b):a;
}
LL lcm(LL a,LL b){
	if(!a)return b;
	if(!b)return a;
	LL g=gcd(a,b);
	return a/g*b;
}
int main(){Accel
	cin>>n;m=n;
	if(n==2){
		cout<<"4 7\n23 10\n";
		return 0;	
	}
	vector<LL>P;P.PB(0);
	for(int i=2;i<=7919;i++)
		if(!p[i]){
			P.PB(i);
			for(int j=i+i;j<=7919;j+=i)p[j]=1;
		}
	//for(auto x:P)
		//cout<<x<<" ";
	FOR(i,1,n)FOR(j,1,m)g[i][j]=1;
	
	FOR(i,1,n)FOR(j,1,m){
		if(i%2==j%2){
			g[i][j]*=P[(i+j)/2];
			
			g[i][j]*=P[(i-j+n)/2+n+1];
		}
	}
	//FOR(i,1,n){FOR(j,1,m)cout<<g[i][j]<<" ";cout<<endl;}
	FOR(i,1,n)FOR(j,1,m)if(i%2!=j%2){
		g[i][j]+=lcm(lcm(g[i-1][j],g[i][j-1]),lcm(g[i+1][j],g[i][j+1]));
	}
	
	FOR(i,1,n){FOR(j,1,m)cout<<g[i][j]<<" ";cout<<endl;}
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
 ll n,m;
 
 cin>>n>>m;
 
 vector<ll>adj[n+1];
 
 for(ll i=0;i<m;i++){
     ll x,y;
     cin>>x>>y;
     
     adj[x].pb(y);
     adj[y].pb(x);
 }
 
 
 //ll cnt=(n-1)-m;
 bool mark[n+1];
 memset(mark,false,sizeof(mark));
 
 ll cnt=0;
 
 
 function<void(ll)>dfs=[&](ll s){
     mark[s]=true;
     
     for(auto a:adj[s]){
         if(!mark[a])
         dfs(a);
     }
 };
 
 for(ll i=1;i<=n;i++){
     if(!mark[i]){
         cnt++;
         dfs(i);
     }
 }
 
 cnt--;
 
 cout<<cnt<<endl;
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}


Measured memory_bytes: 11212
#include<cstdio>
#include<algorithm>
using namespace std;

int n,k;
int main()
{
	int ans=1;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) {
		if(i==1) ans*=k;
		else ans*=(k-1);
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        cout << (a % 2 == 1 ? 0 : -1)<< endl;
        return 0;
    }
    ll cnt = 0;
    while(1){
        if(c % 2 == 1 || b % 2 == 1 || a % 2 == 1)
        break;
        cnt++;
        ll aa = a,bb = b,cc = c;
        a = (bb + cc) / 2;
        b = (aa + cc) / 2;
        c = (aa + bb) / 2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def prt_list(A):
    s_list = list(map(str, A))
    print(' '.join(s_list))


def insert_sort(A):
    prt_list(A)
    for i in range(1, len(A)):
        key = A[i]
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = key
        prt_list(A)
    return

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))

insert_sort(a)



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

int main(int argc, char **argv) {
  int K, X;
  const int begin = -1000000;
  const int end = 1000000;

  cin >> K >> X;

  int ans;

  for (int i = -K + 1; i < K; i++) {
    ans = X + i;
    if (begin <= ans && ans <= end)
      cout << ans << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val xList = readLine()?.split(" ")?.map { Integer.parseInt(it) } ?: return

    val middleIndex = n / 2
    val sortedX = xList.sorted()

    val middleValue = sortedX[middleIndex] // 真っ二つにしたときに、大きい方の1番目に該当する値
    val lessMiddleValue = sortedX[middleIndex - 1] // 真っ二つにしたときに、小さい方のlastに該当する値

    val resultStr = xList.map {
        if (it >= middleValue) {
            lessMiddleValue
        } else {
            middleValue
        }
    }.joinToString("\n")

    println(resultStr)
}

Measured memory_bytes: 105608
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
ans=float("inf")
for i in range(2**N):
    ruikei=[0]*M
    onedan=0
    for j in range(N):
        if ((i>>j)&1):
            onedan+=CA[j][0]
            for k in range(1,M+1):
                ruikei[k-1]+=CA[j][k]
    #print(onedan)
    #print(ruikei)    
    kari=True    
    for j in ruikei:
        if j<X:
            kari=False
    if kari:
        ans=min(ans,onedan)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

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

def check_combination(a, b, c, x):
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                total = 500*i + 100*j + 50*k
                if total == x:
                    ans += 1
    return ans


a = int(input())
b = int(input())
c = int(input())
x = int(input())

print(check_combination(a, b, c, x))

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k,sum=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	cout<<sum;
	return 0;
}


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

int main(){
    string s;
    int n;
    ll bt, tem, res = 0;
    cin >> s;
    n = s.length();
    for(int i=0; i<(1<<(n-1)); i++){
        tem = (int)(s[0] - '0');
        bt = i;
        for(int j=1; j<n; j++){
            if(bt & 1){
                tem *= 10;
                tem += (int)(s[j] - '0');
            }else{
                res += tem;
                tem = (int)(s[j] - '0');
            }
            bt >>= 1;
        }
        res += tem;
        tem = 0;
    }
    cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int,int>;
const ll INF = (ll)1e10;
int h[4] = {-1,0,1,0};
int w[4] = {0,1,0,-1};

void a(){
    ll H,W; cin >> H >> W;
    auto s = vector<string>(H);
    for(auto &i:s) cin >> i;
	auto f = [&](p f,p e){
    queue<p> q;
    auto d = vector<vector<ll>>(H,vector<ll>(W,INF));
    d[f.first][f.second]=0;
    q.push(f);

        while(!q.empty()){
            auto u = q.front();
            q.pop();
            if(u.first == e.first && u.second == e.second)
                break; 
			for(int i=0;i<4;i++){
                int nh = u.first  + h[i];
                int nw = u.second + w[i];
            	
              	if(0<=nh&&nh<H&&0<=nw&&nw<W&&s[nh][nw]!='#'&&d[nh][nw]==INF){
                    d[nh][nw] = d[u.first][u.second]+1;
                    q.push(make_pair(nh,nw));
                } 
            }
        }
        return d[e.first][e.second];
    };
	
  	
  
  	ll ans =0;
  	for(int bh=0;bh<H;bh++)
        for(int bw=0;bw<W;bw++)
            for(int eh=0;eh<H;eh++)
                for(int ew=0;ew<W;ew++){
                    if(s[bh][bw]=='#'||s[eh][ew]=='#') continue;
                    ans = max(ans,f(make_pair(bh,bw),make_pair(eh,ew)));
                }
    
    cout << ans;
    return;
}

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

Measured memory_bytes: 256
n = gets.to_i
hash = {}
['S','H','C','D'].each do |suit|
  for rank in 1..13
    key = suit + " " + rank.to_s
    hash[key] =false
  end
end

 n.times do
   card = gets.chomp
   hash[card] = true
 end
 hash.select{|key,val|
   puts key if !val
 }

Measured memory_bytes: 8716
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll mod = 1000000007;
int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    ll n = s.size();
    vector<vector<int>> dp(n + 1, vector<int>(13, 0));
    dp[0][0] = 1;
    ll x = 1;
    rep(i, n){
        if(s[i] == '?'){
            rep(j, 10){
                int memo = x * j;
                memo %= 13;
                rep(k, 13){
                    dp[i + 1][(k + memo)%13] += dp[i][k];
                    dp[i+1][(k+memo)%13] %= mod;
                }
            }
        }else{
            int s0 = s[i] - '0';
            s0 = s0 * x;
            s0 %= 13;
            rep(k, 13){
                dp[i + 1][(k + s0)%13] += dp[i][k];
                dp[i+1][(k+s0)%13] %= mod;
            }
        }
        x *= 10;
        x %= 13;
    }
    cout << dp[n][5] << endl;
    return 0;
}

Measured memory_bytes: 8960
#include <stdio.h>
#include <string.h>

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return (key%M); }
int h2(int key){ return (1+key%(M-1)); }

int find(char str[]){
   int i;
   int j;
   for(i=0;i<M;i++){
     j=(h1(getKey(str))+i*h2(getKey(str)))%M;
     if(strcmp(H[j],str)==0) return j;
     else if(H[j][0]=='\0'|| i>=M) return 0;
   }
   return 0;
}

int insert(char str[]){
   int i;
   int j;
   for(i=0;i<M;i++){
     j=(h1(getKey(str))+i*h2(getKey(str)))%M;
     if(H[j][0]=='\0') {
        strcpy(H[j],str);
        return j;
     }
   }
   return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15464
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
#define INF 100000000


int main() {
  int n, m, l, r, left = 0, right = INF;
  cin >> n >> m;
  vector<vector<int>> data(m, vector<int>(2));
  REP(i, m) cin >> data[i][0] >> data[i][1];
  REP(i, m) {
    l = data[i][0]; r = data[i][1];
    if (r < left || right < l) { cout << 0 << "\n"; return 0; }
    left = max(left, l); right = min(right, r);
  }
  cout << (right - left + 1) << "\n";
}

Measured memory_bytes: 5760
from collections import deque

H,W=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
S=[input() for _ in range(H)]
visited=[[-1]*W for _ in range(H)]
visited[ch-1][cw-1]=0
h=deque([(ch-1,cw-1)])
c=0
while 1:
  done=[]
  while h:
    cx,cy=h.popleft()
    done.append((cx,cy))
    for dx,dy in [(0,1),(1,0),(0,-1),(-1,0)]:
      nx,ny = cx+dx,cy+dy
      if 0<=nx<H and 0<=ny<W and S[nx][ny]=='.' and visited[nx][ny]==-1:
        h.append((nx,ny))
        visited[nx][ny]=c
  for cx,cy in done:
    for dx in range(-2,3):
      for dy in range(-2,3):
        nx,ny = cx+dx,cy+dy
        if 0<=nx<H and 0<=ny<W and S[nx][ny]=='.' and visited[nx][ny]==-1:
          h.append((nx,ny))
          visited[nx][ny]=c+1
  if not h or visited[dh-1][dw-1]!=-1:
    break
  c+=1
print(visited[dh-1][dw-1])


Measured memory_bytes: 90648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n; cin >> n;
  int c = 0;

  for (int i = 1; i < n; i++) {
    for (int j = 1; j * j <= n-i; j++) {
      if (j*j == n-i) {
        c++;
      } else if ((n-i)%j == 0) {
        c+=2;
      } 
    }
  }

  cout << c << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int k;
  cin >> k;
  queue<int> que;
  for(int i = 1;i <= 9;i++){
    que.push(i);
  }
  int num = 0;
  while(k--){
    num = que.front();
    que.pop();
    if((num*10+num%10) % 10 != 0) que.push((num*10+num%10) - 1);
    que.push((num*10+num%10));
    if((num*10+num%10) % 10 != 9) que.push((num*10+num%10) + 1);
  }
  cout << num << endl;
}

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

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(c)  (c).begin(),(c).end()
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n;
string a,b,c;

int main(){
    cin >> n >> a >> b >> c;
    int res = 0;
    REP(i,n){
        vector<int> cnt(26,0);
        cnt[a[i]-'a']++;
        cnt[b[i]-'a']++;
        cnt[c[i]-'a']++;
        res+=3-*max_element(all(cnt));
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
# encoding: utf-8
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]

h.sort()

ans = 10 ** 9
for i in range(N - K + 1):
    if h[i + K - 1] - h[i] < ans: ans = h[i + K - 1] - h[i]

print(ans)

Measured memory_bytes: 7508
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		if(N % K == 0) {
			System.out.println(0);
			return;
		}
		System.out.println(Math.min(N, Math.abs(N % K - K)));
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
const long long INFLL = 1LL << 62;
const int INF = 1 << 30;
const double PI = acos(-1);
int main()
{
	ll x;
	ll ans = 0LL;
	cin >> x;
	ll now = 0LL;
	ans = x / 11LL ;
	now = ans  * 11LL;
	x = x%11LL;
	ans*=2;
	clog << ans << " " << now << endl;
	clog << x << endl;
	if (0 < x and x <= 6)
	{
		ans++;
	}
	else if (x>6)
	{
		ans += 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import math

X = int(input())

#xが素数か判定する    
def isPrime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False
    
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i += 2    
    return True

for i in range(X,10**10):
    if isPrime(i):
        print(i)
        break


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n)cin >> s[i];

    sort(all(s));

    rep(i,n)cout << s[i];
    cout << endl;   
}



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

int main(){
    int h, w, i, j, flag = 0, sum = 0;
    cin >> h >> w;
    int a[h][w] = {};
    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            cin >> a[i][j];
        }
    }
    
    for(i=0; i<h; i++){
        if(i%2 == 0){
            for(j=0; j<w; j++){
                if(flag == 1) sum++;
                if(a[i][j]%2 == 1){
                    if(flag == 0){
                        flag = 1;
                    }else{
                        flag = 0;
                    }
                }
            }
        }else{
            for(j=w-1; j>=0; j--){
                if(flag == 1) sum++;
                if(a[i][j]%2 == 1){
                    if(flag == 0){
                        flag = 1;
                    }else{
                        flag = 0;
                    }
                }
            }
        }
    }
    printf("%d\n", sum);

    for(i=0; i<h; i++){
        if(i%2 == 0){
            for(j=0; j<w; j++){
                if(i==h-1 && j==w-1){
                    continue;
                }
                if(a[i][j]%2 == 1){
                    a[i][j]--;
                    if(j == w-1){
                        printf("%d %d %d %d\n", i+1, j+1, i+2, j+1);
                        a[i+1][j]++;
                    }else{
                        printf("%d %d %d %d\n", i+1, j+1, i+1, j+2);
                        a[i][j+1]++;
                    } 
                }
            }
        }else{
            for(j=w-1; j>=0; j--){
                if(i==h-1 && j==0){
                    continue;
                }
                if(a[i][j]%2 == 1){
                    a[i][j]--;
                    if(j == 0){
                        printf("%d %d %d %d\n", i+1, j+1, i+2, j+1);
                        a[i+1][j]++;
                    }else{
                        printf("%d %d %d %d\n", i+1, j+1, i+1, j);
                        a[i][j-1]++;
                    } 
                }
            }
        }
    }
 
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

bool isPrime(int n) {
  for (int i = 2; i*i < n; i++) {
    if (n%i==0) return false;
  }
  return true;
}

signed main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (char num1 = '0'; num1 <= '9'; num1++) {
    int i = 0;
    while(i<n && s[i]!=num1) i++;
    if (i>n-3) continue;
    i++;
    for (char num2 = '0'; num2 <= '9'; num2++) {
      int j = i;
      while(j<n && s[j]!=num2) j++;
      if (j>n-2) continue;
      j++;
      for (char num3 = '0'; num3 <= '9'; num3++) {
        int k = j;
        while(k<n && s[k]!=num3) k++;
        if (k<n) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b,c,d,e,x,y;
	cin >> a >> b >> c >> d >> e;
	if(a<40){
		a=40;
	}if(b<40){
		b=40;
	}if(c<40){
		c=40;
	}if(d<40){
		d=40;
	}if(e<40){
		e=40;
	}
	x=a+b+c+d+e;
	y=x/5;
	cout << y << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
    int p, l, r;
};

Node T[MAX];
int D[MAX];
int H[MAX];
int S[MAX];

/*
void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "sibling = " << S[u] << ", ";
    int deg = 0;
    if (T[u].l != NIL) deg++;
    if (T[u].r != NIL) deg++;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";

    if (T[u].p == NIL) cout << "root";
    else if (T[u].l == NIL) cout << "leaf";
    else cout << "internal node";
    cout << endl;
}
*/

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].p);
    printf("sibling = %d, ", S[u]);
    int deg = 0;
    if (T[u].l != NIL) deg++;
    if (T[u].r != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if (T[u].p == NIL) {
        printf("root\n");
    } else if (T[u].l == NIL && T[u].r == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int setHeight(int u) {
    int h1 = 0;
    int h2 = 0;
    if (T[u].r != NIL) {
        h1 = setHeight(T[u].r) + 1;
    }

    if (T[u].l != NIL) {
        h2 = setHeight(T[u].l) + 1;
    }

    H[u] = max(h1, h2);
    return H[u];
}

void setSibling(int u) {
    if (T[u].p == NIL) {
        S[u] = NIL;
    } else {
        Node p = T[T[u].p];
        if (u == p.l) {
            S[u] = p.r;
        } else {
            S[u] = p.l;
        }
    }

}

void setDepth(int u, int d){
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r,d+1);
}

int main() {
    int n;
    cin >> n;
    for (int i=0; i < n; i ++) {
        T[i].p = T[i].l = T[i].r = NIL;
    }

    for (int i=0; i < n; i++) {
        int id_;
        cin >> id_;
        int left, right;
        cin >> left >> right;
        if (left != NIL) {
            T[id_].l = left;
            T[left].p = id_;
        }

        if (right != NIL) {
            T[id_].r = right;
            T[right].p = id_;
        }
    }

    int root = 0;
    // 高さの設定をする
    for (int i=0; i < n; i++) {
        if (T[i].p == NIL) {
            root = i;
        }
    }

    setHeight(root);
    setDepth(root, 0);
    // 兄弟ノードの設定をする
    for (int i=0; i < n; i++) {
        setSibling(i);
    }

    for (int i=0; i < n; i++) {
        print(i);
    }

    return 0;
}


Measured memory_bytes: 3220
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
class UnionFind {
	mutable std::vector<int> parent;
public:
	UnionFind(const int _size) : parent(_size, -1) {};
	int find_root(const int a) const {
		return (parent[a] < 0) ? a : parent[a] = find_root(parent[a]);
	}
	bool is_same(const int a, const int b) const {
		return find_root(a) == find_root(b);
	}
	void merge(int a, int b) {
		a = find_root(a);
		b = find_root(b);
		if (a == b) return;
		if (parent[a] > parent[b]) std::swap(a, b);
		parent[a] += parent[b];
		parent[b] = a;
	}
	int size_of(const int a) const { return -parent[find_root(a)]; }
};

int main() {
	int n, q; std::cin >> n >> q;
	UnionFind uft(n);
	for (auto i = 0; i < q; ++i) {
		int t, u, v; std::cin >> t >> u >> v;
		if (t == 0) {
			uft.merge(u, v);
		}
		else if (t == 1) {
			if (uft.is_same(u, v)) {
				std::cout << "1\n";
			}
			else {
				std::cout << "0\n";
			}
		}
		else {
			throw 0;
		}
	}
}


Measured memory_bytes: 3964
#include <iostream>
#include <stack>
#include <cstring>
using namespace std;

int n, m, cnt;
int pos[20], tmpPos[20];

void copyPos(int *fromPos, int *toPos){
  for(int i = 0; i < 20; i++){
    toPos[i] = fromPos[i];
  }
}

void move(int x, int to){
  if(pos[x] == to){
    return;
  }

  int ops = -to + 2;

  if(pos[x] == ops){
    for(int i = x + 1; i < n; i++){
      move(i, to);
      if(cnt > m) return;
    }

    cnt++;
    if(cnt > m) return;
    pos[x] = 1;
  }

  if(pos[x] == 1){
    for(int i = x + 1; i < n; i++){
      move(i, ops);
      if(cnt > m) return;
    }

    cnt++;
    if(cnt > m) return;
    pos[x] = to;
  }
}

void solve(){
  int res = m + 1;

  copyPos(pos, tmpPos);
  cnt = 0;

  for(int i = 0; i < n; i++){
    move(i, 0);
    if(cnt > m) break;
  }

  res = min(res, cnt);
  copyPos(tmpPos, pos);
  cnt = 0;

  for(int i = 0; i < n; i++){
    move(i, 2);
    if(cnt > m) break;
  }

  res = min(res, cnt);

  cout << (res == m + 1 ? -1 : res) << endl;
}

int main(){
  while(cin >> n >> m, n || m){
    for(int i = 0; i < 3; i++){
      int a;
      cin >> a;

      for(int j = 0; j < a; j++){
        int x;
        cin >> x;
        x--;
        pos[x] = i;
      }
    }

    solve();
  }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int maxValue = 1e5 + 5 , mod = 1e9 + 7;

int main(){
    int h , w;
    cin>>h>>w;
    string s[h];
    int paths[h][w];
    bool visited[h][w];
    for(int i = 0; i < h; i++){
        cin>>s[i];
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            paths[i][j] = 0;
            visited[i][j] = false;
        }
    }
    queue<pair<int , int> >q;
    q.push({0 , 0});
    paths[0][0] = 1;
    
    while(q.size()){
        pair<int , int>temp = q.front();
        q.pop();
        int tempH = temp.first , tempW = temp.second;
        if(tempH + 1 < h && tempW < w){
            if(s[tempH + 1][tempW] == '.'){
                paths[tempH + 1][tempW] = (paths[tempH + 1][tempW] + paths[tempH][tempW])%mod;
                if(!visited[tempH + 1][tempW]){
                    q.push({tempH + 1 , tempW});
                    visited[tempH + 1][tempW] = 1;
                }
            }
        }
        if(tempW + 1 < w && tempH < h){
            if(s[tempH][tempW + 1] == '.'){
                paths[tempH][tempW + 1] = (paths[tempH][tempW + 1] + paths[tempH][tempW])%mod;
                if(!visited[tempH][tempW + 1]){
                    q.push({tempH , tempW + 1});
                    visited[tempH][tempW + 1] = 1;
                }
            }
        }
    }
    cout<<paths[h - 1][w - 1];
}

Measured memory_bytes: 10352