akhauriyash/Code-Regression huggingface dataset:
import 'dart:convert';
import 'dart:io';
import 'dart:async';

Future main() async {
  List hw = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  Stream<String> sLines =
      stdin.transform(utf8.decoder).transform(LineSplitter()); // ここ大事（複数行入力）
  int lineNum;
  lineNum = 1;
  List si = [];
  List s = [];
  await for (var line in sLines) {
    si = line.split("").map((x) => (x)).toList(); // 文字列をListに変換
    lineNum = lineNum + 1;
    s.add(si);

    if (lineNum > hw[0]) break; // ここの場所！
  }
  List afterS = s;

  for (int i = 0; i < hw[0] - 1; i++) {
    for (int j = 0; j < hw[1] - 1; j++) {
      if (afterS[i][j] == "#" || afterS[i][j] == "B") {
        if (afterS[i + 1][j] == "#" || afterS[i + 1][j] == "B") {
          afterS[i][j] = "B";
          afterS[i + 1][j] = "B";
        }
        if (afterS[i][j + 1] == "#" || afterS[i][j + 1] == "B") {
          afterS[i][j] = "B";
          afterS[i][j + 1] = "B";
        }
      }
    }
  }

  int i = hw[0] - 1;

  for (int j = 0; j < hw[1] - 1; j++) {
    if (afterS[i][j] == "#" || afterS[i][j] == "B") {
      if (afterS[i][j + 1] == "#" || afterS[i][j + 1] == "B") {
        afterS[i][j] = "B";
        afterS[i][j + 1] = "B";
      }
    }
  }
  int j = hw[1] - 1;

  for (int i = 0; i < hw[0] - 1; i++) {
    if (afterS[i][j] == "#" || afterS[i][j] == "B") {
      if (afterS[i + 1][j] == "#" || afterS[i + 1][j] == "B") {
        afterS[i][j] = "B";
        afterS[i + 1][j] = "B";
      }
    }
  }
  // print(afterS);

  for (int i = 0; i < hw[0]; i++) {
    for (int j = 0; j < hw[1]; j++) {
      if (afterS[i][j] == "#") {
        print("No");
        return;
      }
    }
  }

  print("Yes");
}


