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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

ll dp[2005][2005];

ll mpower(ll x, ll y, ll m)
{
    ll ans = 1;

    x %= m;

    while(y)
    {
        if(y & 1)
        {
            ans = (ans * x) % m;
        }

        y /= 2;

        x = (x * x) % m;
    }

    return ans%m;

}

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

    // cout<<fixed<<setprecision(15);

    for(ll i = 0 ; i <= 2000 ; i++)
    {
        for(ll j = 0 ; j <= i ; j++)
        {
            if(j == 0 || j == i)
            {
                dp[i][j] = 1;
            }
            else
            {
                dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % mod;
            }
        }
    }

    ll n,k;
    cin>>n>>k;

    if(n == k)
    {
        for(ll i = 1 ; i <= k ; i++)
        {
            if(i == 1)
                cout<<1<<endl;
            else
            {
                cout<<0<<endl;
            }
        }
        return 0;
    }

    for(ll i = 1; i <= k ; i++)
    {
        if(i > (n - k + 1))
        {
            cout<<0<<endl;
            continue;
        }

        ll t1 = k;

        ll t2 = i;

        t1 -= i;

        ll ans = dp[t1 + i - 1][i-1];

        ll ans1 = 0;
        ll ans2 = 0;
        ll ans3 = 0;

        if((i - 1) <= (n - k))
        {

            if(t2 - 1 > 0)
            {
                ll t11 = n - k;

                ll t22 = i - 1;

                t11 -= t22;

                if(t11 >= 0)
                    ans1 = dp[t11 + t22 - 1][t22 - 1];
            }
        }

        if(i <= (n - k))
        {
            ll t111 = n - k;

            ll t222 = i;

            t111 -= t222;

            if(t111 >= 0)
            {
                ans2 = dp[t111 + t222 - 1][t222 - 1];
            }
        }

        if((i + 1) <= (n - k))
        {
            ll t1111 = n - k;

            ll t2222 = (i + 1);

            t1111 -= t2222;

            if(t1111 >= 0)
            {
                ans3 = dp[t1111 + t2222 - 1][t2222 - 1];
            }

        }

        // cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;

        ll tmp = (ans1 + 2 * ans2 + ans3) % mod;

        if(tmp > 0)
        ans = (ans * tmp) % mod;

        cout<<ans<<endl;

    }


}

Measured memory_bytes: 30208
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M,R;
  cin>>N>>M>>R;
  vector<int> B(R);
  for(int &i:B){
    cin>>i;
    i--;
  }
  sort(B.begin(),B.end());
  vector<vector<int>> A(N,vector<int>(N,100000000000000));
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    A[a-1][b-1]=c;
    A[b-1][a-1]=c;
  }
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
  int ans=1000000000000000000;
  do{
    int cnt=0;
    for(int i=1;i<R;i++)
      cnt+=A[B[i-1]][B[i]];
    ans=min(ans,cnt);
  }while(next_permutation(B.begin(),B.end()));
  cout<<ans<<endl;
}

Measured memory_bytes: 3900
#include <bits/stdc++.h>
#define SIZE 200005
using namespace std;
typedef long long int ll;

int A[SIZE];
int main()
{
	int n;
	scanf("%d",&n);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		sum+=A[i];
	}
	ll left=0,right=sum;
	ll ret=sum;
	for(int i=0;i+1<n;i++)
	{
		left+=A[i],right-=A[i];
		ll d=llabs(right-left);
		ret=min(ret,d);
	}
	printf("%lld\n",ret);
	return 0;
}
	

Measured memory_bytes: 1024
#################################
#ここからcode
import fractions
A,B = map(int,input().split())

gcd = fractions.gcd(A,B)
if gcd == 1:
    print(1)
else:
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])

        if temp!=1:
            arr.append([temp, 1])

        if arr==[]:
            arr.append([n, 1])

        return arr

    soinsulist=factorization(gcd)
    print(len(soinsulist)+1)


Measured memory_bytes: 5340
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, j = 0; cin >> n;
	for(int i = 0; i < n; i++)
	{
		int d1, d2; cin >> d1 >> d2;
		if(d1 == d2) j++;
		else j = 0;
		if(j == 3)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";

	return 0;
}

Measured memory_bytes: 3632
#C

S = input()

s0 = 0
s1 = 0
flag = False

for i in S:
    if (i == "1") ^ flag:
        s0 += 1
    if (i == "0") ^ flag:
        s1 += 1
    flag = not(flag)
    
print(min(s0, s1))



