akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n, btot = 0;
  cin >> n;
  vector<ll> t(n),a(n),b(n);
  rep(i, n) {
    cin >> a[i] >> b[i];
    t[i] = a[i] + b[i];
    btot += b[i];
  }

  sort(t.rbegin(), t.rend());
  ll ans = -btot;
  for (int i = 0; i < n; i += 2) ans += t[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
n = int(input())
s1 = input()
s2 = input()
count = 1
j = 0
if s1[0] == s2[0]:
  count *= 3
else:
  count *= 6 
  j += 1
while j < n-1:
  if s1[j] == s2[j]:
    if s1[j+1] == s2[j+1]:
      count *= 2
      count %= 1000000007
    else:
      count *= 2
      count %= 1000000007
      j += 1
  else:
    if s1[j+1] == s2[j+1]:
      count *= 1
      count %= 1000000007
    else:
      count *= 3
      count %= 1000000007
      j += 1
  j += 1
print(count)


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


int main(){
    char S[200001], T[200001];
    int ans = 0;
    scanf("%s %s", S, T);
    for (int i = 0; S[i] != '\0' && T[i] != '\0'; i++) {
        if (S[i] != T[i]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int cnt[3];
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  REP(i, N) {
    int p;
    cin >> p;
    if (p % 4 == 0)
      cnt[2]++;
    else if (p % 2 == 0)
      cnt[1]++;
    else
      cnt[0]++;
  }
  if (cnt[1] == 0) {
    if (cnt[0] > cnt[2] + 1) {
      print("No");
    } else {
      print("Yes");
    }
  } else if (cnt[0] > cnt[2]) {
    print("No");
  } else {
    print("Yes");
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int s1 = 0;
        int s2 = 0;
        for (int i = 0; i < N; i++) {
            int D = sc.nextInt();
            s1 += D;
            s2 += D * D;
        }
        System.out.println((s1 * s1 - s2) / 2);
    }

}


Measured memory_bytes: 21716
#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;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if (a>=b) {
        rrep(i,a) cout<<b;
        cout<<endl;
    }
    else{
        rrep(i,b) cout<<a;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		new Main().start();
	}
	Scanner in;
	void start(){
		in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n == 0) return;
			int m = in.nextInt();
			Point[] origins = getChange(m);
			for(int i = 0; i < n; i++){
				int mm = in.nextInt();
				Point[] oresen = getChange(mm);
				Point[] gyakuOresen = new Point[oresen.length];
				for(int j = 0; j < oresen.length;j++){
					gyakuOresen[oresen.length-1-j] = oresen[j];
				}
				if(m == mm){
					if(hikaku(origins, oresen)){
						System.out.println(i+1);
					}else if(hikaku(origins, gyakuOresen)){
						System.out.println(i+1);
					}
				}
			}
			System.out.println("+++++");
		}
	}
	Point[] getChange(int m){
		Point[] points = new Point[m];
		for(int i = 0; i < m; i++){
			int x = in.nextInt();
			int y = in.nextInt();
			points[i] = new Point(x,y);
		}
		Point[] changes = new Point[m-1];
		for(int i = 0; i < points.length-1; i++){
			changes[i] = new Point(points[i+1].x - points[i].x, points[i+1].y - points[i].y);
		}
		return changes;
	}
	boolean hikaku(Point[] o, Point[] c){
		if(o[0].x != 0 && o[0].x == c[0].x){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].x, c[i].x, o[i].y, c[i].y)) return false;
			}
		}else if(o[0].x != 0 && o[0].x == c[0].y){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].x, c[i].y, o[i].y, -c[i].x)) return false;
			}
		}else if(o[0].x != 0 && o[0].x == -c[0].x){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].x, -c[i].x, o[i].y, -c[i].y)) return false;
			}
		}else if(o[0].x != 0 && o[0].x == -c[0].y){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].x, -c[i].y, o[i].y, c[i].x)) return false;
			}
		}else if(o[0].y != 0 && o[0].y == c[0].y){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].y, c[i].y, o[i].x, c[i].x)) return false;
			}
		}else if(o[0].y != 0 && o[0].y == c[0].x){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].y, c[i].x, o[i].x, -c[i].y)) return false;
			}
		}else if(o[0].y != 0 && o[0].y == -c[0].y){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].y, -c[i].y, o[i].x, -c[i].x)) return false;
			}
		}else if(o[0].y != 0 && o[0].y == -c[0].x){
			for(int i = 1; i < o.length; i++){
				if(!keisan(o[i].y, -c[i].x, o[i].x, c[i].y)) return false;
			}
		}else {
			return false;
		}
		return true;
	}
	boolean keisan(int a, int b, int c, int d){
		if((a != 0 && a == b) || (c != 0 && c == d))return true;
		return false;
	}
}

