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

int main(){
    long long N, five=5, add=1, out=0, ans=0;
    cin >> N;
    if(N%2==1){
        cout << 0 << endl;
        return 0;
    }
    while(N>five){
        five *= 5;
        add++;
    }
    five /= 5;
    add--;
    N -= N%10;
    while(five!=1){
        long long tar = (N/five) / 2;
        ans += (tar - out) * add;
        out += tar - out;
        five /= 5;
        add--;
    }
    cout << ans << endl;
    return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	cin >> n;
	map<string, bool> u;
	for(int i=0; i<n; i++){
		string t;
		cin >> t;
		u[t] = false;
	}

	int m;
	cin >> m;
	bool f = false;
	for(int i=0; i<m; i++){
		string t;
		cin >> t;
		if(u.find(t) == u.end()){
			cout << "Unknown " << t << endl;
		}else if(f == false){
			cout << "Opened by " << t << endl;
			f = true;
		}else{
			cout << "Closed by " << t << endl;
			f = false;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3216
s=input()
for i in range(len(s)):
    if s[i]=="A":
        x=i#"A"のインデックス番号
        break
for i in range(1,len(s)):
    if s[-i]=="Z":
        y=len(s)-i#"Z"のインデックス番号
        break
ans=y-x+1
print(ans)

Measured memory_bytes: 3628
#include <stdio.h>

int n;
int temp1[1000], temp2[1000];

void k_cut(int card[], int k)
{

	int i, j, l, m;

	for(i = 0; i < k; i++) {
		temp1[i] = card[i];
	}
	for(j = i, m = 0; j < 2 * n; j++, m++) {
		temp2[m] = card[j];
	}

	for(i = 0; i < m; i++) {
		card[i] = temp2[i];
	}
	for(j = i, l = 0; j < i + k; j++) {
		card[j] = temp1[l++];
	}

}

void riffle_shuffle(int card[])
{

	int i, j, l;

	for(i = 0; i < n; i++) {
		temp1[i] = card[i];
	}
	for(j = i, l = 0; j < 2 * n; j++, l++) {
		temp2[l] = card[j];
	}

	for(i = 0, j = 0; i < 2 * n; i += 2, j++) {
		card[i] = temp1[j];
		card[i + 1] = temp2[j];
	}

}

int main(void)
{

	int m, k, i;
	int card[1000];

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

	for(i = 0; i < 2 * n; i++) {
		card[i] = i + 1;
	}

	for(i = 0; i < m; i++) {
		scanf("%d", &k);
		if(k > 0) {
			k_cut(card, k);
		}
		else {
			riffle_shuffle(card);
		}
	}

	for(i = 0; i < 2 * n; i++) {
		printf("%d\n", card[i]);
	}

	return 0;

}

Measured memory_bytes: 608
function main(){
  var localInput = input;
  var f = [
    [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ,[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    ];
  
  var len = localInput.length - 1;
  for(;len--;){
    var l = localInput[len];
    var ix = parseInt(l[0]) + 2;
    var iy = parseInt(l[2]) + 2;
    switch(l[4]){
    case '3': // no-break case;
      f[iy+2][ix]++;
      f[iy-2][ix]++;
      f[iy][ix-2]++;
      f[iy][ix+2]++;
    case '2':
      f[iy+1][ix-1]++;
      f[iy+1][ix+1]++;
      f[iy-1][ix-1]++;
      f[iy-1][ix+1]++;
    case '1':
      f[iy+1][ix]++;
      f[iy][ix-1]++;
      f[iy][ix]++;
      f[iy][ix+1]++;
      f[iy-1][ix]++;
      break;
    }
  }
  
  var nd=0;//not dropped
  var md=0;//most dropped
  var y = 10;
  for(;y--;){
    var x = 10;
    for(;x--;){
      nd += !(f[y+2][x+2]);
      md = mx(f[y+2][x+2], md);
    }
  }
  
  console.log(nd);
  console.log(md);
}
   
function mx(a, b){
 var t = (a-b);
 return a - (t & (t >> 31));
}

var
input = '';
  
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7644
s = input()
t = []
for i in range(len(s)):
    if s[i] == "0":
        t.append('0')
    elif s[i] == "1":
        t.append('1')
    else:
        if len(t) != 0:
            del t[-1]
w = ''.join(t)
print(w)

Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d\n", &n);
    while (n > 0)
    {
        double x, y, b, p, ret;
        scanf("%lf %lf %lf %lf\n", &x, &y, &b, &p);
        ret = x * b + y * p;
        if (5 <= b && 2 <= p)
        {
            printf("%.0lf\n", 80 * ret / 100);
        }
        else if (5 <= b && p < 2)
        {
            printf("%.0lf\n", min((b * x + 2.0 * y) * 4 / 5, ret));
        }
        else if (2 <= p && b < 5)
        {
            printf("%.0lf\n", min((5.0 * x + p * y) * 4 / 5, ret));
        }
        else
        {
            printf("%.0lf\n", min((5.0 * x + 2.0 * y) * 80 / 100, ret));
        }
        n--;
    }
    return 0;
}


Measured memory_bytes: 2708
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	int[] a = new int[N];
	for (int i = 0; i < N; i++) {
	    a[i] = scan.nextInt();
	}
	int anser = 0;
	for (int i = 0; i < N; i++) {
	    while(a[i] % 2 == 0) {
		a[i] = a[i] / 2;
		anser++;
	    }
	}
	System.out.println(anser);
    }
}


Measured memory_bytes: 34528
module Main (main) where
  
import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  print . showAnswer $ solve n

type Input  = (Int)
type Output = Bool

solve :: Input -> Output
solve = cmp . show

cmp :: String -> Bool
cmp cs = (cs !! 0) == cs !! 2

showAnswer :: Output -> Answer
showAnswer = YesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool

instance Show Answer where
  show (YesNo b) = if b then "Yes" else "No"

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------
set<ll> listDivisors(ll n) {
  set<ll> divs;
  repi(i, 1, (ll)(sqrt(n) + 1)) {
    if (n % i == 0) {
      divs.insert(i);
      divs.insert(n / i);
    }
  }
  return divs;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  int count = 0;

  for (int i = 1; i <= n; i += 2) {
    auto divs = listDivisors(i);
    if (divs.size() == 8) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}



void solve()
{
    string s, t;
    cin>>s>>t;

    int n=s.size();
    int m=t.size();
    vector<int> pref_s(n+1);
    for(int i=1;i<=n;i++)
        pref_s[i] = pref_s[i-1] + (s[i-1]=='A');

    vector<int> pref_t(n+1);
    for(int i=1;i<=m;i++)
        pref_t[i] = pref_t[i-1] + (t[i-1]=='A');
    int q;
    cin>>q;

    for(int i=0;i<q;i++)
    {
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        int len1 = b-a+1;
        len1+= (pref_s[b]-pref_s[a-1]);
        int len2 = d-c+1;
        len2+= (pref_t[d]-pref_t[c-1]);
        if((len1-len2)%3==0)
        {
            cout<<"YES"<<endl;
        }
        else
            cout<<"NO"<<endl;
    }
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 2512
a, b, k = map(int, input().split())
if b - a + 1 >= 2 * k:
  for i in range(a, a+k):
    print(i)
  for i in range(b-k+1, b+1):
    print(i)
else:
  for i in range(a, b+1):
    print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,k;
vector<vector<int> > f,e;

struct node{
  int id,ty;
  node(){}
  void init(int x,int y){
    id=x;
    ty=y;
  }
  bool operator<(const node& a)const{
    for(int i=0;i<k;i++){
      if(f[id][e[ty][i]]!=f[a.id][e[ty][i]]) return f[id][e[ty][i]]>f[a.id][e[ty][i]];
    }
    return 0;
  }
};
node nodes[24][114514];
vector<int> G[114514];
set<node> ns[24];
signed main(){
  cin>>n>>k;
  f.resize(n,vector<int>(k));
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
      //cin>>f[i][j];
      scanf("%d",&f[i][j]);
    }
  }
  int d;
  cin>>d;

  int indeg[n];
  memset(indeg,0,sizeof(indeg));
  for(int i=0;i<d;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    indeg[b]++;
  }
  map<vector<int>,int> m;
  vector<int> v(k);
  for(int i=0;i<k;i++) v[i]=i;
  int cnt=0;
  do{
    for(int i=0;i<n;i++){
      nodes[cnt][i].init(i,cnt);
    }
    e.push_back(v);
    m[v]=cnt++;
  }while(next_permutation(v.begin(),v.end()));

  for(int j=0;j<cnt;j++){
    for(int i=0;i<n;i++){
      if(indeg[i]==0) ns[j].insert(nodes[j][i]);
      //if(indeg[i]==0) cout<<":"<<i<<endl;
    }
  }

  for(int i=0;i<k;i++) cin>>v[i],v[i]--;
  //cout<<m.count(v)<<endl;
  int ans=0,idx=m[v];
  //cout<<idx<<endl;
  
  int r;
  cin>>r;
  while(r--){
    int p;
    cin>>p;
    while(ans<p){
      int id=(ns[idx].begin())->id;
      for(int i=0;i<cnt;i++){
	//ns[i].insert(nodes[i][id]);
	//cout<<id<<":"<<ns[i].count(nodes[i][id])<<endl;
	//cout<<ns[i].size()<<" "<<ns[i].begin()->id<<endl;
	//cout<<(*ns[i].begin()==nodes[i][id])<<endl;
	ns[i].erase(nodes[i][id]);
      }
      for(int u:G[id]){
	indeg[u]--;
	if(indeg[u]==0){
	  for(int i=0;i<cnt;i++){
	    ns[i].insert(nodes[i][u]);
	  }
	}
      }
      //cout<<id+1<<endl;
      printf("%d\n",id+1);
      ans++;
    }
    for(int i=0;i<k;i++) cin>>v[i],v[i]--;
    idx=m[v];
    //cout<<idx<<endl;
  }
  while(ans<n){
    int id=ns[idx].begin()->id;
    for(int i=0;i<cnt;i++){
      //cout<<":"<<ns[i].count(nodes[i][id])<<endl;
      ns[i].erase(nodes[i][id]);
    }
    for(int u:G[id]){
      indeg[u]--;
      if(indeg[u]==0){
	for(int i=0;i<cnt;i++){
	  ns[i].insert(nodes[i][u]);
	}
      }
    }
    //cout<<id+1<<endl;
    printf("%d\n",id+1);
    ans++;
  }
  return 0;
}

Measured memory_bytes: 74312
#include<string>
#include<iostream>
using namespace std;
long long N;
int main()
{
	cin>>N;
	for (long long h=1;h<=3500;++h)
		for (long long n=1;n<=3500;++n){
			long long a=N*h*n;
			long long b=4*h*n-N*h-N*n;
			if (b<1) continue;
			if (a%b==0){
				cout<<h<<' '<<n<<' '<<a/b;
				return 0;
			}
		}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int a;
    string s;
    cin>>a>>s;

    cout<<(a >= 3200 ? s : "red")<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    long long A[N];
    long long Yama0=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        Yama0+=A[i];
    }
    Yama0/=2;
    for(int i=1; i<N; i+=2){
        Yama0-=A[i];
    }
    cout << Yama0*2 << " ";
    for(int i=0; i<N-1; i++){
        Yama0 = A[i] - Yama0;
        cout << Yama0*2 << " ";
    }
    return 0;
}

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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n), d(n);
    cin >> h;
    sort(h.begin(), h.end());
    int ans = numeric_limits<int>::max();
    for (int i = k-1; i < n; i++) {
        ans = min(ans, h[i] - h[i-k+1]);
    }
    cout << ans << '\n';
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

