akhauriyash/Code-Regression huggingface dataset:
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
n=int(input())
print(num2alpha(n).lower())

Measured memory_bytes: 9160
#include <iostream>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;
ll C[32];
ll S[366][32];
ll T[366];
ll P[32];
ll L[32];
set<int> H[32];

uint32_t xor128(void) {
  static uint32_t x = 123456789;
  static uint32_t y = 362436069;
  static uint32_t z = 521288629;
  static uint32_t w = 88675123;
  uint32_t t;

  t = x ^ (x << 11);
  x = y; y = z; z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

ll calcPenalty(int con, int D) {
  ll ret = 0;
  ll prev = 0;
  for (auto& it: H[con]) {
    ll dif = it - prev;
    ret += (dif - 1) * dif / 2;
    prev = it;
  }
  ll dif = D + 1 - prev;
  ret += (dif - 1) * dif / 2;
  ret *= C[con];
  return ret;
}

ll update(int day, int pcon, int ncon, int D) {
  ll pen = -P[pcon] - P[ncon];
  H[pcon].erase(day);
  H[ncon].insert(day);
  T[day] = ncon;
  ll vP = calcPenalty(pcon, D);
  ll vN = calcPenalty(ncon, D);
  pen += P[pcon] + P[ncon];
  ll ret = -pen;
  ret -= S[day][pcon];
  ret += S[day][ncon];
  if (ret > 0) {
    P[pcon] = vP;
    P[ncon] = vN;
    T[day] = ncon;
  } else {
    H[pcon].insert(day);
    H[ncon].erase(day);
  }
  return ret;
}

int main() {
  clock_t time_start = clock();
  ios::sync_with_stdio(false);
  int D;
  cin >> D;
  for (int i=1; i<=26; i++) {
    cin >> C[i];
  }
  for (int i=1; i<=D; i++) {
    for (int j=1; j<=26; j++) {
      cin >> S[i][j];
    }
  }
  for (int day=1; day<=D; day++) {
    ll ocon = 1;
    ll oval = S[day][ocon] + (day - L[ocon]) * C[ocon];
    for (int con=2; con<=26; con++) {
      ll val = S[day][con] + (day - L[con]) * C[con];
      if (val > oval) {
        ocon = con;
        oval = val;
      }
    }
    T[day] = ocon;
    L[ocon] = day;
    H[ocon].insert(day);
  }
  for (int con=1; con<=26; con++) {
    P[con] = calcPenalty(con, D);
  }
  while (1) {
    clock_t time_now = clock();
    if ((double)(time_now - time_start) > (double)CLOCKS_PER_SEC * 1.9) {
      break;
    }
    int day = xor128() % D + 1;
    int ncon = xor128() % 26 + 1;
    int pcon = T[day];
    update(day, pcon, ncon, D);
  }
  for (int day=1; day<=D; day++) {
    cout << T[day] << '\n';
  }
  cout << flush;
}

Measured memory_bytes: 3996
#include<iostream>
using namespace std;
int main(){
  int i,K,h,x,count = 0;
  cin >> i >> K;

  for(int j = 0; j < i; j++){
    x = 0;
    cin >>h;
    x += h;
    if(h >= K){
      count += 1;
    }
  }
  cout << count << endl;
}

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

int queen[9][9];
bool field[9][9];

void check(int r, int c){
    for(int i=0; i<8; i++){
        field[r][i]=true;
        field[i][c]=true;
    }
    for(int i=1;;i++){
        int update=0;
        if(r-i>=0 && c+i<8){
            field[r-i][c+i]=true;
            update++;
        }
        if(r-i>=0 && c-i>=0){
            field[r-i][c-i]=true;
            update++;
        }
        if(r+i<8 && c-i>=0){
            field[r+i][c-i]=true;
            update++;
        }
        if(r+i<8 && c+i<8){
            field[r+i][c+i]=true;
            update++;
        }
        if(update==0){
            break;
        }
    }
}

bool dfs(int h){
    bool copy[9][9];
    if(h==8) return true;
    for(int i=0; i<8; i++){
        if(queen[h][i]==1){
            if(dfs(h+1)){
                return true;
            }else{
                return false;
            }
        }
    }
    for(int i=0; i<8; i++){
        for(int j=0; j<8; j++){
            copy[i][j]=field[i][j];
        }
    }
    for(int i=0; i<8; i++){
        if(field[h][i]) continue;
        queen[h][i]=1;
        check(h, i);
        if(dfs(h+1)){
            return true;
        }
        queen[h][i]=0;
        for(int j=0; j<8; j++){
            for(int k=0; k<8; k++){
                field[j][k]=copy[j][k];
            }
        }
    }
    return false;
}


int main(void){
    int r, c, k;
    
    for(int i=0; i<8; i++){
        for(int j=0; j<8; j++){
            queen[i][j]=0;
            field[i][j]=false;
        }
    }
    cin >> k;
    for(int i=0; i<k; i++){
        cin >> r >> c;
        queen[r][c]=1;
        check(r, c);
    }
    if(dfs(0)){
        for(int i=0; i<8; i++){
            for(int j=0; j<8; j++){
                if(queen[i][j]==1){
                    cout << "Q";
                }
                else{
                    cout << ".";
                }
            }
            cout << "\n";
        }
    }
    return 0;
}



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

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long; using ld = long double;
using P = pair<int, int>;

int main() {
    int dh[4] = {1, 0, -1, 0};
    int dw[4] = {0, 1, 0, -1};
    int h, w;
    cin >> h >> w;
    string a[h];
    rep(i,h) cin >> a[i];
    bool canf = true;
    rep(i,h) rep(j,w) {
            if (a[i][j] == '.') continue;
            bool canp = false;
            rep (k,4) {
                int ni = i + dh[k];
                int nj = j + dw[k];
                if (ni < 0 || ni >= h) continue;
                if (nj < 0 || nj >= w) continue;
                if (a[ni][nj] == '#') canp = true;
            }
            if (!canp) {
                canf = false;
                break;
            }
        }
    if (canf) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,W;
    cin >> N >> W;
    int w[N];
    int v[N];
    for(int i=0;i<N;i++)cin >> w[i] >> v[i];
    vector<vector<long> >dp(N+1,vector<long>(100001,1LL<<40));
    dp[0][0] = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<v[i];j++){
            dp[i+1][j] = dp[i][j];
        }


        for(int j=0;j<=i*1000;j++){
            dp[i+1][j+v[i]] = min(dp[i][j+v[i]],dp[i][j]+w[i]); 
        }
    }
    long ans = 0;
    for(int i=0;i<=100000;i++){
        if(dp[N][i] <= W){
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 80256
#include <stdio.h>
int main(void){
    int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if(a * b > c * d){
	    printf("%d", a * b);
	}else{
	    printf("%d", c * d);
	}
    
}


Measured memory_bytes: 1728
def time_to_sec(time):
    sec = int(time[0:2])*3600
    sec = sec + int(time[3:5])*60
    sec = sec + int(time[6:8])
    return sec


while True:
    timeline = [0] * 86400
    num = int(input())
    if num == 0:
        break
    for i in range(num):
        start,end = input().split()
        start = time_to_sec(start)
        end = time_to_sec(end)
        timeline[start] = timeline[start]+1 
        timeline[end] = timeline[end]-1
    for i in range(1,86400):
        timeline[i] = timeline[i] + timeline[i-1]

    print(max(timeline))



Measured memory_bytes: 9588
a,b,c = map(int,input().split())
k = int(input())
while k>0 and a>=b:
    b *= 2
    k-=1
while k>0 and b >= c:
    c *= 2
    k-= 1
if a < b and b< c:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61612
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        k: i64,
    }

    if a >= k {
        println!("{}", k);
    } else if a+b >= k {
        println!("{}", a);
    } else {
        println!("{}", 2*a+b-k)
    }
}


