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

public class Main
{
   public static void main(String[] args) throws Exception
   {
      PrintWriter out = new PrintWriter(System.out);
      new Main(new FastScanner(System.in), out);
      out.close();
   }

   public Main(FastScanner in, PrintWriter out)
   {
      int N = in.nextInt();

      int[] size = new int[2];
      Point[] vs = new Point[2*N];
      for (int x=0; x<2; x++)
         for (int i=0; i<N; i++)
            vs[i+x*N] = new Point(x, in.nextInt());
   
      Arrays.sort(vs);

      long MODO = 1_000_000_007;
      long res = 1L;
      for (Point p : vs)
      {
         if (size[1-p.t] > 0)
         {
            res *= size[1-p.t];
            res %= MODO;

            size[1-p.t]--;
         }
         else
         {
            size[p.t]++;
         }
      }
      out.println(res);
   }
}

class Point implements Comparable<Point>
{
   int t, i;

   Point(int tt, int ii)
   {
      t=tt; i=ii;
   }

   public int compareTo(Point rhs)
   {
      return Integer.compare(i, rhs.i);
   }
}

class FastScanner{
   private InputStream stream;
   private byte[] buf = new byte[1024];
   private int curChar;
   private int numChars;

   public FastScanner(InputStream stream)
   {
      this.stream = stream;
   }

   int read()
   {
      if (numChars == -1)
         throw new InputMismatchException();
      if (curChar >= numChars){
         curChar = 0;
         try{
            numChars = stream.read(buf);
         } catch (IOException e) {
            throw new InputMismatchException();
         }
         if (numChars <= 0)
            return -1;
      }
      return buf[curChar++];
   }

   boolean isSpaceChar(int c)
   {
      return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
   }
   
   boolean isEndline(int c)
   {
      return c=='\n'||c=='\r'||c==-1;
   }

   int nextInt()
   {
      return Integer.parseInt(next());
   }
   
   long nextLong()
   {
      return Long.parseLong(next());
   }

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

   String next(){
      int c = read();
      while (isSpaceChar(c))
         c = read();
      StringBuilder res = new StringBuilder();
      do{
         res.appendCodePoint(c);
         c = read();
      }while(!isSpaceChar(c));
      return res.toString();
   }
   
   String nextLine(){
      int c = read();
      while (isEndline(c))
         c = read();
      StringBuilder res = new StringBuilder();
      do{
         res.appendCodePoint(c);
         c = read();
      }while(!isEndline(c));
      return res.toString();
   }
}


Measured memory_bytes: 34708
def resolve():
    N = int(input())
    eat = list(map(int, input().split()))
    heal = list(map(int, input().split()))
    plus = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        if eat[i+1] - eat[i] == 1:
           ans += plus[eat[i]-1]
    print(sum(heal) + ans)
resolve()

Measured memory_bytes: 3064
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_B


def solve():
    _ = int(input())
    S = set(map(int, input().split()))
    _ = int(input())
    T = set(map(int, input().split()))

    print(len(S & T))


if __name__ == '__main__':
    solve()



Measured memory_bytes: 16604
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
           long n = scan.nextLong();
           long i ;
           long d = 1;
           
           for(i = 1; i<=n;i++){
               d = d * i;
           }
           System.out.println(d);
        }

    }




Measured memory_bytes: 26104
#include <iostream>
#include <complex>
using namespace std;
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)

#define X real()
#define Y imag()
typedef double D;
typedef complex<D>P;
#define EPS (1e-10)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)
 
inline D outprd(const P &a, const P &b){ return (conj(a) * b).Y; }
bool is_parallel(const P &a, const P &b, const P &c, const P &d){
    return DEQ(outprd(a-b, c-d), 0.0);
}

