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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int lcs(string x, string y) {
  int c[1001][1001];
  int m = x.size(), n = y.size();
  int maxl = 0;
  x = ' ' + x, y = ' ' + y;
  for(int i = 0; i <= m; i++) c[i][0] = 0;
  for(int i = 1; i <= n; i++) c[0][i] = 0;

  for(int i = 1; i <= m; i++) {
    for(int j = 1; j <= n; j++) {
      if(x[i] == y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

signed main() {
	ll n;
  string s1, s2;

  cin >> n;
  rep(i, n) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
}


Measured memory_bytes: 11012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string S;
  cin >> S;
  int size = S.size() / 2;
  bool ans = true;
  for (int i = 0; i < size; i++) {
    if (S[i] != S[size - 1 - i]) ans = false;
    if (S[i + size + 1] != S[size + size - i]) ans = false;
  }
  string Srev = S;
  reverse(Srev.begin(),Srev.end());
  if (S != Srev) ans = false; 
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <algorithm>

using ll = long long int;

using P = std::pair<int, int>;

constexpr ll mod = 1e9 + 7;

ll inv(ll x)
{

    ll bit = 1;
    ll mm = mod - 2;
    ll res = 1;

    for (int i = 1; i <= 30; ++i)
    {

        if (mm & bit)
            res = res * x % mod;
        bit *= 2;
        x = x * x % mod;
    }

    return res;
}

ll pow(ll p, int m)
{

    return (m == 0) ? 1 : p * pow(p, m - 1) % mod;
}

constexpr int MAX = 1e4 + 10;

std::map<int, int> mp, mpc;

int a[MAX];

int main()
{

    int n;

    std::cin >> n;

    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i];

        mpc.clear();

        int x = a[i], p = 2;

        while (p * p <= x)
        {
            if (x % p)
            {
                ++p;
            }
            else
            {
                x /= p;
                ++mpc[p];
            }
        }

        if (x != 1)
            ++mpc[x];

        for (auto p : mpc)
            mp[p.first] = std::max(mp[p.first], p.second);
    }

    ll lcm = 1;

    for (auto p : mp)
        lcm = lcm * pow(p.first, p.second) % mod;

    //std::cerr << "DE" << lcm << std::endl;

    ll ans = 0;

    for (int i = 0; i < n; ++i)
    {
        ans = (ans + lcm * inv(a[i])) % mod;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define EB emplace_back
#define gcd std::__gcd

typedef std::vector <int> vector;
const int N = 2054, M = N * N;

int n, E = 0;
int a[N], to[M], first[N], next[M], deg[N];
bool used[N];
vector G[N];
std::priority_queue <int> pq;

inline void addedge(int u, int v) {to[++E] = v, next[E] = first[u], first[u] = E, ++deg[v];}
inline void dfs(int x) {used[x] = true; for (int y : G[x]) if (!used[y]) addedge(x, y), dfs(y);}

int main() {
	int i, j, x, y;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", a + i);
	std::sort(a + 1, a + (n + 1));
	for (i = 1; i < n; ++i)
		for (j = i + 1; j <= n; ++j)
			if (gcd(a[i], a[j]) > 1) G[i].EB(j), G[j].EB(i);
	for (i = 1; i <= n; ++i) if (!used[i]) dfs(i);
	for (i = 1; i <= n; ++i) if (!deg[i]) pq.emplace(i);
	for (i = 1; i <= n; ++i) {
		printf("%d%c", a[x = pq.top()], i == n ? 10 : 32), pq.pop();
		for (j = first[x]; j; j = next[j])
			if (!--deg[y = to[j]]) pq.emplace(y);
	}
	return 0;
}


Measured memory_bytes: 21224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[100][100]={ 0 },b[100][100]={ 0 },n,m,l,s=0;
  long long c[100][100] = { 0 };
  cin >> n >> m >> l;
  for(int i=0;i<n;i++){
    for(int k=0;k<m;k++){
      cin >> a[i][k];
    }
  }
  for(int k=0;k<m;k++){
    for(int j=0;j<l;j++){
      cin >> b[k][j];
    }
  }

  for(int i=0;i<n;i++){
      for(int j=0;j<l;j++){
          for(int k =0;k<m;k++){
              c[i][j] += a[i][k]*b[k][j];
          }
      }
  }
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            if (s == 1){
                cout << " ";
            }
            cout << c[i][j];
            s = 1;
        }
        cout << endl;
        s = 0;
    }
  return 0;
}



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

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


Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include <vector>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	string ans;
	if (s == "Sunny") ans = "Cloudy";
	else if (s == "Cloudy") ans = "Rainy";
	else ans = "Sunny";
	cout << ans << endl;
}

