akhauriyash/Code-Regression huggingface dataset:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def l_b(x):
  ok = 0
  ng = 40
  while ng - ok > 1:
    mid = (ok+ng) // 2
    if n % (k ** mid) == 0:
      ok = mid
    else:
      ng = mid
  return x ** ok
n = int(input())
L = make_divisors(n)
ans = 0
for k in L:
  if k == 1:
    continue
  k_m = l_b(k)
  if (n // k_m) % k == 1:
    ans += 1
ans += len(make_divisors(n-1))
ans -= 1
print(ans)

Measured memory_bytes: 42092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Index		index = null;
		IndexTbl	tbl   = new IndexTbl();
		int			cnt   = 0;
		int[][]		dat   = new int[100][101];

		while((index = parseIndex()) != null) {
			int	id = cnt;
			if (!tbl.containsKey(index.w)) {
				tbl.put(index.w, cnt++);
			} else {
				id = (Integer)tbl.get(index.w);
			}
			dat[id][0]++;
			dat[id][dat[id][0]] = index.i;
		}

		{
			IndexKey			keys = new IndexKey(tbl.keySet());
			Iterator<String>	iter = keys.iterator();

			while(iter.hasNext()) {
				String	out = "";
				String	key = iter.next();
				int		val = tbl.get(key);
				System.out.println(key);
				Arrays.sort(dat[val], 1, dat[val][0]+1);
				for (int l = 1; l <= dat[val][0]; l++) {
					out = (l == 1) ? "" + dat[val][l] : out + (" " + dat[val][l]);
				}
				System.out.println(out);
			}
		}
	}

	private static Index parseIndex() {
		String	str   = null;
		Index	index = null;

		if ((str = parseStdin()) != null) {
			String[]	lines = str.split(" ");

			if (lines.length == 2) {
				index   = new Index();
				index.w = lines[0];
				index.i = Integer.parseInt(lines[1]);
			}
		}
 
		return index;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

class IndexTbl extends HashMap<String, Integer> {
}

class IndexKey extends TreeSet<String> {
	IndexKey(Set<String> set) {
		super(set);
	}
}

class Index {
	String	w;
	int		i;
}

Measured memory_bytes: 15196
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;

int main() {
  int A, B;
  string S;
  cin>>S;
  
  for(int i=0; i<S.size();i++) S[i] = 'x';
  
  cout<<S<<endl;
  
  return 0;
}

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

int main(void)
{
	long int i, j;
	long int n;
	long int flg;
	long int count;
	long int sum;
	long int a[200001];
	long int x[200001] = {0};
	
	scanf("%ld", &n);
	
	count = 0;
	for(i = 1; i <= n; i++) {
		scanf("%ld", &a[i]);
	}
	
	for(i = n; i > 0; i--) {
		sum = 0;
		for(j = i; j <= n; j = j + i) {
			sum += a[j];
		}
		if( ((sum % 2) == a[i]) && (a[i] == 0) ) {
			a[i] = 0;
		} else if( ((sum % 2) == a[i]) && (a[i] == 1) ) {
			a[i] = 1;
			count++;
		} else if( ((sum % 2) != a[i]) && (a[i] == 0) ) {
			a[i] = 1;
			count++;
		} else if( ((sum % 2) != a[i]) && (a[i] == 1) ) {
			a[i] = 0;
		}
	}
	
	printf("%ld\n", count);
	
	for(i = 1; i <= n; i++) {
		if(a[i] == 1) {
			printf("%ld ", i);
		}
	}
	
	return 0;
}


Measured memory_bytes: 2432
import itertools
import math
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X = []
    for i in range(N):
        x,y = mi()
        X.append((x,y))

    sm = 0
    count = 0
    for v in itertools.permutations(X,N):
        V = list(v)
        pre = V[0]

        for u in V[1:]:
            d = math.sqrt((pre[0]-u[0])**2 + (pre[1]-u[1]) ** 2)
            sm += d
        
        count += 1

    ans = sm/count
    print('{:.10f}'.format(ans))

    


if __name__ == "__main__":
    main()

Measured memory_bytes: 73800
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;

int main(){
  int i,N;
  cin>>N;
  string S,T;
  cin>>S>>T;
  i=0;
  while(i<N){
    cout<<S[i]<<T[i];
    i++;
  }
  cout<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include<stdlib.h>
using namespace std;
int cmp(const void*a,const void*b)
{
	return *(int*)b-*(int*)a;
}
int main() {
	int n,k;
	cin >> n >>k;
	int arr[n];
	int i;
	for(i=0;i<n;i++)cin >> arr[i];
	qsort(arr,n,4,cmp);
	
	long long int sum=0;
	for(i=0;i<k;i++)
	sum+=arr[i];
	cout << sum << endl;
	// your code goes here
	return 0;
}

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


int main(){
    int n;  cin >> n;
    map<ll, ll> balls;
    set<ll> kinds;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        ll x;  cin >> x;
        x--;    a.at(i) = x;
        balls[x] += 1;
        kinds.insert(x);
    }
    map<ll, ll> isOn, isOff;
    ll ans=0;
    for(auto x: kinds){
        ll a = balls[x];
        isOn[x] = a*(a-1)/2;
        isOff[x] = (a-1)*(a-2)/2;
        ans += isOn[x];
    }

    for(int i=0; i<n; i++){
        int key = a.at(i);
        cout << ans-isOn[key]+isOff[key] << endl;
    }

}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b,v,w,t,d;
	cin>>a>>v>>b>>w>>t;
	d=abs(a-b);
	if((a<0 && b>0) || (a>0 && b<0))
	d = abs(a)+abs(b);
	if(a<0 && b<0)
	d = abs(abs(a)-abs(b));
	long long int total_distance =d+(t*w);
	if((t*v)>=total_distance)
	cout<<"YES"<<"\n";
	else
	cout<<"NO"<<"\n";
	return 0;
}


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

