akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np

N_MAX = 200000 + 5
INF = 10**9 + 7
sys.setrecursionlimit(N_MAX)
MOD = 10**9 + 7

H, W, K = map(int, sys.stdin.readline().rstrip().split())
C = []
for _ in range(H):
    C.append([0 if s == "." else 1 for s in sys.stdin.readline().rstrip()])

A = np.array(C)
# print(A, A.sum())

ans = 0
for i in range(2**H):
    for j in range(2**W):
        A = np.array(C)

        for row in range(H):
            if (i >> row) & 1 == 1:
                A[row, :] = 0

        for col in range(W):
            if (j >> col) & 1 == 1:
                A[:, col] = 0

        # print(i,j)
        # print(A, A.sum())

        if A.sum() == K:
            ans += 1

print(ans)


Measured memory_bytes: 27268
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    static Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws Exception {


            int a = sc.nextInt();

            out.println(a + (a * a) + (a * a * a));


        out.flush();
        out.close();
        sc.close();
    }

    static final int MOD = (int) 1e9 + 7;
    static final double PI = 3.14159265358979323846;

    // takes array input
    public static int[] init(int n) {

        int[] arr = new int[n];

        for (int i = 0; i < n; ++i)
            arr[i] = sc.nextInt();

        return arr;
    }

    // finds GCD of two number
    public static int gcd(int a, int b) {

        if (a == 0) {
            return b;
        }

        return gcd(b % a, a);
    }

    // checks whether a number is prime or not
    public static boolean prime(int n) {

        if (n < 2)
            return false;

        for (int i = 2; i * i <= n; ++i)
            if (n % i == 0)
                return false;

        return true;
    }
}


Measured memory_bytes: 27156
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<math.h>

using namespace std;






int i, n, goukei,iro,k;
char bunsyou[600000];
int main() {
	cin >> n;
	cin >> k;
	for (i = 0; i < n; i++) {
		cin >>bunsyou[i];		
	}
	iro = 0;
	goukei = 0;
	for (i = 0; i < n-1; i++) {
		if (bunsyou[i] == bunsyou[i+1]) {
			goukei++;
		}
		if (bunsyou[i] != bunsyou[i + 1] || i == n - 1) {
			iro++;
			
			if (iro % 2 == 1&&iro<=k*2) {
				
				
				goukei = goukei + 2;
				if (i == n - 1&& bunsyou[i] == bunsyou[i + 1]) {
					goukei--;
				}
			}
		}
		
	}
	if (goukei > n - 1) {
		goukei = n - 1;
	}
	
	printf("%d\n",goukei);

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    int m = (n & 1 ? 2 : 1);
    auto dp = defvec<ll>(-LLINF, n + 1, m + 1);
    FOR(i, 0, m + 1)dp[i + 1][i] = a[i];
    FOR(i, 1, n)eFOR(j, 0, m) {
        chmax(dp[i + 1][j], dp[i - 1][j] + a[i]);
        if (j < m)chmax(dp[i + 1][j + 1], dp[i][j]);
    }

    cout << dp[n][m] << "\n";
}

Measured memory_bytes: 15832
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
//#include <chrono>
//#include <set>
//#include <map>
//#include <deque>
//#include <cmath>
//#include <queue>
//#include <cassert>
//#include <random>
//#include <bitset>
//#include <iomanip>
//#include <numeric>
//#include <time.h>
//#include <ctime>
//#include <string>
//#include <cstdio>
//#include <vector>
//#include <cstdlib>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>
//#include <unordered_set>
//#include <fstream>
//#include <stack>
//#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.14159265358979;
//----------------------------------------------------
#define endl '\n';
//----------------------------------------------------
int n, s;
vector<vector<ll>> dp;
vector<ll> a;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> s;
    a.resize(n);
    forn(i, n) cin >> a[i];
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    dp.resize(n+1, vector<ll>(s+1, 0));
    dp[0][0] = 1;
    forn(i, n){
        forn(j, s+1){
            dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % mod2;
            if(a[i] + j <= s) dp[i+1][a[i]+j] = (dp[i+1][a[i]+j] + dp[i][j]) % mod2;
        }
    }

    cout << dp[n][s] << endl;
}