Measured memory_bytes: 256
import math
a, b, x = list(map(float, input().split()))
if x/a >= 0.5 * a * b:
    area = (a * b) - (x/a)
    c = 2 * area / a
    d = (a ** 2 + c ** 2) ** (1/2)
    angle = math.asin(c/d)
    angle = math.degrees(angle)
else:
    area = (x/a)
    c = 2 * area /b
    d = (b ** 2 + c ** 2) ** (1/2)
    angle_k = math.asin(c/d)
    angle_k = math.degrees(angle_k)
    angle = 90- angle_k
print(angle)

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

int main() {
    int N;
    string h, p, b;
    h = "hon";
    p = "pon";
    b = "bon";

    cin >> N;

    int first_num = N%10;

    if (first_num == 3){
        cout << b << endl;
    }

    else if (first_num == 0 or first_num == 1 or first_num == 6 or first_num == 8){
        cout << p << endl;
    }

    else{
        cout << h << endl;
    }
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
using namespace std;
   
#define MAX_PLAY 2
#define MAX_ROUNDS 10000
   
int rounds[MAX_ROUNDS][MAX_PLAY];
int total_a = 0, total_b = 0;
   
void cards(int i) {
    if(rounds[i][0] > rounds[i][1]) {
        total_a += (rounds[i][0] + rounds[i][1]);
    }
    else if (rounds[i][0] < rounds[i][1]) {
        total_b += (rounds[i][0] + rounds[i][1]);
    }
    else {
        total_a += rounds[i][0];
        total_b += rounds[i][1];
    }
}
  
void card_counter()
{
    int n;
    while(cin >> n) {
      if(n == 0) {
          break;
      }
      for(int i = 0; i < n; i++) {
          cin >> rounds[i][0] >> rounds[i][1];
      }
      for(int j = 0; j < n; j++) {
          cards(j);
      }
      cout << total_a << " " << total_b << endl;
      total_a = 0, total_b = 0;
    }
}
  
int main() {
card_counter();
return 0;
}


Measured memory_bytes: 3056
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();
        int mx=100000;
        int d[] = new int[mx+2];

        for(int i=0; i<n; i++) {
            int x=sc.nextInt();
            d[x+1]++;
            if(x-1>=0)d[x-1]++;
            d[x]++;
        }
        int ans=0;
        for(int i=0; i<=mx; i++) {
            ans=max(ans,d[i]);
        }
        out.println(ans);
        out.flush();
    }
    
    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P[i];

  int now_min = 1<<30;
  int ans = 0;
  rep(i, N){
    chmin(now_min, P[i]);

    if(P[i] <= now_min){
      ans++;
    }

  }

  cout << ans << endl;

  return 0;
}


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

long long F(long long A, long  long B){
    long long ta = A, tb = B;
    long long ca = 0, cb = 0;
    for(long long i = 0; i < 10; i++){
        if(ta != 0) ca++;
        if(tb != 0) cb++;
        ta /= 10;
        tb /= 10;
    }
    return ca > cb ? ca : cb;
}

int main() {
    long long  N;
    cin >> N;
    long long ans = 10;
    for(long long i = 1; i <= sqrt(N); i++){
        if(N % i == 0) {
            ans = min(ans, F(i, N/i));
        }
    }
    cout << ans << endl;
}







