akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

const int MAX_N = 105;
const int MAX_W = 100005;

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n, w; cin >> n >> w;
    ll dp[MAX_N][MAX_W];

    rep(i, n){
        int _w, _v; cin >> _w >> _v;
        rep(j, w + 1){
            if(0 <= j - _w)
                dp[i + 1][j] = max(dp[i][j],
                                   dp[i][j - _w] + _v);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }

    cout << dp[n][w] << endl;

return 0;
}

Measured memory_bytes: 81792
using System;
class flame{
    public static void Main(){
        while(true){
            String[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            if(a+b==0){
                break;
            }
            else{
                for(int i=0; i<a; i++){
                    for(int j=0; j<b; j++){
                        if(i==0 || i==a-1 || j==0 || j==b-1){
                            Console.Write("#");
                        }
                        else{
                            Console.Write(".");
                        }
                    }
                    Console.WriteLine("");
                }
            }
            Console.WriteLine("");
        }
    }
}


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

using namespace std;

using ll = long long;

const int N = 2e5 + 5;
const int M = 1e6 + 5;
int n;
int a[N], cnt[M];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		cnt[a[i]]++;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		auto divi = [&](int i) {
			for (ll j = 1; j * j <= a[i]; j++) {
				if (a[i] % j == 0) {
					if (cnt[j] >= 1 + (a[i] == j)) return false;
					if (cnt[a[i] / j] >= 1 + (a[i] / j == a[i])) return false;
				}
			}
			return true;
		};
		ans += divi(i);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 8412
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#include<deque>
#include<utility>
#define INF 1000000000
#define fi first
#define se second
#define N 505
#define P 1000000007
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
char mp[N][N];
int vis[N],vis2[N];
int main()
{
    int n,m=0,flag=0,i,j,ans=INF,cnt;
    cin>>n;
    for(i=1;i<=n;i++)
        scanf("%s",mp[i]+1);
    for(i=1;i<=n;i++)
    {
        //cnt=0;
        for(j=1;j<=n;j++)
        {
            if(mp[i][j]=='.')
            {
                if(!vis[j])
                    m++,vis[j]=1;
                //cnt++;
            }
            else
                flag=1,vis2[j]=1;
        }
        //ans=min(ans,cnt);
    }
    for(i=1;i<=n;i++)
    {
        cnt=0;
        for(j=1;j<=n;j++)
        {
            if(mp[i][j]=='.')
            {
                cnt++;
            }
        }
        ans=min(ans,cnt+!vis2[i]);
    }
    ans+=m;
    if(flag==0)
        printf("-1\n");
    else cout<<ans<<endl;
    return 0;
}
// davidlee1999WTK 2017/
// ios::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:102400000,102400000") compiler c++,not g++
/*
4
...#
#.##
....
....
*/


Measured memory_bytes: 512
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#ans = [0]*n
h1, m1, h2, m2, k = map(int, input().split())

h = h2 - h1

if m1 > m2 :
    m = 60 - (m1 - m2)
    h -= 1
else:
    m = m2 - m1

ans = 60 * h + m - k
print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<ll> sum(n, 0);
  REP(i, k){
    ll d;
    cin >> d;
    REP(j, d){
      ll a;
      cin >> a;
      sum[--a]++;
    }
  }
  ll ans = 0;
  REP(i, n) if(sum[i] == 0) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = (s); i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N, T, ans = 0;
    cin >> N >> T;

    vector<int> t(N);
    REP(i, N) {
        cin >> t[i];
    }

    RREP(i, 1, N) {
        if (t[i] - t[i-1] < T) {
            ans += t[i] - t[i-1];
        } else {
            ans += T;
        }
        // cout << ans << endl;
        
    }

