akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

llint n;
string s;
bool dp[305][305][305];
llint dp2[305][305][305];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	llint n = s.size();
	s = "#" + s;
	
	dp[0][0][0] = true;
	for(int i = 0; i < n; i++){
		for(int j = n; j >= 0; j--){
			for(int k = n; k >= 0; k--){
				if(!dp[i][j][k]) continue;
				
				if(i+2 <= n) dp[i+1][j][k] = true;
				
				if(i+2 <= n && s[i+2] == '0' && j+1 <= n) dp[i+2][j+1][k] = true;
				if(i+2 <= n && s[i+2] == '1' && k+1 <= n) dp[i+2][j][k+1] = true;
				
				if(i+2 <= n && s[i+1] == '0' && j+1 <= n) dp[i+2][j+1][k] = true;
				if(i+2 <= n && s[i+1] == '1' && k+1 <= n) dp[i+2][j][k+1] = true;
				
				if(i+1 <= n && s[i+1] == '0' && j >= 1) dp[i+1][j+1-1][k] = true;
				if(i+1 <= n && s[i+1] == '0' && j+1 <= n && k >= 1) dp[i+1][j+1][k-1] = true;
				if(i+1 <= n && s[i+1] == '1' && k >= 1) dp[i+1][j][k+1-1] = true;
				if(i+1 <= n && s[i+1] == '1' && k+1 <= n && j >= 1) dp[i+1][j-1][k+1] = true;
				
				if(i+1 <= n && (j >= 1 || k >= 1)) dp[i+1][j][k] = true;
				
				if(i+1 <= n && j >= 2) dp[i][j-2][k] = true;
				if(i+1 <= n && k >= 2) dp[i][j][k-2] = true;
				if(i+1 <= n && j >= 1 && k >= 1) dp[i][j-1][k-1] = true;
				
				if(i+1 <= n && j >= 1) dp[i][j-1][k] = true;
				if(i+1 <= n && k >= 1) dp[i][j][k-1] = true;
			}
		}
	}
	
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++){
				cout << dp[i][j][k] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}*/
	
	dp2[n+1][0][0] = 1;
	for(int i = n+1; i > 1; i--){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++){
				if(s[i-1] == '0') (dp2[i-1][j][k] += dp2[i][j][k]) %= mod;
				else if(j+1 <= n) (dp2[i][j+1][k] += dp2[i][j][k]) %= mod;
				
				if(s[i-1] == '1') (dp2[i-1][j][k] += dp2[i][j][k]) %= mod;
				else if(k+1 <= n) (dp2[i][j][k+1] += dp2[i][j][k]) %= mod;
			}
		}
	}
	
	/*for(int i = n+1; i >= 1; i--){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++){
				cout << dp2[i][j][k] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}*/
	
	llint ans = 0;
	for(int i = 1; i <= n+1; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++){
				if(dp[i-1][j][k]) ans += dp2[i][j][k], ans %= mod;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 228460
h, w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
L = [[0 for i in range(w)] for j in range(h)]
R = [[0 for i in range(w)] for j in range(h)]
U = [[0 for i in range(w)] for j in range(h)]
D = [[0 for i in range(w)] for j in range(h)]
#Uを決める
for i in range(w):
    if grid[0][i] == '#':
        U[0][i] = 0
    else:
        U[0][i] = 1
for i in range(1,h):
    for j in range(w):
        if grid[i][j] == '#':
            U[i][j] = 0
        else:
            U[i][j] = U[i-1][j] + 1
 #Dを決める
for i in range(w):
    if grid[-1][i] == '#':
        D[-1][i] = 0
    else:
        D[-1][i] = 1
for i in range(h-2, -1,-1):
    for j in range(w):
        if grid[i][j] == '#':
            D[i][j] = 0
        else:
            D[i][j] = D[i+1][j] + 1
# R を決める
for i in range(h):
    if grid[i][-1] == '#':
        R[i][-1] = 0
    else:
        R[i][-1] = 1
for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == '#':
            R[i][j] = 0
        else:
            R[i][j] = R[i][j+1] + 1
#Lを決める
for i in range(h):
    if grid[i][0] == '#':
        L[i][0] = 0
    else:
        L[i][0] = 1
for i in range(h):
    for j in range(1,w):
        if grid[i][j] == '#':
            L[i][j] = 0
        else:
            L[i][j] = L[i][j-1] + 1
ans = 0
for i in range(h):
    for j in range(w):
        #print("x:{} y:{} L:{} R:{} U:{} D:{}".format(j+1,i+1,L[i][j],R[i][j],U[i][j],D[i][j]))
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)

Measured memory_bytes: 313736
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        long a = Reader.Int(), b = Reader.Int();
        if (Math.Sign(a) * Math.Sign(b) == -1) Console.WriteLine("Zero");
        else if (a > 0 || (b - a + 1) % 2 == 0) Console.WriteLine("Positive");
        else Console.WriteLine("Negative");
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 2648
//O(n^2)の解法
#include<iostream>
#include<algorithm>
using namespace std;

