akhauriyash/Code-Regression huggingface dataset:
def main():
    N, P = map(int, input().split())
    *A, = map(int, input().split())

    odd = sum(a % 2 for a in A)
    even = N - odd
    o, e = 0, 0
    # 奇数枚の袋の選び方
    # P=0: 奇数個含まれる袋から足して２の倍数になる袋の組合せ(袋0でもよい)
    # P=1: 奇数なので奇数枚の袋を奇数個
    for i in range(P, odd+1, 2):
        o += ncr(odd, i)

    for i in range(even+1):
        e += ncr(even, i)
    ans = o * e

    print(ans)


def _factorial(n):
    if n < 0:
        raise ValueError("factorial() not defined for negative values")
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a


def npr(n, r):
    if n < r:
        return 0
    a = 1
    for i in range(r):
        a *= n - i
    return a


def ncr(n, r):
    _npr = npr(n, r)
    if _npr == 0:
        return 0
    return _npr // _factorial(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	long long int h1,s1,h2,s2;
	cin>>h1>>s1>>h2>>s2;
	long long int a=0,t=0;
	while(true){
		h2=h2-s1;
		if(h2<1){
			a=1;
			break;
		}
		h1=h1-s2;
		if(h1<1){
			t=1;
			break;
		}
	}
	if(t==1){
		cout<<"No";
	}
   	else if(a==1){
   		cout<<"Yes";
	   }
		return 0;}
	


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

#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int main()
{
    jaldi
    int n;
    cin>>n;
    vector<int> v(n);
    for(int &x:v) cin>>x;
    vector<ll> dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++)
    {
        int cost1=abs(v[i]-v[i-1]);
        int cost2=abs(v[i]-v[i-2]);
        dp[i]=min(cost1+dp[i-1],cost2+dp[i-2]);
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
	int index[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
	int a, b; cin >> a >> b;
	if (index[a] == index[b]) 
		cout << "Yes\n";
	else 
		cout << "No\n";
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    int ans = 0;
    for(int i = 0; i < N ; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k]){
                    if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[i] + L[k] > L[j]){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n,k;
	cin>>n>>k;
	deque<int>dk;
	
	while(n--){
		int temp;
		cin>>temp;
		dk.push_back(temp);	
	}
	int counter = 0;
	while(dk.size()){
		counter++;
		for(int i=0; i<k && dk.size(); i++) dk.pop_front();
		if(dk.size()) dk.push_back(1);
	}
	cout<<counter;
}

Measured memory_bytes: 3568
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n = read::<usize>();

    let mut a = vec![];
    for _ in 0..n {
        let ai = read::<usize>();
        a.push(ai);
    }

    let mut sorted = a.clone();
    sorted.sort_by(|x, y| y.cmp(x));

    for ai in a.into_iter() {
        let res = if ai == sorted[0] {
            sorted[1]
        } else {
            sorted[0]
        };
        println!("{}", res);
    }
}

Measured memory_bytes: 9724
S = list(input())
s1 = list("keyence")

x = []
y = []
for i in range(7):
  if S[i] == s1[i]:
    x.append(1)
  if S[len(S)-1-i] == s1[6-i]:
    y.append(1)
  

if sum(x) + sum(y) >= 7:
  print("YES")  
else:
  print("NO")

Measured memory_bytes: 3064
h,w = map(int,input().split())
field = [list(input())for i in range(h)]
a= [[0]*w for i in range(h)]

vec = [(-1,0),(1,0),(0,1),(0,-1)]
ans = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":continue
        stack = [(i,j)]
        visited = [[0]*w for i in range(h)]
        a[i][j] = 0
        
        while stack:
            next = []
            for x,y in stack:
                
                if visited[x][y]:continue

                visited[x][y] = 1
                

                for tx,ty in vec:
                    nx = x+tx
                    ny = y+ty
                    if nx < 0 or ny <0 or nx >=h or ny >=w:continue
                    if field[nx][ny] == "#" :continue
                    if visited[nx][ny]:continue
                    next.append((nx,ny))
                    a[nx][ny] = a[x][y] + 1
                    
                    
            stack = next
   
        for k in range(h):
            ans = max(ans,max(a[k]))
            a[k] = [0]*w
print(ans)
            
            
            
            