typedef long long ll;

const ll max_n = 100010;
ll n, c[max_n];
vector<pair<ll, ll>> t[max_n];

void dfs(ll v, ll previous=-1) {
    for (auto it: t[v]) {
        ll u = it.first;
        ll w = it.second % 2;
        if (u != previous) {
            c[u] = c[v] ^ w;
            dfs(u, v);
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        ll u, v, w;
        cin >> u >> v >> w;
        t[u].push_back({v, w});
        t[v].push_back({u, w});
    }
    
    dfs(1);
    
	for(int i = 1; i <=n; ++i) {
        cout << c[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
 
#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define VT(T) vector<T>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;
typedef unsigned long long int ull;

ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
 
ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}
 
ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}
 
ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

int farthest(string grid[], int n, int m, int r, int c){
	vvint dst(n,vint(m,-1));
	queue<pii> q;
	q.push({r,c});
	dst[r][c]=0;
	while(!q.empty()){
		auto p=q.front();
		q.pop();
		int i=p.fst, j=p.scd;
		if(i+1<n && grid[i+1][j]=='.' && dst[i+1][j]==-1){
			dst[i+1][j]=dst[i][j]+1;
			q.push({i+1,j});
		}
		if(i>=1 && grid[i-1][j]=='.' && dst[i-1][j]==-1){
			dst[i-1][j]=dst[i][j]+1;
			q.push({i-1,j});
		}
		if(j+1<m && grid[i][j+1]=='.' && dst[i][j+1]==-1){
			dst[i][j+1]=dst[i][j]+1;
			q.push({i,j+1});
		}
		if(j>=1 && grid[i][j-1]=='.' && dst[i][j-1]==-1){
			dst[i][j-1]=dst[i][j]+1;
			q.push({i,j-1});
		}
	}

	int ret=0;
	for(auto x : dst){
		for(auto y : x){
			if(y>=0){
				ret=max(ret,y);
			}
		}
	}

	return ret;
}

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

	int h, w;
	cin>>h>>w;
	string grid[h];
	for(int i=0; i<h; i++){
		cin>>grid[i];
	}

	int ans=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(grid[i][j]=='.'){
				ans=max(ans,farthest(grid,h,w,i,j));
			}
		}
	}
	cout<<ans<<endl;
}

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

ll powmod(ll a, ll n)
{
    if(a<=0)
    return 0;
    if(n==0)
        return 1;
    if(n%2==0)
    {
        return (powmod(a,n/2)*powmod(a,n/2))%mod;
    }
    else
    {
         return (((powmod(a,n/2)*powmod(a,n/2))%mod)*a)%mod;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    vector<ll> dp(k+1);
    for(ll i=k;i>=1;--i)
    {
        ll temp=powmod(k/i,n);
        
        for(int j=2*i;j<=k;j+=i)
        {
            temp-=dp[j];
        }
        //temp = (temp+mod)%mod;
        dp[i] = temp;
    }
    
    for(int i=1;i<=k;++i)
    {
        //cout<<dp[i]<<" ";
        ans=(ans+i*dp[i])%mod;
    }
    
    ans=(ans+mod)%mod;
    cout<<ans<<"\n";

}


Measured memory_bytes: 3964
#include "bits/stdc++.h"
using namespace std;
int N, K, a[102], dp[100002];
bool fun(int n){
    if(n == 0) return dp[n] = 0;
    if(dp[n] != -1) return dp[n];
    for(int i=1; i<=N; i++)
        if(n >= a[i] && !fun(n-a[i])) return dp[n] = 1;
    return dp[n] = 0;
}
int main(){
    scanf("%d %d", &N, &K); memset(dp, -1, sizeof(dp));
    for(int i=1; i<=N; i++) scanf("%d", &a[i]);
    printf("%s\n", fun(K)? "First": "Second");
}

Measured memory_bytes: 3712
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)

Measured memory_bytes: 3500
b_size = {}
for b in range(1, int(input())+1):
  if b%2 == 0:
    continue
  size = len([by for by in range(1, b+1) if b%by == 0 and by%2 == 1])
  if size == 8:
    b_size[b] = size
