akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define N 510
using namespace std;
struct Info{int l,r;}a[N];
ll n,mo,ans,dp[N][N];
bool c1(const Info &a,const Info &b){if (a.l!=b.l) return a.l<b.l;return a.r<b.r;}
int main(){
	cin>>n>>mo;
	for (int i=0;i<n;i++){
		for (int j=n+n-1;j>=0;j--)if (i*i+j*j>=n*n)a[i].l=j;
		for (int j=0;j<n+n;j++)if (i*i+j*j<=n*n*4)a[i].r=j;
		a[i].r++;
	}
	for (int i=n;i<n+n;i++){
		a[i].r=-1;
		for (int j=0;j<n+n;j++)if (i*i+j*j<=n*n*4)a[i].l=j;
		a[i].l++;
	}
	sort(a,a+n+n,c1);
	for (int k=0;k<=n;k++){
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for (int i=0;i<n+n;i++){
			for (int j=0;j<=k;j++){
				if ((a[i].l-i+j)>0)dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(a[i].l-i+j))%mo;
				if ((a[i].r-n-n+(k-j))>0)dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*(a[i].r-n-n+(k-j)))%mo;
			}
		}
		if ((n-k)%2)ans=(ans+mo-dp[n+n][k])%mo;else ans=(ans+dp[n+n][k])%mo;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>

int solve(int, int);

int n;
int A[2000];

int main()
{
  int i;
  int q;
  int m[2000];

  scanf("%d", &n);
  for(i=0;i<n;i++)
    {
      scanf("%d", &A[i]);
    }
  
  scanf("%d", &q);
   for(i=0;i<q;i++)
    {
      scanf("%d", &m[i]);
    }

   for(i=0;i<q;i++)
     {
       if(solve(0, m[i]))printf("yes\n");
       else printf("no\n");
     }
   
  return 0;
}

int solve(int i, int m)
{
  int p=0;
  
  if(m==0)return 1;
  if(i>=n)return 0;

  int res = solve(i+1, m) || solve(i+1, m - A[i]);
  
  //return solve(i+1, m);
  //return solve(i+1, m - A[i]);
}



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

