akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B == C)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    ll arr[n];
    for(i = 0; i < n; i++){
        cin >> arr[i];
    }
    sort(arr,arr+n);
    for(i = 1; i < n; i++){
        if(arr[i] == arr[i-1]){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    rep(i, 5){
        int n;
        cin >> n;
        if(n==0){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void){
  int m,f,r;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1&&f==-1&&r==-1)return(0);
    if(m==-1||f==-1)printf("F\n");
    else if(m+f>=80)printf("A\n");
    else if(65<=m+f&&m+f<80)printf("B\n");
    else if(50<=m+f&&m+f<65)printf("C\n");
    else if(30<=m+f&&m+f<50){
      if(r>=50)printf("C\n");
      else printf("D\n");
    }
    else printf("F\n");
  }
  return(0);
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
int n,m;
double a,b,ans;
int main(){
	cin>>n>>m;
	a=1900*m+100*(n-m);b=1.0-1.0/(1<<m);
	for(double c=1.0;c>1e-9;ans+=c*a,c=c*b);
	cout<<(int)(ans+0.5)<<endl;
	return 0;
}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
#define ses   "\n"
#define whp   " "
#define mxi 200003
#define mp make_pair
#define PII pair<long long, long long>
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a));
#define PI acos(-1)
#define what_is(x) cout<<x<<ses;
//set <int, greater <int> > ::iterator it;
//vector<pair<int,int> >a;
//memset(arr,0,sizeof(hg));
//priority_queue <int, vector<int>, greater<int> > pq;
///  string single character erase-
///             s.erase(s.begin()+x); where s is st ring name
///               ans x is index;
///    transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
///    transform(su.begin(), su.end(), su.begin(), ::toupper);
typedef long long v99;
typedef unsigned long long ull;
using namespace std;
v99 fx[4]= {1,-1,0,0};
v99 fy[4]= {0,0,1,-1};
v99 ox8[] = {0, 0, 1, 1, 1, -1, -1, -1};
v99 oy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
bool sort2val(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.second==b.second)return a.first<b.first;
    return a.second<b.second;
}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
/**bool prime[10000020];vector<v99>prm;
void SieveOfEratosthenes(v99 n)
{
	memset(prime, true, sizeof(prime));
	for(v99 i=4;i<=n;i+=2)prime[i]=false;
	for (v99 p=3; p*p<=n; p+=2)
	{
		if (prime[p] == true)
		{
			/// Update all multiples of p
			for (v99 i=p*p; i<=n; i += 2*p)
				prime[i] = false;
		}
	}
	rep1(i,2,n)if(prime[i])prm.push_back(i);

}*/
v99 pw(v99 a, v99 b)
{
	v99 ans = 1;
	for(v99 i = 1; i <= b; ++i)
		ans = (ans * a);
	return ans;
}

template <class T> inline T bigmod(T n,T p,T m)
{
    if(p==0)return 1;
    else if(p%2==0)
    {
        v99 val=bigmod(n,p/2,m);
        return (T)((val*val)%m);
    }
    else return (T)(((v99)n*(v99)bigmod(n,p-1,m))%m);
}
///-------------------------------------------------------------------------------------------------------



void solve()
{
    /// code is here->
    v99 n,k;cin>>n>>k;v99 a[n+1];
    rep0(i,0,n)cin>>a[i];
    for(v99 l=0,r=k;r<n;r++,l++)
    {
        if(a[l]<a[r])cout<<"Yes"<<ses;
        else cout<<"No"<<ses;
    }
}






int main()
{

    //freopen("data.out","w",stdout);
    //while(1)
    //test
    solve();

    return 0;
}



      ///  Alhamdulillah...


Measured memory_bytes: 5204
X, K, D = map(int, input().split())

X = abs(X)
if X // D >= K:
  print(X - K*D)
else:
  tmp = X
  X %= D
  K -= tmp // D
  #print(X,K)
  if K % 2 == 0:
    print(X)
  else:
    print(-(X-D))

  

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	int count = 0;
	int ans = 0;
	REPA(i, N+1){
		int d;
		cin >> d;
		if(i==d){
			++count;
		}else{
			ans += (count + 1) / 2;
			count = 0;
		}
	}
	ans += (count + 1) / 2;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define MOD 1000
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

ll a, b, c, k;

