akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    s = lines[1]

    return (n, s)


def solve(n, s):

    
    last = None
    result = []
    for i in range(n):
        if s[i] != last:
            result.append(s[i])
        last = s[i]


    if debug:
        log("result=%s" % result)
        
    return len(result) 


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, end=' ')
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 4092
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, x, y, z;
int dp[2][70000];
signed main() {
	cin >> n >> x >> y >> z;
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, ((ll)1 << (x + y + z - 1))) {
			if (!dp[0][j])continue;
			deque<int> deq;
			int cnt = 1;
			for (int k = x + y + z - 2; k >= 0; k--) {
				if ((j >> k) & 1) {
					deq.push_back(cnt);
					cnt = 1;
				}
				else cnt++;
			}
			deq.push_back(cnt);
			deq.pop_front();
			reverse(deq.begin(), deq.end());
			REP(k, 10) {
				if (k > z) {
					dp[1][((j << k) + ((ll)1 << (k - 1))) % ((ll)1 << (x + y + z - 1))] += dp[0][j];
					continue;
				}
				cnt = z - k;
				int s = 3;
				if (k == z) {
					cnt = y;
					s = 2;
				}
				bool f = false;
				for (int i : deq) {
					if (cnt == i) {
						if (s == 1) {
							cnt = 0;
							break;
						}
						else if (s == 2) {
							s--;
							cnt = x;
						}
						else {
							s--;
							cnt = y;
						}
					}
					else if (cnt < i) {
						f = true;
						break;
					}
					else cnt -= i;
				}
				if (f || s != 1 || cnt) {
					dp[1][((j << k) + ((ll)1 << (k - 1))) % ((ll)1 << (x + y + z - 1))] += dp[0][j];
				}
			}
		}
		rep(j, ((ll)1 << (x + y + z - 1))) {
			dp[0][j] = dp[1][j];
			dp[0][j] %= mod;
			dp[1][j] = 0;
		}
	}
	int ans = 1;
	rep(i, n) {
		ans *= 10;
		ans %= mod;
	}
	rep(j, ((ll)1 << (x + y + z - 1))) {
		ans -= dp[0][j];
		ans += mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>

using namespace std;

int main(void){
  int n,m,c, ans=0;
  cin >> n >> m >> c;
  vector<int>b(m);
  for(int i=0;i<m;i++)cin >> b[i];
  for(int i=0;i<n;i++){
    int a, sum=0;
    for(int j=0;j<m;j++)cin >> a, sum+=a*b[j];
    ans += (sum+c > 0);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

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

        if (a*500>=b)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}


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

int main(){
  int64_t N,ans=0;
  cin >> N;
  vector<int> A(N+1),B(N);
  for(int i=0;i<N+1;i++) cin >> A[i];
  for(int i=0;i<N;i++) cin >> B[i];
  
  for(int i=0;i<N;i++){
    if(A[i]<=B[i]){
      B[i]-=A[i];
      ans+=A[i];
      A[i]=0;
      if(A[i+1]<=B[i]){
        B[i]-=A[i+1];
        ans+=A[i+1];
        A[i+1]=0;
      }
      else{
        A[i+1]-=B[i];
        ans+=B[i];
        B[i]=0;
      }
    }
    else{
      A[i]-=B[i];
      ans+=B[i];
      B[i]=0;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#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 <iomanip>

using namespace std;
using ll = long long;

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

#include <iostream>

int main()
{
	int A, B;
	cin >> A >> B;

	cout << max(2 * A - 1, max(A + B, 2 * B - 1)) << endl;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll n, m;
ll dx[4] = {0, -1, 0, 1};
ll dy[4] = {-1, 0, 1, 0};
string grid[25];
ll vis[25][25];
bool valid(ll xx, ll yy)
{
	if (xx < 0 || yy < 0)
		return false;
	if (xx >= n || yy >= m)
		return false;
	if (grid[xx][yy] == '#')
		return false;
	if (vis[xx][yy] != -1)
		return false;
	return true;
}
ll bfs(ll sx, ll sy)
{
	
	queue<pll> q;
	q.push(mp(sx, sy));
	vis[sx][sy] = 0;
	while (!q.empty())
	{
		pll fr = q.front();
		q.pop();
		for (int i = 0; i < 4; ++i)
		{
			if (valid(fr.x + dx[i], fr.y + dy[i]))
			{
				q.push(mp(fr.x + dx[i], fr.y + dy[i]));
				vis[fr.x + dx[i]][fr.y + dy[i]] = 1 + vis[fr.x][fr.y];
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			ans = max(ans, vis[i][j]);
		}
	}
	memset(vis, -1, sizeof(vis));
	return ans;
}
int main(int argc, char const *argv[])
{
	fast;
	memset(vis, -1, sizeof(vis));
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
	{
		cin >> grid[i];
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (valid(i, j))
				ans = max(ans, bfs(i, j));
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
M=998244353
N=int(input())
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for _ in range(N):
	a=int(input())
	i=s
	while i>=0:
		d[i+a]+=d[i]%M
		d[i]*=2
		e[i+a]+=e[i]%M
		i-=1
	s+=a
	z=z*3%M
for i in range(s+1>>1,s+1):
	z-=d[i]*3
	z%=M
print([(z+e[s//2]*3)%M,z][s%2])


Measured memory_bytes: 141644
#include<bits/stdc++.h>
using namespace std;
long long n,m,i,j,ans=99999,sum,x,a,b;

int main()
{
	cin>>n;
	
	for(i=1;i<n;i++)
	{
	a=i;
	b=n-i;
	
	x=a; sum=0;
	while(x)
	{
		sum+=x%10;
		x/=10;
	}

	x=b; 
	while(x)
	{
		sum+=x%10;
		x/=10;
	}

if(ans>sum)ans=sum;	
	
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100000;
int num[maxn + 10];
int ji[maxn + 10];
int ou[maxn + 10];
int n;
int main()
{
	//freopen("p.in","r",stdin);
	//freopen("f.out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;++i)
	{
		scanf("%d",&num[i]);
		if(i & 1)
		{
			ji[(i + 1) / 2] = num[i];
		}
		else
		{
			ou[i / 2] = num[i];
		}
	}
	sort(ji + 1,ji + 1 + (n + 1) / 2);
	sort(ou + 1,ou + 1 + n / 2);
	sort(num + 1,num + 1 + n);
	int ans = 0;
	if(n & 1)
	{
		int p = 1;
		for(int i = 1;i <= n;i += 2)
		{
			while(num[i] > ji[p] && p < (n + 1) / 2)
				++p;
			if(num[i] != ji[p])
				++ans;
			while(ji[p] < num[i] && p < (n + 1) / 2)
				++p;
		}
	}
	else
	{
		int p = 1;
		for(int i = 1;i < n;i += 2)
		{
			while(num[i] > ji[p] && p < n  / 2)
				++p;
			if(num[i] != ji[p])
				++ans;
			while(ji[p] < num[i] && p < n  / 2)
				++p;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>

using namespace std;

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

    long long t = 1, a = 1;
    for (int i = 0; i < n; i++) {
        long long ti, ai;
        cin >> ti >> ai;

        long long n = max((t + ti - 1) / ti, (a + ai - 1) / ai);
        t = n * ti;
        a = n * ai;
    }

    cout << t + a << endl;
}


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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = min(B, N * A);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define REP(i,x)for(int i=0;i<x;i++)

string res;
int H,W,dx,dy,min_len;
char s[200];
char MAP[11][22];
bool visit[20][20];
vector<string> ss;
void dfs(int x,int y,int k){
  if(visit[y][x]){
    ss.push_back(string(s));
    return;
  }
  s[k]=MAP[y][x];  visit[y][x]=1;
  dfs((x + dx + W) % W, (y + dy + H) % H, k + 1);
  s[k]=0;  visit[y][x]=0;
}
int main() {
  while(scanf("%d%d",&H,&W),H){
    REP(i,H)scanf("%s",MAP[i]);
    ss.clear();
    min_len=1; res="0";
    REP(y,H)REP(x,W){
      for(dx=-1;dx<=1;dx++){
        for(dy=-1;dy<=1;dy++){
          if(dx|dy)dfs(x,y,0);
        }
      }
    }
    string res = "0";
    sort(ss.begin(),ss.end());
    REP(i,ss.size()-1){
      int len = 0;
      if(min(ss[i].size(),ss[i+1].size()) < len)continue;
      REP(k,min(ss[i].size(),ss[i+1].size())){
        if(ss[i][k]==ss[i+1][k])len++;
        else break;
      }
      if(len < res.size())continue;
      if(res.size() == len){
        res = min(res, ss[i].substr(0,len));
      }else{
        res = ss[i].substr(0, len);
      }
    }
    puts(res.c_str());
  }
}

Measured memory_bytes: 1304
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(int a, int b){
	return a>b;
}
int main() {
    long long N, K; cin >> N >> K;
    vector<long long> A(N), F(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), cmp);
    
    long long ng = -1;
    long long ok = A[N-1] * F[0];
    while(abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        long long cut_cost = 0;
        for(int i = 0; i < N; ++i) cut_cost += max(0LL, A[i] - mid / F[i]);
        if(cut_cost <= K) ok = mid;
        else ng = mid;
    }
    
    cout << ok << endl;
}

Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        new Main().solve();
    }
    int n,m;
    int[]k;
    int[][]l;
    ArrayList<Integer>[]edge;
    boolean[] visited;

    void solve() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        k = new int[n];
        l = new int[n][];

        for (int i = 0; i < n; i++) {
            k[i] = Integer.parseInt(sc.next());
            l[i] = new int[k[i]];
            for (int j = 0; j < k[i]; j++) {
                l[i][j] = Integer.parseInt(sc.next());
            }
        }
        edge=new ArrayList[n+m];
        for(int i=0;i<n+m;i++){
            edge[i]=new ArrayList<Integer>();
        }
        for(int i=0;i<n;i++) {
            for (int j = 0; j < k[i]; j++) {
                edge[i].add((n-1)+l[i][j]);
                edge[(n-1)+l[i][j]].add(i);
            }
        }

        visited=new boolean[n+m];
        dfs(0);
        for(int i=0;i<n;i++){
            if(!visited[i]){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

    void dfs(int x) {
        visited[x] = true;
        for (int i = 0; i < edge[x].size(); i++) {
            if (!visited[edge[x].get(i)]) {
                dfs(edge[x].get(i));
            }
        }
    }
}

Measured memory_bytes: 71428
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

/*
for(int i=0;i<n;i++)
printf("%d\n",n)
scanf("%d",&n)
*/

using namespace std;
int n,r=1000,sm;
string s;

int ci(char c){return int(c)-48;}

int main(){
    cin>>s;
    for(int i=0;i<s.length()-2;i++){
        sm=abs(753-(ci(s[i])*100+ci(s[i+1])*10+ci(s[i+2])));
        r=min(r,sm);
        
    }
    printf("%d\n",r);
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(string s;cin>>s;){
		int res=0;
		repi(i,1,s.size())
			res+=s[i]!=s[i-1];
		cout<<res<<endl;
	}
}


Measured memory_bytes: 512
#include<algorithm>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> rev(n + 1);
    rep(i, n){
        int p;
        cin >> p;
        rev[p] = i;
    }

    multiset<int> st;
    st.insert(rev[n]);
    st.insert(-1);
    st.insert(-1);
    st.insert(n);
    st.insert(n);
    lint ans = 0;
    rreps(i, n - 1){
        auto it1 = st.lower_bound(rev[i]);
        auto it2 = it1;
        auto it3 = it1;
        auto it4 = it1;

        --it1;
        --it1;
        --it2;
        ++it4;

        ans += (lint)i * (rev[i] - *it2) * (*it4 - *it3);
        ans += (lint)i * (*it3 - rev[i]) * (*it2 - *it1);

        st.insert(rev[i]);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int n, k, ans=0;
    vector<int> a(n);
    cin >> n >> k;

    for(int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    for(int j=0; j<k; j++){
        ans += a.at(j);
    }

    cout << ans << endl;
 
}

Measured memory_bytes: 16640
#include<stdio.h>
int construct(int n)
{
	if(n%2) return 3*n+1;
	else return n/2;
}
int main()
{
	int s,i,a,b,c,d,count;
	while(~scanf("%d", &s))
	{
		a = s;
		b = construct(a);
		c = construct(b);
		count = 3;
		while(1)
		{
			count++;
			d = construct(c);
			if(d==a) break;
			a=b;b=c;c=d;
		}
		printf("%d\n", count);
	}
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, k;
int main() {
	std::cin >> n >> k;

	if (k == 1)
		std::cout << 0 << std::endl;
	else
		std::cout << n - k << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
        int int2 = Integer.parseInt(scan.next());
        int int3 = Integer.parseInt(scan.next());
//        String temp_str1 = "";
//        String temp_str2 = "";
        int temp_int1 = 0;
//        String str1 = scan.next();
//        String str2 = scan.next();
//        String str3 = scan.next();
        int ans_int = 0;
        String ans = "";
//        double ans_dob = 0;
        if(int1>int2){
            if(int3>int1){
                ans_int = int1+int2;
            }else{
                ans_int = int3+int2;
            }
        }else{
            if(int3>int2){
                ans_int = int1+int2;
            }else{
                ans_int = int1+int3;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans_int);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 24020
def main():
	N, X, Y = [int(n) for n in input().split(" ")]
	vertex = [[1]] + [[i - 1, i + 1] for i in range(1, N - 1)] + [[N - 2]]
	vertex[X - 1].append(Y - 1)
	vertex[Y - 1].append(X - 1)

	count = [0] * N
	for i in range(N):
		to_visit = [i]
		checked = [0] * N
		steps = [0] * N
		checked[i] = 1

		while len(to_visit) > 0:
			visiting = to_visit.pop(0)
			vs = vertex[visiting]
			step = steps[visiting]
			for v in vs:
				if checked[v] == 0:
					checked[v] = 1
					to_visit.append(v)
					steps[v] = step + 1
					count[step + 1] += 1

	for c in count[1:]:
		print(int(c/2))

main()

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

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

  vector<int> X(N);
  for (auto &i : X) cin >> i;

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

  vector<vector<int>> a(M);
  for (auto &i : X) a[i % M].push_back(i);

  int ans = a[0].size() / 2;
  if (M % 2 == 0) {
    ans += a[M / 2].size() / 2;
  }

  for (int i = 1; i <= (M - 1) / 2; ++i) {
    int s = i, t = M - i;
    if (a[s].size() > a[t].size()) swap(s, t);

    ans += a[s].size();

    int cnt = 0;
    for (int j = 1; j < a[t].size(); ++j) {
      if (a[t][j] == a[t][j - 1]) {
        cnt++;
        j++;
      }
    }

    ans += min((int)(a[t].size() - a[s].size()) / 2, cnt);
  }

  cout << ans << endl;
}


Measured memory_bytes: 6144
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:break
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:break
r,j=0,len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Measured memory_bytes: 40660
import collections
import bisect
N = int(input())
AL = list(map(int, input().split(" ")))

d = collections.defaultdict(list)
for index, num in enumerate(AL):
    d[num].append(index)

ans = 0
if not d[1]:
    print(-1)
else:
    current_pos = d[1][0]
    ans = 0
    for i in range(1, N+1):
        a = d[i+1]
        index = bisect.bisect_right(a, current_pos)
        if index != len(a):
            current_pos = a[index]
            continue
        else:
            ans = i
            break
    print(N - ans)

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

int h[100000];
int d[100000];

int dfs(int n){
  if(d[n]!=-1) return d[n];
  int res=min(dfs(n-1)+abs(h[n]-h[n-1]),dfs(n-2)+abs(h[n]-h[n-2]));
  d[n]=res;
  return res;
}

int main(){
  int n;
  cin>>n;
  rep(i,0,n) cin>>h[i];
  rep(i,0,n) d[i]=-1;
  d[0]=0;
  d[1]=abs(h[1]-h[0]);
  cout<<dfs(n-1)<<endl;
}

Measured memory_bytes: 2560
n = int(input())
lst = [int(i) for i in input().split()]
if n == 1 or n == 2:
  print(0)
else:
  lst.sort()
  #print(lst)
  count = 0
  for i in range(n-2):
    for j in range(i+1, n-1):
      if lst[j] == lst[i]:
        continue
      for k in range(j+1, n):
        if lst[k] == lst[j]:
          continue
        if lst[i] + lst[j] > lst[k]:
          count += 1
  print(count)

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

int main()
{
    int q;
    long long int n,m;
    long long int s = 0;
    scanf("%lld%lld",&n,&m);
    if(m>=n*2)
    {
        s += n;
        m -= 2*n;
        n = 0;
        s += m/4;
    }
    else
    {
        s += m/2;
        n -= m/2;
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 128
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
ab = nan(n)
cd = nan(m)

ans = [-1] * n
for i in range(n):
    a, b = ab[i]
    min_val = inf
    for j in range(m):
        c, d = cd[j]
        dist = abs(a - c) + abs(b - d)
        if min_val > dist:
            min_val = dist
            ans[i] = j + 1

print(*ans, sep="\n")

Measured memory_bytes: 3064
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/



unordered_set<int> s;
unordered_set<int> black;
unordered_set<int> black1;

void proc() {
	LOAD(int, H);
	LOAD(int, W);
	//
	auto getID = [&](int h, int w) {
		return h * W + w;
	};
	auto getHW = [&](int ID) -> std::pair<int, int> {
		return { ID / W,ID % W };
	};
	//
	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			char A;
			cin >> A;
			if (A == '#') {
				black.insert(getID(h, w));
			}
			else {
				s.insert(getID(h, w));
			}
		}
	}
	int count = 0;
	while (true) {
		if (s.empty())break;
		black1.clear();
		for (auto a : black) {
			auto hw = getHW(a);
			auto h_ = hw.first;
			auto w_ = hw.second;
			if (1 <= h_) {
				int ID_ = getID(h_ - 1, w_);
				auto itr = s.find(ID_);
				if (itr != s.end()) {
					black1.insert(ID_);
					s.erase(itr);
				}
			}
			if (h_ < H - 1) {
				int ID_ = getID(h_ + 1, w_);
				auto itr = s.find(ID_);
				if (itr != s.end()) {
					black1.insert(ID_);
					s.erase(itr);
				}
			}
			if (1 <= w_) {
				int ID_ = getID(h_, w_ - 1);
				auto itr = s.find(ID_);
				if (itr != s.end()) {
					black1.insert(ID_);
					s.erase(itr);
				}
			}
			if (w_ < W - 1) {
				int ID_ = getID(h_, w_ + 1);
				auto itr = s.find(ID_);
				if (itr != s.end()) {
					black1.insert(ID_);
					s.erase(itr);
				}
			}
		}
		black = black1;
		++count;
	}
	cout << count << endl;
}


#endif


Measured memory_bytes: 53648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    ll xmin = LLINF, xmax = -LLINF, ymin = LLINF, ymax = -LLINF;
    FOR(i, 0, n) {
        ll x, y; cin >> x >> y;
        chmin(xmin, x + y);
        chmax(xmax, x + y);
        chmin(ymin, x - y);
        chmax(ymax, x - y);
    }
    print(max(xmax - xmin, ymax - ymin));

    return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>
int main(){ 
     char ch; 
     while(1){ 
         scanf("%c", &ch); 
         if(ch=='\n'){ 
             printf("\n"); 
             break; 
         }else if(islower(ch)){ 
             printf("%c", toupper(ch)); 
         }else if(isupper(ch)){ 
             printf("%c", tolower(ch)); 
         }else{ 
             printf("%c", ch); 
         } 
     } 
     return 0; 
}




Measured memory_bytes: 2104
V,E = map(int,input().split())
matrix = [ [float('inf')]*V for _ in range(V) ]

for i in range(V):
  matrix[i][i] = 0

for _ in range(E):
  u,v,w = map(int,input().split())
  matrix[u][v] = w

for k in range(V):
  for i in range(V):
    for j in range(V):
      matrix[i][j] = min(matrix[i][j], matrix[i][k]+matrix[k][j])

for i in range(V):
  if matrix[i][i] < 0:
    print("NEGATIVE CYCLE")
    exit()


for i in range(V):
  print(" ".join(map(str, [ "INF" if e==float('inf') else e for e in matrix[i] ])))


Measured memory_bytes: 6032
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int turn = 0;
  string ans;
  
  while(1) {
    if (s[turn].empty()) {
      ans = turn + 'A';
      break;
    }
    int tmp = s[turn][0] - 'a';
    s[turn].erase(s[turn].begin());
    turn = tmp;
  }
  cout << ans << endl;
}

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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static void Main() {
        var s = Console.ReadLine().Split(new[] { ' ' });
        Console.WriteLine("A{0}C", s[1][0]);
    }
}

Measured memory_bytes: 2776
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	ll K;
	cin >> K;
	ll N = 50;
	VL a(N);
	REP(i, N) a[i] = i;
	REP(i, N) a[i] += K / N;
	REP(i,K%N) {
		REP(j,N){
			if (i == j) a[j] += N;
			if (i != j) a[j] -= 1;		
		}
	}
	cout << N << endl;
	REP(i, N) cout << a[i] << " ";
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
### constant

CX, CY = [20, 20]
BX, BY = [CX * 2 + 1, CY * 2 + 1]

### subroutines

def rot_x(dc0, n = 1)
  dc = dc0
  n.times.each{dc = [dc[0], 7 - dc[2], dc[1]]}
  dc
end

def rot_y(dc0, n = 1)
  dc = dc0
  n.times.each{dc = [dc[2], dc[1], 7 - dc[0]]}
  dc
end

def rot_z(dc0, n = 1)
  dc = dc0
  n.times.each{dc = [7 - dc[1], dc[0], dc[2]]}
  dc
end

### main

dices = 7.times.map{[]}
dc = [1, 2, 3]

4.times do
  dices[dc[2] - 1][dc[0] - 1] = dc
  4.times do
    dices[dc[2] - 1][dc[0] - 1] = dc
    4.times do
      dices[dc[2] - 1][dc[0] - 1] = dc
      dc = rot_z(dc)
    end
    dc = rot_y(dc)
  end
  dc = rot_x(dc)
end
#p dices; exit

loop do
  n = gets.to_i
  break if n == 0

  brd = BY.times.map{BX.times.map{[0, nil]}}

  n.times do
    ti, fi = gets.split.map(&:to_i)
    #p [[ti, fi], dices[ti - 1][fi - 1]]

    dc = dices[ti - 1][fi - 1]
    x, y = [CX, CY]

    loop do
      bh, bt = brd[y][x]
      max_s = 0
      tmp = [x, y, dc]

      if brd[y][x - 1][0] < bh && dc[0] >= 4 && max_s < dc[0]
        max_s = dc[0]
        tmp = [x - 1, y, rot_y(dc)]
      end
      if brd[y][x + 1][0] < bh && 7 - dc[0] >= 4 && max_s < 7 - dc[0]
        max_s = 7 - dc[0]
        tmp = [x + 1, y, rot_y(dc, 3)]
      end
      if brd[y - 1][x][0] < bh && dc[1] >= 4 && max_s < dc[1]
        max_s = dc[1]
        tmp = [x, y - 1, rot_x(dc, 3)]
      end
      if brd[y + 1][x][0] < bh && 7 - dc[1] >= 4 && max_s < 7 - dc[1]
        max_s = 7 - dc[1]
        tmp = [x, y + 1, rot_x(dc)]
      end

      break if max_s == 0

      x, y, dc = tmp
    end

    brd[y][x] = [brd[y][x][0] + 1, dc[2]]
  end
  #p brd[CY][CX]

  counts = 6.times.map{0}
  for y in (0...BY)
    for x in (0...BX)
      bh, bt = brd[y][x]
      if bh > 0
        counts[bt - 1] += 1
      end
    end
  end

  puts counts.join(' ')
end

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------

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

    int n = input();

    vector<int> arr;
    while(n > 0){
        arr.push_back(n%10);
        n /= 10;
    }

    int ans = 0;
    int t = 1;
    rep(i,0,arr.size()){
        if(arr[i] == 1) arr[i] = 9;
        else if(arr[i] == 9) arr[i] = 1;

        ans += arr[i] * t;
        t *= 10;
    }
    print(ans);


}

Measured memory_bytes: 256
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#define ll long long

using namespace std;

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

Measured memory_bytes: 764
#include<cstdio>
#include<string>
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;

ll n, d[1000000], e[1000000]; // e: 0+ 1*
string s;

int main() {
  while (scanf("%lld", &n), n) {
    d[0] = 0, e[0] = 0;
    ll mx = 0;
    for (ll i = 0; i < n; i++) {
      cin >> s;
      ll sz = s.size()-1;
      while (mx != sz) {
        if (e[mx-1]) d[mx-1] *= d[mx];
        else d[mx-1] += d[mx];
        mx--;
      }
      if (s[sz] == '+') mx++, e[mx] = 0, d[mx] = 0;
      else if (s[sz] == '*') mx++, e[mx] = 1, d[mx] = 1;
      else {
        if (e[mx]) d[mx] *= s[sz] - '0';
        else d[mx] += s[sz] - '0';
      }
    }
    while (mx != 0) {
      if (e[mx-1]) d[mx-1] *= d[mx];
      else d[mx-1] += d[mx];
      mx--;
    }
    printf("%lld\n", d[0]);
  }
}



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

int main(){
    long long a ,b, ans, tmp;

    cin >> a >> b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

  	long long m = a,n = b, temp;
    while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}

    ans = a * b / n;
    
    cout << ans << endl;
    return 0;
 
}



Measured memory_bytes: 256
// IN THE NAME OF GOD
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 1e5 + 15;
int n, a[MAXN], ans;
map <int, int> pos;
vector <int> vect;
int main(){
  //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i], vect.push_back(a[i]);
  sort(vect.begin(), vect.end());
  for(int i = 0; i < (int)vect.size(); i++) pos[vect[i]] = i;
  for(int i = 0; i < n; i++) if(abs(i - pos[a[i]]) % 2) ans++;
  cout << ans / 2 << endl;
}


Measured memory_bytes: 5752
import java.util.Scanner;

public class Main {
	static long toLong(double N) {
			long num=(long)(N*100+0.001);
			return num;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A=sc.nextLong();
		double B=sc.nextDouble();
		sc.close();
		long result=Math.floorDiv(A*toLong(B),100l);
		System.out.println(result);
	}
}


Measured memory_bytes: 37300
#include <stdio.h>

int main() {
	int r, g, b, n;

	scanf("%d%d%d%d", &r, &g, &b, &n);

	int count = 0;
	for (int i = 0; i <= n; i++) {
		if (i * r > n) break;
		for (int j = 0; j <= n; j++){
			if (i * r + j * g > n) break;
			if (((n - i * r - j * g) / b) == (float)(n - i * r - j * g) / b) {
				count += 1;
			}
		}
	}

	printf("%d\n", count);

	return 0;
}

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

#define int long long

using namespace std;

int n, a[233];

int dfs(int l, int r, int xl, int xr) {
	if (l + 1 == r) return 0;
	int ans = 1e18;
	for (int m = l + 1; m <= r - 1; m++) 
		ans = min(ans, dfs(l, m, xl, xl + xr) + dfs(m, r, xl + xr, xr) + (xl + xr) * a[m]);
	return ans;
}		

signed main(void) {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	cout << dfs(1, n, 1, 1) + a[1] + a[n] << "\n";
}


Measured memory_bytes: 384
import Control.Monad
import Control.Applicative
import Data.List


getBysplit = map read . words <$> getLine

getList :: IO [Int]
getList = do
  (k:xs) <- getBysplit :: IO [Int]
  return xs

main :: IO()
main = do
  [n, m] <- getBysplit :: IO [Int]
  lst <- replicateM n getList
  print $ solve [1..m] lst


solve :: [Int] -> [[Int]] -> Int
solve list lst = sum [ v | x <- list, let v = f x lst]
    where
      f :: Int -> [[Int]] -> Int
      f x lst = if (all (==True) . map (elem x)) lst
                  then 1
                  else 0


Measured memory_bytes: 1148
loop do
    m, f, r = gets.split.map(&:to_i)
    break if m == -1 && f == -1 && r == -1
    
    if m == -1 || f == -1
        puts "F"
        next
    end
    
    sum = m + f
    case sum
    when 80..100
        puts "A"
    when 65..80
        puts "B"
    when 50..65
        puts "C"
    when 30..50
        if r >= 50
            puts "C"
        else
            puts "D"
        end
    else
        puts "F"
    end
end

Measured memory_bytes: 8552
using System;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var s = int.Parse(str);

            var aList = new List<int>();
            aList.Add(s);
            var a = s;
            var i = 2;
            while (true)
            {
                if (a % 2 == 0)
                {
                    a = a / 2;
                }
                else
                {
                    a = a * 3 + 1;
                }

                if (aList.Contains(a))
                {
                    Console.WriteLine(i);
                    return;
                }

                aList.Add(a);
                i++;
            }
        }
    }
}


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

namespace AOJ
{
  class Program
  {
    public static void Main(string[] args)
    {
      foreach (var n in ReadNumbers())
      {
        int count = 0;
        foreach (var a in Enumerable.Range(0, 10))
          foreach (var b in Enumerable.Range(0, 10))
            foreach (var c in Enumerable.Range(0, 10))
              foreach (var d in Enumerable.Range(0, 10))
                if (a + b + c + d == n)
                  ++count;
        Console.WriteLine(count);
      }
    }

    static IEnumerable<int> ReadNumbers()
    {
      string line;
      while ((line = Console.ReadLine()) != null)
        yield return int.Parse(line);
    }
  }
}

Measured memory_bytes: 6008
import math

N = int(input())

F = [None] * N
P = [None] * N

for i in range(N):
    F[i] = [x for x in input().split()]

for i in range(N):
    P[i] = [int(x) for x in input().split()]

def rieki(shopIdx, joisinoBit):
    binStr = "".join(F[shopIdx])
    shopBit = int(binStr,2)

    common = shopBit & joisinoBit
    r = 0
    c = common
    while(c != 0):
        if c%2 == 1:
            r += 1
        c //= 2
    return P[shopIdx][r]


ma = -10**10
for bit in range(1,2 ** 10):
    r = 0
    for shopIdx in range(N):
        r += rieki(shopIdx, bit)
    ma = max(ma, r)

print(ma)

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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

int N, X, Y, Z;
const int mask = (1<<17) - 1;
int memo[42][(1<<17)];
int zyx[3];

bool have_xyz(int bit){
    zyx[0] = Z;
    zyx[1] = Y;
    zyx[2] = X;
    int idx = 0;
    int len = 0;
    for(int i=0;i<17;i++){
        len++;
        if((bit>>i)&1){
            zyx[idx] -= len;
            if(zyx[idx] < 0){
                break;
            }else if(zyx[idx] == 0){
                if(idx == 2){
                    return true;
                }else{
                    idx++;
                }
            }
            len = 0;
        }
    }
    return false;
}

int dfs(int p, int bit){
    if(p == N) return 1;
    if(memo[p][bit] != -1) return memo[p][bit];
    ll ret = 0;
    for(int i=1;i<=10;i++){
        int nbit = (bit << i) | (1 << (i-1));
        nbit &= mask;
        if(!have_xyz(nbit)){
            ret = (ret + dfs(p+1, nbit)) % MOD;
        }
    }
    memo[p][bit] = ret;
    return ret;
}

int main(){
    cin >> N >> X >> Y >> Z;
    memset(memo, -1, sizeof(memo));
    ll ret = dfs(0, 0);
    ll ans = 1;
    for(int i=1;i<=N;i++){
        ans = (ans * 10) % MOD;
    }
    ans = (MOD + ans - ret) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21760
#include<stdio.h>
int main() {
	int S;
	int h=0, m=0, s=0;
	scanf("%d",&S);
	h = S / 3600;
	S = S - (3600 * h);
	m = S / 60;
	s = S - (60 * m);
	printf("%d:%d:%d\n",h, m, s);
	return 0;
}


Measured memory_bytes: 2112
W,H,x,y,r=(int(x) for x in input().split())

if -100<=x<=100 and -100<=y<=100 and 0<W<=100 and 0<H<=100 and 0<r<=100:
   if x<r or y<r or W-x<r or H-y<r or W<2*r or H<2*r:
      print("No")
   else:
      print("Yes")
else:
   pass   


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

char capitalize(char c) {
  return static_cast<char>(toupper(static_cast<unsigned char>(c)));
}

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num;
  bool flag;

  num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  flag = true;
  // flag = false;

  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  cout << capitalize(s1[0]) << capitalize(s2[0]) << capitalize(s3[0]) << endl;

  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100009],b,c,d,n,dp[100009];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
    {
        b=abs(a[i]-a[i-1])+dp[i-1];
        c=abs(a[i]-a[i-2])+dp[i-2];
        dp[i]=min(b,c);
    }
    cout<<dp[n-1]<<endl;
}












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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int n,q; 
  cin >> n  >> q ;
  string s;
  cin >>s;
  VI cnt(n);
  cnt.at(0)=0;
  ll sum=0;
  rep(i,n-1){
    if(s.at(i)=='A' && s.at(i+1)=='C')sum++;;
    cnt.at(i+1)=sum;
  }
  VI l(q);
  VI r(q);
  rep(i,q){
    cin >>l.at(i) >> r.at(i);
  }
  rep(i,q){
    cout << cnt.at(r.at(i)-1)-cnt.at(l.at(i)-1) << endl;
  }
}

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

int main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    for(int i=0;i<min(k,n);i++){
        ans += x;
    }
    for(int i=0;i<(n-k);i++){
        ans += y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256