akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
map<P,ll> mp;
ll nature(ll a){
  if(a>=0){return a;}
  else{return -1*a;}
}
ll gcd(ll a,ll b){
  if(a%b==0){return(b);}
  else{return(gcd(b,a%b));}
}
ll pw(ll x,ll y) {
	ll tmp = x;
	ll res = 1;
	while (y) {
		if (y%2) res = res*tmp%MOD;
		y >>= 1;
		tmp = tmp*tmp%MOD;
	}
	return res;
}
int main(){
  ll N,count0=0,rock1=0,rock2=0;
  cin>>N;
  map<P,ll> visited;
  vector<ll> A(N);//こっちにーも格納//x座標
  vector<ll> B(N);//必ず正になる//y座標
  for(ll i=0;i<N;i++){
    ll a,b;
    cin>>a>>b;
    if(a==0 && b==0){A.at(i)=0;B.at(i)=0;count0++;}
    else if(a==0 && b!=0){A.at(i)=0;B.at(i)=1;rock1++;}
    else if(a!=0 && b==0){A.at(i)=1;B.at(i)=0;rock2++;}
    else{
      //gcd(nature(a),nature(b))
      if(a>0&&b>0){A.at(i)=a/gcd(nature(a),nature(b));B.at(i)=b/gcd(nature(a),nature(b));}
      if(a<0&&b>0){A.at(i)=a/gcd(nature(a),nature(b));B.at(i)=b/gcd(nature(a),nature(b));}
      if(a>0&&b<0){A.at(i)=-1*a/gcd(nature(a),nature(b));B.at(i)=-1*b/gcd(nature(a),nature(b));}
      if(a<0&&b<0){A.at(i)=-1*a/gcd(nature(a),nature(b));B.at(i)=-1*b/gcd(nature(a),nature(b));}
    }
    mp[make_pair(A.at(i),B.at(i))]++;
    //if(i==0){cout<<A.at(i)<<" "<<B.at(i)<<endl;}
  }
  ll ans=1;
  ll n=N;
  if(n==1){cout<<1<<endl;return 0;}
  if(n==count0){cout<<n<<endl;return 0;}
//cout<<mp[make_pair(1,2)]<<endl;
  //cout<<rock1<<" "<<rock2<<endl;
  for(ll i=0;i<N;i++){
    ll count=0;
    if(A.at(i)==0 && B.at(i)==0){}
    else if(A.at(i)>0 && B.at(i)!=0 && visited[make_pair(A.at(i),B.at(i))]!=54){
      //cout<<i<<endl;
      ll x=mp[make_pair(-1*B.at(i),A.at(i))];
      ll y=mp[make_pair(A.at(i),B.at(i))];
      //cout<<pw(2,x)+pw(2,y)<<endl;
      if(x>0 && y>0){
        n-=x;
        n-=y;
        visited[make_pair(A.at(i),B.at(i))]=54;
        count+=(pw(2,x)+pw(2,y)-1);
        if(count%MOD!=0){count=count%MOD;}
        else{count=MOD;}
      }
    }else if(A.at(i)==0 && B.at(i)!=0 && visited[make_pair(0,0)]!=54 && rock1>0 && rock2>0){
      count=pw(2,rock1)+pw(2,rock2)-1;
      n-=rock1;
      n-=rock2;
      count=(count+MOD)%MOD;
      visited[make_pair(0,0)]=54;
      //cout<<43220936513<<endl;
    }
    if(count>0){ans*=count;}
    ans%=MOD;
    //if(B.at(i)==2237){cout<<i<<" "<<A.at(i)<<endl;}
    //if(count>0)cout<<i<<" "<<count<<" "<<A.at(i)<<" "<<B.at(i)<<endl;
  }
  //cout<<A.at(0)<<" "<<B.at(0)<<endl;
  //cout<<ans<<" "<<n<<endl;
  if(count0==0){ll answer=ans*pw(2,n)-1;cout<<(answer+MOD)%MOD<<endl;}
  else{ll answer=ans*pw(2,n-count0)-1+count0;cout<<(answer+MOD)%MOD<<endl;}
}

