akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int m,n;
  while(cin>>m>>n, m+n){
    vector<bool> f(m, true);
    int p = 0;
    int r = m;
    REP(i,n){
      int cnt = i + 1;
      string tmp;
      string ans;
      cin >> tmp;

      if(r == 1) continue;

      if(cnt % 3 == 0) ans += "Fizz";
      if(cnt % 5 == 0) ans += "Buzz";
      if(ans.size() == 0){
	char buff[256];
	sprintf(buff,"%d",cnt);
	ans = buff;
      }
      if(ans != tmp){
	f[p] = false;
	r--;
      }
      if(r != 1){
	do
	  if(++p == m) p = 0;
	while(!f[p]);
      }
    }

    bool fst = true;
    REP(i,m) if(f[i]){
      if(!fst) cout << " ";
      else fst = false;
      cout << i + 1;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 964
N = int(input())
s = []
for i in range(N) :
    s.append(input())

M = int(input())
t = []
for i in range(M) :
    t.append(input())

s_uni = list(set(s))

count_p = []
count_m = []
_sum = []

for i in range(len(s_uni)) :
    count_p.append(0)
    for j in range(N) :
        if s_uni[i] == s[j] :
            count_p[i] += 1

for i in range(len(s_uni)) :
    count_m.append(0)
    for j in range(len(t)) :
        if s_uni[i] == t[j] :
            count_m[i] += 1

for i in range(len(s_uni)) :
    _sum.append(count_p[i] - count_m[i])

if max(_sum) >= 0 :
    print(max(_sum))
else :
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  long n, k;
  cin >> n >> k;

  long a = n % k;
  cout << min(a, k - a) << endl;
}

Measured memory_bytes: 3592
#coding:utf-8
import re

S = input()
flag = 0
#一文字目がA
if S[0] == 'A':
    flag += 1
#Sの先頭から3文字目と末尾から2文字目の間（両端含む）に大文字のCがちょうど1個
if S[2:len(S)-1].count('C') == 1:
    flag += 1
#以上の A, C を除く S のすべての文字は小文字(大文字は2文字目以降に1つだけ)
if len(re.findall(r'[A-Z]', S[1:])) == 1:
	flag += 1


#条件が全部合えばAC
if flag == 3:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(void){
  int h1,m1,s1,h2,m2,s2;
  while(cin >>h1>>m1>>s1>>h2 >>m2>>s2){
    h1 = h1*3600; h2 = h2*3600;
    m1 = m1*60; m2 = m2*60;
    s1 = h1+s1+m1; s2=h2+m2+s2;
    s2-=s1;
      cout << s2/3600 << " ";
      s2 %= 3600;
      cout << s2/60 << " ";
      s2 %= 60;
      cout << s2 << endl;
   }
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

LL dp[51][5001];
void solve() {
    int n,a;
    cin >> n >> a;
    VI x(n);
    REP(i,0,n) cin >> x[i];
    REP(i,0,n) x[i] -= a;

    dp[0][2500] = 1;
    dp[0][x[0]+2500]++;

    REP(i,1,n) {
        REP(k,0,5001) {
            dp[i][k] = dp[i-1][k];
            if (k - x[i] >= 0 && k - x[i] < 5001) dp[i][k] += dp[i-1][k-x[i]];
        }
    }

    cout << dp[n-1][2500] - 1 << endl;
}

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

Measured memory_bytes: 2176
#include <stdio.h>
#define MAX 1000000001
void mergesort(int *,int ,int );
void merge(int *,int ,int ,int );
int count=0,n,Left[250001],Right[250001];

int main(void){
  int S[500000],i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  mergesort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}
void mergesort(int *S,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(S,left,mid);
    mergesort(S,mid,right);
    merge(S,left,mid,right);
  }
}
void merge(int *S,int left,int mid,int right){
  int n1=mid-left,n2=right-mid,i,j,k;
  for(i=0;i<n1;i++)
    Left[i]=S[left+i];//not include mid
  for(i=0;i<n2;i++)
    Right[i]=S[mid+i];//include mid
  Left[n1]=MAX;
  Right[n2]=MAX;
  for(i=0,j=0,k=left;k<right;k++){
    if(Left[j]>Right[i])S[k]=Right[i++];
    else S[k]=Left[j++];
  }
  count+=right-left;
}


Measured memory_bytes: 5636
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int n,c,e;
int a[100001],b[100001];
int main(){
  c=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
  sort(a,a+n);
  for(int i=0;i<n;i++){
    b[a[i]]++;
  }
  for(int i=1;i<=a[n-1];i++){
    if(b[i]!=0)c++;
    if(b[i]!=0 && b[i]%2==0)e++;
  }
  if(e%2==0)printf("%d\n",c);
  else printf("%d\n",c-1);
  return 0;
}


Measured memory_bytes: 896
N=gets.to_i
list=gets.chomp.split(" ").map(&:to_i);
count=0
n=0
while(n<(N-2))
if((list[n]-list[n+1])*(list[n+1]-list[n+2])>0)
 count=count+1
end
n=n+1
end
print(count)

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

ll dp[101][4][4][4];
bool check(int a,int b,int c,int d){
  if(a*100+b*10+c==123||b*100+c*10+d==123)return false;
  swap(a,b);if(a*100+b*10+c==123||b*100+c*10+d==123)return false;swap(a,b);
  swap(b,c);if(a*100+b*10+c==123||b*100+c*10+d==123)return false;swap(b,c);
  swap(c,d);if(a*100+b*10+c==123||b*100+c*10+d==123)return false;swap(c,d);
  return true;
}
ll f(int idx,int a,int b,int c){
  if(~dp[idx][a][b][c])return dp[idx][a][b][c];
  if(idx==3)return 1;
  ll res=0;
  for(int i=0;i<4;i++)if(check(i,a,b,c))res+=f(idx-1,i,a,b);
  return dp[idx][a][b][c]=res%MOD;
}

signed main(){
  memset(dp,-1,sizeof(dp));
  int n;cin>>n;
  ll ans=0;
  for(int i=0;i<64;i++){
    int a=i%4,b=(i/4)%4,c=(i/16)%4;
    if(check(a,b,c,-1))ans+=f(n,a,b,c);
  }
  cout<<ans%MOD<<endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long dp[51][51];

long long comb(int n, int r) {
    if (dp[n][r] != -1) return dp[n][r];
    if (r == 0) return dp[n][r] = 1;
    if (n == r) return dp[n][r] = 1;
    return dp[n][r] = comb(n - 1, r - 1) + comb(n - 1, r);
}

int main() {

    for (int i = 0; i < 51; i++) {
        for (int j = 0; j < 51; j++) {
            dp[i][j] = -1;
        }
    }

    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] %= 2;
        sum += A[i];
    }
    int rest = N - sum;
    if (P == 0) {
        long long ret = 0;
        for(int i = 0; i <= sum; i+=2) {
            ret += comb(sum, i) * (1LL << rest);
        }
        cout << ret << endl;
    } else {
        long long ret = 0;
        for(int i = 1; i <= sum; i+=2) {
            ret += comb(sum, i) * (1LL << rest);
        }
        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
ll int w[105],v[105];
ll int dp[105][100005];
ll int N,W;
ll int fun(ll int i,ll int B)
{
  if(i>=N)
    return 0;
  if((B+w[i])<=W)
  {
    if(dp[i+1][B+w[i]]==-1)
      dp[i+1][B+w[i]]=fun(i+1,B+w[i]);
    if(dp[i+1][B]==-1)
      dp[i+1][B]=fun(i+1,B);
    dp[i][B]=(v[i]+dp[i+1][B+w[i]])>=(dp[i+1][B])?(v[i]+dp[i+1][B+w[i]]):(dp[i+1][B]);
  }
  else
  {
    if(dp[i+1][B]==-1)
      dp[i+1][B]=fun(i+1,B);
    dp[i][B]=dp[i+1][B];
  }
  return dp[i][B];
}
int main()
{
  cin>>N>>W;
  for(auto i=0;i<N;i++)
  {
    cin>>w[i]>>v[i];
  }
  for(auto i=0;i<100;i++)
  {
    for(auto j=0;j<100005;j++)
      dp[i][j]=-1;
  }
  dp[0][0]=fun(0,0);
  cout<<dp[0][0]<<endl;
  return 0;
}


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

int main() {
    int a, b, c, d;  cin >> a >> b >> c >> d;
    if (abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d)  cout << "Yes" << endl;
    else  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000000;
using namespace std;
vector<pair<long long,long long>>juice;
int gcd(int a,int b){
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
long long stair[100009];
long long memo = 1;
long long DP(long long a) {
	stair[0] = memo;
	stair[1] = memo;
	if (a <= 1) {
		return memo;
	}
	else {
		return stair[a] = DP(a - 1) + DP(a - 2);
	}
}
string S;
int main() {
	int a = 0, b = 0, c = 0;
	cin >> a >> b >> c;
	cout << a + b + c - max(a, max(b, c)) << endl;
		return 0;
}

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

#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main(int argc, char const* argv[])
{
   int tot, a, p;
   cin >> a >> p;
   tot = p + 3*a;
   cout << tot/2 << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a <= 8 && b <= 8) 
			System.out.println("Yay!");
		else
			System.out.println(":(");
	}
}

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

void solve()
{
	char a;
	cin>>a;
	if(a>='A'&&a<='Z')
		cout<<"A"<<endl;
	else
		cout<<"a"<<endl;
}

int main()
{
	ll t  = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 
vector<int> h[100001];
int used[100001]={};


 
signed main(){
    int n,m;
    cin>>n>>m;
    
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        
   
        h[u-1].push_back(v-1);
        h[v-1].push_back(u-1);
    }
    int t=0,count,t0,c[3]={};
    queue<int> hasi;
    
    while(true){
        while(t<n&&used[t]!=0)t++;
        if(t==n)break;
        count=0;
        hasi.push(t);
        used[t]=1;
        while(!hasi.empty()){
            t0=hasi.front();
            hasi.pop();
            for(int i=0;i<h[t0].size();i++){
                if(used[h[t0][i]]==used[t0])count=1;
                if(used[h[t0][i]]==0){
                    used[h[t0][i]]=-1*used[t0];
                    hasi.push(h[t0][i]);
                }
                
            }
           
        }
         if(t==t0)c[2]++;
            else c[count]++;


    }
    cout<<(c[0]+c[1])*(c[0]+c[1])+c[0]*c[0]+2*c[2]*n-c[2]*c[2];
    return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
const int inf = 100000000;

int main(){
  int m = inf;
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i=0; i<N; i++) cin >> X[i];
  
  for (int j=0; j<100; j++){
    int cost = 0;
    for (int i=0; i<N; i++){
      cost += (X[i]-j)*(X[i]-j);
    }
    m = min(cost, m);
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int k;
	cin >> k;
	if (k % 2 == 0 || k % 5 == 0) {
		cout << -1 << endl;
		return 0;
	}
	int x = 7;
	int ans = 1;
	while (true) {
		if (x % k == 0) {
			cout << ans << endl;
			break;
		}
		x *= 10;
		x += 7;
		ans++;
		x %= k;
		if (ans > 1000001) {
			cout << -1 << endl;
			break;
		}
	}

}


Measured memory_bytes: 3616
def main():
    (N, K) = map(int, input().split())
    H = [int(x) for x in input().split()]
    dp = [0] * N
    for i in range(1, N):
        ret = 10 ** 18
        for j in range(K):
            if i - 1 - j < 0:
                break
            ret = min(ret, dp[i-1-j] + abs(H[i] - H[i-1-j]))
        dp[i] = ret
    print(dp[-1])


if __name__ == '__main__':
    main()


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

max_left = 1
min_right = n

for i in range(m):
    left, right = map(int, input().split())
    max_left = max(max_left, left)
    min_right = min(min_right, right)

print(max(min_right - max_left + 1, 0))


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def get_sum(a, b, c):
    """ 等差数列の和：(初項a, 末項b, 項数c) """
    return (a+b) * c // 2

N, K = MAP()
A = LIST()

B = [0] * N
for i in range(N):
    B[i] = get_sum(1, A[i], A[i]) / A[i]

acc = [0] + list(accumulate(B))
ans = 0
for i in range(N-K+1):
    ans = max(ans, acc[i+K] - acc[i])
print(ans)


Measured memory_bytes: 26176
#include <iostream>
#include <string>

using namespace std;
#define ll long long

void test_case()
{
	int cons = 0;
	string s;
	cin >> s;
	if (s.find('R') != string::npos) cons = 1;
	if (s.find("RR") != string::npos) cons = 2;
	if (s.find("RRR") != string::npos) cons = 3;
	cout << cons;
}
int main()
{
	test_case();
	return 0;
}


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

signed main(){
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  const int INF=1e9+7;
  int N=1e7;
  std::vector<int> v(N);
  v[0]=1;
  for(int i=1;i<N+1;i++){
    v[i]=v[i-1]*(i);
    v[i]%=INF;
  }
  int ans=0;
  int a,b,c,d,e;
  for(int i=0;A+i+1<=H&&B+i+1<=W;i++){
    a=v[H-A-1+B];
    c=1;
    d=INF-2;
    e=v[B+i];
    while(d>0){
      if(d&1==1)c=c*e;
      c%=INF;
      e*=e;
      e%=INF;
      d>>=1;
    }
    a*=c;
    a%=INF;
    c=1;
    d=INF-2;
    e=v[H-A-1-i];
    while(d>0){
      if(d&1==1)c=c*e;
      c%=INF;
      e*=e;
      e%=INF;
      d>>=1;
    }
    a*=c;
    a%=INF;
    b=v[W-B-1+A];
    c=1;
    d=INF-2;
    e=v[A+i];
    while(d>0){
      if(d&1==1)c=c*e;
      c%=INF;
      e*=e;
      e%=INF;
      d>>=1;
    }
    b*=c;
    b%=INF;
    c=1;
    d=INF-2;
    e=v[W-B-1-i];
    while(d>0){
      if(d&1==1)c=c*e;
      c%=INF;
      e*=e;
      e%=INF;
      d>>=1;
    }
    b*=c;
    b%=INF;
    int k=1;
    a=max(a,k);
    b=max(b,k);
    ans+=a*b;
    ans%=INF;
    //cout<<a<<" "<<b<<" "<<ans<<endl;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int64 ans;
int N,L,cnt[30];
char s[MAXN];
void Solve() {
	scanf("%s",s + 1);
	N = strlen(s + 1);
	ans = 1 + 1LL * N * (N - 1) / 2;
	for(int i = 1 ; i <= N ; ++i) {
		cnt[s[i] - 'a']++;
	}
	for(int i = 0 ; i <= 25 ; ++i) {
		ans -= 1LL * cnt[i] * (cnt[i] - 1) / 2;
	}
	out(ans);enter;
}

int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int h[]=new int[n];
    int count=0;
    for (int i=0;i<n;i++) {
      h[i]=sc.nextInt();
      if (h[i]>=k) {
        count++;
      }
    }

    System.out.println(count);

  }
}


Measured memory_bytes: 51168
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto S = readln.chomp;
    auto N = S.length;
    int k = int.max;
    char last;
    foreach (i, c; S) {
        if (c != last) {
            if (i) {
                k = min(k, max(i, N-i).to!int);
            }
            last = c;
        }
    }
    writeln(k == int.max ? N : k);
}

Measured memory_bytes: 2760
// atcoder/abc155/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

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

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << (set<int>({a, b, c}).size() == 2 ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define DEC(x) fixed<<setprecision(x)
#define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);
const long long INF=2e18;

template<typename T,typename T1>void amax(T &a,T1 b){if(b>a)a=b;}
template<typename T,typename T1>void amin(T &a,T1 b){if(b<a)a=b;}

ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

// #define _NCR_

int TLE_TERROR()
{
 	ll n,ans=0,z;
 	cin>>n;
 	for(ll i=1;i<=n;i++)
 	{
 		z=n/i;
 		if(n%i==0)
 			z--;
 		ans+=z;
 	}
 	cout<<ans;
 	return 0;   
}

int main()
{
    FAST
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll int TESTS=1;
    // cin>>TESTS;
    #ifdef _NCR_
        initialvalues();
    #endif
    while(TESTS--)
        TLE_TERROR();
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin>>n;
  vector<ll>A(n);
  rep(i,n) cin>>A[i];
  map<ll, ll>mp;
  rep(i,n) mp[A[i]]++;
  ll ans = 0;
  for(auto p:mp){
    ans += p.second*(p.second-1)/2;
  }
  rep(i,n){
    if (mp[A[i]] == 1) cout << ans << endl;
    else{
      cout << ans-(mp[A[i]]-1) << endl;
    }
  }

}

Measured memory_bytes: 12744
N = int(input())
A = list(map(int,input().split()))

A.sort()

B = [0 for _ in range(N)]
b = 0
for i in range(N):
    b += A[i]
    B[i] = b

ans = 1
for i in range(N-1):
    if 2*B[i]>=A[i+1]:
        ans += 1
    else:
        ans = 1
        
print(ans)


Measured memory_bytes: 14316
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, A[100000];
vector<int> v[100001];

// 1 ずつ増加する列 3 つに分ける
// 列は空でもよい

ll ans;

signed main(){
	cin >> N;
	rep(i, N){
		cin >> A[i];
		v[A[i]].pb(i);
	}

	if(v[0].size() == 1) ans = 3;
	if(v[0].size() == 2) ans = 6;
	if(v[0].size() == 3) ans = 6;

	int tmp = 3;
	rep(i, N+1){
		if(tmp < v[i].size()){
			cout << 0 << endl;
			return 0;
		}
		tmp = v[i].size();
		int k = 0;
		while(v[i].size() < 3){
			v[i].pb(1000000*(3-k)+i);
			k++;
		}
		sort(v[i].begin(), v[i].end());
	}

	rep(i, N){ // i -> i+1 の場合の数を求める
		for(int j=2; j>=0; j--){
			if(upper_bound(all(v[i+1]), v[i][j]) == v[i+1].end()){
				cout << 0 << endl;
				return 0;
			}
			ll tmp = v[i+1].end() - upper_bound(all(v[i+1]), v[i][j]) - (2-j);
			//cout << tmp << endl;
			ans *= max(tmp, 0LL);
		}
		if(v[i].end()-lower_bound(all(v[i]), 1000000) + 2 == v[i+1].end()-lower_bound(all(v[i+1]), 1000000)) ans /= 2;
		if(v[i].end()-lower_bound(all(v[i]), 1000000) + 3 == v[i+1].end()-lower_bound(all(v[i+1]), 1000000)) ans /= 6;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6520
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int N;
    static long A;
    static long B;
    static long C;
    static int[] map;


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


        A = scanner.nextInt();
        B =scanner.nextInt();
        C = scanner.nextInt();
        long X = scanner.nextInt();
        long Y  =scanner.nextInt();
        long cost;
        long ans = 1938470973;

        for (int i = 0; i <= 2*(X + Y); i++) {
            long x = X - i;
            long y = Y - i;
            cost = C * 2 * i;

            cost += Math.max(x, 0) * A;
            cost += Math.max(y, 0) * B;
            ans = Math.min(ans, cost);
        }

        System.out.println(ans);

    }
}



Measured memory_bytes: 23124
P,Q,R=map(int,input().split())
a=P+Q
b=Q+R
c=R+P
if a<b:
    if a<c:
        print(a)
    elif c<a:
        print(c)
    else:
        print(c)
elif b<a:
    if b<c:
        print(b)
    elif c<b:
        print(c)
    else:
        print(c)
else:
    if a<c:
        print(a)
    elif c<a:
        print(c)
    else:
        print(c)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){
    long X,N;
    std::cin >> X >> N;
    std::vector<long> p(100);
    for(long i=0; i<N; i++){
        std::cin >> p[i];
    }

    long temp=114514;
    long result=114514;
    for(long i=200; i>=0; i--){
        for(long j=0; j<N; j++){
            if(i==p[j]){
                break;
            }
            if(j==N-1){
                if(temp>=abs(X-i)){
                    temp = abs(X-i);
                    result=i;
                }
            }
        }
    }
    if(N==0){
        result=X;
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) int((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl '\n'
#define ff first
#define ss second
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T add(T x, T y, T m) { return ((x % m)  + (y % m)) % m;}
template<typename T>   T mul(T x, T y, T m) { return ((x % m) * (long long)(y % m)) % m;}
template<typename T>   T sub(T x, T y, T m) { return add(x, -y + m);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}

int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

struct pair_hash{
	template<class T1, class T2>
	size_t operator() (const pair<T1, T2> &p) const {
		auto h1 = hash<T1>{}(p.first);
		auto h2 = hash<T2>{}(p.second);
		return h1 ^ h2;
	}
};




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

	string s;
	cin >> s;

	cout << (s.find('7') != string::npos ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
const long long INF = 1LL << 60;

int n;
int main(){
  cin >> n;
  int alphabet[n][26];
  string s[n];
  rep(j,n){
    rep(i,26) alphabet[j][i] = 0;
  }
  //各文字列にどれだけの数のアルファベットが含まれているかチェック
  rep(j,n){
    cin >> s[j];
    rep(i,s[j].length()) alphabet[j][(s[j][i])-97]++;
  }

  vector<char> common;
  rep(i,26){
    int m = 10000;
    rep(j,n){
      if(m > alphabet[j][i]) m = alphabet[j][i];
    }
    char tmp = 'a' + i;
    rep(k,m) common.push_back(tmp);
  }
  if(common.size() == 0) cout << " " << endl;
  else{
    rep(i,common.size()) cout << common[i];
    cout << endl;
  }
  return 0;
}


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

int main() {
  int n, ans=0;
  cin >> n;
  int a[n];

  rep(i, n)
  {
    cin >> a[i];
  }

  int i = 0;
  while(true)
  {
    ans++;

    if(ans > n)
      break;

    if(a[i] == 2)
    {
      cout << ans << endl;
      break;
    }

    i = a[i]-1;
  }

  if(ans > n)
    cout << -1 << endl;

}


Measured memory_bytes: 4008
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int a, b, t;
    cin >> a >> b >> t;
    cout << t / a * b << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
N = int(input())
Nlist = list(map(int, input().split()))
total = 1

if Nlist.count(0)>=1:
    total = 0
    print(total)
    sys.exit()


for i in range(N):
    total = total*Nlist[i]
    if total > 1000000000000000000:
        total = -1
        break

print(total)


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


#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);


signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n,m;
        cin>>m>>n;
        int a[n],s=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            s += a[i];
        }
        if(s>m)
            cout<<-1;
        else cout<<m-s;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


Measured memory_bytes: 3848
#include <stdio.h>

int main(void){
    int w,h;
    while(1){
        scanf("%d %d",&h,&w);
        if(w==0 && h == 0){
            break;
        }
        int i,j;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2032
#include <iostream>
#include <array>
#include <string>

using namespace std;

constexpr size_t SIZE = 8;
constexpr size_t PATTERN = 7;

const array<string, PATTERN> pattern = {
    "1100000011", "1000000010000000100000001", "1111",
    "1000000110000001", "11000000011",
    "100000001100000001", "110000011"};

string surface;

char match();

int main()
{
    while (true) {
        surface = "";

        for (size_t row = 0; row < SIZE; row++) {
            string buf;
            cin >> buf;

            surface += buf;
        }

        cout << match() << endl;

        cin.ignore(2);
        if (cin.eof()) {
            break;
        }
    }

    return 0;
}

char match()
{
    for (size_t i = 0; i < PATTERN; i++) {
        if (surface.find(pattern.at(i), 0) != string::npos) {
            return static_cast<char>('A' + i);
        }
    }

    cout << "BUG!" << endl;
    return 'X';
}

Measured memory_bytes: 1192
N, A = map(int, input().split(' '))

X = map(int, input().split(' '))
X = [x - A for x in X]

from collections import defaultdict
counter = defaultdict(int)
counter[0] = 1

for x in X:
	copy = dict(counter)
	for d,c in copy.items():
		counter[d+x] += c

print(counter[0]-1)

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct unionFind{

    vector<int> par, rank;

    void init(int n){
        par.resize(n);
        rank.resize(n, 0);
        for(int i = 0 ; i < n ; ++i){
            par[i] = i;
        }
        return;
    }

    int root(int x){
        if(par[x] == x){
            return x;
        }else{
            par[x] = root(par[x]);
            return par[x];
        }
    }

    bool unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return false;
        }
        par[ry] = rx;
        return true;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

};

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

    int n, q;
    while(cin >> n >> q, n){
        vector<int> p(n);
        REP(i, 1, n){
            cin >> p[i];
            --p[i];
        }

        vector< pair<char, int> > v;
        vector<bool> marked(n);
        marked[0] = true;
        rep(i, q){
            char c;
            int k;
            cin >> c >> k;
            --k;
            if(c == 'M'){
                if(!marked[k]){
                    v.push_back({c, k});
                    marked[k] = true;
                }
            }else{
                v.push_back({c, k});
            }
        }
        reverse(v.begin(), v.end());

        unionFind uf;
        uf.init(n);
        rep(i, n){
            if(!marked[i]){
                uf.unite(p[i], i);
            }
        }

        lint ans = 0;
        rep(i, v.size()){
            if(v[i].first == 'Q'){
                ans += (lint)(uf.root(v[i].second) + 1);
            }else{
                uf.unite(p[v[i].second], v[i].second);
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 5040
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// AGC034-B, 1100, 
	string s; cin >> s;
	int n = s.size();
	int i = 0;
	ll ans = 0;
	int anum = 0;
	bool streak = false;
	while (i < n) {
		if (!streak) {
			if (s.find("A", i) == i) {
				streak = true;
				anum = 1;
			}
			i++;
			continue;
		}
		if (s.find("A", i) == i) {
			anum++;
			i++;
		}
		else if (s.find("BC", i) == i) {
			ans += ll(anum);
			i += 2;
		}
		else {
			streak = false;
			anum = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3732
N = int(input())
S = list(input())

num2alpha = lambda c:chr(c+65)
alpha2num = lambda c:ord(c) - ord('A')

ans = ['A']*len(S)
for i in range(len(S)):
    tmp = alpha2num(S[i])
    tmp += N
    tmp %= 26
    c = num2alpha(tmp)
    ans[i] = c

print(''.join(ans))


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner Input = new Scanner(System.in);
        String S = Input.next();
        for (int I = 0; I < S.length(); I += 2) {
            System.out.print(S.charAt(I) + "");
        }

    }
}


Measured memory_bytes: 33484
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}
func judgean(x []int, y []int, l int) bool {
	for i := 0; i < len(x); i++ {
		// fmt.Println(l, x[i], y[i], (l>>uint64(x[i]-1))&1)
		if !((l>>uint64(x[i]-1))&1 == y[i]) {
			return false
		}
	}
	return true
}
func judge(x [][]int, y [][]int, l int) int {
	count := 0
	for i := 0; i < len(x); i++ {
		if l>>uint64(i)&1 == 1 {
			count++
		}
		if (l>>uint64(i)&1 == 1) && !judgean(x[i], y[i], l) {
			return 0
		}
	}
	return count
}

func main() {
	sc.Split(bufio.ScanWords)
	x := [][]int{}
	y := [][]int{}
	n, _ := strconv.Atoi(read())
	ans := 0

	for i := 0; i < n; i++ {
		xtmp := []int{}
		ytmp := []int{}
		atmp, _ := strconv.Atoi(read())
		// fmt.Println(atmp)
		for j := 0; j < atmp; j++ {
			xitem, _ := strconv.Atoi(read())
			yitem, _ := strconv.Atoi(read())
			xtmp = append(xtmp, xitem)
			ytmp = append(ytmp, yitem)
		}
		x = append(x, xtmp)
		y = append(y, ytmp)
	}
	for i := 0; i < 2<<uint64(n-1); i++ {
		count := 0
		if count = judge(x, y, i); count == 0 {
			continue
		}

		if ans < count {
			ans = count
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
 
int cal(ll z)
{
    int cnt;
    for(cnt = 0; z != 0; cnt++) z /= 10;
    return cnt;
}

int main()
{
    ll n;
    cin >> n;
    int ans = INF;
    for(ll i = 1; i*i <= n; i++){
        if(n%i == 0){
            int a = cal(i),b = cal(n/i);
            ans = min(ans,max(a,b));
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define si(n) scanf("%d",&n)
#define MAX 2003

int n,k,cnt[MAX][MAX];

int getSum(int x1,int y1,int x2,int y2)
{
    int xx= cnt[x2][y2]-cnt[x2][y1]-cnt[x1][y2]+cnt[x1][y1];
    return xx;
}

int solve(int x,int y)
{
    if(x<=k){
        return getSum(x,y,x+k,k)+getSum(0,0,x,y)
            + getSum(x+k,0,2*k,y);
    }
    return getSum(0,y,x-k,k)+getSum(x-k,0,x,y)
        + getSum(x,y,2*k,k);
}

int main()
{
   // freopen("input.txt","r",stdin);
    int i,j;
    si(n);si(k);
    for(i=1;i<=n;i++){
        int x,y;
        char ch;
        si(x);si(y);scanf(" %c",&ch);
        if(ch=='W')x+=k;
        x%=2*k;y%=2*k;
        if(y>=k){
            x+=k;y-=k;
        }
        x%=2*k;
        cnt[x+1][y+1]++;
        //cout<<x+1<<' '<<y+1<<' '<<cnt[x+1][y+1]<<endl;
    }
    //exit(0);
    for(i=1;i<=2*k;i++){
        for(j=1;j<=k;j++){
            cnt[i][j]+=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1];
        }
    }

   // exit(0);
    int ans=0;
    for(i=0;i<2*k;i++){
        for(j=0;j<k;j++){
            int x=solve(i,j);
            //cout<<i<<' '<<j<<' '<<x<<endl;
            ans=max(ans,x);
        }
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s; cin >> s;
    ll k; cin >> k;
    ll ans = 0;
    set<char> c;
    int n = s.size();
    rep(i,n){
        c.insert(s[i]);
    }
    if(c.size() == 1){
        cout << n * k / 2 << endl;
        return 0;
    }

    int x = 0;
    rep(i,n-1){
        if(s[i] != s[i+1]){
            x = i+1;
            break;
        }
    }
    string t,l,r;
    srep(i,x,n){
        t += s[i];
        r += s[i];
    }
    rep(i,x){
        t += s[i];
        l += s[i];
    }
    rep(i,n){
        if(i == n - 1){
            ;
        }else{
            if(t[i] == t[i+1]){
                ans += k-1;
                i++;
            }
        }
    }
    rep(i,l.size()){
        if(i == n - 1){
            ;
        }else{
            if(l[i] == l[i+1]){
                ans++;
                i++;
            }
        }
    }
    rep(i,r.size()){
        if(i == n - 1){
            ;
        }else{
            if(r[i] == r[i+1]){
                ans++;
                i++;
            }
        }
    }

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


Measured memory_bytes: 256
import copy

n = input()
m = copy.copy(n)
ans = 0

for x in range(len(n)):
    for l in range(len(n)):
            mm = m[x:len(n)-l]
            if mm.count("A") + mm.count("C") + mm.count("G")+ mm.count("T") == len(mm):
                ans = max(ans, len(mm))

print(ans)

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

int main() {
    

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    int d = a - b;
    
    if(c > d) {
        cout << c - d << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    X,K,D = map(int, input().split())

    X = abs(X)
    if X//D > K:
        print(X-K*D)
        return
    
    K -= X//D
    X %= D

    if K%2 == 0:
        print(X)
    else:
        print(abs(X-D))

main()


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int>> vec;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		vec.pb({x,y});
	}
	sort(all(vec));
	int mxpos = -vec[0].ff-vec[0].ss, mxneg = -vec[0].ff+vec[0].ss;
	int ans = 0;
	for(int i = 1; i < n; i++)
	{
		int res = max(vec[i].ff+vec[i].ss+mxpos,vec[i].ff-vec[i].ss+mxneg);
		ans = max(ans, res);
		mxpos = max(mxpos, -vec[i].ff-vec[i].ss);
		mxneg = max(mxneg, -vec[i].ff+vec[i].ss);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5256
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int [][] List = new int[N][3];
        int [] DP = new int[3];
        for(int i=0;i<N;i++){
            List[i][0] = sc.nextInt();
            List[i][1] = sc.nextInt();
            List[i][2] = sc.nextInt();
        }
        for(int i=0;i<3;i++) DP[i]=List[0][i];
        for(int i=1;i<N;i++){
            int [] DP2 = new int[3];
            for(int j=0;j<3;j++) DP2[j] = DP[j];
            for(int j=0;j<3;j++){
                int DP_max = 0;
                for(int k = 0;k<3;k++) if(j!=k&&DP[k]>DP_max) DP_max = DP[k];
                DP2[j]=DP_max+List[i][j];
            }
            for(int j=0;j<3;j++) DP[j]=DP2[j];
        }
        int max = 0;
        for(int i=0;i<3;i++) if(max<DP[i]) max = DP[i];
        System.out.println(max);
    }
}

Measured memory_bytes: 96264
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;

const double EPS=1e-9;

int main()
{
	//for(char buf[1024];fgets(buf,1024,stdin),buf[0]!='-';){
	//	double x; sscanf(buf,"%lf",&x);
	for(double x;scanf("%lf",&x),x>=0;){
		x/=256;
		
		if(x>=1){
			puts("NA");
			continue;
		}
		string s(12,'0');
		for(int i=0;i<12;i++){
			x*=2;
			if(x>=1){
				s[i]++;
				x-=1;
			}
		}
		if(x!=0){
			puts("NA");
			continue;
		}
		
		for(int i=0;i<8;i++)
			putchar(s[i]);
		putchar('.');
		for(int i=0;i<4;i++)
			putchar(s[8+i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n;
    l(i,0,n)
    {
        cin>>a;
        v.pb(a);
        u.pb(a);

    }
    hi(u);
    l(i,0,n)
    {
     if(v[i]!=u[0])
     {
         cout<<u[0]<<endl;

     }
     else
     {
         cout<<u[1]<<endl;
     }



            }




}


Measured memory_bytes: 6608
n = int(input())
nums = list(map(int, input().split()))
answers = list()

while True:
    i = len(nums) - 1
    while i  >= 0:
        num = nums[i]
        if i + 1 == num:
            answers.insert(0, nums.pop(i))
            break
        i -= 1
    else:
        break
if len(nums) == 0:
    for num in answers:
        print(num)
else:
    print(-1)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<int> P(A), Q(B), R(C);
    REP(i, 0, A) cin >> P[i];
    REP(i, 0, B) cin >> Q[i];
    REP(i, 0, C) cin >> R[i];

    sort(ALL(P), greater<int>());
    sort(ALL(Q), greater<int>());

    R.insert(R.end(), P.begin(), P.begin() + X);
    R.insert(R.end(), Q.begin(), Q.begin() + Y);
    sort(ALL(R), greater<int>());
    cout << accumulate(R.begin(), R.begin() + X + Y, 0LL) << endl;;
    return 0;
}

Measured memory_bytes: 2808