akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<cmath>
#include<stack>
#include<math.h>
#include<queue>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) if(scanf("%d",&x)){}
#define scaa(x,y) if(scanf("%d%d",&x,&y)){}
#define prt(x) printf("%d\n",x)
#define inf 0x7f7f7f7fconst int maxn = 1e5+5;
using namespace std;
const int maxn = 9e5+1000;
int n, m;
struct Tree {
    int ls, rs, val; // 左右儿子的编号, 和维护的一个值.
}tre[maxn*40];
int idx = 0, root[maxn];
int build(int l, int r) {
    int nod = ++idx;
    tre[nod].val = 0;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    tre[nod].ls = build(l, mid);
    tre[nod].rs = build(mid+1, r);
    return nod;
}
int update(int pre, int l, int r, int pos, int v) {
    int nod = ++idx;
    tre[nod] = tre[pre]; tre[nod].val += v;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    if (pos <= mid) tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
    else tre[nod].rs = update(tre[pre].rs, mid+1, r, pos, v);
    return nod;
}
int query(int id, int l, int r, int pos) {
    if (l == r) return tre[id].val;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
    }
    else return query(tre[id].rs, mid+1, r, pos);
}
int a[maxn], vis[maxn*10];
int main() {
    scaa(n,m);
    for (int i = 1 ; i <= n ; i ++) {
        sca(a[i]);
    }
    root[0] = build(1, n);    //根节点
    for (int i = 1 ; i <= n ; i ++) {
        if (!vis[a[i]])
            root[i] = update(root[i-1], 1, n, i, 1);
        else {
            int t = update(root[i-1], 1, n, vis[a[i]], -1);
            root[i] = update(t, 1, n, i, 1);
        }
        vis[a[i]] = i;
    }
    while (m--) {
        int l, r; 
		scaa(l,r);
        int tmp = query(root[r], 1, n, l);
        printf("%d\n", tmp);
    }
}


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

