akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
// union - find tree !!!!!!!!!!!!!!!!!!!!!!!!!
vector<int> par; //oya
vector<int> rnk; //ki no hu ka sa
// n要素で初期化
void init(int n){
    par.resize(n);rnk.resize(n);
    FOR(i, 0, n){par[i] = i;rnk[i] = 0;}
}
//木の根を求める
int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}
//xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y])par[x] = y;
    else {
      par[y] = x;
      if(rnk[x] == rnk[y]) rnk[x]++;
    }
    return;
}
bool isSame(int x, int y){return find(x) == find(y);}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  priority_queue<PP, vector<PP>, greater<PP> > que;
  int n;
  cin >> n;
  init(n+1);
  FOR(i,1,n+1){
    FOR(j,1,n+1){
      int cost;
      cin >> cost;
      if(cost == -1) cost = 1e9;
      que.push(PP(cost, P(i, j)));
    }
  }
  int ans = 0;
  while(!que.empty()){
    PP pp = que.top();
    que.pop();
    P p = pp.second;
    if(!isSame(p.first, p.second)){
      ans += pp.first;
      unite(p.first, p.second);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3252
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n; cin >> n;
  cout << 48 - n << endl;
  
  
}

Measured memory_bytes: 3624
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
      	if(s.equals("ABC")){
          System.out.println("ARC");
        } else {
          System.out.println("ABC");
        }
		
	}
}

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

public class Hello
{
    private const ulong MOD9 = 1000000007;

    public static void Main()
    {
        var nq = Console.ReadLine().Split(' ');
        var a = int.Parse(nq[0]);
        var b = int.Parse(nq[1]);
        var c = int.Parse(nq[2]);

        if (a > b)
        {
            var t = a;
            a = b;
            b = t;
        }

        Console.WriteLine(a < c && c < b ? "Yes" : "No");
    }
}


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

