akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;
     
class Main{
     
    static final PrintWriter out=new PrintWriter(System.out);
    
    static class binarySearchTree{
	
	static class Node{
	    int id;
	    Node p;
	    Node l;
	    Node r;
	    //コンストラクタ
	    Node(int id){
		this.id=id; this.p=null; this.l=null; this.r=null;
	    }
	}
	
	private static Node root;
	
	binarySearchTree(){
	    root=null;
	}
	
	public static void insert(int w){
	    if(root==null) root=new Node(w);
	    else __insert(new Node(w));
	}
	
	private static void __insert(Node z){
	    Node x=root;
	    Node y=null;
	    while(x!=null){
		y=x;
		if(z.id<x.id) x=x.l;
		else x=x.r;
	    }
	    z.p=y;
	    if(z.id<y.id) y.l=z;
	    else y.r=z;
	}
	
	public static boolean find(int w){
	    Node x=root;
	    while(x!=null){
		if(x.id==w) return true;
		else if(x.id>w) x=x.l;
		else x=x.r;
	    }
	    return false;
	}
	
	public static boolean delete(int w){
	    Node x=root;
	    Node y=null;
	    boolean isLeftChild=true;
	    while(true){
		if(x==null) return false;
		else if(x.id==w) break;
		y=x;
		if(w<x.id){
		    x=x.l;
		    isLeftChild=true;
		}
		else{
		    x=x.r;
		    isLeftChild=false;
		}
	    }
	    if(x.l==null){
		if(x==root) root=x.r;
		else if(isLeftChild) y.l=x.r;
		else y.r=x.r;
	    }
	    else if(x.r==null){
		if(x==root) root=x.l;
		else if(isLeftChild) y.l=x.l;
		else y.r=x.l;
	    }
	    else{
		y=x;
		Node right=x.r;
		isLeftChild=false;
		while(right.l!=null){
		    y=right;
		    right=right.l;
		    isLeftChild=true;
		}
		x.id=right.id;
		if(isLeftChild) y.l=right.r;
		else y.r=right.r;
	    }
	    return true;
	}
	
	public static void print(){
	    inorder(root);
	    out.println();
	    preorder(root);
	    out.println();
	}
	
	private static void preorder(Node now){
	    if(now==null) return;
	    out.print(" "+now.id);
	    preorder(now.l);
	    preorder(now.r);
	}
	
	private static void inorder(Node now){
	    if(now==null) return;
	    inorder(now.l);
	    out.print(" "+now.id);
	    inorder(now.r);
	}
	
	private static void postorder(Node now){
	    if(now==null) return;
	    postorder(now.l);
	    postorder(now.r);
	    out.print(" "+now.id);
	}
    }
    
    public static void main(String[] args) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st;
	binarySearchTree tree=new binarySearchTree();
	int num=Integer.parseInt(br.readLine());
	while(num-->0){
	    st=new StringTokenizer(br.readLine());
	    String command=st.nextToken();
	    int n;
	    if("insert".equals(command)){
		n=Integer.parseInt(st.nextToken());
		tree.insert(n);
	    }
	    else if("find".equals(command)) {
		n=Integer.parseInt(st.nextToken());
		out.println((tree.find(n))?"yes":"no");
	    }
	    else if("delete".equals(command)) {
		n=Integer.parseInt(st.nextToken());
		tree.delete(n);
	    }
	    else tree.print();
	}
	out.flush();
    }
}


Measured memory_bytes: 114132
a, b, c = [int(i) for i in input().split()]

def cond(a, b, c):
    if a == 1:
        return True
    candidate = []
    i = 1
    while True:
        r = (a * i) % b
        if r in candidate:
            break
        i += 1
        candidate.append(r)
    if c in candidate:
        return True
    return False

if cond(a, b, c):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>

using namespace std;

map<string, int> change;

void Init()
{
    change["yotta"] = 24, change["zetta"] = 21, change["exa"] = 18;
    change["peta"] = 15, change["tera"] = 12, change["giga"] = 9;
    change["mega"] = 6, change["kilo"] = 3, change["hecto"] = 2;
    change["deca"] = 1, change["deci"] = -1, change["centi"] = -2;
    change["milli"] = -3, change["micro"] = -6, change["nano"] = -9;
    change["pico"] = -12, change["femto"] = -15, change["ato"] = -18;
    change["zepto"] = -21, change["yocto"] = -24;
}