Measured memory_bytes: 31468
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    cin >> S;
    write(S == "AAA" || S == "BBB" ? "No" : "Yes");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int x = Integer.parseInt(sc.next());
        
        if((x/100)*5 >= x % 100){
            System.out.println("1");
        }else{
            System.out.println("0");
        }
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	ll ans = k;
	rep(i,n - 1) ans *= k - 1;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	 string b[] = {"a","e","i","o","u"};
	string a,c;
	c = "consonant";
	cin >> a;
	
	for (int i = 0; i < 5; i++)if (b[i] == a)c = "vowel";
	cout <<c<<endl;
} 

Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > G;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
string Psb[2] = {"Impossible", "Possible"};
string psb[2] = {"impossible", "possible"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    forn(i, n) cin >> s[i];
    forn(i, n) forn(j, m)
    {
        int t = 0;
        forn(k, 4)
        {
            if (ok(i + cx[k], n) && ok(j + cy[k], m) && s[i + cx[k]][j + cy[k]] == '#')
            {
                t = 1;
            }
        }
        if (!t && s[i][j] == '#') cout << "No", exit(0);
    }
    cout << "Yes";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

using namespace std;
typedef long long ll;
typedef pair<ll, int> Pair;

vector<vector<int>> e;

int N, M, S, K;
int P, Q;
int iszombi[100000];
int danger[100000];
ll d[100000];

void bfs() {
	queue<Pair> q;
	for (int i = 0; i < K; i++)q.push(Pair(danger[i], S));
	while (q.size()) {
		auto tmp = q.front(); q.pop();
		if (tmp.second == 0)continue;

		for (int i = 0; i < e[tmp.first].size(); i++) {
			auto next = e[tmp.first][i];
			if (iszombi[next] == 0) {
				iszombi[next] = 1;
				q.push(Pair(next, tmp.second - 1));
			}
		}
	}
}

void djk() {
	for (int i = 0; i < N; i++)d[i] = 1145141919810;
	priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
	pq.push(Pair(0, 0));
	d[0] = 0;
	while (pq.size()) {
		auto tmp = pq.top(); pq.pop();
		if (tmp.first > d[tmp.second])continue;
		
		for (int i = 0; i < e[tmp.second].size(); i++) {
			auto next = e[tmp.second][i];
			ll plus = iszombi[next] == 1 ? Q : P;
			if (iszombi[next] == 2)continue;
			if (d[next] > d[tmp.second] + plus) {
				d[next] = d[tmp.second] + plus;
				pq.push(Pair(d[next], next));
			}
		}

	}
}

int main() {
	cin >> N >> M >> K >> S;
	cin >> P >> Q;
	for (int i = 0; i < K; i++) {
		int a;
		cin >> a;
		iszombi[a - 1] = 2;
		danger[i] = a - 1;
	}

	e.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	bfs();

	djk();

	cout << d[N - 1] - (iszombi[N - 1] == 1 ? Q : (iszombi[N - 1] == 0 ? P : 1145141919810)) << endl;
	return 0;
}

Measured memory_bytes: 10540
N,M = map(int,input().split())
a = list(map(int,input().split()))
sum = 0
for i in range(N): sum+=a[i]
b = sum/(4*M)
counter = 0
for i in range(N):
  if a[i]>=b: counter+=1
if counter>=M: print("Yes")
else: print("No")

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

int main(){
	int x[2],y[2],i;
	for(i=0;i<2;i++){
		cin >> x[i];
		if(x[i]==2) y[i]=0;
		if(x[i]==4||x[i]==6||x[i]==9||x[i]==11) y[i]=1;
		if(x[i]==1||x[i]==3||x[i]==5||x[i]==7||x[i]==8||x[i]==10||x[i]==12) y[i]=2;
	}
	if(y[0]==y[1]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
std::string s;
long ans;

int main(){
    scanf("%ld", &n);
    std::cin >> s;
    for(int i = 1; i < n;i++){
        long alp[2][26];
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 26; k++){
                alp[j][k] = 0;
            }
        }
        for(int j = 0; j < i; j++){
            alp[0][s[j]-'a']++;
        }
        for(int j = i; j < n; j++){
            alp[1][s[j]-'a']++;
        }
        /*
        printf("  %ld\n", i);
        for(int j = 0; j < 2; j++){
            printf("    ");
            for(int k = 0; k < 26; k++){
                printf("%ld ", alp[j][k]);
            }
            printf("\n");
        }
        //*/
        long res = 0;
        for(int j = 0; j < 26; j++){
            if(alp[0][j] && alp[1][j]){
                res++;
            }
        }
        ans = std::max(ans, res);
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
int l1,l2;

using namespace std;
int main()
{
    ll i,j,k,l,m,n;
    string s1,s2;
    cin>>s1>>s2;
    l1=s1.length();
    l2=s2.length();
    int arr[l1+1][l2+1];
    for(i=0;i<=l1;i++)
    {
        for(j=0;j<=l2;j++)
        {
            if(i==0||j==0)
                arr[i][j]=0;
            else if(s1[i-1]==s2[j-1])
                arr[i][j]=arr[i-1][j-1]+1;
            else
                arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
        }
    }

    vector <int> vec;
    i=l1,j=l2;
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1] )
        {
            vec.push_back(j-1);
            i--;
            j--;
        }
        else if(arr[i-1][j]>arr[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    if(!vec.size())
    {
        cout<<" ";
        return 0;
    }
    for(i=vec.size()-1;i>=0;i--)
        cout<<s2[vec[i]];


}


Measured memory_bytes: 38792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ARC076
{
    class Reconciled
    {
        public static void Main()
        {
            var nm = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            var n = nm[0]; var m = nm[1];
            long mod = 1000000007;
            if (n == m) {
                WriteLine((Factorial(n, mod) * Factorial(m, mod) * 2) % mod);
            }
            else if (n == m - 1 || n == m + 1) {
                WriteLine((Factorial(n, mod) * Factorial(m, mod)) % mod);
            }
            else {
                WriteLine(0);
            }
        }
        static long Factorial(int n, long Mod = int.MaxValue)
        {
            long res = 1;
            for (var i = 1; i <= n; ++i)
                res = res * i % Mod;
            return res;
        }
    }
}


Measured memory_bytes: 13396
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)


Measured memory_bytes: 285828
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};



int main() {
    int A,B; cin>>A>>B;
    for (int i = 1; i <= 10000; ++i) {
        int tax8=(int)floor(0.08*i);
        int tax10=(int)floor(0.1*i);
        if(tax8==A&&tax10==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#define mod 1000000007
char buf[99];sz;
int N,A,B;
long p(long a,long b){
	long ret=1;
	while(b)
	{
		if(b&1)ret=ret*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ret;
}
main()
{
	read(0,buf,99);
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		N=N*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		A=A*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		B=B*10+c-'0';
	}
	long ans=p(2,N)-1;
	long x=1,y=1;
	for(int i=1;i<=A;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	ans-=x*p(y,mod-2)%mod;
	for(int i=A+1;i<=B;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	ans-=x*p(y,mod-2)%mod;
	printf("%d\n",(ans%mod+mod)%mod);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}


int main()
{
  int a[] = {1,2,1,2,1,4,1,4};
  int p[8],i=0;
  while(cin >> p[(i++)%8])
  {
    if(i%8==0)
    {
      int ans=0, md = 1e5, dist;
      REP(j,8)
      {
        dist = 0;
        REP(k,8) dist+=(p[k]>a[(k+j)%8])?p[k]-a[(k+j)%8]:0;
        if(dist == md)
        {
          int s1=0, s2=0;
          for(int k=0,d=1e7;k<8;k++,d/=10)
          {
            s1 += d*a[(k+ans)%8];
            s2 += d*a[(k+j)%8];
          }
          if(s2 < s1) ans = j;
        }
        if(dist < md)
        {
          md = dist;
          ans = j;
        }
      }
      REP(j,8) printf("%d%s",a[(j+ans)%8],j==7?"\n":" ");
    }
  }
  return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;

const int N = (int)3e3+5;

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

    int n,x;
    cin>>n>>x;
    vector<int> l(n+1);
    int d = 0, ans = 1;
    for(int i=1;i<=n;i++) {
        cin>>l[i];
        d += l[i];
        if(d<=x) ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
        int b = scan.nextInt();
        
        int squer = a*b; 
        int sum = a*2+b*2;
        
        System.out.print(squer);
        System.out.println(" " + sum);
	}

}


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

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

  for (int i = 1; i < 100000; i++) {
    if(int(i*0.08)==a && int(i*0.1)==b){
      std::cout << i << '\n';
      return 0;
    }
  }
  std::cout << "-1" << '\n';
  return 0;
}


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

int main(){
  ll N, i;
  string S, ans;
  cin >> S;
  if(S == "ABC"){
    ans = "ARC";
  } else {
    ans = "ABC";
  }

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

Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] h = new int[N];
        long[] min = new long[N];
        
        h[0] = Integer.parseInt(sc.next());
        h[1] = Integer.parseInt(sc.next());
        min[0] = 0;
        min[1] = zetta(h[0], h[1]);
        
        if(N > 2) {
            for(int i = 2; i < N; i++) {
                h[i] = Integer.parseInt(sc.next());
                if(zetta(h[i], h[i-1])+ min[i-1] > zetta(h[i], h[i-2]) + min[i-2]) {
                    min[i] = zetta(h[i], h[i-2]) + min[i-2];
                }else {
                    min[i] = zetta(h[i], h[i-1]) + min[i-1];
                }
            }
        }
        System.out.println(min[N-1]);
    }
    
    public static int zetta(int a, int b) {
        if(a >= b) {
            return a - b;
        }else {
            return b - a;
        }
    }
}

Measured memory_bytes: 49604
n,x,m = map(int,input().split())
appeared=[False]*(m+1)
appeared[x]=True
ans = [0]
ANS = 0
div = x
DIV=[]
llen = 0
cnt = 0
while cnt < n:
  if div == 0:
    break
  cnt += 1
  ANS += div
  DIV.append(div)
  ans.append(ANS)
  llen += 1
  appeared[div] = True
  if appeared[div**2%m]:
    PPP=DIV.index(div**2%m)
    ANS = (ANS-ans[PPP])*((n-PPP)//(llen-PPP))
    rem = (n-PPP)%(llen-PPP)
    ANS+=ans[rem+PPP]
    break
  div **= 2
  div %= m
  
print(ANS)


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

int n, w;
int data[101][2] = {0};
int dp[105][100005] = {0};

int solve();

int main() {
  cin >> n >> w;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 2; ++j) cin >> data[i][j];
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 0;
  for(int i = 1; i <= 100000; ++i) dp[0][i] = w + 10;
  dp[0][data[0][1]] = data[0][0];
  for(int i = 1; i < n; ++i)
    for(int j = 1; j <= 100000; ++j) {
      dp[i][j] = dp[i - 1][j];
      if(j >= data[i][1])
        dp[i][j] = min(dp[i][j], dp[i - 1][j - data[i][1]] +
                                     data[i][0]);
    }
  for(int i = 0; i <= 100000; ++i)
    if(dp[n - 1][i] <= w) ans = i;
  return ans;
}


Measured memory_bytes: 41216
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int [N];
        for (int i = 0; i < N; ++i) {
                A[i] = sc.nextInt();
        }
        
        int max = A[0];
        int min = A[0];
        for(int i = 1; i < N; ++i) {
                if (A[i] > max) {
                        max = A[i];
                } else if (A[i] < min) {
                        min = A[i];
                }
        }

        System.out.println(max- min);
	}
}


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

int cal_sum(int);

int main(void) {
    int a,b;
    int n;
    int ans = 0;
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        int res = cal_sum(i);
        if (res >= a && res <= b) {
            ans += i;
        }
    }
    cout << ans;
    return 0;
}
int cal_sum (int num) {
    int sum = num % 10;
    while(num / 10 > 0) {
        num /= 10;
        sum += num % 10;
    }
    return sum;
}


