akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] str = (br.readLine()).split(" ");

			int H = 0;
			int W = 0;

			H = Integer.parseInt(str[0]);
			W = Integer.parseInt(str[1]);

			if (H == 0 && W == 0) {
				break;
			}
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {

					if (((i + 1) % 2 != 0) && ((j + 1) % 2 != 0)) {
						System.out.print("#");

					} else if (((i + 1) % 2 == 0) && ((j + 1) % 2 == 0)) {
						System.out.print("#");

					} else if (((i + 1) % 2 != 0) && ((j + 1) % 2 == 0)) {
						System.out.print(".");

					} else if (((i + 1) % 2 == 0) && ((j + 1) % 2 != 0)) {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}

	}
}

Measured memory_bytes: 31544
// Problem : B - Product Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=a*c;
	ckmax(ans,a*d);
	ckmax(ans,b*c);
	ckmax(ans,b*d);
	cout<<ans;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3692
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}
//priority_queue<int, vector<int>, greater<int> > que; //昇順

using namespace std;

const int mod=1e9+7;

int ans=0;

signed main(){
    SPEED;
    int r;
    cin >> r;
    cout << 3*r*r << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define GRAY  2 
#define WHITE 0
#define BLACK 1 

int n,color[110],d[110],f[110],time,adj[110][110];
void visit(int u){
int i;
color[u]=GRAY;
d[u]=++time;
 for(i=1;i<=n;i++){
   if(adj[u][i]==1){
     if(color[i]==WHITE) visit(i);
   }
 }
 color[u]=BLACK;
 f[u]=++time;

}
void dfs(int u){
  int i;
  for(i=1;i<=n;i++){
  color[i]=WHITE;
  time=0;
  }
  for(i=1;i<=n;i++){
    if(color[i]==WHITE) visit(i);
  }
}



int main(){

  int u,k,v,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      adj[u][v]=1;
    }
    dfs(u);
  }

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;



}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;

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

int ways3[7][7]={{1,0,0},{1,0,0},{0,2,2}};
int ways4[7][7]={{2,3,1,1},{2,3,4,4},{5,5,7,8},{6,6,7,8}};
int ways5[7][7]={{0,0,1,2,3},{0,0,1,2,3},{4,4,7,5,5},{6,6,7,0,10},{8,8,9,9,10}};
int ways6[7][7]={{0,0,0,1,2,3},{0,0,0,1,2,3},{4,5,6,0,0,0},{4,5,6,0,0,0},{7,7,8,8,9,9},{10,10,11,11,12,12}};
int ways7[7][7]={{0,0,0,0,1,2,3},{0,0,0,0,1,2,3},{0,0,0,0,4,5,6},{0,0,0,0,4,5,6},{7,7,8,8,0,0,11},{9,9,10,10,0,0,11},{12,12,13,13,14,14,0}};
int ans[N][N];

int n;

void work(int x,int y,int len,int a[7][7]) {
	for(int i=x;i<x+len;i++)
		for(int j=y;j<y+len;j++) ans[i][j]=a[i-x][j-y];
}

void print() {
	for(int i=0;i<n;i++,cout<<'\n')
		for(int j=0;j<n;j++) {
			if(!ans[i][j]) putchar('.');
			else putchar(ans[i][j]-1+'a');
		}
}

int main() {//
	cin>>n;
	if(n==2) { cout<<-1;return 0; }
	if(n==3) { work(0,0,3,ways3);print();return 0; }
	for(int i=0;i+7<n;i+=4) work(i,i,4,ways4);
	if(n%4==0) work(n-4,n-4,4,ways4);
	else if(n%4==1) work(n-5,n-5,5,ways5);
	else if(n%4==2) work(n-6,n-6,6,ways6);
	else if(n%4==3) work(n-7,n-7,7,ways7);
	print();
	return 0;
}


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

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int left[n+1], right[n+1];
    left[0] = right[0] = 0;
    
    rep(i,n){
        left[i+1] = left[i] + ((s[i]=='W')? 1 : 0);
        right[i+1] = right[i] + ((s[n-i-1]=='E')? 1 : 0);
    }
    // rep(i,n+1){
    //     cout << left[i] << "|" << right[i] << endl;
    // }
    
    int ans = INF;
    rep(i,n+1){
        ans = min(ans, left[i] + right[n-i]);
    }
    
    cout << ans << endl;

    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111];