Measured memory_bytes: 73648
// AOJ
// ALDS1_2_A Bibble Sort

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N, i, j, v, w, k;
	cin >> N;
	int A[N];
	for (i=0; i<N; i++) {
		cin >> A[i];
	}

	bool flag = 1;
	int cnt = 0;
	for (i=0; flag; i++) { 
		flag = 0;
		for (j=N-1; j>=i+1; j--) {
			if (A[j] < A[j-1]) {
				swap(A[j],A[j-1]);
				cnt++;
				flag = 1;
			}
		}
	}
	for (i=0; i<N; i++) {
		cout << A[i];
		if (i!=N-1) {
			cout << " ";
		}
	}
	cout << endl;
	cout << cnt << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <cstring>

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

using namespace std;
typedef long long ll;


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


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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

#define endl '\n'
int x[2][201];
int main() {
  fast_io;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[0][i];
    x[0][i] += x[0][i - 1];
  }
  for (int i = 1; i <= n; i++) {
    cin >> x[1][i];
    x[1][i] += max(x[0][i], x[1][i - 1]);
  }
  cout << x[1][n] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

constexpr int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> m(26);
  char c;
  while (cin >> c) ++m[c - 'a'];
  cout << accumulate(begin(m), end(m), 1LL,
                     [](auto a, int x) { return a * (x + 1) % MOD; }) -
              1
       << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if((a%3==0)||(b%3==0)||((a+b)%3==0)){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
}

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

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

int main()
{
    int a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2<<endl;
    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INT long long
#define MOD 1000000007
using namespace std;
INT n, a[100010], b[100010], c[100010], d[100010];
int main(void)
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i], b[i]=a[i];
    for(int i = 1 ; i < n ; i++ ) b[i] -=  b[i-1];
    c[0] = b[n-1];
    a[0] -= c[0]/2;
    a[n-1] -= c[0]/2;
    cout<<c[0]<<" ";
    for(int i = 0 ; i < n-1 ; i++ ) a[i] -= a[i-1], cout<<a[i]*2<<" ";
    return 0;
}


Measured memory_bytes: 2944
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main 
{
	static long MOD = 1000000007;
	static long[] inv = new long[200001];
	static long[] fact = new long[200001];
	static long[] factinv = new long[200001];
	
	static long nCk(int n, int k)
	{
		return (((fact[n]*factinv[n-k])%MOD)*factinv[k])%MOD;
	}
	
	static long binpow(long a, long b, long m)
	{
		a = a%m;
		long res = 1;
		while(b>0)
		{
			if((b & 1) != 0)
				res = (res*a)%m;
			a = (a*a)%m;
			b >>= 1;
		}
		res=res%MOD;while(res<0)res+=MOD;
		return res;
	}
	
	static long ainb(int a, int b)
	{
//		System.out.println(a + " in " + b);
		long sum = 0;
		if(a <= b)
			for(int i = 1; i <= a; i++)
			{
//				System.out.println("from " + nCk(b,i) + " " + nCk(a-1,i-1));
				sum = (sum + (nCk(b,i)*nCk(a-1,i-1))%MOD)%MOD;
			}
		else if(a>b)
		{
			for(int k = 0; k < b; k++)
			{
				sum = (sum + nCk(a, k))%MOD;
			}
		}
		return sum;
	}

	public static void main(String[] args) 
	{
		//calculate inverse using binary exponentiation
		fact[0] = 1;
		factinv[0] = 1;
		for(int i = 1; i <= 200000; i++)
		{
			inv[i] = (binpow(i,MOD-2,MOD));
			fact[i] = (fact[i-1] * i)%MOD;
			factinv[i] = (inv[i] * factinv[i-1])%MOD;
		}
		
		
		long tes = 1;
		for(int i = 0; i < 3; i++)
		{
			tes = (tes*2)%MOD;
		}
//		System.out.println("test " + tes);
//		System.out.println("test2 " + (ainb(5,2)));
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long q = 0;
		
		int free = Math.min(n, k); //max zeroes
		int rest = n - free;
		q = (ainb(n,n))%MOD;
//		System.out.println("starts with " + q);
		
		for(int i = free+1; i < n; i++)
		{
//			System.out.println("Can't have " + i + " zeroes");
			int nonzero = n-i;
//			System.out.println("Deduct those with " + nonzero + " terms");
//			long cur = ainb(n,nonzero);
			long cur = nCk(n-1,nonzero-1);
//			System.out.println("of which there are " + cur + " unshuffled");
			cur = (cur * nCk(n,nonzero))%MOD;
//			System.out.println("Shuffle times " + (i+1) + " becomes " + cur);
			
			q = (q-cur)%MOD;
			while(q<0)q+=MOD;
		}
		System.out.println(q);
	}

}


