akhauriyash/Code-Regression huggingface dataset:
let n = stdin.ReadLine() |> int64

let str26 n :int64[]= 

    let unfolder tmp =
        if tmp = 0L then None
        else
        let tmp = tmp - 1L
        let out = tmp % 26L
        let tmp = (tmp - out) / 26L
        Some(out, tmp)
        
    Array.unfold unfolder n
    |> Array.rev

str26 n |> Array.map (fun x -> x + 97L |> char) |>fun x -> new string(x) |> stdout.WriteLine

Measured memory_bytes: 28408
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_A
 * 
 * @author chrone
 * 
 */
public class Main {
    
    private final static String SPACE = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int a = Integer.valueOf(inputs[0]);
                int b = Integer.valueOf(inputs[1]);
                // int c = Integer.valueOf(inputs[2]);
                
                // Zero Divide
                if (b == 0)
                    System.exit(-1);
                
                System.out.print((a - a % b) / b);
                System.out.print(SPACE);
                System.out.print(a % b);
                System.out.print(SPACE);
                double divide = (double)a / (double)b;
                String divideStr = String.format("%.5f", divide);
                System.out.print(divideStr);
                
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
}

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

int main () {
	int A, B;
	cin >> A >> B;
	
	if (A >= 1 && A <= 13 && B >= 1 && B <= 13) {
		if (A > B && B != 1) {
			cout << "Alice" << endl;
		}
		else if (A == 1 && B != 1) {
			cout << "Alice" << endl;
		}
		if (B > A && A != 1) {
			cout << "Bob" << endl;
		}
		else if (B == 1 && A != 1) {
			cout << "Bob" << endl;
		}
		else if (A == B) {
			cout << "Draw" << endl;
		}
	}
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))
count=0
for i in range(n):
    for j in range(i+1,n):
        if A[i]>A[j]:
            count += (k*(k+1)//2)
    for l in range(i):
        if A[i]>A[l]:
            count += ((k-1)*(k)//2)

print(count%(10**9+7))

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

using namespace std;
typedef long long int ll;
int INF = 100100101;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  bool a[26];
  rep(i,26){
    a[i] = false;
  }
  rep(i,s.length()){
	int itr = (int)s[i]-97;
    a[itr]=true;
  }
  rep(i,26){
   	if(a[i] == false) {
      cout << (char)(i+97) << endl; 
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int D, X;
  int A[N];
  cin >> D >> X;
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  int count=0;
  for (int i=0; i<N; i++) {
    for (int j=0, k=0; j<D; j++) {
      if (j==k*A[i]) {
        count++;
        k++;
      }
    }
  }
  
  cout << count+X << endl;
  
  return 0;
}


Measured memory_bytes: 3612
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();
		
		if(a + b >= x && a <= x) {
        	System.out.println("YES");
        } else {
        	System.out.println("NO");  
        }
	}
}

Measured memory_bytes: 22740
n = int(input())
a, b = map(int, input().split())
P = list(map(int, input().split()))

C = [0, 0, 0]
for p in P:
  if p <= a:
    C[0] += 1
  elif a < p <= b:
    C[1] += 1
  else:
    C[2] += 1

print(min(C))

Measured memory_bytes: 3064
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll cd = c*d/__gcd(c,d);

    a--;

    cout << (b-b/c-b/d+b/cd) - (a-a/c-a/d+a/cd) << endl;
    return 0;
}

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

vector< int > graph[50];
int N, M;
int dp[50][50][5100];
 
int getTern(int Aaron, int Bruth, bool which, int cost)
{
  int ret;
  if(Aaron == Bruth) {
    return(dp[Aaron][Bruth][cost] = cost);
  } else if(cost == M * 2) {
    return(dp[Aaron][Bruth][cost] = 1 << 30);
  } else if(~dp[Aaron][Bruth][cost]) {
    return(dp[Aaron][Bruth][cost]);
  } else if(which) {
    ret = 1 << 30;
    for(int i = 0; i < graph[Bruth].size(); i++) { 
      ret = min(ret, getTern(Aaron, graph[Bruth][i], false, cost + 1));
    }
    ret = min(ret, getTern(Aaron, Bruth, false, cost + 1));
  } else {
    ret = 0;
    for(int i = 0; i < graph[Aaron].size(); i++) {
      ret = max(ret, getTern(graph[Aaron][i], Bruth, true, cost + 1));
    }
    ret = max(ret, getTern(Aaron, Bruth, true, cost + 1));
  }
  return(dp[Aaron][Bruth][cost] = ret);
}