Measured memory_bytes: 13132
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

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

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n, x;
	cin >> n >> x;
	if (n < x)cout << 0 << endl;
	else {
		cout << n - x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N_MAX 200
#define D_MAX 200

typedef struct {
	short a;
	short b;
	short c;
} clothers;
/**/

short n,d,t[D_MAX];
clothers abc[N_MAX];
short dp[D_MAX][N_MAX];

short i_abs(short x){return(x<0)?-x:x;}

void solve(void)
{
	short i,j;
	for(i=0;i<d;i++){
		for(j=0;j<n;j++){
			if(!(abc[j].a <= t[i] && t[i] <= abc[j].b)){
				dp[i][j] = -1;
			}else if(!i){
				dp[i][j] = 0;
			}else{
				short k,l;
				dp[i][j] = 0;
				for(k=0;k<n;k++){
					if(!(abc[k].a <= t[i-1] && t[i-1] <= abc[k].b) || dp[i-1][k] < 0){
						continue;
					}
					l = dp[i-1][k] + i_abs(abc[j].c - abc[k].c);
					if(l > dp[i][j])dp[i][j] = l;//
				}
			}
		}
	}
	j = 0;
	for(i=0;i<n;i++)if(dp[d-1][i] > j)j = dp[d-1][i];
	printf("%hd\n",j);
	return;
}
int main(void){
	short i;
	scanf("%hd%hd",&d,&n);
	for(i=0;i<d;i++)scanf("%hd",&t[i]);
	for(i=0;i<n;i++)scanf("%hd%hd%hd",&abc[i].a,&abc[i].b,&abc[i].c);
	solve();
	return 0;
}

Measured memory_bytes: 680
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int list[][] = new int[3][3]; // 3*3の二次元配列
        // 二次元配列に値を格納
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                list[i][j] = Integer.parseInt(sc.next());
            }
        }
        final int n = Integer.parseInt(sc.next());
        for (int i = 0; i < n; i++) {
            // bの値
            int num = Integer.parseInt(sc.next());
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    // bと一致する値が二次元配列に存在する場合
                    if (list[j][k] == num) {
                        // 該当箇所を0に更新(当たりとして扱う)
                        list[j][k] = 0;
                    }
                }
            }
        }
        // 縦横斜め列のいずれか一列の要素が全て0の場合、ビンゴ達成
        if (checkBingoVertical(list) ||
                checkBingoParallel(list) ||
                checkBingoLeftUpToRightDown(list) ||
                checkBingoRightUpToLeftDown(list)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }

    // ビンゴの縦列
    private static boolean checkBingoVertical(int[][] plist) {
        final int verticalsize = plist.length;
        final int parallelsize = plist[0].length;
        HashSet<Integer> hs = new HashSet<>();
        for (int i = 0; i < verticalsize; i++) {
            hs.clear();
            hs.add(plist[0][i]);
            for (int j = 0; j < parallelsize; j++) {
                hs.add(plist[j][i]);
            }
            if (hs.size() == 1) {
                return true;
            }
        }
        return false;
    }

    // ビンゴの横列
    private static boolean checkBingoParallel(int[][] plist) {
        final int verticalsize = plist.length;
        final int parallelsize = plist[0].length;
        HashSet<Integer> hs = new HashSet<>();
        for (int i = 0; i < verticalsize; i++) {
            hs.clear();
            hs.add(plist[i][0]);
            for (int j = 0; j < parallelsize; j++) {
                hs.add(plist[i][j]);
            }
            if (hs.size() == 1) {
                return true;
            }
        }
        return false;
    }

    // ビンゴの斜め列(＼：左上から右下)
    private static boolean checkBingoLeftUpToRightDown(int[][] plist) {
        final int size = plist.length;
        HashSet<Integer> hs = new HashSet<>();
        for (int i = 0; i < size; i++) {
            hs.add(plist[i][i]);
        }
        // 1列全て0ならば、HashSetの要素は0のみ格納される
        if (hs.size() == 1) {
            return true;
        }
        return false;
    }

    // ビンゴの斜め列(／：右上から左下)
    private static boolean checkBingoRightUpToLeftDown(int[][] plist) {
        final int size = plist.length;
        HashSet<Integer> hs = new HashSet<>();
        for (int i = 0; i < size; i++) {
            hs.add(plist[i][size - 1 - i]);
        }
        if (hs.size() == 1) {
            return true;
        }
        return false;
    }

}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> k(m),p(m);
    vector<vector<int>> s(m,vector<int>(n));
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            cin>>s[i][j];        
        }
    }
    rep(i,m) cin>>p[i];
    int cnt2 =0;
    for (int bit =0; bit<(1<<n);bit++){
        bitset<10> sw(bit);
        bool ok =true;
        rep(i,m){
            int cnt =0;
            rep(j,k[i]){
                if (sw[s[i][j]-1]==1) cnt++;
            }
            if (cnt%2 != p[i]) ok =false;
        }
        if(ok) cnt2++;
    }
    cout << cnt2 <<endl;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0, last = -1; i < n; i++) {
    int t;
    cin >> t;
    if (t == last) {
      t = -1;
      ans++;
    }
    last = t;
  }
  cout << ans << endl;
  return 0;
}


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

#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#define debug(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#define debug(...) __VA_ARGS__
#endif

const int N = 1e5 + 5;



int (((((main)))))() <%
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	map<string, int> m;
	int n; cin >> n;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		auto& x = m[move(s)];
		x++;
		ans = max(ans, x);
	}

	for (auto& p : m) {
		if (p.second == ans)
			cout << p.first << endl;
	}
	
	return 0;
%>

Measured memory_bytes: 23808
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy                 \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define Open_Sesame Open()
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define Accepted 0
#define watch(x) cout << #x << " = " << x << endl;
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define pr(a) printf("%d", a)
#define scll(x) scanf("%I64d", &x)
#define prll(x) printf("%I64d", x)
#define scan(s) scanf("%[^\n]%*c", &s)
#define print(s) printf("%s", s.c_str()); // print string
#define sz(v) v.size()
typedef long long ll;
typedef vector<int> vi;
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int Mx = INT_MAX;
const int Mn = INT_MIN;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const double PI = acos(-1.0);
void Open()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
const double EPS = -1e-2;
const ll mod = ll(1e9 + 7);
const int N = 2000 + 5;

//“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent


int main() {

	Ma7moud_7amdy;
	//Open_Sesame;
	int n;
	cin >> n;
	int a = n / 500;
	n %= 500;
	int b = n / 5;

	cout << a * 1000LL + b * 5;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    int a, ans = 0;
    cin >> a;
    if (a % 2 == 0)
        cout << a / 2 - 1 << endl;
    else
        cout << a / 2 << endl;
}

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