Measured memory_bytes: 28116
N = int(input())
a_word = input()
words = [a_word]
judge = 'Yes'
for i in range(N-1):
  b_word = input()
  if not a_word[-1] == b_word[0]:
    judge = 'No'   
  elif b_word in words:
    judge = 'No'
  words.append(b_word)
  a_word = b_word

print(judge)

Measured memory_bytes: 9000
package main

import "fmt"

func main() {
	var r, c int
	fmt.Scan(&r, &c)

	a := make([]int, c)
	for i := 0; i < r; i++ {
		s := 0
		var x int
		for j := 0; j < c; j++ {
			fmt.Scan(&x)
			s += x
			a[j] += x
			fmt.Printf("%d ", x)
		}
		fmt.Printf("%d\n", s)
	}
	s := 0
	for _, e := range a {
		s += e
		fmt.Printf("%d ", e)
	}
	fmt.Printf("%d\n", s)
}



Measured memory_bytes: 1784
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a,b,i;
    int n;
    cin>>a>>b;
    int cb=b,cifb=0;
    while (cb!=0)
    {
        cifb++;
        cb/=10;
    }
    for (i=1;i<=cifb;i++)
    {
        a*=10;
    }
    a+=b;
    n=sqrt(a);
    if (n*n==a)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main(){
	cin>>a>>b;
	if(a==1||b==1){
		cout<<1;
		return 0;
	}
	long long ans=(a*b+1ll)/2;
	cout<<max(ans,1ll);
	return 0;
}

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