ll N;
string S;
const ll K=6;
ll A[6][250010],B[6][250010];
vector<ll> C[250010];
map<vector<ll>,ll> cnt;

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

  vector<ll> xs{452,8112,5734,56343,8766754,64537};

  cin>>N>>S;
  ll res=0;
  rep(k,K)A[k][N]=1;
  rep(k,K)C[N].push_back(0);
  for(ll j=N-1;j>=0;j--){
    rep(i,K){
      if(S[j]=='+'){
        A[i][j]=A[i][j+1];
        B[i][j]=(B[i][j+1]+1)%mod;
      }else if(S[j]=='-'){
        A[i][j]=A[i][j+1];
        B[i][j]=(B[i][j+1]+mod-1)%mod;
      }else if(S[j]=='>'){
        A[i][j]=A[i][j+1]*mod_pow(xs[i],mod-2)%mod;
        B[i][j]=B[i][j+1]*mod_pow(xs[i],mod-2)%mod;
      }else if(S[j]=='<'){
        A[i][j]=A[i][j+1]*xs[i]%mod;
        B[i][j]=B[i][j+1]*xs[i]%mod;
      }
      C[j].push_back(B[i][j]*mod_pow(A[i][j],mod-2)%mod);
    }
  }

  for(ll i=N;i>=0;i--){
    vector<ll> nc;
    rep(k,K){
      nc.push_back(((B[k][i]-B[k][0]+mod)%mod)*mod_pow(A[k][i],mod-2)%mod);
    }

    res+=cnt[nc];
    cnt[C[i]]++;
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 119700
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAXN = 1024;
int a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];