int main(){
    //n:情報数,b:何棟か,f:何階か,r:何番目の部屋か,v:何人か
    int n,b,f,r,v;
    cin >> n;
    int room[4][3][10]={0};

    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout << " " << room[i][j][k] ;
            }
            cout << endl;
        }
        if(i != 3){
            cout << "####################" << endl;
        }
    }
    return 0;

}




Measured memory_bytes: 3016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (1<<21)
const int maxn=20+10;
const int maxv=50000+10;
int n,m;
int c[maxn];
int d[maxv];
void solve()
{
    fill(d,d+n+1,INF);
    d[0]=0;
    for(int i=0;i<m;i++)
    {
        for(int j=c[i];j<=n;j++)
        {
            d[j]=min(d[j],d[j-c[i]]+1);
        }
    }
    printf("%d\n",d[n]);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++) scanf("%d",&c[i]);

    solve();

    return 0;
}

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

double ans,x;
char u[10];
int n;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lf%s",&x,u);
		if (u[0]=='J') ans+=x;
		else ans+=x*380000.00;
	}
	printf("%.8lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);

		W = in.readLine();
		String[] Ws = W.split(" ");
		long[] L = new long[Ws.length];
		for(int i=0;i<Ws.length;i++){
			L[i] = Long.parseLong(Ws[i]);
		}
		Arrays.sort(L);

		long ans =0;
		long ansA =0;
		long ansB =0;
//		for(int a=0;a<N;a++){
//			if(a!=0&&L[a-1]==L[a]){
//				ans+=ansA;
//				continue;
//			}
//			ansA=0;
//			for(int b=a+1;b<N;b++){
//				if(b-1!=a&&L[b-1]==L[b]){
//					ansA+=ansB;
//					continue;
//				}
//				ansB=0;
//				for(int c=b+1;c<N;c++){
//					if(L[a] < L[b]+L[c] && L[b] < L[c]+L[a] && L[c] <L[a]+L[b]){
//						ansB++;
//						System.out.println("a="+L[a]+",b="+L[b]+",c="+L[c]);
//					}
//				}
//				ansA+=ansB;
//			}
//			ans+=ansA;
//		}

		for(int a=0;a<N;a++){
			for(int b=a+1;b<N;b++){
				for(int c=b+1;c<N;c++){
					if(L[c] >= L[a]+L[b]){
						break;
					}
					if(L[a] < L[b]+L[c] && L[b] < L[c]+L[a] && L[c] <L[a]+L[b]){
						ans++;
					}
				}
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 22484
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    K, T = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    x=A[0]
    print(max(x-1-(K-x),0))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll            long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const ll MOD = 1e9+7;
const li mx = 1e4; 

void solve()
{
    int n;
    cin>>n;
    int val=0;
    vli f(n+1,0);
    forn(x,1,101)
    {
        forn(y,1,101)
        {
            forn(z,1,101)
            {
                val = x*x+y*y+z*z+x*y+x*z+y*z; 
                if(val<= n)f[val]++;
            }
        }
    }
    forn(i,1,n+1)
        cout<<f[i]<<endl;
}
int32_t main()
{
    ioS
    int t;
    // cin>>t;
    // while(t--)
        solve();
}


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


int sum_check(int i, int n){

    int k, mod, cur;
    cur = i;

    int sum_cur = 0;

    for(k=0;k<n;k++){
        mod = cur % 10;
        sum_cur = sum_cur + mod;
        cur = cur / 10;
    }

    return sum_cur;
}

int check(int i, int n){

    int cur;
    int k, j;
    int mod, ans;

    for(j=1;j<=n;j++){
        cur = i;
        ans = 0;
        for(k=0;k<n;k++){
            mod = cur % 10;
            if(mod == j){
                ans = ans + 1;
                cur = cur / 10;
            }else{
                cur = cur / 10;
            }
        }
        if(ans != 1){
            break;
        }
    }

    if(j > n){
        return 1;
    }else{
        return 0;
    }

}



int main(void)
{

    int n;
    int p;
    int q;

    int k, temp;

    int i, j;
    int count;
    int sum = 0;

    k = 1;

    cin >> n;
    for(i=1;i<n;i++){
        k = k * 10;
    }
    temp = k;

    for(i=1;i<=n;i++){
        sum = sum + i;
    }

    p = 0;
    q = 0;

    for(i=0;i<n;i++){
        cin >> j;
        p = p + k*j;
        k = k / 10;
    }
    k = temp;
    for(i=0;i<n;i++){
        cin >> j;
        q = q + k*j;
        k = k / 10;
    }

    if(p > q){
        temp = p;
        p = q;
        q = temp;
    }

    count = 0;
    for(i=p+1;i<q;i++){
        if(sum_check(i, n) == sum){
            if(check(i, n) > 0){
                count++;
            }
        }
    }

    if(p == q){
        cout << count;
    }else{
        cout << count + 1;
    }

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 2e5;
char a[mxN+3]; bool f[mxN+3];
int n;

int main()
{
	scanf("%s",a+1); n = strlen(a+1);
	for(int i=1; i<=n; i++) printf("%c",a[i]=='?'?'D':a[i]); puts("");
	return 0;
}

Measured memory_bytes: 3888
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
#define LL long long
const int MAX = 1e5+10;
LL n,m,x,y;
int main ()
{
    cin>>n>>m;
    int add=n-1;
    if(m>=n)
        add++;
    cout<<add<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))
min_val = 0
for i in range(N):
    temp = min_val + 1
    if temp == a_list[i]:
        min_val = a_list[i]
        
if min_val == 0:
    print(-1)
else:
    print(N - min_val)

Measured memory_bytes: 26140
def dist(c):
    return (ord('z') - ord(c) + 1) % 26

s = list(input())
k = int(input())
i = 0
while 0 < k and i < len(s):
    d = dist(s[i])
    if d <= k:
        k -= d
        s[i] = 'a'
    i += 1

s[-1] = chr((ord(s[-1]) + (k % 26)))
print(''.join(s))


Measured memory_bytes: 4156
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <stack>
using namespace std;
using Graph = vector<vector<int>>;
int dist[100005][3];
const int INF = 1001001001;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    int M;
    cin >> M;
    vector<vector<int>> to(N);
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
    }
    int S, T;
    cin >> S >> T;
    --S;
    --T;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            dist[i][j] = INF;
        }
    }
    queue<P> q;
    q.push(P(S, 0));
    dist[S][0] = 0;
    while (!q.empty())
    {
        int v = q.front().first;
        int l = q.front().second;
        q.pop();
        for (int u : to[v])
        {
            int nl = (l + 1) % 3;
            if (dist[u][nl] != INF)
                continue;
            dist[u][nl] = dist[v][l] + 1;
            q.push(P(u, nl));
        }
    }

    int ans = dist[T][0];
    if (ans == INF)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << ans / 3 << endl;
    return 0;
}