int main(void){
    int a,b,T[1000],i;
    cin>>a>>b;
    
    T[1]=1;
    for(i=2;i<1000;i++){
        T[i]=T[i-1]+i;
    }
    
    int s;
    for(i=2;i<1000;i++){
        if(T[i]-T[i-1]==b-a)s=i;
    }
    cout<<T[s]-b;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	setcomb();
	ll h, w, i, ans, a, b;
	cin >> h >> w >> a >> b;
	for (i = b; i <= min(w - 1, h - a + b-1); i++)
		ans = (ans + (comb(h - a + b-1, i)*comb(w + a - b - 1, w - 1 - i) % M))%M;
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

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

	int res = pow(3, N);
	int b = 1;
	for (int i = 0; i < N; ++i) {
		int t = (a[i] % 2 ? 1 : 2);
		b *= t;
	}

	cout << res - b << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll bisket;
ll K,A,B; 
int main(){
	scanf("%lld %lld %lld",&K,&A,&B);
	bisket=1;
	if((A<B-2) && (K>A)){
		K-=(A-1); // 5
		bisket=A; // 1
		ll cnt=K/2; //
		bisket+=cnt*(B-A);
		if(K%2==1){
			bisket+=1;
		}
	}
	else{
		bisket=K+1;
	}
	printf("%lld\n",bisket);
	return 0;
}
// 53513332169120811
// 48518828981938099

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

int main(){
  long long int N;
  cin >> N;
  vector<long int> height(N);
  
  for(long long int i = 0; i < N; i++){
    cin >> height[i];
  }
  
  vector<long int> step(N);
  
  step[0] = 0;
  
  for(long long int i = 1; i < N; i++){
    int diff = height[i] - height[i - 1] - step[i - 1];
    
    if(diff >= 0){
      step[i] = 0;
    }
    
    else{
      step[i] = -diff;
    }
    
  }
    long int sum = 0;
    
    for(int i = 0; i < N;i++){
      sum += step[i];
    }
    
    cout << sum << endl;
  }

Measured memory_bytes: 6400
# AOJ 0033 Ball
# Python3 2018.6.16 bal4u

n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = c = 0
	yes = True
	for j in range(10):
		if a[j] > b: b = a[j]
		elif a[j] > c: c = a[j]
		else: yes = False
	print('YES' if yes else 'NO')


Measured memory_bytes: 5596
#include"bits/stdc++.h" 
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
vector<int>u;
vector<int>w;
vector<int>::iterator it;
priority_queue<int>pq;
const int N=1e5+10;
/*--------------------------hbp16@hbp16-Inspiron-3543:-$------------------------------*/

int solve(string s,int l)
{
	for(int i=0;i<l;i++)
	{
		//cout<<s[i];
		if(s[i] != s[l-i-1])
		{
			return 0;
		}
	}
	return 1;

}

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

	int l = s.length();
	int first = solve(s,l);
	//cout<<endl;
	if(first == 1)
	{
		int end = (l-1)/2;
		string sc = "";
		for(int i=0;i<end;i++)
		{
			sc += s[i];
		}

		int sec = solve(sc,sc.length());
		//cout<<endl;
		if(sec == 1)
		{
			int st = (l+3)/2;
			string thr = "";
			for(int i=st-1;i<l;i++)
			{
				thr += s[i];
			}
			int third = solve(thr,thr.length());
			//cout<<endl;

			if(third == 1)
			{
				cout<<"Yes";
			}
			else
			{
				cout<<"No";
			}
		}
		else
		{
			cout<<"No";
		}
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  int N;
  cin >> N;
  int ans = N % 2 ? 2 * N : N;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int minus_num = 0;
  rep(i,n){
    int t;
    cin >> t;
    if (t<0) minus_num++;
    a[i] = abs(t);
  }
  cerr << minus_num << endl;
  ll sum = 0;
  rep(i,n){
    sum += a[i];
  }
  if (minus_num%2 == 1) {
    sum -= *min_element(a.begin(),a.end())*2;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if (x < 1200) {
			System.out.println("ABC");
		}else {
			System.out.println("ARC");
		}
	}
}


Measured memory_bytes: 35560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	string S;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < S.size() / 2; i++)
	{
		int l = i;
		int r = S.size() - 1 - i;

		if (S[l] != S[r])
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
/**
 * Dijkstra's Algorithm
 *
 * O(m + nlogn)
 */

#include <vector>
#include <queue>
#include <set>
using namespace std;

struct edge{
  int to;
  int cost;
};
int INF = 1 << 30;
using Pii = pair<int,int>;

vector<int> Dijkstra(const vector<vector<edge>>& G,int s){
  vector<int> dist(G.size(),INF);
  dist[s] = 0;
  priority_queue<Pii,vector<Pii>,greater<Pii>> que;
  que.emplace(dist[s],s);
  while(!que.empty()){
    auto d = que.top().first;
    auto v = que.top().second;
    que.pop();
    if(dist[v] < d) continue;
    for(auto & e : G[v]){
      if(dist[e.to] > d + e.cost){
        dist[e.to] = d + e.cost;
        que.emplace(dist[e.to],e.to);
      }
    }
  }
  return dist;
}

#include <iostream>

int main(){
  int v,e,r;
  cin >> v >> e >> r;
  vector<vector<edge>> G(v);
  for(int i = 0;i < e;i++){
    int s,t,d;
    cin >> s >> t >> d;
    G[s].push_back({t,d});
  }
  auto res = Dijkstra(G,r);
  for(auto i : res){
    if(i == INF) cout << "INF";
    else cout << i;
    cout << endl;
  }
}



Measured memory_bytes: 12852
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  vector<P> v;
  int t=0;
  rep(i,n){
    int j=i;
    v.PB(P(t,s[i]));
    while(j<n&&s[i]==s[j]) j++;
    t+=j-i;
    i=j-1;
  }
  v.PB(P(t,0));

  int ans=0;
  rep(i,v.size()){
    int m=v.size()-1;
    int ij=i+k*2+(v[i].S=='1');
    int j=min(m,ij);
    ans=max(ans,v[j].F-v[i].F);
  }

  cout<<ans<<endl;



}

Measured memory_bytes: 2548
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define ll long long