bool used_red[MAXN];

int main() {
    int n; cin>>n;
    for(int i = 0; i < n; ++i) {
        cin>>a[i]>>b[i];
    }
    for(int i = 0; i < n; ++i) {
        cin>>c[i]>>d[i];
    }

    vector<pair<int,int> > v;
    for(int i = 0; i < n; ++i) {
        v.push_back(pair<int,int>(c[i], d[i]));
    }
    sort(v.begin(), v.end()); // 0,1,2,...

    fill(used_red, used_red + MAXN, false);
    int res = 0;
    for(int i = 0; i < n; ++i) {
        int x = v[i].first;
        int y = v[i].second;
        vector<pair<int,int> > vv;
        for(int j = 0; j < n; ++j) {
            if(used_red[j]) continue;
            if(a[j] >= x) continue;
            vv.push_back(pair<int,int>(b[j], j));
        }
        sort(vv.begin(), vv.end(), greater<pair<int,int> >()); // 99,98,...
        for(int j = 0; j < (int)vv.size(); ++j) {
            int yy = vv[j].first;
            int k = vv[j].second;
            if(yy >= y) continue;
            used_red[k] = true;
            ++res;
            break;
        }
    }
    cout << res << endl;
    return 0;
}


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

namespace _0074
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int[] items = RIntAr();
                if (items.All(x => x == -1)) break;

                TimeSpan remaining = new TimeSpan(2, 0, 0) - new TimeSpan(items[0], items[1], items[2]);
                TimeSpan remaining_3 = new TimeSpan(remaining.Ticks * 3);

                Console.WriteLine(remaining.ToString((@"hh\:mm\:ss")));
                Console.WriteLine(remaining_3.ToString((@"hh\:mm\:ss")));
            }
        }

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

}



