akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   string A; cin >> A;
   map<char,int> count;
   rep(i, 0, SZ(A)) {
      count[A[i]]++;
   }

   int ans = SZ(A) * (SZ(A) - 1) / 2;
   EACH(i, count) {
      ans -= i->second * (i->second - 1) / 2;
   }
   ans++;
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 640
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;



int main(){
    ll k;
    cin>>k;
    vector<pair<double,ll>> a;
    /*
    for(int i=0;i<=9;i++){
        for(int t=0;t<=9;t++){
            for(int h=0;h<=9;h++){
                ll sum=i+t+h+9;
                ll n=i*1000+t*100+h*10+9;
                a.push_back({1.0*n/sum,n});
            }
        }
    }
     */
    for(int K=4;K<=15;K++){
        for(int i=0;i<=9;i++){
            for(int t=0;t<=9;t++){
                for(int h=0;h<=9;h++){
                    for(int j=0;j<=9;j++){
                        ll sum=i+t+h+j;
                        if(K==4 && sum==0){continue;}
                        ll n=i*1000+t*100+h*10+j;
                        for(int l=4;l<K;l++){
                            sum+=9;
                            n*=10;
                            n+=9;
                        }
                        a.push_back({(double)n/sum,n});
                    }
                }
            }
        }
    }
    
    sort(a.begin(),a.end());
    ll mx=a[0].S;
    ll count=0;
    for(int i=0;i<a.size() && count<k;i++){
        mx=max(a[i].S,mx);
        if(a[i].S==mx && (i==0 || a[i-1].S!=a[i].S)){cout<<a[i].S<<endl; count++;}
    }
    
    
    return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#include <string.h>



int main(){
  int a1[10];
  int a2[10];
  int a3[10];
  int p = 0, q = 0, r = 0;
  int j = 0, k = 0, l = 0;
  int x = 0, y = 0, z = 0;

  scanf("%d %d %d", &a1[0], &a1[1], &a1[2]);
  scanf("%d %d %d", &a2[0], &a2[1], &a2[2]);
  scanf("%d %d %d", &a3[0], &a3[1], &a3[2]);


  int n;
  scanf("%d", &n);

  for(int i = 1; i<=n; i++){
    int b;

    scanf("%d", &b);
    
    if(a1[0] == b || a1[1] == b || a1[2] == b){
      p++;
    }
    if(a2[0] == b || a2[1] == b || a2[2] == b){
      q++;
    }
    if(a3[0] == b || a3[1] == b || a3[2] == b){
      r++;
    }
    if(a1[0] == b || a2[0] == b || a3[0] == b){
      j++;
    }
    if(a1[1] == b || a2[1] == b || a3[1] == b){
      k++;
    }
    if(a1[2] == b || a2[2] == b || a3[2] == b){
      l++;
    }
    if(a1[0] == b || a2[1] == b || a3[2] == b){
      x++;
    }
    if(a1[2] == b || a2[1] == b || a3[0] == b){
      y++;
    }

  }

  //printf("%d %d %d %d %d %d %d %d\n", p, q, r, j, k ,l, x, y);


  if(p == 3 || q == 3 || r == 3 || j == 3 || k==3 || l == 3 || x == 3 || y == 3){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    cout <<((s == "ABC")?"ARC":"ABC") << endl;    
}


Measured memory_bytes: 3652
N, M, X, Y = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i)
y = gets.chomp.split(" ").map(&:to_i)
x_min, x_max = x.minmax
y_min, y_max = y.minmax
flag = false
if x_max <= y_min
  ((X+1)..Y).each do |num|
    if ((x_max+1)..y_min).member?(num)
      flag = true
    end
  end
else
  flag = false
end
flag ? print("No War") : print("War")

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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	vector<int>ans(n,0);
	for (int i = n; i >= 1; i--) {
		int res = 0;
		int x = (n/i)*i;
		while (x > 0) {
			res += ans.at(x - 1);
			x -= i;
		}
		res %= 2;
		ans.at(i-1) = abs(a.at(i-1) - res);
	}
	//cout << ans.at(0) << ans.at(1) << ans.at(2) << ans.at(3) << ans.at(4) << endl;
	int k = 0;
	for (int i = 0; i < n; i++)k += ans.at(i);
	cout << k << endl;
	bool fi = true;
	for (int i = 0; i < n; i++) {
		if (fi == true && ans.at(i) == 1) {
			cout << i+1;
			fi = false;
		}
		else if (ans.at(i) == 1)cout << " " << i+1;
	}
	if(k!=0)cout << endl;
}

