akhauriyash/Code-Regression huggingface dataset:
import sys
import string
li = []
for l in sys.stdin:
    for ll in list(l.lower()):
        li.append(ll)

d = dict([(x, 0) for x in string.ascii_lowercase])

for i in li:
    if i in d:
        d[i] += 1

for i in d.items():
    print(i[0], ":", i[1])



Measured memory_bytes: 6680
import math
import bisect
import sys
input = sys.stdin.readline
q = int(input())

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

prime = set([i for i, f in enumerate(sieve_of_erastosthenes(10**5)) if f])
like = []
for p in prime:
    if (p+1)//2 in prime:
        like.append(p)
like.sort()

for i in range(q):
    l, r = map(int, input().split())
    st = bisect.bisect_left(like, l)
    en = bisect.bisect_right(like, r)

    print(en-st)

Measured memory_bytes: 4880
n = int(input())
a = list(map(int, input().split(" ")))

a.sort()
maxs = []
for i in range(2):
	max_1 = a.pop()
	while True:
		max_2 = a.pop()
		if max_1 == max_2:
			maxs.append(max_1)	
			break
		max_1 = max_2
		if len(a) == 0:
			print(0)
			exit()
print(maxs[0]*maxs[1])

Measured memory_bytes: 14252
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);

    ll i,j,h;
    ll Q,M,K,P,A,B,N,X;

    long double x;

    string s;
    char aaa;
    ll ans=0;
    ll count=0;
    ll flag=0;
  

    vector<ll> aa(100000); 
    ll a,b,c;
    
    ll d;


    cin >>N;
    
ll temp;
    rep(i,N){
        cin>>temp;
        aa[temp-1]++;
        ans+=temp;
    }
    cin>>Q;
    rep(i,Q){
cin>>b>>c;
ans += (c-b)*aa[b-1];
aa[c-1] +=aa[b-1];
aa[b-1]=0;
cout<<ans<<endl;

    }



  
    return 0;
}

Measured memory_bytes: 3404
K, N = map(int, input().split())
fst = None
lst = None
pre = None
mx = 0
for a in sorted(map(int, input().split())):
    lst = a
    if fst is None:
        fst = pre = a
        continue
    d = a - pre
    if d > mx:
        mx = d
    pre = a
d = (K - lst) + fst
if d > mx:
    mx = d
print(K - mx)

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

int n, k, a[1010][110];

int main()
{
	k = 42, n = k * (k - 1) + 1;
	printf("%d %d\n", n, k);
	for(int i = 1; i <= k; ++i)
	{
		printf("1");
		for(int j = (i - 1) * (k - 1) + 2, p = 1; p <= k - 1; ++p, ++j)
		{
			printf(" %d", j);
			a[i][p - 1] = j;
		}
		printf("\n");
	}
	for(int i = 0; i <= k - 2; ++i)
		for(int j = 0; j <= k - 2; ++j)
		{
			printf("%d", i + 2);
			for(int l = 2, z = j; l <= k; ++l, z = (z + i) % (k - 1))
				printf(" %d", a[l][z]);
			printf("\n");
		}
	return 0;
}

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  vector<int> arr(n+1),dp(n+1,INT_MAX);
  for(int i=0; i<n; i++) cin>>arr[i+1];
  dp[1] = 0;
  int i=1;
  while(i<=n){
    if(i+1 <= n){
      dp[i+1] = min(dp[i+1],dp[i]+abs(arr[i+1]-arr[i]));
    }
    if(i+2 <= n){
      dp[i+2] = min(dp[i+2],dp[i]+abs(arr[i+2]-arr[i]));
    }
    i++;
  }
  cout<<dp[n];
  return 0;
}


Measured memory_bytes: 1024
Q = int(input())
for i in range(Q):
    a,b = map(int,input().split())
    if a > b: a,b = b,a
    if b in (a, a+1):
        print((a-1)*2)
        continue
    c = int((a*b)**0.5)
    if c*c == a*b:
        c -= 1
    ans = 2*c - 2
    if c*(c+1) < a*b:
        ans += 1
    print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	int n,m;cin>>n;m=n;
	int high=0;
	int gray=0;
	int brown=0;
	int green=0;
	int cyan=0;
	int blue=0;
	int yellow=0;
	int orange=0;
	int red=0;
	while(m--){
		int tmp;cin>>tmp;
		if(tmp<400) gray++;
		else if(tmp<800) brown++;
		else if(tmp<1200) green++;
		else if(tmp<1600) cyan++;
		else if(tmp<2000) blue++;
		else if(tmp<2400) yellow++;
		else if(tmp<2800) orange++;
		else if(tmp<3200) red++;
		else high++;
	}
	int a1=!!gray+!!brown+!!green+!!cyan+!!blue+!!yellow+!!orange+!!red;
	cout<<max(a1,1LL)<<" "<<a1+high;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    int a,b;
    cin>>a>>b;

    if(a>b)cout<<a-1<<endl;
    else cout<<a<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    cin >>S;
    if(S[S.size()-1]=='s'){
        cout<<S<<"es"<<endl;
    }else{
        cout<<S<<"s"<<endl;
    }



    return 0;
    

}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

