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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

struct Edge {
    int cost, to;
    Edge(int to_, int cost_) : 
        to(to_), cost(cost_) { } 
};


int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<vector<Edge> > node(n);
    map<pii, bool> used_path;

    irep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        node[a-1].push_back(Edge(b-1, c));
        node[b-1].push_back(Edge(a-1, c));
        used_path[pii(a-1,b-1)] = false;
    }

    irep(start, n) {
        v_int dist(n, INF);
        v_bool seen(n, false);
        v_int prev(n, -1);

        dist[start] = 0;
        vector<pii> dist_path[n];

        while(1) {
            int current = -1;
            irep(i, n) {
                if(seen[i] == false && (current == -1 || dist[i] < dist[current])) {
                    current = i;
                }
            }

            if(current == -1) { break; }
            seen[current] = true;

            vector<Edge> edges = node[current];

            irep(i, edges.size()) {
                if(dist[edges[i].to] > dist[current] + edges[i].cost) {
                    dist[edges[i].to] = dist[current] + edges[i].cost;
                    prev[edges[i].to] = current;
                }
            }
        }

        irep(i, n) {
            v_int path;
            if(i == start) { continue; }
            for (int cur = i; cur != -1; cur = prev[cur]) {
                path.push_back(cur);
            } 
            irep(j, path.size()-1) {
                used_path[pii(path[j], path[j+1])] = true;        
                used_path[pii(path[j+1], path[j])] = true;        
            }
        }
    }
    int ans = 0;
    for(auto path : used_path) {
        if(!path.second) { ans++; }
    }
    cout << ans << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 384
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);

  double t, x;
  cin >> t >> x;

  double d = (double)(t/x);

  printf("%.10f\n", d);
    //cout << d << endl;
  
  return 0;
}


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

//#define int long long
//#define ll int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(vec) (vec).begin(),(vec).end()
#define vint vector<int>
#define pint pair<int,int>
#define vpint vector<pint>

int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
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]++;}}
bool same(int x,int y){return find(x)==find(y);}

int n,k;

signed main(){
    cin>>n>>k;
    int ans=(n-1)/(k-1)+!!((n-1)%(k-1));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[10];
	int temp,i,j;
	for(i=0;i<=9;i++)
	{
		scanf("%d",&a[i]);
	}
	for(j=9;j>=0;j--)
	{
	for(i=0;i<j;i++)
	{
		if(a[i]>=a[i+1])
		{
			temp=a[i];
			a[i]=a[i+1];
			a[i+1]=temp;
		}
	}
	}
	for(i=9;i>6;i--)
	{
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
import sys
from math import pi

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    R = int(readline())

    print(2 * R * pi)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 62092
#include <cstddef>
#include <initializer_list>


using usize = ::std::size_t;

template <usize N> struct ce_disjoint_sets {
	usize t[N];
	constexpr ce_disjoint_sets(
		const ::std::initializer_list<::std::initializer_list<usize>> &sets)
		: t() {
		for (const auto &s : sets) {
			const auto f = s.begin();
			for (const auto &e : s) {
				t[e] = *f;
			}
		}
	}
	constexpr usize find(const usize &x) const noexcept { return t[x]; }
	constexpr bool is_same(const usize &x, const usize &y) const noexcept {
		return find(x) == find(y);
	}
};


static constexpr auto h = ce_disjoint_sets<13>(
	{ { 1,3,5,7,8,10,12 },{ 4 ,6, 9, 11 },{ 2 } });

#include<iostream>

int main() {
	usize x, y;
	::std::cin >> x >> y;
	::std::cout << (h.is_same(x, y) ? "Yes" : "No") << ::std::endl;
	return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int a, b;

    cin >> a>> b;

    cout<< a*b;
    nl;
    return 0;
}




Measured memory_bytes: 3604
#include <cstdio>
char M[12][13];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
void dfs(int x,int y) {
	M[y][x]=0;
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0>nx||nx>=12||0>ny||ny>=12) continue;
		if(M[ny][nx]=='1') dfs(nx,ny);
	}
}
int main() {
	while(scanf("%s",M[0])!=EOF) {
		for(int i=1;i<12;i++) scanf("%s",M[i]);
		int sum=0;
		for(int i=0;i<12;i++) {
			for(int j=0;j<12;j++) {
				if(M[i][j]=='1') {
					sum++;
					dfs(j,i);
				}
			}
		}
		printf("%d\n",sum);
	}
}

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

int main() {
  int N, M, x;
  cin >> N >> M >> x;
  int a = 0;

  for (int i = 0; i < M; i++) {
    int y;
    cin >> y;
    if(y<x) a++;
  }
    
    cout << min(a, M-a) << endl;

}

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

