akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<char>a(n);
    rep(i,4){
        if(i/2==0) a[0]='S';
        else a[0]='W';
        if(i%2==0) a[1]='S';
        else a[1]='W';
        repi(j,2,n){
            if(s[j-1]=='o'){
                if(a[j-1]=='S') a[j]=a[j-2];
                else a[j]=(a[j-2]=='S' ?'W' :'S');
            }else{
                if(a[j-1]=='S') a[j]=(a[j-2]=='S' ?'W' :'S');
                else a[j]=a[j-2];
            }
        }
        if((s[n-1]=='o'&&a[n-1]=='S')||(s[n-1]=='x'&&a[n-1]=='W')){
            if(a[n-2]!=a[0]) continue;
        }else{
            if(a[n-2]==a[0]) continue;
        }
        if((s[0]=='o'&&a[0]=='S')||(s[0]=='x'&&a[0]=='W')){
            if(a[n-1]!=a[1]) continue;
        }else{
            if(a[n-1]==a[1]) continue;
        }
        rep(i, a.size() - 1) cout << a[i];
        cout << a[a.size()-1] << endl;
        return 0;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
struct point{
	double x,y,c,r;
}p[maxn],p1[maxn];
int n,k,tot;
int sgn(double x)
{
	if(fabs(x)<ep)return 0;
	if(x>0)return 1;return -1;
}
inline double len2(point a,point b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline void getCircleIntersection(point a,point b)
{
	double ab,ae,h;
	ab=len2(a,b);//圆心距
	if(sgn(ab)==0)return;//同心圆
	ae=(a.r*a.r-b.r*b.r+ab)/2;
	h=ab*a.r*a.r-ae*ae;
	if(h<0)return;
	h=sqrt(h);
	p1[++tot].x=a.x+ae*(b.x-a.x)/ab-(b.y-a.y)*h/ab;
	p1[tot].y=a.y+ae*(b.y-a.y)/ab+(b.x-a.x)*h/ab;
	p1[++tot].x=a.x+ae*(b.x-a.x)/ab+(b.y-a.y)*h/ab;
	p1[tot].y=a.y+ae*(b.y-a.y)/ab-(b.x-a.x)*h/ab;
}
inline bool solve(double r)
{
	for(int i=1;i<=n;i++)p[i].r=r/p[i].c;
	for(int i=1;i<=n;i++)
	{
		p1[++tot].x=p[i].x,p1[tot].y=p[i].y;
		for(int j=1;j<i;j++)getCircleIntersection(p[i],p[j]);
	}
	for(int i=1;i<=tot;i++)
	{
		int sum=0;
		for(int j=1;j<=n;j++)
		{
			if(sgn(sqrt(len2(p1[i],p[j]))*p[j].c-r)<=0)sum++;
		}
		if(sum>=k)return 1;
	}
	return 0;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].c);
	double l=0,r=100000000;
	while(sgn(l-r)<0)
	{
		tot=0;
		double mid=(l+r)/2;
		if(solve(mid))r=mid;
		else l=mid;
	}
	printf("%f\n",r);
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>


using namespace std;


int main() {
	int tab[3];
	cin >> tab[0] >> tab[1] >> tab[2];
	sort(tab, tab + 3);
	cout << tab[2] * 10 + tab[1] + tab[0] << endl;

	return 0;
}

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

int main(void) {
    int a;
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a;
    cin >> s;
    cout << (a < 3200? "red" : s) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> r(n, 0), c(n, 1);
    r[0] = 1;
    while (m--) {
        int x, y; cin >> x >> y;
        x--; y--;
        if (r[x] > 0)
            if (c[x] > 1) r[y] = 1;
            else r[x] = 0, r[y] = 1;
        c[x]--; c[y]++;
    }
    cout << accumulate(r.begin(), r.end(), 0) << endl;
}


Measured memory_bytes: 1024
# frozen_string_literal: true

n, Q = gets.split.map(&:to_i)
ab = (n - 1).times.map { gets.split.map { |e| e.to_i - 1 } }.sort_by { |e| e[0] }
px = Q.times.map { gets.split.map(&:to_i) }

s = Array.new(n) { 0 }

px.each do |e|
  p = e[0]
  x = e[1]
  s[p - 1] += x
end

d = Array.new(n) { false }
h = Hash.new { [] }
ab.each do |e|
  a = e[0]
  b = e[1]
  unless h[a].empty?
    h[a].push b
  else
    h[a] = [b]
  end
  unless h[b].empty?
    h[b].push a
  else
    h[b] = [a]
  end
end

q = []

q.push 0

loop do
  break if q.empty?

  a = q.shift
  d[a] = true
  h[a].each do |b|
    next if d[b]

    s[b] += s[a]
    q.push b
  end
end

puts s.join(' ')


Measured memory_bytes: 66468
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

if ki[0][0] == gu[0][0] :
    if len(ki) == 1 and len(gu) == 1 :
        print(int(n/2))
    else :
        if ki[1][1] > gu[1][1] :
            print(n-ki[1][1]-gu[0][1])
        else :
            print(n-ki[0][1]- gu[1][1])

else :
    print(n-ki[0][1]-gu[0][1])

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int a,b; cin >> a >> b;
  if((a*b)&1) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define all(x) x.begin(),x.end()
#define rep(i, n) for (Int i=0;i<(Int)(n);i++)
#define repd(i, n) for (Int i=n-1;i>=0;i++)
#define dcout(d) cout << fixed << setprecision(15) << d //dcout(d) << endl;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1 << 29)
#define LINF (1LL << 60)
#define PI 3.1415926535897932384626433832795028
#define itn int
typedef long long Int;
typedef unsigned long long uInt;

int main(){
	int a;
	cin >> a;
	rep(i,a) cout << "ACL";
	cout << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#define int long long
using namespace std;

int n;
int s, d;

int ans;
void dfs( int now, int ed, int dep ) {
	//cout << now << " " << ed << " " << dep << endl;
	if( dep >= ans )
		return;
	if( now == ed ) {
		ans = dep;
		return;
	}
	int maxd = now & -now;
	
	for( ; now + maxd > ed; maxd /= 2);
	dfs( now + maxd, ed, dep+1 );
}

signed main() {
	int i;
	cin >> n;
	for( i = 0; i < n; i++ ) {
		cin >> s >> d;
		s += ((int)1 << (40));
		d += ((int)1 << (40));
		ans = 100;
		dfs(s, d, 0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <algorithm>
int n, k, s;
int main() {
	scanf("%d%d%d", &n, &k, &s);
	if (s != 1000000000) {
		for (int i = 0; i < n; i++) {
			if (i < k)printf("%d", s);
			else printf("%d", s + 1);
			if (i < n - 1)printf(" ");
			else printf("\n");
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			if (i < k)printf("%d", s);
			else printf("1");
			if (i < n - 1)printf(" ");
			else printf("\n");
		}
	}
}

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

using namespace std;

int main()
{
    long long int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    long long int p[a],q[b],r[c],i=0,sum=0,ans[x+y+c],j=a-1,k=0;
    for(i=0;i<a;i++)
        cin>>p[i];
    for(i=0;i<b;i++)
        cin>>q[i];
    for(i=0;i<c;i++)
        cin>>r[i];
    sort(p,p+a);
    sort(q,q+b);
    for(i=0;i<c;i++)
        ans[i]=r[i];
    for(i=c;k<x;i++){
        ans[i]=p[j];
        j--;
        k++;
    }
    k=0;
    j=b-1;
    for(i=c+x;k<y;i++)
    {
        ans[i]=q[j];
        j--;
        k++;
    }
    sort(ans,ans+(x+y+c));
    for(i=c;i<x+y+c;i++)
        sum=sum+ans[i];
    cout<<sum;
    return 0;
}


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

#define MOD 1000000007
typedef long long ll;

#define rep(i, n) for(i=0;i<(int)(n);i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define bit(n) (1LL<<(n))
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int kou[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(void){
  int n;
  scanf("%d", &n);
  printf("%d", kou[n-1]);
  
  return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N, M;
	cin >> N >> M;
	ll X;
	cin >> X;
	vl C(N);
	vector<vl> A(N);
	ll ans = InfLL;
	rep(i, N) {
		cin >> C[i];
		A[i].resize(M);
		rep(j, M) {
			cin >> A[i][j];
		}
	}
	ll N2 = 1;
	rep(i, N)N2 *= 2;
	rep(b, N2) {
		bool can = 1;
		ll Csum = 0;
		vl Asum(M);
		rep(i, N) {
			if ((b >> i) % 2) {
				Csum += C[i];
				rep(j, M) {
					Asum[j] += A[i][j];
				}
			}
		}
		rep(j, M) {
			can &= (Asum[j] >= X);
		}
		if (can)
			ans = min(ans, Csum);
	}
	if (ans == InfLL)
		ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    d = {}
    for i in a:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    s = sum(a)
    q = int(input())
    for i in range(q):
        b, c = map(int, input().split())
        if b in d:
            s = s + (c - b) * d[b]
            if c in d:
                d[c] += d[b]
            else:
                d[c] = d[b]
            d[b] = 0
        print(s)


main()

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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll>h(n);
  rep(i,n) cin >>h[i];
  sort(h.begin(),h.end(),greater<ll>());
  
  ll ans=0;
  if(n<=k){
    cout << ans << endl;
    return 0;
  }
  rep(i,n){
    if(i<k) continue;
    else ans+=h[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    X, K, D = map(int, readline().split())
    X = abs(X)
    if X // D >= K:
        ans = X - D * K
    else:
        if (K - X // D) % 2 == 0:
            ans = X - X // D * D
        else:
            ans = abs(X - X // D * D - D)


    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << a+b+c-max(max(a,b),c) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int n, i, j, k;
    char string[101];

    scanf("%d", &n);

    scanf(" %[^\n]", string);
    if(n%2 != 0)
    {
        printf("No\n");
        return 0;
    }
    char copy1[n], copy2[n];
    for(i=0, j=0, k=0; string[i]!='\0' ; i++)
    {
        if(i<n/2)
        {
            copy1[j] = string[i];
            j++;
        }

        else
        {
            copy2[k] = string[i];
            k++;
        }

    }
    copy1[j] = '\0';
    copy2[k] = '\0';

    if(strcmp(copy1,copy2) == 0)
    {
        printf("Yes\n");
    }
    else
        printf("No\n");

    return 0;

}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
private static Scanner s = new Scanner(System.in);
static int n = s.nextInt();
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
int[] a = new int[n+1];

for(int i = 1;i < n+1;i++) {
a[i] = s.nextInt();
}
buildMaxHeap(a);

for(int i = 1;i < n+1;i++) {
sb.append(" " + a[i]);
}
System.out.println(sb);
}

static void maxHeapify(int[] a,int i) {
	int l = i*2;
	int r = i*2+1;
	int larg = 0;
	if(l <= n && a[l] > a[i]) {
		larg = l;
	}else {
		larg = i;
	}
	if(r <= n && a[r] > a[larg]) {
		larg = r;
	}
	if(larg != i) {
		int tmp = a[i];
		a[i] = a[larg];
		a[larg] = tmp;
	maxHeapify(a,larg);
	}
}

static void buildMaxHeap(int[] a) {
for(int i = n/2;i > 0;i--) {
	maxHeapify(a,i);
}
}
}



Measured memory_bytes: 166092
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L=[]
for _ in range(M):
    L.append(list(map(int, input().split())))

cost=[]
for i in range(M):
    cost.append(a[L[i][0]-1]+b[L[i][1]-1]-L[i][2])

cost.append(min(a)+min(b))
print(min(cost))

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

int main() {
  string s;
  cin>>s;
  s.erase(s.size()-1);
  while(s.size()>0){
    if(s.size()%2==0){
      if(s.substr(0,s.size()/2)==s.substr(s.size()/2,s.size()/2)){
        cout<<s.size()<<endl;
        return 0;
      }
    }
    s.erase(s.size()-1);
  }
}

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

int machi;
int jigoku;
int d[1002];
int tsu[1002];
int a[1002][1002];
int main(){
	cin >> machi >> jigoku;
	for (int i = 0; i < machi; i++){
		cin >> d[i];
	}
	for (int j = 0; j < jigoku; j++){
		cin >> tsu[j];
	}
	for (int i = 0; i < machi+1; i++){
		for (int j = 0; j < jigoku+1; j++){
			a[i][j] = 10000000000;
			a[1][1] = d[0] * tsu[0];
		}
	}
	for (int i = 0; i < machi; i++){
		for (int j = i; j < jigoku; j++){
		if(i==0){a[i + 1][j + 1] = min(d[i] * tsu[j], a[i + 1][j]);
		}else{
			a[i + 1][j + 1] = min(a[i][j] + d[i] * tsu[j], a[i + 1][j]);
		}
		
		}
	}
	cout << a[machi][jigoku] << endl;
	return 0;
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

struct hist {
	int x, y, dir; pii dist;
	bool operator<(const hist& h) const {
		return dist > h.dist;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int h, w, k; read(h, w, k);
	vector<string> mp(h);

	int x1, y1, x2, y2; read(x1, y1, x2, y2);
	--x1; --y1; --x2; --y2;

	rep(i, 0, h) read(mp[i]);

	const int inf = 0x3f3f3f3f;
	vector<vector<vector<pii>>> mindist(h, vector<vector<pii>>(w, vector<pii>(4, {inf, 0})));
	rep(i, 0, 4) mindist[x1][y1][i] = {1, 0};

	priority_queue<hist> pq;
	rep(i, 0, 4) pq.push({ x1, y1, i, {1, 0} });

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

	while (!pq.empty()) {
		hist hh = pq.top(); pq.pop();
		if (hh.dist > mindist[hh.x][hh.y][hh.dir]) continue;
		rep(i, 0, 4) {
			int xx = hh.x + dx[i], yy = hh.y + dy[i];
			if (!(0 <= xx && xx < h && 0 <= yy && yy < w && mp[xx][yy] == '.'))
				continue;

			pii nd;
			if (hh.dist.second < k && i == hh.dir) nd = { hh.dist.first, hh.dist.second + 1};
			else nd = {hh.dist.first + 1, 1};
			
			if (chmin(mindist[xx][yy][i], nd)) {
				pq.push({ xx, yy, i, mindist[xx][yy][i] });
			}
		}
	}

	pii ans = {inf, 0};
	rep(i, 0, 4) chmin(ans, mindist[x2][y2][i]);
	die(ans.first == inf ? -1 : ans.first);
}



Measured memory_bytes: 144984
#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;

int main(int argc, char* argv[]){
  int n;
  cin >> n;
  double a[1000];
  double top = 1;
  double bot = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    top *= a[i];
  }
  for(int i = 0; i < n; i++){
    bot += top/a[i];
  }
  printf("%.7lf\n", top/bot);
}


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

int GetDigit(int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
  long long int N,A;
  cin >> N;
  A = sqrt(N);
  for(int i=A; i>0; i--){
    if(N%i==0){
     cout << GetDigit(N/i) << endl;
      return 0;
  }
  }
}



Measured memory_bytes: 256
from math import * 
import sys
from collections import *
input = sys.stdin.readline

def main():
    N, D, A = list(map(int, input().split()))
    XH = sorted([list(map(int, input().split())) for i in range(N)])

    t = 0
    q = deque([])
    
    ans = 0
    for X, H in XH:
        while q and q[0][0] < X-D:
            x, c = q.popleft()
            
            t -= c
        H -= A * t
        
        if H <= 0: continue 

        c = ceil(H/A)
        ans += c
        q.append((X+D, c))
        t += c   
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 65616
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  k <- getInt
  s <- getLine

  let r = if length s <= k
          then s
          else take k s ++ "..."

  putStrLn r


Measured memory_bytes: 3792
module Main where

import Control.Applicative
import Numeric
import Data.Char

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [n] <- getIntegers
  ; if n == 0 then return ()
    else do
      { print (sum (map digitToInt (show n)))
      ; loop
      }
  }


--

getIntegers :: IO [Integer]
getIntegers = map read . words <$> getLine

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles =map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



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

int gcd(int x, int y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

int main() {
  lint N,X,y; cin >> N >> X;
  vector<lint> x(N,0);
  for(lint i=0;i < N;i++) { cin >> y; x[i] = abs(y-X); }

  int d=x[0];
  for(lint i=1;i<N && d!=1;i++) { d = gcd(x[i],d); }

  cout << d << endl;
  return 0;
}

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

int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n) cin>> a[i];
    sort(a.begin(),a.end());
    auto itr = a.begin();
    while(itr!=a.end()){
        if(a[n-2]==0) break;
        for(auto it = itr+1;it != a.end();it++){
            *it %= *itr;
        }
        sort(itr,a.end());
        itr = upper_bound(itr,a.end(),0);
    }
    cout << *upper_bound(a.begin(),a.end(),0) << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#define N_MAX 200000
#define RT_MAX 1000000000

int main(){
  int i,j,n,R[N_MAX],max=-RT_MAX,db;
  int ma=-RT_MAX,mi,d;
  scanf("%d",&n);
  if(n>N_MAX || n<2)exit(8);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
    if(R[i]>RT_MAX || R[i]<1)exit(8);
  }
  /*
  for(i=n-1;i>0;i--){
    for(j=i-1;j>=0;j--){
      db=R[i]-R[j];
      if(db>max)max=db;
    }
  }
  */
  mi=R[0];
  for(j=1;j<n;j++){
    d=R[j]-mi;
    if(d>ma)ma=d;
    if(R[j]<mi)mi=R[j];
  }
  max=ma;
  printf("%d\n",max);
  return 0;
}



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

int main(){
  string S;
  cin >> S;
  int N=S.size();
  vector<int> left(N+1),right(N+1);
  left.front()=0;
  right.back()=0;
  for(int i=1;i<N+1;i++){
    if(S.at(i-1)=='<'){
      left.at(i)=left.at(i-1)+1;
    }else{
      left.at(i)=0;
    }
  }
  for(int i=N-1;i>=0;i--){
    if(S.at(i)=='>'){
      right.at(i)=right.at(i+1)+1;
    }else{
      right.at(i)=0;
    }
  }
  int64_t ans=0;
  for(int i=0;i<N+1;i++){
    ans+=max(left.at(i),right.at(i));
  }
  cout << ans << endl;
  return 0;
}


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

string S;

int main(){

    cin >> S;

    int size = S.size();
    int i, cnt_tmp = 0, cnt = 0;
    for (i=0; i<size; i++){
        if ((S.at(i) == 'A') || (S.at(i) == 'C') || (S.at(i) == 'G') || (S.at(i) == 'T')){
            cnt_tmp++;
        }
        else{
            cnt_tmp = 0;
        }
        cnt = max(cnt, cnt_tmp);
    }

    cout << cnt << endl;
    return 0;
}

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

#define dbg(a)	cerr << __LINE__ << ": " << #a << " = " << a << '\n'

int main(){
	int n;	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			for (int k = 0; k < n; ++k){
				ans += __gcd(i+1, __gcd(j+1, k+1));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
n = int(input())

l = []
l.append([0, 0, 0])
for _ in range(n): l.append(list(map(int, input().split())))

for i in range(n):
  t = abs(l[i][1] - l[i+1][1]) + abs(l[i][2] - l[i+1][2])
  s = l[i+1][0] - l[i][0]
  if t > s or t%2 != s%2:
    print("No")
    exit()
print("Yes")

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

using namespace std;

int main() {
    int n;
    float t, a;
    cin >> n >> t >> a;
    vector<float> h(n);
    for(int i = 0; i < n; i++) {
        float x;
        cin >> x;
        h[i] = x;
    }

    vector<float> temp(n);
    vector<float> cal(n);
    vector<pair<float, int>>ans(n);
    for(int i = 0; i < n; i++) {
        temp[i] = t - h[i] * 0.006;
        cal[i] = abs(a - temp[i]);
        ans[i] = make_pair(cal[i], i+1);
  }
  
  sort(ans.begin(), ans.end());
  cout << ans[0].second << endl;
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

ll N;

ll X[50];
ll Y[50];

ld distance(ld x1, ld y1, ld x2, ld y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

ld f(ld x, ld y) {
    ld maxn = -1.0;
    rep(i,N) {
        maxn = max(maxn, distance(x, y, X[i], Y[i]));
    }
    return maxn;
}

// xはfix
ld g(ld x) {
    ld lhs = 0.0;
    ld rhs = 2000.0;
    rep(i,300) {
        ld y1 = (lhs * 2 + rhs) / 3.0;
        ld y2 = (lhs + rhs * 2) / 3.0;
        if(f(x,y1)>f(x,y2)) lhs = y1;
        else rhs = y2;
    }
    return f(x, (lhs+rhs)/2.0);
}

ld h() {
    ld lhs = 0.0;
    ld rhs = 2000.0;
    rep(i,300) {
        ld x1 = (lhs * 2 + rhs) / 3.0;
        ld x2 = (lhs + rhs * 2) / 3.0;
        if(g(x1) > g(x2)) lhs = x1;
        else rhs = x2;
    }
    return g((lhs+rhs)/2.0);
}

int main() {
    cin >> N;
    rep(i,N) {
        cin >> X[i] >> Y[i];
    }
    cout << fixed;
    cout << setprecision(8) << h() << endl;
    return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_ls(num):
    return reduce(lcm, num, 1)

n = int(input())
ls = [int(input()) for _ in range(n)]

print(lcm_ls(ls))

Measured memory_bytes: 5332
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll s, t;
	cin >> s >> t;
	ll ans = 0;
	ll cnt = 1;
	while (cnt < t) {
		ans++;
		cnt += s - 1;
	}

	dump(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const int MOD = (int)1e9+7;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;

const int MAX_N = 200050;
int n;
int a[MAX_N];
int b[MAX_N];

int main(void) {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	rep(i,1,n+1) {
		cin >> a[i];
	}
	per(i,1,n+1) {
		b[i] = a[i];
		for(int j = 2; i*j <= n; ++j) {
			b[i] += b[i*j];
		}
		b[i] %= 2;
	}
	vi ret;
	rep(i,1,n+1) {
		if(b[i] == 1) {
			ret.pb(i);
		}
	}
	cout << sz(ret) << endl;
	rep(i,0,sz(ret)) {
		cout << ret[i] << ' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3320
#include<stdio.h>
int main(void){
	int N,a,b,c,i;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d %d",&a,&b,&c);
		a=a*a;
		b=b*b;
		c=c*c;
		if(a+b==c||a+c==b||b+c==a){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2040
#include <iostream>  
#include <algorithm> 
#include <string> 
#include <cstdlib>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int max = a;
  if(b > max){
    max = b;
  }
  if(c > max){
    max = c;
  }
  cout << a+b+c-max << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#define N 20
#define Q 2000

int solve(int , int , int*, int );

/*
How to test
% diff <(./a.out < b1in.txt) <(cat b1out.txt) 

  for( i=0 ; i < n ; i++){
    fprintf(stderr, "%d: C2[%d] = %c%c \n" ,__LINE__ ,i ,C2[i].suit ,C2[i].value );
  }

 */
int main(){
  int i,j;
  int res;
  int nmax;
  int n[N];
  int qmax;
  int q[Q];

  scanf("%d", &nmax);
  for ( i = 0; i < nmax; i++ ) scanf("%d", &n[i]);
  scanf("%d", &qmax);
  for ( i = 0; i < qmax; i++ ) scanf("%d", &q[i]);

  for( i =0 ; i < qmax ; i++){
    res = solve(0, q[i], n, nmax);
    if(res == -1 ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }


  return 0; // Don't forget return 0
}

int solve(int i, int m, int* a_p, int n ){
  int res, r1 ,r2;

  if( m == 0){
    return -1; // true
  }
  if( i >= n){
    return -2; // false
  }

  //fprintf(stderr, "%d: i=%d m=%d n=%d a_p[i]=%d " ,__LINE__ ,i ,m ,n ,a_p[i]);
  r1 = solve(i+1, m,          a_p, n);
  r2 = solve(i+1, m - a_p[i], a_p, n);
  if(r1 == -1 || r2 == -1 ){
    res = -1;
  }else{
    res = -2;
  }

  return res;
}

Measured memory_bytes: 588
using System;
using System.Linq;
using static System.Console;

class AtCoder
{
  public static void Main()
  {
    var raw = ReadLine().Split().Select(int.Parse).ToArray();
    var N = raw[0];
    var A = raw[1];
    var B = raw[2];

    WriteLine(Math.Min(A * N, B));
  }
}


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

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

int main(){
    
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	string s, t,u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (u==s) {
		cout << a - 1<<" "<<b << endl;
	}
	else {
		cout << a <<" "<< b-1 << endl;
	}
}

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

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  ans = 0
  for i in range(200):
    if i in p:
      continue
    else:
      dis = i - X
      if dis < abs(ans - X):
        ans = i

print(ans)

Measured memory_bytes: 61540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

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




int n;
ll k;
vector<int> a, b;
int z;

ll calc(vector<int> c, ll x) {
  ll ret = 0;
  rep(i, sz(c)) {
    // 以下にしたい
    int it;
    if (x % c[i] == 0) {
      it = ub(c, x / c[i]);
      it--; // 以下すべて
    } else {
      it = ub(c, x / c[i]);
      it--;
    }
    if (it >= i) ret--;
    ret += it + 1;
    // cout << "ret " << ret << endl;
  }
  // cout << ret << endl;
  return ret;
}

bool check(ll x) { // 積が x 以下の何個?
  ll ret = 0;

  if (x >= 0) { //負, 0 全部
    ret += 1LL * sz(a) * sz(b);
    ret += 1LL * z * (sz(a) + sz(b));
    ret += 1LL * z * (z - 1) / 2;
  }

  if (x < 0) {
    // 値としては以上
    ll y = -x;
    rep(i, sz(a)) {
      int it;
      if (y % a[i] == 0) {
        it = lb(b, y / a[i]);
      } else {
        it = ub(b, y / a[i]);
      }
      ret += sz(b) - it;
    }
  } else if (x > 0) { // 正
    ll tmp = 0;
    tmp += calc(a, x);
    tmp += calc(b, x);
    tmp /= 2;
    ret += tmp;
  }
  // cout << ret << endl;
  if (ret >= k) return 1;
  return 0;
}

template<typename T>
void binary_search(T ok, T ng) {
  while (abs(ng - ok) > 1) {
      T mid = (ng + ok) / 2;
      // cout << ok << " " << mid << " " << ng << endl;
      (check(mid) ? ok : ng) = mid;
  }
  cout << ok << endl;
}

void solve() {
  cin >> n >> k;

  rep(i, n) {
    int A;
    cin >> A;
    if (A > 0) a.eb(A);
    else if (A < 0) b.eb(-A);
    else z++;
  }
  sort(all(a));
  sort(all(b));

  binary_search(INF, -INF);

}


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

ll c,d;

ll gcd(ll x, ll y){
    ll z;
    while(y>0){
        z=x;
        x=y;
        y=z%x;
    }
    return x;
}

ll f(ll x){
    ll c1=x/c, c2=x/d, c12=x/(c*d/gcd(c,d));
    return x-(c1+c2-c12);
}

int main(){
    ll a,b; cin >> a >> b >> c >> d;
    cout << f(b)-f(a-1) << endl;
}

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

using namespace std;

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

  vector<long long> A(N);

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }

  vector<int> table(1000006, 0);
  for (int i = 0; i < N; i++) {
    if (table[A[i]] >= 2) {
      continue;
    }
    for (int j = A[i]; j <= 1000000; j += A[i]) {
      table[j]++;
    }
  }
  int ans = 0;
  for (auto a : A) {
    if (table[a] == 1) {
      ans++;
    }
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 8804
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt();
        }

        int min = P[0];

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] <= min) {
                ans++;
            }
            min = Math.min(min, P[i]);
        }

        System.out.println(ans);
    }
}

// 4 2 5 1 3


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

int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a%b);
}
int main() {
	int w, h, c; scanf("%d%d%d", &w, &h, &c);
	int g = gcd(w, h);
	printf("%d\n", (w / g)*(h / g)*c);
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif


ll N, K;

bool f(vector<ll> &A, vector<ll> &F, ll x) {
    ll remain = K;
    rep(i, N) {
        if (A[i] * F[i] > x) {
            remain -= (A[i] * F[i] - x + F[i] - 1) / F[i];
            if (remain < 0) {
                return false;
            }
        }
    }
    return true;
}

void Main() {
    cin >> N >> K;
    vector<ll> A(N), F(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll ok = A[N - 1] * F[0];
    ll ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (f(A, F, mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int d,n;
int hot[512];
int a[512],b[512],c[512];
int dp[512][512];
int main(){
    scanf("%d%d",&d,&n);
    rep(i,d)scanf("%d",&hot[i]);
    rep(i,n)scanf("%d%d%d",&a[i],&b[i],&c[i]);

    memset(dp,-1,sizeof(dp));
    rep(i,n)if(a[i] <= hot[0] &&hot[0] <= b[i])dp[1][c[i]] = 0;

    reps(i,1,d){
        rep(j,256){
            if(dp[i][j] != -1){
                rep(k,n){
                    if(a[k] <= hot[i] && hot[i] <=b[k]){
                        dp[i+1][c[k]] = max(dp[i+1][c[k]],dp[i][j]+abs(c[k]-j));
                    }
                }
            }
        }
    }
    int ans = 0;
    rep(i,256)ans = max(ans,dp[d][i]);
    printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2228
using System;
using System.Collections.Generic;

namespace ABC085
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            var N = int.Parse(input[0]);
            var Y = int.Parse(input[1]);

            var oneCount = Y / 1000;
            var end = false;
            var visited = new bool[2010, 2010];
                
            Action<int, int, int> dfs = null;
            dfs = (one, five, ten) =>
            {
                if (end || one < 0 || five > 2000 || one + five + ten < N || visited[five, ten]) return;
                visited[five, ten] = true;

                if (one + five + ten == N)
                {
                    Console.WriteLine($"{ten} {five} {one}");
                    end = true;
                    return;
                }
                dfs(one - 5, five + 1, ten);
                dfs(one - 10, five, ten + 1);
            };

            dfs(oneCount, 0, 0);
            if (!end) Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 17120
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int b[] = new int[a];
        int ans = 0;
        int i;
        for(i = 0;i < a;i++){
          b[i] = sc.nextInt();
          if((i + 1) % 2 == 1 && b[i] % 2 == 1){
            ans += 1;
          }
        }
        
      	System.out.println(ans);
 
    }
}

Measured memory_bytes: 35696
import sys

n, m = map(int, sys.stdin.readline().split())

root = list(range(n))
height = [0] * n
size = [1] * n

def find_root(u):
  if root[u] == u: return u
  root[u] = find_root(root[u])
  return root[u]

def unite(u, v):
  ru = find_root(u)
  rv = find_root(v)
  if ru == rv: return
  if height[ru] >= height[rv]:
    root[rv] = ru
    size[ru] += size[rv]
    height[ru] = max(height[ru], height[rv] + 1)
  else:
    root[ru] = rv
    size[rv] += size[ru]

def main():
  for _ in range(m):
    x, y, z = map(int, sys.stdin.readline().split())
    unite(x-1, y-1)
  
  for i in range(n): find_root(i)
  print(len(set(root)))
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 14700
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <queue>

using namespace std;



int main() {
  //
  int MAX_N = 100, MAX_V = 1000;
  long long N, W;
  cin >> N >> W;
  vector<long long> w(N), v(N);

  long long v_sum = 0, w_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
    v_sum += v[i];
    w_sum += w[i];
  }

  // table[i][j]はi番目までのアイテムを使いv_sum以上の合計値の時の最小の重さ
  const long long INF = 1LL<<50;
  vector<vector<long long>> table(N+1, vector<long long>(v_sum+1, INF));
  table[0][0] = 0;
//  for (int i = 0; i < N; ++i) {
//    table[i][0] = 0;
//  }
//  for (int j = 0; j < v_sum; ++j) {
//    table[0][j] = 0;
//  }

  for (int i = 0; i < N; ++i) {
//    cout << i << " v[i] = " << v[i] << endl;

    for (int j = 0; j <= v_sum; ++j) {
      if(j < v[i]){
        table[i+1][j] = table[i][j];

      }else{
        table[i+1][j] = min(table[i][j], table[i][j-v[i]] + w[i]);
//        cout << table[i][j] << " " << table[i][j-v[i]] + w[i] << endl;

      }
    }
  }

//  (table[i-1][j-v[i]] + w[i]) <= W

//  for (int i = 0; i <= N; ++i) {
//    for (int j = 0; j <= v_sum; ++j) {
//      cout << table[i][j] <<  " ";
//    }
//    cout << endl;
//  }


  // 最適値の出力
  long long res = 0;
  for (int sum_v = 0; sum_v <= v_sum; ++sum_v) {
    if (table[N][sum_v] <= W) res = sum_v;
  }
  cout << res << endl;

//  cout << table[N][v_sum] << endl;

  return 0;
}




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

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    char op;
    int a,b;
    cin >> a >> op >> b;
    if(op=='+') cout << ll(a+b)<< endl;
    else cout << a-b << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<double> P(N);
  for(int i = 0; i < N; ++i) cin >> P[i];
  vector<double> dp(N+1,0);
  dp[0] = 1;
  for(int i = 0; i < N; ++i){
    vector<double> dp_(N+1,0);
    for(int j = 0; j <= N; ++j){
      dp_[j] += dp[j]*(1-P[i]);
      if(j < N)
        dp_[j+1] += dp[j]*P[i];
    }
    dp = dp_;
  }
  double ans = 0;
  for(int i = N/2+1; i <= N; ++i) ans += dp[i];
  printf("%.12f\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
//#include <pair>
#include <map>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c * x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!= ) cerr << boolalpha << i; ris;
}
eni(== ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


const double pi = 3.141592653589793238462643383279502884197169399;
typedef long long ll;

void solve() {
	double r;
	cin >> r;
	cout << 2 * pi * r << endl;
}

	



int main() {
	cout << fixed << setprecision(20) << endl;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("test.txt", "r", stdin);

	solve();
	return 0; 
}

Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int inf = 1e9;

typedef long long int lli;
typedef vector<vector<lli> > Matrix;
bool mul(Matrix &a, Matrix &b, Matrix &c){ //A*B=C
	if(a[0].size() != b.size()) return false;
	int n = a.size();
	int m = b.size();
	int l = b[0].size();
	Matrix ret(n, vector<lli>(l,0));
	for(int i=0; i<n; i++){
		for(int j=0; j<l; j++){
			for(int k=0; k<m; k++){
				ret[i][j] += a[i][k]*b[k][j];
			}
		}
	}
	c = ret;
	return true;
}

int main(){
	while(1){
		int n,m,a,b,c,t;
		cin >> n >> m >> a >> b >> c >> t;
		if(n==0) break;
		
		Matrix ini(n, vector<lli>(1));
		for(int i=0; i<n; i++){
			cin >> ini[i][0];
		}
		
		Matrix r(n, vector<lli>(n));
		Matrix mat(n, vector<lli>(n, 0));
		for(int i=0; i<n; i++){
			r[i][i] = b;
			mat[i][i]=1;
			if(i!=0) r[i][i-1] = a;
			if(i!=n-1) r[i][i+1] = c;
		}
		for(int i=log2(t); i>=0; i--){
			mul(mat, mat, mat);
			if((t&1<<i) != 0){
				mul(mat, r, mat);
			}
			for(int j=0; j<n; j++){
				for(int k=0; k<n; k++){
					mat[j][k] = mat[j][k]%m;
				}
			}
		}
		
		mul(mat, ini, ini);
		for(int i=0; i<n-1; i++){
			cout << ini[i][0]%m << " ";
		}
		cout << ini[n-1][0]%m << endl;
	}
	return 0;
}

Measured memory_bytes: 3440
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 public class abc084b {

 }

 */
public class Main {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    int a = in.readInteger();
    int b = in.readInteger();

    String s = in.read();

    if (s.charAt(a) != '-') {
      System.out.println("No");
      return;
    }

    for (int i = 0; i < a; i++) {
      if (!Character.isDigit(s.charAt(i))) {
        System.out.println("No");
        return;
      }
    }

    for (int i = a + 1; i < a + b + 1; i++) {
      if (!Character.isDigit(s.charAt(i))) {
        System.out.println("No");
        return;
      }
    }

    System.out.println("Yes");
    // end here
  }

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

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}


Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;

int main(){
    int n;
    double x,sum=0;
    string u;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x>>u;
        if(u[0]=='J'){
            sum+=x;
        }else{
            sum+=x*380000;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256