int main() {
 int N;
  cin >> N;
  int D=1;
  vector<int> vec(10);
  int i=0;
  int warukazu=0;
  while ((N/D)>0){
    vec.at(i)= (N/D) - 10*(N/(D*10));
      i++;
    D = D*10;
  }
  for (int j=0; j<i; j++){
    warukazu = warukazu + vec.at(j);
  }
  if( N%warukazu ==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict, deque
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n=r()
a=rl()
all=a[0]^a[1]
for i in range(2,n):
    all^=a[i]
b=[]
for j in range(n):
    b.append(all^a[j])
print(*b)

Measured memory_bytes: 111272
n=int(input())
ki=[[] for _ in range(n)]
hen=[tuple(map(int,input().split())) for i in range(n-1)]
color={(hen[i][0]-1,hen[i][1]-1):0 for i in range(n-1)}
for i in range(n-1):
  a,b=hen[i][0],hen[i][1]
  ki[a-1].append(b-1)
  ki[b-1].append(a-1)
mcol=0
ne=0
for i in range(n):
  if len(ki[i])>mcol:
    mcol=len(ki[i])
    ne=i
print(mcol)
from collections import deque
d=deque()
d.append(ne)
visited=[False]*n
visited[ne]=True
col=[0]*n
while d:
  g=d.popleft()
  for i in ki[g]:
    if visited[i]:
      continue
    d.append(i)
    visited[i]=True
    if g>i:
      x,y=i,g
    else:
      x,y=g,i
    color[(x,y)]=col[g]%mcol+1
    col[g],col[i]=color[(x,y)],color[(x,y)]
for i in hen:
  print(color[(i[0]-1,i[1]-1)])

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    int ans = 0;
    rep(i, n-1) {
        if (s[i] != s[i+1]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
   ll n; cin >> n;
   vector<int> a(n);rep(i, n) cin >> a.at(i);

   ll q; cin >> q;
   vector<ll> b(q), c(q);
   rep(i, q) cin >> b.at(i) >> c.at(i);

   map<ll, ll> mp;
   rep(i, n){
      mp[a.at(i)]++;
   }

   ll cnt = 0;
   for(auto x: mp){
      cnt += x.first * x.second;
   }  

   rep(i, q){
      ll tmp = mp[b.at(i)];
      if(tmp==0) {
         cout << cnt << endl;
         continue;
      }
      mp[b.at(i)] = 0;
      mp[c.at(i)] += tmp;

      cnt -= tmp*b.at(i);
      cnt += c.at(i) * tmp;
      cout << cnt << endl;
   }

   return 0;
}


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

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

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    int size = (int) s.size();
    if (size % 2 == 1) {
      ans++;
    }
  }

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

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	int ans =0;
	rep(i, sz(s) -1){
		ans += s[i] != s[i+1];
	}
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a<b){
    if(a<c){
      if(b<c){
	cout << c-a << "\n";
      }
      else{
	cout << b-a << "\n";
      }
    }
    else{
      cout << b-c << "\n";
    }
  }
  else{
    if(a<c){
      cout << c-b << "\n";
    }
    else{
      if(b<c){
	cout << a-b << "\n";
      }
      else{
	cout << a-c << "\n";
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement as comb_rplc
n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
for i in range(q):
	a[i],b[i],c[i],d[i]=map(int,input().split())
ans=0

for A in comb_rplc(range(1,m+1),n):
	sum=0
	for i in range(q):
		if A[b[i]-1]-A[a[i]-1]==c[i]:
			sum=sum+d[i]
	if sum>=ans:
		ans=sum

print(ans)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
 
void solve()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    int n = s.size();
    for (int i = 0; i < n;i++){
        if(s[i]!=t[i])
            ans++;
    }
    cout << ans << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3800
N = input()
s = int(N) % 10
if s == 3:
    print('bon')
if s == 0:
    print('pon')
if s == 1:
    print('pon')
if s == 6:
    print('pon')
if s == 8:
    print('pon')
 
if s == 2:
    print('hon')
if s == 4:
    print('hon')
if s == 5:
    print('hon')
if s == 7:
    print('hon')
if s == 9:
    print('hon')

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

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

	ll n,k;
	long double mx,sum=0;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		if(i<k)
			sum+=a[i];
	}	
	mx=sum;
	for(ll i=k;i<n;i++)
	{
		sum=sum+a[i]-a[i-k];
		mx=max(mx,sum);
	}
	mx+=k;
	mx=mx/2.0;
	cout<<fixed<<setprecision(10)<<mx<<endl;

	
	
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<long long> a(N);
	for(int i=0;i<N;i++)cin>>a[i];
	
	sort(a.begin(),a.end());
	
	int K = a[a.size()-1];
	int K2 = a[0];
	map<int,int> mp;
	if(K%2==0){
		for(int i=1;i<N;i++){
			mp[a[i]]++;
		}
	}
	else{
		K--;
		for(int i=2;i<N;i++){
			mp[a[i]]++;
		}
	}
	
	if(mp[K2]!=0){
		cout<<"Impossible"<<endl;
		return 0;
	}
	
	for(int i=K2+1;i<=K;i++){
		if(mp[i]<=1){
			cout<<"Impossible"<<endl;
			return 0;
		}
	}
	
	cout<<"Possible"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <algorithm>

using namespace std;

//edmonds_carpツづ個ヘツδ仰パツー
//Verified PKU 1459
bool find_augment_path(const vector<vector<int> > &capacity, const vector<vector<int> > &flow, vector<int> &augment_path, int S, int G) {
    int N = (int)capacity.size();
    queue<int> q;
    vector<int> prev(N, -1);
    q.push(S);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        if(u == G) {
            int pos = 0;
            int v = G;
            while(v != -1) {
                augment_path[pos++] = v;
                v = prev[v];
            }
            reverse(augment_path.begin(), augment_path.begin()+pos);
            return true;
        }
        //Sourceツづ鳴づ債行ツつゥツづ按つ「ツづヲツつ、ツづ可つキツづゥ
        for(int i = 0; i < N; ++i) {
            if(i == S) continue;
            if(prev[i] != -1) continue;
            if(capacity[u][i] - flow[u][i] > 0) {
                prev[i] = u;
                q.push(i);
            }
        }
    }
    return false;
}

//Verified PKU 1459
//ツノツーツド[S]ツつェSource, [G]ツつェTerminal
void edmonds_carp(const vector<vector<int> > &capacity, vector<vector<int> > &flow, int S, int G) {
    int N = (int)capacity.size();
    vector<int> augment_path(N, -1);
    while(find_augment_path(capacity, flow, augment_path, S, G)) {
        int aug = INT_MAX;
        for(int i = 0; augment_path[i] != G; ++i)
            aug = min(aug, capacity[augment_path[i]][augment_path[i+1]] - flow[augment_path[i]][augment_path[i+1]]);
        for(int i = 0; augment_path[i] != G; ++i) {
            int u = augment_path[i], v = augment_path[i+1];
            flow[u][v] += aug;
            flow[v][u] = -flow[u][v];
        }
    }
}

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

    vector<vector<int> > capacity(N+1, vector<int>(N+1, 0)), capacity_idx(N+1, vector<int>(N+1, 0));
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        capacity[a][b] = capacity[b][a] = 1;
        capacity_idx[a][b] = i+1;
    }

    int S, G;
    cin >> S >> G;
    vector<vector<int> > flow(N+1, vector<int>(N+1, 0));
    edmonds_carp(capacity, flow, S, G);

    int cap = 0;
    for(int i = 1; i <= N; ++i) {
        if(flow[i][G] != 0) cap += flow[i][G];
    }

    vector<int> changes;
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j <= N; ++j) {
            if(flow[i][j] > 0) {
                if(!capacity_idx[i][j]) changes.push_back(capacity_idx[j][i]);
            }
        }
    }

    cout << cap << endl;
    cout << changes.size() << endl;
    for(int i = 0; i < changes.size(); ++i) {
        cout << changes[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long

int main(){
    int N;
    cin >> N;
    vector<int> X(N);
    int maxp = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
        maxp = max(maxp, X[i]);
    }
    ll ans = 900000000;
    ll sum = 0;
    for (int i = 1; i <= maxp; i++)
    {
        for (int j = 0; j < N; j++)
        {
            sum += pow(abs(X[j]- i),2);
        }
        ans = min(ans, sum);
        sum = 0;
    }
    cout << ans << endl;
}

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

int cnt[200010];

int main ()
{
 int n,k;	cin >> n >> k;
  
  for (int i=0; i<n; i++) {
    int a;	cin >> a;
    cnt[a-1]++;
  }
  sort (cnt, cnt+n);

  int ans=0;
  for (int i=0; i<n-k; i++)  ans += cnt[i];
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[1001];
    bool flag=1;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    for(int i=1;i<=n;i++)
    {
    	if(a[i]%2==1)continue;
    	else if(a[i]%3!=0&&a[i]%5!=0)flag=0;
	}
	if(flag)cout<<"APPROVED";
	else cout<<"DENIED";
    return 0;
} 

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=200020,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31)*mod;}
int n,cnt[66][66];
ll ans;
int main(){
	n=read();
	FOR(i,1,n){
		double xx;
		scanf("%lf",&xx);
		ll x=ll(0.5+xx*1e9);
		int cnt2=0,cnt5=0;
		while(x%2==0) x/=2,cnt2++;
		while(x%5==0) x/=5,cnt5++;
		cnt[cnt2][cnt5]++;
	}
	FOR(i,9,60) FOR(j,9,60) ans+=1ll*cnt[i][j]*(cnt[i][j]-1)/2;
	FOR(i,0,60) FOR(j,0,60) FOR(k,i,60) FOR(l,i==k?j+1:0,60) if(i+k>=18 && j+l>=18) ans+=1ll*cnt[i][j]*cnt[k][l];
	printf("%lld\n",ans);
}