class Point{
	int x, y;
	Point(int x, int y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 38164
s = []
for _ in range(3):
	s.append(list(input()))

n_p = ['a']

while True:
	if n_p[0] == 'a' and len(s[0]) != 0:
		n_p[0] = s[0].pop(0)

	elif n_p[0] == 'b' and len(s[1]) != 0:
		n_p[0] = s[1].pop(0)

	elif n_p[0] == 'c' and len(s[2]) != 0:
		n_p[0] = s[2].pop(0)

	else:
		print(n_p[0].upper())
		break		


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

int main(){
	int n,k; cin >> n >> k;
	long long ans=0;
	for(int b=1;b<=n;b++){
		int p=n/b;
		int r=n%b;
		ans+=p*max(0,b-k)+max(0,r-k+1)-(k==0?1:0);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
const ll MOD = 1000000007;
const ll INF = 1000000000;
const int MAX = 10000000;


int main() {
    ll n, m;
    cin >> n >> m;
    if (n == 1 && m == 1) cout << 1 << endl;
    else if (n == 1 || m == 1) cout << n*m - 2;
    else cout << n*m - 2 * n - 2 * m + 4 << endl;
    
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,k;cin>>n>>k;
  vector<int> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i];
  }
  int nw = 0;
  int ans = 0;
  for(int i = 0; n > i; i++){
    if(i <= k-1){
      nw+=(A[i]+1);
      if(i==k-1){
        ans = nw;
      }
    }else{
      nw+=(A[i]+1);
      nw-=(A[i-k]+1);
      ans = max(ans,nw);
    }
  }
  cout << fixed << setprecision(10) << (double)ans/2 << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
 
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        String relation;
 
        if(a > b){
            relation = ">";
        }else if(a < b){
            relation = "<";
        }else{
            relation = "==";
        }
 
        System.out.printf("a %s b\n", relation);
    }
}


Measured memory_bytes: 26260
N = int(input())
A = list(map(int, input().split()))
abs_min = 10 ** 9
minus = 0
total = 0
for x in A:
    if x < 0:
        minus += 1
        x = - x
    if abs_min > x:
        abs_min = x
    total += x
if minus % 2 == 0:
    print(total)
else:
    print(total - abs_min * 2)

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
int t[100100], us[100100][20];
vector <int> g[100100];
void func(int v, int d, int c)
{
    if(us[v][d])
        return;
    us[v][d] = 1;
    if(d == 0)
    {
        t[v] = c;
        return;
    }
    func(v, d - 1, c);
    for(int i = 0; i < g[v].size(); ++i)
        func(g[v][i], d - 1, c);
}

int main()
{
    int n, m, i, x, y, q, z;
    vector <pair <pair <int, int>, int> > v;

    cin >> n >> m;
    for(i = 0; i < m; ++i)
    {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cin >> q;
    for(i = 0; i < q; ++i)
    {
        cin >> x >> y >> z;
        v.push_back(make_pair(make_pair(x, y), z));
    }
    while(!v.empty())
    {
        func(v.back().first.first, v.back().first.second, v.back().second);
        v.pop_back();
    }
    for(i = 1; i <= n; ++i)
        cout << t[i] << endl;

return 0;
}


Measured memory_bytes: 18032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int arr[n];
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> arr[i];
    sum+=arr[i];
  }
  int ans;
  if(sum%10==0)
  {
    int p=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
    {
      int k = sum-arr[i];
      if(k%10!=0)
      {
        ans=k;
        p=1;
        break;
      }
    }
    if(p==0)
      ans=0;
  }
  else{
    ans=sum;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
ary = []
ary = gets.split(' ').map(&:to_i)
m = ary[0]
d = ary[1]

result = 0
1.upto(m) { |m_num|
  1.upto(d) { |d_num|
    d_s = d_num.to_s.split('').map(&:to_i)
    if d_s.length == 1
        next
    end 
    if d_s[0] < 2 || d_s[1] < 2
        next
end
    if d_s[0] * d_s[1] == m_num
      result += 1
    end

  }
}
 
puts result

Measured memory_bytes: 2172
N=int(input())
A=list(map(int,input().split()))
two=0
one=0
four=0
for a in A:
    if a%4==0:
        four+=1
    elif a%2==0:
        two+=1
    else:
        one+=1
if two==0 and one<=four+1:
    print('Yes')
elif one<=four:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a2,a4,a6,b2,b4,b6,c,q,i,j,z=0,k=1,o=0,m[1001][1001]={0};
  int a[1001]={0},b[1001]={0},w[1001]={0},e[6][2]={0};
  for(a2=a4=a6=b2=b4=b6=i=0;i<6;i++){
    cin>>q>>c;
    w[q]++;
    w[c]++;
    if(q>c)m[q][c]++;
    else m[c][q]++;
  }
  for(i=0;i<1001;i++){
    if(w[i])o++;
      for(j=0;j<1001;j++){
        if(m[i][j]){a[j]+=m[i][j];b[i]+=m[i][j];
	  if(m[i][j]==4){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
	  else if(m[i][j]==6){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
	  else{ e[z][0]=i;e[z++][1]=j;}
	}
       }
    }
  if(e[0][0]!=e[2][1]||e[1][0]!=e[2][0]||e[0][1]!=e[1][1]||o>3)k=0;
  for(i=0;i<1001;i++){
    if(w[i]%4)k=0;
    if(a[i]==4)a4++;
    if(a[i]==2)a2++;
    if(a[i]==6)a6++;
    if(b[i]==4)b4++;
    if(b[i]==2)b2++;
    if(b[i]==6)b6++;
  }
  if(a4&&a2&&b4&&b2&&k||a6&&b4&&b2&&k||b6&&a4&&a2&&k||b6&&a6&&k)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}

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

using P = pair<int, int>;

P p(int v)
{
	int t = v;
	while (t >= 10)
	{
		t /= 10;
	}
	int b = v % 10;

	return P(t, b);
}

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

	map<P, int> m;

	for (int i = 1; i <= n; ++i)
	{
		P a = p(i);
		++m[a];
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		P a = p(i);
		P b(a.second, a.first);
		ans += m[b];
	}

	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

void fin(){
	freopen("test.txt", "r", stdin);
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(!n) break;
		while(n--){
			int a[4], b[4], c[4]; // 1 i j k
			rep(i, 4) cin >> a[i];
			rep(i, 4) cin >> b[i];
			c[0] = a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3];
			c[1] = a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2];
			c[2] = a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1];
			c[3] = a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0];
			rep(i, 4) cout << (i?" ":"") << c[i];
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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; }

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int N;
string S;