Measured memory_bytes: 6912
#include<stdio.h>
#include <string.h>

char lower(char c);

int main(){
  int i=0,j=0,count[26]={};
  char c,s[1201]={},charas[26]={};
  //memset(s,'\n',1201);
  for (j=0;j<26;j++){
    charas[j] = 'a' + j;
  }

  while(fgets(s, 1200, stdin) != NULL){
    i = 0;
    while(1){
      if(s[i]=='\n'){

        break;
      }
      c = lower(s[i]);
      for (j=0;j<26;j++){
        if(charas[j]==c){
          count[j]++;
          break;
        }
      }

      i++;
    }
  }

  for (j=0;j<26;j++){
    printf("%c : %d\n",charas[j],count[j]);
  }

  return 0;
}



char lower(char c){
  if(c>='A' && c<='Z'){
    return c+'a'-'A';
  }
  else{
    return c;
  }
}


Measured memory_bytes: 2044
n = int(input())
a = [int(i) for i in input().split()]

minv = -1
count = 0
s = 0
for i in range(n):
    if a[i] < 0:
        s += -a[i]
        if minv > -a[i] or minv == -1:
            minv = -a[i]
        count += 1
    else:
        s += a[i]
        if minv > a[i] or minv == -1:
            minv = a[i]

if count % 2 == 1:
    s += 2*(-minv)

print(s)


Measured memory_bytes: 64752
from collections import Counter

n = int(input())
prime_list = []
while n > 1:
    k = 2
    while k ** 2 <= n:
        if n % k == 0:
            prime_list.append(k)
            n //= k
            break
        else:
            k += 1
    else:
        prime_list.append(n)
        n = 1
prime_fact = Counter(prime_list)
ans = 1
for p, k in prime_fact.items():
    ans *= (p ** (k - 1) )*(p - 1)
print(ans)



Measured memory_bytes: 6000
[n,c,k] = [int(x) for x in input().split()]

xs = [int(input()) for i in range(n)]
xs.sort()

ans = 0
prv = -2e9
cnt = 0

for x in xs:
    if cnt == c or prv < x:
        cnt = 1
        prv = x + k
        ans += 1
    else:
        cnt += 1