print(len(b_size))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n, a[100010];
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	if(n == 1) {cout << "YES"; return 0;}
	int cnt = 0;
	for(int i = 1; i <= n; i ++)
		if(a[i] % 2 == 1) cnt ++;
	if(cnt % 2 == 1) cout << "NO";
	else cout << "YES";
	return 0;
}


Measured memory_bytes: 640
from collections import deque
H, W = map(int, input().split())


field = []
num_blacks = 0
for i in range(H):
    line = input()
    num_blacks += line.count(".")
    field.append(line)

cost = [[-1]*(W) for _ in range(H)]

cost[0][0] = 1
dxdy = [(-1, 0), (1, 0), (0, -1), (0, 1)]
def bfs():
    q = deque()
    q.append((0, 0))
    while len(q):
        x, y = q.popleft()
        for dx, dy in dxdy:
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue

            if field[ny][nx] == "." and cost[ny][nx] < 0:
                cost[ny][nx] = cost[y][x]+1
                q.append((nx, ny))

bfs()
print(num_blacks - cost[H-1][W-1]) if cost[H-1][W-1] > 0 else print(-1)


Measured memory_bytes: 3316
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 r          PIC 9(10).
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT r.
  COMPUTE ans = 3 * r ** 2.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


Measured memory_bytes: 3856
#include<stdio.h>
int a,b,c,m,f;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	while(m<(a*b)){
		m+=a;
		if((m%b)==c){
			f=1;
			break;
		}
	}
	if(f==1){
		puts("YES");
	}else{
		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int k; cin >> k;
	rep(i, k) {
		cout << "ACL";
	}
}



Measured memory_bytes: 3524
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int N, M, sum(0);
    cin >> N >> M;
    int A[M];
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    int result = N - sum;
    if (result < 0)
        result = -1;
    cout << result << endl;
}

Measured memory_bytes: 3660
while True:
	n, r = map(int, input().split())
	if (n, r) == (0, 0):
		break
	cards = list(range(1, n+1))[::-1]

	for i in range(r):
		p, c = map(int, input().split())
		cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
	print(cards[0])

Measured memory_bytes: 7612
import java.util.*;

public class Main{

	public static void main(String[] args) {
		scan();
	}
	public static void scan() {
		Scanner scanner = new Scanner(System.in);
		while(true){
			int H = scanner.nextInt();
			int W = scanner.nextInt();
			if(H == 0 && W == 0){break;}
			Print(H , W);
			System.out.println("");
			
		}
		scanner.close();
		return ;
	}
	public static void Print(int H, int W){
		for(int y = 0 ; y < H ; y++){
			for(int x = 0; x < W ; x++){
				if(y==0 || x == 0 || y == H-1 || x == W-1){
					System.out.print("#");
				}
				else {
					System.out.print(".");
				}
			}
			System.out.println("");
		}
		return;
	}	
	
	
}

Measured memory_bytes: 32752
def main():
    N, K = map(int, input().split())
    D = list(input().split())

    while True:
        S = str(N)
        f = True
        for s in S:
            if s in D:
                f = False
                break
        if f:
            break
        N += 1
    print(N)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#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() {
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i+=2) cout<<s[i];
}

Measured memory_bytes: 3608
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]

c = [0] * (m + 1)
for i in range(n):
    for j in range(a[i], m + 1, a[i]):
        c[j] += 1

ans = 0
for e in list(set(a)):
    if c[e] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 39468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    
   int n;
   cin >> n;
   vector<int> a(n),b(n),c(n-1);
   for(int i = 0; i < n;i++){
       cin >> a[i];
   }

   for(int i = 0; i < n;i++){
       cin >> b[i];
   }
   for(int i = 0; i < n-1;i++){
       cin >> c[i];
   }
   int pre;
   int ans=0;
   for(int i = 0; i < n;i++){
       ans += b[a[i]-1];
       if(pre+1 == a[i]-1){
           ans += c[a[i-1]-1];
       }
       pre = a[i]-1;
   }

   cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> p(n); for (auto&& e : p) cin >> e;

  auto fn = [&]() -> pair< V<>, V<> > {
    V<> ip(n + 1);
    for (int i = 0; i < n; ++i) {
      ip[p[i]] = i;
    }
    bitset<100001> bs;
    bs[n] = 1;
    V<> a(n + 1), b(n + 1);
    for (int v = n; v; --v) {
      int i = ip[v];
      int j = bs._Find_next(i);
      a[v] = j - i;
      if (j < n) {
        b[v] = bs._Find_next(j) - j;
      }
      bs[i] = 1;
    }
    return {a, b};
  };

  V<> ra, rb;
  tie(ra, rb) = fn();
  reverse(begin(p), end(p));
  V<> la, lb;
  tie(la, lb) = fn();
  lint res = 0;
  for (int v = 1; v <= n; ++v) {
    res += (lint)ra[v] * lb[v] * v;
    res += (lint)rb[v] * la[v] * v;
  }
  cout << res << '\n';
}

