akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

map<int, int> prime_factor(int n) {
  map<int, int> ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

map<int, int> mp;

int num(int k)
{
  int ret = 0;
  for(auto p: mp){
    if(p.second>=k) ret++;
  }
  return ret;
}

int main()
{
  int n;
  cin >> n;
  
  for(int i=2; i<=n; i++){
    map<int, int> tmp = prime_factor(i);
    for(auto itr=tmp.begin(); itr!=tmp.end(); itr++){
      mp[itr->first] += itr->second;
    }
  }
  
  int ans = 0;
  ans += num(74);
  ans += num(24) * (num(2) - 1);
  ans += num(14) * (num(4) - 1);
  ans += num(4) * (num(4) - 1) * (num(2) - 2) / 2;
  cout << ans << '\n';
  return 0;
}


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

int main() {
  
  int A, B, max;
  cin >>A >>B;
  
  max = A+B;
  
  if(max<A-B){
	  
		max=A-B;
	  
  }
  if(max<A*B){
	  
	  max=A*B;
	  
  }
  
  cout <<max <<endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll n; cin>>n;
    cout << "ABC" << setfill('0') << right << setw(3) << n << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  LL n,p;
  cin >> n >> p;
  if(n == 1) {
    cout << p << endl;
    return 0;
  }
  LL answer = 1;
  FOR(i, 2, (1<<20)) {
    int pow = 0;
    while(p%i == 0) {
      ++pow;
      p/=i;
    }
    REP(j, pow/n) answer*=i;
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;

void solve()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}

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


Measured memory_bytes: 256
inf = float('inf')
def dijkstra(s):
    d = [(inf, 1)] * N
    used = [False] * N
    d[s] = (0, -L)  
    for i in range(N):
        v = -1
        for i in range(N):
            if used[i]:
                continue
            if v==-1:
                v = i
            elif d[v]>d[i]:
                v = i
        if v == -1:
            break
        used[v] = True   
        m, r = d[v]
        r = -r
        for nv in range(N):
            c = cost[v][nv]
            if r>=c:
                d[nv] = min(d[nv],(m, -(r-c)))
            elif c<=L:
                d[nv] = min(d[nv], (m+1, -(L-c)))
    return d
N, M, L = map(int, input().split())
cost = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c
ans = []
for i in range(N):
    ans.append(dijkstra(i))
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    res = ans[a-1][b-1][0]
    print(res if res != inf else -1)

Measured memory_bytes: 72408
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math
from collections import defaultdict
pc = True
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)

LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
def make():
    for i in range(2,LIMIT+1):
        if minPrime[i] == 0:
            minPrime[i] = i
            #print(i)
            for j in range(i+i,LIMIT+1,i):
                #print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i
make()
class Sieve_of_Eratosthenes:
    def __init__(self, N):
        self.sieve = [-1] * (N+1)

        for i in range(2,N+1):
            if self.sieve[i] == -1:
                for j in range(1,1+N//i):
                    self.sieve[i*j] = i

    def isprime(self, num):
        if num <= 1:
            return False
        else:
            return self.sieve[num] == num

    def factorization(self, num):
        ret = set([])
        while num != 1:
            div = self.sieve[num]
            ret.add(div)
            num //= div
        return ret

sofe = Sieve_of_Eratosthenes(M)
ddic = defaultdict()
judge = set([])

for i in a:
    if not pc:
        break
    asf = sofe.factorization(i)

    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")
# import sys,collections

# N = int(sys.stdin.readline())
# #a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = list(map(int,input().split()))

# import math

# # def factrial(N):
# #     ret = []
# #     while minPrime[N] != N:
# #         ret.append(minPrime[N])
# #         N = N//minPrime[N]
# #     if N != 1:
# #         ret.append(N)
# #     return ret

# def factrial(N):
#     ret = set()
#     while 1 != N:
#         ret.add(minPrime[N])
#         N = N//minPrime[N]
#     if N != 1:
#         ret.add(N)
#     return ret

# for i in range(N):
#     acc = math.gcd(acc,a[i])
# if acc != 1:
#     print("not coprime")
#     exit()

# pairwise = True
# p = set() #all prime
# for e in a:
#     if not pairwise:
#         break
#     f = factrial(e)
#     if p & f != set():
#         pairwise = False
#         print("setwise coprime")
#         exit(0)
#     p = p | f

# if pairwise:
#     print("pairwise coprime")
# else:
#     print("setwise coprime")


Measured memory_bytes: 195084
#include <iostream>

namespace ABC175
{

  class C
  {
  public:
    C() = default;
    ~C() = default;


    void Run()
    {
      long long X = {};
      long long K = {};
      long long D = {};
      std::cin >> X;
      std::cin >> K;
      std::cin >> D;

      long long absX = X < 0 ? -X : X;
      long long minx_requireK = (absX / D);
      bool is_over_zero = false;
      if (absX - D * minx_requireK > D / 2) { minx_requireK++; is_over_zero = true; }

      long long Answer = X;
      if (minx_requireK > K)
      {
        Answer = absX - K * D;
      }
      else
      {
        long long restK = K - minx_requireK;
        if ((restK & 1) == 1)
        {
          Answer = absX - (minx_requireK + (is_over_zero ? -1 : 1)) * D;
        }
        else
        {
          Answer = absX - minx_requireK * D;
        }
      }

      if (Answer < 0) Answer = -Answer;

      std::cout << Answer << std::endl;
    }
  };

}
int main()
{

  ABC175::C prob;
  prob.Run();

  return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>
#include <string.h>
#include <stack>
#include <iostream>
using namespace std;

#define LARGE_NUM 114514
 
using namespace std;
 
int main(void)
{
	int K,T;
	cin >> K >> T;
	int a[LARGE_NUM];
	int A = 0;
	int I;

	int cake;

	for(int i=0;i<T;i++){
		cin >> a[i];
		if(A<a[i]){
			A=a[i];
			I = i;
		}
	}

	cake = A;

	for(int i=0;i<T;i++){
		if(i != I){
			cake -=a[i];
		}
	}
		cake--;


	cout << max(cake,0) << endl;
	return 0;
 
}

Measured memory_bytes: 256
N = int(input())
c = list(str(input()))

num = 0
x = N
flag = False
for i in range(N):
    if c[i] == "W":
        for j in reversed(range(x)):
            if j <= i:
                flag = True
                break
            elif c[j] == "R":
                c[i] = "R"
                c[j] = "W"
                x = j
                num += 1
                #print(i,j,c)
                break

    if flag:
        break

print(num)

Measured memory_bytes: 77604
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by shoya on 2017/04/30.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int N = sc.nextInt();
        int T = sc.nextInt();
        ArrayList<Integer> t = new ArrayList<Integer>();
        for (int i = 0; i < N; i++){
            t.add(sc.nextInt());
        }

        int prev = -1;
        long ans = 0;
        for (int i : t){
            //System.out.println(i);
            if (prev != -1 && i - prev < T){
                ans += i - prev;
            }
            else{
                ans += T;
            }
            prev = i;
        }

        pw.println(ans);
        pw.flush();
        return;
    }
}

Measured memory_bytes: 67512
data = input().split()
tab = [int(data[0]), int(data[1]),int(data[2])]
tab = sorted(tab)
a, b, c = tab[0], tab[1], tab[2]
res = 0
res += c - b
a += res
b += res

while (a < b):
    res += 1
    a += 2

if (a > b):
    print( res+1)
else:
    print(res)


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

int main(){
	char num1[102], num2[102];

	for(int i = 0; i < 102; ++i){
		num1[i] = 0;
		num2[i] = 0;
	}

	cin >> num1 >> num2;
	int flag = 102;

	for(int i = 101; i >= 0; --i){
		if(num1[i] != 0 && num2[i] == 0){
			cout << "GREATER\n";
			break;
		}else if(num1[i] == 0 && num2[i] != 0){
			cout << "LESS\n";
			break;
		}else if(num1[i] != 0 && num2[i] != 0){
			flag = i;
			break;
		}
	}

	if(flag < 102){
		for(int i = 0; i <= flag; ++i){
			if(num1[i] > num2[i]){
				cout << "GREATER\n";
				break;
			}else if(num1[i] < num2[i]){
				cout << "LESS\n";
				break;
			}
			if(i == flag)
				cout << "EQUAL\n";
		}
	}

	return 0;
}

Measured memory_bytes: 256
import collections

def bfs(tree, s, distance):
    queue = collections.deque([s])
    distance[s] = 0

    while queue:
        v = queue.popleft()
        v_c = distance[v]
        for node, cost in tree[v]:
            if distance[node] == -1:
                distance[node] = v_c + cost
                queue.append(node)

N = int(input())

Tree = collections.defaultdict(list)

for i in range(N - 1):
    a, b, c = map(int, input().split())
    Tree[a].append((b, c))
    Tree[b].append((a, c))

q, k = map(int, input().split())

distance = collections.defaultdict(lambda : -1)
bfs(Tree, k, distance)

for i in range(q):
    x, y = map(int, input().split())
    print(distance[x] + distance[y])


Measured memory_bytes: 58528
#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define MAXN   1015
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n , m ;
    cin >> n >> m ;
    cout << (((n-1)*n)/2)+ (((m-1)*m)/2) << endl ;
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    def select(n,k):
        return math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    n,p = LI()
    a = LI()
    a = list(map(lambda x: x%2, a))
    dic = collections.Counter(a)
    c0 = dic[0]
    c1 = dic[1]
    ans = 0

    if p == 0:
        for i in range(n+1):
            for s in range(i//2+1):
                n1 = 2*s
                n0 = i-n1
                if n0<=c0 and n1<=c1:
                    ans += select(c0,n0)*select(c1,n1)
    else:
        for i in range(1,n+1):
            for s in range((i-1)//2+1):
                n1 = 2*s+1
                n0 = i-n1
                if n0<=c0 and n1<=c1:
                    ans += select(c0,n0)*select(c1,n1)
                    
    print(ans)

main()            


Measured memory_bytes: 74684
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
s=input()
a=[]
b=[]
now=1
q=int(input())
for i in range(q):
    x=list(input().split())
    if x[0]=="1":
        now*=-1
    else:
        if now==1 and x[1]=="2" or now==-1 and x[1]=="1":
            b.append(x[2])
        else:
            a.append(x[2])
if now==-1:
    ans=b[::-1]+list(s[::-1])+a
    print(*ans,sep="")
else:
    ans=a[::-1]+list(s)+b
    print(*ans,sep="")


Measured memory_bytes: 13492
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;

ll POWER (ll x, ll y, ll mod){
    ll ans = 1, c = x;
    while (y){
        if ((y & 1) == 1)
            ans = ans * c % mod;
        c = c * c % mod;
        y /= 2;
    }
    return ans;
}

const ll N = 1e5 + 5, MOD = 1e9 + 7;
const double C = 1;

ll n, k;
ll a[N], s[N];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    a[0] = 1;
    for (int i = 0; i <= k; i++)
        s[i] = 1;
    while (n--){
        int x;
        cin>>x;
        for (int i = 0; i <= k; i++){
            a[i] = s[i];
            if (i - x - 1 >= 0)
                a[i] -= s[i - x - 1];
            if (a[i] < 0)
                a[i] += MOD;
        }
        s[0] = a[0];
        for (int i = 1; i <= k; i++)
            s[i] = (s[i - 1] + a[i]) % MOD;
    }
    cout<<a[k]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;

    int c = stoi(a + b);
    int d = (int)sqrt(c);

    cout << (c == d * d ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int a, b;

 scanf("%d", &a);

 scanf("%d", &b);

 if (a > b)
 printf("a > b\n");
else if (a < b)
 printf("a < b\n");
else if (a == b)
 printf("a == b\n");

 return 0;

}



Measured memory_bytes: 2060
from math import ceil
n,k = map(int, input().split())
bi = [2**i for i in range(1000)]
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1 / n
        continue
    for j in range(1,k+1):
        if i * bi[j] >= k:
            # print(j, i * 2**j)
            break
    ans += (0.5**j) / n
print('{:.10f}'.format(ans))

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;


void solve()
{
    int h, w; cin >> h >> w;
    char image[h+1][w+1];
    FOR(i, 1, h+1)
        FOR(j, 1, w+1) cin >> image[i][j];

    FOR(i, 1, 2*h+1)
    {
        FOR(j, 1, w+1)
        {
            cout << image[(i+1)/2][j];
        }
        cout << endl;
    }
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define popcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>

T pow(T a, long long n, ll mod, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        ret %= mod;
        a %= mod;
        n >>= 1;
    }
    return ret % mod;
}

int solve(int n){
    if(n == 0) return 0;
    return solve(n % popcnt(n)) + 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n; string s; cin >> n >> s;
    ll cnt = 0;
    REP(i, n) if(s[i] == '1') cnt++;
    ll psum = 0, msum = 0;
    REP(i, n) if(s[i] == '1'){
        psum += pow((ll)2, n - i - 1, cnt + 1);
        psum %= (cnt + 1);
    }
    if(cnt - 1) REP(i, n) if(s[i] == '1'){
        msum += pow((ll)2, n - i - 1, cnt - 1);
        msum %= (cnt - 1);
    }
    REP(i, n){
        if(s[i] == '0'){
            ll x = psum + pow((ll)2, n - i - 1, cnt + 1);
            x %= (cnt + 1);
            cout << solve(x) + 1 << endl;
        }
        else{
            if(!(cnt - 1)){
                cout << 0 << endl;
                continue;
            }
            ll y = msum - pow((ll)2, n - i - 1, cnt - 1);
            y %= (cnt - 1);
            if(y < 0) y += (cnt - 1);
            cout << solve(y) + 1 << endl;
        }
    }
}

Measured memory_bytes: 3736
"""
r > p
s > r
p > s
"""
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

ans = 0
hand = [""] * n

for i in range(n):
    if i < k:
        if t[i] == "r":
            ans += p
            hand[i] = "p"
        elif t[i] == "s":
            ans += r
            hand[i] = "r"
        elif t[i] == "p":
            ans += s
            hand[i] = "s"
    else:
        if t[i] == "r":
            if hand[i-k] != "p":
                ans += p
                hand[i] = "p"
            else:
                hand[i] = "?"
        elif t[i] == "s":
            if hand[i-k] != "r":
                ans += r
                hand[i] = "r"
            else:
                hand[i] = "?"
        elif t[i] == "p":
            if hand[i-k] != "s":
                ans += s
                hand[i] = "s"
            else:
                hand[i] = "?"
print(ans)


Measured memory_bytes: 4084
def find_ways(n, x):
    number_list = [i+1 for i in range(n)]
    cnt = 0
    for j in number_list:
        if j > n-2:
            break
        for k in number_list:
            if k <= j:
                continue
            l = x - j - k
            if l > n or l <= k:
                continue
            else:
                cnt += 1
    return cnt
 
while True:
    data = list(map(int, list(input().split())))
    if data[0] == 0 and data[1] == 0:
        break
    else:
        comb = find_ways(data[0], data[1])
        print(comb)



Measured memory_bytes: 5604
#include <stdio.h>
int main (){
	int a,b,c,temp;
	scanf ("%d %d %d",&a,&b,&c);
	temp=0;
	if (a>b){
		temp=a; //temp becomes a
		a=b; //a becomes b
		b=temp; //temp becomes b
	}
		if (b>c){
		temp=b;
		b=c;
		c=temp;
	}
		if (a>b){
		temp=a;
		a=b;
		b=temp;
	}
		printf ("%d %d %d\n",a,b,c);
	
	return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//
bool lost[100010];
string S;
int N;
int dfs(int a,int b)
{
  if(lost[a] && a > 0)return dfs(a-1,b);
  if(lost[b] && b < N-1)return dfs(a,b+1);
  if(lost[a] || lost[b]) return 0;
  if(S[a] == S[b]) return 0;
  lost[a] = true;
  lost[b] = true;
  if(a <= 0 || b >= N-1) return 2;
  else return 2 + dfs(a-1,b+1); 
}
signed main()
{
  ios();
  cin >> S;
  int ans = 0;
  int N = S.length();
  rep(i,N)
  {
    lost[i] = false;
  }
  rep(i,N-1)
  {
    ans += dfs(i,i+1);
  }
  cout << ans << endl;


}


Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  string s[n];
  rep(i,n) cin>>s[i];
  ll march[5] = {};
  rep(i,n) {
    if(s[i][0] == 'M') march[0]++;
    if(s[i][0] == 'A') march[1]++;
    if(s[i][0] == 'R') march[2]++;
    if(s[i][0] == 'C') march[3]++;
    if(s[i][0] == 'H') march[4]++;
  }
  ll ans = 0;
  
  for(int i = 0; i <= 2; i++)
  {
    for(int j = i + 1; j <=3; j++)
    {
      for(int k = j + 1; k <= 4; k++)
      {
        ans += march[i] * march[j] * march[k];
      }
    }
  }
  cout << ans << endl;
  

  return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    LL k,a,b;cin>>k>>a>>b;

    if(a+2>=b){
        cout<<k+1<<endl;
        return;
    }
    if(k<=a){
        cout<<k+1<<endl;
        return;
    }
    LL result = 0;
    k -= a+1;
    result += b;

    result += (k/2)*(b-a);
    result += k%2;
    cout<<result<<endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    string s;
    cin >> s;

    if (s <= "2019/04/30") {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl; 
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import bisect
n = int(input())
a = list(map(int, input().split()))

a.sort()
m = a[-1] / 2


i = bisect.bisect_left(a[:-1], m)

if i == n-1:
    i -= 1
elif i > 0 and abs(a[i-1]-m) < abs(a[i]-m):
    i -= 1

print(a[-1], a[i])

Measured memory_bytes: 14420
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
int main()
{
  string W;
  string T;
  string s;
  char ch;
  int point = 0;
  int result = 0;
  cin >> W;
  cin >> s;
  while (s != "END_OF_TEXT")
  {
    T += s;
    T += " ";
    cin >> s;
  }

  // すべて小文字にする
  for (int i = 0; i < T.size(); i++)
  {
    if (T.at(i) >= 65 && T.at(i) <= 90)
    {
      char c = T.at(i) + 32;
      T.at(i) = c;
    }
  }

//  cout << W << endl;
//  cout << T << endl;
  // 空白で分離
  istringstream iss(T);
  while (iss >> s)
  {
    if (s.size() != W.size())
    {
      continue;
    }
//    cout << s << "\n";
    for (int i = 0; i < W.size(); i++)
    {
      if (s.at(i) == W.at(i))
      {
        point++;
      }
    }
    if (point == W.size())
    {
      result++;
    }
    point = 0;
  }
  cout << result
       << "\n";
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, j , k , l , n,counter;
 bool ara3[200000];
 void seive()
 {
     for(i= 2; i<=100001; i++)
     {
         ara3[i]  = true;
     }
     ara3[1]  = false;
     for(i=2 ; i<=100001; i++)
     {
         for(j=2;i*j<=100001; j++)
         {
             if(ara3[i]==true)
             {
                 ara3[i*j] = false;
             }
         }
     }
 }
int main(void)
{
    seive();
     while(cin>>n)
     {
         counter = 0;
         for(i=1,j=n; i<=n; i++,j--)
         {
             if(ara3[i]==true && ara3[j]==true)
             {
                 counter++;
             }

         }
         cout<<counter<<endl;
     }
     return 0;

}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    ll n;cin>>n;
    n--;
    ll ans=(n*(n+1))/2;
    cout<<ans;
    
    
    
    
 return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if (A % 2 == 0 || B % 2 == 0) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
//****************************************************                
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define vvll vector<vector<ll>>
#define mtp make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions
void solve();

int binary(int a[],int l,int r,int find)
{
    if(l>r)
    {
        return -1; 
    }else
    {
        int mid=(l+r)/2;
        if(a[mid]==find)
        {
            return mid+1;
        }else if(a[mid]>find)
        {
            binary(a,l,mid-1,find);
        }else
        {
            binary(a,mid+1,r,find);
        }   
    }   
}

int main()
{
    FAST_IO;
    ll testcases = 1;
    // cin >> testcases; //comment for 1 test case
    while(testcases--)
    {
        solve();
    }
}

void solve()
{
    ll a,b;
    cin>>a>>b;
    ll v=b-2*a;
    if(v<0 || v%2)
    {
    	cout<<"No";
    	nl;
    }else
    {
    	ll y=a-v/2;
    	if(y>=0)
    	{
    		cout<<"Yes";
    		nl;
    	}else
    	{
    		cout<<"No\n";
    	}
    }
}

Measured memory_bytes: 3652
n = gets.to_i
k = gets.to_i
x_i = gets.split.map(&:to_i)
sum = 0

# ボールが一つの場合を考える
x_i.each do |pos|
  a = pos
  b = k - pos
  if a > b then
    distance = b * 2
  else
    distance = a * 2
  end
  sum += distance
end

p sum


Measured memory_bytes: 1788
//In The Name Of God
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 1e3 + 5, Mod = 1e9 + 7, P = 727, Lg = 22, TOF = 1900, Inf = 3e18 + 10;

int Dp[N][N];
char C[N][N];
int main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n, m; cin >> n >> m;
      for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                  cin >> C[i][j];
      for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                  if(i == 1 && j == 1){
                        Dp[i][j] = 1;
                        continue;
                  }
                  if(C[i][j] != '.')
                        continue;
                  Dp[i][j] = (Dp[i - 1][j] + Dp[i][j - 1]) % Mod;
            }
      }
      cout << Dp[n][m];
      return 0;
}



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

using namespace std;
long long x[110],v[110],dp[100010][110];
int main(){

  int n,w;
  cin>>n>>w;

  memset(dp,0,sizeof(dp));

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

  for(int i=1;i<=w;i++){
    for(int j=1;j<=n;j++){
      dp[i][j]=dp[i][j-1];
      if(i>=x[j]){
        dp[i][j]=max(dp[i][j],dp[i-x[j]][j-1] + v[j]);
      }
    }
  }

  cout<<dp[w][n];

   return 0;
}

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

using namespace std;

int main(void)
{
    int N, A, B;
    string S;
    cin >> N >> A >> B;
    cin >> S;

    int kakutei = 0;
    int junni = 1;

    for (int i = 0; i < N; ++i) {
        if (S[i] == 'a' && kakutei < A + B) {
            ++kakutei;
            cout << "Yes" << endl;
        }
        else if(S[i] == 'b' && kakutei < A + B && junni <= B){
            ++junni;
            ++kakutei;
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}


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

ll solve() {
    ll N;
    cin >> N;
    ll ans = 0;
    bool n9 = true;
    while ( N / 10 > 0 ) {
        ans += 9;
        if ( N % 10 != 9 ) n9 = false;
        N /= 10;
    }
    ans += n9 ? N : N-1;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import collections as col


n = int(input())
a = col.Counter(map(int, input().split()))

edges = []
for k, v in a.items():
    if v >= 4:
        edges.extend((k, k))
    elif v >= 2:
        edges.append(k)

edges.sort(reverse=True)

if len(edges) >= 2:
    print(edges[0]*edges[1])
else:
    print(0)


Measured memory_bytes: 24104
//It's time to be who I am, rather than who I am supposed to be.
#include<bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 1e5+10;
const int mod = 998244353;
const int inf = 1e12;
int n, k, h[N], dp[N];

int solve(int currPos){
	if(currPos <= 0)
		return inf;

	int &ans = dp[currPos];
	if(ans != inf)
		return ans;

	for(int i = 1; i <= k; i++){
		int prev = currPos - i;
		if(prev >= 1){
			ans = min(ans, solve(prev) + abs(h[prev] - h[currPos]));
		}
	}
	return ans;

}

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

    fill(dp, dp + N, inf);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    	cin >> h[i];

    dp[1] = 0;
    //dp[2] = abs(h[2] - h[1]);

    cout << solve(n) << '\n';

}

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define sz(x) int(x.size())

using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt
    /////////
    //write//
    /////////
    
    int n;
    cin >> n;
    int a[25], b[25], c[25];
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> b[i];
    rep(i, n-1)cin >> c[i];
    
    int res = 0;
    int prev_num = -100;
    for(int i=0; i<n; i++){
        int now_num = a[i];
        now_num--;
        if(now_num -1 == prev_num)res+=c[prev_num];
        res+=b[now_num];
        prev_num = now_num;
    }
    
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		Map<Integer, Long> map = new TreeMap<>();
		for(int i = 0 ; i < n ; i++) {
			int a = sc.nextInt();
			long b = sc.nextLong();
			if(map.containsKey(a)) {
				map.put(a, map.get(a) + b);
			} else {
				map.put(a, b);
			}
		}
		for(int key : map.keySet()) {
			k -= map.get(key);
			if(k <= 0) {
				System.out.println(key);
				return;
			}
		}
	}
}


Measured memory_bytes: 86968
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b;
    cin>>a;
    cin>>b;

    int c = a-2*b;

    if(c>0){
        cout<<c;
    }
    else {
        cout<<0;
    }



    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e3 + 5);

int n;

ll t[MAX_N], a[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

  for (int i = 1; i < n; ++i) {
    ll part_t = t[i - 1] / t[i];
    ll part_a = a[i - 1] / a[i];

    if (part_t == 0 && part_a == 0) {
      // do nothing
    }
    else if (part_t == 0) {
      for (ll j = part_a - 1; j < (part_a - 1 + 3); ++j) {
        if (a[i] * j >= a[i - 1]) {
          a[i] = a[i] * j;
          t[i] = t[i] * j;
          break;
        }
      }
    }
    else if (part_a == 0) {
      for (ll j = part_t - 1; j < (part_t - 1 + 3); ++j) {
        if (t[i] * j >= t[i - 1]) {
          a[i] = a[i] * j;
          t[i] = t[i] * j;
          break;
        }
      }
    }
    else {
      ll part = max(part_t, part_a);
      for (ll j = part - 1; j < (part - 1 + 3); ++j) {
        if (t[i] * j >= t[i - 1] && a[i] * j >= a[i - 1]) {
          a[i] = a[i] * j;
          t[i] = t[i] * j;
          break;
        }
      }
    }

  }

  printf("%lld\n", t[n - 1] + a[n - 1]);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A

#define swap(x, y)                                                             \
    x = x + y;                                                                 \
    y = x - y;                                                                 \
    x = x - y;

int main(int argc, char **argv) {
    int n, a[1024], i, j, cnt = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        // printf("%d\n", a[i]);
    }
    for (i = 0; i < n; i++) {
        for (j = n - 1; j > i; j--) {
            if (a[j - 1] > a[j]) {
                swap(a[j - 1], a[j]);
                cnt++;
            }
        }
    }
    for (i = 0; i < n; i++) {
        printf("%d", a[i]);
        if (i == n - 1)
            printf("\n");
        else
            printf(" ");
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 2112
s = gets.chomp.split("")
l = s.size
if l % 2 == 1
  s.delete_at(l / 2)
  l -= 1
end
count = 0

(0..l / 2 - 1).each do |i|
  count += 1 if s[i] != s[-i - 1]
end

puts count

Measured memory_bytes: 1788
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
#define int long long
using namespace std;

int b[10000];
signed main() {
	int a; cin >> a;
	int sum = 0;
	for (int c = 0; c < a; c++) {
		cin >> b[c];
		sum += b[c];
	}
	printf("%lld %lld %lld\n", *min_element(b, b + a), *max_element(b, b + a), sum);
}

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int A,B;
  cin>>A>>B;
  cout<<A*B<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int k,s;
      cin>>k>>s;
      int ans=0;
      for(int i=0;i<=k;i++)
      {
            for(int j=0;j<=k;j++)
            {
                  int o=s-(i+j);
                  if(o<=k&&o>=0)
                  {
                        ans++;
                  }
            }
      }
      cout<<ans;
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		while (scan.hasNext()) {
			double a = scan.nextDouble();
			double b = scan.nextDouble();
			double c = scan.nextDouble();
			double d = scan.nextDouble();
			double e = scan.nextDouble();
			double f = scan.nextDouble();

			double y = (c * d - a * f) / (b * d - a * e);
			double x = (c - b * y) / a;
			System.out.printf("%4.3f %4.3f\n", x, y);

		}

	}
}

Measured memory_bytes: 20568
#include <cstdio>
#include <cstring>
using namespace std;

int w, h, n;
int y, x;
int dp[1000][1000];
int table[1000][1000];

void solve(){
	memset(dp,0,sizeof(dp));
	x = 0; y = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++) scanf("%d", &table[i][j]);
	}
	dp[0][0] = n-1;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(dp[i][j]%2){
				if(table[i][j]){
					if(j != w-1) dp[i][j+1] += dp[i][j]/2+1;
					if(i != h-1) dp[i+1][j] += dp[i][j]/2;
				} else{
					if(j != w-1) dp[i][j+1] += dp[i][j]/2;
					if(i != h-1) dp[i+1][j] += dp[i][j]/2+1;
				}
				table[i][j] = (table[i][j]+1)%2;
			} else{
				if(j != w-1) dp[i][j+1] += dp[i][j]/2;
				if(i != h-1) dp[i+1][j] += dp[i][j]/2;
			}
		}
	}
	while(true){
		if(y == h || x == w){
			printf("%d %d\n", y+1, x+1);
			break;
		}
		if(table[y][x]){
			x++;
		} else{
			y++;
		}
	}
}