    ans += T;

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

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
bool is753(int N){
    bool a7 = 0;
    bool a5 = 0;
    bool a3 = 0;
    while(N){
        int a = N % 10;
        if(a==7){
            a7 = 1;
        }else if(a==5){
            a5 = 1;
        }else if(a==3){
            a3 = 1;
        }else{
            return 0;
        }
        N /= 10;
    }
    if(a7 && a5 && a3) return 1;
    return 0;
}

int main(){
    int n;
    cin >> n;
    int ans = 0;
    if(n<500000000){
        for(int i=1; i<=n; i++){
            ans += is753(i);
        }
    }else{
        ans += 14384;
        for(int i=500000000; i<=n; i++){
            ans += is753(i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <cstdio>
#define scanf __builtin_scanf
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

vector<int> g[100010];
int c[100010], d[100010], s[100010], x;
long res;

void dfs(int v, int p)
{
    s[v]=c[x++];
    for(auto& u: g[v]) {
        if (u==p) continue;
        dfs(u, v);
        res+=min(s[u], s[v]);
    }
}

int main()
{
    int n; scanf("%d", &n);
    for(int i=0; i+1<n; ++i) {
        int a, b; scanf("%d%d", &a, &b);
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        d[a]++;
        d[b]++;
    }
    for(int i=0; i<n; ++i) scanf("%d", c+i);
    sort(c, c+n);
    reverse(c, c+n);

    int k=max_element(d, d+n)-d;
    dfs(k, -1);
    printf("%ld\n", res);
    for(int i=0; i<n; ++i) printf("%d%c", s[i], i==n-1 ? '\n' : ' ');
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
//B - Counting Roads
int main() {
  int n, m;
  cin >> n >> m;
  
  int a = 0, b= 0;
  vector<int> nrods(n);
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    nrods.at(a-1) ++;
    nrods.at(b-1) ++;
  }
  for (int i = 0; i < nrods.size(); i++){
    cout << nrods.at(i) << endl;
  }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int a,b;
    string op;
    cin >> a >> op >> b;
    if(op=="+")cout<<a+b;else cout <<a-b;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

func abs(result int) int {
	if result < 0 {
		return -result
	}
	return result
}

func routine(r io.Reader, w io.Writer) {
	var N int
	fmt.Fscanf(r, "%d\n", &N)
	a := make([]int, N+2)
	a[0] = 0
	for i := 1; i <= N; i++ {
		fmt.Fscanf(r, "%d", &a[i])
	}
	a[N+1] = 0

	sum := 0
	for i := 1; i <= N+1; i++ {

		sum += abs(a[i-1] - a[i])
	}

	for ignoreI := 1; ignoreI <= N; ignoreI++ {
		ans := sum - abs(a[ignoreI-1]-a[ignoreI]) - abs(a[ignoreI]-a[ignoreI+1]) + abs(a[ignoreI-1]-a[ignoreI+1])
		fmt.Fprintf(w, "%v\n", ans)
	}
}

func main() {
	routine(os.Stdin, os.Stdout)
}


Measured memory_bytes: 6528
def cul(x,X):
    dic={0:1}
    for i in range(len(x)):
        tmp={}
        for j in dic:
            tmp[j+x[i]]=1
            tmp[j-x[i]]=1
        dic=tmp
    if X in dic: return True
    else: return False

S=input()
s=list(S.split("T"))
X,Y=map(int,input().split())
x,y=[len(i) for i in s[::2]],[len(i) for i in s[1::2]]
if S[0]=="F": X=abs(X-x.pop(0))
Y=abs(Y)

x.sort(reverse=True)
y.sort(reverse=True)

print("Yes" if cul(x,X) and cul(y,Y) else "No")

Measured memory_bytes: 4000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1, };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1, };

int d[9][9];
vector<P> solve_pos(int t, int x, int y)
{
	vector<P> res;
	res.push_back(P(x, y));
	if (d[y][x])
		return res;

	for (int i = 0; i < 8; ++i)
	{
		vector<P> p;
		int tx, ty;
		tx = x + dx[i];
		ty = y + dy[i];
		while (true)
		{
			if (d[ty][tx] == -t)
				p.push_back(P(tx, ty));
			else
			{
				if (d[ty][tx] == t)
				{
					for (int j = 0; j < p.size(); ++j)
						res.push_back(p[j]);
				}
				p.clear();
				break;
			}
			if (d[ty][tx] != -t)
				break;

			tx += dx[i];
			ty += dy[i];
		}
	}
	unique(res.begin(), res.end());
	return res;
}
int main()
{
	for (int i = 1; i <= 8; ++i)
	{
		char buf[16];
		scanf("%s", buf);
		for (int j = 1; j <= 8; ++j)
			if (buf[j-1] == 'o')
				d[i][j] = 1;
			else if (buf[j-1] == 'x')
				d[i][j] = -1;
			else
				d[i][j] = 0;
	}

	int turn = 1;
	for (int pass = 0; pass != 2; turn *= -1)
	{
		vector<P> m;
		m.push_back(P(-100000, -10000));
		if (turn == 1)
		{
			for (int i = 1; i <= 8; ++i)
			{
				for (int j = 1; j <= 8; ++j)
				{
					vector<P> r = solve_pos(turn, j, i);
					if (r.size() > m.size())
						m = r;
				}
			}
		}
		else
		{
			for (int i = 8; i >= 1; --i)
			{
				for (int j = 8; j >= 1; --j)
				{
					vector<P> r = solve_pos(turn, j, i);
					if (r.size() > m.size())
						m = r;
				}
			}
		}

		if (m.size() > 1)
		{
			for (int i = 0; i < m.size(); ++i)
				d[m[i].second][m[i].first] = turn;
			pass = 0;
		}
		else
			++pass;
	}

	for (int i = 1; i <= 8; ++i)
	{
		for (int j = 1; j <= 8; ++j)
			if (d[i][j] == 1)
				putchar('o');
			else if (d[i][j] == -1)
				putchar('x');
			else
				putchar('.');
			putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 0
N,H=map(int,input().split())

d=[]
for _ in range(N):
    d.append(list(map(int,input().split())))

d.sort(key=lambda x:x[0],reverse=True)
a = d[0][0]

d.sort(key=lambda x:x[1],reverse=True)

i=0
dam=0
b_damage=[]

while d[i][1]>a:
    dam+=d[i][1]
    b_damage.append(dam)
    i+=1
    if i==N:
        break

r = H//a + 1
l = 0

def damage(k):
    if k<len(b_damage)+1:
        return b_damage[k-1]
    elif len(b_damage)==0:
        return a*k
    else:
        l=k-len(b_damage)
        return b_damage[-1]+a*l


while r-l!=1:
    mid=(r+l)//2
    dam = damage(mid)
    if dam >= H:
        r=mid
    else:
        l=mid
print(r)




Measured memory_bytes: 73816
#include<iostream>
#include<string>
#include<algorithm>
#include<unordered_set>
#include<vector>
#include<math.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2;
}

Measured memory_bytes: 256
l,r=map(int,input().split())
m=l//2019
l-=m*2019
r-=m*2019
if r>=2019:
    print(0)
    exit()
ans=2018
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min(ans,i*j%2019)
print(ans)

Measured memory_bytes: 9120
#include <iostream>

long long beat_the_monster(long long h)
{
	if (h == 1LL)
	{
		return h;
	}
	return 2 * beat_the_monster(h / 2) + 1;
}

int main()
{
	using std::cin;
	using std::cout;
	using std::endl;
	cin.sync_with_stdio(false);
	cin.tie(nullptr);
	long long h;
	cin >> h;
	cout << beat_the_monster(h) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,dx[]={1,0,-1,0},dy[]={0,1,0,-1},e,s;
char d;
struct F{int x,y,xx,yy,w;}f[20010];
map<pi,int> M,N;
stack<int> S;

int main(){
	while(cin>>n&&n){
		rep(i,n)f[i].w=0;
		M.clear(),N.clear();
		rep(i,n)cin>>f[i].x>>f[i].y>>d,
		f[i].xx=f[i].x+dx[d=='y'],f[i].yy=f[i].y+dy[d=='y'],
		M[pi(f[i].x,f[i].y)]=M[pi(f[i].xx,f[i].yy)]=i,
		N[pi(f[i].x,f[i].y)]=N[pi(f[i].xx,f[i].yy)]=-1;
		e=0;
		rep(i,n)if(!f[i].w){
			s=1;
			stack<int> S;
			S.push(i);
			while(S.sz){
				int i=S.top();S.pop();
				F& c=f[i];
				if(c.w)continue;
				if(s==1){
					c.w=1,s=0;
					N[pi(c.x,c.y)]=1,N[pi(c.xx,c.yy)]=2;
				}else{
					int OK=0;
					rep2(i,1,3){
						int ok=1;
						rep(j,4){
							int nx=c.x+dx[j],ny=c.y+dy[j];
							if(N[pi(nx,ny)]==3-i)ok=0;
						}
						rep(j,4){
							int nx=c.xx+dx[j],ny=c.yy+dy[j];
							if(N[pi(nx,ny)]==i)ok=0;
						}
						if(ok){
							c.w=i;
							N[pi(c.x,c.y)]=i,N[pi(c.xx,c.yy)]=3-i;
							OK=1;
							break;
						}
					}
					if(!OK){e=1;break;}
				}
				rep(i,4){
					int nx=c.x+dx[i],ny=c.y+dy[i];
					if(N[pi(nx,ny)]==-1)S.push(M[pi(nx,ny)]);
					nx=c.xx+dx[i],ny=c.yy+dy[i];
					if(N[pi(nx,ny)]==-1)S.push(M[pi(nx,ny)]);
				}
			}
		}
		cout<<(e?"No":"Yes")<<endl;
	}
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  vector<int> count(n, 0);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    count.at(tmp) += 1;
  }
  int loop_max = (n + 2 - 1) / 2;
  for (int i = 0; i < loop_max; i++) {
    if (n % 2 == 0) {
      if (count.at(2 * i + 1) != 2) {
        cout << 0 << endl;
        return 0;
      }
    } else {
      if (count.at(0) != 1) {
        cout << 0 << endl;
        return 0;
      } else if (i != 0 && count.at(2 * i) != 2 && n != 1) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  long ans = 1;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < n / 2; i++) {
    ans = (ans * 2);
    ans = ans % (1000000000 + 7);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3688
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        mut aa: [usize; n]
    };
    let mut count = 0;
    while aa.iter().all(|&a| a % 2 == 0) {
        aa = aa.iter().map(|&a| a / 2).collect::<Vec<usize>>();
        count += 1;
    }
    println!("{}", count);
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int ts(char *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 200007;

int H,W,n,sx,sy;char s[_],t[_];

int main()
{
	H=ty(),W=ty(),n=ty();
	sy=ty(),sx=ty();
	ts(s+1),ts(t+1);

	int xl=1,xr=W,yl=1,yr=H;
	for(int i=n;i>=1;i--)
	{
		int a=s[i],b=t[i];
		xl=max(xl-(b=='R'),1)+(a=='L');
		xr=min(xr+(b=='L'),W)-(a=='R');
		yl=max(yl-(b=='D'),1)+(a=='U');
		yr=min(yr+(b=='U'),H)-(a=='D');
		if(xl>xr || yl>yr){puts("NO");return 0;}
	}
	puts((xl<=sx && sx<=xr && yl<=sy && sy<=yr)?"YES":"NO");
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>vec(3);
    for(int i=0;i<3;i++)cin>>vec[i];
    sort(vec.begin(), vec.end());
    if(vec[0]==vec[2])cout<<1<<endl;
    else if(vec[0]==vec[1])cout<<2<<endl;
    else if(vec[1]==vec[2])cout<<2<<endl;
    else cout<<3<<endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;
ll num[ten52];
ll num2[ten52];

int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;
    for(i=1;i<=n;i++) cin>>num[i];
    for(i=1;i<=n;i++)
        if(i+num[i]<=n)
            num2[i+num[i]]++;
    for(i=1;i<=n;i++)
    {
        if(i-num[i]>0)
            sum+=num2[i-num[i]];
    }
    cout<<sum;
    return 0;
}





Measured memory_bytes: 6680
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	string s;
	cin >> s;

	int includeCnt = 0;
	int includePos = 0;
	bool isSmall = true;

	for (int i = 1; i < s.length(); i++)
	{
		if ( 2 <= i && i <= s.length() - 2 )
		{
			if ( s[i] == 'C' )
			{
				includeCnt++;
				includePos = i;
			}
		}
	}


	if ( s[0] == 'A' )
	{
		for ( int i = 1; i < s.length(); i++ )
		{
			if ( 'A' <= s[i] && s[i] <= 'Z' && i != includePos )
			{
				isSmall = false;
			}
		}

		if ( isSmall && includeCnt == 1 )
		{
			cout << "AC" << endl;
		}
		else
		{
			cout << "WA" << endl;
		}
	}
	else
	{
		cout << "WA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
chl = "abcdefghijk"
chli = {
  'a':0,
  'b':1,
  'c':2,
  'd':3,
  'e':4,
  'f':5,
  'g':6,
  'h':7,
  'i':8,
  'j':9
}

def ret(M):
  if M == 1:
    return "a"
  retl = []
  for stra in ret(M-1):
    maxi = min(chli[sorted(stra)[-1]] + 2, 10)
    cand = chl[:maxi]
    for ch in cand:
      retl.append(stra + ch)
  return retl

ans = ret(N)

for x in ans:
  print(x)


Measured memory_bytes: 12984
#include<iostream>
using namespace std; // 575

int main() {
	string S, T = "keyence";
	cin >> S;
	for (int i = 0;i <= 7;++ i) {
		for (int j = 0;j < i;++ j) if (S[j] != T[j]) goto cont;
		for (int j = i;j < 7;++ j) if (S[S.length() + j - 7] != T[j]) goto cont;
		cout << "YES";
		return 0;
		cont:;
	}
	cout << "NO";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

言い換えると、
1. 先頭7文字がkeyence
2. 末尾7文字がkeyence
3. 先頭x文字と末尾7-x文字がkeyence
のいずれかしかないので、要するにxが0から7まで全探索
*/

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

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

ll N;
vector<ll> a;

int main(int argc, char **argv)
{
	cin >> N;
	a.resize(N);
	REP(i, N) cin >> a[i];
	REP(i, N-1)
		a[i+1] += a[i];

	ll res{INF};
	ll pre;
	ll cnt;

	// pattern 1
	pre = 0;
	cnt = 0;
	REP(i, N)
	{
		ll t = a[i] + pre;
		if (i & 1)
		{
			if (t <= 0)
			{
				cnt += -t + 1;
				pre += -t + 1;
			}
		}
		else
		{
			if (t >= 0)
			{
				cnt += t + 1;
				pre -= t + 1;
			}
		}
	}
	res = min(res, cnt);

	// pattern 2
	cnt = 0;
	pre = 0;
	REP(i, N)
	{
		ll t = a[i] + pre;
		if (~i & 1)
		{
			if (t <= 0)
			{
				cnt += -t + 1;
				pre += -t + 1;
			}
		}
		else
		{
			if (t >= 0)
			{
				cnt += t + 1;
				pre -= t + 1;
			}
		}
	}
	res = min(res, cnt);

	std::cout << res << std::endl;
}


Measured memory_bytes: 1024
N = int(input())

if N == 1 or N == 2:
    print(N)
    exit()


candidate = [0] * 1001

candidate[2] = 1
candidate[3] = 1
for i in range(4,N + 1):
    tmp = i
    for j in range(2, int(i ** (1/2)) + 1):
        while tmp % j == 0:
            candidate[j] += 1
            tmp = tmp // j
    candidate[tmp] += 1

ans = 1
for i in range(2,len(candidate)):
    if candidate[i] != 0:
       ans = ans * (candidate[i] + 1) % 1000000007
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;


public class C
{
	public static void Main()
	{
		string[] args;
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);
		
		List<int> X = new List<int>(M);
		args = Console.ReadLine().Split(' ');
		for(int i = 0; i < M; i++)
			X.Add(Int32.Parse(args[i]));
		
		X.Sort();
		
		List<int> L = new List<int>(M);
		for(int i = 0; i < M - 1; i++)
			L.Add(X[i + 1] - X[i]);
		
		L.Sort((a,b) => b-a);
		
		int result = 0;
		if(N < M)
		{
			result = X[M-1] - X[0];
			for(int i = 0; i < N-1; i++)
				result -= L[i];			
		}
		Console.WriteLine(result);
	}
}

Measured memory_bytes: 25052
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
  int n, x, y; cin >> n >> x >> y;
  
  int ans[2005] = {};
  for (int i = 1; i <= n-1; ++i) for (int j = i+1; j <= n; ++j) {
    int d = min(j-i, abs(i-x)+abs(j-y)+1);
    ++ans[d];
  }
  
  for (int i = 1; i < n; ++i) cout << ans[i] << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	for(int i = 0; i <= n; i++){
		int price = n - 7 * i;
		if(price >= 0 && price % 4 == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3640
H, W = map(int, input().split())
a = [0] * H
for i in range(H):
    if i % 2 == 0:
        a[i] = list(map(int, input().split()))
    else:
        a[i] = list(map(int, input().split()))[::-1]

s = [[0] * W for i in range(H)]
s[0][0] = a[0][0] % 2
for i in range(1,W):
    s[0][i] = (s[0][i-1] + a[0][i]) % 2
for i in range(1,H):
    for j in range(W):
        if j == 0:
            s[i][j] = (s[i-1][-1] + a[i][j]) % 2
        else:
            s[i][j] = (s[i][j-1] + a[i][j]) % 2

s[H-1][W-1] = 0
#print(a)
ans = []
for i in range(H):
    for j in range(W):
        if s[i][j]:
            if i % 2 == 0:
                if j != W-1:
                    ans.append([i+1, j+1, i+1, j+2])
                else:
                    ans.append([i+1, j+1, i+2, j+1])
            else:
                if j != W-1:
                    ans.append([i+1, W-j, i+1, W-j-1])
                else:
                    ans.append([i+1, W-j, i+2, W-j])

print(len(ans))
for i in range(len(ans)):
    print("{} {} {} {}".format(ans[i][0], ans[i][1], ans[i][2], ans[i][3]))


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

struct basis{
	vector<ll> V;
	bool insert(ll x, bool add = true){
		for(ll a : V) if(a & -a & x) x ^= a;
		bool ret = x == 0;
		if(!add) return ret;
		if(ret) return 0;
		for(ll & a : V) if(x & -x & a) a ^= x;
		V.push_back(x);
		return 1;
	}
};

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int t; cin >> t;
	while(t--){
		int n; cin >> n;
		vector<ll> A(n);
		for(auto & it : A) cin >> it;
		string s; cin >> s;
		basis B;
		bool ok = true;
		for(int i = n - 1; i >= 0; i--){
			if(s[i] == '0') B.insert(A[i]);
			else if(!B.insert(A[i], 0)){
				ok = false;
			}
		}
		printf(ok?"0\n" : "1\n");
	}
}

Measured memory_bytes: 3704
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(string& s) {
        int n = s.length();

        const long long MOD = 1e9 + 7;

        int m = 1;
        int M = 1 << m;
        vector<long long> dp(M, 0);
        dp[0] = 1;
        vector<long long> ndp(dp);
        for (int i = 0; i < n; ++i) {
            fill(ndp.begin(), ndp.end(), 0);
            int d = s[i] - '0';
            for (int j = 0; j < M; ++j) {
                int la = 0, ra = 1;
                int lb = 0, rb = 1;
                int mx = 1;
                if ((j & 1) == 0) {
                    mx = d;
                }

                for (int a = la; a <= ra; ++a) {
                    for (int b = lb; b <= rb; ++b) {
                        if (a == 1 && b == 1) {
                            continue;
                        }
                        if ((a ^ b) > mx) {
                            continue;
                        }
                        int nj = j;
                        if ((a ^ b) < d) {
                            nj |= 1;
                        }
                        // cout << a << " " << b << " " << j << endl;
                       
                        (ndp[nj] += dp[j]) %= MOD;
                    }
                }
            }
            // for (int j = 0; j < M; ++j) {
            //     cout << j << " : " << ndp[j] << endl;
            // }
            swap(ndp, dp);
        }
        long long res = 0;
        for (auto x : dp) {
            res += x;
        }
        res %= MOD;
        return res;
    }

};

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

    string S;
    cin >> S;
    Solution sol;
    cout << sol.solve(S) << "\n";

    return 0;
}

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

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

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

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

int main(){
    ll a,b;cin>>a>>b;
    cout << (a*b)/2 << ednl;
}


Measured memory_bytes: 256
import sys

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    a = read_int()
    res = n * n - a
    print(res)


main()


Measured memory_bytes: 2940
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int l=a+b;
  int r=c+d;
  if(l>r)cout<<"Left"<<endl;
  else if(r>l)cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string t = s;
    int c = 0;
    rep(i, s.size()) { //01
        if (i % 2 == 0 && s[i] == '1') {
            c++;
        }
        if (i % 2 != 0 && s[i] == '0') {
            c++;
        }
    }
    int ans = c;
    c = 0;
    rep(i, s.size()) {
        if (i % 2 == 0 && s[i] == '0') {
            c++;
        }
        if (i % 2 != 0 && s[i] == '1') {
            c++;
        }
        
    }
    cout << min(ans, c) << endl;
}


Measured memory_bytes: 512
import java.util.*;

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

        out_of_loop: while (true) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());

            if (a == 0 && b == 0) {
                break out_of_loop;
            }

            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
        sc.close();

    }
}


Measured memory_bytes: 34204
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
using ll = long long;

vector<ll> g[N];
vector<ll> dist(N),col(N);
vector<ll> res(N),c(N);
ll f(ll n){
    return 1LL*n*(n+1)/2;
}

void dfs(ll x, ll p){
    ll t = c[col[x]];
    for(auto i : g[x]){
        if(i==p) continue;
        c[col[x]] = 0;
        dfs(i,x);
        dist[x]+=dist[i];
        res[col[x]] += f(dist[i]-c[col[x]]);
    }
    c[col[x]]=t+dist[x];
}


int main(){
    int n;
    cin>>n;
    
    for(int i = 1; i <= n; i++){
        dist[i] = 1;
        cin>>col[i];
    } 

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

    dfs(1,-1);

    for(int i = 1; i <= n; i++){
        cout<<f(n) - f(n-c[i]) - res[i]<<"\n";
    }
}


Measured memory_bytes: 35896
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
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;
}
const long long INF = 1LL << 60;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<long long> p;
    vector<long long> m;
    rep(i, 0, N)
    {
        int x;
        cin >> x;
        if (x >= 0)
        {
            p.push_back(x);
        }
        else
        {
            m.push_back(-1 * x);
        }
    }

    sort(m.begin(), m.end());
    int pl = p.size();
    int ml = m.size();
    long long min = INF;
    if (pl >= K)
    {
        chmin(min, p[K - 1]);
    }
    if (ml >= K)
    {
        chmin(min, m[K - 1]);
    }
    if (pl > 0 && ml > 0)
    {

        rep(i, 1, K)
        {
            if (pl >= i && ml >= K - i)
            {
                chmin(min, 2 * p[i - 1] + m[K - i - 1]);
            }
            if (ml >= i && pl >= K - i)
            {
                chmin(min, 2 * m[i - 1] + p[K - i - 1]);
            }
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 1656
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 = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = b[i] = sc.nextInt();
        }
        Arrays.sort(b);
        int c = b[n/2-1];
        int d = b[n/2];

        for(int i=0; i<n; i++) {
            if(a[i] <= c) {
                System.out.println(d);
            } else {
                System.out.println(c);
            }
        }
    }

}


Measured memory_bytes: 90500
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N, Q;
    string S;
    cin >> N >> S >> Q;

    vector< set<int> > list(26);

    rep(i,N) {
        list[S[i] - 'a'].insert(i);
    }

    rep(q,Q) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (S[i] != c) {
                list[S[i] - 'a'].erase(i);
                S[i] = c;
                list[S[i] - 'a'].insert(i);
            }
        } else {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int count = 0;
            rep(i,26) {
                auto itr = list[i].lower_bound(l);
                if (itr != list[i].end() && *itr <= r) count++;
            }
            cout << count << endl;
        }
    }
    
    return 0;
}

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