Measured memory_bytes: 14312
#import <stdio.h>
#import <limits.h>
#define INT long long
#define MIN(a,b) ((a)<(b)?(a):(b))
INT Q,H,S,D,N;
INT f(INT y, INT z, INT w){
    if (y+2*z+4*w>2*N) {
        return LONG_MAX;
    }
    return 4*Q*N + (H-2*Q)*y + (S-4*Q)*z + (D-8*Q)*w;
}
int main(){
    scanf("%lld %lld %lld %lld %lld",&Q,&H,&S,&D,&N);
    INT min = f(0,0,0);
    min = MIN(min, f(2*N,0,0));
    min = MIN(min, f(2*N,0,1));
    min = MIN(min, f(2*N,1,0));
    min = MIN(min, f(0,N,0));
    min = MIN(min, f(1,N,0));
    min = MIN(min, f(0,N,1));
    min = MIN(min, f(0,0,N/2));
    min = MIN(min, f(1,0,N/2));
    min = MIN(min, f(2,0,N/2));
    min = MIN(min, f(3,0,N/2));
    min = MIN(min, f(0,1,N/2));
    min = MIN(min, f(0,2,N/2));
    min = MIN(min, f(0,3,N/2));
    min = MIN(min, f(1,1,N/2));
    min = MIN(min, f(1,2,N/2));
    min = MIN(min, f(2,1,N/2));
    min = MIN(min, f(2,2,N/2));
    printf("%lld",min);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i=0; i<N; i++) {
  	cin >> card.at(i);
  }
  
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int alice = 0;
  int bob = 0;
  for (int i=0; i < N; i++) {
    if (i%2 == 0) {
      alice += card.at(i);
    }
    else if (i%2 == 1) {
      bob += card.at(i);
    }
  }
  
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

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

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

X, Y, A, B, C = MII_split()
p_list = LII_split()
q_list = LII_split()
r_list = LII_split()

prices = sorted(p_list, reverse=True)[0:X] + sorted(q_list, reverse=True)[0:Y] + r_list
prices = sorted(prices, reverse=True)
# print(prices)
print(sum(prices[0:X + Y]))

Measured memory_bytes: 23328
#include <stdio.h>
#include <string.h>
#define slmt 101    /*slmt:手札文字数限界*/
#define winp 3    /*winp:勝利時加算ポイント*/
#define drowp 1    /*drowp:引き分け時加算ポイント*/

int main(void){
    char tarou[slmt], hanako[slmt];    /*tarou:太郎手札, hanako:花子手札*/
    int times, x;    /*times:ゲーム回数, x:ループ変数*/
    int twin=0, hwin=0;    /*twin:太郎勝利回数, hwin:花子勝利回数*/
    
    /*入力部*/
        scanf("%d\n", &times);    /*ゲーム回数を読み取る*/
        /*ゲーム状況の読み込みは判定とともに行う*/
        
    /*判定部*/
        for(x=0; times>x; x++){    
            scanf("%s %s\n", &tarou, &hanako);    /*ゲーム状況読み込み*/
            if (strcmp(&tarou, &hanako) > 0){    /*勝敗判定＆ポイント加算*/
                twin += winp;    /*太郎勝利加算*/
            }else if (strcmp(&tarou, &hanako) < 0){
                hwin += winp;    /*花子勝利加算*/
            }else{
                twin += 1;    /*引き分け加算*/
                hwin += 1;
            }
        }
        
    /*出力部*/
        printf("%d %d\n", twin, hwin);    /*各ポイントを1行出力*/
        
    return 0;
}

