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

public class Main {
	
	static int INF = 1000000000;
	static int MAXN = 31;
	
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[][] point = new int[n][2];
		for (int i = 0; i < n; ++i) {
			point[i][0] = input.nextInt();
			point[i][1] = input.nextInt();
		}
		int q = input.nextInt();
		for (int i = 0; i < q; ++i) {
			int x, y;
			x = input.nextInt();
			y = input.nextInt();
			System.out.println(checkWithPolygon(x, y, point));
		}
	}
	
	static int checkWithPolygon(int x, int y, int[][] pol) {
		boolean check = false;
		for (int i = 0; i < pol.length; ++i) {
			int ax = pol[i][0] - x, ay = pol[i][1] - y;
			int bx = pol[(i + 1) % pol.length][0] - x, by = pol[(i + 1) % pol.length][1] - y;
			if (ay > by) {
				int temp = ax; ax = bx; bx = temp;
				temp = ay; ay = by; by = temp;
			}
			if (ay <= 0 && by > 0 && cross(ax, ay, bx, by) < 0) check = !check;
			if (cross(ax, ay, bx, by) == 0 && dot(ax, ay, bx, by) <= 0) return 1;
		}
		return check ? 2 : 0;
	}
	
	static int cross(int ax, int ay, int bx, int by) {
		return ax * by - ay * bx;
	}
	
	static int dot(int ax, int ay, int bx, int by) {
		return ax * bx + ay * by;
	}
}

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

using namespace std;

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

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


	int ans[k + 1];
	memset(ans,  0,  sizeof ans);

	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] <= i and ans[i - a[j]] == 0) {
				ans[i] = 1;
				break;
			}
		}
	}

	if (ans[k]) {
		cout << "First" << endl;
	} else
		cout << "Second" << endl;

	return 0;
}

Measured memory_bytes: 3988
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

typedef ll Weight;
struct Edge {
    int from, to;
    Weight wei;
    Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {}
};
typedef vector<Edge> Edges;
const Weight INFW = numeric_limits<Weight>::max();

struct Graph : public vector<Edges> {
    Graph() { }
    Graph(int V) : vector<Edges>(V) { }
    /*
    有向辺を追加する
    */
    void addEdge(int from, int to, Weight wei = 1) {
        (*this)[from].push_back(Edge(from, to, wei));
    }
    /*
    無向辺を追加する
    */
    void addUEdge(int u, int v, Weight wei = 1) {
        (*this)[u].push_back(Edge(u, v, wei));
        (*this)[v].push_back(Edge(v, u, wei));
    }
};

bool operator>(const Edge &a, const Edge &b) {
    return a.wei>b.wei;
}

class Prim {
public:
    Prim(const Graph &G, int root = 0) :sum(0), mst(G.size()) {
        int V = (int)G.size();
        vector<int> visited(V);
        priority_queue<Edge, vector<Edge>, greater<Edge>> PQ;

        PQ.push(Edge(root, root, 0));
        while (PQ.size()) {
            Edge e = PQ.top(); PQ.pop();
            int v = e.to;
            if (visited[v]++) continue;
            if (v != root) {
                mst[e.from].push_back(e);
                mst[v].emplace_back(v, e.from, e.wei);
                sum += e.wei;
            }
            for (const auto &ee : G[v]) {
                if (!visited[ee.to]) {
                    PQ.push(ee);
                }
            }
        }
    }

    Weight getWeight() {
        return sum;
    }

    Graph getMST() {
        return mst;
    }
private:
    Weight sum;
    Graph mst;
};

using P = tuple<int, int, int>;

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

    int N;
    cin >> N;
    
    Graph G(N);
    vector<P> S(N);
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        S[i] = mt(x, y, i);
    }
    sort(all(S));
    rep(i,sz(S)-1) {
        int x, y, k, xx, yy, kk;
        tie(x, y, k) = S[i];
        tie(xx, yy, kk) = S[i + 1];
        G.addUEdge(k, kk, xx - x);
    }
    each(p, S) {
        swap(get<0>(p), get<1>(p));
    }
    sort(all(S));
    rep(i, sz(S) - 1) {
        int x, y, k, xx, yy, kk;
        tie(x, y, k) = S[i];
        tie(xx, yy, kk) = S[i + 1];
        G.addUEdge(k, kk, xx - x);
    }

    ll ans = Prim(G).getWeight();
    cout << ans << endl;
}


Measured memory_bytes: 21360
n = int(input())
a = list(map(str,input().split()))
b = []

for i in range(n-1-(1-(n-1)%2),0,-2):
    b.append(a[i])
for i in range(0,n-1-(n-1)%2+1,2):
    b.append(a[i])

if n%2 == 1:
    b = b[::-1]