using namespace std;

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

    long long int N,a;
    cin>>N;

    string s="";

    while(N>0){
       a = (N-1)%26;
       s+=char(97+a);
       N=(N-a)/26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<"\n";

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define lo long long
using namespace std;
int n;
string s,t;
int main(){
	cin>>s>>t;
	int say=0;
	for(int i=0;i<=2;i++){
		if(s[i]==t[i]) say++;
	}
	printf("%d\n",say);
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	int cnt[N+1]{};
	bool ans = true;
	int cnt1 = 0;
	while(cnt1 < K && ans){
		cnt1++;
		ans = false;
		rep(i,N) cnt[i] = 0;
		rep(i,N){
			cnt[max((int)0, i-A[i])]++;
			cnt[min(N, i+A[i]+1)]--;
		}
		int tmp = 0;
		rep(i,N){
			tmp+=cnt[i];
			A[i] = tmp;
			if(A[i] != N) ans = true;
		}
	}
	rep(i,N){
		cout << A[i] << " ";
	}
}

Measured memory_bytes: 6372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int counter = 0;
        char[] in = s.next().toCharArray();
        for (int i = 0; i < 3; i++) {
            if (in[i] == '1') {
                counter++;
            }
        }

        System.out.println(counter);
    }
}

Measured memory_bytes: 22228
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC042-A.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 STR PIC X(100).
       77 A PIC 9(2).
       77 B PIC 9(2).
       77 C PIC 9(2).
       77 COUNT5 PIC 9(1) VALUE 0.
       77 COUNT7 PIC 9(1) VALUE 0.

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
               ACCEPT STR FROM SYSIN.
               UNSTRING STR DELIMITED " "
                INTO A B C.
               EVALUATE A
                   WHEN 5
                       ADD 1 TO COUNT5
                   WHEN 7
                       ADD 1 TO COUNT7
               END-EVALUATE
               EVALUATE B
                   WHEN 5
                       ADD 1 TO COUNT5
                   WHEN 7
                       ADD 1 TO COUNT7
               END-EVALUATE
               EVALUATE C
                   WHEN 5
                       ADD 1 TO COUNT5
                   WHEN 7
                       ADD 1 TO COUNT7
               END-EVALUATE
               IF COUNT5 = 2 AND COUNT7 = 1 THEN
                   DISPLAY "YES"
               ELSE
                   DISPLAY "NO"
               END-IF
               STOP RUN.
       END PROGRAM ABC042-A.