print(ans)


Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n);
    REP(i, n) cin >> a[i];
    vll ball(n);
    for(ll i = n / 2; i < n; i++){
        if(a[i]) ball[i] = 1;
    }
    for(ll i = n / 2 - 1; i >= 0; i--){
        ll k = 2, cnt = 0;
        while(k * (i + 1) <= n){
            if(ball[k * (i + 1) - 1]) cnt++;
            k++;
        }
        if((a[i] + cnt) % 2) ball[i] = 1;
    }
    ll rr = 0;
    REP(i, n){
        if(ball[i]) rr++;
    }
    cout << rr << endl;
    REP(i, n){
        if(ball[i]) cout << i + 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    int A,B;
    char op;
    cin>>A>>op>>B;

    if(op=='+'){
        cout<<A+B<<endl;
    }else{
        cout<<A-B<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <limits.h>
#include <math.h>

using namespace std;

int n, k;

int main() {
	cin >> n >> k;
	vector<int> da(n);
	int su = 0;
	for (int i = 0;i < n;i++) {
		cin >> da[i];
		su += da[i];
	}
	vector<int> cand(0);
	int sqr = sqrt(su);
	for (int i = 1;i < sqr+1;i++) {
		if (su%i == 0) {
			cand.push_back(i);
			cand.push_back(su / i);
		}
	}
	sqr = cand.size();
	int ans = 0,U=0,P=0;
	vector<int> up(n);
	for (int i = 0;i < sqr;i++) {
		U = 0;P = 0;
		for (int j = 0;j < n;j++) {
			up[j] = (da[j]) % cand[i];
			U += up[j];
		}
		sort(up.begin(), up.end());
		U /= cand[i];
		for (int j = 0;j < U;j++) {
			P += cand[i] - up[n - j - 1];
		}
		if (P <= k) {
			ans = max(ans, cand[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n)	 for(int i = 0; i < (n); i++)
#define all(a)		 begin(a), end(a)

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(string s) {
	auto itr = begin(s);
	char a	 = *itr;
	itr = end(s);
	char b	 = *(--itr);
	printf("%c%d%c", a, s.length() - 2, b);
}

int main() {
	string s;
	cin >> s;
	solve(s);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll; 
const int N = 100010;
const ll mod = 1e9 + 7;

ll fac[N << 1], inv[N << 1];
int h, w, a, b;

ll power(ll a, int b) {
	ll ans = 1;
	while(b) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod; b >>= 1;
	}
	return ans;
}

ll C(int n, int m) {
	return fac[m] * inv[n] % mod * inv[m - n] % mod;
}

ll Calc(int h, int w) {return C(h - 1, h + w - 2);}

int main() {
	scanf("%d%d%d%d", &h, &w, &a, &b);
	fac[0] = inv[0] = 1; 
	a = h - a + 1;
	for(int i = 1; i <= 200000; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
	for(int i = 1; i <= 200000; ++i) inv[i] = power(fac[i], mod - 2);
	ll ans = 0;
	for(int i = b + 1; i <= w; ++i) {
		ans = (ans + 1LL * Calc(a - 1, i) * Calc(h - a + 1, w - i + 1) % mod) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >

//------------------------------------------------------

int main() {
    int h, w;
    cin >> h >> w;
    char red[h][w], blue[h][w];

    rep(i, h) rep(j, w) red[i][j] = blue[i][j] = '.';


    rep(i, h) red[i][0] = '#';
    rep(i, h) blue[i][w - 1] = '#';

    rep(i, h) REP(j, 1, w - 1) {
        if (i % 2 == 0) red[i][j] = '#';
        else blue[i][j] = '#';
    }

    rep(i, h) {
        string s;
        cin >> s;

        rep(j, s.length()) {
            if (s[j] == '#') {
                if (i % 2 == 0) blue[i][j] = '#';
                else red[i][j] = '#';
            }
        }
    }

    rep(i, h) {
        rep(j, w) cout << red[i][j];
        cout << endl;
    }

    cout << endl;

    rep(i, h) {
        rep(j, w) cout << blue[i][j];
        cout << endl;
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  int x,y,z;
  x=a+b;
  y=a-b;
  z=a*b;
  if(x>=y&&x>=z){
    printf("%d\n",x);
  }
  else if(y>=z&&y>=x){
    printf("%d\n",y);
  }
  else if(z>=x&&z>=y){
    printf("%d\n",z);
  }
 // printf("%d%d%d",x,y,z);
}
  


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

int main() {
  
  int e, m, s;
  
  while(cin>>e,e) {
    m=e;
    for(int i=0;i*i*i<=e;i++) {
      for(int j=0;i*i*i+j*j<=e;j++) {
          s = i+j+e-(i*i*i+j*j);
          if(s<m)m=s;
      }
    }
    cout<<m<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())
p = list(map(int, input().split()))

m = [(e + 1) / 2 for e in p]

t = sum(m[0:K])
result = t
for i in range(N - K):
    t -= m[i]
    t += m[i + K]
    if t > result:
        result = t
print(result)

Measured memory_bytes: 77448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n,k,s,m=1e9;
int main(){
	scanf("%d%d%d", &n, &k, &s);
	rep(i,n) printf("%d%c", i<k?s:s==m?1:m,i<n-1?' ':'\n');
}

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

using namespace std;
using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<pair<ll, ll>> job(n);
    for(int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        job[i] = {b, a};
    }
    sort(job.begin(), job.end());
    ll total_a = 0;
    bool can = true;
    for(int i = 0; i < n; i++)
    {
        total_a += job[i].second;
        if(job[i].first < total_a){
            can = false;
            break;
        }
    }
    if(can){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3328
#include<iostream>

using namespace std;
int main(){
    char num[1010];
    int i, j, n;
    i = 0;
    while(1) {
        scanf("%s", num);
        j = i = 0;
        while(num[i] != '\0') {
            j += (int)(num[i] - '0');
            i++;
        }
        if(j == 0 && i < 2) break;
        cout << j << endl;
    }
    return 0;
}


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

int main(){
  int cs, ts;

  cin >> cs;

  int *c = new int[cs + 1];

  for(int i = 0; i < cs; i++){
    cin >> c[i];
  }


  cin >> ts;
  int t , cnt = 0;

  for(int i = 0; i < ts; i++){
    cin >> t;

    int left = 0, right = cs;

    while(left < right){
      int mid = (left + right)/2;
      if(c[mid] == t){
        cnt++;
        break;
      }
      else if(c[mid] > t){
        right = mid;
      }
      else if(c[mid] < t){
        left = mid + 1;
      }
    }
  }

  cout << cnt << endl;
  return 0;
}



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

int main() {

    string s,t;
    cin >> s >> t;
   int n = s.size();
   int m = t.size();

   int dp[n+1][m+1];
   memset(dp, 0, sizeof(dp));


   for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(s[i-1] == t[j-1]){
        dp[i][j] = 1 + dp[i-1][j-1];
      }
      else{
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
   }

   string ans;

   int i=n,j=m;

   while(i>0 && j>0){
       if(dp[i][j] == dp[i-1][j-1] + 1 && s[i-1] == t[j-1]){
        //cout << i << " " << j << endl;
        //cout << s[i-1] << " " << t[j-1] << endl << endl;

          ans.pb(s[i-1]);
          i--;
          j--;
       }
       else if (dp[i][j] == dp[i-1][j]){
          i--;
       }
       else {
          j--;
       }
   }
    reverse(ans.begin(),ans.end());

   cout << ans;

    return 0;
}


Measured memory_bytes: 38788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    map<string,int> m;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans=0;
    for(auto it=m.begin();it!=m.end();it++){
        if(it->second>=2){
            ans+=1ll*(it->second)*(it->second-1)/2;
        }
    }
    cout<<ans;
}

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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2 - x1;
    int b = y2 - y1;
    cout << x2 - b << " " <<  y2 + a << " " << x1 - b << " " << y1 + a << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    
    public static void  main (String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String str = sc.next();
        
        char c1 = str.charAt(0);
        char c2 = str.charAt(1);
        
        if (c1 == '9' || c2 == '9') {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }

}

Measured memory_bytes: 22868
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll power(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x;
    }
    x = x * x;
    n >>= 1;
  }
  return res;
}

ll X;

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

  for (ll a = -200; a <= 200; a++) {
    for (ll b = -200; b <= 200; b++) {
      if (power(a, 5) - power(b, 5) == X) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

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

  int ans;
  if(N % (2*D + 1) == 0){
    ans = N / (2*D + 1);
  }else{
    ans = (N / (2*D + 1)) + 1;
  }

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

Measured memory_bytes: 256
import numpy as np


def std_input():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    return N, A, B, C, D, E


N, A, B, C, D, E = std_input()

arr = np.array((A, B, C, D, E))
ceil_arr = np.array(
    [np.ceil(N / A), np.ceil(N / B), np.ceil(N / C), np.ceil(N / D), np.ceil(N / E)]
).astype(int)

print(4+max(ceil_arr))

Measured memory_bytes: 12504
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
bool ok;
LL ans;
int n,now,k,p,q;
char s[55555];
int main(){
	scanf("%s",s+1);
	cin>>k;
	n=strlen(s+1);
	ok=1;
	FOR(i,2,n) if (s[i]!=s[1]) ok=0;
	if (ok){
		cout<<1ll*n*k/2<<endl;
		return 0;
	}
	FORD(i,n,1) if (s[i]==s[1]) ++q; else break;
	p=1;
	FOR(i,2,n) if (s[i]==s[1]) ++p; else break;
	now=0;
	FOR(i,p+1,n-q){
		if (i>p+1 && s[i]==s[i-1]) ++now; else{ans+=now/2;now=1;}
		
	}
	ans+=now/2;
	ans=ans*k;
	ans+=1ll*(p+q)/2*(k-1);
	ans+=p/2+q/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli n;
	cin>>n;
	lli a[n],i,count[100005]={0},sum=0;
	fr(i,n)
	{
		cin>>a[i];
		count[a[i]]++;
		sum+=a[i];
	}
	lli q;
	cin>>q;
	lli b[q],c[q];
	fr(i,q)
	{
		cin>>b[i]>>c[i];
	}
	fr(i,q)
	{
		sum-=count[b[i]]*b[i];
		sum-=count[c[i]]*c[i];
		count[c[i]]+=count[b[i]];
		count[b[i]]=0;
		sum+=count[c[i]]*c[i];
		cout<<sum<<"\n";
	}

	return 0;
}

Measured memory_bytes: 6768
// Copyright 2017 Parallelc
#include <bits/stdc++.h>

#include <ext/numeric>
#include <ext/rope>
using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
template<typename T>
using pbq = priority_queue<T>;
template<typename T>
using rbt = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

#include <tr2/dynamic_bitset>
using namespace tr2;
using db = dynamic_bitset<>;

template <typename T> 
bool in(T& x){
    x = 0; T f = 1; char ch = cin.get();
    while (!isdigit(ch)) {
        if (ch == -1) return false;
        if (ch == '-') f = -1; 
        ch = cin.get();
    }
    while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = cin.get();}
    x *= f; return true;
}
template <typename T, typename... S>
bool in(T& t, S&... s) {if(!in(t)) return false; return in(s...);}

using LL = int64_t;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> c >> b;
    if (a <= b && b <= c) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  int r,g,b,n;
  cin >> r >> g >> b >> n;

  int ans = 0;
  for (int x = 0; x <= 3000; x++){
    for(int y = 0; y <= 3000; y++){
      if((n - x*r - y*g) % b != 0) continue;
      int z = (n - x*r - y*g) / b;
      if(z >= 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    ll n;
    cin >> s >> n;
    for(int i = 0; i < min((ll)s.size(), n); i++) {
        if(s[i] >= '2') {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define si set<int>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define sq(x) ((x) * (x))
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, x, t;
    cin >> n >> x >> t;
    cout << t * ((n + x - 1) / x) << endl;
    GAME_OVER;
}

Measured memory_bytes: 3652
N=int(input())
A=list(map(int, input().split()))[::-1]

flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[-(i+1)]!=now:
			A.pop(-(i+1))
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)
		
		

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

typedef long long ll;

int main(void){
    int N;
    ll W;
    vector<ll> weight(110);
    vector<ll> value(110);
    
    cin >> N >> W;
    
    vector< vector<ll> > dp(110,vector<ll>(100100));
    for(int i = 0 ; i < N ; i++){
        cin >> weight[i] >> value[i];
    }
    
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            
            if (sum_w - weight[i] >= 0) {
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 90304
#include <iostream>
#include <utility>

using namespace std;

int main(void){
	int w,n,*num,a,b,tmp;
	pair<int,int> *ln;
	char nul;

	cin >> w >> n;
	num = new int[w+1];
	ln = new pair<int,int>[n];

	for(int i=0;i<n;i++){
		cin >> a >> nul >> b;
		ln[i]=make_pair(a,b);
	}

	for(int i=1;i<=w;i++){
		tmp=i;
		for(int j=0;j<n;j++)
			tmp=tmp!=ln[j].first?tmp!=ln[j].second?tmp:ln[j].first:ln[j].second;
		num[tmp]=i;
	}
	for(int i=1;i<=w;i++)
		cout << num[i] << endl;

	delete [] ln;
	delete [] num;
	return 0;
}

Measured memory_bytes: 1196
#include "bits/stdc++.h"

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
std::vector<int> z_algorithm(const std::string& s)
{
  int sz = s.length();
  std::vector<int> z(sz, 0);
  int i = 1, j = 0;
  while (i < sz)
  {
    while (i + j < sz && s[j] == s[i + j])
      j++;
    z[i] = j;
    if (j == 0)
    {
      i++;
      continue;
    }
    int k = 1;
    while (i + k < sz && k + z[k] < j)
    {
      z[i + k] = z[k];
      k++;
    }
    i += k;
    j -= k;
  }
  return z;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  REP(i, n) {
    auto v = z_algorithm(s.substr(i));
    FOR(i, 1, v.size()) {
      chmax(ans, min(v[i], (int)i));
    }
  }
  cout << ans << endl;
}


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

import sys

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

N = INT()
A = LIST()

# +-どっちに揃えるかを決める
mn = min(A)
mx = max(A)
if abs(mx) >= abs(mn):
    flag = 1
    base = mx
    baseidx = A.index(mx)
else:
    flag = 0
    base = mn
    baseidx = A.index(mn)

# 符号を揃える
ans = []
for i in range(N):
    if i == baseidx:
        continue
    A[i] += base
    ans.append((baseidx, i))

# 正負によって左右から累積和っぽくする
if flag:
    for i in range(N-1):
        A[i+1] += A[i]
        ans.append((i, i+1))
else:
    for i in range(N-2, -1, -1):
        A[i] += A[i+1]
        ans.append((i+1, i))

print(len(ans))
for a, b in ans:
    print(a+1, b+1)


Measured memory_bytes: 3316
w,h,n = map(int,input().split())
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        x1 = max(x,x1)
    elif a == 2:
        x2 = min(x,x2)
    elif a == 3:
        y1 = max(y,y1)
    else:
        y2 = min(y,y2)
if x2-x1 <= 0 or y2-y1 <= 0:
    print(0)
else:
    print((x2-x1)*(y2-y1))

Measured memory_bytes: 3064
/*
AizuOnline A0013
Switching Railroad Cars
*/
#include <stdio.h>
int siding[100];


main()
{               int index=0;
                int ord;

while(EOF != scanf("%d",&ord))
	  if(ord > 0)
	  {      siding[index] = ord;
	         index ++;
	  }
	  else if(ord == 0)
	  {       index--;
	          printf("%d\n",siding[index]);
          }

	  return(0);

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << " " << x << "\n"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e3 + 3;
const ll M = 1e9 + 7;

ll n, m, cnt[N][N];
char a[N][N];

void init() {
	for (ll i = 0; i < N; ++i) a[i][0] = '#';
	for (ll i = 0; i < N; ++i) a[0][i] = '#';
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	init();
	
	cin >> n >> m;
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= m; ++j) cin >> a[i][j];
	}
	
	cnt[0][1] = 1;
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= m; ++j) {
			if (a[i][j] == '.') {
				cnt[i][j] = cnt[i-1][j] + cnt[i][j-1];
				cnt[i][j] %= M;
			}
		}
	}
	cout << cnt[n][m];
	
	return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
	long n; cin>>n;
	vector<long> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	long x=a[0],s=a[0];
	long b=0,r=1;
	for(int i=1;i<n;i++){
		x^=a[i],s+=a[i];
		if(x==s)
			r+=i-b;
		else{
			do{
				x^=a[b],s-=a[b];
				b++;
			}while(x!=s);
			r+=i-b;
		}
		r++;
	}
	cout<<r;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
using namespace std;

int main ()
{
	int n;
	cin >> n;
	long long sum = 0, a;
	unordered_map<long long, long long> m;
	++m[sum];
	for (int i=1; i<=n; ++i)
	{
		cin >> a;
		sum += a;
		++m[sum];
	}

	long long count = 0LL;
	for (auto c : m)
	{
		count += max(0LL, (c.second * (c.second - 1LL)) >> 1);
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 8520
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    ll ans = 0;
    int now = 1;
    int M = 1;
    rep(i,N){
        int d = 0;
        int cnt = 0;
        if(i != 0 && a[i] % now == 0){
            if(a[i] >= now+1){
                a[i] -= now+1;
                d++;
                cnt++;
            }
        }
        d += (a[i]+now-1)/now-1;
        ans += d;
        int r = a[i]-(d-cnt)*now;
        now = max(r+1,M);
        M = max(r+1,M);
    }
    cout << ans << endl;
}

    



Measured memory_bytes: 640