int main () {
    cin >> a >> b >> c >> k;
    if (a == b) {
        cout << 0;
    } else {
        if (k%2 == 0) cout << a-b;
        else cout << b-a;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int n,l,t,pos[100100],rk=0;

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    n=read();l=read();t=read();int i;
    for (i=1;i<=n;i++)
    {
        int now=read(),face=read();
        if (face==1)
        {
            pos[i]=(now+t)%l;
            rk+=((now+t)/l);
        }
        else if (face==2)
        {
            pos[i]=(now-t)%l;
            if (pos[i]<0) {pos[i]+=l;rk--;}
            rk+=(now-t)/l;
        }
    }
    sort(pos+1,pos+1+n);
    rk=(rk%n+n)%n;
    for (i=rk+1;i<=n;i++) printf("%d\n",pos[i]);
    for (i=1;i<=rk;i++) printf("%d\n",pos[i]);
    return 0;
}

Measured memory_bytes: 1536
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var A, B, K int
	fmt.Scan(&A, &B, &K)
	m := map[int]int{}

	for i := A; i <= min(A+K-1, B); i++ {
		m[i]++
	}
	for i := B; max(B-K+1, A) <= i; i-- {
		m[i]++
	}
	arr := []int{}
	for k := range m {
		arr = append(arr, k)
	}
	sort.Ints(arr)
	for i := 0; i < len(arr); i++ {
		fmt.Println(arr[i])
	}
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) > abs(a[j]) }


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    string s;
    deque<char> d;
    cin >> s;
    // rep(i,s.size())d.push_front(s[i]);
    for(char c:s) d.push_back(c);
    int q;
    cin >> q;
    bool r1;
    r1 = false;
    rep(i,q){
        int qq;
        cin >> qq;
        if(qq==1){
            r1 = !r1;
        }
        else{
            int f;
            char c;
            cin >>f >> c;
            if(r1)f=3-f;
            if(f==1){
                d.push_front(c);
            }else{
                d.push_back(c);
            }
        }   
    }
    if(r1)reverse(d.begin(),d.end());
    for(auto dd :d)cout << dd;
    cout << endl;
    // string ans;
    // for(char c: d)ans +=c;
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
const int maxn=100010;
int n,m;
struct Point {
	int p,y,id;
	bool operator < (const Point &t) const{
		return p<t.p?1:p==t.p&&y<t.y;
	}
}z[maxn];
bool cmp(const Point &a,const Point &b) {
	return a.id<b.id;
}
int main() {
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=m;++i)scanf("%d%d",&z[i].p,&z[i].y),z[i].id=i;
	std::sort(z+1,z+m+1);
	for(register int i=1,j,k;i<=m;i=j)for(j=i,k=1;j<=m&&z[i].p==z[j].p;++j,++k)z[j].y=k;
	std::sort(z+1,z+m+1,cmp);
	for(register int i=1;i<=m;++i)printf("%06d%06d\n",z[i].p,z[i].y);
	return 0;
}

Measured memory_bytes: 2560
h, w = map(int, input().split())
c = []
d = []
for i in range(w+2):  
  d.append(".")
c.append(d)
a = 1
for i in range(h):
  s = list(input())
  s = ["."] + s + ["."]
  c.append(s)
c.append(d)
for i in range(1,h+1):
  for j in range(1,w+1):
    if c[i][j] == "#":
      if  c[i-1][j] == "." and  c[i+1][j] == "." and c[i][j-1] == "." and c[i][j+1] == ".":
        a = 0
        break
print("Yes") if a == 1 else print("No")

Measured memory_bytes: 3064
A = []
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))

N = int(input())

B = [int(input()) for i in range(N)]

B = set(B)
bingo = False
for i in range(3):
    if all(A[i][j] in B for j in range(3)) or all(A[j][i] in B for j in range(3)):
        bingo = True

if all(A[j][j] in B for j in range(3)) or all(A[2 - j][j] in B for j in range(3)):
    bingo = True