print(" ".join(b))

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  map<ll, ll> mp;
  rep(i,n) mp[a.at(i)]++;
  ll cnt = 0;
  for(auto p : mp) {
    ll m = p.second;
    cnt += m*(m-1)/2;
  }
  rep(i,n) {
    ll ans = cnt;
    ll l = mp.at(a.at(i));
    ans -= l*(l-1)/2;
    l--;
    ans += l*(l-1)/2;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 11008
using System;
using System.Linq;

class Test {
	static void Main(string[] args) {
      string str = System.Console.ReadLine();
      int cnt = 0;
      if(str[0] == 'R'){
        cnt++;
      }
      if(str[1] == 'R'){
        cnt++;
      }
      if(str[2] == 'R' && str[1] == 'S'){
        cnt = 1;
      }else if(str[2] == 'R'){
        cnt++;
      }
      
      Console.WriteLine(cnt);
	}
}

Measured memory_bytes: 17532
#include <cstdio>
#include <cstring>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int n;
  cin >> n;
  char ans[n];
  for(int i=0;i<n;i++)
    cin >> ans[i];

  int c[4][100001]={};
  c[0][0] = 0;   //0=s  1=w
  c[0][1] = 0;
  c[1][0] = 0;
  c[1][1] = 1;
  c[2][0] = 1;
  c[2][1] = 0;
  c[3][0] = 1;
  c[3][1] = 1;

  for(int i=1;i<n-1;i++){
    if(ans[i]=='o'){
      for(int j=0;j<4;j++){
        if(c[j][i]==1){
          c[j][i+1] = 1 - c[j][i-1];
        }else{
          c[j][i+1] = c[j][i-1];
        }
      }
    }else{
      for(int j=0;j<4;j++){
        if(c[j][i]==1){
          c[j][i+1] = c[j][i-1];
        }else{
          c[j][i+1] = 1 - c[j][i-1];
        }
      }
    }
  }

  for(int i=0;i<4;i++){
    if(

      (
      ((c[i][n-1] == c[i][1]) && (c[i][0] == 0) && (ans[0] == 'o') )
      ||
      ( (c[i][n-1] == c[i][1]) && (c[i][0] == 1) && (ans[0] == 'x') )
      ||
      ( (c[i][n-1] != c[i][1]) && (c[i][0] == 0) && (ans[0] == 'x') )
      ||
      ( (c[i][n-1] != c[i][1]) && (c[i][0] == 1) && (ans[0] == 'o') )
      )

      &&

      (
      ((c[i][n-2] == c[i][0]) && (c[i][n-1] == 0) && (ans[n-1] == 'o') )
      ||
      ( (c[i][n-2] == c[i][0]) && (c[i][n-1] == 1) && (ans[n-1] == 'x') )
      ||
      ( (c[i][n-2] != c[i][0]) && (c[i][n-1] == 0) && (ans[n-1] == 'x') )
      ||
      ( (c[i][n-2] != c[i][0]) && (c[i][n-1] == 1) && (ans[n-1] == 'o') )
      )



      )

    {
      for(int j=0;j<n;j++){
        if(c[i][j]==1)
          cout << 'W';
        else
          cout << 'S';
      }
      cout << endl;
      return 0;
    }
  }

  cout << -1 <<endl;

  return 0;
}


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

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

    vector<bool> a(N+1, true);
    rep(i, M){
        int b; cin >> b;
        a[b] = false;
    }

    vector<ll> dp(N+1, 0);
    dp[0] = 1;
    if(a[1]) dp[1] = 1;

    for (int i = 2; i <= N; ++i){
        if(a[i-1]) dp[i] += dp[i-1];
        if(a[i-2]) dp[i] += dp[i-2];
        dp[i] %= MOD;
        
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int m = N*(N-1)/2 + M*(M-1)/2;
		
		System.out.println(m);
		
	}

}

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

