akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ff(i,n) for(i=0;i<n;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg=998244353;
ll power(ll x,ll y)
{
	ll ss=1;
	if(y==0)
	return ss;
	ll h=(power(x,y/2))%bg;
	h=(h*h)%bg;
	ll gg=(x*h)%bg;
	if(y%2==1)
	 return gg;
	else
	 return h;
}
ll modinv(ll k)
{
	return (power(k,bg-2))%bg;
}
int main()
{
    ll i,n,m,flag=-1;
	cin>>n>>m;
	ll arr[n];
	ff(i,n)  arr[i]=-1;
	for(i=0;i<m;i++)
	{
	    ll a,b;	
	    cin>>a>>b;
	    if(arr[a-1]!=-1 && b!=arr[a-1])
	      {
	           flag=0;	  
		  }
		arr[a-1]=b;
	}
	if(flag==0)
	{
		cout<<"-1";
		return 0;
	}
	if(n==1 && arr[0]==-1)
	{
		cout<<"0";
		return 0;
	}
	ff(i,n)
	{
		if(i==0)
		{
			if( arr[i]==0 && n!=1)
			{
				cout<<"-1";
				return 0;
			}
			else if(arr[i]==-1)
			  cout<<"1";
			else
			  cout<<arr[i];     
		}
		else
		{
	    if(arr[i]==-1)
		   cout<<"0";
		else
		   cout<<arr[i];
	    }
	} 			   
    return 0;
}

Measured memory_bytes: 256
n = 10**5 + 3
primes = set(range(3, n+1, 2))

for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes.add(2)
primes = list(primes)
primes.sort()

x = int(input())

primes = [y for y in primes if y >= x]

print(primes[0])

Measured memory_bytes: 14884
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
import networkx as nx
def resolve():
    m, n = map(int, input().split())
    # source = -1, row = 0, ..., m - 1, col = m, ..., m + n - 1, terminartion = m + n
    G = nx.Graph()
    G.add_nodes_from(range(m + n + 2))
    for i in range(m):
        for j, c in enumerate(input()):
            if c == '.':
                continue
            elif c == 'o':
                G.add_edge(i, m + j, capacity = 1)
            elif c == 'S':
                G.add_edge(-1, i, capacity = INF)
                G.add_edge(-1, m + j, capacity = INF)
            elif c == 'T':
                G.add_edge(i, m + n, capacity = INF)
                G.add_edge(m + j, m + n, capacity = INF)

    ans = nx.algorithms.flow.maximum_flow_value(G, -1, m + n)
    if ans >= INF:
        ans = -1
    print(ans)
resolve()

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


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
        String N = scan.next();
        String M[]=new String [6];

        for(int i=0;i<6;i++)
        { M[i]=N.substring(i,i+1);}
        if(M[2].equals(M[3])&&M[4].equals(M[5])){System.out.println("Yes");}
       else{System.out.println("No");}
//入力完了


/*
        for (int iii = 0; iii < (1 << N); iii++) {
                int PP=0;
                int S[] = new int[M];
                for (int j = 0; j < N; j++) {

                    if ((1 & iii >> j) == 1) {
                        for(int y=0;y<M;y++){S[y]=S[y]+A[j][y];}
                        PP=PP+C[j];
                    }

                }
                int K=0;
             for(int p=0;p<M;p++) {if(S[p]>=X){K=K+1;}  }
             if (K==M&&(P==-1||P>=PP)){P=PP;}
            }
*/

    }

}



Measured memory_bytes: 22868
#include<cstdio>
#include<iostream>
using namespace std;
int s[21],w[11],k[11];
int main()
{
	int i,j,n,m,l;
	for(i=1;i<=20;i++)cin>>s[i];
	for(i=1;i<=10;i++)
	{
		for(j=1;j<=10-i;j++)
		{
			if(s[j]<s[j+1])
			{
				l=s[j];
				s[j]=s[j+1];
				s[j+1]=l;
			}
		}
		for(j=11;j<=20-i;j++)
		{
			if(s[j]<s[j+1])
			{
				l=s[j];
				s[j]=s[j+1];
				s[j+1]=l;
			}
		}
	}
	n=s[1]+s[2]+s[3];
	m=s[11]+s[12]+s[13];
	cout<<n<<" "<<m<<endl;
	return 0;
}

Measured memory_bytes: 3076
//
// Created by 李青坪 on 2018/12/14.
//

#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

#define MAXN 100
#define MAXW 10000
#define NIL -1
using namespace std;

struct Good {
    int v;
    int w;

    Good(int v, int w) : v(v), w(w) {}
};