int main(int argc, const char * argv[]) {
    cin >> S;

    int ans = 0;
    if (S[1] == 'R') {
        ans += 1;
        if (S[0] == 'R') {
            ans += 1;
        }
        if (S[2] == 'R') {
            ans += 1;
        }
    } else {
        if (S[0] == 'R') {
            ans = 1;
        } else if (S[2] == 'R') {
            ans = 1;
        }
    }

    output(ans);
    

    return 0;
}

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

using namespace std;

int main()
{
for(;;){
int ak, bk, ck;
int data[1000][4];
int n;

cin >> ak;
cin >> bk;
cin >> ck;
if((ak == 0) && (bk == 0) && ( ck == 0)){
break;
}

vector<int> a(ak);
vector<int> b(bk);
vector<int> c(ck);
vector<int> check_data(ak+bk+ck+1, 2);		//0ツ氾板姪堋づ債使ツ用ツつオツづ慊つケツづア

int all = ak+bk+ck+1;
cin >> n;

for(int i = 0; i < n; i++){
cin >> data[i][0];
cin >> data[i][1];
cin >> data[i][2];
cin >> data[i][3];
}

/*ツ債格ツづ個閉板品ツづーツパツスツつキツづゥ*/
/*0.ツ不ツ債格 1.ツ債格 2.ツ不ツ鳴セ*/
for(int i = 0; i < n; i++){
if(data[i][3] == 1){
check_data[data[i][0]] = 1;
check_data[data[i][1]] = 1;
check_data[data[i][2]] = 1;
}
}

/*ツ不ツ鳴セツづ個閉板品ツづ個チツェツッツク*/
for(int i = 0; i < n; i++){
if(data[i][3] != 1){
if((check_data[data[i][0]] == 1)&&(check_data[data[i][1]] == 1)){
check_data[data[i][2]] = 0;
}
if((check_data[data[i][0]] == 1)&&(check_data[data[i][2]] == 1)){
check_data[data[i][1]] = 0;
}
if((check_data[data[i][1]] == 1)&&(check_data[data[i][2]] == 1)){
check_data[data[i][0]] = 0;
}
}
}

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

Measured memory_bytes: 0
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
a = nsn(n)
b = nsn(m)

ans = False
for i in range(n):
    for j in range(n):
        if i + m - 1 >= n or j + m - 1 >= n:
            continue
        flag = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = False
        if flag:
            ans = True

print("Yes" if ans else "No")

Measured memory_bytes: 40560
DOWN = 0
UP = 1
MOVE_LIST = ["lu","ru","ld","rd"]

def get_input():
    input_data = int(input())
    return input_data

def get_data_list():
    data_list = input().split()
    return data_list


class Manager:
    def __init__(self, move_num, record_list):
        self.move_num = move_num
        self.record_list = record_list
        self.count = 0
        self.right_status = DOWN
        self.left_status = DOWN
        self.kazu_status = DOWN


    def watach_move(self):
        for move in self.record_list:
            if move == "lu":
                self.left_status = UP
            elif move == "ru":
                self.right_status = UP
            elif move == "ld":
                self.left_status = DOWN
            else:
                self.right_status = DOWN
            self.counter()

    def counter(self):
        if self.left_status == self.right_status != self.kazu_status:
            self.kazu_status = self.left_status
            self.count += 1


if __name__ == "__main__":
    while True:
        move_num = get_input()
        if move_num == 0:
            break
        record_list = get_data_list()
        manager = Manager(move_num, record_list)
        manager.watach_move()
        print(manager.count)



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

long long ara[5005],tra[5005],mp[5005];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x,y=0,cnt=0,res=0,ttl=0,ans,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&k);

        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a); tra[i]=a;

        }

        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a); ara[i]=a;
        }

        ans=mx;

        for(i=1;i<=n;i++)
        {

            cnt=0; g=mx; sum=0; fr=mx; x=i;

            while(1)
            {
                h=tra[x];
                sum=sum+ara[h];

                if(sum>g)g=sum;

                cnt++;
                mp[cnt]=g;

                if(cnt==k || h==i)break;

                x=h;

            }

            if(cnt==k){ if(g>ans)ans=g;  }
            else
            {
                for(j=1;j<=cnt;j++)
                {
                    c=k-j; d=c/cnt; if(d==0)break;

                    e=sum*d; e=max(0LL,e); f=e+mp[j]; if(f>g)g=f;

                }

                if(g>ans)ans=g;

            }


        }

        printf("%lld\n",ans);





        return 0;
}





