akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n;cin>>n;
    vector<ld> a(n);
    ld sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
    }
    ld ave=sum/n, mi=INF;
    int idx=-1;
    for(int i=0;i<n;i++){
        if(abs(ave-a[i])<mi){
            mi = abs(ave-a[i]);
            idx=i;
        }
    }
    cout<<idx<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define up(i,x,y) for(register int i=x;i<=y;++i)

using namespace std;
const int N=2e5+5;
int a[N],b[N];

int main() {
	int n;
	scanf("%d",&n);
	up(i,1,n) {
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1,greater<int>());
	if(b[1]==b[2]) up(i,1,n) {
		printf("%d\n",b[1]);
	} else {
		up(i,1,n) {
			printf("%d\n",((a[i]==b[1])?b[2]:b[1]));
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000000000000000

/*方針*/
//連続で正の値が続いている部分について、水やりを行う

/*ex) 4  23  75  0  23  96  50  100
      <------->     <------------->		計27回
       4回水やり　　　　23回水やり

	  0  19  71  0  0   73  27   67
	     <---->         <--------->		計27+46=73回
		 19回水やり　　　　27回水やり
	  
	  0   0  52  0  0   46   0   40
	         <->        <->      <->    計73+148=221回
			 52回       46回     40回
*/

/*
➀連続の正の値の区間に対して、その区間における最小値分、水やりをする。(vector hから最小値を引く)
➁hが0になるまで➀を繰り返す
*/

int main(){
	int n;cin>>n;
	vector<int> h(n+1);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	h[n]=0;//番兵

	int ans=0;
	bool allzero=false;

/*➁*/	while(!allzero){//hが全部0になるまで
		int num=0;
		for(int i=0;i<=n;i++){//0探す
			int MIN=10000000;

			if(h[i]==0){
/*➀*/				for(int j=num;j<i;j++){
					MIN=min(MIN,h[j]);
				}
				if(MIN!=10000000) ans+=MIN;
				for(int j=num;j<i;j++){
					h[j]-=MIN;
				}
				num=i+1;
			}
		}

		for(int i=0;i<=n;i++){//全部0になったか
			if(h[i]==0){allzero=true;}
			else{allzero=false;break;}
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
	int a; std::cin >> a;
	std::string op; std::cin >> op;
	int b; std::cin >> b;
	if(op=="+") std::cout << a+b;
	else std::cout << a-b;
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)b-*(int*)a;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int bag[4][100];
int sum[4][101];
int size[4];
int w[100],v[100];
ll ws[4];
int main(void)
{
	int n,W,index,vsum,i,j,k,l;
	int w_0=INT_MAX,ans=0;
	ll s;
	scanf("%d%d",&n,&W);
	FOR(i,0,n){
		scanf("%d%d",&w[i],&v[i]);
		w_0=MIN(w_0,w[i]);
	}
	FOR(i,0,4) ws[i]=w_0+i;
	FOR(i,0,n){
		index=w[i]-w_0;
		bag[index][size[index]++]=v[i];
	}
	FOR(i,0,4){
		qsort(bag[i],size[i],sizeof(int),comp);
		sum[i][1]=bag[i][0];
		FOR(j,2,size[i]+1){
			sum[i][j]=sum[i][j-1]+bag[i][j-1];
		}
	}
	FOR(i,0,size[0]+1){
		FOR(j,0,size[1]+1){
			FOR(k,0,size[2]+1){
				FOR(l,0,size[3]+1){
					s=ws[0]*i+ws[1]*j+ws[2]*k+ws[3]*l;
					if(s<=W){
						vsum=sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l];
						ans=MAX(ans,vsum);
					}
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
    
    
    

Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int main() {
	// your code goes here
	long int t=1;
// 	cin>>t;
	while(t--)
	{
	   long int n;
	   cin>>n;
	   long int a[n],b[n];
	   pair<long int,long int> c[n+1],d[n+1];
	   for(long int i=0;i<=n;i++)
	   c[i].ff=0,d[i].ff=0;
	   for(long int i=0;i<n;i++)
	   {
	     cin>>a[i];
	     c[a[i]].ff++;
	     c[a[i]].ss=i;
	   }
	   for(long int i=0;i<n;i++)
	   {
	       cin>>b[i];
	       d[b[i]].ff++;
	       if(d[b[i]].ff==1)
	       d[b[i]].ss=i;
	   }
	   long int ans=-1,ans1=0;
	   for(long int i=1;i<=n;i++)
	   {
	       if(c[i].ff+d[i].ff>n)
	       {
	           cout<<"No";
	           return 0;
	       }
	       if(c[i].ff>0 && d[i].ff>0 && c[i].ss-d[i].ss>ans)
	       {
	           ans=c[i].ss-d[i].ss;
	           ans1=i;
	       }
	   }
	   long int pos=0;
	   for(long int i=0;i<n;i++)
	   {
	       if(a[i]==ans1)
	       pos=i;
	   }
	   pos++;
	   long int kk[n];
	   long int in=0;
	   for(long int i=0;i<n;i++)
	   {
	       if(b[i]==ans1)
	       {
	           in=i;
	           break ;
	       }
	   }
	   for(long int i=in;i<in+n;i++)
	   {
	      long int j=i%n;
	      pos%=n;
	     kk[pos] = b[j];
	      pos++;
	   }
	   cout<<"Yes"<<endl;
	   for(long int i=0;i<n;i++)
	   cout<<kk[i]<<" ";
	}
	return 0;
}


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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll  a,b,c,s,t,i,j,k,x,y,z;
 ll A,B,C,S,T,X,Y,Z;
 ll count;

 long double pi=3.14159;

 string N;

signed main(){
	
	cin>>N;

	if(N[2]==N[3] && N[4]==N[5]) cout<<"Yes";
	else cout<<"No";


 return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

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

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}

	for (int i = 0; i < n; i++) {
		cout << 1 + i * (n + 1) << " ";
	}
	cout << endl;

	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		b[i] = 1 + i * (n + 1);
	}
	reverse(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		b[p[i]] += i;
	}

	for (int bi : b) {
		cout << bi << " ";
	}

}

Measured memory_bytes: 3760
#! /usr/bin/env python3

def main():
    s = input()
    for i in range(len(s)-2):
        if len(set(s[i: i+3])) < 3:
            print(i+1, i+3)
            return
    for i in range(len(s)-1):
        if len(set(s[i: i+2])) < 2:
            print(i+1, i+2)
            return
    print(-1, -1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);

void solve(int T){
    int n,l;
    cin>>n>>l;
    vector<string>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)cout<<v[i];
}
int main() {
    fastio

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()

    i = 1
    ans = 0
    for a in A:
        if i % 2 == 1 and a % 2 == 1:
            ans += 1
        i += 1
    print(ans)


if __name__ == '__main__':
    solve()


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


int main()
{
  int n;
  cin >> n;
  vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
  dp[0][0] = 1;
  rep(i, n)
  {
    double p;
    cin >> p;
    rep(j, n)
    {
      dp[i+1][j] += dp[i][j] * (1 - p);
      dp[i+1][j+1] += dp[i][j] * p;
    }
  }
  double ans = 0;
  for (int i = n / 2 + 1; i <= n; i++)
    ans += dp[n][i];
  printf("%.10lf\n", ans);
  return 0;
}

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

int main(){

    double a;
    cin >> a;
    double res1 = 0;
    double res2 = 0;

    res1 = a * a * 3.141592653589;
    res2 = a * 2 * 3.141592653589;

    printf("%f %f\n", res1, res2);
    return 0;
}



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

int main(){
	long k,n;
	cin >> k >> n;
  	vector<int> a(n);
  	for(int i = 0; i < n; i++)
      cin >> a[i];
  	int max = 0;
  	for(int i = 0; i < n-1; i++) {
    	 if(max < a[i+1] - a[i]) {
           	max = a[i+1] -a[i];
         }
    }
  	if(max < a[0] + k - a[n-1]) {
     	max = a[0] + k - a[n-1];
    }
  	cout << k-max << endl;	
}


Measured memory_bytes: 1024
a = input().split()
b = int(a[0]) // 2
c = int(a[0]) % 2
if int(a[0]) == 1 or int(a[1]) == 1:
  print("1")
elif c == 0:
  print(int(int(b) * int(a[1])))
else:
  if int(a[1]) % 2 == 1:
    print(int(int(b) * int(a[1]) + int(a[1]) // 2 + 1))
  else:
    print(int(int(b) * int(a[1]) + int(a[1]) // 2))

Measured memory_bytes: 61812
N, Y = map(int, input().split())
result = [-1, -1, -1]

for i in reversed(range(N + 1)):
  for j in reversed(range(N + 1 - i)):
    if (i * 10000 + j * 5000 + (N - i - j) * 1000) == Y:
      result = [i, j, N - i - j]
      break
print(' '.join(map(str, result)))

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<ll> cnt,used;
vector<vector<ll>> G;
void dfs(ll root, ll num){
    used[root]=1;
    cnt[root]+=num;
    for(ll x:G[root]){
        if(used[x]==0)dfs(x, cnt[root]);
    }
    return;
}

int main() {
    ll n, m, i, j, k;
    ll q;
    cin >> n >> q;
    cnt.resize(n+1);
    used.resize(n+1);
    for(i=0;i<=n;i++){
        cnt[i]=used[i]=0;
    }
    G.resize(n+1);
    for(i=0;i<n-1;i++){
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(i=0;i<q;i++){
        ll p,x;
        cin >> p >> x;
        cnt[p]+=x;
    }
    dfs(1LL, 0LL);
    for(i=0;i<n;i++){
        cout << cnt[i+1] << " ";
    }
    cout << endl;
    return 0;
}


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

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

    int N;
    cin >> N;
    int a[N];
    for (int i=0; i<N; i++) cin >> a[i];
    int mx = -1;
    int mn = 9999;
    for (int i=0; i<N; i++) {
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }
    cout << (mx-mn) << endl;
}


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

int main() {
    int r, g, b;
    cin  >> r >> g >> b;
    int num = 100*r + 10*g + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		double now_length = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa - now_min >= eps || (abs(goa - now_min) <= eps && (abs(a[i] - a[starter]) - now_length) >= eps)) {
					now_min = goa;
					now_go = i;
					now_length = abs(a[i] - a[starter]);
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
int main() {
	double x, p;
	cin >> x >> p;
	p /= 100.0;
	cout << fixed << setprecision(100);
	cout << ceil(x / 2) / p << endl;
}

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

int main(){

    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    long long ans = 0;
    int right = 0;
    int sum = 0;
    for(int left = 0; left < N; left++){
        while(right < N && (sum ^ A[right]) == (sum + A[right])){
            sum += A[right];
            right++;
        }
        ans += right - left;
        if (left == right) right++;
        else sum -= A[left];
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	int a, b, c, t;
	while(cin >> a >> b >> c){
	int d = 20 - (a + b);
	t = 0;
	for(int i = 1;i < 11;++i){
		if(d >= i){
			if(i != a && i != b && i != c){
				++t;
			}
		}
	  }
	  if(t >= 4) cout << "YES" << endl;
	  else cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i <= (b); i++)

const int N = 1e5 + 100;

char s[10];

int main() {
  cin >> (s + 1);
  if (s[1] == 'S') puts("Cloudy");
  if (s[1] == 'C') puts("Rainy");
  if (s[1] == 'R') puts("Sunny");
  return 0;
}

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

int main() {
  long long x;
  cin >> x;
  long long y = sqrt(x) + 1;
  int i = 2;
  if(x <= 2){
    x = 2;
    cout << x << endl;
  }else if(x == 3){
    cout << x << endl;
  }else{
    while(1){
      if(x % i != 0){
	if(i <= y){
	  i++;
	  continue;
	}else{
	  cout << x << endl;
	  break;
	}
      }else{
	x++;
	i = 2;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+10;
LL num[maxn];
map<int,int>mp;
LL C(LL x)
{
    if(x==0)
        return 0;
    return x*(x-1)/2;
}
int main()
{
  int n;
  cin >> n;
  int x;
  for(int i = 0;i<n;++i)
  {
      cin >>x;
    num[i] = x;
      mp[x]++;
  }
  LL ans = 0;
  for(map<int,int>::iterator it =mp.begin();it!=mp.end();++it)
  {
      int d = it->second;
      ans+=C(d);
  }
  for(int i = 0;i<n;++i)
  {
      int d = num[i];
      cout << ans-C(mp[d])+C(mp[d]-1) << "\n";
  }
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

void solve()
{
	ll a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='+')
		cout<<a+b;
	else
		cout<<a-b;
	return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3612
alp=['************','*qwertyuiop*','*asdfghjkl**','*zxcvbnm****','************']
_alp=''.join(alp)
def check(now,nxt):
    a,b=_alp.find(now)//12,_alp.find(now)%12
    c,d=_alp.find(nxt)//12,_alp.find(nxt)%12
    q1=_log[-1]
    q2='L' if d<=5 else 'R'
    log.append(q2)
    if abs(a-c) + abs(b-d)<=1 :
        _log.append(q1)
    else:
        _log.append(q2)

while 1:
    s=input()
    if s=='#':
        break
    log=['L' if _alp.find(s[0])%12<=5 else 'R']
    _log=[log[0]]
    for i in range(len(s)-1):
        check(s[i],s[i+1])
    
    count=0
    for x,y in zip(log,_log):
        if x!=y:
            count+=1
    c=log[0]
    ans=0
    for v in log:
        if c!=v:
            c=v
            ans+=1
    print(ans)
    


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

/*ll comb(ll a, ll b){ //aCb
    ll c = 1;
    REP(i, b)
    {
        c *= (a - i) / (1 + i);
    }
    return c;
}*/

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

    ll N;
    string S;
    cin >> N;
    vector<string> vec(N);
    REP(i, N)
        cin >> vec.at(i);

    REP(i,N){
        sort(vec.at(i).begin(), vec.at(i).end());
    }

    sort(vec.begin(), vec.end());

    /*REP(i,N){
        cout << vec.at(i) << endl;
    }*/

    ll count = 1;
    ll ans = 0;

    REP(i,N-1){
        if(vec.at(i)==vec.at(i+1)){
            count++;
        }
        else{
            if(count>1){
                ans += count*(count-1)/2;
                count = 1;
            }
        }
    }
    if (count > 1)
    {
        ans += count * (count - 1) / 2;
        count = 1;
    }
    cout << ans << endl;

}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

typedef string::const_iterator Iter;

int expr(Iter &p);
int term(Iter &p);
int factor(Iter &p);
int number(Iter &p);

int expr(Iter &p) {
	int r = term(p);
	for(;;)  {
		if(*p == '+') {
			p++;
			int rs = term(p);
			r += rs;
		}
		else if(*p == '-') {
			p++;
			int rs = term(p);
			r -= rs;
		}
		else
			break;
	}
	return r;
}

int term(Iter &p) {
	int r = factor(p);
	for(;;) {
		if(*p == '*') {
			p++;
			int rs = factor(p);
			r *= rs;
		}
		else if(*p == '/') {
			p++;
			int rs = factor(p);
			r /= rs;
		}
		else
			break;
	}
	return r;
}

int factor(Iter &p) {
	if(*p == '(') {
		p++;
		int r = expr(p);
		p++;
		return r;
	}
	else
		return number(p);
}

int number(Iter &p) {
	int r = 0;
	while(isdigit(*p)) {
		r *= 10;
		r += *p - '0';
		p++;
	}
	return r;
}

int main() {
	int N;
	cin >> N;
	cin.ignore();
	while(N--) {
		string line;
		getline(cin, line);
		line = line += "|";
		Iter begin = line.begin();
		cout << expr(begin) << endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, R;
    cin >> N >> R;
    cout << R + 100 * max(0, (10 - N))<< endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<algorithm>
#include<functional>
#include<iostream>
#define rep(i,a) for(int i=1;i<=a;i++)
#define LL long long int
using namespace std;
int main(void)
{
	LL n,sum,x=1;
	cin>>n;
	rep(i,n) {
		x=(x*i)%1000000007;
		sum=x;
	}
	cout<<sum<<endl;
	return 0;
}
	

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

L = int(input())

if L == 2:
    print (2, 2)
    print (1, 2, 0)
    print (1, 2, 1)
    exit()

L -= 1

N = len(bin(L)) - 2 #頂点数


M = 0
G = []
G_append = G.append

for i in range(N - 1):
    G.append((i + 1, i + 2, 0))
    G.append((i + 1, i + 2, 2 ** (N - 2 - i)))

# print (G)
tmp = 2 ** (N - 1)
for i in range(N - 2, 0, -1):
    if (L >> i) & 1:
        G.append((1, N - i, tmp))
        tmp += 2 ** i

if 2 ** (N - 1) == L + 1:
    pass
else:
    if (L >> 0) & 1:
        G.append((1, N, tmp))
        G.append((1, N, tmp + 1))
    else:
        G.append((1, N , tmp))

print (N, len(G))
for g in G:
    print (*g, sep = ' ')

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


int N;

int main(){
	cin >> N;
	int x[N], y[N], h[N];
	int maxh = 0;
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i] >> h[i];
	}
	for(int cx=0;cx<101;cx++){
		for(int cy=0;cy<101;cy++){
			for(int k=0;k<N;k++){
				int ch = abs(x[k]-cx)+ abs(y[k]-cy) + h[k];
				for(int l=0;l<N;l++){
					if(max(ch-abs(x[l]-cx)-abs(y[l]-cy),0) != h[l]){
						break;
					}else if(l == N-1){
						cout << cx << " " << cy << " " << ch << endl;
						return 0;
					}
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
# include "cstdio"
# include "algorithm" 
# define ll long long 

using namespace std;

int main(){
	ll a,b,ans=0;
	scanf("%lld%lld",&a,&b);
	ans=a+b;
	ans=max(ans,max(a-b,a*b));
	printf("%lld",ans);
	return 0; 
} 

Measured memory_bytes: 128
import sys
import fractions
from functools import reduce

# N 時計の数
n = int(input())

# Ti 各時計が1周する秒数
t = [int(input()) for i in range(n)]

# 最小公倍数を求める
def lcm_base(a, b):
    return (a * b) // fractions.gcd(a, b)

def lcm(*num_list):
    return reduce(lcm_base, num_list, 1)

print(lcm(*t))

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define forn(i,n) for(int i=0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fst first
#define snd second

int main() {
    ios::sync_with_stdio(false);
    vi x(3);
    forn(i, 3) cin >> x[i];
    sort(all(x));
    cout << (x[2] - x[0]) << '\n';
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  string s;cin>>s;
  vector<set<ll>>st(26);
  rep(i,0,n)st[s[i]-'a'].insert(i);
  ll q;cin>>q;
  while(q--){
    ll t;cin>>t;
    if(t==1){
      ll x;cin>>x;x--;
      char c;cin>>c;
      st[s[x]-'a'].erase(x);
      st[c-'a'].insert(x);
      s[x]=c;
    }
    else{
      ll l,r;cin>>l>>r;l--;
      ll ret=0;
      rep(i,0,26){
        if(st[i].lower_bound(l)!=st[i].end()&&*st[i].lower_bound(l)<r)ret++;
      }
      cout<<ret<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 24220
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n, p;
    cin >> n >> p;
    int a[52];
    int count0 = 0, count1 = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2) count1++;
        else count0++;
    }
    if(count1 == 0 && p == 1){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 0; i < count0; i++) ans *= 2;
    for(int i = 0; i < count1 - 1; i++) ans *= 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 233333;
int n,a[N],b[N];ll res;
priority_queue<Pii>heap;
void GG(){puts("-1");exit(0);}
inline void ins(int i){
	if(a[i]!=b[i])heap.push(Pii(b[i],i));
	if(a[i]>b[i])GG();
}
int qry(int i){
	if(i<1)i+=n;
	if(i>n)i-=n;
	return b[i];
}
int main() {
	read(n);rep(i,1,n)read(a[i]);
	rep(i,1,n)read(b[i]);
	rep(i,1,n)ins(i);
	while(!heap.empty()){
		int i=heap.top().se;heap.pop();
		int mx=max(qry(i-1),qry(i+1));
		int c=qry(i-1)+qry(i+1);
		int x=min(b[i]-a[i],c-mx+b[i]-1)/c;
		if(!x)continue;
		res+=x;b[i]-=c*x;
		ins(i);
	}
	rep(i,1,n)if(a[i]!=b[i])GG();cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n + 1), b(n + 1), c(n + 1);
    for(ll i = 1; i <= n; i++) cin >> a[i];
    for(ll i = 1; i <= n; i++) cin >> b[i];
    for(ll i = 1; i < n; i++) cin >> c[i];
    
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        ans += b[a[i]];
        if(i < n){
            if(a[i] + 1 == a[i + 1]){
                ans += c[a[i]];
            }
        }
    }

    cout << ans << endl;

    
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{   
    int n, m, k;
    cin >> n >> m >> k;
    vi a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(j, m) cin >> b[j];

    ll t = 0;
    rep(i, m) t += b[i];

    int j = m;
    int ans = 0;
    rep(i, n+1) {
        while(j > 0 && t > k) {
            j--;
            t -= b[j];
        }
        if(t > k) break;
        ans = max(ans, i + j);
        if(i == n) break;
        t += a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1ll << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
double T;
/* function */
/* main */
int main(){
    ll N, K;
    cin >> N >> K;
    vector<pll> v(N);
    ll t, d;
    for (int i = 0; i < N; i++) {
        cin >> t >> d;
        v[i] = pll(d, t);
    }
    sort(v.begin(), v.end(), greater<pll>());

    priority_queue<ll> PQ;
    set<ll> S;
    ll sum = 0;
    ll kind = 0;
    for (int i = 0; i < K; i++) {
        sum += v[i].first;
        if (S.count(v[i].second) == 0) {
            S.insert(v[i].second);
            kind++;
        }
        else { PQ.push(-v[i].first); }
    }

    ll ans = sum + kind * kind;
    for (int i = K; i < N; i++) {
        if (PQ.empty()) break;
        if (S.count(v[i].second) == 0) {
            sum += PQ.top(); PQ.pop();
            sum += v[i].first;
            kind++;
            S.insert(v[i].second);
            ans = max(ans, sum + kind * kind);
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5116
#include <iostream>
#include <vector>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace  std;

const double cos60 = cos(M_PI / 3);
const double sin60 = sin(M_PI / 3);

struct StPnt
{
  double m_nx;
  double m_ny;

  StPnt() :
    m_nx(0), m_ny(0)
  { }

  StPnt(double nx, double ny) :
    m_nx(nx), m_ny(ny)
  { }
};

void fnInput(int &rnRcSiz)
{
  cin >> rnRcSiz;
}

void fnKochCrv( const StPnt &cnroPnt1, const StPnt &cnroPnt2, vector<StPnt> &rvoRtnPnt)
{
  rvoRtnPnt[0] = cnroPnt1;
  rvoRtnPnt[1].m_nx = (2 * cnroPnt1.m_nx + cnroPnt2.m_nx) / 3;
  rvoRtnPnt[1].m_ny = (2 * cnroPnt1.m_ny + cnroPnt2.m_ny) / 3;
  rvoRtnPnt[3].m_nx = (cnroPnt1.m_nx + 2 * cnroPnt2.m_nx) / 3;
  rvoRtnPnt[3].m_ny = (cnroPnt1.m_ny + 2 * cnroPnt2.m_ny) / 3;

  rvoRtnPnt[2].m_nx =  (rvoRtnPnt[3].m_nx - rvoRtnPnt[1].m_nx) * cos60 
                     - (rvoRtnPnt[3].m_ny - rvoRtnPnt[1].m_ny) * sin60 + rvoRtnPnt[1].m_nx;
  rvoRtnPnt[2].m_ny =  (rvoRtnPnt[3].m_nx - rvoRtnPnt[1].m_nx) * sin60 
                     + (rvoRtnPnt[3].m_ny - rvoRtnPnt[1].m_ny) * cos60 + rvoRtnPnt[1].m_ny;

  rvoRtnPnt[4] = cnroPnt2;
}

void fnKochCtl(int nRcSiz, vector<vector<StPnt>> &rvvoPnt)
{
  StPnt oPntB(0.0, 0.0);
  StPnt oPntE(100.0, 0.0);

  rvvoPnt.resize(7);
  rvvoPnt[0].clear();
  rvvoPnt[0].push_back(oPntB);
  rvvoPnt[0].push_back(oPntE);

  for (int nRc = 0; nRc < nRcSiz; nRc++)
  {
    rvvoPnt[nRc + 1].clear();
    rvvoPnt[nRc + 1].push_back(oPntB);
    for (int i = 0; i < rvvoPnt[nRc].size() - 1; i++)
    {
      StPnt oPnt1 = rvvoPnt[nRc][i];
      StPnt oPnt2 = rvvoPnt[nRc][i + 1];
      vector<StPnt> voRtnPnt(5);

      fnKochCrv(oPnt1, oPnt2, voRtnPnt);
      for (int j = 1; j < 5; j++)
        rvvoPnt[nRc + 1].push_back(voRtnPnt[j]);
    }
  }
}

void fnResult(int nRcSiz, const vector<vector<StPnt>> &cnrvvoPnt)
{
  for (int i = 0; i < cnrvvoPnt[nRcSiz].size(); i++)
    cout << cnrvvoPnt[nRcSiz][i].m_nx << " " << cnrvvoPnt[nRcSiz][i].m_ny << endl;
}

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

  int nRcSiz;
  vector<vector<StPnt>> vvoPnt;

  fnInput(nRcSiz);
  fnKochCtl(nRcSiz, vvoPnt);

  fnResult(nRcSiz, vvoPnt);

  return 0;
}

Measured memory_bytes: 3376
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    string s,c[5]={"hi","hihi","hihihi","hihihihi","hihihihihi"};
    in>>s;
    bool f{};
    fr(i,5) if(s==c[i]) f=true;
    puts(f?"Yes":"No");
}

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

#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 each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        char c; cin>>c;
        if(c=='A')cout<<'T'<<endl;
        else if(c=='T')cout<<'A'<<endl;
        else if(c=='C')cout<<'G'<<endl;
        else cout<<'C'<<endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i,n) cin >>a[i];
	
	sort(all(a));
	int f1 = a.back(), f2=-1;
	ll mn = 1LL<<55;
	rep(i, n-1){
		if(mn > abs(2*a[i] - f1)){
			mn = abs(2*a[i] - f1); f2 = a[i];
		}
	}
	cout << f1 <<" "<<f2<<"\n";
	return 0;
}


Measured memory_bytes: 1276
#include<stdio.h>
#define MAX 500
int main()
{
  int a,b,i=1;
  int array[MAX];
  scanf("%d%d",&a,&b);
  array[1] = a;
  array[2] = b;
  while(array[i]!=array[i+1])
    {
      if(array[i] > array[i+1])
	{
	  array[i+2] = array[i] - array[i+1];
	}
      else
	{
	  array[i+2] = array[i+1] - array[i];
	}
      i++;
    }
  printf("%d\n",array[i]);
  return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  string S;
  cin >> S;
  const char* s = S.c_str();

  ll ans = 0;
  REP(i, 0, S.size()) {
    ll cnt = 0;
    REP(j, 0, i+1) {
      if (s[j] == 'I') {
        cnt++;
      } else {
        cnt--;
      }
    }
    if (ans < cnt) {
      ans = cnt;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

#define N 3
#define N2 9

struct Puzzle {
	int f[N2];
	int space;
	string path;
	bool operator <(const Puzzle &p) const {
		for (int i = 0; i < N2; ++i) {
			if (f[i] == p.f[i])
				continue;
			return f[i] > p.f[i];
		}
		return false;
	}
};
bool isTarget(Puzzle p) {
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] != i + 1) {
			return false;
		}
	}
	return true;
}
const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };

string bfs(Puzzle p) {
	queue<Puzzle> Q;
	p.path = "";
	Q.push(p);
	Puzzle u, v;
	map<Puzzle, bool> M;
	M[p] = true;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (isTarget(u))
			return u.path;
		int sx = u.space / N;
		int sy = u.space % N;
		for (int r = 0; r < 4; ++r) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)
				continue;
			v = u;
			swap(v.f[u.space], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if (!M[v]) {
				M[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}
	return "not solved";
}

int main() {

	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		cin >> p.f[i];
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = bfs(p);
	cout << ans.size() << endl;

	return 0;
}

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

const int INF = 1e+9;

int main() {
	string s;
	int ans = 0;
	while(cin >> s){
		int res = 0, cnt = 0, sum = 0;
		for(int i = 0; i < s.size(); ++i){
			if('0' <= s[i] && s[i] <= '9'){
				if(cnt != 0)
					sum *= 10;
				sum += s[i] - '0';
				cnt++;
			}
			else{
				res += sum;
				cnt = 0;
				sum = 0;
			}
		}
		res += sum;
		ans += res;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1188
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<long long,long long>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(long long i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const long long N=1e5+5;
int main()
{
   ll n;
   lscn(n);

   ll ans=0;

   ll cnt=0;

   while(1)
   {
      ans=ans*10+7;

      ans=ans%n;
      cnt++;

      if(ans==0)
      {
         cout<<cnt<<endl;
         return 0;
         break;
      }

      if(cnt>n*50)
      {
         cout<<-1<<endl;
         return 0;
      }
   }

   
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 998244353;

ll powm(ll b, ll i, ll m) {
  if (i == 0) return 1;
  if ((i%2) == 1) return powm(b, i-1, m) * b % m;
  ll h = powm(b, i/2, m);
  return h * h % m;
}

int main()
{
  int n;
  cin>>n;
  vecint d(n);
  vecint cnt(n);
  for(auto& e:d) {
    cin>>e;
    ++cnt[e];
  }
  if (d[0] != 0 || cnt[0] != 1) {
    cout<<0<<endl;
    return 0;
  }
  bool conti = true;
  bool ok = true;
  for(const auto& e:cnt) {
    if (e==0) {
      conti=false;
    } else {
      if (!conti) ok = false;
    }
  }
  if (!ok) {
    cout<<0<<endl;
    return 0;
  }
  ll mul = 1;
  for (int i:irange(0,n-1)) {
    if (cnt[i+1] == 0) break;
    mul *= powm(cnt[i], cnt[i+1], MOD);
    mul %= MOD;
  }
  cout<<mul<<endl;
  return 0;
}


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

ll solve(ll i,ll n,ll capacity,ll*w,ll*v,ll temp_ans,ll temp_cap,ll dp[100][100001]){
	
	if(i>=n){
		return 0;
	}
	
	if(dp[i][temp_cap]!=-1){
		return dp[i][temp_cap];
	}

	if(temp_cap+w[i]>capacity){
		dp[i][temp_cap]=solve(i+1,n,capacity,w,v,temp_ans,temp_cap,dp);
		return dp[i][temp_cap];
	}
	
	else{
	ll	a1=v[i]+solve(i+1,n,capacity,w,v,temp_ans+v[i],temp_cap+w[i],dp);
	
	ll a2=solve(i+1,n,capacity,w,v,temp_ans,temp_cap,dp);

	return dp[i][temp_cap]=max(a1,a2);
	}
}

int main(){
	#ifndef ONLINE_JUDGE 

	// For getting input from input.txt file 
	freopen("/home/devanshi/AtCoderDPproblems/Knapsack1input.txt", "r", stdin); 

	// Printing the Output to output.txt file 
	freopen("/home/devanshi/AtCoderDPproblems/Knapsack1output.txt", "w", stdout); 

	#endif 

	ll n,capacity;
	cin>>n>>capacity;

	ll*w=new ll[n];
	ll*v=new ll[n];

	for(ll i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	ll dp[100][100001];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<=capacity;j++){
			dp[i][j]=-1;
		}
	}

	ll ans=solve(0,n,capacity,w,v,0,0,dp);
	cout<<ans<<endl;

}

Measured memory_bytes: 81696
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  case class Rotation(run: Dice => Dice){
    def apply(d: Dice): Dice = run(d)
    def compose(other: Rotation): Rotation = Rotation(run compose other.run)
  }

  object Rotation {
    def id = Rotation(d => d)
    def north = Rotation(d => Dice(List(1,5,2,3,0,4).map(d.pip)))
    def east = Rotation(d => Dice(List(3,1,0,5,4,2).map(d.pip)))
    def ccw = Rotation(d => Dice(List(0,3,1,4,2,5).map(d.pip)))

    final def axial(rotation: Rotation): Seq[Rotation] =
      for(i <- 0 to 3) yield List.fill(i)(rotation).fold(id)(_ compose _)

    def enumerateTop: Seq[Rotation] =
      for(i <- 1 to 6) yield ((0 to i).map(j => if(j % 2 == 0) north else east)).fold(id)(_ compose _)

    def enumerate: Seq[Rotation] = {
      val ax = axial(ccw)
      enumerateTop.flatMap(e => ax.map(e compose _))
    }
  }

  case class Dice(pip: List[Int]){
    lazy val all: Seq[Dice] = Rotation.enumerate.map(_.run(Dice(pip)))
    def ===(that: Dice): Boolean = pip.corresponds(that.pip)(_ == _)
    def ==(that: Dice): Boolean = all.exists(_ === that)
  }

  def main(args: Array[String]): Unit = {
    val Array(n,_*) = readLine.split(" ").map(_.toInt)
    val dices = for(i <- 1 to n) yield Dice(readLine.split(" ").map(_.toInt).toList)

    val res = for{
      i <- 0 until n
      j <- i+1 until n
    } yield dices(i) == dices(j)

    println( if(res.forall(_ == false)) "Yes" else "No")
  }

}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int ans = 0;
  for (int i = 0; i < N; i++)
    ans += a[i] - 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s = br.readLine();
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
      if(s.charAt(i) == 'A' || s.charAt(i) == 'C' || s.charAt(i) == 'G' || s.charAt(i) == 'T'){
        int count = 1;
        for(int j = i + 1; j < s.length(); j++){
          if(!(s.charAt(j) == 'A' || s.charAt(j) == 'C' || s.charAt(j) == 'G' || s.charAt(j) == 'T')) break;
          count++;
        }
        ans = Math.max(ans, count);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22100
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace templete
{
    class abc96_c
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int x = input[0];
            int y = input[1];
            string[] canvas = new string[x];

            for(int i=0; i<x; i++)
            {
                canvas[i] = Console.ReadLine();
            }

            for(int i=0; i<x; i++)
            {
                for(int j=0; j<y; j++)
                {
                    if(canvas[i][j] == '#')
                    {
                        if(!((i != 0 && canvas[i-1][j] == '#') || ( i != x-1 && canvas[i+1][j] == '#') || (j != 0 && canvas[i][j-1] == '#') || (j != y-1 && canvas[i][j+1] == '#')))
                        {
                            WriteLine("No");
                            return;
                        }
                    }
                }
            }
            WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
map <int, int> x;
int main() {
	int n, a, ans=0;
	scanf("%d", &n);
	while(n--) {
		scanf("%d", &a);
		x[a]++;
	}
	for(map<int,int>::iterator it = x.begin(); it!= x.end(); it++) {
		if(it->second % 2 == 1) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        printf("%d\n", n * (n - 2) / 2);
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (i + j == n + 1) continue;
                printf("%d %d\n", i, j);
            }
        }
    }
    else {
        printf("%d\n", (n * n - 2 * n + 1) / 2);
        for (int i = 1; i <= n - 1; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (i + j == n) continue;
                printf("%d %d\n", i, j);
            }
        }
    }
}

Measured memory_bytes: 256
n, *aa = map(int, open(0).read().split())

aa.sort()

count = 1
tmp = aa[0]
for i in range(1,n):
    if 2 * tmp >= aa[i]:
        tmp += aa[i]
        count += 1
    else:
        tmp += aa[i]
        count = 1
#     print(count, tmp)

print(count)

Measured memory_bytes: 92328
# coding: UTF-8
def insertsort(A, N):
    print " ".join(A)
    A = map(int,A)
    for i in range(1,N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        out_A = map(str,A)
        print " ".join(out_A)
    return A

n =  int(raw_input())
array = raw_input().split()
insertsort(array, n)



Measured memory_bytes: 4660