akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<functional>
#include<queue>
#define F1 first.first
#define F2 first.second
#define F3 second.first
#define F4 second.second
#define MM 2000000000
using namespace std;
typedef pair<int,int> P1;
typedef pair<P1,P1> P2;
P2 p[6000];
int st[102];
int leng[101],flg[101];
int main(void)
{
	int n,m,a,b,co,ti,i,j,pp,q,r,x,p1,p2,le,xx,n2,k;
	P1 ppp;
	while(1)	{
		scanf("%d %d",&n,&m);
		if(n==0 && m==0)	break;
		priority_queue<P1,vector<P1>,greater<P1> >qu;	
		for(i=0;i<n;i++)	{
			scanf("%d %d %d %d",&a,&b,&co,&ti);
			p[i].F1=a;	p[i].F2=b;	p[i].F3=co;	p[i].F4=ti;
			p[i+n].F1=b; p[i+n].F2=a; p[i+n].F3=co; p[i+n].F4=ti;
		}
		n2=n*2;
		sort(p,p+n2);
//		for(i=0;i<n2;i++)	printf("i=%d %d %d %d %d\n",i,p[i].F1,p[i].F2,p[i].F3,p[i].F4);
		for(i=1;i<=m;i++)	st[i]=-1;
		for(i=0;i<n2;i++)	{
			if(st[p[i].F1]==-1)	 st[p[i].F1]=i;
		}
		st[m+1]=n2;
		scanf("%d",&k);
		for(i=0;i<k;i++)	{
			scanf("%d %d %d",&p1,&q,&r);
			for(j=1;j<=m;j++)	{
				leng[j]=MM;	flg[j]=0;
			}
			leng[p1]=0;	qu.push(P1(leng[p1],p1));
			while(1)	{
				while(1)	{
					ppp=qu.top();	qu.pop();
					x=ppp.second;	xx=ppp.first;
					if(flg[x]==0)	break;
				}
				flg[x]=1;
				if(x==q)	break;
				for(j=st[x];j<st[x+1];j++)	{
					if(flg[p[j].F2]==0)	{
						if(r==0)	co=p[j].F3;
						else co=p[j].F4;
						qu.push(P1(xx+co,p[j].F2));
					}
				}
			}
			printf("%d\n",xx);
			while(qu.size())	qu.pop();
		}
	}
	return 0;
}


Measured memory_bytes: 2728
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int a;
    cin>>a;cout<<(a*800-((a/15)*200))<<endl;
}

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

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int rom[200];

int main() {
	int tmp,res;
	string str;
	rom['I']=1;
	rom['V']=5;
	rom['X']=10;
	rom['L']=50;
	rom['C']=100;
	rom['D']=500;
	rom['M']=1000;
	for(;cin>>str;){
		int i;
		tmp=res=0;
		for(i=0;i<str.size();i++){
			int nw;
			nw=rom[str[i]];
			if(tmp<nw)res-=tmp*2;
			res+=nw;
			tmp=nw;
		}
		cout<<res<<endl;
	}
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    rep(i, s.size()) {
        if (s[i] == '1') s[i] = '9';
        else s[i] = '1';
    }
    cout << s << endl;
}



Measured memory_bytes: 256
n = int(input())
cnt = 0
flag = False
for i in range(n):
  d = list(map(int, input().split()))
  if d[0] == d[1]:
    cnt += 1
    if cnt == 3:
      flag = True
  else:
    cnt = 0
if flag == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX 
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll modexp(ll x,ll n,ll p){    //modular exponential function
  if(n==0){return 1;}
  ll u = modexp(x,n/2,p);
  u = u*u%p;
  if(n%2==1){u=(u*x)%p;}
  return u;
}