int main() {
  int n;
  string s;
  cin >> n;
  int i, cnt;
  rep(i, n) {
    cin >> s;
    if (s=="Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 3628
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,a,b,c,d;
bool check(int x,int y)
{
	if(a+1ll*c*x-1ll*d*y<=b&&a+1ll*d*x-1ll*c*y>=b)return true;
	return false;
}
int main()
{
	get3(n,a,b);
	get2(c,d);
	for(int i=0;i<n;i++)if(check(i,n-1-i))
	{
		puts("YES");
		return 0;
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        String S,T;
        S = scanner.next();
        T = scanner.next();

        System.out.print(T);
        System.out.println(S);
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<arr[k-1];
  return 0;
            }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//組み合わせ計算
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

//繰り返し二乗法
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,k;
    mint ans=0;
    cin >> n >> k;
    for(int i=k;i<=n+1;i++){
        ans+=(n+1-i)*i+1;
    }
    cout << ans << endl;

    return 0;
}












Measured memory_bytes: 3640
import java.io.*;
import java.util.*;
 
class Main{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr =new InputStreamReader(System.in);
        BufferedReader reader =new BufferedReader(isr);
        
        String buf = reader.readLine();
        int w = Integer.parseInt(buf);

        buf = reader.readLine();
        int n = Integer.parseInt(buf);
         
        int i;
        int[] num = new int[w];
         
        for (i = 0;i < w;i++) {
            num[i] = i + 1;
        }
         
        for (i = 0;i < n;i++) {

            buf = reader.readLine();
            StringTokenizer st = new StringTokenizer(buf,",");
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int x = num[a - 1];
            num[a - 1] = num[b - 1];
            num[b - 1] = x;
        }
         
        for (i = 0;i < w;i++) System.out.println(num[i]);
    }
}

Measured memory_bytes: 24144
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int i, j, n, a[100000], x[100000];
	unsigned int p = 1;
	scanf("%d", &n);
	for (i = 0; i < 100000; i++)
		x[i] = 0;

	for (i = 0; i < n - 1; i++)
		scanf("%d ", &a[i]);
	scanf("%d", &a[n - 1]);
	
	for (i = 0; i < n; i++) {
		x[a[i]]++;
		if (n % 2 == a[i] % 2 || x[a[i]] > 2 || x[0] > 1) {
			printf("0\n");
			return 0;
		}
	}
	
	for (i = 0; i < n / 2; i++) {
		p *= 2; 
		if (p > 1000000007)
			p -= 1000000007;
		
	//	p = (2 * p) % 1000000007;
	}
	printf("%u\n", p);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
	int a, eq=0, eq2=0;
	scanf("%d", &a);
	eq= pow(a,2);
	eq2= pow(a,3);
	printf("%d\n", eq+a+eq2);
	return 0;
}

Measured memory_bytes: 2600
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
ll dp[1005][1005];
int main()
{
    fast();
    ll n,m,i,j;
    cin>>n>>m;
    dp[0][0]=1;
    char x;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cin>>x;
            if(x=='#')
                continue;
            if(i-1>=0)
                dp[i][j]=(dp[i-1][j]+dp[i][j])%MOD;
            if(j-1>=0)
                dp[i][j]=(dp[i][j-1]+dp[i][j])%MOD;
        }
    }
    cout<<dp[n-1][m-1];
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int n,m;
  cin >> n >> m;
  vector <P> p(n);
  
  REP(i,n){
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(),p.end());
  REP(i,m){
    int x1,x2,y1,y2;
    int sum = 0;
    cin >> x1 >> y1 >> x2 >> y2;
    REP(j,n){
      if(p[j].first >= x1 && p[j].first <= x2 && p[j].second >= y1 && p[j].second <= y2){
	sum++;
	
      }
      if(x2 < p[j].first){
	  break;
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}



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

public class Main{
	public static int n;
	public static int A[];
	public static int B[];
	public static int C[] = new int[10000];
	public static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		A = new int[n];
		B = new int[n];

		for(int i = 0; i<n ;i++){
			A[i] = scan.nextInt();
			C[A[i]]++;
		}

		for(int i=1;i<10000;i++){
			C[i] = C[i-1]+C[i];
		}

		for(int i = n-1;i>=0;i--){
			B[C[A[i]]-1] = A[i];
			C[A[i]]--;
		}

		for(int i = 0; i < n-1 ;i++){
			sb.append(B[i]);
			sb.append(" ");
		}
		System.out.println(sb.toString()+B[n-1]);

	}

}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n, k;

int main() {
    cin >> n >> k;
    ll ans = 0;
    for (ll b = k+1; b <= n; b++) {
        ll t = b-k;
        ll c = n/b;
        ans += c*t;
        ll x = c*b+k;
        if (x <= n) {
            ans += n-x+1;
        }
    }
    if (k == 0) ans -= n;
    cout << ans << endl;
}
































Measured memory_bytes: 256
# coding: utf-8

def maximum_profit(A, N):
    min_x = 10e9
    max_benefit = -10e9
    for i in range(N):
        x = A[i]
        
        current_benefit = x - min_x
        if current_benefit > max_benefit:
            max_benefit = current_benefit
            
        if x < min_x:
            min_x = x


    print(max_benefit)


if __name__ == "__main__":
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    maximum_profit(A, N)


Measured memory_bytes: 13636
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
asum=0
bsum=0
pointer=0
while pointer<m and bsum+b[pointer]<=k:
	bsum+=b[pointer]
	pointer+=1
ans=pointer
for i in range(n):
	asum+=a[i]
	while asum+bsum>k and pointer>=0:
		pointer-=1
		bsum-=b[pointer]
	if asum+bsum>k:
		break
	ans=max(ans,(i+1)+pointer)
print(ans)

Measured memory_bytes: 117908
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
long long N, M;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  if(N == 1 && M == 1)
    cout << 1 << "\n";
  else if(N == 1 || M == 1)
    cout << max(N, M) - 2 << "\n";
  else
    cout << max(N-2, 0LL)*max(M-2, 0LL) << "\n";
  return 0; 
}



