akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {

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

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

    public static void main(String[] args) {

        long res = 0;
        Scanner sc = new Scanner(System.in);
        // int n = sc.nextInt();
        String str = sc.next();
        char[] ch = str.toCharArray();

        if (ch[0] == 'A' && ch[1] == 'R' && ch[2] == 'C') {
            System.out.println("ABC");
        } else {
            System.out.println("ARC");
        }

        // System.out.println(res);
        sc.close();
    }
}


Measured memory_bytes: 35680
import math
N,D = (int(x) for x in input().split())
n = []
p=0
for _ in range(N):
    blist=[int(x) for x in input().split()]
    n.append(blist)
for i in range(N):
    if math.sqrt((n[i][0]**2)+(n[i][1]**2)) <= D:
        p += 1
print(p)

Measured memory_bytes: 102632
#include <stdio.h>

int main(void){
  int N,T[100];
  int M,P[100],X[100];
  int i,j;
  int sum = 0;
  
  scanf("%d",&N);
  for(i = 0;i < N; ++i){
    scanf(" %d",&T[i]);
    sum += T[i];
  }
  scanf(" %d",&M);
  for(j = 0;j < M; ++j)	scanf(" %d %d",&P[j],&X[j]);
  
  for(i = 0;i < M; ++i)  printf("%d\n",sum - (T[P[i] - 1] - X[i]));
  return 0;
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	ll A, B, X;
	cin >> A >> B >> X;
	X = (X + 499) / 500 * 500;
	ll ans = 0;
	if (A > B * 2) {
		ans += X / 1000 * 2 * B;
	}else{
		ans += X / 1000 * A;
	}
	if (X % 1000 == 0)
		cout << ans << endl;
	else if (X % 1000 == 500) {
		if (A > B) ans += B;
		else ans += A;
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3136
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int a, b, c, d;
   
    int x, y = 0;
   
      
    scanf("%d %d %d %d", &a, &b, &c, &d );
   

    if( d < a || b < c ){

        printf("0\n");

        return 0;

        }


    if( a < c ){

        y = c;

        }

    else y = a;

    if( b < d ){

        x = b;

        }

    else x = d;


    printf("%d\n", x - y );


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N + 1), y(M + 1);
    for(int i = 0; i < N; i++) {
        cin >> x[i];
    }
    for(int i = 0; i < M; i++) {
        cin >> y[i];
    }
    x[N] = X;
    y[M] = Y;
    if(*max_element(WHOLE(x)) >= *min_element(WHOLE(y))) {
        cout << "War" << endl;
    } else {
        cout << "No War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <math.h>

int main(){
    std::string S;
    std::cin >> S;
    int l = sizeof(S);
    int maxlen = 0;
    int curlen = 0;
    for (int i = 0; i < l; i++) {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
            curlen++;
        } else {
            if (curlen > maxlen) maxlen = curlen;
            curlen = 0;
        }
    }
    std::cout << maxlen << std::endl;
    return 0;
}

Measured memory_bytes: 3168
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define NMAX 100000

int main()
{
	int N;
	int **h;
	long **happ;
	h = (int**)malloc(sizeof(int*) * NMAX);
	happ = (long**)malloc(sizeof(long*) * NMAX);
	for (int i = 0; i < NMAX; i++) {
		h[i] = (int*)malloc(sizeof(int) * 3);
		happ[i] = (long*)malloc(sizeof(long) * 3);
	}

	scanf("%d", &N);

	for (int i = 0; i < N; i++) {
		scanf("%d", &h[i][0]);
		scanf("%d", &h[i][1]);
		scanf("%d", &h[i][2]);
	}

	happ[0][0] = h[0][0];
	happ[0][1] = h[0][1];
	happ[0][2] = h[0][2];

	long dst1, dst2;
	for (int i = 1; i < N; i++) {
		for (int k = 0; k < 3; k++) {
			dst1 = happ[i - 1][(k + 1) % 3];
			dst2 = happ[i - 1][(k + 2) % 3];
			happ[i][k] = (dst1 < dst2 ? dst2 : dst1) + h[i][k];
			//printf("%ld ", happ[i][k]);
		}
		//printf("\n");
	}

	long max = happ[N - 1][0];
	if (max < happ[N - 1][1])max = happ[N - 1][1];
	if (max < happ[N - 1][2])max = happ[N - 1][2];


	printf("%ld", max);


	return 0;
}


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

int main() {
	int n;
    cin >> n;
    vector<int> a(n);
    map<int, bool> m;
    set<int> s;
    rep(i, n) {
        cin >> a[i];
        if (s.count(a[i])) {
            m[a[i]] = true;
        } else {
            s.insert(a[i]);
        }
    }
    vector<bool> b(1000001, true);
    for (int x : s) {
        for (int i = x + x; i <= 1000000; i += x) {
            b[i] = false;
        }
    }
    int cnt = 0;
    rep(i, n) {
        if (m[a[i]]) {
            continue;
        }
        if (b[a[i]]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 22640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;
int main(void){
 vector<int>num(3);
 for(int i=0;i<3;i++){
     cin>>num[i];
 }
 sort(num.begin(),num.end());
 int a,b,c;
 a=num[0];
 b=num[1];
 c=num[2];
 bool a_odd=a%2,b_odd=b%2,c_odd=c%2;
 int ans=0;
 if(a_odd==b_odd&&b_odd==c_odd){
     ans=(c-a)/2+(c-b)/2;
 }else if(a_odd==b_odd){
     a++;
     b++;
     ans=abs(c-a)/2+abs(c-b)/2+1;
 }else if(b_odd==c_odd){
     b++;
     c++;
     ans=abs(b-c)/2+abs(c-a)/2+1;
 }else if(a_odd==c_odd){
     a++;
     c++;
     ans=(abs(b-c)/2+abs(c-a)/2)+1;
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  srep(i,1,n+1){
    int d = i,cnt=0;
    while(d){
      cnt++;
      d/=10;
    }
    if(cnt%2)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(int argc, char const *argv[]) {
	int N;
	cin >> N;

	std::vector<int> array(10001, 0);
	for (int i = 0; i < N; ++i) {
		int temp;
		cin >> temp;
		array[temp]++;
	}

	std::vector<int> ans;
	for (int i = 0; i <= 10000; ++i) {
		while(array[i]) {
			ans.push_back(i);
			array[i]--;
		}
	}

	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i];
		if (i != ans.size() - 1) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	//三つの数から最大値を求める。
	int n = max(a, b);
	n = max(n, c);

	cout << a + b + c - n << endl;

	return 0;
}

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

int main(){
  string s;
  std::cin >> s;
  if(s[0] == s.back()){
    std::cout << ((s.length() & 1)?"Second":"First") << std::endl;
  }else{
    std::cout << ((s.length() & 1)?"First":"Second") << std::endl;    
  }
  return 0;
}


Measured memory_bytes: 512
import itertools
dishes=[int(input()) for i in range(5)]
all_comb=list(itertools.permutations(dishes))
t_min=123*50
for comb in all_comb:
  t=0
  for i in range(4):
    t=int((t+comb[i]-1)/10)*10+10
  t=t+comb[4]
  if t < t_min:
    t_min=t
print(t_min)


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

int main(){
bool a[30];
for(int i=0;i<30;i++){
a[i]=true;}
int x;
for(int i=0;i<30;i++){
cin>>x;
a[x-1]=false;}
for(int i=0;i<30;i++){
if(a[i])cout<<i+1<<endl;}}

Measured memory_bytes: 1160
#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;
  cin >> n;
  string s;
  cin >> s;
  string ans(s.size(), '?');
  rep (i, s.size()) {
    ans[i] = (s[i] - 'A' + n) % 26 + 'A';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	static long start;
	static long end;

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		String s = scan.next();
		String t = scan.next();

		int ret = 0;
		for (int i = 0; i < 3; i++) {

			if (s.charAt(i) == t.charAt(i)) {
				ret++;
			}
		}
		System.out.println(ret);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
  string color;
  char colortype[1000000];
  int res1=0;
  int res2=0;
  cin >> color;
  strcpy(colortype, color.c_str());
  if(color.length()==1){
    cout << res1;
    exit(0);
  }
  for(int i=1; i<color.length(); ++i){
    if (colortype[i]==colortype[i-1]){
      res1++;
      if (colortype[i]=='0'){
        colortype[i] = '1';
      }
      else{
        colortype[i] = '0';
      }
    }
  }
  strcpy(colortype, color.c_str());
  for(int i=1; i<color.length(); ++i){
    if (colortype[i]==colortype[i-1]){
      res2++;
      if (colortype[i]=='0'){
        colortype[i] = '1';
      }
      else{
        colortype[i] = '0';
      }
    }
  }
  if(res1<res2){
    cout << res1;
  }
  else{
    cout << res2;
  }
}

Measured memory_bytes: 540
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd

N, K = map(int, input().split())
snuke = defaultdict(int)
for _ in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for n in A:
        snuke[n] += 1

ans = 0
for i in range(1, N+1):
    if snuke[i] == 0:
        ans += 1

print(ans)

Measured memory_bytes: 27084
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while(true){
    cin >> H >> W;
    if(H == 0 && W == 0){
           break;
    }
    for(int j=0;j<H;j++){
        for(int i=0;i<W;i++){
            cout << '#';
        }
        cout << endl;
    }
    cout << endl;
    }
}


Measured memory_bytes: 3068
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	string a, b;
	cin >> a >> b;
	if (a.length() < b.length()) {
		cout << "LESS" << endl;
		return 0;
	}
	else if (a.length() > b.length()) {
		cout << "GREATER" << endl;
		return 0;
	}
	else {
		REP(q, a.length()) {
			if (a[q] > b[q]) {
				cout << "GREATER" << endl;
				return 0;
			}
			else if (a[q] < b[q]) {
				cout << "LESS" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int l, r, d; cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#define ll long long
using namespace std;
ll dp[2][100001]={},ar[100][2]={},mn=0;
int main()
{
	ll n,w;cin>>n>>w;
	for (ll i=0;i<n;i++)
	{
		for (int j=0;j<2;j++) {cin>>ar[i][j];}
	}
	for (ll j=0;j<=100000;j++) {dp[0][j] = 1000000000000000;}
	dp[0][0]=0;
	for (ll i=1;i<=n;i++)
	{
		for (ll j=0;j<=100000;j++)
		{
			dp[i%2][j] = dp[(i-1)%2][j];
			if (j>=ar[i-1][1])
			{
				dp[i%2][j] = min(dp[(i-1)%2][j],dp[(i-1)%2][j-ar[i-1][1]] + ar[i-1][0]);
			}
		}
	}
	for (int i=1;i<=100000;i++)
	{
		if (dp[n%2][i]<=w)
		{
			mn = i;
		}
	}
	cout<<mn<<"\n";
	return 0;
}

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

int main() {
  long long a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  string ans = "NO";

  // if (v <= w) {
  //   cout << ans << endl;
  //   return 0;
  // }
  //
  // if (abs(w - v) >= v * t) {
  //   cout << ans << endl;
  //   return 0;
  // }

  if (v * t - abs(a-b) >= w * t) ans = "YES";


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cmath>
struct point{
	double x, y;
	point(double _x = 0, double _y = 0){ x = _x, y = _y; }
	void read(){ scanf("%lf%lf", &x, &y); }
	void print(char ch = '\n'){ printf("%.10lf %.10lf", x, y), putchar(ch); }
	point operator + (const point &rhs) const { return point(x + rhs.x, y + rhs.y); }
	point operator - (const point &rhs) const { return point(x - rhs.x, y - rhs.y); }
}A, B, C;
int q;
double dot_product(point a, point b){
	return a.x * b.x + a.y * b.y;
}
double cross_product(point a, point b){
	return a.x * b.y - a.y * b.x;
}
int main(){
	A.read(), B.read();
	scanf("%d", &q);
	for (register int i = 1; i <= q; ++i){
		C.read();
		if (cross_product(B - A, C - A) > 0) puts("COUNTER_CLOCKWISE");
		else if (cross_product(B - A, C - A) < 0) puts("CLOCKWISE");
		else if (dot_product(B - A, C - A) < 0) puts("ONLINE_BACK");
		else if (dot_product(B - A, B - A) < dot_product(C - A, C - A)) puts("ONLINE_FRONT");
		else puts("ON_SEGMENT");
	}
}


Measured memory_bytes: 2764
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  if(65<=n&&n<=90) cout<<1<<endl;
  else if(97<=n&&n<=122) cout<<2<<endl;
  else cout<<0<<endl;
  return 0;
}



Measured memory_bytes: 3080
import sys
input = sys.stdin.buffer.readline

import math

n = int(input())
mod = 1000000007
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))

def power(a, n, mod):
  bi=str(format(n,"b")) #2進数
  res=1
  for i in range(len(bi)):
    res=(res*res) %mod
    if bi[i]=="1":
      res=(res*a) %mod
  return res

def toid(a, b):
    flag = False
    if a == 0 and b == 0:
        return (0, 0)
    elif a == 0:
        return (0, 1)
    elif b == 0:
        return (1, 0)
    else:
        if a > 0 and b > 0:
            g = math.gcd(a, b)
            a //= g
            b //= g
        elif a > 0 and b < 0:
            b = -b
            g = math.gcd(a, b)
            a //= g
            b //= g
            b = -b
        elif a < 0 and b > 0:
            a = -a
            g = math.gcd(a, b)
            a //= g
            b //= g
            b = -b
        else:
            a = -a
            b = -b
            g = math.gcd(a, b)
            a //= g
            b //= g
        return (a, b)

def totg(a, b):
    if a == 0 and b == 0:
        return (0, 0)
    elif a == 0:
        return (1, 0)
    elif b == 0:
        return (0, 1)
    else:
        if a > 0 and b > 0:
            g = math.gcd(a, b)
            a //= g
            b //= g
            t = (b, -a)
        elif a > 0 and b < 0:
            b = -b
            g = math.gcd(a, b)
            a //= g
            b //= g
            b = -b
            t = (-b, a)
        elif a < 0 and b > 0:
            a = -a
            g = math.gcd(a, b)
            a //= g
            b //= g
            a = -a
            t = (b, -a)
        else:
            a = -a
            b = -b
            g = math.gcd(a, b)
            a //= g
            b //= g
            a = -a
            b = -b
            t = (-b, a)
        return t


d = {}
ans = 0
for i in range(n):
    a, b = AB[i]
    s = toid(a, b)
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1

ans = 1
used = set()
for k1, v1 in d.items():
    if k1 in used:
        continue
    if k1 == (0, 0):
        continue
    a, b = k1
    k2 = totg(a, b)
    if k2 in d:
        v2 = d[k2]
    else:
        v2 = 0
    temp = power(2, v1, mod)-1+power(2, v2, mod)-1+1
    ans *= temp
    ans %= mod
    used.add(k1)
    used.add(k2)

ans -= 1
if (0, 0) in d:
    ans += d[(0, 0)]

print(ans%mod)

Measured memory_bytes: 163004
import math

A,B,C,D = map(int, input().split())
E = C*D // math.gcd(C, D)
count =0
n = (A-1)//C
m = B//C
o = (A-1)//D
p= B//D
q= (A-1)//E
r= B//E
print((B-A+1) - ((m-n)+(p-o)-(r-q)))

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

#define N 1005
#define MP make_pair
typedef long long LL;
const int mod = 1e9 + 7;


int main()
{
	//freopen("in.txt", "r", stdin);
	
	LL k, a, b, ans = 1;
	cin >> k >> a >> b;
	if (a >= b) ans += k;
	else
	{
		//k - 2x + 1 >= a 
		//k-2x >= 0
		// x <= k/2
		//2x <= k+1-a
		LL mx = k+1-a;
		if (mx <= 0) ans += k;
		else
		{
			mx >>= 1;
			//1+k-2x+ x*(b-a) = (b-a-2)x + k + 1
			if (b-a-2 >= 0) ans = (b-a-2)*mx+k+1;
			else ans = k + 1; 
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll MOD = 1e9 + 7;

//二項係数 nCk mod p
//aのp乗を求める
ll modpow(ll a, int p) {
   if(p == 0) return 1;
   if(p % 2 == 0) {
      int halfP = p / 2;
      ll half = modpow(a, halfP);
      //a^(p/2)をhalfとして、half*halfを計算
      return half * half % MOD;
   } else {
      //pが奇数のときは偶数にするために1減らす
      return a * modpow(a, p-1) % MOD;
   }
}
//二項係数の計算
//10C3 (10*9*8) / (3*2*1)
//(10*9*8):ansMul (3*2*1):ansDiv
ll calcComb(int a, int b) {
   if(b > a - b) return calcComb(a, a - b);

   ll ansMul = 1;
   ll ansDiv = 1;
   rep(i, b) {
       ansMul *= (a - i);
       ansDiv *= (i + 1);
       ansMul %= MOD;
       ansDiv %= MOD;
   }
   //ansMul / ansDiv をしたい
   //ansDivの逆元を求める
   ll ans = ansMul * modpow(ansDiv, MOD - 2) % MOD;

   return ans;
}

int main() {
    int x, y;
    cin >> x >> y;

    if((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int n = (x + y) / 3;
    x -= n; y -= n;
    if(x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << calcComb(x+y, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 10, mod = 1e9 + 7;
 
 
 
int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        int n; cin >> n;
        bool ok = 0;
        while(n) {
            if((n % 10) == 7) ok = 1;
            n /= 10;
        }
        if(ok) puts("Yes");
        else puts("No");
    }    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    string s; cin >> s;
    if(s=="Sunny") puts("Cloudy");
    else if(s=="Cloudy") puts("Rainy");
    else puts("Sunny");
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }

    long long res = 0;
    for (int l = 0; l <= K; l++) {
        for (int r = 0; r <= K - l; r++) {
            if (l + r > N) break;

            int d = K - (l + r);

            long long sum = 0;
            vector<int> chosen;
            for (int i = 0; i < l; i++) {
                sum += V[i];
                chosen.push_back(V[i]);
            }
            for (int i = N - 1; i > N - r - 1; i--) {
                sum += V[i];
                chosen.push_back(V[i]);
            }
            sort(chosen.begin(), chosen.end());
            for (int i = 0; i < d; i++) {
                if (i >= chosen.size()) break;
                if (chosen[i] < 0) {
                    sum -= chosen[i];
                }
            }
            res = max(res, sum);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int[] l = sc.nextIntArray(n);
    int[][] dp = new int[3][1 << n];
    for (int i = 0; i < 3; i++) {
      Arrays.fill(dp[i], Integer.MAX_VALUE);
    }
    int[] target = new int[] {a, b, c};
    for (int i = 0; i < 3; i++) {
      for (int j = 1; j < (1 << n); j++) {
        int sum = 0;
        int count = 0;
        for (int k = 0; k < n; k++) {
          if (((j >> k) & 1) == 1) {
            sum += l[k];
            count++;
          }
        }
        dp[i][j] = (count - 1) * 10 + Math.abs(sum - target[i]);
      }
    }
    int min = Integer.MAX_VALUE;
    for (int i = 1; i < (1 << n); i++) {
      for (int j = 1; j < (1 << n); j++) {
        for (int k = 1; k < (1 << n); k++) {
          boolean dup = false;
          for (int p = 0; p < n; p++) {
            if (((i >> p) & 1) + ((j >> p) & 1) + ((k >> p) & 1) > 1) {
              dup = true;
              break;
            }
          }
          if (!dup) min = Math.min(min, dp[0][i] + dp[1][j] + dp[2][k]);
        }
      }
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 23764
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x == 3 || x == 5 || x == 7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

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

using namespace std;
mt19937_64 rng(58);

int idx(char c) {
    string s = "RGB";
    for (int i = 0; i < 3; i++)
        if (s[i] == c) return i;
    assert("invalid char");
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    string s;
    long long ans = 0;
    cin >> n >> s;
    int m[3][4001];
    m[0][0] = 0;
    m[1][0] = 0;
    m[2][0] = 0;

    for (int i = 0; i < n; i++) {
        if (i > 0)
            for (int j = 0; j < 3; j++)
                m[j][i] = m[j][i - 1];
        m[idx(s[i])][i]++;

        for (int j = 1; j < i; j++) {
            if (s[i] == s[j]) continue;
            char sk = (char)((int)'R' + 'G' + 'B' - s[i] - s[j]);
            ans += m[idx(sk)][j - 1];
            if (j - (i - j) >= 0 && s[j - (i - j)] == sk) ans--;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3700
x = [c  for c in input()]

n = len(x)
ret=[]
for i in range(n-1):
    ret.append([0,0])

if x[n-1] == "1":
    print (-1)
elif x[0] == "0":
    print (-1)
else:
    flg = 1
    for i in range(int((n-1)/2)):
        if x[i] != x[n-1-i-1]:
            flg = 0
    if flg == 0:
        print (-1)
    else:
        a=1
        b=n
        for i in range(int((n-2)/2)):
            if x[i] == "1":
                ret[i] = [a,i+2]
                ret[n-i-2] = [b,n-i-2+1]
                a=i+2
                b=n-i-2+1
            else:
                ret[i] = [a,i+2]
                ret[n-i-2] = [b,n-i-2+1]
                
        if n % 2 == 1:
            i = int((n-3)/2)
            if x[i] == "1":
                ret[i] = [a,i+2]
                ret[n-i-2] = [b,n-i-2+1]
            else:
                tmp = b
                for j in range(i):
                    if ret[n-j-2][1] == b:
                        ret[n-j-2][1] = a
                    if ret[n-j-2][0] == b:
                        ret[n-j-2][0] = a
                ret[i] = [a,i+2]
                ret[n-i-2] = [a,tmp]
        else:
            i = int(n/2)-1
            if x[i] == "1":
                ret[i] = [a,b]
            else:
                tmp = b
                for j in range(i):
                    if ret[n-j-2][1] == b:
                        ret[n-j-2][1] = a
                    if ret[n-j-2][0] == b:
                        ret[n-j-2][0] = a
                ret[i] = [a,b]
                
        
        for i in range(n-1):
            print ("{0} {1}".format(ret[i][0], ret[i][1]))

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

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans;
    ans = max(b*d,a*c);
    ans = max(ans,a*d);
    ans = max(ans,b*c); 
    
    // vector<ll> input(4);
    // rep(i,4) cin >> input[i];
    // ll ans;
    // rep(i,3){
    //     for(int j = i+1; j<4; j++){
    //        ans = max(input[i]*input[j],ans); 
    //     }
    // }
    cout << ans << endl;

    return 0;
}

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

int main() {
    string S;
  	cin >> S;
    long long sum = 0;
  	int n = S.length();
  	for (int bit = 0; bit < (1<<(n-1)); ++bit) {
    	long long num = S[0] - '0';
      	for (int i = 0; i < (n - 1); ++i) {
        	if (bit & (1<<i)) {
            	sum += num;
                num = 0;
            }
          	num = 10 * num + S[i + 1] - '0';
        }
      	sum += num;
    }
  	cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  int n,a,b;cin>>n>>a>>b;
  int p[n];
  int m[3];
  fill(m,m+3,0);
  for(int i=0;i<n;i++){
    cin>>p[i];
    if(p[i]<=a)m[0]++;
    else if(p[i]<=b)m[1]++;
    else m[2]++;
  }
  sort(m,m+3);
  cout<<m[0]<<endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

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

template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 5e3 + 15;
int n, sz[N];
vector <int> G[N];
int dp[N][N][2], g[N];

inline int add(int a, int b) {
    a += b;
    if(a >= mod)
        a -= mod;
    if(a < 0)
        a += mod;
    return a;
}

inline void add_t(int &a, int b) {
    a = add(a, b);
}

inline int mt(int a, int b) {
    return 1ll * a * b % mod;
}

int temp[N][2];

void dfs(int v, int p = -1) {
    sz[v] = 1;
    dp[v][1][0] = 1;
    for(int to : G[v]) {
        if(to == p)
            continue;
        dfs(to, v);
        memset(temp, 0, sizeof(temp));
        for(int x = 1; x <= sz[v]; ++x) {
            for(int y = 1; y <= sz[to]; ++y) {
                for(int p = 0; p < 2; ++p) {
                    for(int s = 0; s < 2; ++s) {
                        int val = 1ll * dp[v][x][p] * dp[to][y][s] % mod;
                        add_t(temp[x + y][p ^ s], val);
                        add_t(temp[x][p ^ s ^ 1], mt(val, g[y]));
                    }
                }
            }
        }
        memcpy(dp[v], temp, sizeof(dp[v]));
        sz[v] += sz[to];
    }
}

inline void precalc() { 
    g[0] = 1;
    for(int i = 2; i < N; ++i)
        g[i] = mt(g[i-2], i - 1);
}

main() {
    precalc();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // setin("input.txt");
    cin >> n;
    for(int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }
    dfs(1);
    int ans = 0;
    for(int x = 1; x <= n; ++x)
        for(int y = 0; y < 2; ++y)
            add_t(ans, mt(g[x], (y == 0 ? dp[1][x][y] : -dp[1][x][y])));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 200316
def main():
    num = int(input())
    data = list(map(int, input().split()))

    color = [0 for i in range(9)]
    for i in range(num):
        score = data[i]
        ind = score // 400
        if ind > 8:
            ind = 8
        color[ind] += 1

    now_data = 0
    for i in range(8):
        if color[i]:
            now_data += 1

    min_data = max(1, now_data)
    # max_data = min(8, now_data + color[8])
    max_data = now_data + color[8]
    print(min_data, max_data)





if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 99824435
int main()
{   
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	fast;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll p=b*d;
    ll q=a*c;
    ll r=a*d;
    ll s=b*c;
    cout<<max(p,max(q,max(r,s)))<<"\n";
	return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,k;
    cin >> n >> k;
    if (n > k) n %= k;
    cout << min(abs(n-k), k - abs(n-k)) << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
x,y,a,b,c = gets.split.map(&:to_i)
red = gets.split.map(&:to_i)
green = gets.split.map(&:to_i)
colorless = gets.split.map(&:to_i)
red.sort!{|s,t| t <=> s}
green.sort!{|s,t| t <=> s}
colorless.sort!{|s,t| t <=> s}
red = red.slice(0,[a,x].min)
green = green.slice(0,[b,y].min)
aa = []
aa.concat(red)
aa.concat(green)
aa.concat(colorless)
aa.sort!{|s,t| t <=> s}
puts aa.slice(0,x+y).sum

Measured memory_bytes: 30516
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  char c; cin >> c;
  int n = c - '0';
  n++;
  char ans = n + '0';
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mxn 300005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
#define ld long double
typedef long long int ll;
using  namespace std;
int r[mxn],c[mxn];
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	int h,w,m,i,j,ans=0,a,b,mr=0,mc=0,cr=0;
	set<pair<int,int>>s;
	cin>>h>>w>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		r[a]++;
		c[b]++;
		s.insert({a,b});
	}
	vector<int>mrc;
	vector<int>mcc;
	for(i=1;i<=h;i++){
		mr=max(mr,r[i]);
	}
	for(i=1;i<=w;i++){
		mc=max(mc,c[i]);
	}
	for(i=1;i<=h;i++){
		if(r[i]==mr)
		mrc.pb(i);
	}
	for(i=1;i<=w;i++){
		if(c[i]==mc)
		mcc.pb(i);
	}
		for(auto x:mrc){
			for(auto y:mcc){
				if(s.find({x,y})==s.end())
				ans=max(ans,mr+mc);
				else
				ans=max(ans,mr+mc-1);
				cr++;
				if(cr>mxn)
				break;
			}
		}
	cout<<ans;
	
}


Measured memory_bytes: 23764
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N, K = InputToInt()
    h = InputToInt()

    c = 0
    for a in h:
        if a >= K:
            c += 1
    print(c)


Measured memory_bytes: 9860
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll H,W;
string s[1010];
ll s_count[100];
int main(){
  cin >> H >> W;
  rep(i,H){
    cin >> s[i];
    rep(j,W){
      s_count[s[i][j] - 'a']++;
    }
  }
  ll count1=0,count2=0,count4=0;
  if(H%2 == 1 && W%2 == 1){
    count1 = 1;
  }
  if(H%2 == 1){
    count2 += W/2;
  }
  if(W%2 == 1){
    count2 += H/2;
  }
  count4 += (W/2) * (H/2);
  //cerr << count1 << endl;
  //cerr << count2 << endl;
  //cerr << count4 << endl;
  /*
  rep(i,26){
    cerr << s_count[i] << endl;
  }
  */
  rep(i,26){
    if(count4 > s_count[i]/4){
      count4 -= s_count[i]/4;
      s_count[i]%=4;
    }
    else{
      s_count[i] -= count4*4;
      count4 = 0;
    }

    if(count2 > s_count[i]/2){
      count2 -= s_count[i]/2;
      s_count[i]%=2;
    }
    else{
      s_count[i] -= count2*2;
      count2 = 0;
    }
    if(count1 > s_count[i]){
      count1 -= s_count[i];
      s_count[i]=0;
    }
    else{
      s_count[i] -= count1;
      count1 = 0;
    }
  }
  if(count4 == 0 && count2 == 0 && count1 == 0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}


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

using namespace std;

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

//#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; print(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain;


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

	std::vector<ll> X(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}

	int L;
	cin >> L;

	//尺取り法で各ホテルからLでいけるホテルを探す
	std::vector<std::vector<int>> H(N, std::vector<int>(20));
	int r = 0;
	for (int l = 0; l < N; l++) {
		while (r < (N - 1)) {
			if (L < (X[r + 1] - X[l])) {
				break;
			}
			r++;
		}
		H[l][0] = r;
	}

	//ダブリング
	for (int k = 1; k < 20; k++) {
		for (int i = 0; i < N; i++) {
			H[i][k] = H[H[i][k - 1]][k - 1];
		}
	}

	int Q;
	cin >> Q;

	for (int q = 0; q < Q; q++) {
		int a, b;
		cin >> a >> b;
		if (a > b) std::swap(a, b);
		a -= 1;
		b -= 1;

		int ans = 0;
		for (int k = 19; 0 <= k; k--) {
			if (H[a][k] < b) {
				a = H[a][k];
				ans += (1 << k);
			}
		}

		print(ans + 1);
	}


	return 0;
}


Measured memory_bytes: 13312
S = input()

if(S[0] == 0):
    Z = int(S[1])
else:
    Z = S[0] + S[1]
    X = int(Z)

if(S[2] == 0):
    K = int(S[3])
else:
    K = S[2] + S[3]
    Y = int(K)

if(1 <= X <= 12):
    if(1 <= Y <= 12):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if(1 <= Y <= 12):
        print("YYMM")
    else:
        print("NA")

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

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

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

    int refrain = 0;
    for (int i = 0; i < N - 1; i++ ){
        for ( int j = i + 1 ; j < N ; j++){
            refrain += d[i]*d[j];
        }
    }

    cout << refrain << endl;

    return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int K = sc.nextInt();
		int S = sc.nextInt();
		int count = 0;
		for (int x = 0; x <= K; x++) {
			for (int y = x; y <= K; y++) {
				for (int z = y; z <= K; z++) {
					if (x + y + z == S) {
						if (x == y && y == z)
							count++;
						else if ((x != z && x == y) || (x != z && y == z))
							count += 3;
						else
							count += 6;
					}
				}
			}
		}
		System.out.println(count);

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23124