Measured memory_bytes: 764
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=998244353;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

//////////////////////////////////////////////////////////////////

map<string,int>has;
void Solve(){
  int n;
  cin>>n;
  rep(i,1,n){
    string str;
    cin>>str;
    has[str]++;
  }
  cout<<"AC x "<<has["AC"]<<endl;
  cout<<"WA x "<<has["WA"]<<endl;
  cout<<"TLE x "<<has["TLE"]<<endl;
  cout<<"RE x "<<has["RE"]<<endl;
}


Measured memory_bytes: 3636
def solve(string):
    n, *ss = string.split()
    d = {}
    for s in ss:
        s = "".join(sorted(s))
        d[s] = 1 + d[s] if s in d.keys() else 1
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 27468
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

long long sum_section(long long s, long long t, long long* sum){
  return t<0 ? 0 : (s>0 ? sum[t]-sum[s-1] : sum[t]);
}

long long max_4(long long x, long long y, long long z, long long w){
  return max(max(x,y),max(z,w));
}

long long min_4(long long x, long long y, long long z, long long w){
  return min(min(x,y),min(z,w));
}

int main(){
  long n;
  cin >> n;
  long a[n];
  long long sum[n];
  REP(i,n){
    cin >> a[i];
    if(i>0){
      sum[i] = sum[i-1]+a[i];
    }else{
      sum[i] = a[i];
    }
  }
  long long i = 1;
  long long j = 2;
  long long k = 3;
  long long ans = sum[n-1];
  for(j=2; j<=n-2; j++){
    while(sum_section(0,i-1,sum)<sum_section(i,j-1,sum)&&i<j-1)i++;
    if(abs(sum_section(0,i-1,sum)-sum_section(i,j-1,sum))>abs(sum_section(0,i-2,sum)-sum_section(i-1,j-1,sum))){
      i--;
    }
    while(sum_section(j,k-1,sum)<sum_section(k,n-1,sum)&&k<n-1)k++;
    if(abs(sum_section(j,k-1,sum)-sum_section(k,n-1,sum))>abs(sum_section(j,k-2,sum)-sum_section(k-1,n-1,sum))){
      k--;
    }
    long long diff = max_4(sum_section(0,i-1,sum),sum_section(i,j-1,sum),sum_section(j,k-1,sum),sum_section(k,n-1,sum))-min_4(sum_section(0,i-1,sum),sum_section(i,j-1,sum),sum_section(j,k-1,sum),sum_section(k,n-1,sum));
    if(ans > diff){
      ans = diff;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

bool kaibun(string s) {
	string t;
	int n = s.size();
	for (int i = n - 1; i >= 0; i--) {
		t.push_back(s[i]);
	}
	if (s == t) return true;
	else return false;
}

int main() {
	string S;
	cin >> S;
	int N = S.size();
	string a = S.substr(0, (N - 1) / 2);
	string b = S.substr((N + 3) / 2 - 1);
	if (kaibun(S) && kaibun(a) && kaibun(b)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3576
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	string s; cin >> s;
	int len = s.length();
	for(int i=0; i<len; i++){
		if(s[i] != s[len-1-i]){
			cout << "No" << endl;
			return 0;
		}
	}

	string tmp;
	for(int i=0; i<(len-1)/2; i++){
		if(s[i] != s[(len-1)/2-1-i]){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=(len+3)/2-1; i<len-1; i++){
		if(s[i] != s[len-1-i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
a,b=map(int, input().split())
s=[]
for i in range(a):
    name, time = input().split()
    time = int(time)
    s.append([name,time])
time=0
while True:
    if len(s)==0:
        break
   
    if s[0][1]>b:
        s[0][1]-=b
        s.append(s[0])
        s.pop(0)
        time+=b
    else:
        time=time+s[0][1]
        print("{} {}".format(s[0][0],time))
        s.pop(0)
       
        
  


Measured memory_bytes: 12872