akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

struct Item {
    int value, weight;
};

int main() {

    int n, w;
    cin >> n >> w;

    vector<Item> items(n);
    rep(i, n)cin >> items[i].value >> items[i].weight;

    vector<int> dp(w + 1, INT_MIN);
    dp[0] = 0;
    rep(i, w + 1) {
        if (dp[i] == INT_MIN) continue;
        for (Item &item : items) {
            if (item.weight + i > w)continue;
            cmax(dp[i + item.weight], dp[i] + item.value);
        }
    }

    int ans = 0;
    rep(i, w + 1) cmax(ans, dp[i]);
    cout<< ans << endl;

}




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


bool rev(string s){
	for(int i=0;i<s.size();i++){
		if(s[i]!=(s[s.size()-1-i])){
			return 0;
		}
	}
	return 1;
}

int main(){
	string s;
	int ans=0;
	while(cin>>s){
		if(rev(s)){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n, a,b; ll k; cin >> n >> k;
    map<int, ll> mp;
    rep(i,n) {
        cin >> a >> b;
        mp[a] += b;
    }
    ll siz = 0;
    for(auto p : mp) {
        siz += p.second;
        if(siz >= k) {
            cout << p.first << '\n';
            break;
        }
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 4224
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

string s;
bool use[32];
set<string> memo;
void dfs(int idx){
  if(idx == SZ(s)){
	memo.insert(s);
	return;
  }
  
  int i = s[idx] - 'a';
  if(use[i] || s[idx] == 'a'){
	dfs(idx+1);
  }
  if(s[idx] != 'z' && !use[i+1]){
	use[i+1] = true;
	s[idx]++;
	dfs(idx+1);
	s[idx]--;
	use[i+1] = false;
  }
}

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

  while(cin>>s,s!="#"){
	memo.clear();
	fill(use, use+32, false);
	dfs(0);
	cout << SZ(memo) << endl;

	if(SZ(memo) <= 10)
	  for(auto str: memo) cout << str << endl;
	else{
	  int i = 0;
	  for(auto it=memo.begin();i<5;++it,++i)
		cout << *it << endl;

	  i = 0;
	  VS vs(5);
	  for(auto it=memo.rbegin();i<5;++it,++i)
		vs[i] = *it;
	  for(i=4;i>=0;--i)
		cout << vs[i] << endl;
	}
  }
  
  return 0;
}

Measured memory_bytes: 3136
#include <stdio.h>
int main(){
  int Num[100];
  int a,b=0,n,i,j;
  scanf("%d",&a);
  
  for(i = 0;i < a;i++){
    scanf("%d",&n);
     Num[i] = n;
    b++;
  }
  for(j = a-1;j >= 0;j--){
    
    if (j != 0) printf("%d ",Num[j]);
    else printf("%d",Num[j]);
    
  }
  printf("\n");

  
  return 0;
}



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

int main() {
  int a,b;
  string s;
  cin >> a;
  
  for(int i = 0; i < a; i++){
    cin >> s;
    if( s == "Y" ){
    cout << "Four" << endl;
      
    return 0;
  }
  }
  
   cout << "Three" << endl;
  
}
 
  
  
  
 


Measured memory_bytes: 256
#include <complex>
#include <cstdio>
#include <cmath>
using namespace std;

// ?????§?¨?????????¨??????
typedef complex<double> P;
// ???????????
#define PI 3.1415926535898

// ?¨±?????????????????
#define EPS (1e-10)
//XY??§?¨?
#define X real()
#define Y imag()

// ????§???¢?????????
class Triangle{

private:
	//????§???¢??????????????§?¨?
	P a, b, c;
	//????§???¢??????????????????
	double edgeA,edgeB,edgeC;
	//????§???¢???????§??????§??????(????????¢???)
	double angleA,angleB,angleC;
	//????????????????????????????§????????±?????????¢??°
	double LawOfCosines(double a,double b, double c){
		return acos( (b*b+c*c-a*a) / (2.0*b*c) );
	}


public:
	//?????????????????????(??????????????¨?????¨?§????????????????)
	Triangle(P p1, P p2, P p3){
		a = p1;
		b = p2;
		c = p3;
		edgeB = abs(c-a);
		edgeA = abs(b-c);
		edgeC = abs(a-b);
		angleA = LawOfCosines(edgeA,edgeB,edgeC);
		angleB = LawOfCosines(edgeB,edgeC,edgeA);
		angleC = LawOfCosines(edgeC,edgeA,edgeB);
	}

	double circumscribedCircleRadius(){//?????\?????????????????????
		return ( edgeA / sin(angleA) / 2.0 );
	}
	double circumscribedCircleX(){//??????(?????\????????????)???X??§?¨??????????
		double A = sin(2.0*angleA);
		double B = sin(2.0*angleB);
		double C = sin(2.0*angleC);
		return ( (a.X * A + b.X * B + c.X * C) / (A+B+C) );
	}
	double circumscribedCircleY(){//??????(?????\????????????)???Y??§?¨??????????
		double A = sin(2.0*angleA);
		double B = sin(2.0*angleB);
		double C = sin(2.0*angleC);
		return ( (a.Y * A + b.Y * B + c.Y * C) / (A+B+C) );
	}
};

int main(){
	int n;
	double x1, x2, x3, y1, y2, y3;
	double r, xp, yp;

	scanf("%d", &n);
	for (int i=0 ; i<n ; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
		P a( x1 , y1 );
		P b( x2 , y2 );
		P c( x3 , y3 );
		Triangle Tr(a,b,c);
		r  = Tr.circumscribedCircleRadius();
		xp = Tr.circumscribedCircleX();
		yp = Tr.circumscribedCircleY();
		printf("%.3f %.3f %.3f\n", xp,yp,r);
	}
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    int s=r*x-d;
    cout<<s;
    nl;
    for(int i=2;i<=10;i++)
    {
      s= r*s-d;
      cout<<s;
      nl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int y,m,d;
	scanf("%lld/%lld/%lld",&y,&m,&d);
	if(m <= 4) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}

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

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

    cout << (int)pow((int)sqrt(N), 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

void solve(){
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n+5);
	rep(i,n)cin>>a[i+1];
	vector<int>used(n+5),pos(n+5);
	int cur=1;
	ll loop,start;
	for(ll i=1;i<=k;++i){
		cur=a[cur];
		pos[i]=cur;

		if(i==k){
			cout<<cur<<"\n";
			return;
		}
		if(used[cur]>0){
			loop=i-used[cur];
			start=used[cur];
			break;
		}
		used[cur]=i;
	}
	ll x=(k-start)%loop;
	cout<<pos[start+x]<<"\n";
}


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


Measured memory_bytes: 6304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    int x[n],t[n],y[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d %d %d",&t[i],&x[i],&y[i]);
    }
    for(int i=0;i<n;i++)
    {
        int a=x[i]+y[i];
        if(a>t[i])
        {
            cout<<"No"<<endl;
            return 0;
        }
        else if((a+t[i])%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}


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

using namespace std;

int main(){
    long N;
    cin>>N;
    vector<int> p(N);
    int c=0;
    for(int i=0; i<N; ++i){
        cin>>p[i];
        if(p[i] != i+1){
            c++;
        }
    }
    if(c<=2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define int long long
using namespace std;
typedef long long ll;
signed main()
{
    ll l,r;
    //ios_base::sync_with_stdio(0),cin.tie(0);
    while(cin>>l>>r)
    {
        ll ans=2020;
        if(l+2019<=r) {cout<<"0\n";return 0;}
        ll l1=l%2019;ll r1=r%2019;
        if(r1<=l1) {cout<<"0\n";return 0;}
 
        for(int i=l;i<=r;i++)
        {
            for(int j=i+1;j<=r;j++)
            {
                ans=min(ans,i*j%2019);
            }
        }
        cout<<ans<<"\n";
    }
    //cout<<"\n";

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
        G[a - 1].append((i, b - 1))
        G[b - 1].append((i, a - 1))

    color = [0] * (N - 1)

    def dfs(v, p, pc):
        c = 1
        for i, nv in G[v]:
            if nv == p:
                continue
            if c == pc:
                c += 1
            color[i] = c
            dfs(nv, v, c)
            c += 1

    dfs(0, -1, 0)

    print(max(color))
    print('\n'.join(map(str, color)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 99860
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long sum=0;
		for(int i=1;i<=n;i++) {
			if(i%3!=0&&i%5!=0)sum+=i;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 27220
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    K = int(input())
    X = list(map(int, input().split()))

    total = 0
    for x in X:
        move = min(x, K-x)
        total += 2 * move

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;

int main() {
    int H, W;
    cin >> H >> W;
    char a[H][W];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> a[i][j];
        }
    }

    bool high[H] = {false}, width[W] = {false};
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if(a[i][j] == '#') {high[i] = true; width[j] = true;}
        }
    }

    for (int i = 0; i < H; ++i) {
        if(!high[i]) continue;
        for (int j = 0; j < W; ++j) {
            if(!width[j]) continue;
            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    string S;
    cin >> N >> K >> S;
    int l = 0, r = 0, k = 0, sum = 0, res = 0;
    while (r < N) {
        while (r < N && k < K) {
            if (S[r] == '0' && S[r + 1] == '1') {
                k++;
            }
            r++, sum++;
        }
        while (S[r] == '1') {
            r++, sum++;
        }
        amax(res, sum);
        while (k == K) {
            if (S[l] == '0' && S[l + 1] == '1') {
                k--;
            }
            l++, sum--;
        }
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int a[1000][1000];
int dx[8]={0,0,1,-1},
	dy[8]={1,-1,0,0};
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char k;
			cin>>k;
			if(k=='.') a[i][j]=0;
			else a[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]==0) continue;
			int sum=0;
			for(int k=0;k<=3;k++){
				int x=i+dx[k],y=j+dy[k];
				if(x>0 && x<=n && y>0 && y<=m)
				{
					if(a[x][y]==1) sum++;
				}	
			}
			if(sum==0){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000000
#define VMAX 10000

int main(){
	int *A, *B;
	int C[VMAX + 1];
	int n, i, j;
	scanf("%d", &n);
	A = new int[n + 1];
	B = new int[n + 1];
	for (i = 0; i <= VMAX; i++){
		C[i] = 0;
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &j);
		A[i + 1] = j;
		C[A[i + 1]]++;
	}

	for (i = 1; i <= VMAX; i++){
		C[i] += C[i - 1];
	}

	for (i = n; i > 0; i--){
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}


	for (int i = 1; i <= n; i++){
		if (i > 1)printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");
	delete[] A;
	delete[] B;
	return 0;
}

Measured memory_bytes: 17864
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define all(v) v.begin(),v.end()
#define PB push_back
#define T(val) while(val--)
#define FIN for(i=0;i<n;i++)
#define FIS for(i=0;i<s.length();i++)
#define AIN for(i=0;i<n;i++){cin>>a[i];}
#define F(i,k,n) for(i=k;i<n;i++)
#define FG(i,k,n,x) for(i=k;i<n;i+=x)
#define YES cout<<"YES\n"; 
#define NO cout<<"NO\n"; 
#define ll long long
#define ld long double
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//sort(arr, arr+n, greater<int>()); For sorting in reverse order 
  ll dp[3005][3005][4];

int solve(){
  int r,c,k;
  int i,j;

  cin>>r>>c>>k;
  ll a[r][c];
  ll ans=0;
  ll x,y,v;
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      a[i][j]=0;
    }
  }
  while(k--){
    cin>>x>>y>>v;
    a[x-1][y-1]=v;
  }

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      dp[i][j][0]=0;
      dp[i][j][1]=0;
      dp[i][j][2]=0;
      dp[i][j][3]=0;
    }
  }
  dp[0][0][1]=a[0][0];

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      if(i>0){
        // 0
        dp[i][j][0]=max(dp[i-1][j][0],dp[i][j][0]);
        dp[i][j][0]=max(dp[i-1][j][1],dp[i][j][0]);
        dp[i][j][0]=max(dp[i-1][j][2],dp[i][j][0]);
        dp[i][j][0]=max(dp[i-1][j][3],dp[i][j][0]);
        
        // 1
        dp[i][j][1]=max(dp[i-1][j][0]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][1]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][2]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][3]+a[i][j],dp[i][j][1]);
        
        // 2
        dp[i][j][1]=max(dp[i-1][j][0]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][1]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][2]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][3]+a[i][j],dp[i][j][1]);
        
        // 3
        dp[i][j][1]=max(dp[i-1][j][0]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][1]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][2]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i-1][j][3]+a[i][j],dp[i][j][1]);
        
      }
      if(j>0){
        // 0
        dp[i][j][0]=max(dp[i][j-1][0],dp[i][j][0]);
        
        // 1
        dp[i][j][1]=max(dp[i][j-1][0]+a[i][j],dp[i][j][1]);
        dp[i][j][1]=max(dp[i][j-1][1],dp[i][j][1]);

        // 2
        dp[i][j][2]=max(dp[i][j-1][1]+a[i][j],dp[i][j][2]);
        dp[i][j][2]=max(dp[i][j-1][2],dp[i][j][2]);

        // 3
        dp[i][j][3]=max(dp[i][j-1][2]+a[i][j],dp[i][j][3]);
        dp[i][j][3]=max(dp[i][j-1][3],dp[i][j][3]);        
        
      }
    }
  }
  /*for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      cout<<dp[i][j]<<" ";
    }
    cout<<"\n";
  }*/
  ans=max(dp[r-1][c-1][0],ans);
  ans=max(dp[r-1][c-1][1],ans);
  ans=max(dp[r-1][c-1][2],ans);
  ans=max(dp[r-1][c-1][3],ans);
  cout<<ans<<"\n";
  return 0;
}
int main(){
fast
        int t=1;
        // cin>>t; 
        T(t){
          solve();
        }
        return 0;
}       