Measured memory_bytes: 3908
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int i,j,ans=0;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;

int main(){
	int w,a,b;
	cin>>w>>a>>b;
	if(a>b){
		i=a;
		a=b;
		b=i;
	}
	cout << max(0,b-a-w) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}
template <class T> void print(T a){ cout << a << endl;};
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};


int main(){
    INT(n);
    vlint a(n); line(a);
    map<lint, lint> cnt;
    lint ans = 0;
    rep(i, n){
        ans += cnt[i+1 - a[i]];
        cnt[i+1+a[i]] ++;
    }
    print(ans);
}
    



Measured memory_bytes: 27372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)



//セグ木ここから
//*
//↓ここを変える
typedef struct atai{ll a,i,f;}atai;
atai xx(atai x,atai y){
	if(x.f==0)return y;
	if(y.f==0)return x;
	if(x.a>y.a){
		return x;
	}else{
		return y;
	}
}
atai aid={0,0,0};
//↑ここを変える

int segNUM;
atai *segN,*seg;
void seguse(int n){
	segN=(atai*)calloc(2*n,sizeof(atai));
	segNUM=n;
	seg=segN+segNUM;
	rep(i,1,2*segNUM)segN[i]=aid;
}
//seg[]に値を与えてから初期化
void seginit(){for(int node=segNUM-1;node;node--)segN[node]=xx(segN[node*2],segN[node*2+1]);}
void segupdate(int node,atai x){
	//seg[node]をxに更新
	node+=segNUM;
	segN[node]=x;
	while(node/=2)segN[node]=xx(segN[node*2],segN[node*2+1]);
}

