akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

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

    int N;int A;int B;
    scanf("%d %d %d",&N,&A,&B);

    int count=0;
    bool aliceTurn=true;
    bool aliceMake=false;
    bool boliceMake=false;
    while(count<=100000){
        if(aliceTurn){
            if(A<=B-2){
                A++;
                aliceTurn=false;
            }else if(A!=1){
                A--;
                aliceTurn=false;
            }else{
                aliceMake=true;
                break;
            }
        }else{
            if(A+2<=B){
                B--;
                aliceTurn=true;
            }else if(B!=N){
                B++;
                aliceTurn=true;
            }else{
                boliceMake=true;
                break;
            }
        }
        count++;
    }

    if(!aliceMake&&!boliceMake){
        printf("Draw\n");
    }else if(aliceMake){
        printf("Borys\n");
    }else{
        printf("Alice\n");
    }

    return 0;

}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[100005];
ll vis[100005];

ll modMul(ll X, ll Y) {
	return (X * Y) % MOD;
}

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	ll mul = 1;
	if(N % 2 == 0) {   //even case
		for(int i = 0; i < N; i++) {
			vis[arr[i]]++;
		}
		for(int i = 1; i <= N; i += 2) {
			if(vis[i] != 2) {
				printf("0\n");
				return 0;
			}
		}
		for(int i = 0; i <= N; i += 2) {
			if(vis[i]) {
				printf("0\n");
				return 0;
			}
		}
		// mul = 1;
		
	}
	else { //odd case
		for(int i = 0; i < N; i++) {
			vis[arr[i]]++;
		}
		for(int i = 2; i < N; i += 2) {
			if(vis[i] != 2) {
				printf("0\n");
				return 0;
			}
		}
		if(vis[0] != 1) {
			printf("0\n");
			return 0;
		}
		for(int i = 1; i <= N; i += 2) {
			if(vis[i]) {
				printf("0\n");
				return 0;
			}
		}

	}
	for(int i = 0; i < N / 2; i++) {
		mul = modMul(mul, 2);
	}
	printf("%lld\n", mul);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1792
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  static int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

  static int[] factors = new int[primes.length];

  public static void main(String[] args) {

    int N = sc.nextInt();

    //N!の素因数分解
    for (int i=2; i<=N; i++) {
      int n = i;
      for (int j=0; j<primes.length; j++) {
        if (n % primes[j] == 0) {
          n /= primes[j];
          factors[j]++;
          j--;
          if (n == 1) break;
        }
      }
    }

    System.out.println(f(2, 4, 4) + f(4, 2, 4) + f(4, 4, 2) +
            g(4, 14) + g(14, 4) + g(2, 24) + g(24, 2) + h(74));

  }

  static int f(int a, int b, int c) {
    int ret = 0;
    for (int i=0; i<primes.length; i++) {
      for (int j=i+1; j<primes.length; j++) {
        for (int k=j+1; k<primes.length; k++) {
          if (factors[i] >= a && factors[j] >= b && factors[k] >= c) {
            ret++;
          }
        }
      }
    }
    return ret;
  }

  static int g(int a, int b) {
    int ret = 0;
    for (int i=0; i<primes.length; i++) {
      for (int j=i+1; j<primes.length; j++) {
        if (factors[i] >= a && factors[j] >= b) {
          ret++;
        }
      }
    }
    return ret;
  }

  static int h(int a) {
    int ret = 0;
    for (int i=0; i<primes.length; i++) {
      if (factors[i] >= a) {
        ret++;
      }
    }
    return ret;
  }

}


Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int H,p,c,f,l,b; //p:point, c:check, f:flag, l:length
	int s[50];

	while(cin >> H){
		if(H==0){return 0;}

		p=0; b=-1;
		for(int i=0; i<50; i++){ s[i]=0;}
		for(int i=H-1; i>=0; i--){
			for(int j=0 ; j<5; j++){
				cin >> s[i*5+j];
			}
		}

		while(true){
			if(b==p){break;}
			b=p;
			for(int i=H-1; i>=0; i--){
				c=s[i*5+0]; l=1; f=0;
				for(int j=1 ; j<5; j++){
					if(c==s[i*5+j]){l++;}
					else if(l>=3){break;}
					else{ f=j; l=1; c=s[i*5+j];}
				}

				if(l>=3){
					for(int j=f ; j<l+f; j++){
						p+=s[i*5+j];
						s[i*5+j]=0;
					}
				}
			}

			for(int k=0; k<H-1; k++){		
				for(int i=H-1; i>0; i--){
					for(int j=0 ; j<5; j++){
						if(s[(i-1)*5+j]==0){
							s[(i-1)*5+j]=s[i*5+j];
							s[i*5+j]=0;
						}
					}
				}	
			}
		}
		cout << p << endl;
	}
}