Measured memory_bytes: 46940
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<sstream>
#include<numeric>
#include<queue>
#include<cstdio>
#include<iterator>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb(x) push_back(x)
ll mod = 1e9 + 7;
ll inf = 1e9 + 7;
template<typename T, typename U>
T binpow(T a, U n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return (binpow(a, n - 1) * a) % mod;
    else {
        ll b = binpow(a, n / 2) % mod;
        return (b * b) % mod;
    }
}
template<typename T>
T gcd(T a, T b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
template<typename T>
istream& operator>>(istream& str, vector<T>& vec) {
    for (auto& w : vec) str >> w;
    return str;
}
template<typename T>
ostream& operator<<(ostream& str, vector<T>& vec) {
    for (auto& w : vec) str << w << ' ';
    return str;
}





int main() {
    ll h, w, ch, cw, dh, dw, m;
    cin >> h >> w >> m;
    /*vector<vector<ll>>vec(h, vector<ll>(w, inf));
    vector<vector<bool>> mapp(h, vector<bool>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if (c == '.')mapp[i][j] = 1;
        }
    }
    for(int i )*/
    vector<int> cols(w), rows(h);
    vector <pair<int, int>>tg(m);
    set<pair<int, int>>mn;
    for (int i = 0; i < m; ++i) {
        cin >> tg[i].first >> tg[i].second;
        mn.insert(tg[i]);
        rows[tg[i].first - 1]++;
        cols[tg[i].second - 1]++;
    }
    int maxcol = max_element(all(cols)) - cols.begin();
    int maxrow = max_element(all(rows)) - rows.begin();
    vector<int>irow, icol;
    for (int i = 0; i < rows.size(); ++i) {
        if (rows[i] == rows[maxrow])irow.push_back(i);
    }
    for (int i = 0; i < cols.size(); ++i) {
        if (cols[i] == cols[maxcol])icol.push_back(i);
    }
    bool flag = false;
    for (int i = 0; i < irow.size(); ++i) {
        for (int j = 0; j < icol.size(); ++j) {
            if (mn.count({ irow[i] + 1 ,icol[j] + 1 }) == 0) {
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        cout << cols[maxcol] + rows[maxrow] - 1;
    }
    else {
        cout << cols[maxcol] + rows[maxrow];
    }

}

Measured memory_bytes: 26200
#include <bits/stdc++.h>
using namespace std;
int n, p;
long long s, a[100020], x, y;
int main() {
	scanf("%d%d", &n, &p);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &x, &y);
		a[i] = x * (100 - p) + y * p;
		s += y * p;
	}
	sort(a, a + n);
	for (int i = n - 1; i >= 0; i--) {
		s -= a[i];
		if (s <= 0) {
			printf("%d\n", n - i);
			break;
		}
	}
	return 0;
}

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

int main() {
        int H, W, sum;
        cin >> H >> W;

        sum = H * W;

        vector<char> s(sum);

        for (int i = 0; i < sum; i++) {
            cin >> s.at(i);
        }

        for (int i = 0; i < W + 2; i++) {
            cout << '#';
        }
        cout << endl;

        int k = 0;
        for (int i = 0; i < H; i++) {
            cout << '#';
            for (int j = 0; j < W; j++) {
                cout << s.at(k);
                k++;
            }
            cout << '#' << endl;
        }

        for (int i = 0; i < W + 2; i++) {
            cout << '#';
        }
        cout << endl;
}


Measured memory_bytes: 256
import sys
# sys.stdin = open('input.txt')

m = 2019
s = input()
n = len(s)
s = list(map(int, s[::-1]))

x = 1
tot = 0
cnt = [0 for _ in  range(m)]
ans = 0

for i in range(n):
    cnt[tot] += 1
    tot += (s[i] - 0) * x
    tot %= m
    ans += cnt[tot]
    x = x * 10%m

print(ans)

Measured memory_bytes: 10828
def resolve():
    x,k,d = map(int, input().split())
    x=abs(x)
    if abs(x)>=k*d:
        print(abs(x-k*d))
    else:
        m=x//d
        n=abs(x)%d
        if (m-k)%2==0:
            print(n)
        else:
            print(abs(n-d))
resolve()

Measured memory_bytes: 61796
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] ABC = new int[3];
        int cont = 0;
        for (String s:str.split(" ")){
            ABC[cont] = Integer.parseInt(s);
            cont++;
        }
        if (ABC[0]==ABC[1] && ABC[1]==ABC[2]){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
bool vis[100010];
int num[100010];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	  num[i]=1;
	vis[1]=true;
	for(int i=1;i<=m;i++)
	  {
	  	int x,y;
	  	scanf("%d%d",&x,&y);
	  	if(num[x]==0)
	  	  continue;
	  	if(vis[x])
	  	  vis[y]=true;
	  	if(num[x]==1)
	  	  vis[x]=false;
	  	num[x]--;
	  	num[y]++;
	  }
	int ans=0;
	for(int i=1;i<=n;i++)
	  if(vis[i])
	    ans++;
	cout<<ans;
}

