akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 100000000
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}
double arg(Vector p){ return atan2(p.y,p.x);}
Vector polar(double a,double r){ return Point(cos(r)*a,sin(r)*a);}


static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return COUNTER_CLOCKWISE;
  if(cross(a,b)<-eps)return CLOCKWISE;
  if(dot(a,b)<-eps)return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

pair<Point,Point> getCrossPoints(Circle c1,Circle c2){
  double d=abs(c1.c-c2.c);
  double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
  double t=arg(c2.c-c1.c);
  return mp(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

int main()
{
  int n;
  Point p[150][2];
  double dp[150][2];
  Circle C[101];

  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>C[i].c.x>>C[i].c.y>>C[i].r;
    for(int i=0;i<150;i++){
      dp[i][0]=inf;
      dp[i][1]=inf;
    }

    p[0][0]=C[0].c; // ?§????
    p[0][1]=C[0].c;

    //  ????????????????????????
    for(int i=1;i<n;i++){
      pair<Point,Point> pp=getCrossPoints(C[i-1],C[i]);
      p[i][0]=pp.f;
      p[i][1]=pp.s;
    }
    p[n][0]=C[n-1].c; // ??????
    p[n][1]=Point(inf,inf);

    dp[0][0]=0;
    for(int i=1;i<=n;i++){
      for(int j=0;j<2;j++){
	for(int k=i-1;k>=0;k--){
	  for(int l=0;l<2;l++){
	    bool flag=true;
	    Segment S=Segment(p[i][j],p[k][l]);
	      for(int c=k+1;c<i;c++){
		if(!intersect(Segment(p[c][0],p[c][1]),S))flag=false;
	      }
	    if(flag){
	      dp[i][j]=min(dp[i][j],dp[k][l]+abs(S.p1-S.p2));
	    }
	  }
	}
      }
    }
    printf("%.10f\n",dp[n][0]);
  }
  return 0;
}

Measured memory_bytes: 1380
fun main(args: Array<String>) {
    val c = Array(3) { listOfInt() }
    for (a1 in 0 .. 100) {
        val b1 = c[0][0] - a1; if (0 > b1 || b1 > 100) continue
        val b2 = c[0][1] - a1; if (0 > b2 || b2 > 100) continue
        val b3 = c[0][2] - a1; if (0 > b3 || b3 > 100) continue
        val a2 = c[1][0] - b1; if (0 > a2 || a2 > 100) continue
        val a3 = c[2][0] - b1; if (0 > a3 || a3 > 100) continue
        if (c[1][1] != a2 + b2) continue
        if (c[1][2] != a2 + b3) continue
        if (c[2][1] != a3 + b2) continue
        if (c[2][2] != a3 + b3) continue
        println("Yes")
        return
    }
    println("No")

}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  vector<ll> cum(n);
  cum[0] = a[0];
  for (int i = 1; i < n; ++i) cum[i] = cum[i-1] + a[i];

  reverse(a.begin(), a.end());
  reverse(cum.begin(), cum.end());

  int ans = 1;
  for (int i = 1; i < n; ++i) {
    if (a[i-1] > 2 * cum[i]) break;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4560
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

pushed = [False] * N
pushed[0] = True
now = 0
cnt = 0

while True:
    next = A[now] - 1

    if pushed[next]:
        cnt = -1
        break

    if next == 1:
        cnt += 1
        break

    if next != 1:
        now = next
        pushed[next] = True
        cnt += 1


print(cnt)


Measured memory_bytes: 7888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}






int main(){
  ll D;
  cin >> D;
  vector<ll> c(26);
  FOR(i,0,26) cin >> c[i];
  vector<ll> last(26,0),s(26);
  vector<vector<ll>> S;

  FOR(i,0,D){
    FOR(j,0,26){
      cin >> s[j];
    }
    S.push_back(s);
  }
  ll ans = -INF;

  vector<ll> ans_(D),now_t(D);



  FOR(k,0,26){
    ll kk = k;
    FOR(i,0,D)now_t[i] = ((kk++)%26)+1;
    ll ans_t = 0;
    FOR(i,0,D){
      ll t;
      t = now_t[i];
      t--;
      ans_t += S[i][t];
      last[t] = i+1;
      FOR(j,0,26){
        ans_t -= c[j] * (i+1 - last[j]);
      }
      
      if(ans < ans_t){
        ans_ = now_t;
        ans = ans_t;
      }

    }
  }

  FOR(k,0,26){
    ll kk = k;
    FOR(i,0,D){
      now_t[i] = (kk%26)+1;
      kk--;
      if(kk<0)kk=25;
    }
    ll ans_t = 0;
    FOR(i,0,D){
      ll t;
      t = now_t[i];
      t--;
      ans_t += S[i][t];
      last[t] = i+1;
      FOR(j,0,26){
        ans_t -= c[j] * (i+1 - last[j]);
      }
      
      if(ans < ans_t){
        ans_ = now_t;
        ans = ans_t;
      }

    }
  }

  FOR(i,0,D){
    cout << ans_[i] << endl;
  }

}



Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A.at(i);

  sort(A.begin(), A.end());
  
  string YesNo = "YES";
  
  for(int i = 0; i < N; i++) {
    if(i != 0) {
      if (A.at(i) == A.at(i - 1)) {
        YesNo = "NO";
        break;
      }
    }
  }
  
  cout << YesNo << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N=2000;
map<int,int>mp[200]; ///前i个物品用背包w能获取的最大价值

int main() {

    int n,W;
    cin>>n>>W;
    int w,v;
    mp[0][0]=0;
    for(int i=0;i<n;i++){
        cin>>w>>v;
        for(auto p:mp[i]){
            mp[i+1][p.first]=max(mp[i][p.first],mp[i+1][p.first]);
            if(p.first+w<=W){
                mp[i+1][p.first+w]=max(mp[i+1][p.first+w],mp[i][p.first]+v);
            }
        }
    }
    int ans=0;
    for(auto p:mp[n]){
        ans=max(ans,p.second);
    }
    cout<<ans;
    return 0;
}




Measured memory_bytes: 8272
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int n;
vector<int> a;

int main()
{
  ll ans=0;

  cin >> n;
  a.resize(n);
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  ans = a[n-1];
  for (int i=n-n/2; i<n-1; i++) {
//printf("*2: a[%d] = %d\n", i, a[i]);
    ans += 2*a[i];
  }
  if (n%2 && n-n/2-1>=0) {
//printf("+: a[%d] = %d\n", n-n/2-1, a[n-n/2-1]);
    ans += a[n-n/2-1];
  }

  cout << ans << endl;
  return 0;
}

/*
  Aiを降順に並べ、大きい順に到着させる。
  心地よさが最も大きい所に入れる。
  A1 *A2 (A1): A1
  A1 A2 *A3 (A1): A1+A2
  A1 *A4 A2 A3 (A1): A1+A2+A2
  A1 A4 A2 *A5 A3 (A1): A1+A2+A2+A3
  A1 A4 A2 A5 A3 *A6 (A1): A1+A2+A2+A3+A3
  A1 *A7 A4 A2 A5 A3 A6 (A1): A1+A2+A2+A3+A3+A4
  A1 A7 A4 *A8 A2 A5 A3 A6 (A1): A1+A2+A2+A3+A3+A4+A4
…
  A1+Σ2*A_k(k=2..n/2-1)+A_n/2

  A1=a[n-1];
  A2=a[n-2];
  …
  A4=a[n-4];
  */


Measured memory_bytes: 3984
import java.math.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println((a - c) * (b - d));
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, ab, x, y;
    cin >> a >> b >> ab >> x >> y;

    int ans = min({a * x + b * y, ab * 2 * x + b * max(0, y - x), ab * 2 * y + a * max(0, x - y)});
    cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

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

  map<char, int> m;
  rep(i, s.size()){
    m[s[i]]++;
  }

  if(abs(m['a']-m['b']) <= 1 and abs(m['b']-m['c']) <= 1 and abs(m['c']-m['a']) <= 1) cout << "YES" << endl;
  else cout << "NO" << endl;


  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define rg register
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2e5+5;
int n,A,B,C,D;
char s[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc == '-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	n=rd(); A=rd(); B=rd(); C=rd(); D=rd();
	scanf("%s",s+1);
	int fl=1,cover=0;
	go(i,D,B)
		if(s[i] == '#' && s[i+1] == '#') fl=0;
	go(i,D+1,B)
		if(s[i] == '.' && s[i-1] == '.' && s[i+1] == '.') cover=1;
	if(cover == 0 && C > D) fl=0;
	go(i,C,A)
		if(s[i] == '#' && s[i+1] == '#') fl=0;
	if(fl) puts("Yes");
	else puts("No");
	return 0;
}

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

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

	ll sum = 0;
	for(char i : s){
		sum += i-'0';
	}

	if(sum%9 == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
}

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

using namespace std;

int main(){
	int n, m, k, x, y;

	scanf("%d%d%d", &n, &m, &k);

	for (x = 0; x <= n; x++){
		for (y = 0; y <= m; y++){
			if (x * m + y * n - 2 * x * y == k){
				break;
			}
		}

		if (y <= m){
			break;
		}
	}

	if (x <= n){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    double ans = 0.0;
    rep(i,1,n+1){
        ll a = i;
        double m = 1.0;
        while(a < k){
            a *= 2;
            m /= 2.0;
        }
        ans += m/(double)n;
    }
    printf("%.15f\n",ans);
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    auto check = [&](int x) {
        ll cnt = 0;
        rep(i, n) {
            if(a[i]%x == 0) {
                cnt += a[i]/x-1;
            } else {
                cnt += a[i]/x;
            }
        }
        if(cnt <= k) {
            return true;
        } else {
            return false;
        }
    };

    int aa = 0, b, c = 1e9+10;
    while(c-aa != 1) {
        b = (aa+c)>>1;
        if(check(b)) {
            c = b;
        } else {
            aa = b;
        }
    }

    cout << c << endl;
}

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

const int maxN = 5e5 + 10;

struct Node
{
	int to, next;
}edge[maxN * 2 + 1];

int head[maxN + 1], n, tot;
int c0, c1, c2, ans[maxN + 1];

vector<int> num[2];

inline void add(int x, int y)
{
	tot ++;
	edge[tot].to = y;
	edge[tot].next = head[x];
	head[x] = tot;
}

inline void dfs(int u, int pa, int dep)
{
	num[dep].push_back(u);
	for(int i = head[u]; i; i = edge[i].next)
	{
		int v = edge[i].to;
		if(v == pa) continue;
		dfs(v, u, dep ^ 1);
	}
}

int main()
{
	scanf("%d", &n);
	c0 = n / 3, c1 = (n + 2) / 3, c2 = (n + 1) / 3;

	for(int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		add(x, y); add(y, x);
	}

	dfs(1, 0, 1);

	if(num[0].size() > num[1].size()) swap(num[0], num[1]);

	if(num[0].size() <= c0)
	{
		for(int i = 0; i < num[0].size(); i++)
			ans[ num[0][i] ] = 0, c0 --;
	}
	else
	{
		for(int i = 0; i < num[0].size(); i++)
			if(c1) ans[ num[0][i] ] = 1, c1 --;
			else if(c0) ans[ num[0][i] ] = 0, c0 --;
	}

	for(int i = 0; i < num[1].size(); i++)
		if(c1) ans[ num[1][i] ] = 1, c1 --;
		else if(c2) ans[ num[1][i] ] = 2, c2 --;
			else if(c0) ans[ num[1][i] ] = 0, c0 --;

	int t[3]; t[1] = t[2] = 0; t[0] = 1;
	for(int i = 1; i <= n; i++)
		printf("%d ", t[ ans[i] ] * 3 + ans[i]), t[ ans[i] ] ++;
	return 0;
}


Measured memory_bytes: 12660
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

template<class T>
class d_heap{
	static const int N_MAX=3000; // !!
	int n,d;
	T a[N_MAX];
public:
	d_heap(int d):n(0),d(d){}
	const T &find_min()const{ return a[0]; }
	void insert(const T &x){
		int u=n++;
		a[u]=x;
		while(u!=0 && a[(u-1)/d]>a[u]) swap(a[(u-1)/d],a[u]), u=(u-1)/d;
	}
	void delete_min(){
		a[0]=a[--n];
		for(int u=0;;){
			int v=u;
			for(int w=d*u+1;w<=d*u+d;w++) if(w<n && a[v]>a[w]) v=w;
			if(v==u) break;
			swap(a[v],a[u]);
			u=v;
		}
	}
	bool empty()const{ return n==0; }
	int size()const{ return n; }
};

#define define_heap d_heap< pair<int,int> > H(2);

const int INF=1<<29;

struct edge{ int v,cost1,cost2; };

int main(){
	for(int m,n;scanf("%d%d",&m,&n),n;){
		vector<edge> G[100];
		rep(i,m){
			int u,v,cost1,cost2; scanf("%d%d%d%d",&u,&v,&cost1,&cost2); u--; v--;
			G[u].push_back((edge){v,cost1,cost2});
			G[v].push_back((edge){u,cost1,cost2});
		}

		int q; scanf("%d",&q);
		while(q--){
			int s,t,type; scanf("%d%d%d",&s,&t,&type); s--; t--;

			int d[100];
			rep(u,n) d[u]=(u==s?0:INF);
			define_heap;
			H.insert(make_pair(0,s));
			while(!H.empty()){
				int d_now=H.find_min().first,u=H.find_min().second;
				H.delete_min();

				if(d[u]<d_now) continue;

				rep(i,G[u].size()){
					const edge &e=G[u][i];
					int d2=d_now+(type==0?e.cost1:e.cost2);
					if(d[e.v]>d2){
						d[e.v]=d2;
						H.insert(make_pair(d2,e.v));
					}
				}
			}

			printf("%d\n",d[t]);
		}
	}

	return 0;
}

Measured memory_bytes: 1168
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    int ans = 0;
    for (int i = 0; i < N.length(); i++) {
      if (N.charAt(i) == '2') {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

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

int main() {
      int x = 0;
      cin >> x;
    int maxi = 0;

    for(int q = 1; q <= x; q++){
        for(int j = 2; j < 10; j++){
            int num = pow(q, j);
            if(num > x)
                j = 11;
            else if(num <= x && num > maxi)
                maxi = num;
        }
    }

    cout << maxi << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h) * (W - w);
	return 0;
}

Measured memory_bytes: 256
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
//    func enumerated() -> [(Int, Element)] {
//        return self.enumerate()
//    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (A, B) = (input[0], input[1])
if A < 6 {
    print(0)
} else if A <= 12 {
    print(B/2)
} else {
    print(B)
}


Measured memory_bytes: 7908
function min(x,y:word):word;begin if x>y then exit(y) else exit(x);end;
var
  a,b,c:longint;
procedure read;
begin
  readln(a,b,c);
end;
procedure write;
begin
  writeln(min(min(a+b,a+c),b+c));
end;
begin
  read;
  write;
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
/* 0/1 Knapsack problem, GFG*/

void solve()
{
    ll n,w,i,j;
    cin >> n >> w;
    ll p[n+1] = {0};
    ll wt[n+1] = {0};

    for(i=0;i<n;i++)
        cin >> wt[i+1] >> p[i+1];

    ll a[n+1][w+1];
    memset(a,0,sizeof(a));

    for(i=0;i<n+1;i++)
    {
        for(j=0;j<w+1;j++)
        {
            if(i == 0 || j == 0)
                a[i][j] = 0;
            else if(wt[i] <= j)
            {
                a[i][j] = max(a[i-1][j], a[i-1][j-wt[i]] + p[i]);
            }
            else
            {
                a[i][j] = a[i-1][j];
            }
        }
    }
    cout << a[n][w] << "\n";


}
int main()
{

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin >> t;
	while(t-- > 0)
	{
		solve();
	}

}


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

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// Graph
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  char a;
  cin >> a;
  for (int i = 0; i < 26; i++)
  {
    char tmp = 'a' + i;
    if (a == tmp)
    {
      cout << 'a' << endl;
      return 0;
    }
  }
  cout << 'A' << endl;
  return 0;
}


Measured memory_bytes: 3648
def solve(n, P):
    min_val = P.pop(0)
    count = 1
    for p in P:
        if min_val >= p:
            count += 1
        if min_val > p:
            min_val = p
    return count

_n = int(input())
_P = list(map(int, input().split()))
print(solve(_n, _P))


Measured memory_bytes: 24744
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  int N;
  int h[100001] = {0};
  int cost1to[100001] = {0};
  int cost2to[100001] = {0};
  int mincostto[100001] = {0};
  cin >> N;
  for(int i=1; i <= N; i++){
    cin >> h[i];
  }
  cost1to[1] = 0;
  cost1to[2] = abs(h[2]-h[1]);
  cost2to[1] = 0;
  cost2to[2] = 1000000000;
  cost2to[3] = abs(h[3]-h[1]);
  mincostto[1] = 0;
  mincostto[2] = min(cost1to[2], cost2to[2]);
  for(int i=3; i <= N; i++){
    cost1to[i] = abs(h[i] - h[i-1]);
    cost2to[i] = abs(h[i] - h[i-2]);
  }
  for(int i=3; i <= N; i++){
    mincostto[i] = min(mincostto[i-1]+cost1to[i],mincostto[i-2]+cost2to[i]);
  }
  cout << mincostto[N];
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int a,b,r,s,t;
    cin>>a>>b;
    r=a+b;
    s=a-b;
    t=a*b;
    if (r>=s&&r>=t){
        cout<<r;
    }
    else if(s>=r&&s>=t){
        cout<<s;
    }
    else{
        cout<<t;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib> //std::abs() を使いたいので

int main(){
  
  int n;
  std::cin >> n;
  
  std::vector<int> numbers(n);
  for(int i=0; i < numbers.size(); i++)
    std::cin >> numbers.at(i);
  
  int answer = 0;
  //二重ループにして各要素の絶対値をとる
  //あとでループ一回にして最大, 最小の差をとる方法も書くこと
  for(int i=0; i < numbers.size(); i++){
    for(int j=0; j < numbers.size(); j++){
      if( answer < std::abs( numbers.at(i) - numbers.at(j) ) )
        answer = std::abs( numbers.at(i) - numbers.at(j) );
    }
  }

  std::cout << answer << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
	int n;
	string s;
	cin >> n >> s;
	char a = '0';
	int ans = 0;
	for (int i = 0; i < n; i++){
		if (a != s[i]){
			ans++;
			a = s[i];
		}
	}
	cout << ans << endl;



}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits>
//#include <stack>
//#include <tuple>

using namespace std;


const double Inf = numeric_limits<double>::infinity();



int main(int argc, char** argv){
    int A, B, C;
    cin >> A >> B >> C;
    if (A==B && A==C) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

ll N, M, s, g;
vector<ll> paths[50];
ll u[500], v[500];
string S[500];
bool can[50];
string ans;

void solve() {
    ans.clear();
    for(int i = 0; i < N; i++) {
        paths[i].clear();
        can[i] = false;
    }
    for(int i = 0; i < M; i++) {
        cin >> u[i] >> v[i] >> S[i];
        paths[u[i]].push_back(i);
    }
    can[g] = true;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            can[u[j]] |= can[v[j]];
        }
    }
    if(!can[s]) {
        cout << "NO" << endl;
        return;
    }
    vector<l_l> candidate;
    candidate.push_back({s, -1});
    while(true) {
        if(ans.size() >= 1e5) {
            cout << "NO" << endl;
            return;
        }
        char nxt = 'z';
        for(auto now : candidate) {
            if(now.first == g and now.second == -1) {
                cout << ans << endl;
                return;
            }
            if(now.second != -1) {
                chmin(nxt, S[now.first][now.second]);
            } else {
                for(auto e : paths[now.first]) {
                    if(!can[v[e]]) continue;
                    chmin(nxt, S[e][0]);
                }
            }
        }
        vector<l_l> tmp;
        ans.push_back(nxt);
        for(auto now : candidate) {
            if(now.second != -1) {
                if(S[now.first][now.second] != nxt) continue;
                if(S[now.first].size() == now.second + 1) {
                    tmp.push_back({v[now.first], -1});
                } else {
                    tmp.push_back({now.first, now.second + 1});
                }
            } else {
                for(auto e : paths[now.first]) {
                    if(!can[v[e]]) continue;
                    if(S[e][0] != nxt) continue;
                    if(S[e].size() >= 2) tmp.push_back({e, 1});
                    else tmp.push_back({v[e], -1});
                }
            }
        }
        sort(tmp.begin(), tmp.end());
        tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
        swap(tmp, candidate);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M >> s >> g) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


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

int M = 100000, N = 100;

int GetRandom(int min,int max){
	return min + (int)(rand()*(max-min+1.0)/(1.0+RAND_MAX));
}

int main(){
    // 入力
    int D;
    cin >> D;   // D = 365
    ll c[26];
    for(int i=0;i<26;i++)
        cin >> c[i];
    ll s[D][26];
    for(int i=0;i<D;i++)
        for(int j=0;j<26;j++)
            cin >> s[i][j];
    // 初期解t[D]
    int t[D];
    /*
    for(int i=0;i<D;i++)
        cin >> t[i];
    */
    for(int i=0;i<D;i++){
        //t[i] = GetRandom(1,26);   // 1<=, <=26
        t[i] = i%26 + 1;
    }
    // クエリ
    // cin >> M;
    int d[M][N], q[M][N];
    /*
    for(int i=0;i<M;i++)
        cin >> d[i] >> q[i];
    */
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            d[i][j] = GetRandom(1,D);   // 1<=, <=365
            q[i][j] = GetRandom(1,26);   // 1<=, <=26
        }
    }

    // 処理部
    ll v_best = 0;
    for(int query=0;query<M;query++){
        if(query > 9000)
            N = 10;
        int last[26] = {}, q_[N];
        // コンテスト種別の変更（N個）
        for(int i=0;i<N;i++){
            q_[i] = t[d[query][i]-1];
            t[d[query][i]-1] = q[query][i];
        }
        // D日分
        ll v = 0;
        for(int i=1;i<=D;i++){
            // 満足度の増加分
            v += s[i-1][t[i-1]-1];
            last[t[i-1]-1] = i;
            // 満足度の低下分（コンテスト26種分）
            for(int j=0;j<26;j++)
                v -= c[j]*(i - last[j]);
        }
        // cout << v << endl;
        if(v < v_best){
            for(int i=0;i<N;i++){
                t[d[query][i]-1] = q_[i];
            }
        }else{
            v_best = v;
        }
    }

    // 答え出力
    for(int i=0;i<D;i++)
        cout << t[i] << endl;

}

Measured memory_bytes: 81860
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=d/10;j++)
		{
			for(int k=2;k<=9;k++)
			{
				if(j*10+k<=d)
				{
					if(k*j==i)
					{
						ans++;
					}
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int n;
int a[100], b[100];
int memo[100][100];

int recur(int left, int right){
	if(memo[left][right] == -1){
		int ret = INT_MAX;

		if(left == right){
			ret = 0;
		}
		else{
			for(int mid = left; mid < right; ++mid){
				int cost = recur(left, mid) + recur(mid + 1, right) + a[left] * b[mid] * a[mid + 1] * b[right];
				ret = min(ret, cost);
			}
		}
		memo[left][right] = ret;
	}

	return memo[left][right];
}

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

	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			memo[i][j] = -1;
		}
	}

	int ans = recur(0, n - 1);
	cout << ans << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s) freopen((string(s) + ".inp").c_str(), "r", stdin),\
		freopen((string(s) + ".out").c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
int n, m;
string s, t;
int lcm(int a, int b) { return a * b / __gcd(a, b); }
void bad() {
	cout << "-1";
	exit(0);
}
signed main() {
	#ifdef BLU
	//in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	cin >> s >> t;
	n = s.length(), m = t.length();
	int l = lcm(n, m);
	int n2 = l / n, m2 = l / m;
	fw (i, 0, n) {
		if (i * n2 % m2 != 0) continue;
		if (i * n2 / m2 >= m) continue;
		if (s[i] != t[i * n2 / m2]) bad();
	}
	cout << l;
	return 0;
}

Measured memory_bytes: 640
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios: :sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


void solve()
{ 
  string s;
  cin >> s;
  f(i,3)
  {
   if(s[i]=='7')
   {
    cout << "Yes\n";return; 
   }
  }
  cout << "No\n";
  return;
}

signed main()
{
  int T=1;
  //cin >> T;
  while(T--)
  {
    solve();
	}
  return 0;
}

Measured memory_bytes: 3624
fun main(args: Array<String>) {
//    val s = "RRLRL"
    val s = readLine()!!
    val rlList = mutableListOf<RL>()

    var pre = 'x'
    s.forEachIndexed { index, cur ->
        if (pre == 'R' && cur == 'L') {
            rlList.add(RL(index - 1))
        }
        pre = cur
    }

    pre = 'x'
    val iterator = rlList.iterator()
    var poolRL = iterator.next()

    s.forEachIndexed { index, cur ->
        if (pre == 'L' && cur == 'R') {
//            println("chenged at $index. pre: $pre, cur: $cur")
            poolRL = iterator.next()
        }
        poolRL.join(index)
        pre = cur
    }

    val ite2 = rlList.iterator()
    var resRL = ite2.next()

    (0 until (s.length - 1)).forEach { i ->
        if (i == resRL.rIndex) print("${resRL.rChild} ")
        else if (i == resRL.rIndex + 1) {
            print("${resRL.lChild} ")
            if (ite2.hasNext()) {
                resRL = ite2.next()
            }
        }
        else {
            print("0 ")
        }

    }
    when (s.length - 1) {
        resRL.rIndex -> print("${resRL.rChild} ")
        resRL.rIndex + 1 -> print("${resRL.lChild} ")
        else -> print("0 ")
    }
//    println(rlList)
}

data class RL(val rIndex: Int, var rChild: Int = 0, var lChild: Int = 0) {
    fun join(startIndex: Int) {
        if ((rIndex - startIndex) % 2 == 0) {
            rChild++
        } else {
            lChild++
        }
    }
}


Measured memory_bytes: 49508
h,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(h)]
B=[list(map(int,input().split())) for i in range(h)]
C=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        C[i][j]=abs(A[i][j]-B[i][j])
        