Measured memory_bytes: 1160
#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 snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<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;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[200005];
vector<int> ans;
void dfs(int v,int p=-1){
    for(int u:to[v]){
        if(u==p)continue;
        ans[u]+=ans[v];
        dfs(u,v);
    }
}
int main() {
    ll N,Q;
    cin>>N>>Q;
    ll a,b;
    ll p,x;
    rep(i,N-1){
        cin>>a>>b;
        --a;--b;
        to[a].push_back(b);
        to[b].push_back(a);      
    }
    ans.resize(N);

    rep(i,Q){
        cin>>p>>x;
        --p;
        ans[p]+= x;

    }
    dfs(0);
    rep(i,N){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 23424
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll N,K;
	inp >> N >> K;
	if(K==0){
		cout << N*N << endl;
		return;
	}
	ll ret = 0;
	for(ll b=K+1; b<=N; b++){
		ret += (N/b)*(b-K);
		if(N%b>=K) ret += N%b-K+1;
	}
	cout << ret << endl;
}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
std::string s;
  std::cin>>s;
  for(char i = 'a'; i <= 'z'; ++i){
		int counter = 0;
		for(int j = 0; j <= s.length(); ++j){
			if(s[j]==i)
				++counter;
		}
		if (counter%2 == 1){
			std::cout<<"No";
			return 0;
		}
  }
	std::cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
	ll argN, argC, argK;
	cin >> argN >> argC >> argK;

	vector<ll> argT(argN);
	for (ll i = 0; i < argN; ++i) {
		cin >> argT.at(i);
	}

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

	ll base = 0;
	ll numB = 0;
	for (ll i = 0; i < argN; ++i) {
		ll wait = argT.at(i) - argT.at(base);

		if (wait > argK) {
			ll numH = i - base;
			numB += numH % argC == 0 ? numH / argC : numH / argC + 1;
			base = i;
			continue;
		}

		if (i - base + 1 >= argC) {
			base = i + 1;
			numB++;
			continue;
		}
	}
	ll numL = argN - base;
	numB += numL % argC == 0 ? numL / argC : numL / argC + 1;

	cout << numB << endl;
}

