akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
  int a,b;
  int n = 0;
  int k = 1;
  int i = 0;
  int x[200]={};
   
    
    
  while(i < 200 && cin >> a >> b){
      
      //条件に合わないデータの判定
      if(a < 0 || a > 1000000 || b < 0 || b > 1000000){
          cout << "データを入力し直してください!!" << endl;
          break;
      }
      
      else{
          i++;
          n = a+b;
          
    //桁数判定部分
    while(n/10 !=0){
        k++;
        n = n/10;
    }
          x[i-1] = k;
          k = 1;
      }
  }
    
    //表示部分
    for(int j = 0;j < i;j++)
        cout << x[j] << endl;
    
  return 0;
}



Measured memory_bytes: 3020
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};
ll const MAX = 100005;
ll a[MAX];

int main() {
	ll n;
	cin >> n;
	REP(i, 1, n) {
		cin >> a[i];
	}
	SORT(a, n);
	a[0] = 0;
	ll ans = 0;
	REP(i, 1, n) {
		ll x = a[i] - a[i - 1];
		if (x % 2 == 1) {
			ans ^= n + 1 - i;
		}
	}
	if (ans == 0) {
		cout << "second" << endl;
	}
	else {
		cout << "first" << endl;
	}
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n;
    cin>>n;
    vector<ll> h(n);
    for (int i = 0; i < n; i++)
    {
        cin>>h[i];
    }
    h[0]--;
    for (int i = 1; i < n; i++)
    {
        if(h[i-1]<h[i]) h[i]--;
    }
    bool ok = true;
    for (int i = 1; i < n; i++)
    {
        if(h[i-1]>h[i]) 
        {
            ok=false;
            break;
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;    

    return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

const MOD = 1000000007

func pow(x, n int64) int64 {
	ret := int64(1)
	for i := int64(0); i < n; i++ {
		ret *= x
		ret %= MOD
	}

	return ret
}

func main() {
	var n int64
	fmt.Scan(&n)
	ans := (pow(10, n) - 2*pow(9, n)%MOD + pow(8, n) + MOD) % MOD

	fmt.Println(ans)

}


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

int r[101010][3];

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

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		int a, b, c;
		cin >> a >> b >> c;

		if (i == 0) {
			r[i][0] = a;
			r[i][1] = b;
			r[i][2] = c;
			continue;
		}
		r[i][0] = max(r[i-1][1], r[i-1][2]) + a;
		r[i][1] = max(r[i-1][0], r[i-1][2]) + b;
		r[i][2] = max(r[i-1][0], r[i-1][1]) + c;
	}
	cout << max(r[n-1][0], max(r[n-1][1], r[n-1][2])) << '\n';
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
string s,yl="AKIHABARA";
int n,l;
int main()
{
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]==yl[n])
            n++;
        else
        {
            if(i>0)
            if(s[i]==s[i-1])
            {
                cout<<"NO"<<endl;
                exit(0);
            }
            if(yl[n]=='A')n++,i--;
            else
            {
                cout<<"NO"<<endl;
                exit(0);
            }
        }
    }
    l=s.length();
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='A')l--;
    }
    if(l==5)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}

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