int main(){
    
    int a;
    int b;
    
    // 標準入力
    cin >> a >> b;

    if (a * b % 2 == 0){
        cout << "Even" << endl;
    
    } else {
        cout << "Odd" << endl;
    }
    
    return 0;

}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		cs1: Chars,
		cs2: Chars,
	}

	if cs1[0] == cs2[2] && cs1[1] == cs2[1] && cs1[2] == cs2[0] {
		println!("YES");
	}
	else {
		println!("NO");
	}
}



Measured memory_bytes: 2180
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int A[N];
    cin>>A[0];
    int M,m;
    M=A[0];
    m=A[0];
    for(int i=1;i<N;i++){
        cin>>A[i];
        M=max(M,A[i]);
        m=min(m,A[i]);
    }
    cout<<M-m<<endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;

int main(void){
    string s;
    cin >> s;
    char alpa[100];
    for(int i=0;i<100;i++){
    	alpa[i] = 0;
    }
    for(int i=0;i<s.length();i++){
        alpa[s[i] - 'a']++;
    }
    for(int i=0;i<30;i++){
        if(alpa[i] > 1){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
def hash1(m, key):
    return key % m

def hash2(m, key):
    return 1 +  key % (m - 1)

def hash(m, key, i):
    return (hash1(m, key) + i * hash2(m, key) ) % m

def insert(T, key):
    i = 0
    l = len(T)
    while True:
        h = hash(1046527,key,i)
        if (T[h] == None ):
            T[h] = key
            return h
        elif (T[h] == key):
            return h
        else:
            i += 1

def search(T,key):
    l = len(T)
    i = 0
    while True:
        h = hash(1046527,key,i)
        if(T[h] == key):
            return h
        elif(T[h] is None or h >= l):
            return -1
        else:
            i += 1

def find(T, key):
    a = search(T,key)
    if(a == -1):
        print('no')
    else:
        print('yes')

dict = {'A' : '1', 'C' : '2', 'G' : '3', 'T' : '4'}
data = []
T = [None]*1046527
n = int(input())


while n > 0:
    st = input()
    d = list(st.split())

### convert key to num(1~4)
    tmp_key = ''
    for x in list(d[1]):
        tmp_key += dict[x]

    data.append([d[0],int(tmp_key)])
    n -= 1
for com in data:
    if(com[0] == 'insert'):
        insert(T,com[1]) 
    else:
        find(T,com[1])

Measured memory_bytes: 207444
from fractions import gcd
from functools import reduce

MOD = 10 ** 9 + 7

def lcm(list_):
    return reduce(lambda x, y: x // gcd(x, y) * y,
                  list_)

n = int(input())
a = list(map(int, input().split()))

l = lcm(a)
total = 0

for a_ in a:
    total += l // a_

print(total % MOD)


Measured memory_bytes: 6100
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    char data[12][12];

    while (cin >> data[0]) {
        for (int i = 1; i < 8; i++) {
            cin >> data[i];
        }
        getchar();

        bool fl = false;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if (data[i][j] == '1') {
                    if (data[i][j+1] == '1' &&
                            data[i+1][j+1] == '1' &&
                            data[i+1][j] == '1') {
                        puts("A");
                        fl = true;
                    } else if (data[i+1][j] == '1' &&
                            data[i+2][j] == '1' &&
                            data[i+3][j] == '1' ) {
                        puts("B");
                        fl = true;
                    } else if (data[i][j+1] == '1' && 
                            data[i][j+2] == '1' &&
                            data[i][j+3] == '1') {
                        puts("C");
                        fl = true;
                    } else if (data[i+1][j] == '1' && 
                            data[i+1][j-1] == '1' &&
                            data[i+2][j-1] == '1') {
                        puts("D");
                        fl = true;
                    } else if (data[i][j+1] == '1' && 
                            data[i+1][j+1] == '1' &&
                            data[i+1][j+2] == '1') {
                        puts("E");
                        fl = true;
                    } else if (data[i+1][j] == '1' && 
                            data[i+1][j+1] == '1' &&
                            data[i+2][j+1] == '1') {
                        puts("F");
                        fl = true;
                    } else if (data[i+1][j] == '1' && 
                            data[i][j+1] == '1' &&
                            data[i+1][j-1] == '1') {
                        puts("G");
                        fl = true;
                    }
                }
                if (fl) {
                    break;
                }
            }
            if (fl) {
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3056
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

result = -10**9
for b in range(1, 1 << 10):
    c = [0 for _ in range(N)]
    for t in range(10):
        if (b & (1 << t)) != 0:
            # Joisino's shop is open
            for i in range(N):
                if F[i][t] == 1:
                    c[i] += 1
    profit = 0
    for i in range(N):
        profit += P[i][c[i]]
    result = max(result, profit)
print(result)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    //int x = sc.nextInt();
    List<String> list = new ArrayList<>();
    int count = 0;

    if(b + c - a <= 0){
        System.out.println(0);
    }else{
        System.out.println(b + c - a);
    }
  

    


    


    

    
    
    



    





}
}

Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int x = stdIn.nextInt();
        
        if(x == 0){
            System.out.println(1);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
 #define rep(i,a,b) for (int i=a;i<b;i++)
 #define rep2(i,a,b) for (int i=a;i>=b;i--)
 #define mod 1000000007
 #define INF  1e9+5
 #define f first
 #define se second
 #define endl '\n'
 #define ll long long
 #define ii pair <int,int>
 #define pll pair <ll,ll>
 #define vi vector <int>
 #define vl vector <ll>
 #define vvi vector < vi >
 #define vii vector < ii >
 #define vvii vector < vii >
 #define vll vector < ll >
 #define mi map<int,int>
 #define mll map<ll,ll>
 #define mci map<char,int>
 #define msi map<string,int>
 #define vb  vector <bool>
 #define pb push_back
 #define mk make_pair
 #define sz(a) a.size()
 #define all(a) a.begin(),a.end()
 #define rall(a) a.rbegin(),a.rend()
 #define int long long int
 #define Anurag_Gupta ios_base::sync_with_stdio(false);
#define IIIT_ALLD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
vi fact(1000007);
inline int mdpower(int a,int b)
{
    int res =1;
    while(b)
    {
        if(b&1) res = (res%mod*a%mod)%mod;
        b/=2;
        a = (a%mod*a%mod)%mod;
    }
    return res;
}
inline int power(int a,int b)
{
    int res =1;
    while(b)
    {
        if(b&1) res = (res*a);
        b/=2;
        a = a*a;
    }
    return res;
}

inline void factorial()
{
    fact[0]=1;
    for(int i=1;i<1000007;i++)
        fact[i] = (fact[i-1]%mod*i%mod)%mod;
}

inline int inverse(int a)
{
    return mdpower(a,mod-2);
}
 signed main()
 {
     Anurag_Gupta
     IIIT_ALLD
     
    /* #ifndef ONLINE_JUDGE
         freopen("input.txt","r",stdin);
         freopen("output.txt","w",stdout);
     #endif*/
      int n,m;
      cin>>n>>m;
      vii v;
      for(int i=0;i<n;i++)
      {
        int a,b;
        cin>>a>>b;
        v.pb({a,b});
      }
      sort(all(v));

      int sum=0;
      int i=0;
      while(m>0)
      {
        int a = v[i].f;
        int b = v[i].se;
        int mini = min(m,b);
        sum+=a*mini;
        m-=mini;
        i++;
      }
      cout<<sum<<"\n";


 }


Measured memory_bytes: 10228
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e5+10;
const ll mod=1e9+7;
int main()
{
	ll n,i,j,mp[111][15],cnt[111],k,val[111][15],now;
	ll ans;
	while(~scanf("%lld",&n))
	{
		ans=-LLINF;
		for(i=0;i<n;i++)
		{
			for(j=0;j<10;j++) scanf("%lld",&mp[i][j]);
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<=10;j++) scanf("%lld",&val[i][j]);
		}
		for(i=1;i<(1<<10);i++)
		{
			mem(cnt,0);
			for(j=0;j<10;j++)
			{
				if(i&(1<<j))
				{
					for(k=0;k<n;k++)
					{
						cnt[k]+=mp[k][j];
					}
				}
			}
			now=0;
			for(k=0;k<n;k++) now+=val[k][cnt[k]];
			ans=max(ans,now);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	int n;
	cin >> n;

	if (n % 1000)
		cout << 1000 - n % 1000 << endl;
	else
		cout << 0 << endl;
}



Measured memory_bytes: 3632
import random
N = int(input())
cnt = 0
slime = list(map(int,input().split()))
for i in range(N):
  try:
    if slime[i]==slime[i+1]:
      cnt+=1
      while slime[i]==slime[i+1]:
        slime[i+1]=random.randint(1,10000)
  except IndexError:
    break;

print(cnt)

Measured memory_bytes: 5224
def slove():
    import sys
    input = sys.stdin.readline
    n, y = list(map(int, input().rstrip('\n').split()))
    for i in range(n + 1):
        for j in range(n + 1 - i):
            t = n - i - j
            if 0 <= i <= n and 0 <= j <= n and 0 <= t <= n:
                if i + j + t == n and i * 10000 + j * 5000 + t * 1000 == y:
                    print(i, j, t)
                    exit()
            elif i + j > n or i * 10000 + j * 5000 > y:
                break
    print(-1, -1, -1)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38896
#include<algorithm>
#include<stack>
#include<ctime>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<queue>
using namespace std;
inline int read(){
	int num=0,f=1;char x=getchar();
	while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}
	while(x>='0'&&x<='9'){num=num*10+x-'0';x=getchar();}
	return num*f;
}
int n,x,t;
int main(){
	 n=read();x=read();t=read();
	 printf("%d",(n/x+(n%x>0))*t);
	return 0;
}


Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int main()
{
    int A , B , C , D;

    cin >> A >> B >> C >> D ;

    int R1 = A * B;
    
    int R2 = C * D;

    if ( A >=1 && A <= 10^4 && B >=1 && B <= 10^4 && C >=1 && C <= 10^4 && D >=1 && D <= 10^4 ){



     if (R1 >= R2)

     cout << R1;

     else if ( R2 > R1)
     cout << R2;
    }
    return 0;
}

Measured memory_bytes: 256
/**
	Language: C++
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define fastio() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define debug(v) cerr << '\n' << #v << " :\t" << v << '\n'
#define loop(i, L, U) for (ll i = (L); i <= (U); ++i)
#define rloop(i, U, L) for (ll i = (U); i >= (L); --i)
#define foreach(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
	fastio();
	int p, q, r;
	cin >> p >> q >> r;
	cout << (p + q + r) - max(p, max(q, r)) << '\n';
	return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = chunk.split(" ");
  x[0] = Number(x[0])
  x[1] = Number(x[1])
  x[2] = Number(x[2])
  if ((x[0] < x[1]) && (x[1] < x[2])) {
    console.log("Yes")
  }else{
    console.log("No")
  }
});



Measured memory_bytes: 19328
#pragma GCC optimize("O3") 
#include<bits/stdc++.h>
#define ll      				long long int
#define vi      				vector<int>
#define ii      				pair<int,int>
#define iii     				pair<ii,int>
#define iiii    				pair<ii,ii>
#define fi      				first
#define se      				second
#define unord_map				unordered_map
#define nxt_pmt					next_permutation
#define clr					clear()
#define ALL(x) 					x.begin(),x.end()


#define pb      				push_back
#define pob     				pop_back

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

#define db(x)					  cout << "!!!!!! " << #x << " => " << x << "\n"

#define fori(i, s, N)     for (int i = s; i <= N; i++)
#define ford(i, s, N)     for (int i = s; i >= N; i--)
using namespace std;

void init(int precision){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

int t;
void cjam(int z){
	cout<<"Case #"<<z<<": ";
	
}

string s;
int main(){
//	init(10);
	cin>>t;
	cin>>s;
	int r = 0, w= 0;
	for(int z = 0;z<t;z++){
		if(s[z] == 'R') r++;
		else w++;
	}
	int move = 0;
	for(int i = 0;i<r;i++){
		if(s[i] == 'W') move++;
	}
	int ans = 0;
	ans = move;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3764
#include <stdio.h>

int main(void)
{
	int a[6];
	int i = 0;
	int one = 0,two = 0,three = 0,four = 0;
	
	while (i < 6){
		scanf("%d %d", &a[i], &a[i + 1]);
		i += 2;
	}
	i = 0;
	while (i < 6){
		switch (a[i]){
			case 1:
				one++;
				break;
			case 2:
				two++;
				break;
			case 3:
				three++;
				break;
			case 4:
				four++;
				break;
		}
		i++;
	}
	if ((one == 1)&&(two == 2)&&(three == 2)&&(four == 1)){
		printf("YES");
	}
	else{
		printf("NO");
	}
	
	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, pair<int, int>>> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;

const int nmax = 8;
bool gragh[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){
    
    bool all_visited = true;
    
    for(int i = 0; i < N; i++){
        if(visited[i] == false){
            all_visited = false;
        }
    }
    
    if(all_visited){
        return 1;
    }
    
    int ret = 0;
    
    for(int i = 0; i < N; i++){
        if(gragh[v][i] == false) continue;
        if(visited[i]) continue;
        
        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }
    return ret;
    
}


int main(){
    int N,M;
    cin >> N >> M;
    
    for(int i = 0; i < M; i++){
        int A,B;
        cin >> A >> B;
        gragh[A-1][B-1] = gragh[B-1][A-1] = true;
    }
    
    bool visited[nmax];
    for(int i = 0; i < N; i++){
        visited[i] = false;
    }
    
    visited[0] = true;
    cout << dfs(0, N, visited) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
using namespace __gnu_pbds;

#define os tree<long long, null_type,less_equal<long long>, rb_tree_tag,tree_order_statistics_node_update>
const ll MOD=1e9+7;
ll add(ll a, ll b)
{
	return (a%MOD+b%MOD)%MOD;
}

ll mult(ll a, ll b)
{
		return (a%MOD*b%MOD)%MOD;
}

int main()
{
    IOS
    os o_set; 
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll r[n];
    ll tot[n];
    map<ll,ll>mp;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        ll small=o_set.order_of_key(a[i])+mp[a[i]];
        ll gt=i-small;
        r[i]=gt;
        o_set.insert(a[i]);        // cout<<o_set.size()<<endl;
        mp[a[i]]++;             
    }
    for(ll i=0;i<n;i++)
    {
        ll small=o_set.order_of_key(a[i])+mp[a[i]];
        ll gt=n-small;
        tot[i]=gt;
    }
    ll ans=0;
    ll t=k*(k-1);
    t/=2;                   
    for(ll i=0;i<n;i++)
    {                                              // cout<<a[i]<<" "<<r[i]<<endl;
        ans=add(ans,mult(k,r[i]));
        ans=add(ans,mult(t,tot[i]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
# r, c = map(int, input().split())
# elements = []
# total = 0

# for i in range(r):
#     element = list(map(int, input().split()))
#     elements.append(element)

# for i in range(r + 1):
#     for j in range(c + 1):
#         if j == c:
#             print(sum(elements[i]))
#         elif i == r:
#             for k in range(r):
#                 total += int(element[k][j])
#                 print(total, end=" ")
#         else:
#             print(elements[i], end=" ")
#     print()
# print()

r, c = map(int, input().split())
elements = []
total = 0
for i in range(r):
    element = list(map(int, input().split()))
    elements.append(element)

for i in range(r + 1):
    for j in range(c + 1):
        if i == r and j == c:
            print(total)
        elif j == c:
            total += sum(elements[i])
            print(sum(elements[i]))
        elif i == r:
            total2 = 0
            for k in range(r):
                total2 += elements[k][j]
            print(total2, end=" ")
        else:
            print(elements[i][j], end=" ")



Measured memory_bytes: 6256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#include <tuple>
#include <string>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
#define FORk(N) for(int k=0;k<N;++k)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  string L;
  cin>>L;
  vector <ll> A(L.size(),-1);
  function<ll(ll,bool)> f =[&](ll i,bool flag)->ll{
    if(i==L.size())return 1;
    if(flag==false&&A[i]!=-1)return A[i];
  	ll num=0;
    if(flag==true&&L[i]=='1'){
      num=f(i+1,false);
      num+=f(i+1,true)*2;
    }else if(flag==true&&L[i]=='0'){
      num+=f(i+1,true);
    }else{
      num=f(i+1,flag)*3;
    }
    num%=1000000007;
    if(flag==false)A[i]=num;
    return num;
  };
  cout<<f(0,true);
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  string s, t; cin >> s >> t;
  for (int i = 0; i < (int)s.size(); i++){
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    s = s.substr(1) + s[0];
  }
  cout << "No" << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <assert.h>

using namespace std;

int sign(int ops, int i)
{
  return ((ops >> i) & 1) ? +1 : -1;
}

string sign_s(int ops, int i)
{
  return ((ops >> i) & 1) ? "+" : "-";
}

int value(int a, int b, int c, int d, int ops)
{
  return a + sign(ops, 2) * b + sign(ops, 1) * c + sign(ops, 0) * d;
}

string str(int a, int b, int c, int d, int ops)
{
  return string(1, '0' + a) 
    + sign_s(ops, 2) + string(1, '0' + b)
    + sign_s(ops, 1) + string(1, '0' + c)
    + sign_s(ops, 0) + string(1, '0' + d);
}

string seven(int a, int b, int c, int d)
{
  for (int ops = 0; ops < (1 << 3); ops++) {
    if (value(a,b,c,d,ops) == 7) {
      return str(a,b,c,d,ops) + "=7";
    }
  }
  assert(false);
  return "";
}

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

  int a, b, c, d;
  d = n % 10; n = n / 10;
  c = n % 10; n = n / 10;
  b = n % 10; n = n / 10;
  a = n % 10; n = n / 10;

  cout << seven(a,b,c,d) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
    int a;
    cin >> a;
    int b;
    cin >> b;
      vector<int> c(a);
    for (int i = 0; i < a; i++) {
  cin >> c.at(i);
}
    int d = 0;
    for (int i = 0; i < b; i++) {
  d += c.at(i);
}
    int e = 0;
    int f = 0;
    for (int i = 0; i < (a-b); i++) {
      e += (c.at(i+b)-c.at(i));
        if(e >= f)
        {f = e;}
    }
     int g;
      g = (b + d + f) / 2;
      
        cout << g;
      if((b + d + f) % 2 == 1)
      {cout << ".5";}
      cout << endl;
      
}

Measured memory_bytes: 1024
/*
  I used a template program in C.
*/

#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){


}
 
Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}
 
Node treeSuccessor(Node x){


}
 
Node treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y


}
 
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  /*my code beginning*/
  while ( x != NIL ){
    y = x;
    if ( z->key < x->key ){ 
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if ( y == NIL ){ 
    root = z;
  } else if ( z->key < y->key ){
    y->left = z;
  } else {
    y->right = z;
  }
  /*my code end*/

}
 
void inorder(Node u){

  /*my code beginning*/
  if ( u != NIL ){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  /*my code end*/

}
void preorder(Node u){

  /*my code beginning*/
  if ( u != NIL ){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
  /*my code end*/

}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  /*my code beginning*/
  root=NIL;
  /*my code end*/

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}

Measured memory_bytes: 24036
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
int a, b, c, d, ans;

int main()
{
    cin >> a >> b >> c >> d;
    int x, y;
    x = max(a, c);
    y = min(b, d);
    ans = y - x;
    if(ans < 0) ans = 0;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

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

  String str = br.readLine();

  int x=Integer.parseInt(str),h=x/3600,m,s;
  x%=3600;
  
  m=x/60;
  x%=60;
     
  s=x;

  System.out.println(h+":"+m+":"+s);
 }
}

Measured memory_bytes: 24420
n = int(input())
total = 0
for i in range(n):
    a = input().split()
    value = float(a[0])
    type = str(a[1])

    if type == 'JPY':
        total += value
    elif type == 'BTC':
        total += value * 380000
    else:
        pass
print(total)


Measured memory_bytes: 2940
use std::io;


fn main() {
    let mut ans: u64 = 0;
    let s = read_one::<String>().chars().collect::<Vec<char>>();
    let mut cnt: u64 = 0;
    for i in 0..s.len() {
        if s[i] == 'B' { cnt += 1; }
        if s[i] == 'W' { ans += cnt; }
    }
    println!("{}", ans);

}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    if s[0] != s[1] or s[0] != s[2] or s[1] != s[2]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
def solve():
    from bisect import bisect_left, bisect_right
    import sys
    input = sys.stdin.readline

    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def setInit(As):
        for iB, A in enumerate(As, 1):
            data[iB] = A
        for iB in range(1, numPow2):
            i = iB + (iB & -iB)
            data[iB] -= data[i]
    def addValue(iA, A):
        iB = iA + 1
        while iB > 0:
            data[iB] += A
            iB -= iB & -iB
    def getValue(iA):
        iB = iA + 1
        ans = 0
        while iB <= numPow2:
            ans += data[iB]
            iB += iB & -iB
        return ans
    def addRangeValue(iFr, iTo, A):
        addValue(iTo, A)
        if iFr > 0:
            addValue(iFr-1, -A)

    N, D, A = map(int, input().split())
    XHs = [tuple(map(int, input().split())) for _ in range(N)]

    XHs.sort()
    Xs = [X for X, H in XHs]
    Hs = [H for X, H in XHs]

    data, numPow2 = makeBIT(N)
    setInit(Hs)

    ans = 0
    for iL in range(N):
        H = getValue(iL)
        if H <= 0: continue
        iR = bisect_right(Xs, Xs[iL]+2*D) - 1
        num = -(-H // A)
        addRangeValue(iL, iR, -num*A)
        ans += num

    print(ans)


solve()


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

using namespace std;

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

    vector<int> b;
    for (int i = 1; i <= n; i++) {
        int t;
        cin >> t;
        if (t > i) {
            cout << -1 << endl;
            return 0;
        }
        b.insert(b.begin() + t - 1, t);
    }

    for (auto x:b) cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i,j,n,m,cn;
  char c,s[5]={'S','H','C','D','\0'};
  static int card[4][13];
  scanf("%d\n",&n);

  for(i=0;i<n;i++){
    scanf("%c %d\n",&c,&m);
    for(j=0;j<4;j++)
      if(s[j]==c)
        card[j][m-1]=1;
  }
  
  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      if(card[i][j]==0)
        printf("%c %d\n",s[i],j+1);

  return 0;
}


Measured memory_bytes: 2096
import java.util.*;
import java.io.*;

public class Main {
    static Scanner sc = new Scanner();
    static List<List<Integer>> tree;
    static int[] score;
	public static void main(String[] args) throws IOException {
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        int[] tree = new int[n];
 
        for(int i=0; i<n-1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            tree[b] = a;
        }
 
        long[] p = new long[n];
        for(int i=0; i<q; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt();
            p[a] += b;
        }
 
        for(int i=1; i<n; i++) {
            p[i] += p[tree[i]];
        }
 
        System.out.print(p[0]);
        for(int i=1; i<n ;i++) {
            System.out.print(' ');
            System.out.print(p[i]);
        }
        System.out.println();
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 68524
#include<stdio.h>
#include<math.h>

int main(){
	int n;
	int ansx;
	int ansy;
	int i;
	int time = 0;
	for(i = 0; i < 4; i++){
		scanf("%d", &n);
		time += n;
	}
	ansx = time / 60;
	ansy = time % 60;
	printf("%d\n%d\n", ansx, ansy);
	return 0;
}

Measured memory_bytes: 596
//
// Created on 2020/01/12.
//

#include <istream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;//(n,vector<int>(m,initialize))


int maze(){
    int H,W;
    cin>>H>>W;//迷路の縦横を受け取る
    vector<string> data(H);
    for (int i=0;i<H;i++){
        cin>>data[i];//文字列として格納
    }
    queue <vector<int>> d_queue;
    int count =0;//移動回数をカウントする
    int ans =0;
    vector<pair<int,int>> move = {
            {0,  1},
            {1,  0},
            {-1, 0},
            {0,  -1},
    };

    for (int k=0;k<H;k++){
        for (int l=0;l<W;l++){
            if (data[k].at(l) != '#'){//必要に応じて条件を変更
                d_queue.push({k,l,count});//スタート位置をキューにセット

                vector<string> temp_data = data;//データをディープコピー。元のデータを残しておきたい時に使う
                while (!d_queue.empty()){
                    vector<int> now_queue = d_queue.front();
                    d_queue.pop();
                    temp_data[now_queue[0]][now_queue[1]]= '#';//現在地の状態を変更。場合によっては別の配列に入れる。移動済みをマークする。場合によってはゴールか判定する
                    for (pair<int,int>move_array:move){
                        if (0 <= now_queue[0]+move_array.first && now_queue[0]+move_array.first < H && 0 <= now_queue[1]+move_array.second && now_queue[1]+move_array.second < W){//範囲外に出ないかどうかチェック
                            if (temp_data[now_queue[0]+move_array.first][now_queue[1]+move_array.second]== '.'){//次に移動できるかチェック
                                d_queue.push({now_queue[0]+move_array.first,now_queue[1]+move_array.second,now_queue[2]+1});//移動できたら移動先をキューに入れる
                                ans = max(ans,now_queue[2]+1);//答えを更新する（移動の最大値など）
                                temp_data[now_queue[0]+move_array.first][now_queue[1]+move_array.second] = '#';//移動先を訪問済みにする
                            }
                        }
                    }
                }
            }
        }

    }
    cout<<ans<<endl;

}

int main(){
    maze();

}

Measured memory_bytes: 256
S = input()
S = list(S)
N = int(input())

for i,c in enumerate(S):
    needed = (97  - ord(c)) % 26
    if needed <= N:
        N -= needed
        S[i] = "a"

N %= 26

S[-1] = chr(  ((ord(S[-1]) -97) + N) %26 + 97 )
print("".join(S))


Measured memory_bytes: 49520
def check(X, Y, N, S):
    overtake = False
    while X <= Y:
        if S[X-2] == "." and S[X] == ".":
            overtake = True
        if X == Y:
            break
        if S[X] == ".":
            X += 1
        else:
            if X+1 <= N and S[X+1] == ".":
                X += 2
            else:
                return False, False
    return True, overtake

def main():
    N, A, B, C, D = map(int, input().split())
    S = input()
    S += "#"
    A_ok, _ = check(A, C, N, S)
    B_ok, overtake = check(B, D, N, S)
    if A_ok and B_ok and (C < D or overtake):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c && c == a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll MOD=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    vector<ll> flg(n,0) , cnt(n,0);
    for(ll i=0;i<m;i++){
        ll x;cin>>x;x--;
        string s;cin>>s;
        if(s=="AC")flg[x]=1;
        else{
            if(!flg[x])cnt[x]++;
        }
    }

    ll a=0,b=0;
    for(ll i=0;i<n;i++){
        if(!flg[i])continue;
        a++;
        b+=cnt[i];
    }
    cout<<a<<" "<<b;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

const int M = 1e4 + 10;

int a[M]; 

int main() {
	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= m; i++) cin >> a[i];
	
	int res = n;
	for (int i = 1; i <= m; i++) {
		res -= a[i];
	}
	
	if (res < 0) cout << -1 << '\n';
	else cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>

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

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int num[105][105];
int colvector[105];
int main() {
//	freopen("in","r",stdin);
	memset(num,0,sizeof(num));
	int row, col; cin>>row>>col;
	for(int i=0;i<row;i++) {
		for(int j=0;j<col;j++) {
			cin>>num[i][j];
		}
	}

	for(int i=0;i<col;i++) cin>>colvector[i];

	for(int i=0;i<row;i++) {
		int sum = 0;
		for(int j=0;j<col;j++) {
			sum += num[i][j]*colvector[j];
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n, m;
    while (cin >> n >> m, n) {
        vector<pair<int ,i_i > > data(m);
        vector<bool> infected(n, false);
        rep(i, m) {
            cin >> data[i].first >> data[i].second.first
                >> data[i].second.second;
            data[i].second.first--;
            data[i].second.second--;
        }
        sort(data.begin(), data.end());
        infected[0] = true;
        rep(i, m) {
            infected[data[i].second.second] = 
                (infected[data[i].second.second] || 
                 infected[data[i].second.first]);
        }
        int ret = 0;
        rep(i, n) {
            if (infected[i]) {
                ret++;
            }
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 3320
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<queue>
#define For(i,j,k)	for(ll i=j;i<=k;++i)
#define Dow(i,j,k)	for(ll i=k;i>=j;--i)
#define inf 1e17
#define ll long long
using namespace std;
inline ll read()
{
    ll t=0,f=1;char c=getchar();
    while(c<'0'||c>'9')	{if(c=='-')	f=-1;	c=getchar();}
    while(c>='0'&&c<='9')	t=t*10+c-'0',c=getchar();
    return t*f;
}
inline void write(ll x){if(x>=10)	write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
ll n,dp[5001];
struct node{ll h,p;}	a[5001];
inline bool cmp(node x,node y){return (x.h+x.p)<(y.h+y.p);}
inline void upd(ll &x,ll y){x=x<y?x:y;}
int main()
{
	n=read();
	For(i,1,n)	a[i].h=read(),a[i].p=read();
	sort(a+1,a+n+1,cmp);
	dp[0]=0;
	For(i,1,n)	dp[i]=inf;
	For(i,1,n)
	{
		Dow(j,0,n-1)
		{
			if(dp[j]<=a[i].h)
				upd(dp[j+1],dp[j]+a[i].p);
		}
	}
	Dow(i,1,n)	if(dp[i]!=inf)	{writeln(i);return 0;}
}

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

int main() {
  int N, Yen;
  cin >> N >> Yen;
  
  int a, b, c;
  int r = 0;
  for (int i = 0; i <= N; i++) {
    if (Yen == 10000*i) {
      if (N == i) {
      a=i, b=0, c=0;
      r++;
      goto SKIP;
      }
    }
    for (int j = 0; j <= N-i; j++) {
      if (j == N-i) {
        if (Yen == 10000*i + 5000*j) {
        a=i, b=j, c=0;
        r++;
        goto SKIP;
        }
        else {
        j = 0;
        break;
        }
      }
      for (int k = 0; k <= N-i-j; k++) {
        if (k == N-i-j) {
          if (Yen == 10000*i + 5000*j + 1000*k) {
          a=i, b=j, c=k;
          r++;
          goto SKIP;
          }
          else {
          k = 0;
          break;
          }
        }
      } 
    }
  }
  SKIP:
  if (r == 0) cout << -1 << " " << -1 << " " << -1 << endl;
  if (r == 1) cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 3540
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
#from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

def chmax(a, b):
    if a < b:
        return b
    else:
        return a

def main():
    n = int(input())
    abc = [None] * n
    for i in range(n):
        abc[i] = tuple(map(int, input().split()))

    dp = [[0] * 3 for _ in range(n+1)]
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][k] = chmax(dp[i+1][k], dp[i][j] + abc[i][k])
    
    ans = 0
    for j in range(3):
        ans = chmax(ans, dp[n][j])
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 91480