Measured memory_bytes: 3760
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import itertools

x, k, d = list(map(int, input().split(" ")))

res = 0
saiteki_kaisu = min(abs((x // d)), k)
saigoni_hituyo = (k - saiteki_kaisu) % 2
if x > 0:
    res = x - (saiteki_kaisu * d)
else:
    res = x + (saiteki_kaisu * d)

if res > 0:
    res -= saigoni_hituyo * d
else:
    res += saigoni_hituyo * d

print(abs(res))


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

using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		int student[501] = {0};
		vector<int> student2[501];
		int a, b;
		int count = 0;

		for (int i = 0; i < m; i++) {
			cin >> a >> b;
			if (a == 1) {
				student[b] = 1;
			} else {
				student2[a].push_back(b);
				student2[b].push_back(a);
			}
		}
		
		for (int i = 2; i <= n; i++) {
			if (student[i] == 1) {
				for (int j = 0; j < student2[i].size(); j++) {
					if (student[student2[i][j]] != 1) {
						student[student2[i][j]] = 2;
					}
				}
			}
		}

		for (int i = 2; i <= n; i++) {
			if (student[i] == 1 || student[i] == 2) {
				count++;
			}
		}
		/*
		for (int i = 0; i <= n; i++) {
			cout << student[i] << " ";
		}
		cout << endl;

		for (int i = 0; i <= n; i++) {
			cout << student2[i] << " ";
		}
		cout << endl;
		*/
		cout << count << endl;
	}
	return 0;
}

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

class Program
{
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Array.Sort(l);
    int sum = 0;
    for (int i = 0; i < n-1; i ++) {
      sum += l[i];
    }
    if (l[n-1] >= sum) Console.WriteLine("No");
    else Console.WriteLine("Yes");
  }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    int c0=0,c2=0,c4=0; 
    for(int i=0;i<n;i++)
    {
        int x=nxt();
        if(x%4==0)
            c4++;
        else if(x%2==0)
            c2++;
        else
            c0++;
    }
    if(c2==0&&c4<c0-1||c2!=0&&c4<c0)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    s=input().strip()
    n=len(s)-1
    NUM_CASE= 2**n
    sum=0
    for case in range(0,NUM_CASE):
        left=0
        for index in range(n):
            if (case>>index) & 1 == 1:
                sum+=int(s[left:index+1])
                left=index+1
            else:               # if (case>>index) & 1 ==0:
                continue
        index=n
        sum+=int(s[left:index+1])
    print(sum)  
    return

if __name__ == '__main__':
    main()


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


int food[31];
int main()
{
    int N, M;
    cin >> N >> M;

    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int a;
            cin >> a;
            food[a] += 1;
        }
    }

    int cnt = 0;
    for (int i = 1; i <= M; i++) {
        if (food[i] == N) {
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
sum = 1

for i in 1..n do
 if(a[i-1] == 0)
  sum = 0
 end
end

a.each{|num|
  sum *= num
  if(sum > 10 ** 18)
    sum = -1
    break
  end
}
if(sum > 10 ** 18)
  sum = -1
end

puts sum


Measured memory_bytes: 23416
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <map>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for (int i = 0; i < (int)n; ++i)
#define loop1(i, n) for (int i = 1; i <= (int)n; ++i)
#define pb push_back
#define pi pair<int, int>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ti tuple<int, int, int, int>
#define mkt make_tuple
#define mkp make_pair
#define cerr if (1) cerr

void solve() {
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k)
        cout << s;
    else
        cout << s.substr(0, k) << "...";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int64_t sum = 0;
  queue<int64_t> q;
  int64_t max_sum = 0;
  for (int i = 0; i < N; i++) {
    int64_t P;
    cin >> P;

    sum += (P + 1);
    q.push(P);
    if ((int)q.size() == K) {
      max_sum = max(max_sum, sum);
      sum -= (q.front() + 1);
      q.pop();
    }
  }

  printf("%.10lf\n", (double)max_sum * 0.5);
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 xx, nn, tmp, ans, memo;
	cin >> xx >> nn;
	if(nn == 0)
	{
		cout << xx;
		return 0;
	}
	vector<int64> pp;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> tmp;
		pp.push_back(tmp);
	}
	sort(pp.begin(),pp.end());
	vector<int64>::iterator ite = pp.begin();
	for(int64 ii = 0;ii <= 101;ii++)
	{
		if(ii == *ite)
		{
			ite++;
			continue;
		}
		if(ii == xx)
		{
			cout << ii << endl;
			return 0;
		}
		if(ii < xx)
		{
			memo = ii;
		}
		if(ii > xx)
		{
			if(xx-memo <= ii-xx)
			{
				cout << memo << endl;
				return 0;
			}
			else
			{
				cout << ii << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3596
D = int(1e9 + 7)
N = int(input())
M = [int(i) for i in input().split()]

R = sum(M[1:])

sum_ = 0
for i, x in enumerate(M[:-1]):
    sum_ += R * x
    sum_ %= D
    R -= M[i+1]

print(sum_)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 105;
int F[N][10], P[N][10];
int n, ans;
int cnt[N];

int main() {
    ans = INT_MIN;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> F[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 10; ++j) {
            cin >> P[i][j];
        }
    }
    for (int mask = 1; mask < (1 << 10); ++mask) {
        memset(cnt, 0, sizeof cnt);
        for (int j = 0; j < 10; ++j) {
            if (mask & (1 << j)) {
                for (int i = 0; i < n; ++i) {
                    if (F[i][j]) {
                        ++cnt[i];
                    }
                }
            }
        }
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += P[i][cnt[i]];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    int dp[N+1];
    for(int i = 0; i <= N; i++){
        dp[i] = i;
    }
    for(int i = 0; i <= N; i++){
        dp[i+1] = min(dp[i]+1, dp[i+1]);

        // 6
        int add;
        add = 6;
        while(i + add <= N){
            dp[i+add] = min(dp[i]+1, dp[i+add]);
            add *= 6;
        }
        add = 9;
        while(i + add <= N){
            dp[i+add] = min(dp[i]+1, dp[i+add]);
            add *= 9;
        }
    }
    cout << dp[N] << endl;
} 


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    map<int, pair<int, int>> pos;
    map<int, bool> exsist;
    vector<vector<bool>> is_selected(3, vector<bool>(3, false));

    rep(i, 3) rep(j, 3) {
        int a; cin >> a;
        pos[a] = make_pair(i, j);
        exsist[a] = true;
    }

    int n; cin >> n;
    rep(i, n) {
        int b; cin >> b;
        if(!exsist[b]) continue;

        int h = pos[b].first;
        int w = pos[b].second;
        is_selected[h][w] = true;
    }

    bool bingo = false;
    rep(h, 3) {
        bool all_checked = true;
        rep(w, 3) if(!is_selected[h][w]) all_checked = false;
        if(all_checked) bingo = true;
    }

    rep(w, 3) {
        bool all_checked = true;
        rep(h, 3) if(!is_selected[h][w]) all_checked = false;
        if(all_checked) bingo = true; 
    }

    {
        bool all_checked = true;
        rep(i, 3) if(!is_selected[i][i]) all_checked = false;
        if(all_checked) bingo = true;
    }

    {
        bool all_checked = true;
        rep(i, 3) if(!is_selected[i][2-i]) all_checked = false;
        if(all_checked) bingo = true;
    }

    if(bingo) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]
    B = [list(map(int, readline().split())) for _ in range(H)]

    G = [[0] * W for _ in range(H)]
    M = 0
    for i in range(H):
        for j in range(W):
            G[i][j] = abs(A[i][j] - B[i][j])
            if M < G[i][j]:
                M = G[i][j]

    dp = [[set() for j in range(W + 1)] for i in range(H + 1)]
    dp[0][1].add(0)
    dp[1][0].add(0)

    for i in range(H):
        for j in range(W):
            b = G[i][j]
            for k in dp[i + 1][j]:
                dp[i + 1][j + 1].add(k + b)
                dp[i + 1][j + 1].add(abs(k - b))
            for k in dp[i][j + 1]:
                dp[i + 1][j + 1].add(k + b)
                dp[i + 1][j + 1].add(abs(k - b))

    print(min(dp[H][W]))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 545984
# coding: utf-8
import queue
while 1:
    n=int(input())
    if n==0:
        break
    dic={}
    for i in range(n):
        k,s=input().split()
        dic[k]=s
    s=input()
    ans=input()
    q=queue.Queue()
    q.put((s,0))
    find=False
    while not q.empty():
        s=q.get()
        if s[0]==ans:
            print(s[1])
            q=queue.Queue()
            find=True
        if not find:
            for k in dic.keys():
                t=s[0].replace(k,dic[k])
                if len(t)<=len(ans) and s[0]!=t:
                    q.put((t,s[1]+1))
    if not find:
        print(-1)
                


Measured memory_bytes: 7368
#include<bits/stdc++.h>
int n;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++)
			printf("%d ",__builtin_ctz(i^j)+1);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 512
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut scan = Scanner::new(cin);
    let n: i64 = scan.read();
    let k: i64 = scan.read();
    println!("{}", if k*2-1<=n {"YES"} else {"NO"});
}

// region template
struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read_opt<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_opt().unwrap()
    }
}
// endregion


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string s;
    cin >> s;
    map<char, string> mp = {
        {'2', "hon"}, 
        {'4', "hon"},
        {'5', "hon"},
        {'7', "hon"},
        {'9', "hon"},
        {'0', "pon"},
        {'1', "pon"},
        {'6', "pon"},
        {'8', "pon"},
        {'3', "bon"}
    };
    cout << mp[s[s.size()-1]];
    return 0;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),K=in();
	string S=in<string>();
	int state=-1;
	ll A=0;
	REP(i,N){
		if(state==-1){
			if(S[i]=='R') state=0;
			else state=1;
		}
		else if(state==0){
			if(S[i]=='R') A++;
			else state=1;
		}
		else if(state==1){
			if(S[i]=='L') A++;
			else state=0;
		}
	}
	out(min(N-1,A+2*K));
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long a,b,k;
void solve()
{
    long long i,x=min((b-a+1)/2,k);
    set < long long > num;
    for (i=0;i<x;i++)
        num.insert(a+i);
    if (x!=k) num.insert(b-x);
    for (i=0;i<x;i++)
        num.insert(b+1-x+i);
    for (set < long long >::iterator iter=num.begin();iter!=num.end();iter++)
        cout<<*iter<<endl;
}
int main()
{
    while(cin>>a>>b>>k)
        solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//h, w, dir, P, Q
typedef struct _State{
    int h, w, dir;
    vector<int> pq;
}State;
 
int N, M, A;
int Sh, Sw, Gh, Gw;
vector<string> field;
 
//south is 0
int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};
 
