akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string str;
	int ary[100];
	int ans = 0;

	while (cin >> str)
	{
		ans = 0;

		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] == 'I') ary[i] = 1;
			if (str[i] == 'V') ary[i] = 5;
			if (str[i] == 'X') ary[i] = 10;
			if (str[i] == 'L') ary[i] = 50;
			if (str[i] == 'C') ary[i] = 100;
			if (str[i] == 'D') ary[i] = 500;
			if (str[i] == 'M') ary[i] = 1000;
		}

		for (int i = 0; i < str.size() - 1; i++)
		{
			if (ary[i] < ary[i + 1]) ans -= ary[i];
			else					 ans += ary[i];
		}
		ans += ary[str.size() - 1];
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#!python3

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


def main():
    d = {i: 0 for i in range(1, N + 1)}
    for a in A:
        d[a] += 1
    
    for ans in d.values():
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38948
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   if c+f<F[v]:F[v]=c+f;heappush(H,(c+f,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6304
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
judge = False
ans = 10**9
for i in range(2**N):
  even = []
  odd = []
  x = 0
  tmp = True
  for j in range(N):
    if ((i>>j) & 1):
      if j%2==1:
        even.append([B[j],j])
      else:
        odd.append([B[j],j])
      
    else:
      if j%2==1:
        odd.append([A[j],j])
      else:
        even.append([A[j],j])
        
  if N%2==0:
    if len(even)!=len(odd):
      continue
      
  else:
    if (len(even)-1)!=len(odd):
      continue
      

  even = sorted(even,key = lambda x:x[0])
  odd = sorted(odd,key = lambda x:x[0])
  ind = [0]*N
  for k in range(N//2):
    o = odd[k]
    e = even[k]
    if o[0]<e[0]:
      tmp = False
      break
    
    if (k!=N//2-1)or(N%2==1):
      if o[0]>even[k+1][0]:
        tmp = False
        break
    
    ind[2*k]=e[1]
    ind[2*k+1]=o[1]

  if tmp:
    if N%2==1:
      ind[N-1]=even[-1][1]
      

    for k in range(N):
      y = ind[k]
      x+=abs(y-k)
      ind = [x+1 if (x<y)and(x>=k) else x for x in ind]
    ans = min(ans,x)
    judge = True
    
if judge:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 54748
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
#define IS_INF(x) x < 2100000000
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}




int main(){

    FAST_IO
    int ans,N;
    ans = 0;
    cin>>N;
    int prev = 0;
    for(int i = 1; i <= N; i++){
        int tmp;
        cin>>tmp;
        if(i != 1){
            if(tmp == prev) { ans++; prev = 0;}
            else prev = tmp;
        }
        else prev = tmp;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Heavenly Jewels
public class Main{

	double EPS = 1e-8;
	double norm(Point p) {
		return Math.hypot(p.x, p.y);
	}
	double inp(Point p1, Point p2) {
		return p1.x*p2.x + p1.y*p2.y;
	}
	double extp(Point p1, Point p2) {
		return p1.x*p2.y - p2.x*p1.y;
	}
	Point sub(Point p1, Point p2) {
		return new Point(p1.x-p2.x, p1.y-p2.y);
	}
	int ccw(Point a, Point b, Point c) {
		Point p = sub(b, a);
		Point q = sub(c, a);
		if(extp(p, q) > EPS) return 1;		// counter clockwise
		if(extp(p, q) < -EPS)return -1;		// clockwise
		if(inp(p, q) < -EPS) return 2;		// c--a--b on line
		if(Math.abs(norm(p) - norm(q)) < EPS) return -2;	// a--b--c on line
		return 0;				// a--c--b(or a--c=b) on line 
	}
	Point crosspoint(Line l, Line m) {
		if(isParallel(l, m)){
			throw new IllegalArgumentException("parallel");
		}
		double A = extp(sub(l.t, l.s), sub(m.t, m.s));
		double B = extp(sub(l.t, l.s), sub(l.t, m.s));
		if (Math.abs(A) < EPS && Math.abs(B) < EPS) return m.s; // same line
		if (Math.abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
		Point tp = sub(m.t, m.s);
		return new Point(m.s.x + B/A*tp.x, m.s.y + B/A*tp.y);
	}
	boolean isParallel(Line l, Line m){
		Point a = new Point(l.t.x - l.s.x, l.t.y - l.s.y);
		Point b = new Point(m.t.x - m.s.x, m.t.y - m.s.y);
		if(Math.abs(Math.abs((a.x*b.x + a.y*b.y)/(Math.hypot(a.x, a.y)*Math.hypot(b.x, b.y)) - 1)) < EPS){
			return true;
		}
		return false;
	}

	double area(Point[] p) {
		double s = 0;
		for(int i=0; i<p.length; i++) {
			int j = (i+1)%p.length;
			s += extp(p[i], p[j]);
		}
		s /= 2;
		return Math.abs(s);
	}
	Point[] convexCut(Point[] p, Line l) {
		List<Point> q = new ArrayList<Point>();
		for (int i = 0; i < p.length; ++i) {
			Point a= p[i], b = p[(i+1)%p.length];
			if (ccw(l.s, l.t, a) != -1) q.add(a);
			if (ccw(l.s, l.t, a)*ccw(l.s, l.t, b) < 0)
				q.add(crosspoint(new Line(a, b), l));
		}
		return q.toArray(new Point[q.size()]);
	}

	class Point {
		double x;
		double y;
		public Point(double x_, double y_) {
			x = x_; y=y_;
		}
	}
	class Line {
		Point s,t;
		public Line(Point s_, Point t_) {
			s = s_; t = t_;
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		int T = 1;
		for(;;){
			int x1 = sc.nextInt(), y1 = sc.nextInt(), x2 = sc.nextInt(), y2 = sc.nextInt(), x3 = sc.nextInt(), y3 = sc.nextInt();
			if((x1|y1|x2|y2|x3|y3)==0)break;
			Point[] p = new Point[4];
			p[0] = new Point(0, 0);
			p[1] = new Point(10000, 0);
			p[2] = new Point(10000, 10000);
			p[3] = new Point(0, 10000);
			Point ic = new Point(x1, y1);
			Point pc = new Point(x2, y2);
			Point ac = new Point(x3, y3);
			Point mid = new Point((x1+x2)/2.0, (y1+y2)/2.0);
			Point sub = sub(pc, ic);
			Point r = new Point(mid.x-sub.y, mid.y+sub.x);
			p = convexCut(p, new Line(mid, r));
			mid = new Point((x1+x3)/2.0, (y1+y3)/2.0);
			sub = sub(ac, ic);
			r = new Point(mid.x-sub.y, mid.y+sub.x);
			p = convexCut(p, new Line(mid, r));
			double a = area(p);
			System.out.printf("%d %.5f\n", T++, a/(100000000));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,s2;
    int i,j,c=0;
    cin>>s;
    s2=s;
    reverse(s2.begin(),s2.end());
    for(i=0;i<s.size();i++)
    {
        if(s[i]!=s2[i])
        {
            c++;
        }
    }
    cout<<c/2<<endl;
}


Measured memory_bytes: 256
N=int(input())
P=list(map(int,input().split()))
ans = 0
for i in range(1,N+1):
  if P[i-1]==i and i!=N:
    P[i-1],P[i]=P[i],P[i-1]
    ans += 1
  elif P[i-1]==i and i==N:
    ans += 1
print(ans)

Measured memory_bytes: 14004
N = int(input())
A = [0] * N
f = s = 1
fi = si = 0
for i in range(N):
    A[i] = int(input())
    if A[i] > f:
        s = f
        si = fi
        f = A[i]
        fi = i
    elif A[i] > s:
        s = A[i]
        si = i
for i in range(N):
    if i != fi:
        print(f)
    else:
        print(s)


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

int main() {
  
	long long int a,b,c[100010],d=0;
  cin >> a >> b;
  
  long long int ans =0;
  
  for(int i=0;i<a;i++)
    cin >> c[i];
  

  
  for(int i=0;i<a-1;i++){
    
    
    if(b < c[i]+c[i+1]){
      
      ans += (c[i+1]+c[i])-b;
      c[i+1] = max(d,b-c[i]);
    }
    
  }
  cout << ans << endl;
}
       


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);

using namespace std;
const int N = 2e5 + 2;
string days[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main()
{
    fast;
    string s; cin >> s;
    int dayn;
    FOR(i, 7, 0)
    {
        if(s == days[i])
        {
            dayn = i;
            break;
        }
    }
    cout << 7 - dayn;
    return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

vi dx = {0, -1, -1, -1, 0, 1, 1, 1};
vi dy = {1, 1, 0, -1, -1, -1, 0, 1};

string solve(int h, int w, const vector<vector<char>> &donuts) {
  string res = "A";
  map<string, bool> m;
  REP(i, h) {
    REP(j, w) {
      vector<string> s;
      REP(k, 8) {
        string tmp = "";
        int posi = i, posj = j;
        tmp += donuts[posi][posj];
        posi = (posi + dy[k] + h) % h;
        posj = (posj + dx[k] + w) % w;
        while(posi != i || posj != j) {
          s.push_back(tmp);
          // if(i == 4 && j == 5 && k == 5) cout << posi << ":" << posj << endl;
          tmp += donuts[posi][posj];
          posi = (posi + dy[k] + h) % h;
          posj = (posj + dx[k] + w) % w;
        }
        // if(i == 4 && j == 5 && k == 5) cout << tmp << endl;
        s.push_back(tmp);
      }
      // printv(s);
      REP(k, SZ(s)) {
        if(m[s[k]] && (res == "A" || SZ(res) < SZ(s[k]) || (SZ(res) == SZ(s[k]) && s[k] < res))) {
          res = s[k];
        }
      }
      REP(k, SZ(s)) {
        m[s[k]] = true;
      }
    }
  }
  return res;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  
  while(1) {
    int h, w; cin >> h >> w;
    if(h == 0 && w == 0) break;
    vector<vector<char>> donuts(h, vector<char>(w));
    REP(i, h) {
      REP(j, w) {
        cin >> donuts[i][j];
      }
    }
    string ans = solve(h, w, donuts);
    cout << ((SZ(ans) == 1) ? "0" : ans) << endl;
  }
}



Measured memory_bytes: 37280
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

min_ab = min(a_list) + min(b_list)
for i in range(m):
  x, y, c = map(int, input().split())
  if a < x or b < y:
    continue
  min_ab = min(a_list[x-1] + b_list[y-1] - c, min_ab)

print(min_ab)

Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n; cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(dp[i-2]+abs(h[i]-h[i-2])));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
long long GCD(long long a,long long b){
    if(b==0)return a;
    return GCD(b,a%b);
}
long long LCM(long long a,long long b){
    return a*b/GCD(a,b);
}
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll k;
    cin>>k;
    ll f=7;
    rep(i,1e7+1){
        if(f%k==0){
            cout<<i+1<<endl;
            return 0;
        }
        f*=10;
        f+=7;
        f%=k;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(){
int n,e,s;
long long r;
cin>>n;
if(n>=15){
    if(n%15==0){
        r=(n/15)*200;
        cout<<(n*800)-r<<"\n";
    }
    else{
        s=n%15;
        e=n-s;
        cout<<((e*800)-((n/15)*200))+(s*800)<<"\n";
    }
}
else{
    cout<<n*800;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e3+5,MOD=998244353;
int n,m,ans;
int a[N],f[N]; 
signed main(){
	scanf("%lld%lld",&n,&m);
	for (register int i=1; i<=n; ++i) scanf("%lld",&a[i]); 
	for (register int i=1; i<=n; ++i)
	{
		for (register int j=m; j>a[i]; --j) f[j]=(f[j]+f[j-a[i]])%MOD;
		f[a[i]]=(f[a[i]]+i)%MOD;
		ans=(ans+f[m]*(n-i+1)%MOD)%MOD;
		f[m]=0;
	}
	printf("%lld\n",ans);
return 0;
}


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

using namespace std;

int main()
{   int n,m;
    long long ans=0;
    cin >>n>>m;
    vector <pair<long long,long long> > p(n);
    long long a[n],b[n];
    for(int i=0;i<n;i++){
        cin >> a[i]>>b[i];
        p[i]=make_pair(a[i],b[i]);
    }
    sort(p.begin(),p.end());
    int i=0;
    while(true){
       if(p[i].second>m){
        ans+=p[i].first*m;
        m-=m;
       }
       else{
        ans+=p[i].first*p[i].second;
        m-=p[i].second;
       }
       i++;
       if(m==0)break;
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,m,a,ans1=0,d=0,c[100000]={};
  int ans2[1000000]={};
  string b;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a>>b;
   if(c[a]==0 && b=="AC"){
     c[a]++;
     d+=ans2[a];
     ans1++;
   }
   if(c[a]==0 && b=="WA"){
      ans2[a]++;
   }
  }
  cout<<ans1<<" "<<d<<endl;
  return(0);
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> mp;
int main(){
	while(1){
	int n,m;
	cin>>n>>m;
	if(n==0)break;
	vector<int> dp(n,0),mi(n,0);
	for(int i=0;i<m;i++){
		int s,k,c;
		cin>>s>>k;
		for(int j=0;j<k;j++){
			cin>>c;
			c--;
			dp[c]+=s;
		}
		if(k==1)mi[c]+=s;
	}
	int ma=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(i!=j)ma=max(ma,dp[i]-mi[j]);
	//sort(dp.begin(),dp.end());
	//sort(mi.begin(),mi.end() );
	cout<<ma+1<<endl;

	}

	return 0;
}



Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        bool ok = s.Contains("AC");

        string answer = ok ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 25840
h,w,d = map(int,input().split())

dic = {}
for i in range(h):
  line = list(map(int,input().split()))
  for j in range(w):    
    dic[line[j]-1]=(i,j)              

q = int(input())
L = [0]*q
R = [0]*q    
    
for i in range(q):
  L[i],R[i] = map(int,input().split())    
    
A = [0]*(h*w)
i = 0
j = 0
while i < h*w:  
  if A[i]>0:      
    pass
  else:
    j = i+d
    while j < h*w and j-d>=0:
      pos_j = dic[j]
      pos_jd = dic[j-d]
      A[j] = A[j-d] + abs(pos_j[1]-pos_jd[1]) + abs(pos_j[0]-pos_jd[0])    
      j += d        
  i+=1
  
for i in range(q):
  print(A[R[i]-1] - A[L[i]-1])  

Measured memory_bytes: 30532
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

	for (int i = 1; i < 10000;i++) {
		int zei8 = i * 0.08;
		int zei10 = i * 0.1;
		if (zei8 == a && zei10 == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for(int i = (s), mi = (t); i <= mi; i++)
#define dwn(i, s, t) for(int i = (s), mi = (t); i >= mi; i--)

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define LL long long

bool check(LL mid, LL a, LL b, LL x) {
	LL na = a - mid * x, nb = b - mid;
	na -= nb / x;
	if(na < 0) return 0;
	return 1;
}

void work() {
	LL a = read(), b = read(), ql = read(), qr = read(), x = (max(a, b) + min(a, b)) / (min(a, b) + 1);
	LL l = 0, r = b + 1;
	while(r - l > 1) {
		LL mid = l + r >> 1;
		if(check(mid, a, b, x)) l = mid; else r = mid;
	}
	LL lft = l, rgt = (b - l) / x;
	rep(i, ql, qr)
		if(i <= (x + 1) * lft) putchar(i % (x + 1) ? 'A' : 'B');
		else if(i >= a + b - (x + 1) * rgt + 1) putchar((a + b - i + 1) % (x + 1) ? 'B' : 'A');
		else putchar(i - (x + 1) * lft <= a - rgt - lft * x ? 'A' : 'B');
	putchar('\n');
	return ;
}

int main() {
	int T = read();
	while(T--) work();
	
	return 0;
}

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

using namespace std;
//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; }
template<class T> inline bool chmin(T a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
typedef long long int ll ;


#define INF 2000000000

int main() {

	int N,R,tmp;
	cin >> N >> R ;

	if(N >= 10) {
		cout << R << endl;
	}else{
		cout << R+100*(10-N) << endl;
	}
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int count=0;
	for(int i=0;i<20;i++){
		if(n<(1<<(i+1))){
			cout<<(1<<i)<<endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, a;
int x4, x2, x1;
int main(){
  	cin >> N;
  	for(int i=0; i<N; i++){
    	cin >> a;
      	if(a % 4 == 0){
        	x4++;
        }else if(a % 2 == 0){
        	x2++;
        }else{
          	x1++;
        }
    }
  	cout << ((x4 >= x1 || (x4 == x1 - 1 && x2 == 0)) ? "Yes": "No") << endl; 
}


Measured memory_bytes: 256
const main = (inputs) => {
  var num = inputs[0] - 0;
  var sum = 0;

  for (var i = 1; i <= num; i++) {
    if (i % 3 == 0 || i % 5 == 0) {

    } else {
      sum = sum + i;
    }
  }

  console.log(sum);

}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

Measured memory_bytes: 35124
#include<bits/stdc++.h>
using namespace std;
 typedef long long ll;

int main(){
    string s;
    cin>>s;
    if(s =="abc" || s=="acb" || s=="bac" || s =="bca" || s=="cab" || s=="cba"){
        cout<<"Yes";
    }
    else cout<<"No";
}

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

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

  int now = 0;
  for(int i=0; i<60; i++){
    for(int j=0; j<=a; j++){
      if(now%60==c){
        cout << now << endl; 
        return 0;
      }
      now++;
    }
    now += b-1;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3100
/*

4
10 20 30 40

190

(10, 20, 30, 40) → (30, 30, 40)
(30, 30, 40) → (60, 40)
(60, 40) → (100)
-------------------------------------
5
10 10 10 10 10

120

(10, 10, 10, 10, 10) → (20, 10, 10, 10)
(20, 10, 10, 10) → (20, 20, 10)
(20, 20, 10) → (20, 30)
(20, 30) → (50)
--------------------------------------
6
7 6 8 6 1 1

68

(7, 6, 8, 6, 1, 1) → (7, 6, 8, 6, 2)
(7, 6, 8, 6, 2) → (7, 6, 8, 8)
(7, 6, 8, 8) → (13, 8, 8)
(13, 8, 8) → (13, 16)
(13, 16) → (29)

dp[l][r] = Min. possible cost in joining slimes a[l, l+1, ..., r] and making it into 1 slime.

dp[l][r] = min(dp[l][i]+dp[i+1][r]+pre[r]-pre[l]+a[l], l<=i<r)

dp[i][i+1] = a[i]+a[i+1]
dp[i][i] = 0
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ull INF = 1e17;
const ll MDO = 1e9+7;

int main(){
	int n;
	vector<ull> a, pre;
	vector<vector<ull> > dp;
	cin>>n;
	a.assign(n+1, 0);
	pre.assign(n+1, 0);
	dp.assign(n+1, vector<ull>(n+1, 0));
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	pre[0] = a[0];
	for(int i=1;i<n;i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int l=n-1;l>=0;l--){
		for(int r=0;r<n;r++){
			if(l==r)
				continue;
			ull mini = INF;
			for(int i=l;i<r;i++){
				mini = min(mini, dp[l][i]+dp[i+1][r]+pre[r]-pre[l]+a[l]);				
			}
			/*if(l<r){		
				cout<<l<<" "<<r<<" "<<mini<<"\n";	
			}*/
			dp[l][r] = mini;
		}
	}
	cout<<dp[0][n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    while (true) {
      int H = stdin.nextInt();
      int W = stdin.nextInt();
      if (H == 0 && W == 0) {
        break;
      }
 
      StringBuilder rect = new StringBuilder();
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
            rect.append("#");
          } else {
            rect.append(".");
          }
        }
        rect.append("\n");
      }
 
      System.out.println(rect);
    }
  }
 
}

Measured memory_bytes: 27340
#include <iostream>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>
using namespace std ;
int main(){
    int n, s;
    cin >> n ;
    s = n ;
    vector<int> a(n) ;
    vector<int> b(s) ;
    for(int i = 0;i < n; i++){
        cin >> a.at(i)  ;
        b.at(i) = a.at(i) ;

    }
    //二列！

    sort(a.begin(), a.end() );
    //そーと！！

    for(int i =0; i < n; i++){
        if(b.at(i) == a.at(n-1)){
        cout << a.at(n-2)  << endl ;
        }
        if(b.at(i) != a.at(n-1)){
            cout << a.at(n-1) << endl ;
        }
    }
    //出力！

    return 0;
}

Measured memory_bytes: 3200
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf")]*(N + 2)
dp[0] = 0
for i in range(N):
    for k in range(1, min(K + 1, N - i)):
        dp[i + k] = min(dp[i + k], abs(h[i] - h[i + k]) + dp[i])

print(dp[N - 1])


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int SPT_MAX = 123456;
const int SPT_lg = 20;
const int INF = 123456789;

template <class T> class SPT{
	T x[SPT_MAX + 1][SPT_lg];
	int lg[SPT_MAX + 1];
	
	T eval(T a , T b){
		return min(a,b);
	}
	
public:
	
	void dft(int n , T a[]){
		lg[1] = 0;
		for(int i = 2 ; i <= SPT_MAX ; ++i) lg[i] = lg[i / 2] + 1;
		for(int i = 0 ; i < n ; ++i) x[i][0] = a[i];
		for(int i = n ; i < SPT_MAX ; ++i) x[i][0] = INF;
		for(int j = 0 ; j < SPT_lg - 1 ; ++j){
			for(int i = 0 ; i < n - (1 << j) ; ++i){
				x[i][j + 1] = eval(x[i][j] , x[i + (1 << j)][j]);
			}
		}
	}
	
	T get(int s , int f){
		int z = f - s;
		return eval(x[s][lg[z]] , x[f - (1 << lg[z])][lg[z]]);
	}
};

const int MC = 200010;
int N;
SPT<int> spt[2];
int p[2][MC];
int r[MC];
int b[MC];
int t[MC];
priority_queue<P2 , vector<P2> , greater<P2> > Q;

void solve(int s , int u){
	if(s==u) return;
	t[s] = u;
	int a = spt[s%2].get(s/2,u/2);
	b[a] = spt[(s+1)%2].get((r[a]+1)/2,(u+1)/2);
	Q.push(MP(a,s));
}

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		scanf("%d" , p[i%2] + i/2);
		r[p[i%2][i/2]] = i;
	}
	spt[0].dft(N/2,p[0]);
	spt[1].dft(N/2,p[1]);
	solve(0,N);
	while(!Q.empty()){
		int a = Q.top().first;
		int s = Q.top().second;
		Q.pop();
		solve(r[b[a]]+1,t[s]);
		solve(r[a]+1,r[b[a]]);
		solve(s,r[a]);
		printf("%d %d%c" , a , b[a] , Q.empty()?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 26104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> a(N+1,1);
    for(int i=1;i<=M;i++){
        int tmp;
        cin >> tmp;
        a[tmp] = 0;
    }
    vector<ll> dp(N+1);
    dp[0] = 1;
    if(a[1]==1){
        dp[1]=1;
    }
    for(int i=1;i<N;i++){
        dp[i+1]=a[i]*dp[i]+a[i-1]*dp[i-1];
        dp[i+1]%=MOD;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N, M;
    cin >> N >> M;
    for(int i = M / N; i > 0; i--) {
        if(M % i == 0) {
            print(i);
            return 0;
        } 
    }
    
}

Measured memory_bytes: 256
n, h = map(int, input().split())

a = [0 for _ in range(0, n)]
b = [0 for _ in range(0, n)]

for i in range(n):
    aa, bb = map(int, input().split())
    a[i] = aa
    b[i] = bb

a_max = max(a)

b = sorted(b, reverse=True)

res = 0
for hits in b:
    if hits < a_max:
        break
    h -= hits
    res += 1
    if h <= 0:
        h = 0
        break

res += (h + a_max - 1) // a_max

print(res)

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

using namespace std;
#define int long long


#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
// priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

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

int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

int solve(string& s1, string& s2) {
	int ret=-1;
	int ln = min(s1.length(),s2.length());
	for(int i = 0; i < ln; i++) {
		if(s1[i]!=s2[i]) {
			ret=i;
			break;
		}
	}
	if(ret==-1)
		ret=ln;
	return ret/2;
}
int md = 1e9 + 7;
#define arr (int)(4e5+10)

int f[arr];
int rf[arr];

int C(int l,int k, int md) 
{
    if (k<0||k>l){
        return 0;
    }
    return f[l]*rf[k]%md*rf[l-k]%md;
}

void precfac() {
    f[0]=1;
    for (int i=1;i<arr;i++){
        f[i]=f[i-1]*i%MOD;
    }
    rf[arr-1]=powmod(f[arr-1],MOD-2, MOD);
    for (int i=arr-2;i>=0;i--){
        rf[i]=rf[i+1]*(i+1)%MOD;
    }
}
signed main(void)
{
	IOS;
	precfac();
	int n,k;
	cin>>n>>k;
	vi a(n);
	for(int i = 0; i < n; i++)
		cin>>a[i];
	sort(all(a));
	// for(int i: a)
	// 	cout<<i<<" ";
	// cout<<endl;
	int ans=0;
	for(int i  = 0; i < n; i++) {
		if(i >= k-1) {
			ans = (ans+(C(i,k-1,md)*a[i])%MOD)%MOD;
			ans = (ans+MOD)%MOD;
		}
		
	}
	// cout<<ans<<endl;
	for(int i = 0; i < n; i++) {
		if(i <= n-k) {
			ans = (ans-(C(n-i-1,k-1,md)*a[i])%MOD)%MOD;
			ans = (ans+MOD)%MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7296
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 200005
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

char s[N], t[N];
int main(){
    //srand(time(NULL)+clock());
    int T,ca=0,k,i,j,m=0, K, n;
    scanf("%d%d%d", &n, &m, &K);
    int sx, sy;
    scanf("%d%d", &sx, &sy);
    scanf("%s%s", s, t);
    sx--, sy--;
    int l = 0, r = m - 1;
    per(i, 0, K){
        if(s[i] == 'L'){
            l++;
        }
        else if(s[i] == 'R'){
            r--;
        }
        if(l > r){
            break;
        }
        if(i){
            if(t[i-1] == 'L'){
                r = min(r+1, m-1);
            }
            else if(t[i-1] == 'R'){
                l = max(l-1, 0);
            }
        }
    }
    if(l > r || sy < l || sy > r){
        puts("NO");return 0;
    }
    l = 0, r = n - 1;
    per(i, 0, K){
        if(s[i] == 'U'){
            l++;
        }
        else if(s[i] == 'D'){
            r--;
        }
        if(l > r)break;
        if(i){
            if(t[i-1] == 'U'){
                r = min(r+1, n-1);
            }
            else if(t[i-1] == 'D'){
                l = max(l-1, 0);
            }
        }
    }
    if(l > r || sx < l || sx > r){
        puts("NO");return 0;
    }
    puts("YES");
    //cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}



Measured memory_bytes: 640
def ABC159B(a):
    mae = [i for i in a][:(len(a)//2)]
    ushiro = [i for i in a][(-1*(-len(a)//2)):]
    if mae == ushiro[::-1]:
        return True
    else:
        return False


s = input()
if ABC159B(s) and ABC159B(s[:(len(s)-1)//2]) and ABC159B(s[(len(s)+3)//2-1:]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main(){
	int n, k;
	cin>>n>>k;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i)cin>>vec[i];
	vector<int> table(n, inf);
	table[0]=0;
	for(int i = 1; i < n; ++i){
		for(int j = i - k; j < i; ++j){
			if(j >= 0){
				table[i] = min(abs(vec[i] - vec[j]) + table[j], table[i]);
			}
		}
	}
	cout<<table[n - 1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
const int MAXN = 10;
int F[MAXN];
int P[MAXN];
int Q[MAXN];
int N;

struct BinaryIndexedTree {
  int data[MAXN];

  void add(int x, int v) {
    for (int i = x; i <= N; i += i & -i) {
      data[i] += v;
    }
  }

  void clr() {
    for (int i = 0; i <= N; ++i) {
      data[i] = 0;
    }
  }

  int get(int x) const {
    int v = 0;
    for (int i = x; i >= 1; i -= i & -i) {
      v += data[i];
    }
    return v;
  }
} bit;

int count(int* A) {
  bit.clr();
  for (int i = 1; i <= N; ++i) {
    bit.add(i, 1);
  }
  int pos = 0;
  for (int i = 1; i <= N; ++i) {
    int val = bit.get(A[i]) - 1;
    pos += val * F[N-i];
    bit.add(A[i], -1);
  }
  return pos;
}

void init() {
  F[0] = 1;
  for (int i = 1; i <= N; ++i) {
    F[i] = F[i-1] * i;
  }
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &P[i]);
  for (int i = 1; i <= N; ++i) scanf("%d", &Q[i]);
  init();
  int a = count(P);
  int b = count(Q);
  printf("%d\n", abs(a - b));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1.0E-14
using namespace std;

int main(){
    long double a,b,c;
    cin>>a>>b>>c;
    if(sqrt(a)+sqrt(b)+eps<sqrt(c)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)
//CCW??¨///////////////////////////////////
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;
/////////////////////////////////////////
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);}

  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;
  }
};
/*class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};*/
typedef Point vect;
struct seg{Point p1,p2;};
//????????´???
double norm(Point p){return p.x*p.x+p.y*p.y;}
//??¶??????
double abs(Point p){return sqrt(norm(p));}
//??????
double dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}
//??????
double cross(Point a,Point b){
  return a.x*b.y-a.y*b.x;
}
//??´?????????
bool C90(seg s1,seg s2){
  return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}
bool C0(seg s1,seg s2){
  return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}
//?°???±
Point project(seg s,Point p){
  Point base = s.p2-s.p1;
  double r=dot(p-s.p1,base) / norm(base);
  return s.p1+base*r;
}
//????°?
Point reflection(seg s,Point p){
  return  p+(project(s,p)-p)*2.0;
}
//2???????????¢
double getDistancePP(Point a,Point b){
  return abs(a-b);
}
//??´??????????????¢(????°?)
double getDistanceLP(seg l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}
//?????????????????¢
double getDistanceSP(seg s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0)return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0)return abs(p-s.p2);
  return getDistanceLP(s,p);
}
//????????????????????¢
/*double getDistance(seg s1,seg s2){
  if(intersect(s1,s2))return 0.0;
  return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
    min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}*/
//????¨?????????????????¨??????????
int CCW(Point p0,Point p1,Point p2){
  Point a=p1-p0;
  Point 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(norm(a)<norm(b))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(seg s1,seg s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

main(){
  int n;
  seg a,b;
  cin>>n;
  while(n--){
    cin>>a.p1.x>>a.p1.y>>a.p2.x>>a.p2.y;
    cin>>b.p1.x>>b.p1.y>>b.p2.x>>b.p2.y;
    cout<<intersect(a,b)<<endl;
  }
}

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

typedef pair<int,int> P;

const int INF = 1 << 28;

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

    vector<P> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i].first >> v[i].second;
    }

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

    int len = sqrt(N);
    vector<vector<P> > m((N + len - 1) / len), n((N + len - 1) / len);

    for (int i = 0; i < N; i++) {
        m[i / len].push_back(P(v[i].second, v[i].first));
        n[i / len].push_back(v[i]);
    }

    for (auto& i : m) {
        sort(i.begin(), i.end());
    }

    while (M--) {
        int sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;

        int ans = 0;
        for (int i = 0; i < m.size(); i++) {
            int n_first = n[i][0].first;
            int n_last = n[i][n[i].size()-1].first;
            if ((sx <= n_first && n_first <= gx) && (sx <= n_last && n_last <= gx)) {
                int low = lower_bound(m[i].begin(), m[i].end(), P(sy, sx)) - m[i].begin();
                int up = upper_bound(m[i].begin(), m[i].end(), P(gy, gx)) - m[i].begin();
                ans += up - low;
            } else {
                if ((n_first <= sx && sx <= n_last) || (n_first <= gx && gx <= n_last)) {
                    int low = lower_bound(n[i].begin(), n[i].end(), P(sx,sy)) - n[i].begin();
                    int up = upper_bound(n[i].begin(), n[i].end(), P(gx,gy)) - n[i].begin();
                    for (low; low <= up && low < n[i].size(); low++) {
                        if (
                            sx <= n[i][low].first && n[i][low].first <= gx
                            && sy <= n[i][low].second && n[i][low].second <= gy
                            ) ans++;
                    }
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3252
N=int(input())
r=[0]*10000
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            v = i*i + j*j + k*k + i*j + i*k + k*j
            if v <= 10000:
                r[v-1] += 1
for i in range(N):
    print(r[i])

Measured memory_bytes: 9112
def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    l, h = min(a), max(a)
    min_c = 4000001
    for i in range(l, h+1):
        cost = 0
        for j in a:
            cost += (j-i) ** 2
        
        if cost < min_c:
            min_c = cost
            
    print(min_c)
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H,W;
    while (1) {
        scanf("%d %d",&H,&W);
        if(H==0 && W==0) break;
        for(int i=0; i<H; i++) {
            if(i%2==1) {
                for(int j=0; j<W; j++) {
                    if(j%2==1) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                }
            } else {
                for(int j=0; j<W; j++) {
                    if(j%2==1) {
                        printf(".");
                    } else {
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <vector>
#include <algorithm>

#define MAX_SIZE 1500000

using namespace std;

int main(){
	int dansu,kansu,shelf[20],book[100],min_size,left,right,m,dansu_index,max_length;

	while(true){
		scanf("%d %d",&dansu,&kansu);
		if(dansu == 0 && kansu == 0)break;

		max_length = 0;

		for(int i = 0; i < kansu; i++){
			scanf("%d",&book[i]);
			max_length = max(max_length,book[i]);
		}

		min_size = MAX_SIZE;
		left = max_length,right = MAX_SIZE;
		m = (left+right)/2;

		while(left < right){

			for(int i = 0; i < dansu; i++)shelf[i] = m;
			dansu_index = 0;
			for(int i = 0; i < kansu && dansu_index < dansu;){
				if(shelf[dansu_index] >= book[i]){
					shelf[dansu_index] -= book[i];
					i++;
				}else{
					dansu_index++;
				}
			}

			if(dansu_index == dansu){
				left = m + 1;
				m = (left + right)/2;
			}else{
				right = right - 1;
				m = (left + right)/2;
			}
		}

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

	}

    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A>12) cout << B << endl;
  else if(A<6) cout << 0 << endl;
  else cout << B/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
inline int read(){
    int w=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        w=(w<<3)+(w<<1)+ch-48;
        ch=getchar();
    }
    return w*f;
}
int n,m,dis[2000010],cnt,head[2000010];
set<int> c[2000010];
struct Edge{
    int from,to,next,col;
}edge[5000010];
inline void addedge(int u,int v,int w){
    cnt++;
    edge[cnt].from=u;
    edge[cnt].to=v;
    edge[cnt].col=w;
    edge[cnt].next=head[u];
    head[u]=cnt;
}
inline void ins(int u,int v,int w){
    addedge(u,v,w);addedge(v,u,w);return;
}
struct heap{int u,v;};
inline bool operator<(heap a,heap b){return a.v==b.v?a.u<b.u:a.v<b.v;}
priority_queue<heap>q;
bool vis[200010];
inline void dij(){
    dis[1]=0;q.push((heap){1,0});
    while(!q.empty()){
        heap cur=q.top();q.pop();int u=cur.u;
        for(int i=head[u];i;i=edge[i].next){
            int v=edge[i].to;int w=c[u].count(edge[i].col)?0:1;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;q.push((heap){v,-dis[v]});c[v].clear();c[v].insert(edge[i].col);
            }
            else if(dis[v]==dis[u]+w){
                c[v].insert(edge[i].col);
            }
        }
    }
}
signed main(){
    n=read();m=read();
    for(int i=1;i<=m;i++){
        int x=read();int y=read();int z=read();
        addedge(x,y,z);addedge(y,x,z);
    }
    memset(dis,0x3f,sizeof(dis));
    dij();
    if(dis[n]==INF)cout<<-1<<endl;
    else cout<<dis[n]<<endl;
    return 0;
}

Measured memory_bytes: 123768