Measured memory_bytes: 256
N = int(input())
ab = [list(map(int,input().split())) for i in range(N)]
ab.sort(key=lambda x:x[1])
p = ab.pop()
suma = 0
for i in range(N-1):
    suma += ab[i][0]
    if suma > ab[i][1]:
        print("No")
        exit()
    
print("Yes" if suma+p[0]<=p[1] else "No")

Measured memory_bytes: 53660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int n,aa[N],a[N],k;
ll sum=0;
int main(){
//	freopen("a.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i) aa[i]=read(),sum+=aa[i];
	ll t=(ll)n*(n+1)/2;
	if(sum%t){puts("NO");return 0;}k=sum/t;
	for(int i=2;i<=n;++i) a[i]=aa[i]-aa[i-1];a[1]=aa[1]-aa[n];
	for(int i=1;i<=n;++i)
		if((k-a[i])%n){puts("NO");return 0;}//x<0也不行啊。 
		else if((k-a[i])/n<0){puts("NO");return 0;}
	puts("YES");return 0;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/arc071/submissions/6325840

from itertools import accumulate

*S, = map(lambda x: 1 if x == 'A' else 2, input())
*T, = map(lambda x: 1 if x == 'A' else 2, input())
# A=1,B=2

acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))

ans = []
Q = int(input())
for _ in range(Q):
    sl, sr, tl, tr = map(int, input().split())
    diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
    ans.append('YES' if diff % 3 == 0 else 'NO')

print(*ans, sep='\n')
# 逐次printだと1000ms
# 一括だと500ms


Measured memory_bytes: 15764
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

int n, deg[N];

int main(){
    int m, x, y;
    scanf("%d %d", &n, &m);
    for(int i=1;i<=m;i++){
        scanf("%d %d", &x, &y);
        deg[x] += 1;
        deg[y] += 1;
    }
    bool flag = true;
    for(int i=1;i<=n;i++){
        if(deg[i] % 2) flag = false;
    }
    if(flag) cout << "YES\n";
    else cout << "NO\n";
	return 0;
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  string s;
  cin >> n;
  cin >> s;
  vl white(n,0);
  REP(i,n){
    if(i>0) white[i] = white[i-1];
    if(s[i]=='.') white[i]++;
  }
  ll ma = n;
  ma = min(ma,white[n-1]);
  REP(i,n){
    ll count = 0;
    count += i+1 - white[i];
    count += white[n-1] - white[i];
    ma = min(ma,count);
  }
  if(ma == n) ma = 0;
  cout << ma << endl;
  return 0;
}


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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  
  ll m = 1000001;
  
  vector<ll> a(n);
  vector<ll> f(m, 0);
  
  for ( ll i = 0; i < n; i++ )
    cin >> a[i];
  
  for ( ll i = 0; i < n; i++ ){
    if ( f[a[i]] == 2 ) continue;
    else if ( f[a[i]] == 1 ) f[a[i]]++;
    else f[a[i]] = 1;
    
    for ( ll j = 2; j * a[i] < m; j++ ){
      f[j * a[i]] = 2;
    }
  }

  
  ll ans = 0;
  
  for ( ll i = 0; i < m; i++ ) if ( f[i] == 1 ) ++ans; 
  
  cout << ans << endl;
}

Measured memory_bytes: 12736
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<map>
#include <cmath>
using namespace std;
typedef long long int ll;
#include <bits/stdc++.h>
 
ll gcd(ll a, ll b){
    if (b == 0) return a;

    return gcd(b, a % b);
}