Measured memory_bytes: 355612
import java.util.Scanner;
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();
		System.out.println((a-b+1)*(a-c+1));
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int n, k;
int a[2010], b[2010];
vector<int> G[2010];

int dist[2010];

void calc(int n, int p, int d){
    dist[n] = d;
    rep(i, 0, G[n].size()){
        if(G[n][i] == p) continue;
        calc(G[n][i], n, d + 1);
    }
}

signed main(){
    cin >> n >> k;
    rep(i, 0, n - 1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]]. push_back(b[i]);
        G[b[i]]. push_back(a[i]);
    }
    int ans = 2010, cnt = 0;
    if(k % 2){
        rep(i, 0, n - 1){
            cnt = 0;
            calc(a[i], b[i], 0);
            calc(b[i], a[i], 0);
            rep(j, 0, n){
                if(dist[j] > (k - 1) / 2) cnt++;
            }
            ans = min(ans, cnt);
        }
    }else{
        rep(i, 0, n){
            cnt = 0;
            calc(i, -1, 0);
            rep(j, 0, n){
                if(dist[j] > k / 2) cnt++;
            }
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
const ll mn=1e5+4;
ll a[mn];
int main() {
	ios_base::sync_with_stdio(false);
	ll n; scanf("%lld",&n);
	for (ll i=0;i<n;i++) {
		scanf("%lld",&a[i]);
	}
	ll extra=0;
	ll ans=0;
	for (ll i=0;i<n;i++) {
		ll sum=extra+a[i];
		ll take=sum/2;
		ans+=take;
		sum-=take*2;
		if (sum>0&&a[i]>0) extra=1;
		else extra=0;
		//printf("i:%lld sum:%lld take:%lld extra:%lld\n",i,sum,take,extra);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   if(a<b) {
       if(c<a){
           printf("%d %d %d\n",c,a,b);
       }
       else if(b<c){
           printf("%d %d %d\n",a,b,c);
       }
       else{
           printf("%d %d %d\n",a,c,b);
     } }
   else if(b<a){
       if(c<b){
           printf("%d %d %d\n",c,b,a);
       }
       else if(a<c){
           printf("%d %d %d\n",b,a,c);
       }
       else{
           printf("%d %d %d\n",b,c,a);
   }}
   else if(a<c){
       if(b<a){
           printf("%d %d %d\n",b,a,c);
       }
       else if(b<c){
           printf("%d %d %d\n",a,b,c);
       }
       else{
           printf("%d %d %d\n",a,c,b);
   }}
   else if(c<a){
       if(b<c){
           printf("%d %d %d\n",b,c,a);
       }
       else if(a<b){
           printf("%d %d %d\n",c,a,b);
       }
       else{
           printf("%d %d %d\n",c,b,a);
   }}
  else if(b<c){
       if(a<b){
           printf("%d %d %d\n",a,b,c);
       }
       else if(c<a){
           printf("%d %d %d",b,c,a);
       }
       else{
           printf("%d %d %d\n",b,a,c);
   }}
   else if(c<b){
       if(a<c){
           printf("%d %d %d\n",a,c,b);
       }
       else if(b<a){
           printf("%d %d %d\n",c,b,a);
       }
       else{
           printf("%d %d %d\n",c,a,b);
   }}
   return 0;
   }


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

int main()  {

long long int N , A , B;

cin >> N >> A >> B;

if((A-B)%2==0) cout << (B-A)/2 << endl;

else cout << min(A-1 , N-B) + 1 + (B-A-1)/2<< endl;


}

Measured memory_bytes: 256
n = int(input())
ans = []
count = 1
two = 1
for i in range(20):
    if two*2 <= n:
        count += 1
        ans.append([count-1,count,0])
        ans.append([count-1,count,two])
        two *= 2
    else:
        break

for i in range(count,0,-1):
    if n - pow(2,i-1) >= two:
        
        ans.append([i,count,n-pow(2,i-1)])
        n -= pow(2,i-1)
print(count,len(ans))
for i in ans:
    print(*i)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    set<string> U;
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
        U.insert(S[i]);
    }
    int M;
    cin >> M;
    vector<string> T(M);
    for (int i = 0; i < M; i++)
    {
        cin >> T[i];
        U.insert(T[i]);
    }
    int ans = 0;
    for (string str : U)
    {
        int s, t;
        s = count(S.begin(), S.end(), str);
        t = count(T.begin(), T.end(), str);
        if ((0 < (s - t)) && (ans < (s - t)))
        {
            ans = s - t;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
ll x[55], y[55];
std::map<std::pair<ll, ll>, int> mp;
int main() {
	std::cin >> n;

	for (int i = 0; i < n; ++i)
		std::cin >> x[i] >> y[i];

	for (int i = 0; i < n; ++i) {

		for (int j = 0; j < n; ++j) {
			auto xx = x[i] - x[j], yy = y[i] - y[j];
			if (xx != 0 || yy != 0)
				++mp[std::make_pair(xx, yy)];
		}
	}

	ll before = 0;
	for (auto& m : mp) {
		if (before < m.second) {
			before = m.second;
		}
	}

	std::cout << n - before << std::endl;
	return 0;
}


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

#define y1 hasjdnasd
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define t top()
#define pb push_back
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e2 + 5;
const int VAL  = 1e5 + 5;
int n , W , res;
int w[N] , v[N];
int dp[N][VAL];

main()
{
    //freopen("D.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> W;
    FOR(i , 1 , n)
        cin >> w[i] >> v[i];
    FOR(i , 1 , n)
        FOR(j , 0 , W)
            dp[i][j] = -1e16;
    dp[1][0] = 0;
    dp[1][w[1]] = v[1];
    FOR(i , 2 , n)
        FOR(j , 0 , W)
        {
            dp[i][j] = dp[i - 1][j];
            if(j >= w[i])
                dp[i][j] = max(dp[i][j] , dp[i - 1][j - w[i]] + v[i]);
        }
    FORD(j , W , 0)
        res = max(res , dp[n][j]);
    cout << res;
}


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

const int coins[] = {500, 100, 50, 10, 5, 1};
int main(){
  int m;
  while(cin >> m){
    if(m==0)break;

    m = 1000 - m;
    int res = 0;
    for(int i=0;i<6;i++){
      while(m >= coins[i]){
	res++;
	m -= coins[i];
      }
    }
    cout << res << endl;
  } 
}

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

int n,i;
long long int sum;
long long int pre,A,B,curr;
long long int t;
vector <long long int> v; //!!!
int main(){
    cin>>n;
    for(i=0;i<n+1;i++){
        cin>>t;
        v.push_back(t);
    }
    sum=0;
    pre=0;
    for(i=0;i<n;i++){
        cin>>t;
        A = v[i]-pre;
        B=t;
        curr=min(A,B);
        pre = min(max(B-A,(long long int)0),v[i+1]); //!!!!
        sum+=(curr+pre);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    string s;
    int k;
    cin >> k >> s;
    int n =s.size();
    if(n<=k){
        print(s);
    }
    else{
        print(s.substr(0,k)+"...");
    }
    return 0;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		int q = Integer.parseInt(reader.readLine());
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < q; i++) {
			if (subsetSum(Integer.parseInt(st.nextToken()), a)) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
		reader.close();
	}

	private boolean subsetSum(int s, int[] a) {
		int n = a.length;
		boolean[][] dp = new boolean[n+1][s+1];
		for (int i = 1; i <= n; i++) {
			int v = a[i-1];
			for (int j = 0; j <= s; j++) {
				if (v == j) {
					dp[i][j] = true;
				} else if (v > j) {
					dp[i][j] = dp[i-1][j];
				} else {
					dp[i][j] = dp[i-1][j] || dp[i-1][j-v];
				}
			}
		}
		return dp[n][s];
	}
}



Measured memory_bytes: 29396
class Node():
    def __init__(self, prv = None, nxt = None, val = None):
        self.prv = prv
        self.nxt = nxt
        self.val = val

class DoublyLinkedList():
    def __init__(self):
        self.head = Node(prv=None, nxt=None, val="H")
        self.cur_node = self.head
        self.tail = Node(prv=None, nxt=None, val="E")
        
    def insert(self, x):
        if self.cur_node == self.head:
            new_node = Node(prv=None, nxt=None, val=x)

            new_node.prv = self.head
            new_node.nxt = self.tail

            self.head.nxt = new_node
            self.tail.prv = new_node

            self.cur_node = new_node

        elif self.cur_node == self.tail:
            new_node = Node(prv=None, nxt=None, val=x)

            self.tail.prv.nxt = new_node

            new_node.prv = self.tail.prv
            new_node.nxt = self.tail
            
            self.tail.prv = new_node
            self.cur_node = new_node
            
        else:
            new_node = Node(prv=None, nxt=None, val=x)

            if self.cur_node.prv is self.head:
                new_node.prv = self.head
                self.head.nxt = new_node
            else:
                new_node.prv = self.cur_node.prv
                self.cur_node.prv.nxt = new_node
               
            if self.cur_node is not self.tail:
                new_node.nxt = self.cur_node
                self.cur_node.prv = new_node

            self.cur_node = new_node

    def move(self, d):
        if d > 0:
            for _ in range(d):
                if self.cur_node.nxt is not None:
                    self.cur_node = self.cur_node.nxt
        elif d < 0:
            for _ in range(-d):
                self.cur_node = self.cur_node.prv
            
    def erase(self):
        prv = self.cur_node.prv
        nxt = self.cur_node.nxt

        if prv is self.head:
            self.head.nxt = nxt
        else:
            prv.nxt = nxt

        nxt.prv = prv
        self.cur_node = nxt

    def dump(self):
        cur = self.head.nxt

        while True:
            if cur is self.tail :
                break
            
            print(cur.val)
            cur = cur.nxt

def main():
    dll = DoublyLinkedList()
    q = int(input())

    for _ in range(q):
        com, *para = map(int, input().split())

        if   com == 0:
            dll.insert(para[0])

        elif com == 1:
            dll.move(para[0])

        elif com == 2:
            dll.erase()
    dll.dump()
    
main()


Measured memory_bytes: 89088
#include<stdio.h>

main(void)
{
int h,m,s,t;
scanf("%d", &t);
h=t/3600;
t=t-h*3600;
m=t/60;
t=t-m*60;
s=t;
printf("%d:%d:%d\n", h,m,s);
return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
unsigned short *A, *B;
int C[VMAX+1];
int n, i, j;
void CountingSort(){
  for(i = 0;i < VMAX;i++){
    C[i] = 0;
  }
  
  for(j = 0;j < n;j++){
    C[A[j]]++;
  }
  for(i = 1;i < VMAX;i++){
    C[i] = C[i] + C[i-1];
  }
 
  for(j = n-1;j >= 0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

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

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
  for(i=0;i < n;i++){
    scanf("%hd",&A[i]);
  }
  
  CountingSort();
  for(i=1;i < n;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[i]);
  
  return 0;
}



Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b,n;
  cin>>a>>b>>n;
  Int ans=abs(a-b);
  for(Int x=1;x<=n;x++){
    for(Int y=1;y<=n;y++){
      Int d=b*x-a*y;
      if(d%y!=0) continue;
      chmin(ans,abs(d/y));      
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  // read inputs
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b && b == c) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}


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

int main() {
	int q;
	cin >> q;
	while(q--){
		int c, a, n;
		cin >> c >> a >> n;
		int tmp, sum = 0;
		tmp = min( c, min( a, n ) );
		c-=tmp;	a-=tmp;
		sum = tmp;
		tmp = min( c/2, a );
		c-=tmp*2;
		sum += tmp;
		sum += c/3;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#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;
    list <int> l;
    int lll;
    rep(i,n){
        cin >> lll;
        l.push_back(lll);
    }
    l.sort();

vector <int> v;
for (list <int>::iterator it=l.begin(); it != l.end(); ++it)
    {
           v.push_back(*it); 
    }

//rep(i,n) cout << v[i] << endl;

int k;
int s;
int ans;
int kan;

ans=0;
rep(i,n-2){
    k=0;
    kan=0;
    s=i+2;
    rep(j,n-i-2){
        ans+=k;
        if(s<=j+i+1){
            s=j+i+2;
        }
        
        while((v[i]+v[i+j+1])>v[s]){
            //cout << v[i] << " " << v[i+j+1] << " " << v[s] << " " << ans <<endl;
            
            
            

            if(s==n-1){
                if (kan==0){
                kan=1;
                ++k;
                ++ans;
            }
                break;
            }
            ++ans;
            ++k;
            ++s;
            
        }
        if(k>0){
        --k;
        }
    }
}

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
// /**/
// #include <cstdio>
// #include <cstring>
// #include <cmath>
// #include <cctype>
// #include <iostream>
// #include <algorithm>
// #include <map>
// #include <set>
// #include <vector>
// #include <string>
// #include <stack>
// #include <queue>

// typedef long long LL;
// using namespace std;

// int n, st[1000005], top;
// LL dp[1000005];

// struct node
// {
// 	long x, y;
// 	int id;
// 	bool operator <(const node &rhs){
// 		LL temp = x * rhs.y - y * rhs.x;
// 		if(temp) return temp > 0;
// 		else return x * x + y * y > rhs.x * rhs.x + rhs.y * rhs.y;
// 	}
// }a[1000005];

// LL cross(node x, node y){
// 	return x.x * y.y - x.y * y.x;
// }

// int main()
// {
// 	//freopen("in.txt", "r", stdin);
// 	//freopen("out.txt", "w", stdout);

// 	scanf("%d", &n);
// 	for (int i = 1; i <= n; i++){
// 		scanf("%lld %lld", &a[i].x, &a[i].y);
// 		a[i].id = i;
// 		dp[i] = -1;
// 	}
// 	sort(a + 1, a + 1 + n);
// 	int b, c;
// 	scanf("%d", &b);
// 	for (int i = 1; i <= n; i++){
// 		if(a[i].id == b){
// 			c = i;
// 			break;
// 		}
// 	}
// 	dp[b] = 0, st[++top] = c;
// 	for (int i = c + 1; i <= n; i++){
// 		if(cross(a[c], a[i]) == 0) continue;
// 		while(top > 1 && cross(a[st[top - 1]], a[st[top]]) == 0) top--;
// 		while(top > 1 && dp[a[st[top]].id] + cross(a[st[top]], a[i]) > dp[a[st[top - 1]].id] + cross(a[st[top - 1]], a[i])) top--;
// 		dp[a[i].id] = dp[a[st[top]].id] + cross(a[st[top]], a[i]);
// 		st[++top] = i;
// 	}
// 	for (int i = 1; i <= n; i++) printf("%lld\n", dp[i]);

// 	return 0;
// }
// /**/


/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int n;
LL x, sum[100005], pos;

struct node
{
	LL b, l, r;
	bool operator <(const node &rhs)const{
		return (x - b) * r + l * b > (x - rhs.b) * rhs.r + rhs.l * rhs.b;
	}
}a[100005];

LL val(LL k, int i){
	if(k >= a[i].b) return (k - a[i].b) * a[i].r;
	return (k - a[i].b) * a[i].l;
}

LL max_val(int i){
	return (x - a[i].b) * a[i].r;
}

int fun(LL x, LL sum1){
	for (int i = 1; i < pos; i++){
		if(sum1 - max_val(i) + val(x, i) >= 0) return 1;
	}
	sum1 -= max_val(pos) - val(0, pos);
	for (int i = pos; i <= n; i++){
		if(sum1 + val(x, i) - val(0, i) >= 0) return 1;
	}
	return 0;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d %lld", &n, &x);
	for (int i = 1; i <= n; i++){
		scanf("%lld %lld %lld", &a[i].b, &a[i].l, &a[i].r);
	}
	sort(a + 1, a + 1 + n);
	LL sum1 = 0;
	for (int i = n; i >= 1; i--) sum[i] = sum[i + 1] - val(0, i);
	for (int i = 1; i <= n; i++){
		sum1 += max_val(i);
		if(sum1 >= sum[i + 1]) {pos = i; break;}
	}
	sum1 -= sum[pos + 1];
	LL l = 0, r = x, ans = x;
	while(l <= r){
		LL mid = (l + r) >> 1;
		if(fun(mid, sum1)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%lld\n", ans + (pos - 1) * x);

	return 0;
}
/**/

Measured memory_bytes: 3328
#26　AtCoder Beginner Contest 138 D - Ki
from collections import deque
n, q = map(int, input().split())
edge = [[] for _ in range(n)]
counter  = [0]*n
for _ in range(n-1):
    u, v = map(int, input().split())
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)
for _ in range(q):
    u, v = map(int, input().split())
    counter[u-1] += v
que = deque([0])
check = [0]*n
while que:
    k = que.pop()
    check[k] = 1
    for i in edge[k]:
        if check[i]: continue
        counter[i] += counter[k]
        que.append(i)
print(*counter)

Measured memory_bytes: 56168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b;
    int n,sum,i,j,m;

    while(scanf("%d %d",&n,&m)==2)
    {
        sum = 0;
        for(i=1;i<=n;i++)
        {
            scanf("%lf %lf",&a,&b);

            if(sqrt(a*a+b*b)<=m)sum++;

        }
        printf("%d\n",sum);
    }










return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b; cin >> a >> b;
	cout << (a*3 + b)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n;
    cin >> n;
    vector<ll> bik(171104);
    bik.at(0) = 1;
    for (ll i = 1; i < 171104; i++) {
        bik.at(i) = bik.at(i - 1) * i;
        bik.at(i) %= 1000000007;
    }
    vector<ll> fl(n);
    ll f = 0;
    for (int i = 0; i < n+1; i++) {
        ll k;
        cin >> k;
        if (fl.at(k - 1) == 0)fl.at(k - 1) = i + 1;
        else f = i - fl.at(k - 1);
    }
    f = n - f - 1;
    for (int i = 0; i < n; i++) {
        ll ans = bik.at(n) * modinv(bik.at(i + 1), 1000000007) % 1000000007 * modinv(bik.at(n - i - 1), 1000000007) % 1000000007;
        ans += bik.at(n-1) * modinv(bik.at(i), 1000000007) % 1000000007 * modinv(bik.at(n - i - 1), 1000000007) % 1000000007;
        ans %= 1000000007;
        if(f>=i)ans -= bik.at(f) * modinv(bik.at(i), 1000000007) % 1000000007 * modinv(bik.at(f-i), 1000000007) % 1000000007;
        ans += 1000000007;
        ans %= 1000000007;
        if (i != 0)ans += bik.at(n - 1) * modinv(bik.at(i - 1), 1000000007) % 1000000007 * modinv(bik.at(n - i), 1000000007) % 1000000007;
        ans %= 1000000007;
        cout << ans << endl;
    }
    cout << 1 << endl;
}

Measured memory_bytes: 3328
N = int(input())
A = N//1000
B = (N%1000)//100
C = (N%100)//10
D = N%10
opdict = {-1:'-', 1:'+'}
for op1 in (-1, 1):
  for op2 in (-1, 1):
    for op3 in (-1, 1):
      if op1*B + op2*C + op3*D == 7 - A:
        print(str(A)+opdict[op1]+str(B)+opdict[op2]+str(C)+opdict[op3]+str(D)+'=7')
        exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"



 
  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
	 long long a, b, k;
     cin >> a >> b >> k;
     if(k <= a){
		 cout << a-k << " " << b;
	 }
	 else if(k <= a+b){
		 cout << 0 << " " << b - (k-a);
	 }
	 else{
		 cout << 0 << " " << 0;
	 }

	
}


	



Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
s=input().rstrip("\n")
t=input().rstrip("\n")
cnt=[0]*len(s)
if len(s)>len(t):
    for i in range(len(s)-len(t)):
        for j in range(len(t)):
            if t[j]==s[i+j]:
                cnt[i]+=1
else:
    for i in range(len(s)):
        if t[i]==s[i]:
            cnt[0]+=1
print(len(t)-max(cnt))


Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

    ll ans = 1;
    FOR(i, 0, N) {
        ll t; cin >> t;
        ll g = __gcd(ans, t);

        ans = (t / g) * ans;
    }
    cout << ans << endl;
}




















































































Measured memory_bytes: 256