struct point {
	int x; int y;
};

// x座標が小さい順になるように並び替えたいので、このような順序を定義。
bool order(point a, point b) {
	return a.x < b.x;
}

point blue[200];
point red[200];
// 配列の宣言のときに = {}をつけると全部の要素が0になる。
// 必要だったら「配列　初期化」とかでググるとよい。
// この配列usedの役割は後で説明する。
int used[200] = {};

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int p, q;
		cin >> p >> q;
		red[i] = { p,q };
	}
	for (int i = 0; i < n; i++) {
		int p, q;
		cin >> p >> q;
		blue[i] = { p,q };
	}
	int ans = 0;	//最終的な答えがこのansである。ペアを見つけるたびに+1されていく。

	sort(blue, blue + n, order);	//青点をx座標の小さい順にソートする。

	for (int i = 0; i < n; i++) {	//i番目の青点から見ていく。以下、i番目の青点をbiと呼ぶ。

		//今、次のa～cの条件を満たす中で、もっともy座標が大きい赤点を探したいのだった（貪欲法）。
		//a. x座標がbiのx座標よりも小さい。
		//b. y座標がbiのy座標よりも小さい。
		//c. まだどの青点ともペアになっていない。

		int bx = blue[i].x;
		int by = blue[i].y;

		int max_red = -1; 
		int max_red_y = -1000000; 

		//上記の2行と以下のfor文が「配列に入っている要素の中で最大の要素は何番目？」という問題の典型的な解き方。
		//jが0からn-1まで動くが、今まで見てきた中での最大値をmax_red_yに、それが何番目かをmax_redに保存する。
		//それをjが動くごとに更新する。
		//なお、max_red_yに最初はとても小さい値をいれておく。
		//今回は「配列に入っている要素の中で○○の条件を満たすもののうち最大の要素は何番目？」という問題なので、
		//更新は○○の条件を満たす場合のみ更新する。
		//この問題の実装のポイントその1。

		for (int j = 0; j < n; j++) {	

			//上記cの条件（各赤点がもうペアになっているかどうかという状態）を管理しているのが配列usedで、
			//used[j] == 0の場合はj番目の赤点はまだペアになっておらず、1の場合はもうペアになっている。
			//一般に「状態を管理するための配列」をわざわざ用意するというのはよくあるテクで、これが実装のポイントその2。

			if (used[j] == 0 && red[j].x < bx && red[j].y < by && red[j].y > max_red_y) {
				//このifの4条件のうち前3つが上の3条件のチェック
				//その3条件を満たしたうえで、最大値を更新する必要があったら（4番目の条件を満たしたら）更新を行う。
				max_red = j;
				max_red_y = red[j].y;
			}
		}
		//max_redが-1のままであったというのは上の3条件を満たす赤点が見つからなかったということ。
		//見つかった場合はansを+1し、その赤点を使われた状態にする(配列usedのmax_red番目の要素を1にする)
		if (max_red != -1) {
			ans++;
			used[max_red] = 1;
		}
	}
	cout << ans << endl;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int d = a / b;
    int r = a % b;
    double f = 1.0 * a / b;
    printf("%d %d %.8lf\n", d, r, f);
}


Measured memory_bytes: 3160
from collections import deque
K = int(input())


G = [[] for i in range(K)]
for i in range(K):
    G[i].append(((i + 1) % K, 1))
    G[i].append(((10 * i) % K, 0))


dist = [float('inf')] * K
dist[1] = 1
que = deque()
que.append(1)

while que:
    n = que.pop()
    for v, c in G[n]:
        if dist[v] > dist[n] + c:
            dist[v] = dist[n] + c
            if c == 0:
                que.append(v)
            else:
                que.appendleft(v)

print(dist[0])


Measured memory_bytes: 35316
#include <iostream>
#include <cstdio>
#define MAX 1000000
using namespace std;

bool prime[MAX+1];

bool hurui(){
  for(int i=0;i<MAX;i++){prime[i]=true;}
  prime[0]=prime[1]=prime[2]=true;
  
  for(int i=2;i<MAX;i++){
    if(prime[i]){
      for(int j=2*i;j<MAX;j+=i)prime[j]=false;
    }
  }
}


int main(){
  hurui();
  
  for(;;){
    int n,x;
    cin >> n >> x;
    if(n==0)return 0;
    
    int kane[n];
    for(int i=0;i<n;i++)
      cin >> kane[i];
    
    bool dp[x+1];
    for(int i=0;i<=x;i++)dp[i]=false;
    dp[0]=true;
    
    for(int i=0;i<=x;i++){
      if(dp[i]){
	for(int j=0;j<n;j++){
	  if(i+kane[j]<=x)dp[i+kane[j]]=true;
	}
      }
    }

    //cout << "aa";
    for(int i=x;i>=0;i--){
      if(i==0){
	cout << "NA" << endl;
	break;
      }
      if(dp[i]&&prime[i]){
	cout << i << endl;
	break;
      }
    }
  } 
  
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string a,b;
   int i,j, m=0,n=0 ,p;
   cin>>a>>b;
   for(i=0;i<a.size();i++){
   for(j=0;j<b.size();j++){
         if(a[i]==b[i]) m++;
         else n++;
         break;
   }
   }

cout<<n<<endl;
  }







