akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 100010;
int res[MAXN], visited[MAXN];

int n, m, p, q, c;

vector< unordered_map<int, vector<int> > > adj;

queue<int> vq;
set<PII> vp;

void visit(int u) {
    visited[u] = 1;
}

void dfs(int u, int col, int val) {
    if (vp.find(MP(u, col)) != vp.end()) return;
    vp.insert(MP(u, col));

    if (res[u] == -1) {
        res[u] = val;
        vq.push(u);
    }

    for (auto& v : adj[u][col]) {
        dfs(v, col, val);
    }
}

int main() {
    GI(n); GI(m); adj.resize(n+1);

    FOR1(i, m) {
        GI(p); GI(q); GI(c);

        adj[p][c].PB(q);
        adj[q][c].PB(p);
    }

    vq.push(1);

    memset(res, -1, sizeof res); res[1] = 0;

    while (vq.size() > 0) {
        int u = vq.front(); vq.pop();

        for (auto& cp : adj[u]) { // cp.FF is color, cp.SS is children
            dfs(u, cp.FF, res[u] + 1);
        }
    }

    cout << res[n] << "\n";

    return 0;
}


Measured memory_bytes: 62336
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS
int binpow(int a,int b) {
    if(b == 0) return 1;
    if(b&1) return a*binpow(a,b-1);
    return binpow(a,b/2)*binpow(a,b/2);
}
vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n,k;
cin>>n>>k;
vector<bitset<50>> v(n);
FOR(i,0,n){
    int a;
    cin>>a;
    v[i] = a;
}
int ans = 0;
// cout<<v[0]<<endl;
for(int i=49;i>=0;i--) {
    int cnt = 0;
    FOR(j,0,n) if(v[j][i] == 1) cnt++;
    int val = binpow(2,i);
    if(n-cnt>cnt && k>=val) ans+=val*(n-cnt),k-=val;
    else ans+=val*cnt;
}
cout<<ans;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (ll i=0;i<(n);i++)
using namespace std;
#define vecout(v) for(int i=0;i<v.size();i++) {cout<<v[i]<<endl;}
typedef long long ll;
ll INF=1e10;
int main(void){
    int n, k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i, n) cin>>h[i];
    sort(h.begin(), h.end());
    ll ans=INF;
    for(int i=0;i<=n-k;i++){
        ans=min(ans, h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>

int main(void)
{
    int A,B,N;
    scanf("%d%d%d",&N,&A,&B);
    if(N==1)
    {
        if(A==B)
            printf("1\n");
        else
            printf("0\n");
    }
    else 
    {
        if(A>B)
            printf("0\n");
        else
            printf("%lld\n",(long )(B-A)*(N-2)+1);
    }
    return 0;
}

Measured memory_bytes: 128
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
A = np.array(list(map(int, sys.stdin.readline().split())))

ans = 0
while (A % 2).sum() == 0:
    A //= 2
    ans += 1
print(ans)


Measured memory_bytes: 13648
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
g=0
ans=0
S.each do|c|
  case c
  when "g" then
      if g>0
          ans+=1
          g-=1
      else
          g+=1
      end
  when "p" then 
      if g>0
          g-=1
      else
          ans-=1
          g+=1
      end
  end
end
puts ans

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

long double a,b;

int main()
{
	cin>>a>>b;
	LL tmp=(LL)(a*b);
	if((long double)tmp>(long double)a*b) cout<<tmp-1<<endl;
	else cout<<tmp<<endl;
	return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sync ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD  1000000007 
int powm(int base,int exp,int mod=MOD) {int ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
int32_t main()
{
	string s;
	cin>>s;
	int n=s.length();
	int i=0,j=n-1;
	int count=0;
	for(int i=0;i<n/2;i++)
	{
		if(s[i]==s[j-i]) continue;
		else
			count++;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    string s; cin >> s;

    int count_t = 0, count_s = 0;

    rep(i, s.size()){
        if(s[i] == 'T'){
            if(count_s == 0) count_t++;
            else count_s--;
        }else count_s++;
    }
    cout << count_t + count_s << endl;
}

Measured memory_bytes: 3704
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class APassword {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        out<<N*N*N<<'\n';
    }
};


int main() {
	APassword solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d, e;
    while (1) {
        cin >> d >> e;
        if (d == 0) break;
        double nin = 1e9;
        for (int x = 0; x <= d; x++) {
            int y = d - x;
            nin = min(nin, abs(hypot(x, y) - e));
        }
        printf("%.10f\n", nin);
    }
}


Measured memory_bytes: 3192
#include "bits/stdc++.h"
using namespace std;
typedef long long int lli;
#define pb push_back



int main() {
	int n;
	cin >> n ;
	std::vector<int > v(n);

	int val =0;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin >> v[i];
		val = val ^ v[i];
	}

	for (int i = 0; i < n; ++i)
	 {
	 	int ans = val ^ v[i];
	 	cout << ans << " ";
	 } 
	 cout << endl;

	/*for (int i = 0; i < n; ++i)
	{
		
		int  val = 0;
		for (int j = 0; j < n; ++j)
		{
			if(i!=j){
				val = val ^ v[j];
			}
		}
		cout << val <<" " << endl;
	}
	*/


}
	

Measured memory_bytes: 4020
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int X;
  cin >> X;
  vector<int> k(360);
  for (int i=0; i<360; i++) {
    k[i]=5000;
  }
  for (int j=0; j<360; j++) {
    if (((j+1)*X)%360==0) {
      k[j]=j+1;
    }
  }
  sort(k.begin(),k.end());
  cout << k[0] << endl;
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;



/// Info.
///****************************************************************************************************************************************///
/// author                : BAHAA El-DEEN OSAMA .
/// Problem name          : P - One Quadrillion and One Dalmatians
/// Method                : brute force
/// Online judge          : vjudge(Contest)
/// Date                  : 8/7/2020
///****************************************************************************************************************************************///

typedef long long ll ;
typedef unsigned long long ull ;

ll n;
string str = "";

int main()
{

    cin >> n;
	while (n)
    {
		int s = (n-1) % 26;
		str = (char)('a' + s) + str;
		n = (n-1)/ 26;
	}
	cout << str << endl;

	   return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
	int a[3];

	cin >> a[0] >> a[1] >> a[2];

	int c5 = 0;
	int c7 = 0;
	for (int i = 0; i < 3 ; i++) {
		if (a[i] == 5) c5++;
		if (a[i] == 7) c7++;
	}

	if (c5 == 2 && c7 == 1) {
		cout << "YES";
	} else {
		cout << "NO";
	}
	cout << endl;

	return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

using ll = long long;

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int rem = s - i - j;
      if (rem >= 0 && rem <= k)
        ans += 1;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

#define EPS 1e-10

int main()
{
	int N;
	double D;
	cin >> N >> D;
	int ans = 0;
	rep(i, N) {
		double X, Y;
		cin >> X >> Y;
		auto d = sqrt(X*X + Y*Y);
		clog << d << endl;
		if (d - D < EPS)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#define rep(i, n) for (int i=0; i < n; i++)
using namespace std;

int main() {
	int input[3], count5=0, count7=0;
	rep(i, 3) {
        cin >> input[i];
        if (input[i] == 5) {
            count5 ++;
            continue;
        }
        if (input[i] == 7) {
            count7 ++;
            continue;
        }
    }
    if (count5 == 2 && count7 == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static String solve() {
		int[] cnt = new int[101];
		while (true) {
			int a = in.nextInt();
			int b = in.nextInt();
			if (a + b == 0) break;
			cnt[a]++;
			cnt[b]++;
		}

		for (int i=3; i<101; i++) {
			if (cnt[i]%2 != 0) {
				return "NG";
			}
		}

		return cnt[1]%2 == 1 && cnt[2]%2 == 1 ? "OK" : "NG";
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(in.hasNext()) out.println(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 33008
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int i;
  for(i = 1;i <= n;i++){
   if (i%3 == 0) {
    System.out.printf(" " + i);
   }else if(i%10 == 3){
      System.out.printf(" " + i);
   }else{ 
    int x = i;
    while(x > 10){
     x= x/10;
     if(x%10 == 3){
      System.out.printf(" " + i);
      break;
     }
    }
   }
  }
 System.out.println("");
 }
}

Measured memory_bytes: 30892
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> e[n];
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        e[a-1].emplace_back(b-1);
        e[b-1].emplace_back(a-1);
    }
    vector<long long> x(n, 0);
    for (int i = 0; i < m; i++) {
        int p; long long q; cin >> p >> q;
        x[p-1] += q;
    }
    queue<int> q; q.push(0);
    vector<bool> flag(n, false);
    while (!q.empty()) {
        int from = q.front(); q.pop();
        flag[from] = true;
        for (auto to: e[from]) {
            if (flag[to]) continue;
            x[to] += x[from];
            q.push(to);
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << x[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 16372
#include <stdio.h>
#include <string.h>
#define min(a, b) ((a) < (b)) ? (a) : (b)
#define max(a, b) ((a) > (b)) ? (a) : (b)

int main(int argc, const char *argv[])
{
  char s[100001];
  int zero = 0, one = 0;
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0') zero++;
    if (s[i] == '1') one++;
  }
  int ans;
  if (zero == 0 || one == 0)
    ans = 0;
  else
    ans = min(zero, one);
  printf("%d\n", ans * 2);

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char ha[1<<21],k[256];
int main(int argc,char *argv[]){
    int flg;
    int val,s,t;
    char c;
    k['T'] = 1;
    k['G'] = 2;
    k['C'] = 3;
    k['A'] = 4;
    
    scanf("%d", &val);
    getchar();
    while (val--) {
        s = 0;
        t = 1;
        flg = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = k[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if (flg) ha[s] = 1; else puts( ha[s] ? "yes" : "no" );
    }
    return 0;
}

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

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

  ll ans = (ll)1e18;
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum += a[i];
    ans = min(ans, abs(total - 2 * sum));
  }

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


Measured memory_bytes: 4300
A,B = map(int,input().split())
import math
A_se = set()
B_se = set()

for i in range(math.ceil(A/0.08),math.ceil((A+1)/0.08)):
    A_se.add(i)

for i in range(math.ceil(B/0.1),math.ceil((B+1)/0.1)):
    B_se.add(i)

C = A_se & B_se
if len(C)==0:
    print(-1)
else:
    print(min(C))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, K;
	cin >> N >> K;

	vector<int> V(N);
	for (int i = 0; i < N; i++)
		cin >> V[i];

	int ans = 0;
	for (int l = 0; l <= K; l++)
	{
		for (int r = 0; r <= K-l; r++)
		{
			if (l + r > N)
				break ;

			int sum = 0;
			vector<int> S;
			for (int i = 0; i < l; i++)
			{
				sum += V[i];
				S.push_back(V[i]);
			}
			for (int i = N-1; i > N-1-r; i--)
			{
				sum += V[i];
				S.push_back(V[i]);
			}
			sort(all(S));

			int d = K - (l+r);
			for (int i = 0; i < min(d, (int)S.size()); i++)
			{
				if (S[i] < 0)
					sum -= S[i];
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  long long X,K,D,tmp=0;
  cin>>X>>K>>D;
  X=abs(X);
  D=abs(D);
  tmp=X/D;
  if(K<=tmp){X=X-D*K;K=0;}
  else{X=X-D*tmp;K=K-tmp;}
  if(K%2==0){cout<<X<<endl;}else{cout<<abs(X-D)<<endl;}
}

Measured memory_bytes: 3628
def solve():
    n = int(input())
    t1, a1 = map(int, input().split())
    ans = t1 + a1
    for i in range(n - 1):
        t, a = map(int, input().split())
        t1 = (t1 + t - 1) // t * t
        a1 = (a1 + a - 1) // a * a
        if t1 < a1 * t // a:
            t1 = a1 * t // a
        elif a1 < t1 * a // t:
            a1 = t1 * a // t
        ans = t1 + a1
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,k,n,l;
	cin>>n>>l;
	string s[n];
	for(i=0;i<n;i++)
		cin>>s[i];
	sort(s,s+n);
	for(i=0;i<n;i++)
		cout<<s[i];
	return 0;
} 

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N;
int A[310][310];
int dis[310][310];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, N) REP(j, N) cin >> A[i][j];
  MINF(dis);
  REP(i, N) dis[i][i] = 0;
  int ans = 0;
  REP(i, N) REP(j, N) if (i < j) {
    bool is_edge = true;
    REP(k, N) if (k != i && k != j && A[i][k] + A[k][j] == A[i][j]) is_edge = false;
    if (is_edge) {
      dis[i][j] = dis[j][i] = A[i][j];
      ans += A[i][j];
    }
  }
  REP(k, N) REP(i, N) REP(j, N) {
    CHMIN(dis[i][j], dis[i][k]+dis[k][j]);
  }
  REP(i, N) REP(j, N) if (dis[i][j] != A[i][j]) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////

int P, Q, A[100 + 2];
int dp[100 + 1][100 + 2];

int main() {

	double L;
	cin >> L;

	double ans = pow(L/3,3);

	printf("%.10f\n", ans);

	return 0;
}

Measured memory_bytes: 384
from itertools import combinations as comb
def get_ans(m, n):
    ans = sum(1 for nums in comb(range(1, min(m+1,n-2)), 3) if sum(nums)==n)
    return ans
      
while True:
    m, n = (int(x) for x in input().split())
    if m==0 and n==0:
        quit()
    ans = get_ans(m, n)
    print(ans)


Measured memory_bytes: 5644
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll n, a, b; cin >> n >> a >> b;
	if( a % 2 == b % 2 ){
		cout << (b-a)/2 << endl;
	} else {
		cout << min(a, n-b+1) + (b-a-1)/2 << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int DigitsSum(int N) {
	int sum = 0;
	int tmp = N;
	while (tmp != 0) {
		sum += tmp % 10;
		tmp /= 10;
	}
	return sum;
}
int main() {
	int N;
	cin >> N;
	int ans = 900;
	for (int i = 1; i <= N - i; i++) {
		int A = i, B = N - i;
		int sum = DigitsSum(A) + DigitsSum(B);
		if (ans > sum) ans = sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int h = s.nextInt();
		int w = s.nextInt();
		int i = 0;
		int j = 0;


		String[] ary2 = new String[h];

		for (i = 0; i<h; i++) {
			String str = s.next();
			ary2[i] = str;
			System.out.println(ary2[i]);
			System.out.println(ary2[i]);


		}


	}
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
int M;
  cin>>M;
  cout<<(24-M)+24;
 return 0;
}
/*


*/


Measured memory_bytes: 256
A,B,C = (0,1,5,4),(1,2,4,3),(2,0,3,5)
D = (-1,3)

f = input().split()

for i in range(int(input())):
    t, s = map(f.index, input().split())
    if t in A and s in A:
        print(f[2]) if A.index(t) - A.index(s) in D else print(f[3])
    if t in B and s in B:
        print(f[0]) if B.index(t) - B.index(s) in D else print(f[5])
    if t in C and s in C:
        print(f[1]) if C.index(t) - C.index(s) in D else print(f[4])

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

int main() {
	char b; cin >> b;
	if (b == 'C') cout << 'G' << endl;
	else if (b == 'G') cout << 'C' << endl;
	else if (b == 'A') cout << 'T' << endl;
	else cout << 'A' << endl;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n, a[4], b[4];
long long f[25000005];

long long DP(int n) {
	for (int i = 0; i <= n; ++i) {
		f[i] = 0;
	}
	for (int i = 1; i <= 3; ++i) {
		for (int j = a[i]; j <= n; ++j) {
			f[j] = std::max(f[j], f[j - a[i]] + b[i] - a[i]);
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		ans = std::max(ans, f[i]);
	}
	return n + ans;
}

int main() {
	read(n);
	for (int i = 1; i <= 3; ++i) {
		read(a[i]);
	}
	for (int i = 1; i <= 3; ++i) {
		read(b[i]);
	}
	n = DP(n);
	std::swap(a, b);
	print(DP(n));
}


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

int X[500][500];
int Y[500][500];

int main() {
	int H,W,cnt;
	cin>>H>>W;
	cnt=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>X[i][j];
			if(X[i][j]%2==0)X[i][j]=-1;
			else X[i][j]=1;
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(X[i][j]<1 || j == W-1 && i == H-1) continue;
			if(j==(W-1)){
				X[i][j]*=-1;
				X[i+1][j]*=-1;
				Y[i][j]=2;
				cnt++;
			}else{
				X[i][j]*=-1;
				X[i][j+1]*=-1;
				Y[i][j]=1;
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(Y[i][j]==2){
				cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
			}else if(Y[i][j]==1){
				cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
			}
		}
	}
	return 0;
}

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

using namespace std;

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

const int maxn = 100003;

struct Node
{
	int fro, to, bh, col;
} p[maxn];
struct IN
{
	int ds, idx;
} in[maxn];
int n, tot, head[maxn], ver[maxn * 2], nxt[maxn * 2];
int cnt;
map <pair <int, int>, int> ap;

inline bool cmp(IN x, IN y) {return x.ds > y.ds;}

void dfs(int u, int f)
{
	int yy = 0;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = ver[i]; if (v == f) continue;
		++yy;
		//cout << "fa=" << f << "u=" << u << "v=" << v << "yy=" << yy << endl;
		if (yy == p[ap[make_pair(u, f)]].col) ++yy;
		p[ap[make_pair(u, v)]].col = yy;
		dfs(v, u);
	}
}

inline void add(int u, int v)
{
	p[++cnt].fro = u, p[cnt].to = v, p[cnt].bh = cnt;
	ap[make_pair(u, v)] = cnt;
	ap[make_pair(v, u)] = cnt;
	ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;
	ver[++tot] = u, nxt[tot] = head[v], head[v] = tot;
	++in[u].ds, ++in[v].ds;
}

int main()
{
	n = gi();
	for (int i = 1; i <= n; i+=1) in[i].idx = i;
	for (int i = 1; i < n; i+=1)
	{
		int u = gi(), v = gi();
		add(u, v);
	}
	sort(in + 1, in + 1 + n, cmp);
	printf("%d\n", in[1].ds);
	dfs(in[1].idx, 0);
	for (int i = 1; i < n; i+=1) 
	{
		printf("%d\n", p[i].col);
	}
	return 0;
}

Measured memory_bytes: 17280
import math

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

if (R-L) >= 2019:
  print(0)
else:
  l = L % 2019
  r = l + (R - L)
  if r >= 2019:
    print(0)
  else:
    all_e = []
    for i in range(r-l+1):
      for j in range(r-l-i):
        all_e.append((l+i)*(l+i+j+1))
    for i in range(len(all_e)):
      all_e[i] = all_e[i] % 2019
    print(min(all_e))

  

Measured memory_bytes: 83632
import collections
import sys

S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()

for i, j in enumerate(sys.stdin.readline()):
    if j == '\\':
        S1.append(i)
    elif j == '/':
        if S1:
            left_edge = S1.pop()
            new_puddle = i - left_edge
            while True:
                if S2:
                    if S2[-1] > left_edge:
                        S2.pop()
                        new_puddle += S3.pop()
                    else:
                        break
                else:
                    break
            S2.append(left_edge)
            S3.append(new_puddle)
        else:
            pass


print(sum(S3))

print(len(S3), *S3)

Measured memory_bytes: 8408
primes = [0, 0] + [1]*50020
for i in range(2, 225):
    if primes[i]:
        for j in range(i*i, 50022, i):
            primes[j] = 0
while True:
    try:
        n = int(input())
    except:
        break
    m, o = n-1, n+1
    while not primes[m]:
        m -= 1
    while not primes[o]:
        o += 1
    print(m, o)

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  string s; cin>>s;
  int n = s.size();

  vector<int> a;
  int t = 0;
  char b = '.';
  for (int i=0; i<n; i++) {
    if (i > 0) {
      if (b != s[i]) {
        a.push_back(t);
        t = 0;
      }
    }
    b = s[i];
    t++;
  }
  a.push_back(t);

  int ans = 0;
  int m = a.size();
  int x = 0;
  int y = 0;
  for (int i=0; i<m&&x<(n+1)/2; i++) {
    x += a[i];
  }
  for (int i=m-1; i>=0&&y<(n+1)/2; i--) {
    y += a[i];
  }
  debug(x, y);
  ans = min(x, y);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3896
//55
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  char g[8][8];
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      cin>>g[i][j];
    }
  }
  for(;;){
    bool f=false;
    for(int i=0;i<2;i++){
      const char *c="ox";
      int r[64]={};
      char n[64][8][8];
      for(int j=0;j<8;j++){
	for(int k=0;k<8;k++){
	  int x=j*8+k;
	  copy(g[0],g[8],n[x][0]);
	  if(g[j][k]=='.'){
	    for(int l=0;l<8;l++){
	      char t[8][8];
	      copy(n[x][0],n[x+1][0],t[0]);
	      int dx[]={0,1,1,1,0,-1,-1,-1};
	      int dy[]={1,1,0,-1,-1,-1,0,1};
	      for(int m=1;;m++){
		int ny=j+dy[l]*m;
		int nx=k+dx[l]*m;
		if(nx<0||ny<0||8<=nx||8<=ny||t[ny][nx]=='.')break;
		if(t[ny][nx]==c[i]){
		  r[x]+=m-1;
		  copy(t[0],t[8],n[x][0]);
		  break;
		}else{
		  t[ny][nx]=c[i];
		}
	      }
	    }
	    if(r[x]){
	      n[x][j][k]=c[i];
	    }
	  }
	}
      }
      if(i){
	reverse(r,r+64);
      }
      int m=max_element(r,r+64)-r;
      f|=r[m];
      if(i){
	m=63-m;
      }
      copy(n[m][0],n[m+1][0],g[0]);
    }
    if(!f)break;
  }
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      cout<<g[i][j];
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

const int MAX_N = 50;
const int MAX_X = 50;
int N, A, x[MAX_N];
ll dp[MAX_N + 1][MAX_N + 1][MAX_N * MAX_X + 1];

int main() {
    cin >> N >> A;
    for (int i = 0; i < N; i++)
        scanf("%d", &x[i]);

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= MAX_N * MAX_X; k++) {
                if (i == 0 && j == 0 && k == 0) dp[i][j][k] = 1;
                else if (i > 0 && k < x[i - 1]) dp[i][j][k] = dp[i - 1][j][k];
                else if (i > 0 && j > 0 && k >= x[i - 1])
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
                else dp[i][j][k] = 0;
            }
        }
    }
    
    ll ans = 0;
    for (int i = 1; i <= MAX_N; i++)
        ans += dp[N][i][i * A];

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int a, b;
int n;
int x[50], y[50];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        cin >> n;
        rep(i, n) cin >> x[i] >> y[i];
        ll dp[20][20] = {};
        dp[0][0] = 1;
        rep(i, b)rep(j, a) {
            bool ok = true;
            rep(k, n) {
                if (y[k] == i + 1 && x[k] == j + 1) {
                    ok = false;
                    break;
                }
            }
            if (!ok) continue;
            if (i > 0) dp[i][j] += dp[i - 1][j];
            if (j > 0) dp[i][j] += dp[i][j - 1];
        }
        cout << dp[b - 1][a - 1] << endl;
    }
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main()
{
  long long int a,b,c,d;
  cin>>a>>b>>c>>d;
  long long int p,q,r,s;
  p=a*c;
  q=a*d;
  r=b*c;
  s=b*d;
  cout<<max(p,max(q,max(r,s)));
  return 0;
}

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

int main(){
    long A,B,count=0;
    string temp1,temp2;
    cin >> A >> B;
    while(A<=B){
        temp1=to_string(A);
        temp2=temp1;
        reverse(temp2.begin(),temp2.end());
        if (temp1==temp2){
            count++;
        }
        A++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
Up = []
Down = []
for _ in range(N):
    S = input()
    L = [0]
    mi = 0
    now = 0
    for __ in range(len(S)):
        if S[__] == '(':
            now += 1
        else:
            now -= 1
            mi = min(mi, now)
    if now > 0:
        Up.append((mi, now))
    else:
        Down.append((mi - now, mi, now))

Up.sort(reverse=True)
Down.sort()

now = 0
for i, j in Up:
    if now + i < 0:
        print('No')
        exit()
    else:
        now += j
for _, i, j in Down:
    if now + i < 0:
        print('No')
        exit()
    else:
        now += j
if now == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 172460
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

ll p[maxn];
int a[maxn];
ll sum[maxn];

void gcd(ll a,ll b, ll& d,ll& x,ll& y){  //      已经测试 FZU 1402
  if(!b) {d=a;x=1;y=0;}
  else   {	gcd(b,a%b,d,y,x);	y-=a/b*x;}
}
ll inv(ll a,ll n)  { //无逆元返回-1
  ll d,x,y;	gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum[i] = sum[i-1] + a[i];
  }
  p[0] = 1;
  ll ret = 0;
  for(int i=1;i<=n;i++)p[i] = p[i-1] * i % mod;
  for(int i=2;i<=n-1;i++){
    ll tmp = p[n-1-i] * p[n-1]%mod * inv(p[n-1-i]*p[i]%mod, mod)%mod;
    tmp = tmp * p[i-2]%mod * ((sum[n-1] - sum[i-1] - sum[n-i])%mod)%mod;
    ret = (ret+tmp)%mod;
  }
  for(int i=1;i<n;i++){
    ll tmp = (a[n] - a[i])%mod;
    tmp = tmp * p[n-i-1] %mod*p[i-1]%mod;
    tmp = tmp *p[n-1]%mod*inv(p[n-i]*p[i-1]%mod, mod)%mod;
    ret = (ret + tmp)%mod;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 2176
#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[222222],B[222222];
int sum[111111],sum1[111111],sum2[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i]>>B[i];
    rep(i,N){
        sum[A[i]]++;
        sum[B[i]]--;

        sum1[A[i]]++;
        sum2[B[i]]++;
    }

    rep(i,111111-1){
        sum[i+1]+=sum[i];
        sum1[i+1]+=sum1[i];
        sum2[i+1]+=sum2[i];
    }

    int ans=0;
    rep(i,N){
        int tmp=0;
        tmp+=sum2[A[i]];
        tmp+=N-sum1[B[i]-1];
        chmax(ans,N-tmp);
    }

    cout<<ans<<" "<<*max_element(sum,sum+111111)<<endl;
    return 0;
}

Measured memory_bytes: 8812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans;
    if (k % 2 == 0) ans = a-b;
    else ans = b-a;
    if (abs(ans) > 1e18) cout << "Unfair" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int i=1; i<=n; i++) {
      int x=i;
      if(x%3==0) {
          cout << " " << x;
      }
      else {
          while(x>0) {
              if(x%10==3) {
                  cout << " " << i;
                  break;
              }
              x/=10;
          }
      }
  }
  cout << endl;
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct node{
	int x,y;
	int index,pre;
}a[N];
bool cmp(node a,node b){
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
bool cmp1(node a,node b){
	return a.index<b.index;
}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d %d",&a[i].x,&a[i].y);
		a[i].index=i;
	}
	sort(a+1,a+m+1,cmp);
	int cnt=1;
	int t=a[1].x;
	for(int i=1;i<=m;i++){
		if(a[i].x != t){
			t = a[i].x;
			cnt = 1;
			a[i].pre = cnt;
			cnt++;
		}
		else{
			a[i].pre = cnt;
			cnt++;
		}
	}
	sort(a+1,a+m+1,cmp1);
	for(int i=1;i<=m;i++){
		printf("%06d%06d\n",a[i].x,a[i].pre);
	}
	return 0;
} 

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

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

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	long long int n;
	cin >> n;
	long long int ans = 0;
	for(long long int i = 2; i*i <= n; i++) {
		if(n%i != 0) continue;
		long long int num = 0;
		while(n % i == 0) {
			n /= i;
			num += 1;
		}
		for(long long int j = 1; ; j++){
			if(num >= j) {
				num -= j;
				ans += 1;
			}else break;
		}
	}
	if(n != 1) {
		ans += 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (unsigned long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (unsigned long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    constexpr ll p = 1000000007;

    int n;
    cin >> n;
    vector<int> c(n);
    REP(i, n) cin >> c[i];

    for (int i = n; --i; ) {
        if (c[i] == c[i-1]) {
            n--;
            c.erase(c.begin() + i);
        }
    }

    vector<ll> dq(200100, 0);
    ll ans = 1;
    REP(i, n) {

        ll pans = ans;

        ans += dq[c[i]];
        ans %= p;

        dq[c[i]] += pans;
        dq[c[i]] %= p;

    }

    cout << ans << endl;
    
}

Measured memory_bytes: 2688
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

bool found(long double i, int a, int b) {
	int v1 = (i * 8) / 100;
	int v2 = (i * 10) / 100;

	if (v1 == a && v2 == b) {
		return 1;
	}

	return 0;
}

int main() {
	int a, b;

	cin >> a >> b;

	for (int i = b * 10; i < b * 10 + 10; ++i) {
		if (found(i, a, b)) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L, R, D;
    cin >> L >> R >> D;
    int now = D;
    int ans = 0;
    while (now < L) {
        now += D;
    }
    while (now <= R) {
        ++ans;
        now += D;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  cin>>n;
  string ans="No";
  if(n%4==0||n%7==0) cout<<"Yes"<<endl;
  else{
    while(n>0){
      if(n%4==0){
        ans="Yes";
      }
      n-=7;
    }
    cout<<ans<<endl;
  }
}

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

int main() {
  string S;
  cin>>S;
  int C=0,c=0,i;
  for (i=0;i<S.size();i++) {
    if (S[i]=='R') {
      c++;
      C = max(C, c);
    }
    else c=0;
  }
  cout<<C<<endl;
  return 0;
}


Measured memory_bytes: 3140