akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  char sd[100] = {};int sdcnt = 0;
  char t[100] = {};int tcnt = 0;
  int i = 0;
  int j = 0;
  int success = 0;
  int li = 0;
  int ok = 0;
  scanf(" %s",sd);
  scanf(" %s",t);
  for(i=0;i < 100;i++){
    if(sd[i] == '\0'){
      sdcnt = i;
      break;
    }
  }
  for(i=0;i < 100;i++){
    if(t[i] == '\0'){
      tcnt = i;
      break;
    }
  }
  if(tcnt > sdcnt){
    success = 0;
  }else{
    for(i=0;i<=sdcnt-tcnt;i++){
      ok=1;
      for(j=0;j<tcnt;j++){
        //printf("%c %c\n",sd[i+j],t[j]);
        if(sd[i+j] != t[j] && sd[i+j] != '?'){
          ok=0;
        }
      }
      if(ok){
        success = 1;
        li = i;
        //printf("#");
      }
    }
  }
  if(success){
    for(i=0;i<tcnt;i++){
      sd[i+li] = t[i];
    }
    for(i=0;i<sdcnt;i++){
      if(sd[i] == '?'){
        sd[i] = 'a';
      }
    }
    printf("%s",sd);
  }else{
    printf("UNRESTORABLE");
  }

  return 0;
}
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define rep(i,st,end)   for(int i=st;i<end;i++)
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void s_g_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	s_g_c();
	int n;
	cin >> n;
	if (n % 1000 != 0)
		cout << 1000 - (n % 1000) << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int W, H, N;
	cin >> W >> H >> N;
	vector<vector<int>> b(H, vector<int>(W, 0));

	for (int i = 0; i < N; ++i) {
		int x, y, a;
		cin >> x >> y >> a;
		int x1 = 0;
		int y1 = 0;
		int x2 = W;
		int y2 = H;
		if (a == 1) {
			x2 = x;
		}
		else if (a == 2) {
			x1 = x;
		}
		else if (a == 3) {
			y2 = y;
		}
		else if (a == 4) {
			y1 = y;
		}

		for (int i = y1; i < y2; ++i) {
			for (int j = x1; j < x2; ++j) {
				b[i][j] = 1;
			}
		}
	}
	int ans = 0;
	for (auto &row : b) {
		ans += count(row.begin(), row.end(), 0);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
for ($i  = 0; $i < $n; $i++) fscanf(STDIN, '%d %d', $x[], $y[]);
$sum = 0.0;
for ($i = 0; $i < $n - 1; $i++) {
    for ($j = $i + 1; $j < $n; $j++) {
        $sum += sqrt(($x[$i] - $x[$j]) ** 2 + ($y[$i] - $y[$j]) ** 2);
    }
}
echo $sum * ($n - 1) / nCr($n, 2);

function fac($n)
{
    if ($n === 1) return 1;
    return $n * fac($n - 1);
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return fac($n) / fac($n - $r);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return nPr($n, $r) / fac($r);
}

Measured memory_bytes: 4604
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#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-5;
typedef long long ll;

int main(){
	int t;
	cin>>t;
	
	for(int ti=0;ti<t;ti++){
		int n,k;
		cin>>n>>k;
		
		vector<int> housex;
		int zenx;
		cin>>zenx;
		for(int i=1;i<n;i++){
			int cux;
			cin>>cux;
			housex.push_back(cux-zenx);
			zenx=cux;
		}
		
		sort(housex.begin(),housex.end());
		
		int cost=0;
		if(n-k>0){
			for(int i=0;i<n-k;i++){
				cost+=housex[i];
			}
		}
		
		cout<<cost<<endl;
	}
	return 0;
}

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

int main(){
	int D;
	cin >> D;
	if(D == 25){
		cout << "Christmas" << endl;
	}else if(D == 24){
		cout << "Christmas Eve" << endl;
	}else if(D == 23){
		cout << "Christmas Eve Eve" << endl;
	}else{
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
#3**nから全部奇数のものをひく
# a[i]が偶数なら*2 で奇数なら*1をしていくだけ
all_odd = 1
for i in range(n):
    if a[i] % 2 == 0: all_odd *= 2
print(3**n - all_odd)

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

long long pow(long long base,long long exp){
    long long res = 1;
    while(exp>0){
        if(exp & 1)res = res * base;
        base = base * base;
        exp >>= 1;
    }
    return res;
}

int main()
{
    long long a,b;
    std::cin >> a >> b;
    char aa = a + '0';
    char bb = b + '0';
    std::string res1,res2;
    for(int i = 0; i < b; i++){
        res1 += aa;
    }
    for(int i = 0; i < a; i++){
        res2 += bb;
    }
    std::cout << std::min(res1,res2) << std::endl;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------

mod = 10**9 +7
N, K = inpl()

ans = 0
for i in range(K, N + 2):
    ans += (N + 1 - i) * i + 1
    ans %= mod

print(ans)

Measured memory_bytes: 63228
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

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;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  int arr[n - 1][3];

  fi(0, n - 1) {
    cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
  }
  fi(0, n - 1) {
    int est = 0;
    fj(i, n - 1) {
      if(est <= arr[j][1]) {
        est = arr[j][1] + arr[j][0];
      }
      else {
        int start = arr[j][1];
        while(start < est) {
          start += arr[j][2];
        }
        est = start + arr[j][0];
      }
    }
    cout << est << endl;
  }
  cout << "0\n";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll n;
    cin >> n;
    while (n) {
    	ll x = n % 10;
    	if (x == 7) {
    		return cout << "Yes", 0;
		}
		n /= 10;
	}
	cout << "No";
    return (0);
}


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

ll gcd(ll x, ll y){
	while(1){
		if(x < y) swap(x, y);
		if(!y) break;
		x %= y;
	}
	return x;
}

int main(){
	ll a, b; cin >> a >> b;
	ll t = gcd(a, b);
	ll ans = 0;
	ll T = t;
	for(ll i=2; i<=sqrt(T); i++){
		if(t == 1) break;
		if(t % i == 0){ ans++; }
		while(t%i == 0){
			t /= i;
		}
	}
	if(t > 1) ans++;
	cout << ans + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
#include<queue>
#include<utility>
using namespace std;

const int N = 20+1;
int costMap[N][N];

int MinCost(int startP, int endP, int n)
{
	int distance[N];
	queue<pair<int,int> > q;
	pair<int,int> p;
	int i;
	fill(distance, distance+N, INT_MAX);
	distance[startP] = 0;
	q.push( make_pair(0, startP) );
	while(!q.empty())
	{
		p = q.front(); q.pop();
		for(i = 1; i <= n; ++i)
		{
			if(costMap[p.second][i] != INT_MAX)
			{
				if(distance[i] > p.first+costMap[p.second][i])
				{
					distance[i] = p.first + costMap[p.second][i];
					q.push( make_pair(distance[i], i) );
				}
			}
		}
	}
	return distance[endP];
}


int main()
{
	int n,m;
	int startP, pillarP, income, pillarCost;
	while(scanf("%d%d",&n,&m) > 0)
	{
		int i,j,a,b,c,d;
		for(i = 0; i < N; ++i)
			for(j = 0; j < N; ++j)
				costMap[i][j] = INT_MAX;
		for(i = 0; i < m; ++i)
		{
			scanf("%d,%d,%d,%d",&a,&b,&c,&d);
			costMap[a][b] = c;
			costMap[b][a] = d;
		}
		scanf("%d,%d,%d,%d",&startP,&pillarP, &income, &pillarCost);

		int goCost = MinCost(startP, pillarP, n),
			fromCost = MinCost(pillarP, startP, n);
		printf("%d\n", income - pillarCost - goCost - fromCost);
	}
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    int r=0,w=0;
    rep(i,S.length()){
        if(S[i]=='R')r++;
        else w++;
    }
    int rr=0;
    rep(i,r){
        if(S[i]=='R')rr++;
    }
    cout<<r-rr<<endl;
    return 0;
}

Measured memory_bytes: 3740
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

// Use g++ compiler for this include to work.
#include <bits/stdc++.h>

using namespace std;

// Constants 
#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007
 
// // for using in pairs
#define F first
#define S second
 
// Macros
#define all(x) begin(x), end(x)
 
// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Temporary macro.
#define int long long

// Operator overloads.
/**
 * The type of element in the vector should have overload for << operator with ostream. 
 */
template<typename T>
ostream& operator<<(ostream &stream, vector<T> v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

/**
 * Both types in the pair should have overload for << operator with ostream. 
 */
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2> p)
{
	ostream << p.first << " " << p.second;
	return ostream;
}

template<typename T>
void swap(T &a, T &b)
{
	T t = a;
	a = b;
	b = t;
}

// Utility functions.
void swap(int &a, int &b)
{
	int t = a;
	a = b;
	b = t;
}

int GCD(int a, int b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}

int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}

int modpow(int x, int n, int m = MOD)
{
	if (n == 0) return 1 % m;
	long long u = modpow(x, n / 2, m);
	u = (u * u) % m;
	if (n % 2 == 1)
		u = (u * x) % m;
	return u;	
}

//////////////////// START CODE HERE ///////////////////////////


void solve(int tc)
{
	int n;
	cin >> n;
	ld p[n];
	for (int i = 0; i < n; i++)
		cin >> p[i];

	ld dp[n + 1][n + 1];
	// dp[i][j]: probability of getting j heads using upto i coins
	for (int i = 0; i <= n; i++)
		dp[i][0] = 1;
	for (int j = 1; j <= n; j++)
		dp[0][j] = 0;

	ld ans = 0;
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			// If we get tails
			dp[i][j] = dp[i - 1][j]  * (1 - p[i - 1]);
			dp[i][j] += dp[i - 1][j - 1] * p[i - 1];

			// if (j > n / 2)
			// {
			// 	ans += dp[i][j];
			// 	count++;
			// }
		}
	}

	// for (int i = 0; i <= n; i++)
	// {
	// 	for (int j = 0; j <= n; j++)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	// ans /= count;
	cout << setprecision(10) << dp[n][n / 2 + 1] << "\n";

}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;		
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


Measured memory_bytes: 144336
n=int(input())
ls = list(map(int,input().split()))

ls = sorted(ls)
ans = sum(ls)
newls = [0]*(100000+1+1)
for p in ls:
  newls[p] += 1
ls = newls

q=int(input())
for _ in range(q):
  b,c = map(int,input().split())
  
  tmp = ls[b]
  ans = ans + tmp*c - tmp*b
  ls[b] = 0
  ls[c] += tmp
  
  print(ans)
  

Measured memory_bytes: 20844
import java.util.Scanner;

public class Main {
	
	static Scanner scan = new Scanner(System.in);
	
	//0埋め
	static String zeroLine(String a) {
		String zero = "";
		if(a.length() < 32) {
			
			for(int i=0; i<32-a.length(); i++) {
				zero += "0";
			}
		}
		return zero + a;
	} 
	
	//文字列の出力
	static void printStr(String a) {
		
		for(int i=a.length()-32; i<a.length(); i++) {
			System.out.print(a.charAt(i));
		}
		System.out.println();
	}
	
	
	public static void main(String args[]) {
	
		Long num10 = scan.nextLong();
		
		//2進数
		printStr(zeroLine(Long.toBinaryString(num10)));
		//反転
		printStr(zeroLine(Long.toBinaryString(~num10)));
		//右に1ビット
		printStr(zeroLine(Long.toBinaryString(num10 << 1)));
		//左に1ビット
		printStr(zeroLine(Long.toBinaryString(num10 >> 1)));
		
		
	}
}


Measured memory_bytes: 26252
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart;
#define setTime tStart = clock();
#define time0 (double)(clock() - tStart)/CLOCKS_PER_SEC
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
#define NMAX 30
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
int main(){
    //setin("input.in");
    string str;
    cin >> str;
    str[0]='2';
    str[1]='0';
    str[2]='1';
    str[3]='8';
    cout << str;
	return(0);
}


Measured memory_bytes: 768
import sys

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    has_nagative_cycle = False
    for i in range(n):
        if d[i][i] < 0:
            has_nagative_cycle = True
            break
    for i in range(n):
        d[i][i] = 0
    return has_nagative_cycle

V, E = map(int, sys.stdin.readline().strip().split())

d = [[float("inf") for _ in range(V)] for _ in range(V)]
for i in range(V):
    d[i][i] = 0
for _ in range(E):
    s, t, d_i = map(int, sys.stdin.readline().strip().split())
    d[s][t] = d_i

negative_cycle = warshall_floyd(d, V)
if negative_cycle:
    print("NEGATIVE CYCLE")
else:
    for i in range(V):
        for j in range(V):
            print(d[i][j] if d[i][j] != float("inf") else "INF", end="")
            if j == V - 1:
                print("")
            else:
                print(" ", end="")


Measured memory_bytes: 7052
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, M;
	char[] S;
	Deque<Integer> result;
	boolean enable = true;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		S = in.readLine().toCharArray();
		result = new ArrayDeque<>();
	}

	void calc() {
		search(N);
	}

	void search(int current) {
		// System.out.println(current);
		if (current == 0) {
			// 先頭についた
			return;
		}
		// Mが大きい順にsearchする
		for (int i = M; i >= 1; --i) {
			int index = current - i;
			if (index < 0) {
				continue;
			}
			if (S[index] == '0') {
				// 行ける
				result.addFirst(i);
				search(index);
				return;
			}
		}
		// 行けなかった
		enable = false;
	}

	void showResult() {
		if (!enable) {
			System.out.println("-1");
		} else {
			StringBuilder strBuilder = new StringBuilder();
			strBuilder.append(Integer.toString(result.pollFirst()));
			while (!result.isEmpty()) {
				strBuilder.append(" " + Integer.toString(result.pollFirst()));
			}
			System.out.println(strBuilder.toString());
		}
	}
}