Measured memory_bytes: 768
import math
a,b = map(int,input().split())
ans = 0
g = 0

for i in range(10*b,10*b+10):
	if math.floor(i*0.08) == a and math.floor(i*0.1) == b:
		ans = i
		g += 1
		break
if g > 0:        
	print(ans)
else:
	print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mk make_pair
    #define ft first
    #define sc second
    #define ppb pop_back
    #define sz size
    #define forn(i,a,n) for(i=a;i<n;i++)
    #define M 1000000007
    #define inf 2e18
    
    int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1==m2)cout<<"0\n";
        else
            cout<<"1\n";
    return 0;
    }

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

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

#define rrep(i,n) for(int i =n; i >=0; --i)

#define rep_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

const ll MOD = 1000000007;

const  long double PI=(acos(-1));

const  long double EPS=0.0000000001;

int main(){
    ll n,k; cin >> n >> k;

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

    double ans =  0.0;


    vector<double> kitai(10000);

    double x = 0;
    rep_(i,1,10000){
        x += i;
        kitai[i] = x/i; 
    }


    double a = kitai[p[0]];
    rep_(j,1,k)
        a += kitai[p[0+j]];

    ans = a;

    rep_(i,1,n-k+1){
        a -= kitai[p[i-1]];
        a += kitai[p[i+k-1]];
        if(ans < a) ans = a;
    }
    cout << fixed <<  setprecision(11) << ans << endl;


    return 0;
}

Measured memory_bytes: 1152
from collections import deque
def inputs(): return [int(x) for x in input().split()]
s = deque(input())
q = int(input())
flag = 1
for i in range(q):
    q1 = input()
    if len(q1)==1:
      flag *=-1 
    else:
        l,f,c = q1.split()
        if flag ==1:
            if int(f)==1:
                s.appendleft(c)
            else:
                s.append(c)
        elif flag==-1:
            if int(f)==1:
                s.append(c)
            else:
                s.appendleft(c)
if flag==1:
    print("".join(list(s)))
else:
    s = list(s)
    s = s[::-1]
    print("".join(list(s)))

Measured memory_bytes: 8672
using System;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var A = Console.ReadLine().Split(' ');
		var B = Console.ReadLine().Split(' ');
		var C = Console.ReadLine().Split(' ');
		int ans = 0;
		int tmpA = 21;
//		string[] sH = Console.ReadLine().Split(' ');
		foreach (var An in A) {
			var Ani = int.Parse(An);
			ans += int.Parse(B[Ani - 1]);
			if (tmpA + 1 == Ani) {
				ans += int.Parse(C[Ani - 2]);
			}
			tmpA = Ani;
		}
		Console.Write(ans);
	}
}


Measured memory_bytes: 13140
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int A, B, C;
	cin >> A >> B >> C;
	cout << max(0, C - (A - B)) << endl;
	return 0;
}


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

int main(void){
  double hlen,mlen,hour,minute,rad,len;
  scanf("%la %la %la %la",&hlen,&mlen,&hour,&minute);
  rad = M_PI * (hour/6 - minute * 11/360);
  len = sqrt(pow(hlen,2) + pow(mlen,2) -2*hlen*mlen*cos(rad));
  printf("%.10f\n",len);
  return 0;
}

Measured memory_bytes: 2544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Problem A: Cubist Artwork
 */