if bingo:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int main(){
	int h,w;
	cin>>h>>w;
	char s[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>s[i][j];
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='.')continue;
			if(i!=0&&s[i-1][j]=='#')continue;
			if(j!=0&&s[i][j-1]=='#')continue;
			if(i!=h-1&&s[i+1][j]=='#')continue;
			if(j!=w-1&&s[i][j+1]=='#')continue;
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
from collections import deque
from collections import defaultdict
edges = defaultdict(list)
N,M = map(int, input().split())
pairs = []
for i in range(M):
    a,b  = map(int, input().split())
    a -= 1
    b -= 1
    pairs.append((a,b))
ans = 0
# M本目の辺を切って全探索
for i in range(M):
    edges = defaultdict(list)
    s = 0
    for j,(a,b) in enumerate(pairs):
        if i == j:continue
        edges[a].append(b)
        edges[b].append(a)
        s = b
    cnt = 0
    # print(i,edges)
    # bfs
    seen = [False] * N 
    q = deque()
    q.append(b) 
    while len(q) > 0:
        e = q.popleft()
        nx = edges[e]
        for n in nx:
            if seen[n]:continue
            seen[n] = True
            q.append(n)
    if sum(seen) != N:
        ans += 1


    
print(ans)



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


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

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

int		main(void)
{
	int		k, s;
	cin >> k >> s;
	int		x, y, z;
	int		ans = 0;

	x = 0;
	while (x <= k){
		y = x;
		while (y <= k){
			z = y;
			while (z <= k){
				if (x + y + z == s){
					if (x == y || x == z || y == z){
						if (x == y && x == z)
							ans++;
						else
							ans +=3;
					} else
						ans += 6;
				}
				z++;
			}
			y++;
		}
		x++;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N, H, W;
  cin >> N >> H >> W;
  int res = (N - W + 1) * (N - H + 1);
  if (res < 0)
    cout << 0 << endl;
  else
    cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
GC.disable

(R, C, K), *RCVs = readlines.map{_1.split.map(&:to_i)}

a = RCVs.each_with_object(Array.new(R + 1){Array.new(C + 1, nil)}){|(r, c, v), a| a[r][c] = v}
dp, dp1 = Array.new(C + 2){Array.new(4, 0)}, Array.new(C + 2){Array.new(4, 0)}
(1 .. R).each do |i|
  (1 .. C).each do |j|
    v = a[i][j]
    3.downto(1){|k| dp[j][k] = dp[j][k - 1] + v if dp[j][k] < dp[j][k - 1] + v} if v
    dp1[j][0] = dp[j].max
    dp[j + 1][0] = dp[j][0] if dp[j + 1][0] < dp[j][0]
    dp[j + 1][1, 3] = dp[j][1, 3]
  end
  dp, dp1 = dp1, dp
end
puts dp[C][0]

Measured memory_bytes: 541332
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define lop(a,b,c) for(a=c;a<b;a++)
#define srt(v) v.begin(),v.end()
using namespace std;
int main()
{
    ll i,j,k,l,m,n,a;
    cin>>n>>m;
    if(n>9||m>9)
    cout<<"-1";
    else
    cout<<n*m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int count=0;
  cin >> s;
  int ones=0;
  int zeros=0;
  int sizes = s.size();
  for(int i=0;i<sizes;i++){
    if(s[i]==49){
      ones++;
    } else {
      zeros++;
    }
  }
  int ans = min(ones,zeros)*2;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(int, n);
    MAT(int, a, 2, n);
    FOR(i, 1, n) a[0][i] += a[0][i-1];
    a[1][0] += a[0][0];
    FOR(i, 1, n) a[1][i] += max(a[1][i-1], a[0][i]);
    OUTL(a[1][n-1]);
RET;}


Measured memory_bytes: 256
A = []
b = 0
while True:
    try:
        A.append(list(map(int,input().split())))
    except:
        break;
for i in range(1, A[0][0]+1):
  if (A[i][0])**2+(A[i][1])**2 <= (A[0][1])**2:
    b += 1
print(b)    

Measured memory_bytes: 45336
import java.util.Scanner;
public class Main {
	private static int[][] A = null;
	private static int W = -1;
	private static int H = -1;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		W = sc.nextInt();
		H = sc.nextInt();
		int N = sc.nextInt();
		A = new int[H][W];
		for (int n=0; n<N; n++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			set(x, y, a);
		}
		int res = 0;
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (A[i][j] == 0) res++;
			}
		}
		System.out.println(res);
	}
	public static void set(int x, int y, int a) {
		if (a == 1) {
			for (int i=0; i<H; i++) {
				for (int j=0; j<x; j++) {
					A[i][j] = 1;
				}
			}
		}else if (a ==2) {
			for (int i=0; i<H; i++) {
				for (int j=x; j<W; j++) {
					A[i][j] = 1;
				}
			}
		}else if (a ==3) {
			for (int i=0; i<y; i++) {
				for (int j=0; j<W; j++) {
					A[i][j] = 1;
				}
			}
		}else if (a ==4) {
			for (int i=y; i<H; i++) {
				for (int j=0; j<W; j++) {
					A[i][j] = 1;
				}
			}
		}
	}
}


Measured memory_bytes: 23100
#include <stdio.h>
#include <unordered_set>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i=a; i<b; i++)
typedef long long ll;
#define EXIST(a, b) ((a).find(b)!=(a).end())

int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};
// char c[70][20];
char c[20][70];
unordered_set<int> s;
int ky, kx, kd, my, mx, md, ny, nx, nd;
bool cango, canback;

void dp(int ay, int ax, int ad, int by, int bx, int bd){
	int cod=(ad<<10|ay<<6|ax)<<12|(bd<<10|by<<6|bx);
	if(EXIST(s, cod)) return;
	s.insert(cod);
	// printf("(%d, %d)-%d (%d, %d)-%d\n", ay, ax, ad, by, bx, bd);
	if(ay==my && ax==mx){
		// cango=true;
		if(by==ny && bx==nx && bd==nd){
			canback=true;
		}
	}
	REP(di, 2){
		int cy=ay, cx=ax, cd=(ad+di*2-1+4)%4;
		while(c[cy+dy[cd]][cx+dx[cd]]=='.') cy+=dy[cd], cx+=dx[cd];
		int ey=by, ex=bx, 
				// ed=(bd-di*2+1+4)%4, 
				ed=(bd+di*2-1+4)%4, 
				ee=(bd+2)%4;
		do{
			// printf("at (%d, %d)-%d %c: [%d, %d]=%c\n", ay, ax, ad, di?'L':'R', ey+dy[ed], ex+dx[ed], c[ey+dy[ed]][ex+dx[ed]]);
			if(c[ey+dy[ed]][ex+dx[ed]]=='#'){
				// printf("(%d, %d)-%d (%d, %d)-%d --%c--> (%d, %d)-%d (%d, %d)-%d\n", 
				// 		ay, ax, ad, by, bx, bd, di?'L':'R', cy, cx, cd, ey, ex, ed);
				dp(cy, cx, cd, ey, ex, ed);
			}
			ey+=dy[ee], ex+=dx[ee];
		}while(c[ey][ex]=='.');
		// printf("END LOOP\n");
	}
}