Measured memory_bytes: 3432
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
Hn = list(map(int, input().split()))

ans = 0
n = 0
for i in range(1, N):
    b = Hn[i] - Hn[i-1]
    if b <= 0:
        n += 1
    else:
        ans = max(ans, n)
        n = 0
    if i == N - 1:
        ans = max(ans, n)
print(ans)


Measured memory_bytes: 20528
while True:
  m, f, r = list(map(int, input().split()))
  if m == -1 and f == -1 and r == -1:
    break
  if m == -1 or f == -1:
    print("F")
  elif m + f >= 80:
    print("A")
  elif m + f >= 65:
    print("B")
  elif m + f >= 50:
    print("C")
  elif m + f >= 30:
    print("C" if r >= 50 else "D")
  else:
    print("F")


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

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; i++){
        cin >> v.at(i);
    }
    int max = -1;
    for(int i = 0; i < N; i++){
        int j = i;
        int cnt = 0;
        if(max < N - i){
            while( (j != N - 1) && (v.at(j) >= v.at(j+1))){
                j++;
                cnt++;
            }
        }
        if(max < cnt){
            max = cnt;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] a = str.split("");
//        System.out.println(a[0]);
		int num = a.length;
		String sum0 = "";
		String sum1 = "";
		int ans = 0;;
		
 		for(int i=0; i<num/2-1; i++ ){
 			sum0 = sum0 + a[i];
 			for(int j=i+1; j<2*i+2; j++ ){
 				sum1 = sum1 + a[j];
 				
 			}
 			if (sum0.equals(sum1)){
 				ans = (i+1)*2;
 			}
 			sum1 = "";
 		}
 		System.out.println(ans);
	}
}

Measured memory_bytes: 23508
import re
class c:
 def __init__(self,value):self.x=value
 def __str__(self):return str(self.x)
 def __add__(self,value):return c(self.x+value.x)
 def __sub__(self,value):return c(self.x-value.x)
 def __mul__(self,value):return c(self.x*value.x)
 def __truediv__(self,value):return c(int(self.x/value.x))
for i in[0]*int(input()):print(eval(re.sub(r'(\d+)',r'c(\1)',input()[:-1])))


Measured memory_bytes: 6612
#include<iostream>
#include<math.h>
using namespace std;
int n,a[100010],b[100010],c[100010];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int l=0,r=a[1]+1,w;
	bool no=false;
	while(r-l!=1)
	{
		no=false;
		w=(l+r)/2;
		b[1]=w;
	//	cout<<w<<endl;
		for(int i=2;i<=n;i++)
		{
			b[i]=a[i-1]-b[i-1];
			//cout<<i<<" "<<b[i]<<endl;
			if(b[i]<0)
			{
				if(i%2==0)
					r=w;
				else
					l=w;
				no=true;
				break;
			}
		}
		if(no==true)
			continue;
		if(b[1]+b[n]>a[n])
			r=w;
		else if(b[1]+b[n]<a[n])
			l=w;
		else
			break;
	}
	w=(l+r)/2;
	for(int i=2;i<=n;i++)
	{
		if(b[i]<0)
		{
			if(i%2==0)
				b[1]=l;
			else
				b[1]=r;
			for(int i=2;i<=n;i++)
				b[i]=a[i-1]-b[i-1];
			break;
		}
	}
	if(w+b[n]<a[n])
  	{
		b[1]=r;
		for(int i=2;i<=n;i++)
			b[i]=a[i-1]-b[i-1];
	}
	else if(w+b[n]>a[n])
	{
		b[1]=l;
		for(int i=2;i<=n;i++)
			b[i]=a[i-1]-b[i-1];
	}
	for(int i=1;i<n;i++)
		cout<<b[i]*2<<" ";
	cout<<b[n]*2<<endl;
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <math.h>
int main() {
    int n, p, o=0, e=0;
    scanf("%d %d", &n, &p);
    for (int i=0; i<n; i++) {
        int k;
        scanf(" %d", &k);
        if (k % 2)
            o++;
        else
            e++;
    }
    if (o == 0) {
        if (p == 1)
            puts("0");
        else
            printf("%ld\n", (long)powl(2, n));
    } else
        printf("%ld\n", (long)powl(2, n-1));
}

Measured memory_bytes: 384
inp_1 = input().split()
n = int(inp_1[0])
x = int(inp_1[1])
l_in = input().split()

count = 1 # 初回
d = 0
for i in range(n):
    if d + int(l_in[i]) > x:
        break
    else:
        count = count+1
        d = d + int(l_in[i])
print(count)




Measured memory_bytes: 3060
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <string>
using namespace std;