Measured memory_bytes: 3188
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define up(a,b) max(a,b)
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
template <typename T> T add(T& a, T b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T mul(T& a, T b){ a = a*b%mod;}
template <typename T> T up_self(T& a, T b){a = up(a,b);}
template <typename T> T min_self(T& a, T b){a = min(a,b);}
string find_largest_pref_palindrome(const string& a){string s = a;reverse(s.begin(),s.end());s = a+"%"+s;int c = 0;vector<int> pref(2*((int)a.size()) +2);for(int i = 1; i< s.size() ; i++ ){while(c!=0&&s[i]!=s[c])c = pref[c-1];if(s[i]==s[c])c++;pref[i] = c;}return s.substr(0,c);}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
/*All the macros below are copied from nik_y(OG)*/
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define all(c) c.begin(),c.end()
#define endl "\n"
#define get(a,n) fl(i,0,n)  cin>>a[i];
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
int main()
{
	Shazam;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int A = (c+b-1)/b;
	int B = (a+d-1)/d;
	if(A<=B)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
  	return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
 
int top,S[10000];
 
void push(int x){
  S[++top]=x;
}
 
int pop(){
 return S[top--];
}
 
int main(){
  int a,b;
  char s[100];
  top=0;
   
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      b=pop();
      a=pop();
      push(a+b);
    }else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      b=pop();
      a=pop();
      push(a*b);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  return 0;
}

Measured memory_bytes: 548
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      	int b = sc.nextInt();
       	int result = (a*b)%2;
      	if (result == 0) {
          System.out.println("Even");
        } else {
          System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21844
from bisect import bisect_left
N = int(input())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        t = l[i] + l[j]
        idx = bisect_left(l, t)
        res += idx-j-1
print(res)


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> l(n);
    for(i = 0;i < n;++i){
        cin >> x.at(i) >> l.at(i);
    }
    vector<pair<ll,ll>> y(n);
    for(i = 0;i < n;++i){
        y.at(i).first = x.at(i) + l.at(i);
        y.at(i).second = x.at(i) - l.at(i);
    }
    sort(all(y));
    ll ans = 0;
    ll hazi = -1e10;
    for(i = 0;i < n;++i){
        if(y.at(i).second >= hazi){
            ++ans;
            hazi = y.at(i).first;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
import re
class c:
    def __str__(self):
        return str(self.x)
    def __init__(self,value):
        self.x=value
    def __add__(self,value):
        return c(self.x+value.x)
    def __sub__(self,value):
        return c(self.x-value.x)
    def __mul__(self,value):
        return c(self.x*value.x)
    def __truediv__(self,value):
        return c(int(self.x/value.x))
n=int(input())
for i in range(n):
    s=input()[:-1]
    d=re.sub(r'(\d+)',r'c(\1)',s)
    #print(d)
    print(eval(d))
    #s.group(1)



Measured memory_bytes: 6612
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
#define mod2 20071027
//#define mod 1000074259
#define base 139
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case %lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=300010;
ll h, n, k, a[N], f=0, res;
int main()
{
    in2(n, k);
    for(int i=0;i<n;i++)
        in1(a[i]);
    sort(a, a+n);
    for(int i=0;i<n-k;i++)
    {
        res+=a[i];
    }
    cout<<res<<endl;

    return 0;
}

/*

*/


Measured memory_bytes: 1792
#include<iostream>
#include<string>
const int oo = 1e9;
using namespace std;
void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}


int main(){
	fast();
	string s; cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
	return 0;
}
//mosta7il_

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int cost[30][30][30][30];
int visited[30][30];
int W,H;

int main()
{
	int dx,dy;
	int x=0,y=0;
	int rx=0,ry=0;
	int maxv = 0;
	int N;
	scanf("%d",&N);
	while(~scanf("%d %d",&dx,&dy)){
		if(dx == dy && dy==0){
			printf("%d %d\n",rx,ry);
			x = 0;
			y = 0;
			rx = 0;
			ry = 0;
			maxv = 0;
		}

		x += dx;
		y += dy;
		if(maxv < x*x+y*y){
			maxv = x*x+y*y;
			rx = x;
			ry = y;
		}
		else if(maxv == x*x+y*y){
			if(x > rx){
				rx = x;
				ry = y;
			}
		}
	}
}

Measured memory_bytes: 0
use std::io;

fn main() {
    for i in 1.. {
        let mut input = String::new();
        io::stdin().read_line(&mut input).ok();

        let x = input.trim().parse::<i32>().unwrap();
        if x == 0 { break; }
        println!("Case {}: {}", i, x);
    }
}



Measured memory_bytes: 5040
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int N, M, C;
  cin >> N >> M >> C;
  int A[N][M], B[M];
  for(int m=0; m < M; ++m){
    cin >> B[m];
  }
  for(int n=0; n < N; ++n){
    for(int m=0; m < M; ++m){
      cin >> A[n][m];
    }
  }

  int score, ans;
  ans = 0;
  for(int i=0; i < N; ++i){
    score = 0;
    for(int m=0; m < M; ++m){
      score += A[i][m]*B[m];
    }
    score += C;
    if(score > 0){
      ++ans;
    }
  }

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


Measured memory_bytes: 256
a,b=map(int,input().split())
if a<=0 and b>=0:
  print('Zero')
elif a>0:
  print('Positive')
elif a<0 and b>0:
  if abs(a)%2==0:
    print('Positive')
  else:
    print('Negative')
else:
  if (b-a)%2==0:
    print('Negative')
  else:
    print('Positive')

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

int main(){
   int H, W;
   while(1){
       cin >> H >> W;
       if(H == 0 && W == 0) break;
       for(int i = 1; i <= H; i++){
           for(int j = 1; j <= W; j++){
                if((i + j) %2 == 0 ){
                cout << "#";
                }else{
                cout << ".";
                }
            }cout << endl;
        } cout << endl;
       }
  return 0;
}


Measured memory_bytes: 3088
A = input()
B = input()
judge = 0

if(len(A) > len(B)):
  print('GREATER')
elif(len(A) < len(B)):
  print('LESS')
elif(len(A) == len(B)):
  for i in range(len(A)):
    if(A[i] > B[i]):
      print('GREATER')
      judge = 1
      break
    elif(A[i] < B[i]):
      print('LESS')
      judge = -1
      break
  if(judge == 0):
    print('EQUAL')

Measured memory_bytes: 3064
/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
const int fr = 4;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    if (k == 0) return 1;
    ll t = power(a, k >> 1);
    t = (t * t) % MOD;
    if (k & 1) t = (t * a) % MOD;
    return t;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 2010;

int a[M], n, l;

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n >> l;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 1; i++)
        if (a[i] + a[i + 1] >= l)
        {
            cout << "Possible\n";
            for (int x = 0; x < i; x++)
                cout << x + 1 << "\n";
            for (int x = n - 2; x >= i + 1; x--)
                cout << x + 1 << "\n";
            cout << i + 1 << "\n";
            return 0;
        }
    cout << "Impossible\n";
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long int>
#define fi first
#define se second
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}


using namespace std;

int main()
{
  __;
  string s,t;
  cin>>s>>t;
  s = "$"+s;
  t = "$"+t;
  int n = s.size(),m = t.size();
  vector<vector<int> > dp(n,vector<int>(m));
  vector<vector<int> > keep(n,vector<int>(m));
  dp[0][0] = s[0]==t[0];
  if(dp[0][0]) keep[0][0] = 3;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      if(i==0 && j==0) continue;
      else if(i==0)
      {
        dp[i][j] = dp[i][j-1];
        keep[i][j] = 1;
      }
      else if(j==0)
      {
        dp[i][j] = dp[i-1][j];
        keep[i][j] = 2;
      }
      else
      {
        int a = s[i]==t[j];
        int max1 = -1;
        if(dp[i-1][j-1] + a >= dp[i-1][j]) {max1 = dp[i-1][j-1]+a; keep[i][j] = 3;}
        else {max1 = dp[i-1][j]; keep[i][j] = 2;}
        if(dp[i][j-1] > max1) {max1 = dp[i][j-1]; keep[i][j] = 1;}
        dp[i][j] = max1;
      }
    }
  }

  int i = n-1, j = m-1;
  string k;
  while(i>=0 && j>=0)
  {
    if(i==0 && j==0) break;
    int a = keep[i][j];
    if(a==3)
    {
      // k+=s[i];
      if(s[i]==t[j]) k+=s[i];
      i = i-1;
      j = j-1;
    }
    else if(a==2)
    {
      i = i-1;
    }
    else
    {
      j = j-1;
    }
  } 
  // cout<<dp[n-1][m-1]<<endl;
  reverse(k.begin(),k.end());
  cout<<k<<endl;
  // for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<dp[i][j]<<" "; cout<<endl;}
  // for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<keep[i][j]<<" "; cout<<endl;}
  return 0;
}



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

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define f80 double
#define LOCAL 0
#define endl '\n'

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 100005;
const int inf = 2e9;