int main() {
  int H, A;
  cin >> H >> A;
  
  if (H <= A) {
    cout << 1 << endl;
  } else if (H > A && H % A == 0) {
    cout << H / A << endl;
  } else {
    cout << H / A + 1 << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

base = H[0]

for i in range(1, N):
    if base < H[i]:
        base = H[i] - 1
    elif base > H[i]:
        print("No")
        exit(0)
    else:
        base = H[i]

print("Yes")

Measured memory_bytes: 85432
import java.util.Scanner;

public class Main {
	static public void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		scan.close();

		int ans = a * x + b * y;

		int tmp1 = 2 * c * x + b * Math.max(y - x, 0);
		if (ans > tmp1) {
			ans = tmp1;
		}

		int tmp2 = 2 * c * y + a * Math.max(x - y, 0);
		if (ans > tmp2) {
			ans = tmp2;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

int main(){
	string s; cin >> s;
	if (s.size() < 4){
		cout << "No" << endl;
		return 0;
	}if (s[0] == 'Y'&&s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def tsp(matrix):
    INF = float("inf")
    n = len(matrix)

    # dp[bit_state][i] := すでにbit_stateの状態を訪れていて、
    #                     最後に訪問したのがi番目のときの最小値
    dp = [[INF]*n for i in range(1 << n)]
    dp[1 << 0][0] = 0
 
    for bit_state in range(1 << n):
        for i in range(n):
            # bit_stateにiを含んでいる
            if (bit_state >> i) & 1:
                for j in range(n):
                    # bit_stateにjを含んでいない
                    if not ((bit_state >> j) & 1):
                        dp[bit_state|(1 << j)][j] = min(dp[bit_state|(1 << j)][j], dp[bit_state][i] + matrix[i][j])
    ans = INF
    for i in range(n):
        ans = min(dp[(1 << n) - 1][i] + matrix[i][0], ans)
    return ans

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
INF = float("inf")

matrix = [[INF]*n for i in range(n)]
for i in range(m):
    a, b, cost = info[i]
    matrix[a][b] = cost
for i in range(n):
    matrix[i][i] = 0

ans = tsp(matrix)
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 15460
N = int(input())
str = [input() for i in range(1)]
STRING=str[0]
enc = ""

for i in list(STRING):
    ASCII = ord(i)
    num = ASCII - 65
    num = (num + N % 26)
    ASCII = num + 65
    if ASCII > 90:
        ASCII -= 26
    enc += chr(ASCII)
print(enc)

Measured memory_bytes: 3064
n,m = map(int,input().split())

right = [False]*n
penalty = [0]*n

for i in range(m):
    p,s = input().split()
    p = int(p)-1
    if right[p]:
        pass
    else:
        if s == "AC":
            right[p] = True
        else:
            penalty[p] += 1
r = 0
pen = 0

for j in range(n):
    if right[j]:
        r += 1
        pen += penalty[j]

print(r,pen)

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

int main(){
	int n,m,s[100000+2],a,loc=1,b[100000+2]={0},ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++){
		scanf("%d",&s[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%d",&a);
		if(a>0){
			for(int i=0;i<a;i++){
				b[loc]++;
				loc++;
			}
		}
		else {
			for(int i=0;i<(-a);i++){
				loc--;
				b[loc]++;
			}
		}
	}
	for(int i=1;i<n;i++){
		ans+=s[i]*b[i];
		ans%=100000;
	}
	printf("%d\n",ans);
}

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

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

int niz[10000];

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

    int n;
    cin >> n;
    bool ok = true;
    for(int i = 0; i < n; i++)
    {
        cin >> niz[i];
        if(niz[i] % 2 == 0)
        {
            if(niz[i] % 3 != 0 && niz[i]%5 != 0)
                ok = false;
        }
    }
    if(ok) cout << "APPROVED";
    else cout << "DENIED";

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	bool works = false;
	for (int i = 0; i <= k; ++i) {
		for (int j = 0; j <= k; ++j) {
			for (int l = 0; l <= k; ++l) {
				if (i + j + l > k)
					continue;
				int aa = a * (1 << i);
				int bb = b * (1 << j);
				int cc = c * (1 << l);
				if (bb > aa && cc > bb) {
					works = true;
				}
			}
		}
	}
	cout << (works ? "Yes" : "No") << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		//cout << "Case #" << i << ": ";
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 3496
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
    size_t N;
    scanf("%zu", &N);

    std::vector<int64_t> a(3*N);
    for (int64_t &a_: a)
        scanf("%lld", &a_);

    std::sort(a.begin(), a.end(), std::greater<int64_t>());

    int64_t res=0;
    for (size_t i=1; i<2*N; i+=2)
        res += a[i];

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


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
const ll mod = 1e9+7;


int main(){
  int n;
  cin >> n;
  vector<ll> vx(n);
  vector<ll> vy(n);
  rep(i,n){
     ll x,y;
     cin >> x >> y;
     vx[i] = x-y;
     vy[i] = x+y;
  }
  ll maxvx = -(1LL << 60),minvx = 1LL << 60, maxvy = -(1LL << 60),minvy = 1LL << 60;
  rep(i,n){
    maxvx = max(maxvx,vx[i]);
    maxvy = max(maxvy,vy[i]);
    minvx = min(minvx,vx[i]);
    minvy = min(minvy,vy[i]);
  }
  cout << max(maxvx-minvx,maxvy-minvy) << endl;


  return 0;
}

Measured memory_bytes: 6424
n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
#ak=a*k
#ad=a.uniq.size
#add=(ad*(ad-1))/2
as=a.size
rn=0

a.each do |ae|
  rn+=a.select{|s|s<ae}.size
end

r=0
as.times do
  ai = a.pop
  r+=a.select{|s|s<ai}.size
end

add=rn
ks = ((k*(k+1))/2)
e = 1000000007
p (ks*add-r*k)%e


Measured memory_bytes: 33020
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
char buff[1 << 22];
template <int size>
struct Buffer{
    int idx = 0;
    Buffer(){ read(0, buff, size); }
    template <class T>
    void next(T& ret){
        // int ret = 0;
        ret = 0;
        // while(!(buff[idx] & 0x10)){ idx++; }
        while(buff[idx] & 0x10){ ret = ret * 10 + (buff[idx++] ^ '0'); }
        idx++;
        // while(!isdigit(buff[idx])){ idx++; }
        // while(isdigit(buff[idx])){ ret = ret * 10 + buff[idx++] - '0'; }
        // return ret;
    }
};
struct FastInput {
    Buffer<1 << 22> buf;
    template <class T>
    FastInput& operator >> (T& num) { buf.next(num); return *this; }
    // FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

enum { SIZE = 1 << 20 };
char buf[SIZE];
int accs[512][512];
pair<int, int> pqs[100000];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        accs[1][r]++;
        accs[l + 1][r]--;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
        }
    }
    char* ptr = buf + SIZE;
    for(int i = 0; i < q; i++){
        cin >> pqs[i].first >> pqs[i].second;
    }
    for(int i = q - 1; i >= 0; i--){
        int p = pqs[i].first, q = pqs[i].second;
        *--ptr = '\n';
        div_t num2;
        num2.quot = accs[p][q];
        do{
            num2 = div(num2.quot, 10);
            *--ptr = num2.rem | '0';
        }while(num2.quot);
    }
    write(1, ptr, buf + SIZE - ptr);
}


Measured memory_bytes: 6784
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	s := scanInts(n)
	t := scanInts(m)

	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, m+1)
	}
	for i := 0; i < m+1; i++ {
		dp[0][i] = 1
	}

	for i := 0; i < n; i++ {
		add := 0
		dp[i+1][0] = 1
		for j := 0; j < m; j++ {
			dp[i+1][j+1] = dp[i][j+1]
			if s[i] == t[j] {
				add+=dp[i][j]
				add %= MOD
			}

			dp[i+1][j+1] += add
			dp[i+1][j+1] %= MOD
		}
		debug(dp[i+1])
	}

	fmt.Fprintln(wr, dp[n][m])
}

// MOD constant
const MOD = 1000000007


Measured memory_bytes: 66304
H,N = map(int,input().split())
Q = []
for _ in range(N):
    a,b = map(int,input().split())
    Q.append((a,b))
INF = float("inf")
dp = [INF]*(H+1)
dp[0] = 0
for i in range(H+1):
    for a,b in Q:
        if i+a>=H:
            dp[H] = min(dp[H],dp[i]+b)
        else:
            dp[i+a] = min(dp[i+a],dp[i]+b)
print(dp[-1])

Measured memory_bytes: 73604
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    ll ans = HIGHINF;
    for (int i = 0; i <= 2 * max(x + (x & 1), y + (y & 1)); i += 2) {
        ll tmp = i * c;
        ll rema = x - i / 2, remb = y - i / 2;
        tmp += a * max(rema, 0LL);
        tmp += b * max(remb, 0LL);
        chmin(ans, tmp);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
flag = True
n = int(input())
L = []
for i in range(n):
    t = int(input())
    L.append(t)
L.append(0)
if L[0] != 0:
    flag = False
cur = 0
ans = 0
for i in range(1, n+1):
    if cur < L[i]:
        if L[i]-cur != 1:
            flag = False
            break
        else:
            ans += 1
            cur = L[i]
    else:
        ans += L[i]
        cur = L[i]
if flag:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 11052
#include<stdio.h>

int main(){
  int a,b,c,i;
  int flg[60];
  scanf("%d %d %d",&a,&b,&c);
  for(i=0;i<60;i++){
    flg[i]=0;
  }
  
  int p=0;
  int sum=0;
  while(1){
    if(flg[p]==1){
      printf("-1\n");
      break;
    }
    flg[p]=1;
    
    if(p<=c&&c<=p+a){
      printf("%d\n",sum+c-p);
      break;
    }
    p=(p+a+b)%60;
    sum=(sum+a+b);
  }
  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main()
{
  int t;	
	scanf("%d",&t);
	int a[t],i;
	int sum1=0,sum2=0;
	for(i=0;i<t;i++)
	{
	scanf("%d",&a[i]);
	sum1+=a[i]*a[i];
	sum2+=a[i];
    }
    int s;
   if(sum2*1.0/t-sum2/t<=0.5) s=sum2/t;
   else                        s=sum2/t+1;
   printf("%d\n",sum1+t*s*s-2*s*sum2);
}

Measured memory_bytes: 128
n = int(input())
l = sorted(map(int, input().split()))
ans=0
for i in range(n):
  for j in range(i):
    for k in range(j):
      if l[i]!=l[j]and l[k]!=l[j]and l[k]!=l[i]:
        if l[k] +l[j] > l[i]:
          ans+=1
print(ans)


Measured memory_bytes: 67984
n,k = map(int, input().split())
lis = list(map(int, input().split()))

if len(lis) == 1:
    print(abs(lis[0]))
    exit()

ans = 10**9+7
for i in range(n-k+1):
    l = abs(lis[i]) + abs(lis[i+k-1]-lis[i])
    r = abs(lis[i+k-1]) + abs(lis[i+k-1]-lis[i])
    ans = min(ans, l, r)

print(ans)

Measured memory_bytes: 19956
#include <iostream>

int
main(int argc, char** argv) {
    std::string S;
    std::cin >> S;

    int cnt = 0;
    for (int i=0; i < S.length(); i++) {
        auto wp = S.c_str() + i;
        if (*wp == 'x') {
            cnt++;
        }
    }
    std::printf("%s\n", cnt < 8 ? "YES" : "NO");
    return 0;
}

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

using namespace std;

int min_cost(array<array<int, 10>, 10> &c, int n, int st,
             vector<vector<int>> &memo) {
  if (n == 1) {
    return 0;
  }

  if (memo[n][st] < 0) {
    int ans = -1;
    for (int i = 0; i <= 9; ++i) {
      if (st & (1 << i)) {
        continue;
      }

      int cost = min_cost(c, i, st | (1 << i), memo) + c[n][i];
      if (ans < 0 || cost < ans) {
        ans = cost;
      }
    }

    memo[n][st] = ans;
  }

  return memo[n][st];
}

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  array<array<int, 10>, 10> c;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> c[i][j];
    }
  }

  vector<vector<int>> va(h, vector<int>(w));
  vector<vector<int>> memo(10, vector<int>(2048, -1));
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> va[i][j];
      if (va[i][j] == -1) {
        continue;
      }

      ans += min_cost(c, va[i][j], 0, memo);
    }
  }

  cout << ans << '\n';
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int ans = 0;
    if (N > K) ans += Y * (N - K);
    ans += X * min(N, K);
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readInputLine()
    
    val aList = readInputLine().split(" ").map { it.toInt() }
    var ok = true
    
    for (a in aList) {
        if (a % 2 == 1) {
            ok = !ok
        }
    }
    
    if (ok) {
        println("YES")
    } else {
        println("NO")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 53764
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF 1001001001001001001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, 0, n)cin >> a[i];
	long long int ans = 0;
	rep(i, 0, n)rep(j, i, n) {
		if (i == j)continue;
		ans += a[i] * a[j];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

const ll INF = 1LL<<60;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    vector<vector<ll>> p(n, vector<ll>(11));

    rep(i,n) rep(j, 10) cin >> f[i][j];
    rep(i,n) rep(j, 11) cin >> p[i][j];

    ll ans = -INF;
    for(int i = 1; i < 1<<10; i++){
        vector<int> isOpen(10);
        rep(j, 10) if (i>>j & 1) isOpen[j] = 1;
        vector<int> cnt(n);
        rep(j, n) rep(k, 10){
            if (isOpen[k] == 1 && f[j][k] == 1) cnt[j]++;
        }
        ll sum = 0;
        rep(j, n) sum += p[j][cnt[j]];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define calc(l,r) max(0,(int)(upper_bound(t,t+n,r)-lower_bound(t,t+n,l)))
int n,a[200005],b[200005];
long long ans,t[200005];
int main(){cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<32;i++){
		for(int j=0;j<n;j++)t[j]=b[j]&(1ll<<i+1)-1;
		sort(t,t+n);
		for(int j=0;j<n;j++){
			int x=a[j]&(1ll<<i+1)-1;
			if(calc((1ll<<i)-x,(1ll<<i+1)-x-1)+calc((1ll<<i+1)+(1ll<<i)-x,(1ll<<i+2)-x-1)&1)ans^=1ll<<i;
		}
	}cout<<ans;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;
const int MaxNV = MaxN * 2 + 2;

int n;
int a[MaxN + 1], b[MaxN + 1];
int c[MaxN + 1], d[MaxN + 1];

int ufs[MaxN + 1];

int nV = 0;
map<int, int> id;

inline void add(const int &v)
{
	if (id.find(v) == id.end())
	{
		id.emplace(v, ++nV);
		ufs[nV] = nV;
	}
}

int ufs_find(const int &u)
{
	return ufs[u] == u ? u : ufs[u] = ufs_find(ufs[u]);
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		a[i] = getint(), a[0] ^= a[i];
	for (int i = 1; i <= n; ++i)
		b[i] = getint(), b[0] ^= b[i];

	for (int i = 0; i <= n; ++i)
		c[i] = a[i], d[i] = b[i];
	sort(c, c + n + 1);
	sort(d, d + n + 1);

	for (int i = 0; i <= n; ++i)
		if (c[i] != d[i])
		{
			cout << -1 << endl;
			return 0;
		}

	int res = 0;
	for (int i = 0; i <= n; ++i)
		if (a[i] != b[i] || !i)
		{
			res += i > 0;
			add(a[i]), add(b[i]);
		}

	if (res == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	for (int i = 0; i <= n; ++i)
		if (a[i] != b[i])
		{
			int u = ufs_find(id[a[i]]);
			int v = ufs_find(id[b[i]]);
			ufs[u] = v;
		}

	for (int i = 1; i <= nV; ++i)
		res += ufs[i] == i;

	cout << res - 1 << endl;

	return 0;
}

Measured memory_bytes: 9984
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};

int cnt(ll num){
	int i=0;
	for(;num>=1;i++){
		num /= 10;
	}
	return i;
}

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

	ll n;
	cin >> n;
	int ans;
	ans = cnt(n);

	for(int i=2;i<=sqrt(n);i++){
		if(n%i == 0) ans = cnt(n/i);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char** argv)
{
	int m, f, r, max;
	char result[1000];
	int i = 0;

	memset(result, '\0', sizeof(result));
	while (1) {
		scanf("%d %d %d", &m, &f, &r);

		if (m == -1 || f == -1) {
			result[i] = 'F';
		}
		else {
			int sum = m + f;
			if (sum >= 80) {
				result[i] = 'A';
			}
			else if (sum >= 65 && sum < 80) {
				result[i] = 'B';
			}
			else if (sum >= 50 && sum < 65) {
				result[i] = 'C';
			}
			else if (sum >= 30 && sum < 50) {
				result[i] = 'D';
				if (r >= 50) {
					result[i] = 'C';
				}
			}
			else if (sum < 30) {
				result[i] = 'F';
			}
		}

		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		i++;
	}
	max = i;

	for (i = 0; i < max; i++) {
		printf("%c\n", result[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
/*
#define mod 7
typedef long long ll;

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int main()
{
    calcFacAndInv(100000);
     cout<<inv[3];
    return 0;
}
*/


// GCD

int gcd(long long a,long long b)
{
    if (b==0)
        return a;
    return gcd (b,a%b);
}
//fast power
/*
#define mod 1000000007
long long fp(long long  base, long long exp)
{
    if (exp == 0)
        return 1;
    long long  ans = fp(base, exp / 2);
    ans = (ans * ans);
    if (exp % 2 != 0)
        ans = (ans * (base )) ;
    return ans;
}
*/
//prime factoriation
/*
set<int >s;
bool prime factorization (int x)
{
    for (int j=2; j*j<=x; ++j)
    {
        while (x%j==0)
        {
            s.insert(j);
            x/=j;
        }
    }
    if (x>1)
    {
        s.insert(x);
    }
    if (s.size()==2)
        return true ;
    else
        return false ;
}

#define ll long long
int a,b,q,p,n;
int countDivisorss(int x,int y)
{
    ll cnt = 0;
    for (int i = min(x,y); i <= sqrt(n); i++)
    {
        if (x % i == 0&&y%i==0)
        {
            if (x / i == i||y / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}
int countDivisors(int x)
{
    ll cnt = 0;
    int tmp=n;
    if (n-x>10000000)  tmp=sqrt(n);
    for (int i = x; i <= tmp; i++)
    {
        if (x % i == 0)
        {
         if (x/i==i)
            cnt++;
         else
            cnt = cnt + 2;
        }
    }
    return cnt;
}
*/

/*
        int s =n/2,e=n-1;
        while (s<=e&&e<=n-1)
        {
            int mid =s+e/2;

            if (arr[mid]==arr[n/2])
            {
                s=mid;
                num +=mid -s;
            }
            else
                e=mid-1;
        }
        */




const int N = 1e5 + 5;

vector<int> adj[N];
bool visited[N];
int nodesNum;
void dfs(int node)
{
   if (visited[node])
       return;
   visited[node] = true;
   for (int child: adj[node])
       dfs(child);
}

int main()
{
   int n;
   cin>>n;
   if (n%2==0)
    cout<<n/2;
   else 
    cout<<n/2+1;
   return 0;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    ll s;cin>>s;
    ll b=s;
    vector<int> f(1000010);
    f[s]=1;
    for(int i=2;i<=1000000;i++){
        ll a;
        if(b%2){
            a=3*b+1;
        }else{
            a=b/2;
        }
        if(f[a]){
            cout<<i<<endl;
            return 0;
        }
        f[a]=true;
        b=a;
    }
}


Measured memory_bytes: 4096
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List as List
import Data.Array.ST
import Data.Array


isSiritori :: String -> String -> Bool
isSiritori a b = t == h
    where
        t = last a
        h = head b

solve :: String -> String -> String -> Bool
solve a b c = (isSiritori a b) && (isSiritori b c)

toYesNo :: Bool -> String
toYesNo True = "YES"
toYesNo _ = "NO"

main :: IO()
main = do
    (a:b:c:_) <- map BS.unpack . BS.words <$> BS.getLine
    putStrLn $ toYesNo $ solve a b c

Measured memory_bytes: 380
n=int(input())
s1=input()
s2=input()

v=3
for i in range(1,n):
  if s1[i-1]==s2[i-1]:
    v*=2
  elif s1[i-1]!=s1[i] and s1[i]!=s2[i]:
    v*=3
  elif i==1:
    v*=2

print(v%1000000007)    


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    string s;
    cin >> s;
    int nedan = 700;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == 'o') {
            nedan += 100;
        }
    }
    cout << nedan;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		String inputData = br.readLine();
		String[] inputValue = inputData.split(" ");

		int a = Integer.parseInt(inputValue[0]);
		int b = Integer.parseInt(inputValue[1]);

		double conversion_a = a;
		double conversion_b = b;

		int d = a/b;
		int r = a%b;
		double f = conversion_a/conversion_b;

		System.out.printf(d + " " + r + " " + "%.5f", f);
	}

}

Measured memory_bytes: 24820
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define NEWMAT(N, M, ini) MAT(N, vector<lint>(M, ini))
#define MOD 1000000007

typedef long long lint;
typedef pair<lint, lint> P;
typedef vector<lint> V;
typedef vector<vector<lint>> MAT;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint H; cin >> H;
    lint W; cin >> W;
    lint N; cin >> N;

    lint r,c;
    cin >> r; cin >> c;
    r--;
    c--;

    string S, T;
    cin >> S; cin >> T;

    vector<P> aok_tate(2*N+1);
    vector<P> aok_yoko(2*N+1);

    aok_tate[2*N] = P(0, H);
    aok_yoko[2*N] = P(0, W);

    for(lint i = N-1; i >= 0; i--) {
      P old = aok_yoko[2*i+2];
      if(T[i] == 'L') {
        aok_yoko[2*i+1] = P(old.first, min(W, old.second+1));
      } else if (T[i] == 'R') {
        aok_yoko[2*i+1] = P(max((lint)0, old.first-1), old.second);
      } else {
        aok_yoko[2*i+1] = P(old.first, old.second);
      }

      old = aok_yoko[2*i+1];
      if(S[i] == 'L') {
        aok_yoko[2*i] = P(min(W,old.first+1), old.second);
      } else if (S[i] == 'R') {
        aok_yoko[2*i] = P(old.first, max((lint)0, old.second-1));
      } else {
        aok_yoko[2*i] = P(old.first, old.second);
      }

      if(aok_yoko[2*i].first >= aok_yoko[2*i].second) {
        PRINT("NO");
        exit(0);
      }

      //      cout << aok_yoko[2*i].first << ", " << aok_yoko[2*i].second << "\n";
    }

    for(lint i = N-1; i >= 0; i--) {
      P old = aok_tate[2*i+2];
      if(T[i] == 'U') {
        aok_tate[2*i+1] = P(old.first, min(H, old.second+1));
      } else if (T[i] == 'D') {
        aok_tate[2*i+1] = P(max((lint)0, old.first-1), old.second);
      } else {
        aok_tate[2*i+1] = P(old.first, old.second);
      }

      old = aok_tate[2*i+1];
      if(S[i] == 'U') {
        aok_tate[2*i] = P(min(H, old.first+1), old.second);
      } else if (S[i] == 'D') {
        aok_tate[2*i] = P(old.first, max((lint)0, old.second-1));
      } else {
        aok_tate[2*i] = P(old.first, old.second);
      }

      if(aok_tate[2*i].first >= aok_tate[2*i].second) {
        PRINT("NO");
        exit(0);
      }

      //     cout << aok_tate[2*i].first << ", " << aok_tate[2*i].second << "\n";
      
    }

    if(c >= aok_yoko[0].first && c < aok_yoko[0].second &&
       r >= aok_tate[0].first && r < aok_tate[0].second ) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }

    return 0;
}


