akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    vector<vector<int>> cl(n, vector<int>(26, -1));
    cl[n - 1][s[0] - 'a'] = 0;
    for (int i = n - 2; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) {
            cl[i][j] = cl[i + 1][j];
        }
        cl[i][s[i + 1] - 'a'] = i + 1;
    }
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) {
            if (cl[i][j] == -1) {
                cl[i][j] = cl[0][j];
            }
        }
    }
    int64_t res = 0;
    int prev = n - 1;
    for (int i = 0; i < m; ++i) {
        int val = cl[prev][t[i] - 'a'];
        if (val == -1) {
            cout << "-1\n";
            return;
        }
        val -= prev;
        if (val <= 0) {
            val += n;
        }
 //       cout << val << endl;
        res += val;
        prev = cl[prev][t[i] - 'a'];///(val - 1) % n;
        if (prev < 0) {
            prev += n;
        }
     }
    cout << res << endl;
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}


Measured memory_bytes: 13904
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n>k)
    cout<< ((k*x)+(n-k)*y)<<"\n";
    else
          cout<< (n*x)<<"\n";
    return 0;
}



Measured memory_bytes: 256
while True:
    (H, W) = [int(x) for x in input().split()]
    if H == W == 0:
        break
   
    for hc in range(H):
        if hc == 0 or hc == H -1:
            print('#' * W)
        else:
            print('#' + '.' * (W -2) + '#')
    print()

Measured memory_bytes: 7652
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.array;

void main() {
    auto tmp = readln.split.map!(s => s.chomp[0]).array;
    auto X = tmp[0];
    auto Y = tmp[1];
    writeln(X == Y ? "=" : X < Y ? "<" : ">");
}

Measured memory_bytes: 256
from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rev_a = list(reversed(a))
ans = 0
accumulation_gcd = [0] * n
rev_accumulation_gcd = [0] * n
accumulation_gcd[0] = a[0]
rev_accumulation_gcd[0] = rev_a[0]

for i in range(1, n):
    accumulation_gcd[i] = f.gcd(a[i], accumulation_gcd[i-1])
    rev_accumulation_gcd[i] = f.gcd(rev_a[i], rev_accumulation_gcd[i-1])

rev_accumulation_gcd.reverse()


for i in range(n):
    if i == 0:
        ans = max(ans, rev_accumulation_gcd[1])
    elif i == (n - 1):
        ans = max(ans, accumulation_gcd[n-2])
    else:
        ans = max(ans, f.gcd(accumulation_gcd[i-1], rev_accumulation_gcd[i+1]))

print(ans)


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

