akhauriyash/Code-Regression huggingface dataset:
fun main(args:Array<String>) {
    val mod = 1000000007L
    val (N, D) = readLine()!!.split(" ").map(String::toInt)

    val A = Array(N){ readLine()!!.split(" ").map { it.toInt() }.toIntArray()}

    fun dist(Y:IntArray , Z:IntArray ):Int  {
        var res = 0

        for((y,z) in Y.zip(Z))
            res += Math.pow(Math.abs(y-z).toDouble(),2.0).toInt()

        return res
    }

    var ans = 0

    val list = IntArray(200){it*it}

    for (i in 0 until N-1)
        for (j in i+1 until N) {
            val dist = dist(A[i], A[j])
            for (k in list) {
                if (k == dist) ans++
                if (k >= dist) break
            }
        }

    println(ans)
}

Measured memory_bytes: 37808
use std::io;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("Failed");
    return buf;
}

fn main() {
    let mut n: isize = read_line().trim().parse().unwrap();
    let a: isize = read_line().trim().parse().unwrap();
    n -= 500*(n/500);
    if n <= a {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4476
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,q;
  cin>>n;
  vlong a(n);
  rep(i,n){
    cin>>a[i];
  }
  cin>>q;
  rep(i,q){
    int tmp,a2,b;
    cin>>tmp>>a2>>b;
    if(tmp==0){
      cout<<*min_element(a.begin()+a2,a.begin()+b)<<'\n';
    }
    else{
      cout<<*max_element(a.begin()+a2,a.begin()+b)<<'\n';
    }
  }
  return(0);
}


Measured memory_bytes: 3176
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		double A[]=new double[N];
		int z=0;
		while(z<N){
			A[z]=stdIn.nextDouble();
			z++;
		}z=0;
		Arrays.sort(A);
		while(z<N-1){
			A[z+1]=(A[z]+A[z+1])/2;
			z++;
		}
		System.out.println(A[z]);
	}
}

Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int a[5];
    rep(i,5)cin>>a[i];
    sort(a,a+5);
    int k;
    cin>>k;
    if(a[4]-a[0]<=k){
        cout<<"Yay!"<<endl;
    }
    else cout<<":("<<endl;
    return 0;
}

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

main()
{

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

    long long i,j,k,l,m,n,p;

    string s;

    while(cin>>s){
        l=0;p=0;
        for(i=0;i<3;i++){ l=0;
            while(s[i]=='R'&&i<3){
                i++;
                l++;
            }
            p=max(p,l);
        }
        cout<<p<<endl;

    }

    return 0;
}


Measured memory_bytes: 3620
x,y=map(int,raw_input().split())
if x>=0 and y==0:
    print(x+1)
elif x<=0 and y==0:
    print(-x)
elif x>=0 and y>=0:
    if abs(y)>=abs(x):
        print(y-x)
    else:
        print(x-y+2)
elif x>=0 and y<=0:
    if abs(x)>=abs(y):
        print(x+y+1)
    else:
        print(-y-x+1)
elif x<=0 and y<=0:
    if abs(x)>=abs(y):
        print(y-x)
    else:
        print(x-y+2)
else:
    if abs(x)>=abs(y):
        print(-x-y+1)
    else:
        print(y+x+1)


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int n;
int D1, D2;
bool vis[666][666];
void work(int D){
	int t = 0;
	while(D % 4 == 0)t++, D >>= 2;
	if(D % 4 == 1){
		for(int i = 0;i < n; i++){
			for(int j = 0;j < n; j++){
				if((i >> t & 1) + (j >> t & 1) == 1)vis[i][j] = 1;
			}
		}
	}
	if(D % 4 == 2){
		for(int i = 0;i < n; i++){
			for(int j = 0;j < n; j++){
				if(i >> t & 1)vis[i][j] = 1;
			}
		}
	}
}
int main(){
	cin>>n>>D1>>D2;
	n <<= 1;
	work(D1); work(D2);
	int tot = (n >> 1) * (n >> 1);
	for(int i = 0;i < n; i++){
		for(int j = 0;j < n; j++){
			if(!vis[i][j]){
				printf("%d %d\n", i, j);
				tot--;
				if(!tot)exit(0);
			}
		}
	}
	return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  
  int a[n+1];
  for(int i = 0;i<n;i++)cin >> a[i];
  
  n--;
  k--;
  
  cout << (n+k-1)/k << endl;
  return 0;
}

Measured memory_bytes: 892
n,k=map(int,input().split())
ab=[]
for i in range(n):
  aa,bb=map(int,input().split())
  ab.append([aa,bb])
ab.sort(key=lambda x: x[0])
a,b=[],[]
for aa,bb in ab:
  a.append(aa)
  b.append(bb)