Measured memory_bytes: 13464
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;cin>>S;
    const string K="keyence";
    bool flag=true;
    for(int i=0;i<7;i++){
        if(flag==true&&S.at(i)!=K.at(i)){
            flag=false;
        }if(flag==false){
            if(S.at(S.size()+i-7)!=K.at(i)){
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	long long a, b, n;
	cin >> a >> b >> n;
	if (b-1<n) {
		long long t = (b-1) / b;
		cout << (b-1) * a / b - t * a << endl;
	}
	else {
		long long t = n / b;
		cout << n * a / b - t * a << endl;
	}
	return 0;
}

Measured memory_bytes: 3580
n = int(input())
d = list(map(int, input().split()))
count = 0

d = sorted(d)
k = int(d[int((n/2)-1)])

if d[int((n/2)-1)] == d[int(n/2)]:
    print(0)
else:
    while k < d[int(n/2)]:
        count += 1
        k += 1
    print(count)

Measured memory_bytes: 14428
#include <iostream>
#include <cmath>

using namespace std;

long long flipping_signs(int n, long long a[]) {
  long long sum = 0;
  long long minimum = 1000000001;
  int num_minus = 0;
  for(int i=0;i<n;i++) {
    if(a[i] < 0)
      num_minus++;
    long long absolute = abs(a[i]);
    sum += absolute;
    minimum = min(absolute, minimum);
  }
  if(num_minus % 2 == 0)
    return sum;

  return sum - 2 * minimum;
}

int main() {
  int n;  
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  long long ans = flipping_signs(n , a);
  cout << ans;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
    	int i, j;
    	while(true) {
        	String moji = sc.nextLine();
    		int sum = 0;
    		if(moji.equals("0")) break;
    	
    		for(char c : moji.toCharArray()) {
    			sum += Integer.parseInt(String.valueOf(c));
    		}
    		System.out.println(sum);
    	}
    }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int ret=0;
	for (int i=0; i<n-1; i++) {
		if (s[i]==s[i+1]) ret++;
	}
	ret += 2*k;
	cout << min(n-1, ret) << endl;
	return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  string S;
  cin>>N>>S;
  map<char,int> mp;
  for(char c:S)mp[c]++;
  int ans=mp['R']*mp['G']*mp['B'];
  for(int i=0;i<N-1;i++)
    for(int j=i+1;j<N && j*2-i<N;j++)
      if(S[i]!=S[j] && S[i]!=S[j*2-i] && S[j]!=S[j*2-i])ans--;
  cout<<ans<<endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <cctype>
//小文字を大文字 c-0x20;


#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
using namespace std;


int main(){
  while(1){
  string s;
  cin>>s;
  if(s=="-")break;
  size_t sin=s.length();
  int m,h;
  cin>>m;
  rep(i,m){
    cin>>h;
    rep(j,h){
      s.pb(s[0]);
    s.erase(s.begin());
    
    }
  }
  cout<<s<<endl;
}
return 0;
}


Measured memory_bytes: 3160
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        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){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << "\n";
        }
        cout << endl;
    }
    
    return 0;
    
    
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> s(N+1);
    int P[M],Y[M];
    for(int i=0; i<M; i++) {
        cin >> P[i] >> Y[i];
        s[P[i]].push_back(Y[i]);
    }
    for(int i=0; i<N; i++) sort(s[i+1].begin(),s[i+1].end());
    for(int i=0; i<M; i++) {
        int n = lower_bound(s[P[i]].begin(),s[P[i]].end(),Y[i]) - s[P[i]].begin() + 1;
        cout << setfill('0') << setw(6) << right << P[i];
        cout << setfill('0') << setw(6) << right << n << endl;
    }
}