int main() {
  int N;
  cin >> N;
  assert(1 <= N && N <= 100000);

  int ac = 0, wa = 0, tle = 0, re = 0;

  string s;
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s == "AC") ac++;
    else if (s == "WA") wa++;
    else if (s == "TLE") tle++;
    else if (s == "RE") re++;
    else throw runtime_error("What's wrong!");
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
	int h,m,s;
	int hl,ml,sl;
	int timesum,timesuml;
	int sasum;
	int sah,sam,sas;
	while(scanf("%d %d %d",&h,&m,&s)!=EOF){
	
		scanf("%d %d %d",&hl,&ml,&sl);
		
		timesum=h*60*60+m*60+s;
		timesuml=hl*60*60+ml*60+sl;

		sasum=timesuml-timesum;

		sah=sasum/3600;
		sasum=sasum%3600;
		sam=sasum/60;
		sas=sasum%60;

		printf("%d %d %d\n",sah,sam,sas);
	}
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    string s;
    cin >> s;
    int ans = INF;
    rep(i, s.size() - 2) {
        ans = min(ans, abs(753 - ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0'))));
    }
    cout << ans << endl;
}

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



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

using namespace std;

typedef long long ll;

int main() {
   ll N;    cin >> N;
   vector<ll> v;
   
   ll x = 6, y = 9;
   while (x <= N) {
       v.push_back(x);
       x *= 6;
   } 
   while (y <= N) {
       v.push_back(y);
       y *= 9;
   }

   ll sz = v.size();

   ll *dp = new ll[N+1];
   dp[0] = 0;
   for (int i = 0; i < N; i++) {
       dp[i+1] = dp[i] + 1;
       for (int j = 0; j < sz; j++) {
           if (v[j] <= i+1) {
               dp[i+1] = min(dp[i+1], dp[i+1-v[j]] + 1);
           }
       }
   }

   cout << dp[N] << endl;
   return 0;
}  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define us unsigned short int
#define fin freopen("/home/imtiaz/Desktop/in.txt", "r", stdin)
#define fout freopen("/home/imtiaz/Desktop/out.txt","w", stdout)
#define dbg(x) cerr << #x << ": " << x << endl
#define fastio ios::sync_with_stdio (false); cin.tie (0);
using namespace std;


int main(){
    ll n;
    cin>>n;
    ll th=1000;
    while (!(n<=th))
    {
        th+=1000;
    }
    cout<<th-n<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, A;
    cin >> N;
    cin >> A;

    if( (N % 500) > A )
    {
        cout << "No";
    }
    else
    {
        cout << "Yes";
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }




    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }




    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);


        var input = Reads();
        long a = input[0];
        long b = input[1];
        long gcd = Gcd(a, b);
        long tmp = gcd;
        var c = new List<long>();
        bool tf;
        long divide = 2;
        while (divide * divide <= tmp)
        {
            tf = false;
            while (gcd % divide == 0)
            {
                gcd = gcd / divide;
                tf = true;
            }
            if (tf)
                c.Add(divide);
            divide++;
        }
        if (gcd == 1)
            Console.WriteLine(c.Count + 1);
        else
            Console.WriteLine(c.Count + 2);





        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const D = parseInt(arg[0].split(" ")[1]);
    
    const XY = arg.slice(1, N + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        const p = XY[i][0];
        const q = XY[i][1];
        
        const abs = Math.sqrt(Math.pow(p, 2) + Math.pow(q, 2));
        
        if(abs <= D) {
            answer++;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 93120
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
int a[MAXN];
int main() {
    int n; scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    int rez = 0;
    for(int i = 1; i <= n; i++) {
        if(a[i] == i) swap(a[i], a[i+1]), rez++;
    }
    printf("%d", rez);
    return 0;
}


Measured memory_bytes: 640
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    while (n > 0) n -= 1000;
    cout << -n;
    return 0;
}


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

using namespace  std;

const int N = 1e5 + 4;
const int deltaX[4] = {-1 , 1, 0 , 0};
const int deltaY[4] = {0 , 0 , -1 , 1};
char grid[26][26];
int h , w;
bool ok(int x , int y){
    return x >-1 && x < h && y >-1 && y < w && grid[x][y]=='.';
}
int BFS(int x , int y){
    int dist[26][26];
    int ans = 0;
    memset(dist, -1 , sizeof(dist));
    dist[x][y] = 0;
    queue<pair<int, int> > q;
    q.push({x, y});
    while(!q.empty()){
        pair<int,int> pos = q.front();
        q.pop();
        for(int d = 0 ; d < 4; ++d){
            pair<int,int> new_pos = {pos.first + deltaX[d]  , pos.second + deltaY[d]};
            if(ok(new_pos.first , new_pos.second)){
                if(dist[new_pos.first][new_pos.second] == -1){
                    dist[new_pos.first][new_pos.second] = dist[pos.first][pos.second] + 1;
                    ans = max(dist[new_pos.first][new_pos.second] , ans);
                    q.push(new_pos);
                }
            }
        }
    }
    return ans;

}

int main() {
    cin>>h>>w;
    for(int i = 0 ; i < h; ++i){
        cin>>grid[i];
    }
    int res = 0;
    for(int i = 0 ; i < h; ++i){
        for(int j = 0 ;j < w; ++j){
            if(grid[i][j]=='.'){
                res = max(res , BFS(i , j));
            }
        }
    }
    cout<<res<<endl;

}

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

void solv() {
    int N, K;
    cin >> N >> K;
    ll sum = 1;
    rep(i,N){
        if(i == 0 ){
            sum *= K;
        }
        else{
            sum *= K -1;
        }
    }
    cout << sum << endl;
}

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

Measured memory_bytes: 256
def check(seq)
	a = b = 0
	seq.each do |i|
		if a < i
			a = i
		elsif b < i
			b = i
		else
			return false
		end
	end

	return true
end

$<.gets.to_i.times do
	puts check($<.gets.split.map(&:to_i)) ? 'YES' : 'NO'
end

Measured memory_bytes: 6100
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
nums = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while True:
    try:
        m, d = map(int, input().split())
        if not m:
            break
    except:
        break
    print(days[(sum(nums[:m - 1]) + d + 2) % 7])

Measured memory_bytes: 7600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long A;
    string B,D;
    cin>>A>>B;
    D=B.substr(0,1)+ B.substr(2,2);
    int C=0;

    C = stoi(D);
    //cout << C << endl;
    long long ans=C*A;
    ans=ans/100;    
    cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 	
 	int n, k; cin >> n >> k;
 	set<int> s;
 	FOR(i, k){
 		int d; cin >> d;
 		FOR(j, d){
 			int x; cin >> x;
 			s.insert(x);
 		}
 	}

 	cout << n-s.size();

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    #define int long long
    const int t=26;
    int d;
    cin>>d;
    int c[t],s[d][t],last[t];
    for(int i=0;i<t;i++){
        cin>>c[i];
        last[i]=-1;
    }
    for(int i=0;i<d;i++)for(int j=0;j<t;j++)cin>>s[i][j];
    int T[d];
    for(int i=0;i<d;i++)cin>>T[i];
    int happy=0;
    for(int i=0;i<d;i++){
        int m=0,x;
        for(int j=0;j<t;j++){
            int up=0;
            for(int k=0;k<t;k++){
                if(k==j)up+=s[i][k];
                else up-=c[k]*(i-last[k]);
            }
            if(up>m){
                x=j;
                m=up;
            }
            last[x]=i;
        }
        /*happy+=m;
        cout<<happy<<endl;*/
        cout<<x+1<<endl;
    }
    return 0;
}

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