Measured memory_bytes: 256
import fractions

n = int(input())
l = list(map(int, input().split()))

gcd_l = [0]
gcd_r = [0]

for i in range(n):
  gcd_l.append(fractions.gcd(gcd_l[i], l[i]))
  gcd_r.append(fractions.gcd(gcd_r[i], l[-(i+1)]))
gcd_r = gcd_r[::-1]
# print(gcd_l)
# print(gcd_r)

ans = [0]*n
for i in range(n):
  ans[i] = fractions.gcd(gcd_l[i], gcd_r[i+1])
print(max(ans))


  
  

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if (A == 5 && B == 5 && C == 7) cout << "YES" << endl;
  else {
    if (A == 5 && B == 7 && C == 5) cout << "YES" << endl;
    else {
      if (A == 7 && B == 5 && C == 5) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

class UnionFind {
  vector<int> par, sz;
public:
  UnionFind(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++)
      par[i] = i;
    sz.resize(n, 1);
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sz[root(x)];
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (sz[x] >= sz[y]) {
      sz[x] += sz[y];
      par[y] = x;
    } else {
      sz[y] += sz[x];
      par[x] = y;
    }
    return true;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  if (m == n-1) {
    cout << 0 << endl;
    return 0;
  }
  UnionFind uf(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }
  map<int, vector<int>> mp;
  rep(i, n)
    mp[uf.root(i)].push_back(a[i]);
  for (auto& e : mp)
    sort(e.second.begin(), e.second.end());
  ll ans = 0;
  vector<int> node;
  for (auto e : mp) {
    ans += e.second[0];
    for (int i = 1; i < (int)e.second.size(); i++)
      node.push_back(e.second[i]);
  }
  if (node.size() < (int)mp.size()-2) {
    cout << "Impossible" << endl;
    return 0;
  }
  sort(node.begin(), node.end());
  rep(i, (int)mp.size()-2)
    ans += node[i];
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int min = 1000000, min_temp = 0;
  vector<int> vec(N);
  for(int i=0; i<N; i++) {
    cin >> vec.at(i);
  }
  for(int i=0; i< 100;i++) {
    min_temp = 0;
    for(int j=0; j<vec.size(); j++){
      min_temp += (i - vec.at(j)) * (i - vec.at(j));
    }
    if(min > min_temp) {
      min = min_temp;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,ans=0, i,b;
    scanf("%d", &n);
    for(i=0;i<6;i++){
        b = n%10;
        n = n/10;
        ans += b;
    }
    if( ans == 1 ){
        ans = 10;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int c = 0;
		bool prev = false;
		bool R = false;
		bool L = false;
		rep(i,n){
			char str[5];
			scanf("%s",str);
			if(strcmp(str,"lu") == 0){
				L = true;
			}
			if(strcmp(str,"ru") == 0){
				R = true;
			}
			if(strcmp(str,"ld") == 0){
				L = false;
			}
			if(strcmp(str,"rd") == 0){
				R = false;
			}
			//cout << L << " " << R << " " << prev << "\n";
			if(L != prev && R != prev){
				c++;
				prev = !prev;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int k, x;
    cin >> k >> x;
    if(500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}
  


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N;
  	cin >> N; 
	int count = 0;
  	for(int i = 1;i<N+1;i++){
	if((i%2)!=0){
      count+=1;
    }
    }
  cout << setprecision(10)<<(double)count/N << endl;
  
}

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

int main(){
	int N;
	cin >> N;
	vector<pair<pair<string, int>, int>> rest(N);
	for(int i = 0; i < N; i++){
		cin >> rest[i].first.first >> rest[i].first.second;
		rest[i].first.second *= (-1);
		rest[i].second = i + 1;
	}
	
	sort(rest.begin(), rest.end());
	for(int i = 0; i < N; i++){
		cout << rest[i].second << endl;
	}
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class EMaxGCD {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, k; cin >> n >> k;
      vector<int> a(n);
      ll sum = 0;
      rep(i, n) {
        cin >> a[i];
        sum += a[i];
      }
      auto p = sum;
      set<int, greater<>> divisors;
      for(int i=1; i*i<=p; i++) {
        if (p%i == 0) {
          divisors.insert(i);
          divisors.insert(p/i);
        }
      }
      for(auto d: divisors) {
        vector<int> m(n);
        ll msum = 0;
        rep(i, n) {
          m[i] = a[i]%d;
          msum += m[i];
        }
        auto mcnt = msum/d;
        debug(mcnt);
        sort(all(m));
        ll now = 0;
        rep(i, n-mcnt) {
          now += m[i];
        }
        if (now <= k) {
          cout << d << endl;
          return;
        }
      }

    }
};

signed main() {
  EMaxGCD solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  cin>>a;

  ll ans = 0ll;

  for(int l=0;l<=k&&l<=
      n;++l)for(int r=0;l+r<=k&&l+r<=n;++r){
    priority_queue<ll,vector<ll>,greater<>> que;
    rep(i,l)que.emplace(a[i]);
    rep(i,r)que.emplace(a[n-1-i]);
    for(int cnt=l+r;cnt<k;++cnt){
      if(que.empty())break;
      if(que.top()>0)break;
      que.pop();
    }
    ll sum = 0ll;
    while(!que.empty()){
      sum += que.top();
      que.pop();
    }
    chmax(ans,sum);
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int temp;
		if(a > b){
			temp=b;
			b=a;
			a=temp;
		}
		
		if(b > c){
			temp=b;
			b=c;
			c=temp;
		}
		if(a > b){
			temp=b;
			b=a;
			a=temp;
		}
		
		System.out.println(a+" "+b+" "+c);
	}
}


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

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

/*Xを前から見ていって、Sの１個以上の連続箇所があれば、それ以降の部分で
Tが何個連続しているかを見る
各連続箇所で、連続回数の少ない方*2をカウント
*/

int main() {
   int K,T;
   cin >> K >> T;
   vector<int> a(T);
   rep(i,T){
       cin >> a[i];
   }
   sort(a.begin(),a.end());
   reverse(a.begin(),a.end());
   int sum = 0;

   for(int i = 1;i<T;i++){
       sum += a[i];
   }
   int ans = 0;
   if(T == 1) ans = a[0]-1;
   else if(a[0] - 1 > sum) ans = a[0]-1-sum;
   else ans = 0;
   
   cout << ans << endl;
 }

Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}



void solve(){
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = s.size();
    //string m[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    map<string,int> pos;


    for(int i = 0;i<l;i++){
        s[i] = (s[i]-'A'+n)%26+'A';
    }
    cout << s <<endl; 
} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


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


using namespace std;

const int N = 2e5 + 7;
const int Inf = 0x3f3f3f3f;
struct Pair{
	int l,r;
	bool operator < (const Pair& t)const{
		return l == t.l ? r < t.r : l < t.l;
	}
}p[N];
inline int Read(int x = 0,char ch = 0){
	while(!isdigit(ch = getchar()));
	x = ch - 48;
	while(isdigit(ch = getchar()))x = x * 10 + ch - 48;
	return x;
}
int n,m;
int b[N];
int f[N];
int sum[N];
struct Node{
	int f,s;
	Node(){f = s = -Inf;}
}st[N << 2];
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define Mid (L + R >> 1)
void Insert(int x,int f,int s,int L = 0,int R = n,int rt = 1){
	if(st[rt].f < f)st[rt].f = f;
	if(st[rt].s < s)st[rt].s = s;
	if(L == R)return;
	if(x <= Mid)Insert(x,f,s,L,Mid,ls);
	else Insert(x,f,s,Mid + 1,R,rs);
}
int tmp;
void Qmaxf(int l,int r,int L = 0,int R = n,int rt = 1){
	if(tmp >= st[rt].f)return;
	if(l <= L && r >= R)return tmp = st[rt].f,void();
	if(l <= Mid)Qmaxf(l,r,L,Mid,ls);
	if(r >  Mid)Qmaxf(l,r,Mid + 1,R,rs);
}
void Qmaxs(int l,int r,int L = 0,int R = n,int rt = 1){
	if(tmp >= st[rt].s)return;
	if(l <= L && r >= R)return tmp = st[rt].s,void();
	if(l <= Mid)Qmaxs(l,r,L,Mid,ls);
	if(r >  Mid)Qmaxs(l,r,Mid + 1,R,rs);
}
inline int Calc(int x){
	return 2 * sum[x] - x;
}
int main(){
#ifdef WTY
	freopen("in","r",stdin);
#endif
	cin >> n;
	for(int i = 1; i <= n; i++)b[i] = Read(),sum[i] = sum[i - 1] + !b[i];
	memset(f,0xcf,sizeof f);
	f[0] = sum[n];
	Insert(0,f[0],f[0] + Calc(0));
	cin >> m;
	for(int i = 1; i <= m; i++)
		p[i].l = Read(),p[i].r = Read();
	sort(p + 1,p + 1 + m);
	int ans = f[0];
	for(int i = 1; i <= m; i++){
		int asd = INT_MIN,k = p[i].l - 1;
		tmp = INT_MIN;
		Qmaxf(0,p[i].l - 1);
		asd = tmp + 2 * sum[k] - k;
		tmp = INT_MIN;
		Qmaxs(p[i].l,p[i].r);
		asd = max(asd,tmp) + p[i].r - 2 * sum[p[i].r];
		Insert(p[i].r,asd,asd + Calc(p[i].r));
		ans = max(ans,asd);
/*		for(int j = 0,t; j <= p[i].r; j++){
			int k = max(j,p[i].l - 1);
			if(asd < (t = f[j] + (p[i].r - k - 2 * (sum[p[i].r] - sum[k]))))asd = t;
		}
		f[p[i].r] = asd;*/
	}
	cout << n - ans << endl;

	return 0;
}

Measured memory_bytes: 10496
//When nothing comes in mind gcd laga lena
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define endl '\n'
#define MOD 1000000007

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    string s;
    cin >> s;

    char cur = '%';
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != cur) {
            ans++;
            cur = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
from itertools import *
from collections import *
from bisect import *
s=list(input())
t=input()
sets=set(s)
"""
a=len(s)*len(t)
maxcount=len(s)
for i in range(100):
    if maxcount<a:
        maxcount**=10
    else:
        break
"""

for T in t:
    if not T in sets:
        print(-1)
        exit()
N=len(s)
dic={}
for i in range(N):
    if not s[i] in dic:
        dic.update({s[i]:[i]})
    else:
        dic[s[i]].append(i)

count=0
prei=0
for i in range(len(t)):
    idx=bisect_left(dic[t[i]],prei)
    if idx<len(dic[t[i]]):
        prei=dic[t[i]][idx]+1
    else:
        prei=dic[t[i]][0]+1
        count+=N
    if i==len(t)-1:
        count+=prei



print(count)


Measured memory_bytes: 51208
#include <iostream>
#include <cmath>
#include <cstdio>
#define INF 1e+9
#define EPS 1e-13
using namespace std;

int w,n,r[12];
double dp[1 << 12][12]; 

int main(){
	char c;
	while(1){
		bool flag = false;
		int tmp = 0,n = 0;
		while(c = getchar()){
			if(c == EOF) return 0;
			if(c == '\n') {
				r[n++] = tmp;
				break;
			}
			if(c == ' '){
				if(!flag){
					flag = true;
					w = tmp;
					tmp = 0;
				}else{
					r[n++] = tmp;
					tmp = 0;
				}
			}else{
				tmp = tmp * 10 + (c - '0');
			}
		}
		for(int i = 0;i < 1 << n;i++){
			for(int j = 0;j < n;j++) dp[i][j] = INF;
		}
		for(int i = 0;i < n;i++){
			dp[1 << i][i] = (double)r[i];
		}
		for(int i = 0;i <= (1 << n) - 1;i++){
			for(int j = 0;j < n;j++){
				if(i >> j & 1){
					for(int k = 0;k < n;k++){
						dp[i][j] = min(dp[i][j],dp[i & ~(1 << j)][k] + sqrt(4.0 * (double)r[j] * (double)r[k]));
					}
				}
			}
		}
		double mi = INF;
		for(int i = 0;i < n;i++){
			mi = min(mi,dp[(1 << n) - 1][i] + (double)r[i]);
		}
		if(w - mi + EPS >= 0) cout << "OK" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3344
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    for (auto &c: s) {
        if (c == 'I') {
            ++cnt;
            ans = max(ans, cnt);
        } else {
            --cnt;
        }
    }
    cout << ans << endl;
}

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

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

min_x, max_x = min(x), max(x)

min_cost = sum([(x[i] - min_x) ** 2 for i in range(n)])
for p in range(min_x + 1, max_x + 1):
  cost = sum([(x[i] - p) ** 2 for i in range(n)])
  min_cost = min(cost, min_cost)

print(min_cost)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const long long int inf=1e18+7;
const int mod=1e9+7;

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int n;
	
	cin>>n;
	
	ll int j=sqrt(n);
	
	ll int minn=inf;
	
	for(ll int i=j;i>=1;i--)
	{
		if(n%i==0)
		{
			ll int now=i+n/i-2;
			
			if(now<minn)
				minn=now;
			
		}
	}
	
	cout<<minn<<endl;
	
	return 0;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::min;
using std::vector;

int
main()
{
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int &a: A)
  {
    cin >> a;
  }
  vector<int> B(N);
  for (int &b: B)
  {
    cin >> b;
  }
  long killed = 0;
  for (int n = 0; n < N; n++)
  {
    int k1 = min(A[n], B[n]);
    int k2 = min(A[n + 1], B[n] - k1);
    killed += k1 + k2;
    A[n + 1] -= k2;
  }
  cout << killed << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int X;

int main(){
	scanf("%d" , &X);
	int s = 0;
	repp(i,1,12345678){
		s += i;
		if(X<=s){
			printf("%d\n" , i);
			break;
		}
	}
	return 0;
}


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

int main() {
  int N, AC = 0, WA = 0, TLE = 0, RE = 0;
  string a;
  cin >> N;
  for( int i=0 ; i<N ; i++ ){
  	cin >> a;
    if( a == "AC" ){
      AC++;
    }
    else if( a == "WA" ){
      WA++;
    }
    else if( a == "TLE" ){
      TLE++;
    }
    else{
      RE++;
    }
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

Measured memory_bytes: 3628
N,M=map(int,input().split())
c=[]
t=[]
for _ in range(M):
  c_i,t_i=map(int,input().split())
  c.append(c_i)
  t.append(t_i)
x=max(c)
y=min(t)
z=y-x+1
if z>=1:
  print(z)
else:
  print(0)

Measured memory_bytes: 10996
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main () {
	ll N, D, X;
    ll ans = 0;
    cin >> N >> D >> X;
    vector<ll> A;
    for(int i = 0; i < N; i++)
    {
        ll a;
        cin >> a;
        ans += 1 + ((D - 1) / a);
    }
    ans += X;
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
int_list = sorted([int(input()) for i in range(n)],reverse=True)
count = 1
i= 0
while i + 1 < len(int_list) :
    if int_list[i] > int_list[i + 1]:
        count += 1
    i += 1 
print(count)


Measured memory_bytes: 62408
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		
		//方針
		//数字とindexをpairとかで持っておき、数字ソート
		//loop
		//大きい順に、自分より大きい数字を一つ含む時の左と右の候補を計算
		//Treesetに自分のindexを入れる
		//loop
		int n = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;
		int left = 0;
		for(int i = 0;i < n-1;i++){
			if(h[i + 1] > h[i]){
				ans = Math.max(ans, i-left);
				left = i+1;
			}
		}
		ans = Math.max(ans, n-1-left);

		System.out.println(ans);
	}


	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}

class Town{
	int index;
	int x ;
	int y;
	public Town(int index,int x,int y) {
		this.index = index;
		this.x = x;
		this.y = y;
		// TODO 自動生成されたコンストラクター・スタブ
	}


}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}

class Pair implements Comparable{
	int from;
	int end;
	public Pair(int from,int end) {
		this.from = from;
		this.end = end;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   otherpair.from - from;
	}








}






Measured memory_bytes: 50348
#include<bits/stdc++.h>
using namespace std;
int main(void){
int sx,sy,tx,ty;
cin >> sx >> sy >> tx >> ty;
const int dx=tx-sx,dy=ty-sy;
cout<<string(dy,'U')<<string(dx,'R');
// Path 2
cout<<string(dy,'D')<<string(dx,'L');
// Path 3
cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
// Path 4
cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
// EndLine
cout << endl;
return 0;
}


Measured memory_bytes: 256
import math
n,m = map(int,input().split())
if abs(n-m) >= 2:
    print(0)
elif abs(n-m) == 1:
    print((math.factorial(n)*math.factorial(m))%(10**9+7))
else:
    print((2*(math.factorial(n)*math.factorial(m)))%(10**9+7))

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	for (int i = 0; i < h; i++) cin >> grid[i];

	set<int> h_white, v_white;
	for (int i = 0; i < h; i++) {
		bool white = true;
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '#') {
				white = false;
				break;
			}
		}
		if (white) h_white.insert(i);
	}
	for (int i = 0; i < w; i++) {
		bool white = true;
		for (int j = 0; j < h; j++) {
			if (grid[j][i] == '#') {
				white = false;
				break;
			}
		}
		if (white) v_white.insert(i);
	}

	vector<string> answer;
	for (int i = 0; i < h; i++) {
		if (h_white.count(i)) continue;
		string s;
		for (int j = 0; j < w; j++)
			if (!v_white.count(j)) s.push_back(grid[i][j]);
		answer.push_back(s);
	}
	for (const string& s : answer) cout << s << endl;
}


Measured memory_bytes: 256