public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int w, d;
			w = parseInt(line.substring(0, line.indexOf(' ')));
			d = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((w | d) == 0) break;

			int[][] h = new int[21][2];
			StringTokenizer st;

			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < w; i++) {
				h[parseInt(st.nextToken())][0]++;
			}
			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < d; i++) {
				h[parseInt(st.nextToken())][1]++;
			}

			int ans = 0;

			for (int i = 1; i <= 20; i++) {
				ans += i * Math.max(h[i][0], h[i][1]);
			}
			System.out.println(ans);
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  long long a[n];
  for ( int i = 0; i < n; i++ ) { 
    cin >> a[i];
  }
  sort(a, a+n);

  long long ans = a[n-1];
  int ct = n-3;
  int sec = 0;
  while ( ct-- >= 0 ) {
    ans += a[n-2];
    sec++;
    if ( sec == 2 ) {
      sec = 0;
      n--;
    }
  }

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


Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int digit(ll n) {
  int res = 0;
  while(n > 0) {
    ++res;
    n /= 10;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  ll ans = INF;
  rep(i,1,sqrt(n)+1) {
    if (n%i == 0) {
      ll tmp = max(digit(i),digit(n/i));
      ans = min(ans,tmp);
    }
  }
  cout << ans << '\n';


  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;

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

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  rep(i, N) cin >> v[i];
  sort(all(v), greater<ll>());

  ll sum = 0;
  rep(i, A) {
    sum += v[i];
  }

  printf("%.6f\n", (double)sum / A);

  ll k = 0;
  rep(i, A) {
    if (v[i] == v[A - 1])
      k++;
  }

  ll n = 0;
  rep(i, N) {
    if (v[i] == v[A - 1])
      n++;
  }

  ll COM[51][51];

  repp(i, 0, N) {
    repp(j, 0, i) {
      if (j == 0 || j == i)
        COM[i][j] = 1;
      else {
        COM[i][j] = COM[i - 1][j - 1] + COM[i - 1][j];
      }
    }
  }

  ll ans = 0;
  if (k == A) {
    repp(i, A, B) {
      ans += COM[n][i];
    }
  } else {
    ans = COM[n][k];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define MAXI (1<<32)
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define SIZ 1000005
#define SIZE 200005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair<ll,ll>&a,const pair<ll,ll>&b){
	return a.ss < b.ss;
}

//ll p[20000005]={0};
//vector<ll>ans;
/*void sieve(){
    ll i,j;
    p[0]=p[1]=1;
    for(i=2;i*i<=20000005;i++){
        if(!p[i]){
            for(j=2*i;j<20000005;j+=i){
                p[j]=1;
            }
        }
    }
    fo(i,2,20000005){
        if(!p[i]){
            ans.pb(i);
        }
    }
}*/

signed main(){ 
    IOS
    //io_set();
    ll n, x;
    cin >> n;
    map < ll , ll > m;
    rep(i, n){
        cin >> x;
        m[x]++;
    }
    ll c = 0;
    for(auto it : m){
        if(it.second < it.first){
            c += it.ss;
        }
        else{
            if(it.second == it.first);
            else{
                c += (it.second - it.first); 
            }
        }
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 6272
#A,B= map(int,input().split())
#list(map(int,input().split()))
N = int(input())

l = []
for i in range(N):
    A,B= map(int,input().split())
    l.append([B,A])
l.sort()

ruiseki = [0]*(N+1)
for i in range(N):
    ruiseki[i+1] = ruiseki[i]+l[i][1]
for i in range(N):
    if l[i][0] < ruiseki[i+1]:
        print('No')
        break
else:
    print('Yes')
    


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vll;

const ll INFL = (1L<<62);

int main() {
  int n, m; cin >> n >> m;
  int N = (1 << n);
  vll keys(m);
  vl dp(N, INFL);
  rep(i,m) {
    int a, b; scanf("%d %d", &a, &b);
    int bits = 0;
    rep(j,b) {
      int c; scanf("%d",&c); c--;
      bits |= (1 << c);
    }
    keys[i] = mp(bits, a);
  }
  
  dp[0] = 0;
  rep(i,m) {
    rep(j,N) {
      int d = keys[i].ff, a = keys[i].ss;
      dp[j|d] = min(dp[j|d], dp[j] + a);
    }
  }
  ll ans = dp[N-1];
  if (ans == INFL) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s=input()
t=input()
dp=[[0 for i in range(len(t)+1)] for j in range(len(s)+1)]
#print(lcs(s,t,0,0," ",dp))

for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=1+(dp[i-1][j-1])
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])

x=len(s)
y=len(t)
ans=""
while x!=0 and y!=0:
    if dp[x-1][y]==dp[x][y]:
        x-=1
    elif dp[x][y-1]==dp[x][y]:
        y-=1
    else:
        ans=t[y-1]+ans
        x-=1
        y-=1
print(ans)

Measured memory_bytes: 121052
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1505;
typedef long long ll;
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN][MAXN];
short l[MAXN][MAXN], r[MAXN][MAXN];
int n, a[MAXN][MAXN], res[MAXN][MAXN];
inline void chkmax(short &x, short y) {x = (x > y) ? x : y; }
inline void chkmin(short &x, short y) {x = (x < y) ? x : y; } 
int main() {
	read(n);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= n; j++)
			if (s[i][j] == '#') a[i][j] = 0;
			else a[i][j] = s[i][j] - '0';
	}
	ll finalans = 0;
	for (int i = n; i >= 1; i--)
	for (int j = n; j >= 1; j--) {
		if (a[i][j] != 0) {
			if (a[i + 1][j] == 0 && a[i][j + 1] == 0) l[j][i] = r[j][i] = j;
			else if (a[i + 1][j] == 0) {
				memcpy(l[j] + i, l[j + 1] + i, sizeof(short) * (n - i + 1));
				memcpy(r[j] + i, r[j + 1] + i, sizeof(short) * (n - i + 1));
				l[j][i] = j, res[i][j] = res[i][j + 1];
			} else if (a[i][j + 1] == 0) {
				l[j][i] = r[j][i] = j;
				res[i][j] = res[i + 1][j];
			} else {
				short Max = 0; int ans = res[i + 1][j] + res[i][j + 1];
				l[j][i] = j, r[j][i] = r[j + 1][i];
				for (int k = i + 1; k <= n; k++) {
					if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > Max) ans -= res[k][l[j + 1][k]];
					chkmax(Max, r[j][k]);
					chkmax(r[j][k], r[j + 1][k]);
					chkmin(l[j][k], l[j + 1][k]);
				}
				res[i][j] = ans;
			}
			finalans += a[i][j] * res[i][j];
			res[i][j] += a[i][j];
		} else {
			memset(l[j] + i, 0x3f, sizeof(short) * (n - i + 1));
			memset(r[j] + i, 0, sizeof(short) * (n - i + 1));
		}
	}
	cout << finalans << endl;
	return 0;
}

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