int cnt[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];

    rep(i,N)cnt[A[i]]++;

    int ans=0;
    int d=0;
    rep(i,111111){
        if(!cnt[i])continue;
        ans++;
        d+=cnt[i]-1;
    }

    if(d&1)ans--;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define All(v) v.begin(),v.end()

using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;

    ll x = m/2;

    ll ans = min(n,x);

    if(n < x)
        m -= n*2;
    else
        m = 0;


    ans += m/4;

    cout << ans << endl;



    return 0;
}


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

using namespace std;

long long calc(vector<int> boxes, long long x) {
  int n = boxes.size();
  long long last = boxes[n - 1] + boxes[n - 2],
      ldiff = last - x,
      lsub = max(0ll, ldiff);
  boxes[n - 2] -= lsub;
  if (boxes[n - 2] < 0) {
    boxes[n - 1] += boxes[n - 2];
    boxes[n - 2] = 0;
  }
  long long result = lsub;
  for (int i = 0; i < n - 1; i++) {
    long long sum = boxes[i] + boxes[i + 1],
        diff = sum - x,
        sub = max(0ll, diff);
    boxes[i + 1] -= sub;
    if (boxes[i + 1] < 0) boxes[i + 1] = 0;
    result += sub;
  }
  return result;
}


signed main() {
  long long n, x;
  cin >> n >> x;
  vector<int> fwd(n), bck;
  for (auto& i : fwd) {
    cin >> i;
    bck.push_back(i);
  }
  reverse(begin(bck), end(bck));
  auto left = calc(move(fwd), x),
       right = calc(move(bck), x);
  cout << min(left, right) << endl;
}


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

int main(void){
	int n;
	
	cin>> n ;
	for(int i = 0 ; i < n ; i++){
		int a,b; char c;
		
		cin>>a>>c>>b;
//		cout<<a<<" "<<b<<endl;
		double A =a/12.0+b/60.0/12;
		double B =b/60.0;
		
		double judge =fabs(A-B);
//		if(180<judge)judge = 360.0 - judge;
//		cout<<judge<<endl;
	
		if(judge>0.5){
			judge = 1 - judge;
		}
		if(judge<30.0/360)cout<<"alert"<<endl;
		else if(judge<90.0/360)cout<<"warning"<<endl;
		else cout<<"safe"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = scn.nextInt();
		}
		boolean cont = true;
		int ans = 0;
		while (cont) {
			boolean ren = false;
			for (int i = 0; i < h.length; i++) {
				if (i == h.length - 1) {
					if (h[i] == 0) {
						if (ren) {
							ans++;
							ren = false;
						}
					} else {
						ren = true;
						h[i]--;
						ans++;
					}
				} else {
					if (h[i] == 0) {
						if (ren) {
							ans++;
							ren = false;
						}
					} else {
						ren = true;
						h[i]--;
					}
				}
			}
			cont = false;
			for(int i = 0;i < h.length;i++) {
				cont |= !(h[i]==0);
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("O3") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
#define __USE_MINGW_ANSI_STDIO 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include<stdio.h>
#include<iomanip>
#include<set>
#include<string>
#include<map>
#include <math.h>
#include<queue>
#include<complex>
#include<ctime>
#include<list>
#include<stack>
#define ll  long long
#define lll __int128
#define fi first
#define ld long double
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<vector<int>>
using namespace std;
int k;
string s;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
   cin >>k >> s;
   if(s.size() <= k)
        cout << s;
    else
        cout << s.substr(0,k) <<"...";
  return  0;    
}

Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
	    StringBuilder out;

		int a = sc.nextInt();
		int b = sc.nextInt();

		int gcd = getGCD(a, b);
		System.out.println(gcd);

	}


	static int getGCD(int a, int b) {

		int gcd = 0;
		int x = Math.max(a, b);
		int y = Math.min(a, b);
		int rest = x % y;

		if(rest == 0) {
			return y;
		}

		for(int i = rest; i > 0; i--) {

			if(y % i == 0 && rest % i == 0) {
				return i;
			}
		}

		return 0;
	}
}