void dp2(int ay, int ax, int ad){
	int cod=(ad<<10|ay<<6|ax);
	if(EXIST(s, cod)) return;
	s.insert(cod);
	if(ay==my && ax==mx){
		cango=true;
	}
	REP(di, 2){
		int cy=ay, cx=ax, cd=(ad+di*2-1+4)%4;
		while(c[cy+dy[cd]][cx+dx[cd]]=='.') cy+=dy[cd], cx+=dx[cd];
		dp2(cy, cx, cd);
	}
}

int main(){
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		cango=canback=false;
		REP(i, h) scanf("%s", c[i]);

		REP(i, h) REP(j, w) if(c[i][j]=='K') ky=i, kx=j;
		REP(i, 4) if(c[ky+dy[i]][kx+dx[i]]=='.') kd=i;
		c[ky][kx]='.';

		REP(i, h) REP(j, w) if(c[i][j]=='M') my=i, mx=j;
		REP(i, 4) if(c[my+dy[i]][mx+dx[i]]=='.') md=i;
		c[my][mx]='.';

		int ay=ky, ax=kx, ad=kd;//, by=my, bx=mx, bd=md;
		ny=my, nx=mx, nd=md;
		while(c[ay+dy[ad]][ax+dx[ad]]=='.') ay+=dy[ad], ax+=dx[ad];
		while(c[ny+dy[nd]][nx+dx[nd]]=='.') ny+=dy[nd], nx+=dx[nd];
		REP(i, 4){
			if(i!=kd){
				s.clear();
				dp2(ay, ax, ad);
				s.clear();
				dp(ay, ax, ad, ky, kx, i);
			}
		}

		if(!cango) printf("He cannot bring tea to his master.\n");
		else if(!canback) printf("He cannot return to the kitchen.\n");
		else printf("He can accomplish his mission.\n");
	}
}



Measured memory_bytes: 4832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n,k;
int main(){
	cin>>n>>k;
	if (k==1) cout<<"0";
	else cout<<n-k;
}

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

namespace AtCoder.BC088
{
    public class B
    {
        public static void Main()
        {
            Console.ReadLine();
            List<int> cards = Console.ReadLine().Split(" ").Select(n => int.Parse(n)).OrderByDescending(n => n).ToList();
            int a = 0, b = 0;

            for (int i = 0; i < cards.Count(); i++)
            {
                if (i % 2 == 0)
                {
                    a += cards[i];
                }
                else
                {
                    b += cards[i];
                }
            }

            Console.WriteLine(a - b);
        }
    }
}

