akhauriyash/Code-Regression huggingface dataset:
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def euclid_dis(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0

n=int(raw_input())
#n,k=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=IS
for i in range(-100,101,1):
    tmp=0
    for j in l:
        tmp+=(i-j)**2
    ans=min(ans,tmp)
print ans

Measured memory_bytes: 2696
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
#define repM_1(i, n) for(ll i = (ll)(n - 1); i >= 1; i--)
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 (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);

	// 1．最大値の半分の生物までは単独でOK
	// 2. それ未満は足して半分以上にできるかどうか

	ll n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 0;

	rep(i, n)
		cin >> a[i];

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

	vector<ll> sum(n, 0);

	sum[0] = a[0];
	rep1(i, n)
		sum[i] = sum[i - 1] + a[i];

	repM_1(i, n - 1) {
		if (sum[i - 1] * 2 < a[i]) {
			ans = n - i;
			break;
		}
		if (i == 1)
			ans = n;
	}
	

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
class Dice
  attr_accessor :faces #メンバ変数を外部から参照可能に dice.faces

  def initialize(arr)
    @faces = arr
  end
  def roll(direction)
    case direction
    when "N"
      tmp = @faces[0]
      @faces[0] = @faces[1]
      @faces[1] = @faces[5]
      @faces[5] = @faces[4]
      @faces[4] = tmp
    when "S"
      tmp = @faces[0]
      @faces[0] = @faces[4]
      @faces[4] = @faces[5]
      @faces[5] = @faces[1]
      @faces[1] = tmp
    when "E"
      tmp = @faces[0]
      @faces[0] = @faces[3]
      @faces[3] = @faces[5]
      @faces[5] = @faces[2]
      @faces[2] = tmp
    when "W"
      tmp = @faces[0]
      @faces[0] = @faces[2]
      @faces[2] = @faces[5]
      @faces[5] = @faces[3]
      @faces[3] = tmp
    end
  end
end

face = gets.split.map { |e| e.to_i }
dice = Dice.new(face)
s = gets.chomp.split(//).map { |e| dice.roll(e) }

puts dice.faces[0]

Measured memory_bytes: 6116
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let m = 10usize.pow(9) + 7;
    let mut v:Vec<usize> = Vec::new();
    let mut b = vec![0; n+1];
    for i in 0..n {
        v.push(read());
        b[i+1] = b[i] + v[i];
    }
    let mut ans = 0;

    for i in 0..n {
        let sum = (b[n] - b[i+1]) % m;
        ans += v[i] * sum;
        ans %= m;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5272
a = int(input())

b = []
m = 0
for i in range(a):
	b.append(list(map(int,input().split())))

c = [[0,0,0] for i in range(a+1)]

for i in range(a):
	for j in range(3):
		for k in range(3):
			if j == k:
				continue
			else:
				c[i+1][k] = max(c[i+1][k],c[i][j] + b[i][k])

print(max(c[-1]))


Measured memory_bytes: 47328
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int s, w;
	cin >> s >> w;
	cout << (s<=w? "unsafe": "safe") << endl;

	return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 2e5+100;
LL a[maxn],sum[maxn],tot;
LL Min = 1000000000000000000LL;
int n;
int main()
{
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
    scanf("%lld",&a[i]);
    sum[i]=sum[i-1]+a[i];
    tot+=a[i];
   }
   for(int i=1;i<n;i++){
    Min=min(Min,abs(2*sum[i]-tot));
   }
   printf("%lld\n",Min);
}
/*
1 2 3 4
4 2 1 3

0   6  7  6 7 0
n-2 3 n-1 2 n 1
↓
0 6 6 0 7 7
*/


Measured memory_bytes: 3328
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<numeric>

using namespace std;

int main() {
    int ans=0,count=0;
    string S;
    cin>>S;
    for(int i=0;i<=S.size();i++){
        if(S[i]=='A'||S[i]=='T'||S[i]=='C'||S[i]=='G')count++;
        else{
            ans=max(ans,count);
            count=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const double pi = 3.14159265358979;

string str;
pair<int, int> dp[200001][2];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> str;
	for(int i = 0; i < (int)str.length(); i++)
		if(str[i] == '?'){
			if(i > 0 && str[i - 1] == 'P') str[i] = 'D';
			else if(i < (int)str.length() - 1 && str[i + 1] == 'D') str[i] = 'P';
			else if(i < (int)str.length() - 1 && str[i + 1] == '?') str[i] = 'P';
			else str[i] = 'D';
		}
	cout << str << "\n";
	return 0;
}

Measured memory_bytes: 3748
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll GCD(ll A, ll B){
  if (A < B) swap(A, B);
  while (A % B != 0){
    A %= B; swap(A, B);
  }
  return B;
}

ll LCM(ll A, ll B){
  ll G = GCD(A, B);
  return A / G * B;
}

int main(){
  ll A, B; cin >> A >> B;
  cout << LCM(A, B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int n;
    cin >> n;
    int a[3][101] = {0};
    rrep(i, 1, 3) rrep(j, 1, n + 1) cin >> a[i][j];
    int ans = 0;
    rrep(i, 1, n + 1) {
        int tmp = 0;
        rrep(j, 1, i + 1) tmp += a[1][j];
        rrep(j, i, n + 1) tmp += a[2][j];
        //cout << tmp << endl;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    //0indexedでやるべきだった
    //事故らせがち
}


Measured memory_bytes: 256
n = int(input())
s = input()

s_len = len(s)

if len(s) % 2 == 1:
    print("No")
else:
    s_0 = s[:s_len // 2]
    if s[s_len // 2:] == s_0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 38384
import java.util.*;

class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        //今日の天気を取得し、明日の天気を定義する
        String todayWeather = sc.next();
        String tomorrowWeather = "";
        
        //明日の天気を求める
        if(todayWeather.equals("Sunny")) {
            tomorrowWeather = "Cloudy";
        } else if(todayWeather.equals("Cloudy")) {
            tomorrowWeather = "Rainy";
        } else if(todayWeather.equals("Rainy")) {
            tomorrowWeather = "Sunny";
        } else {
            //何もしない
        }

        //明日の天気を出力する
        System.out.println(tomorrowWeather);
    }
}

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

using namespace std;
using ll = long long int;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    int n, m; cin >> n >> m;

    cout << ((1900 * m + 100 * (n - m)) * (pow(2, m)));
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	vi cnt(26, 0);
	REP(i, s.size()) {
		cnt[s[i] - 'a']++;
	}
	int p = -1;
	REP(i, 26) {
		if (cnt[i] == 0) {
			p = i;
			break;
		}
	}
	if (p != -1) {
		cout << s + char(p+'a') << endl;
	}
	else {
		string ret = "";
		RREP(i, 26) {
			int maxj = -1;
			REP(j, i) {
				if (s[j] < s[i])maxj = j;
			}
			if (maxj == -1)continue;

			string tmp = s;
			tmp = tmp.substr(0, maxj + 1);
			tmp[maxj] = s[i];
			if (ret == "" || ret > tmp)ret = tmp;
		}
		if (ret == "")cout << -1 << endl;
		else cout << ret << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define int long long
using namespace std;
inline int read(){
	register int x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200],str[200];int tt;
inline void print(int x,char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
const int maxn=300000+10;
const int p=998244353;
const int b=1000000000000000000ll%p;
int h[maxn],cnt,s[maxn],n;
int sg[maxn],f[4][maxn],m;
bool vis[maxn];
struct _{
	int nxt,to;
}e[maxn<<1];
void add(int u,int v){
	e[++cnt].nxt=h[u];
	e[cnt].to=v;
	h[u]=cnt;
}
signed main(){
    n=read();
    s[0]=1;
    for(int i=1;i<=n*3;i++){
    	s[i]=s[i-1]*b%p;
	}
	for(int o=1;o<=3;o++){
		memset(h,0,sizeof(h));
		memset(sg,0,sizeof(sg));
		cnt=0;m=read();
		for(int i=1;i<=m;i++){
            int u=read(),v=read();
            if(u<v) add(u,v);
            if(v<u) add(v,u);
        }
        for(int i=n;i>=1;i--){
        	for(int j=h[i];j;j=e[j].nxt){
        		vis[sg[e[j].to]]=1;
			}
			for(int j=0;;j++){
				if(!vis[j]){
					sg[i]=j;
					break;
				}
			}
			for(int j=h[i];j;j=e[j].nxt){
        		vis[sg[e[j].to]]=0;
			}
            (f[o][sg[i]]+=s[i])%=p;
		}
	}
	int ans=0;
	for (int i=0;i<500;i++)
        for (int j=0;j<500;j++)
            (ans+=f[3][i]*f[1][j]%p*f[2][i^j])%=p;
    print(ans);
	return 0;
}

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

int main()
{
    double height;
    double maxUp,maxLow;
    cin>>maxUp;
    maxLow=maxUp;
    while(cin>>height,!cin.eof()){
        if(height>maxUp){
            maxUp=height;
        }
        else if(height<maxLow){
            maxLow=height;
        }
    }
    cout<<maxUp-maxLow<<endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ld 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 (b<a) { a=b; return 1; } return 0; }



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  string s; cin >> s;
  stack<char> t;
  int n=s.size();
  rep(i,0,n){
    if(t.size()>0 && t.top()=='S' && s[i]=='T')
        t.pop();
    else{
      t.push(s[i]);
    }
  }
  cout << t.size() << endl; 
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;

int main() {
    cin >> n;
    for (int a = 1; a <= 3500; ++a) {
        for (int b = 1; b <= a; ++b) {
            int lo = 1, hi = b, mid;
            while (lo < hi) {
                mid = (lo + hi) >> 1;
                int c = mid;
                if (4ll * a * b * c < (LL)n * (a * b + b * c + c * a)) {
                    lo = mid + 1;
                } else {
                    hi = mid;
                }
            }
            int c = lo;
            if (4ll * a * b * c == (LL)n * (a * b + b * c + c * a)) {
                cout << a << ' ' << b << ' ' << c << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll solve(ll n, ll i, vector<vector<ll>> &h, vector<vector<ll>> &memo)
{
    if (n < 0)
    {
        return 0;
    }
    if (memo.at(n).at(i) != -1)
    {
        return memo.at(n).at(i);
    }

    ll res = 0;

    rep(0, j, 3)
    {
        if (j == i)
        {
            continue;
        }
        res = max(res, solve(n - 1, j, h, memo) + h.at(n).at(j));
    }

    return memo.at(n).at(i) = res;
}

int main()
{
    ll N;
    cin >> N;
    vector<vector<ll>> h(N, vector<ll>(3));
    rep(0, i, N)
    {
        rep(0, j, 3)
        {
            cin >> h.at(i).at(j);
        }
    }

    vector<vector<ll>> memo(100010, vector<ll>(3, -1));

    ll ans = 0;
    rep(0, i, 3)
    {
        ans = max(ans, solve(N - 1, i, h, memo));
    }

    cout << ans << endl;
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  bool f[27]={},act;
  string s;
  char m='z'+1,n='z'+1;
  cin>>s;
  if(s.length()!=26){
    for(int i=0;i<s.length();i++){
      f[s[i]-97]=true;
    }
    for(int i=0;i<26;i++){
      if(!f[i]){m=i+97;break;}
    }
    cout<<s<<m<<endl;
    return 0;
  }else{
    for(int i=s.length()-1;i>=0;i--){
      act=false;
      f[s[i]-97]=true;
      for(int j=s[i]-97+1;j<26;j++){
        if(f[j]) {
          m=j+97;
          act=true;
          break;
        }
      }
      if(act) {
        for(int j=0;j<i;j++){
          cout<<s[j];
        }
        cout<<m<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    long long h,w,a;
    cin >> h >> w;
    a=h*w;
    if(h==1||w==1)
        cout << 1;
    else if(a%2==0)
        cout << a/2;
    else
        cout << (a+1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

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

Measured memory_bytes: 3588
//
//   Mirror String.cpp
//  Algorithm
//
//  Created by SkyGao on 2020/2/13.
//  Copyright © 2020 skygao. All rights reserved.
//

#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#define re register
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    string a,b;
    cin>>b;
    a=b;
    reverse(b.begin(),b.end());
    for(re int i=0;i<b.length();++i)
        switch(b[i])
        {
            case 'b':b[i]='d';break;
            case 'd':b[i]='b';break;
            case 'p':b[i]='q';break;
            case 'q':b[i]='p';break;
        }
    if(a==b)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    k=int(input())
    xx=LI()
    ans=0
    for x in xx:
        ans+=min(x,k-x)
    print(ans*2)

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

bool compare(pair<int,int> a,pair<int,int> b){
    if(a.first==b.first) return a.second>b.second;
    return a.first<b.first;
}

int main(){
    
    int N,M;cin>>N>>M;
    vector<pair<int,int>> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i].first>>S[i].second;
    }
    
    sort(all(S),compare);
    
    priority_queue<int> PQ;
    
    int now=0;
    ll sum=0;
    
    for(int i=1;i<=M;i++){
        while(S[now].first<=i&&now<N){
            PQ.push(S[now].second);
            now++;
        }
        if(!PQ.empty()){
            int a=PQ.top();
            PQ.pop();
            sum+=ll(a);
        }
    }
    
    cout<<sum<<endl;
}




Measured memory_bytes: 1660
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
	int key;
	struct Node *prev, *next;
};

struct Node *nil;

void init() {
	nil = (struct Node *)malloc(sizeof(struct Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	struct Node *x = (struct Node *)malloc(sizeof(struct Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

struct Node* listSearch(int key) {
	struct Node *cur = nil->next;
	while(cur != nil && cur->key != key ) {
		cur = cur-> next;
	}
	return cur;
}

void deleteNode(struct Node *t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}
void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void printList() {
	struct Node *cur;
	cur = nil->next;
	int isf = 0;

	while(1) {
		if (cur == nil) break;
		if(isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}


int main(void) {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d",com, &key);
		if(com[0] == 'i') {
			insert(key);
			np++;
			size++;
		} else if(com[0] == 'd') {
			if(strlen(com) > 6) {
				if( com[6] == 'F') {
					deleteFirst();
				} else if(com[6] == 'L') {
					deleteLast();
				}
			} else {
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}
	printList();
	return 0;

}

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

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

from1 = []
gotoN = []

for m in range(M):
    a, b = list(map(int, input().split()))
    if a==1:
        from1.append(b)
    if b==N:
        gotoN.append(a)

can = set(from1) & set(gotoN)

if len(can) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


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

const int MAXN = 200;
int cnt[MAXN];

int main()
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    for(int i=A;i<B;i++)   cnt[i]++;
    for(int i=C;i<D;i++)   cnt[i]++;
    int ans=0;
    for(int i=0;i<=100;i++) ans+=(cnt[i]==2);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
w,h,n=map(int, input().split())
xl=0
xr=w
yd=0
yu=h
for _ in range(n):
    x,y,a=map(int, input().split( ))
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xr=min(xr,x)
    elif a==3:
        yd=max(yd,y)
    else:
        yu=min(yu,y)
ans=max(xr-xl,0)*max(yu-yd,0)
print(ans)

Measured memory_bytes: 38256
#include<stdio.h>
int main(){
	char a, b, c;
	scanf("%c%c%c", &a, &b, &c);
	if(a==b && a!=c){
		puts("Yes");
	}
	else if(c==b && a!=c){
		puts("Yes");
	}
	else if(a==c && a!=b){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) //cerr << #x << " : " << x << '\n'

using namespace std;

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

const ll Mod = 1000000007LL;
const int N = 6000;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}

ll dp[N], dp1[N];
ll dpc[N], dpm[N];
ll fdp[N][3];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, A, B;
	cin >> n >> A >> B;
	if(A > B) swap(A, B);

	//dp[0] = 1;
	for(int i = 1; i <= n; i++){
		dp[i] = 1;
		for(int j = A + 1; j <= i; j++) dp[i] += (1ll * dp[i - j] * (j - A)) % Mod;
		dp[i] %= Mod;
		//cerr << i << ' ' << dp[i] << '\n';
	}
	cerr << '\n';
	for(int i = 1; i <= n; i++){
		for(int j = A; j < i; j++) dp1[i] += dp[i - j];
		dp1[i] %= Mod;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j < min(A, i); j++){
			if(i - j >= B) dpc[i] += dp[i - j];
		}
		dpc[i] %= Mod;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j < min(A, i); j++){
			dpm[i] += dp[i - j];
		}
		dpm[i] %= Mod;
	}
	ll ans = 1;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j + i < n; j++) if((i == 0 || i >= A) && (j == 0 || j >= A)) ans += dp[n - i - j];
	}
	ans %= Mod;
	debug(ans);
	debug(dp[3]);
	for(int i = 1; i <= n; i++){
		//fdp[i][1] += 0;
		if(i < A) fdp[i][0] += 1;
		for(int j = 1; j <= min(A - 1, i - 1); j++){
			if(i - j < B) fdp[i][0] += dp[i - j];
			else fdp[i][1] += dp[i - j];
		}
		for(int j = 1; j <= min(A - 1, i - 1); j++){
			if(i - j >= B) fdp[i][1] += dp1[i - j];
			else fdp[i][0] += dp1[i - j];
		}
		if(i + B > n) fdp[i][0] = 0;
		fdp[i][0] %= Mod;
		fdp[i][1] %= Mod;	
		
		//cerr << i << ' ' << fdp[i][0] << ' ' << fdp[i][1] << '\n';

		for(int ln = 1; ln + i <= n; ln ++){
			for(int k = 0; k < 2; k++){
				for(int k2 = k; k2 < 2; k2 ++){
					( fdp[i + ln][k2] += 1ll * fdp[i][k] * (k == k2 ? (k == 0 ? dpm[ln] - dpc[ln] + Mod : dpm[ln]) : dpc[ln]) ) %= Mod;
				}
			}
		}
		ans += (fdp[i][0] + fdp[i][1]) * (i < n ? (dp1[n - i] + dp[n - i]) : 1);
		ans %= Mod;
	}
	debug(dpc[3]);
	cout << ans % Mod << '\n';
	return 0;
}
/*
4 2 2

*/

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

// Macros
#define F  first
#define S  second
#define PB push_back

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

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "TRACE ON! (Line: " << __LINE__ << ")\n"; auto _stream = istringstream{string{#args}}; d_f(_stream, args); } while(0)
	void d_f(__attribute__((unused)) istringstream& _stream) {}
	template<typename Head, typename... Tails> void d_f(istringstream& _stream, Head H, Tails... T) { string _name; _stream >> _name; if(_name.back() == ',') _name.pop_back(); cerr << "\t" << _name << " <=> [" << H << "]\n"; d_f(_stream, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

void solve(){
	string s;
	cin >> s;

	int n = s.size();

	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());

	cout << (s.size() < n ? "no" : "yes") << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


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

#define X 1000000

void sieve(long int n) {
  vector<bool> is_prime(X+1, true);
  is_prime[0] = is_prime[1] = false;
  for(long int i = 2; i <= X; i++) {
    if(is_prime[i] && (long long)i * i <=X) {
      for(long int j = i * i; j <= X; j += i)
        is_prime[j] = false;
    }
  }

  for(long int i = n; i <= X; i++) {
    if(is_prime[i]) {
      cout << i << endl;
      break;
    }
  }
}

int main() {
  long int m;

  cin >> m;

  sieve(m);
  return 0;
}


Measured memory_bytes: 384
import fractions

N = int(input())
A = list(map(int, input().split()))

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def solve():
    memo = A[0]
    for i in range(1, N):
        memo = lcm(memo, A[i])

    ans = 0
    for i in range(N):
        ans += memo // A[i]

    return ans % (10 ** 9 + 7)

print(solve())


Measured memory_bytes: 6200
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<limits.h>
#include<math.h>

using namespace std;
#define MOD 1000000007


static long long int fact[200000] = { 0 };

long long int factrial(long long int num) {
	if (num == 0)return 1;
	if (num == 1)return 1;
	if (fact[num] != 0)return fact[num];

	long long int ans = 1;

	ans = num * factrial(num - 1) % MOD;
	fact[num] = ans;
	return ans;

}

long long int superpow(long long int num, long long int count) {
	if (count == 0)return 1;
	if (count == 1)return num;

	long long int wk = superpow(num, count / 2);

	if (count % 2 == 0)return (wk * wk) % MOD;

	return (((wk * wk) % MOD) * num) % MOD;

}

long long int inv(long long int num) {

	return superpow(num, MOD - 2) % MOD;

}

//nCrのやつ
long long int comb(long long int n, long long int r) {
	if (n == r)return 1;
	if (r == 0)return 1;
	long long int ans = 1;

	ans = factrial(n);

	long long int wk = 1;

	wk = factrial(r);
	
	ans = (ans * inv(wk)) % MOD;

	wk = 1;
	
	wk = factrial(n - r);

	ans = (ans * inv(wk)) % MOD;

	return ans;
}

long long int min(long long int a, long long int b) {
	if (a > b)return b;
	return a;



}


typedef pair<int, long long int> P;

bool pairCompare(const P& firstElof, const P& secondElof) {
	return firstElof.second > secondElof.second;
}


int main()
{
	int n, m;

	cin >> n >> m;

	vector<long long int> a;

	long long int wk;
	long long int wk2;

	for (int i = 0; i < n; i++) {
		cin >> wk;
		a.push_back(wk);
	}


	//（置き換えられる個数、置き換える数）
	vector<P> pairs(m);


	for (int i = 0; i < m; i++) {
		cin >> wk >> wk2;

		pairs[i] = make_pair(wk, wk2);

	}

	sort(pairs.begin(), pairs.end(), pairCompare);
	sort(a.begin(), a.end());

//	for (int i = 0; i < pairs.size(); i++) {
//		cout << pairs[i].second << " " << pairs[i].first << endl;
//
//	}
//	
//	
//	
//	for (int i = 0; i < a.size(); i++) {
//		cout << a[i] << endl;
//	}
	long long int okikaeta = 0;
	bool owari = false;
	for (int i = 0; i < m && okikaeta < n; i++) {

		for (int j = 0; j < pairs[i].first; j++) {
			if (pairs[i].second > a[okikaeta]) {
				a[okikaeta] = pairs[i].second;
				okikaeta++;
			}
			else {
				owari = true;
				break;
			}




		}

		if (owari)break;
	}

	long long int ans = 0;

	for (int i = 0; i < a.size(); i++) {
		ans += a[i];
	}

	cout << ans << endl;


	return 0;



}



Measured memory_bytes: 2676
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
long long n,a,k=0,i,c=0;
string str="";
char ch;
cin>>n;
while(n>0){
        a=n%26;
       k=n/26;
       c++;
      if(a==0){
          k--;
          a=26;
          
      }
       ch=96+a;
      str+=ch;
      n=k;
}
reverse(str.begin(),str.end());
cout<<str;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int N,T,H,L;
	cin>>N>>T>>H>>L;
	vector<int> t(N),h(N);
	for(int i=0;i<N;i++){
		cin>>t[i]>>h[i];
	}
	
	int i=0;
	int ven=0;
	while(true){
		if(t[i]!=0){
			//cout<<i+1<<":10pay  T:"<<T<<" H:"<<H<<" ven:"<<ven<<endl;
			t[i]--;
			T++;
			if(T>L)break;
			ven+=10;
		}else if(h[i]!=0){
			//cout<<i+1<<":100pay T:"<<T<<" H:"<<H<<" ven:"<<ven<<endl;
			h[i]--;
			H++;
			ven+=100;
		}
		else break;

		if(ven>=90){
			ven-=90;
			if((ven%100)/10>T)break;

			T-=(ven%100)/10;
			t[i]+=(ven%100)/10;	
			ven-=ven%100;

			if(T>=ven/10){
				T-=ven/10;	
				t[i]+=ven/10;
				ven=0;
			}else{
				ven-=(T/10)*100;
				t[i]+=(T/10)*10;
				T-=(T/10)*10;

				H-=ven/100;
				h[i]+=ven/100;
				ven=0;
			}
		}

		i++;
		i%=N;
	}
	cout<<i+1<<endl;
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
	int V;
	cin >> V;
	vector <vector <bool>> adj(V, vector <bool> (V, 0));
	rep(V, i) {
		int u, k;
		cin >> u >> k;
		u--;
		rep(k, j) {
			int n;
			cin >> n;
			n--;
			adj[u][n] = 1;
		}
	}
	rep(V, i) rep(V, j) {
		cout << adj[i][j] << (j == V-1 ? '\n' : ' ');
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  1000000007;

     signed main(){
       int n,k;
    
       cin>>n>>k;
       int ans=0;
     for(int i=k;i<=n+1;i++){
          ans=(ans+(2*n+1-i)*i/2-(i-1)*i/2 +1)%MOD;
     }
     cout<<ans<<endl;


      }

        


Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

const int maxn=1e5+5;

ll k;
int n,m;
int c[maxn];
bool bo[maxn];
ll a[maxn],ans[maxn];

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

int main() {
	n=read();
	for(int i=1;i<=n;i++)
	    scanf("%lld",a+i),c[i]=i;
	m=read();scanf("%lld",&k);
	for(int i=1;i<=m;i++) {
		int x=read();
		swap(c[x],c[x+1]);
	}
	for(int i=1;i<=n;i++)
		if(!bo[i]) {
			int u=i,cnt=0,step,goal;
			while(!bo[c[u]])
				bo[c[u]]=1,cnt++,u=c[u];
			step=k%cnt,goal=u=i;
			for(int j=1;j<=step;j++)
				goal=c[goal];
		    for(int j=1;j<=cnt;j++)
				ans[u]=goal,u=c[u],goal=c[goal];
		}
	for(int i=2;i<=n;i++) {
		int x=ans[i];
		ans[i]=a[x]-a[x-1];
	}
	ans[1]=a[1];
	for(int i=1;i<=n;i++)
		ans[i]+=ans[i-1],printf("%.1lf\n",(double)ans[i]);
	return 0;
}


Measured memory_bytes: 3456
/*
C++ のソースコードのテンプレート
特にAOJ-ITP1に使いやすい
*/
#define _USE_MATH_DEFINES

#include <iostream> // 標準入出力
#include <fstream>  // ファイル入出力
#include <string>   // 文字列関係
#include <vector>   // 可変の配列
#include <cmath>    // 数学系
#include <iomanip>  // streamの書式関係
#include <algorithm>// max関数など

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // 要素数が可変のベクトル
using std::fixed;         // ストリームの設定をデフォルトにする
using std::setprecision;  // 引数に小数点以下の桁数を指定することが出来る

int main() {
	string S;
	int sum = 0;
	cin >> S;
	for (size_t i = 0; i < S.length(); i++)
	{
		if (S[i] == '1') {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), diff(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll ans = 0, sum = 0;
  REP(i, n) {
    diff[i] = a[i] - b[i];
    if (diff[i] < 0) {
      ++ans;
      sum -= diff[i];
    }
  }

  sort(ALL(diff));
  REPR(i, n - 1) {
    if (diff[i] < 0 || sum == 0) break;

    ++ans;
    if (sum <= diff[i]) {
      sum = 0;
      break;
    } else {
      sum -= diff[i];
    }
  }

  if (sum == 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 2560
# Volume0 - 0008
while n = gets
    n = n.to_i
    count = 0
    
    for a in 0..9
        break if a > n
        
        for b in 0..9
            break if a + b > n 
            
            for c in 0..9
                break if a + b + c > n
                
                for d in 0..9
                    break if a + b + c + d > n
                    
                    count += 1 if a + b + c + d == n
                end
            end
        end
    end
    puts count
end



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

int main() {
  unordered_set<string> dic;
  int count = 0;
  cin >> count;
  for (int i = 0; i < count; i++) {
    string mode;
    string str;
    cin >> mode >> str;
    if (mode == "insert") {
      dic.insert(str);
    } else {
      if (dic.find(str) != dic.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 31996
m, f, r = map(int, raw_input().split())

while m != -1 or f != -1 or r != -1:

	s = m + f

	if m == -1 or f == -1:
		print "F"
	elif s >= 80:
		print "A"
	elif s >= 65:
		print "B"
	elif s >= 50:
		print "C"
	elif s >=30:
		if r >= 50:
			print "C"
		else:
			print "D"
	else:
		print "F"

	m, f, r = map(int, raw_input().split())

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
int a[N];
int n,L;
int main()
{
    scanf("%d%d",&n,&L);
    int sum=0;
    for(int i=1;i<=n;i++)
	{
		a[i]=L+i-1;
		sum+=a[i];
	}
	int sum1=sum;
	int ans;
	int cha=1e9;
	for(int i=1;i<=n;i++)
	{
		sum1=sum;
		sum1-=a[i];
		if(abs(sum1-sum)<cha)
		{
			ans=sum1;
			cha=abs(sum1-sum);
		}
	}
	
	cout<<ans<<endl;

	return 0;
 
}

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

int main()
{
    int n;
    cin>>n;
    set<int> ss;
    ss.clear();
    int x;
    while(n--){
        cin>>x;
        if(ss.count(x))
            ss.erase(x);
        else ss.insert(x);
    }
    int ans=ss.size();
    cout<<ans;
    return 0;
}


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

int main(){

    int n;
    string s;
    cin >> n >> s;

    int t=0;
    int cnt=0;

    rep(i,n){
        if(s[i]=='I'){
            cnt++;
            t=max(t,cnt);
        }else if(s[i]=='D'){
            cnt--;
        }
    }
    cout << t << endl;

    return 0;
}

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

using namespace std;

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

int main(){
    int n, k;
    cin >> n >> k;
    if (n % k == 0){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }   
}


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

using namespace std;

int main(){
    long  sum = 0;
    int n;
    int a[200001];
    int pos[200001];
    set<int> data;

    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        pos[a[i]] = i;
    }

    data.insert(0);
    data.insert(n + 1);

    for (int i = 1; i <= n; ++i)
    {
        int l, r;
        data.insert(pos[i]);
        set<int>::iterator it = data.find(pos[i]);
        r = *(++it) - pos[i];
        --it;
        l = pos[i] - *(--it);
        sum += (long)i * r * l;
    }
    cout << sum << endl;
}


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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;

    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define ll long long int
int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll a[n][3];
	for(int i=0;i<n;i++){
		ll x, y,z;
		cin>>x>>y>>z;
		a[i][0]=x;
		a[i][1]=y;
		a[i][2]=z;
	}
	ll dp[n][3];
	
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			dp[i][j]=0;
			for(int k=0;k<3;k++){
				if(j!=k){
					dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
				}
			}
		}
	}
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
	return 0;
}

Measured memory_bytes: 4992
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    h, w = MI()
    s = [["."] + list(input().rstrip()) + ["."] for _ in range(h)]

    empty = ["."] * (w + 2)
    s.append(empty)
    s.insert(0, empty)
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if s[i][j] == "#":
                continue
            else:
                bomb = 0
                for row in [-1, 0, 1]:
                    for col in [-1, 0, 1]:
                        if s[i + row][j + col] == "#":
                            bomb += 1
                s[i][j] = str(bomb)
        print("".join(s[i][1 : w + 1]))

    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 40048
n, m = map(int, input().split( ))

war = [10**10 for i in range(n)]


for _ in range(m):
    a, b = map(int, input().split( ))
    war[a-1] = min(war[a-1],b-1)

a = []
b = []

for ai,bi in enumerate(war):
    if bi<10**9:
        a.append(ai)
        b.append(bi)


bridge = []
i=0
l = len(a)
while i<l:#iを固定して、一緒に切るwarのうちbが最小のものがb_dum
    b_dum = b[i]
    while i+1<l and a[i+1]<b_dum:
        b_dum = min(b_dum,b[i+1])
        i+=1
    bridge.append(b_dum-1)
    i += 1    

print(len(bridge))



Measured memory_bytes: 57632
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  ll n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (ll i = 0; i < n; ++i) cin >> a[i];
  for (ll i = 0; i < m; ++i) cin >> b[i];
  ll j = m;
  ll sum = accumulate(b.begin(), b.end(), 0LL);
  ll result = 0;
  for (ll i = 0; i <= n; ++i) {
    if (i > 0) sum += a[i - 1];    
    while (sum > k && j > 0) {
      sum -= b[j - 1];
      j--;
    }
    if (sum <= k) result = max(result, i + j);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 6436
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

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

bool color[8];

int main()
{
    int N;
    cin >> N;
    int a[100];
    for(int i = 0; i < N; ++i) cin >> a[i];
    int all_type = 0;
    int color_index = -1;
    for(int i = 0; i < N; ++i){
        if(a[i] <= 399){
            color_index = 0;
        }else if(a[i] >= 400 && a[i] <= 799){
            color_index = 1;
        }else if(a[i] >= 800 && a[i] <= 1199){
            color_index = 2;
        }else if(a[i] >= 1200 && a[i] <= 1599){
            color_index = 3;
        }else if(a[i] >= 1600 && a[i] <= 1999){
            color_index = 4;
        }else if(a[i] >= 2000 && a[i] <= 2399){
            color_index = 5;
        }else if(a[i] >= 2400 && a[i] <= 2799){
            color_index = 6;
        }else if(a[i] >= 2800 && a[i] <= 3199){
            color_index = 7;
        }else{
            all_type++;
        }
        color[color_index] = true;
    }
    int mincnt = 0;
    int maxcnt = 0;
    for(int i = 0; i < 8; ++i){
        if(color[i])
            mincnt++;
    }
    if(mincnt == 0){
        cout << 1 << " " << all_type << endl;
        return 0;
    }
    maxcnt = mincnt+all_type;
    cout << mincnt << " " << maxcnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N + 1];
		int ans = 0;

		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}

		for (int i = 0; i < N; i++) {
			if (x[i] <= Math.abs(K - x[i])) {
				ans += x[i] * 2;
			} else {
				ans += Math.abs(K - x[i]) * 2;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23764
import scala.io.StdIn._

object Main extends App {

  val n = readInt()
  val A = readLine().split(" ").map(_.toLong)
  def solve() = {
    val mod = (1e9+7).toInt
    var sum = (0 until n).foldLeft(0L){ (acc, i) =>
      (acc + A(i)) % mod
    }
    (0 until n-1).foldLeft(0L) { (acc, i) =>
      sum -= A(i)
      if(sum < 0) sum += mod
      acc + A(i) * sum % mod
    } % mod
  }

  println(solve())

}



Measured memory_bytes: 86676
#include <bits/stdc++.h> 
#define MAX 5000 
using namespace std; 
#define ll long long
void printString(long long n) 
{ 
	char str[MAX];  
	ll i = 0;  

	while (n > 0) { 
	 
		ll rem = n % 26; 

		if (rem == 0) { 
			str[i++] = 'z'; 
			n = (n / 26) - 1; 
		} 
		else 
		{ 
			str[i++] = (rem - 1) + 'a'; 
			n = n / 26; 
		} 
	} 
	str[i] = '\0'; 


	reverse(str, str + strlen(str)); 
	cout << str << endl; 

	return; 
} 


int main() 
{ 
	long long n;
	cin>>n;
	printString(n);
	
	return 0; 
} 


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

ll mod = 1000*1000*1000+7;

vector<ll> tree[100*1000+5];
ll dp[100*1000+5][2];
bool visited[1000*100+5];


void solve(ll u){	
	visited[u] = true;
	dp[u][0] = dp[u][1] = 1;
	
	if (tree[u].size() == 0) return;
	
	for(ll v: tree[u]){
		if(!visited[v]){
			solve(v);
			dp[u][0] = ((dp[u][0]%mod) * (dp[v][1]%mod))%mod;
			dp[u][1] = ((dp[u][1]%mod)*(dp[v][0]%mod + dp[v][1]%mod))%mod;
		}
	}
}
	

int main(){
	ll N;
	cin>>N;
	ll x,y;
	for(ll i = 0;i<N-1;i++){
		cin>>x>>y;
		tree[x-1].push_back(y-1);
		tree[y-1].push_back(x-1);
	}
	
	memset(visited, false, sizeof visited);
	
	solve(0);
	//for(ll i = 0;i<N;i++)
	//	cout<<i+1<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
	cout<<(dp[0][0]%mod+dp[0][1]%mod)%mod<<endl;
}

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

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

    int favorite[M + 1] = {};
    int K;
    int A;
    for (int i = 0; i < N; i++)
    {
        cin >> K;
        for (int j = 0; j < K; j++)
        {
            cin >> A;
            favorite[A]++;
        }
    }
    int ans = 0;
    for (int i = 0; i <= M; i++)
    {
        if (favorite[i] == N){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

public class Hello{
    public static void Main(){
        // Your code here!
        
        int n = int.Parse(Console.ReadLine());
        int ans = 10000; 
      
        string[] mofu = Console.ReadLine().Split(' ');
        int[] mofii = mofu.Select(int.Parse).ToArray();

      for(int i = 1; i < n; i++){
        int t = i;
        int w1 = 0;
        int w2 = 0;
        for(int j = 0; j < t; j++){
          w1 += mofii[j];
        }
        for(int j = t; j < n; j++){
          w2 += mofii[j];
        }
        w1 = w1 - w2;
        
        if(w1 < 0){
          w1 = -w1;
        }
        
        if(ans > w1){
          ans = w1;
        }
      }
      
        System.Console.WriteLine(ans);
      
    }
}


Measured memory_bytes: 13268