signed main(){
    IO;
    if(LOCAL){
        freopen("inp.txt", "r", stdin);
    }
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[2] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string s;
    int n;
    cin >> s >> n;
    for(int i = 0;i < n;i++)
    {
        string o;
        cin >> o;
        if(o == "reverse")
        {
            int b,e;
            string r;
            cin >> b >> e;
            r = s.substr(b,e - b + 1);
            reverse(r.begin(),r.end());
            s.replace(b,r.length(),r);
        }
        else if(o == "replace")
        {
            int b,e;
            string r;
            cin >> b >> e >> r;
            s.replace(b,r.length(),r);
        }
        else
        {
            int b,e;
            cin >> b >> e;
            string r = s.substr(b,e - b + 1);
            cout << r << endl;
        }
    }
}

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

int main()
{
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t a = (N / (A + B)) * A;
  int64_t b = min((N % (A + B)), A);
  cout << a + b << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>
bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

VI dp;
vector<VI> G;
int search(int v){
    if(dp[v] != -1) return dp[v];
    int ret = 0;
    REP(i, SZ(G[v])){
        chmax(ret, search(G[v][i]) + 1);
    }
    return dp[v] = ret;
}

int main(){
    int n, m; cin >> n >> m;
    dp.resize(n, -1); //i番目の点からの最長パス
    G.resize(n);//to
    REP(i, m){
        int x, y; cin >> x >> y;
        --x; --y;
        G[x].PB(y);
    }
    int ans = 0;
    REP(i, n){
        chmax(ans, search(i));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
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; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }

  int ans=0;
  vector<int> q(n+1,0);
  rep(i,n){
    if(p[i]==0) q[0]=1;
    else q[p[i]]=q[p[i]-1]+1;
    chmax(ans,q[p[i]]);
  }

  cout << n - ans << endl;
}

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

const double eps = 1e-10;

int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        return x < 0 ? -1 : 1;
}