from itertools import accumulate
c=list(accumulate(b))
idx=-1
for i in range(n):
  if i==0:
    if 0<=k<=c[i]:
      idx=i
      break
    continue
  if c[i-1]<k<=c[i]:
    idx=i
    break
print(a[idx])

Measured memory_bytes: 27112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    long long int n,i,sum=0;
    cin >> n;
    for(i=1; i<=n; i++)
    {
        if(i%3 == 0 && i%5 == 0)
        {
            continue;
        }
        else if(i%3 == 0)
        {
            continue;
        }
        else if(i%5 == 0)
        {
            continue;
        }
        else
        {
            sum+=i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3660
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    a = [int(x) for x in input().split()]

    ans = 10 ** 11
    for bit in range(1 << N):
        can = set()
        for i in range(1, N):
            if bit & (1 << i):
                can.add(i)
        h_max = a[0]
        cost = 0
        cnt = 1
        for i in range(1, N):
            res = h_max - a[i] + 1 if i in can and a[i] <= h_max else 0
            cost += res
            cnt += 1 if a[i] + res > h_max else 0
            h_max = max(h_max, a[i] + res)
        if cnt >= K:
            ans = min(ans, cost)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#include<iostream>

int main(){
    int a, b;

    std::cin >> a >> b;

    if(a < b){
        std::cout << "a < b" <<std::endl;
    }else if(a > b){
        std::cout << "a > b" <<std::endl;
    }else {
        std::cout << "a == b" <<std::endl;
    }
    
    return 0 ;
}


Measured memory_bytes: 3092
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,m,k = LI()
    d = LI_()
    v = [LI_() for _ in range(n)]
    dd = collections.defaultdict(lambda: None)
    for i in range(m):
        dd[d[i]] = i
    vv = []
    for c in d:
        vv.append([dd[v[c][i]] for i in range(k)])
    vvv = [[vv[i][j] for i in range(m)] for j in range(k)]
    u = set()
    m2 = 2**m
    u.add(m2-1)
    q = [(m2-1, 1)]
    ii = [2**_ for _ in range(m)]
    # print('vv',vv)
    while q:
        qd, qk = q.pop(0)
        # print('q', qd,qk)
        qdi = [di for di in range(m) if qd & ii[di]]
        for vi in range(k):
            t = 0
            vvi = vvv[vi]
            for di in qdi:
                if not vvi[di] is None:
                    t |= ii[vvi[di]]
            # print('vit',vi,t)
            if t in u:
                continue
            if t == 0:
                return qk
            u.add(t)
            q.append((t,qk+1))

    return -1



print(main())




Measured memory_bytes: 15204
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll x;
	cin>>x;
	ll hp=0;
	while (x>=5){
		if(x>=500){
			ll r = x/500;
			hp+=(r*1000);
			x = x%500;
			
			}
		else{
			
			ll r = x/5;
			hp+=(r*5);
			x = x%5;
			
			}
		
		}
		cout<<hp<<endl;
	
	
	}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
#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(v) v.begin(),v.end()

int main() {
    int s,w;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe\n";
    } else {
        cout << "safe\n";
    }
    return 0;
}

Measured memory_bytes: 3632
S = input()
S = S+"0"
max = 0
j = -1
for i in range(0, len(S)):
    if not(S[i]=="A" or S[i]=="C" or S[i]=="G" or S[i]=="T"):
        if max<i-j-1:
            max = i-j-1
        j = i
print("{}".format(max))


Measured memory_bytes: 3060
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_cond(T, A, B, h):

    s = 0
    for i in range(len(h)):
        h_new = h[i] - B*T
        if h_new > 0:
            s += h_new / (A - B) + (0 if h_new % (A - B) == 0 else 1)

    return s <= T

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    h = []
    for i in range(N):
        input_raw = read_func().strip().split()
        h.append(long(input_raw[0]))
    
    l = 0L
    r = max(h)/B + 1
    while(1):
        #print l r
        if abs(l - r) <= 1:
            print r
            break
        T = (l + r)/2
        if is_cond(T, A, B, h) == True:
            r = T
        else:
            l = T


if __name__ == '__main__':
    main()