Measured memory_bytes: 3924
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Who_Are_The_Student_Yet_To_Submit
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list30 = new List<int>();
            for (int i = 1; i <= 30; ++i)
            {
                list30.Add(i);
            }
            for (int i = 0; i < 28; ++i)
            {
                list30.Remove(int.Parse(Console.ReadLine()));
            }
            foreach (int item in list30)
            {
                Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 17864
#template
def inputlist(): return [int(j) for j in input().split()]
#template
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N,P = inputlist()
li = factorization(P)
ans = 1
n = len(li)
for i in range(n):
    k = li[i][1]
    ans *= max(1,li[i][0]**(k//N))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;

dd pai = 3.1415926535897932384626433832795028;
dd r;

int main(){
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin>>r;
  printf("%.15f\n",2*pai*r);
  return 0;
}


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

using namespace std;

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

    int n;
    cin >> n;
    pair<int, int> p[n];

    for (int i = 0; i < n; i++)
        cin >> p[i].first, p[i].second = i;

    sort(p, p + n);

    for (int i = 0; i < n; i++)
        if (p[n - 1].second == i)
            cout << p[n - 2].first << '\n';
        else
            cout << p[n - 1].first << '\n';

    return 0;
}

Measured memory_bytes: 3200
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    T = input()
    # ?をDに置き換えるよりも、Pに置き換えたほうがいいケースは？
    # ないのでは
    S = []
    for c in T:
        if c == "?":
            S.append("D")
        else:
            S.append(c)
    print("".join(S))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 11024
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#define pi 3.14159265358979323846
using namespace std;
int main(){
  long double a,b,h,m;
  cin >> a >> b >> h >> m;
  cout << fixed << setprecision(20) << sqrt(a*a+b*b-2*a*b*cos(min({abs(30*h-5.5*m),\
abs(5.5*m-30*h),abs(360-30*h+5.5*m),abs(360-5.5*m+30*h)})*pi/180)) << "\n";
  return 0;
}


Measured memory_bytes: 4100
grid = []
for i in range(3):
    row = list(map(int, input().split()))
    grid.append(row)

c = grid[0][0]
for i in range(c+1):
    a, b = [], []
    a.append(i)
    for j in range(3):
        b.append(grid[0][j]-a[0])

    for j in range(1, 3):
        a.append(grid[j][0]-b[0])

    for j in range(3):
        for k in range(3):
            if a[j]+b[k] != grid[j][k]:
                break

        else:
            continue
        break

    else:
        print("Yes")
        break

else:
    print("No")


Measured memory_bytes: 3064
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n != -1) {
    string s = "";
    if (!n) {
      cout << 0 << endl;
      continue;
    }
    while (n) {
      s = string(1, '0' + n % 4) + s;
      n /= 4;
    }
    cout << s << endl;
  }
}

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

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  vector<pair<int, int>> student(N, make_pair(0, 0));
  for (int i = 0; i < N; i++) {
    int x = 0, y = 0;
    scanf("%d%d", &x, &y);
    student.at(i) = make_pair(x, y);
  }
  vector<pair<int, int>> checkpoint(M, make_pair(0, 0));
  for (int i = 0; i < M; i++) {
    int x = 0, y = 0;
    scanf("%d%d", &x, &y);
    checkpoint.at(i) = make_pair(x, y);
  }

  for (int i = 0; i < N; i++) {
    int min_distance = 1e9;
    int select_point = 0;
    for (int j = 0; j < M; j++) {
      int d = 0;
      d += abs(student.at(i).first - checkpoint.at(j).first);
      d += abs(student.at(i).second - checkpoint.at(j).second);
      if (d < min_distance) {
        min_distance = d;
        select_point = j + 1;
      }
    }
    printf("%d\n", select_point);
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  
  for (int i = 0; i < N; i++) {
    cin >> D.at(i);
  }
  
  sort(D.begin(), D.end());
  int count = 0;
  int now = 0;
  
  for (int i = 0; i < N; i++) {
    if (now != D.at(i)) {
      count++;
    }
    now = D.at(i);
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    S = input()
    N = len(S)
    def isP(S):
        return S == S[::-1]
    YN(isP(S) and isP(S[:(N-1)//2]) and isP(S[((N+3)//2-1):]))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 66028
n=int(input())
A=list(map(int, input().split()))

stock=0
money=1000
d=-1
for i in range(len(A)-1):
	if A[i+1]-A[i]>0 and d==-1:
		'''kau'''
		stock=money//A[i]
		money=money%A[i]
		d=1
	elif A[i+1]-A[i]<0 and d==1:
		'''uru'''
		money+=A[i]*stock
		stock=0
		d=-1
	#print(i,money,stock)
if stock!=0:
	money += A[-1]*stock
	stock=0
print(money)


Measured memory_bytes: 9172
import sys
readline = sys.stdin.readline
write = sys.stdout.write
B = [771, 16843009, 15, 66306, 1539, 131841, 774]
C = "ABCDEFG"
def solve():
    N = 8
    su = 0
    for i in range(N):
        s = readline().strip()
        for j in range(N):
            if s[j] == '1':
                su |= 1 << (i*N + j)
    for i in range(N*N):
        for k in range(7):
            b = B[k] << i
            if (su & b) == b:
                write("%s\n" % C[k])
    return True
try:
    while solve():
        readline()
except:
    ...



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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long[] aa = sc.LongArray();

        ModInt answer = new ModInt(0);

        ModInt[] sums = new ModInt[n];
        sums[0] = aa[0];
        for (int i = 1; i < n; i++)
        {
            sums[i] = aa[i] + sums[i - 1];
        }

        for (int i = 1; i < n; i++)
        {
            answer += sums[i - 1] * (new ModInt(aa[i]));
        }

        Console.WriteLine(answer);
    }

    // ModInt
    class ModInt
    {
        public const long Mod = (int)1e9 + 7;

        public long num;

        public ModInt(long n) { num = n; }

        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }

        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 64512
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
using namespace std;

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

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;


int main(){
    string S;cin>>S;
    int A = S[0] - '0';
    int B = S[1] - '0';
    int C = S[2] - '0';
    int D = S[3] - '0';
    int sum;
    char op[2] = {'-','+'};
    REP(i,2){
        REP(j,2){
            REP(k,2){
                sum = A + (2*i-1)*B + (2*j-1)*C + (2*k-1)*D;
                if(sum==7){
                    cout << A << op[i] << B << op[j] << C << op[k] << D << "=7";
                    return 0;
                }
            }
        }
    }
}


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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rInt(a) scanf("%d",&a);

struct train{
    int c,s,f;
    train(int c,int s, int f) : c(c), s(s), f(f) {}
};

main(){
    int n;
    scanf("%d",&n);
    vector<train> arr;
    int x,y,z;
    rep(i,n-1){
        scanf("%d %d %d",&x,&y,&z);
        arr.push_back(train(x,y,z));
    }
    rep(i,n-1){
        int totalTime = arr[i].s + arr[i].c;
        for(int j = i+1;j<n-1;++j){
            int arrive = arr[j].s;
            if(arrive<totalTime){
                int val = totalTime - arrive;
                if(val%arr[j].f!=0) val = (val/arr[j].f) +1;
                else val/= arr[j].f;
                arrive = arr[j].s + arr[j].f*val;
            }
            totalTime = arrive + arr[j].c; 
        }
        cout << totalTime << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int b=a[0],c=a[1],d=a[2];

  if(b%2==c%2&&c%2==d%2){
    cout<<(2*d-b-c)/2<<endl;
  }
  else{
    if(b%2!=c%2&&c%2==d%2){
      d++;c++;
      cout<<(2*d-b-c)/2+1<<endl;
    }else if(b%2!=c%2&&c%2!=d%2){
      b++;d++;
      cout<<(2*d-b-c)/2+1<<endl;
    }else{
      b++;c++;
      cout<<(2*d-b-c)/2+1<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int n, k, ans;
int v[50];

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  
  for (int i = min(k/2, n); i <= min(k, n); i++) {  // 取り出す数
    for (int l = 0; l <= i; l++) {  // 左から取り出す数
      int r = i - l;
      priority_queue<int, vector<int>, greater<int> > pq;
      int sm = 0;
      for (int j = 0; j < l; j++) {
        sm += v[j];
        pq.push(v[j]);
      }
      for (int j = 0; j < r; j++) {
        sm += v[n-j-1];
        pq.push(v[n-j-1]);
      }
      for (int j = 0; j < min(i, k-i); j++) {
        if (pq.top() >= 0) break;
        sm -= pq.top();
        pq.pop();
      }
      ans = max(ans, sm);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<string.h>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define None cout<<"None"<<endl
typedef long long ll;
using namespace std;

int main() {
	char str[220];
	scanf("%s", str);
	int n = strlen(str);
	for (int i = n - 2; i >= 0; i -= 2) {
		if (strncmp(str, str + i / 2, i / 2) == 0) {
			cout << i << endl;
			return 0;
		}
	}
}	


Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let n = line.trim().parse::<i32>().unwrap();
    let line = gets();
    let k = line.trim().parse::<i32>().unwrap();
    let line = gets();
    let x = line.trim().parse::<i32>().unwrap();
    let line = gets();
    let y = line.trim().parse::<i32>().unwrap();
    if n <= k {
        println!("{}", n * x);
    } else {
        println!("{}", k * x + (n - k) * y);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    string S;
    vector<int> count(1e6, 0);

    cin >> S;

    int i = 0, ir = 0, il = 0;
    while (i < S.size())
    {
        if (S[i] == 'L')
        {
            il = i;
            while (i < S.size())
            {
                if (S[i] == 'L')
                    i++;
                else
                    break;
            }

            count[il - 1] = (il - ir + 1) / 2 + (i - il) / 2;
            count[il] = (il - ir) / 2 + (i - il + 1) / 2;

            ir = i;
        }
        else
            i++;
    }

    for (int i = 0; i < S.size(); i++)
        cout << count[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

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

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

int main()
{
    int N,A,B;
    scanf("%d %d %d",&N,&A,&B);
    if((N*A)<=B)
    {
        printf("%d",(N*A));
    }
    else
    {
        printf("%d",B);
    }

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int INF=int(1e9);
int n,goal;
int con[15][2];
int dp[15][int(1e5)];
int DP(int x,int y)
{
    if(y<=0) return 0;
    if(x<1) return INF;
    if(dp[x][y]!=-1) return dp[x][y];
    dp[x][y]=INF;
    for(int i=0;i<con[x][0];i++)
        dp[x][y]=min(dp[x][y],DP(x-1,y-i*x)+i);
    dp[x][y]=min(dp[x][y],DP(x-1,y-con[x][0]*x-con[x][1])+con[x][0]);
    return dp[x][y];
}
int main()
{
    memset(dp,-1,sizeof dp);
    scanf("%d%d",&n,&goal);
    goal/=100;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&con[i][0],&con[i][1]),con[i][1]/=100;
    printf("%d\n",DP(n,goal));
    return 0;
}

Measured memory_bytes: 6016
n, m = map(int, input().split())
ac = 0
wa = 0
l = [input().split() for i in range(m)]
d = dict()
for i in range(m):
    if l[i][0] + "wa" not in d:
        d[l[i][0] + "wa"] = 0
    if l[i][0] not in d or d[l[i][0]] != "AC":
        d[l[i][0]] = l[i][1]
        if l[i][1] == "AC":
            ac += 1
            wa += d[l[i][0] + "wa"]
        else:
            d[l[i][0] + "wa"] += 1
print(ac, wa)

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

#[fastout]
fn main() {
    input! {
        n: usize,
        d: usize,
        p: [(isize, isize); n],
    }

    let mut ans = 0;
    for (x, y) in p {
        if x.pow(2) + y.pow(2) <= d.pow(2) as isize {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7780
S = input()
T = input()

sl = len(S)
tl = len(T)

minc = 1000

for i in range(sl):
    if i+tl-1 >= sl:
        break
    else:
        str1 = S[i:i+tl]
        count=0
        for j in range(tl):
            if str1[j] != T[j]:
                count+=1
        if count < minc:
            minc = count

print(minc)
        






Measured memory_bytes: 9084
a = int(input())
b = input()
ans = 0
for i in range(1000):
	T = '0'*(3-len(str(i)))
	t = T+ str(i)
	I = 0
	while I < 3:
		for j in b:
			#if t == '022':print(I,t[I],j)
			if I == 3:
				break
			if t[I] == j:I+=1
			#if t == '022':print(I,j)
		
		if I == 3: 
			#print(t)
			ans +=1
		break
print(ans)

Measured memory_bytes: 41436
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)


const double inf = 10000;
const double eps = 1e-11;

double f(double x,double a,double b,double c,double d){
  return a*x*x*x+b*x*x+c*x+d;
}

double bsearchdec(double l,double r,double a,double b,double c,double d){
  double mid;
  rep(i,200){
    mid = (l+r)/2;
    if (f(mid,a,b,c,d) > 0)l=mid;
    else r=mid;
  }
  return mid;
}

double bsearchinc(double l,double r,double a,double b,double c,double d){
  double mid;
  rep(i,200){
    mid = (l+r)/2;
    if (f(mid,a,b,c,d) >0)r=mid;
    else l=mid;
  }
  return mid;
}

pair<double,double> qu(double a,double b,double c){
  double tmp = sqrt(b*b-4*a*c+0);
  double waru=2*a;
  return make_pair((-b-tmp)/waru,(-b+tmp)/waru);
}

main(){
//   for(double i=-100;i<=100;i+=0.001){
//     double tmp = f(i,1,3,3,1);
//     if (fabs(tmp) < 1e-10)cout << i << endl;
//   }
//   return 0;
  double a,b,c,d;
  int te;
  cin>>te;
  while(te--){
    cin>>a>>b>>c>>d;
    int neg=0,pos=0;
    if (4*b*b - 12*a*c < 0){
      //      cout <<"no info" << endl;
      double ans;
     if (a > 0)ans=bsearchinc(-inf,inf,a,b,c,d);
    else if (a < 0)ans=bsearchdec(-inf,inf,a,b,c,d);
      if (fabs(f(ans,a,b,c,d))>1e-10||fabs(ans)<1e-10);
     else if (ans > 0)pos++;
    else if (ans < 0)neg++;      
    }else {
      pair<double,double> ahoge=qu(3*a,2*b,c);
      //cout << ahoge.first <<" " << ahoge.second << endl;
      if (ahoge.first > ahoge.second)swap(ahoge.first,ahoge.second);
      double tmp[3];
      if (a > 0){
	tmp[0]=bsearchinc(-inf,ahoge.first,a,b,c,d);
	tmp[1]=bsearchdec(ahoge.first,ahoge.second,a,b,c,d);
	tmp[2]=bsearchinc(ahoge.second,inf,a,b,c,d);
      }else if(  a < 0){
	//cout <<"test " << endl;
	tmp[0]=bsearchdec(-inf,ahoge.first,a,b,c,d);
	tmp[1]=bsearchinc(ahoge.first,ahoge.second,a,b,c,d);
	tmp[2]=bsearchdec(ahoge.second,inf,a,b,c,d);
      }
      rep(i,3){
	//printf("%d %.15lf %.15lf\n",i,tmp[i],f(tmp[i],a,b,c,d));
	bool flag=true;
	if (fabs(f(tmp[i],a,b,c,d))>1e-10 || fabs(tmp[i]) < 1e-10)continue;
	if (tmp[i] > 0){
	  pos++;
	}else if (tmp[i] < 0){
	  neg++;
	}
      }
    }
    cout << pos <<" " << neg << endl;
  }

  return false;
}

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

long long y[308],a=0;
vector<int> p;

void f(){
    for(int i=2;i<300;i++){
        bool b=true;
        for(int j=2;j<i;j++){
            if(i%j==0){
                b=false;
                break;
            }
        }
        if(b)p.push_back(i);
    }
}

long long h(int r){
    long long s=0;
    for(int i=2;i<=300;i++){
        if(r%i==0){
            s+=y[i];
        }
    }
    return s;
}


long long g(long long r, int x){
    long long s,m=0;
    a++;
    if(x<7){
        s=1;
        while(s<=300){
            m=max(m,g(r*s, x+1));
            s*=p[x];
            a++;
        }
    }else{
        s=0;
        for(int i=2;i<=300;i++){
            if(r%i==0){
                s+=y[i];
                a++;
            }
        }
        
        for(int i=7;i<p.size();i++){
            long long t=0,k=1;
            while(p[i]*k<=300){
                if(r%k==0){
                    t+=y[p[i]*k];
                }
                k++;
            }
            s+=max(t,t*0);
        }
        
        return s;
    }
    return m;
}

int main(void){
    long long q;
    cin>>q;
    f();
    for(int i=0;i<308;i++){
        y[i]=0;
    }
    for(int i=0;i<q;i++){
        int m,x;
        cin>>m>>x;
        y[m]=x;
    }
    cout<<g(1,0)<<endl;
    //cout<<a<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int somaDigito (int n) {
    int soma = 0;
    while (n != 0) {
        soma += n % 10;
        n /= 10;
    }
    return soma;
}

int main() {
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a;

    if ((a % somaDigito(a)) == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<b){
    cout<<"a < b"<< endl;
    
  }else if(a>b){
    cout<<"a > b" << endl;
    
  }else
 if(a==b){
    cout<<"a == b" << endl;  
  }
}



Measured memory_bytes: 3108
hw=list(map(int,input().split()))
h=hw[0]
w=hw[1]
a=[[] for i in range(h)]
b=[]
for i in range(h):
    a[i] = list(str(input()))
for i in range(h):
    y=True
    for j in range(w):
        if y and a[i][j]==".":
            y=True
        else:
            y=False
    if not(y):
        b.append(a[i][:])
c=[[] for i in range(len(b))]
e=[0 for i in range(len(b[0]))]
for i in range(len(b[0])):
    t=True
    for j in range(len(b)):
        if t and b[j][i]==".":
            t=True
        else:
            t=False
    e[i]=t
for i in range(len(b)):
    for j in range(len(b[0])):
        if not(e[j]):
            c[i].append(b[i][j])
for i in range(len(c)):
    print("".join(c[i]))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
 
int main() {
 
  int long long H,N,A=0,t=0,i,j=0,a=0;
  string ans;
  
  cin >> H >> N;

  for ( i = 0; i < N; i++)
  {
    cin >> a;
    A=a+A;
  }
  
  if (A>=H)
  {
    ans="Yes";
  }else
  {
    ans="No";
  }
  
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	ll h,w; cin >> h >> w;
	if(h>w) swap(h,w);
	if(h == 1){
		cout << 1 << endl;
		return 0;
	}
	cout<<(h*w+1)/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(){

    int n; 
    int max_v = -1e+9; 
    int min_v;
    cin >> n;
    int R[n];
    cin >> min_v;
    for(int i=0; i<n-1; i++){
        cin >> R[i];
        max_v = max(R[i]-min_v, max_v);
        min_v = min(R[i],min_v); 
    }

    cout << max_v << endl;


    return 0;
}

Measured memory_bytes: 3900
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int DP[201][201];

int main(int argc, const char * argv[]) {
    int D, N;
    cin >> D >> N;
    vector<int> T(D), A(N), B(N), C(N);
    for (int d = 0; d < D; ++d) {
        cin >> T[d];
    }
    for (int n = 0; n < N; ++n) {
        cin >> A[n] >> B[n] >> C[n];
    }
    for (int n = 0; n < N; ++n) {
        if (T[0] >= A[n] && T[0] <= B[n]) {
            DP[0][n] = 0;
        } else {
            DP[0][n] = -INF;
        }
    }
    for (int d = 1; d < D; ++d) {
        for (int n = 0; n < N; ++n) {
            if (T[d] >= A[n] && T[d] <= B[n]) {
                for (int m = 0; m < N; ++m) {
                    DP[d][n] = max(DP[d][n], DP[d-1][m]+abs(C[n]-C[m]));
                }
            } else {
                DP[d][n] = -INF;
            }
        }
    }
    int Res = -INF;
    for (int n = 0; n < N; ++n) {
        Res = max(Res, DP[D-1][n]);
    }
    cout << Res << endl;

    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n;std::cin>>n;
    int m=0;
    for(int i=n;i>0;i/=10){
        m+=i%10;
    }
    std::cout<<(n%m==0?"Yes":"No")<<std::endl;
}

Measured memory_bytes: 256
from collections import deque
def isok(x):
    que=deque(sorted(z%x for z in a))
    res=0
    while que:
        l=que[0]
        if l==0:
            que.popleft()
            continue
        r=que[-1]
        if r==0:
            que.pop()
            continue
        d=min(l,x-r)
        que[0]-=d
        que[-1]=(que[-1]+d)%x
        res+=d
    return res
        
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr

n,k=map(int,input().split())
a=list(map(int,input().split()))
sum_=sum(a)

fac=sorted(factor(sum_),reverse=True)
ans=1
for x in fac:
    c=isok(x)
    if c<=k:
        ans=x
        break
print(ans)


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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int r[4010] = {};
    int g[4010] = {};
    int b[4010] = {};
    long long res = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            r[i] = (s[i] == 'R') ? 1 : 0;
            g[i] = (s[i] == 'G') ? 1 : 0;
            b[i] = (s[i] == 'B') ? 1 : 0;
        } else {
            r[i] = (s[i] == 'R') ? (r[i-1] + 1) : r[i-1];
            g[i] = (s[i] == 'G') ? (g[i-1] + 1) : g[i-1];
            b[i] = (s[i] == 'B') ? (b[i-1] + 1) : b[i-1];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int k = i; k < n; k++) {
            if (s[i] == s[k]) continue;
            if (s[i] != 'R' && s[k] != 'R') {
                res += r[k-1] - r[i];
                if ((k + i) % 2 == 0 && s[(k+i)/2] == 'R') res--;
            } else if (s[i] != 'G' && s[k] != 'G') {
                res += g[k-1] - g[i];
                if ((k + i) % 2 == 0 && s[(k+i)/2] == 'G') res--;
            } else if (s[i] != 'B' && s[k] != 'B') {
                res += b[k-1] - b[i];
                if ((k + i) % 2 == 0 && s[(k+i)/2] == 'B') res--;
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int S(ll n) {
    string s = to_string(n);
    int res = 0;
    rep(i, s.size()) res += s[i]-'0';
    return res;
}

ll f(ll n) {
    string s = to_string(n);
    ll sn = S(n);
    double mn = 1e18;
    ll next = -1;
    rep(i, s.size()) {
        rep(d, 10) {
            string t = s;
            t[i] = d + '0';
            for (int j=i+1; j<s.size(); ++j) t[j] = '9';
            ll m = stoll(t);
            if (m < n) continue;
            ll sm = S(m);
            if (mn > (double)m/sm) {
                mn = (double)m/sm;
                next = m;
            }
        }
    }
    return next;
}

int main() {
    ll K;
    cin >> K;
    ll a = 1;
    rep(i, K) {
        cout << a << endl;
        a = f(a+1);
    }
}


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

string S;
int K;

int main(void) {
  cin >> K >> S;
  int n = S.size();
  string ans;
  if (n <= K) ans = S;
  else ans = S.substr(0,K) + "...";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

typedef unsigned long long ULL;

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

	vector<int> card(N);
	for(int i=0; i<N; i++)
		cin >> card[i];
	sort(card.begin(), card.end());

	vector<vector<vector<ULL>>> dp(N+1, vector<vector<ULL>>(N+1, vector<ULL>(N*A+1, 0)));
	for(int i=0; i<N+1; i++)
		dp[i][0][0] = 1;

	// pos card
	for(int i=1; i<N+1; i++)
	{
		// cnt card
		for(int j=1; j<N+1; j++)
		{
			// sum
			for(ULL k=0; k<N*A+1; k++)
			{
				dp[i][j][k] += dp[i-1][j][k];

				int c = card[i-1];
				if(c <= k)
					dp[i][j][k] += dp[i-1][j-1][k-c];
			}
		}
	}

	ULL ret = 0;
	for(ULL i=1; i<N+1; i++)
		ret += dp[N][i][i*A];

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 52224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=1<<16,INF=1<<30;
vector<int> A,B;
int dis[MAX];

void BFS(){
    queue<int> Q;
    Q.push(0);
    
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        
        for(int i=0;i<si(A);i++){
            int v=u;
            v&=A[i];
            v|=B[i];
            if(chmin(dis[v],dis[u]+1)){
                Q.push(v);
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    dis[0]=0;
    for(int i=1;i<(1<<16);i++) dis[i]=INF;
    
    set<int> SE;
    for(int i=0;i<N;i++){
        int h,w;cin>>h>>w;
        for(int uh=-3;uh<=3;uh++){
            for(int uw=-3;uw<=3;uw++){
                int nuru=0;
                for(int dh=0;dh<h;dh++){
                    for(int dw=0;dw<w;dw++){
                        int toh=uh+dh,tow=uw+dw;
                        if(toh<0||toh>=4||tow<0||tow>=4) continue;
                        nuru|=(1<<(toh*4+tow));
                    }
                }
                SE.insert(nuru);
            }
        }
    }
    
    vector<string> S(4);
    for(int i=0;i<4;i++) cin>>S[i];
    
    string T="RGB";
    
    for(int a:SE){
        for(int k=0;k<3;k++){
            int x=(1<<16)-1;
            x^=a;
            A.push_back(x);
            
            x=0;
            
            for(int i=0;i<4;i++){
                for(int j=0;j<4;j++){
                    if(!(a&(1<<(i*4+j)))) continue;
                    if(T[k]!=S[i][j]) continue;
                    x|=1<<(i*4+j);
                }
            }
            
            B.push_back(x);
        }
    }
    
    BFS();
    
    cout<<dis[(1<<16)-1]<<endl;
}




Measured memory_bytes: 3640
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/13/20 20:47:40
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  int minx = 1e9+1, maxx = -1e9-1, miny = 2e9+1, maxy = 0;
  for (int i = 0; i < n; i++) {
    int a,b; cin>>a>>b;
    int x = a - b, y = a + b;
    minx = min(minx, x);
    maxx = max(maxx, x);
    miny = min(miny, y);
    maxy = max(maxy, y);
  }
  int ans = max(maxx - minx, maxy - miny);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()

for i in range(m+1):
    for j in range(n+1):
        if n*i+m*j-2*i*j == k:
            print('Yes')
            exit()

print('No')

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

int main()
{
	int K, A, B;
	cin >> K >> A >> B;

	string ans = "NG";
	for( int i = A; i <= B; i++ ) {
		if( i % K == 0 ) ans = "OK";
	}

	cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    int taro = 0, hanako = 0;
    for (int i = 0; i < n; i++){
        string in_t, in_h;
        cin >> in_t >> in_h;
        if (in_t == in_h){
            taro++;
            hanako++;
        }
        else if (in_t > in_h){
            taro += 3;
        }
        else hanako += 3;
    }
    cout << taro << " " << hanako << endl;
}


Measured memory_bytes: 3136
#include <stdio.h>
#include <limits.h>

long long h[110000], dp[110000];

long long  min(long long a,long long b){
    if(a>b) return b;
    else return a;
}
long long dec(long long a,long long b){
    if(a>b) return a-b;
    else return b-a;
}

int main(){
    int n,k;
    scanf("%d", &n);
    scanf("%d", &k);
    
    for(int i=0;i<n;i++) scanf("%lld", &h[i]);
    for(int i=0;i<110000;i++) dp[i]=LLONG_MAX;
    dp[0]=0;
    dp[1]=dec(h[1],h[0]);
    if(n>k){
        for(int i=2;i<n;i++){
            for(int j=1;j<=k&&i-j>=0;j++){
                dp[i]=min(dp[i],dp[i-j]+dec(h[i],h[i-j]));
            }
        }
    }
    if(n<=k) dp[n-1]=dec(h[n-1],h[0]);
    
    printf("%lld", dp[n-1]);
    
    return 0;
}


Measured memory_bytes: 1792
n=int(input())
s=input()
cnt = 0

if n%2 == 1:
    print('No')

else :
    for i in range(n//2):
        if s[i] == s[i+n//2]:
            cnt += 1

    if cnt == n//2:
        print('Yes')
    else :
        print('No')


Measured memory_bytes: 9108