int n, m;
vector<Good> goods;
int c[MAXN + 1][MAXW + 1];

int knapsack() {
    for (int i = 0; i <= n; ++i) {
        fill(c[i], c[i] + m + 1, 0);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (j - goods[i].w >= 0) {
                if (c[i - 1][j - goods[i].w] + goods[i].v > c[i - 1][j]) {
                    c[i][j] = c[i-1][j - goods[i].w] + goods[i].v;
                } else {
                    c[i][j] = c[i-1][j];
                }
            } else {
                c[i][j] = c[i - 1][j];
            }
        }

    }
    return c[n][m];
}

int main() {
    scanf("%d %d", &n, &m);
    int x, y;
    goods.push_back(Good(0, 0));
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &x, &y);
        goods.push_back(Good(x, y));
    }
    printf("%d\n", knapsack());
}


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

MOD = int(1e9 + 7)  # 998244353
INF = int(8e18)

in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]


def main():

    N = in_n()
    p = list(in_nn())
    p = [x - 1 for x in p]

    A = [i * 20000 + 1 for i in range(N)]
    B = [-1] * N

    B[p[0]] = 1
    now = A[p[0]] + B[p[0]]

    for i in range(1, N):
        ind = p[i]
        B[ind] = now + 1 - A[ind]
        now += 1

    if min(B) <= 0:
        p = abs(min(B)) + 1
        for i in range(N):
            B[i] += p

    print(*A)
    print(*B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 71496
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 C = sc.nextInt();
        
        if (A + B == C || A+C == B|| B+C == A) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int n;cin>>n;
  vec d(n);
  rep(i,n)cin>>d[i];
  sort(d.begin(),d.end());
  
  cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 640
K = int(input())

lunlun = set()

def dfs(A):
    # 終端条件 --- 10 重ループまで回したら処理して打ち切り
    if len(A) == 10:
        return
    for v in range(0, 10):
        if len(A) != 0:
            if abs(A[-1] - v) > 1:
                continue
        A.append(v)
        lunlun.add(int(''.join(list(map(str, A)))))
        dfs(A)
        A.pop() # これが結構ポイント

dfs([])

print(sorted(list(lunlun))[K])

Measured memory_bytes: 73048
import math

def main():

    R = input_int()

    print(R * 2 * math.pi)


def input_int():
    return int(input())


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


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


Measured memory_bytes: 62084
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    vector<int> cnt(13);
    cnt[0] = 1;
    while (n--) {
        int x;
        cin >> x;
        ++cnt[x];
    }
    if (cnt[0] >= 2 || cnt[12] >= 2) {
        cout << 0 << '\n';
        return 0;
    }
    forn(i, 0, 13) if (cnt[i] > 2) {
        cout << 0 << '\n';
        return 0;
    }
    int ans = 0;
    forn(m, 0, 1 << 24) {
        if (m % 2 == 0) continue;
        vector<int> _cnt(13);
        forn(i, 0, 24) {
            if (m & (1 << i))
                ++_cnt[min(i, 24 - i)];
        }
        bool ok = cnt == _cnt;
        if (ok) {
            int s = INF;
            int i = 0;
            while (i < 24 && !(m & (1 << i))) ++i;
            int pr = i;
            int st = i;
            while (i < 24) {
                do {
                    ++i;
                } while (i < 24 && !(m & (1 << i)));
                setmin(s, i - pr);
                pr = i;
            }
            if (24 + st - pr != 0)
                setmin(s, 24 + st - pr);
            //if (s == 12) cout << m << ' ';
            setmax(ans, s);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <cstdio>

int n;
int A[21];

constexpr int mod = 1000000007;

int dp[1<<21];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int x;
      scanf("%d", &x);
      if(x) A[i] |= 1 << j;
    }
  }

  dp[0] = 1;
  for(int x = 0; x < (1<<n); x++){
    if(dp[x] == 0) continue;
    int i = __builtin_popcount(x);
    for(int y = ~x & A[i]; y; y &= y-1){
      int j = y & -y;
      dp[x + j] += dp[x];
      if(dp[x + j] >= mod) dp[x + j] -= mod;
    }
  }
  printf("%d\n", dp[(1<<n)-1]);
  return 0;
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a%b!=0)
	{
		cout<<(a/b+1)*c;
	}
	else
	{
		cout<<(a/b)*c;
	}
}


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