Measured memory_bytes: 26404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define F first
#define S second
//参考:https://pyteyon.hatenablog.com/entry/2019/03/11/200000
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        siz.assign(sz_, 1LL);  // assign: 再代入
        par.resize(sz_);  // resize: 再確保
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        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)];
    }
};
int main(void){
    ll n,m; cin>>n>>m;
    vector <pair <ll,ll>> bridges(m);
    for(int i=0;i<m;i++){
        ll a,b; cin>>a>>b;
        --a; --b;
        bridges[i]=make_pair(a,b);
    }
    UnionFind uf(n);
    vector<ll> ans(m);
    ans[m-1] = (n*(n-1))/2;
    
   
    for(ll i= m-1; i >= 1; i--){
        if(uf.issame(bridges[i].F, bridges[i].S)){
            ans[i-1] = ans[i];
        }else {
            ans[i-1] = ans[i] - (uf.size(bridges[i].F) * uf.size(bridges[i].S));
            uf.merge(bridges[i].F,bridges[i].S);
        }
    }
    for(int i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 1000000001


int a,b,c,x,y;
// int dp[100001][100001];

int main(void){
    cin >> a >> b >> c >> x >> y;
    // int res = MAX;
    // dp[1][0] = 1500;
    // dp[0][1] = 2000;
    // dp[1][1] = 3200;
    int ans = MAX;
    REP(i,0,(x+y+1)) {
        ans = min(i * 2*c + max(0,x-i)*a + max(0,y-i)*b,ans);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
vector<int> a[50];
map<LL, LL>mp;
int n, k, x, y;
int main(){
//    IN;
    SCC(n, k);
    FF(i, 1, n){
        SC(x);
        SC(y);
        if(mp.count(x) == 0){
            a[31].PB(x);
            mp[x] = y;
        }
        else mp[x] = mp[x] + y;
    }
    LL ans = 0;
    for(int p = 30; p >= 0; --p){
        if((k & (1 << p)) == 0){
            for(int x : a[p + 1]){
                if((x & (1 << p)) == 0) a[p].PB(x);
            }
            continue;
        }
        LL s = 0;
        for(int x : a[p + 1]){
            if((x & (1 << p)) == 0) s += mp[x];
            a[p].PB(x);
        }
        if(s > ans) ans = s;
    }
    LL s = 0;
    for(int x : a[0]) s += mp[x];
    if(s > ans) ans = s;
    printf("%lld\n", ans);
}


Measured memory_bytes: 19448
#include<stdio.h>
#include<string.h>
#include<math.h>
#define pr(x) printf("%s %lld\n", #x , x)
int main()
{
    //freopen("in.txt", "w", stdout);
    long long n , k ;
    scanf("%lld %lld", &n  ,&k);
    long long remainder;
    if(k == 1) printf("0\n");
    else{
        remainder = n % k;
        long long m = (k - 1)/ 2;
        if(remainder <= m) printf("%lld\n", remainder);
        else printf("%lld\n",k - remainder);
    }
}   

Measured memory_bytes: 1728
import java.util.*;

public class Main {
    static Stack<Integer> sort; static boolean[] visited; static ArrayList<Integer> [] adj;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); int m = sc.nextInt();
        adj = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt(); int b = sc.nextInt();
            adj[a].add(b);
        }
        visited = new boolean[n+1]; ArrayList<Integer> order = new ArrayList<>(); sort = new Stack<>();
        for (int i = 1; i <= n; i++) {
            if (!visited[i]) {
                dfs(i);
            }
        }
        while (!sort.isEmpty()) order.add(sort.pop());
        int [] dp = new int[n+1]; ArrayList<Integer> [] rev = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) rev[i] = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            for (Integer j: adj[i]) {
                rev[j].add(i);
            }
        }
        long ans = 0;
        for (int i = 0; i < order.size(); i++) {
            int here = order.get(i);
            for (Integer come: rev[here]) {
                dp[here] = Math.max(dp[here], 1 + dp[come]);
            }
            ans = Math.max(dp[here], ans);
        }
        System.out.println(ans);
    }

    static void dfs(int cur) {
        visited[cur] = true;
        for (Integer next: adj[cur]) {
            if (!visited[next]) {
                dfs(next);
            }
        }
        sort.push(cur);
    }

}