Measured memory_bytes: 19108
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define db double
#define zero(x) (fabs(x)<eps)
#define sgn(x) (zero(x)?0:((x)>0?1:-1))
const db eps=1e-10;
struct point{
    db x,y;
    point(){}
    point(db x,db y):x(x),y(y){}
    point operator + (point B){ return point(x+B.x,y+B.y); }
    point operator - (point B){ return point(x-B.x,y-B.y); }
    point operator * (db k){ return point(k*x,k*y); }
    db operator * (point B){ return x*B.y-y*B.x; }
    db operator ^ (point B){ return x*B.x+y*B.y; }
    bool operator < (point B){ return (y>0)!=(B.y>0)?y>0:((*this)*B)>0; }
};
db dis2(point A,point B){ return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y); }
struct line{
    point A,B;
    line(){}
    line(point A,point B):A(A),B(B){}
};
point projection(line l,point P){
    point dir=l.B-l.A; P=P-l.A;
    return dir*((P^dir)/dis2(l.A,l.B))+l.A;
}
point reflection(line l,point P){
    return projection(l,P)*2-P;
}
int direction(point P0,point P1,point P2){
    db det=(P2-P0)*(P1-P0); return sgn(det);
}
bool parallel(line l1,line l2){
    return zero((l1.B-l1.A)*(l2.B-l2.A));
}
bool orthogonal(line l1,line l2){
    return zero((l1.B-l1.A)^(l2.B-l2.A));
}
int main(){
    int q; scanf("%d",&q);
    while (q--){
        db x1,y1,x2,y2; line l1,l2;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l1=line(point(x1,y1),point(x2,y2));
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l2=line(point(x1,y1),point(x2,y2));
        printf("%d\n",parallel(l1,l2)?2:orthogonal(l1,l2));
    }
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long x, long long y)
{
	long long result = 1;
	while (y != 0) {
		if (y%2 != 0) {
			result *= x;
			y -= 1;
		}	
		x *= x;
		y /= 2;
	}
	return result;
}
int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> ss(m);
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int s;
			cin >> s;
			ss[i].push_back(s);
		}
	}
	vector<int> p(m);
	for (int i = 0; i < m; i++)
		cin >> p[i];


	int ans = 0;
	for (uint32_t i = 0; i < mypow(2, n); i++) {
		vector<bool> s(n);
		for (int j = 0; j < n; j++) {
			if (((i>>j)&1) == 1)
				s[j] = true;
			else
				s[j] = false;
		}
		int l_count = 0;
		for (int j = 0; j < m; j++) {
			int s_count = 0;
			for (auto e : ss[j]) {
				if (s[e-1])
					s_count++;
			}
			if (s_count%2 == p[j])
				l_count++;
			else
				break;
		}
		if (l_count == m) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

typedef pair <int, int> ii;
typedef long long ll;
typedef pair <ll, int> lli;

const int Maxn = 100005;
const ll has = 1000000000000000ll;

int n, m, s, t;
vector <ii> neighS[Maxn], neighT[Maxn];
ll distS[Maxn], distT[Maxn];
ll mx;
ll res[Maxn];

void Dijkstra(int v, vector <ii> neigh[], ll dist[])
{
	fill(dist, dist + Maxn, has); dist[v] = 0;
	priority_queue <lli> Q; Q.push(lli(-dist[v], v));
	while (!Q.empty()) {
		int v = Q.top().second;
		ll d = -Q.top().first; Q.pop();
		if (dist[v] != d) continue;
		for (int i = 0; i < neigh[v].size(); i++) {
			ii u = neigh[v][i];
			if (d + u.second < dist[u.first]) {
				dist[u.first] = d + u.second;
				Q.push(lli(-dist[u.first], u.first));
			}
		}
	}
}

int main()
{
	scanf("%d %d %d %d", &n, &m, &s, &t);
	for (int i = 0; i < m; i++) {
		int u, v, a, b; scanf("%d %d %d %d", &u, &v, &a, &b);
		neighS[u].push_back(ii(v, a));
		neighS[v].push_back(ii(u, a));
		neighT[u].push_back(ii(v, b));
		neighT[v].push_back(ii(u, b));
	}
	Dijkstra(s, neighS, distS);
	Dijkstra(t, neighT, distT);
	for (int i = n - 1; i >= 0; i--) {
		mx = max(mx, has - distS[i + 1] - distT[i + 1]);
		res[i] = mx;
	}
	for (int i = 0; i <= n - 1; i++)
		printf("%lld\n", res[i]);
	return 0;
}

Measured memory_bytes: 16252
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

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

  cin >> a >> b >> c >> d;

  if (d >= abs(a - c))
  {
    cout << "Yes" << endl;
  }
  else if (d >= abs(a - b) && d >= abs(b - c))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#ifdef USE_COUT
#define dump(...) (cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#else
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

/// --- Union Find Library {{{ ///

struct UF {
  int n;
  vector<int> par, rank;
  UF(int n): n(n), par(n, -1), rank(n, 0) {}
  int find(int x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }
  int size(int x) {
    return -par[find(x)];
  }
  bool same(int a, int b) {
    return find(a) == find(b);
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if(a == b) return;
    if(rank[a] > rank[b]) swap(a, b);
    par[b] += par[a];
    par[a] = b;
    if(rank[a] == rank[b]) rank[b]++;
  }
};

/// }}}--- ///

const int N = 1e5;
vector<int> g[N];
int n, m;
int a[N], b[N], c[N];
ll sumb[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i], c[i] = a[i] - b[i];
  for(int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  vector<int> ord(n);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int a, int b) {
    return c[a] < c[b];
  });
  UF uf(n);
  ll ans[N] = {};
  bool used[N] = {};
  for(int i = 0; i < n; i++) {
    int id = ord[i];
    used[id] = 1;
    ll nsumb = b[id];
    ll nans = 1e18;
    set<int> go;
    for(int j : g[id]) if(used[j] && !go.count(uf.find(j))) {
      nsumb += sumb[uf.find(j)];
      go.emplace(uf.find(j));
    }
    for(int gj : go) {
      if(ans[gj] < c[id]) {
        nans = min(nans, c[id] + nsumb - sumb[gj]);
      } else {
        dump(ans[gj], sumb[gj], nsumb);
        nans = min(nans, ans[gj] - sumb[gj] + nsumb);
      }
    }
    for(int j : g[id]) if(used[j]) {
      uf.unite(id, j);
    }
    if(nans == 1e18) nans = max(a[id], b[id]);
    ans[uf.find(id)] = nans;
    sumb[uf.find(id)] = nsumb;
    dump(id + 1, c[id], b[id], nans, nsumb);
  }
  cout << ans[uf.find(ord[n-1])] << endl;
}