atai segcalcsub(int l,int r,int k,int cl,int cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return segN[k];

	int cm=(cl+cr)/2;
	//左側だけ
	if(r<=cm)return segcalcsub(l,r,2*k  ,cl,cm);
	//右側だけ
	if(cm<=l)return segcalcsub(l,r,2*k+1,cm,cr);
	//両方
	return xx(segcalcsub(l,r,2*k,cl,cm),segcalcsub(l,r,2*k+1,cm,cr));
}
atai segcalc(int l,int r){return segcalcsub(l,r,1,0,segNUM);}
//セグ木ここまで
//*/

ll a[200010],b[200010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)scanf("%lld",b+i);
	seguse(1<<18);

	ll ans=0,cnt=0;
	rep(i,0,n){
		if(a[i]!=b[i]){
			seg[i].f=1;
			cnt++;
		}else{
			seg[i].f=0;
		}
		seg[i].a=b[i];
		seg[i].i=i;
	}
	seginit();
	
	while(cnt){
		atai x=segcalc(0,1<<18);
		int m=x.i;
		int l=(m-1+n)%n;
		int r=(m+1)%n;
		ll diff=(seg[m].a-a[m])/(seg[l].a+seg[r].a);
		if(diff<1){
			puts("-1");
			return 0;
		}
		ans+=diff;
		x=seg[m];
		x.a-=(seg[l].a+seg[r].a)*diff;
		if(x.a==a[m]){
			cnt--;
			x.f=0;
		}
		segupdate(m,x);
	}
	printf("%lld",ans);
}

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


int main()
{
  int n;
  cin >> n;
  int ans = 0;
  if (n < 10)
    cout << n << endl;
  else if (n < 100)
    cout << 9 << endl;
  else if (n < 1000)
    cout << n - 90 << endl;
  else if (n < 10000)
    cout << 909 << endl;
  else if (n < 100000)
    cout << n - 9090 << endl;
  else
    cout << 90909 << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, h);
    
    int ans = 0;
    int m = 0;
    For(i, n-1){
        if(h[i] >= h[i+1]) m ++;
        else ans = max(ans, m), m = 0;
    }
    ans = max(ans, m);
    Cout(ans);
    
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;

struct edge {
    int to, cost;
};

class dijkstra {
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<P>> que;

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    int find(int e) {
        return d[e];
    }
};

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

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

class Union_Find {
private:
    vector<int> t, s;

public:
    Union_Find(int max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(int x, int y) {
        if (same(x, y)) return;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        } else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        } else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        } else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }

    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(int x, int y) {
        return Find(x) == Find(y);
    }

    int get_Size(int a) {
        return s[a];
    }
};

vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}

int memo[100012];
signed main() {
    set<int> st;
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int in;
        cin>>in;
        st.insert(in);
    }
    memo[0]=1;
    rep(i,n){
        if(st.count(i+1)==0)memo[i+1]+=memo[i];
        if(st.count(i+2)==0)memo[i+2]+=memo[i];
        memo[i+1]%=1000000007;
        memo[i+2]%=1000000007;

    }
    cout<<memo[n]%1000000007<<endl;
}


Measured memory_bytes: 5760
N = int(input())
num=N
S=[]

while int(num) > 0:
    S.append(num % 10)
    num = int(num / 10)