int main() {
    string S1, S2;
    cin >> S1 >> S2;

    if (S1[0] == S2[2] && S1[1] == S2[1] && S1[2] == S2[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def dfs(v, n, graph, visited):
    visited[v] = True
    for v2 in range(n):
        if not graph[v][v2]:
            continue
        if visited[v2]:
            continue
        dfs(v2, n, graph, visited)


n, m = [int(v) for v in input().split()]
graph = [[False] * n for i in range(n)]
a = []
b = []
for i in range(m):
    v1, v2 = [int(v) for v in input().split()]
    v1 -= 1
    v2 -= 1
    a.append(v1)
    b.append(v2)
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True

ans = 0
for i in range(m):
    graph[a[i]][b[i]] = False
    graph[b[i]][a[i]] = False

    visited = [False] * n
    dfs(0, n, graph, visited)
    if False in visited:
        ans += 1

    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int i = 2;
	while(true){
		if(i%2){
			a -= d;
			// cout << "a : " << a << endl;
			if(a <= 0){
				cout << "No" << endl;
				break;
			}
			
		} else {
			c -= b;
			// cout << "c : " << c << endl; 
			if(c <= 0){
				cout << "Yes" << endl;
				break;
			}
		}
		// cout << i << endl;
		i++;
	}
	return 0;
}


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

int main() {
  int ans=0;
  string S;
  cin >> S;

  for(int i=0;i<3;i++){
    if(S.at(i) == 'R') ans += 1;
  }

  if(S.at(1)=='S'){
    if(ans == 2){
      ans--;
    }
  }

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

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
#define vi vector<int>
int n,m,d[200005],maxd=0,maxnum=0,vis[200005],A,B;
vi G[200005];
void dfs(int x)
{
	vis[x]=1;
	int sz=G[x].size();
	for(int i=0;i<sz;i++)
	{
		int y=G[x][i];
		if(vis[y]==2) A?B=y:A=y;
		else if(!vis[y]) dfs(y);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);G[y].push_back(x);
		d[x]++,d[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(d[i]&1)
		{
			puts("No");
			return 0;
		}
		if(d[i]>maxd) maxd=d[i],maxnum=1;
		else if(d[i]==maxd) maxnum++;
	}
	if(maxd>=6){puts("Yes");return 0;}
	else if(maxd<=2||maxnum==1){puts("No");return 0;}
	else if(maxnum>2){puts("Yes");return 0;}
	else
	{
		for(int i=1;i<=n;i++) if(d[i]==maxd) vis[i]=2;
		int sum=0;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				A=0,B=0;
				dfs(i);
				if(A==B) sum++;
			}
		}
		if(sum) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 13328
#pragma region
#ifndef LOCAL_DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <assert.h>
#include <math.h>

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <vector>
#define pb push_back
#define f(i, a, b) for (int i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define all(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define revsrt(v) sort(v.rbegin(), v.rend())
#define sp << ' ' <<
#define en << '\n'
#define precision(x) cout << fixed << setprecision(x);
#define fio                \
  ios::sync_with_stdio(0); \
  cin.tie(0);              \
  cout.tie(0);

using namespace std;

template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &v) {
  os << "{" << v.first << ", " << v.second << "}" en;
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, set<T> &v) {
  for (T t : v) os << t << " ";
  os en;
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (T t : v) os << t << " ";
  os en;
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++) is >> v[i];
  return is;
}

#define int long long
#define pii pair<int, int>
#define float long double
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#pragma endregion

int mod = 1e9 + 7;  // 998244353;
const int MAX = 1e6 + 5;

vvi factors(MAX);

void preprocessing() {
  // factors[1].pb(1);

  f(i, 2, MAX) {
    if (!factors[i].size())
      for (int j = i; j < MAX; j += i) {
        factors[j].pb(i);
      }
  }
}

void solvetestcase() {
  int n;
  cin >> n;
  vi v(n);
  cin >> v;

  srt(v);

  bool a = true;
  vector<bool> factors_vis(MAX, 0);
  f(i, 0, n) {
    // cout << i sp factors[v[i]];
    for (int j : factors[v[i]]) {
      if (factors_vis[j]) {
        a = false;
        break;
      }
      factors_vis[j] = 1;
    }

    if (!a) break;
  }

  int g = 0;
  f(i, 0, n) g = __gcd(g, v[i]);
  bool b = g == 1;

  if (a) {
    cout << "pairwise coprime\n";
  } else if (b) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}

#undef int
int main() {
  fio;
  preprocessing();

  int t = 1;
  // UNCOMMENT FOR TESTCASES	\
	cin >> t;

  f(T, 1, t + 1) {
    // UNCOMMENT FOR CODEJAM,HACKERCUP	\
		cout << "Case #" << T << ": ";
    solvetestcase();
    cout.flush();
  }

  return 0;
};

/*
    AUTHOR:     KUNAL TAWATIA
    EDUCATION:  INDIAN INSTITUTE OF TECHNOLOGY, JODHPUR
*/


Measured memory_bytes: 81384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){

    //入力部
    int n;
    int a[101]={0};//0埋めされた配列
    cin >> n;
    for(int i=0;i<n;i++){
        int input;
        cin >> input;
        a[input]  = 1;
    }

    // 計算部
    int ans=0;
    for(int i=1;i<101;i++){
        ans += a[i];
    }

    //出力部
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int N;
  
  string s1, s2;
  
  cin >> N;
  
  cin >> s1 >> s2;
  
  long long int ans = 1;
  
  for(int i=0;i<N;i++){
    
    if(s1[i] == s2[i]){
      
      if(i == 0){
        ans *= 3;
      }
      
      else if(s1[i-1] == s2[i-1]){
        ans *= 2;
        ans %= 1000000007;
      }
      
    }
     
      
      else{
        if(i == 0){
          ans *= 6;
          i++;
        }
        
      
        
        else if(s1[i-1] == s2[i-1]){
          ans *= 2;
          ans %= 1000000007;
          i++;
        }
           
          else{
                  ans *= 3;
                  ans %= 1000000007;
            i++;
                }
        
      }
      
}
      cout << ans << endl;
  
}
      
      
        
      
      
      
      
  
 


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 20400, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};

const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int a[N], dp[10][N];