int main(void){

    int n;
    cin>>n;
    ll ans = 1;
    for(int i=1;i<=n;i++){
        ans = ans * i % 1000000007;
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
 cin>>s;
 if(s[0]==s[1]&&s[1]==s[2])cout<<"No";
 if(s[0]==s[1]&&s[1]!=s[2])cout<<"Yes";
 if(s[0]!=s[1]&&s[1]==s[2])cout<<"Yes";
 if(s[0]==s[2]&&s[0]!=s[1])cout<<"Yes";
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++)
  {
    if(i%k==0)
    {
      cout<<"OK";
      return 0;
    }
  }
  cout<<"NG";
  return 0;
}

Measured memory_bytes: 3632
from math import *
import sys,bisect,copyreg,copy,statistics,os
def inp(): return sys.stdin.readline().strip()
def IIX(): return (int(x) for x in sys.stdin.readline().split())
def II(): return (int(inp()))
def LI(): return list(map(int, inp().split()))
def LS(): return list(map(str, inp().split()))
def L(x):return list(x)
def out(var): return sys.stdout.write(str(var))


x,k,d=LI()

x=abs(x)

if (x//d>=k) :  out(x-k*d)
else:
    k-=x//d
    x-=(x//d) *d
    if k % 2==0:    out(x)
    else:   out(abs(x-d))

















 










Measured memory_bytes: 72772
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
ll powMod(ll k, ll n, ll mod) {
    ll x = 1;
    while (n > 0) {
        if (n & 1) {
            x = x * k % mod;
        }
        k = k * k % mod;
        n >>= 1;
    }
    return x;
}

int main() {
  ll n, m, x, y = 0, z = 0, h, w, sum = 0, Max = -1, Min = 1e9+1;
  string s, t, u;
  bool ok=true;
  cin >> n;
  VI a(n); rep(i,n) cin >> a[i];
  VI b(n);

  if(n%2==0){
    rep(i,n){
      if(a[i]%2==0){
        pri(0); return 0;
      }
      b[a[i]]++;
    }

    for(int i=1; i<n; i+=2){
      if(b[i] != 2){
        pri(0); return 0;
      }
    }
    x = powMod(2,n/2,mod);
    pri(x);
  }
  else{
    rep(i,n){
      if(a[i]%2!=0){
        pri(0); return 0;
      }
      b[a[i]]++;
    }
    if(b[0]!=1){
      pri(0); return 0;
    }
    for(int i=2; i<n; i+=2){
      if(b[i] != 2){
        pri(0); return 0;
      }
    }
    x = powMod(2,n/2,mod);
    pri(x);
  }


  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

bool memo[10];
int nodenum,edge;

int dfs(int cnt, int node, const vector<P>& v){
    static int ret = 0;
    if(memo[node] != 0) return ret;
    if(cnt == nodenum) return ret += 1;
    memo[node] = true;
    for(int i = 0; i < edge; ++i){
        if(node == get<0>(v[i])) dfs(cnt+1, get<1>(v[i]), v);
        if(node == get<1>(v[i])) dfs(cnt+1, get<0>(v[i]), v);
    }
    memo[node] = false;
    return ret;
}

int main()
{
    cin >> nodenum >> edge;
    vector<P> v(edge);
    for(int i = 0; i < edge; ++i) cin >> get<0>(v[i]) >> get<1>(v[i]);

    cout << dfs(1, 1, v) << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

vector<ll> ans;

void dfs(ll a){
  if(a>3234566667){
    return;
  }
  else{
    ans.push_back(a);
    int x=a%10;
    if(x!=0) dfs(a*10+x-1);
    dfs(a*10+x);
    if(x!=9) dfs(a*10+x+1);
  }
}

int main(){
  int k; cin >> k;
  ans.resize(0);
  for(int i=1;i<10;i++) dfs(i);
  sort(all(ans));
  cout << ans[k-1] << endl;
}

Measured memory_bytes: 1400
import java.util.*;class Main{public static void main(String[]a){Locale.setDefault(Locale.US);int m;for(Scanner s=new Scanner(System.in);(m=s.nextInt())>0;System.out.println(new java.text.SimpleDateFormat("EEEE").format(new GregorianCalendar(2004,m-1,s.nextInt()).getTime())));}}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
int main(){
  #define int long long
  int N,m=0,ans=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    m=max(m,a);
    ans+=m-a;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
const int ZERO = 2 * 80 * 80 * 33;
std::bitset<2 * ZERO + 1> curr[80], next[80];
int a[80][80], b[80][80], nRows, nCols;
int main() {
    std::cin >> nRows >> nCols;
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            std::cin >> a[i][j];
        }
    }
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            std::cin >> b[i][j];
        }
    }
    curr[0][ZERO] = 1;
    for (int r = 0; r < nRows; r++) {
        std::fill(next,next+80,0);
        int d = std::abs(a[r][0] - b[r][0]);
        next[0] = (curr[0] << d) | (curr[0] >> d);
        for (int c = 1; c < nCols; c++) {
            d = std::abs(a[r][c] - b[r][c]);
            next[c] |= (next[c-1] << d) | (next[c-1] >> d);
            next[c] |= (curr[c] << d) | (curr[c] >> d);
        }
        std::copy(next,next+80,curr);
    }
    int answ = ZERO+1;
    for (int x = -ZERO; x <= ZERO; x++) {
        if (curr[nCols-1][x+ZERO]) {
            answ = std::min(answ,std::abs(x));
        }
    }
    assert(answ <= ZERO);
    std::cout << answ << std::endl;
    return 0;
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

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


long long power(long long x, long long y, long long p)
{
long long res = 1;


x = x % p;


while (y > 0)
{
if (y & 1)
res = (res*x) % p;


y = y>>1;
x = (x*x) % p;
}
return res;
}

void solve()
{
     ll n,k;
     cin>>n>>k;
     ll i,j;
     ll cnt[k+1];
     clr(cnt);
     for(i=1;i<=k;i++)
     {
        cnt[i]=k/i;
     }
     ll ans[k+1];
     clr(ans);
     for(i=k;i>=1;i--)
     {
        ll tans=power(cnt[i],n,mod);
        for(j=2*i;j<=k;j+=i)
        {
            tans-=ans[j];
            tans%=mod;
            tans+=mod;
            tans%=mod;
        }
        ans[i]=tans;
     }
    ll nos2=0;
    ll res=0;
    for(i=1;i<=k;i++)
    {
      ll tans=ans[i]*i;
      res+=tans;
      res%=mod;      
    }
    res%=mod;
    res+=mod;
    res%=mod;

    cout<<res<<"\n";

}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll, ll> sll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<int, ll> mil;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define PB push_back

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	int types[5]={0,6000,4000,3000,2000};
	for(int i=0;i<4;i++){
		int t,n;
		cin>>t>>n;
		cout<<types[t]*n<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
using LL = long long;
using namespace std;
int mod = 998244353;
int main() {
	LL N, K;
	cin >> N >> K;
	vector<LL> Li(K), Ri(K);
	vector<bool> S_has(N + 1, false);
	for (int i = 0; i < K; i++) {
		cin >> Li[i] >> Ri[i];
		for (int j = Li[i]; j <= Ri[i]; j++) {
			S_has[j] = true;
		}
	}
	vector<LL> Dp(N + 1, 0);
	Dp[1] = 1;

	for (int i = 2; i <= N; i++) {
		Dp[i] += Dp[i - 1];
		for (int k = 0; k < K; k++) {
			if (i - Li[k] > 0) {
				Dp[i] += Dp[i - Li[k]];
			}
			if (i - Ri[k] - 1 > 0) {
				Dp[i] -= Dp[i - Ri[k] - 1];
			}
		}
		while (Dp[i] < 0) {
			Dp[i] += mod;
		}
		Dp[i] = Dp[i] % mod;

	}
	LL ans = Dp[N] - Dp[N - 1];
	while (ans < 0) {
		ans += mod;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4840
import java.util.Scanner;

/**
 * https://arc091.contest.atcoder.jp/tasks/arc091_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		sc.close();
		
		long ans = 0;
		if(N==2 || M==2){
			ans = 0;
		}else if(N==1 && M==1){
			ans = 1;
		}else if(N==1){
			ans = Math.max(0, M-2);
		}else if(M==1){
			ans = Math.max(0, N-2);
		}else{
			ans = (M-2)*(N-2);
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 21972
# 間違った人のポイントを引くのではなく、正解した人にポイントを足して最後に全員のポイントから問題数を引く
n, k, q = map(int, input().split())

# 各人の最初のポイント
point = [k] * n

# 問題正解者のリスト
a = []
for i in range(q):
    ai = int(input())
    a.append(ai)

# 正解した人のポイントに+1
for num in a:
    point[num-1] += 1

# 全員のポイントから問題数を引く
point_final = [x-q for x in point]

# YesとNoの判定
for points in point_final:
    if points > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14448
local n = io.read("*n", "*l")
local str = io.read()
local t = {}
for v in str:gmatch("(%d+)") do
  table.insert(t, tonumber(v))
end
table.sort(t)
local sum = 0
for i = 1, n do
  sum = sum + t[n + 2 * i - 1]
end
print(sum)


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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) cin<<(x);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x, v) lower_bound((x).begin(), (x).end(), (v))
#define uboundv(x, v) upper_bound((x).begin(), (x).end(), (v))
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;

using namespace std;

//int a[]={0, 1, 2, 3, 4, 5, 6, 7};
#define N 205
ll dis[N][N], mans=1e17;
int R;

void permu(int a[], int l, int r) {
	int i;
	if(l==r) {
		ll ans=0;
		FI(R-1) {
			//cout<<a[i]<<' '<<a[i-1]<<endl;
			ans += dis[a[i]][a[i-1]];
		}
		if(ans<mans) mans=ans;
	}
	else {
		for(i=l; i<=r; i++) {
			swap(a[l], a[i]);
			permu(a, l+1, r);
			swap(a[l], a[i]);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	int n, m, u, v, c;
	cin>>n>>m>>R;
	//memset(dis, 1e17, sizeof(dis));
	F(n+1) FF(n+1) dis[i][j]=1e15;
	FI(n+1) dis[i][i] = 0;
	int r[R];
	F(R) cin>>r[i];
	F(m) {
		cin>>u>>v>>c;
		dis[u][v] = c;
		dis[v][u] = c;
	}
	FORI(k, n) {
		FORI(i, n) {
			FORI(j, n) {
				dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
			}
		}
	}
	/*FI(n) {
		FFI(n) {
			cout<<dis[i][j]<<' ';
		}
		cout<<endl;
	}*/
	permu(r, 0, R-1);
	cout<<mans<<endl;
	return 0;
}

Measured memory_bytes: 640
using System;
class ITP1_6_C
{
    static void Main()
    {
        int[,,] list=new int [4,3,10];
        int n=int.Parse(Console.ReadLine());
        for(int i=0;i<n;i++){
            string[] readl=Console.ReadLine().Split(' ');
            int b=int.Parse(readl[0]);
            int f=int.Parse(readl[1]);
            int r=int.Parse(readl[2]);
            int v=int.Parse(readl[3]);
            list[b-1,f-1,r-1]+=v;
        }
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                for (int k = 0; k < 10; k++ )
                {
                    Console.Write(' ');
                    Console.Write(list[i, j, k]);
                }
                Console.WriteLine();
            }
            Console.WriteLine("####################");
        }
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                Console.Write(' ');
                Console.Write(list[3, j, k]);
            }
            Console.WriteLine();
        }
    }
}

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