int main()
{
	int a,b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main( ){
  int ans=0,h,w,k,i,j,x,y,count=0;
  cin>>h>>w>>k;
  string s[h];
  for(i=0;i<h;i++){
    cin>>s[i];
  }
  int mask;
  for(i=0;i<(1<<h)-1;i++){
    for(j=0;j<(1<<w)-1;j++){
      count=0;
      for(x=0;x<h;x++){
        for(y=0;y<w;y++){
          if(((i&(1<<x))||(j&(1<<y)))!=0){
            continue;
          }
          if(s[x][y]=='#'){
            count+=1;
          }
        }
      }
      if(count==k){
        ans+=1;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

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

constexpr int MX=2005;

using namespace std;

int main(){
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(s.begin(), s.end());
  
  int ret = 3 *MX;
  do{
    bool bPosOK[3][3][MX];
    REP(i,3)REP(j,3)REP(k,s[i].size()){
      bool bOK = true;
      if(i >= j) continue;
      for(int l=k; l<s[i].size();l++){
        int ni = l;
        int nj = ni - k;
        if (nj >= s[j].size()) break;
        if (s[i][ni] == '?' || s[j][nj] == '?') continue;
        if (s[i][ni] == s[j][nj]) continue;
        bOK = false;
        break;
      }
      bPosOK[i][j][k] = bOK;
    }
    
    auto isOK = [&](int i, int j, int k){
      if (k >= s[i].size()) return true;
      return bPosOK[i][j][k]; 
    };
    
    REP(x,MX)REP(y,MX){
      if(!isOK(0, 1, x)) continue;
      if(!isOK(1, 2, y)) continue;
      if(!isOK(0, 2, x+y)) continue;
      
      int length = 0;
      length = max<int>(length, s[0].size());
      length = max<int>(length, x + s[1].size());
      length = max<int>(length, x + y + s[2].size());
      
      ret = min(ret, length);
    }
  }while(next_permutation(s.begin(), s.end()));
  
  cout << ret;
  return 0;
  
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

int main(){
  int s;
  cin >> s;
  vector<int> v;
  int now=s;
  bool ok=false;
  while(!ok){
   for(int i=0;i<v.size();i++){
    if(now==v[i]){
      ok=true;
      cout << v.size()+1 << endl;
    }
   }
    v.push_back(now);
    if(now%2==0){
     now/=2; 
    }else now=3*now+1;
  }
return 0;}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int num,i;
    int ans[11];

    while(scanf("%d",&num),num+1){
        
        if(num==0){
            puts("0");
            continue;
        }

        for(i=0;num;i++){
            ans[i]=num%4;
            num/=4;
        }

        for(i--;i>=0;i--){
            printf("%d",ans[i]);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n,t,a,h[1000],ans=1;
	double avet,avet1;
	cin>>n>>t>>a;
	for (int i = 0; i < n; i++){
		cin>>h[i];
	}

	avet=t-h[0]*0.006;
	for (int i = 1; i < n; i++){
		avet1=t-h[i]*0.006;
		if(abs(avet1-a)<abs(avet-a)){
			avet=avet1;
			ans=i+1;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int N;
  cin >> N;
  vector<pair<int, int>> e;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e.emplace_back(a, b);
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  int K = 0;
  map<pair<int, int>, int> ans;
  vector<int> used(N, 0);
  vector<int> cs(N, 0);
  queue<int> que;
  que.emplace(0);
  used[0] = 1;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    int cur = 1;
    for (int u : G[v]) {
      if (used[u]) continue;
      if (cs[v] == cur) cur++;
      cs[u] = ans[make_pair(u, v)] = ans[make_pair(v, u)] = cur++;
      K = max(cs[u], K);
      used[u] = 1;
      que.emplace(u);
    }
  }
  cout << K << endl;
  for (auto p : e) cout << ans[p] << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}


Measured memory_bytes: 20088
import math

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

Rc = T.count("r")
Sc = T.count("s")
Pc = len(T) - (Rc + Sc)

#print(Rc, Sc, Pc)

def check(x):
  global Rc, Sc, Pc
  if x == "r":
    Rc -= 1
  elif x == "s":
    Sc -= 1
  else:
    Pc -= 1

a, b = divmod(N, K)
T = list(T + "x"*(K - b))

#print(T)

for i in range(K):
  Flag = False
  for j in range(1, a+1):
    if T[i + K*j] == T[i + K*(j-1)]:
      if Flag:
        Flag = False
      else:
        check(T[i + K*j])
        Flag = True
    else:
      Flag = False
  #print(Rc, Pc, Sc)

print(Rc * P + Sc * R + Pc * S)


Measured memory_bytes: 4852
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		for(int i = 0; i < n; i++){

			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == b * b + a * a )
			{ System.out.println("YES");
			} else {
				System.out.println("NO");
			}

		}
	}
}

Measured memory_bytes: 33828
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

zero = sum(A % 2 != 0)  # 2で割りきれない数
four = sum(A % 4 == 0)  # 4で割りきれる数
two = sum(np.logical_and(A % 2 == 0, A % 4 != 0))  # 4で割り切れないが、2で割りきれる数

flag = False

if two == 0:
    if zero <= four + 1:
        flag = True
else:
    if zero <= four:
        flag = True

if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 23124
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int m = stdIn.nextInt();
        int d = stdIn.nextInt();
        int count = 0;
        for(int i = 1;i<=m;i++) {
            for(int j = 10;j<=d;j++) {
                int j1 = j%10;
                int j2 = j/10;
             if(j1>=2 && j2>=2) {
                if(i == j1*j2) {
                    //System.out.println("i:"+i);
                    //System.out.println("j:"+j);
                    count++;
                }
            }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23636
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),A=in(),B=in();
	auto X=vecin<ll>(N);

	ll S=0;
	REP(i,N-1){
		ll D=(X[i+1]-X[i])*A;
		S += min(D,B);
	}
	
	out(S);
	return 0;
}


Measured memory_bytes: 1024
n = int(input()) 
a = [int(i) for i in input().split()]
d = dict()
d[0] = 1
ans = 0
t = 0
for i in range(n):
    t += a[i]

    s = d.get(t,0)
    ans += s 
    d[t] = s+1
    
print(ans)

Measured memory_bytes: 111184
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans;
int a[101],b[101];
void read()
{
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++)
	scanf("%d",&b[i]);
	return ;
}
int main()
{
	read();
	a[1]=b[1];
	b[n]=2147483647;
	for(int i=2;i<=n;i++)
	{
		a[i] = min(b[i],b[i-1]);
	}
	for(int i=1;i<=n;i++)
	ans += a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

st = list(set(s + t))
d = dict()
for _st in st:
    d[_st] = 0

for i in range(n):
    d[s[i]] += 1
for i in range(m):
    d[t[i]] -= 1

print(max([0] + list(d.values())))


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

int main()
{
	string s;
	int cs = 0;
	cin >> s;
	int n = s.size();
	for(int i = 0; i < n/2; i++)
		if(s[i] != s[n-(1+i)]) cs++;
	cout << cs;
	return 0;
}


Measured memory_bytes: 256
F=input()
if F[0]==F[1] and F[2]==F[3] and F[0]!=F[2]:
  print('Yes')
elif F[0]==F[2] and F[1]==F[3] and F[0]!=F[1]:
  print('Yes')
elif F[0]==F[3] and F[1]==F[2] and F[0]!=F[1]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    long n = S.length;
    auto T = sread();
    {
        auto cnt = new long[]('z' - 'a' + 1);
        foreach (c; S)
            cnt[c - 'a']++;
        foreach (c; T)
            if (cnt[c - 'a'] == 0)
            {
                writeln(-1);
                return;
            }
    }
    auto next = new long[][](n, 'z' - 'a' + 1);
    auto SS = S ~ S;
    next[$ - 1][] = 0;
    next[$ - 1][S[0] - 'a'] = 1;
    foreach_reverse (i; 0 .. n * 2)
    {
        next[i % n][] = next[(i + 1) % n][] + 1;
        next[i % n][SS[i] - 'a'] = 0;
    }
    // foreach (i, r; next)
    //     writeln(i, " ", S[i], " ", r['t' - 'a']);
    // writeln();
    long cur = -1;
    foreach (c; T)
    {
        cur++;
        // writeln(cur, " ", c, " ", next[cur % n][c - 'a']);
        cur += next[cur % n][c - 'a'];
    }
    writeln(cur + 1);
}


Measured memory_bytes: 31768
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <complex>
using namespace std;
const string alpha = "abcdefghijk";

char strmax(string s){
  char mc = 'a';
  for (char c : s){
    if (c > mc){
      mc = c;
    }
  }
  return mc - 'a';
}
vector<string> super_troop(int n){
  if (n == 1){
    return {"a"};
  }
  else{
    vector<string> L = super_troop(n-1);
    vector<string> LL(0);
    for (string i : L){
      char mc = strmax(i) + 2;
      for (char k=0;k<+mc;k++){
        LL.push_back(i + alpha.at(k));
      }
    }
    return LL;
  }
}
int main(){
  int N;
  cin >> N;
  vector<string> LLL = super_troop(N);
  sort(LLL.begin(), LLL.end());
  for (int i=0;i<LLL.size();i++){
    cout << LLL.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 9164
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int n, x, t;
    cin >>n>>x>>t;
    if (n % x == 0) cout << n/x*t<<"\n";
    else cout << (n/x +1)*t<<"\n";
}


Measured memory_bytes: 3568
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<utility>
#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;
const int maxn = 2e5 + 233;
typedef long long ll;
ll pre[maxn],suf[maxn],a[maxn];
int k1[maxn],k2[maxn];
bool check(ll s1,ll s2,int v)
{
	ll t1 = abs(s1-s2-s2);
	s2 += v;
	ll t2 = abs(s1-s2-s2);
	if(t2<t1)return 1;
	return 0;
}
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[i] = x;
	}
	pre[0] = 0;
	int j = 0;
	for(int i=1;i<=n;i++)
	{
		pre[i] = pre[i-1] + a[i];
		while(check(pre[i],pre[j],a[j+1]))j++;
		k1[i] = j;
	}
	j = n+1;
	a[n+1] = suf[n+1] = 0;
	for(int i=n;i;i--)
	{
		suf[i] += suf[i+1] + a[i];
		while(check(suf[i],suf[j],a[j-1]))j--;
		k2[i] = j;
	}
	ll ans = 1LL<<60;
	for(int i=2;i<n-1;i++)
	{
		a[1] = pre[k1[i]];
		a[2] = pre[i]-pre[k1[i]];
		a[3] = suf[i+1]-suf[k2[i+1]];
		a[4] = suf[k2[i+1]];
/*		cout<<i<<"************"<<endl;
		cout<<k1[i]<<" "<<k2[i+1]<<" "<<endl;
		cout<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;*/
		sort(a+1,a+5);
		ans = min(ans,a[4]-a[1]);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> meals(M, 0);
    rep(i, N) {
        int k;
        cin >> k;
        rep(j, k) {
            int a;
            cin >> a;
            meals[a-1]++;
        }
    }
    int cnt=0;
    rep(i, M) {
        if(meals[i] == N) cnt++;
    }

    cout << cnt << endl;
    return 0;

}

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

using Pi = pair < int , int >;

const int INF = (1 << 30) - 1;

int main()
{
        int n;
        Pi dat[45];
                
        
        while ( cin >> n, n != 0 ) {
                int dp[45][4];
                int ans[45];

                for ( int i = 1; i <= n; i++ ) {
                        cin >> dat[i].second >> dat[i].first;
                }

                dat[0] = Pi(0, 0);

                sort(dat, dat + n + 1);
                fill_n(*dp, 45 * 4, INF);
                fill_n(ans, 45, INF);

                dp[0][0] = 0;

                for ( int i = 0; i < n; i++ ) {
                        for ( int j = 0; j < 4; j++ ) {
                                if ( dp[i][j] == INF ) continue;
                                int base = (j + 1) * dat[i].second;
                                int pos = 0;
                                int pcost = 0;
                                for ( int k = 1; k <= 3 && i + k <= n; k++ ) {
                                        int nextpos = dat[i + k].second;
                                        int nowtime = dat[i + k - 1].first;
                                        int nexttime = dat[i + k].first;
                                        if ( base + abs(nextpos - pos) * k <= nexttime - nowtime ) {
                                                pcost += base / (j + 1) + abs(nextpos - pos);
                                                dp[i + k][k] = min(dp[i + k][k], dp[i][j] + pcost);
                                                base = 0;
                                                pos = nextpos;
                                        } else {
                                                break;
                                        }
                                }
                        }
                }

                for ( int i = 0; i < 45; i++ ) {
                        for ( int j = 0; j < 4; j++ ) {
                                ans[i] = min(ans[i], dp[i][j]);
                        }
                }

                if ( ans[n] != INF ) {
                        cout << "OK" << " " << ans[n] + dat[n].second << endl;
                } else {
                        int i;
                        cout << "NG" << " ";
                        for ( i = 0; i < n && ans[i] != INF; i++);
                        cout << i << endl;
                }
        }
        return ( 0 );
}



Measured memory_bytes: 3056
import java.util.Scanner;

public class Main {
    private static int maximalValue(int[] A, int[] B) {
        int res = B[0] * 2;
        for (int i = 1; i < B.length; i++) {
            if (B[i] > B[i - 1]) res += B[i];
            else res = res - B[i- 1] + B[i] * 2;
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] B = new int[N-1];
        int[] A = new int[N];
        for (int i = 0; i < B.length; i++) B[i] = in.nextInt();

        System.out.println(maximalValue(A, B));
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct RangeMaximumQuery
{
    using type = ll;
    static type id() { return 0; }
    static type op(const type &l, const type &r) { return max(l, r); }
};

// segment tree
template <typename M>
class segment_tree
{
    using T = typename M::type;
    const int n;
    vector<T> data;
    int size(int n)
    {
        int res;
        for (res = 1; res < n; res <<= 1)
            ;
        return res;
    }

  public:
    segment_tree(int n_) : n(size(n_)), data(n * 2, M::id()) {}
    segment_tree(int n_, T val) : n(size(n_)), data(n * 2, val) {}
    void init(const vector<T> &data_)
    {
        for (int i = 0; i < (int)data_.size(); i++)
            data[i + n] = data_[i];
        for (int i = n - 1; i >= 0; i--)
            data[i] = M::op(data[i * 2], data[i * 2 + 1]);
    }
    void update(int p, T val)
    {
        p += n;
        data[p] = val;
        while (p >>= 1)
            data[p] = M::op(data[p * 2], data[p * 2 + 1]);
    }
    void add(int p, T val)
    {
        p += n;
        data[p] += val;
        while (p >>= 1)
            data[p] = M::op(data[p * 2], data[p * 2 + 1]);
    }
    T find(int l, int r)
    {
        l += n;
        r += n + 1;
        T res1 = M::id(), res2 = M::id();
        while (l < r)
        {
            if (l & 1)
                res1 = M::op(res1, data[l++]);
            if (r & 1)
                res2 = M::op(data[--r], res2);
            l >>= 1;
            r >>= 1;
        }
        return M::op(res1, res2);
    }
};

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

    int N;
    cin >> N;
    segment_tree<RangeMaximumQuery> dp(N + 1);
    ll res = 0;
    vector<ll> h(N), a(N);
    for(int i=0;i<N;i++) cin>>h[i];
    for(int i=0;i<N;i++) cin>>a[i];
    for (int i = 0; i < N; i++)
    {
        ll ma = dp.find(0, h[i]);
        res = max(res, ma + a[i]);
        dp.add(h[i], ma + a[i]);
    }
    cout << res << endl;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long int> A(N + 1, 0);
    A[0] = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i + 1];
        A[i + 1] += A[i];
    }
    long int answer = 0;
    sort(A.begin(), A.end());
    long int temp = 1;
    for (int i = 0; i < N; ++i) {
        if (A[i] == A[i + 1]) {
            answer += temp;
            ++temp;
        } else {
            temp = 1;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int sum = 0;
		for(int i=0; i<4; i++){
			int x = stdIn.nextInt();
			sum += x;
		}
		System.out.println(sum/60);
		System.out.println(sum%60);
	}
}

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

typedef pair<int, int> P;

string con[15] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int main() {
	string s;
	int n;
	cin >> n;
	for(int q = 0; q < n; ++q){
		cin >> s;
		string ans("");
		P cnt;
		cnt.first = cnt.second = 0;
		for(int i = 0; i < s.size(); ++i){
			if(s[i] == '0'){
				int num = cnt.first;
				if(num == 1){
					ans += con[num - 1][cnt.second % 5];
				}
				else if(num == 7 || num == 9){
					ans += con[num - 1][cnt.second % 4];
				}
				else if(num == 0){
					continue;
				}
				else{
					ans += con[num - 1][cnt.second % 3];
				}
				
				cnt.first = cnt.second = 0;
			}
			else{
				if(cnt.first == 0){
					cnt.first = s[i] - '0';
				}
				else{
					cnt.second++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int  main(void)
{
	
	char in,out;
	
	scanf("%c",&in);
	
	if(in=='A'){
		out='T';
	}else if(in=='T'){
		out='A';
	}else if(in=='G'){
		out='C';
	}else{
		out='G';
	}
	
	printf("%c",out);
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String[] s = new String[3];
        for (int i = 0; i < 3; i++) {
            s[i] = sc.next();
        }
        if (s[0].charAt(s[0].length() - 1) == s[1].charAt(0) &&
                s[1].charAt(s[1].length() - 1) == s[2].charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21844
# ABC137C - Green Bin
from collections import Counter


def main():
    N = int(input())
    A = Counter("".join(sorted(input())) for _ in range(N))
    ans = sum(i * (i - 1) // 2 for i in A.values())
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
  int N;
  cin >> N;
  vector<int> W(N);

  int ans = 110;

  for(int i = 0; i < N; i++)
  {
    /* code */
    cin >> W[i];
  }

  for(int i = 0; i < N; i++)
  {
    /* code */
        int sum = 0;
  int t1 = 0;
  int t2 = 0;
    for(int j = 0; j < N; j++)
    {
      /* code */
      if(j <= i){
        t1 += W[j];
      }else{
        t2 += W[j];
      }
    }
    //cout << "t1:"  << t1 << "\tt2:" << t2 << endl;
    sum = abs(t1 - t2);
    if(ans  > sum){
      ans = sum;
    }
    
  }
  cout << ans << endl;
  

  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define ll long long 
using namespace std;
int F[1000009];
long long lazy[4*100005][2];
pair<long long,int> mx(-200000000000000,0);
void push(int v,int tl,int tr) {
	for (int i = 0; i < 2; i++) {
		lazy[v*2][i] += lazy[v][i]; 
		lazy[v*2+1][i] += lazy[v][i]; 
		lazy[v][i]=0;
	}
}
void get(int v,int tl,int tr) {
	if (tl == tr) {
		ll a = lazy[v][0]*tl;
		a += lazy[v][1];
		mx = max(mx,{a,tl});
		return;
	}
	int tm = (tl + tr)/2;
	push(v,tl,tr);
	get(v*2,tl,tm);
	get(v*2+1,tm+1,tr);
}
void add(int v,int tl,int tr,int l,int r,int type,int val) {
	if (r < tl || l > tr || l > r) return;
	if (l <= tl && r >= tr) {
		if (type == 0) {
			lazy[v][0]++;
		}
		else lazy[v][1] += val;
		return;
	}
	int tm = (tl + tr)/2;
	push(v,tl,tr);
	add(v*2,tl,tm,l,r,type,val);
	add(v*2+1,tm+1,tr,l,r,type,val);
}
main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	vector<int> a(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i != 1) {
			if (a[i] > a[i-1]) {
				add(1,1,m,a[i-1] + 2,a[i],0,0);
				add(1,1,m,a[i-1]+2,a[i],1,-a[i-1]-1);
			}
			else {
				add(1,1,m,a[i-1] + 2,m,0,0);
				add(1,1,m,a[i-1] + 2,m,1,-a[i-1]-1);
				add(1,1,m,1,a[i],0,0);
				add(1,1,m,1,a[i],1,m - a[i-1] - 1);
			}
		}
	}
	get(1,1,m);
	int x = mx.second;
	long long ans = 0;
//	x = 2;
	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			if (x > a[i-1] && x <= a[i]) {
				ans += 1 + a[i] - x;
			}
			else ans += a[i] - a[i-1];
		}
		else {
			if (x > a[i-1]) {
				ans += 1 + (m - x) + a[i];
			}
			else if (x <= a[i]) ans += a[i] - x + 1;
			else ans += m - a[i-1] + a[i];
		}
	}
	cout << ans;
}

Measured memory_bytes: 8216
//write：Sakura
//id：
//problem：Minimization
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

int n,k;
int a[100005];
int ans=0;

int main(){
	//freopen("Minimization.in","r",stdin);
	//freopen("Minimization.out","w",stdout);
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	ans=(n-1)/(k-1);
	//printf("%d\n",ans);
	if((n-1)%(k-1)!=0)ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
 
public class Main {
	
	public static final int A = 0;
	public static final int B = 1;
	
    public static void main( String args[] ) {
        Scanner scan = new Scanner( System.in );
		
		double a = scan.nextDouble();
		double b = scan.nextDouble();
		double C = scan.nextDouble();
		
		double sinC =Math.sin( Math.toRadians( C ) );
		double cosC = Math.cos( Math.toRadians( C ) );
		
		
		// S
		double S = a * b * sinC / 2;
		
		// L
		double L = a + b + Math.sqrt( a * a + b * b - 2 * a * b * cosC );
		
		// h
		double h = b * sinC;
		
		System.out.print(S + "\n" + L + "\n" + h + "\n");
		
	}
	
}

Measured memory_bytes: 18192
#include <stdio.h>
int main(void)
{
  int d[6],n,i,j,blank,ue,mae;
  for(i = 0; i < 6; i++){  
    scanf("%d",&d[i]);
  }

  scanf("%d",&n);
  for(j = 0; j < n; j++){
    scanf("%d %d",&ue,&mae);
    for(i = 0; d[1] != mae && i < 3; i++){

	blank=d[0];
	d[0]=d[4];
	d[4]=d[5];
	d[5]=d[1];
	d[1]=blank;
	}

	if(d[1] != mae){

	blank=d[0];
	d[0]=d[3];
	d[3]=d[5];
	d[5]=d[2];
	d[2]=blank;

	for(i = 0; d[1] != mae; i++){

	blank=d[0];
	d[0]=d[4];
	d[4]=d[5];
	d[5]=d[1];
	d[1]=blank;

	}
       
    }
     
    for(i = 0; d[0] != ue; i++){

      blank=d[0];
      d[0]=d[3];
      d[3]=d[5];
      d[5]=d[2];
      d[2]=blank;
       
    }
    printf("%d\n",d[2]);
  }
  return 0;
}


Measured memory_bytes: 2108
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int n,i,m,f=1;
cin>>n>>m;
int a[n];memset(a,-1,sizeof(a));
for(i=0;i<m;i++)
{
	int s,c;cin>>s>>c;
	if(a[s-1]==-1) a[s-1]=c;
	else{
		if(a[s-1]!=c)
		{
			f=0;
		}
	}
}
if(f==0) cout<<-1;
else if(a[0]==0)
{
	if(n==1) cout<<0;
	else cout<<-1;
}
else{
	for(i=0;i<n;i++)
	{
		if(a[i]!=-1) cout<<a[i];
		else{
			if(i==0 && n>1) cout<<1;
			else cout<<0;
		}
	}
}

return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
using ll = long long int;
const ll INF = 1e9;
const int max_loop = 1e5;


int main(void) {
    int n; cin >> n;
    vector<vector<int>> as(n, vector<int>{});
    for(int i=0; i<n; i++){
        for(int j=0; j<n-1; j++){
            int a; cin >> a; a--;
            as[i].push_back(a);
        }
    }
    int total = n * (n - 1) / 2;
    int days = 0;
    vector<int> itrs(n, 0);
    int fights = 0;
    unordered_set<int> wants;

    while(true){
        wants.clear();
        bool has_match = false;
        for(int i=0; i<n; i++){
            int idx = itrs[i];
            if(idx == n -1){continue;}
            int want = as[i][idx];
            if(as[want][itrs[want]] == i){
                has_match = true;
                wants.insert(i);
                wants.insert(want);
            }
        }
        if(has_match == false){
            break;
        }
        for(auto& v:wants){
            itrs[v]++;
            fights++;
        }
        if(days > max_loop){
            cout << total << endl;
            return 0;
        }
        days++;
    }
    if(fights / 2 == total){
        cout << days << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4352
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
 
typedef long long LL;
typedef double DL;
 
const LL INF = 10000000000000000LL;
const int maxn = 100010;
 
LL ans,a[maxn],b[maxn],c[maxn],d[maxn];
int n,m;
 
inline LL getint()
{
    LL ret = 0,f = 1;
    char c = getchar();
    while (c < '0' || c > '9') 
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        ret = ret * 10 + c - '0',c = getchar();
    return ret * f;
}
 
int main()
{
    #ifdef AMC
        freopen("AMC1.txt","r",stdin);
//        freopen("AMC2.txt","w",stdout);
    #endif
    n = getint(); m = getint();
    for (int i = 1; i <= n; i++)
    {
    	a[i] = getint();
    	b[i] = getint();
    	c[i] = getint();
	}
	ans = -INF;
	for (int j = 0; j < 8; j++)
	{
		for (int i = 1; i <= n; i++)
		{
			LL flag1 = 1,flag2 = 1,flag3 = 1;
			if (j & 1) flag1 = -1;
			if (j & 2) flag2 = -1;
			if (j & 4) flag3 = -1;
			d[i] = flag1 * a[i] + flag2 * b[i] + flag3 * c[i];
		}
		sort(d + 1,d + n + 1);
		LL sum = 0;
		for (int i = 1; i <= m; i++)
			sum += d[n - i + 1];
		ans = max(ans,sum);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase < 1234567;testcase++){
    int3(n, r, t);
    int p[n], now[n];
    scn(n, p);
    rep(i, n)now[i] = 0;
    int res[r], stc[r];
    rep(i, r){ res[i] = 0; stc[i] = 0; }

    rep(j, t){
      rep(i, n){
        now[i] = (now[i] + p[i]) % r;
        if(stc[now[i]])stc[now[i]]--;
        else res[now[i]]++;
      }
      if(j)rep(i, n)stc[now[i]]++;
    }
    int sum = 0;
    rep(i, r)sum += res[i];
    pri(sum);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1252
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,a,b;
    cin>>n>>a>>b;
    int ans=(n/(a+b))*a;
    n%=(a+b);
    ans+=min(a, n);
    cout<<ans;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

// ����̕�����𐔂���֐�
size_t count(const string& str, const string& sub, const size_t ini = 0, const size_t fin = string::npos) {
	size_t pos = str.find(sub, ini);
	size_t cnt = 0;
	while (pos < fin) {
		cnt += 1;
		pos = str.find(sub, pos + sub.length());
	}
	return cnt;
}

int main() {

	string S;
	cin >> S;

	string ALP = "ABDEFGHIJKLMNOPQRSTUVWXYZ";

	bool jdg = true;
	string str;
	size_t cnt;
	if ("A" == S.substr(0, 1)) {
		str = S.substr(2, S.length() - 3);
		cnt = count(str, "C");
		if (cnt != 1) {
			jdg = false;
		}
		else {
			str = S.substr(1, S.length() - 1);
			for (int i = 0; i < str.length(); i++) {
				if (string::npos != ALP.find(str.substr(i, 1))) {
					jdg = false;
					break;
				}
			}
		}
	}
	else {
		jdg = false;
	}

	if (jdg == true) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}

	return 0;
}



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


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

  vector<int> A(N);
  for(int i = 0;i < N;i++) cin >> A[i];

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

  vector<int> S(1000010);
  int ans = 0;
  for(int i = 0;i < N;i++) {
    int num = A[i];
    if(S[num] != 0) {
      S[num] = 2;
      continue;
    }
    for(int j = num;j < 1000010;j += num) S[j]++;
  }

  for(int i = 0;i < N;i++) {
    if(S[A[i]] == 1) ans++;
  }

  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 8000
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    ans = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                m = x
                m = m - 500*i - 100*j - 50*k
                if m == 0:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  string s;
  cin >> s;
  int zeros = 0, ones = 0;
  for(int i = 0;i < s.size();i++) {
    if(s[i] == '0') zeros++;
    else ones++;
  }
  cout << 2*min(zeros, ones) << endl;

  return 0;
}


Measured memory_bytes: 512
//============================================================================
// Name        : alds1_2_D_ShellSort.cpp
// Author      : lovesaemi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	// 数列Gを生成
	for (int h = 1;;) {
		if (h > n) {
			break;
		}
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main() {
	cin >> n;
	// より早いscanf関数を利用
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	cnt = 0;
	shellSort(A, n);
	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i)
			printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) {
		printf("%d\n", A[i]);
	}
	return 0;
}



Measured memory_bytes: 7148
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] count = new long[100001];
        int[] A = new int[N];
        long sum = 0;
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            sum += A[i];
            count[A[i]]++;
        }

        int Q = sc.nextInt();
        for(int i=0;i<Q;i++){
            int b = sc.nextInt();
            int c = sc.nextInt();
            sum = sum + c * count[b] - b* count[b];
            count[c] += count[b];
            count[b] = 0;
            System.out.println(sum);
        }


    }

}


Measured memory_bytes: 62060
n = int(input())
x = list(map(int,input().split()))
c = 0

for i in range(n):
    min = i
    for j in range(i+1,n):
        if x[min] > x[j]:
            min = j
    if i != min:       
        x[i],x[min] = x[min],x[i]
        c += 1

print(*x)
print(c)


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

const int maxn=2507;
int n,m,p,dis[maxn],cnt[maxn];
vector<int> to[maxn],d[maxn],tof[maxn];
bool vis[maxn],okk[maxn];

queue<int> q;

int spfa()
{
	while(!q.empty()) q.pop();
	memset(dis,127,sizeof dis);
	dis[1]=0;
	q.push(1);
	while(!q.empty()) {
		int now=q.front();q.pop();vis[now]=0;cnt[now]++;
		for(int i=0;i<to[now].size();++i) {
			int t=to[now][i];
			if(okk[t]&&dis[t]>dis[now]+d[now][i]) {
				dis[t]=dis[now]+d[now][i];
				if(cnt[t]>n) return -1;
				if(vis[t]) continue;
				q.push(t);vis[t]=1;
			}
		}
	}
	return max(0,-dis[n]);
}

int main()
{
	scanf("%d %d %d",&n,&m,&p);
	for(int i=1;i<=m;++i) {
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		to[a].push_back(b);
		d[a].push_back(p-c);
		tof[b].push_back(a);
	}
	q.push(n);
	okk[n]=1;
	while(!q.empty()) {
		int tmp=q.front();q.pop();
		for(int i=0;i<tof[tmp].size();++i) {
			int t=tof[tmp][i];
			if(okk[t]) continue;
			okk[t]=1;
			q.push(t);
		}
	}
	printf("%d",spfa());
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
    int x = 0;
    int t = 400;
    cin >> x;
    for (int i = 0;i < 8; i++) {
        if (x >= t && x <= t + 199) {
            cout << 8-i << endl;
            return 0;
        }
        t += 200;
    }
    return 0;
}



Measured memory_bytes: 3164