Measured memory_bytes: 608
n,m = map(int,input().split())

#赤フラグ 玉の個数
arr = [1 for _ in range(n)]
arr1 = [False for _ in range(n)]
arr1[0]=True
ch1 = True

for i in range(m):
    x,y = map(int,input().split())
    x = x-1
    y = y-1
    if ch1 == True and x == 0:
        ch1 = None
        arr[y] +=1
        arr1[y] = True
        arr[x] -=1
        if arr[x] == 0:
            arr1[x] = False
        continue
    
    arr[y] +=1
    arr[x] -=1
    if ch1 == None and arr1[x] == True:
        
        arr1[y] = True
        
    if ch1 == None and arr[x] == 0:
        arr1[x] = False

cnt=0
for i in range(n):
    if arr1[i] == True:
        cnt +=1   
print(cnt)

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

using namespace std;

const int INF = 1e9 + 5;
const int N = 1e5;
const int MOD = 998244353;
const double EPS = 1e-9;

const double PI = acos(-1);

set<int> gr[N + 1];
bool used[N + 1];
int ans[N + 1];

void bfs() {
    queue<pair<int, int>> que;
    que.push({1, 0});
    used[1] = 1;
    while (!que.empty()) {
        int cur = que.front().first, val = que.front().second;
        que.pop();
        if (!ans[cur])
            ans[cur] = val;
        for (int x : gr[cur]) {
            if (!used[x]) {
                que.push({x, cur});
                used[x] = 1;
            }
        }
    }
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        gr[x].insert(y);
        gr[y].insert(x);
    }
    bfs();
    bool ok = 1;
    for (int i = 2; i <= n; i++)
        ok &= used[i];
    if (!ok) {
        cout << "No";
        return 0;
    }
    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++)
        cout << ans[i] << endl;
}

Measured memory_bytes: 27912
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int N,cnt=0,i,j,x,y;
  int dx[2]={-1,1};
  int dy[2]={1,-1};
  int dir;
  while(cin>>N,N){
    vector< vector<int> >field(N,vector<int>(N));
    cnt++;
    cout<<"Case "<<cnt<<":"<<endl;
    x=y=dir=0;
    for(i=1;i<=N*N;i++){
      field[x][y]=i;
      if(x+dx[dir]<0 && N<=y+dy[dir]){
	x++;
	dir^=1;
      }else if(N<=x+dx[dir] && y+dy[dir]<0){
	y++;
	dir^=1;
      }else if(x+dx[dir]<0){
	y++;
	dir^=1;
      }else if(N<=y+dy[dir]){
	x++;
	dir^=1;
      }else if(N<=x+dx[dir]){
	y++;
	dir^=1;
      }else if(y+dy[dir]<0){
	x++;
	dir^=1;
      }else{
	x+=dx[dir];y+=dy[dir];
      }
    }
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
	printf("%3d",field[i][j]);
      }
      puts("");
    }
  }
}

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

bool f[200005];

int main(){
  ll n,k;
  cin>>n>>k;
  int a[200005];
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  vector<int> v;
  int now=0;
  f[now]=true;
  v.push_back(now);
  int cnt=1;
  while(1){
    now=a[now];
    if(f[now]) break;
    v.push_back(now);
    f[now]=true;
    cnt++;
  }
  vector<int> v2;
  bool flag=false;
  rep(i,v.size()){
    if(now==v[i]) flag=true;
    if(flag) v2.push_back(v[i]);
  }
  int ans=(int)((k-(cnt-v2.size()))%(ll)v2.size());
  /*rep(i,v2.size()){
    cout<<v2[i]<<endl;
    }*/
  if(cnt>k) cout<<v[k]+1<<endl;
  else cout<<v2[ans]+1<<endl;
  return 0;
}


Measured memory_bytes: 6604
N = int(input())

CSF = []
for _ in range(N-1):
  C, S, F = map(int, input().split())
  CSF.append((C, S, F))