void solve(std::string S, std::string T){
    int cnt = 0;
    for (int i=0; i<S.size(); i++) {
        if (S[i] != T[i]) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  string ans;
  if(n==0){
    cout << 0 << endl;
    return 0;
  }
  while(n!=0){
    ll m = n%(-2);
    if(m<0)m+=2;
    n = (n-m)/(-2);
    ans += (char)(m +'0');
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 3624
def main():
  M=10**9+7
  r1,c1,r2,c2=map(int,input().split())
  n=r2+c2+2
  fac=[1]+[0]*n
  for i in range(1,n+1):fac[i]=fac[i-1]*i%M
  f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
  print((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M)
main()

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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;
};

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

  ll H;
  cin >> H;
  ll ans = 0;
  ll cnt = 1;
  while (H) {
    ans += cnt;
    cnt *= 2ll;
    H /= 2ll;
  }

  cout << ans << endl;

  return 0;
};


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2((a.first - b.first)) + x2((a.second - b.second)));
    return dist;
}

// End of Template //



int main() {

    lint N;
    cin >> N;

    vpii town(N);
    int x, y;
    rep(i, N) {
        cin >> x >> y;
        town[i].first = x;
        town[i].second = y;
    }

    double distsum = 0;
    rep(i, N) {
        rep(j, N) {
            if (i != j)
                distsum += distance(town[i], town[j]);
        }
    }

    double distave = distsum / N;
    cou(setprecision(20) << distave);
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;

const int N = 1e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;

struct SegmentTree {
    int n;
    vi a, t;

    void init(int x, vi y) {
        n = x;
        a = y;
        t.assign(4 * n, -INF);
        build(1, 0, n - 1);
    }

    int merge(int x, int y) { return max(x, y); }

    void build(int i, int l, int r) {
        if (l == r) {
            t[i] = a[l];
            return;
        }
        int mid = (l + r) / 2;
        build(lc(i), l, mid);
        build(rc(i), mid + 1, r);
        t[i] = merge(t[lc(i)], t[rc(i)]);
    }

    void modify(int i, int l, int r, int pos, int val) {
        if (l > pos || r < pos) return;
        if (l == pos && r == pos) {
            t[i] = val;
            return;
        }
        int mid = (l + r) / 2;
        modify(lc(i), l, mid, pos, val);
        modify(rc(i), mid + 1, r, pos, val);
        t[i] = merge(t[lc(i)], t[rc(i)]);
    }

    int query(int i, int l, int r, int ql, int qr) {
        if (l > qr || r < ql) return -INF;
        if (l >= ql && r <= qr) return t[i];
        int mid = (l + r) / 2;
        int resL = query(lc(i), l, mid, ql, qr);
        int resR = query(rc(i), mid + 1, r, ql, qr);
        return merge(resL, resR);
    }

    void modify(int p, int v) { modify(1, 0, n - 1, p, v); }

    int query(int l, int r) { return query(1, 0, n - 1, l, r); }
};

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int n;
    cin >> n;
    int h[n], b[n];
    for (auto &x : h) cin >> x;
    for (auto &x : b) cin >> x;
    SegmentTree seg;
    seg.init(n, vi(n, -INF));
    vi dp(n, -INF);
    dp[0] = b[0];
    seg.modify(h[0], dp[0]);
    for (int i = 1; i < n; i++) {
        dp[i] = max({dp[i], seg.query(0, h[i] - 1) + b[i], b[i]});
        seg.modify(h[i], dp[i]);
    }
    cout << *max_element(all(dp));
}

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