Measured memory_bytes: 1024
#[test]
fn test_solve() {
    assert_eq!(solve("4 4\n1 2\n2 4\n1 3\n3 4\n"), "YES\n");
    assert_eq!(solve("5 5\n1 2\n3 5\n5 1\n3 4\n2 3\n"), "NO\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut ok = vec![true; n];
    for _ in 0..2*m {
        let a: usize = sc.read();
        ok[a-1] ^= true;
    }
    if ok.iter().all(|&b| b) {
        "YES\n".to_string()
    } else {
        "NO\n".to_string()
    }
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

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

int main() {
  int N,K;
  int sum=0;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0;i<N;i++){
    cin >> l.at(i);
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  for(int i=0;i<K;i++){
    sum += l.at(i);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if(a >= 13) {
			System.out.println(b);
		}else if(a >= 6) {
			System.out.println(b / 2);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21844
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

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

using namespace std;

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

  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  int ans = 1e9 + 9;
  for (int i = 0; i < n - k + 1; i++) {
    int tmp;
    if (x[i] * x[i + k - 1] >= 0) {
      tmp = max(abs(x[i]), abs(x[i + k - 1]));
    } else {
      tmp = min(abs(x[i]), abs(x[i + k - 1])) + x[i + k - 1] - x[i];
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

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

#define ll                 long long
#define ull                unsigned long long
#define pii                pair<int, int>
#define pll                pair<ll, ll>
#define mp                 make_pair
#define ff                 first
#define ss                 second
#define sz(x)              (int) x.size()
#define all(v)             v.begin(), v.end()
#define fill(a, b)         memset(a, b, sizeof(a))
#define endl               '\n'

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}

template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}

const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;

std::map<string, int> cnt;

int solve() {
   int n; Int(n);
   int mx = 0;
   for(int i = 1; i <= n; i++) {
    string s; cin >> s;
    cnt[s]++;
    smax(mx, cnt[s]);
   }
   std::vector<string> ans;
   for(auto x : cnt) {
       if(x.ss == mx) ans.push_back(x.ff);
   }
   sort(all(ans));
   for(auto x : ans) cout << x << endl;
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1, tc = 0;
    //Int(test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}

Measured memory_bytes: 26868
import sys
input=lambda: sys.stdin.readline().rstrip()
h,w=map(int,input().split())
A=[input() for i in range(h)]
n=h*w
edge=[[] for i in range(n)]
for i in range(n):
  h1,w1=i//w,i%w
  if w1!=w-1:
    if A[h1][w1]=="." and A[h1][w1+1]=="#":
      edge[i].append(10**6+i+1)
    else:
      edge[i].append(i+1)
  if h1!=h-1:
    if A[h1][w1]=="." and A[h1+1][w1]=="#":
      edge[i].append(10**6+i+w)
    else:
      edge[i].append(i+w)

import heapq
def dijkstra_heap(s):
  d=[float("inf")]*n
  used=[True]*n
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(0)
if A[0][0]=="#":
  print(D[h*w-1]+1)
else:
  print(D[h*w-1])

Measured memory_bytes: 5108
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
const int    dx[]={-1,0,0,1};
const int    dy[]={0,-1,1,0};
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

//幾何学テンプレート

#define equals(a,b) (fabs((a)-(b))<EPS)

//点
class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0):x(x), y(y){};

  Point operator + (Point p) {return Point (x+p.x, y+p.y);}
  Point operator - (Point p) {return Point (x-p.x, y-p.y);}
  Point operator * (double a) {return Point(a*x, a*y);}
  Point operator / (double a) {return Point(x/a,y/a);}

  double abs(){return sqrt(norm());}
  double norm(){return x*x+y*y;}

  bool operator < (const Point &p)const{
    return x!=p.x ? x<p.x:y<p.y;
  }
  bool operator > (const Point &p)const{
    return x!=p.x ? x>p.x:y>p.y;
  }
  bool operator == (const Point &p)const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};

//ベクトル
typedef Point Vector;

//内積
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

//外積
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

//線分
struct Segment{Point p1,p2;};

//直線
typedef Segment Line;

//円
class Circle{
public:
  Point c;   //中心
  double r;  //半径
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

//多角形
typedef vector<Point> Polygon;

//二つの線分の交差判定をする。

//3点の位置関係を調べる。

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>EPS)   return COUNTER_CLOCKWISE;
  if(cross(a,b)<-EPS)  return CLOCKWISE;
  if(dot(a,b)<-EPS)    return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;

  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}


signed main(){
  int q;cin>>q;

  for(int i=0;i<q;i++){
    double x0,y0,x1,y1,x2,y2,x3,y3;cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
    Point p0={x0,y0},p1={x1,y1},p2={x2,y2},p3={x3,y3};
    cout<<intersect(p0,p1,p2,p3)<<endl;
  }

  return 0;
}



Measured memory_bytes: 3228
#include<stdio.h>
int main(void){
  char b;
  scanf("%c",&b);
  if(b=='A'){
    printf("T\n");
  }else if(b=='G'){
    printf("C\n");
  }else if(b=='C'){
    printf("G\n");
  }else{
    printf("A\n");
  }
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;

  cin >> n;
  if (n == 0) {
    cout << 2 << endl;
    return 0;
  } else if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  long l = 1;
  long pre = 2;
  int i = 1;

  while (i != n) {
    long tmp = l;
    l += pre;
    pre = tmp;
    i++;
  }
  cout << l << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
const int MAX_N=205;
const int INF=0x3f3f3f3f;
ll d[MAX_N][MAX_N];
int R[10];
bool vis[MAX_N];
int n,m,r,a,b;
ll c;
ll ans;
void floyd()
{
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}
void dfs(int before,int t,ll tmp)
{
	if(tmp>=ans)
	{
		return;
	}
	if(t==r)
	{
		ans=min(tmp,ans);
		return;
	}
	for(int i=1;i<=r;i++)
	{
		if(!vis[R[i]])
		{
			vis[R[i]]=true;
			if(before!=0)
			dfs(i,t+1,tmp+d[R[i]][R[before]]);
			else
			{
				dfs(i,t+1,tmp);
			}
			vis[R[i]]=false;
		}
	}
}
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	scanf("%d%d%d",&n,&m,&r);
	mem(d,0);
	mem(R,0);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i==j)
			d[i][j]=0;
			else
			d[i][j]=INF;
		}
	}
	mem(vis,0);
	ans=1000000000000000000;
	for(int i=1;i<=r;i++)
	{
		scanf("%d",R+i);
	}
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%lld",&a,&b,&c);
		d[b][a]=d[a][b]=c;
	}
	floyd();
	dfs(0,0,0);
	printf("%lld\n",ans);
	return 0;
}



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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto&& i : a) {
    cin >> i;
  }
  sort(a.begin(), a.end());
  auto b = a;
  b.erase(unique(b.begin(), b.end()), b.end());
  vector<int> cnt;
  for (auto&& i : b) {
    cnt.push_back(upper_bound(a.begin(), a.end(), i) - lower_bound(a.begin(), a.end(), i));
  }
  sort(cnt.begin(), cnt.end());
  int ans = 0;
  for (int i = 0; i < static_cast<int>(cnt.size()) - k && i < cnt.size(); i++) {
    ans += cnt[i];
  }
  cout << ans << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