Measured memory_bytes: 2196
//In the name of God

#include <bits/stdc++.h>
using namespace std;

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

#define int ll

const int N = 2e5+10 , mod = 1e9+7;

int x[N] , L , n;

int go(int m , int l , int r , int id , int pos){
   if(id == 0){
      if(l < 0)
         return L - x[pos];
      return L - (x[pos] - x[l]) + go(m , l - 1 , r , 1 - id , l);
   }
   else{
      if(r == n)
         return x[pos];
      return L - (x[r] - x[pos]) + go(m , l , r + 1 , 1 - id , r);
   }
}

int check(int m){
   int l = m - 1 , r = m + 1;
   return max(go(m , l , r , 0 , m) , go(m , l , r , 1 , m));
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cin >> L >> n;
   for(int i = 0 ; i < n ; i++)
      cin >> x[i];
   int l = -1 , r = n;
   while(r - l > 5000){
      int m1 = (2 * l + r) / 3 , m2 = (l + 2 * r) / 3;
      if(check(m1) > check(m2))
         r = m2;
      else
         l = m1;
   }
   l = max(l , 0ll);
   r = min(r , n - 1);
   int ret = 0;
   for(int i = l ; i <= r ; i++){
      ret = max(ret , check(i));
//      cout << i << " " << check(i) << endl;
   }
   cout << ret;
   return 0;
}


Measured memory_bytes: 1792
def p_c():
    N = int(input())
    before = [0] * 3

    for _ in range(N):
        abc = list(map(int, input().split()))
        for i in range(3):
            abc[i] += max(before[(i + 1) % 3], before[(i + 2) % 3])

        before = abc

    print(max(abc))


if __name__ == '__main__':
    p_c()