vector<string> Parse(string s)
{
    int st = 0;
    vector<string> a;

    for (int i = 0; i < s.size(); ++i)
        if (s[i] == ' ') {
            a.push_back(s.substr(st, i - st));
            st = i + 1;
        }
    return a;
}

void Solve(string s)
{
    vector<string> p = Parse(s);
    int b = 0;

    if (p.size() == 3)
        b = change[p[1]];

    if (p[0][0] == '0') { // 0.xxxx
        int i;
        for (i = 2; i < p[0].size(); ++i)
            if (p[0][i] != '0')
                break;
        b -= (i - 1);
    }
    else {
        int i;
        for (i = 0; i < p[0].size(); ++i)
            if (p[0][i] == '.')
                break;
        if (i != 1)
            b += i - 1;
    }

    // Output
    int tmp = 0;
    while (p[0][tmp] == '0' || p[0][tmp] == '.')
        ++tmp;
    cout << p[0][tmp++];
    if (tmp != p[0].size())
        cout << '.';
    for (int i = tmp; i < p[0].size(); ++i)
        if (p[0][i] != '.')
            cout << p[0][i];
    cout << " * 10^" << b << ' ' << p[p.size() - 1] << endl;
}

int main()
{
    Init();

    int t;
    cin >> t;
    cin.ignore();
    while (t--) {
        string s;

        getline(cin, s);
        s += " ";
        Solve(s);
    }

    return 0;
}

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


ll dp[101][100010];
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,W;
    cin>>n>>W;
    ll wt[n+1],v[n+1];
    for(int i=1;i<=n;i++)
        cin>>wt[i]>>v[i];
    for(int i=1;i<=n;i++)
    {
        for(int w = 1;w<=W;w++)
        {
            if(wt[i]<=w)
              dp[i][w] = max(v[i] + dp[i-1][w - wt[i]],dp[i-1][w]);   
            else dp[i][w] = dp[i-1][w];
        }
    }
    cout<<dp[n][W];
    return 0;
}

Measured memory_bytes: 78464
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 1e18

#define MAX 1000005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	char ch;
	db aa,bb,cc;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,n,m,sum=0,ans=0,temp,t;
	cin >> n;
	for(i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			sum+=i;
		}
	}
	cout << sum;
    
    
    return 0;
}





















/* UJJWAL KESHRI */

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	N %= 10;
	if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9){
		cout << "hon" << endl;
	}
	else if(N == 3){
		cout << "bon" << endl;
	}
	else{
		cout << "pon" << endl;
	}
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  i64 k;
  cin >> n >> k;
  map<int, i64> ma;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ma[a] += b;
  }
  each(m, ma) {
    k -= m.second;
    if (k <= 0) {
      cout << m.first << endl;
      return;
    }
  }
}


Measured memory_bytes: 4224
S = input()
T = input()
ans = 1e10
for i in range(len(S)):
    if i+len(T) > len(S):
        break
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt += 1
    ans = min(cnt, ans)
print(ans)


Measured memory_bytes: 9056
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    if(s.equals("SUN")) System.out.println(7);
    if(s.equals("MON")) System.out.println(6);
    if(s.equals("TUE")) System.out.println(5);
    if(s.equals("WED")) System.out.println(4);
    if(s.equals("THU")) System.out.println(3);
    if(s.equals("FRI")) System.out.println(2);
    if(s.equals("SAT")) System.out.println(1);
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#include <string>
const int mxN=1e5;
const int maxN=5e3;
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int c=0;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        c^=a[i];
    }
    for(int i=0;i<n;i++)
        a[i]^=c;
    for(int i=0;i<n;i++)
        cout << a[i] << " ";    
}

Measured memory_bytes: 3952
a,b=map(int, input().split())
k=50
MAP=[]
for _ in range(k):
    MAP.append(["#"]*2*k)
for _ in range(k):
    MAP.append(["."]*2*k)
a-=1
b-=1
for i in range(0,k-1,2):
    for j in range(0,2*k,2):
        if a>0:
            MAP[i][j]="."
            a-=1
for i in range(k+1,2*k,2):
    for j in range(0,2*k,2):
        if b>0:
            MAP[i][j]="#"
            b-=1
print(2*k,2*k)
for i in MAP:
    print("".join(i))

Measured memory_bytes: 3188
X = int(input())
if X >= 1800:
    print(1)
elif X >= 1600:
  print(2)