int main() {
  long long N,H,D;
  cin >> N >> H >> D;
  vector<long long> dp(H,0);
  vector<long long> totdp(H,0);
  long long ii = 1;
  long long ic;
  long long iii = 0;
  for (int i=1; i<N+1; i++) {
    ic = i;
    ii *= ic;
    ii %= 1000000007;
    iii += ii;
    iii %= 1000000007;
  }
  dp[0] = ii;
  totdp[0] = ii;
  
  cerr << ii << endl;
  for (int i=1; i<H; i++) {
      
    dp[i] = totdp[i-1];
    if (i > D) {
      dp[i] += 1000000007;
      dp[i] -= totdp[i-D-1];
    }
    dp[i] %= 1000000007;
    dp[i] *= iii;
    dp[i] %= 1000000007;
    totdp[i] = totdp[i-1] + dp[i];
    totdp[i] %= 1000000007;
    cerr << dp[i] << endl;
  }
  
  long long ans = totdp[H-1];
  ans += 1000000007;
  if (H > D) {
    ans -= totdp[H-D-1];
  }
  ans %= 1000000007;
  cout << ans << endl;
    
  cerr << iii;
  
  return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <math.h>
#include <string>
#include <string.h> 
#include <cstdio>
using namespace std;
#define MAX 200000

int main(){
    int n,k,l[50],sum=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",&l[i]);
    
    for(int i=0;i<k;i++){
        for(int j=n-1;j>0;j--){
            if(l[j]>l[j-1])swap(l[j],l[j-1]);
        }
    }
    for(int i=0;i<k;i++){
        sum+=l[i];
    }
    printf("\n%d\n",sum);
    return 0;
}

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

int main(){
    ll N,K; cin >> N >> K;
    vector <int> P(N);
    rep(i,N) cin >> P[i];
    double mx=0;
    double s=0;
    queue<double> Q;
    rep(i,N){
        s+=(1.0+P[i])/2.0;
        Q.push((1+P[i])/2.0);
        if (Q.size()>K){
            s-=Q.front(); Q.pop();
        }
        if (Q.size()==K){
            mx=max(mx,s);
        }
    }
    printf("%.10f\n",mx);
    return 0;
}

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


int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll K; cin >> K;
	vector<vector<pll>> G(K);
	for (int i = 1;i < K;i++) {
		G[i].push_back({ (i+1)%K,1 });
		G[i].push_back({ (i * 10) % K,0 });
	}
	for (int i = 0; i < K;i++) {
		sort(G[i].begin(), G[i].end());
		G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
	}
	vector<ll> dist(K, INF);
	queue<ll> q; q.push(1);
	dist[1] = 0;
	while (!q.empty()) {
		ll n = q.front(); q.pop();
		for (auto e : G[n]) {
			if (dist[e.first] > dist[n] + e.second) {
				dist[e.first] = dist[n] + e.second;
				q.push(e.first);
			}
		}
	}
	cout << dist[0] + 1 << endl;
	return 0;
}

Measured memory_bytes: 8320
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
//int dp[100010]={0};//dp[i]:=i番目までで0がいくつ連続してあるか
int main(){
	int n;

	while(1){
        scanf("%d",&n);
		//int a[100010]={0};
		if(n==0)break;
		vector<pii> x(0);
		for(int i =1;i <=n;i++){
			int a;
			scanf("%d",&a);
			if(i%2){
				if(x.empty()||a!=x[x.size()-1].first){
					x.push_back(mp(a,1));
				}else{
					x[x.size()-1].second++;
				}
			}else{
				if(x[x.size()-1].first==a){
					x[x.size()-1].second++;
				}else{
					int v =x[x.size()-1].second;
					x.pop_back();
					if(!x.empty()){
						x[x.size()-1].second+=(v+1);
					}else{
						x.push_back(mp(a,v+1));
					}
				}
			}
		}
		int ans = 0;
		for(int i =0;i <x.size();i++){
			if(x[i].first==0){
				ans +=x[i].second;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1188
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
  		int t=0;
  if(x==2){
 	 System.out.println(x);
  }else{
  
   for(int x1=x;x1>0;x1++){
     for(int c=2;c<x1;c++){
         if(x1%c==0){
           t=0;
           break;
          }else{
           t++;
         }
    	 }
     if(t>0){
        System.out.println(x1);
           return;
     } 
   }

  }
    }
}

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

int main()
{
    string s; cin >> s;
    int k; cin >> k;
    int n = s.length();

    set<string> st;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= 5 && i + j <= n; j++) {
            st.insert(s.substr(i, j));
        }
    }
    auto iter = st.begin();
    for (int i = 1; i < k; i++) iter++;
    cout << *iter << endl;
    return 0;
}

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

void program(); 
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    program();
}

#define INF 0x7fffffffffffffff
#define UINF 0xffffffffffffffff
#define MOD 1000000007