int main() {
	FREOPEN();
	int n;
	cin >> n;
	int m;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + 1 + m);
	for (int i = 0; i <= m; i++) for (int j = 0; j < n; j++) dp[i][j] = -1;
	for (int i = 1; i <= m; i++) {
		for (int j = n; j >= 0; j--) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			int k = j - cost[a[i]];
			if (k < 0) continue;
			dp[i][k] = max(dp[i][k], dp[i][j] + 1);
		}
	}
	string ans = "";
	for (int j = 0, i = m; j < n && i >= 1;) {
		int k = j + cost[a[i]];
		if (k <= n && dp[i][k] == dp[i][j] - 1) {
			ans += char(a[i] + '0');
			j = k;
		}
		else {
			i--;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N, cnt=0;
vll A;
map<int, int> mp;

void solve(){

    printf("%d %lld\n", max(1,(int)mp.size()), mp.size()+cnt);

}

int main(){
    cin >> N;
    A.resize(N,0);
    rep(i,N){
        cin >> A[i];
        if(A[i] >= 3200) cnt++;
        else mp[A[i]/400]++;        
    }

    solve();
}


Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
degree = abs(h * 30 + 0.5 * m - m * 6)
degree = min(degree, abs(360 - degree))
theta = math.radians(degree)
l = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(theta))
print(l)

Measured memory_bytes: 9352
/*
?????????????????£??¨????????°?????£??±???????????´??¬??????????????????
*/
#include<iostream>
using namespace std;
int main(){
int n,h,j,i;
cin>>n;
int number[3][n],sum[n];
for(i=0;i<n;i++){
for(j=0;j<3;j++){
cin>>number[j][i];
}
sum[i]=number[0][i]+number[1][i]+number[2][i];
}

for(i=0;i<n;i++){
for(j=0;j<3;j++){
for(h=0;h<n;h++){
if(number[j][i]==number[j][h]&&i!=h){
sum[i]-=number[j][i];
h=n;
}
}
}
cout<<sum[i]<<endl;
}
return 0;
}

Measured memory_bytes: 1160
n,m=map(int,input().split())
l=[0]*(m+1)
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(1,a[0]+1):
        l[a[j]]+=1
if max(l)==n:
    print(l.count(max(l)))
else:
    print(0)


Measured memory_bytes: 38256
// C - Synthetic Kadomatsu
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define ote(x) cout<<(x)<<endl

int main(){
	int N; cin>>N;
	vi A(4); for(int i=1; i<4; ++i) cin>>A[i];
	vi L(N); for(int i=0; i<N; ++i) cin>>L[i];

	int ans = INT_MAX;
	int e = 1<<16;
	for(int i=0; i<e; i+=1){

		vi B(4), C(4);
		for(int j=0; j<N; ++j){
			int b = (i>>(j*2))&3;
			int l = N - j - 1;
			C[b]++;
			B[b] += L[l];
		}

		if(min({B[1],B[2],B[3]})!=0){
			int sum = 0;
			for(int j=1; j<4; ++j){
				sum += abs(A[j]-B[j]);
				if(C[j]>=2) sum += (C[j]-1)*10;
			}
			ans = min(ans, sum);
		}

	}
	ote(ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int dh[2] = {1, 0};
const int dw[2] = {0, 1};

int H, W;

void dfs(vector<string> &G, vector<vector<int>> &S, int h, int w) {
    S[h][w] = 1;
    if (h == H - 1 && w == W - 1) return;

    int nexth = -1, nextw = -1;
    REP(i, 0, 2) {
        int nh = h + dh[i];
        int nw = w + dw[i];
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;    
        if (G[nh][nw] == '#') {
            if (nexth != -1 && nextw != -1) return;
            nexth = nh; nextw = nw;
        }
    }
    if (nexth == -1 && nextw == -1) return;
    dfs(G, S, nexth, nextw);
    return;
}

int main() {
    cin >> H >> W;
    vector<string> G(H);
    REP(i, 0, H) cin >> G[i];

    vector<vector<int>> S(H, vector<int>(W, 0));
    dfs(G, S, 0, 0);

    REP(i, 0, H) {
        REP(j, 0, W) {
            if (G[i][j] == '#' && S[i][j] == 0) {
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}

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

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n,b-1);
    ll ans = a*x/b - a*(x/b);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<int> deg(n, 0);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    deg[y]++;
  }
  vector<int> dp(n, 0);
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto t : g[s]) {
      dp[t] = max(dp[t], dp[s] + 1);
      deg[t]--;
      if (deg[t] == 0) q.push(t);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define eps 10E-10
#define mod 998244353
#define pai acos(-1)
#define N 1000005


int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int x,y;
    cin>>x>>y;
    map<int,bool>vis;
    for(int i=0;i<=x;i++){
      int ar=(x-i)*2+(i*4);
      vis[ar]=1;
    }
    cout<<(vis[y]?"Yes\n":"No\n");
    return 0;
}




Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using vi = vector<int>;
using vll = vector<ll>;
ll fast_exp(ll base,ll e){
    ll r=1;
    while(e>0){
        if(e%2)r=(r*base);
        base=base*base;
        e/=2;
    }
    return r;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}

const int nax=305;
double ev[nax][nax][nax];
// ev[a][b][c] is the expected number of operations to get to the state (a,b,c);
double dp[nax][nax][nax];
// dp[a][b][c] is p-bility of getting to the state (a,b,c);

int main(){
    int n;scanf("%d",&n);
    vector<int> v(4);
    for(int i=0;i<n;i++){
        int x;scanf("%d",&x);
        v[x]++;
    }
    dp[v[1]][v[2]][v[3]]=1;
    for(int c=n;c>=0;c--){
        for(int b=n;b>=0;b--){
            for(int a=n;a>=0;a--){
                if(a==0&&b==0&&c==0||(a+b+c)>n)continue;
                
                double p_waste= (double)(n-(a+b+c))/n;
                
                double ev_waste=p_waste/(1-p_waste)+1;
                ev[a][b][c]+=ev_waste*dp[a][b][c];
                
                
                if(a!=0){
                    double p_go = (double)a/(a+b+c);
                    dp[a-1][b][c]+=dp[a][b][c]*p_go;
                    ev[a-1][b][c]+=ev[a][b][c]*p_go;
                }
                if(b!=0){
                    double p_go = (double)b/(a+b+c);
                    dp[a+1][b-1][c]+=dp[a][b][c]*p_go;
                    ev[a+1][b-1][c]+=ev[a][b][c]*p_go;
                }
                if(c!=0){
                    double p_go = (double)c/(a+b+c);
                    dp[a][b+1][c-1]+=dp[a][b][c]*p_go;
                    ev[a][b+1][c-1]+=ev[a][b][c]*p_go;
                }
            }
        }
    }
    printf("%.10lf",ev[0][0][0]);
    
}

Measured memory_bytes: 438528
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>

using namespace std;

const double EPS = 1e-8;

bool dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    else {
        return d < 0? -1 : 1;
    }
}

struct Vector {
    double x, y;
    Vector(double x = 0, double  y = 0):x(x), y(y) {
    }
};

typedef Vector Point;

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

double ccw(const Point& a, const Point& b, const Point& c) {
    return cross(b - a, c - a);
}

int main() {
    int n; 
    cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    
    double area = 0;
    for (int i = 1; i < n - 1; i++) {
        area += ccw(p[0], p[i], p[i+1]) / 2;
    }
    
    cout << fixed << setprecision(1) << area << endl;
    
    return 0;
}

Measured memory_bytes: 3284
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int A, B, M, ans = INF;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    for(int i=0;i<A;++i) cin >> a[i];
    for(int i=0;i<B;++i) cin >> b[i];

    ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());

    vector<int> x(M), y(M), c(M);
    for(int i=0;i<M;++i) {
        cin >> x[i] >> y[i] >> c[i];
        ans = min(ans, a[x[i]-1]+b[y[i]-1]-c[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 2176
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

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

    int N = scanner.nextInt();
    List<Integer> dups = new ArrayList<>();
    Set<Integer> set = new HashSet<>();
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      if (set.contains(a)) {
        dups.add(a);
        set.remove(a);
      } else {
        set.add(a);
      }
    }
    Collections.sort(dups);
    Collections.reverse(dups);

    if (dups.size() < 2) {
      System.out.println(0);
    } else {
      System.out.println((long) dups.get(0) * dups.get(1));
    }
  }
}


Measured memory_bytes: 61528
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll H,W,N;
  cin >> H >> W >> N;
  map<P,ll> m;
  ll a,b;
  ll cnt[10]={0};
  cnt[0]=(H-2)*(W-2);
  for(int i=0;i<N;i++){
    cin >> a >> b;
    a--;
    b--;
    for(int k=a-2;k<=a;k++){
      for(int l=b-2;l<=b;l++){
        if(k<0 || l<0 || k>=H-2 || l>=W-2)continue;
        cnt[m[{k,l}]]--;
        m[{k,l}]++;
        cnt[m[{k,l}]]++;
      }
    }
  }

  /*for(int i=0;i<H-2;i++){
    for(int j=0;j<W-2;j++){
      black=m[{i,j}];
      cnt[black]++;
    }
  }*/
  for(int i=0;i<=9;i++){
    cout << cnt[i] << endl;
  }
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;cin>>n;
	if(n<=599 && n>=400)cout<<"8\n";
	if(n<=799 && n>=600)cout<<"7\n";
	if(n<=999 && n>=800)cout<<"6\n";
	if(n<=1199 && n>=1000)cout<<"5\n";
	if(n<=1399 && n>=1200)cout<<"4\n";
	if(n<=1599 && n>=1400)cout<<"3\n";
	if(n<=1799 && n>=1600)cout<<"2\n";
	if(n<=1999 && n>=1800)cout<<"1\n";
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int D,G,p[11],c[11];
	cin>>D>>G;G/=100;
	int ans=G;
	for(int i=0;i<D;i++)cin>>p[i]>>c[i],c[i]/=100;
	for(int s=0;s<(1<<D);s++)
	{
		int cnt=0,poi=0;
		for(int i=0;i<D;i++)
		{
			if((1<<i)&s)
			{
				cnt+=p[i];
				poi+=(i+1)*p[i]+c[i];
			}
		}
		if(poi>=G)
		{
			ans=min(ans,cnt);
			continue;
		}
		for(int i=D-1;i>=0;i--)
		{
			if(!((1<<i)&s))
			{
				if(poi+(i+1)*(p[i]-1)>=G)
				{
					ans=min(ans,cnt+(G-poi)/(i+1)+((G-poi)%(i+1)>0));
					break;
				}
				else
				{
					cnt+=p[i]-1;
					poi+=(i+1)*(p[i]-1);
				}
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}

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

int main(){
  int A,B,C,a,i;
  scanf("%d %d %d",&A,&B,&C);
  a=A;
  for(i=1;a<=B*A;i++){
    a=A*i;
    if((a%B)==C){
      printf("YES\n");
      exit(0);
    }
  }printf("NO\n");
}


Measured memory_bytes: 128
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a = readi()
s = read()
if a >= 3200:
    print(s)
else:
    print("red")



Measured memory_bytes: 7872
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

double dp[2][210];
int N, t[110], v[110], lim[40010];

signed main() {
    cin >> N;
    rep(i,0,N) cin >> t[i];
    rep(i,0,N) cin >> v[i];

    int sum = 0;
    rep(i,0,N) rep(j,0,t[i]) rep(k,0,2) lim[sum++] = v[i] * 2;
    rep(i,0,2) rep(j,0,210) dp[i][j] = -1.0;
    dp[0][0] = 0;
    rep(i,0,sum) {
        int mo = i % 2;
        rep(j,0,210) {
            if(dp[mo][j] < 0) continue;
            repq(d,-1,1) {
                if(j+d<0 || j+d>lim[i+1]) continue;
                // up ... do not exceed 
                if(d == 1 && j+d>lim[i]) continue;
                // ( (j/2) + ((j+d)/2) ) * 0.5 / 2
                // (j + d/2) / 4.0
                chmax(dp[mo^1][j+d], dp[mo][j] + (j + d/2.0)/4.0);
            }
        }
        fill(dp[mo], dp[mo]+210, -1.0);
    }
    printf("%.12f\n", dp[sum%2][0]);
    return 0;
}

Measured memory_bytes: 512
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Tue Dec 11 00:35:24 2018
//
package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func scanSlice(slice []int) {
	for i := 0; i < len(slice); i++ {
		fmt.Scan(&slice[i])
	}
}

func accumulateSlice(slice []int) {
	length := len(slice)
	for i := 0; i < length; i++ {
		if i+1 < length {
			slice[i+1] += slice[i]
		}
	}
}

func leftSums(arr []int, left, mid int) (int, int) {
	return arr[left-1], arr[mid-1] - arr[left-1]
}

func rightSums(arr []int, mid, right int) (int, int) {
	return arr[right-1] - arr[mid-1], arr[len(arr)-1] - arr[right-1]
}

func findRight(arr []int, mid int) int {
	diff := 1000000000
	right := mid + 1
	for i := mid + 1; i < len(arr)-1; i++ {
		lower, upper := rightSums(arr, mid, i)
		if abs(lower-upper) < diff {
			diff = abs(lower - upper)
			right = i
		}
	}
	return right
}

func diffSums(sums ...int) int {
	sort.Ints(sums)
	return sums[len(sums)-1] - sums[0]
}

func main() {
	var N int

	fmt.Scan(&N)
	arr := make([]int, N)
	scanSlice(arr)
	accumulateSlice(arr)

	minVal := 100000000000
	left := 1
	right := findRight(arr, 2)

	for mid := 2; mid < len(arr)-1; mid++ {
		p, q := leftSums(arr, left, mid)
		for diffLeft := abs(p - q); left < mid; left++ {
			newP, newQ := leftSums(arr, left+1, mid)
			if abs(newP-newQ) > diffLeft {
				break
			}
			diffLeft = abs(newP - newQ)
		}

		r, s := rightSums(arr, mid, right)
		for diffRight := abs(r - s); right < len(arr)-1; right++ {
			newR, newS := rightSums(arr, mid, right+1)
			if abs(newR-newS) > diffRight {
				break
			}
			diffRight = abs(newR - newS)
		}

		P, Q := leftSums(arr, left, mid)
		R, S := rightSums(arr, mid, right)
		val := diffSums(P, Q, R, S)

		if val < minVal {
			minVal = val
		}
	}
	fmt.Println(minVal)
}


Measured memory_bytes: 5760
module kkk
  sub main()
    
    dim n as integer
    dim s as string
    dim t as string
    
    dim i as integer
    dim a as string
    
    n = console.readline()
    s = console.readline()
    t = right(s, n)
    s = left(s, n)
    
    for i = 0 to n - 1
    a = a & right(left(s, i+1), 1) & right(left(t, i+1), 1)
    next
  
  console.writeline(a)
  
end sub
end module
  

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


int main(){
  int n,k;
  cin>>n>>k;
  vector<int> dp(100200,1000000000);
  vector<int> h(100200);
  dp.at(0)=0;
  rep(i,n)cin>>h.at(i);
  rep(i,n){
    for(int j=1;j<=k;j++)
      dp.at(i+j)=min(dp.at(i)+abs(h.at(i)-h.at(i+j)),dp.at(i+j));
  }
  cout<<dp.at(n-1)<<endl;
  }

Measured memory_bytes: 1024
/**
 *   author: malviyanshiv
 *   created: 07 September 2019  18:08:25
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'L'){
            if(i != 0 && s[i-1] == 'L')
                cnt++;
        }else{
            if( i != n-1 && s[i+1] == 'R')
                cnt++;
        }
    }
    cout << min(n-1, cnt + k*2) << endl;
    return 0;
}


Measured memory_bytes: 512
import itertools
H, W, K = map(int,input().split())
c = [list((ord(x) - 46) // (-11) for x in list(input())) for i in range(H)]   
ans = 0
for i in itertools.product((0,1), repeat=W):    
    for j in itertools.product((0,1), repeat=H):
        temp = 0
        for a in range(W):
            for b in range(H):
                if i[a] == 1 and j[b] == 1:
                    temp += c[b][a]
        if temp == K:
            ans += 1
print(ans)

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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scanner.nextInt();
        int[][] mat = new int[n][3];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 3; j++){
                mat[i][j] = scanner.nextInt();
            }
        }

        for(int i = 1; i < n; i++){
            mat[i][0] = mat[i][0] + Math.max(mat[i - 1][1], mat[i - 1][2]);
            mat[i][1] = mat[i][1] + Math.max(mat[i - 1][0], mat[i - 1][2]);
            mat[i][2] = mat[i][2] + Math.max(mat[i - 1][0], mat[i - 1][1]);
        }

        System.out.println(Math.max(mat[n - 1][0], Math.max(mat[n - 1][1], mat[n - 1][2])));
    }
}


Measured memory_bytes: 94844
n = gets.to_i
t = gets.chomp.split(' ').map(&:to_i)
m = gets.to_i
p, x = [], []
m.times do |i|
  p[i], x[i] = gets.chomp.split(' ').map(&:to_i)
end

sum = t.inject(0){ |result, n| result + n }
m.times do |i|
  puts sum - t[p[i] - 1] + x[i]
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
using namespace std;
 
#define debug(a) cerr << #a << ": " << a << endl
 
typedef long long ll;
typedef pair<int, int> ii;
 
#define x first
#define y second
 
const int N = 1e5 + 10;

string s;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
 
	cin >> s;
	int len = s.length();
	if (s[0] == s[len - 1] && len % 2 == 0) cout << "First\n";
	else if (s[0] != s[len - 1] && len % 2 == 1) cout << "First\n";
	else cout << "Second\n";

	return 0;
}

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

int main(void){
  int n;
  string num;
  cin >> n;
  for(int i = 0; i < n; i++){
    int cnt = 0;
    cin >> num;
    while(num.size() > 1){
      int maxn = 0;
      for(int i = 0; i < num.size() - 1; i++){
        string op1(num, i + 1, num.size() - i), op2(num, 0, i + 1);
        int n = stoi(op1) * stoi(op2);
        if(n > maxn) maxn = n;
      }
      num = to_string(maxn);
      cnt++;
      if(cnt > 1000000) break;
    }
    if(cnt <= 1000000) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static long MOD = 1000000007;
	public static void main(String[] args) {
		int i,j,k;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		i = 1;
		j = 0;
		int cnt=0;
//		boolean f=false;
LABEL:	while(true) {
			while(i!=a[j]) {
				j++;
				cnt++;
				if(j==n) {
					break LABEL;
				}
			}
			j++;
			if(j==n) {
				break LABEL;
			}
			i++;
		}
		out.println(n==cnt?-1:cnt);
	}
}


Measured memory_bytes: 50684
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int now = 0;
	while (now <= 10000)
	{
		for (int i = 0; i <= a; i++)
		{
			if (now > c)c += 60;
			if (now == c)
			{
				cout << now << endl;
				return 0;
			}
			now++;
		}

		for (int i = 0; i < b-1; i++)
		{
			now++;
			if (now > c)c += 60;
		}
	}


	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3112
import numpy as np
from collections import defaultdict

#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

A, B, K = map(int, input().split())  #

A_list = list()
B_list = list()
all_list = list()
for a in range(A):
    if A%(a+1) == 0:
        A_list.append(a+1)
    
for b in range(B):
    if B%(b+1) == 0:
        B_list.append(b+1)

for a in A_list:
    for b in B_list:
        if a == b:
            all_list.append(a)
all_list.sort(reverse=True)
print(all_list[K-1])            
# m_list = list()

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

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

    vector<tuple<string, int, int>> v;

    string s;
    int p;

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

        cin >> s >> p;
        v.push_back(make_tuple(s, 100 - p, i + 1));
    }

    sort(v.begin(), v.end());

    for (int i = 0; i < N; i++)
    {
        int n;
        tie(ignore, ignore, n) = v[i];

        cout << n << endl;
    }
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

#include <atcoder/fenwicktree>
using namespace atcoder;

int main(){
	int n,q;cin>>n>>q;
	fenwick_tree<ll>fw(n);
	rep(i,n){
		int a;cin>>a;
		fw.add(i,a);
	}
	rep(i,q){
		int t,a,b;scanf("%d%d%d",&t,&a,&b);
		if(t==0){
			fw.add(a,b);
		}
		else{
			printf("%lld\n",fw.sum(a,b));
		}
	}
}

Measured memory_bytes: 8204
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n, k, m, count = 0, i;
	vector<int>a, b;


	cin >> n >> k;

	for (i = 0; i < n; i++) {
		cin >> m;
		a.push_back(m);
	}
	sort(a.begin(), a.end());

	m = a[0];
	count = 1;
	for (i = 1; i < n; i++) {
		if (m != a[i]) {
			b.push_back(count);
			m = a[i];
			count = 1;
		}
		else {
			count++;
		}
	}
	b.push_back(count);

	sort(b.begin(), b.end());
	
	count = 0;
	if (b.size() > k) {
		for (i = 0; i < b.size() - k; i++) {
			count += b[i];
		}
	}
	cout << count;

	return 0;
}

Measured memory_bytes: 2548
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int n;
    scanf("%d", &n);

    if(n == 0){
      break;
    }

    bool l = false, r = false;
    llong ans = 0;
    bool isup = false;
    REP(i,n){
      string s;
      cin >> s;
      if(s == "lu"){
        l = true;
      }else if(s == "ld"){
        l = false;
      }else if(s == "ru"){
        r = true;
      }else{
        r = false;     
      }

      if(r & l){
        if(!isup){
          ans++;
          isup = true;
        }
      }    
      if(!r & !l){
        if(isup){
          ans++;
          isup =false;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}




Measured memory_bytes: 3220
import heapq

def solve():
    H, W = map(int, input().split())
    sy, sx = map(lambda x: int(x) - 1, input().split())
    ty, tx = map(lambda x: int(x) - 1, input().split())
    graph = [input() for i in range(H)]
    INF = 10 ** 9
    dist = [INF] * (H * W)
    que = []

    def push(y, x, d):
        v = y * W + x
        if dist[v] <= d:
            return
        dist[v] = d
        heapq.heappush(que, (d, v))

    push(sy, sx, 0)

    while que:
        d, v = heapq.heappop(que)
        y, x = divmod(v, W)
        if dist[v] < d:
            continue
        for dy in range(-2, 3):
            for dx in range(-2, 3):
                ny, nx = y + dy, x + dx
                if ny < 0 or ny >= H or nx < 0 or nx >= W:
                    continue
                if graph[ny][nx] == '#':
                    continue
                push(ny, nx, d + (abs(dy) + abs(dx) > 1))

    t = ty * W + tx
    if dist[t] == INF:
        return -1
    else:
        return dist[t]

print(solve())


Measured memory_bytes: 98124
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sstream> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <queue> //C++
#include <map> //C++
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  max(x,y) ((x)>(y)?(x):(y))
#define  min(x,y) ((x)>(y)?(y):(x))


using namespace std; //C++


int main(void) {

	int total, k;
	int number[1000];

	cin >> total>>k;
	int i;
	for (i = 0; i < total; i++) {
		cin >> number[i];
	}

	int  j, tmp;



	for (i = 0; i < total; ++i) {
		for (j = i + 1; j < total; ++j) {
			if (number[i] > number[j]) {
				tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
		}
	}

	int ans=0;

	for (i = 0; i < k; i++) {
		ans += number[i];
	}
	cout << ans;

}

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var N = long.Parse(input[0]);
        var M = long.Parse(input[1]);
        var K = long.Parse(input[2]);


        var array1 = Console.ReadLine().Split(' ');
        var array2 = Console.ReadLine().Split(' ');

        var aBooks = new List<long>();
        var bBooks = new List<long>();

        long current = 0;
        long ans = 0;

        foreach (var book in array1)
        {
            var time = long.Parse(book);
            if(current + time <= K)
            {
                aBooks.Add(time);
                current += time;
            }
            else
            {
                break;
            }
        }

        ans = aBooks.Count;
        var currentCount = ans;

        foreach(var book in array2)
        {
            bBooks.Add(long.Parse(book));
        }

        int currentBPlace = 0;


        while (true)
        {
            if (currentBPlace >= bBooks.Count)
            {
                break;
            }
            if (bBooks[currentBPlace] + current <= K)
            {
                current += bBooks[currentBPlace];
                currentBPlace += 1;
                currentCount += 1;

                if (currentCount > ans)
                {
                    ans = currentCount;
                }
            }
            else
            {
                break;
            }
        }



        for (int i = aBooks.Count - 1; i >= 0; i--)
        {
            if(currentBPlace >= bBooks.Count)
            {
                break;
            }

            currentCount -= 1;
            current -= aBooks[i];

            while (true)
            {
                if (currentBPlace >= bBooks.Count)
                {
                    break;
                }
                if (bBooks[currentBPlace] + current <= K)
                {
                    current += bBooks[currentBPlace];
                    currentBPlace += 1;
                    currentCount += 1;

                    if(currentCount > ans)
                    {
                        ans = currentCount;
                    }
                }
                else
                {
                    break;
                }
            }
        }

        long onlyBTime = 0;
        int onlyBCount = 0;

        foreach (var book in bBooks)
        {
            if (onlyBTime + book <= K)
            {
                onlyBTime += book;
                onlyBCount += 0;
            }
            else
            {
                break;
            }
        }


        if(ans < onlyBCount)
        {
            ans = onlyBCount;
        }



        Console.WriteLine(ans);

        

        Console.ReadLine();

    }
}

Measured memory_bytes: 59812
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    vector<pair<int, int>> time(5);
    int ans = 0;
    for(int i = 0; i < 5; i++)
    {
        cin >> time[i].second;
        time[i].first = time[i].second % 10;
        if (time[i].first == 0) {
            time[i].first = 10;
        }
        
    }
    sort(time.begin(), time.end());
    reverse(time.begin(), time.end()); //降順に
    for(int i = 0; i < 5; i++)
    {
        ans += time[i].second;
        if (i != 4) {
            ans += (10 - time[i].first);
        }
    }
    cout << ans;    
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846
 
void solve()
{
        set<string> st;
        string a, b; cin >> a >> b;
        for(int i = 0; i <= 1000; ++i)
        {
                st.insert(to_string(i * i));
        }
        if(st.find(a + b) != st.end())
        {
                cout << "Yes";
        }
        else cout << "No";
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	char c;
	cin >> c;
	if (c >= 'A' and c <= 'Z')
		cout << "A" << endl;
	else
		cout << "a" << endl;
}

Measured memory_bytes: 3564
using System;
using System.Collections.Generic;
class Program
{	
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long K = long.Parse(str[1]);
		long ans = 0;
		long a = N/K;
		ans += a * a * a;
		if(K%2==0){
			a = (N+K/2)/K;
			ans += a * a * a;
		}
		Console.WriteLine(ans);
	}
}

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

// Z-Algorithm
// Z_array の構築, 「S と S[i:|S|-1] の最長共通接頭辞の長さ」
vector<int> Z_array(string S){
    int n = S.size();
    vector<int>res(n, 0);
    res[0] = -1;
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < n && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) { ++i; continue; }
        int k = 1;
        while (i+k < S.size() && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k; j -= k;
    }
    return res;
}

int Z_Algorithm(string word, string S){
    string concat = word + "$" + S;
    auto v = Z_array(concat);
    int res = 0;
    for (int i = word.size() + 1; i < concat.size(); ++i) {
        res = max(res, v[i]);
    }
    return res;
}

int main() {
    string s, t;
    cin >> s >> t;

    // KMP法でtをいっぱい並べた文字列の先頭から何文字が含まれるかを調べる
    string tk, sk;
    while(tk.size() < s.size() + t.size()){
        tk += t;
    }
    while(sk.size() < s.size() + t.size() * 2){
        sk += s;
    }
    // sk.size() > tk.size() >= 2 * t.size()

    int mx = Z_Algorithm(tk, sk);

    int ans = -1;
    if(mx < (s.size() + t.size())){
        ans = mx / t.size();
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 23240