S.reverse()

hako=[]
tmp=0
ans=0
for num in range(1<<(len(S)-1)):      
    tmp=S[0]
    sum=0
    for i in range(len(S)-1):
            if num & (1 << i):
                sum+=tmp
                tmp=0
            tmp = tmp * 10 + S[i+1]
    hako.append(sum+tmp)
    ans+=sum+tmp
        
print(ans)    


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    if (n > m) {
        for (int i = 0; i < n; ++i) cout << m;
    }
    else {
        for (int i = 0; i < m; ++i) cout << n;
    }
}
    

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, K;
    cin >> N >> K;

    VVL s(N);
    rep(i, 0, N){
        ll t, d;
        cin >> t >> d;
        t--;
        s[t].push_back(d);
    }

    rep(i, 0, s.size()){
        sort(ALL(s[i]), greater<ll>());
        if(s[i].empty()) s[i].push_back(-(1LL<<40));
    }

    sort(s.begin(), s.end(), [&](VL a, VL b){return a[0] > b[0];});

    ll now = 0;
    priority_queue<ll> que;
    rep(i, 0, K){
        now += s[i][0];
        rep(j, 1, s[i].size()) que.push(s[i][j]);
    }

    rep(i, K, N){
        rep(j, 0, s[i].size()){
            que.push(s[i][j]);
        }
    }

    ll ans = now + K*K;
    for(ll x = K-1; x >= 1; x--){
        ll v = s[x][0];
        ll w = que.top();
        if(v < w){
            que.pop();
            now += w;
            now -= v;
            que.push(v);
        }
        ans = max(ans, now + x*x);
    }
    cout << ans << endl;
    return 0;
}

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

int x, n;
bool valid[104];
int ans, mn=1e9;