const LL MAX = 4010000;
const LL MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (LL i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(LL n, LL k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

LL mod = 998244353;

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

  LL N, M;
  cin >> N >> M;
  
  //3M回 +1
  //N要素で2M+1以上のがあったらダメ
  //N-1要素で(M-1回以内+1)の個数*N
  //単にN要素でM-1回+1
  
  //ある要素が2M-1
  //残りがM+1回のどこかで+2がされる
  //逆に、+1しかない場合を除け

  //+2 がM回存在しないものを除く
  //i=0~M-1
  //N個から適当にi回+2
  //N個から3M-2*i要素を+1

  COMinit();

  LL ans = COM(3 * M + N - 1, 3 * M) - COM(M - 1 + N - 1, M - 1) * N;
  LL sum = 0;
  FOR(i, 0, M)
  {
    //A=
    sum += (COM(i+N-1, N-1) * COM(N,3*M-2*i))%mod;
    sum %= mod;
  }
  ans -= sum ;
  ans = (ans%mod + mod) % mod;

  cout << ans << endl;
}


Measured memory_bytes: 94208
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  int v;
  for(int i=1;i<10;i++){
     v = i + 10*i + 100*i;
     if(v >= N) break;
  }

  cout << v << endl;

}

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

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

string s;
cin>>s;

if(s.at(2)==s.at(3)&&s.at(4)==s.at(5))
cout<<"Yes"<<endl;
else
{
    cout<<"No"<<endl;
}

return 0;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main()
{
    int n,k=0,x;
    cin>>n;
    x=n;
    while(n!=0){
        n=n/10;
        k++;
    }
    n=x;
    if(k==1){
        cout<<n;
    }
    if(k==2){
        cout<<"9";
    }
    if(k==3){
        cout<<9+n-99;
    }
    if(k==4){
        cout<<"909";
    }
    if(k==5){
        cout<<909+n-9999;
    }
    if(k==6){
        cout<<"90909";
    }

    return 0;
}



Measured memory_bytes: 256
a, b, m = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
xycs = [tuple(map(int, input().split())) for _ in range(m)]
ans = min(arr) + min(brr)

for elem in xycs:
    x = elem[0]
    y = elem[1]
    c = elem[2]
    ans = min((arr[x - 1] + brr[y - 1] - c), ans)

print(ans)


Measured memory_bytes: 81348
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [n, k, s] = nextIntArray()
    let ans = []
    if (s == 1e9) {
        for (let i = 0; i < k; i++) {
            ans.push(s)
        }
        for (let i = 0; i < n - k; i++) {
            ans.push(1)
        }
    } else {
        for (let i = 0; i < k; i++) {
            ans.push(s)
        }
        for (let i = 0; i < n - k; i++) {
            ans.push(s + 1)
        }
    }
    console.log(ans.join(" "))
}
Main()


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const double INF=1000000000000000.0;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}