using namespace std;
ll n, i,W, g[200005], v[200005], dp[200005], j;
int main()
{
    cin>>n>>W;

    for(i=1;i<=n;i++)
    {cin>>g[i]>>v[i];
    }

    for(i=1;i<=n;i++){
        for(j=W;j>=1;j--)
             if(j>=g[i])
            dp[j]=max(dp[j-g[i]]+v[i],dp[j]);


    }


cout<<dp[W];
return 0;

}


Measured memory_bytes: 3072
A, B, C, X, Y = map(int, input().split())

miab = min(X, Y)
c1 = A * X + B * Y
c2 = C * miab * 2 + A * (X - miab) + B * (Y - miab)
c3 = C * max(X, Y) * 2

print(min(c1, c2, c3))

Measured memory_bytes: 3060
//#pragma comment(linker,"/STACK:102400000,102400000")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PI 3.14159265357979823846
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

int main(){
//	freopen("C:\\Users\\wz\\Desktop\\in.txt","r",stdin);
//	freopen("C:\\Users\\wz\\Desktop\\out.txt","w",stdout);
	ios_base::sync_with_stdio(0);
    int  n;cin>>n;
    if(n/100 == n%10)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    REP(i, N) {
        cin >> A[i];
        if (A[i] == K) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    sort(A.begin(), A.end());
    if (K > A[N-1]) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    int g = A[0];
    REP(i, N) {
        g = gcd(g, A[i]);
    }
    if (K % g == 0) {
        cout << "POSSIBLE" << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;



int main() {
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  ll l=0;
  ll r=k;
  rep(i,n-k){
    if (a[r]>a[l])cout<<"Yes";
    else cout<<"No";
    l++;r++;
    cout<<endl;
  //  cout<<l<<" "<<r<<endl;
  }

}


Measured memory_bytes: 4792
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    ll ans=0;
    for(long int i=1;i<=n;i++)
    {
        if(i<=9)
        {
            ans++;
        }
        else if(i>=100 && i<=999)
        {
            ans++;
        }
        else if(i>=10000 && i<100000)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;

int n;
int in[3][100005];
int dp[3][100005];


int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  cin >>n;
  iFOR(i,1,n+1){
    FOR(j,3) cin >>in[j][i];
  }
  iFOR(i,0,n+1){
    FOR(j,3){
      dp[j][i+1]=max(dp[(j+1)%3][i],dp[(j+2)%3][i])+in[j][i+1];
    }
  }

  cout <<max(dp[0][n],max(dp[1][n],dp[2][n])) fin;

  return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define rf(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
const int N=100002;
int n;
struct data{
	int x,y;
}a[N];
map<int,int> mp;
int f[N],sz[N];
vector<int> w[N];
int b[N];

void read(int &x){
	char ch=getchar();x=0;
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
}

int gf(int x){
	return f[x]==x?x:f[x]=gf(f[x]);
}

void unio(int x,int y){
	int fx=gf(x),fy=gf(y);
	if (fx!=fy){
		f[fx]=fy;
		sz[fy]+=sz[fx];
	}
}

int main(){
	read(n);
	int xr=0;
	fr(i,1,n) read(a[i].x),xr^=a[i].x,mp[a[i].x]++;
	a[n+1].x=xr;mp[xr]++;
	int tot=0;
	/*for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	 it->second=++tot;*/
	int flag=0;
	fr(i,1,n){
		read(a[i].y);
		if (!mp.count(a[i].y)){
			printf("-1\n");
			return 0;
		}
		mp[a[i].y]--;
		if (mp[a[i].y]==0) mp.erase(a[i].y);
		if (a[i].y==xr&&a[i].x!=a[i].y) flag=1;
	}
	a[n+1].y=mp.begin()->first;
	
	//sort(a+1,a+1+n,cmp)
	mp.clear();
	fr(i,1,n+1) if (a[i].x!=a[i].y) mp[a[i].x]=1,mp[a[i].y]=1;
	tot=0;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	 it->second=++tot;
	fr(i,1,n+1) if (a[i].x!=a[i].y) a[i].x=mp[a[i].x],a[i].y=mp[a[i].y];
	//fr(i,1,n+1) if (a[i].x!=a[i].y) w[a[i].y].push_back(i);
	fr(i,1,tot) f[i]=i;
	fr(i,1,n+1) if (a[i].x!=a[i].y) sz[a[i].x]++;
	fr(i,1,n+1)
	 if (a[i].x!=a[i].y){
	 	//b[a[i].x]=1;
		unio(a[i].x,a[i].y);
	 } 
	int ans=0;
	fr(i,1,tot) if (gf(i)==i) ans+=sz[i]+1;
	if (ans==0){
		printf("0\n");
		return 0;
	}
	//cout<<ans<<endl;
	if (flag) ans-=2;
	if (flag&&a[n+1].x==a[n+1].y) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10368
def median(q):
  l = len(q)
  q = sorted(q, reverse=True)
  if l%2 == 0:
    return (q[int(l/2)] + q[int(l/2)-1])/2
  else:
    return q[int((l+1)/2-1)]
n = int(input())

a = []
b = []
for i in range(n):
  x, y = map(int, input().split())
  a.append(x)
  b.append(y)
med_a = median(a)
med_b = median(b)

if n%2 == 0:
  print(int(2*(med_b - med_a) + 1))
else:
  print((med_b - med_a) + 1)

Measured memory_bytes: 27132
N = int(input())
#not 0,9 -> 8**N
#include 0 but not 9 -> 9**N - 8**N
#include 9 but not 0 -> 9**N - 8**N
#all -> 10**N
print((10**N - (2 * 9**N - 8**N)) % (10**9 + 7))

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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int

int main()
{
  double x1,x2,y1,y2;
  cin>>x1>>y1>>x2>>y2;

  cout << fixed<<setprecision(16);
  cout << sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))<<endl;

  return 0;
}



Measured memory_bytes: 3280
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto& x : p) cin >> x;
  
  int mi = 1e9;
  int ans = 0;
  for (auto x : p) {
    ans += (x < mi);
    mi = min(mi, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, T: int, A: int, H: "List[int]"):
    d = float('inf')
    ret = 0
    for i, h in enumerate(H):
        if abs(A - (T - h * 0.006)) < d:
            ret = i
            d = abs(A - (T - h * 0.006))
    return ret + 1


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    H = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, T, A, H)
    print(result)

if __name__ == '__main__':
    main()


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

int main() {
  int A, B;
  cin >> A >> B;
  if(A < B) {
    if((B - A) % 2 == 0) {
      cout << (B - A) / 2 + A << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  } else {
    if((A - B) % 2 == 0) {
      cout << (A - B) / 2 + B << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)1e10
int dp[100001];
int32_t main()
{
    int N,W; 
   cin >> N>>W;
      int price[N],wt[N];

   for(int i=0;i<N;i++)
   {
       cin>> wt[i] >> price[i];
   }
   	for(int i=0;i<100001;i++)dp[i]=inf;
       dp[0]=0;
   for(int i=0;i<N;i++)
   {
      for(int j=100000-price[i];j>=0;j--)
      {
         dp[j+price[i]] = min(dp[j+price[i]],dp[j]+wt[i]);
      }
   }
   
   for(int i=100000;i>=0;i--)
   {
       if(dp[i]<=W)
       {
           cout<<i;
           break;
       }
   }

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){

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

}
for(int i = 0 ; i<n ; i++)
{
    if(a[i]%2==0){
   c++;
        if(a[i]%3==0 || a[i]%5 == 0) d++;

    }
}
if(c==d)cout<<"APPROVED";
else cout<<"DENIED";
return 0 ;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

    int h,w;
    cin >> h >> w;
    vector<string> s(h);

    for(int i = 0 ; i < h ; i++){
        cin >> s.at(i);
    }

    vector<vector<int>> cnt(h, vector<int>(w));

    for(int i = 0 ; i < h ; i++){
        vector<int> done(w);
        for(int j = 0 ; j < w ; j++){
            if(s.at(i).at(j) == '#'){
                continue;
            }
            if(done.at(j)){
                continue;
            }
            int l = 0;
            while((j+l) < w){
                if(s.at(i).at(j+l) == '#'){
                    break;
                }
                l++;
            }
            for(int k = 0 ; k < l ; k++){
                cnt.at(i).at(j+k) += l;
                done.at(j+k) = 1;
            }
        }
    }

    for(int j = 0 ; j < w ; j++){
        vector<int> done(h);
        for(int i = 0 ; i < h ; i++){
            if(s.at(i).at(j) == '#'){
                continue;
            }
            if(done.at(i)){
                continue;
            }
            int l = 0;
            while((i+l) < h){
                if(s.at(i+l).at(j) == '#'){
                    break;
                }
                l++;
            }
            for(int k = 0 ; k < l ; k++){
                cnt.at(i+k).at(j) += l;
                done.at(i+k) = 1;
            }
        }
    }

    int ans = 0;
    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++){
            ans = max(ans,cnt.at(i).at(j)-1);
        }
    }
    cout << ans << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(b<a) {
  swap(b,a);
  }
  if(c<a) {
      swap(c,a);
  }
  if(c<b) {
      swap(c,b);
  }
  cout << a << ' ' << b << ' ' << c << endl;
}


Measured memory_bytes: 3096
import math
import fractions
a,b,c,d = map(int, input().split())
e = a-1
less_than_e = e - (e//c) - (e//d) + (e//(c*d//fractions.gcd(c,d)))
less_than_b = b - (b//c) - (b//d) + (b//(c*d//fractions.gcd(c,d)))
if less_than_e < 0:
    less_than_e = 0
print(less_than_b - less_than_e)

Measured memory_bytes: 5048
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    string[] ss;
    for (int i = 0; i < n; i++) {
        ss ~= read!string;
    }

    char[] ans;
    foreach (c; 'a'..'z'+1) {
        int cnt = int.max;
        foreach (s; ss) {
            cnt = min(cnt, s.count!(e => e == c));
            if (cnt == 0) break;
        }

        if (cnt > 0) {
            ans ~= repeat(cast(char) c, cnt).array;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 256