int main(){
  int x,y;
  cin>>x>>y;
  vector<int>z(y);
  for(int i=0;i<y;i++){
  cin>>z.at(i);
  }
  vector<int>d(y-1);
  for(int i=0;i<y-1;i++){
  d.at(i)=z.at(i+1)-z.at(i);
  }
  d.push_back(x-z.at(y-1)+z.at(0));
  sort(d.begin(),d.end());
    cout<<x-d.at(y-1)<<endl;
}

Measured memory_bytes: 2560
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define YESORNO(a) printf(a?"YES\n":"NO\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  string s = "";
  char c;
  rep(i,4) cin >> c, s.push_back(c);
  sort(s.begin(), s.end());

  YESORNO(s == "1479");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int a[] = {1,3,5,7,8,10,12};
    int b[] = {4,6,9,11};
    int c[] = {2};

    int x,y,found;
    found=0;
    cin>>x>>y;
    if(x==2||y==2){
        cout<<"No"<<endl;
    }
    else {

        for (int i = 0; i < 7; i++) {

            if (a[i] == x) {
                found = found + 1;
            }
            else if(a[i]==y){
                found=found+1;
            }
        }
        if (found == 2) {
            cout << "Yes" << endl;
        } else {
            found=0;
            for (int i = 0; i < 4; i++) {
                if (b[i] == x) {
                    found= found+ 1;
                }
                else if(b[i]==y){
                    found=found+1;
                }
            }
            if (found== 2) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }

}

Measured memory_bytes: 256
#include <stdio.h>

main(){

  int a,b,r,tmp;

  
  scanf("%d%d",&a,&b) ;
    if(a < b){
      tmp=a;
      a=b;
      b=tmp;
    }
  
    

    while((r = a%b) !=0){
      a=b;
      b=r;
	    }
    printf("%d\n",b);
  
  return 0;

}

Measured memory_bytes: 592
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>


using namespace std;
int p[100000]; 
long long y[100000] ;
long long arrayy[100000];
int aaaaaa[100000]; long long  cnt[100001];
int main() {

	int n, m;
	
	int P;

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> y[i];
		arrayy[i] = y[i] * (int)1e5 + i;
	}
	sort(arrayy, arrayy + m);
	
	for (int i = 0; i < m; i++) {
		arrayy[i] = arrayy[i] % 100000;
	}

	for (int i = 0; i < m; i++) {
		P = p[arrayy[i]];
		aaaaaa[arrayy[i]] = cnt[P] + 1;
		cnt[P]++;
	}
	for (int i = 0; i < m; i++) {
		printf("%06d%06d\n", p[i], aaaaaa[i]);
	}




	return(0);
}