int main()
{
  cin >> N;
  while(N--) {
    fill_n(**dp, 50 * 50 * 5100, -1);
    cin >> M;
    for(int i = 0; i < M; i++) {
      graph[i].clear();
      for(int j = 0; j < M; j++) {
        bool line;
        cin >> line;
        if(line) graph[i].push_back(j);
      }
    }
    int A, B;
    cin >> A >> B;
    int dist = getTern(A, B, false, 0) / 2;
    if(dist >= 1 << 29) {
      puts("infinity");
    } else {
      cout << dist << endl;
    }
  }
}

Measured memory_bytes: 51040
n, a = map(int, input().split())
x = list(map(int, input().split()))

maxx = max(x)
maxx = max(maxx, a)
# dp[j][k][s] : j枚目までからk枚選んで合計をsにする場合の数
dp = [[[0 for _ in range(maxx * n + 1)] for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for j in range(n + 1):
    for k in range(j + 1):
        for s in range(maxx * k + 1):
            if j >= 1 and s < x[j - 1]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j - 1]:
                dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]

ans = 0
for k in range(1, n + 1):
    ans += dp[n][k][k*a]
print(ans)

Measured memory_bytes: 65504
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	vv := make([]float64, n)

	for i := 0; i < n; i++ {
		vv[i] = getNextFloat64(scanner)
	}

	sort.Float64s(vv)
	ans := vv[0]
	for i := 1; i < n; i++ {
		ans = (ans + vv[i]) / 2.0
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
N, Y = map(int, input().split())
# print(N,Y)

for a in range(N+1):
    aa = a * 10000
    for b in range(N+1-a):
        c = N - a - b
        if aa + b * 5000 + c * 1000 == Y:
            print("{} {} {}".format(a, b, c))
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int l = scanner.nextInt();
		List<String> list = new ArrayList<>();
		for(int i = 0; i < n; i++){
			list.add(scanner.next());
		}
		Collections.sort(list);
		for(String s : list){
			System.out.print(s);
		}
		System.out.println();
	}
}


Measured memory_bytes: 22484
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

import queue

a = list(input())
b = list(input())
c = list(input())

A = queue.Queue()
B = queue.Queue()
C = queue.Queue()

for i in range(len(a)):
    A.put(a[i])
for i in range(len(b)):
    B.put(b[i])
for i in range(len(c)):
    C.put(c[i])

memo = "a"
while(1):
    if memo == "a":
        if A.empty():
            print("A")
            break
        memo = A.get()

    elif memo == "b":
        if B.empty():
            print("B")
            break
        memo = B.get()

    elif memo =="c":
        if C.empty():
            print("C")
            break
        memo = C.get()

Measured memory_bytes: 3952
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n =  Integer.parseInt(sc.next());
		int k =  Integer.parseInt(sc.next());
		int q =  Integer.parseInt(sc.next());
		int num[] = new int[n];
		for (int i = 0 ; i < n ; i++) {
			num[i] = k - q ;
		}
		
		for (int i = 0 ; i < q ; i++) {
			num[Integer.parseInt(sc.next())-1] += 1 ;
		}
		
		for (int i = 0 ; i < n ; i++) {
			if(Math.signum(num[i]) == 1) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
		
		
	}	
}