ll gcd (ll a, ll b) {     //Eulers algorithm
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

ll arr[3001];
ll dp[3001][3001];

ll f(ll i,ll j){
  if(i+1==j){return max(arr[i],arr[j]);}
  if(i==j){return arr[i];}
  if(dp[i][j]!=-1){return dp[i][j];}
  ll ans = max(arr[i]+min(f(i+2,j),f(i+1,j-1)),arr[j]+min(f(i+1,j-1),f(i,j-2)));
  dp[i][j] = ans;
  return ans;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    ll n; cin>>n; ll sum=0;
    rep(i,0,n-1){cin>>arr[i]; sum+=arr[i];}
    ll x = f(0,n-1);
    ll y = sum-x;
    cout<<(x-y);
}


Measured memory_bytes: 74108
import qualified Data.ByteString.Lazy.Char8 as B
import Data.ByteString.Lazy.Char8 (ByteString)
import Control.Monad.Trans.State.Strict
import Control.Applicative (many)
import Data.Char (isSpace)

main :: IO ()
main = B.interact $ output . solve . input

output :: Int -> ByteString
output = B.pack . show

solve :: [Int] -> Int
solve = sum . map pred

input :: ByteString -> [Int]
input = maybe (error "parse error") fst . runStateT (parseInt *> many parseInt)

parseInt :: StateT ByteString Maybe Int
parseInt = StateT $ B.readInt . B.dropWhile isSpace


Measured memory_bytes: 1148
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> P;
static const int INF=1<<24;

int a[60][60][60][60]={0};
int m[60][60];
int b[5][3];
int c[5][3];
int main(){
	b[0][0]=1; b[0][1]=0;
	b[1][0]=0; b[1][1]=-1;
	b[2][0]=-1; b[2][1]=0;
	b[3][0]=0; b[3][1]=1;
	c[0][0]=-1; c[0][1]=0;
	c[1][0]=0; c[1][1]=1;
	c[2][0]=1; c[2][1]=0;
	c[3][0]=0; c[3][1]=-1;
	queue<pair<P,P> > qu;
	pair<P,P> tmp;
	int X,Y;
	while(cin>>X>>Y,X){
		//cout<<X<<" "<<Y<<endl;
		//3 4 5 2
		//3 3 5 3
		//4 3 4 3
		memset(a,0,sizeof(a));
		rep(i,60){
			rep(j,60){
				m[i][j]=1;
			}
		}
		
		while(!qu.empty()) qu.pop();
		P ta,ka;
		//cout<<"hoge"<<endl;
		cin>>ta.F>>ta.S>>ka.F>>ka.S;
		rep(i,Y){
			rep(j,X){
				cin>>m[j+1][i+1];
			}
		}
		/*
		rep(i,Y+2){
			rep(j,X+2){
				cout<<m[j][i]<<" ";
			}
			cout<<endl;
		}
		*/
		a[ta.F][ta.S][ka.F][ka.S]=1;
		tmp.F=ta;
		tmp.S=ka;
		qu.push(tmp);
		bool f=true;
		int tt;
		rep(i,100){
			tt=qu.size();
			rep(h,tt){
				P tta=qu.front().F,kka=qu.front().S;
				//cout<<"tta "<<tta.F<<" "<<tta.S<<"  kka "<<kka.F<<" "<<kka.S<<endl;
				qu.pop();
				if(tta.F==kka.F&&tta.S==kka.S){
					cout<<i<<endl;
					f=false;
					break;
				}
				rep(j,4){
					if(m[tta.F+b[j][0]][tta.S+b[j][1]]==1){
						tmp.F=tta;
					}
					else{
						tmp.F.F=tta.F+b[j][0];
						tmp.F.S=tta.S+b[j][1];
					}
					
					if(m[kka.F+c[j][0]][kka.S+c[j][1]]==1){
						tmp.S=kka;
					}
					else{
						tmp.S.F=kka.F+c[j][0];
						tmp.S.S=kka.S+c[j][1];
					}
					if(a[tmp.F.F][tmp.F.S][tmp.S.F][tmp.S.S]==1){
						continue;
					}
					else{
						qu.push(tmp);
						//cout<<"j="<< j<<" "<<tmp.F.F<<" "<<tmp.F.S<<" "<<tmp.S.F<<" "<<tmp.S.S<<endl;
						a[tmp.F.F][tmp.F.S][tmp.S.F][tmp.S.S]=1;
					}
				}
				//cout<<endl;
			}
			if(!f) break;
		}
		if(f) cout<<"NA\n";
	}
	return 0;
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    ll mod = N % K;
    ll nmod = K - mod;
    ll ans = min(mod, nmod);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {

  int n;
  int p[20];
  int count = 0;
  int max = 0;

  cin >> n;

  for ( int i = 0; i < n; i++ ) cin >> p[i];

  for ( int i = 1; i < n-1; i++ ) {
    if ( p[i] < p[i-1] ) max++;
    if ( p[i] < p[i+1] ) max++;
    if ( max == 1 ) count++;
    max = 0;
  }

  cout << count << endl;

  return 0;

}


Measured memory_bytes: 256
N=input()
min_n=float("inf")
max_n=float("-inf")
a=[]
for i in range(N):
	l,r=map(int,raw_input().split())
	a.append((l,r))
	min_n=min(min_n,l)
	max_n=max(max_n,r)

prime=[i for i in range(0, max_n+1)]
prime[1]=0
p_len=len(prime)
for i in range(2,p_len):
	if prime[i]!=0:
		for j in range (i+i,p_len,i):
			prime[j]=0
#print prime

C=[0 for i in range(max_n+1)]
cnt=0
for i in range(max_n+1):
	if prime[i]!=0 and prime[(i+1)/2]!=0:
		cnt+=1
		C[i]=cnt
	else:
		C[i]=cnt

#print C


for i,j in a:
	print C[j]-C[i-1]

Measured memory_bytes: 24564
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
//#include<numerice>
using namespace std;
int main(){
    int N;
    int total=0;
    int  price_max=-10;
    cin>>N;
    for(int i=0;i<N;i++){
        int price;
        cin >>price;
        total+=price;
        price_max=max(price_max,price);
    }
    //cout<<total<<endl;
    //cout<<price_max<<endl;
    cout<<total-price_max+(price_max/2)<<endl;
    return 0;
}

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

int main() {
  long long n; cin >> n;
  
  if(n < 2 ) {
    cout << 0 << endl;
    return 0;
  }
  
  long long mod = 1000000007;
  
  long long ten = 10;
  long long eight = 8;
  long long nine = 9;
  for( int i = 1; i < n; i++) {
    ten = ten * 10 % mod;
  	eight = eight * 8 % mod;
  	nine = nine * 9 % mod;
  }
  nine = 2 * nine % mod;
  
  long long ans = ten - nine;
  if(ans > 0) ans %= mod;
  ans = (ans + eight) % mod;
  if(ans < 0) ans += mod;

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

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
int gcd(int x, int y) {
	if (y == 0)return x;
	else return gcd(y, x%y);
}
using namespace std;
ll a[114514];
signed main() {
	ll n;
	cin >> n;
	rep(i, n)cin >> a[i];
	ll cnt[114514];
	cnt[0] = gcd(a[0], a[1]);
	for (int i = 1; i < n - 1; i++) {
		cnt[i] = gcd(cnt[i - 1], a[i + 1]);
	}
	cout << cnt[n - 2] << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 1792
//=======================//
// coder: Andy - Tohrumi //
//=======================//

#include <bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)
#define int long long

typedef vector<int> vi;		typedef vector<ll> vl;
typedef pair<int, int> ii; 	typedef vector<ii> vii;

// code start here //

const int N = 200005;
ll dp[N], a[N];

signed main() {
	fastio;
	int n; cin >> n;
	rep(i, 1, n + 1) cin >> a[i];
	rep(i, 1, n + 1) dp[i] = dp[i - 1] + a[i];
	ll ans = LLONG_MAX, val[4];
	rep(i, 1, n + 1) {
		int l = 1, r = i, p1 = 1, p2;
        while (l <= r) {
            int x = (l + r) / 2;
            if(dp[x] * 2 <= dp[i]) {
                l = x + 1;
                p1 = x;
            }
			else {
                r = x - 1;
            }
        }
        
        l = i + 1, r = n, p2 = i + 1;
        while (l <= r) {
            int x = (l + r) / 2;
            if ((dp[x] - dp[i]) * 2 <= dp[n] - dp[i]) {
                l = x + 1;
                p2 = x;
            }
			else {
                r = x - 1;
            }
        }
        for (int j = p1 - 5; j <= p1 + 5; j++){
            for (int k = p2 - 5; k <= p2 + 5; k++){
				if (j <= i && i <= k) {
					val[0] = dp[j];
					val[1] = dp[i] - dp[j];
					val[2] = dp[k] - dp[i];
					val[3] = dp[n] - dp[k];
					ans = min(*max_element(val, val + 4) - *min_element(val, val + 4), ans);
				}
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 6676
#include <stdio.h>
#include <string.h>

const int MAX = 210000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long POW(int n, int x) {
	if (x == 0) return 1;
	if (x == 1) return n;
	if (n == 0) return 0;
	if (n == 1) return 1;
	if (x % 2 == 1) {
		return (POW(n, x - 1) * n) % MOD;
	}
	else {
		long long t = POW (n, x / 2);
		return (t * t) % MOD;
	}
}

int main()
{
	COMinit();

	int N, M, K;
	scanf("%d%d%d", &N, &M, &K);

	long long ans = 0;
	for (int i = 0; i <= K; i++) {
		long long n1k = COM(N - 1, i);
		long long x = M * POW(M - 1, N - i - 1) % MOD;
		ans += (n1k * x) % MOD;
		ans %= MOD;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 6648
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    if n>=30:
        print("Yes")
    else:
        print("No")
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

void rotate(int dice[], int seq[]);

int main() {
	int dice[6];
	char comm;

	int w_seq[5] = {1,3,6,4};
	int s_seq[5] = {1,5,6,2};
	int n_seq[5] = {1,2,6,5};
	int e_seq[5] = {1,4,6,3};

	
	for(int i=0; i<6; i++) dice[i] = 0;
	for(int i=0; i<6; i++) cin >> dice[i];

	while(cin >> comm) {
		switch(comm) {
			case 'E': rotate(dice, e_seq); break;
			case 'N': rotate(dice, n_seq); break;
			case 'S': rotate(dice, s_seq); break;
			case 'W': rotate(dice, w_seq); break;
			default: break;
		}
	}

	cout << dice[0] << endl;
	return 0;
}

void rotate(int dice[], int seq[]) {
	int temp=dice[seq[0]-1];
	for(int i=0; i<4; i++) {
		dice[seq[i]-1] = dice[seq[i+1]-1];
	}
	dice[seq[3]-1] = temp;
}


Measured memory_bytes: 3124
#include<cstdio>
#include<cstring>
#include<cctype>
#include<iostream>
using namespace std;

int main(){
    char ch;
    int cnt[26] = {};

    while( cin >> ch){
        ch = tolower(ch);
        if ( isalpha(ch) ){
            cnt[ch - 'a']++;

        }
    }

    for (int i = 0; i < 26; i++ ){
        printf("%c : %d\n", i+'a', cnt[i]);
    }


    return 0;
}

Measured memory_bytes: 3208
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int count = 0;
		int max = 0;
		for(int i = 0; i < num; i ++) {
			int crt = sc.nextInt();
			if(crt >= max) {
				count ++;
			}
			max = Math.max(max, crt);
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll v;cin>>v;vec.push_back(v);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
ll inv(ll a)
{
    ll p=mod2;
    ll b=p-2,ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll ncr(ll n,ll m)
{
    ll p=mod2;
    if(m > n)return 0;
    ll up=1,down=1;
    for(int i=n-m+1;i<n+1;i++)up*=i,up%=p;
    for(int i=1;i<m+1;i++)down*=i,down%=p;
    return up*inv(down)%p;
}

ll countDigit(ll n)
{   
    return floor(log10(n) + 1); 
}  
ll a_pow_b(ll a,ll b)
{
    ll p=1000000007;
    ll ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll gcd(ll a,ll b) 
{ 
    if (b==0) 
        return a; 
    return gcd(b,a%b);      
} 
ll lcm(ll a, ll b)  
{  
    return (a*b)/gcd(a, b);  
}
bool isPerfectSquare(ll x) 
{   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
}
ll ncr123(ll n, ll k){
    if (k == 1) {
        return n;
    }
    if (k == 2) {
        return n * (n - 1) / 2;
    }
    if (k == 3) {
        return n * (n - 1) * (n - 2) / 6;
    }
}
bool com(const pi &a,const pi &b)   //acc to second element sort for vec of pi
{ 
    if(a.second==b.second)
        return a.first<b.first;
    return a.second<b.second;
}



void solve(){

    ll k,a,b;
    cin>>k>>a>>b;

    for(ll i=1;i<=1000;i++){
        ll p=k*i;
        if(p>=a and p<=b){
            cout<<"OK"
            ; return;
        }
    }

    cout<<"NG";

    return ;
}
 
 
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll c[200010];

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll modinv(ll x, ll n){
    return modpow(x, n - 2);
}

int main(){
    int n;
    cin >> n;
    rep(i, n) {
        cin >> c[i];
    }
    ll ans = 0;
    sort(c, c+n);
    reverse(c, c+n);
    rep(i, n){
        ll tmp = 1;
        tmp *= c[i];
        tmp %= MOD;
        tmp *= (i+2);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }

    cout << (ans * modpow(4, n-1)) % MOD << endl;

    return 0;
}


Measured memory_bytes: 5196
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n;
    cin >> n;
    vector<ll> a(n);
    ll ans=0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for( ll i=n/2;i<n;i++){
        ans += a[i];
    }
    for(ll i=0;i<n/2-1;i++){
        ans+=a[n-2-i];
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 4812
#include<bits/stdc++.h> 
using namespace std; 
#define rep(i, n) for(int i = 0; i < (int)n; i++)
int main() {
  int n; 
  cin >> n; 
  vector<int> p(n);
  rep(i, n) cin >> p[i]; 
  int k = 0; 
  rep(i, n) if(p[i] != i + 1) k++; 
  if(k <= 2) cout << "YES" << endl; 
  else cout << "NO" << endl; 
  return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m[2],n[2];
int main(){
	scanf("%d%d%d%d",&m[0],&n[0],&m[1],&n[1]);
	if(m[0]!=m[1]) printf("1");
	else printf("0");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
ll sum=0;
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
       sum+=a[i]*a[j];
    }
}
cout<<sum<<endl;
}

Measured memory_bytes: 256
def main():
    n,t = map(int,input().split())
    tl = list(map(int,input().split()))
    res = t
    for i in range(1,n):
        res += t - max((tl[i-1]+t-tl[i]),0)
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 85456
M=998244353
n,m,k=map(int,input().split())
p,c=[m]*n,[1]*n
for i in range(1,n):
  p[i]=p[i-1]*(m-1)%M
  c[i]=c[i-1]*(n-i)*pow(i,M-2,M)%M
print(sum(p[n-i-1]*c[i]%M for i in range(k+1))%M)

Measured memory_bytes: 24452
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long gcd(long long a,long long b){
    return b==0?a:gcd(b,a%b);
}
int main(){
	cin>>n>>m;
	cout<<n*m/gcd(n,m);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	string X;
	for (int i = 0; i < s.size(); i++) {
		if (X == "") {
			if (s[i] == '0')
				X += '0';
			else if (s[i] == '1')
				X += '1';
		}
		else {
			if (s[i] == '0')
				X += '0';
			else if (s[i] == '1')
				X += '1';
			else if (s[i] == 'B') {
				X.erase(X.size() - 1);
			}
		}
	}
	cout << X << endl;
	return 0;
}

Measured memory_bytes: 256
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();

    System.out.println(Math.max(c - (a - b), 0));
  }
}


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

vector<int> cond(8,-1), ans(8);

bool valid(int pos){
    bool ret = true;
    for(int i = 0; i < pos; i++){
        ret &= ans[i] != ans[pos];
        ret &= abs(ans[pos]-ans[i]) != pos-i;
    }
    return ret;
}

void dfs(int pos){
    if(pos == 8){
        for(int i = 0; i < 8; i++){
            if(cond[i] != -1 && cond[i] != ans[i])  return;
        }
        // found!
        for(int i = 0; i < 8; i++){
            for(int j = 0; j < 8; j++){
                if(ans[i] == j)    cout << "Q";
                else               cout << ".";
            }
            cout << endl;
        }
        exit(0);
    }
    for(int j = 0; j < 8; j++){
        ans[pos] = j;
        if(!valid(pos))  continue;
        dfs(pos+1);
    }
}

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        int i, j;
        cin >> i >> j;
        cond[i] = j;
    }
    dfs(0);
    return 0;
}


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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

int n, q;
vector<vector<int>> graph;
vector<ll>sums;
vector<ll>mem;

ll sum(int i){
  if(sums[i]!=-1)return sums[i];
  ll ans=0;
  for(auto&&e:graph[i]){
    ans += sum(e);
  }
  sums[i] = ans + mem[i];
  return sums[i];
}

int main(){
  cin >> n >> q;
  graph.resize(n);
  sums.resize(n,-1);
  for(int i = 0; i < n-1; ++i){
    int a,b;cin >> a >> b;a--;b--;
    graph[b].push_back(a);
  }
  mem.resize(n,0);
  for(int i = 0; i < q; ++i){
    int p, x;cin >> p >> x;p--;
    mem[p]+=x;
  }

  for(int i = 0; i < n; ++i){
    if(i)cout << ' '; 
    cout << sum(i);
  }
  cout << endl;
			      
  return 0;
}


Measured memory_bytes: 16512
# -*- coding: utf-8 -*-
n=int(input())
alist=list(map(int,input().split()))
blist=sorted(alist,reverse=True)
total=blist[0]
for i in range(1,int(n/2)):
  total+=blist[i]*2
if n%2:
  total+=blist[int(n/2)]
print(total)

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  int sum = 0;
  int inf = 0;
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];
  rep(i, n) {
    sum += v[i] - c[i];
    if(sum > inf) inf = sum;
    else sum -= v[i] - c[i];
  }
  cout << inf << endl;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
stack<char>s;
string a;
int main(){
	cin>>a;
	int n=a.size();
	for(int i=0;i<n;i++){
		s.push(a[i]);
	}
	long long ans=1;
	for(int i=0;i<n;i++){
		char top=s.top();
		if(top=='b')
			top='d';
		else
			if(top=='d')
				top='b';
		else
			if(top=='p')
				top='q';
		else
			if(top=='q')
				top='p';
		if(top==a[i]){
			ans=1;
			s.pop();
		}
		else{
			ans=0;
			break;
		}
	}
	if(ans==0)
		printf("No");
	else
		printf("Yes");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define IS_DEBUG true

#define DEBUG_OUTPUT(X) if (IS_DEBUG) cout << X << endl
#define RESULT_OUTPUT(X) cout << X << endl

int main()
{
  long a, b, x;
  cin >> a >> b >> x;
  
  long x1 = a / x;
  if (a % x == 0)
    x1--;
  long x2 = b / x;
  RESULT_OUTPUT(x2 - x1);

    

	if (IS_DEBUG)
	{
		int end;
		cin >> end;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
//POJ 1979 DFS
public class Main{
	static int N;
	static int W;
	static int w[];
	static int v[];
	static int dp[][];
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		W = scan.nextInt();
		dp=new int[N+1][10001];
		w=new int[N+1];
		v=new int[N+1];
		for(int i=0;i<N;i++){
			v[i]=scan.nextInt();
        	w[i]=scan.nextInt();
        }
        System.out.println(rec(0,W));
	}
	
	public static int rec(int item,int weight) {
		if(dp[item][weight]>0) {
			return dp[item][weight];
		}
		int res;
		if(item==N) {
			res = 0;
			//weightは残りの重さ
		}else if(weight<w[item]) {
			res = rec(item+1, weight);
		}else {
			res = Math.max(rec(item+1, weight),rec(item+1, weight-w[item])+v[item]);
		}
		return dp[item][weight]=res;
	}
}


Measured memory_bytes: 31700
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main(void){
  int n,k;cin>>n>>k;
  ll ans=0;
  rep(i,n){
    int h;cin>>h;
    if(h>=k)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long gcd(long long a,long long b){
	return b?gcd(b,a%b):a;
}
int main(void){
	long long  a,b;
	while(scanf("%lld",&a)==1&&scanf("%lld",&b)==1){
		long long temp=gcd(a,b);
		printf("%lld %lld\n",temp,a/temp*b);
	}
	return 0;
}

Measured memory_bytes: 2680
h, w = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(h).map{Array.new(w,0)}
kara = Array.new(w+2," ")
arr = []
arr << kara
h.times do |i|
    s = gets.chomp.split("")
    s.unshift(" ")
    s << " "
    arr << s
end
arr << kara
y = 1
x = 1
ka = []
until y == h + 1 && x == w + 1
    x = 1
    kazu = []
    until x == w + 1
        count = 0
        if arr[y][x] == "."
            if arr[y-1][x-1] == "#"
                count += 1
            end
            if arr[y-1][x] == "#"
                count += 1
            end
            if arr[y-1][x+1] == "#"
                count += 1
            end
            if arr[y][x-1] == "#"
                count += 1
            end
            if arr[y][x+1] == "#"
                count += 1
            end
            if arr[y+1][x-1] == "#"
                count += 1
            end
            if arr[y+1][x] == "#"
                count += 1
            end
            if arr[y+1][x+1] == "#"
                count += 1
            end
            kazu << count
        elsif arr[y][x] == "#"
            kazu << "#"
        end
        x += 1
    end
    ka << kazu
    y += 1
end
ka.each do |i|
    puts i.join("")
end

Measured memory_bytes: 14516
#include<cstdio>
using namespace std;
typedef long long int ll;

ll K, A, B;

int main(){
	scanf("%lld %lld %lld", &K, &A, &B);
	if(B - A <= 2 || K <= A) printf("%lld\n", K + 1);
	else printf("%lld\n", (K + 1 - A) / 2 * (B - A) + A + (K + 1 - A) % 2);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  int BY[]={0,0,1,1,0,0,1,1,2,2,3,3};
  int BX[]={2,3,2,3,0,1,0,1,0,1,0,1};
  int w,h,x[10010],y[10010],gx,gy,by,bx,n,ny,nx,i,j,c,t,r,sc,d;
  while(scanf("%d %d",&w,&h),w||h){
    int m[110][110]={0};
    scanf("%d %d %d %d %d",&x[0],&y[0],&gx,&gy,&n);
    while(n--){
      scanf("%d %d %d %d",&c,&d,&bx,&by);
      for(i=0;i<8;i++)m[by+BY[d*4+i]][bx+BX[d*4+i]]=c;
    }
    /*for(i=0;i<h;i++){
      for(j=0;j<w;j++)printf("%d ",m[i][j]);
      printf("\n");
      }//*/
    sc=m[y[0]][x[t=0]];
    m[y[0]][x[0]]=0;
    if(sc==0){
      printf("NG\n");
      continue;
    }
    for(r=1;r-t;t++){
      for(i=0;i<4;i++){
	ny=y[t]+Y[i];
	nx=x[t]+X[i];
	if(m[ny][nx]-sc)continue;
	m[ny][nx]=6;
	y[r  ]=ny;
	x[r++]=nx;
      }
    }
    if(m[gy][gx]-6)printf("NG\n");
    else           printf("OK\n");
  }
  return 0;
}

Measured memory_bytes: 648
def resolve():
    n, m = map(int, input().split())
    a = list(input() for _ in range(n))
    b = list(input() for _ in range(m))
    if n == m:
        if a == b:
            print('Yes')
        else:
            print('No')
        exit()
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            part = [ai[j:j + m] for ai in a[i:i + m]]
            if part == b:
                print("Yes")
                exit()
    print("No")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int sx, sy, tx, ty;

void solve() {
    if (tx > sx) {
        REP(i, tx - sx) putchar('R');
        if (ty > sy) {
            REP(i, ty - sy) putchar('U');
            REP(i, tx - sx) putchar('L');
            REP(i, ty - sy)putchar('D');
            putchar('L');
            REP(i, ty - sy + 1) putchar('U');
            REP(i, tx - sx + 1) putchar('R');
            putchar('D');
            putchar('R');
            REP(i, ty - sy + 1) putchar('D');
            REP(i, tx - sx + 1) putchar('L');
            putchar('U');
        } else {
            REP(i, sy - ty) putchar('D');
            REP(i, tx - sx) putchar('L');
            REP(i, sy - ty)putchar('U');
            putchar('L');
            REP(i, sy - ty + 1) putchar('D');
            REP(i, tx - sx + 1) putchar('R');
            putchar('U');
            putchar('R');
            REP(i, sy - ty + 1) putchar('U');
            REP(i, tx - sx + 1) putchar('L');
            putchar('D');
        }
    } else {
        REP(i, sx - tx) putchar('L');
        if (ty > sy) {
            REP(i, ty - sy) putchar('U');
            REP(i, sx - tx) putchar('R');
            REP(i, ty - sy)putchar('D');
            putchar('R');
            REP(i, ty - sy + 1) putchar('U');
            REP(i, sx - tx + 1) putchar('L');
            putchar('D');
            putchar('L');
            REP(i, ty - sy + 1) putchar('D');
            REP(i, sx - tx + 1) putchar('R');
            putchar('U');
        } else {
            REP(i, sy - ty) putchar('D');
            REP(i, sx - tx) putchar('R');
            REP(i, sy - ty)putchar('U');
            putchar('R');
            REP(i, sy - ty + 1) putchar('D');
            REP(i, sx - tx + 1) putchar('L');
            putchar('U');
            putchar('L');
            REP(i, sy - ty + 1) putchar('U');
            REP(i, sx - tx + 1) putchar('R');
            putchar('D');
        }
    }
}

int main() {
    cin >> sx >> sy >> tx >> ty;
    solve();
    return 0;
}

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

typedef long long ll;
using namespace std;


int main() {
    int N, M; cin >> N >> M;
    vector<ll> X(M, 0);
    vector<ll> sub(M, 0);
    for (int i = 0; i < M; i++) { cin >> X[i]; }
    sort(begin(X), end(X));

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i < M; i++) {
        sub[i] = abs(X[i] - X[i-1]);
    }
    sort(begin(sub), end(sub));
    ll sum = 0;
    for (int i = 1; i < M - N + 1; i++) {
        sum += sub[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
/*
  Contest 107
  B - Grid Compression
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

inline void print(const std::vector<std::string>& grid, const std::vector<bool>& cols) {
    for (std::size_t r = 0; r < grid.size(); ++r) {
        for (std::size_t c = 0; c < grid[r].size(); ++c)
            if (cols[c])
                std::cout << grid[r][c];
        std::cout << std::endl;
    }
}

inline void check_cols(const std::vector<std::string>& grid, std::vector<bool>& cols) {
    for (std::size_t c = 0; c < grid[0].size(); ++c) {
        for (std::size_t r = 0; r < grid.size(); ++r)
            if (grid[r][c] == '#')
                cols[c] = true;
    }
}

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

    int r = 0, c = 0;
    std::cin >> r >> c;
    std::cin.ignore();

    std::vector<std::string> grid;
    while (r--) {
        std::string s;
        std::getline(std::cin, s);
        if (s.find('#') != std::string::npos)
            grid.emplace_back(s);
    }
    std::vector<bool> cols(c, false);
    check_cols(grid, cols);
    print(grid, cols);

    return 0;
}


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

int main() {
    int N,M;
    cin>>N>>M;
    vector<ll> a[3];
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            ll num; cin>>num;
            a[j].push_back(num);
        }
    }
    ll res=0;
    for(int bit=0;bit<(1<<3);bit++){
        vector<ll> b;
        for(int i=0;i<N;i++){
            ll tmp=0;
            for(int j=0;j<3;j++){
                if(bit&(1<<j)) tmp+=a[j][i];
                else tmp-=a[j][i];
            }
            b.push_back(tmp);
        }
        sort(b.begin(),b.end(),greater<ll>());
        ll sum=0;
        for(int i=0;i<M;i++){
            sum+=b[i];
        }
        res=max(res,sum);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()
item_set = set()
ans = 0

for _ in range(N):
    S = input()
    if S in item_set: continue
    item_set.add(S)
    ans += 1

print(ans)

Measured memory_bytes: 31180
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int n,z=0,ans=0;
signed main(){
    cin>>n;
    int nn=n;
    while(nn>=1){
        nn/=10;
        z++;
    }
    int d=1;
    for(int i=0;i<z;i++){
        int x=(n/d)%10;
        ans+=x;
        d*=10;
    }
    if(ans==1)ans=10;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))

P_zero=[i for i in range(1,N+1)]
Q_zero=[j for j in range(1,N+1)]
a=0
b=0
for i in range(N):
    x=N-(i+1)
    fx=math.factorial(x)
    dp=P_zero.index(P[i])
    dq=Q_zero.index(Q[i])
    a+=dp*fx
    b+=dq*fx
    P_zero.remove(P[i])
    Q_zero.remove(Q[i])

if a>=b:
    print(a-b)
else:
    print(b-a)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int N;
	cin >> N;
	int a[N];
	for(int i=0; i<N; i++){
		cin >> a[i];
		a[i]--;
	}
	
	int temp=0;
	for(int i=1; i<=N*2; i++){
		temp=a[temp];
		
		if(temp==1){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

#define MAXPROCS 100000

typedef struct {
    char name[11];
    int time;
} proc;

int main(void)
{
    int i;

    int procs_n, quan;
    scanf("%d %d", &procs_n, &quan);

    proc queue[MAXPROCS];
    for (i = 0; i < procs_n; i++) {
        scanf(" %s %d", queue[i].name, &queue[i].time);
    }

    int timeline = 0;
    int head = 0, tail = procs_n;
    while (head != tail) {
        if (queue[head].time <= quan) {
            timeline += queue[head].time;
            printf("%s %d\n", queue[head].name, timeline);
            head = (head + 1) % MAXPROCS;
        } else {
            timeline += quan;
            queue[head].time -= quan;
            queue[tail] = queue[head];
            head = (head + 1) % MAXPROCS;
            tail = (tail + 1) % MAXPROCS;
        }
    }

    return 0;
}

Measured memory_bytes: 2160
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		String T = in.next();
		int index = S.length() - T.length() + 1;
		List<String> list = new ArrayList<>();
		for (int i = 0; i < index; i++) {
			StringBuilder sb = new StringBuilder(S);
			for (int j = 0; j < T.length(); j++) {
				if (i + j > sb.length()) {
					break;
				}
				if (sb.charAt(i + j) == '?' || sb.charAt(i + j) == T.charAt(j)) {
					sb.setCharAt(i + j, T.charAt(j));
				} else {
					break;
				}
				if (j == T.length() - 1) {
					for (int j2 = 0; j2 < sb.length(); j2++) {
						if (sb.charAt(j2) == '?') {
							sb.setCharAt(j2, 'a');
						}
					}
					list.add(sb.toString());
				}
			}
		}
		Collections.sort(list);
		System.out.println(list.size() > 0 ? list.get(0) : "UNRESTORABLE");
		in.close();
	}
}

Measured memory_bytes: 21844
_,*a=map(str.split,open(0))
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
for *z,u in a:d[u]+=[*map(int,z)],
N=9e9
P,M="x+y,","x-y,"
for A,B,S in(U,D,"x,y,"),(R,L,"y,x,"),(R,U,P+M),(D,L,P+M),(U,L,M+P),(R,D,M+P):
 n=p=-9e9
 for x,y,r in sorted(eval(f"[({S}Q)for P,Q in[(A,1),(B,0)]for x,y in d[P]]")):
  if x-n:
   if r:n,p=x,y
  elif r:p=y
  else:N=min(N,y-p)
print(["SAFE",N*5][N!=9e9])

Measured memory_bytes: 131280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0086
{
    public class Program

    {
        public static void Main(string[] args)
        {

            Dictionary<int, int> nodeOrder = new Dictionary<int, int>();
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                int[] items = Array.ConvertAll(line.Trim().Split(' '), e => int.Parse(e));
                if (items.Sum() != 0)
                {
                    foreach (var item in items)
                    {
                        if (!nodeOrder.ContainsKey(item)) nodeOrder.Add(item, 0);
                        nodeOrder[item]++;
                    }
                }
                else
                {
                    Console.WriteLine(nodeOrder.All(x => x.Key < 3 && x.Value % 2 == 1 || x.Key >= 3 && x.Value % 2 == 0)  ? "OK" : "NG");
                    nodeOrder = new Dictionary<int, int>();
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 18312
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int N;


class State
{

public:
	string item;
	int cost;

	State(string item, int cost):item(item),cost(cost){}

};

int main(void)
{
	while(cin >> N, N){

		vector<State> items;
		map<string, int> itemmap;
		map<string, vector<string> > itemR;

		string itemstr,itemstr2;
		string queryitem;
		int money;
		for(int i = 0; i < N; i++){
			cin >> itemstr >> money;
			State st(itemstr,money);
			items.push_back(st);
			itemmap[st.item] = st.cost;
		}
		cin >> N;

		int M;
		for(int i = 0; i < N; i++){
			cin >> itemstr;
			cin >> M;

			
			while(M > 0){
				cin >> itemstr2;
				itemR[itemstr].push_back(itemstr2);
				M--;
				
			}
				for(int j = 0; j < items.size(); j++){
					int sum = 1 << 28;
					int mcost = items[j].cost;

				//	printf("\n");
					if(itemR[items[j].item].size()){
						sum = 0;
						for(int k = 0; k < itemR[items[j].item].size();  k++){
							string No = itemR[items[j].item][k];
							sum += itemmap[No];
			//				cout << No << ' ';
						}
						items[j].cost = min(mcost, sum);
						itemmap[items[j].item] = min(mcost, sum);
					//	cout << items[j].item << ' ' << mcost << ' ' << sum << endl;
					
				}

			}
		}
		

		cin >> queryitem;

		int ans = itemmap[queryitem];


		cout << ans << endl;

	//	for(int i = 0; i < items.size(); i++){
	//		cout << items[i].item << items[i].cost << endl;;
	//	}




	}



	return 0;
}

Measured memory_bytes: 1240
#include<cstdio>

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

using namespace std;

typedef long long ll;

bool is_leap(int y){
	return y%400==0 || y%100!=0 && y%4==0;
}

int num_of_leap(int y){
	return y/4-y/100+y/400;
}

int main(){
	const int MON[13]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

	for(char s[32];scanf("%s",s),s[0]!='#';){
		int dot=0;
		for(int i=0;s[i];i++) if(s[i]=='.') dot++;

		if(dot==2){ // seireki -> maya
			ll y,m,d;
			sscanf(s,"%lld.%lld.%lld",&y,&m,&d);

			ll days=0;
			while(m>1 || d>1){
				if(d>1){
					d--;
				}
				else{
					m--;
					d=MON[m];
					if(m==2 && is_leap(y)) d++;
				}
				days++;
			}
			days+=365*y+num_of_leap(y-1);
			days-=365*2012+num_of_leap(2012);
			days-=354;

			int b,ka,t,w,ki;
			b=days/(20*20*18*20)%13;
			days%=20*20*18*20;
			ka=days/(20*18*20);
			days%=20*18*20;
			t=days/(18*20);
			days%=18*20;
			w=days/20;
			days%=20;
			ki=days;
			printf("%d.%d.%d.%d.%d\n",b,ka,t,w,ki);
		}
		else{ // maya -> seireki
			int b,ka,t,w,ki;
			sscanf(s,"%d.%d.%d.%d.%d",&b,&ka,&t,&w,&ki);

			ll days=0;
			days+=b*20*20*18*20;
			days+=ka*20*18*20;
			days+=t*18*20;
			days+=w*20;
			days+=ki;

			int y=2012,m=12,d=21;
			int days400=400*365+num_of_leap(400);
			y+=days/days400*400;
			days%=days400;
			while(days>0){
				if(d<MON[m]+(m==2&&is_leap(y)?1:0)){
					d++;
				}
				else if(m<12){
					m++;
					d=1;
				}
				else{
					y++;
					m=1;
					d=1;
				}
				days--;
			}
			printf("%d.%d.%d\n",y,m,d);
		}
	}

	return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;

const int MOD = 2019;

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

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

    vector<int> v(R-L+1, 0);
    for(int i = 0; i <= R-L;i++) {
        v[i] = (L+i) % MOD;
    }

    sort(v.begin(), v.end());
    int min_val = (v[0] * v[1]) % MOD;
    vector<vector<int>> matrix(R-L+1, vector<int>(R-L+1, 0));
    for(int i = 0; i <= R-L; i++) {
        for(int j = i+1; j <= R-L; j++) {
            matrix[i][j] = (v[i]*v[j])%MOD;
            //cout << min_val << "," << matrix[i][j] << endl;
            min_val = min(min_val, matrix[i][j]);
        }
    }

    cout << min_val << endl;

}

Measured memory_bytes: 16256
#include <stdio.h>
int n, m, a;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &a);
		n -= a;
	}
	if (n < 0)n = -1;
	printf("%d\n", n);
}

Measured memory_bytes: 1732