Measured memory_bytes: 2432
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int ma = sc.nextInt();
		int mb = sc.nextInt();
		int[][] dp=new int[401][401];
		for(int i = 0; i<401; i++){
			Arrays.fill(dp[i],Integer.MAX_VALUE);
		}
		dp[0][0]=0;
		for(int i = 0; i<n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			for(int j=400; j>=a; j--){
				for(int k =400; k>=b; k--){
					if(dp[j-a][k-b]!=Integer.MAX_VALUE){
						dp[j][k]=Math.min(dp[j][k],c+dp[j-a][k-b]);
					}
				}
			}
		}
		int ans=Integer.MAX_VALUE;
		for(int i = 1; 401>Math.max(ma,mb)*i; i++){
			if(dp[ma*i][mb*i]!=Integer.MAX_VALUE){
				ans=Math.min(ans,dp[ma*i][mb*i]);
			}
		}
		if(ans==Integer.MAX_VALUE){
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}
}


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

int main(void){
    int n,flag=0;
    std::deque<int> deq;
    deq.emplace_back(2);
    for (int i=3;deq.size()<=10000;i+=2) {
            double sqrtNum=sqrt(i);
            for (int j=3;j<=sqrtNum;j+=2) {
                if (i%j==0) {
                    flag=1;
                    break;
                }
            }
            if (flag==0) {
                deq.emplace_back(i);
            } else {
                flag=0;
            }
        }
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int sum=0;
            for (int k=0;k<n;k++) {
                sum+=deq[k];
            }
            cout<<sum<<endl;
        }
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<int> v;
  while (n)
  {
    if (n % 2 == 0)
    {
      v.push_back(0);
    }
    else
    {
      v.push_back(1);
      n--;
    }
    n /= -2;
  }
  if (v.empty())
    v.push_back(0);
  for (int i = v.size() - 1; i >= 0; --i)
    cout << v[i];
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  priority_queue<int> h;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    h.push(x);
  }
  for(int i=0;i<k;i++){
    if(h.empty())
      break;
    h.pop();
  }
  int64_t t=0;
  while(!h.empty()){
    t+=h.top();
    h.pop();
  }
  cout<<t<<endl;
}

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> c(H);
    for (int i = 0; i < H; i++) cin >> c[i];
    
    int ans = 0;
    for (int i = 0; i < W-1; i++) {
        vector<vector<int>> dp(H+1, vector<int>(H+1, 0));
        for (int j = H-1; j >= 0; j--) {
            for (int k = H-1; k >= 0; k--) {
                if (c[H-1-j][i] == c[H-1-k][i+1]) dp[j][k] = dp[j+1][k+1] + 1;
                else dp[j][k] = dp[j+1][k+1];
            }
        }
        
        for (int j = H-1; j >= 0; j--) {
            for (int k = H-1; k >= 0; k--) {
                dp[j][k] += min(dp[j+1][k], dp[j][k+1]);
            }
        }
        ans += dp[0][0];
    }
    cout << ans << endl;
    return 0;
}


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

for i in range(1,n+1):
    a[i-1] = a[i-1]-i