void print_vector(vector<ll>& a){
    REP(i, a.size()){
        cout << a.at(i);
        if(i + 1 < a.size()){
            cout << ' ';
        }
    }
    cout << endl;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }

    bool flag = true;
    ll count = 0;
    for(ll i = 0; flag; ++i){
        flag = false;
        for(ll j = a.size() - 1; j > i; --j){
            if(a.at(j) < a.at(j - 1)){
                swap(a.at(j), a.at(j - 1));
                count++;
                flag = true;
            }
        }
    }
    print_vector(a);
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3100
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    println((sc.next().toInt()..sc.next().toInt())
            .map({i:Int -> i.toString()})
            .filter({s:String -> s[0] == s[4] && s[1] == s[3] } )
            .size
    )
}

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

using namespace std;

struct RangeSegmentTree
{
  vector< int > data;
  int sz;

  RangeSegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    data.assign(2 * sz - 1, -1);
  }

  void update(int a, int b, int x, int k, int l, int r)
  {
    if(a >= r || b <= l) {
      return;
    } else if(a <= l && r <= b) {
      data[k] = max(data[k], x);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) >> 1);
      update(a, b, x, 2 * k + 2, (l + r) >> 1, r);
    }
  }

  void update(int a, int b, int x)
  {
    update(a, b, x, 0, 0, sz);
  }

  int get(int k)
  {
    k += sz - 1;
    int ret = data[k];
    while(k > 0) {
      k = (k - 1) >> 1;
      ret = max(ret, data[k]);
    }
    return (ret);
  }
};

int main()
{
  int N, M;
  RangeSegmentTree tree(394);
  int dp[394];

  cin >> N;
  while(N--) {
    int s, l, p;
    cin >> s >> l >> p;
    tree.update(s, l + 1, p);
  }
  for(int i = 0; i < 394; i++) {
    dp[i] = tree.get(i);
  }

  for(int i = 0; i < 394; i++) {
    if(dp[i] == -1) continue;
    for(int j = 0; j <= i && i + j < 394; j++) {
      if(dp[j] == -1) continue;
      dp[i + j] = max(dp[i + j], dp[i] + dp[j]);
    }
  }
  cin >> M;
  vector< int > q;
  while(M--) {
    int w;
    cin >> w;
    if(~dp[w])  {
      q.emplace_back(dp[w]);
    } else {
      cout << -1 << endl;
      exit(0);
    }
  }
  for(int k : q) {
    cout << k << endl;
  }
}