int table[2][4] = {{2, 3, 0, 1}, {3, 2, 1, 0}};
 
int dist[110][110][4][11][11];
 
int bfs(){
    queue<State> que;
    //map<State, int> dist;
    memset(dist, -1, sizeof(dist));
    State s = State({Sh, Sw, 0, {A, A}});
    que.push(s);
    dist[s.h][s.w][s.dir][s.pq[0]][s.pq[1]] = 0;
     
    while(!que.empty()){
        State u = que.front(); que.pop();
        for(int nh=u.h+dh[u.dir], nw=u.w+dw[u.dir]; 0<=nh&&nh<N && 0<=nw&&nw<M && field[nh][nw]!='#'; nh+=dh[u.dir], nw+=dw[u.dir]){
         	if(nh == Sh && nw == Sw && u.dir == 1) break;
            
            for(int i=-1; i<2; i++){
                if(nh == Sh && nw == Sw && i>=0) break;
                    State v({nh, nw, u.dir, u.pq});
                if(i >= 0){
                    if(u.pq[i] == 0) continue;
                    v.pq[i]--;
                    v.dir = table[i][u.dir];
                }
                 
                if(dist[v.h][v.w][v.dir][v.pq[0]][v.pq[1]] < 0){
                    dist[v.h][v.w][v.dir][v.pq[0]][v.pq[1]] = dist[u.h][u.w][u.dir][u.pq[0]][u.pq[1]];
                    if(i >= 0)
                        dist[v.h][v.w][v.dir][v.pq[0]][v.pq[1]]++;
                    if(v.h == Gh && v.w == Gw)
                        return dist[v.h][v.w][v.dir][v.pq[0]][v.pq[1]];
                     
                    //cout << v.h << " " << v.w << " " << dist[v.h][v.w][v.dir][v.pq[0]][v.pq[1]] << endl;
                    que.push(v);
                }
            }
        }
    }
    return -1;
}
 
int main(){
    cin >> N >> M >> A;
    field.resize(N);
    for(auto &s: field) cin >> s;
     
    for(int i=0; i<N; i++) for(int j=0; j<M; j++){
        if(field[i][j] == 'S')
            Sh = i, Sw = j;
        if(field[i][j] == 'G')
            Gh = i, Gw = j;
    }
     
    cout << bfs() << endl;
     
    return 0;
}

Measured memory_bytes: 27672