Measured memory_bytes: 3604
def warshall_floyd(G, n):
    global c
    for i in range(n):
        for j in range(n):
            b = 1
            for k in range(n):
                if j == k or i == k:
                    continue
                if G[i][j] == G[i][k] + G[k][j]:
                    b = 0
                elif G[i][j] > G[i][k] + G[k][j]:
                    print(-1)
                    exit()
            if b == 1:
                c += G[i][j]

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
c = 0
warshall_floyd(a, n)
print(c // 2)

Measured memory_bytes: 43228
#include<stdio.h>
int main(void)
{
int i,a[9999]={0};
for(i=0;i < 10000;i++){
scanf("%d",&a[i]);
if(a[i] == 0)return 0;
printf("Case %d: %d\n",i+1,a[i]);
}
return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500 + 10;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,1,-1};
int p[N*N],a[N][N],b[N][N];
bool upd(int i,int j){
    int x = 1e9;
    for(int k=0;k<4;k++) x = min(x,b[i+dx[k]][j+dy[k]]);
    if(a[i][j]) x++;
    if(b[i][j]==x) return false;
    b[i][j] = x; return true;
}
void print(int n){
    cout<<"-----"<<endl;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) cout<<a[i][j]<<' ';
        cout<<endl;
    }
    cout<<endl;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) cout<<b[i][j]<<' ';
        cout<<endl;
    }
}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<=n*n;i++) scanf("%d",&p[i]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int d = 1e9;
            d = min(d,min(i,n-i+1));
            d = min(d,min(j,n-j+1));
            a[i][j] = 1, b[i][j] = d;
        }
    }
//    print(n);
    int ans = 0;
    for(int i=1;i<=n*n;i++){
        int x = (p[i]-1)/n+1, y = (p[i]-1)%n+1;
//        cout<<x<<' '<<y<<endl;
        a[x][y] = 0;
        queue<pair<int,int> > q;
        upd(x,y), q.push({x,y});
        while(!q.empty()){
            int x = q.front().first, y = q.front().second;
            q.pop();
            for(int i=0;i<4;i++){
                int tx = x + dx[i], ty = y + dy[i];
                if(tx>=1&&tx<=n&&ty>=1&&ty<=n&&upd(tx,ty)) q.push({tx,ty});
            }
        }
//        print(n);
        ans += b[x][y];
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 6728
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007;

 
int main()
{
    io();
    li l,r,d;
    cin>>l>>r>>d;
    li i,c=0;
    for(i=l;i<=r;i++)
    {
    	if(i%d==0)c++;
    }cout<<c;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cmath>

using namespace std;

int a, b, c, cb, cnt = 0;

int main()
{
	cin >> a >> b;
	cb = b;
	while (cb > 0)
	{
		++cnt;
		cb /= 10;
	}
	cb = 1;
	for (int i = 1;i <= cnt;++i)
		cb *= 10;
	c = a * cb + b;
	int r = sqrt(c);
	if (r * r == c)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int count = 0;
        int[] tmp = new int[n];
        for (int i = n; i >= 1; i--) {
            int sum = 0;
            for (int j = i * 2; j <= n; j += i) {
                sum += tmp[j - 1];
            }
            
            if (array[i - 1] == 0) {
                if (sum % 2 == 1) {
                    tmp[i - 1]++;
                    count++;
                }
            } else {
                if (sum % 2 == 0) {
                    tmp[i - 1]++;
                    count++;
                }
            }
        }
        
        System.out.println(count);
        if (count == 0) return;
        for (int i = 0; i < n; i++) {
            if (tmp[i] % 2 == 0) continue; 
            System.out.print(i+1);
            if (i != n - 1) {
                System.out.print(" ");
            }
        }
        System.out.println();
    }
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl             '\n'
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr <<'}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int string_to_int(string s){
	int ans = 0;
	int p=1;
	for(int i=s.size()-1;i>=0;i--){
		ans += (s[i]-'0')*p;
		 p *= 10;
	}
	return ans;
}

void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int n,k; cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr,arr+n);
	int ans = 0;
	for(int i=0;i<n and k;i++){
		ans += arr[i];
		k--;
	}
	cout << ans << endl;

}