int main(){
	while(scanf("%d%d%d", &h, &w, &n), w||h||n) solve();
}

Measured memory_bytes: 8848
$num,$tracks = gets.split.map(&:to_i)
$ws = []
for i in 1..$num do
	w = gets.chomp.to_i
	$ws.push(w)
end

def check(p)
	i = 0
	for j in 1..$tracks do
		s = 0
		while s + $ws[i] <= p
			s = s + $ws[i]
			i = i + 1
			if i == $num then
				return $num
			end
		end
	end
	return i
end

def solve()
	left = 0
	right = 100000 * 10000
	while right - left > 1
		mid = (left + right) / 2
		v = check(mid)
		if v >= $num then
			right = mid
		else
			left = mid
		end
	end
	return right
end

ans = solve()
p ans

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

void f(ll N)
{
	char c;
	if (0 <= N && N <= 26) 
	{
		c = 'a' + (N-1);
		cout << c;
		return;
	}
	int n = N % 26;
	if (n == 0)
	{
		n = 26;
	}
	c = 'a' + (n-1);
	f((N-n)/26); 
	cout << c;
	return;
}

int main()
{
	ll N;
	cin >> N;
	f(N);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a);
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef double db;
const db EPS = 1e-9;
const int N = 1e5+100;
using namespace std;