Measured memory_bytes: 2936
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap = 1){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

std::vector<unsigned> make_gap_table(unsigned n){
  std::vector<unsigned> gaps;
  unsigned h = 1;
  unsigned i = 1;
  while(h <= n){
    gaps.push_back(h);
    h = pow(4,i) + 3*pow(2,i-1) + 1;
    i++;
  }
  return gaps;
}

void shell_sort(unsigned a[], unsigned n){
  auto gaps = make_gap_table(n);
  unsigned count = 0;
  for(int i=gaps.size()-1;i>=0;i--){
    count += insertion_sort(a,n,gaps[i]);
  }

  std::cout << gaps.size() << '\n';

  for(int i=gaps.size()-1;i;i--){
    std::cout << gaps[i] << ' ';
  }
  std::cout << gaps[0] << '\n';

  std::cout << count << '\n';
}

int main(){
  std::ios::sync_with_stdio(false);
  unsigned n,buf;
  std::cin >> n;
  std::vector<unsigned> a(n);
  for(unsigned i = 0; i < n; i++){
    std::cin >> buf;
    a[i] = buf;
  }
  shell_sort(a.data(),a.size());
  for(auto &v : a){
    std::cout << v << '\n';
  }
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	cin>>a>>b;
	for(int i=0;i<3;i++)
	{
		if(a[i]!=b[2-i]) {cout<<"NO"<<endl;return 0;}
	}
	cout<<"YES"<<endl;
	return 0;
}

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

int main(){
  int a,b,c,d,e;
  int ans;

  cin >> a >> b >> c >> d >> e;

  if(a<=0){
    ans = (-a)*c+d+b*e;
  }else{
    ans = (b-a)*e;
  }

  cout << ans << endl;


  return 0;
}


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

int main(int, char**) {
        int64_t N, M, A;
        std::cin >> N >> M;
        for (int i; i<M; i++) {
                std::cin >> A;
                N = N - A;
                if (N < 0) {
                        N = -1;
                        break;
                }
        }
        std::cout << N << std::endl;
        return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	string s;
	// nyuryoku
	cin >> s;
	// keisan
	for(int i=0;i<3;i++){
		if(s[i] == s[i+1]){
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	// syutsuryoku
}

Measured memory_bytes: 3564
use proconio::input;

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        k: usize,
    }

    for i in 0..=k {
        for j in 0..=k {
            if i + j > k { break; }
            for v in 0..=k {
                if i + j + v > k { break; }
                if a * 1 << i < b * 1 << j && c * 1 << v > b * 1 << j {
                    println!("Yes");
                    return;
                }
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const char nl = '\n';

void solve()
{
    int num, i = 1;
    while (cin >> num) {
        if (num == 0) {
            cout << i << nl;
            return;
        }
        ++i;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL K;
	cin >> K;

	if((K % 2) == 0){
		printf("-1\n");
		return 0;
	}

	LL ans = 1;
	LL r = 7 % K;
	while(r != 0){
		r = 10*r + 7;
		r = (r % K);
		ans++;
		if(ans > K+1){
			break;
		}
	}

	if(ans > K+1){
		printf("-1\n");
	}
	else{
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3784
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(h int) int {
	attack := 0
	hp := h
	dup := 1
	for hp > 0 {
		hp >>= 1
		attack += dup
		dup <<= 1
	}
	return attack
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

Measured memory_bytes: 1784
N=int(input())
A_list=[int(thing) for thing in input().split(" ")]
B_list=[int(thing) for thing in input().split(" ")]
C_list=[int(thing) for thing in input().split(" ")]
ret=0
P_B=0
for d in range(len(A_list)):
    tottano=A_list[d]-1
    if d!=0 and tottano!=N:
        if tottano==sakki+1:
            ret=ret+C_list[sakki]
    ret=ret+B_list[tottano]
    sakki=tottano
print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	std::vector<int> miin(26,0);
	int n;
	std::cin >> n;
	string ss;
	std::cin >> ss;
	rep(j,ss.size()){
		miin[ss[j]-97]++;
	}
	rep(i,n-1){
		string s;
		std::cin >> s;
		std::vector<int> dum(26,0);
		rep(j,s.size()){
			dum[s[j]-97]++;
		}
		rep(j,26){
			miin[j]=min(miin[j],dum[j]);
		}
	}
	string ans;
	rep(i,26){
		rep(j,miin[i])std::cout << (char)(i+97);
	}
	std::cout  << std::endl;
	
}


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

int main(){
  string s,t;
  cin >> s >> t;
  int ls=s.length(), lt=t.length();
  
  vector<char> S(ls),T(lt);
  rep(i,ls) S.at(i) = s[i];
  rep(i,lt) T.at(i) = t[i];
  sort(S.begin(), S.end());
  sort(T.begin(), T.end(), greater<char>());
  
  rep(i,ls) s[i] = S.at(i);
  rep(i,lt) t[i] = T.at(i);
  
  if(t > s) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') {
      count++;
    }
    else if (S[i] == 'D') {
      count--;
    }
    ans = max(ans,count);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a / b << " ";
    cout << a % b << " ";
    cout << fixed << setprecision(8);
    cout << static_cast<double>(a) / b << "\n";
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
char arr[101][101];
int h,w;
int dp[101][101][2];
int f(int i,int j,int p)
{
    if(i >= h || j >= w)
        return INT_MAX;

    int cost;
    if(arr[i][j] == '#' && p == 1)
        cost = 1;
    else cost = 0;

    if(i == h-1 && j == w-1)
    {
        return cost;
    }

    if(dp[i][j][p] != -1)
        return dp[i][j][p];


    int a,b;
    if(arr[i][j] == '.')
    {
        a = f(i+1,j,1);
        b = f(i,j+1,1);
        dp[i][j][p] = min(a,b);

    }
    else
    {
        a = f(i+1,j,0);
        b = f(i,j+1,0);
        dp[i][j][p] = cost+min(a,b);
    }
    return dp[i][j][p];
}

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

    memset(dp,-1,sizeof(dp));
    cin>>h>>w;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin>>arr[i][j];
        }
    }
    int ans = f(0,0,1);
    cout<<ans<<"\n";
    return 0;
}





















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

int solve(int x) {
  int res = 0;
  while (x) {
    res++;
    x %= __builtin_popcount(x);
  }
  return res;
}

int main() {
  int n; string s; cin >> n >> s;
  reverse(s.begin(), s.end());
  int modp = count(s.begin(), s.end(), '1') + 1;
  int modm = modp - 2;
  if (modm < 1) {
    modm = n + 1;
  }
  int sump = 0;
  int summ = 0;
  vector<int> res(n);
  for (int i = 0, bp = 1, bm = 1; i < n; i++, bm = bm * 2 % modm, bp = bp * 2 % modp) {
    if (s[i] == '1') {
      sump = (sump + bp) % modp;
      summ = (summ + bm) % modm;
    }
  }
  for (int i = 0, bp = 1, bm = 1; i < n; i++, bm = bm * 2 % modm, bp = bp * 2 % modp) {
    if (s[i] == '0') {
      res[n-i-1] = solve((sump + bp) % modp) + 1;
    } else {
      if (modm == n + 1) res[n-i-1] = 0;
      else {
        int t = summ - bm + modm;
        t %= modm;
        res[n-i-1] = solve(t) + 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
}

Measured memory_bytes: 4436
import collections
def cal(n):
    ans = int(n*(n-1)/2)
    return ans 
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
temp = list(c.values())
t_val = list(map(cal,c.values()))
t_key = list(c.keys())
t_cal = sum(t_val)
# print(t_key)
# print(t_cal)
# print(temp)
for i in range(n):
    ans1 = c[a[i]]-1
    print(t_cal - ans1)

Measured memory_bytes: 26780
def comb(n,r,m):
    if r == 0: return 1
    return memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)
def mempow(a,b):
    temp = 1
    yield temp
    for i in range(b):
        temp = temp * a % 998244353
        yield temp
def memfact(a):
    temp = 1
    yield temp
    for i in range(1,a+1):
        temp = temp * i % 998244353
        yield temp

N,M,K = (int(x) for x in input().split())
memp = []
memf = []
mpappend = memp.append
mfappend = memf.append
for x in mempow(M-1,N-1):
    mpappend(x)
for x in memfact(N-1):
    mfappend(x)
ans = 0
if M == 1:
    if K + 1 < N:
        print('0')
    else:
        print('1')
else:
    i = 0
    for i in range(K+1):
        ans = (ans + (comb(N-1,i,998244353)*M*memp[N-i-1])) % 998244353
    print(ans)

Measured memory_bytes: 92188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll dp[2][13];
    string ss;cin>>ss;
    int t=ss.size();
    rep(i,2)rep(j,13)dp[i][j]=0;
    dp[0][0]=1;
    int keta=1;
    for(int i=0;i<t;i++){
        if(ss[t-i-1]=='?'){
            for(int j=0;j<13;j++)for(int k=0;k<10;k++){
                dp[(i+1)&1][(k*keta+j)%13]+=dp[i&1][j];
                dp[(i+1)&1][(k*keta+j)%13]%=mod;
            }
        }
        else{
            int k=ss[t-i-1]-'0';
            for(int j=0;j<13;j++){
                dp[(i+1)&1][(k*keta+j)%13]+=dp[i&1][j];
                dp[(i+1)&1][(k*keta+j)%13]%=mod;               
            }
        }
        keta=keta*10%13;
        for(int j=0;j<13;j++)dp[i&1][j]=0;
    }
    cout<<dp[t&1][5]<<endl;
    return 0;
}


Measured memory_bytes: 512
N = int(input())
lst = list(map(int, input().split()))
S = sum(lst)
ans = []

for i in range(2, N, 2):
  S -= 2 *lst[i-1]
  
ans.append(S)

for i in range(1, N):
  ans.append(2 * lst[i-1] - ans[i-1])

s = " ".join([str(n) for n in ans])
print(s)

Measured memory_bytes: 19092
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i) = (a);(i) < (b);(i)++)
#define Rep(i,n) For(i,0,n)
#define All(a) (a).begin(),(a).end()
#define sp " "
#define Rev(s,a,b) reverse((s).begin()+(a),(s).begin()+(b)+1)//s[a]....s[b] rev
#define MAX 100100

vector<char> boin = {'a','i','u','e','o'};
typedef long long ll;

map<int,pair<int,int>> tree;
map<pair<int,int>,int> ans;
using Graph = vector<vector<int>>;
vector<bool> seen;

int main(){
    int n;
    cin >> n;
    Graph G(n);
    for(int i = 0;i < n-1;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
        pair<int,int> e = make_pair(a,b);
        tree.emplace(i,e);
        e = make_pair(b,a);
        tree.emplace(i,e);
    }

    int k = 0;
    seen.assign(n,false);
    queue<pair<int,int>> que;
    int res;
    pair<int,int> s = make_pair(0,0);
    que.push(s);
    seen[0] = true;
    while(!que.empty()){
        res = 1;
        int v = que.front().first;
        int b = que.front().second;
        que.pop();
        int sz = G[v].size();
        k = max(sz,k);
        for(int i = 0;i < G[v].size();++i){
            if(seen[G[v][i]] == true)continue;
            seen[G[v][i]] = true;
            pair<int,int> e = make_pair(v,G[v][i]);
            if(res == b){
                ans.emplace(e,sz);
                e = make_pair(G[v][i],v);
                ans.emplace(e,sz);
                que.push(make_pair(G[v][i],sz));
                res++;
            }else{
                ans.emplace(e,res);
                e = make_pair(G[v][i],v);
                ans.emplace(e,res);
                que.push(make_pair(G[v][i],res));
                res++;
            }
        }
    }    
    cout << k << endl;
    for(int i = 0;i < n-1;i++){
        pair<int,int> e = tree.at(i);
        cout << ans.at(e) << endl;
    }
    //cin >> n;
}

Measured memory_bytes: 24832
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N;
  ll ac=0,wa=0,tl=0,re=0;
  
  REP(i,N) {
    in<string> S;
      if (S=="AC")
        ac++;
      if (S=="WA")

        wa++;

      if (S=="TLE")

        tl++;

      if (S=="RE")

        re++;

  }


  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;

  cout << "TLE x " << tl << endl;

  cout << "RE x " << re << endl;

}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3632
N = int(input())
S = input()
L = [S[1:].count('E'),S[:N].count('W')]
k = 0
w = 0
e = S[1:].count('E')
while (k <= N-2):
  if (S[k] == 'W' and S[k+1] == 'W'):
    w += 1
  elif (S[k] == 'W' and S[k+1] == 'E'):
    w += 1
    e -= 1
  elif (S[k] == 'E' and S[k+1] == 'W'):
    w += 0
  else:
    e -= 1
  L.append(e+w)
  k += 1
  
print(min(L))

Measured memory_bytes: 15564
count = gets.chomp.to_i
input_line = gets.split(' ').map(&:to_i)

if input_line.include?(0)
  puts 0
  exit
end

total = 1
input_line.each do |num|
  if total*num > 1000000000000000000
    puts -1
    exit
  else
    total *= num
  end
end
puts total


Measured memory_bytes: 21540
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int grid[505][505];
int ans[250005][4];
int main(){
    int h,w; cin >> h >> w;
    rep(i,h)rep(j,w) cin >> grid[i][j];
    int cnt = 0;
    
    rep(i,h)rep(j,w){
        if(j == w-1 && grid[i][j]%2 == 1){
            if(i == h-1) continue;
            ans[cnt][0] = i+1;
            ans[cnt][1] = w;
            ans[cnt][2] = i+2;
            ans[cnt][3] = w;
            grid[i+1][w-1]++;
            cnt++;
            continue;
        }
        if(grid[i][j]%2 == 1){
            ans[cnt][0] = i+1;
            ans[cnt][1] = j+1;
            ans[cnt][2] = i+1;
            ans[cnt][3] = j+2;
            grid[i][j+1]++;
            cnt++;
        }
    }
    
    cout << cnt << endl;
    rep(i,cnt){
        printf("%d %d %d %d\n",ans[i][0],ans[i][1],ans[i][2],ans[i][3]);
    }

}

Measured memory_bytes: 6684
import bisect
w,h = map(int,input().split())
p = [int(input()) for _ in [0]*(w)]
q = [int(input()) for _ in [0]*(h)]

p.sort()

ps = [0,p[0]]
for i in range(1,w):
    ps.append(ps[-1]+p[i])

res = sum(p)
for e in q:
    k = bisect.bisect_right(p,e)
    res += e*(w-k+1) + ps[k]
print(res)

Measured memory_bytes: 72664
#include <iostream>

using namespace std;

int main(int argc, char** argv) {
    char S[1000];
    int K;
    cin >> S >> K;
    int ans;
    for (int i = 0; i < K; i++) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
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 main(void) {
    llint n, m;
    cin >> n >> m;

    llint ans, c;
    c = m - 2*n;
    if(c>=0) {
        ans = n;
        c /= 4LL;
        ans += c;
        cout << ans << endl;
    }
    else {
        ans = m / 2;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import java.math.BigDecimal

fun main(arr:Array<String>) {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    goal = k
    var win = 0L
    var lose = 0L
    val ret = (1..n).map { getAns(it) }
    val max = ret.map { it.lose + it.win }.max()!!
    ret.forEach {
        val b = max / (it.lose+it.win)
        win += it.win*b
        lose += it.lose*b
    }
    val ans = win.toDouble()/(win+lose).toDouble()
    println("%.10f".format(ans))

}

val dic = mutableMapOf<Int, Result>()
var goal = 0
fun getAns(current:Int):Result {
    if(current >= goal) {
        return Result(1, 0)
    }
    dic[current]?.let { return it }
    val ret = getAns(current * 2)
    val ans = Result(ret.win, ret.lose + (ret.win+ret.lose))
    dic[current] = ans
    return ans
}

class Result(val win:Long, val lose:Long)

Measured memory_bytes: 40460
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1],sum=0;

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

    }

    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            sum+=a[i]*a[j];
        }
    }

    cout<<sum<<endl;
    exit(0);
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N,C;
  cin >> N >> C;
  long long x[N], v[N], sum = 0, answer = 0, y[N];
  multiset<long long> z;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }
  for (int i = N-1; i+1; i--) {
    sum += v[i];
    y[i] = sum-2*(C-x[i]);
    answer = max(answer,sum-C+x[i]);
    z.insert(y[i]);
  }
  sum = 0;
  for (int i = 0; i < N-1; i++) {
    z.erase(z.find(y[i]));
    sum += v[i];
    answer = max(answer,*z.rbegin()+sum-x[i]);
  }
  z.clear();
  sum = 0;
  for (int i = 0; i < N; i++) {
    sum += v[i];
    y[i] = sum-2*x[i];
    answer = max(answer,sum-x[i]);
    z.insert(y[i]);
  }
  sum = 0;
  for (int i = N-1; i; i--) {
    z.erase(z.find(y[i]));
    sum += v[i];
    answer = max(answer,*z.rbegin()+sum-C+x[i]);
  }
  cout << answer;
}