dp=[[0]*w for i in range(h)]
m=80
dp[0][0] = (1<<m+C[0][0]) | (1<<m-C[0][0])

for i in range(h):
    for j in range(w):
        if i>=1:
            dp[i][j] |= (dp[i-1][j]<<m+C[i][j]) | (dp[i-1][j]<<m-C[i][j])
        if j>=1:
            dp[i][j] |= (dp[i][j-1]<<m+C[i][j]) | (dp[i][j-1]<<m-C[i][j])
            
b=list(bin(dp[h-1][w-1]))[::-1]
ans=float("inf")

for i in range(len(b)):
    if b[i]=="1":
        ans=min(ans,abs(m*(h+w-1)-i))

print(ans)

Measured memory_bytes: 16116
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int h;
    cin >> h;
    int w;
    cin >> w;
    char c[h][w];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < 2*h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << c[i/2][j];
        }
        cout << "" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;



void _main() {
    int A, B;
    cin >> A >> B;
    cout << max(0LL, A - 2 * B) << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    string s; cin >> s;
    ll k; cin >> k;
    ll j = 0;
    while(j < k){
        if(s[j] != '1'){
            cout << s[j] << endl;
            return 0;
        }
        j++;
    }
    cout << 1 << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    static int[] Tcard,Hcard;
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	int m = sc.nextInt();

	while(n!=0 && m!=0){
	    Tcard = new int[n];
	    Hcard = new int[m];
	    for(int i=0; i<n; i++){
		Tcard[i] = sc.nextInt();
	    }
	    for(int i=0; i<m; i++){
		Hcard[i] = sc.nextInt();
	    }

	    String ans = solve();

	    System.out.println(ans);

	    n = sc.nextInt();
	    m = sc.nextInt();
	}
    }

    public static String solve(){
	int Tsum = 0;
	int Hsum = 0;
	for(int i=0; i<Tcard.length; i++){
	    Tsum += Tcard[i];
	}
	for(int i=0; i<Hcard.length; i++){
	    Hsum += Hcard[i];
	}
	int Tpass = 0;
	int Hpass = 0;
	int sum = 200;
	boolean hantei = false;
	for(int i=0; i<Tcard.length; i++){
	    for(int j=0; j<Hcard.length; j++){
		if(Hsum+Tcard[i]-Hcard[j]==Tsum+Hcard[j]-Tcard[i]){
		    if(Tcard[i]+Hcard[j]<sum){
			Tpass=Tcard[i]; 
			Hpass=Hcard[j]; 
			sum=Tpass+Hpass;
			hantei = true;
		    }
		}
	    }
	}
	if(hantei)return Tpass+" "+Hpass;
	return "-1";
    }
}