def cnt(x):
  ret = 0
  for i in range(x, N-1):
    C, S, F = CSF[i]
    if ret < S:
      ret = S
      ret += C
    else:
      ret = -(-ret//F)*F
      ret += C
  return ret

for x in range(N):
  print(cnt(x))

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int h,w;
    cin >>h>>w;
    vector<vector<char>> c(h,vector<char> (w,'.'));
    vector<vector<bool>> reach(h,vector<bool> (w,false));
    queue <pair<int,int>> q;
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
            if(c[i][j]=='#'){
                q.push(make_pair(i,j));
            }
        }
    }
    int count=0;
    int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
    while(!q.empty()){
        bool ans = true;
        bool Br = false;
        rep(k,h){
            rep(l,w){
                
                if(c[k][l]=='.'){
                    ans = false;
                    Br = true;
                    break;
                }
                
               //cout << c[k][l];
            }
            //cout<<endl;
            if(Br){
                break;
            }
        }
        if(ans){
            break;
        }
        int size = q.size();
        for (int i = 0; i < size; i++)
        {
            pair<int, int> p = q.front();
            q.pop();
            rep(j, 4)
            {
                int ny = p.first + dy[j];
                int nx = p.second + dx[j];
                if (nx < 0 || ny < 0 || nx >= w || ny >= h)
                {
                    continue;
                }
                else if (c[ny][nx] == '#')
                {
                    continue;
                    //もう黒
                }
                else
                {
                    c[ny][nx] = '#';
                    //cout <<"dis["<<ny<<"]["<<nx<<"]="<<dis[ny][nx]<<endl;
                    q.push(make_pair(ny, nx));
                    //新しく確定マスをキューに入れる
                }
            }
        }
        count++;

        //cout <<"__________"<<endl;

    }
    cout << count<<endl;
}

Measured memory_bytes: 9616
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    priority_queue<int> neg;
    priority_queue<int, vector<int>, greater<int>> pos;
    int z = 0;
    rep(i, n){
        if(a[i] > 0) pos.push(a[i]);
        else if(a[i] < 0) neg.push(a[i]);
        else z++;
    }

    if(z == n){
        cout << 0 << endl;
        rep(i, n-1){
            cout << 0 << " " << 0 << endl;
        }
        return 0;
    }

    vector<pair<int, int>> ans;
    if(pos.empty()){
        if(z > 0){
            ans.push_back(make_pair(0, neg.top()));
            pos.push(-neg.top());
            neg.pop();
            z--;
        }else{
            int a1 = neg.top(); neg.pop();
            int a2 = neg.top(); neg.pop();
            ans.push_back(make_pair(a1, a2));
            pos.push(a1 - a2);
        }
    }
    if(neg.empty() && pos.size() > 1){
        if(z > 0){
            ans.push_back(make_pair(0,pos.top()));
            neg.push(-pos.top());
            pos.pop();
            z--;
        }else{
            int a1 =pos.top();pos.pop();
            int a2 =pos.top();pos.pop();
            ans.push_back(make_pair(a1, a2));
            neg.push(a1 - a2);
        }
    }

    while(pos.size() > 1){
        int p1 = pos.top(); pos.pop();
        int n1 = neg.top(); neg.pop();
        ans.push_back(make_pair(n1, p1));
        neg.push(n1 - p1);
    }
    while(!neg.empty()){
        int p1 = pos.top(); pos.pop();
        int n1 = neg.top(); neg.pop();
        ans.push_back(make_pair(p1, n1));
        pos.push(p1 - n1);
    }
    rep(i, z){
        ans.push_back(make_pair(pos.top(), 0));
    }
    cout << pos.top() << endl;
    repe(i, ans){
        cout << i.first << " " << i.second << endl;
    }


}

Measured memory_bytes: 3700
#include<stdio.h>