Measured memory_bytes: 96784
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  int max = 0;
  int total = 0;
  for(int i=0;i<N;i++) {
    cin >> H[i];
    if(max<=H[i]) {
      total++;
      max = H[i];
    }
  }

  cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int totient(Int n){
  Int res = 1;
  if(n == 1)return 1;
  for(Int i = 2;i * i < n;i++){
    if(n % i)continue;
    n /= i;
    res *= (i-1);
    while(n % i == 0){
      res *= i;
      n /= i;
    }
  }
  if(n != 1)res *= n-1;
  return res;
}

int main(){
  Int n;
  cin >> n;
  cout << totient(n) << endl;
  return 0;
}


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

struct point {
    double x, y;
    point(double a, double b) {
        x = a, y = b;
    }
    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(k * x, k * y) ;
    }
    point operator / (double k) {
        return point(x / k, y / k);
    }
    double norm() {
        return x * x + y * y;
    }
    double abs() {
        return sqrt(norm());
    }
};

double dot(point a, point b) {
    return a.x * b.x + a.y * b.y;
}

double cross(point a, point b) {
    return a.x * b.y - a.y * b.x;
}

point project(point a, point base) {
    return base * (dot(a, base) / base.norm());
}

int main() {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    point p1(x1, y1);
    point p2(x2, y2);
    point base = p2 - p1;
    int n;
    scanf("%d", &n);
    rep(i, n) {
        int x, y;
        scanf("%d %d", &x, &y);
        point p(x, y);
        point hypo = p - p1;
        point m = p1 + project(hypo, base);
        point r = p + (m - p) * 2;
        printf("%.10lf %.10lf\n", r.x, r.y);
    }
}


Measured memory_bytes: 3216
import java.io.*;
public class Main {
	public static void main(String[] args){
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int ah,bh;
		int as=0,bs=0;
		int[] as_a=new int[10000];
		int[] bs_a=new int[10000];
		String[] s;
		int i=0;
		try{
			while(true){
				int n=Integer.parseInt(br.readLine());
				if(n==0) break;
				for(int j=0;j<n;j++){
					s=br.readLine().split(" ");
					ah=Integer.parseInt(s[0]);
					bh=Integer.parseInt(s[1]);
					if(ah>bh) as+=ah+bh;
					else if(ah<bh) bs+=ah+bh;
					else {as+=ah;bs+=bh;}
				}
				as_a[i]=as;bs_a[i++]=bs;
				as=0;bs=0;
			}
			for(int j=0;j<i;j++){
				System.out.println(as_a[j]+" "+bs_a[j]);
			}
		}catch(Exception e){
			System.out.println("Error");
		}
	}
}

Measured memory_bytes: 37664
N, K = map(int, input().split())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]


def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % mod


for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


A.sort()
ans = 0
for i, (n, x) in enumerate(zip(A, A[::-1])):
    if i < K-1:
        continue
    ans += n * cmb(i, K - 1)
    ans %= mod
    ans -= x * cmb(i, K - 1)
    ans %= mod
print(ans)


Measured memory_bytes: 105252
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    string s;
    cin>>s;
    for  (ll i=0;i<s.size()-8;i++){
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

//s.find_by_order(index);
//s.order_of_key(value);
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

ll solve(){
    string s;
    ll k; cin>>k>>s;
    if(sz(s) <= k){cout<<s;}
    else {
        lp(i,0,k) cout<<s[i];
        cout<<"...";
    }
    return 0;
}

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}  

Measured memory_bytes: 3652
def search(arr, start):
    s = set()
    s.add(start)
    for i in arr:
        ns = set()
        for j in s:
            ns.add(j+i)
            ns.add(j-i)
        s = ns
    return s