Measured memory_bytes: 3172
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(((a*b*1)%2 ==0 ) || ((a*b*3)%2 == 0) || ((a*b*2) ==0 )) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

int main(){

	int n;
	string er, ge;
	char tmp;
	int mid;

	cin >> n;

	while (n--){
		cin >> er;
		cin >> ge;

		for (int i = er.size() - 1; i >= 0; i--){
			if (er[i] == 'J'){
				tmp = ge[ge.size() - 1];
				for (int j = ge.size() - 1; j > 0; j--){
					ge[j] = ge[j - 1];
				}
				ge[0] = tmp;
			}
			else if (er[i] == 'C'){
				tmp = ge[0];
				for (int j = 0; j < ge.size()-1; j++){
					ge[j] = ge[j + 1];
				}
				ge[ge.size()-1] = tmp;
			}
			else if (er[i] == 'E'){
				mid = ge.size() / 2 + ge.size() % 2;
				for (int i = 0; i < ge.size() / 2; i++){
					swap(ge[i], ge[i + mid]);
				}
			}
			else if (er[i] == 'A'){
				for (int i = 0; i < ge.size() / 2; i++){
					swap(ge[i], ge[ge.size()-1-i]);
				}
			}
			else if (er[i] == 'P'){
				for (int i = 0; i < ge.size(); i++){
					if ('0' <= ge[i] && ge[i] <= '9'){
						if (ge[i] == '0') ge[i] = '9';
						else ge[i]--;
					}
				}
			}
			else if (er[i] == 'M'){
				for (int i = 0; i < ge.size(); i++){
					if ('0' <= ge[i] && ge[i] <= '9'){
						if (ge[i] == '9') ge[i] = '0';
						else ge[i]++;
					}
				}
			}
		}
		cout << ge << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;

#define CLR(arr,val) memset(arr,val,sizeof(arr))
int fun(int year,int month,int day){
	int sum = 0;
	if(year%3){
	  if(month%2)
		  sum = 20-day+1;
	  else
		  sum = 19-day+1;
	  for(int i = month+1;i <= 10;++i){
	    if(i%2)
			sum += 20;
		else
			sum += 19;
	  }
	}
	else{
	  sum = 20 - day + 1;
	  for(int i = month+1;i <= 10;++i)
		  sum += 20;
	}
	return sum;
}
int main(){
	//freopen("1.txt","r",stdin);
	int numcase;
	scanf("%d",&numcase);
	while(numcase--){
	  int day,month,year;
	  scanf("%d%d%d",&year,&month,&day);
	  int sum1 = 0,sum2 = 0;
	  sum1 = fun(year,month,day);
	  for(int i = year+1;i <= 999;++i){
	    sum2 += fun(i,1,1);
	  }
	  printf("%d\n",sum1+sum2);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
int main(){
    long long a,b,c;
    cin >> a >> b >> c;
    long long d;
    long long ans = 0;
    if(a == b && a == c){
        if(a%2 == 0){
            cout << -1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else{
    while(a%2 == 0 && b%2 == 0 && c%2 == 0){
        d = (a+b+c)/2;
        a = d - a/2;
        b = d - b/2;
        c = d - c/2;
        ans++;
    } 
    cout << ans << endl;
    }
}

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

int main() {
  int n;
  cin>>n;
  long long int answer=0,f;
  vector<long long int> town(n+1);
  vector<long long int> hero(n);
  for(int i=0;i<n+1;i++){
    cin>>town.at(i);
  }
  for(int i=0;i<n;i++){
    cin>>hero.at(i);
  }
  for(int i=0;i<n;i++){
    f=min(town.at(i),hero.at(i));
    answer+=f;
    hero.at(i)-=f;
    if(hero.at(i)>0){
      f=min(town.at(i+1),hero.at(i));
      answer+=f;
      town.at(i+1)-=f;
    }
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		if(a.equals(b)){
			System.out.print("H");
		}else{
			System.out.print("D");
		}
	}
}

Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        SegmentTree st = new SegmentTree(n, Integer.MAX_VALUE);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            if(sc.next().equals("0")){
                st.update(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()));
            }else{
                sb.append(st.getMin(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()) +1, 0, 0, st.n));
                sb.append(System.lineSeparator());
            }
        }
        System.out.print(sb);
    }
    
    static class SegmentTree {
        int n;
        int[] node;

        public SegmentTree(int size, int defaultValue) {
            n = 1;
            while(n < size) n <<= 1;
            node = new int[2*n-1];
            Arrays.fill(node, defaultValue);
        }
        void update(int i, int x){
            i += n-1;
            node[i] = x;
            while(i > 0){
                i = (i-1)/2;
                node[i] = Math.min(node[i*2+1], node[i*2+2]);
            }
        }
        int getMin(int a, int b, int k, int l, int r){
            if(r <= a || b <= l) return Integer.MAX_VALUE;
            if(a <= l && r <= b){
                return node[k];
            }else{
                int vl = getMin(a, b, k*2+1, l, (l+r)/2);
                int vr = getMin(a, b, k*2+2, (l+r)/2, r);
                return Math.min(vl, vr);
            }
        }
    }
}


Measured memory_bytes: 73260
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,a,b,c;

int main(){
  cin >> n>>a>>b>>c;
  vi L(n);
  REP(i,n){
	  cin>>L[i];
  }
  int ans=114514191;

  int nn=pow(4,n);
  
  REP(i,nn){
	  vi ii(n);
	  vi iabc(4);
	  vi sabc(4,-10);
	  REP(j,n){
		  ii[j]=(i/(int)pow(4,j))%4;
		  iabc[ii[j]]+=L[j];
		  sabc[ii[j]]+=10;
	  }
	  
  	  int score=sabc[0]+sabc[1]+sabc[2];
	  score+=abs(a-iabc[0]);
	  score+=abs(b-iabc[1]);
	  score+=abs(c-iabc[2]);
	  if (sabc[0]>=0){
		  if (sabc[1]>=0){
			  if (sabc[2]>=0){
				  ans=min(ans,score);
			  }
		  }
	  }

  }

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



Measured memory_bytes: 256
while True:
    n, x = map(int,input().split())
    if n == x == 0:
        exit(0)
    ans = 0
    for a in range(1,n-1):
        for b in range(a+1,n):
            for c in range(b+1,n+1):
                if a+b+c == x:
                    ans += 1
    print(ans)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> H(N);
    rep(i, N) { 
        cin >> H[i];
    }
    for (ll i = N-1; i > 0; i--) {
        if (H[i] < H[i-1]) {
            if (H[i-1] - H[i] == 1) {
                H[i-1]--;
            } else {
                cout << "No" << endl;
                return 0;
            }
        } 
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
	int H, W;
	std::cin >> H >> W;

	std::vector<int> mass(H * W);
#define MASS(y, x) mass[((y) * W) + (x)]
	for(int y = 0; y < H; y++) {
		std::string line;
		std::cin >> line;

		for(int x = 0; x < W; x++) {
			MASS(y, x) = line[x];
		}
	}

	bool able = true;
	// 上下左右が黒でないマスを探す
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			if(MASS(y, x) == '#') {
				bool bocchi = true;
				for(int dy = -1; dy <= 1; dy += 2) {
					if(0 <= (y + dy) && (y + dy) < H
						&& MASS(y + dy, x) == '#') {
						bocchi = false;
						break;
					}
				}
				for(int dx = -1; dx <= 1; dx += 2) {
					if(0 <= (x + dx) && (x + dx) < W
						&& MASS(y, x + dx) == '#') {
						bocchi = false;
						break;
					}
				}
				if(bocchi) {
					able = false;
					goto RESULT;
				}
			}
		}
	}

RESULT:
	if(able) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define    ll           long long
#define    dd           double
#define    mp           make_pair
#define    pb           push_back
#define    se           second
#define    fi           first
#define    mod          1000000007
#define    sob(v)       v.begin(),v.end()
#define    sobr(v)      v.rbegin(),v.rend()
#define    fr(i,a,b)    for(int i=a;i<=b;++i)
#define    frr(i,a,b)   for(int i=a;i>=b;--i)
#define    pi           acos(-1.00)
#define    check        cout<<"*"<<endl
#define    ffix(x)      cout<<fixed<<setprecision(x)
#define    fast         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<int,vi> pp;

int dr[4]= {0,0,-1,1};
int dc[4]= {-1,1,0,0};

const int N=100;

ll binpow(ll a,ll b)
{
    ll res=1*1LL;
    a%=mod;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1];
    fr(i,1,n)cin>>a[i];
    sort(a+1,a+n+1);
    int sum=0;
    fr(i,1,k)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3592
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-6
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=200005;

int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll ans=0;
    if(n&1)ans^=n,n++;
    if(!(m&1))ans^=m,m--;
    ans^=(((m-n+1)/2)&1);
    printf("%lld\n",ans);
    re 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,c,x,k;
	int cnt=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
    for(int i=0;i<=a;i++)
       for(int j=0;j<=b;j++)
          for(int p=0;p<=c;p++)
             {
             k=i*500+j*100+p*50;
			 if(k==x)
               cnt++;
             if(k>x)
               break;
             }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 256
n,m = list(map(int, input().split()))

problem_list = {}

for i in range(m):
    p, s = list(input().split())
    if p in problem_list.keys():
        if problem_list[p][1] == 1:
            continue
        else:
            if s == "AC":
                problem_list[p][1] += 1
            else:
                problem_list[p][0] += 1
    else:
        if s == "AC":
            problem_list[p] = [0, 1]
        else:
            problem_list[p] = [1, 0]
            
correct = 0
penalty = 0

for v in problem_list.values():
    p, c = v
    if c == 0:
        continue
    correct += c
    penalty += p
    
print(str(correct) + " " + str(penalty))

Measured memory_bytes: 25360