Measured memory_bytes: 4608
#!/usr/bin/env python3 
# Knapsack問題

# input
N,W = map(int, input().split())
w = []
v = []
for _ in range(N):
    a,b = map(int ,input().split())
    w.append(a)
    v.append(b)

# calc
dp = [[0 for _ in range(W+1)] for _ in range(N+2)]

for i in range(N):
    for j in range(W+1):
        if w[i] <= j:
            dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])


Measured memory_bytes: 171656
<?php
//error_reporting(0);
//$S = trim(fgets(STDIN));
list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$B = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$N;$i++) {
  $a = new StdClass();
  list($a->price,$a->maxcnt)= explode(" ",trim(fgets(STDIN)));
  $SHOP[]=$a;
}
usort($SHOP,"cmp");

$ret = 0;
$left = $M;
foreach($SHOP as $s) {
  //何個必要か
  $ret += $s->price * min($left,$s->maxcnt);
  $left -= $s->maxcnt;
  if ($left <= 0) break;
}
printf("%d\n",$ret);

function cmp($a,$b) {
  return $a->price - $b->price;
}


Measured memory_bytes: 62324
#include <stdio.h>
/** Problem 0026 : Dropping Ink **/
int board[10][10];

void init(void)
{
	int i, j;
	
	for (i=0; i<10; i++) {
		for (j=0; j<10; j++) {
			board[i][j] = 0;
		}
	}
}

int main(void)
{
	int i, j, ii, jj, size;
	init();
	
	while (scanf("%d,%d,%d", &i, &j, &size) != EOF) {
		switch (size) {
			case 1:
				board[i][j] += 1; 
				if (i-1 >= 0) board[i-1][j] += 1; 
				if (i+1 < 10) board[i+1][j] += 1; 
				if (j-1 >= 0)  board[i][j-1] += 1; 
				if (j+1 < 10) board[i][j+1] += 1;
				break;
				
			case 3:
				if (i-2 >= 0)  board[i-2][j] += 1; 
				if (i+2 < 10) board[i+2][j] += 1; 
				if (j-2 >= 0)  board[i][j-2] += 1; 
				if (j+2 < 10) board[i][j+2] += 1;
				
			case 2:
				for (ii=i-1; ii<=i+1; ii++) {
					for (jj=j-1; jj<=j+1; jj++) {
						if (ii >= 0 && ii < 10 && jj >= 0 && jj < 10) board[ii][jj] += 1;
					}
				}
		}
	}
	
	int zero = 0, max = 0;
	for (i=0; i<10; i++) {
		for (j=0; j<10; j++) {
			if (board[i][j] == 0) zero += 1;
			else if (max < board[i][j]) max = board[i][j];
		}
	}
	
	printf("%d\n%d\n", zero, max);
	return 0;
}

Measured memory_bytes: 0
using System;

namespace AOJ.Volume1
{
    public class SpiralPattern
    {
        public static int Main()
        {
            int dataset = int.Parse(Console.ReadLine());
            for (int d = 0; d < dataset; d++)
            {
                int n = int.Parse(Console.ReadLine());
                var sq = new string[n];
                // 初期化
                string line = new string('#', n);
                int cnt = n % 2 == 0 ? n / 2 : n / 2 + 1;
                
                // 上半分
                string bef = "";
                string aft = "";
                bool horizontal = true;
                for (int i = 0; i < cnt; i++)
                {
                    if (horizontal) { line = bef + new string('#', n - bef.Length - aft.Length) + aft; }
                    else
                    {
                        if (bef.Length + aft.Length > n) { line = bef + aft.Substring(1); }
                        else
                        {
                            line = bef + new string(' ', n - bef.Length - aft.Length) + aft;
                        }
                    }
                    sq[i] = line;
                    if (i % 2 == 0)
                    {
                        bef += "# ";
                        aft += " #";
                    }
                    horizontal = !horizontal;
                }

                // 下半分
                cnt = n / 2;
                bef = "# ";
                aft = "";
                horizontal = true;
                for (int i = 1; i <= cnt; i++)
                {
                    if (horizontal) { line = bef + new string('#', n - bef.Length - aft.Length) + aft; }
                    else
                    {
                        if (bef.Length + aft.Length > n)
                        {
                            line = bef + aft.Substring(1);
                        }
                        else
                        {
                            line = bef + new string(' ', n - bef.Length - aft.Length) + aft;
                        }
                    }
                    sq[n - i] = line;
                    if (i % 2 != 0)
                    {
                        if (n % 4 == 0 && i == cnt - 1) { aft += " #"; }
                        else
                        {
                            bef += "# ";
                            aft += " #";
                        }
                    }
                    horizontal = !horizontal;
                }

                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine(sq[i]);
                }
                if (d != dataset - 1) { Console.WriteLine(); }
            }
            return 0;
        }
    }
}

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