Measured memory_bytes: 10636
// https://atcoder.jp/contests/abc154/tasks/abc154_d
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 200005

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

	double exp = 0;
	rep(i,k)exp += ((double)p[i]+1)/2.0;
	double ans = exp;
	for(int i=k;i<n;i++){
		exp += ((double)p[i]+1)/2.0;
		exp -= ((double)p[i-k]+1)/2.0;
		if(exp>ans){
			ans = exp;
		}
	}
	cout << fixed << setprecision(10) << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

class Main {

    public int foo(int K, int N, int[] dist) {
        int last = K;
        int max = 0;
        for (int i = 1; i < N; i++) {
            int d = dist[i]-dist[i-1];
            max = Math.max(max, d);
            last -= d;
        }
        max = Math.max(max, last);
        return K - max;
    }

	public static void main(String[] args){
        Main o = new Main();

		Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        sc.close();

        System.out.println(o.foo(K, N, arr));
	}
}


Measured memory_bytes: 65376
l = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

w = gets.chomp.split("")

w.each do |v|
	print(l[(l.index(v).to_i-3)%26])
end
print("\n")

Measured memory_bytes: 8744
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m,k;
  cin >> n >> m >> k;

  ll a[n+1],b[m+1];
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<m;i++)cin >> b[i];

  ll sa[n+1]={},sb[m+1]={};

  //sa[i]..aのi番目までの和(1-indexed)
  for(int i=0;i<n;i++)sa[i+1]=sa[i]+a[i];
  for(int i=0;i<m;i++)sb[i+1]=sb[i]+b[i];

  ll s=0;
  for(int i=0;i<=n;i++){
    if(sa[i]<=k){  //sa[i]>kなら論外
      ll c=lower_bound(sb,sb+m,k-sa[i])-sb;  //sb[c]+sa[i]が初めてkを超えるようなcを探す
      if(c==m+1)c--; //sa[i]+sb[m]<=kのとき
      else if(sa[i]+sb[c]>k)c--;  //upper_boundについてよくわかっていないがこれが必要らしい(これがないとサンプルすら通らない)
      s=max(s,c+i);
    }
  }
  cout << s << endl;
}



Measured memory_bytes: 9860
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}
map<string, int>mp;
string s[105], t[105];
signed main() {
	int n, m,sum=0;
	cin >> n;
	rep(i, n) {
		cin >> s[i];
		mp[s[i]]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> t[i];
		mp[t[i]]--;
	}
	for (auto p : mp) {
		if (p.second > sum)sum = p.second;
	}
	cout << sum << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; cin>>n>>k;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	int L=0,R=*max_element(a.begin(),a.end());
	while(R-L>1){
		int M=(L+R)/2;
		int cnt=0;
		for(auto&&i:a)cnt+=(i-1)/M;
		if(cnt>k)L=M;
		else R=M;
	}
	cout<<R<<"\n"s;
}


Measured memory_bytes: 3920