Measured memory_bytes: 51284
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#include<math.h>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	rep(i, 10) {
		rep(j, 10) {
			if (i*j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

int main()
{
  int t;
  cin>>t;
  int ans = int(1e9);
  while(t--)
  {
    int n;
    cin>>n;
    ans = min(ans,int(log2(n&(~(n-1)))));
  }
  cout<<ans<<"\n";
  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 998244353;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, s; cin >> n >> s;
  vll a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  vll dp(s+1);
  ll ans = 0;
  for(int i=0;i<n;++i) {
    for(int j=s;j-a[i]>=0;--j) {
      dp[j] += dp[j-a[i]];
      dp[j] %= MOD;
    }
    if(a[i] <= s) dp[a[i]] += i+1;
    dp[a[i]] %= MOD;
    ans += dp[s];
    ans %= MOD;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
    cin >> N;
    vector<int> vec(N-1);
    vector<int> vec2(N);
    for(int i=0;i<N-1;i++){
    int a;
    cin >> a;
    vec.at(i)=a;
    }
    for(int i=0;i<N-1;i++){
    vec2.at(vec.at(i)-1) ++;}
    for(int i=0;i<N;i++){
    cout << vec2.at(i) << endl;
    }
    }
    

Measured memory_bytes: 4840
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
res=0

for i in range(n):
	if B[i]>A[i]:
		res+=A[i]
		if (B[i]-A[i])>A[i+1]:
			res+=A[i+1]
			A[i+1]=0
		else:
			res+=B[i]-A[i]
			A[i+1]-=(B[i]-A[i])
	else:
		res+=B[i]
print(res)

Measured memory_bytes: 18624
n = int(input())
a_all = input()
a_l = a_all.split()
c = 0
for i in range(1,n):
  if int(a_l[i]) < int(a_l[i-1]):
    c = c - int(a_l[i]) + int(a_l[i-1])
    a_l[i] = a_l[i-1]
print(c)

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

def dec_to_n(N, n):
    if N == 0:
        return "0"
    digits = []
    base = 1
    while N != 0:
        if N % (base * n) == 0:
            digits.append('0')
        else:
            digits.append('1')
            N -= base
        base *= n
    return "".join(digits[::-1])

print(dec_to_n(N, -2))

Measured memory_bytes: 38256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

class Person
{
	public:
		string name;
		int score;
		int idx;
		Person(string name, int score, int idx)
		{
			this->name = name;
			this->score = score;
			this->idx = idx;
		}
};

bool compare(Person &a, Person &b)
{
	if (a.name == b.name)
		return a.score < b.score;
	else
		return a.name > b.name;
}
int main()
{
	char tmp[11];
	int n, tsc;
	vector<Person> v;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%s %d", &tmp, &tsc);

		v.push_back(Person(tmp, tsc, i+1));
	}

	sort(v.begin(), v.end(), compare);

	for (int i = n - 1; i >= 0; i--)
		cout << v[i].idx << endl;

	return 0;
}

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

# define C continue;
# define R return

#define int long long
# define D double
# define I insert
# define ld long double
# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) v.begin() , v.end()
# define allcomp(v) v.begin() , v.end() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type, vector<type>, greater<type>>

#define mii map<int, int>
#define mll map<ll, ll>
#define mci map<char, int>
#define msi map<string, int>
#define mis map<int, string>
#define mib map<int, bool>
#define mcb map<char,bool>

#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umci unordered_map<char, int>
#define umsi unordered_map<string, int>
#define umis unordered_map<int, string>

#define init(arr,val) memset(arr,val,sizeof(arr))
#define REP(i,a,b) for(int i=a; i<b; i++)
#define distance(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = { -2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const int mod = 1e9 + 7 ;
#define test int t; cin>>t;
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .
void a_b_c()
{
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
}

void solve()
{
   int n,d; cin>>n>>d;
   vpii a(n);
   vld b(n);
   REP(i,0,n)
   {
       int x,y;
       cin>>x>>y;
       a[i].F=x;
       a[i].S=y;
       b[i]=distance(0,0,x,y);
   }
   int ans=0;
   REP(i,0,n)
   {
       if(b[i]<=d) ans++;
   }
   cout<<ans;
}
int32_t main()
{	fast
    int t=1;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    //int t;  cin>>t;
    for(int i=1; i<=t; i++) solve();

}


Measured memory_bytes: 9548
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

type P struct {
	l, r int
}

func main() {
	var N, K int
	fmt.Scanf("%d %d\n", &N, &K)
	m := map[int]bool{}
	for i := 0; i < K; i++ {
		var d int
		fmt.Scanf("%d\n", &d)
		for j := 0; j < d; j++ {
			var a int
			fmt.Scan(&a)
			m[a] = true
		}
	}
	cnt := 0
	for i := 1; i <= N; i++ {
		if !m[i] {
			cnt++
		}
	}
	fmt.Println(cnt)

}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 2528
#include<stdio.h>
#include<string.h>
int main(void){
	char name1[200],name2[100];
	scanf("%s%s",name1,name2);
	sprintf(name1,"%s%s",name1,name1);
	if(strstr(name1,name2)==NULL){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

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

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 105;
const int oo = 1000000007;

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


int n, m, dist[MAXN][MAXN];
char s[MAXN][MAXN];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; ++i)
        scanf("%s", s[i]);

    // for(int i = 0; i < n; ++i)
    //     printf("%s\n", s[i]);

    for(int x = 0; x < n; ++x)
        for(int y = 0; y < m; ++y)
            dist[x][y] = oo;
    dist[0][0] = 0;
    
    deque<pii> q;
    q.push_back({0, 0});

    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop_front();

        for(int dir = 0; dir < 2; ++dir) {
            int u = x + dx[dir], v = y + dy[dir];
            if (u >= 0 && u < n && v >= 0 && v < m) {
                int cost = (s[u][v] != s[x][y]);
                // printf("%d %d %d %d %c %c %d\n", x, y, u, v, s[x][y], s[u][v], cost);
                if (dist[x][y] + cost < dist[u][v]) {
                    dist[u][v] = dist[x][y] + cost;
                    if (cost == 0)
                        q.push_front({u, v});
                    else 
                        q.push_back({u, v});
                }
            }
        }
    }

    // for(int x = 0; x < n; ++x) {
    //     for(int y = 0; y < m; ++y)
    //         printf("%d ", dist[x][y]);
    //     puts("");
    // }
    
    int cnt;
    if (s[0][0] == '#' && s[n-1][m-1] == '#')
        cnt = dist[n-1][m-1]/2 + 1;
    else if (s[0][0] == '.' && s[n-1][m-1] == '.')
        cnt = dist[n-1][m-1]/2;
    else 
        cnt = (dist[n-1][m-1] + 1) / 2;

    int ans = cnt;

    printf("%d\n", ans);

    return 0;
}

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

using namespace std;
// using Graph = vector<vector<ll>>;

typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

string s[50000];
int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll n;
  string str, p, q;
  cin >> n;
  for (i = 0; i < n; i++)
  {
    str += '0' + i + 1;
  }
  for (i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    p += '0' + a;
  }
  for (i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    q += '0' + a;
  }

  sort(all(str));
  i = 0;
  do
  {
    s[i] = str;
    // cout << i << ' ' << str << endl;
    i++;
  } while (next_permutation(all(str)));

  for (i = 0; i < powll(n, n); i++)
  {
    if (s[i] == p)
    {
      ans += i + 1;
      // cout << "p " << i << endl;
      break;
    }
  }

  for (i = 0; i < powll(n, n); i++)
  {
    // cout << q << " " << s[i] << endl;
    if (s[i] == q)
    {
      ans = abs(ans - (i + 1));
      // cout << "q " << i << endl;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
bool praime_numbers[100001];


static const long long MOD = 1000000007;

const int int_inf = 2147483647;
const ll long_inf = 9223372036854775807ll;

#define rep(i,n) for(int i = 0;i<n;i++)
//#define rep(j,n) for(int j = 0;j<n;j++)
#define defvi(a,c) vector<int>(a,c)
#define defvvi(a,b,c) vector<vector<int>>(a, vector<int>(b, c))

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

long long factorial(long long x) {
	long long n = 1;
	for (ll i = 1; i <= x; i++) {
		n = (n * i) % MOD;
		//if (n == 0) { cout << i << endl; }
	}
	n %= MOD;
	return n;
}


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;
}

void check_1D(vector<int>& ls);
void check_2D(vector<vector<int>>& ls);
void check_1D_l(vector<ll>& ls);
void check_2D_l(vector<vector<ll>>& ls);




int main(void)
{
	long long x, y, a, b, ans;
	cin >> x >> y;
	a = (2 * y - x) / 3;
	b = (2 * x - y) / 3;
	ans = modinv(factorial(a), MOD) * modinv(factorial(b), MOD) % MOD;
	ans *= factorial(a + b) % MOD;
	ans %= MOD;
	if (((2 * y - x) % 3 != 0) or ((2 * x - y) % 3 != 0) or x == 0 or y == 0 or a < 0 or b < 0) {
		cout << 0;
	}
	else {
		cout << ans;
	}
}


//デバック用関数
//一次元の配列を出力する関数
void check_1D_l(vector<ll>& ls) {
	int length = ls.size();
	for (int i = 0; i < length; i++) {
		cout << ls[i] << ' ';
	}
	cout << endl;
}


//デバック用関数
//一次元の配列を出力する関数
void check_1D(vector<int>& ls) {
	int length = ls.size();
	for (int i = 0; i < length; i++) {
		cout << ls[i] << ' ';
	}
	cout << endl;
}

//二次元配列を出力する関数
void check_2D_l(vector<vector<ll>>& ls) {
	for (int i = 0; i < ls.size(); i++) {
		for (int j = 0; j < ls[0].size(); j++) {
			cout << ls[i][j] << ' ';
		}
		cout << endl;
	}
}

//二次元配列を出力する関数
void check_2D(vector<vector<int>>& ls) {
	for (int i = 0; i < ls.size(); i++) {
		for (int j = 0; j < ls[0].size(); j++) {
			cout << ls[i][j] << ' ';
		}
		cout << endl;
	}
}

//Union Find
class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] memo = new int[4];

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                string[] data = input.Split(',');

                switch (data[1])
                {
                    case "A":
                        memo[0]++;
                        break;
                    case "B":
                        memo[1]++;
                        break;
                    case "AB":
                        memo[2]++;
                        break;
                    case "O":
                        memo[3]++;
                        break;
                }
            }
            for (int i = 0; i < 4; i++) Console.WriteLine(memo[i]);
        }
    }
}