int main(){
	memset(valid,0,sizeof valid);
	cin >> x >> n;
	for (int i=0;i<n;i++){
		int p;
		cin >> p;
		valid[p]=1;
	}
	for (int i=0;i<=101;i++){
		if (!valid[i]){
			if (abs(x-i)<mn){
				mn=abs(x-i);
				ans=i;
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3592
;; E - Payment

(defun solve (n)
  (setf n (nreverse n))
  (loop with s = 0
        and carry = 0
        for c across n
        for x = (+ (digit-char-p c) carry)
        and prev = 0 then x
        if (or (> x 5) (= x prev 5))
          do (when (= prev 5) (incf x 1))
             (incf s (- 10 x))
             (setf carry 1)
        else
          do (incf s x)
             (setf carry 0)
        end
        finally (progn (incf s carry) (return s))))

(let ((n (read-line)))
  (princ (solve n)))


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

using namespace std;

int main(void)
{
    int N; cin >> N;
    
    vector<pair<int,int>> p(N);

    for(int i = 0; i < N; i++)
    {
        int a,b; cin >> a >> b;
        p.at(i) = make_pair(b,a);
    }

    sort(p.begin(),p.end());
    
    int64_t task = 0,deadline = 0;
    bool flag  = true;
    for(int i =  0; i <  N; i++)
    {
        int a,b;
        tie(a,b) = p.at(i);
        deadline = a;
        task += b;
        if(task > deadline) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
using namespace std;

int main(){ 
  int n,x=0,y=0,ans=100000,c=0;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  rep(i,1,n-1){
    if(a[i-1]<a[i] && a[i]<a[i+1]) c++;
    if(a[i-1]>a[i] && a[i]>a[i+1]) c++;
  }
  co(c);
  
  return 0;
}

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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
//void ret_digit(int a){rep(i, count_digit(a)){Dig[i]=a%10;a/=10;}}

int main(void){
 
    int n, y;

    scanf("%d", &n);
    
    y=n%100;
    y=y%10;
    
    if (y==2||y==4||y==5||y==7||y==9) {
        printf("hon");
    } else if (y==0||y==1||y==6||y==8) {
        printf("pon");
    } else if(y==3){
        printf("bon");
    }

    return 0;
}



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

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const long long int INF=0x3f3f3f3f3f3f;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

typedef struct node
{
	ll x,y,left,up,right,down;
}node;

int main()
{
	vivek_ghosh;
	
	cin>>n;
	vl p(n+2);
	p[0]=0;
	p[n+1]=100;
	for(i=1;i<=n;i++)
	{
		cin>>p[i];
	}
	
	for(i=1;i<=n;i++)	
	{
		if(p[i]!=i)
			cnt++;
	}
	
	if(cnt>2)
		cout<<"NO";
	else
		cout<<"YES";
	cout<<endl;
		
		
	
	
	
	return 0;
}







Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int a[N];

int main()
{
	int n;
	cin>>n;
	n%=10;
	if(n==3) cout<<"bon\n";
	else if(n==0||n==1||n==6||n==8) cout<<"pon\n";
	else cout<<"hon\n"; 
	return 0;
}

Measured memory_bytes: 3636
import math
X,N = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while 1:
    if (X-i in p) == False:
        print(X-i)
        break
    elif (X+i in p) == False:
        print(X+i)
        break
    i += 1


Measured memory_bytes: 9204
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Yasuo
{
class Yasuo
{
	static void Main(string[] asrgs)
	{
		int n;
		int a, b, c;
		string s;
		string[] ss;
		bool flag = true;
		List<string> reslist = new List<string>();
		n = int.Parse(Console.ReadLine());
		for(int i = 0; i < n; i++)
		{
			s = Console.ReadLine();
			ss = s.Split(' ');
			a = int.Parse(ss[0]);
			b = int.Parse(ss[1]);
			c = int.Parse(ss[2]);

			flag = false;
			if(a >= b && a >= c)
			{
				if (a*a == b*b + c*c) flag = true;
			}
			else if (b >= a && b >= c)
			{
				if (b*b == a*a + c*c) flag = true;
			}
			else
			{
				if (c*c == a*a + b*b) flag = true;
			}
			if (flag)
			{
				reslist.Add("YES");
			}
			else
			{
			reslist.Add("NO");
			}
		}
		for (int i = 0; i < n; i++)
		{
			Console.WriteLine(reslist[i]);
		}
	}
}
}

Measured memory_bytes: 8980
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>>s(m, vector<int>(10));
	vector<int>p(m),k(m);
	for (int i = 0; i < m; ++i) {
		cin >> k[i];
		for (int j = 0; j < k[i]; ++j) {
			cin>>s[i][j];
		}
	}
	int ans2 = 0;
	for (int i = 0; i < m; ++i)cin >> p[i];
		for (int bit = 0; bit < (1 << n); ++bit){
			int ans = 0;
		for (int j = 0; j < m; ++j) {
			int count = 0;
			for (int i = 0; i < k[j]; ++i) {
				if (bit & (1 << s[j][i]-1)) {
					++count;
				}
			}
				if (count % 2 == p[j])++ans;
		}if (ans == m)++ans2;
	}
	cout << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
  string s;
  cin >> s;
  if (s == "ABC" )
  {
    cout << "ARC" << endl;
  }
  else
  {
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 3528
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <algorithm>
// #include "./Debug.h"

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

int main(void) {

	AtCoder::Num n = AtCoder::replaceToInteger(AtCoder::input());
	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());
	
	int cc = 0;
	int l = n[0] - 1;
	for (int i = 1; i < l; i++) {
		if (s[(i - 1)] > s[i]) {
			if (s[(i + 1)] < s[i]) {
				cc++;
				continue;
			}
		}
		if (s[(i - 1)] < s[i]) {
			if (s[(i + 1)] > s[i]) {
				cc++;
			}
		}
	}

	printf("%d\n", cc);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<string> S(N);
    rep(i, N){
        cin >> S.at(i);
    }
    ll ans = 0;
    rep(A, N){
        vector<string> T(N);
        rep(i, N){
            T.at(i) = S.at((i+A)%N);
        }
        bool sym = true;
        rep(i, N){
            rep(j, N){
                if(T.at(i).at(j) != T.at(j).at(i)){
                    sym = false;
                    break;
                }
            }
            if(!sym){
                break;
            }
        }
        if(sym){
            ans += N;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 200002;

int n, h[maxn], v[maxn];
long long tr[maxn], ans = 0;

int lowbit(int x) {
    return x & (-x);
}

void update(int x, long long val) {
    while (x <= n) {
        tr[x] = max(tr[x], val);
        x += lowbit(x);
    }
}

long long query(int x) {
    long long res = 0;
    while (x > 0) {
        res = max(res, tr[x]);
        x -= lowbit(x);
    }

    return res;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }

    for (int i = 1; i <= n; ++i) {
        cin >> v[i];
    }

    for (int i = 1; i <= n; ++i) {
        long long cur = query(h[i]-1) + v[i];
        ans = max(ans, cur);
        update(h[i], cur);
    }

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

Measured memory_bytes: 3328
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#define Max 2*100002
using namespace std;

struct node{
	char val;
	int index;
};

vector<struct node>vec;

bool cmp(struct node a,struct node b){
	return (a.val == b.val)?(a.index<b.index):(a.val<b.val);
}


int search(char key,int index){
	int start = 0,end = vec.size()-1,mid,resultIndex=-1;
	while(start<=end){
		mid = (start+end)/2;
		if(vec[mid].val == key){

			if(vec[mid].index > index){
				resultIndex = vec[mid].index;
				end = mid-1;
			}else{
				start = mid+1;
			}

		}else if(vec[mid].val < key){
			start = mid+1;
		}else{
			end = mid-1;
		}
	}

	return resultIndex;		
}


int main(){
	char s1[Max],s2[Max];
	int i;
	scanf("%s %s",s1,s2);
	int len1 = strlen(s1);
	int len2 = strlen(s2);

	for(i=0;i<len1;i++){
		struct node tmp;
		tmp.val = s1[i];
		tmp.index = i;
		vec.push_back(tmp);
	}

	sort(vec.begin(),vec.end(),cmp);

	int index,lastIndex=-1;
	long long int min = 0;

	for(i=0;i<len2;){
		index = search(s2[i],lastIndex);

		

		if(lastIndex == -1 && index == -1){
			min = -1;
			break;
		}else if(index == -1){
			min += (len1-lastIndex-1);
			lastIndex = -1;
		}else{
			if(lastIndex == -1){
				min += index+1;
			}else{
				min += (index-lastIndex);
			}
			lastIndex = index;
			i++;
		}
	}

	printf("%lld\n",min);

	return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B;
	cin>>A>>B;
	if(A>8){
    cout<<":("<<endl;
    }
	else if(B>8){
    cout<<":("<<endl;
    }
	else{
    cout<<"Yay!"<<endl;
    } 




}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,a,b;
int q[10000],l[100],head,tail,last,best,ans;
int cantop[100],can[100][100];
bool vis[100],set[100];
void DFS(int x,int len){
	if(len>best){last=x;best=len;}
	vis[x]=true,set[x]=true;
	for(int i=0;i<cantop[x];i++){
		if(!vis[can[x][i]]){
			DFS(can[x][i],len+1);
			vis[can[x][i]]=false;
		}
	}
}
int main(){
	int n;
	while(true){
	cin>>n;
	if(!n)break;
	rep(i,100)cantop[i]=false;
	rep(i,n){
		cin>>a>>b;
		a--,b--;
		can[a][cantop[a]]=b,can[b][cantop[b]]=a;
		cantop[a]++,cantop[b]++;
	}
	rep(i,100)set[i]=false;
	ans=0;
	for(int i=0;i<100;i++){
		if(!set[i]){
		rep(i,100)vis[i]=false;
		best=0;
		DFS(i,1);
		rep(i,100)vis[i]=false;
		best=0;
		DFS(last,1);
		ans=max(ans,best);
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
#include<vector>
using namespace std ;
typedef long long ll;

// N K
// A_1, ..., A_N
int main(){
  int N, A, B ;
  cin >> N >> A >> B ;

  if(A>B){
    cout << B << " ";
  }else{
    cout << A << " ";
  }

  if(A+B>N){
    cout << A+B-N << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 888
from collections import Counter
n = int(input())
s = []
for i in range(n):
  	s.append(input())

s = ["".join(sorted(i)) for i in s]
table = {}

count = 0
for word in s:
  if word in table:
    count += table[word]
    table[word] += 1
  else :
    table[word] = 1
print(count)

Measured memory_bytes: 76760