Measured memory_bytes: 10068
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD = 998244353;
const ll inf = 1e18;

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

    ll n, s;
    cin >> n >> s;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }
    
    // dp[i][x] : R == i のとき和が x になる場合の数
    vvll dp(n + 1, vll(3010));
    ll res = 0;
    REP(i, n) {
        REPR(j, s + 1) {
            dp[i + 1][j] = dp[i][j];
            if (j == 0) {
                // L \in [0, i], R == i をまとめる
                dp[i + 1][a[i]] += i + 1;
                dp[i + 1][a[i]] %= MOD;
            }
            // j != 0 からの推移では L を固定済
            else if (j + a[i] <= s) {
                dp[i + 1][j + a[i]] += dp[i][j];
                dp[i + 1][j + a[i]] %= MOD;
            }
        }
        res += dp[i + 1][s];
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 71040
struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

var scanner = Scanner()
let N = scanner.nextInt()
let K = scanner.nextInt()
let P = (0 ..< N).map { _ in scanner.nextInt() - 1 }
let C = (0 ..< N).map { _ in scanner.nextInt() }

var answer = Int.min

for i in 0 ..< N {
    var k = i
    var cycleLength = 0
    var scorePerCycle = 0
    repeat {
        k = P[k]
        scorePerCycle += C[k]
        cycleLength += 1
        if cycleLength <= K {
            answer = max(answer, scorePerCycle)
        }
    } while k != i

    let useCycle = max(0, K / cycleLength - 1)
    var score = useCycle * scorePerCycle
    if useCycle != 0 {
        answer = max(answer, score)
    }
    for _ in 0 ..< K - useCycle * cycleLength {
        k = P[k]
        score += C[k]
        answer = max(answer, score)
    }
}

print(answer)


Measured memory_bytes: 8420
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]>x:
        ans+=a[i]-x
        a[i]=x
for i in range(n-1):
    ta=a[i]+a[i+1]
    if ta>x:
        ans+=ta-x
        a[i+1]-=ta-x
print(ans)

Measured memory_bytes: 14252
import re

S = input()

if S[0] != 'A':
  print('WA')
  exit()

if S[2:-1].count('C') != 1:
  print('WA')
  exit()

if re.match(r'A[a-z]+C[a-z]+\Z', S) == None:
  print('WA')
  exit()

print('AC')


Measured memory_bytes: 3188
#include<algorithm>
#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
    int x=0;char ch=getchar();
    while (ch<'0'||ch>'9')ch=getchar();
    while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x;
}
int n,a[MN+5],rk[MN+5];long long ans[MN+5];
bool cmp(int x,int y){return a[x]>a[y];}
int main()
{
    n=read();
    for(int i=1;i<=n;++i) a[i]=read(),rk[i]=i;
    sort(rk+1,rk+n+1,cmp);
    for(int i=1,j,now=1e9;i<=n;i=j)
    {
        for(j=i;j<=n&&a[rk[j]]==a[rk[i]];++j) now=min(now,rk[j]);
        ans[now]+=1LL*(j-1)*(a[rk[i]]-a[rk[j]]);
    }
    for(int i=1;i<=n;++i) printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 2688
s = gets.to_s.chomp

n = s.size

ATGC = "ATGC".freeze
ans = cnt = 0
s.each_char do |c|
  
  if ATGC.include?(c)
    cnt += 1
  else
    ans = cnt if ans < cnt
    cnt = 0
  end
end

ans = cnt if ans < cnt

puts ans

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<ld> a(n);
    priority_queue<ld> que;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        que.push(a[i]);
    }
    while(m>0){
        ld v = que.top();
        //cout << v << endl;
        que.pop();
        v = v / 2;
        que.push(v);
        m--;
    }
    ll ans = 0;
    while(!que.empty()){
        ll v = ll(que.top());
        que.pop();
        ans += v;
    }
    cout << ans << endl;
}

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

int main() {
  int N, M = 1e9+7;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());

  if (N % 2) {
    for (int i = 0; i < N; i++) {
      if (!i) if (A.at(i)) return cout << 0 << "\n", 0;
      int tmp = (i + 2 - 1) / 2 * 2;
      if (A.at(i) != tmp) return cout << 0 << "\n", 0;
    }
  } else {
    for (int i = 0; i < N; i++) {
      int tmp = (i % 2) ? i : i + 1;
      if (A.at(i) != tmp) return cout << 0 << "\n", 0;
    }
  }

  int cnt = N / 2;
  long ans = 1;
  while (cnt--) ans *= 2, ans %= M;
  cout << ans << "\n";
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <string>
#include <climits>
using namespace std;

vector<vector<long long int> > dp(101,vector<long long int>(4,-1));

long long int digitSum(const string &a,int idx,int k,bool tight,const int &n){
	if(idx==n)
		return k==0?1:0;
	if(tight){
		if(!k)
			return digitSum(a,idx+1,k,a[idx]-48==0?1:0,n);
		long long int ans = digitSum(a,idx+1,k,a[idx]-48==0?1:0,n);
		for(int i=1;i<=a[idx]-48;i++)
			ans += digitSum(a,idx+1,k-1,i==(a[idx]-48),n);
		return ans;
	} else {
		if(dp[idx][k]!=-1)
			return dp[idx][k];
		if(!k)
			return dp[idx][k] = 1;
		dp[idx][k] = digitSum(a,idx+1,k,0,n);
		for(int i=1;i<10;i++)
			dp[idx][k] += digitSum(a,idx+1,k-1,0,n);
		return dp[idx][k];
	}
}