Measured memory_bytes: 11516
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class UnionFind:
    def __init__(self, n):
        self._parent = [i for i in range(n)]
        self._rank = [0 for _ in range(n)]
        self._group_size = [1 for _ in range(n)]
        self.num_of_groups = n

    def find(self, x):
        # vs = []
        while self._parent[x] != x:
            # vs.append(x)
            x = self._parent[x]
        # for v in vs: self._parent[v] = x
        return x

    def union(self, x, y):
        px, py = self.find(x), self.find(y)
        if px == py: return
        if self._rank[px] < self._rank[py]:
            self._parent[px] = py
            self._group_size[py] += self._group_size[px]
        else:
            self._parent[py] = px
            self._group_size[px] += self._group_size[py]
        if self._rank[px] == self._rank[py]:
            self._rank[py] += 1
        self.num_of_groups -= 1

    def is_same(self, x, y): return self.find(x) == self.find(y)
    def group_size(self, x): return self._group_size[self.find(x)]


def main():
    N, Q = LI()
    TUV = LIR(Q)

    uf = UnionFind(N+1)

    for t, u, v in TUV:
        if t == 0:
            uf.union(u, v)
        else:
            print(int(uf.is_same(u, v)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 130088
N = int(input())
b = list(map(int, input().split()))

#成り立たせることができるかどうか
for i in range(1, N + 1):
    if b[i - 1] > i:
        print (-1)
        exit()


check_lst = [False] * N #i番目の数を使ったかどうか

ans_lst = [] #答えの逆順
index = N - 1
while len(ans_lst) != N:
    if check_lst[index] == False and b[index] <= check_lst[:index].count(True) + 1:
        ans_lst.append(b[index])
        check_lst[index] = True
        index = N - 1
    else:
        index -= 1

for i in ans_lst:
    print (i)    
        

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define INF 2000000000

int main() {
    int n;
    scanf("%d", &n);
    int ans;
    for (ans=n; ans<=999; ans++) {
        if (ans/100 == ans/10%10 && ans/10%10 == ans%10) break;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
#define REP(i, a, b) for(int i = int(a); i <= int(b); i++)
#define LOOP(i, v) for(int i = 0; i < v.size(); i++)
#define EPS 1e-9
#define INF 1e12
#define debug(x) cerr << "DEBUG : " << (#x) << " => " << (x) << endl

int where[2][2002];

ii leftt[2][2002];
ii rightt[2][2002];

ii qui[4004];
int bad[2][2002];
int other[2][2002][2002];

int main()
{
  int N;
  char c;
  int x;
  scanf("%d\n", &N);
  
  int col;
  int a = -1, b = -1, A, B;
  
  REP(i, 0, 2*N-1)
  {
    scanf("%c %d\n", &c, &x);
    if(c == 'W') col = 0;
    else col = 1;
    qui[i] = make_pair(col, x);
    bad[col][x] = 0;
    where[col][x] = i;
    REP(j, 0, i-1)
    {
      if(qui[j].first == col && qui[j].second > x) bad[col][x]++;
    }
  }

  REP(i, 0, 1) REP(j, 1, N)
  {
    other[i][j][N] = 0;
    for(int k = N-1; k >= 0; k--)
    {
      other[i][j][k] = other[i][j][k+1];
      if(where[1-i][k+1] < where[i][j]) other[i][j][k]++;
    }
  }
  
  int ans[2002][2002];
  ans[0][0] = 0;
  REP(i, 0, N) REP(j, 0, N)
  {
    // i white et j blacks bien placés
    if(i || j)
    {
      int poss0 = -1;
      if(i > 0) poss0 = ans[i-1][j] + bad[0][i] + other[0][i][j];
      int poss1 = -1;
      if(j > 0) poss1 = ans[i][j-1] + bad[1][j] + other[1][j][i];
      if(poss0 == -1) ans[i][j] = poss1;
      else if(poss1 == -1) ans[i][j] = poss0;
      else ans[i][j] = min(poss0, poss1);
    }
  }
  
  printf("%d\n", ans[N][N]);
    
  return 0;
}

Measured memory_bytes: 47232
const val MOD = 1000000007L

fun main() {
  val N = readInt()
  val AN = readLongs()

  val SN = Array(N) { 0L }
  SN[0] = AN[0]
  for (i in 1 until N) {
    SN[i] = SN[i - 1] + AN[i]
  }

  var result = 0L
  for (i in 0 until N - 1) {
    result = (result + (AN[i] * ((SN.last() - SN[i]) % MOD)) % MOD) % MOD
  }
  println(result)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 72928
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s; cin >> s;
    for(int i = 0; i<s.size(); ++i)cout << 'x';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        Map<Long, Long> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
            map.merge(A[i], 1L, Long::sum);
        }
        long sum = Arrays.stream(A).sum();
        int Q = scan.nextInt();
        for (int i = 0; i < Q; i++) {
            long B = scan.nextInt();
            long C = scan.nextInt();
            if (map.containsKey(B)) {
                long count = map.get(B);
                sum += (C - B) * count;
                map.remove(B);
                map.merge(C, count, Long::sum);
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 66592
#include <iostream>
using namespace std;
int main()
{
	int n,m,ans;
	char IOI[1000001];
	while(cin>>n,n){
		cin>>m>>IOI;
		int i,k;
		ans = 0;
		n = 2*n+1;
		k=0;
		// 4__ IOIOIOIOI
		for(;;){
			for(i=0; i<n/2; i++){
				if( IOI[i+k]!=(i&1?'O':'I') ||
					 IOI[i+k]!=IOI[k+n-i-1] )
					break;
			}
			if( i==n/2 && IOI[k+n/2]==((n/2)%2?'O':'I')){
				//printf("k_%d IOI[%d]=%c\n",k,k+n/2,IOI[k+n/2]);
				ans++;
				k += n;
				for(; k<m; k+=2){
					if( IOI[k]=='O' && IOI[k+1]=='I' ){
						ans++;
						//printf("k__%d\n",k);
					}
					else break;
				}
			}else{
				for(k++; k<m && IOI[k]=='O'; k++);
			}
			//printf("next_k_%d\n",k);
			if( k+n>m )break;
		}
		printf("%d\n",ans);
	}
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  ll ans = 0;  

  for (int bit = 0; bit <(1<<(N-1)); bit++) {
    ll sm = 0;				//bunkatsu sita goukei
    ll a = S[0] - '0';		//tasuyatu
    for (int i = 0; i < N-1; i++) {
      if(bit & (1<<i)){		//bit ni ibanme no flag aru?
        sm += a;
        a = 0;
      }
      a = a*10 + S[i+1] - '0';
    }
    sm += a;
    ans += sm;	//ans ni irete reset
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
ll dp[2010][2010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll S[2010], T[2010];
    rep(i,0,N) cin >> S[i];
    rep(i,0,M) cin >> T[i];
    dp[0][0] = 1;
    ll sb[2010], tb[2010];
    memset(sb,-1,sizeof(sb));
    memset(tb,-1,sizeof(tb));
    ll pos[100010] = {};
    memset(pos,-1, sizeof(pos));
    rep(i,0,N){
        if(pos[S[i]] == -1){
            sb[i] = -1;
        }else{
            sb[i] = pos[S[i]];
        }
        pos[S[i]] = i;
    }
    memset(pos,-1, sizeof(pos));
    rep(i,0,M){
        if(pos[T[i]] == -1){
            tb[i] = -1;
        }else{
            tb[i] = pos[T[i]];
        }
        pos[T[i]] = i;
    }
    rep(i,1,N+1){
        dp[i][0] = 1;
    }
    rep(i,1,M+1){
        dp[0][i] = 1;
    }
    rep(i,0,N){
        rep(j,0,M){
            if(S[i] == T[j]){
                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % MOD;
            }else{
                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j] + MOD) % MOD;
            }
        }
    }
    print(dp[N][M]);


    
    

}

Measured memory_bytes: 32512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t--)
#define input1(n) ll n;cin>>n;
#define input2(a,b) ll a,b;cin>>a>>b;
#define mod 1000000007
ll min(ll a,ll b)
{
    if(a<b)
    return a;
    return b;
}

int main()  
{  
    ll n,W;
    cin>>n>>W;
    //cout<<n<<" "<<W<<"\n";
    ll w[n],v[n];
    for(ll i=0;i<n;i++)
    cin>>w[i]>>v[i];
    ll dp[n+1][W+1];
    for(ll i=0;i<n+1;i++)
    {
        for(ll j=0;j<W+1;j++)
        {
        if(i==0||j==0)
        dp[i][j]=0;
        // if(j==0)
        // dp[i][j]=1;
        }
    }
    ll sum=0;
    for(ll i=1;i<n+1;i++)
    {
        
        sum+=w[i-1];
        //cout<<sum<<"\n";
        for(ll j=1;j<W+1;j++)
        {
        
        // if(j%sum==0)
        // {
            //cout<<i<<"\n";
            if(w[i-1]<=j)
            {
                dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
                //cout<<dp[i][j]<<" "<<"\n";
            }
            else
            dp[i][j]=dp[i-1][j];
        }
        //     else
        //     dp[i][j]=0;
        // }
    }
    // for(ll i=0;i<n+1;i++)
    // {
    //     for(ll j=0;j<W+1;j++)
    //     cout<<dp[i][j]<<" ";
    //     cout<<"\n";
    
    // }
    cout<<dp[n][W];
    return 0;
}


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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){

  int n,p;

  while(cin >> n,n){
    cin >> p;
    int a = p;
    vi v(n,0);
    int pos = 0;

    while(1){
      if(p > 0){
        ++v[pos];
        --p;
      }
      else{
        p += v[pos];
        v[pos] = 0;
      }

      if(v[pos] == a){
        cout << pos << endl;
        break;
      }
      pos = (pos+1) % n;
    }
  }
  return 0;

}


Measured memory_bytes: 3084
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k, c_yutori = tin()
	if n == 1:
		return 1
		
		
	s = input()
	can_work = [0]*n
	can_work[0] = 1 if s[0]=='o' else 0
	yn = c_yutori if s[0]=='o' else 0
	for i, c in enumerate( list(s)[1:],1):
		if yn == 0 and c == 'o':
			can_work[i] = can_work[i-1]+1
			yn = c_yutori
		else:
			can_work[i] = can_work[i-1]
			yn = max(0, yn - 1)
	need_to_work = [k]*n
	if s[-1]=='o':
		need_to_work[-1] = k-1
		yn = c_yutori
	else:
		need_to_work[-1]=k
		yn=0
	for i, c in enumerate(list(s)[-2::-1],1):
		pos = n-i-1
		if yn == 0 and c == 'o':
			need_to_work[pos] = need_to_work[pos+1]-1
			yn = c_yutori
		else:
			need_to_work[pos]=need_to_work[pos+1]
			yn = max(0, yn-1)
	#pa(can_work)
	#pa(need_to_work)
	if need_to_work[1] == 1:
		print(1)
		
	for i in range(1, n-1):
		if can_work[i-1] < need_to_work[i+1]:
			print(i+1)
		
	if can_work[-2]==k-1:
		print(n)
		
		
		
			
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k%2 == 0) cout << a-b << endl;
  else cout << b-a << endl;
}

Measured memory_bytes: 256
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline

sys.setrecursionlimit(500005)
read_int = lambda: int(ns())
read_list = lambda: list(map(int, input().split()))
read_string = lambda: input().rstrip()

x, n = read_list()
p = set(read_list())
res = 1000000
for i in range(-100, 300):
    if i in p:
        continue
    if abs(i - x) < abs(res - x) or (abs(i - x) == abs(res - x) and i < res):
        res = i
print(res)

Measured memory_bytes: 9724
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,count=0;
    cin>>n;
    char s[n];
    for(i=0;i<n;i++)
    cin>>s[i];
    for(i=0;i<n-1;i++)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3604
h, w = gets.split.map(&:to_i)
ary = []
h.times do
  ary << gets.strip
end
ary.each_with_index do |k, i|
  ary[i] = "##{k}#"
end
ary << "#"*(w+2)
ary.insert(0, "#"*(w+2))
puts ary

Measured memory_bytes: 1788
plusNum d n
   | n == 0    = 0
   | otherwise = n + d*15

main = do
   n <- read <$> getLine
   let (d,m) = n `divMod` 15
   putStrLn $ show $ 60*d*d + (sum $ take m $ map (plusNum d) [1,2,0,4,0,0,7,8,0,0,11,0,13,14,0])


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,n1,n3;
    scanf("%d", &n); 
	n3=n%10;
	n1=n/100;
    if(n1==n3)
        printf("Yes");
    else
        printf("No");
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string A,B,C;
  cin >> A >> B >> C;

  if(A.back()==B.front() && B.back()==C.front()){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include <algorithm> 
#include <iostream> 
#include <stdio.h>
using namespace std; 
 
int main(){
long long int A,B,C,f=0,s=0;
cin>>A>>B>>C;
if(A==5){
f++;
}
if(A==7){
s++;
}

if(B==5){
f++;
}
if(B==7){
s++;
}

if(C==5){
f++;
}
if(C==7){
s++;
}

if(f==2&&s==1){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}

Measured memory_bytes: 256
n = int(input())
s = input()
lis = []
ws=s.count('.')
lis.append(ws)
bs = 0
for x in s:
    if x == '#':
        bs += 1
        lis.append(bs+ws)
    else:
        ws -= 1
    lis.append(bs+ws)
print(min(lis))


Measured memory_bytes: 19304
H, W, M = map(int, input().split())
 
h = [0] * H
w = [0] * W
Mem = [tuple(map(int, input().split())) for _ in range(M) ]
for i, j in Mem:
  h[i-1] += 1
  w[j-1] += 1

maxh = max(h)
maxw = max(w)
 
listh = {i for i, v in enumerate(h, 1) if v == maxh}
listw = {j for j, v in enumerate(w, 1) if v == maxw}

cnt = len(listh) * len(listw)

for i, j in Mem:
  if i in listh and j in listw:
    cnt -= 1
 
if cnt:
  ans = maxh + maxw
else:
  ans = maxh + maxw - 1

print(ans)

Measured memory_bytes: 96180