int main(){
    int n;
    cin >> n;
    REP(i,n){
        double x1, y1, x2, y2, x3, y3, x4, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        P p1(x1,y1), p2(x2,y2), p3(x3,y3), p4(x4,y4);
        if(is_parallel(p1,p2,p3,p4)){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s, t; cin >> s >> t;
	bool ans = false;
	REP(i, s.size())
	{
		if (s.substr(i) + s.substr(0, i) == t) ans = true;
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int E,Y;
    cin >> E;
    cin >> Y;
    if(E == 0){
        if( Y <= 1911){
            cout << 'M' << Y-1867 << endl;
        }
        else if( Y <= 1925 && Y >= 1912){
            cout << 'T' << Y-1911 << endl;
        }
        else if( Y <= 1988 && Y >= 1926){
            cout << 'S' << Y-1925 << endl;
        }
        else{
            cout << 'H' << Y-1988 << endl;
        }
    }    
    else if(E == 1){
        cout << Y+1867 << endl;
    }
    else if(E == 2){
        cout << Y+1911 << endl;
    }
    else if(E == 3){
        cout << Y+1925 << endl;
    }
    else{
        cout << Y+1988 << endl;
    }
        
 }



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

int gcb(int a,int b){
    if(a%b == 0) return b;
    return gcb(b,a%b);
}

int main() {
    //input
    long long a;
    long long b;
    long long c;
    long long d;
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;
    std::cin >> d;


    long long ansb = b - b/c - b/d + b/(c*d/gcb(max(c,d),min(c,d)));
    long long oa = a-1;
    long long ansa = oa - oa/c - oa/d + oa/(c*d/gcb(max(c,d),min(c,d)));
    //int a[n];
    //vector<int> a(n);
    //for (int i = 0; i < n; i++) {
    //    cin >> a.at(i);
    //}
    //for (int i=0;i<n;i++){
    //    std::cout << a.at(i) << std::endl;
    //}
    cout << ansb - ansa;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

void ok() {
	cout << "YES" << endl;
	exit(0);
}

void ng() {
	cout << "NO" << endl;
	exit(0);
}

vector<Int> edge[216000];
Int deg[216000];
Int A[216000];
Int a, b, n;

int dfs(int x, int last = -1) {
	if (deg[x] == 1) return A[x];
	Int mx = 0;
	Int sum = 0;
	for (auto to : edge[x]) {
		if (to == last)continue;
		Int u = dfs(to, x);
		mx = max(mx, u);
		sum += u;
	}
	Int flip = sum - A[x];
	Int res = sum - 2 * flip;
	if (flip < 0)ng();
	if (flip > min(sum - mx, sum / 2))ng();
	if (res < 0)ng();
	return res;
}

void solve()
{
	cin >> n;
	REP(i,n) cin >> A[i];
	REP(i,n-1) {
		cin >> a >> b; a--, b--;
		deg[a]++, deg[b]++;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	if (n == 2) {
		if (A[0] == A[1])ok();
		else ng();
	}
	int root = 0;
	while (deg[root] == 1) root++;
	if (dfs(root) == 0)ok();
	ng();
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 19972
n=int(input())
def f(x,y):
  ret=0
  for i in range(1,n+1):
    if i%10!=y:
      continue
    else:
      if x==int(str(i)[0]):
        ret+=1
  return ret
ans=0
T=[[0]*10 for _ in range(10)]
for i in range(1,10):
  for j in range(1,10):
    T[i][j]=f(i,j)

for i in range(1,10):
  for j in range(1,10):
    ans+=T[i][j]*T[j][i]
print(ans)


Measured memory_bytes: 41068
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <string>
using namespace std;


int main() {
  char alpha;
  cin >> alpha;

  const string UPPERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  const string LOWERS = "abcdefghijklmnopqrstuvwxyz";

  if (UPPERS.find(alpha) != string::npos) {
    cout << 'A' << endl;
  } else if (LOWERS.find(alpha) != string::npos) {
    cout << 'a' << endl;
  } else {
    throw runtime_error("what's wrong?");
  }
  return 0;
}

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

int main() {  
  string s;
  cin >> s;
  int n = s.size();
  int win = 0;
  for(int i = 0; i < n; i++) {
    if(s[i]=='o') win++;
  }
  cout << ( win+(15-n)>=8 ?"YES" :"NO") << "\n";
}

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

using namespace std;

int main() {
  int N; cin >> N;
  map<int, int> m;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
    m[v[i]] = 0;
  }
  int cnt = 0;
  for (auto& p : m) {
    p.second = cnt++;
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    res += (i % 2 != m[v[i]] % 2);
  }
  cout << res / 2 << endl;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  ll r;
  cin >> r;
  cout << 3 * r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n * 3);
    int i;
    for (i = 0; i < n * 3; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.rbegin(), a.rend());
    ll s = 0;
    for (i = 0; i < n; i++) {
        s += a[i * 2 + 1];
    }
    printf("%lld\n", s);


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include <fstream>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0, };
typedef pair<int, int>P;

int N, K, Q;
vector<int>A;

signed main() {
	//std::ifstream in("test2.txt");
	//std::cin.rdbuf(in.rdbuf());
	cin >> N >> K >> Q;
	A.resize(N);
	REP(i, N)cin >> A[i];
	A.pb(-INF); A.pb(-INF);
	int l = 0, r = 0;
	int ans = INF;
	REP(i, N) {
		vector<int>res;
		int x = A[i];
		l = 0, r = 0;
		while (r < N) {
			if (A[l] < x) {
				l++; r++;
				continue;
			}
			if (A[r + 1] >= x) {
				r++;
			}
			else {
				if (r - l + 1 >= K) {

					vector<int>vec;
					for (int j = l; j <= r; j++) {
						vec.pb(A[j]);
					}
					VSORT(vec);
					REP(k, r - l + 2 - K) {
						res.pb(vec[k]);
					}
				}
				l = r + 2;
				r += 2;
			}
		}
		if (res.size() == 0)continue;
		VSORT(res);
		if (res[0] < x) {
			//print("fault");
			//return 0;
		}
		if (res.size() >= Q) {
			//print(res[Q - 1] - res[0]);
			ans = min(ans, res[Q - 1] - res[0]);
		}
	}
	print(ans);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n,c;
  cin >> n >> c;
  vector<pair<ll,ll>> food(n);
  rep(i,n) cin >> food[i].first >> food[i].second;
  vector<ll> clock, anticlock;
  ll sum=0;
  rep(i,n){
    sum += food[i].second;
    clock.pb(sum-food[i].first);
  }
  
  ll ans = 0LL;
  ll anti_max=0;
  sum =0;
  rep(i,n){
    //    cout << clock[n-1-i]+anti_max << endl;
    ans = max(clock[n-1-i]+anti_max,ans);
    sum += food[n-1-i].second;
    anti_max = max(anti_max,sum - 2 *(c - food[n-1-i].first) ) ;
  }


  sum=0;
  rep(i,n){
    sum += food[n-1-i].second;
    anticlock.pb(sum-(c-food[n-1-i].first));
  }

  anti_max=0;
  sum =0;
  rep(i,n){
    //    cout << clock[n-1-i]+anti_max << endl;
    ans = max(anticlock[n-1-i]+anti_max,ans);
    sum += food[i].second;
    anti_max = max(anti_max,sum - 2 *(food[i].first) ) ;
  }
  
  
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}

int main(){
	ll a,b,c=1,d=1;
	cin>>a>>b;
	if(a==b){
		cout<<1<<endl;
		return 0;
	}
	while(c*2<=(a^b))c<<=1;
	a&=c*2-1,b&=c*2-1;
	while(d<=b-c)d<<=1;
	ll r=c-a+(d>a?c:c-a+d);
	cout<<r<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct edge {
	int to, cap, rev;
	edge(int t, int c, int r):to(t), cap(c), rev(r){}
};

vector<vector<edge> > G;
vector<int> level;
vector<int> iter;

void init(int v) {
	G.clear();
	G.resize(v);
	level.clear();
	level.resize(v);
	iter.clear();
	iter.resize(v);
}

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}

void bfs(int s) {
	fill(level.begin(), level.end(), -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);

	while(!que.empty()) {
		int v = que.front();
		que.pop();

		for(int i = 0; i < G[v].size(); ++i) {
			const edge& e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f) {
	if(v == t)
		return f;

	for(int& i = iter[v]; i < G[v].size(); ++i) {
		edge& e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}

	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;

	for(;;) {
		bfs(s);
		if(level[t] < 0)
			return flow;

		fill(iter.begin(), iter.end(), 0);
		int f;
		while((f = dfs(s, t, INT_MAX)) > 0)
			flow += f;
	}
}

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

	for(int m, n; cin >> m >> n, m;) {
		int source = m + n, sink = m + n + 1;	
		init(m + n + 2);

		vector<int> b(m), r(n);
		for(int i = 0; i < m; ++i) {
			cin >> b[i];
			add_edge(source, i, 1);
		}

		for(int i = 0; i < n; ++i) {
			cin >> r[i];
			add_edge(m + i, sink, 1);
		}

		for(int i = 0; i < m; ++i)
			for(int j = 0; j < n; ++j)
				if(__gcd(b[i], r[j]) > 1)
					add_edge(i, j + m, 1);

		cout << max_flow(source, sink) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5620
<?php
$input = trim(fgets(STDIN));
list($n, $m) = explode(' ', $input);

$inputs = [];
$count=0;
while($count < $m) {
    $input = trim(fgets(STDIN));
    list($p, $y) = explode(' ', $input);
    $inputs[$p][$y] = $count;

    $count++;
}

$results = [];
foreach($inputs as $p => $input) {
    ksort($input);
    $cities = array_values($input);

    $id = 1;
    foreach($cities as $i => $count) {
        $results[$count]['p'] = $p;
        $results[$count]['c'] = $id;
        $id++;
    }
}

ksort($results);
foreach($results as $result) {
    echo str_pad((string)$result['p'], 6, "0", STR_PAD_LEFT)
        . str_pad((string)$result['c'], 6, "0", STR_PAD_LEFT)
        . "\n";
}



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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main() {
  int n, d;
  cin >> n >> d;
  set<ll> st;
  rep (i, 100000) {
    st.insert((ll)i * i);
  }

  vii x(n, vi(d));
  rep (i, n) {
    rep (j, d) {
      cin >> x[i][j];
    }
  }
  int cnt = 0;
  rep (i, n) {
    for (int j = i + 1; j < n; j++) {
      int sum = 0;
      rep (k, d) {
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      cnt += st.count(sum);
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
ll dp[42][420][420];
int main()
{
  int n,ma,mb;
  cin >> n >> ma >> mb;
  vector<ll>A(n,0),B(n,0),C(n,0);
  rep(i,n)cin >> A[i] >> B[i] >> C[i];
  rep(i,42)rep(j,420)rep(k,420)dp[i][j][k]=INF;
  dp[0][0][0]=0;
  rep(i,n){
      rep(a,405){
          rep(b,405){
              dp[i+1][a][b]=min(dp[i+1][a][b],dp[i][a][b]);
              dp[i+1][a+A[i]][b+B[i]]=min(dp[i+1][a+A[i]][b+B[i]],dp[i][a][b]+C[i]);
          }
      }
  }
  ll ans=INF;
  rep(i,410){
      rep(j,410){
          if(dp[n][i][j]==INF||i*j==0)continue;
          if(i*mb==j*ma){ans=min(ans,dp[n][i][j]);}
      }
  }

  if(ans==INF){cout << -1 << endl;}
  else{cout << ans << endl;}
}


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

ans = "Yes"

for i in range(1,3):
    a = c[0][0] - c[0][i]
    if c[1][0] - a != c[1][i] or c[2][0] - a != c[2][i]:
        ans = "No"
for i in range(1,3):
    a = c[0][0] - c[i][0]
    if c[0][1] - a != c[i][1] or c[0][2] - a != c[i][2]:
        ans = "No"
    
print(ans)

Measured memory_bytes: 3064
N = gets.to_i
A = gets.split.take(N).map(&:to_i).map(&:pred)

def f(a)
  a = a.dup
  res = 0
  a.each_index{|i|
    if a[i] == i
      if i < a.size - 1
        a[i], a[i + 1] = a[i + 1], a[i]
      else
        a[i], a[i - 1] = a[i - 1], a[i]
      end
      res += 1
    end
  }
  res
end

def g(a)
  a = a.dup
  res = 0
  a.each_index{|i|
    if a[i] == i
      if i > 0
        a[i], a[i - 1] = a[i - 1], a[i]
      else
        a[i], a[i + 1] = a[i + 1], a[i]
      end
      res += 1
    end
  }
  res
end

# p [f(A), g(A)].min
p f(A)


Measured memory_bytes: 9868
from heapq import heapify, heappush, heappop


N, M = map(int, input().split())
lst_A = list(map(int, input().split()))


hq = []
heapify(hq)
for a in lst_A:
    heappush(hq, [-a, 1])
for _ in range(M):
    b, c = map(int, input().split())
    heappush(hq, [-c, b])

ans = 0
while N > 0:
    c, b = heappop(hq)
    c *= -1
    if b < N:
        ans += c * b
        N -= b
    else:
        ans += c * N
        N = 0


print(ans)

Measured memory_bytes: 37160
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;
 


int main() {
	int x;
	string a;
	cin >> x;
	cin >> a;
	int n = a.length();
	for (int i = 0; i < n; ++i)
	{
		if (((int)a[i]) - 65 + x > 25) {
			cout << (char)(((int)a[i]) + x - 26);
		} else {
			cout << (char)(((int)a[i]) + x);
		}
		
	}
}
 


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

int main(){
    long long int x,t;

    cin>>x>>t;

    if(x-t>0){
        cout<<x-t<<endl;
    }
    if(x-t<0){
        cout<<"0"<<endl;
    }
    if(x-t==0){
        cout<<"0"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define MP make_pair
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

using Graph = vector<vector<pair<int, int>>>;
using vvec = vector<vector<int>>;
using vec = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int h,n;
    cin>>h>>n;
    vec a(n);
    vec b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    int dp[100100];
    rep(i,100100) dp[i]=INF;
    dp[0]=0;
    for(int i=0;i<=h+10;i++){
        rep(j,n){
            dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j]);
        }
    }
    ll ans=INF;
    for(int i=h;i<100100;i++){
        ans=min(ans,dp[i]);
    }
    cout<<ans<<endl;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> r(n);
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    r[--a].push_back(--b);
    r[b].push_back(a);
  }
  vector<P> used(n, P(0, 1000000));
  used[0] = P(1, 0), used[n - 1] = P(2, 0);
  queue<int> que;
  que.push(0);
  while(que.size()) {
    int q = que.front();
    que.pop();
    for(auto c : r[q]) {
      if(used[c].first == 0) {
        used[c] = P(1, used[q].second + 1);
        que.push(c);
      }
    }
  }
  que.push(n - 1);
  while(que.size()) {
    int q = que.front();
    que.pop();
    for(auto c : r[q]) {
      if(used[c].first == 0) {
        used[c] = P(2, used[q].second + 1);
        que.push(c);
      } else if(used[c].first == 1 && used[q].second + 1 < used[c].second) {
        used[c] = P(2, used[q].second + 1);
        que.push(c);
      }
    }
  }
  int f = 0, s = 0;
  for(auto x : used) {
    f += x.first & 1;
    s += x.first / 2 & 1;
  }
  if(f > s)
    printf("Fennec\n");
  else
    printf("Snuke\n");
}


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

int main() {
  int a[12];
  for(int i=0; i<12; i++) cin >> a[i];
  sort(a,a+12);
  if(a[0]==a[3]&&a[4]==a[7]&&a[8]==a[11]) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};

int n;
vector<vector<int> > a;
vector<int> adj[500000];
bool visited[500000];
bool finished[500000];
int match2idx[1000][1000];
int dp[500000];

void precal() {
	int t = 0;
	rep(i,0,n) {
		rep(j,i+1,n) {
			match2idx[i][j] = t++;
		}
	}
}

int getIdx(int a, int b) {
	if(a>b) swap(a,b);
	return match2idx[a][b];
}

int dfs(int here) {
	if(visited[here]) {
		return dp[here];
	}
	visited[here] = true;
	int& ret = dp[here];
	ret = 0;
	for(int i=0; i<adj[here].size(); ++i) {
		int there = adj[here][i];
		ret = max(ret, 1+dfs(there));
	}
	return ret;
}

int dfsAll() {
	memset(visited, false, sizeof(visited));
	int ret = 0;
	rep(i,0,n) {
		rep(j,i+1,n) {
			if(!visited[match2idx[i][j]]) {
				ret = max(ret, dfs(match2idx[i][j]));
			}
		}
	}
	return ret;
}

bool checkCycle(int here) {
	visited[here] = true;
	//cout << here << endl;
	for(int i=0; i<adj[here].size(); ++i) {
		int there = adj[here][i];
		//cout << "there : " << there << endl;
		if(!visited[there]) {
			if(!checkCycle(there)) {
				return false;
			}
		} else {
			if(!finished[there]) {
				return false;
			}
		}
	}

	finished[here] = true;
	return true;
}

bool checkAll() {
	memset(visited, false, sizeof(visited));
	memset(finished, false, sizeof(finished));

	rep(i,0,n) {
		rep(j,i+1,n) {
			if(!visited[match2idx[i][j]]) {
				if(!checkCycle(match2idx[i][j])) {
					return false;
				}
			}
		}
	}

	return true;
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	a.resize(n);
	rep(i,0,n) {
		rep(j,0,n-1) {
			int b;
			cin >> b;
			b--;
			a[i].pb(b);
		}
	}

	precal();

	rep(i,0,n) {
		rep(j,0,sz(a[i])-1) {
			int here = a[i][j];
			int there = a[i][j+1];
			adj[getIdx(i,here)].pb(getIdx(i,there));
		}
	}

	if(checkAll()) {
		cout << dfsAll()+1 << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;

int main() {
	int n; cin >> n;
	vector<int>t(n);
	vector<int>x1(n);
	vector<int>x2(n);
	rep(i, n) {
		cin >> t[i] >> x1[i] >> x2[i];
	}

	bool okay = false;

	if (n == 1) {
		int tl = t[0] - 0;
		int dl = abs(x1[0]) + abs(x2[0]);
		if (dl > tl || tl % 2 != dl % 2) {
			cout << "No" << endl;
			return 0;
		}
	}


	rep(i, n - 1) {
		if (n > 1) {
			int tl = t[i + 1] - t[i];
			int dl = abs(x1[i] - x1[i + 1]) + abs(x2[i] - x2[i + 1]);

			if (dl > tl || tl % 2 != dl % 2) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string.h>
#include<cstdio>
#include<map>
using namespace std;


int main(){

   int n, l, r;
   while(cin >> n){
      map<int, int> mp;
      //memset(flag, 0, sizeof(flag));
      int a;
      int cnt = 0;
      for(int i = 0; i < n; ++i){
         int a;cin >> a;
         mp[a]++;
         if(mp[a] & 1){
            cnt++;
         }else{
            cnt--;
         }
      }
      cout << cnt <<endl;
   }


   return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <deque>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31) - 1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

//#define _DEB 0

int main(){
	int n; cin >> n;
	cout << n / 3 << endl;
	return 0;
}

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


int main() {
    int n; cin >> n;
    vector<int> h(n+2,-1);
    rep(i,n) cin >> h[i+1];
    
    int ans=0;
    int lm=0;
    rep2(i,n+1){
        if(h[i]>=h[i-1] && h[i]>h[i+1]){
            ans+=h[i]-lm;
        }
        else if(h[i]<h[i-1] && h[i]<=h[i+1]){
            lm=h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


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

  Vbo cnt(n, false);

  rep(i, k) {
    int d; cin >> d;
    rep(j, d) {
      int x; cin >> x;
      cnt[x-1] = true;
    }
  }

  ll ans = 0;
  rep(i, n) {
    if (!cnt[i]) ++ans;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long

int main()
{
    BeatMeScanf;
    //freopen("G:/C++/in.txt", "r", stdin);
    //freopen("G:/C++/out.txt", "w", stdout);

    ll H;
    cin >> H;
    ll cnt = 1;
    ll sum = 1;
    while (H > 1)
    {
        H /= 2;
        cnt *= 2;
        sum += cnt;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    buf = input()
    N = int(buf)
    if N % 2 == 0:
        print(N // 2, N, N)
        return
    else:
        divisor = N
        mult = 1
        while True:
            factor = factorization(divisor)
            for h in factor:
                for n in factor:
                    for w in factor:
                        if h + n + w == 4 * mult:
                            print(divisor // h, divisor // n, divisor // w)
                            return
            divisor += N
            mult += 1

def factorization(number):
    i = 2
    factor = {1, number}
    while i * i <= number:
        if number % i == 0:
            factor.add(i)
            factor.add(number // i)
        i += 1
    return factor

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import Control.Monad
import System.Random

main :: IO ()
main = do
    n <- fmap read getLine
    as <- (replicateM n (fmap read getLine)) :: IO [Int]
    putStrLn (show $ pirupiru as)

pirupiru :: [Int] -> Int
pirupiru ns =   if ns == [] then 0
                else 1 + pirupiru (deletesuru (maximum ns) ns)

deletesuru :: Int -> [Int] -> [Int]
deletesuru x xs = filter (/= x) xs



Measured memory_bytes: 1020
a = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
try:
    while True:
        s = raw_input()
        sm = a[s[-1]]
        for i in range(1, len(s)):
            if a[s[i - 1]] < a[s[i]]:
                sm -= a[s[i - 1]]
            else:
                sm += a[s[i - 1]]
        print sm
except EOFError:
    pass

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
using ll=long double;
#define all(x) (x).begin(), (x).end()

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

    ll m1 = (N/3);
    ll m2 = (N/3);
    ll m3 = N -m1 -m2;
    cout.precision (12);
    //cout << " m1 : " << m1 << endl;
    //cout << " m2 : " << m2 << endl;
    //cout << " m3 : " << m3 << endl;
    cout << fixed << m1 * m2 * m3 << endl;
}


Measured memory_bytes: 256
using System;
using System.ComponentModel.DataAnnotations;
using System.IO.Pipes;
using System.Linq;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int N = cin.NextInt();
            int sum = 0;
            while (sum < N) 
            {
                sum+=1000;
            }
            Console.WriteLine(Math.Abs(N-sum));
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 27468
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;

LL n,a,b,c,d;
int main()
{
	#ifdef LOCAL_JUDGE
		freopen("differences.in","r",stdin);
		freopen("differences.out","w",stdout);
	#endif
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);n--;
	for (LL x=0,y=n;x<=n;x++,y--)
	{
		LL mi=x*c-y*d;
		LL mx=mi+(d-c)*n;
		if (a+mi<=b&&a+mx>=b)
			{printf("YES");return 0;}
	}
	printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string s;
    cin >> s;
    auto isok = [](string s) {
        if(s.size()%2 != 0) return false;
        rep(i,s.size()/2) {
            if(s[i] != s[i+s.size()/2]) return false;
        }
        return true;
    };
    for(int i = s.size()-1; i >= 1; i--) {
        if(isok(s.substr(0,i))) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int D, G; cin >> D >> G;
  vector<int> p(D), c(D);
  int ans = 0;
  rep(i, D) {
    cin >> p[i] >> c[i];
    ans += p[i];
  }
  rep(i, 1 << D) {
    int ans1 = 0, score = 0;
    vector<bool> comp(D, false);
    int tmp = i;
    for (int j = D - 1; tmp != 0; tmp >>= 1, j--) {
      if (tmp & 0x0001) {
        comp[j] = true;
        ans1 += p[j];
        score += c[j] + 100 * (j + 1) * p[j];
      } else {
        comp[j] = false;
      }
    }
    //for (auto i : comp) cout << i << " ";
    //cout << endl;

    if (score >= G) {
      ans = min(ans, ans1);
      continue;
    }
    bool flag = false;
    repR(j, D) {
      if (comp[j]) continue;
      rep(k, p[j]) {
        score += 100 * (j + 1);
        ans1++;
        if (score >= G) {
          ans = min(ans, ans1);
          flag = true;
          break;
        }
      }
      if (flag) break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    int h, w;
    bool a[505][505]{};
    cin >> h >> w;
    REP(i, h) REP(j, w) {
        int t;
        cin >> t;
        a[i][j] = t % 2 == 1;
    }
    vector<pair<P, P> > ans, tmp;
    bool flag = false;
    int px = 1, py = 1;
    REP(i, h * w) {
        int y = i / w, x = (i / w % 2 == 0 ? i % w : w - i % w - 1);
        if (flag) {
            tmp.push_back({{py, px}, {y+1, x+1}});
            if (a[y][x]) {
                for (auto t : tmp) ans.push_back(t);
                tmp.clear();
                flag = false;
            }
        } else if (a[y][x])
            flag = true;
        px = x+1;
        py = y+1;
    }

    cout << ans.size() << endl;
    for (auto i : ans) {
        cout << i.first.first << " " << i.first.second << " ";
        cout << i.second.first << " " << i.second.second << endl;
    }
    return 0;
}


Measured memory_bytes: 4464
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
#include <map>
#include <ctime>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n;
    cin >>n;
    vector<pair<ll,ll>> point(n);
    vector<pair<ll,int>> sum(n);
    rip(i,n,0){
        cin >> point[i].first >> point[i].second;
        sum[i].first=point[i].first+point[i].second;
        sum[i].second=i;
    }
    sort(all(sum));
    reverse(all(sum));
    long long ans=0;
    rip(i,n,0){
        if(i%2){
            ans-=point[sum[i].second].second;
        }
        else{
            ans+=point[sum[i].second].first;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int P, Q, R;

int main(int argc, const char * argv[]) {
    cin >> P >> Q>> R;
    int mint = P+Q;
    chmin(mint, Q+R);
    chmin(mint, P+R);
    output(mint);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int A, B;
	string S;
	cin >> A >> B >> S;
	string res = "Yes";
	REP(i, A + B + 1) {
		if (i != A) {
			if (S[i]<'0' || S[i]>'9') {
				res = "No";
				break;
			}
		}
		else if (i == A) {
			if (S[i] != '-') {
				res = "No";
				break;
			}
		}
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256