int32_t main()
{
	t_c_c();
	return 0;
}


Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int Remainder = 0;
		int ans=0;
		ans=(N/((2*D)+1));
		Remainder=(N%((2*D)+1));
		if(Remainder>=1){
		ans=ans+1;
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int i,j,k,p,ans;

int calc(){
  char c=s[p++];
  if('0'<=c&&c<='9')return (c-'0');
  else if(c=='P')return i;
  else if(c=='Q')return j;
  else if(c=='R')return k;
  else if(c=='-'){
    return 2-calc();
  }else if(c=='('){
    int a=calc();
    char ch=s[p++];
    int b=calc();
    p++;
    if(ch=='*')return min(a,b);
    else if(ch=='+')return max(a,b);
  }
  return 0;
}


void solve(){
  p=0;
  if(calc()==2)ans++;
}
int main(){
  while(1){
    cin>>s;
    if(s==".")break;
    ans=0;
    for(i=0;i<3;i++)
      for(j=0;j<3;j++)
	for(k=0;k<3;k++)
	  solve();
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n; cin >> n;
  vector<int> c(n, 0);
  rep(i, n-1){
    int a; cin >> a;
    a--;
    c[a]++;
  }
  rep(i, n){
    cout << c[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4052
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""

s = input()
cnt = 0
for i in range(3):
    if s[i]=='R':
        cnt += 1
if (s[1]=='S' and cnt != 0):
    print(1)
    exit()
else:
    print(cnt)


    

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

using namespace std;
typedef long long ll;

ll N;
ll a[3000];
ll dp[3001][3001];

ll taro(ll sp, ll ep);
ll jiro(ll sp, ll ep);

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j] = -1;
        }
    }
    ll p = taro(0,N);
    ll sum = 0;
    for(int i=0;i<N;i++) sum += a[i];
    ll q = sum - p;
    cout << p - q << endl; 
    return 0;
}

ll taro(ll sp, ll ep){
    if(dp[sp][ep] != -1) return dp[sp][ep];
    if(sp == ep-1) return dp[sp][ep] = a[sp];
    if(sp == ep-2) return dp[sp][ep] = max(a[sp],a[sp+1]);
    return dp[sp][ep] = max(jiro(sp+1,ep) + a[sp], jiro(sp,ep-1) + a[ep-1]);
}

ll jiro(ll sp, ll ep){
    if(dp[sp][ep] != -1) return dp[sp][ep];
    if(sp == ep-1) return dp[sp][ep] = 0;
    if(sp == ep-2) return dp[sp][ep] = min(a[sp],a[sp+1]);
    return dp[sp][ep] = min(taro(sp+1,ep), taro(sp,ep-1));
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string n;
  cin >> n;
  ll k=n.size();
  vl dp0(k),dp1(k);//dp0[i]はピッタリ、dp1[i]は余分に払う。
  /*高い位から順々に考えていく*/
  rep(i,k){
    ll d=n[i]-'0';
    if(i==0){
      dp0[i]=d;
      dp1[i]=9-d;
    }
    else{
      dp0[i]=min(dp0[i-1]+d,dp1[i-1]+d+2);
      dp1[i]=min(dp0[i-1]+9-d,dp1[i-1]+9-d);
    }
  }
  cout << min(dp0[k-1],dp1[k-1]+2) << endl;
}

Measured memory_bytes: 17028
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, a, res; 
  cin >> n >> t >> a;
  t *= 1000;
  a *= 1000;
  vector<int> vec(n);
  int ans = 10000000;
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    vec.at(i) = t - vec.at(i) * 6;
    if (abs(a - vec.at(i)) < ans) {
      ans = abs(a - vec.at(i));
      res = i + 1;
    }
  }
  cout << res << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	double W, H; cin >> W >> H;
	double x, y; cin >> x >> y;
	cout << setprecision(10) << (W * H) / 2 << " ";
	if (x == W/2 && y == H/2) cout << 1 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <algorithm>
#include <climits>
#include <cstring>
using namespace std;

int flip=0, h, w, mp[105][105];
char board[105][105];

bool inside(int r, int c){
    return r<=h && c<=w;
}
int dp(int r, int c){
    int sum =0;
    if(r==h && c==w){
        if(board[h][w]=='#'){
            sum=1;
        }
        return sum;
    }
    else if(mp[r][c]!=-1){
        return mp[r][c];
    }
    int result = INT_MAX;
    int dx[] ={0, 1};
    int dy[] ={1, 0};
    for(int i=0; i<2; i++){
        int nextRow = r + dx[i];
        int nextCol = c + dy[i];
        if(!inside(nextRow, nextCol))continue;
        else if(board[r][c]=='.')flip = dp(nextRow, nextCol);
        else if(board[r][c]=='#' && board[nextRow][nextCol]=='#')flip = dp(nextRow, nextCol);
        else if(board[r][c]=='#' && board[nextRow][nextCol]=='.')flip = dp(nextRow, nextCol) + 1;
        result = min(result, flip);
        mp[r][c]=result;
    }
    return result;
}

int main(){
memset(mp, -1, sizeof(mp));
    
    cin >> h >> w;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> board[i][j];
        }
    }
    
    cout << dp(1, 1) << endl;
    return 0;
}