int main(){
  int N;
  cin >> N;
  int a=N;
  int s=0;
  for(int i=0;i<10;i++){
    s+=a%10;
    a/=10;
  }
  if(N%s==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(){
int n,i,kari,ri;
kari=100000;
scanf("%d",&n);
for(i=0;i<n;i++){
ri=kari*5;
ri=ri/100;
kari=kari+ri;
if(kari%1000>0){
kari=kari/1000;
kari++;
kari=kari*1000;
}

}
printf("%d\n",kari);

return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  string X,Y;
  int ans=0;

  for (int i = 1; i < N; i++) {
    X=S.substr(0,i);
    Y=S.substr(i);
    int cnt=0;
    vector<int> A(26);
    vector<int> B(26);
    for (int j = 0; j < X.size(); j++) {
      A.at(X.at(j)-'a')++;
    }
    for (int j = 0; j < Y.size(); j++) {
      B.at(Y.at(j)-'a')++;
    }
    for (int k = 0; k < 26; k++) {
      if(A.at(k)>0&&B.at(k)>0) cnt++;
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int c[10][10];

int main()
{
    cin >> N;
    repe(i, 1, N)
    {
        int end = i % 10;
        int top = i;
        while (top >= 10)
        {
            top /= 10;
        }
        c[top][end]++;
    }

    ll ans = 0;
    repe(i, 1, 9)
    {
        repe(j, 1, 9)
        {
            ans += c[i][j] * c[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	int A, B;
	cin >> A >> B;
	int result = B % A == 0 ? A + B : B - A;
	cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N, M;
    cin >> N >> M;
    if(N == 1 && M == 1){
        cout << 1 << endl;
    }else if(N == 1){
        cout << M-2 << endl;
    }else if(M == 1){
        cout << N-2 << endl;
    }else{
        cout << (N-2) * (M-2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ');
  function buildMaxHeap(arr) {
    const n = arr.length;
    const maxHeapify = (i) => {
      let left, right, largest = i;
      left = 2 * i + 1;
      right = 2 * i + 2;
      if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left;
      if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
      if (largest != i) {
        arr[largest] = arr[i] + (arr[i] = arr[largest], "");
        maxHeapify(largest);
      }
    };
    for (let i = Math.floor(n / 2 - 1); i >= 0; i--) maxHeapify(i);
  }
  buildMaxHeap(arr);
  console.log(' ' + arr.join(' '));
})();



Measured memory_bytes: 73616
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

ll calc_xor(ll n)
{
    ll res = 0;
    ll base = 1;
    while (base <= n)
    {
        ll cnt = 0;
        cnt = (n + 1) / (base * 2) * base + max(0LL, (n + 1) % (base * 2) - base);
        // cout << base << ' ' <<  n / (base * 2) * base << ' ' << n % (base * 2) - base << endl;
        res += cnt % 2 * base;
        base <<= 1;
    }
    return res;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    // cout << calc_xor(b) << endl;

    ll ans = calc_xor(b);
    if (a > 0)
        ans ^= calc_xor(a - 1);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n & 1)
		return cout << "No" << '\n', 0;
	for (int i = 0; i < n / 2; ++i)
	{
		if (s[i] != s[i + n / 2])
			return cout << "No" << '\n', 0;
	}
	cout << "Yes" << '\n';
	return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

  int n;
  cin >> n;

  long long ans = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += mp[i - a];
    mp[a + i]++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 20716
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint X;
	cin >> X;

	lint y = 100;
	for (int i = 1; i < 4000; i++) {
		y = (1.01 *y);
		if (X <= y) {
			cout << i << "\n";
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3692
#include <iostream>
using namespace std;

int main(void){
   int m, f, r;

while(1){
   cin >> m >> f >> r;
   if(m == -1 && f == -1 && r == -1) break;

   if(m == -1 || f == -1){
       cout << 'F';
   }else if(m+f >= 80){
      cout << 'A';
   }else if (m+f >= 65){
      cout << 'B';
   }else if (m+f >= 50){
      cout << 'C';
   }else if (m+f >= 30){
      if(r >= 50)
      cout << 'C';
      else cout << 'D';
   }else {
      cout << 'F';
   }
   cout << endl;
}
}


Measured memory_bytes: 3100
// #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
using VV = vector<V>;

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 A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a) {
    if (a == 2) return true;
    if (a <= 1 || a % 2 == 0) return false;

    for (int i = 3; i * i <= a; i += 2) {
        if (a % i == 0) return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> aaa;
// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (aaa[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok =
        (int)aaa
            .size();  // 「index =
                      // a.size()-1」が条件を満たさないこともあるので、初期値は
                      // a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

void memo() {
    int n = 100;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    vector<int> ans(n);
    iota(ans.begin(), ans.end(), 0);
    sort(ans.begin(), ans.end(), [&](int i, int j) { return a[i] < a[j]; });

    double t1 = 0.1;
    cout << fixed << setprecision(6) << t1 << endl;
}

int main() {
    int n, m;
    cin >> n >> m;

    dsu d(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        d.merge(--a, --b);
    }

    auto vv = d.groups();
    cout << vv.size() - 1 << endl;
    return 0;
}


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

int main(){
  vector<vector<int>> C(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> C.at(i).at(j);
    }
  }
  int count=0;
  for(int i=1;i<3;i++){
    if(C.at(i).at(0)-C.at(0).at(0)==C.at(i).at(1)-C.at(0).at(1)
       && C.at(i).at(1)-C.at(0).at(1)==C.at(i).at(2)-C.at(0).at(2)){
      count++;
    }
  }
  if(count==2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
typedef long long ll;

int main()
{
	string c[3];
	rep(i, 3) cin >> c[i];
	cout << c[0][0] << c[1][1] << c[2][2] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int maxx(int a,int b)
{
  if(a<b)
    return b;
  return a;
}
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int i=0,j=0,k=0,c=0;
  while(k<n-1)
  {
    if(a[k]>=a[k+1])
      j++;
    else
    {i=k+1;
    j=k+1;}
    k++;
    c=maxx(c,j-i);
    //cout<<c<<" ";
  }
  cout<<c;
  return 0;
}


Measured memory_bytes: 640
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

	static boolean[] used = new boolean[10];
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		while(true){
			try{
				int n = scan.nextInt();
				int s = scan.nextInt();
				System.out.println(solve(n, s));
			}catch(NoSuchElementException e){
				break;
			}
		}
	}

	//大きい値から計算していく
	private static int solve(int numRemained, int s){
//		System.out.printf("%d %s\n", numRemained, s);
		if(numRemained == 1){
			if(s <= 9 && used[s] == false)
				return 1;
			else
				return 0;
		}
		
		int c = 0;
		for(int i = 9; i >= 0; i--){
			if(used[i])	continue;
			used[i] = true;
			int sum =  s - numRemained * i;
			if(sum >= 0)
				c += solve(numRemained - 1, sum);
			used[i] = false;
		}
//		System.out.println(c);
		return c;
	}
}

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

int powint(int n){
    int x = 1;
    rep(i,n){
        x *= 10;
    }
    return x;
}

int midcnt(int x){
    string s = to_string(x);
    s = s.substr(1,s.size()-2);
    if(s.empty()) return 0;
    return stoi(s) + 1;
}

int main(){
    int n;
    cin >> n;
    int mdcnt = midcnt(n);
    // cout << mdcnt << endl;
    int nd;
    char nt, nb;
    string ns = to_string(n);
    nd = ns.size();
    nt = ns.at(0);
    nb = ns.at(ns.size()-1);
    ll cnt = 0;
    for(int x=1;x<=n;x++){
        string xs = to_string(x);
        int xdst = xs.size();
        char a,b;
        int addcnt = 0;
        a = xs.at(0);
        b = xs.at(xs.size()-1);
        if(b == '0') continue;
        for(int xd=1;xd<=nd;xd++){
            if(xd == 1){
                if(a==b) addcnt += 1;
            }
            else if(xd == 2){
                string tmp = "";
                tmp += b;
                tmp += a;
                int y = stoi(tmp);
                // cout << y << endl;
                if(y <= n) addcnt += 1;
            }
            else{
                if(nd == xd){
                    if(b < nt){
                        addcnt += powint(xd-2);
                    }
                    else if(b == nt){
                        if(a <= nb){
                            addcnt += mdcnt;
                        }
                        else{
                            addcnt += max(mdcnt-1,0);
                        }
                    }
                } else {
                    addcnt += powint(xd-2);
                }
            }
        }
        // if(addcnt > 0 && x > n-10) std::cout << x << " " << addcnt << endl;
        cnt += addcnt;
    }
    std::cout << cnt << endl;
    return 0;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
  int d, t, s;

  cin >> d >> t >> s;

  cout << (d <= t * s ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ara[102];

int main()
{
    int n,m,i,sum=0,rm,cnt=0;
    cin>>n>>m;
    for(i=0; i<n; i++)
    {
        cin>>ara[i];
        sum+=ara[i];
    }
    rm=sum/(4*m);
    if(sum%(4*m)>0)rm++;
    for(i=0; i<n; i++)
    {
        if(ara[i]>=rm)cnt++;
    }
    if(cnt>=m)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, W;
  cin >> N >> W;
  vvi WV(N, vi(2));
  cin >> WV;

  vi dp(W+1, 0);
  rep(i, N){
    rrep(j, W, 0){
      if(j - WV[i][0] >= 0){
        chmax(dp[j], dp[j - WV[i][0]] + WV[i][1]);
      }
    }
  }
  cout << dp[W] << "\n";
}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5005,M=1e9+7;
int n,m,g[N][N],f[N][N],fac[N],inv[N];
inline int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;
}
signed main(){
	scanf("%lld%lld",&m,&n);
	fac[0]=inv[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*2%M,inv[i]=ksm(fac[i],M-2);
	for (int i=1;i<=n;i++)f[0][i]=1,g[0][i]=(g[0][i-1]+inv[i+1]*i)%M;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=n;j++){
			(f[i][j]+=g[i-1][j-1]*fac[j]+f[i-1][j]*(j+1))%=M;
			(g[i][j]+=g[i][j-1]+f[i][j]*inv[j+1]%M*j)%=M;
		}
	printf("%lld\n",f[m][n]);
}
 


Measured memory_bytes: 394896
s = list(input())
t = list(input())

ans = False

for _ in range(len(t)):
    if s == t:
        ans = True
        break
    else:
        tmp = t[0]
        t.remove(t[0])
        t.append(tmp)

if ans:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
import sys
S = input()
S_list = list(S)

l = len(S)


if len(S) % 2 == 0:
  ideal1 = list('01' * int(l / 2))
  ideal2 = list('10' * int(l / 2))
else:
  ideal1 = list('01' * (l // 2) + '0')
  ideal2 = list('10' * (l // 2) + '1')

ans = 0
ans1 = 0

for base,compe1 in zip(S_list,ideal1):
    if base != compe1:
        ans = ans + 1

for base,compe2 in zip(S_list,ideal2):
    if base != compe2:
        ans1 = ans1 + 1

print(min(ans,ans1))

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

lli data[400];
lli n,m;

void solve(map<lli,vector<lli>> &v,set<lli> &s){
	REP(i,0,400)data[i] = 0;

	for(lli i=0;i<n;i++){
		for(lli j=0;j<m;j++){
			auto itr = s.find(v[i][j]);
			if(itr == s.end())continue;

			data[v[i][j]]++;
			break;
		}
	}
}

signed main(){

	cin>>n>>m;

	map<lli,vector<lli>> v;

	REP(i,0,n)REP(j,0,m){
		lli tmp;
		cin>>tmp;
		tmp--;
		v[i].push_back(tmp);
	}

	set<lli> sports;

	REP(i,0,m)sports.insert(i);

	lli ans = INF;

	while(sports.size()){
		solve(v,sports);

		lli maxSports=0;
		lli maxIndex =0;
		for(lli i=0;i<m;i++){
			if(maxSports < data[i]){
				maxSports = data[i];
				maxIndex = i;
			}
		}
		if(DEBUG)cout<<"maxSports="<<maxSports<<endl;
		if(DEBUG)cout<<"maxINdex="<<maxIndex<<endl;
		ans = min(ans,maxSports);
		sports.erase(maxIndex);
	}

	cout<<ans<<endl;




	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

LL comb(LL n, LL k){
	LL res=1;
	for(LL i=0; i<k; i++){
		res*=(n-i);
		res/=(i+1);
	}
	return res;
}

int main(){
	int N, P;
	cin >> N >> P;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	LL ans=0, odd=0;
	rep(i,N) if(A[i]%2) odd++;
	LL c=0, k=0;
	while(k<=odd){
		c+=comb(odd,k);
		k+=2;
	}
	ans=c*pow(2,N-odd);
	if(P) ans=pow(2,N)-ans;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    // O(N^2 log N)
    int N, K;
    cin >> N >> K;
    vector<i64> A(N), B, C;
    B.reserve((N * (N - 1)) / 2);
    for(i64 &a : A) cin >> a;
    for(int i = 0; i < N; i++) {
        i64 S = 0;
        for(int j = i; j < N; j++) {
            S += A[j];
            B.push_back(S);
        }
    }
    i64 ans = 0;
    for(int b = 40; b >= 0; b--) {
        int cnt = 0;
        C.clear();
        for(i64 x : B) {
            if(x & (1ll << b)) {
                C.push_back(x);
                cnt++;
            }
        }
        if(cnt >= K) {
            ans |= 1ll << b;
            swap(B, C);
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int a;
  cin >> a;
  cout << a + a*a +a*a*a << endl;
 
  return 0;
}

Measured memory_bytes: 3632
N = int(input())
 
for h in range(1, 3501):
  for n in range(1, 3501):
    a = (4 * h * n) - N * h - N * n
    if a <= 0:
      continue
    w = (N * h * n) / a
    if w.is_integer() and 0 < w:
      print(h, n, int(w))
      exit(0)

Measured memory_bytes: 9136
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        for (int i = 0; i < n; i++) {
            String v = s.substring(i);
            if (t.startsWith(v)) {
                System.out.println(2 * n - v.length());
                return;
            }
        }
        System.out.println(2 * n);
    }
}


Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	static IntStream REPS(int l) {
		return IntStream.range(0,l);
	}
	public static void main(String[]__){
		int[]m=new int[26];
		for(char c:s.next().toCharArray())
			m[c-'a']++;
		System.out.println(
				Arrays.stream(m).anyMatch(i->i>1)
				?"no":"yes"
				);
	}
}


Measured memory_bytes: 28884
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll MOD = 1e9 + 7;
ll H, N, M, L, K, W, X, Y, Z;
ll ans = 0;
const int MAX = 210000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	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;
}

int main() {
	COMinit();
	cin >> N >> M;
	vector<ll> v;
	for (ll j = 2; j*j <= M; j++) {
		ll tmp = 0;
		while (M%j == 0) {
			M /= j;
			tmp++;
		}
		v.push_back(tmp);
	}
	if (M != 1)v.push_back(1);
	ans = 1;
	for (int i = 0; i < v.size(); i++) {
		ans = (COM(v[i] + N-1, N-1)*ans)%MOD;
	}
	cout << ans << endl;
}


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

int main()
{
  string S;
  cin >> S;
  int64_t Q, t;
  cin >> Q;
  bool reversed = 0;
  deque<char> dq;
  for (int i = 0; i < S.size(); i++)
  {
    dq.push_back(S[i]);
  }
  int f;
  char c;
  for (int i = 0; i < Q; i++)
  {
    cin >> t;
    if (t == 1)
    {
      reversed = !reversed;
    }
    else
    {
      cin >> f >> c;
      if ((f == 1 && !reversed) || (f == 2 && reversed))
      {
        dq.push_front(c);
      }
      else
      {
        dq.push_back(c);
      }
    }
  }
  if (reversed)
  {
    while (dq.size())
    {
      cout << dq.back();
      dq.pop_back();
    }
  }
  else
  {
    while (dq.size())
    {
      cout << dq.front();
      dq.pop_front();
    }
  }
  cout << endl;
}

Measured memory_bytes: 4040
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int N,tt,xx,yy,move,tmp;
    bool ans=true;
    int t[100005],x[100005],y[100005];
    cin>>N;  
    for(int i=0;i<N;i++){
        cin >> t[i] >> x[i] >> y[i];
    }

    for(int i=0;i<N;i++){
        if(i==0){
            tt = t[i];
            xx = x[i];
            yy = y[i];
        }else{
            tt = t[i]-t[i-1];
            xx = abs(x[i]-x[i-1]);
            yy = abs(y[i]-y[i-1]);
        }
        move= xx + yy;
        tmp = tt - move;
        //cout <<move;
        //cout<<(tmp) % 2<<endl;
        //||(tmp % 2 == 1 && tt % 2 == 1)
        if(tmp >= 0){
            if(tmp % 2 == 0){
            }else{
                ans = false;
                break;
            }
        }else{
            ans = false;
            break;
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N,K,S=map(int,input().split())
    if S>1:
        print(*[S]*(K)+[S-1]*(N-K))
    else:
        print(*[S]*(K)+[S+1]*(N-K))


resolve()

Measured memory_bytes: 45356
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int N, A, B;
  scanf("%d", &N);
  if (N == 2)
    scanf("%d %d", &A, &B);
  if (N == 1)
    printf("Hello World\n");
  else
    printf("%d\n", A + B);
  
  return 0;
}


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

using namespace std;

int main(void) {
	int num, i, x, ans = 0;
	cin >> num >> x;
	vector<int> d(num);
	for (i = 0; i < num; i++)
		scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	i = 0;
	while (i < num) {
		x -= d[i++];
		if (x >= 0)
			ans++;
		else
			break;
	}
	if (x > 0)
		ans--;
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int main()
{
  int n, input;
  cin >> n;

  vector<int> v;
  for (int i = 0; i < n; i++)
  {
    cin >> input;
    v.push_back(input);
  }

  reverse(v.begin(), v.end());

  for (int i = 0; i < n - 1; i++)
  {
    cout << v[i] << " ";
  }
  cout << v[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	vector<PII> A(N), B(N);
	foreach(i, B)cin>>i.first>>i.second;
	foreach(i, A)cin>>i.first>>i.second;
	sort(ALL(A));
	sort(ALL(B));
	vector<int> y;
	int p = 0;
	int ans = 0;
	foreach(i, A){
		while(p < N && B[p].first < i.first)y.push_back(B[p++].second);
		sort(ALL(y));
		int ln = lower_bound(ALL(y), i.second) - y.begin();
		if(ln){
			y.erase(y.begin()+ln-1);
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	n := scanInt(sc)
	ds := nextIntSlice(sc, n)
	problems := map[int]int{}
	for _, v := range ds {
		problems[v]++
	}
	m := scanInt(sc)
	ts := nextIntSlice(sc, m)
	for _, v := range ts {
		rest := problems[v]
		if rest == 0 {
			fmt.Println("NO")
			return
		}
		problems[v] = rest - 1
	}
	fmt.Println("YES")
	return
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 17220
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll N;
vector<ll> v;
void search(ll x){
  if(x > N){
    return;
  }
  v.push_back(x);
  if(x * 10 + 3 <= N){
    search(x * 10 + 3);
  }
  if(x * 10 + 5 <= N){
    search(x * 10 + 5);
  }
  if(x * 10 + 7 <= N){
    search(x * 10 + 7);
  }
}

int main(){
  cin >> N;
  ll ans = 0;
  search(3);
  search(5);
  search(7);
  for(ll c:v){
    bool flag3 = false;
    bool flag5 = false;
    bool flag7 = false;
    ll t = c;
    while(t > 0){
      if(t % 10 == 3) flag3 = true;
      else if(t % 10 == 5) flag5 = true;
      else if(t % 10 == 7) flag7 = true;

      t /= 10;
    }
    if(flag3 && flag5 && flag7){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(int argc, char const *argv[]) {
    int h, a;
    cin >> h >> a;

    int ans = 0;
    while (h > 0) {
        h -= a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

// dijkstra(O((E+V)log(v)))
template<class T>
struct dijkstra {
    struct edge{int to, cost;};
    vector<T> d;
    vector<vector<edge>> G;
    T init_v;

    dijkstra(int n, T init_v): init_v(init_v) {init(n);} 

    void init(int n) {
        G.resize(n);
        d.resize(n);
        rep(i,n) d[i] = init_v;
    }

    void add_edge(int s, int t, int cost) {
        edge e;
        e.to = t; e.cost = cost;
        G[s].push_back(e);
    }

    void run(int s) {
        priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
        d[s] = 0;
        q.push(pair<T,int>(0,s));
        while (!q.empty()) {
            pair<T,int> e = q.top(); q.pop();
            int v = e.second;
            if (d[v] < e.first) continue;
            for (auto e: G[v]) {
                if (chmin(d[e.to],d[v]+e.cost)) {
                    q.push(pair<T,int>(d[e.to],e.to));
                }
            }
        }
    }
};

int main() {
    int n, m; cin >> n >> m;
    int s, t; cin >> s >> t;
    s--; t--;
    dijkstra<ll> dj_s(n,inf_l), dj_t(n,inf_l);
    rep(i,m) {
        int u, v, a, b; 
        cin >> u >> v >> a >> b;
        u--; v--;
        dj_s.add_edge(u,v,a);
        dj_s.add_edge(v,u,a);
        dj_t.add_edge(u,v,b);
        dj_t.add_edge(v,u,b);
    }
    dj_s.run(s); dj_t.run(t);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> cost;
    rep(i,n) cost.push(make_pair(dj_s.d[i]+dj_t.d[i],i+1));
    ll init_v = 1e15;
    rep(i,n) {
        auto p = cost.top();
        if (i < p.second) printf("%ld\n",init_v-p.first);
        else {
            while (i >= p.second) {
                cost.pop();
                p = cost.top();
            }
            printf("%ld\n",init_v-p.first);
        }
    }
}

Measured memory_bytes: 19700
#include<cstdio>
const int MaxN=2010,mod=924844033;
int N,K,fa[MaxN*2],siz[MaxN*2],f[MaxN*2][MaxN];
bool ty[MaxN*2];
int find(int i){return fa[i]==i?i:fa[i]=find(fa[i]);}
void mer(int i,int j){siz[j=find(j)]+=siz[i=find(i)];fa[i]=j;}
int main(){
	scanf("%d%d",&N,&K);
	for(int i=0;i<N*2;i++)
		if(i<N-K||i>=N+K)fa[i]=i,siz[i]=1;
	for(int i=0;i<N;i++){
		if(i>=K&&i<N-K)mer(i,i+N);
		if(i+K*2<N)mer(i,i+N+K*2);
	}
	int sz=0;
	ty[0]=1;
	for(int i=0;i<N*2;i++)
		if(fa[i]==i)ty[sz+=siz[i]]=1;
	f[0][0]=1;
	for(int i=0;i<sz;i++)
		for(int j=0;j<=i+1&&j<=N;j++){
			f[i+1][j]=f[i][j];
			if(j){
				if(ty[i])f[i+1][j]+=f[i][j-1];
				else if(i)f[i+1][j]+=f[i-1][j-1];
			}
			f[i+1][j]%=mod;
		}
	int s=0,p=1;
	for(int i=0;i<=N;i++){
		s=(s+1ll*(N-i&1?mod-p:p)*f[sz][N-i])%mod;
		p=p*(i+1ll)%mod;
	}
	printf("%d\n",s);
}

Measured memory_bytes: 30720
#include<bits/stdc++.h>
using namespace std;
int n,ans,ma;
char m;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>m;
		if(m=='I') ans++;
		else ans--;
		if(ans>ma) ma=ans;
	}
	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L+7;
int n;
int r,c,k;
vector<vector<ll>> inp;
vector<vector<vector<ll>>> dp;

ll solution (int i,int j,int cnt)
{
    if(i>r or j>c) return 0;
    if(dp[i][j][cnt] != -1) return dp[i][j][cnt];
    else
    {
        ll best=0;
        /*if(i+1<=r)
        {
            if(cnt <3 and inp[i][j] != 0) best +=inp[i][j];
            //cout<<best<<endl;
            best += solution (i+1,j,0);
            
        }
        if(j+1<=c)
        {
            if(cnt<3 and inp[i][j] != 0)
            {
                best = max(best,inp[i][j]+solution(i,j+1,cnt+1));
            }
            //cout<<best<<endl;
            best = max(best,solution(i,j+1,cnt));
            //cout<<best<<endl;
        }*/

        best = max(solution(i+1,j,0),solution(i,j+1,cnt));
        if(cnt<3) best = max(best,inp[i][j]+max(solution(i+1,j,0),solution(i,j+1,cnt+1)));
        return dp[i][j][cnt] = best;
    }
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>r>>c>>k;
        inp.assign(r+2,vector<ll> (c+2,0));
        dp.assign(r+2,vector<vector<ll>> (c+2,vector<ll> (4,-1)));

        for(int i=0;i<k;i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            inp[a][b] = c;
        }

        cout<<solution(1,1,0)<<endl;
    }
    
}


Measured memory_bytes: 707812
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define TC int tt; cin >> tt; for(int t=0; t<tt; t++)
#define ll long long
#define pb push_back
#define Mod 1000000007
#define limit 2000008
using namespace std;

void solve(int t)
{
    ll i,j,n=7,m,k,ct=1,r;
    cin >> k;
    map <ll,ll>mymap;
    while(1)
    {
        r = n%k;
        if(r==0)
        {
            cout <<ct<<endl;
            return ;
        }
        if(mymap[r])
        {
            cout <<-1<<endl;
            return ;
        }
        mymap[r]=1;
        n = r*10+7;
        ct++;
    }
}
int  main()
{
    Fast
//    Freed
//    Fout
    int tt=1,t;
  //  cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}




Measured memory_bytes: 66084
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=300300,M=100100;
int i,j,k,n,m,ch;
int T[M];
struct cc {
	int l,r;
	bool operator < (const cc &n) const {
		return r-l<n.r-n.l;
	}
} A[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void W(int x) {
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void T_add(int x,int y) {
	for (;x<=m;x+=x&-x) T[x]+=y;
}
int T_query(int x) {
	int y=0;
	for (;x;x-=x&-x) y+=T[x];
	return y;
}
int main() {
	R(n);R(m);
	for (i=1;i<=n;i++) R(A[i].l),R(A[i].r);
	sort(A+1,A+n+1);
	j=1;
	for (i=1;i<=m;i++) {
		while (j<=n && A[j].r-A[j].l+1<i) T_add(A[j].l,1),T_add(A[j].r+1,-1),j++;
		int ans=n-j+1;
		for (k=i;k<=m;k+=i) ans+=T_query(k);
		W(ans);puts("");
	}
}

Measured memory_bytes: 3584
#include<stdio.h> 
#include<stdlib.h>
#include<string.h>


int main ()  {
	int s,n,i;
	int t[50] ;
	int b[50] ;
	
	scanf("%d\n",&n) ;
	
	for (i=0;i<n;i++)  {
		scanf("%d",&t[i]) ;
 	}
 	
	for (i=0;i<n;i++)  {
		scanf("%d",&b[i]) ;
 	}
 	s=0 ;
 		for (i=0;i<n;i++)  {
		if (t[i]-b[i]>0) {
			s=s+t[i]-b[i] ;
		}
	}
		
    	printf("%d",s) ;
	
	
	

	
	return(0) ;
}

Measured memory_bytes: 128
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

void main()
{
	int X, Y, r;
	auto input = readln.split.to!(int[]);
	X = input[0];
	Y = input[1];
	while(X%Y)
	{
		r = X%Y;
		X = Y;
		Y = r;
	}
	writeln(Y);
}


Measured memory_bytes: 2460
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-03-06(Fri)
   note
**********************************************************************/

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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> a; //string: 都市, int: 点数, int: ID
  for (int i = 1; i <= N; i++) {
    string S;
    int P;
    cin >> S >> P;
    P = -P; //tupleのsortではintが小さい順になる
    a.push_back(tie(S, P, i));
  }
  sort(a.begin(), a.end());
  for(int i = 0; i < N; i++) {
    cout << get<2>(a[i]) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MAX_S 100100
#define INF 1000000007
 
int main(){
  char N[MAX_S];
  cin >> N;
  int l=strlen(N);
  int dp[l+1][13]={};
  dp[0][0] = 1;
  for(int i=0; i<l; i++){
    int a;
    if(N[i]=='?') a=-1;
    else a = N[i]-'0';
    for(int j=0; j<10; j++){
      if(a != -1 && a != j) continue;
      for(int k=0; k<13; k++){
        dp[i+1][(k*10+j)%13] += dp[i][k];
        dp[i+1][(k*10+j)%13] %= INF;
      }
    }
  }
  cout << dp[l][5] << endl;
  return 0;
}

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

ll power(ll a,ll n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a)%mod,n/2))%mod;
    }
    return power((a*a)%mod,n/2)%mod;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n,ans;
  cin>>n;
  ans = (power(10,n) - (2*power(9,n))%mod + mod + power(8,n)+mod)%mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=303;
int n,m,dp[N][N],cst[N][N],ans;
char ss[N][N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
inline int goon(int t)
{
	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) cst[i][j]=0, dp[i][j]=2e9;
	for(int i=n;i>=0;i--)
	{
		for(int j=n;j>=0;j--)
		{
			if(i==n || j==n) cst[i][j]=0;
			else cst[i][j]=cst[i+1][j+1]+ (ss[n-i][t]==ss[n-j][t+1]);
//			printf("%d asda %d %d (%d)\n",t,i,j,cst[i][j]);
		}
	}
	dp[0][0]=0;//cst[0][0];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
//			if(i+j==0) continue;
			if(i) dp[i][j]=mi(dp[i][j],dp[i-1][j]+cst[i-1][j]);
			if(j) dp[i][j]=mi(dp[i][j],dp[i][j-1]+cst[i][j-1]);
//			printf("%d asd %d %d (%d)\n",t,i,j,dp[i][j]);
		}
	}
//	printf("\n");
	return dp[n][n];
	/*dp[n][n]=0;
	for(int i=n;i>=0;i--)
	{
		for(int j=n;j>=0;j--)
		{
			if(i+1<=n) dp[i][j]=mi(dp[i][j],dp[i+1][j]+cst[i+1][j]);
			if(j+1<=n) dp[i][j]=mi(dp[i][j],dp[i][j+1]+cst[i][j+1]);
//			printf("%d asd %d %d (%d)\n",t,i,j,dp[i][j]);
		}
	}
//	printf("\n");
	return dp[0][0];*/
}
int main()
{
//	freopen("Friction.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,m);
	for(int i=1;i<=n;i++) scanf("%s",ss[i]+1);
	for(int i=1;i<m;i++) ans+=goon(i);
	printf("%d\n",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 
 
int _;
 
int n,a[200050],maxn;
long long ans;
  
int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{	
		scanf("%d",a+i);
		maxn=max(maxn,a[i]);
		ans += max(maxn-a[i],0);
	} 
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4564
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef long long ll;
ll comp(const void *a,const void *b)
{
  return *(ll *)b-*(ll *)a;
}
int main(void)
{
  ll x,y,a,b,c;
  scanf("%lld%lld%lld%lld%lld",&x,&y,&a,&b,&c);
  ll *red,*gre,*tmp;
  red=malloc(sizeof(ll)*a);
  gre=malloc(sizeof(ll)*b);
  tmp=malloc(sizeof(ll)*(x+y+c));
  for(ll i=0;i<a;i++) scanf("%lld",&red[i]);
  for(ll i=0;i<b;i++) scanf("%lld",&gre[i]);
  for(ll i=x+y;i<(x+y+c);i++) scanf("%lld",&tmp[i]);
  qsort(red,a,sizeof(ll),comp);
  qsort(gre,b,sizeof(ll),comp);
  for(ll i=0;i<x;i++) tmp[i]=red[i];
  for(ll i=0;i<y;i++) tmp[i+x]=gre[i];
  qsort(tmp,x+y+c,sizeof(ll),comp);
  ll ans=0;
  for(ll i=0;i<(x+y);i++) ans+=tmp[i];
  printf("%lld",ans);


  return 0;
}

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

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

  vector<int64_t> A(N+2);
  for (int i = 1; i < N+2; i++) {
    if (i==1) A.at(i)=0;
    else{
       A.at(i)=A.at(i-1)+i-1;
    }
  }

  vector<int64_t> B(N+2);
  for (int i = 1; i < N+2; i++) {
    if (i==1) B.at(i)=N;
    else {
      B.at(i)=B.at(i-1)+N-i+1;
    }
  }

  int64_t res=0;
  for (int i = K; i < N+2; i++) {
    res+=B.at(i)-A.at(i)+1;
  }

  cout << res%1000000007 << endl;
}

Measured memory_bytes: 6428