const int MOD=(int)1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  long long ans=1;
  vector<int> cnt(3,0);
  for(int i=0;i<N;i++){
    int count=0;
    for(int j=0;j<3;j++){
      if(cnt.at(j)==A.at(i))  count++;
    }
    ans*=count;
    ans%=MOD;
    for(int j=0;j<3;j++){
      if(cnt.at(j)==A.at(i)){
        cnt.at(j)++;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, M; cin >> N >> M;
    vector<set<i64>> G(N);
    REP(i, M) {
        i64 a, b; cin >> a >> b;
        a--, b--;
        G[a].insert(b);
        G[b].insert(a);
    }

    bool ok = false;
    for (i64 v : G[0]) {
        if (G[N - 1].count(v) >= 1) ok = true;
    }
    cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}

Measured memory_bytes: 31328
s = gets.chomp
s1 = s[0..1].to_i
s2 = s[2..3].to_i
if s1 >= 1 && s1 <= 12
  if s2 >= 1 && s2 <= 12
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
else
  if s2 >= 1 && s2 <= 12
    puts "YYMM"
  else
    puts "NA"
  end
end


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

int main()
{
	long long L[3];
	cin >> L[0] >> L[1] >> L[2];
	if (L[0] % 2 == 0 || L[1] % 2 == 0 || L[2] % 2 == 0) {
		cout << 0 << endl;
	}
	else {
		sort(L, L + 3);
		cout << L[0] * L[1] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(111111);
  for (int i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    A.at(a - 1).push_back(b);
  }

  int ans = 0;
  priority_queue<int> que;
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < A.at(i).size(); j++)
    {
      que.emplace(A.at(i).at(j));
    }
    if (!que.empty())
    {
      ans += que.top();
      que.pop();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 5888
n=int(input())
c=list(input())

ans=20000000
num=0
for i in range(n):
     if c[i]=='W':
          num+=1
ans=min(ans,num)


l=0
for i in range(n):
     if c[i]=='W':
          l=i
          break
r=0
for i in range(n):
     if c[i]=='R':
          r=i

sum=0

while(l<r):
     sum+=1
     c[l]='R'
     c[r]='W'
     for i in range(l+1,n):
          if c[i]=='W':
               l=i
               break
     for i in range(r,0,-1):
          if c[i]=='R':
               r=i
               break
     

ans=min(ans,sum)
print(ans)

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

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

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

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if ((m-j)*i + (n-i)*j == k) {
                cout << "Yes" << endl;
                return 0;
            }  
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b,c; cin >> a ;
	//string s; cin >> s;
	cout << "ABC" << a;
	


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
            dp[0][r+1][c] = max(dp[i][r][c], dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])

print(max(dp[0][-2][-2], dp[1][-2][-2], dp[2][-2][-2], dp[3][-2][-2]))


Measured memory_bytes: 427600
import java.io.*;

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
      String count = new String(in.readLine());
      int nCount = Integer.parseInt(count);
      String s = new String(in.readLine());
      System.out.println(s);
      String[] arr = s.split(" ");
      for( int i = 1; i < nCount; i++ ) {
        String v = arr[i];
        int j = i - 1;
        while(j >= 0 && Integer.parseInt(arr[j]) > Integer.parseInt(v)) {
          arr[j+1] = arr[j];
          j--;
          arr[j+1] = v;
        }
        StringBuilder sb = new StringBuilder();
        for( String w : arr ) {
          sb.append(w).append(" ");
        }
        System.out.println(sb.toString().trim());
      }
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }
  }
}