Measured memory_bytes: 3664
// Cursor jump numbers
// main @ 39
// global @ 35
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

char upd(char t, int n) {
  int k = t - 'A';
  k += n;
  k %= 26;
  return k + 'A';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string inp;
  cin >> inp;
  for(auto i = inp.begin(); i!=inp.end(); i++) {
    *i = upd(*i, n);
  }
  cout << inp << '\n';
  return 0;
}



Measured memory_bytes: 256
use text_io::*;
use std::process::exit;

fn main(){
    let mut x:u128 = read!();
    let mut a:u128 = 100;
    for i in 1..100000000 {
        a = (a*101)/100;
        if a >= x {
            println!("{}",i);
            exit(0);
        }
    }
}

Measured memory_bytes: 2140
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
    ll n; cin >> n;
    ll ans = n * (n - 1) / 2;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

int main()
{
    char ch;
    scanf("%c",&ch);
    if(ch=='A')
        printf("T");
    else if(ch=='T')
        printf("A");
    else if(ch=='C')
        printf("G");
    else if(ch=='G')
        printf("C");
        else
            printf("Print the letter representing the base that bonds with the base %c",ch);
    return 0;
}

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

int n;
int m;
int x[110];
int a[110];

bool func(int key) {
	for (int i = 0; i < n; i++) {
		if (key + 1 == x[i]) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		a[i]--;

	}
	/*
	for (int i = 0; i < m; i++) {
		cout << a[i] << endl;
	}
	*/
	for (int i = 0; i < m; i++) {
		int key = a[i];
		if (x[key] + 1 <= 2019 && func(x[key])) {
			// cout << "a" << endl;
			x[key]++;
		}
	}

	for (int i = 0; i < n; i++) {
		cout << x[i] << endl;
	}
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
bool fun(vector<pii>& v, int n){
    for(int i = 0; i+2 < n; i++){
            if(v[i].ff == v[i].ss and v[i+1].ff == v[i+1].ss and v[i+2].ff == v[i+2].ss) return true;
    }
    return false;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in6.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T = 1;
    // cin >> T;
    
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int n; cin >> n;
        vector<pii> v;
        FOR1(i, n){
            int d1, d2;
            cin >> d1 >> d2;
            v.pb({d1, d2});
        }
        cout << (fun(v, n)? "Yes":"No");
        cout << '\n';
    }
    return 0;
}


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

namespace _0004
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                double[] x = s.Split().Select(double.Parse).ToArray();
                double a = (x[1] * x[5] - x[2] * x[4]) / (x[1] * x[3] - x[0] * x[4]);
                double b = (x[0] * x[5] - x[2] * x[3]) / (x[0] * x[4] - x[1] * x[3]);
                Console.Write(a.ToString("F3") + " ");
                Console.WriteLine(b.ToString("F3"));
            }
        }
    }
}


Measured memory_bytes: 9632
#include "bits/stdc++.h"
using namespace std;

int64_t mod = 1000000007;

int64_t ruijo(int64_t a, int64_t b)		// aのb乗(mod)を計算する。
{
	if (b == 1) {
		return  a % mod;
	} else if(b % 2 == 0){
		int64_t temp = ruijo(a, b / 2);
		return (temp * temp) % mod;
	} else {
		return (a * ruijo(a, b - 1)) % mod;
	}
}

int64_t warizan(int64_t bunshi, int64_t bunbo)	// (bunshi / bunbo)(mod)を計算する。
{
	return (bunshi * ruijo(bunbo, mod - 2)) % mod;
}

int64_t comb(int64_t n, int64_t r)		// nCr(mod)を計算する。
{
	int64_t bunshi = 1;
	int64_t bunbo = 1;

	for (int64_t i = n; i >= n - r + 1; i--) {
		bunshi *= i;
		bunshi %= mod;
	}
	for (int64_t i = r; i >= 1; i--) {
		bunbo *= i;
		bunbo %= mod;
	}

	return warizan(bunshi, bunbo);

}

int main()
{
	int64_t n, a, b;
	cin >> n >> a >> b;

	int64_t all = ruijo(2, n) - 1;
	int64_t comb_a = comb(n, a);
	int64_t comb_b = comb(n, b);

	int64_t ans = all - comb_a - comb_b;
	while (ans < 0) {
		ans += mod;
	}

	cout << ans << endl;
}


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