a.sort()
if n%2 == 1:
    b = a[n//2]
else:
    b = (a[n//2-1]+a[n//2])//2

total = 0
for i in range(n):
    total +=abs(a[i]-b)

print(total)

Measured memory_bytes: 104492
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int r = sc.nextInt();

        if (n >= 10)
            System.out.println(r);
        else
            System.out.println(r +100 * (10 - n));
    }
}

Measured memory_bytes: 23252
/**
class cfmaster {
 public:
  struct code {
  	see the details down there !
  };
};
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, W;
  cin >> n >> W;
  vector<long long> w(n), v(n);
  for (int i = 0; i < n; i++) {
  	cin >> w[i] >> v[i];
	}
	vector<long long> dp(W + 1, -1);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		vector<long long> new_dp = dp;
		for (int j = 0; j <= W; j++) {
			if (dp[j] != -1 && j + w[i] <= W) {
				new_dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
			} 
		}
		dp = new_dp;
	}
	cout << *max_element(dp.begin(), dp.end()) << '\n';
  return 0;
}



Measured memory_bytes: 1804
#include <stdio.h>
#include <string.h>

void under_s(char a[], int b)
{
int len, i;
len = strlen(a);
for(i = 0; i < b; i++){
a[len + i] = a[i];
}

for(i = 0; i < len; i++){
a[i] = a[i + b];
}
a[len] = '\0';
}


int main(void)
{
char card[500];
int n, i;
int h[128];

while(1){

scanf("%s",&card);
if( strcmp(card, "-") == 0)
break;

scanf("%d",&n);

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

for(i = 0; i < n; i++){
under_s(card, h[i]);
}
printf("%s\n", card);
}
return 0;
}

Measured memory_bytes: 588
S = input()
N = len(S)

A = [0] * (N + 1)
now = 0
for i, s in enumerate(S, start=1):
    if s == '<':
        now += 1
    else:
        now = 0
    A[i] = now

B = [0] * (N + 1)
now = 0
for i, s in enumerate(S[::-1], start=1):
    if s == '>':
        now += 1
    else:
        now = 0
    B[i] = now
B = B[::-1]

ans = [10**18] * (N + 1)
for i in range(N + 1):
    ans[i] = max(A[i], B[i])
print(sum(ans))


Measured memory_bytes: 31516
#include <iostream>
#include <string>
typedef long long ll;
//#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;

  if(N == 1){
  	cout << (float)1;
  }else{
  	int nodd = N / 2 + N % 2;
    cout << (float) nodd / N;
  }

}


Measured memory_bytes: 256
fun main(arr: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }

    var searchFor = 1
    var ans = 0
    for(i in a) {
        if(searchFor == i) {
            searchFor++
        } else {
            ans++
        }
    }
    println(if(ans==n) -1 else ans)
}


Measured memory_bytes: 64648
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 9;
 
int lx[N], lm[N], rx[N], rm[N], a[N];

signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;	cin >> n;
	lx[0] = 0, lm[0] = inf;
	int l = 0;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	lx[1] = a[1];	lm[1] = 0;
	int s1 = a[1], s2 = 0;
	for(int i = 2; i <= n; i++){
		s1 += a[i];
		while(true){
			int cur = abs((s1 - s2) - s2);
			int nxt = abs((s1 - s2 - a[l+1]) - (s2 + a[l+1]));
			if(nxt > cur)
				break;
			l++;	s2 += a[l];
		}
		lx[i] = max(s2, s1 - s2);
		lm[i] = min(s2, s1 - s2);
	}
	rx[n] = a[n];	rm[n] = inf;
	l = n+1;
	s1 = a[n];	s2 = 0;
	for(int i = n-1; i >= 1; i--){
		s1 += a[i];
		while(true){
			int cur = abs((s1 - s2) - s2);
			int nxt = abs((s1 - s2 - a[l-1]) - (s2 + a[l-1]));
			if(nxt > cur)
				break;
			l--;	s2 += a[l];
		}
		rx[i] = max(s2, s1 - s2);
		rm[i] = min(s2, s1 - s2);
	}
	int mx = 0, mi = inf, ans = inf;
	for(int i = 2; i+1 < n; i++){
		mx = max(lx[i], rx[i+1]);
		mi = min(lm[i], rm[i+1]);
		ans = min(ans, mx - mi);
	}
	cout << ans;
	return 0;
}

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


//全部ゼロで初期化される。
ll dp[105][100005];

int main() {
	int N, W;
	cin >> N >> W;
	vector<int> w(N);
	vector<ll> v(N);
	rep(i, N) {
		cin >> w[i] >> v[i];
	}
	
	rep(i,N){
		rep(j,W+1){
			if( j >= w[i]){
				dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			}else{
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			}
		}
	}
	
	
	
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			int Group[] = {0,0,0,0};
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf,",");
				int n = Integer.parseInt(st.nextToken());
				String blood = st.nextToken();
				if (blood.indexOf("AB")!=-1) Group[2]++;
				else if (blood.indexOf("A")!=-1) Group[0]++;
				else if (blood.indexOf("B")!=-1) Group[1]++;
				else if (blood.indexOf("O")!=-1) Group[3]++;
			}
			for (int i=0;i<4;i++) {
				System.out.println(Group[i]);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17012
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    K = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid
    a_list = [
        1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1,
        15, 2, 2, 5, 4, 1, 4, 1, 51
    ]

    logger.debug('{}'.format([]))

    print(a_list[K - 1])


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """27"""
        output = """5"""
        self.assertIO(input, output)


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
string s;
vec<bool> str, ans;

void f(bool a, bool b) {
   ans.resize(n, false);
   ans[0] = a, ans[1] = b;
   repp (i, 1, n-1) {
      if (str[i]) { // oのとき
         if (ans[i]) { // 羊
            ans[i+1] = ans[i-1];
         } else { // 狼
            ans[i+1] = !ans[i-1];
         }
      } else { // xのとき
         if (ans[i]) { // 羊
            ans[i+1] = !ans[i-1];
         } else { // 狼
            ans[i+1] = ans[i-1];
         }
      }
   }
}

bool judge() {
   bool ok = true;
   if (str[n-1]) { // oのとき
      if (ans[n-1]) { // 羊
         if (ans[n-2] != ans[0]) ok = false;
      } else { // 狼
         if (ans[n-2] == ans[0]) ok = false;
      }
   } else { // xのとき
      if (ans[n-1]) { // 羊
         if (ans[n-2] == ans[0]) ok = false;
      } else { // 狼
         if (ans[n-2] != ans[0]) ok = false;
      }
   }

   if (str[0]) { // oのとき
      if (ans[0]) { // 羊
         if (ans[n-1] != ans[1]) ok = false;
      } else { // 狼
         if (ans[n-1] == ans[1]) ok = false;
      }
   } else { // xのとき
      if (ans[0]) { // 羊
         if (ans[n-1] == ans[1]) ok = false;
      } else { // 狼
         if (ans[n-1] != ans[1]) ok = false;
      }
   }

   return ok;
}

void print() { rep (i, n) { cout << (ans[i]?'S':'W'); } cout << endl; }

int main() {
   cin >> n >> s;
   str.resize(n, false);
   rep (i, n) {
      str[i] = s[i]=='o'?true:false;
   }

   rep (i, 2) {
      rep (j, 2) {
         f(i, j);
         if (judge()) {
            print();
            return 0;
         }
      }
   }

   printf("%d\n", -1);

   return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    vector<string> d = {"SUN","SAT","FRI","THU","WED","TUE","MON"};

    string s;
    cin>>s;

    REP(i,d.size()){
        if(d.at(i) == s){
            if(i==0){
                cout<<7<<endl;
                return 0;
            } else {
                cout<<i<<endl;
            }
        }
    }

    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
map<ll, int> prime_factor(ll n)
{
    map<ll, int> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] = 1;
    }
    return res;
}
const int MAX=1e6+1;
int main()
{
    ios::sync_with_stdio(false);
std::cin.tie(nullptr);
    int N;
    cin>>N;
    vint A(N);
    vint acc(MAX);
    int accGcd=0;
    for (size_t i = 0; i < N; i++)
    {
        cin>>A[i];
        auto pf=prime_factor(A[i]);
        for (auto &&i : pf)
        {
            acc[i.first]++;
        }
        accGcd=gcd(accGcd,A[i]);
    }
    bool pc=true;
    for (auto &&i : acc)
    {
        if(i>1)
        pc=false;
    }
    if(pc){
        cout<<"pairwise coprime"<<endl;
    }
    else if(accGcd==1)
    {
        cout<<"setwise coprime";
    }
    else
    {
        cout<<"not coprime";
    }
    
    return 0;
}

Measured memory_bytes: 11052
#include<stdio.h>
int main(void){

        int a,b,c,d,e,f;
        double x,y;

        while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f) != EOF){

                        x=(float)(c*e-b*f)/(a*e-d*b);
                        y=(float)(a*f-c*d)/(a*e-d*b);

                        if(-0.0005<x && x<0.0005) x=0;
                        if(-0.0005<y && y<0.0005) y=0;

                        printf("%.3f %.3f\n",x,y);


        }
        return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

typedef struct{
  int num;      //割り当て番号
  int par;      //親の番号
  int p_fl;     //親の有無
  int sib;      //兄弟の番号
  int dep;      //深さ
  int deg;      //子供の数
  int deg_n[2]; //子供の数字
  int hei;      //高さ
  int RorL;     //leftなら0、rightなら1
} Nibun;

int main(){

  Nibun data[25];
  int n, i, j, k, cnt, num, degnum, max_dep = 0, h_cnt, temp, flag;
  
  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      scanf("%d",&num);

      data[num].num = num;
      data[num].deg = 0, data[num].dep = 0;

      scanf("%d",&degnum);
      temp = degnum;

      if(degnum == -1)data[num].hei = 0;
      
      else
	{
	  data[degnum].par = num;
	  data[num].deg++;
	  data[degnum].RorL = 0;
	  data[degnum].p_fl = 1;
	}

      scanf("%d",&degnum);

      if(degnum == -1)data[num].hei = 0;
      else
	{
	  data[degnum].par = num;
	  data[num].deg++;
	  data[degnum].RorL = 1;
	  data[degnum].p_fl = 1;
	}
      data[degnum].sib = temp;
      data[temp].sib = degnum;
    }

  for(i = 0; i < n; i++)  //par = -1となるdata[x]を探す処理
    {
      if(data[i].p_fl != 1)
	{
	  data[i].par = -1;
	  data[i].sib = -1;
	  break;
	}
    }
  
  for(i = 0; i < n; i++)  //depthの処理
    {
      j = i;
      cnt = 0;
      
      while(1)
	{
	  if(data[j].par == -1)
	    {
	      data[i].dep = cnt;
	      if(max_dep < cnt)max_dep = cnt;
	      break;
	    }
	  j = data[j].par;
	  cnt++;
	}
    }
  
  for(i = 0; i < n; i++)  //heightの処理
    {
      data[i].hei = 0 , cnt = 0 , flag = 0;
      if(data[i].deg == 0)continue;

      while(2)
	{
	  for(j = 0; j < n; j++)
	    {
	      if(flag == 1)break;
	      if(data[j].dep == max_dep - cnt)
		{
		  h_cnt = 1;
		  k = j;
		  while(3)
		    {
		      if(data[k].par != data[i].num)
			{
			  if(data[k].par == -1)break;
			  k = data[k].par;
			  h_cnt++;
			}
		      else
			{
			  data[i].hei = h_cnt;
			  flag = 1;
			  break;
			}
		    }
		}
	    }
	  if(flag == 1)break;
	  cnt++;
	}
    }

  for(i = 0; i < n; i++)
    {
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, data[i].par, data[i].sib, data[i].deg, data[i].dep, data[i].hei);

      if(data[i].deg == 0 && data[i].par != -1)printf("leaf\n");
      else if(data[i].par == -1)printf("root\n");
      else printf("internal node\n");
    }
  
  
  
  
  
  
  
  
  return 0;
}



Measured memory_bytes: 2148
import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    E[a].append((b,i))
    E[b].append((a,i))
#最大の次数を見つける
K = max(len(e) for e in E)
#Kを出力
print(K)
ans = [-1] * (N-1)
#深さ優先探索
#col:色の番号
#v:注目している頂点(スタート地点の頂点の番号は1)
#p:注目している頂点の親の頂点(スタート地点の親は存在しない０)
#p_col:注目している頂点とその親の頂点を結んでいる辺の色の番号(初期値は-1つまり存在しない)
def dfs(v=1,p=0,p_col=-1):
    #colを初期化する
    col = 1
    #idx:注目している辺の番号
    #u:注目している頂点と結ばれる頂点
    for u, idx in E[v]:
        #もし注目している頂点と親の頂点が一致したら何もしない
        if u != p:
            #注目している辺の色の番号と親の辺の色の番号が一致していないか確認
            #もし一致していたら色の番号を変える
            #一致していなければその辺の色の番号をansに格納する
            if col == p_col:
                col += 1
            ans[idx] = col
            #再帰的に深さ優先探索をくりかえす
            #現在注目している頂点を親の頂点に
            #uを次に注目している頂点とする
            #colを親の辺の番号とする
            dfs(u,v,col)
            #次の頂点へ行くために辺の色の番号を変更する
            col += 1

dfs()
#出力する
print("\n".join(map(str,ans)))

Measured memory_bytes: 85652
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 1e18
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl


ll c[110][110];
ll d[110][110];

int main(){
  ll n;cin>>n;
  vector<ll> x(n),y(n),h(n);
  rep(i,n){
    cin>>x[i]>>y[i]>>h[i];
  }

  rep(i,101){
    rep(j,101){
      c[i][j]=INF;
      rep(k,n){
        if(h[k]==0){
          c[i][j]=min(abs(x[k]-i)+abs(y[k]-j),c[i][j]);
        }
      }
    }
  }

  rep(i,101){
    rep(j,101){
      rep(k,n){
        if(h[k]!=0){
          if(d[i][j]==0){
            d[i][j]=abs(x[k]-i)+abs(y[k]-j)+h[k];
          }else{
            if(d[i][j]!=abs(x[k]-i)+abs(y[k]-j)+h[k]){
              d[i][j]=-1;
            }
          }
        }
      }
    }
  }

  rep(i,101){
    rep(j,101){
      if(d[i][j]>0&&d[i][j]<=c[i][j]){
        cout<<i<<" "<<j<<" "<<d[i][j]<<endl;
        return 0;        
      }
    }
  }

  rep(i,101){
    rep(j,101){
      if(d[i][j]==0&&INF>c[i][j]){
        cout<<i<<" "<<j<<" "<<c[i][j]<<endl;
        return 0;        
      }
    }
  }

  return 0;
}

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

using ll=long long;

int main() {
  double L; cin >>L;
  cout <<fixed;
  cout <<setprecision(12) <<pow(L/3.0,3) <<endl;
  return 0;
}


Measured memory_bytes: 4080
using System;
using System.Linq;

namespace _0240
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int y = int.Parse(Console.ReadLine());
                double ret = 0;
                double max = 0;
                for (int i = 0; i < n; i++)
                {
                    double now = 1;
                    double[] x = Console.ReadLine().Split().Select(double.Parse).ToArray();
                    if (x[2] == 1)
                    {
                        now *= (1 + x[1] / 100 * y);
                    }
                    else
                    {
                        for (int j = 0; j < y; j++)
                        {
                            now *= (1 + x[1] / 100);
                        }
                    }
                    if (max < now)
                    {
                        ret = x[0];
                        max = now;
                    }
                }
                Console.WriteLine(ret);
            }
        }
    }
}

Measured memory_bytes: 9764
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  vector <ll> a;
  vector <ll> b;
  vector <ll> c;
  REP(i,n){
    ll d;
    cin >> d;
    a.pb(d);
  }
  REP(i,n){
    ll d;
    cin >> d;
    b.pb(d);
  }
  REP(i,n){
    ll d;
    cin >> d;
    c.pb(d);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  ll sum = 0;
  REP(i,b.size()){
    ll s;
    
    ll f = upper_bound(c.begin(),c.end(),b[i]) - c.begin();
    f = c.size()-f;
    ll t = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
    
    //cout << f << "   " << t << endl;
    sum += t*f;
  }
  cout << sum << endl;
  
  return 0;
}


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

int main() {
	const string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	int ans = 0;
	string s;

	cin >> s;

	for (int i = 0; i < 7; i++)
	{
		if(s == week[i])
		{
			cout << (7 - i) << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    double sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    double ave=sum/n;
    int iave=sum/n,ans=0;
    if(ave-iave>=0.5) iave++;
    rep(i,n){
       ans+=(a[i]-iave)*(a[i]-iave);
    }
    cout<<ans;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<double,int>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  int n;
  ll c;
  ll arr1[200010],arr2[200010];
  ll *sushi = arr1 + 100005, *dist = arr2 + 100005;
  ll calcl[100005], calcr[100005];
  ll bestl[100005], bestr[100005];
  cin >> n >> c;
  dist[0] = 0;sushi[0] = 0;
  for(int i = 1;i <= n;++i){
    ll x,v;
    cin >> dist[i] >> sushi[i];
    dist[-n-1+i] = c - dist[i];
    sushi[-n-1+i] = sushi[i];
  }
  ll res = 0;
  calcl[0] = 0;
  bestl[0] = 0;
  for(int i = 1;i <= n;++i){
    calcl[i] = calcl[i-1] + sushi[i];
    res = max(res,calcl[i] - dist[i]);
    bestl[i] = max(bestl[i-1],calcl[i] - dist[i]);
  }
  calcr[0] = 0;
  bestr[0] = 0;
  for(int i = 1;i <= n;++i){
    calcr[i] = calcr[i-1] + sushi[-i];
    res = max(res,calcr[i] - dist[-i]);
    bestr[i] = max(bestr[i-1],calcr[i] - dist[-i]);
  }
  for(int i = 1;i <= n;++i){
    res = max(res,calcl[i]  - 2*dist[i] + bestr[n-i]);
  }
  for(int i = 1;i <= n;++i){
    res = max(res,calcr[i]  - 2*dist[-i] + bestl[n-i]);
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 6528
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"5 3
1 2 3 4 5"# => r#"12"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize, k: usize,
        mut l: [usize; n],
    }
    l.sort();
    l[(n-k)..].iter().sum::<usize>().to_string()
}

Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string s;
    cin >> s;
    const bool ans = (s[2] == s[3]) && (s[4] == s[5]);
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    int q;
    cin >> s >> t >> q;
    int a,b,c,d;
    int cnt1[100010],cnt2[100010];
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            cnt1[i+1]=cnt1[i]+2;
        }else{
            cnt1[i+1]=cnt1[i]+1;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='A'){
            cnt2[i+1]=cnt2[i]+2;
        }else{
            cnt2[i+1]=cnt2[i]+1;
        }
    }
    for(int i=0;i<q;i++){
        cin >> a >> b >> c >> d;
        if((cnt1[b]-cnt1[a-1])%3==(cnt2[d]-cnt2[c-1])%3){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;

  int size = S.size(), dm = INF;

  for (int i = 0; i < size - 2; i ++) {
    int x = std::stoi(S.substr(i, 3)), d = std::abs(x - 753);

    dm = std::min(d, dm);
  }
    
  std::cout << dm << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
using namespace std;

int main()
{
  int N, M;
  while (cin >> N >> M) {
    int ans = 0;
    for (int i = 0; i < N; ++i) {
      int cnt = 0;
      for (int j = 0; j < M; ++j) {
	int t;
	cin >> t;
	if (t == 1)
	  ++cnt;
      }
      ans = max(ans, cnt);
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String line = br.readLine();
		String[] split = line.split(" ");
		int N = Integer.parseInt(split[0]);
		int A = Integer.parseInt(split[1]);
		
		line = br.readLine();
		split = line.split(" ");
		
		int[] arr = new int[N];		
		for(int i = 0; i<N; i++) arr[i] = Integer.parseInt(split[i]);
		
		boolean[][] dp =  new boolean[N+1][50*N+1];
		long[][] times = new long[N+1][50*N+1];
		for(int i = 0; i<=N; i++){
			Arrays.fill(times[i], 0);
			Arrays.fill(dp[i], false);
		}

		dp[0][0] = true;
		times[0][0] = 1;
		
		long total = 0;
		
		for(int i = 0; i < N; i++){			
			for(int j = i; j>=0; j--){
				for(int k = 50*N - arr[i]; k>=0; k--){
					if(dp[j][k]){
						int index = k + arr[i];
						dp[j+1][index] = true;
						times[j+1][index] += times[j][k];
						if((A*(j+1)) == index){
							total += times[j][k];
						}
					}
				}
			}	
		}		
		System.out.println(total);
	}
}


Measured memory_bytes: 10320
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long n = Long.parseLong(in.next());
            long k = Long.parseLong(in.next());
            long ans = 0;
            long x = 0;

            x = n;
            long tmp = Long.MAX_VALUE;
            if (n == 0) {
                out.println(0);
                return;
            } else if (k == 1) {
                out.println(0);
                return;
            } else if (n < k) {
                x = Math.abs(n - k);
                if (x < n) {
                    out.println(x);
                } else {
                    out.println(n);
                }
                return;
            } else if (n > k) {
                if (n % k == 0) {
                    out.println(0);
                    return;

                } else if (n % k == 1) {
                    out.println(1);
                    return;

                } else {
                    x = Math.abs(n % k - k);
                    if (n % k > x) {
                        out.println(x);
                        return;

                    } else {
                        out.println(n % k);
                        return;

                    }

                }
            } else {
                out.println(0);
                return;
            }

        }

    }
}



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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n; cin >> n;
  cout << ((n + 999) / 1000) * 1000 - n << endl;
  return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
long long p,a[1000],b,r=30,d,i,j;
long double m,f,l,n,k;
string ss;
char c;
int main()
{
	cin >> d >> ss;

	p=ss.size();

	for(i=0;i<p;i++)
    {
        n=ss[i];
        n+=d;
        if(n>90)
        {
            while(n>90)
            {
                n-=26;
            }
        }

        c=n;

        cout << c;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	vector<string> s(3);
	for(int i = 0; i < 3; ++i) {
		cin >> s[i];
		reverse(s[i].begin(), s[i].end());
	}
	
	int now = 0;
	for(int i = 0; i < 300; ++i) {
		
		if( s[now].empty() ) {
			cout << (char)(now + 'A') << endl;
			return 0;
		}
		
		char c = s[now].back();
		s[now].pop_back();
		now = (int)(c - 'a');
	}
	
	return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define pii pair<int, int>
#define _0 first
#define _1 second

int main()
{
	int n, m, k = 500'100;
	scanf("%d %d", &n, &m);
	vector<int> a(n);
	for (auto& i : a)
	{
		scanf("%d", &i);
		i--;
	}

	int bracket_size = (int)sqrt(n);
	vector<int> cnt(k);
	int dif = 0;

	vector<pii> q(m);
	for (auto& i : q)
	{
		scanf("%d %d", &i._0, &i._1);
		i._0--;
		i._1--;
	}

	vector<int> moidx(m);
	for (int i = 0; i < m; i++)
		moidx[i] = i;
	sort(moidx.begin(), moidx.end(), [&q, &bracket_size](const int& i, const int& j)
		{
			int l = q[i]._0 / bracket_size;
			int r = q[j]._0 / bracket_size;
			return l < r || (l == r && q[i]._1 < q[j]._1);
		});

	vector<int> sol(m);
	for (int i = q[moidx[0]]._0; i <= q[moidx[0]]._1; i++)
	{
		if (cnt[a[i]] == 0)
			dif++;
		cnt[a[i]]++;
	}
	sol[moidx[0]] = dif;
	for (int i = 1; i < m; i++)
	{
		if (q[moidx[i - 1]]._1 < q[moidx[i]]._1)
		{
			for (int j = q[moidx[i - 1]]._1 + 1; j <= q[moidx[i]]._1; j++)
			{
				if (cnt[a[j]] == 0)
					dif++;
				cnt[a[j]]++;
			}
		}
		else
		{
			for (int j = q[moidx[i - 1]]._1; j > q[moidx[i]]._1; j--)
			{
				cnt[a[j]]--;
				if (cnt[a[j]] == 0)
					dif--;
			}
		}

		if (q[moidx[i - 1]]._0 < q[moidx[i]]._0)
		{
			for (int j = q[moidx[i - 1]]._0; j < q[moidx[i]]._0; j++)
			{
				cnt[a[j]]--;
				if (cnt[a[j]] == 0)
					dif--;
			}
		}
		else
		{
			for (int j = q[moidx[i - 1]]._0 - 1; j >= q[moidx[i]]._0; j--)
			{
				if (cnt[a[j]] == 0)
					dif++;
				cnt[a[j]]++;
			}
		}

		sol[moidx[i]] = dif;
	}

	for (auto& i : sol)
		printf("%d\n", i);

	return 0;
}

Measured memory_bytes: 15460