#define int long long
#define unsigned unsigned long long
#define double long double

#define endl "\n"

int pow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

class UF{
public:
    int n;
    vector<int> par, sz;
    UF(int size) : n(size), par(size), sz(size){
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }
    void join(int x, int y){
        if ((x = find(x)) == (y = find(y))) return;
        if (sz[y] < sz[x]) std::swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        sz[x] = 0;
    }
    int find(int x){ return par[x] = (x == par[x] ? x : find(par[x])); }
    bool connected(int x, int y){ return find(x) == find(y); }
};

template<class Iter> void _print_range(ostream& o, Iter s, Iter e){
    for(;s != e;s++) o << *s << " ";
    o << endl;
} 
template<class T> std::ostream& operator<<(ostream& o, const std::vector<T> &ds)
{
    _print_range(o,ds.begin(),ds.end()); 
    return o;
}
template<class T> std::ostream& operator<<(ostream& o, const std::set<T> &ds)
{
    _print_range(o,ds.begin(),ds.end()); 
    return o;
}
template<class T, class U> std::ostream& operator<<(ostream& o, const std::pair<T,U> &ds)
{
    o << "<" << ds.first << "," << ds.second << ">" << endl;
    return o;
}
template<typename ...Args>
void print(Args&&... args) {
    for(auto&& x: {args...})
        cout << x << " ";
    cout << endl;
}

#define debug(x) cout << "DEBUG    " <<  #x << ": " << x << endl;

#define fr(i, a, b) for(int i = a; i != (b); i += (a<b ? 1 : -1))
#define rep(i, a) for(int i = 0; i < (a); i++)

#define trav(x, a) for(auto& x : a)
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define vi vector<int>
#define si set<int>
#define pii pair<int,int>

#define N 100005
int a[N+1],dp[N+1];
void program(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    a[0]=a[1];
    dp[0]=dp[1]=0;
    for(int i=1;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout << dp[n] << endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-bruteforce?
-reduce dimensionality with problem contraints?
*/


Measured memory_bytes: 1792
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	ll n, m;
	cin >> n >> m;

	ll max = -1;
	for (ll b = 1; b * b <= m; b++) {
		if (m % b == 0) {
			if (n * b <= m) max = std::max(max, b);
			if ((m / b) * n <= m) max = std::max(max, m / b);
		}
	}

	cout << max NL;

	return 0;

}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
using namespace std;
#define int long long
#define inf   1000000009
#define minf -1000000009
int a[10];
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];

	int b = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] & 1)b *= 1;
		else b *= 2;
	}

	cout << pow(3, n) - b << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin>>s;

  int ans = 1;
  for(int i=0;i<(int)s.size() - 1;i++) if(s[i] == s[i+1]) ans = 0;

  cout<<(ans? "Good":"Bad")<<endl;
  
  return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int A, B, C; cin >> A >> B >> C;
	if((A+B) >= C) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 256
#include <iostream>
    using namespace std;
 
    int main()
    {
        
   char op;
  int b ,a, x; 
   
   cin >> a >> op >> b ;
   if ( op == '+'){
x = a + b;
cout << x;
}
  else  if ( op == '-'){
x = a - b;
cout << x;
}
        return 0;
    }

Measured memory_bytes: 256
'use strict'

const main = (it) => {
  const a = parseInt(it.next().value);
  const b = parseInt(it.next().value);
  const c = parseInt(it.next().value);
  const abc = [a, b, c];
  abc.sort();
  console.log(abc[2] * 10 + abc[0] + abc[1]);
}

function* read() {
  const input = require('fs').readFileSync('/dev/stdin', 'utf8');
  for (const token of input.trim().split(/\s+/)) {
    yield token;
  }
}

main(read());

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

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			for(int k = 1;k <= n;k++){
		       		ans += __gcd(__gcd(i,j),k);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void)
{
	int H, W,i,j;
	
	while(1){
		scanf("%d %d",&H, &W);
		
		if (H == 0 && W == 0)break;
		
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(i == 0 || i == H - 1)
					printf("#");
				else if(j == 0 || j == W - 1)
					printf("#");
				else 
					printf(".");
			}
				printf("\n");
		}
	printf("\n");
	}

	
	return 0;
}







Measured memory_bytes: 2048
A, B, N = map(int, input().split())
from math import floor
from math import gcd
from math import ceil
k = gcd(A, B)

As = A // k
Bs = B // k

Q = min(N, B-1)
R = ceil(Bs / As)
res = []
for b in range(Q, Q - R, -1):
    res.append(round(floor(b*As/Bs) - A*floor(b/B)))

print(max(res))