long long gcd(long long a,long long b){
  if(b == 0){
    return a;
  }
  
  return gcd(b, a % b);
}

int main() {
  
  int N,count = 0,l;
  cin >> N;
  
for(int i = 1;i <= N;i++){
  for(int j = 1;j <= N;j++){
    for(int k = 1;k <= N;k++){
      l = gcd(i,j);
      count += gcd(l,k);
    }
  }
}
  cout << count << endl;
  

}


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

int main() {
  bool flag=true;
  string s,sback={},sfront={};
  int q;
  cin >> s >> q;
  while(q--){
    int t;
    cin >> t;
    if(t==1){
      if(flag)flag=false;
      else flag=true;
    }
    else{
      int f;
      char c;
      cin >> f >> c;
      if(f==1){
        if(flag)sfront.push_back(c);
        else sback.push_back(c);
      }
      else{
        if(flag)sback.push_back(c);
        else sfront.push_back(c);
      }
    }
  }
  reverse(sfront.begin(),sfront.end());
  s=sfront+s+sback;
  if(flag)cout<<s<<endl;
  else {
    r(i,s.size())cout<<s[s.size()-1-i];
    cout<<endl;
  }
}

Measured memory_bytes: 1348
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;


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

    //偶数は排除
    if (k % 2 == 0 || k%5==0) {
        cout << -1 << endl;
        return 0;
    }
    
    long long count = 0;
    long long i = 1;
    long long number = 7;
    while (1) {
        if (number % k == 0) {
            count = i;
            break;
        }
       
            number = (number%k) * 10+ 7;
            i++;
       
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
int a[300];

int main(){
  int ans = 100000000;
  cin >> n;
  REP(i,n){
    int k;cin >> k;
    int l = 0;
    while(k%2==0){
      k = k/2;
      l++;
    }
    ans = min(l,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
}


Measured memory_bytes: 3516
"use strict"
function main(arg) {
    // let data = arg.trim().split("\n")[1].split(" ").map(Number).sort((a,b) => a-b)
    let data = arg.trim().split("\n")[1].split(" ").map(Number)
    let N = data.length
    let counter = 0
    for (let i = 0;i < N;i++) {
        for (let j = i;j < N;j++) {
            if (i === j) continue
            if (data[i] === data[j]) continue
            for (let k = j;k < N;k++) {
                if (i === k) continue
                if (data[i] === data[k]) continue
                if (k === j) continue
                if (data[k] === data[j]) continue
                // console.log([i+1,j+1,k+1, isEnable(data[i],data[j], data[k])])
                if (isEnable(data[i],data[j], data[k])) {
                    counter++
                }
            }
        }
    }
    console.log(counter)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function isEnable(a,b,c) {
    return (a+b) > c && (b+c) > a && (a+c) > b
}

Measured memory_bytes: 32384
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=54;

int main()
{
	int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;

	int tim;

	if(m1<=m2)
	{
		tim=(h2-h1)*60+(m2-m1);
	}
	else
	{
		tim=(60-m1)+m2+(h2-h1-1)*60;
	}

	priln(tim-k);
	
    return 0;
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//, a = sc.nextInt(),b=sc.nextInt();
		//int x=sc.nextInt();//,k=sc.nextInt();
		long sum=0,count=0,flag=0,max=-999999,min=99999;
		long[] array=new long[87];
		//String s=sc.next(),t=sc.next();
		String buff;
		//String[] arrays = new String[a];
		array[0]=2;
		array[1]=1;
		for(int i=2;i<87;i++) {
			array[i]=array[i-1]+array[i-2];
		}
		System.out.println(array[n]);



	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 21844
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n = 0;
    ll k = 0;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    ll cur = 1;
    while ((cur<<1) <= k) {
        cur <<= 1;
    }
    ll x = 0;
    while (cur > 0) {
        int zero = 0, one = 0;
        for (int i=0; i<n; i++) {
            if ((cur&a.at(i)) == 0) zero++;
            else one++;
        }
        if (zero > one) {
            if (x + cur <= k) {
                x += cur;
            }
        }
        cur >>= 1;
    }
    ll ret = 0;
    for (int i=0; i<n; i++) {
        ret += (x^a.at(i));
    }
    cout << ret << endl;
    return 0;
}
 

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

int main() {
  int r,D,x2000;
  cin >>r>>D>>x2000;
  vector<int> vec(11);
  vec[0] = x2000;
  for(int i=0;i <10;i++){
    vec[i+1] = r*vec[i] - D ;
    cout << vec[i+1] << endl;
  }
}


Measured memory_bytes: 256
def find_base_label(lookup_table, label):
    base_label = label
    while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
    return base_label


def main():
    n, m = map(int, input().split())

    lookup_table = list(range(n))
    for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

    for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

    print(len(set(lookup_table)))


main()


Measured memory_bytes: 13164
# https://atcoder.jp/contests/abc104/tasks/abc104_d
# in
# ????C?????B??????A???????
# out
# 979596887
# in
# ABCBC
# 3

MOD = (10**9) + 7
dp_a = 0
dp_ab = 0
dp_abc = 0

dp_none = 1

gets.chomp.chars do |s|
  if s == 'A'
    dp_a = (dp_a + dp_none)%MOD
  elsif s == 'B'
    dp_ab = (dp_ab + dp_a)%MOD
  elsif s == 'C'
    dp_abc = (dp_abc + dp_ab)%MOD
  else
    dp_abc = (dp_abc * 3 + dp_ab)%MOD
    dp_ab = (dp_ab * 3 + dp_a)%MOD
    dp_a = (dp_a * 3 + dp_none)%MOD
    dp_none = (dp_none * 3)%MOD
  end
end

p dp_abc

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<pii> v(n);
  rep(i,n) cin >> v[i].second >> v[i].first;
  sort(ALL(v));
  int t = 0;
  rep(i,n) {
    t += v[i].second;
    if (t > v[i].first) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main() {
  solve();
  return 0;
}

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

int wa(int x){
  int res=0;
  while(x>0){
    res+=x%10;
    x/=10;
  }
  return res;
}

int main(){
  int N; cin>>N;
  int ans=INT_MAX/2;
  for(int i=1;i<=N/2;i++){
    ans=min(ans,wa(i)+wa(N-i));
  }
  cout<<ans<<endl;
  return 0;
}


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

#include <iostream>
#define pb push_back
#define sort_incr(v) sort(v.begin(),v.end());
#define sort_decr(v) {sort(v.begin(),v.end()); reverse(v.begin(),v.end());}
#define take_input(v,n) for(ll i=0,temp;i<n;i++){cin>>temp;v.pb(temp);}
#define fastio {ios_base::sync_with_stdio(false);    cin.tie(NULL);}
#define ALL(v) v.begin(),v.end()

typedef long long ll;
using namespace std; 

int main() 
{
    fastio;
    ll n,temp,su=0;
    cin>>n;
    vector<ll> v;
    int co[100004]={0};
    // take_input(v,n);
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        co[temp]++;
        su=su+temp;
    }
    ll q ;
    cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        su=su+(b-a)*co[a];
        co[b]+=co[a];
        co[a]=0;
        
        cout<<su<<"\n";
        
    }
    
    return 0; 
} 

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

using namespace std;


priority_queue<int, vector<int>, greater<int> >q;

int main() {
    int T, n, k;
    scanf("%d", &T);
    while(T--) {
        scanf("%d%d", &n, &k);
        q.push(k);
        while(n > 1) {
            k = q.top();
            q.pop();
            k = 127 ^ k;
            //printf("%d %d\n", k, k ^ 127);
            q.push(k);
            k = 127;
            q.push(k);
            n--;
        }
        int ans = 0;
        while(!q.empty()) {
            k = q.top();
            //printf("%d\n", k);
            q.pop();
            ans += k;
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main () {
  int s;
  std::cin >> s;

  int a = s / 1000;
  int b = s % 1000 /100;
  int c = s % 100 /10;
  int d = s % 10;

  if (a == b || b == c || c == d) {
    std::cout << "Bad" << std::endl;
  } else {
    std::cout << "Good" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include<stdio.h>

int main(void)
{

	int a, b, z;
	
	scanf("%d %d", &a, &b);
	z = a * b % 2;

	if (z == 0) {
		printf("Even\n");
	}
	else {
		printf("Odd\n");

	}
	
	return 0;	
		
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll k;
    cin >> k;
  ll a, b;
  cin >> a >> b;
  for (ll i = a; i <= b; i++) {
    if(i % k == 0) {
        cout << "OK" << endl;
        return 0;
    }
  }

  cout << "NG" << endl;
   return 0;
}



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

using namespace std;

int cnt[5],dizi[500],n;
double ans;
double dp[305][305][305];
double dpf(int bir,int iki,int uc){
	// printf("%d %d %d\n",bir,iki,uc );
	if( bir<0 || iki<0 || uc<0 || (bir+iki+uc)==0 ){
		return 0;
	}
	if(dp[bir][iki][uc]!=-1){
		return dp[bir][iki][uc];
	}
	double bol=0,a=0,b=0,c=0;
	double ilk=(double)n/(double)(bir+iki+uc);
	bol=bir+iki+uc;
	if(bir>0)
		a=dpf(bir-1,iki,uc);
	if(iki>0)
		b=dpf(bir+1,iki-1,uc);
	if(uc>0)
		c=dpf(bir,iki+1,uc-1);
	if(a!=0){
		a*=bir;
	}
	if(b!=0){
		b*=iki;
	}
	if(c!=0){
		c*=uc;
	}
	// printf("~~%lf~~\n",bol );
	if(bol>0){
		dp[bir][iki][uc]=(a+b+c);
		dp[bir][iki][uc]/=bol;
		dp[bir][iki][uc]+=ilk;
	}
	else{
		dp[bir][iki][uc]=ilk;
	}
	// printf("%lf %d %d %d\n",dp[bir][iki][uc],bir,iki,uc);
	return dp[bir][iki][uc];
}

int main(){
	// freopen("a.gir","r",stdin);
	// freopen("a.cik","w",stdout);
	for(int i=0;i<302;i++){
		for(int j=0;j<302;j++){
			for(int k=0;k<302;k++){
				dp[i][j][k]=-1;
			}
		}
	}
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%d",&dizi[i]);
		cnt[dizi[i]]++;
	}
	printf("%.10lf\n", dpf(cnt[1],cnt[2],cnt[3]));


	return 0;
}


Measured memory_bytes: 221568
import sys
def f(a):
    b=1
    for i in range(a):
        b*=i+1
        b%=1000000007
    return b
a=sorted(list(map(int,input().split())))
if a[1]-a[0]>=2:
    print(0)
    sys.exit()
c=2
if a[1]>a[0]:
    c=1
print((f(a[1])*f(a[0])*c)%1000000007)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int N, K, L;

const int MAXN = 500000;

vector<int> g[2][MAXN];
int compCnt[2][MAXN], comp[2][MAXN];
bool visited[2][MAXN];

map<pair<int, int>, int> mapa;
int cnt, curr;

void addEdge(int flag, int u, int v) {
	g[flag][u].pb(v);
	g[flag][v].pb(u);
}

void dfs(int flag, int v) {
	if (visited[flag][v])
		return;
	visited[flag][v] = true;
	comp[flag][v] = curr;
	cnt++;
	FOR (i, g[flag][v].sz)
		dfs(flag, g[flag][v][i]);
}

int main() {
	cin >> N >> K >> L;
	FOR (flag, 2)
		FOR (i, MAXN)
			g[flag][i].clear();
	mapa.clear();
	FOR (i, K) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		addEdge(0, u, v);
	}

	FOR (i, L) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		addEdge(1, u, v);
	}

	SET(visited, 0);
	SET(compCnt, 0);
	FOR (flag, 2) {
		curr = 0;
		FOR (i, N) {
			if (!visited[flag][i]) {
				cnt = 0;
				dfs(flag, i);
				compCnt[flag][curr] = cnt;
				curr++;
			}
		}
	}
	FOR (i, N)
		mapa[make_pair(comp[0][i], comp[1][i])]++;
	FOR (i, N) {
		int c1 = comp[0][i], c2 = comp[1][i];
		int val = mapa[make_pair(c1, c2)];
		cout << val;
		if (i < N - 1)
			cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 46848
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC100_A solver = new ABC100_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC100_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            if (a >= 9 || b >= 9) {
                out.print(":(");
            } else {
                out.print("Yay!");
            }
        }

    }
}



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

int main(){
  int n;
  cin>>n;
  int d;
  set<int>st;
  for(int i=0;i<n;i++){
    cin>>d;
    st.insert(d);
  }
  cout<<st.size()<<endl;
  
  return 0;
}


Measured memory_bytes: 256