Measured memory_bytes: 27300
using System;
using System.Collections;
using System.Collections.Generic;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var split = Console.ReadLine().Split(' ');
            int a = int.Parse(split[0]);
            int b = int.Parse(split[1]);
            int c = int.Parse(split[2]);

            if (a == b) Console.WriteLine(c);
            if (b == c) Console.WriteLine(a);
            if (a == c) Console.WriteLine(b);

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 201001, mod = 1e9 + 7;
int cnt[maxn];
int bin_pow(int a, int k) {
    if (k == 0) return 1;
    if (k == 1) return a;
    if (k % 2 == 0) {
        int zn = (bin_pow(a, k / 2)) % mod;
        return (zn * zn) % mod;
    } else {
        int zn = (bin_pow(a, k - 1)) % mod;
        return (zn * a) % mod;
    }
}
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int d = k; d >= 1; d--) {
        int cn1 = 0;
        for (int i = d; i <= k; i += d) {
            cn1++;
        }
        int cn = bin_pow(cn1, n);
        for (int i = d * 2; i <= k; i += d) {
            cn -= cnt[i];
        }
        cn %= mod;
        cn += mod;
        cn %= mod;
        cnt[d] = cn;
        ans += d * cn;
        ans %= mod;
        //cout << d << " " << cnt[d] << "\n";
    }
    cout << ans;
}


Measured memory_bytes: 4388
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main{  
    public static void main(String[] args) throws IOException {
          BufferedReader entrada= new BufferedReader( new InputStreamReader( System.in ),1024*8);
        int A[] = new int[10];
        int numero,i;
    for( i=0;i<10;i++)
    {
            numero=Integer.parseInt(entrada.readLine());
        A[i]=numero;
        
    }
    Arrays.sort(A);   
   
    System.out.println(""+A[9]+"\n"+A[8]+"\n"+A[7]); 
    
    }
    }

Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

// warshall_floyd
// dは隣接行列(long long intを使うこと)
void warshall_floyd(vector<vector<long long int>>& d) {
    long long int n = d.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (d[i][k] == LLONG_MAX || d[k][j] == LLONG_MAX) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

//ただの辺
struct edge {
    using lint = long long int;
    int from;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int f, int t, lint c = 1) : from(f), to(t), cost(c) {
    }
    edge() {
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<lint>> d(n, vector<lint>(n, LLONG_MAX));
    vector<edge> e(m, edge());
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = c;
        d[b][a] = c;
        e[i] = edge(a, b, c);
    }
    for (int i = 0; i < n; i++) {
        d[i][i] = 0;
    }

    warshall_floyd(d);
    int ans = 0;
    for (int i = 0; i < m; i++) {
        int from = e[i].from, to = e[i].to;
        if (d[from][to] != e[i].cost) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N, K; cin >> N >> K; 
	long long mod = 1000000007; 
	long long B[1010][1010] = {}; 
	B[0][0] = 1; 
	for(int i = 0; i < 1005; i++){
		for(int j = 0; j <= i; j++){
			B[i+1][j] += B[i][j];
			B[i+1][j+1] += B[i][j];
			if(B[i+1][j] >= mod) B[i+1][j] -= mod;
			if(B[i+1][j+1] >= mod) B[i+1][j+1] -= mod;
		}
	}
	long long dp[21][1010] = {}; // dp[i日目まで終えて][スペシャルクッキーをj個配布済]
	dp[0][0] = 1; 
	int A[21] = {}; 
	for(int i = 1; i <= K; i++) cin >> A[i]; 
	for(int i = 1; i <= K; i++){
		for(int j = 0; j <= N; j++){
			if(dp[i-1][j] == 0) continue; 
			for(int k = j; k <= min(N, j + A[i]); k++){
				long long tmp = B[N-j][k-j] * B[N-k+j][A[i]-k+j] % mod; 
				tmp *= dp[i-1][j]; tmp %= mod;
				dp[i][k] += tmp; 
				if(dp[i][k] >= mod) dp[i][k] -= mod; 
			}
		}
	}
	cout << dp[K][N] << "\n"; 
}

Measured memory_bytes: 11792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N ; i++) {
            x[i] = scan.nextInt();
            y[i] = scan.nextInt();
        }
        long ans = 0;
        long max = Long.MIN_VALUE;
        long min = Long.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            max = Math.max(max, func0(x[i],y[i]));
            min = Math.min(min, func0(x[i],y[i]));
        }
        ans = max - min;
        max = Long.MIN_VALUE;
        min = Long.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            max = Math.max(max, func1(x[i],y[i]));
            min = Math.min(min, func1(x[i],y[i]));
        }
        ans = Math.max(ans, max - min);
        System.out.println(ans);
    }
    private int func0(int x, int y) {
        return x - y;
    }
    private int func1(int x, int y) {
        return x + y;
    }
}


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

int main() {
	int k;
	cin >> k;
	vector<int> a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	cout << a[k - 1] << endl;
}

Measured memory_bytes: 256