Measured memory_bytes: 47484
N, D = [int(_) for _ in input().split()]
X = []
for i in range(N):
    X.append([int(_) for _ in input().split()])

# N, D = [3, 4]
# X = [
# [-3, 7, 8, 2],
# [-12, 1, 10, 2],
# [-2, 8, 9, 3]
# ]

from math import sqrt

ans = 0
for i in range(N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) ** 2
        if sqrt(d) % 1 == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3064
row1 = input()
row2 = input()
k = int(row1)
a = int(row2.split(' ')[0])
b = int(row2.split(' ')[1])
for i in range(a, b + 1):
    if i % k == 0:
        print('OK')
        break
else:
    print('NG')

Measured memory_bytes: 9184
class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.tmp = [i for i in range(6)]
        self.set_cmd = 'NNNNWNNNWNNNENNNENNNWNNN'


    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def next(self,direction):
        for i in range(6):
            self.tmp[i] = self.number[i]

        if direction == 'E':
            self.setNumber(self.tmp[3], self.tmp[1], self.tmp[0], self.tmp[5], self.tmp[4], self.tmp[2])
        elif direction == 'N':
            self.setNumber(self.tmp[1], self.tmp[5], self.tmp[2], self.tmp[3], self.tmp[0], self.tmp[4])
        elif direction == 'S':
            self.setNumber(self.tmp[4], self.tmp[0], self.tmp[2], self.tmp[3], self.tmp[5], self.tmp[1])
        elif direction == 'W':
            self.setNumber(self.tmp[2], self.tmp[1], self.tmp[5], self.tmp[0], self.tmp[4], self.tmp[3])
    def get_result(self):
        return self.number[0]

    def cheak(self,altanative):

        flag = True

        for i in range(len(self.set_cmd)):
            self.next(self.set_cmd[i])
            flag = True
            for j in range(6):
                if self.number[j] != altanative.number[j]:
                    flag = False
                    break
            else:
                if flag == True:
                    return flag

        return flag

dice1 = Dice()
dice2 = Dice()

fig1 = list(map(int,input().split()))
dice1.setNumber(fig1[0],fig1[1],fig1[2],fig1[3],fig1[4],fig1[5])
fig2 = list(map(int,input().split()))
dice2.setNumber(fig2[0],fig2[1],fig2[2],fig2[3],fig2[4],fig2[5])

is_TRUE = dice1.cheak(dice2)
if(is_TRUE):
    print("Yes")
else:
    print("No")













Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
// int N が既に与えられているとする. 