int main(){
    long double A, B, H, M;
    cin >> A >> B >> H >> M;

    long double Short_theta = H * (long double)30.0 + M / (long double)2.0;
    long double Long_theta = M * (long double)6.0;

    long double theta;
    if (Short_theta >= Long_theta) theta = Short_theta - Long_theta;
    else theta = Long_theta - Short_theta;
    
    if (theta > 180.0) theta = 360.0 - theta;

    long double x = sqrt(A*A + B*B - 2*A*B*cos(M_PI*theta/180.0));

    printf("%.20Lf\n", x);
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
bool valid(int x) {
    return 0 <= x && x < 5;
}

int main(){
    int N;
    int C = 0;
    while(cin >> N && N > 0) {
        if(C != 0) cout << endl;
        cout << "Case " << ++C << ":" << endl;
        int grid[5][5][5] = {};

        REP(z, 5) REP(y, 5) {
            string s;
            cin >> s;
            REP(x, 5) grid[z][y][x] = s[x] == '1';
        }

        vector<int> A;
        int M; cin >> M;
        A.resize(M);
        REP(i, M) { cin >> A[i]; }

        vector<int> B;
        cin >> M;
        B.resize(M);
        REP(i, M) { cin >> B[i]; }

        REP(_, N) {
            int cnt[5][5][5] = {};
            REP(sz, 5) REP(sy, 5) REP(sx, 5) {
                REP(dz, 3) REP(dy, 3) REP(dx, 3) {
                    int x = sx + dx - 1;
                    int y = sy + dy - 1;
                    int z = sz + dz - 1;
                    if(dx == 1 && dy == 1 && dz == 1) continue;
                    if(valid(x) && valid(y) && valid(z)) {
                        cnt[sz][sy][sx] += grid[z][y][x];
                    }
                }
            }

            REP(z, 5) REP(y, 5) REP(x, 5) {
                if(grid[z][y][x] == 0) {
                    int next = 0;
                    for(int a : A) if(cnt[z][y][x] == a) next = 1;
                    grid[z][y][x] = next;
                } else {
                    int next = 0;
                    for(int b : B) if(cnt[z][y][x] == b) next = 1;
                    grid[z][y][x] = next;
                }
            }
        }

        REP(z, 5) {
            REP(y, 5){
                REP(x, 5) cout << grid[z][y][x];
                cout << endl;
            }
            if(z != 4) cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1212
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

pll ps[3001];
bool m[5001][5001];

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    while(cin >> N, N){
        for(int i = 0; i < 5001;i++)for(int j = 0; j < 5001;j++) m[i][j] = false;
        vector<pll> ps(N);
        for(int i = 0; i < N; i++){
            cin >> ps[i].first >> ps[i].second;
            m[ps[i].first][ps[i].second] = true;
        }
        ll res = 0;
        for(int i = 0; i < N;i++){
            for(int j = i+1;j <N;j++){
                ll x1 = ps[i].first,y1 = ps[i].second,x2 = ps[j].first,y2 = ps[j].second;
                
                ll area = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
                if(area <= res) continue;
                ll x3 = x1 + (y1 - y2),y3 = y1 + (x2 - x1);
                if(x3 >= 0 && x3 <= 5000 && y3 >= 0 && y3 <= 5000){
                    if(m[x3][y3]){
                        ll x4 = x2 + (x3 - x1), y4 = y2 + (y3 - y1);
                        if(x4 >= 0 && x4 <= 5000 && y4 >= 0 && y4 <= 5000){
                            if(m[x4][y4]){
                                res = area;
                                continue;
                            }
                        }
                    }
                }
                x3 = x1 - (y1 - y2), y3 = y1 - (x2 - x1);
                if(x3 >= 0 && x3 <= 5000 && y3 >= 0 && y3 <= 5000){
                    if(m[x3][y3]){
                        ll x4 = x2 + (x3 - x1), y4 = y2 + (y3 - y1);
                        if(x4 >= 0 && x4 <= 5000 && y4 >= 0 && y4 <= 5000){
                            if(m[x4][y4]){
                                res = area;
                                continue;
                            }
                        }
                    }
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

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


int main(){

    int N,A[110]={},max,min;
    cin >>N;
    for(int i=0;i<N;i++){
        cin >>A[i];
    }
    max = A[0];
    min = A[0];

    for(int i=0;i<N;i++){
        if(max<A[i])max=A[i];
        if(min>A[i])min=A[i];
    }

    cout << abs(max-min) <<endl;


    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main{
    
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int a = Integer.valueOf(input[0]);
        int b = Integer.parseInt(input[1]);

        System.out.println(gcd(a,b));

    }

    private static int gcd(int a , int b){
        int result = 1;

        if(b > a){
            int tmp = b;
            b = a;
            a = tmp;
        }

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

Measured memory_bytes: 24288
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long int LL;
int max(int a,int b){
	return a>b?a:b;
}
int min(int a,int b){
	return a<b?a:b;
}

int main(){
	int n,a,b;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF){
		printf("%d\n",min(a*n,b));
	}
	return 0;
}

Measured memory_bytes: 128
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
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; }

ul N,K,i,j,a,b,cnt;
map<int,ul> v;
vector<pair<int,ul> > vv;

inline void solve(){
  IN2(N,K);
  REP(i,N){
    IN2(a,b);
    v[a]+=b;
  }
  for(map<int,ul>::iterator it=v.begin();it!=v.end();it++){
    vv.pb(mp(it->first,it->second));
  }
  sort(ALL(vv));
  REP(i,N){
    cnt+=vv[i].second;
    if(K<=cnt){
      OUT(vv[i].first);
      return;
    }
  }
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 5368
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[1] == s[len(s) // 3]:
            n += 1
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n * (k - 1))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;

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

  int N,M;
  while(cin >> N >> M){
    vector<int> a(M); cin >> a;

    vector<bool> p(N+1, true);
    REP(i,M) p[a[i]] = false;
    vector<LLI> dp(N+1);

    dp[0] = 1;

    FORE(i,1,N){
      if(p[i]){
	if(i>=2) (dp[i] += dp[i-1] + dp[i-2]) %= mod;
	else if(i>=1) (dp[i] += dp[i-1]) %= mod;
      }
    }

    cout << dp[N] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll a,b; cin >> a >> b;
  
  if(a % 2 != 0 and b % 2 != 0) cout << "Odd" << endl;
  else cout << "Even" << endl;
  
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    ll a,b;
    cin>>a>>b;
    ll miA=a,miB=b;
    for(int i=1;i<n;i++){
        cin>>a>>b;
        ll mi=max((miA+a-1)/a,(miB+b-1)/b);
        miA=mi*a;
        miB=mi*b;
    }
    cout<<miA+miB<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
class UnionFind:

    def __init__(self, n):
        self.par = [i for i in range(n + 1)]  # init roo

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def union(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        self.par[rx] = ry

    def same(self, x, y):
        return self.root(x) == self.root(y)

N, M = map(int, input().split())
P = list(map(int, input().split()))

tree = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    tree.union(x, y)

cnt = 0
for i, p in enumerate(P, 1):
    if tree.same(i, p):
        cnt += 1
print(cnt)


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

int main() {
  int n, n1;
  cin >> n;
  n1 = n % 10;

  if (n1 == 3)
    cout << "bon" << endl;
  else if (n1 == 0 || n1 == 1 || n1 == 6 || n1 == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  return 0;
}


Measured memory_bytes: 3636
N,M,X,Y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

xs.append(X)
ys.append(Y)

xs.sort()
ys.sort()


print('No War' if xs[-1] < ys[0] else 'War')


Measured memory_bytes: 2940
n=int(input())
l=list(map(int,input().split()))
Min=1000000
Max=-1000000
Sum=0
for i in range(n):
    if l[i]<Min:
        Min=l[i]
    if l[i]>Max:
        Max=l[i]
    Sum+=l[i]
print(Min,Max,Sum)



Measured memory_bytes: 6596
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const [n, m] = p(lines[0]);
  const op = [];
  for (let i = 0; i < m; i++) {
    op[i] = Number(lines[i + n + 1]);
  }
  for (let i = 1; i <= n; i++) {
    const row = p(lines[i]);
    let sum = 0;
    for (let j = 0; j < m; j++) {
      sum += row[j] * op[j];
    }
    console.log(sum);
  }
});

const p = (s) => s.split(" ").map(Number);



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

int main(){
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    for(int i = x1; i < x2; i++){
        cout << "R";
    }
    for(int i = y1; i < y2; i++){
        cout << "U";
    }
    for(int i = x2; i > x1; i--){
        cout <<"L";
    }
    for(int i = y2; i > y1; i--){
        cout << "D";
    }
    cout << "L";
    for(int i = y1; i < y2+1; i++){
        cout << "U";
    }
    for(int i = x1-1; i < x2; i++){
        cout << "R";
    }
    cout << "D";
    cout << "R";
    for(int i = y2; i > y1-1; i--){
        cout << "D";
    }
    for(int i = x2+1; i > x1; i--){
        cout << "L";
    }
    cout << "U";
    return 0;
}

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    if ((A-1) / K != B / K) cout << "OK" << endl;
    else cout << "NG" << endl;
}


Measured memory_bytes: 3592
n,m,c = map(int, input().split())
b = [int(i) for i in input().split()]
A = [[int(j) for j in input().split()] for i in range(n)]
ans = 0    

for i in range(n):
    z = c
    for j in range(m):
        z += A[i][j]*b[j]
    if z > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool ans = true;
    rep(i, n) if (a[i] - 1 != i) ans = false;
    if (ans) {
        puts("YES");
        return 0;
    }
    rep(i, n) for (int j = i+1; j < n; ++j) {
        swap(a[i], a[j]);
        bool ans = true;
        rep(k, n) if (a[k] - 1 != k) ans = false;
        if (ans) {
            puts("YES");
            return 0;
        }
        swap(a[i], a[j]);
    }
    puts("NO");
}


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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
  // cin t;
   while(t--){
         ll n;
         cin >> n;
         n = n % 10;
         if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
         cout << "hon" << endl;
         else if( n == 3)
         cout << "bon" << endl;
         else
         cout << "pon" << endl;    
   }
}


Measured memory_bytes: 3592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int s = Integer.parseInt(in.next());
            int ans = 0;

            List<Integer> collats = new ArrayList<>();

            collats.add(s);
            int i = 0;
            while (true) {
                i++;
                int tmp = fn(collats.get(i - 1));

                if (collats.contains(tmp)) break;

                collats.add(tmp);

            }

            // 出力
            out.println(++i);

        }

        public static int fn(int n) {
            if (n % 2 == 0) {
                return n / 2;
            } else {
                return 3 * n + 1;
            }
        }

    }
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int N, M, X;
int c[12];
int a[12][12];
int t[12] = {0};
int cost;

void solve() {
  int ans = 100000000;
  for(int bit = 0; bit < (1<<N); bit++) {
    cost = 0;

    for(int i = 0; i < M; i++) {
      t[i] = 0;
    }

    for(int i = 0; i < N; i++) {
      if(bit & (1<<i)) {
        cost += c[i];
        for(int j = 0; j < M; j++) {
          t[j] += a[i][j];
        }
      }
    }

    bool f = true;
  
    for(int i = 0; i < M; i++) {
      if(t[i] < X) {
        f = false;
      }
    }

    if(f == false) continue;
    if(f == true) ans = min(ans, cost);
  }

  if(ans != 100000000) cout << ans << endl;
  if(ans == 100000000) cout << -1 << endl;

}


int main() {
  cin >> N >> M >> X;
  for(int i = 0; i < N; i++) {
    cin >> c[i];
    for(int j = 0; j < M; j++) {
      cin >> a[i][j];
    }
  }
  solve();

  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int x[4], y[4];
    rep(i, 2){
        cin >> x[i] >> y[i];
    }
    int x_ = x[1]-x[0], y_ = y[1]-y[0];
    cout << x[1]-y_ << " " << y[1]+x_ << " " << x[0]-y_ << " " << y[0]+x_ << endl;
    return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]==',')
            cout<<" ";
        else
            cout<<s[i];
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 

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

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;

  
int main(){
  ll dp[1100][5000];
  int n,m;
  cin >> n >> m;
  vector<int> a(m),b(m),c(m,0);
  
  rep(i,m){
    cin >> a[i] >>b[i];
    rep(j,b[i]){
      int t;cin >> t;t--;
      c[i]+=(1<<t);
    }
  }
  rep(i,1100)rep(j,5000)dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,m){
    rep(j,(1<<n)){
      chmin(dp[i+1][j],dp[i][j]);
      chmin(dp[i+1][j|c[i]],dp[i][j]+a[i]);
    }
  }
  cout << (dp[m][(1<<n)-1] < INF ? dp[m][(1<<n)-1] : -1)<<endl;
}

    
  
    

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


int main() {
    ll N;
    string S;
    cin >> N >> S;
    int ans = 0;
    int tmp = 0;
    rep(i,N) {
        if (S.at(i) == 'I') ++tmp;
        else --tmp;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
int yakusuunokazu(int a){
  int count = 0;
for(int i = 1; i < a+1;i++){
  if(a % i == 0){
    count += 1;
  }
  }
  return count;
}


int main(){
  int N;
  cin >> N;
  int ans =0;
  for(int i = 1;i < N+1;i++){
    if(i % 2 == 1){
    int cou = yakusuunokazu(i);
    if(cou == 8){
      ans += 1;
    }
  }
  }
  cout << ans;
}
  

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

int main(){
    int n, i;
    cin >> n;
    int a[256];

    double sum = 0;
    for(i = 0; i < n; i++){
        cin >> a[i];
        sum += (double)1/a[i];
    }
    cout << 1/sum << endl;

    return 0;
}


Measured memory_bytes: 3756
n=int(input())
data=[]
for i in range(n-1):
    data.append(list(map(int,input().split())))
for i in range(n-1):
    t=0
    for j in range(i,n-1):
        if t<data[j][1]:
            t=data[j][1]
            t+=data[j][0]
        else:
            t+=((data[j][2])-((t)%(data[j][2])) if (t)%(data[j][2])!=0 else 0)
            t+=data[j][0]
    print(t)
print(0)


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

int main(){
	int i;
	string S;
	cin >> S;
	if(S.size() % 2 == 1){
		printf("No\n");
		return 0;
	}
	for(i = 0; i < S.size(); i += 2){
		if(S[i] != 'h' || S[i + 1] != 'i'){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

using namespace std;

class UnionFind{
public:

    //親の番号を格納する. Parentだった場合は−(the size)とする
    vector<int> Parent;
    
    //作るときはParentの値を全て-1にする
    //こうすると, すべての頂点が根となる
    UnionFind(int N){
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A){
        if (Parent[A] < 0) return A; //自分のグループにいる
        return Parent[A] = root(Parent[A]); //親をつなぎ替える
    }
    
    //size関数を作る
    //自分の所属するグループの頂点数を調べる
    long long size(int A){
        return -Parent[root(A)]; //親をとりたい
    }
    
    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接繋がない
        //root(A) に root(B)をくっつける　
        //リーダー同士をくっつける
        
        A = root(A);
        B = root(B);
        
        if (A == B){
            return false; //すでにくっついてる
        }
            
        //大きい方に小さい方をくっつけたい
        //大小が逆だったらひっくり返す
            
        if(size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        
        //BのParentをAに変更する
        Parent[B] = A;
        
        return true; //くっついた
    }
    
};

int main(void){
    
    int n, m;
    cin >> n >> m;
    
    UnionFind uni(n);
    
    for (int i = 0; i < m; i++){
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        
        uni.connect(x,y);
    }
    
    set<int> st;
    
    for (int i = 0; i < n; i++){
        st.insert(uni.root(i));
    }
    
    cout << st.size() << endl;
}


Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main()
{
  long long N, A, B;
  cin >> N >> A >> B;
  if (A > B || (N == 1 && A != B)) cout << 0 << endl;
  else if (N == 1) cout << 1 << endl; 
  else cout << (N - 2)*(B - A) + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i = 0,ioi,joi;
	char str[10000];
	while(scanf("%s",str) != EOF){
		ioi = 0;
		joi = 0;
		for(i = 0;str[i + 2] != 0;i++){
			if(str[i + 1] == 'O' && str[i + 2] == 'I'){
				if(str[i] == 'J') joi++;
				if(str[i] == 'I') ioi++;
			}
		}
		printf("%d\n%d\n",joi,ioi);
	}
	return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

ll n, a[3000], dp[3000][3000];

ll f(int p, int q)
{
    if (p > q) return 0;
    if (dp[p][q] != -1) return dp[p][q];
    return dp[p][q] = max(a[p] - f(p + 1, q), a[q] - f(p, q - 1));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    memset(dp, -1, sizeof dp);
    cout << f(0, n - 1);
}


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


int main(){
  ll L, R;
  cin >> L >> R;

  if(R - L >= 2018){
    cout << 0 << endl;
    return 0;
  }

  int l = L % 2019;
  int r;
  if(R % 2019 < l ) r = R % 2019 + 2019;
  else r = R % 2019;

  int result = 2019;
  for(int i = l; i < r; i++){
    for(int j = l+1; j <= r; j++){
      int x;
      x = i * (j % 2019) % 2019;
      result = min(result, x);
    }
  }
  cout << result << endl;

}


Measured memory_bytes: 256
H, W = map(int, input().split())
grid = []
for i in range(H):
    grid.append(input())

light = [[None for i in range(W)] for j in range(H)]

for i in range(H):
    j = 0
    count = 0
    before = 0
    while j <= W-1:
        if grid[i][j] == ".":
            count += 1
        else:
            for k in range(before, j):
                light[i][k] = count
            light[i][j] = 0
            before = j+1
            count = 0
        j += 1
    else:
        if count >= 0:
            for k in range(before, j):
                light[i][k] = count

light2 = [[None for i in range(W)] for j in range(H)]

for i in range(W):
    j = 0
    count = 0
    before = 0
    while j <= H-1:
        if grid[j][i] == ".":
            count += 1
        else:
            for k in range(before, j):
                light2[k][i] = count
            light2[j][i] = 0
            before = j+1
            count = 0
        j += 1
    else:
        if count >= 0:
            for k in range(before, j):
                light2[k][i] = count

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, light[i][j] + light2[i][j])
print(ans-1)


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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

N, M = map(int, input().split())
time = 1900 * M + 100 * (N - M)
ans = time * (2 ** M)
print(ans)


Measured memory_bytes: 8264
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int N, W;
int mod = 1e9 + 7;

int main() {
    cin >> N >> W;
    vector<int> w(N), v(N);
    map<int, vector<long long>> value;
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        value[w[i] - w[0]].push_back(v[i]);
    }
    
    for (int i = 0; i < 4; i++) {
        sort(value[i].begin(), value[i].end(), greater<int>());
        for (int j = 1; j < value[i].size(); j++) {
            value[i][j] += value[i][j - 1];
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < value[0].size() + 1; i++) {
        for (int j = 0; j < value[1].size() + 1; j++) {
            for (int k = 0; k < value[2].size() + 1; k++) {
                for (int l = 0; l < value[3].size() + 1; l++) {
                    if (1ll * w[0] * (i + j + k + l) + j + 2 * k + 3 * l <= W) {
                        long long tmp = (i > 0? value[0][i - 1]: 0)
                        + (j > 0? value[1][j - 1]: 0)
                        + (k > 0? value[2][k - 1]: 0)
                        + (l > 0? value[3][l - 1]: 0);
                        ans = max(ans, tmp);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256