elif X >= 1400:
   print(3)
elif X >= 1200:
  print(4)
elif X >= 1000:
  print(5)
elif X >= 800:
  print(6)
elif X >= 600:
  print(7)
else:
  print(8)

Measured memory_bytes: 9180
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)2e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int n;
struct mat{
	vvi x;
	mat(){
		x.resize(n,vi(n,0));
	}mat operator*(const mat& a) const{
		mat c=mat();
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					c.x[i][j]=(c.x[i][j]+(x[i][k]*a.x[k][j])%mod)%mod;
				}
			}
		}return c;
	}
	void input(mat &a){
		for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a.x[i][j];
	}
	void prin(mat &a){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) cout<<a.x[i][j]<<" ";cout<<endl;
		}
	}
};
int main(){
	ll k,c=0;cin>>n>>k;
	mat v=mat();
	v.input(v);
	mat s=mat();
	for(int i=0;i<n;i++) s.x[i][i]=1;
	while(k){
		if(k%2) s=s*v;
		k/=2;v=v*v;
	}
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) c=(c+s.x[i][j])%mod;
	cout<<c<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
string s[305];
bool check(int x){
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(s[(i+x)%n][j]!=s[(j+x)%n][i])
				return false;
	return true;
}
int main(){
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> s[i];
	for(int i=0;i<n;i++)
		if(check(i))ans+=n;
	cout << ans;
    return 0;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

// 2で割れる x 2で割れる or 4で割れる x any
int main() {
    int N;
    cin >> N;
    int odd_cnt=0,mul_of_4_cnt=0,mul_of_2_cnt=0;
    REP(i,N) {
        int inp;
        cin >> inp;

        if (inp%2==1) odd_cnt++;
        else if (inp%4==0) mul_of_4_cnt++;
        else mul_of_2_cnt++;
    }

    if (odd_cnt>mul_of_4_cnt) {
        if (mul_of_2_cnt == 0 && (odd_cnt-mul_of_4_cnt)==1) {
            cout << "Yes" << endl;
            return 0;
        }
        cout << "No" << endl;
        return 0;
    }



    cout << "Yes" << endl;


    return 0;
}


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

class Main 
{
  public static void main(String[] args) 
  {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String result = "";
    for (int i = 0; i < s.length(); i += 2)
    {
      result = result + s.charAt(i);
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 57152
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#define SIZE 200005
#define MOD 1000000007

using namespace std;
typedef long long int ll;

char str[SIZE];
ll dp[SIZE],rdp[SIZE];

ll solve(int n,int L)
{
	dp[1]=1;
	rdp[1]=1;
	for(int i=2;i<=n;i++)
	{
		dp[i]=rdp[i-1]-(i-L-2<=0?0:rdp[i-L-2]);
		if(dp[i]<0) dp[i]+=MOD;
		rdp[i]=rdp[i-1]+dp[i];
		if(rdp[i]>=MOD) rdp[i]-=MOD;
	}
	ll ret=0;
	for(int i=0;i<=min(n-1,L);i++)
	{
		ret+=(ll) (i+1)*dp[n-i]%MOD;
		if(ret>=MOD) ret-=MOD;
	}
	return ret;
}
ll solve2(int n)
{
	dp[1]=1;
	rdp[1]=1;
	dp[2]=0;
	rdp[2]=1;
	for(int i=3;i<=n;i++)
	{
		dp[i]=rdp[i-2];
		rdp[i]=rdp[i-1]+dp[i];
		if(rdp[i]>=MOD) rdp[i]-=MOD;
	}
	ll ret=0;
	for(int i=1;i<=n-1;i++)
	{
		ret+=(ll) (i+1)*dp[n-i]%MOD;
		if(ret>=MOD) ret-=MOD;
	}
	return ret;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	scanf("%s",&str);
	bool R=false,B=false;
	for(int i=0;i<m;i++)
	{
		if(str[i]=='R') R=true;
		else B=true;
	}
	if(!B||!R) printf("%lld\n",(solve2(n)+1)%MOD);
	else
	{
		if(n%2==1) puts("0");
		else
		{
			int mn=n;
			for(int i=0;i<m;)
			{
				if(str[i]!=str[0])
				{
					i++;
					continue;
				}
				int f=i;
				for(;i<m&&str[i]==str[f];i++);
				int len=i-f;
				//printf("%d\n",len);
				if(f==0)
				{
					if(len%2==0) len++;
					mn=min(mn,len);
				}
				else if(i<m&&len%2==1) mn=min(mn,len);
			}
			//printf("%d\n",mn);
			printf("%lld\n",solve(n/2,mn/2)*2LL%MOD);
		}
	}
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//typedef complex<double> P;
typedef pair<int, int> P;
const int MAX_V = 100010;
const int INF = 1e9 + 7;

int dijkstra(const vector< vector<P> > &cost, int s, int t, int V){
  priority_queue<P, vector<P>, greater<P> > open;
  open.push(P(s, 0));
  int closed[MAX_V];
  REP(i, V) closed[i] = INF;
  while(!open.empty()){
    P tmp = open.top(); open.pop();
    int now = tmp.first, c = tmp.second;
    if(closed[now] < c) continue;
    closed[now] = c;
    REP(i, cost[now].size()){
      int next = cost[now][i].first, nc = cost[now][i].second;
      if(nc == INF || c + nc >= closed[next]) continue;
      closed[next] = c + nc;
      open.push(P(next, closed[next]));
    }
  }
  REP(i, V){
    if(closed[i] == INF) cout <<"INF" <<endl;
    else cout <<closed[i] <<endl;
  }
  return closed[t];
}

int main() {
  int V, E, r;
  cin >>V >>E >>r;
  vector< vector<P> > cost(V);
  REP(i, E){
    int f, t, c; cin >>f >>t >>c;
    cost[f].push_back(P(t, c));
  }
  //REP(i, E){
  //  if((int)cost[i].size() <= 0) continue;
  //  SORT(cost[i]);
  //  vector<P> tmp;
  //  int now = cost[i][0].first;
  //  tmp.push_back(cost[i][0]);
  //  FOR(j, 1, cost[i].size()){
  //    if(now == cost[i][j].first) continue;
  //    now = cost[i][j].first;
  //    tmp.push_back(cost[i][j]);
  //  }
  //  cost[i] = tmp;
  //}
  dijkstra(cost, r, -1, V);
  return 0;
}

Measured memory_bytes: 18808
def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


n = int(input())
vertices = [complex(*map(int, input().split())) for _ in range(n)]
edges = [(p0, p1) for p0, p1 in zip(vertices, vertices[1:] + [vertices[0]])]

q = int(input())
while q:
    q -= 1
    p = complex(*map(int, input().split()))
    counter = 0
    for p0, p1 in edges:
        a, b = p0 - p, p1 - p
        if a.imag > b.imag:
            a, b = b, a
        crs = cross(a, b)
        if a.imag <= 0 and 0 < b.imag and crs < 0:
            counter += 1
        if crs == 0 and dot(a, b) <= 0:
            print(1)
            break
    else:
        print(2 if counter % 2 else 0)


Measured memory_bytes: 5688
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    string s;
    cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << "\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import combinations

MOD = 2  # type: int


def solve(N: int, P: int, A: "List[int]"):
    if all(map(lambda a: a % 2 == 0, A)):
        print(2 ** N if P == 0 else 0)
        return
    print(2 ** (N-1))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

int N, A[100005], buff;

ll GCD(ll a, ll b){
    if(b==0) return a;

    return GCD(b, a % b);
}

void solve(){
    buff = A[0];
    for(int i = 1; i < N;i++){
        buff = GCD(buff, A[i]);
    }
    cout << buff << endl;
}

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

    solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e18;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int a,b,c;
      cin>>a>>b>>c;
      a-=b;
      c-=min(a,c);
      cout<<c;
      // int n;
      // cin>>n;
      // int ans=0;
      // for(int i=1;i<=n;i++)
      // {
      //       int x=i;
      //       int cnt=0;
      //       while(x) x/=10,cnt++;
      //       if(cnt&1) ans++;
      // }
      // cout<<ans;
}
// I never lose. I either win or I learn


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] line = br.readLine().split(" ");
		br.close();
		List<Integer> nums = new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			nums.add(Integer.parseInt(line[i]));
		}
		Collections.sort(nums);
		
		boolean flg = false;
		for(int i=0;i<n-1;i++) {
			if(nums.get(i).equals(nums.get(i+1))) {
				flg = true;
				break;
			}
		}
		if(flg) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}

	}

}