Measured memory_bytes: 106304
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(3)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#ifdef WindCry1
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#endif
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ll a[1010],b[1010];
ll dp[40010];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
#endif
	int h,n;cin>>h>>n;
	memset(dp,0x3f,sizeof dp);
	dp[0]=0;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++){
		for(int j=a[i];j<=40000;j++){
			dp[j]=min(dp[j],dp[j-a[i]]+b[i]); 
		}
	}
	ll res=INF; 
	for(int i=h;i<=40000;i++){
		if(dp[i]!=INF){
			res=min(res,dp[i]);
		}
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 640
/*
 
dunjen_master
 
*/
 
 

 
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

inline ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}

  

 
#define all(x) (x).begin(),(x).end()

/* ordered_set A;
   A.insert(x);
   A.erase(x);
   A.order_of_key(x) // no of elements less than (<) x
   *A.find_by_order(k-1) // kth smallest element
*/



double pie=acos(-1);


int main(){
 

  
 ll n,k;
 cin>>n>>k;
 ll ans=0;

 for(ll i=k;i<=n+1;i++){
   ll mini=(i-1)*(i)/2;
   ll maxi=n*(n+1)/2 - (n-i)*(n-i+1)/2;
 //  cout<<i<<" "<<maxi<<" "<<mini<<"\n";
   ans=add(ans,add(maxi-mini,1));
 }

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


   

    


    


    
    
    
    
 
    


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    vll vec(3);
    REP(i, 3) {
        cin >> vec.at(i);
    }
    sort(ALL(vec));
    cout << vec.back() - vec.front() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int a,b,c,d,t=0;
    cin >> a >> b>> c>> d;
    for(int i=0;i<=100;i++){
        if(i>=a && i<b && i>=c && i<d){
            t++;
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m,d;
	cin>>n>>m>>d;
	vp in(n*m);
	rep(i,n)rep(j,m){
		int a;cin>>a;
		in[a-1]={i,j};
	}
	vi dp(n*m);
	loop(i,d,n*m)
		dp[i]+=dp[i-d]+abs(in[i].first-in[i-d].first)+abs(in[i].second-in[i-d].second);
//	rep(i,dp.size())cout<<" "<<dp[i];cout<<endl;
	int q;cin>>q;
	while(q--){
		int a,b;cin>>a>>b;
		a--,b--;
		cout<<dp[b]-dp[a]<<endl;
	}
}






Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
    char ch[20];
    int i;
    scanf("%[^\n]",ch);
    for(i=0;ch[i]!='\0';i++)
    {
        if(ch[i]==',')
        {
            ch[i]=' ';
        }
    }
    puts(ch);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main(){
    int a,b;
    cin >> a >> b;
    int aa,bb;
    int flag=0;
    for(int i=a;i<=2000;i++){
        aa=i*0.08;
        bb=i*0.1;
        if(aa==a&&bb==b)
        {
            flag=1;
            cout << i;
            break;
        }
    }
       if(flag==0)
            cout << -1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long K, long long A, long long B){
  long long ret = 1;
  if (B-A > 2) {
    ret += min(K, A-1);
    K -= A-1;
    if (K < 0) {
      std::cout << ret << std::endl;
      return;
    }
    ret += (B-A)*(K/2);
    ret += K%2;
    std::cout << ret << std::endl;
    return;
  } else {
    std::cout << 1 + K << std::endl;
    return;
  }
}

int main(){
  long long B;
  long long K;
  long long A;
  scanf("%lld",&K);
  scanf("%lld",&A);
  scanf("%lld",&B);
  solve(K, A, B);
  return 0;
}


Measured memory_bytes: 888
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const ll MOD = TEN(9) + 7;
int n;

int main() {
    fastio();

    cin >> n;

    map<int, int> cnt;

    for (int i = 2; i <= n; i++) {
        int temp = i;
        for (int j = 2; j * j <= i; j++) {
            while (temp % j == 0) {
                temp /= j;
                cnt[j]++;
            }
        }
        cnt[temp]++;
    }

    ll ans = 1;
    for (auto p : cnt) {
        if (p.fst == 1) continue;
        ans = ans * (p.snd + 1) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
const double PI=3.14159265358979323846;
int main(){
    int r;
    cin>>r;
    printf("%.5lf\n",2*r*PI);
    return 0;
}


Measured memory_bytes: 3764
S = input()
T = input()

def check():
    n = len(S)
    dic1,dic2 = {},{}
    for i in range(n):
        if T[i] not in dic1:
            dic1[T[i]] = S[i]
        elif dic1[T[i]] != S[i]:
            return 'No'
        if S[i] not in dic2:
            dic2[S[i]] = T[i]
        elif dic2[S[i]] != T[i]:
            return 'No'
    return 'Yes'
print(check())

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(true){
        int n,asscore=0,bsscore=0;
        cin >> n;
        if(n == 0){break;}
        vector<int> ascard(n);
        vector<int> bscard(n);
        for(int i = 0; i < n ; ++i){
            cin >> ascard.at(i) >>bscard.at(i);
            if(ascard.at(i) > bscard.at(i)){
                asscore = asscore + ascard.at(i) + bscard.at(i);
            }
            if(ascard.at(i) == bscard.at(i)){
                asscore = asscore + ascard.at(i);
                bsscore = bsscore + bscard.at(i);
            }
            if(ascard.at(i) < bscard.at(i)){
                bsscore = bsscore + ascard.at(i) + bscard.at(i);
            }
        }
        cout << asscore << " " << bsscore << endl;
    }
}


Measured memory_bytes: 3200
import Data.List

solve :: [Int] -> Int
solve xs = minimum $ map (\i -> step xs i) [0..100]
    where
        step xs i = sum $ map (\x -> (i-x)^2) xs


main = do
    n <- readLn :: IO Int
    xs <- map read . words <$> getLine :: IO [Int]
    print $ solve xs

Measured memory_bytes: 1020
#include<stdio.h>

int main(void){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  while(1){
    if( (c=c-b) <= 0 ){
       printf("Yes");
      return 0;
    }
    else if( (a=a-d) <=0){
      printf("No");
      return 0;
    }
  }
}


Measured memory_bytes: 1692
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		for (int i = 0; i < NUM; i++) {
			nums[i] = scan.nextInt();
		}

		// check
		Arrays.sort(nums);
		int answer = nums[NUM / 2] - nums[NUM / 2 - 1];

		// answer
		System.out.println(answer);

	}
}


Measured memory_bytes: 51804
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AIZU {
	class Program {
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		#endregion
		
		static void Main(string[] args) {
			int[] I = cins();
			long x = I[0], a = I[1], b = I[2];
			print(x+a<b?"dangerous":(a>=b?"delicious":"safe"));
		}
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int HM[958623],*END=HM+958621;

bool insert(int a){
    int *p=HM+a%958621;
    while(*p){
        if(*p==a) return true;
        if(++p==END) p=HM;
    }
    *p=a;
    return false;
}

int main(){
    int n{},a,c;
    while((c=getchar_unlocked()-'0')>=0) n*=10,n+=c;
    fr(i,n){
        a=0;
        while((c=getchar_unlocked()-'0')>=0) a*=10,a+=c;
        if(insert(a)){
            putchar_unlocked('N');
            putchar_unlocked('O');
            putchar_unlocked('\n');
            return 0;
        }
    }
    putchar_unlocked('Y');
    putchar_unlocked('E');
    putchar_unlocked('S');
    putchar_unlocked('\n');
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
using std::vector;

// 辺の集合
using Graph = vector<vector<int>>;

vector<bool> visited(200'005);  // '
vector<long> node(20'005);      // '

void dfs(const Graph &g, int s = 1, long sum = 0L) {
    visited.at(s) = true;
    node.at(s) += sum;
    for (const int &next : g.at(s)) {
        if (visited.at(next)) continue;
        dfs(g, next, node.at(s));
    }
    return;
};

int main() {
    using std::cin;
    using std::cout;
    using std::endl;

    int n, q;
    cin >> n >> q;

    Graph tree(n + 1UL);
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        tree.at(a).push_back(b);
        tree.at(b).push_back(a);
    }

    node.assign(n + 2UL, 0L);
    for (int i = 0; i < q; ++i) {
        long p, x;
        cin >> p >> x;
        node.at(p) += x;
    }

    visited.assign(n + 2UL, false);
    dfs(tree);
    for (int i = 1; i <= n; ++i) {
        cout << node.at(i) << (i == n ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 27360
#include<iostream>
#include<string>


using namespace std;


int main()
{
  string S;
  cin >> S;


  for(int i = 0; i < 3; i++){
    if(S[i] == S[i+1]){
      cout << "Bad" << endl;

      return 0;
    }
  }

  cout << "Good" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long long comb(long long n, long long r){
  static long long c[50][50]={};
  if(r==0 || r==n) return c[n][r] = 1;
  if(r==1 || r==n-1) return c[n][r] = n;
  if(c[n][r] != 0) return c[n][r];
  if(c[n][n-r] != 0) return c[n][r] = c[n][n-r];

  return c[n][r] = comb(n-1, r) + comb(n-1, r-1);
}

int main()
{
  long long i, a, b, ans=0;
  int n, p, t;
  char s[100];

  scanf(" %d %d", &n, &p);

  a=b=0;
  for(i=0; i<n; i++){
    scanf(" %d", &t);
    t%2 ? a++ : b++;
    //printf("[%d (%lld,%lld)] ", t, a, b);
  }

  if(p){
    for(i=1; i<=a; i+=2){
      ans += comb(a, i);
      //printf("comb(%lld,%lld):%lld ", a, i, comb(a, i));
    }
  }else{
    for(i=0; i<=a; i+=2){
      ans += comb(a, i);
      //printf("comb(%lld,%lld):%lld ", a, i, comb(a, i));
    }
  }
  //printf("ans: %lld (%lld, %lld) ", ans, a, b);
  ans *= (long long)1<<b;
  sprintf(s, "%lld", ans);
  puts(s);
  return 0;
}


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

int a[3010][3010];
ll dp[3010][3010][4];

int main(){
  int R,C,K;
  cin>>R>>C>>K;
  rep(i,K){
    int r,c,v; cin>>r>>c>>v;
    a[r-1][c-1]=v;
  }
  for(int i=0; i<R; ++i){
    for(int j=0; j<C; ++j){
      for(int k=2; k>=0; --k){
        dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+a[i][j]);
      }
      rep(k,4){
        dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
        dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
      }
    }
  }
  ll ans=0;
  rep(i,4)ans=max(ans,dp[R-1][C-1][i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 321104
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,L = na()

ans = 10**9
before = 0
t =0
for i in range(N):
    before += L+i
    if ans > abs(L+i):
        ans = min(ans,abs(L+i))
        t = L+i

print(before - t)

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

typedef long long ll;

const int Maxn = 3005;

int n, mod;
int C[Maxn][Maxn];
int pw2[Maxn], all[Maxn];
int dp[Maxn][Maxn];
int cnt[Maxn];
int my[Maxn];
int res;

int main()
{
	scanf("%d %d", &n, &mod);
	for (int i = 0; i <= n; i++) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
	pw2[0] = 1 % mod;
	all[0] = 2 % mod;
	for (int i = 1; i <= n; i++) {
		pw2[i] = ll(pw2[i - 1]) * 2 % mod;
		all[i] = ll(all[i - 1]) * all[i - 1] % mod;
	}
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= i; j++) if (dp[i][j]) {
			dp[i + 1][j] = (dp[i + 1][j] + ll(dp[i][j]) * (j + 1)) % mod;
			dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
		}
	for (int i = n; i >= 0; i--) {
		int tot = 0;
		int cur = 1;
		for (int j = 0; j <= i; j++) {
			tot = (tot + ll(dp[i][j]) * cur) % mod;
			cur = ll(cur) * pw2[n - i] % mod;
		}
		tot = ll(tot) * all[n - i] % mod * C[n][i] % mod;
		if (i % 2 == 0) res = (res + tot) % mod;
		else res = (res - tot + mod) % mod;
	}
	printf("%d\n", res);
	return 0;
}

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

int INF=0x3f3f3f3f;
//memset(a,0x3f,sizeof(a));


int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	int ans=0;
	for(int i=1;i<s.size()-1;i++){
		int cnt=0;
		if(s[i]==s[0]){
			for(int j=0,k=i;j<i&&k<s.size()-1;j++,k++){
				if(s[j]==s[k]) cnt++;
				else break;
			}
		}
		if(cnt==i) ans=max(ans,2*i);
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {

	int a, b, c, d, e, f;

	cin >> a >> b >> c;

	e = 0;

	for (d = 0; d <= b - 1; d++) {

		e = a*d;

		if (c == e%b) {

			cout << "YES" << endl;

		return 0;

		}

	}

	cout << "NO" << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, K;
    scanf("%lld %lld", &N, &K);
    vector<ll> H(N);
    REP(int,i,0,N){
        scanf("%lld", &H.at(i));
    }
    sort(H.begin(),H.end(),greater<ll>());
    ll ans = 0;
    REP(int,i,0,N){
        if ( K > 0 ){
            K--;
        }
        else ans += H.at(i);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int cnt = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] == a[i + 1])
            continue;
        if (a[i] < a[i + 1])
        {
            cnt++;
        }
        else
        {
            break;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import math
A, B, H, M = list(map(int, input().split()))
h_theta = H / 12 * 2.0 * math.pi + M / 60 / 12 * 2.0 * math.pi
m_theta = M / 60 * 2.0 * math.pi
theta = abs(h_theta - m_theta)
L = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
print(L)

Measured memory_bytes: 62348
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
  public static void Main(){
    var n = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
    Console.WriteLine(((n[1]/n[2])-(n[0]%n[2]==0?n[0]/n[2]-1:n[0]/n[2])).ToString());
  }
}


Measured memory_bytes: 13140
n=int(input())
d=dict()
for _ in range(n):
    s=input()
    if s in d:
        d[s]+=1
    else:
        d[s]=1
keys=d.keys()
values=d.values()
m=max(values)
ans=[]
for k,v in zip(keys,values):
    if v==m:
        ans.append(k)
ans.sort()
for a in ans:
    print(a)

Measured memory_bytes: 32096
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n):
  b.append(a[i]-(i+1))

# print(b)
b.sort()
# print(b)

min_b=b[n//2]
# print(min_b)

ans = 0
for i in range(n):
  ans+=abs(a[i]-(min_b+(i+1)))
  # print(ans)
print(ans)

Measured memory_bytes: 25196
#include<stdio.h>
int main(void){
	int n;
	while(1){
		int i,s=0,squareroot;
		scanf("%d",&n);
		if(n==0)break;
		
		for(i=1;;i++){
			if(i*i<=n&&n<(i+1)*(i+1)){
				squareroot=i;
				break;
			}
			
		}
		for(i=1;i<=squareroot;i++){
			if(n%i==0){
				s+=n/i;
				s+=i;
				if(i==n/i)s-=i;
			}
			
			
			
			
		}
		s-=n;
		
		if(n==s)printf("perfect number\n");
		else if(n>s)printf("deficient number\n");
		else printf("abundant number\n");
		
	}
	return 0;
}

Measured memory_bytes: 1012
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=3010;
int n,A[N],sg[N];
vector<int>G[N];
void dfs(int u,int ff)
{
	for(int v:G[u])
		if(v!=ff&&A[v]<A[u])dfs(v,u),sg[u]|=sg[v]^1;
}
int main()
{
	n=gi();
	for(int i=1;i<=n;i++)A[i]=gi();
	for(int i=1;i<n;i++)
	{
		int u=gi(),v=gi();
		G[u].push_back(v);G[v].push_back(u);
	}
	for(int i=1;i<=n;i++){dfs(i,i);if(sg[i])printf("%d ",i);}
	puts("");
	return 0;
}

Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

int main()
{

	ll i, j, k, l, m, flag, N, M,K,H,W,X,P;
  	ll prime[1100001]={};
	bool is_prime[1100001];
	ll primecc[1100001] = {};
	for (i = 0; i <= 1100000; i++) {
		is_prime[i] = true;
	}
	int p = 0;
	is_prime[0] = is_prime[1] = false;
	for (i = 2; i <= 1100000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (j = 2 * i; j <= 1100000; j += i) {
				is_prime[j] = false;
			}
		}
	}
	
	cin >> N >> P;
  if(N==1){
  output(P);
    return 0;
  }
	k = 0;
	ll temp;
	for (i = 0; prime[i] * prime[i] <= P; i++) {
		temp = P;
		while (P%prime[i] == 0) {
			P /= prime[i];
			primecc[i]++;
		}
		P = temp;
	}
	ll ans = 1;
	for (i = 0; i <= 1000000; i++) {
		if (primecc[i] >= N) {
			ans *= (ll)pow(prime[i], primecc[i] / N);

		}
	}

	output(ans);
	

	return 0;
}



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

int main(){
  int n;
  int num;
  string symbol;
  int cards[4][13];
  cin >> n;

  //?????????
  for(int i=0; i<4; i++){
    for(int j=0; j<13; j++){
      cards[i][j] = 0;
    }
  }

  //??¢?´¢
  for(int i=0; i<n; i++){
    cin >> symbol >> num;
    if(symbol == "S"){
      cards[0][num-1] = 1;
    }else if(symbol == "H"){
      cards[1][num-1] = 1;
    }else if(symbol == "C"){
      cards[2][num-1] = 1;
    }else if(symbol == "D"){
      cards[3][num-1] = 1;
    }
  }

  //?¶??????????????????????
  for(int i=0; i<4; i++){
    for(int j=0; j<13; j++){
      if(cards[i][j] == 0){
          if(i == 0){
            cout << "S" << " " << j+1 << endl;
          }else if(i == 1){
            cout << "H" << " " << j+1 << endl;
          }else if(i == 2){
            cout << "C" << " " << j+1 << endl;
          }else if(i == 3){
            cout << "D" << " " << j+1 << endl;
          }
      }
    }
  }


}

Measured memory_bytes: 3104