Measured memory_bytes: 9104
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

int main(){
int a, b, n;
int ans;
cin >> n >> a >> b;
ans = min(a*n,b);
cout << ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s == "A") cout << "T" << endl;
	if (s == "T") cout << "A" << endl;
	if (s == "G") cout << "C" << endl;
	if (s == "C") cout << "G" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

   int p[N];
   int count = 0;

   for (int i = 1; i <= N; i++) {
      scanf("%d", &p[i]);

      if (i != p[i])
         count++;
   }

   if (count < 3)
      printf("YES\n");
   else
      printf("NO\n");

   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  char S[3][101];
  int idx[3]={0, 0, 0};
  int l[3];
  int res=0;
  cin >> S[0] >> S[1] >>S[2];

  rep(i,3) l[i] = strlen(S[i]);

  int turn=0;

  for(;;){
    char c = S[turn][idx[turn]];
    //cout << turn << ":" << idx[turn] << ":" << c << endl;                     
    if(idx[turn]==l[turn]) {
      res=turn;
      break;
    }
    idx[turn]++;
    if(c=='a') turn = 0;
    if(c=='b') turn = 1;
    if(c=='c') turn = 2;
  }

  if(res==0) cout << "A" << endl;
  else if(res==1) cout << "B" << endl;
  else cout << "C" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (S[i] == T[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 888
import sys

# sys.stdin = open('b1.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()
    s = read_str()
    x = 0
    res = 0
    for l in s:
        if l == 'I':
            x += 1
        else:
            x -= 1
        if x > res:
            res = x
    print(res)


main()


Measured memory_bytes: 3060
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		int n;
		int money = 100000;
		
		n = stdIn.nextInt();
		for (int i = 0; i < n; i++){
			money *= 1.05;
			if (money % 1000 != 0){
				money /= 1000;
				money *= 1000;
				money += 1000;
			}
		}
		System.out.println(money);
	}
}