int main()
{
    int i,n,r,n1,j,n2,count=0;
    while(scanf("%d %d",&n1,&n2)==2){
        n=n1+n2;
        count=0;
        while(n!=0){
            r=n%10;
            count++;
            n=n/10;
        }
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 600
t=0
h=0
n=input()
for _ in range (n):
	s = raw_input().split()
	if s[0] > s[1]:
		t+=3
	elif s[0] < s[1]:
		h+=3
	else:
		t+=1
		h+=1
print str(t) + " " + str(h)


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

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll n , k;
ll prt[maxn] , pos[maxn];
ll a[maxn];

int main(){
    migmig
    ll ans = 0;
    cin >> n >> k;
    for(int i = 1 ; i <= n ; i ++)
		cin >> a[i] , prt[i] = prt[i-1] + a[i] , pos[i] = pos[i-1]+max(0LL , a[i]);
    for(int i = 1 ; i <= n - k + 1 ; i ++){
		ll val = prt[i+k-1] - prt[i-1];
		ll ps  = pos[i+k-1] - pos[i-1];
		ans = max(ans , val + pos[n] - ps);
		ans = max(ans , pos[n] - ps);
	}
    cout << ans;
    return(0);
}

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

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

    map<int, int> k;
    int flag = 0;
    pair<int, int> p;
    int ve[n];
    for(int i = 0; i < n; i++){
        ve[i] = -1;
    }
    for(int i = 0; i < m; i++){
        cin >> p.first >> p.second;
        auto itr = k.find(p.first);
        if(itr == k.end()){
            k.insert(p);
            ve[p.first - 1] = p.second;
        }else{
            if(itr->second != p.second){
                flag = 1;
                break;
            }
        }
    }
    string ans;
    if(flag != 1){
        for(int i = 0; i < n; i++){
            string w = to_string(ve[i]);
            if(w == "-1"){
                if(i == 0){
                    if(n == 1){
                        ans += "0";
                    }else{
                        ans += "1";   
                    }
                }else{
                    ans += "0";
                }
            }else{
                ans += w;
            }
        }
    }

    if(ans[0] == '0' && n != 1){
        ans = "-1";
    }
    if(flag == 1){
        ans = "-1";
    }

    cout << ans << endl;
}

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

int main()
{
	int nArrIn[10] = { 0 };
	int n = 0;
	while (n < 10)
	{
		cin >> nArrIn[n];
		n++;
	}
	sort(nArrIn, nArrIn + 10);
	cout << nArrIn[9] << endl;
	cout << nArrIn[8] << endl;
	cout << nArrIn[7] << endl;
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
	int n,m;cin>>n>>m;
	int ans=n*(n-1)/2;
	ans+=m*(m-1)/2;
	cout<<ans;



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())

#単語が全て入ったリストを作るO(n)
wordlist=[input() for i in range(n)]

#wordlistを一つ一つソートさせたものをsortlistとして作るO（n）
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    sortlist.append(a)
    
count=0

#ソートリストをソートするO(nlogn)
sortlist.sort()

checkword=""
check=0

for i in range(n): #O(n)
    a=sortlist.pop()
    if checkword==a:
            check+=1
            count+=check
    else:
        check=0
        checkword=a
    
print(int(count) )   

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int cnt[N + 1];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n, m;
    cin >> n >> m;
    int r = 0, w = 0;
    FOR(i, 1, m)
    {
        string y;
        int x;
        cin >> x >> y;
        if(cnt[x] == -1) continue;
        if(y == "WA" && cnt[x] != -1)
        {
            //cnt[x] = "WA";
            cnt[x]++;
        }
        else
        if(y == "AC" && cnt[x] != -1)
        {
            w += cnt[x];
            cnt[x] = -1;
            r++;
        }
        //cout << r << " " << w << endl;
    }
    cout << r << " " << w;
    return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split())

Map = [['0']*W]*H

for i in range(H):
    Map[i] = list(input())
    
for i in range(H):
    for j in range(W):
        bomb = 0
        if Map[i][j] == '.':
            if i-1>=0 and  j-1>=0 and Map[i-1][j-1] == '#':
                bomb+=1
            if i-1>=0 and  Map[i-1][j] == '#':
                bomb+=1
            if i-1>=0 and  j+1<W and Map[i-1][j+1] == '#':
                bomb+=1
            if j+1<W and Map[i][j+1] == '#':
                bomb+=1
            if i+1<H and  j+1<W and Map[i+1][j+1] == '#':
                bomb+=1
            if i+1<H and Map[i+1][j] == '#':
                bomb+=1
            if i+1<H and  j-1>=0 and Map[i+1][j-1] == '#':
                bomb+=1
            if j-1>=0 and Map[i][j-1] == '#':
                bomb+=1
            Map[i][j] = str(bomb)
        
for i in range(H):
    print(''.join(Map[i]))

Measured memory_bytes: 3188
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    A = list( map( int, input().split()))
    now = 1
    for a in A:
        now *= a
    ans = now
    q = 0
    for a in A:
        q += now//a
    print(ans/q)
if __name__ == '__main__':
    main()


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

using namespace std;

int main(void) {
	int n;
	cin >> n;
	int m = (int)sqrt(n);
	cout << n << ":";
	for(int i = 2;i <= m;i++) {
		while(n % i == 0) {
			cout << " " << i;
			n = n / i;
		}
	}
	if(n != 1) cout << " " << n;
	cout << endl;
}