def main():
    t = 0
    xd, yd = [], []

    inst = list(input())
    x, y = list(map(int, input().split()))

    xcum = 0
    ycum = 0
    first = True

    startx = 0
    for s in inst:
        if s == 'T':
            t += 1
            t %= 2
            if first:
                startx = xcum
                xcum = 0
                first = False
                continue
            if xcum > 0:
                xd.append(xcum)
                xcum = 0
            if ycum > 0:
                yd.append(ycum)
                ycum = 0
        else:
            if t == 0:
                xcum += 1
            else:
                ycum += 1
    if first:
        startx = xcum
    elif xcum > 0:
        xd.append(xcum)
        xcum = 0
    if ycum > 0:
        yd.append(ycum)
        ycum = 0

    # print(startx)
    # print(xd, yd)
    # print(search(xd, startx), search(yd, 0))
    if x in search(xd, startx) and y in search(yd, 0):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define N 3010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forv(i, n)	for(int i = n - 1; i >= 0; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
 
const int inf = 1e9 + 1;
const ll modw = 1e9 + 7;
 
using namespace std;

int dp[N][N];

int main() {
	barnarnar
	string a, b;
	cin >> a >> b;
	forn1(i, a.si)
	{
		forn1(j, b.si)
		{
			if(a[i - 1] == b[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	string ans = "";
	int x = a.si, y = b.si;
	while(dp[x][y] > 0)
	{
		if(dp[x][y] == dp[x - 1][y])
			x--;
		else if(dp[x][y] == dp[x][y - 1])
			y--;
		else
		{
			ans = a[x - 1] + ans;
			x--;
			y--;
		}
	}
	cout << ans;
	return 0;
}

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

int main()
{
    long long n,m;
    std::cin >> n >> m;
    if(n >= m / 2){
        std::cout << m / 2 << std::endl;
    }else{
        long long res = 0;
        res += n;
        res += ( m - n * 2 ) / 4;
        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,m,x = myinput()
CA = mylistinput(n)

ans = INF
for i in range(2**n):
    cost = 0
    ls = [0]*m
    for j in range(n):
        if i & (2**j):
            c = CA[j][0]
            a = CA[j][1:]
            cost += c
            for k in range(m):
                ls[k] += a[k]
    if min(ls)>=x:
        ans = min( ans, cost )

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

Measured memory_bytes: 70616
N = int(input())

A_list = [0 for i in range(N)]

for i in range(N):
    ai = int(input())
    A_list[i] = ai

A_sorted = sorted(A_list)

maxA = A_sorted[-1]
second_maxA = A_sorted[-2]
# print(A_list)
for i in A_list:

    if i == maxA:
        print(second_maxA)
    else:
        print(maxA)


Measured memory_bytes: 14128
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (wrds toInt) >>= putStrLn

solve :: [Int] -> String
solve [a,b]
  | a > 0 = "Positive"
  | b < 0 = if even (b - a) then "Negative" else "Positive"
  | otherwise = "Zero"

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 508
using System;
using System.Linq;
class A
{
    static void Main()
    {
        int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int K = A[0];
        int X = A[1];
        for (int i = -1 + K ;i >= 0 - K + 1 ; i--)
        {
            Console.Write("{0} ", X - i);
        }
    }
}

Measured memory_bytes: 13268
//#pragma comment(linker,"/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int dx82[9] = { 0,-1,-1,1,1, 2,2,-2,-2 };
const int dy82[9] = { 0,2,-2,2,-2, 1,-1,1,-1 };
const int maxn = 2e5 + 50;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;

ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void extgcd(ll a,ll b,ll& d,ll& x,ll& y){ if(!b){ d=a; x=1; y=0;} else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }}
ll inverse(ll a,ll n){ ll d,x,y;extgcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}

void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

ll n;
ll v[maxn],pre[maxn];

ll getsum(ll le, ll ri) {
	return pre[ri] - pre[le-1];
}

void solve() {
	slla(n);
	repp(i,1,n) {
		slla(v[i]);
		pre[i] = pre[i-1] + v[i];
	}
	ll le = 1;
	ll ri = 3;
	ll res = pre[n];
	repp(i,2,n-2) {
		while(le < i && abs(getsum(1,le)-getsum(le+1,i)) >= abs(getsum(1,le+1)-getsum(le+2,i))) {
			le++;
		}
		while(ri < n && abs(getsum(i+1,ri)-getsum(ri+1,n)) >= abs(getsum(i+1,ri+1)-getsum(ri+2,n))) {
			ri++;
		}

		ll p1 = pre[le];
		ll p2 = pre[i] - pre[le];
		ll p3 = pre[ri] - pre[i];
		ll p4 = pre[n] - pre[ri];

		ll pmax = max(p1,max(p2,max(p3,p4)));
		ll pmin = min(p1,min(p2,min(p3,p4)));
		res = min(res, pmax - pmin);

	}
	cout<<res<<endl;
}

int main()
{

	solve();
    // system("pause");
    return 0;
}

Measured memory_bytes: 3328
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    if A[i] > B[i]:
        ans += B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        if i != N:
            if B[i] > A[i+1]:
                ans += A[i+1]
                A[i+1] = 0
            else:
                ans += B[i]
                A[i+1] -= B[i]
        A[i] = 0
        B[i] = 0
print(ans)

Measured memory_bytes: 19156
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Index> list = new ArrayList<>();
        while (sc.hasNext()) {
            String word = sc.next();
            int number = sc.nextInt();
            if (list.isEmpty()) {
                list.add(new Index(word, number));
            }else {
                boolean notMatch=true;
                for(Index i:list) {
                    if(i.word.equals(word)) {
                        i.pages.add(number);
                        notMatch=false;
                        break;
                    }
                }
                if(notMatch) {
                    list.add(new Index(word, number)); 
                }
            }
        }
        list.stream().sorted(Comparator.comparing(Index::getWord)).forEach(Index::print);
    }
}

class Index {
    String word;
    Set<Integer> pages = new TreeSet<>();

    Index(String word, int page) {
        this.word = word;
        this.pages.add(page);
    }
    String getWord() {
        return word;
    }
    void print() {
        System.out.println(word);
        System.out.println(pages.stream().map(Object::toString).collect(Collectors.joining(" ")));
    }
}


Measured memory_bytes: 33068
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	int n;
	string s, p;
	cin >> s;
	cin >> p;
	s += s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == p[0]) {
			for (int j = 0; j < p.size(); j++) {
				if (s[i + j] != p[j]) {
					break;
				}
				if (j == p.size() - 1) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 1188
#include <iostream>

using namespace std;



int main() {
	
	unsigned long long n, a, b;
	cin >> n >> a >> b;

	unsigned long long x = ((n / (a + b)) * a) + (a <= n % (a + b) ? a : n % (a + b));

	cout << x << endl;

	return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int a[10];
bool ok = false;

// これから入れるボールのindex，左の筒の一番上のボール，右の筒の一番上のボール
void dfs(int idx, int l, int r) {
  if (idx == 10) {
    ok = true;
    return;
  }
  int val = a[idx];
  if (l < val) dfs(idx + 1, val, r);  // 左の筒に入れる場合
  if (r < val) dfs(idx + 1, l, val);  // 右の筒に入れる場合
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    REP(i, 10) cin >> a[i];
    ok = false;
    dfs(0, -1, -1);
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 2e5 + 5;
const ll maxm = 3e3 + 5;
const ll cnt = 1e18;
const ll mod = 998244353;
inline void qread(){}
template<class T1, class ...T2>
inline void qread(T1 &IEE, T2&... ls){
    register T1 __ = 0, ___ = 1;
    register char ch;
    while(!isdigit(ch = getchar())) ___ = (ch == '-') ? -___ : ___;
    do{
        __ = (__ << 1) + (__ << 3) + (ch ^ 48);
    }while(isdigit(ch = getchar()));
    __ *= ___;
    IEE = __;
    qread(ls...);
    return ;
}
ll n, s;
ll a[maxn];
ll dp[maxm][maxm];
int main(){
    qread(n, s);
    ll p = 1;
    for(int i = 1;i <= n;i++){
        qread(a[i]);
        p *= 2;
        p %= mod;
        dp[i][0] = p;
    }
    dp[0][0] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= s;j++){
            if(j < a[i]){
                dp[i][j] = dp[i - 1][j] * 2;
                dp[i][j] %= mod;
            } else {
                dp[i][j] = dp[i - 1][j - a[i]] + dp[i - 1][j] * 2;
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}

Measured memory_bytes: 73988
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  
  vector<vector<int>> A(w,vector<int>(2*h+1,0));
  char c;
  rep(i,h){
    rep(j,w){
      cin>>c;
      A[j][h-1-i]=c-'0';
    }
  }
  
  ll ans=0;
  rep(i,w){
    rep(j,h){
      ll x=1,sum=0;
      vector<vector<int>> B(w,vector<int>(2*h+1,0));
      B=A;
      B[i].erase(B[i].begin()+j);
      rep(z,h){
        for(int s=h-1;s>=0;s--){
          vector<int> M(w,0);
          for(int t=0;t<=w-k;t++){
            bool b=true;
            if(B[t][s]==0) continue;
            for(int u=t+1;u<t+k;u++) if(B[u][s]!=B[t][s]) b=false;
            if(b) for(int u=t;u<t+k;u++) M[u]=1;
          }
          for(int t=0;t<w;t++){
            if(M[t]==1){
              sum+=x*B[t][s];
              B[t].erase(B[t].begin()+s);
            }
          }
        }
        x*=2;
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;
  
  return 0;
}

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

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

Measured memory_bytes: 3576
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int V[3010][3010];
int dp[3010][3010][10];

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

	int R, C, K; cin >> R >> C >> K;

	REP(i, 3005)REP(j, 3005)V[i][j] = -1;
	REP(i, K) {
		int r, c, v; cin >> r >> c >> v;
		r--;
		c--;
		V[r][c] = v;
	}


	REP(i, 3005)REP(j, 3005)REP(k, 5)dp[i][j][k] = 0;
	REP(i, R) {
		REP(j, C) {
			eREP(k, 3) {

				if (k != 3 && V[i][j] != -1) {
					if (k == 0)chmax(dp[i][j][k + 1], dp[i][j][k] + V[i][j]);

					if (j != 0 && j >= k)chmax(dp[i][j][k + 1], dp[i][j - 1][k] + V[i][j]);
					
				}
				if (i != R - 1) {
					chmax(dp[i + 1][j][0], dp[i][j][k]);
				}
				if (j != C - 1)chmax(dp[i][j + 1][k], dp[i][j][k]);
			}
		}
	}
	int ans = -INF;
	REP(k, 4)chmax(ans, dp[R - 1][C - 1][k]);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 780940
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1);
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//

const int maxN = 15;
int size_v, size_e;
vector<vector<int> > vv;
vector<vector<int> > g;
int dp[1 << maxN][maxN];

//----------//

int solve(int s, int v){
    if(dp[s][v] >= 0){
        return dp[s][v];
    }

    if(s == (1 << (size_v))-1 && v == 0){
        return dp[s][v] = 0;
    }


    int new_cost = INTINF;
    for(int u : vv[v]){
        if(!(s >> u & 1)){
            int tmp = solve(s | (1 << u), u) + g[v][u];
            if(tmp < new_cost){
                new_cost = tmp;
            }
        }
    }

    return dp[s][v] = new_cost;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//

    cin >> size_v >> size_e;
    vv.resize(size_v);
    g.resize(size_v);
    rep(i, size_v){
        g[i].resize(size_v);
    }

    rep(i, size_e){
        int s, t, d;
        cin >> s >> t >> d;
        vv[s].push_back(t);
        g[s][t] = d;
    }

    memset(dp, -1, sizeof(dp));
    int ans = solve(0, 0);
    if(ans == INTINF) cout << -1 << endl;
    else cout << ans << endl;

    
    return 0;
}



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

void fail(){
    cout << "No" << endl;
    exit(0);
}

int main(){
    int N, A[3];
    cin >> N >> A[0] >> A[1] >> A[2];
    vector<vector<int>> S(N);
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        for(char c : s) S[i].push_back(c-'A');
    }

    vector<vector<int>> nxt(N, vector<int>(3, N));
    vector<int> now(3, N);
    for(int i=N-1; i>=0; i--){
        nxt[i] = now;
        for(int j : S[i]) now[j] = i;
    }

    vector<int> ans;
    for(int i=0; i<N; i++){
        int a = S[i][0], b = S[i][1];
        if(A[a] == 0 && A[b] == 0) fail();
        if(A[a] > A[b] || (A[a] == A[b] && nxt[i][a] > nxt[i][b])) swap(a, b);
        ans.push_back(a);
        A[a]++;
        A[b]--;
    }

    cout << "Yes" << endl;
    for(int a : ans) cout << char('A'+a) << endl;
    return 0;
}


Measured memory_bytes: 14868
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

buff = []
# ll = []


for i in range(N):
    l_b = []
    for j in range(i+1, N):
        l_b.append(L[i]+L[j])
        # ll.append(L[i]+L[j])
    if i != N-1:
        buff.append(l_b)
# buff.sort()
# print(L)
# print(buff)

ans = 0
_len = len(buff)

for i in range(_len):
    for j in range(len(buff[i])):
        index = bisect.bisect_left(L[i+j+1+1:], buff[i][j])
        # print(L[i+j+1+1:])
        # print(index, buff[i][j])
        ans += index
print(ans)


# for i in range(N):
#     index = bisect.bisect_left(buff, L[i])
#     print(index)
#     ans += index
# print(ans)


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

unsigned long long dp[101][21];

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

	dp[1][num[0]] = 1;

	for(int i = 1; i < n - 1; i++){
		for(int j = 0; j <= 20; j++) {
			int plus = j + num[i];
			int minus = j - num[i];
	
			if(plus >= 0 && plus <= 20)
				dp[i + 1][plus] += dp[i][j];
			if(minus >= 0 && minus <= 20)
				dp[i + 1][minus] += dp[i][j];
		}
	}

	cout << dp[n - 1][num[n - 1]] << endl;

	return 0;
}

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

int main(){
    int num;
    cin>>num;
    if(num % 4 == 0){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(num % 7 == 0){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(num % 11 == 0){
        cout<<"Yes"<<endl;
        return 0;
    }
    else{
        int temp = num;
        while(temp >= 4){
            temp -= 4;
            if(temp % 7 == 0){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        while(num >= 7){
            num -= 7;
            if(num % 4 == 0){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;

}


Measured memory_bytes: 256
package main
import (
  "fmt"
  "math"
)
func main() {
  var x,n,y,z int64
  fmt.Scan(&x)
  n = int64(math.Floor(math.Sqrt(float64(1+8*x))))
  n = (n-1)/2
  if (n*(n+1))/2 == x {
    fmt.Println(n)
  } else {
    y = x - (n*(n+1))/2
    z = ((n+1)*(n+2))/2 - x
    if z <= n {
      //fmt.Println(n+y,n+1)
      fmt.Println(min(n+y,n+1))
    } else {
      //fmt.Println(n+y,n+2+z)
      fmt.Println(min(n+y,n+2+z))
    }
  }
}
func min(n int64,m int64) int64 {
  if n < m {
    return n
  } else {
    return m
  }
}

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

const long long inf = 1e18;

class Edge{
public:
  long long f, t, c;
  Edge(int x, int y, int z) : f(x), t(y), c(z){}
};

int main(){
  int n, m, p; cin >> n >> m >> p;

  vector<Edge> edge;
  for(int i=0; i<m; ++i){
    int a, b, c; cin >> a >> b >> c;
    edge.push_back(Edge(a-1, b-1, -c + p));
  }

  vector<long long> v(n, inf);
  v[0] = 0;
  for(int i=0; i<2*n; ++i){
    for(auto e : edge){
      if(v[e.f] >= inf) continue;

      if(v[e.t] > v[e.f] + e.c){
        if(i < n)
          v[e.t] = max(-inf, min(inf, v[e.f] + e.c));
        else
          v[e.t] = -inf;
      }
    }
  }

  if(v[n-1] == -inf) cout << -1 << endl;
  else cout << max(0LL, -v[n-1]) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> to[100005];
const int inf = 100000000;

int main() {
  int N,M;
  cin >> N >> M;
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(N,inf);
  vector<int> pre(N,-1);
  dist.at(0) = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(int u : to[v]){
      if(dist[u] != inf) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  
  cout << "Yes" << endl;
  
  for(int i=0;i<N;i++){
    if(i == 0) continue;
    int ans = pre[i];
    ans++;
    cout << ans << endl;
  }
  
  return(0);
}

Measured memory_bytes: 10732