#define Vector P
struct P {
        double x, y;
        P(double x = 0, double y = 0): x(x), y(y) {}
        P operator + (P b) {return P(x + b.x, y + b.y);}
        P operator - (P b) {return P(x - b.x, y - b.y);}
        P operator * (double b) {return P(x * b, y * b);}
        P operator / (double b) {return P(x / b, y / b);}
        double operator * (P b) {return x * b.x + y * b.y;} // Dot
        double operator ^ (P b) {return x * b.y - y * b.x;} // Cross
        double abs() {return hypot(x, y);}
        P unit() {return *this / abs();}
        P spin(double o) {
                double c = cos(o), s = sin(o);
                return P(c * x - s * y, s * x + c * y);
        }
};

struct Line {
        //ax + by + c = 0
        double a, b, c, theta;
        P pa, pb;
        Line(): a(0), b(0), c(0), theta(0), pa(), pb() {}
        Line(P pa, P pb): a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), theta(atan2(-a, b)), pa(pa), pb(pb) {}        P projection(P p) {return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs());}                P reflection(P p) {return p + (projection(p) - p) * 2;}
        double get_ratio(P p) {return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs());}
        P dis(P p) {return ((pb - pa) ^ (p - pa)) / (pb - pa).abs();} // directed distance
};

struct Circle {
        P c;
        double r;
        Circle(P c, double r = 0): c(c), r(r) {}
};
bool onsegment(P p, P a, P b) {
        return dcmp((a - p) ^ (b - p)) == 0 && dcmp((a - p) * (b - p)) <= 0;
}
bool segment_intersection(P p1, P p2, P p3, P p4) { // end points are not allowed
        return dcmp((p2 - p1) ^ (p3 - p1)) * dcmp((p2 - p1) ^ (p4 - p1)) < 0
                && dcmp((p4 - p3) ^ (p1 - p3)) * dcmp((p4 - p3) ^ (p2 - p3)) < 0;

}

int main() {
        ios_base::sync_with_stdio(false); cin.tie(0);
        P p0, p1;
        cin >> p0.x >> p0.y >> p1.x >> p1.y;
        Vector v = p1 - p0;
        int q; cin >> q;
        while(q--) {
                P p; cin >> p.x >> p.y;
                Vector w = p - p0;
                int f = dcmp(v ^ w);
                if(onsegment(p, p0, p1)) cout << "ON_SEGMENT" << '\n';
                else if(f == 1) cout << "COUNTER_CLOCKWISE" << '\n';
                else if(f == -1) cout << "CLOCKWISE" << '\n';
                else {
                        if((v * w) < 0) cout << "ONLINE_BACK" << '\n';
                        else cout << "ONLINE_FRONT" << '\n';
                }
        }
        return 0;
}


Measured memory_bytes: 3296
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cwctype>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){

	string in;
	cin>>in;
	string out;
	out=in;
	for(int i=0;i<in.size();i++){
		int x=in[i]-'A';
		x-=3;
		x=(x<0)? x+26 : x;
		out[i]=x+'A';

	}

	cout<<out<<endl;

	return 0;
}