int main(){
	ll N; cin>>N;
    ll T,A; cin>>T>>A;
    vector<ll> H(N+1);
    rep1(i,N) cin>>H[i];
    double tmpmin=INF;
    ll ans;
    rep1(i,N){
        if(chmin(tmpmin,abs(T-H[i]*0.006-A))) ans=i;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

ll func(ll int x)
{
	if (x == 1) {
		return 1LL;
	} else {
		return (ll int)(2 * func(x / 2) + 1);
	}
}

int main()
{
	ll int x;

	cin >> x;
	printf("%lld", func(x));

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define repn(i,s,n) for (int i=int(s); i < int(n); i++)
#define rep(i,n) repn(i,0,n)
#define repd(i,n) for (int i=int(n)-1; i >= 0; i--)


struct Node {
  int val;  // この区間に足される値
  int min;  // この区間の最小値（valを含む）
  Node() : min(0), val(0) {}
};

#define LC(k) (k * 2 + 1)  // 左の子
#define RC(k) (k * 2 + 2)  // 右の子

const int INF = INT_MAX;

struct RMQRangeAddSegTree {
  vector<Node> tree;
  int n;
  RMQRangeAddSegTree(int n) : n(n), tree(n*2 - 1) {}  // nは2のべき乗とする

  void addRange(int l, int r, int val) {
    addRange(l, r, 0, 0, n, val);
  }

  int minRange(int l, int r) {
    return minRange(l, r, 0, 0, n);
  }

  // a,b: クエリ対象の範囲[a,b)
  // k: 現在のノードの番号
  // l,r: 現在のノードkの範囲[l,r)
  // val: [a,b)に追加する値
  void addRange(int a, int b, int k, int l, int r, int val) {
      if (r <= a || b <= l) return;
      process_lazy(k);
      if (a <= l && r <= b) {
        tree[k].val += val;
      }
      else {
        addRange(a, b, LC(k), l, (l + r) / 2, val);
        addRange(a, b, RC(k), (l + r) / 2, r, val);
      }
      update_node(k);
  }

  int minRange(int a, int b, int k, int l, int r) {
      if (r <= a || b <= l) return INT_MAX;
      process_lazy(k);
      if (a <= l && r <= b) {
        return tree[k].min;
      }
      int lmin = minRange(a, b, LC(k), l, (l + r) / 2);
      int rmin = minRange(a, b, RC(k), (l + r) / 2, r);
      update_node(k);
      return min(lmin, rmin);
  }

  // 頂点情報の更新。葉ノード側の更新を上へ伝搬していく
  // この処理の後、ノードkのもつ各値（ここではmin）は正しいものとなる
  void update_node(int k) {
    if (k < n - 1) {  // k は葉でない
      tree[k].min = tree[k].val + min(tree[LC(k)].min, tree[RC(k)].min);
    }
    else {  // k は葉
      tree[k].min = tree[k].val;
    }
  }

  // 遅延評価の実行。根ノード側の
  // この処理の後、ノードkのもつ各値（ここではmin）は正しいものとなる
  void process_lazy(int k) {
    if (k < n - 1 && tree[k].val != 0) {
      tree[LC(k)].val += tree[k].val;
      tree[RC(k)].val += tree[k].val;
      tree[LC(k)].min += tree[k].val;
      tree[RC(k)].min += tree[k].val;
      tree[k].val = 0;
    }
  }
};

int main() {

  int n, q;
  cin >> n >> q;
  int nPow2 = n-1;
  nPow2 |= nPow2 >> 1;
  nPow2 |= nPow2 >> 2;
  nPow2 |= nPow2 >> 4;
  nPow2 |= nPow2 >> 8;
  nPow2 |= nPow2 >> 16;
  nPow2++;

  RMQRangeAddSegTree segtree(nPow2);
  segtree.addRange(0, n, INF);
  rep(qi, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      // update(x,y)
      int origval = segtree.minRange(x, x+1);
      segtree.addRange(x, x+1, -origval + y);
    }
    else {
      // find(x,y)
      cout << segtree.minRange(x, y+1) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3116
import sys
input = sys.stdin.readline

def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

class Unionfind:

    __slots__ = ['nodes']

    def __init__(self, n):
        self.nodes = [-1]*n

    def root(self, x):
        if self.nodes[x] < 0:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        rank_x = -self.nodes[x]; rank_y = -self.nodes[y]
        if rank_x < rank_y:
            x, y = y, x
        self.nodes[x] += self.nodes[y]
        self.nodes[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def rank(self, x):
        return -self.nodes[self.root(x)]

N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
uf = Unionfind(N)
ans_list = [comb(N,2)]
ans = comb(N,2)
for A,B in info[:0:-1]:
    A -= 1; B -= 1
    if not uf.same(A,B):
        ans -= uf.rank(A) * uf.rank(B)
    uf.unite(A,B)
    ans_list.append(ans)
 
for e in ans_list[::-1]:
    print(e)

Measured memory_bytes: 35412
from collections import deque
import sys
from typing import List

sys.setrecursionlimit(200000)


N = int(input())
G: List[List[int]] = [[0]] * N
for i in range(N):
    k, *c = map(lambda x: int(x), input().split())
    G[i] = c

H = [0] * N
prv = [None] * N


def dfs(v):
    s = 1
    heavy = None
    m = 0
    for w in G[v]:
        prv[w] = v
        c = dfs(w)
        if m < c:
            heavy = w
            m = c
        s += c
    H[v] = heavy
    return s


dfs(0)


SS: List[List[int]] = []
D: List[int] = []
L = [0] * N
I = [0] * N  # noqa: E741
que = deque([(0, 0)])
while que:
    v, d = que.popleft()
    S: List[int] = []
    k = len(SS)
    while v is not None:
        I[v] = len(S)
        S.append(v)
        L[v] = k
        h = H[v]
        for w in G[v]:
            if h == w:
                continue
            que.append((w, d + 1))
        v = h
    SS.append(S)
    D.append(d)


C = list(map(len, SS))
DS0 = [[0] * (c + 1) for c in C]
DS1 = [[0] * (c + 1) for c in C]


def add(K, data, k, x):
    while k <= K:
        data[k] += x
        k += k & -k


def get(K, data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s


def query_add(v, x):
    while v is not None:
        l = L[v]  # noqa: E741
        i = I[v]
        add(C[l], DS1[l], i + 1, -x)
        add(C[l], DS1[l], 1, x)
        add(C[l], DS0[l], i + 1, x * (i + 1))
        v = prv[SS[l][0]]


def query_sum(v):
    s = - get(C[0], DS1[L[0]], 1) - get(C[0], DS0[L[0]], 1)
    while v is not None:
        l = L[v]  # noqa: E741
        i = I[v]
        s += get(C[l], DS1[l], i + 1) * (i + 1) + get(C[l], DS0[l], i + 1)
        v = prv[SS[l][0]]
    return s


Q = int(input())
ans = []
for q in range(Q):
    t, *cmd = map(lambda x: int(x), input().split())
    if t:
        ans.append(str(query_sum(cmd[0])))
    else:
        v, w = cmd
        query_add(v, w)
print("\n".join(ans))



Measured memory_bytes: 126164
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

const int nax = 1e5 + 5;
vector<int> edges[nax], dist;
int in_degree[nax];
bool visited[nax];

void dfs(int a) {
    visited[a] = true;
    for (int b : edges[a]) {
        dist[b] = max(dist[b], dist[a] + 1);
        --in_degree[b];
        if (in_degree[b] == 0) {
            dfs(b);
        }
    }
}
int main() {
    int n, m;
    cin >> n >> m;
    dist.assign(nax, 0);
    while (m--) {
        int a = nxt(), b = nxt();
        edges[a].push_back(b);
        ++in_degree[b];
    }
    for (int i = 1; i <= n; i++) {
        if (in_degree[i] == 0 && !visited[i]) dfs(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, dist[i]);
    printf("%d\n", ans);
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  vector<ll> s;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      s.push_back(a[j] - a[i]);
    }
  }
  for (int i = 40; i >= 0; i--) {
    vector<ll> t;
    for (auto e : s) {
      if ((e >> i) & 1) {
        t.push_back(e);
      }
    }
    if (t.size() >= k) {
      s = t;
    }
  }
  sort(rbegin(s), rend(s));
  ll r = s.front();
  for (int i = 0; i < k; i++) {
    r &= s[i];
  }
  cout << r << endl;
}


Measured memory_bytes: 6128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    int a,b;
    a = 0,b=0;
    rep(i,n){
        int c,d;
        cin >> c >> d;
        if(c>a)a = c, b = d;
    }
    cout << a + b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */

const int N= 200010;
int monster[N];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */

	int n,k;
	cin>>n>>k;
	Foz(i,n)
	{
		cin>>monster[i];
	}
	sort(monster,monster+n);
	if(n<=k)cout<<0<<endl;
	else
	{
		ll mov=0;
		Foz(i,n-k)
		{
			mov+=monster[i];	
		}
		cout<<mov<<endl;	
	}
}



Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int n;
int a[900000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    F(i, n) cin >> a[i];
    sort(a, a + n);
    ll res = 0;
    vector<pii> ans;
    for (int i = 1; i <= n - 2; i++)
    {
        if (a[i] > 0)
        {
            ans.push_back({a[0], a[i]});
            a[0] -= a[i];
        }
        else
        {
            ans.push_back({a[n - 1], a[i]});
            a[n - 1] -= a[i];
        }
    }
    ans.push_back({a[n - 1], a[0]});
    a[n - 1] -= a[0];
    cout << a[n - 1] << "\n";
    F(i, n - 1)
    {
        cout << ans[i].fi << " " << ans[i].se << "\n";
    }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
string s;
bool checker(int right) {
    int a = 0, b = (right / 2) + 1;
    int stop = b;
    while(a < stop) {
        if(s[a] != s[b])
            return false;
        a += 1;
        b += 1;
    }
    return true;
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    int len = s.length();
    if(len % 2 == 1)
        len -= 1;
    else
        len -= 2;
    for(int i = len - 1; i >= 1; i -= 2) {
        if(checker(i)) {
            cout << i + 1;
            return 0;
        }
    }
}



Measured memory_bytes: 3640
n, q = map(int, input().split())
S = input()
CS = [0]
cur = 0
for i in range(1, n):
    if S[i-1] + S[i] == 'AC':
        cur += 1
        CS.append(cur)
    else:
        CS.append(cur)

for _ in range(q):
    l, r = map(int, input().split())
    print(CS[r-1] - CS[l-1])



Measured memory_bytes: 11468
#include<iostream>
using namespace std;
int main(){
	 int a,b;
	 double A,B;
	 cin>>a>>b;
	 cout<<a/b<<" "<<a%b<<" ";
	 A=a;
	 B=b;
	 cout<<fixed<<A/B<<endl;	 
	 return 0;
	 }

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define MAX 1000000
#define For(i, a, b) for( int i = (a); i < (b); i++ )
#define ll long long
using namespace std;

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

    ll x;
    cin>>x;

    ll sum = 0;
    while(x/500){
        ll b =x/500;
        sum += b * 1000;
        x%=500;
    }

    while(x/5){
        x=x/5;
        sum += x * 5;
        x%=5;
    }

    cout<<sum<<endl;

    return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void wr(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t;
    cin>>s>>t;
    cout<<(t.substr(0,s.size())==s?"Yes":"No");
    return 0;
}



Measured memory_bytes: 3656
# https://atcoder.jp/contests/abc077/tasks/abc077_a

import itertools
import collections
import bisect

def main():
    c1 = input()
    c2 = input()
    c1r = ''.join(list(reversed(c1)))
    c2r = ''.join(list(reversed(c2)))
    print("YES" if c1 == c2r and c2 == c1r else "NO")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import heapq

N, M = map(int, input().split())
jobs = [[] for _ in range(M)]

for _ in range(N):
    d, r = map(int, input().split())
    if d-1 < M:
        jobs[d-1].append(-r)

ans = 0
hp = []

for i in range(M):

    for reward in jobs[i]:
        heapq.heappush(hp, reward)

    if len(hp) > 0:
        reward = heapq.heappop(hp)
        ans += -reward

print(ans)

Measured memory_bytes: 17604
#include <iostream>
#include <string>
#include <locale>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

string txt_tolower(string txt)
{
    locale l = std::locale::classic();
    string lowerdtxt = "";
    for (string::iterator itr = txt.begin(); itr != txt.end(); ++itr)
    {
        lowerdtxt += tolower(*itr, l);
    }
    return lowerdtxt;
}

int main()
{

    string word;
    cin >> word;
    word = txt_tolower(word);

    int ans = 0;
    while (1)
    {
        string s;
        cin >> s;
        if (s == "END_OF_TEXT")
            break;
        s = txt_tolower(s);
        if (s == word)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
bool same(char a,char b){
    return (a=='?'||b=='?'||a==b);
}
bool ab[20010],ac[20010],bc[20010];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b,c;
    cin>>a>>b>>c;
    int A=a.size(),B=b.size(),C=c.size(),ans=6000;
    rep(i,A){
        rep(j,B){
            if(!same(a[i],b[j]))ab[i-j+10000]=true;
        }
    }
    rep(i,A){
        rep(j,C){
            if(!same(a[i],c[j]))ac[i-j+10000]=true;
        }
    }
    rep(i,B){
        rep(j,C){
            if(!same(b[i],c[j]))bc[i-j+10000]=true;
        }
    }
    for(int i=-4000;i<=4000;i++){
        for(int j=-4000;j<=4000;j++){
            if(!ab[i+10000]&&!ac[j+10000]&&!bc[j-i+10000]){
                int l=min({0,i,j}),r=max({A,B+i,C+j});
                chmin(ans,r-l);
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int cps(int w1, int h1, int w2, int h2) {
	int t1 = w1*w1 + h1*h1;
	int t2 = w2*w2 + h2*h2;
	if (t1<t2)return -1;
	else if (t1>t2)return 1;
	else if (h1<h2)return -1;
	else if (h1>h2)return 1;
	return 0;
}

int main(void) {
	for (;;) {
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}

		int mh, mw;
		mh = mw = 200;

		for (int hh = 1; hh <= 150; ++hh) {
			for (int ww = hh + 1; ww <= 150; ++ww) {
				if (cps(w, h, ww, hh) < 0 && cps(ww, hh, mw, mh) < 0) {
					mw = ww;
					mh = hh;
				}
			}
		}
		printf("%d %d\n", mh, mw);
	}
	return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<string>
using namespace std;
int main(){
	string row;
	while(1){
		int sum=0;
		cin>>row;
		if(row=="0")break;
		for(int i=0;i<row.size();i++){
			sum+=row[i]-'0';
		}
		cout<<sum<<endl;
	}
	return 0;
}


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

#define int long long
#define REP(i,n) for(int i=0;i<n;i++)
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
int ans=-1e18,v[5555],c[5555],used[5555];

signed main(){
  int n,k;cin>>n>>k;
  REP(i,n)cin>>v[i];
  REP(i,n)cin>>c[i];
  vector<vector<int>>w;
  REP(i,n){
    if(used[i])continue;
    w.push_back(vector<int>(0));
    int tmp=0,sum=0;
    while(!used[i]){
      used[i]=1;
      w.back().push_back(c[i]);
      sum+=c[i];
      i=v[i]-1;
    }
    int K=k,S=w.back().size();
    if(sum>0&&K/S>0)tmp+=(K/S-1)*sum;
    if(K>S)K=K%S+S;
    REP(j,S){
      int tmp2=0;
      REP(l,K){
        tmp2+=w.back()[(j+l)%S];
        chmax(ans,tmp+tmp2);
      }
    }
  }
  cout<<ans<<endl;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int total = A.at(0);
  for (int i = 1; i < N; i++) total = total ^ (A.at(i));
  for (int i = 0; i < N; i++)
  {
    int ans = total ^ (A.at(i));
    cout << ans << endl;
  }
}


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

using namespace std;

typedef long long ll;

const int N=100000+5;

int n,v[N];

/// bag AIB

int aib[2*N];

inline void add(int poz,int x)
{
    poz+=N;
    for(int i=poz;i<2*N;i+=i&(-i))
        aib[i]+=x;
}

inline int prefix(int poz)
{
    poz+=N;
    int ans=0;
    for(int i=poz;i>=1;i-=i&(-i))
        ans+=aib[i];
    return ans;
}

inline ll cate(int x)
{
    for(int i=0;i<2*N;i++) aib[i]=0;
    ll ans=0;
    add(0,1);
    int pr=0,mi=0;
    for(int i=1;i<=n;i++)
    {
        if(v[i]>=x) pr++;
        else pr--;
        int cur=prefix(pr);
        ans+=cur;
        add(pr,1);
    }
    return ans;
}

int lo=1,hi=1,ans=0;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        hi=max(hi,v[i]);
    }
    ll total=(ll)n*(n+1)/2;
    ll jum=(total+1)/2;
    while(lo<=hi)
    {
        int mid=(lo+hi)/2;
        ll cnt=cate(mid);
        if(cnt>=jum)
        {
            ans=mid;
            lo=mid+1;
        }
        else
            hi=mid-1;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 1408
//ProblemD

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemD

class Solve {
private:

	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(begin(a), end(a));
		int x = a.back();

		auto j = lower_bound(a.begin(), a.begin() + n - 1, x / 2) - a.begin();
		if (j && (x - a[j]) <= a[j-1]) {
			j = j - 1;
		}
		cout << x << ' ' << a[j] << endl;
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int N=50+10;

char arr1[N];
int arr2[N];

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


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(3*n);
    rep(i, 3*n)cin >> a[i];
    vector<ll> s(n+1, 0), t(n+1, 0);
    rep(i, n)s[0] += a[i];
    rep(i, n)t[n] += a[3*n-1-i];

    priority_queue<ll, vector<ll>, greater<ll>> que;
    rep(i, n)que.push(a[i]);
    for(int i = n; i < 2 * n; i++){
        que.push(a[i]);
        s[i-n+1] = s[i-n];
        s[i-n+1] += a[i] - que.top();
        que.pop();
    }
    priority_queue<ll> q;
    rep(i, n)q.push(a[3*n-1-i]);
    for(int i = 2 * n - 1; i >= n; i--){
        q.push(a[i]);
        t[i-n] = t[i-n+1];
        t[i-n] += a[i] - q.top();
        q.pop();
    }
    ll ans = -1001001001001001001;
    rep(i, n+1)ans = max(ans, s[i] - t[i]);
    cout << ans << endl;
}

Measured memory_bytes: 6516
a = 'keyence'
s = input()
S = len(s)
if s[:7] == 'keyence':
    print('YES')
elif s[:6] == 'keyenc' and s[-1] == 'e':
    print('YES')
elif s[:5] == 'keyen' and s[-2:] == 'ce':
    print('YES')
elif s[:4] == 'keye' and s[-3:] == 'nce':
    print('YES')
elif s[:3] == 'key' and s[-4:] == 'ence':
    print('YES')
elif s[:2] == 'ke' and s[-5:] == 'yence':
    print('YES')
elif s[0] == 'k' and s[-6:] == 'eyence':
    print('YES')
elif s[-7:] == 'keyence':
    print('YES')
else:
    print('NO')

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

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

  ll N, S;
  cin >> N >> S;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  ll MOD = 998244353;
  vector<vector<int>> n(N + 1, vector<int>(S + 1, 0));
  vector<vector<int>> l(N + 1, vector<int>(S + 1, 0));
  vector<vector<int>> r(N + 1, vector<int>(S + 1, 0));
  n[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < S + 1; j++) {
      n[i + 1][j] = (n[i + 1][j] + n[i][j]) % MOD;
      l[i + 1][j] = (l[i + 1][j] + n[i][j]) % MOD;
      l[i + 1][j] = (l[i + 1][j] + l[i][j]) % MOD;
      r[i + 1][j] = (r[i + 1][j] + n[i][j]) % MOD;
      r[i + 1][j] = (r[i + 1][j] + l[i][j]) % MOD;
      r[i + 1][j] = (r[i + 1][j] + r[i][j]) % MOD;
      if (j + A[i] <= S) {
        l[i + 1][j + A[i]] += n[i][j];
        l[i + 1][j + A[i]] += l[i][j];
        r[i + 1][j + A[i]] += n[i][j];
        r[i + 1][j + A[i]] += l[i][j];
      }
    }
  }
  // for (int i = 0; i <= N; i++) {
  //   for (int j = 0; j <= S; j++) {
  //     cout << n[i][j] << ' ';
  //   }
  //   cout << "  ";
  //   for (int j = 0; j <= S; j++) {
  //     cout << l[i][j] << ' ';
  //   }
  //   cout << "  ";
  //   for (int j = 0; j <= S; j++) {
  //     cout << r[i][j] << ' ';
  //   }
  //   cout << '\n';
  // }
  cout << (r[N][S] % MOD) << '\n';
  return 0;
}


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

int main(){
  int n,minN,ans;
  cin >> n;
  vector<int> w(n),s1(n-1),s2(n-1);
  for(int i = 0 ;i < n;i++){
    cin >> w.at(i);
  }
  for(int h = 0;h < n-1;h++){
    for(int g = 0;g <= h;g++){
      s1.at(h) += w.at(g);
    }
  }
  for(int h = 0;h < n-1;h++){
    for(int g = h+1;g < n;g++){
      s2.at(h) += w.at(g);
    }
  }
  minN = -1; ans = 101;
 for(int j = 0;j < n-1;j++){
  minN = abs(s1.at(j) - s2.at(j));

   if(minN < ans){
     ans = minN;
   }
 }
  cout << ans << endl;


  return 0;
}

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

using namespace std;

int main() {

  while(1) {

    long long int w, h;
    cin >> w >> h;

    if ( w == 0 ) break;

    vector< string > m;

    for ( long long int i = 0; i < w; i++ ) {

      string in;
      cin >> in;
      m.push_back( in );

    }

    bool f[101][101] = {};

    long long int x = 0;
    long long int y = 0;

    for (;;) {

      if ( m[y][x] == '.' ) {
	cout << x << " " << y << endl;
	break;
      }else if ( m[y][x] == '>' ) {
	x++;
      }else if ( m[y][x] == '<' ) {
	x--;
      }else if ( m[y][x] == '^' ) {
	y--;
      }else if ( m[y][x] == 'v' ) {
	y++;
      }
      if ( f[y][x] == true ) {
	cout << "LOOP" << endl;
	break;
      }
      f[y][x] = true;

    }

  }

  return 0;

}

Measured memory_bytes: 1244
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

char s[200005];
int main()
{
    int b,c;
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        if(s[i]=='A')
        {
            b=i;
            for (int j = i; j < len; j++)
            {
                if(s[j]=='Z')
                {
                    c=j;
                }
            }
            break;
        }
    }
    printf("%d\n",c-b+1 );
    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
B = [0] * N
kabu = 0
yen = 1000
for i in range(1,N):
    if A[i] >= A[i - 1]:
        B[i] = 1
for i in range(1,N):
    if B[i] == 1 and B[i - 1] == 0:
        kabu = yen // A[i - 1]
        yen = yen - kabu * A[i - 1]
    elif B[i] == 0 and B[i - 1] == 1:
        yen = yen + kabu * A[i - 1]
        kabu = 0
print(yen + kabu * A[N - 1])

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void fastio(){
	 ios_base::sync_with_stdio(false);
	 cin.tie(0);
	 cout.tie(0);
}
int main() {
	fastio();
	ll n,ans=0;
	cin>>n;
	ll ar[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		if((ar[i]-b[i])>0)
		ans+=ar[i]-b[i];
	}
	cout<<ans;
	
	
	return 0;
}

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

int main(void){
    int N;
    cin >> N;
    vector<long long> T(N);
    long long sum = 0;
    for(int i = 0; i < N; i++){
        cin >> T[i];
        sum += T[i];
    }
    int M;
    cin >> M;
    for(int i = 0; i < M; i++){
        int P;
        long long X;
        cin >> P >> X;
        cout << sum - T[P - 1] + X << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int i,j,tmp,r;

  scanf("%d%d",&i,&j);
  if(i<j){
    tmp = i;
    i = j;
    j = tmp;
  }

  r = i%j;

  while(r != 0){
    i = j;
    j = r;
    r = i%j;
  }
  printf("%d\n",j);

  return 0;
}



Measured memory_bytes: 2140
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll power = 1LL;
	for(ll i = 1; i <= n; i++){
		power *= i;
		power %= 1000000007;
	}
	cout << power << endl;
	return 0;
}

Measured memory_bytes: 256
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int shihab;
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
//   FI(); /// skip this line for compile
    ll x,k,d;
    cin >> x >> k >> d;

    if(x<0)
        x*=-1;

    if(x/k>=d)
        cout << x-k*d << endl;
    else
    {
        ll n = x/d;
        ll m = x%d;
        ll baki = k-n;
        if(baki%2==0)
            cout << m << endl;
        else
            cout << d-m << endl;
    }
    return 0;
    //code end
}
//okbye


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

struct RollingHash{ //ローリングハッシュ法
private:
    static const int_fast32_t mod1 = 1031326447, mod2 = 993766717;
    static const int_fast32_t base1 = 281, base2 = 383;
    vector<int_fast64_t> hash1, hash2, pow1, pow2;
public:
    string str;
    RollingHash(const string& s) : str(s) { //初期化
        int_fast32_t sz = (int_fast32_t)s.size();
        hash1.assign(sz + 1, 0); hash2.assign(sz + 1, 0);
        pow1.assign(sz + 1, 1); pow2.assign(sz + 1, 1);
        for(int_fast32_t i = 0; i < sz; i++){
            hash1[i + 1] = (hash1[i] * base1 + s[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + s[i]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    inline pair<int_fast64_t, int_fast64_t> get(int_fast32_t l, int_fast32_t r){ //[l, r)
        int_fast64_t res1 = (hash1[r] - hash1[l] * pow1[r - l]) % mod1;
        int_fast64_t res2 = (hash2[r] - hash2[l] * pow2[r - l]) % mod2;
        if(res1 < 0)res1 += mod1; if(res2 < 0)res2 += mod2;
        return { res1, res2 };
    }
    inline int_fast32_t getLCP(int_fast32_t x, int_fast32_t y){ //LCP S[a:], S[b:]
        int_fast32_t len = min((int_fast32_t)size() - x, (int_fast32_t)size() - y) + 1;
        int_fast32_t l = 0, r = len;
        while(r - l > 1){
            int_fast32_t m = (l + r) >> 1;
            if(get(x, x + m) != get(y, y + m))r = m;
            else l = m;
        }
        return l;
    }
    inline void add_str(const string& s){ //string型を連結
        int_fast32_t ns = (int_fast32_t)str.size(), ms = (int_fast32_t)s.size();
        str += s;
        hash1.resize(ns + ms + 1); hash2.resize(ns + ms + 1);
        pow1.resize(ns + ms + 1); pow2.resize(ns + ms + 1);
        for(int_fast32_t i = ns; i < ns + ms; i++){
            hash1[i + 1] = (hash1[i] * base1 + s[i - ns]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + s[i - ns]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    inline void add_char(const char& c){ //char型を連結
        str += c;
        hash1.push_back((hash1.back() * base1 + c) % mod1);
        hash2.push_back((hash2.back() * base2 + c) % mod2);
        pow1.push_back((pow1.back() * base1) % mod1);
        pow2.push_back((pow2.back() * base2) % mod2);
    }
    inline void add_rh(const RollingHash& rh){ //rhを連結
        add_str(rh.str);
    }
    inline size_t size(){ //strのsizeを返す
        return str.size();
    }
};

int main(){

    int N;
    cin >> N;

    string S;
    cin >> S;
    RollingHash rh(S);

    int ans = 0;
    for(int i = 0; i < N - ans; i++){
        for(int j = 0; j < i - ans; j++){
			if(S[i] != S[j])continue;
          	chmax<int>(ans, min<int>(rh.getLCP(i, j), i - j));
        }
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    if(s.size()==2){
        if(s[0]==s[1])cout<<1<<" "<<2<<endl;
        else cout<<-1<<" "<<-1<<endl;
        return 0;
    }
    for(int i=0;i<s.size()-2;i++){
        if(s[i]==s[i+1] || s[i+1]==s[i+2] || s[i+2]==s[i]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 512