int main(){
  int N ;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (i+1 != vec.at(i)){
      cnt++;
    }
  }
  
  if (cnt == 2 || cnt == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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


int main() {
  int N, A, count, min;
  cin >> N;
  count = 0, min = 1000000000;
  
  for (int i=0; i<N; i++){
    cin >> A;
    
    while (A%2 == 0){
      A /= 2;
      count ++;
    }
    if (min > count) {
      min = count;
    }
    count = 0;
  }
    
   cout << min << endl;
}
 


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

int main(){
	string s;
	cin >> s;
	int res = 0;
	REP(i,4){
		if(s[i] == '+')res++;
		else res--;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main() {
  int N;
  cin >> N;
  v(string) s(N);
  rep(i,N) {
    cin >> s[i];
    sort(rng(s[i]));
  }
  ll ans = 0;
  map<string,int> mp;
  rep(i,N) {
      ans += mp[s[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  vector<ll> A(N);
  ll sumA = 0;
  REPLL(i, N){
    cin >> A[i];
    sumA ^= A[i];
  }
  vector<ll> ans(N, 0);
  REP(i, N){
    ans[i] = sumA^A[i];
  }
  REP(i, N){
    cout << ans[i];
    if(i == N-1){
      cout << endl;
    }else{
      cout << " ";
    }
  }
}

Measured memory_bytes: 6384
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF 1000000000LL
using namespace std;
typedef long long ll;

ll N, M, A[300][300];

int main(void) {
  cin >> N >> M;
  REP(i, 0, N) REP(j, 0, M) cin >> A[i][j], A[i][j]--;

  ll ans = INF, cnt[300];
  REP(i, 0, M) {
    REP(j, 0, M) cnt[j] = 0;
    REP(j, 0, N) REP(k, 0, M) if(A[j][k] != -1) {
      cnt[A[j][k]]++;
      break;
    }
    ll d = max_element(cnt, cnt + M) - cnt;
    REP(j, 0, N) *find(A[j], A[j] + M, d) = -1;
    ans = min(ans, cnt[d]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;

int main(){
	char c;
	string s = "abcdefghijklmnopqrstuvwxyz";
	cin >> c;
	for (int i = 0; i < s.length(); i++){
		if (c == s[i]){
			cout << s[i+1] << endl;
			return 0;
		}
	}
	return 0;
}


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

string str(string&, int&);
char let(string&, int&);
string cip(string&s, int&i) {
	string v = str(s, i);
	while (i < s.size() && s[i] != ']') {
		v += str(s, i);
	}
	return v;
}
string str(string&s, int&i) {
	if (s[i] == '[') {
		i++; string v = cip(s, i); i++;
		reverse(v.begin(), v.end());
		return v;
	}
	string v; v += let(s, i); i++;
	return v;
}
char let(string&s, int&i) {
	if (s[i] == '?' || isalpha(s[i]))return s[i];
	if (s[i] == '+') {
		i++; char v = let(s, i);
		if (v == '?')return v;
		return ((v - 'A') + 1) % 26 + 'A';
	}
	i++; char v = let(s, i);
	if (v == '?')return v;
	return ((v - 'A') + 25) % 26 + 'A';
}
int main() {
	string s;
	while (cin >> s, s != ".") {
		int i = 0;
		string t = cip(s, i);
		replace(t.begin(), t.end(), '?', 'A');
		cout << t << endl;
	}
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n; cin >> n;
    vector<int> lis(n), ans;
    REP(i, 0, n){cin >> lis[i];}
    REP(i, 0, n){
        int f = 0;
        for(int l = lis.size()-1; l >= 0; l--){
            if(lis[l] == l+1){
                ans.pb(lis[l]);
                lis.erase(lis.begin() + l);
                f = 1;
                break;
            }
        }
        if(f == 0){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = n-1; i >= 0; i--){
        cout << ans[i] << endl;
    }
}

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

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
	int n,m,a,b;
	int ans;

	cin >> n >> m ;

	UnionFind uf(n);

	rep(i,m) {
		cin >> a >> b ;
		a--;
		b--;
		uf.unite(a, b);
	}
	ans=1;
	rep(i,n) {
		if(ans<uf.size(i)) ans=uf.size(i);
	}
	cout << ans << endl;
	return 0;
}

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

int ppp(int* arr, int n){
    int a = -1000000003;
    int b = arr[0];//min number
    int c = 0;//to store the temp number
    for(int i=1; i<n; i++){
        if(arr[i] < b) b = arr[i];
        c = arr[i] - b;
        if(c>a) a = c;
    }
    return a;
}
int test(int *arr, int n){
    int i=0;
    for(i=1; i<n; i++){
        if(arr[i]-arr[i-1]>0) return 0;
    }
    return 1;
}
int xxx(int*arr, int n){
    int a = -1000000003;
    int c = 0;//to store the temp number
    for(int i=0; i<n-1; i++){
        c = arr[i+1] - arr[i];
        if(c>a) a = c;
    }
    return a;
}

int main(int argc, char** argv) {
    int N, counter;
    scanf("%d", &N);
    int arr[N];
    for(counter=0; counter<N;counter++){	
	scanf("%d", &arr[counter]);
    }
    int result;
    if (test(arr, N)==1){
        result = xxx(arr, N);
    }
    else result = ppp(arr, N);
    printf("%d\n", result);
    
    return 0;
}




Measured memory_bytes: 2548
#include <iostream>

using namespace std;

int main() {
	int N;
	int A[111];
	int oddc = 0;;
	int ans = 1;

	cin >> N;
	for(int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if(A % 2 == 0) oddc++;;
	}

	for(int i = 0; i < N; i++) {
		ans *= 3;
	}
	
	
	int odd = 1;
	for(int i = 0; i < oddc; i++) {
		odd *= 2;
	}
	ans -= odd;
		
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	int n, k;
	cin >> n >> k;
	int ans = n / k;
	if(n % k > 0) ans++;
	cout << ans;
}                                

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int cnt[4];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        if(s == "AC"){
            cnt[0]++;
        }else if(s == "WA"){
            cnt[1]++;
        }else if(s == "TLE"){
            cnt[2]++;
        }else{
            cnt[3]++;
        }
    }
    cout << "AC x " << cnt[0] << endl;
    cout << "WA x " << cnt[1] << endl;
    cout << "TLE x " << cnt[2] << endl;
    cout << "RE x " << cnt[3] << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int tag[N], n, x, y, m, ans, siz[N];
vector<int>v;
int main()
{
	scanf("%d%d", &n, &m);
	tag[1] = 1;
	for (int i = 1; i <= n; i++)
		siz[i] = 1;
	while (m--)
	{
		scanf("%d%d", &x, &y);
		if (tag[x])
			tag[y] = 1;
		siz[x]--;
		siz[y]++;
		if (siz[x] == 0)
			tag[x] = 0;
	}
	for (int i = 1; i <= n; i++)
		ans += tag[i];
	cout << ans;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

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


    string s;
    cin >> s;
    if(s == "ARC")
        cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

Measured memory_bytes: 3636
n = int(input())
p = list(map(int,input().split()))
ans = "NO"
if p == sorted(p):
    ans = "YES"
for i in range(n-1):
    for j in range(i+1,n):
        p[i], p[j] = p[j], p[i]
        if p == sorted(p):
                ans = "YES"
        p[i], p[j] = p[j], p[i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  string S;
  ll K;
  cin >> S >> K;
  for (int i = 0; i < min((long long)S.size(), K); i++)
  {
    if (S[i] >= '2')
    {
      cout << S[i] << endl;
      return 0;
    }
  }
  cout << '1' << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import math
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
e = 0

for i in range(len(L)):
    s = 0
    s = L[i]
    for j, b in enumerate(L[i+1:]):
        if L[i] == b:
            continue
        g = s + b
        for w, n in enumerate(L[i+j+2:]):
            if n == b or n == L[i]:
                continue

            a = g - n
            if a > 0:
                e += 1

print(e)


Measured memory_bytes: 27164
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
string S;
int N;
int nearestR[100005];
int nearestL[100005];
int num[100005];
int main() {
    cin >> S;
    N = S.length();
    int last = 0;
    for (int i=0; i<N; i++){
        if (S[i] == 'R') last = i;
        nearestR[i] = last;
    }
    last = N-1;
    for (int i=N-1; i>=0; i--){
        if (S[i] == 'L') last = i;
        nearestL[i] = last;
    }
    for (int i=0; i<N; i++){
        if (S[i] == 'R'){
            (nearestL[i]-i)%2 == 0 ? num[nearestL[i]]++ : num[nearestL[i]-1]++;
        } else {
            (i-nearestR[i])%2 == 0 ? num[nearestR[i]]++ : num[nearestR[i]+1]++;
        }
    }
    for (int i=0; i<N; i++){
        printf("%d ", num[i]);
    } cout << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    char s[n];
    for(int i = 0; i < n; i++){
        scanf("\n %c",&s[i]);
    }

    bool c[4];
    for(int i = 0; i < 4; i++){
        c[i] = true;
    }

    int count = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'P' && c[0] == true){
            count++;
            c[0] = false;
        }else if(s[i] == 'W' && c[1] == true){
            count++;
            c[1] = false;
        }else if(s[i] == 'G' && c[2] == true){
            count++;
            c[2] = false;
        }else if(s[i] == 'Y' && c[3] == true){
            count++;
            c[3] = false;
        }
        if(count == 4){
            break;
        }
    }

    if(count == 3){
        printf("Three\n");
    }
    if(count == 4){
        printf("Four\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main (){
	int h1, m1, h2, m2, k;
	scanf ("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	int n = ((h2-h1)*60)+(m2-m1)-k;
	printf ("%d\n", n);
	return 0;
}

Measured memory_bytes: 1668
import sys
import numpy as np

def Ss():
  return sys.stdin.readline().rstrip().split(' ')

def Is():
  ss = Ss()
  return map(int, ss) if len(ss) > 1 else int(ss[0])

a, l = Is()

if l % 2 == 0 and 2*a <= l <= 4*a:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 26992
//chef and strings
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

int main()
{ 
	
	int n;
	cin>>n;
	map<string,int> count;
	range(i,0,n)
	{
		string s;
		cin>>s;
		count[s]++;
	}
	cout<<"AC x "<<count["AC"]<<endl;
	cout<<"WA x "<<count["WA"]<<endl;
	cout<<"TLE x "<<count["TLE"]<<endl;
	cout<<"RE x "<<count["RE"]<<endl;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,K;
    cin >> N >> K;
    vector<double> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    for(int i = 0;i < N;i++) {
        vec.at(i) = (1 + vec.at(i)) * vec.at(i) / 2 / vec.at(i);
    }
    double ret = 0;
    double cnt = 0;
    for(int i = 0;i < K;i++) {
        ret += vec.at(i);
        cnt += vec.at(i);
    }
    for(int i = K;i < N;i++) {
        cnt -= vec.at(i - K);
        cnt += vec.at(i);
        ret = max(ret,cnt);
    }
    cout << fixed;
    cout << setprecision(10) << ret  << endl;
}

Measured memory_bytes: 1792
import math
N=int(input())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
for i in range(N):
    x[i],y[i]=map(int,input().split())
M=10000
ans=0
for i in range(M):
    Vx=math.cos(2*i*math.pi/M)
    Vy=math.sin(2*i*math.pi/M)
    X=0
    Y=0
    for j in range(N):
        if Vx*x[j]+Vy*y[j]>=0:
            X+=x[j]
            Y+=y[j]
    ans=max(ans,X*X+Y*Y)
print(math.sqrt(ans))

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1e9+7

using namespace std;

int main()
{
  ll h, _;
  cin >> h >> _;
  rep(i, h) {
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
}


Measured memory_bytes: 256
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]


def solve(N):
    if N%1000 == 0:
        return 0
    num = N//1000
    return (num+1)*1000-N
N = rri()
print(solve(N))

Measured memory_bytes: 64728
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int h,w;
    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            string tmp;
            cin >> tmp;
            if(tmp=="snuke") printf("%c%d\n",j+65,i+1);
        }
    }
    return 0;
}

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

typedef long long ll;
const int maxn = 100005;

int n, m, v, p, a[maxn];
ll sum[maxn];

int check(int x)
{
	if (a[x] + m < a[p]) return 0;
	return (ll)(a[x] + m) * (x - p) - (sum[x - 1] - sum[p - 1]) >= (ll)m * (v - (p - 1) - (n - x + 1));
}

int main()
{
	scanf("%d%d%d%d", &n, &m, &v, &p);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, greater<int>());
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];

	int l = p, r = n, mid;
	while (l < r) {
		mid = (l + r + 1) >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}

	printf("%d\n", l);
	
	return 0;
}


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


int main() {
  int N; cin >> N;
  vector<int> X(N), Y(N);
  for(int i=0; i<N; i++){
    cin >> X[i];
    Y[i] = X[i];
  }

  sort(X.begin(), X.end());
  if(X[N/2-1] == X[N/2]){
    for(int i=0; i<N; i++) cout << X[N/2] << endl;
  }
  else {
    for(int i=0; i<N; i++){
      if(Y[i] <= X[N/2-1]) cout << X[N/2] << endl;
      else cout << X[N/2-1] << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 3712
import bisect

n,l,t = map(int, input().split())
xw = [list(map(int, input().split())) for i in range(n)]
clockwise = []
anticlockwise = []
ans = [None] * n
for key,(x,w) in enumerate(xw):
    if w == 1:
        clockwise.append((x,key))
    else:
        anticlockwise.append((x,key))

len_c = len(clockwise)
len_a = len(anticlockwise)
for key,(x,w) in enumerate(xw):
    if w == 1:
        tmp = bisect.bisect_right(anticlockwise, ((2*t+x)%l,1000000)) - bisect.bisect_right(anticlockwise,(x,0))
        lap = (x+2*t) // l
        num = (key + tmp + lap * len_a) % n
        ans[num] = (x + t) % l
    else:
        tmp = bisect.bisect_left(clockwise, (x,-1)) - bisect.bisect_left(clockwise, ((x-2*t)%l,-1))
        lap = (x-2*t) // l
        num = (key - tmp + lap * len_c) % n
        ans[num] = (x - t) % l

for i in ans:
  print(i)

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int mx = 0;
    ll ans = 0;

    for (int i = 0; i < n; i++) {
        ans += max(0, mx - a[i]);
        mx = max(mx, a[i]);
    }

    cout << ans << "\n";
    return 0;
}

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

const int INF = 1e9;

int main() {
	int V, E, r;
	cin >> V >> E >> r;
	vector<vector<pair<int, int>>> G(V, vector<pair<int, int>>());
	for (int i=0;i<E;i++) {
		int s, t, d;
		cin >> s >> t >> d;
		pair<int, int> p = make_pair(t, d);
		G[s].push_back(p);
	}

	vector<int> cost(V, -1);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	pair<int, int> first = make_pair(0, r); // first: cost, second: vertex
	pq.push(first);
	while (!pq.empty()) {
		pair<int, int> rem = pq.top();
		pq.pop();
		if (cost[rem.second] != -1) continue;
		cost[rem.second] = rem.first;
		for (pair<int, int> p : G[rem.second]) {
			if (cost[p.first] == -1) {
				pair<int, int> tmp = make_pair(rem.first+p.second, p.first);
				pq.push(tmp);
			}
		}
	}

	for (int i=0;i<V;i++) {
		if (cost[i] == -1) {
			cout << "INF" << endl;
		} else {
			cout << cost[i] << endl;
		}
	}
}


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

main() {
    while(1) {
        int h, w;
        cin >> h >> w;
        if(!h) return 0;
        vector<vector<int>> a(h, vector<int>(w));
        rep(i, h) rep(j, w) cin >> a[i][j];
        int ans = 0;
        rep(i, h) rep2(ii, i, h - 1) rep(j, w) rep2(jj, j, w - 1) {
            int d = 0;
            if(i + 1 >= ii or j + 1 >= jj) continue;
            rep2(iii, i + 1, ii - 1) {
                rep2(jjj, j + 1, jj - 1) { d = max(d, a[iii][jjj]); }
            }
            int D = INT_MAX;
            rep2(jjj, j, jj) D = min({D, a[i][jjj], a[ii][jjj]});
            rep2(iii, i, ii) D = min({a[iii][j], a[iii][jj], D});
            if(D <= d) continue;
            int now = 0;
            rep2(iii, i + 1, ii - 1) rep2(jjj, j + 1, jj - 1) now += D - a[iii][jjj];
            ans = max(ans, now);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split("/");
        int y = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        int d = Integer.parseInt(s[2]);
        if(y < 2019) {
            System.out.println("Heisei");
        }else if(y == 2019) {
            if(m < 4) {
                System.out.println("Heisei");
            }else if(m == 4) {
                if(d <= 30) {
                    System.out.println("Heisei");
                }else {
                    System.out.println("TBD");
                }
            }else {
                System.out.println("TBD");
            }
        }else {
            System.out.println("TBD");
        }
    }
}


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

int main() {
    int N, K;
    std::cin >> N >> K;

    int cnt = 0, h;
    for (int i = 0; i < N; ++i) {
        std::cin >> h;
        if (K <= h) {
            ++cnt;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    ll x;
    cin >> x;
    ll ans = x / 11 * 2;
    x %= 11;
    if(x > 0){
        if(x <= 6)  ++ans;
        else    ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k=sc.nextLong();
		int n=50;
		long[] a=new long[50];
		Arrays.fill(a,49+k/50);
		System.out.println(50);
		for(int i=0; i<50; i++){
			if(i<k%50){
				a[i]+=51-k%50;
			}else{
				a[i]-=k%50;
			}
			System.out.println(a[i]);
		}
	}
}


Measured memory_bytes: 23120
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    int s[3];
    char ch;
    int i=0;
    F(i,0,3){
        cin >> s[i];
        if(i!=2) cin >> ch;
    }
    
    if(s[0] <= 2019 && s[1] <= 4 && s[2] <= 30){
        cout << "Heisei" << endl;
    }
    else{
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long h,n;
    cin>>h>>n;
    long long a[n];
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        h = h-a[i];
    }
    if(h>0)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  ll ret = A * X + B * Y;
  ll tmp1 = C * 2 * X + B * max(Y - X, 0LL);
  ll tmp2 = C * 2 * Y + A * max(X - Y, 0LL);
  ret = min(ret, min(tmp1, tmp2));
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    unsigned int A;
    unsigned int B;
    scanf("%u %u", &A, &B);
    if (A >= 1 && A <= 9 && B >= 1 && B <= 9)
    {
        printf("%u", A * B);
    }
    else{
        printf("-1");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;
	return 0;
}

Measured memory_bytes: 3556
# coding: utf-8
import sys
sys.setrecursionlimit(2147483647)
def check(p):
    global field
    if(field[p[1]][p[0]]=='1'):
        field[p[1]][p[0]]='0'
    if(0<=p[0]+1<w and field[p[1]][p[0]+1]=='1'):
        check((p[0]+1,p[1]))
    if(0<=p[0]-1<w and field[p[1]][p[0]-1]=='1'):
        check((p[0]-1,p[1]))
    if(0<=p[1]+1<h and field[p[1]+1][p[0]]=='1'):
        check((p[0],p[1]+1))
    if(0<=p[1]-1<h and field[p[1]-1][p[0]]=='1'):
        check((p[0],p[1]-1))
    if(0<=p[0]+1<w and 0<=p[1]-1<h and field[p[1]-1][p[0]+1]=='1'):
        check((p[0]+1,p[1]-1))
    if(0<=p[0]-1<w and 0<=p[1]-1<h and field[p[1]-1][p[0]-1]=='1'):
        check((p[0]-1,p[1]-1))
    if(0<=p[0]+1<w and 0<=p[1]+1<h and field[p[1]+1][p[0]+1]=='1'):
        check((p[0]+1,p[1]+1))
    if(0<=p[0]-1<w and 0<=p[1]+1<h and field[p[1]+1][p[0]-1]=='1'):
        check((p[0]-1,p[1]+1))
     
while 1:
    ans=0
    w,h=map(int,input().split())
    if w==0:
        break
    field=[]
    for i in range(h):
        s=''.join(input().split())
        field.append(list(s))
    for i in range(h):
        for j in range(w):
            if field[i][j]=='1':
                check((j,i))
                ans+=1
    print(ans)


Measured memory_bytes: 7900
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		int[] l = new int[q];
		int[] r = new int[q];
		int[] d = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			r[i] = n - Integer.parseInt(sa[0]) + 1;
			l[i] = n - Integer.parseInt(sa[1]);
			d[i] = Integer.parseInt(sa[2]);
		}
		br.close();

		int mod = 998244353;
		long[][] dp = new long[10][n];
		for (int i = 1; i < 10; i++) {
			dp[i][0] = i;
		}
		for (int i = 1; i < n; i++) {
			dp[1][i] = dp[1][i - 1] * 10 % mod;
		}
		for (int i = 1; i < n; i++) {
			dp[1][i] += dp[1][i - 1];
		}
		for (int i = 2; i < 10; i++) {
			for (int j = 1; j < n; j++) {
				dp[i][j] = dp[i - 1][j] + dp[1][j];
				dp[i][j] %= mod;
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		long ans = dp[1][n - 1];
		TreeMap<Integer, Integer> map = new TreeMap<>();
		map.put(0, 1);
		for (int i = 0; i < q; i++) {
			SortedMap<Integer, Integer> sm = map.subMap(l[i], r[i]);
			Integer ok = map.lowerKey(l[i]);
			if (ok == null) {
				ok = l[i];
			}
			int ov = map.get(ok);
			ok = l[i];
			for (int key : sm.keySet()) {
				if (key > 0) {
					ans -= dp[ov][key - 1];
				}
				if (ok > 0) {
					ans += dp[ov][ok - 1];
				}
				ok = key;
				ov = sm.get(key);
			}
			ans -= dp[ov][r[i] - 1];
			if (ok > 0) {
				ans += dp[ov][ok - 1];
			}
			sm.clear();
			map.put(l[i], d[i]);
			if (!map.containsKey(r[i])) {
				map.put(r[i], ov);
			} else if (map.get(r[i]) == d[i]) {
				map.remove(r[i]);
			}
			ans += dp[d[i]][r[i] - 1];
			if (l[i] > 0) {
				ans -= dp[d[i]][l[i] - 1];
			}
			ans %= mod;
			if (ans < 0) {
				ans += mod;
			}
			pw.println(ans);
		}
		pw.flush();
	}
}


Measured memory_bytes: 98160
#TLEした
#方針　もっとも近い敵でない島の集まりを調べると区間スケジュール問題となる。
#一列に並んでいるので飛んだ島とは繋げない
#橋の取り壊しの最小値というが、分割としてはもっとも番号の若いものまでしか無理である。
#最近接の敵である島の数字をもつ配列を考える。

#TLEの解決さく最小値順に初めから並べ替えておく。そのとき島の位置がindexkara
#測れないのでtupleを作っていく。

from operator import itemgetter
N,M = (int(_) for _ in input().split())
mostNeightborOpponent = [(N+1,i+1) for i in range(N)]
#print(mostNeightborOpponent)
for i in range(M):
    a,b = (int(_) for _ in input().split())
    if mostNeightborOpponent[a-1][0] > b:
        mostNeightborOpponent[a-1] = (b,a) #tupleを作るsortは第一引数を考えるので順序はこの順
#print(mostNeightborOpponent)
#island:・・・島|島・・・の右の島のindex
island = 1
bridgeWillBreak = 0

sortedOpponent = sorted(mostNeightborOpponent,key = itemgetter(0))

for b,a in sortedOpponent:
    if a < island :
        continue
    island = b
    if island > N :
        break
    bridgeWillBreak += 1

print(bridgeWillBreak)


Measured memory_bytes: 18440
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict



lst = []

for case_num in range(int(input())):
    # read line as a string
    lst.append(input())

    
c = Counter(lst)


print("AC x {}".format(c["AC"]))
print("WA x {}".format(c["WA"]))
print("TLE x {}".format(c["TLE"]))
print("RE x {}".format(c["RE"]))




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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int dist[10][10];

void Warshall_Floyd()
{
    rep(k, 10) rep(i, 10) rep(j, 10)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main()
{
    int H, W;
    cin >> H >> W;
    rep(y, 10) rep(x, 10) cin >> dist[y][x];

    Warshall_Floyd();

    int ans = 0;

    rep(y, H) rep(x, W)
    {
        int input;
        cin >> input;

        if(input == -1) continue;
        
        ans += dist[input][1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int main() {
	int k; cin >> k;
	loop(i, k) cout << "ACL";
	return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0594 : Super Metropolis **/
int main()
{
	int W, H, N;
	cin>>W>>H>>N;
	int sx, sy, gx, gy;
	cin>>sx>>sy;
	int ans=0;
	
	rep(i, N-1) {
		cin>>gx>>gy;
		
		while (1) {
			if (sx==gx && sy==gy)
				break;
			
			if (sx>gx && sy>gy) {
				sx--; sy--;
				ans++;
			}
			
			else if (sx<gx && sy<gy) {
				sx++; sy++;
				ans++;
			}
			
			else if (sx>gx && sy<gy) {
				sx--; sy++;
				ans+=2;
			}
			
			else if (sx<gx && sy>gy) {
				sx++; sy--;
				ans+=2;
			}
			
			else if (sx==gx && sy>gy) {
				sy--;
				ans++;
			}
			
			else if (sx==gx && sy<gy) {
				sy++;
				ans++;
			}
			
			else if (sx>gx && sy==gy) {
				sx--;
				ans++;
			}
			
			else if (sx<gx && sy==gy) {
				sx++;
				ans++;
			}
		}
		sx = gx, sy = gy;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1160