Measured memory_bytes: 7680
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 55
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	// WF("output.txt");
	DF("err.txt");
	
	int N;
	scanf("%d", &N);
	vector <int> H(N);
	for (int i = 0; i < N; i++) scanf("%d", &H[i]);
	bool ok = true;
	for (int i = N - 2; i >= 0 and ok; i--) {
		if (H[i] > H[i + 1] + 1) ok = false;
		else if (H[i] == H[i + 1] + 1) H[i]--;
	}
	puts(ok ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
static const ll INFTY = (1LL << 32);

int V, E;
ll A[100][100];

void warshallFloyd(){
	rep(k, V)
		rep(i, V)
		   rep(j, V)
	{
		if (A[i][k] != INFTY && A[k][j] != INFTY){
			A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
		}
	}
}

int main() {

	cin >> V >> E;

	rep(i, V) rep(j, V){
		A[i][j] = (i == j) ? 0 : INFTY;
	}

	rep(i, E){
		int s, t, d;
		cin >> s >> t >> d;
		A[s][t] = d;
	}

	warshallFloyd();

	rep(i, V){ if (A[i][i] < 0){ cout << "NEGATIVE CYCLE" << endl; return 0; } }

	rep(i, V){
		rep(j, V){
			if (A[i][j] == INFTY){
				cout << "INF";
			}
			else{
				cout << A[i][j];
			}
			if (j < V - 1){ cout << " "; }
		}
		cout << endl;
	}

}

Measured memory_bytes: 3184