int main()
{
    string a;
    int k,n;
    cin >> a >> k;
    n = a.size();
    cout << digitSum(a,0,k,1,n);
    return 0;
}

Measured memory_bytes: 3588
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#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(c) c.begin(),c.end()

/*
n,a=map(int, input().split())
x=list(map(int, input().split()))
x=[i-a for i in x]
d={0:1}
for i in x:
    for j,k in list(d.items()):
        d[i+j]=d.get(i+j,0)+k
print(d[0]-1)
*/
int main()
{
	int N, A;
	cin >> N >> A;
	vector<int> x(N);
	rep(i, N) {
		cin >> x[i];
		x[i] -= A;
	}
	map<int, ll> d;
	d[0] = 1;
	for (auto i : x) {
		decltype(d) tmp(d);
		for (auto& j : tmp) {
			d[i + j.first] = d[i + j.first] + j.second;
		}
	}
	cout << d[0] - 1 << endl;
	return 0;
}


Measured memory_bytes: 384
def bubble_sort(A:list) -> list:
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(len(A)-1, 0, -1):
            if A[i] < A[i-1]:
                A[i], A[i-1] = A[i-1], A[i]
                count += 1
                flag = 1
    print(" ".join(list(map(str, A))))
    return count

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().rstrip().split()))
    print(bubble_sort(A))