Measured memory_bytes: 17160
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long mod = 1e9 + 7;
void get_prime_factors(vector<int> &primes_count, int n) {
	while (n % 2 == 0) {
		++primes_count[2];
		n >>= 1;
	}

	for (int i = 3; i * i <= n; i += 2) {
		while (n % i == 0) {
			++primes_count[i];
			n /= i;
		}
	}

	if (n > 2) {
		++primes_count[n];
	}
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> prime_count(n + 1);
	for (int i = 1; i <= n; ++i) {
		get_prime_factors(prime_count, i);
	}

	long long ans = 1;
	for (int i = 1; i <= n; ++i) {
		ans *= (prime_count[i] + 1);
		ans %= mod;
	}

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int

	fmt.Scanf("%d %d", &n, &k)

	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	pos := 1
	prev := pos
	memo := []int{1}
	var i int

	for i = 0; i < k; i++ {
		prev = pos
		pos = a[pos]
		a[prev] = -(i + 1)
		if pos < 0 {
			break
		}
		memo = append(memo, pos)
	}

	if i == k {
		fmt.Println(pos)
	} else {
		j := -pos
		k1 := k - j
		l := len(memo) - j
		mod := k1 % l
		fmt.Println(memo[j+mod])
	}
}


Measured memory_bytes: 10712
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  string S;
  cin >> N >> S;
  int i = 0, count = 0;
  while (i < N) {
    if (S[i] == 'A') {
      if (i < N - 2 && S[i + 1] == 'B' && S[i + 2] == 'C') {
        count++;
      }
    }
    i++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define NMAX 3000

using namespace std;

int n;
long long v[NMAX+10], dp[NMAX+10][NMAX+10];

int main()
{
    cin >> n;
    for(int i=1; i<=n; i++) cin >> v[i];
    for(int len=0; len<n; len++)
        for(int st=1; st<=n-len+1; st++)
            {   int dr = st + len;
                dp[st][dr] = max(v[st] - dp[st+1][dr], v[dr] - dp[st][dr-1]);
            }
    cout << dp[1][n] << '\n';
    return 0;
}


Measured memory_bytes: 70016
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    private static int[] dx = { 0, 1, 0, -1 };
    private static int[] dy = { 1, 0, -1, 0 };
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        string S = NextString();
        //if (S.All(c => c == '1')) { Console.WriteLine(N); return; }
        List<Pair> a = new List<Pair>();
        int zero_count = 0;
        int one_count = 0;
        bool one = (S[0] == '1' ? true : false);
        Pair p;
        for (int i = 0; i < N; i++)
        {
            if (one && S[i] == '1') one_count++;
            else if (one && S[i] == '0')
            {
                one = false;
                zero_count++;
            }
            else if (!one && S[i] == '0') zero_count++;
            else if (!one && S[i] == '1')
            {
                p.x = one_count;
                p.y = zero_count;
                a.Add(p);
                zero_count = 0;
                one_count = 1;
                one = true;
            }
        }
        p.x = one_count;
        p.y = zero_count;
        a.Add(p);
        //a.ForEach(v => Console.WriteLine(v.x + " " + v.y));
        long box = a[0].x;
        long ans = 0;
        int count = 0;
        for (int i = 0; i < a.Count(); i++)
        {
            count++;
            if (count <= K)
            {
                //Kまでは無限につなげてOK
                box += a[i].y;
                if (i + 1 != a.Count()) box += a[i + 1].x;
            }
            else
            {
                //それ以降はしゃくとりhou
                box -= a[i - K].x + a[i - K].y;
                box += a[i].y;
                if (i + 1 != a.Count()) box += a[i + 1].x;
            }
            ans = Math.Max(ans, box);
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;

int main(){
ll n,a,b;
cin >> n >> a >> b;

ll k = n/(a+b);//塊
ll h = n%(a+b);//端数
if(h > a) h = a;

ll ans = a*k + h;
cout << ans << endl; 
}

Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	// 入力
	int N;
	cin >> N;
	
	ll ans = 0;
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		ans += (b - a + 1);
	}

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


Measured memory_bytes: 256