void dbg() {cout << "\n";}
template<typename T, typename... A> void dbg(T a, A... x) {cout << a << ' '; dbg(x...);}
#define logs(x...) {cout << #x << " -> "; dbg(x);}

int n,a[N];
ll ans;

int main()
{
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d",&a[i]);
		if(a[i]%2 == 1 && a[i] >= 3){
			ll cnt = a[i]-3;
			ans += cnt/2ll;
			a[i] = 3;
		}
		else if(a[i]%2 == 0 && a[i] >= 2){
			ll cnt = a[i]-2;
			ans += cnt/2ll;
			a[i] = 2;
		}
	}
	// logs(ans);
	rep(i,1,n){
		// logs(i,a[i],ans);
		if(a[i] == 2) ans++;
		else if(a[i] > 0){
			if(a[i] >= 2) ans++, a[i] -= 2;
			if(a[i+1] >= 1){
				ans++;
				a[i+1]--;
			}
		} 
	}
	printf("%lld\n",ans);
	return 0;
}
/*
4
2
1
2
1
*/

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int a, b;
    char op;
    cin >> a >> op >> b;

    if(op == '+'){
        cout << a+b << endl;
    }else{
        cout << a-b << endl;
    }
}


Measured memory_bytes: 256
S = (input())
N = len(S)
Ps = [0 for _ in range(N)]
i = p = 0
j = q = 1
while j < N:  # i <= p < q <= j
  while S[p] == "R":
    p += 1
  p -= 1
  q = j = p + 1
  while j < N and S[j] == "L":
    j += 1
  j -= 1
  n = j - i + 1
  if n % 2 == 0:
     Ps[p] = Ps[q] = n // 2
  else:
     r = p - i + 1
     l = j - q + 1
     if r % 2 == 1:
       d = n // 2
       Ps[p], Ps[q] = d + 1, d
     else:
       d = n // 2
       Ps[p], Ps[q] = d, d + 1
  i = p = j + 1
  q = j = i + 1
print(" ".join(str(p) for p in Ps))


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

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

  // llの無限大
  ll ans = 1e18;
  // ルートn回ループを回すときのfor文
  for (ll i = 1; i * i <= n; i++)
  {
    if (n % i != 0)
      continue;
    ll j = n / i;
    // 1,1からi, jにいくのにかかる回数はi+j -2なので
    ans = min(ans, i + j - 2);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256