Measured memory_bytes: 63824
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

ll dp[51][2501];
int n;

int main() {
  int a;
  scanf("%d%d", &n, &a);
  dp[0][0] = 1;
  for(int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    for(int a = i; a >= 0; a--) {
      for(int b = 0; b <= 50*a; b++) {
        dp[a+1][b+t] += dp[a][b];
      }
    }
  }
  ll r = 0;
  for(int i = 1; i <= n; i++) {
    r += dp[i][a*i];
  }
  printf("%lld\n", r);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f;

int n, m;
char s[103];
string t;

inline bool pd(string h)
{
    for (int i = 0; i < h.size(); i+=1)
        if (h[i] != h[h.size() - i - 1]) return false;
    return true;
}

int main()
{
	//File("");
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (int i = 1; i <= n; i+=1) 
	    if (s[i] != s[n - i + 1]) {puts("No"); return 0;}
	for (int i = 1; i <= (n - 1) / 2; i+=1) t = t + (char)(s[i]);
	if (!pd(t)) {puts("No"); return 0;}
	t = "";
	for (int i = (n + 3) / 2; i <= n; i+=1) t = t + (char)(s[i]);
	if (!pd(t)) {puts("No"); return 0;}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
//abc071_b Not Found


#include <bits/stdc++.h>
using namespace std;

namespace
{
bool bFlag[ 30 ];
}

int main()
{
int i;
char S[ 100010 ];
char C;

	cin >> S;

	i = 0;
	C = S[ i ];
	while( C != '\0' )
	{
		bFlag[ C - 'a' ] = true;

		i++;
		C = S[ i ];
	}

	for( i = 0; i < 26; i++ )
	{
		if( ! bFlag[ i ] ) break;
	}

	if( i >= 26 )
		cout << "None" << endl;
	else
		cout << (char) ( 'a' + i ) << endl;

	return 0;
}






Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define all(a) a.begin(),a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll,ll> pp;

#define debug(x) cout << #x << " :: "<< x <<"\n";
#define debug2(x,y) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\n";
#define debug3(x,y,z) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree< pp , null_type,less< pp >, rb_tree_tag,tree_order_statistics_node_update>

ll power(ll b, ll exp){
    ll res = 1;
    while(exp > 0){
        if(exp % 2){
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
        cin >> a[i];
    for(ll i=k;i<n;i++) {
        if( a[i]>a[i-k] )   {
            cout << "Yes\n";
        }
        else    {
            cout << "No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4760
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

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

string bs[110];
string rs[110];
int card[110];

int main() {
    int N, M;
    cin >> N;
    rep(i, N)cin >> bs[i];
    cin >> M;
    rep(i, M)cin >> rs[i];

    rep(i, N) {
        rep(j, M) {
            if (bs[i] == rs[j])card[i]--;
        }
    }
    rep(i, N) {
        for (int j = i; j < N; j++) {
            if (bs[i] == bs[j])card[i]++;
        }
    }
    cout << max(*max_element(card, card + N), 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <queue>

using namespace std;

struct Result
{
    int problem_id;
    int score;
    int count;
    Result(int p, int s, int c) : problem_id(p), score(s), count(c) {}
    Result(int p) : problem_id(p), score(0), count(0) {}
};

int main()
{
    int D, G;
    cin >> D >> G;
    using T = long;
    vector<T> ps(D), cs(D);
    for (int i = 0; i < D; ++i)
    {
        cin >> ps[i] >> cs[i];
    }

    int min_count = INT_MAX;

    for (int i = 0; i < (1 << D); ++i)
    {
        bitset<20> b(i);
        int count = 0;
        int score = 0;
        int pid = -1;
        for (int j = 0; j < D; ++j)
        {
            if (b[j] > 0)
            {
                // このレベルの問題は完全に解く
                score += ps[j] * 100 * (j + 1) + cs[j];
                count += ps[j];
            }
            else
            {
                pid = j;
            }
        }
        if (score < G)
        {
            // まだ足りない場合は、配点の大きい問題を解く
            if (pid >= 0)
            {
                // ps[k]-1個解いても足りない場合は、最初のbitsetの選び方がおかしい
                int s = (pid + 1) * 100;
                int c = ((G - score) + s - 1) / s;
                if (c >= ps[pid])
                {
                    continue;
                }
                else
                {
                    score += s * c;
                    count += c;
                }
            }
        }

        if (score >= G)
        {
            min_count = min(min_count, count);
        }
    }
    cout << min_count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k & 1) cout << b - a << '\n';
    else cout << a - b << '\n';

}   

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool func(pll a, pll b) {
    return b.first*(a.second+1) < a.first*(b.second+1);
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,T; cin >> N >> T;
    vector<pll> A,B;
    rep(i,N) {
        int a,b; cin >> a >> b;
        if (a) A.emplace_back(a,b);
        else B.emplace_back(a,b);
    }

    sort(all(A),func);
    sort(all(B));
    int M = min((int)A.size(),100);
    int L = B.size();
    vector<vector<ll>> dp(A.size()+1, vector<ll>(M+1,1e18));
    dp[0][0] = 0;
    rep(i,A.size()) {
        rep(j,M+1) {
            if (dp[i][j] > T) continue;
            if (j < M) chmin(dp[i+1][j+1],A[i].first*(dp[i][j]+1)+A[i].second + dp[i][j]+1);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    int ans = 0;
    rep(i,M+1) {
        if (dp[A.size()][i] > T) continue;
        ll t = dp[A.size()][i];
        int cnt = i;
        rep(j,L) {
            if (t+1+B[j].second <= T) {
                cnt++;
                t += B[j].second+1;
            } else break;
        }
        chmax(ans,cnt);
    }

    cout << ans << ln;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

int MOD = 1e9+7;

//ll po(ll b, ll p){ return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;}
// ll pomd(ll a, ll k, ll md) { ll p; if (k == 0){ return 1; } p = pomd(a, k / 2, md); p = p * p % md; if (k % 2){ p = p * a % md; } return p; }
// counting divsrs: vi arr(N); for(int i{1}; i<N; ++i) for(int j=i; j<N; j+=i) d[j]++;

#define mp make_pair
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)

void setIO(string name = ""){
    freopen((name+".in").c_str(), "r", stdin); 
    freopen((name+".out").c_str(), "w", stdout);
}	

int main(){
 	ios_base::sync_with_stdio(0); cin.tie(0); 
	// setIO();
 	ll n,x; cin >> n >> x;
 	if(n>=10){
 		cout << x << "\n";
 	}else{
 		cout << x+100*(10-n) << "\n";
 	}

}





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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(5,0);
	for(int i=0;i<n;++i){
		string s; cin>>s;
		if(s.front()=='M')++a.at(0);
		else if(s.front()=='A')++a.at(1);
		else if(s.front()=='R')++a.at(2);
		else if(s.front()=='C')++a.at(3);
		else if(s.front()=='H')++a.at(4);
	}
	vector<int>v;
	for(auto&i:a)if(i>0)v.emplace_back(i);
	uint64_t ans=0;
	for(int i=0;i<v.size();++i){
		for(int j=i+1;j<v.size();++j){
			for(int k=j+1;k<v.size();++k){
				ans+=(uint64_t)v.at(i)*v.at(j)*v.at(k);
			}
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
from decimal import Decimal
N = int(input())
A = []
for _ in range(N):
    a = Decimal(input())
    A.append(int(a * 10**9))
C = [[0 for j in range(19)] for i in range(44)]
for a in A:
    i = 0
    k = a
    while k % 2 == 0:
        k //= 2
        i += 1
    j = 0
    k = a
    while k % 5 == 0:
        k //= 5
        j += 1
    C[i][j] += 1
res = 0
for i in range(44):
    for j in range(19):
        for ii in range(44):
            for jj in range(19):
                if i + ii >= 18 and j + jj >= 18:
                    res += C[i][j] * C[ii][jj]
for a in A:
    if a**2 % 10**18 == 0:
        res -= 1
res //= 2
print(res)

Measured memory_bytes: 17788
#include <stdio.h>
int main(void){
	
	int n;
	int a;
        int i;
	int max;
	int min;
	long int murakami=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a);
		
		murakami=murakami+a;
		

                if(i==0){
                        max=a;
                        min=a;
                }
		if(max<a){
			max=a;
		}
	        if(min>a){
		        min=a;
		}
	}
		
		printf("%d %d %ld\n",min,max,murakami);
	
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner scan=new Scanner(System.in);
		String nn=scan.nextLine();
		int n=Integer.parseInt(nn);
		String val=scan.nextLine();
		String [] numnum=val.split(" ",0);
		int [] num=new int [n];
		for(int i=0;i<n;i++){
			num[i]=Integer.parseInt(numnum[i]);
		}
		int max=-10000000;
		int min=10000000;
		long count=0;
		for(int i=0;i<n;i++){
			if(num[i]>max){
				max=num[i];
			}
			if(num[i]<min){
				min=num[i];
			}
			count+=num[i];
		}
		System.out.println(min+" "+max+" "+count);
	}
}
	

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

using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int a[n];
    int dp[n];

    for (int i=0;i<n;i++)
        cin >> a[i];

    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for (int i=2;i<n;i++)
        dp[i]=min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-a[i]));

    cout << dp[n-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>  // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
#define mod 1000000007
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

void fast()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool isprime(ll x)
{
    for(int i=2;i<=sqrt(x);i++)
    {
        if(x%i==0) return false;
    }
return true;
}
void solve()
{
  ll r,d,x0;
  cin >> r >> d >> x0 ;
  ll x[11];
  x[0]=x0 ;
  for(int i=1;i<=10;i++)
  {
      x[i] = x[i-1]*r - d;
  }
  for(int i=1;i<=10;i++) cout << x[i] << endl;
}
int main()
{
  fast();
  solve();

return 0;
}


Measured memory_bytes: 3668
c = [list(map(int, input().split())) for i in range(3)]

# a1,a2,a3を++、b1,b2,b3を--してもcは変わらない
# うまいことやればa1を0にできる、これを仮定する
# 第一行からbを求める
# 第一列からaを求める

b = [c[0][0], c[0][1], c[0][2]]
a = [0, c[1][0] - b[0], c[2][0] - b[0]]

# 仮のa,bが求まった、これが9マス全体で成り立つか調べる
for i in range(3):
    for j in range(3):
        if a[i] + b[j] != c[i][j]:
            print('No')
            exit()

print('Yes')


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

#define INF 200000000

using namespace std;

int main(void){
	int n,m,s,t,c[2];
	cin >> n >> m;
	
	int d[n][n];
	fill((int *)d, (int *)d+n*n, INF);
	for(int i=0;i<n;i++) d[i][i] = 0;
	
	for(int i=0;i<m;i++){
		cin >> s;
		cin.ignore();
		cin >> t;
		cin.ignore();
		cin >> c[0];
		cin.ignore();
		cin >> c[1];
		d[s-1][t-1] = c[0];
		d[t-1][s-1] = c[1];
	}
	
	//WF
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	
	cin >> s;
	cin.ignore();
	cin >> t;
	cin.ignore();
	cin >> c[0];
	cin.ignore();
	cin >> c[1];
	cout << c[0]-c[1]-d[s-1][t-1]-d[t-1][s-1] << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct Timer{
    chrono::high_resolution_clock::time_point st;

    Timer() { reset(); }

    void reset(){
        st = chrono::high_resolution_clock::now();
    }

    chrono::milliseconds::rep elapsed(){
        auto ed = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
    }
};

struct RNG{
    mt19937 mt;

    RNG() : mt(chrono::steady_clock::now().time_since_epoch().count()){}

    int operator()(int a, int b){
        uniform_int_distribution<int> dist(a, b - 1);
        return dist(mt);
    }

    int operator()(int b){
        return (*this)(0, b);
    }
};

constexpr int D = 365;
vector<int> c(D);
vector<vector<int>> s(D, vector<int>(26));
Timer TimeKeeper;
RNG rng;

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

    int kyomu;
    cin >> kyomu;
    for(int i = 0; i < 26; ++i) cin >> c[i];
    vector<int> maxe(D, -1);
    vector<int> cur(D, 0);
    for(int i = 0; i < D; ++i){
        for(int j = 0; j < 26; ++j){
            cin >> s[i][j];
            if(chmax(maxe[i], s[i][j])) cur[i] = j;
        }
    }

    int BestScore = 0;
    auto calc_score = [&](vector<int>& v) -> int {
        if(v.size() != D)   return -INF;
        int res = 0;
        vector<int> pre(26, -1);
        for(int i = 0; i < D; ++i){
            res += s[i][v[i]];
            pre[v[i]] = i;
            for(int j = 0; j < 26; ++j){
                if(pre[j] == -1)    continue;
                res -= c[j] * (i - pre[j]);
            }
        }
        return res;
    };
    BestScore = calc_score(cur);

    int p = 0;
    while(TimeKeeper.elapsed() < 1950){
        int NxtScore = -INF;
        int ProblemType = -1;
        vector<int> nxt = cur;
        for(int i = 0; i < 26; ++i){
            if(i == cur[p]) continue;
            nxt[p] = i;
            if(chmax(NxtScore, calc_score(nxt)))    ProblemType = i;
        }
        if(NxtScore > BestScore){
            BestScore = NxtScore;
            cur[p] = ProblemType;
        }
        if(++p == D)    p = 0;
    }

    for(int i = 0; i < D; ++i)  cout << cur[i] + 1 << '\n';
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#include <cstdio>

#define M 256

int num[M]={0};
const double EPS = 1e-9;

using namespace std;

int main(void)
{
	int s,a,c;
	int n;
	int R,O;
	double H;
	double mini;
	int mins,mina,minc;
	int i1,i2;

	while(1){
		cin>>n;
		if(n==0) break;

		
		vector<int> I(n);
		for(i1=0;i1<n;i1++){
			cin>>I[i1];
		}

		mini=300.0;
		for(s=0;s<=15;s++){
			for(a=0;a<=15;a++){
				for(c=0;c<=15;c++){

					memset(num,0,sizeof(num));
					R=s;
					for(i1=0;i1<n;i1++){
						R=(a*R+c)%M;
						O=(I[i1]+R)%M;
						num[O]++;
					}

					H=0.0;
					for(i2=0;i2<M;i2++){
						if(num[i2]>0){
							double x=(double)num[i2]/(double)n;
							H-=(x*log(x));
						}
					}

					if(mini>H+EPS) {
						mini=H;
						mins=s;
						mina=a;
						minc=c;
					}
				}
			}
		}
		cout<<mins<<" "<<mina<<" "<<minc<<endl;


	}
	return 0;
}

Measured memory_bytes: 1240
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
plist = np.array(inpl())
plist_sort = np.sort(plist)
if (plist != plist_sort).sum() in [0,2]:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 12524
#include <algorithm>
#include <iostream>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

// int attack(int _hp) {
ll attack(ll _hp) {
    if (_hp == 1) {
        return 1;
    } else {
        return 2 * attack(_hp / 2) + 1;
    }
}

//  -d
int main() {
    ll hp;
    cin >> hp;

    printf("%lld\n", attack(hp));

    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6+5;
bool vis[N];
int main() {
    //  freopen("test.in", "r", stdin);
    //  freopen("ac.txt", "w", stdout);
   int m;
   scanf("%d",&m);
   int v = 7%m;
   int c = 1;
   vis[v]=1;
   while(v){
       v = (v*10+7)%m;
       ++c;
       if(vis[v]){
           c=-1;
           break;
       }
       vis[v]=1;
   }
   printf("%d",c);
}


Measured memory_bytes: 4676
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define what_is(x) cout<<#x<<" is "<<x<<en;

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int A, B, M;
	cin >> A >> B >> M;
	vector<int>a(A), b(B);
	input(a);
	input(b);
	int ans = *min_element(all(a)) + *min_element(all(b));
	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		x--, y--;
		int c;
		cin >> c;
		if (a[x] + b[y] - c < ans)
			ans = a[x] + b[y] - c;
	}
	cout << ans;


}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin>>S;

    int ans=0;
    rep(i,4){
        if(S[i]=='2')ans++;
    }
    cout << ans <<endl;



}


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

int main(){
	int S,h,m,s;
	cin >> S;

	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 3600 % 60;

	cout << h << ":" << m << ":" << s << endl;






	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(void){
  
    int num[100010] = {0};
    long long int sum = 0;
    int seq, treat, tmp1, tmp2;

    scanf("%d", &seq);
    
    for(int i = 1; i <= seq; i++){
        scanf("%d", &tmp1);
        sum += tmp1;
        num[tmp1]++;
    }

    scanf("%d", &treat);
    
    for(int i = 0; i < treat; i++){
        scanf("%d%d", &tmp1, &tmp2);
        
        sum += (tmp2 - tmp1) * num[tmp1];
        num[tmp2] += num[tmp1];
        num[tmp1] -= num[tmp1];

        printf("%lld\n", sum);
    
    }
    
    return 0;
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main () {
	io_optimized
	int a,b;
	while(cin>>a>>b)
	{
		if(a>b)
		{
			while(a--)
			{
				cout<<b;
			}
		}
		else
		{
			while(b--)
			{
				cout<<a;
			}
		}
		cout<<"\n";
	}

	return 0;
}


Measured memory_bytes: 256