Measured memory_bytes: 3092
program prob3
    implicit none
    integer(8)::W, H, x, y
    real(16):: xm,ym, ans
    read(*,*) W, H, x, y
    xm = real(W,kind=16)/2.0_16
    ym = real(H,kind=16)/2.0_16

    ans = real(H*W,kind=16)/2.0_16
    if(mod(W,2)==0 .and. mod(H,2)==0)then
        if(x == W/2 .and. y == H/2)then
            write(*,*) ans, 1
            stop
        end if
    end if

    write(*,*) ans,0

    stop
end program

Measured memory_bytes: 2856
#include<stdio.h>

int main(void) {
	char S[4];
	int i = 0;

	scanf("%s", S);

	while ('\0' != S[i]) {
		if (('A' != S[i]) && ('B' != S[i])) {
			return 0;
		}
		i++;
	}

	if (3 != i) {
		return 0;
	}

	if (('A' == S[0]) && ('A' == S[1]) && ('A' == S[2])) {
		printf("No\n");
		return 0;
	}
	else if (('B' == S[0]) && ('B' == S[1]) && ('B' == S[2])) {
		printf("No\n");
		return 0;
	}
	else {
		printf("Yes\n");
		return 0;
	}
}

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

int main() {
  int N; cin >> N;
  int ans = 1;
  for ( int i = 1; i*i <= N; i++ ) {
    ans = max(ans,i*i);
  }
  cout << ans << endl;
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

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

	cout<<n/(a+b)*a+min(n%(a+b),a)<<endl;


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS



    int n,k;
    cin >> n >> k;

      cout << min({n,abs(n%k),abs(k-n%k)});
    

    


    return 0; 
}


Measured memory_bytes: 3652
N,K=map(int,input().split())
S=input()+"2"
_list=[]
if S[0]=="1":
    _list=[]
else:
    _list=[0]
cnt=1
for i in range(N):
    if S[i]==S[i+1]:
        cnt+=1
    else:
        _list.append(cnt)
        cnt=1
if S[-2]=="0":
    _list.append(0)
import itertools
__list=[0]+list(itertools.accumulate(_list))
C=len(__list)
K=min(C,K)
if (C+1)//2<=K:
    print(__list[-1])
else:
    print(max([__list[2*i+2*K+1]-__list[2*i] for i in range((C+1)//2-K)]))


Measured memory_bytes: 9412
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		int[][] a=new int[h+1][w+1];
		int[][] b=new int[h+1][w+1];
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				a[i][j]=sc.nextInt();
			}
		}
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				b[i][j]=sc.nextInt();
			}
		}
		boolean[][][] dp=new boolean[h+1][w+1][160*80];
		dp[1][1][Math.abs(a[1][1]-b[1][1])]=true;
		for(int j=1; j<=h; j++){
			for(int t=1; t<=w; t++){
				int k1=Math.abs(a[j][t]-b[j][t]);
				for(int i=0; i<160*80; i++){
					if(j-1>=1 && dp[j-1][t][i]){
						dp[j][t][Math.abs(i-k1)]=true;
						dp[j][t][i+k1]=true;
					}else if(t-1>=1 && dp[j][t-1][i]){
						dp[j][t][Math.abs(i-k1)]=true;
						dp[j][t][i+k1]=true;
					}
				}
			}
		}
		for(int i=0; i<160*80; i++){
			if(dp[h][w][i]){
				System.out.println(i);
				break;
			}
		}
	}
}


Measured memory_bytes: 158824
N, M = map(int,input().split())
drinks = []
for _ in range(N):
    drinks.append(list(map(int,input().split())))
drinks.sort()
rest = M
ans = 0
i = 0
while rest != 0:
    temp = min(rest, drinks[i][1])
    ans += drinks[i][0] * temp
    rest -= temp
    i += 1
print(ans)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	vector<ll>x,y;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		x.push_back(now);
	}
	sort(x.begin(),x.end());
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		y.push_back(now);
	}
	sort(y.begin(),y.end());
	reverse(y.begin(),y.end());
    ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right =INF; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        ll mid = left + (right - left) / 2;
        ll cnt=0;
        for(ll i=0;i<n;i++){
        	cnt+=max(ll(0),(x[i]*y[i]-mid+y[i]-1)/y[i]);
        }
        if (cnt<=k) right = mid;
        else left = mid;
    }
    cout << right;
    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return 0;
}

Measured memory_bytes: 4848
#include <iostream>

using namespace std;

int main() {
  int y = 0;
  for (int i = 0; i < 4; i++) {
    int s;
    cin >> s;
    y += s;
  }
  int x = y / 60;
  y %= 60;
  cout << x << endl << y << endl;
  return 0;
}


Measured memory_bytes: 3088