Measured memory_bytes: 60472
#include<bits/stdc++.h>
#define loot 1001
using namespace std;
int main(){
    int n,m;
    int cnt=0;
    bool flag[loot];
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        flag[i]=false;
    }
    for(int i=0;i<m;i++){
        int a;
        scanf("%d",&a);
        flag[a]=true;
        
    }
    for(int i=n;i>=m+1;i--){
        if(flag[i]){
            for(int j=1;j<=m;j++){
                if(!flag[j]){
                    flag[j]=true;
                    cnt++;
                    break;
                }
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
    
}



Measured memory_bytes: 3236
//  ABC
//
//  Created by Amarsanaa Davaasuren on 2019/08/31.
//  Copyright © 2019 Amarsanaa Davaasuren. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
using namespace std;



class UnionFind {
public:
    vector<int> Parent;
    UnionFind(int N){
        Parent = vector<int>(N,-1);
    }
    
    int root(int node){
        if (Parent[node] < 0){
            return node;
        }
        else{
            return Parent[node] = root(Parent[node]);
        }
    }
    
    int size(int node){
        return -root(node);
    }
    
    bool connect(int A, int B){
        int Aroot = root(A);
        int Broot = root(B);
        if (Aroot != Broot){
            if (size(Aroot) < size(Broot)) swap(Aroot,Broot);
            Parent[Aroot] += Parent[Broot];
            Parent[Broot] = Aroot;
            return true;
        }
        else{
            return false;
        }
    }
};




#define rep(i0,i,n) for(int (i)=(i0);(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
using ll = long long;




int main(){
    int N; cin >> N;
    vector<int> H(N);
    rep(0,i,N){
        cin >> H[i];
    }
    rep(1,i,N){
        if (H[i] < H[i-1]){
            cout << "No"<< endl;
            return 0;
        }
        else if (H[i] > H[i-1]){
            H[i]--;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//input
	int N;
	cin >> N;

	vector<ll> a(N);
	ll tmp, count = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		tmp = a[i];
		while (true) {
			if (tmp % 2 == 0) {
				count++;
				tmp /= 2;
			}
			else {
				break;
			}
		}
	}


	cout << count;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,L,v[9][9],ans,a,b,cnt;
vector<ll> u;
int main(void){
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>a>>b;
        v[a][b]=1;;
        v[b][a]=1;
    }
    for(int i=2;i<=n;i++){
        u.push_back(i);
    }
    do{
        L=1;
        cnt=0;
        for(auto x:u){
            if(v[L][x]==1)cnt++;
            L=x;
        }
        if(cnt==n-1)ans++;
    }while(next_permutation(u.begin(),u.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import numpy as np

N, S = map(int, input().split())
A = np.int32(input().split())
M = 998244353
V = max(max(A), S)

ans = 0
cs = np.zeros(V + 1, dtype=np.int64)
for i, a in enumerate(A):
    dp = np.zeros(V + 1, dtype=np.int64)
    dp[a] = i + 1
    dp[a + 1 : S + 1] = cs[np.arange(a + 1, S + 1) - a]
    cs = (cs + dp) % M
    ans = (ans + (N - i) * dp[S]) % M
print(ans)


Measured memory_bytes: 12500
#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>;

int main() {
    int x, y;
    cin >> x >> y;
    if (2 * x <= y&&y<= 4 * x && y % 2 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
H, W = map(int, input().split())
S = ["." * (W + 2)]
for _ in range(H):
    S += ["." + input() + "."]
S += ["." * (W + 2)]

ans = [[-1] * W for _ in range(H)]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            continue
        cnt = 0
        if S[i - 1][j - 1] == "#":
            cnt += 1
        if S[i][j - 1] == "#":
            cnt += 1
        if S[i + 1][j - 1] == "#":
            cnt += 1
        if S[i - 1][j] == "#":
            cnt += 1
        if S[i + 1][j] == "#":
            cnt += 1
        if S[i - 1][j + 1] == "#":
            cnt += 1
        if S[i][j + 1] == "#":
            cnt += 1
        if S[i + 1][j + 1] == "#":
            cnt += 1
        ans[i - 1][j - 1] = cnt

for i in ans:
    p = ["#" if x == -1 else x for x in i]
    print(*p, sep="")


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {

	int n, m;
	cin >> n >> m;

	vector<int>a(n);
	int s = 0, e = n;
	int l=0, r=0;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;

		if (s < l)
			s = l;

		if (e > r)
			e = r;
	}
	
	int ans = e - s + 1;
	if (ans < 0)
		cout << 0 << endl;
	else
		cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <ctype.h>
 
int main(void) {
    char mimori_suzuko[2048], *fukuenn_misato;
    if (fgets(mimori_suzuko, sizeof(mimori_suzuko), stdin) == NULL) return 1;
    if ((fukuenn_misato = strchr(mimori_suzuko, '\n')) != NULL) *fukuenn_misato = '\0';
    for (fukuenn_misato = mimori_suzuko; *fukuenn_misato != '\0'; fukuenn_misato++) {
        int katou_emiri = (unsigned char)*fukuenn_misato;
        if (islower(katou_emiri)) putchar(toupper(katou_emiri));
        else if (isupper(katou_emiri)) putchar(tolower(katou_emiri));
        else putchar(katou_emiri);
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 2112
#include<iostream>
using namespace std;
int main()
{
  int l,i;
  string s,res;
  cin>>l;
  cin>>s;
  int k=l;
  for(i=0;i<l;i++)
  {
    if(s[i]==s[i+1])
    {
      res=res+s[i];
      k--;
    }
  }
  cout<<k;
  return 0;
}
  
  

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

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

Measured memory_bytes: 256
#include <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() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;
    ans = (ll)(n/(a+b)) * a + min(n%(a+b), a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int count=0;
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			count+=a[i]*a[j];
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}

//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i, no){
  switch(no){
    case 0: return i;
    case 1: return parseInt(i);
    case 2: return i.split(" ");
    case 3: return i.split("\n");
    case 4: return i.split(" ").map((a)=>Number(a));
    case 5: return i.split("\n").map((a)=>Number(a));
    case 6: return i.split("");
    case 7: return i.split("").map((a)=>Number(a));
  }}
function Main(input) {
  input = myconv(input, 4);
  S = input[0];
  W = input[1];

  if(S <= W) {
    console.log('unsafe');
  } else {
    console.log('safe');
  }
}
Main(myin());

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

int main(){
  int N,K;
  string S;
  cin >> N >> K >> S;
  
  // 端...内側向くのがbetter
  // 途中...向かい合うflipは-2, 背を向けあうflipは0 or other
  // 最適...一方向orどこかを基準に向かい合い（N-1人）
  // LRLR...L 左端とRL
  // LRLR...R 左端とRLと右端
  // RLRL...R RLと右端
  // RLRL...L RL
  int rl=0;
  for(int i=0; i<N-1; i++){
    if(S[i]=='R'&&S[i+1]=='L') rl++;
  }
  
  if(S[0]=='R'){
    if(S[N-1]=='R'){
      if(K>=rl){
        cout << N-1 << endl;
      }else{
        cout << N-2*(rl-K)-1 << endl;
      }
    }else{
      if(K>=rl){
        cout << N-1 << endl;
      }else{
        cout << N-2*(rl-K) << endl;
      }
    }
  }else{
    if(S[N-1]=='R'){
      if(K>rl){
        cout << N-1 << endl;
      }else if(K==rl){
        cout << N-2 << endl;
      }else{
        cout << N-2*(rl-K)-2 << endl;
      }
    }else{
      if(K>=rl){
        cout << N-1 << endl;
      }else{
        cout << N-2*(rl-K)-1 << endl;
      }
    }
  }
}
  

Measured memory_bytes: 512
#include<stdio.h>

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;


int main(){
	int n,t;
	for(;;){
		scanf("%d",&t);
		if(t==0)break;
		rep(i,9){
			scanf("%d",&n);
			t-=n;
		}
		printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		int move =0;
		for (int i=0; i<N; i++){
			int x = sc.nextInt();
			move += 2 *(Math.min(x, K - x));
		}
		System.out.println(move);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    // Your code here!
    int N, M;
    cin >> N >> M;
    
    vector<int> Ls(M);
    vector<int> Rs(M);
    
    for (int i = 0; i < M; i++)
    {
        int L, R;
        cin >> L >> R;
        Ls[i] = L;
        Rs[i] = R;
    }
    
    int maxl = 0;
    int minr = 10000000;
    
    for (int i = 0; i < M; i++)
    {
        maxl = max(maxl, Ls[i]);
        minr = min(minr, Rs[i]);
    }
    
    int cnt = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i >= maxl && i <= minr) cnt++;    
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
H, W  = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    tmp = 0
    for k in range(W):
        if grid[i][k] == '.':
            tmp += 1
        else:
            ans[i][k] = 0
            for t in range(k-tmp,k):
                ans[i][t] = tmp
            tmp = 0
    for t in range(W-tmp,W):
        ans[i][t] = tmp
a = 0
for i in range(W):
    tmp = 0
    for k in range(H):
        if grid[k][i] == '.':
            tmp += 1
        else:
            for t in range(k-tmp,k):
                a = max(ans[t][i]+tmp-1,a)
            tmp = 0
    for t in range(H-tmp,H):
        a = max(ans[t][i]+tmp-1,a)
print(a)

Measured memory_bytes: 98136
#include<stdio.h>
#define N 100

int main(){
  int M[N][N],n,u,k,v,i,j;
	   scanf("%d",&n);
	   for(i=0;i<n;i++){
	     for(j=0;j<n;j++)M[i][j]=0;
	   }
	   for(i=0;i<n;i++){
	     scanf("%d %d",&u,&k);
	     u--;
	     for(j=0;j<k;j++){
	       scanf("%d",&v);
	       v--;
	       M[u][v]=1;
	     }
	   }

	   for(i=0;i<n;i++){
	     for(j=0;j<n;j++){
	       if(j)printf(" ");
	       printf("%d",M[i][j]);
	     }
	     printf("\n");
	   }
	   
	   return 0;
	   }



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

using namespace std;

typedef long long ll;

const int N(2e5 + 9);

int T, n, m, ans;
int a[N], b[N];

int main()
{
    int n, x;
    cin>>n>>x;
    for (int i = 1; i <= n; i++)
    {
        cin>>a[i];
    }
    ans = 1;
    for (int i = 1; i <= n; i++)
    {
        b[i] = b[i - 1] + a[i]; 
        if (b[i] <= x) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

vector<int> paths[650];
long double dp[650];
int N, M;
long double ans;

void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int s, t;
        cin >> s >> t;
        paths[s].push_back(t);
    }
}

void f(int block) {
    dp[N] = 0;
    for(int i = N - 1; i >= 1; i--) {
        long double sum = 0.0;
        long double maxi = 0.0;
        int num = paths[i].size();
        for(auto to : paths[i]) {
            sum += dp[to];
            chmax(maxi, dp[to]);
        }
        if(i == block && num >= 2) {
            num--;
            sum -= maxi;
        }
        dp[i] = sum / num + 1;
    }
    chmin(ans, dp[1]);
}

void solve() {
    input();
    ans = 1e18;
    for(int i = 0; i <= N - 1; i++) {
        f(i);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return;
}

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

Measured memory_bytes: 1408
n,k = map(int,input().split())
sunuke = list(range(1,n+1))
i = 0
kashi_sunuke = []
d = ''
while i < k:
  d = input()
  okashi = list(map(int,input().split()))
  kashi_sunuke += okashi
  i+=1

o = list(set(sunuke) - set(kashi_sunuke))
print(len(o))

Measured memory_bytes: 9200
#include <iostream>

using namespace std;

int main()
{
    int n, m; cin >> n >> m;
    int c; cin >> c;
    int a[c];
    for (int i = 0; i < c; i++) cin >> a[i];
    int res[n][m];
    bool right = true;
    int index = 0;
    for (int i = 0; i < n; i++)
    {   
        if (right)
        {
            for (int j = 0; j < m; j++)
            {
                if (a[index] == 0) ++index;
                res[i][j] = index + 1;
                a[index]--;
            }
        }
        else
        {
            for (int j = m - 1; j >= 0; j--)
            {
                if (a[index] == 0) ++index;
                res[i][j] = index + 1;
                a[index]--;
            }
        }
        right = !right;
    }   
    for (int i = 0; i < n; i++)
    {   
        for (int j = 0; j < m; j++)
        {
            cout << res[i][j] << ' ';
        }
        cout << '\n';
    }   
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main()
{
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    if (b < c || d < a) {
        std::cout << 0 << std::endl;
        return 0;
    }

    std::cout << std::min(b, d) - std::max(a, c) << std::endl;
}


Measured memory_bytes: 256
//I am so vegetable
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = 3.141593;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }

const int N = 2e5+5;
int cnt[N];
int main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
	int n;cin>>n;
	_for(i,0,n-1){
		int x;cin>>x;
		++cnt[x-1];
	}
	_for(i,0,n)cout<<cnt[i]<<'\n';
	return 0;
}

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

int main(int argc, const char * argv[]) {
    int N, X;
    int L[100];
    int sum[100 + 1] = {0};
    cin >> N >> X;
    
    for (int i = 0; i < N; i++) cin >> L[i];
    
    for (int i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + L[i];
    }
    
    int count = 0;
    for (int i = 0; i <= N; i++) {
        if (sum[i] <= X) {
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
 
  if ( 0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
 
  return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>
int main(void){
  int n,i;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=n-1;i>=1;i--){
    if(a[i]<a[i-1]) a[i-1]--;
    if(a[i]<a[i-1]){printf("No"); return 0;}
  }
  printf("Yes");
}

Measured memory_bytes: 512
def main():
    s = input().rstrip()
    ans = 0
    f = True
    l, r = 0, len(s)-1
    while l < r:
        if s[l] != s[r]:
            if s[l] != "x" and s[r] != "x":
                f = False
                break
            elif s[l] == "x":
                ans += 1
                l += 1
            else:
                ans += 1
                r -= 1
        else:
            l += 1
            r -= 1
    if f:
        print(ans)
    else:
        print("-1")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
A,V  =[int(i) for i in input().split()]
B,W = [int(i) for i in input().split()]
T = int(input())
if V > W:
    if abs(A - B) / abs(V - W) <= T:
        print("YES")
    else:
        print("NO")
else:
    if V == W and A == B:
        print("YES")
    else:
        print("NO")

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

long long gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// long long gc[210][210];
// int sumAll(int k) {
//     int ans = 0;
//     for(int i = 1; i <= k; i++) {
//         gc[i][k] = gcd(i, k);
//         gc[k][i] = gcd(i,k);
//     }
//     for(int i = 1; i <=k; i++) {

//     }
//     return k;
// }
int main() {
//   int n, a, b;
//   cin >> n >> a;
//   for (int i = 1; i < n; i++) {
//     cin >> b;
//     a = gcd(a, b);
//   }
//   cout << a << endl;
    int K; cin >> K;
    long long ans = 0;
    // res[0] = 0;
    // for(int i = 1; i <= K; i++) {
    //     res[i] = res[0] + sumAll(i);
    // }
    rep(i, K+1) {
        rep(j, K+1) {
            rep(k, K+1) {
                if (i == 0 || j == 0 || k == 0) continue;
                // if(gc[i][j] == 0) {
                //     gc[i][j] = gcd(i, j);
                //     gc[j][i] = gcd(i, j);
                //     ans += gcd(k, gc[i][j]);
                //     gc[k][gcd(i, j)] = gcd(k, gc[i][j]);
                // } else {
                //     ans += gcd(k, gc[i][j]);
                //     gc[k][gcd(i, j)] = gcd(k, gc[i][j]);

                // }
                int now = gcd(i,j);
                ans += gcd(k, now);
            }
        }
    }
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(item) for item in input().split()]
    s = input().rstrip()
    if s[-1] == "1":
        print(1)
        continue
    group = []
    prev = "-1"
    for ch, num in zip(s, a):
        if prev != ch:
            group.append([])
        group[-1].append(num)
        prev = ch
    group.reverse()
    tools = []
    ok = True
    for itr, g in enumerate(group):
        if itr % 2 == 0:
            for item in g:
                tools.append(item)
        else:
            tl = tools[:]
            index = 0
            for i in range(64, -1, -1):
                flag = 0
                for j in range(index, len(tl)):
                    if tl[j] & (1 << i):
                        flag = 1
                        tl[index], tl[j] = tl[j], tl[index]
                        break
                for j in range(index + 1, len(tl)):
                    if tl[j] & 1 << i:
                        tl[j] ^= tl[index]
                if flag == 1:
                    index += 1
            for item in g:
                current = 0
                for val in tl:
                    index = len(bin(val)) - 3
                    if item >> index != current >> index:
                        current ^= val
                if current != item:
                    ok = False
    if ok:
        print(0)
    else:
        print(1)

Measured memory_bytes: 71120
N = int(input())
d = [int(a) for a in input().split()]

tot = 0
for i in range(0, N - 1): # 0, 1, ..., N-2
    for j in range(i + 1, N): # i+1, i+2, ..., N-1
        tot += d[i] * d[j]

print(tot)

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

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

int main() {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (k > 0) {
        ans += min (k, a);
        k = max (0, k - a);
    }
    if (k > 0) {
        k = max (0, k - b);
    }
    if (k > 0) {
        ans -= min (k, c);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(void)
{
	int n;
	char bt[2];
	int a, b, ab, o;
	
	a = b = ab = o = 0;
	
	while (scanf("%d, %s", &n, bt) != EOF){
		if (bt[0] =='A' && bt[1] =='B'){
			ab++;
		}
		else if (bt[0] =='A'){
			a++;
		}
		else if (bt[0] =='B'){
			b++;
		}
		else if (bt[0] =='O'){
			o++;
		}
	}
	
	printf("%d\n%d\n%d\n%d\n", a, b, ab, o);
	
	return (0);
}

Measured memory_bytes: 596
#!/usr/bin/env python3
n,k = map(int,input().split())
ans_prob = 0
beki_cnt = 1
for i in range(n,0,-1):
    if i >= k: ans_prob += 1/n
    else:
        while True:
            #print(beki_cnt,i)
            if i >= k / (2** beki_cnt): 
                ans_prob += 1/ ((2**beki_cnt) * n)
                
                #print(i,ans_prob)
                break
            else:   beki_cnt += 1
print(ans_prob)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <bitset>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <deque>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef pair<int, long long> P;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};


int main() {
	int h, w;
	ll a[35][35] = { 0 };
	P d[35][35];
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			d[i][j] = P(INF, LLINF);
		}
	}
	d[0][1] = P(0, a[0][1]);
	d[1][0] = P(0, a[1][0]);
	queue<P>que;
	que.push(P(0, 1));
	que.push(P(1, 0));
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		for (int j = 0; j < 4; j++) {
			int nx = p.first + dx[j];
			int ny = p.second + dy[j];
			if (0 > nx || nx >= h || 0 > ny || ny >= w) continue;
			ll nc = ((d[p.first][p.second].first + 1) * 2 + 1)*a[nx][ny];
			if (d[nx][ny].second > d[p.first][p.second].second + nc) {
				d[nx][ny].second = d[p.first][p.second].second + nc;
				//cout << d[nx][ny].second << endl;
				d[nx][ny].first = d[p.first][p.second].first + 1;
				que.push(P(nx, ny));
			}
		}
	}
	cout << d[h - 1][w - 1].second << endl;
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    map<int,int> M;//num,factorial
    vector<int> S(N+1,-1);
    S.at(1) = 1;
    for(int i = 2; i <= N; i++){
        if(S.at(i)!=-1)continue;
        for(int j = 1; i*j <= N; j++){
            S.at(i*j) = i;
        }
    }
    for(int i = 2; i <= N; i++){
        int tmp = i;
        while(tmp!=1){
            M[S.at(tmp)]++;
            tmp /= S.at(tmp);
        }
    }
    set<int> F2,F4,F14,F24,F74;
    for(auto p: M){
        int num = p.first;
        int count = p.second;
        if(count<2)continue;
        else if(count<4){
            F2.insert(num);
        }else if(count<14){
            F4.insert(num);
        }else if(count<24){
            F14.insert(num);
        }else if(count<74){
            F24.insert(num);
        }else F74.insert(num);
    }

    int res = 0;
    int n74 = F74.size();
    int n24 = F24.size()+n74;
    int n14 = F14.size()+n24;
    int n4 = F4.size()+n14;
    int n2 = F2.size()+n4;
    res = n74 + n24*(n2-1) + n14*(n4-1) + n4*(n4-1)*(n2-2)/2; 
    cout<<res<<endl;
}

Measured memory_bytes: 256
// tested by Hightail: https://github.com/dj3500/hightail
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   wez2(n,d);
   int c = 2*d+1;
   pisz((n + c - 1) / c);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long int ll;
using namespace std;
int main(){
	io;
	ll n;
	ll summ = 0;
	cin >> n;
	for(int i = 1;i <= n;++i){
		if(i % 3 != 0 && i % 5 != 0){
			summ += i;
		}
	}
	cout << summ;
	return 0;
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl A(n);
    rep(i,n)cin>>A[i];
    ll res=0;
    ll l=0;
    ll r=0;
    ll sum=0;
    while(l<n){
        while(r<n&&(sum^A[r])==(sum+A[r])){
            sum+=A[r];
            r++;
        }
        res+=r-l;
        sum-=A[l];
        l++;
        if(l>r){
            r=l;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<pair<int, int> > AB(N, pair<int, int>());
  REP(i, N){
    int a, b; cin >> a >> b;
    AB[i] = {a, b};
  }
  sort(AB.begin(), AB.end(), greater<pair<int, int> >());
  cout << AB[0].first + AB[0].second << endl;
}

Measured memory_bytes: 1024
N = int(input())
S=[]
ans=0
ab=0
a=0
b=0
for i in range(N):
    tmp=input()
    ans+=tmp.count("AB")
    if tmp[-1]=="A" and tmp[0]=="B":
        ab +=1
    elif tmp[-1]=="A":
        a+=1
    elif tmp[0]=="B":
        b+=1
    S.append(tmp)
#print(ans,ab,a,b)
if(ab==0):
    print(ans+min(a,b))
elif(a==0 and b==0):
    print(ans+ab-1)
else:
    print(ans+ab+min(a,b))


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  	ll n;
  	cin>>n;
  	ll a[n], x = 0, y = 0, ans = INT_MAX;
  	for(int i = 0; i < n; i++)
    {
    	cin>>a[i];
      	x += a[i];
    }
  	for(int i = 0; i < n; i++)
    {
    	y += a[i];
      	if(i+1 < n)
          	ans = min(ans, abs(x-2*y));
    }
  	cout<<ans;
	return 0;
}

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

int main(){
  int n,nu=0,x=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      nu++;
    }
    else if(s[i]=='D'){
      nu--;
    }
    if(nu>x){
      x=nu;
    }
    
  }
  
  cout<<x<<endl;
}
  
    


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

def combination2(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))

def combination(n, r):
    # X = n * n-1 * ... * max(r, n - r)+1
    # Y = min(r, n - r)!
    # nCr = X / Y
    if n <= 1:
        return 0

    X = 1
    for i in range(n, max(r, n - r), -1):
        X *= i
    
    if n - r <= 0:
        return X

    Y = math.factorial(min(r, n - r))

    return X / Y

class UnionFindTree():
    def __init__(self, n):
        self.parent = [] # 親のノード
        self.rank = [] # 木の深さ
        self.number = [] # グループの要素数
        for i in range(n):
            self.parent.append(i)
            self.rank.append(0)
            self.number.append(1)

    # 根ノードを取得
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    # 併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.number[y] += self.number[x]
        else:
            self.parent[y] = x
            self.number[x] += self.number[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じノードか判別
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # グループのノード数を取得
    def member_number(self, x):
        x = self.find(x)
        return self.number[x]

N = int(input())
A = [int(i) for i in input().split()]

uft = UnionFindTree(N)

vals = {}
for i in range(N):
    if A[i] in vals:
        uft.unite(vals[A[i]], i)
    else:
        vals[A[i]] = i

comb = {}
group_numbers = {}
total = 0
comb_memo = {}
for k, v in vals.items():
    group_number = uft.member_number(v)
    if group_number not in comb_memo:
        comb_memo[group_number] = combination(group_number, 2)
    comb[k] = comb_memo[group_number]

    group_numbers[k] = group_number
    total += comb[k]

ans = {}
for k, v in vals.items():
    if group_numbers[k] - 1 not in comb_memo:
        comb_memo[group_numbers[k] - 1] = combination(group_numbers[k] - 1, 2)
    ans[k] = int(total - comb[k] + comb_memo[group_numbers[k] - 1])

for a in A:
    print(ans[a])

Measured memory_bytes: 61052
// http://www.igaris.com/math/c.pdf

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define NEXTP(x) next_permutation(x.begin(),x.end())
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

class comb{
	public:
	vector<ll> f,fr;
	ll MOD;
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){//input max_n
		MOD = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
			fr[i] = calc(f[i],mod-2,mod);
		}
	}
	ll nCr(ll n,ll r){
		return f[n] * fr[r] % MOD * fr[n-r] % MOD;
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	ll ans = 0;
	cin >> n >> k;
	comb co;
	co.init(n+k,MOD);
	if(k<n){
		cout << 0 << endl;
		return 0;
	}
	cout << co.nCr(k,n)*co.f[n]%MOD << endl;
}


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

#define int long long 
const int INF = 1e18;

signed main()
{
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i=0;i<n;++i) cin >> h[i];
	
	vector<int> dp(n,INF);
	
	dp[0] = 0;
	for(int i=1;i<n;++i)
	{
		for(int j=1;j<=k;++j)
		{
			if(i-j >= 0)
			{
				dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
			}
			else
			{
				break;
			}
		}
	}
	
	cout << dp[n-1];
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main()
{
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if (a <=5) {
		ans = 0;
	}
	else if(a<=12){
		ans = b / 2;
	}
	else {
		ans = b;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define st string
#define pairi pair<int,int>

int solve(int arr[], int brr[], int n, int m) 
{ 
	map<int,int> ma; 
	sidha(i,0,m){
		ma[brr[i]]++;
	}
    int count = 0; 
    for (int i = 0; i < n; i++) { 
      for (int j = i + 1; j < n; j++) { 
        for (int k = j + 1; k < n; k++){
          if ( arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[k] + arr[j] > arr[i]) {
            count+=(ma[arr[i]]*ma[arr[j]]*ma[arr[k]]);
						//cout<<arr[i]<<" "<<arr[j]<<" "<<arr[k]<<endl;
					}
				}
      } 
    } 
    return count; 
} 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	int n;cin>>n;
	int arr[n];
	set<int> s;
	sidha(i,0,n){
		cin>>arr[i];
		s.insert(arr[i]);
	}
	int brr[s.size()];
	vi v;
	for(auto it=s.begin();it!=s.end();it++){
		v.pb(*it);
	}
	sidha(i,0,v.size()){
		brr[i]=v[i];
	//	cout<<brr[i]<<" ";
	}
	cout<<solve(brr,arr,v.size(),n)<<endl;
}

Measured memory_bytes: 3648
# coding: utf-8

n = input()
an = map(int, raw_input().split())

d = {}
for a in an:
    if not a in d:
        d[a] = 1
    else:
        d[a] += 1
#print d

sa = 0
for ai in d:
    si = d[ai] * (d[ai] - 1) // 2
    sa += si

for a in an:
    a1 = d[a] * (d[a] - 1) // 2
    a2 = (d[a] - 1) * (d[a] - 2) // 2

    print sa - a1 + a2


Measured memory_bytes: 20500
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x, y, z, GCD, GCD_n;
    x = sc.nextInt();
    y = sc.nextInt();
    if (x < y) { //swap
      z = x;
      x = y;
      y = z;
    }
    GCD = y;
    GCD_n = x % GCD;
    while(GCD_n != 0) {
      x = GCD;
      GCD = GCD_n;
      GCD_n = x % GCD;
    }
    System.out.println(GCD);
    sc.close();
  }
}



Measured memory_bytes: 26300