Measured memory_bytes: 5604
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    string s;
    string ret;
    cin >> s;
    for (auto c : s) {
        if (c == 'B') {
            ret.pop_back();
        } else {
            ret.push_back(c);
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll K,ans=0;
string S;

int main(){
    cin>>S>>K;
    if(K==1){
        ans+=S[0]-'0';
        ans+=9*(S.size()-1);
    }
    else if(K==2){
        ans+=(S.size()-1)*(S.size()-2)/2*9*9;
        ans+=(S[0]-'0'-1)*(S.size()-1)*9;
        repi(i,1,S.size()){
            if(S[i]!='0'){
                ans+=S[i]-'0'+(S.size()-i-1)*9;
                break;
            }
        }
    }
    else{
        ans+=(S.size()-1)*(S.size()-2)*(S.size()-3)/6*9*9*9;
        ans+=(S[0]-'0'-1)*(S.size()-1)*(S.size()-2)/2*9*9;
        repi(i,1,S.size()-1){
            if(S[i]!='0'){
                repi(j,i+1,S.size()){
                    if(S[j]!='0'){
                        ans+=(S[i]-'0'-1)*(S.size()-i-1)*9+S[j]-'0'+(S.size()-j-1)*9;
                        break;
                    }
                }
                ans+=(S.size()-i-1)*(S.size()-i-2)/2*9*9;
                break;
            }
        }
    }
    out(ans);
    
    
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: i64,
        a: [i64; n],
    }

    let mut x = 0;
    // let mut max_x = 0;
    // let mut max_sum = 0;

    for i in (0..60).rev() {
        if x | (1 << i) > k {
            continue;
        }

        let mut ones = 0;

        for j in 0..n {
            ones += (a[j] >> i) & 1;
        }

        let zeros = n as i64 - ones;
        if zeros > ones {
            x += 1 << i;
        } else {
            continue;
        }
    }

    // dbg!(x);

    let mut ans = 0;
    for i in 0..n {
        ans += a[i] ^ x;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double power = 1;
		for(int i = 1 ; i <= N ; i++) {
			power = power * i % 1000000007;
		}
		System.out.println((int)power);
	}
}


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

int main()
{
    int n,m;

    cin>>n>>m;

    char arr[n+5][m+5];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
         for(int j=0;j<m;j++)
        {
            cout<<arr[i][j];
        }
        cout<<endl;
         for(int j=0;j<m;j++)
        {
           cout<<arr[i][j];
        }
        cout<<endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    int lim = 0;
    int ans = 0;
    for(int i=0; i<n; i++){
        int h;
        cin >> h;
        lim = max(lim, h);
        if(lim <= h) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input().rstrip())
a = input().split()
H = []
count = []

for i in range(len(a)):
  H.append(int(a[i]))
H.append(10000000000)

temp = 0
for j in range(len(a)):
  if(H[j] >= H[j+1]):
    temp += 1
  else:
    count.append(temp)
    temp = 0

print(max(count))

Measured memory_bytes: 14648
K=int(input())
i=1
if K%2==0 or K%5==0:
  print(-1)
elif K%7==0:
  L=9*K/7
  b=10
  while True:
    b=b%L
    if b==1:
      print(i)
      break
    b=b*10
    i+=1
else:
  L=9*K
  b=10
  while True:
    b=b%L
    if b==1:
      print(i)
      break
    b=b*10
    i+=1

Measured memory_bytes: 9124
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if ((a * b) % 2 == 0)
      System.out.println("Even");
    else
      System.out.println("Odd");
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
pair<int,int> s[maxn];
int main()
{
	int n,t;
	cin>>n>>t;
	int ans=INT_MAX;
	for(int i=1;i<=n;++i)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(b<=t)
		{
			ans=min(ans,a);
		}
	}
	if(ans==INT_MAX)
	{
		cout<<"TLE"<<endl;
	}
	else
	{
		cout<<ans<<endl;
	}
	return 0;
}

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

#define N 8
#define FREE -1
#define NOT_FREE 1
#define true 999
#define false -999

int row[N], col[N], dpos [2 * N - 1], dneg[2 * N - 1];

int X[N][N];

typedef struct{
  int FALSE;
  int TRUE;
}bool;

void initialize() {

  int i;
  
  for ( i = 0; i < N; i++ ) {
    row[i] = FREE, col[i] = FREE;
  }
  for ( i = 0; i < 2 * N - 1; i++ ) {
    dpos[i] = FREE; dneg[i] = FREE;
  }
  
}

void print(int row[]){

  int i,j;

  for ( i = 0; i < N; i++ ) {
    for ( j = 0; j < N; j++) {

      if(row[i]==j) printf("%c",'Q');
      else printf("%c",'.');
      
    }
    printf("\n");
  }

}

void printBoard() {

  int i,j;
  
  for ( i = 0; i < N; i++ ) {
    for ( j = 0; j < N; j++ ) {
      if ( X[i][j]==999 ) {
	if ( row[i] != j) return;
      }
    }
  }

  print(row);
}

void recursive(int i) {

  int j;

  if ( i == N ) {
    printBoard(); return;
  }

  for ( j = 0; j < N; j++ ){
    if ( NOT_FREE == col[j] ) continue;
    if(NOT_FREE == dpos[i + j])continue;
    if(	 NOT_FREE == dneg[i - j + N - 1] ) continue;

    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;

    recursive(i + 1);

    row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;

  }
}

int main() {

  int i,j;
  initialize();
  
  for (  i = 0; i < N; i++){
    X[i][0]=false;
    for (  j = 0; j < N; j++ ) X[i][j] = false;
  }
  int k;
  
  scanf("%d",&k);
  for ( i = 0; i < k; i++ ) {
    int r, c;
    
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
  
}



Measured memory_bytes: 2044
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
    {
        cout<<(n-2)*(b-a)+1<<endl;
    }
    else
    {
        cout<<0<<endl;
    } 
 } 

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>b[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
	llin(n);
	ll a=0;
	FOR(i,1,n){
		a+=i;
	}
	ll g=0;
	FOR(i,2,n){
		if(a%i==0&&((n%i==0&&(n/i)%2==0)||((n+1)%i==0&&(n+1)/i%2==0))){
			g=i;
			break;
		}
	}
	vector<vll> d(g,vll(0,0));
	ll h=0;
	ll y=0;
	rFOR(i,1,n){
		d[h].pb(i);
		if(y==0){
			if(h<g-1){
				h++;
			}else{
				y=1;
			}
		}else{
			if(h>0){
				h--;
			}else{
				y=0;
			}
		}
	}
	ll w=d[0].sz*d[g-1].sz;
	if(g!=2){
		FOR(i,0,g-2){
			w+=d[i].sz*d[i+1].sz;
		}
	}
	sal(w);
	FOR(i,0,g-2){
		FOR(j,0,d[i].sz-1){
			FOR(k,0,d[i+1].sz-1){
				says(d[i][j]);
				sal(d[i+1][k]);
			}
		}
	}
	if(g!=2){
		FOR(j,0,d[g-1].sz-1){
			FOR(k,0,d[0].sz-1){
				says(d[g-1][j]);
				sal(d[0][k]);
			}
		}
	}
}


Measured memory_bytes: 256
#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
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int Q;
  cin >> Q;
  set<int> ext;
  map<int,int> num;
  ll sum = 0;
  int now_num = -1;
  int now_cnt = 1;
  int cnt = 0;
  while(Q--){
    int id;
    cin >> id;
    if(id == 1){
      int a,b;
      cin >> a >> b;
      sum += b;
      ext.emplace(a);
      num[a]++;
      if(now_num == -1){
        now_num = a;
        now_cnt = 1;
        ext.emplace(a);
      }else{
        if(a < now_num){
          sum += abs(a-now_num);
          // 左が増える
          if(cnt%2){
            // 奇数で左増えるので移動
            if(now_cnt == 1){
              auto pos = ext.lower_bound(now_num);
              pos--;
              now_num = *pos;
              now_cnt = num[now_num];
            }else{
              now_cnt--;
            }
          }else{
            // 偶数で左増えるので不動
          }
        }else{
          // 右が増える
          if(cnt%2){
            sum += abs(a-now_num);
            // 奇数で右増えるので不動
          }else{
            // 偶数で右増えるので移動
            if(num[now_num] == now_cnt){
              auto pos = ext.lower_bound(now_num);
              pos++;
              now_num = *pos;
              now_cnt = 1;
            }else{
              now_cnt++;
            }
            sum += abs(a-now_num);
          }
        }
      }
      cnt++;
    }else{
      cout << now_num << " " << sum << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 12864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,l,x,c=0;
    cin>>n;
    int ar[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        if(ar[i]==1)
        {
            c=1;
        }
    }
    if(c==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    else
    {
        x=1;
        for(i=0;i<n;i++)
        {
            if(ar[i]==x)
                x++;
        }
        cout<<n-x+1<<endl;
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<sstream>
#include<cstdlib>
#include<time.h>
#include<math.h>
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define repp(i,n,a) for(int i=n;i>=a;i--)
#define ll long long
#define ull unsign long long
#define ms(x,a) memset(x,a,sizeof(x))
#define lowbit(x) ((x)&(-x))
#define gcd(a,b) _gcd(a,b)
#define inf 0x3f3f3f3f
#define eps 1e-8
#define mod 1e9+7
#define sd(x) scanf("%d",&x)
#define pd(x) printf("%d\n",x)
using namespace std;
const int maxn=1e5+10;
const double pi=acos(-1.0);
int a[maxn];

int main()
{
	int n,m;
	string ss1;
	cin>>ss1;
	if(ss1[0]==ss1[1]||ss1[1]==ss1[2]||ss1[2]==ss1[3]){
		cout<<"Bad"<<endl;
	}
	else cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
N -= 1

for l in range(1, 100):
    if N >= 26**l:
        N -= 26**l
    else:
        ans = ""
        for i in range(l):
            ans += chr(ord('a') + N % 26)
            N //= 26
        print(ans[::-1])
        break

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 200010;

int N;
vector<int> A;
vector<int> graph[MAX_N];

vector<int> dp;
vector<int> ans;    // ノード i までの LIS

// 現在のノード i, 親 par, 現時点での lis
void dfs(int i, int par, int lis) {
    // dp の中で自分より大きい値が最初に出てくる場所
    auto it = lower_bound(dp.begin(), dp.end(), A[i]);
    // 現在の値を覚えておく
    int pre = *it;
    if(pre == LLINF) {
        lis++;  // LIS が伸びた
    }
    // dp の更新
    *it = A[i];
    // 1 を根としたときのノード i までの LIS
    ans[i] = lis;

    // 更に下を見る
    for(auto& next_i : graph[i]) {
        if(next_i == par) { continue; }
        dfs(next_i, i, lis);
    }

    // 下を見終わったら値をロールバック
    *it = pre;
}

signed main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    A.resize(N);
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N-1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dp.assign(N, LLINF);
    ans.resize(N);
    dfs(0, -1, 0);

    REP(i, N) {
        printf("%lld\n", ans[i]);
    }

    return 0;
}



Measured memory_bytes: 33280
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,x;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;
  int sum=0;
  int ans=0;
  for(int i=0;i<a+1;++i) {
    for(int j=0;j<b+1;++j) {
      for(int k=0;k<c+1;++k) {
        sum=500*i+100*j+50*k;
        if(x==sum) {
          ans++;}
      }}}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define Raffica ((int)(1e5+3))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;

int n, V;
LL ans = 0;
LL val[10010], w[10010], d[100010];

LL min(LL x, LL y) { return x > y ? y : x; }
LL max(LL x, LL y) { return x < y ? y : x; }

void in() {
	cin >> n >> V;
    for(int i = 1;i <= n;i ++) cin >> w[i] >> val[i];
}

void solve() {
	int i, j;
    memset(d, 0x3f, sizeof(d));
    d[0] = 0;
    for(i = 1;i <= n;i ++) {
        for(j = 100001;j >= val[i];j --) {
            d[j] = min(d[j], d[j-val[i]] + w[i]);
		}
    }
    for(i = 1;i <= 100001;i ++) {
		if(d[i] <= V) ans = max(ans, (LL)i);
	}
    cout << ans;
}

int main() {
	in();
	solve();
	return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
    vector<long long> N(30);
    for (int i = 0; i < 30; i++) cin >> N[i];
    for (int i = 0; i < 30; i++) {
        if (N[i] == 0) break;

        vector<long long> dp(31);
        for (int j = 0; j < N[i]; j++) dp[j] = 0;
        dp[0] = 1;
        for (int j = 1; j <= N[i]; j++) {
            dp[j] += dp[j - 1];
            if (j >= 2) dp[j] += dp[j - 2];
            if (j >= 3) dp[j] += dp[j - 3];
        }
        cout << (((dp[N[i]] + 9) / 10) + 364) / 365 << endl;
    }
}


Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    char s[h][w];
    repi(i, h, 0)
    {
        repi(j, w, 0)
        {
            cin >> s[i][j];
        }
    }

    vector<pair<int, int>> v;
    int cnt = 0;
    repi(i, h, 0)
    {
        repi(j, w, 0)
        {
            if (s[i][j] == '#')
            {
                cnt++;
            }
        }
        if (cnt)
        {
            v.push_back({i, cnt});
            cnt = 0;
        }
    }

    int prev = 0;
    int ans[h][w];
    int num = 1;
    repi(vi, v.size(), 0)
    {
        int cnt = 0;
        repi(j, w, 0)
        {
            repi(i, v[vi].first + 1, prev)
            {
                ans[i][j] = num;
                if (s[i][j] == '#')
                {
                    cnt++;
                    if (cnt < v[vi].second)
                    {
                        num++;
                    }
                }
            }
        }
        num++;
        prev = v[vi].first + 1;
    }
    if (v[v.size() - 1].first != h - 1)
    {
        repi(j, w, 0)
        {
            repi(i, h, v[v.size() - 1].first + 1)
            {
                ans[i][j] = ans[v[v.size() - 1].first][j];
            }
        }
    }

    repi(i, h, 0)
    {
        repi(j, w, 0)
        {
            cout << ans[i][j] << ((j + 1) % w ? " " : "\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define lli long long int
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
		double num;
		cin>>num;
		num=num/3;
		double val=(double)((double)num*(double)num*(double)num);
		cout<<setprecision(15)<<val<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

int H, W;
vector<vector<bool> > v;

void init()
{
	cin >> H >> W;
	v.resize(H+2);
	rep(i, H+2) {
		v[i].resize(W+2, false);
	}
	rep(i, H) rep(j, W) {
		char c;
		cin >> c;
		v[i+1][j+1] = c == '#';
	}
}

bool walk(int& r, int& c)
{
	v[r][c] = false;
	if (v[r+1][c]) {
		r++;
		return true;
	}
	if (v[r][c+1]) {
		c++;
		return true;
	}
	return false;
}

void solve()
{
	int r = 1, c = 1;
	while (walk(r, c));
	rep(i, H) rep(j, W) {
		if (v[i+1][j+1]) {
			cout << "Impossible" << endl;
			return;
		}
	}
	cout << "Possible" << endl;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>

#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define ld long double
bool less_vectors(const vector<int>& a,const vector<int>& b) 
{
  return a.size() > b.size();
}
class dc
{
    public:
bool operator()(pair<int,ll> p1,pair<int,ll>  p2)
{
    return p1.ss>p2.ss;
}

};
class comp
{
    public:
bool operator()(pair<int,pair<ll,ll> > p1,pair<int,pair<ll,ll> > p2)
{
    if(p1.ss.ff!=p2.ss.ff)
     return p1.ss.ff>p2.ss.ff;
     else
          return p1.ss.ss>p2.ss.ss;
}

};
int gcd(int a,int b)
{
if(a%b==0)
     return b;
     else
          return gcd(b,a%b);
}
ll fastexpo(ll a,ll b)
{
  
      ll res=1;
      while(b>0)
      {
        if(b%2==1)
          res=((res)mod*(a)mod)mod;
        a=((a)mod*(a)mod)mod;
        b/=2;
      }
      return res;
}
ll fastexpom(ll a,ll b,ll m)
{
  ll res=1;
      while(b>0)
      {
        if(b%2==1)
          res=(((res)%m)*((a)%m))%m;
        a=(((a)%m)*((a)%m))%m;
        b/=2;
      }
      return res;
}
ll modinv(ll a, ll m=1000000007)
{
  return fastexpom(a,m-2,m);
}
bool comparator(pair<int,int> p1,pair<int,int> p2)
{
  if(p1.ff!=p2.ff)
  {
    return p1.ff<p2.ff;
  }
  else
    return p1.ss<p2.ss;
}
int main()
{
     IOS;
    /* #ifndef ONLINE_JUDGE
     freopen("int.txt","r",stdin);
     freopen("out.txt","w",stdout);
     #endif*/
     string s;
     cin>>s;
     bool ch=0;
     for(int i=1;i<s.length();i++)
     {
        if(s[i-1]=='A' && s[i]=='C')
          ch=1;
     }
     if(ch)
      cout<<"Yes";
    else
      cout<<"No";
    


     return 0;
} 

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

typedef long long ll;
int n, a[100000];
ll cnt1, cnt2, sum;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    for (int i = 0; i < n; i++) {
        
        if (i % 2 == 0 && sum+a[i] <= 0) {
            
            cnt1 += (-1)*sum + 1 - a[i];
            sum = 1;
            
        } else if (i % 2 != 0 && sum + a[i] >= 0) {
            cnt1 += a[i] + sum + 1;
            sum = -1;
        }
        else
            sum += a[i];
    }
    sum = 0;
    
    for (int i = 0; i < n; i++) {
        
        if (i % 2 != 0 && sum+a[i] <= 0) {
            
            cnt2 += (-1)*sum + 1 - a[i];
            sum = 1;
            
        } else if (i % 2 == 0 && sum + a[i] >= 0) {
            cnt2 += a[i] + sum + 1;
            sum = -1;
        }
        else
            sum += a[i];
    }
    cout << min(cnt1, cnt2);
    
    return 0;
}


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

#define infty 999999999
#define ele 10000000

void merge(int left, int mid, int right);
void mergeSort(int left, int right);

int S[ele];
int count = 0;

int main(){
  int n,i;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  mergeSort(0,n);

  for(i=0;i<n;i++){
     if(i!=n-1)
    printf("%d ",S[i]);
     else
       printf("%d\n",S[i]);
  }
   printf("%d\n",count);
  return 0;
}
void merge(int left, int mid, int right){
  int n1,n2,k,i,j;
  int *L,*R;
   n1 = mid - left;
   n2 = right - mid;
L = (int *)malloc((n1+1) * sizeof(int));
R = (int *)malloc((n2+1) * sizeof(int));
 
    for(i=0;i<= n1-1;i++){
      L[i] = S[left + i];
      }

  for( i = 0;i<= n2-1;i++){
    R[i] = S[mid + i];
  }

  L[n1] = infty;
  R[n2] = infty;

  i = 0;
  j = 0;

  for(k = left; k<= right-1;k++){

    if( L[i] <= R[j]){
      count++;
	S[k] = L[i];
	i = i + 1;
	}

	else {
	  count++;
        S[k] = R[j];
	j = j + 1;
	}
}
  free(L);
  free(R);
}

void mergeSort(int left, int right){
  int mid;
  if(left+1 < right){
  mid = (left + right)/2;
  mergeSort(left, mid);
  mergeSort(mid, right);
  merge(left, mid, right);
  }
}



Measured memory_bytes: 5472
#include <stdio.h>

int main(void) {
	int n, i;
	int a[100];
	
	//数列の長さを入力する
	scanf("%d", &n);
	//数列の長さぶん数値を入力する
	for(i = 0; i < n; i++) {
	    scanf("%d", &a[i]);
	}
	//逆順にして出力する
	for(i = n - 1; i > 0; i--) {
	    printf("%d ", a[i]);
	}
	printf("%d\n", a[i]);
	return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;
//const int MOD=1e9+7;


int main(){
	string S;
	cin>>S;
	int l=S.size();
	if(l==2)cout<<S;
	else{
		cout<<S[2]<<S[1]<<S[0];
	}
}

Measured memory_bytes: 256
def lma():return list(map(int, input().split()))#x or y
a = lma()
f = 1
c =0
while f:
    if a[0]%2==1 or a[1]%2==1 or a[2]%2 ==1:break
    if (a[0] == a[1] and a[0] == a[2]) :
        c=-1
        break
    a[0],a[1],a[2] = (a[1]+a[2])/2,(a[0]+a[2])/2,(a[1]+a[0])/2
    c+=1
print(c)

Measured memory_bytes: 3064
n, m, X, Y = gets.chomp.split(' ').map(&:to_i)
xs = gets.chomp.split(' ').map(&:to_i)
ys = gets.chomp.split(' ').map(&:to_i)
war = true
for z in (X+1)...(Y+1) do
  war = true
  xs.map { |x| war = false if x >= z }
  ys.map { |y| war = false if y < z }
  break if war
end

puts war ? "No War" : "War"

Measured memory_bytes: 2044