Measured memory_bytes: 1184
using System;


    class Program
    {
        static void Main(string[] args)
        {
            // 3の倍数または一桁が３に終わる場合出力
            int num = int.Parse(Console.ReadLine());
            int cnt = 1;

            while(cnt <= num)
            {
                if(cnt % 3 == 0)
                {
                    Console.Write(" " + cnt);
                }
                else if( cnt % 10 == 3)
                {
                    Console.Write(" " +cnt);
                }
                else if (cnt % 100 >= 30 && cnt % 100 < 40)
                {
                    Console.Write(" " +cnt);
                }
                else if (cnt % 1000 >= 300 && cnt % 1000 < 400)
                {
                    Console.Write(" " +cnt);
                }
                else if(cnt % 10000 >= 3000 && cnt % 10000 < 4000)
                {
                    Console.Write(" " + cnt);
                }
                cnt++;      
                
            }   // end while
            Console.WriteLine("");
        }   // end main
    }   // end class




Measured memory_bytes: 15928
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;
	return 0;
}

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

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

    ll ans = 0; int a = 0, b = 0, ab = 0;
    REP(i, 0, N) {
        string s; cin >> s;
        REP(j, 0, s.size() - 1) {
            if (s[j] == 'A' && s[j + 1] == 'B') ans++;
        }
        if (s.front() == 'B' && s.back() == 'A') ab++;
        else if (s.front() == 'B') b++;
        else if (s.back() == 'A') a++;
    }
    
    if (ab > 0) {
        ans += (ab - 1);
        if (a > 0) {
            ans++;
            a--;
        }
        if (b > 0) {
            ans++;
            b--;
        }
    }

    ans += min(a, b);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	

	string S;
	cin>>S;
	
	if(S[0]==S[S.size()-1]){
		if(S.size()%2==0){
			cout<<"First"<<endl;
		}
		else{
			cout<<"Second"<<endl;
		}
	}
	else{
		if(S.size()%2==0){
			cout<<"Second"<<endl;
		}
		else{
			cout<<"First"<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,c,a[101],b[100],k,q;
int main(){
  for(cin>>n>>b[0],i=1;i<n-1;i++){
    cin>>b[i];
    c+=min(b[i],b[i-1]);
  }
  cout<<c+b[i-1]+b[0];
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const ll N = 3e5;
ll n,k;
ll arr[N],dp[N];
int main() {
	speed;
	cin >> n;
	for(int i = 0 ; i < n ; i++)
		cin >> arr[i];
	dp[1] = abs(arr[1] - arr[0]);
	for(int i = 0 ; i < n ; i++){
		dp[i + 1] = min(abs(arr[i + 1] - arr[i]) + dp[i], dp[i + 1]);
		dp[i + 2] = abs(arr[i + 2] - arr[i]) + dp[i];
	}
	cout << dp[n - 1];
}
/*
Timus : 288471KD
CF : Zhabka
mail : dzhon.snoudin@mail.ru
*/



Measured memory_bytes: 3072
# E

import sys

n, k = map(int, input().split())

a = list(map(int, input().split()))

s = sum(a)

l = []

def check(b) :
    r1 = [x % b for x in a]
    r1.sort()
    s1 = sum(r1)
    
    mn = 1e9
    s2 = 0
    for i in range(n):
        s2 += r1[i]
        mn = min(max(s2, (n-1-i)*b - (s1-s2)), mn)
        
    if mn <= k :
        print(int(b))
        sys.exit(0)
        

for p in range(1,int((s+1)**0.5+1)) :
    if s % p != 0:
        continue
    b = s // p
    l.append(b)
    check(b)
    
l.reverse()

for p in l:
    b = s // p
    check(b)
        
    

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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
  IOS;
  int arr[5], i, ans=0;
  for (i=0; i<5; i++)
    {
      cin >> arr[i];
    }
  for (i=0; i<5; i++)
    {
      ans++;
      if (arr[i] == 0)
        break;
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
<?php
list($s) = ints();
// (0,0),(10**9,1),(x2,y2) とすると面積sは s=abs(10**9*y2-x2)
$y2 = intdiv($s, 10 ** 9) + min(1, $s % (10 ** 9));
$x2 = 10 ** 9 * $y2 - $s;
echo implode(' ', [0, 0, 10 ** 9, 1, $x2, $y2]);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<long long int,long long int>
#define vi vector<long long int >
#define vvi vector<vector< long long int>>
#define MP make_pair
#define PB push_back 
#define pb pop_back
#define PF push_front
#define pf pop_front
#define MOD 1000000007
#define mod 998244353
#define MT make_tuple
stack< ll > s;
pii a[200005];
vi vec[200005];
bool vis[200005],in[200005];
ll co=0;
ll ans=1,dp[200005];
bool comp(pii p1,pii p2)
{
	if(p1.first==p2.first)
		return p1.second<p2.second;
	return p1.first<p2.first;
}
void mg(ll i)
{
	while(!s.empty() && a[s.top()].first<a[i].second)
	{
		vec[i].PB(s.top());
		ll j=s.top();
		s.pop();
		in[j]=true;
		mg(j);
	}
}
void dfs(ll i)
{
	dp[i]=1;
	ll k=vec[i].size();
	for(ll j=0;j<k;j++)
	{
		dfs(vec[i][j]);
		dp[i]=(dp[i]*dp[vec[i][j]])%mod;
	}
	dp[i] = (dp[i]+1)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i].first>>a[i].second;
		a[i].second+=a[i].first;
	}
	sort(a,a+n,comp);
	for(ll i=n-1;i>=0;i--)
	{
		//cout<<a[i].first<<endl;
		s.push(i);
		vis[i]=false,in[i]=false;
		dp[i]=-1;
	}
	while(!s.empty())
	{
		ll i=s.top();
		s.pop();
		mg(i);
	}
	for(ll i=0;i<n;i++)
	{
		if(in[i]==true)
			continue;
		if(vec[i].size()>0)
		{
			//co=1;
			dfs(i);
		}
		else
			dp[i]=2;
		ans=(ans*dp[i])%mod;
	}
	
	cout<<ans<<"\n";
    return 0;
}
			

Measured memory_bytes: 25856
N, X, Y = map(int, input().split())
ans = [0] * (N - 1)

start = X
end = Y

for left in range(1, N): # 1 から N - 1 まで
    for right in range(left + 1, N + 1): # left + 1 から N まで
        # 外外
        if left <= start and end <= right: 
            dist = (right - left) - (end - start - 1)
        # 外内
        elif left <= start and right < end:
            dist = min(right - left, start - left + 1 + end - right)
        # 内外
        elif start < left and end <= right:
            dist = min(right - left, left - start + 1 + right - end)
        # 内内
        else:
            dist = min(right - left, left - start + 1 + end - right)

        # リストに格納
        ans[dist - 1] += 1

for a in ans:
    print(a)

Measured memory_bytes: 46300
A = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
    A[i] = A[i][::-1]

S = input()[::-1]
idx = 0
while idx < len(S):
    flag = False
    for i in range(4):
        if len(S) - idx < len(A[i]):
            continue
        else:
            if S[idx:idx+len(A[i])] == A[i]:
                flag = True
                idx += len(A[i])
                break
            else:
                continue
    if idx >= len(S) or flag == False:
        break

print(["NO","YES"][idx == len(S)])

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

int main(){
    int A, B, K;

    cin >> A >> B >> K;

    int C = 0;
    for(int i=min(A,B); i>=0; i--){
        if(!(A%i) && !(B%i)){ C++; }
        if(K == C){
            cout << i;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(K):
    ans += p[i]
    tt = ans
for i in range(K,N):
    tt = tt+p[i]-p[i-K]
    ans = max(ans, tt)
print((ans + K)/2)

Measured memory_bytes: 71792
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char s[N];
int cnt[26];
int main() {
	scanf("%s", s);
	int n = (int) strlen(s);
	long long ans = 0;
	for (int i = 0; i < n; ++ i) {
		ans += i - cnt[s[i] - 'a'];
		cnt[s[i] - 'a'] ++;
	}
	cout << ans + 1 << endl;
}



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

using namespace std;

int main()
{
    int a, b, n;
    while (cin >> a >> b >> n) {
        int sum = 0;
        a *= 10;

        for (int i = 0; i < n; i++) {
            sum += (a / b) % 10;
            a %= b;
            a *= 10;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	int l;
	cin>>l;
	l=(double)l;
	double side=(double)l/3;
	double ans=(double)(pow(side,3));
	cout<<setprecision(20)<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int M[MAX][MAX],n;
 
void dijkstra(int s){
  int i,u,v,minv;
  int d[MAX],p[MAX],color[MAX];
 
  for(i=0; i<n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
    d[s] = 0;
    p[s] = -1;
  }
 
  while(1){
    minv = INFTY;
      for(i=0; i<n; i++){
    if(color[i] != BLACK && d[i] < minv){
      minv = d[i];
      u = i;
    }
      }
    if(minv == INFTY) break;
    color[u] = BLACK;
 
    for(v=0; v<n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
    if(d[u] + M[u][v] < d[v]){
      d[v] = d[u] + M[u][v];
      p[v] = u;
      color[v] = GRAY;
    }
      }
    }
  }
  for(i=0; i<n; i++){
    printf("%d ",i);
    if(d[i] == INFTY) printf("-1\n");
    else printf("%d\n",d[i]);
  }
}
 
 
int main(){
  int i,j,u,k,v,c;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = INFTY;
    }
  }
 
  for(i=0; i<n; i++){
    scanf("%d%d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d%d",&v,&c);
      M[u][v] = c;
    }
  }
 
  dijkstra(0);
 
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    int b;
    int x;
    cin >> x;
    if (x >= 0) {
      a = x;
    }
    else {
      a = -x;
    }
    if (x >= K) {
      b = x - K;
    }
    else {
      b = K - x;
    }
    if (a >= b) {
      sum += 2 * b;
    }
    else {
      sum += 2 * a;
    }
  }
  cout << sum << endl;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int r;cin>>r;
	
	writeln(r*r);



}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;


int main(){
    long long int n;
    cin >> n;

    vector<long long int> a(n), b(n), c(n);
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    rep(i, n){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    long long int ans = 0;
    rep(i, n){
        long long int cnt_a = 0;
        long long int cnt_c = 0;

        cnt_a = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        cnt_c = c.end() - upper_bound(c.begin(), c.end(), b[i]);

        ans += cnt_a * cnt_c;
    }

    cout << ans << endl;
}






Measured memory_bytes: 2560
import heapq
import sys
input = lambda :sys.stdin.readline().rstrip()

def INPUT(mode=int):
    return list(map(mode, input().split()))

def Dijkstra_heap(s, edge):
    # 始点sから各頂点への最短距離#始点sから各頂点への最短距離
    d = [10**20] * n
    used = [False] * n
    d[s] = 0
    used[s] = True
    edgelist = []
    for i, j in edge[s]:
        heapq.heappush(edgelist, i+j*(10**6))
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        v = minedge % (10**6)
        # まだ使われてない頂点の中から最小の距離のものを探す
        if used[v]: continue
        d[v] = minedge // (10**6)
        used[v] = True
        for e in edge[v]:
            if not used[e[0]]:
                heapq.heappush(edgelist, e[0]+(e[1]+d[v]) * (10**6))
    return d

n, m = INPUT()
AB = [INPUT() for _ in range(m)]
edge = [[] for _ in range(n)]
for a, b in AB:
    a -= 1
    b -= 1
    edge[a].append((b, 1))
    edge[b].append((a, 1))

dist = Dijkstra_heap(0, edge)
if dist[-1] <= 2:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 108276
#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=(0);i<(n);i++)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<double> vd;
typedef vector<string> vs;
const int mod = (int)1e9+7;
int main(){
	int n;
	cin>>n;
	int a[n];
	forn(i,n) cin>>a[i];
	int mx=a[0];
	ll ans=0;
	rep(i,1,n){
		if(a[i]<mx) ans+=mx-a[i];
		else mx=max(mx,a[i]);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 4340
#include<stdio.h>

int main(){
  int pm,pe,pj,n,i,ave;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&pm,&pe,&pj);
      ave=(pm+pe+pj)/3;
      if((pm==100||pe==100||pj==100)||
	 ((pm+pe)/2>=90)||
	 (ave>=80)){
	printf("A\n");
      }else if((ave>=70)||
	       (ave>=50&&(pm>=80)||(pe>=80))){
	printf("B\n");
      }else{
	printf("C\n");
      }
    }
  }while(1);
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
int main(){
  int j,i,n,m,best=0;
  char sn[101][11],tm[101][11];
  scanf("%d",&n);
  for(i=0;i<n;i++){
      scanf("%s",sn[i]);
    }
  scanf("%d",&m);
  for(i=0;i<m;i++){
      scanf("%s",tm[i]);
    }
  for(i=0;i<n;i++){
    int scr=0;
    for(j=0;j<n;j++){
      if(strcmp(sn[i],sn[j])==0)scr++;
    }
    for(j=0;j<m;j++){
      if(strcmp(sn[i],tm[j])==0)scr--;
    }
    if(best<scr) best=scr;
  }
  printf("%d",best);
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//String S = sc.next();
		//int N = Integer.parseInt(sc.next());
		//out.println();
		// ArrayList<String> list = new ArrayList<String>();
		// list.stream().sorted().distinct();
		String S = sc.next();
		if(S.charAt(0)==S.charAt(2)){
			out.println("Yes");
		}else{
			out.println("No");
		}
		out.flush();	
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define _READ freopen("input.txt", "r", stdin);
#define _FAST                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
void solve()
{
    int a,b,k;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return ;
        }
    }
    cout<<"NG";

}
int32_t main()
{
    //_READ
    int t;
    t = 1;
    //cin>>t;
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
 
 
int H,W;
bool F[52][52]; //障害物
bool D[52][52][52][52]; //探索済みかの判定用

int inc_tx[4] = {1,-1,0,0}; //方向
int inc_ty[4] = {0,0,1,-1};
int inc_kx[4] = {-1,1,0,0};
int inc_ky[4] = {0,0,-1,1};
 
class Point{
public:
  int tx; //タカユキの座標
  int ty;
  int kx; //カズユキの座標
  int ky;
  int d; //ターン回数
  void set(int a,int b,int c,int d){
    tx = a;
    ty = b;
    kx = c;
    ky = d;
  }
};
 
bool is_out_of_area(int y,int x) //座標が有効範囲内か確認する関数
{
  return x < 1 || x > W || y < 1 || y > H || F[y][x];
}
 
int main(){
 
  while(1){
 
    Point p,q;
    int tx,ty,kx,ky;
    queue<Point> qa;
    cin >> W >> H;
    if(W == 0 && H == 0)
    break;
    cin >> tx >> ty >> kx >> ky;
    memset(F,1,sizeof(F));
    for(int y=1;y<=H;y++){
      for(int x=1;x<=W;x++){
        cin >> F[y][x];
      }
    }
    memset(D,1,sizeof(D));
    p.set(tx,ty,kx,ky);
    D[ty][tx][ky][kx] = 0;
    p.d = 0;
    qa.push(p);
    while(1){
      if(qa.empty()){
        cout << "NA" <<endl;
        break;
      }
      p = qa.front();
      qa.pop();
      if(p.d >= 100){
        cout << "NA" << endl;
        break;
      }
      if(p.tx == p.kx && p.ty == p.ky){
        cout << p.d << endl;
        break;
      }
      for(int i=0;i<4;i++){
        q.tx = p.tx + inc_tx[i]; q.ty = p.ty + inc_ty[i];
        q.kx = p.kx + inc_kx[i]; q.ky = p.ky + inc_ky[i];
 
        if(is_out_of_area(q.ty ,q.tx) == 0 || is_out_of_area(q.ky ,q.kx) == 0){ //タカ,カズともに範囲内なら
          if(is_out_of_area(q.ty ,q.tx)){ //範囲外なら戻る
            q.ty = p.ty; q.tx = p.tx;
          }
          if(is_out_of_area(q.ky ,q.kx)){ //範囲外なら戻る
            q.ky = p.ky; q.kx = p.kx;
          }
          if(D[q.ty][q.tx][q.ky][q.kx]){ //未探索ならキューにプッシュ
            q.d = p.d + 1;
            qa.push(q);
            D[q.ty][q.tx][q.ky][q.kx] = 0;
          }
        }
 
      }
    }
 
  }
  return 0;
}


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

using namespace std;

typedef pair<int, int> ii;

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, a[N], b[N];
int pb[N], pa[N];
int posa[N], posb[N];

vector<int> mem[N];
int gr[N];


void merge(int x, int y) {
    x = gr[pa[x]], y = gr[pa[y]];
    assert(x != y);
    if (mem[x].size() > mem[y].size()) swap(x,y);
    for(auto i : mem[x]){
        gr[i] = y;
        mem[y].push_back(i);
    }
}


int get(int x){
    return min(a[pa[x]], b[pb[x]]);
}
int cost(int x){
    swap(pb[x], pb[x + 1]);
    int ans = get(x) + get(x + 1);
    swap(pb[x], pb[x + 1]);
    ans -= get(x) + get(x + 1);
    return ans;
}
long long solve() {
    int ngr = 0;
    for(int st = 1; st <= n; st++) if (!gr[pa[st]]){
        ++ngr;
        int cur = st;
        while (!gr[pa[cur]]) {
            gr[pa[cur]] = ngr;
            mem[ngr].push_back(pa[cur]);
            cur = posa[pb[cur]];
        }
    }
    priority_queue<ii, vector<ii>, greater<ii>> pq;
    for(int i = 1; i < n; i++) {
        pq.push(ii(cost(i), i));
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++) ans += get(i);
    while (ngr != 1){
        ii cur = pq.top(); pq.pop();
        int pos = cur.second;
        if (gr[pa[pos]] == gr[pa[pos + 1]]) continue;
        if (cur.first != cost(pos)) continue;
        ans += cost(pos);
        swap(pb[pos], pb[pos + 1]);
        merge(pos, pos + 1);
        for(int j = max(1, pos - 1); j <= min(pos + 1, n - 1); j++){
            pq.push(ii(cost(j), j));
        }
        ngr--;
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];

    long long ans = 1e18;
    for(int j = 0; j <= 1; j++){
            for(int i = 1; i <= n; i++) mem[i].clear();
            memset(gr, 0, sizeof(gr));
            for(int i = 1; i <= n; i++) pb[i] = pa[i] = i;
            sort(pa + 1, pa + n + 1, [](int x, int y){return a[x] < a[y];});
            sort(pb + 1, pb + n + 1, [](int x, int y){return b[x] > b[y];});
            for(int i = 1; i <= n; i++){
                posa[pa[i]] = i;
                posb[pb[i]] = i;
            }
            ans = min(ans,solve());
            for(int i = 1; i <= n; i++) swap(a[i], b[i]);
    }
    cout << ans;
}


Measured memory_bytes: 8540