Measured memory_bytes: 12000
#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int d, e, f;
	d = a + b;
	e = b + c;
	f = c + a;
	if (d >= f && e >= f)
	{
		cout << f;
	}
	else if (e >= d && f >= d)
	{
		cout << d;
	}
	else if (d >= e && f >= e)
	{
		cout << e;
	}

	return 0;
}

Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    timeschedule = [na() for _ in range(n - 1)]

    for i in range(n):
        time = 0

        for j in range(i, n - 1):
            c, s, f = timeschedule[j]
            if time < s:
                time = s
            if (time - s) % f:
                time += f - ((time - s) % f)
            time += c

        print(time)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5208
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>
#include <list>

using namespace std;

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

int main(){
	
	long long int N;
	
	while(true){
		
		cin >> N;
		if(N == 0){
			break;
		}
		
		list<elem> lst;
		elem e;
		e.first.first = 1500000000;
		e.first.second = 1;
		e.second = 1500000000;
		
		lst.push_back(e);
		
		for(int loop = 0; loop < N; loop++){
			
			char c;
			cin >> c;
			list<elem>::iterator itr = lst.begin();
			
			if(c == 'W'){
				long long int num, count;
				cin >> num >> count;
				long long int pos = 0;
				while(true){
					elem e_cur = *itr;
					if(e_cur.first.first > pos){
						elem e1;
						e1.first.first = pos;
						e1.first.second = min(count, e_cur.first.first- pos);
						e1.second = num;
						lst.insert(itr, e1);
						count -= e_cur.first.first - pos;
						if(count <= 0){
							break;
						}
					}
					pos = e_cur.first.first + e_cur.first.second;
					++itr;
				}
			}else if(c == 'D'){
				long long int num;
				cin >> num;
				while(itr != lst.end()){
					if(((elem)*itr).second == num){
						itr = lst.erase(itr);
					}else{
						++itr;
					}
				}
			}else{
				long long int pos;
				cin >> pos;
				long long int ans = -1;
				while(itr != lst.end()){
					elem e_cur = *itr;
					if(e_cur.first.first + e_cur.first.second > pos){
						if(e_cur.first.first <= pos){
							ans = e_cur.second;
						}
						break;
					}
					itr++;
				}
				cout << ans << endl;
			}
		}
		/*
		for(list<elem>::iterator itr = lst.begin(); itr != lst.end(); itr++){
			elem e = *itr;
			cout << e.first.first << " " << e.first.second << " " << e.second << endl;
		}
		*/
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3248
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
//#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

ll gcd(ll a, ll b){
  // このコメント外すと不正解になりました
  // if (a < b) swap(a, b);
  return (b ? gcd(b, a%b): a);
}

ll calcLCM(ll a, ll b){
  return a * b / gcd(a, b);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) p[i] /= 2;

  ll lcm = p[0];
  for(int i=1;i<n;i++){
    lcm = calcLCM(lcm, p[i]);
  }
  if (lcm > m){
    cout << 0 << endl;
    return 0;
  }
  rep(i, n){
    if ((lcm / p[i]) % 2 == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = m / lcm;
  ans = (ans + 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin>>n>>k;
    vector<int> elem(n+1);
    for (int i = 0; i < n; i++) {
        cin>>elem[i];
    }
    bool canWin[k+1];
    canWin[0] = 0;
    for (int stones = 1; stones <= k; stones++) {
        canWin[stones] = 0;
        for (int index = 0; index < n; index++) {
            if (elem[index] <= stones && !canWin[stones - elem[index]]) {
                canWin[stones] = 1;
                break;
            }
        }
    }
    if (canWin[k])
        cout<<"First"<<"\n";
    else
        cout<<"Second"<<"\n";
    return 0;
}


Measured memory_bytes: 3708