akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

const int MAX = 1000;
ll fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    ll ans = 0;
    ans += comb(n, 2);
    ans += comb(m, 2);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	string s,t;
	int cnt = 0,i;
	cin>>s>>t;
	for(i=0;i<3;i++)
		if(s[i] == t[i])
			cnt++;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 764
def main():
    H, W = map(int, input().split())
    img = [input().split() for _ in range(H)]
    new_img = list()
    
    print("#" * (W + 2))
    for l in img:
        print("#" + "".join(l) + "#")
    print("#" * (W + 2))
main()

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

int main(){
    int a,b;
    cin>>a>>b;

    int ans=0;
    int outlet=1;
    while(outlet<b){
        outlet--;
        outlet+=a;
        ans++;
    }
   cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll X;
    ll money = 100;
    cin >> X;
    int year = 0;
    while(true) {
        money = money + money / (ll)100;
        year++;
        if (money >= X) {
            cout << year << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3636
function Main(input) {
  var list = input.split("\n").map(s => parseInt(s, 10));
  var ans = 0;
  var last = 10;
  
  for (i = 0; i < 5; i++) {
    ans += Math.ceil(list[i]/10);
    if (last > (list[i]-1)%10) last = (list[i]-1)%10;
  }
  
  console.log(ans * 10 - 9 + last);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
  while(1)
  {
    int c[7] = {}, n;
    cin >> n;
    if(!n)
      break;
    for(int i = 0; i < n; i++)
    {
      int a;
      cin >> a;
      c[min(a / 10, 6)]++;
    }
    for(int i = 0; i < 7; i++)
      cout << c[i] << endl;
  }
}

Measured memory_bytes: 1160
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const double EPS=1e-8;

const int N_MAX=3;
bool Gauss_Jordan(int n,const double A[N_MAX][N_MAX],const double *b,double *x){
	static double B[N_MAX][N_MAX+1];
	rep(i,n){
		rep(j,n) B[i][j]=A[i][j];
		B[i][n]=b[i];
	}

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[piv][i])) piv=j;
		rep(j,n+1) swap(B[i][j],B[piv][j]);

		if(abs(B[i][i])<EPS) return false;

		for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
	}

	rep(i,n) x[i]=B[i][n];
	return true;
}

int main(){
	int n; scanf("%d",&n);
	double sx=0,sy=0,sxx=0,sxy=0,syy=0,sxxx=0,sxxy=0,sxyy=0,syyy=0;
	rep(i,n){
		int x,y; scanf("%d%d",&x,&y);
		sx+=x;
		sy+=y;
		sxx+=x*x;
		sxy+=x*y;
		syy+=y*y;
		sxxx+=x*x*x;
		sxxy+=x*x*y;
		sxyy+=x*y*y;
		syyy+=y*y*y;
	}

	double A[3][3]={
		{sxx,sxy,sx},
		{sxy,syy,sy},
		{sx,sy,n}
	};
	double b[3]={-sxxx-sxyy,-sxxy-syyy,-sxx-syy},x[3];

	Gauss_Jordan(3,A,b,x);

	printf("%.9f %.9f %.9f\n",x[0],x[1],x[2]);

	return 0;
}

Measured memory_bytes: 1072
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt(),w = sc.nextInt();
    String a[] = new String[h];
    for(int i = 0;i<h;i++){
      a[i] = sc.next();
    }
    for(int i = 0;i<w+1;i++){
      System.out.print("#");
    }
    System.out.println("#");
    for(int i = 0;i<h;i++){
      System.out.println("#"+a[i]+"#");
    }
    for(int i = 0;i<w+1;i++){
      System.out.print("#");
    }
    System.out.println("#");
  }
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

int dfs(const int N, const int n, vector<int>& cnt, int digits=0) {
    if (n > N) return 0;
    int sum = 0;
    for (const int i : {3,5,7}) {
        if (digits==9) break;
        cnt[i]++;
        sum += dfs(N, n+i*pow(10,digits), cnt, digits+1);
        cnt[i]--;
    }
    if (cnt[3]&&cnt[5]&&cnt[7]) sum++;
    return sum;
}

void solve(long long N){
//    int answer = 0;
//    stack<int> s;
//    int n = 0, cntSum = 0;
//    vector<int> cnt(10);
//    vector<vector<int>> pows(10,vector<int>(10));
//    rep(i,0,10) for (const int j : {3,5,7}) pows[i][j] = j * pow(10, i);
//    s.push(0);
//    while (!s.empty()) {
//        int current = s.top();
//        s.pop();
//        if (N==575) debug(current);
//        if (current>=0) {
//            if (current!=0 && cntSum<10) {
//                n += pows[cntSum][current];
//                //n += current * pow(10,cntSum);
//                cnt[current]++;
//                cntSum++;
//                if (N==575) {
//                    debug(n);
//                }
//            }
//
//            if (n <= N && cnt[3]>0&&cnt[5]>0&&cnt[7]>0) answer++;
//
//            if (n <= N) {
//                for (const int j : {-3,3,-5,5,-7,7}) {
//                    s.push(j);
//                }
//            }
//        } else if (current<0) {
//            cntSum--;
//            cnt[-current]--;
//            n -= pows[cntSum][-current];
//            //n -= -current * pow(10,cntSum);
//        }
//    }
    vector<int> cnt(10);
    cout << dfs(N,0,cnt) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 4080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int A, B, K; cin >> A >> B >> K;
    set<int> ans;
    for (int i = A; i < A+K; i++) {
        if (i <= B) ans.insert(i);
    }
    for (int i = B; i > B-K; i--) {
        if (i >= A) ans.insert(i);
    }

    for (int t : ans) {
        cout << t << "\n";
    }


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		while ((n = sc.nextInt()) != 0 && (m = sc.nextInt()) != 0) {
			boolean[] flag = new boolean[n];
			int ptr = 0;
			int ptrbu = 0;
			int mCount = 0;
			int trueCount = 0;
			while (trueCount < n) {
				if (ptr < n) {
					if (!flag[ptr]) {
						mCount++;
						if (mCount == m) {
							flag[ptr] = true;
							trueCount++;
							ptrbu = ptr;
							mCount = 0;
						}
						ptr++;
					} else {
						ptr++;
					}
				} else {
					ptr = 0;
				}
			}
			System.out.println(ptrbu + 1);
		}
	}
}

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

int s[100005];


int main(){
	int n,m,tmp;
	long long f[100006];
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		cin>>tmp;
		s[tmp]=1;
	}
	f[1]=1;f[2]=2;
	if(s[1]==1)	{f[1]=0;f[2]=1;}
	if(s[2]==1)	f[2]=0;
	for(int i=3;i<=n;++i){
		if(s[i]==1)	f[i]=0;
		else		f[i]=(f[i-1]+f[i-2])%1000000007;
	}
	cout<<f[n];
}

Measured memory_bytes: 1408
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int t=Integer.parseInt(st.nextToken());
      	st = new StringTokenizer(br.readLine());
      	int y[]=new int[t];
      	int p=0;
      	while(st.hasMoreTokens())
        {
          y[p]=Integer.parseInt(st.nextToken());
          p++;
        }
      	Arrays.sort(y);
      	System.out.println(y[t-1]-y[0]);
    }
}

Measured memory_bytes: 21204
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  // "math"
)

// 行単位で読み込む場合
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Scan()
  N, _ := strconv.Atoi((strings.Split(sc.Text(), " "))[0])

  p := 0
  y := 0
  g := 0
  w := 0
  
  sc.Scan()
  for i := 0; i < N; i++ {
    get := (strings.Split(sc.Text(), " "))[i]
    if get == "P" && p == 0 {
      p++
    }
    if get == "Y" && y == 0 {
      y++
    }
    if get == "G" && g == 0 {
      g++
    }
    if get == "W" && w == 0 {
      w++
    }
  }

  if (p + y + g + w == 3) {
    fmt.Println("Three")
  }
  if (p + y + g + w == 4) {
    fmt.Println("Four")
  }

}

Measured memory_bytes: 768
import collections

N = int(input())
As = sorted(list(map(int, input().split())))
c = collections.Counter(As)

L = [0] * (10 ** 5 + 1)
M = [0] * (10 ** 5 + 1)
for (x, y) in c.items():
    L[x] = y

for i in range(0, (10 ** 5)):
    M[i] = L[i - 1] + L[i] + L[i + 1]

print(max(M))


Measured memory_bytes: 20764
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::sort;
struct rNode
{
    char name[11];
    int score,idx;
    bool operator<(const rNode & b) const
    {
        if(strcmp(name,b.name)==0)
            return score>b.score;
        else
            return strcmp(name,b.name)<0;
    }
};
int main(void)
{
    rNode *r;
    int i,N;
    scanf("%d",&N);
    r=new rNode [N];
    for(i=0;i<N;i++)
    {
        scanf("%s",r[i].name);
        scanf("%d",&r[i].score);
        r[i].idx=i+1;
    }
    sort(r,r+N);
    for(i=0;i<N;i++)
    {
        printf("%d\n",r[i].idx);
    }
    return 0;
}


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

int main(){
    int n,m;
    string word;
    vector<string> list;
    vector<int> list_counter;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> word;
        int j=0;
        if(i == 0 && list.size() == 1){
            list.at(0) = word;
            list_counter.at(0) = 1;
        }else{
            while(true){
                if(j == list.size()){
                    list.push_back(word);
                    list_counter.push_back(1);
                    break;
                }
                if(list.at(j) == word){
                    list_counter.at(j)++;
                    break;
                }
                j++;
            }
        }
    }
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> word;
        int j=0;
        while(true){
            if(j == list.size()){
                list.push_back(word);
                list_counter.push_back(-1);
                break;
            }
            if(list.at(j) == word){
                list_counter.at(j)--;
                break;
            }
            j++;
        }
    }
    int max=0;
    for(int i=0;i<list.size();i++){
        if(max < list_counter.at(i)) max = list_counter.at(i);
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll a, p;
    cin >> a >> p;
    p = p + (a*3);
    cout << (ll)(p/2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n[32]={1,1,1,2,1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << n[k-1] << endl;
  return 0;
}


Measured memory_bytes: 256
from heapq import*
def dijkstra(n,s,edge):
    g=10**6
    d=[10**18]*n
    used=[True]*n
    d[s]=0
    used[s]=False
    edgelist=[]
    for a,b in edge[s]:heappush(edgelist,a*g+b)
    while edgelist:
        minedge=heappop(edgelist)
        if not used[minedge%g]:continue
        v1=minedge%g
        c1=d[v1]=minedge//g
        used[v1]=False
        for c2,v2 in edge[v1]:
            if used[v2]:heappush(edgelist,(c1+c2)*g+v2)
    return d
def main():
    n,m,s,t,*z=map(int,open(0).read().split())
    e1,e2=[[[]for _ in range(n)]for _ in range(2)]
    for u,v,a,b in zip(*[iter(z)]*4):
        u-=1
        v-=1
        e1[u]+=(a,v),
        e1[v]+=(a,u),
        e2[u]+=(b,v),
        e2[v]+=(b,u),
    c1=dijkstra(n,s-1,e1)
    c2=dijkstra(n,t-1,e2)
    a=[]
    m=0
    for y,s in zip(c1[::-1],c2[::-1]):
        t=10**15-y-s
        if t>m:m=t
        a+=m,
    print(*a[::-1],sep='\n')
main()

Measured memory_bytes: 131256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int cnt[100001];
int main() {
	int N;
	cin >> N;
	rep(i, N) {
		int A;
		cin >> A;
		cnt[A]++;
	}
	bool OK = 1;
	if (N % 2 == 0) {
		for(int i=1;i<=N-1;i+=2) {
			if (cnt[i] != 2) {
				OK = 0;
				break;
			}
		}
	}
	else {
		for(int i=2;i<=N-1;i+=2) {
			if (cnt[i] != 2) {
				OK = 0;
				break;
			}
		}
		if (cnt[0] != 1) OK = 0;
	}
	if (OK) {
		LL ans = 1;
		rep(i, N / 2) {
			ans = (ans * 2) % MOD;
		}
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    REP(i, m) cin >> p[i] >> y[i];

    vector<vector<int>> s(n);
    REP(i, m){
        s[p[i]-1].pb(y[i]);
    }
    REP(i, n){
        sort(all(s[i]));
    }

    REP(i, m){
        int num = lower_bound(all(s[p[i]-1]), y[i]) - s[p[i]-1].begin() + 1;
        cout << setfill('0') << setw(12) << p[i] * 1000000 + num << endl;
    }
}

Measured memory_bytes: 8576
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll n;
    ll p[20],q[20];
    vll a,b;
    cin>>n;
    rep(i,n){
        cin>>p[i];
        a.pb(p[i]);
    }
    rep(i,n){
        cin>>q[i];
        b.pb(q[i]);
    }
    sort(all(a));
    sort(all(b));
    ll ca=0,cb=0;
    ll ansa,ansb;
    do{
        bool ok=1;
        rep(i,n){
            if(a[i]!=p[i]) ok=0;
        }
        ca++;
        if(ok) ansa=ca;
    }while(next_permutation(all(a)));
    do{
        bool ok=1;
        rep(i,n){
            if(b[i]!=q[i]) ok=0;
        }
        cb++;
        if(ok) ansb=cb;
    }while(next_permutation(all(b)));

    cout<<abs(ansa-ansb)<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 100;

int N;

int A[MAX_N + 1], B[MAX_N + 2];

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

    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> B[i];
    }

    for (int i = 1; i <= N; i++) {
        A[i] += A[i - 1];
    }
    for (int i = N; i >= 1; i--) {
        B[i] += B[i + 1];
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = max(ans, A[i] + B[i]);
    }

    /*
    for (int i = 1; i <= N; i++) {
        cout << "i = " << i << ", A = " << A[i] << ", B = " << B[i] << "\n";
    }
    */

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b[N],A,B,m,mna=1e9,mnb=1e9,ans;
int main()
{
	scanf("%d%d%d",&A,&B,&m);
	for (int i=1;i<=A;i++) scanf("%d",&a[i]), mna=min(mna,a[i]);
	for (int i=1;i<=B;i++) scanf("%d",&b[i]), mnb=min(mnb,b[i]);
	ans=mna+mnb;
	for (int i=1,x,y,z;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		ans=min(ans,a[x]+b[y]-z);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
h = list(map(int, input().split()))
res = [0] * n

"""
0: 初期値
1: highest
-1: not highest
"""
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    if h[a] > h[b]:
        if res[a] == 0:
            res[a] = 1
        res[b] = -1
    elif h[a] < h[b]:
        res[a] = -1
        if res[b] == 0:
            res[b] = 1
    elif h[a] == h[b]:
        res[a] = -1
        res[b] = -1

print(res.count(1) + res.count(0))

Measured memory_bytes: 86480
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long gcd(long long a, long long b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
#define int long long
	int n,x;
	cin >> n >> x;
	vector<long long> hogea;
	REP(i, n) {
		long long geko;
		cin >> geko;
		hogea.push_back(llabs(geko - x));
	}
	long long ans = max(hogea[0], 0LL);
	for (int i = 1; i < n; ++i) {
		ans = gcd(ans, hogea[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


public class my
{
	
	private static StringBuilder sb = new StringBuilder();
	
	public static void Main()
	{
		for(int i = 1; i <= 9; i++) {
			for(int j = 1; j <= 9; j++) {
				sb.AppendLine(string.Format("{0}x{1}={2}", i, j, i*j ));
			}
		}
		
		Console.Write(sb);
	}
	
	private static int CountChar(string s, char c)
	{
		return s.Length - s.Replace(c.ToString(), "").Length;
	}
	
	private static void Flush()
	{
		Console.Write(sb);
		sb.Length = 0;
	}
	
	private static void AppendLine(int v)
	{
		sb.AppendLine(v.ToString());
	}
	
	private static void AppendLine(long v)
	{
		sb.AppendLine(v.ToString());
	}
	
	private static void AppendLine(string[] v)
	{
		sb.AppendLine(string.Join(" ", v));
	}

	private static void Swap(ref string a, ref string b) 
	{
		string tmp = a;
		a = b;
		b = tmp;
	}
	
	private static void Swap(ref int a, ref int b) 
	{
		int tmp = a;
		a = b;
		b = tmp;
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static long GetLong()
	{
		return long.Parse(Console.ReadLine());
	}
}

Measured memory_bytes: 8988
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P);
int ms(int,int);
P dequeue();

void enqueue(P x){
  Q[tail]=x;
  tail = (tail+1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head+1)%LEN;
  return x;
}

int ms(int a,int b){
  return a<b ? a:b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  tail = n+1;
  head = 1;

  while(head != tail){
    u = dequeue();
    c = ms(q,u.t);
    u.t = u.t-c;
    elaps = elaps+c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 11884
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,k;
	int len;
	while(cin>>n>>m>>k)
	{
		len=0;
		for(int i=min(n,m);i>=1;i--)
		{
			if(n%i==0&&m%i==0)
			{
				len++;
				if(len==k)
				{
					cout<<i<<endl;
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#include <tuple>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef pair<int,int> P;
typedef tuple<int,int,int,int> T;
//const int MAX=1e3+4;


int main(){
	
	int H,W;
	cin>>H>>W;
	int a[501][501];
	rep1(i,H)rep1(j,W){
		int p;
		cin>>p;
		a[i][j]=p%2;
	}
	queue<P> q;
	queue<T> ans;
	rep1(i,H){
		if(i%2){
			rep1(j,W)q.push(make_pair(i,j));
		}
		else{
			for(int j=W;j>0;j--)q.push(make_pair(i,j));
		}
	}
	int N=0;
	while(!q.empty()){
		P r=q.front();
		q.pop();
		if(q.empty())break;
		int i=r.first;
      	int j=r.second;
		if(a[i][j]==1){
			N++;
			P s=q.front();
			int k=s.first;
            int l=s.second;
			ans.push(make_tuple(i,j,k,l));
			a[k][l]=(a[k][l]+1)%2;
		}
	}
	cout<<N<<endl;
	while(!ans.empty()){
		T t=ans.front();
		ans.pop();
		cout<<get<0>(t)<<" ";
		cout<<get<1>(t)<<" ";
		cout<<get<2>(t)<<" ";
		cout<<get<3>(t)<<endl;
	}
}

Measured memory_bytes: 5248
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	string A, B;
	cin>>A>>B;
	int d = 0;
	if(A.size() > B.size()) cout<<"GREATER"<<endl;
	else if(A.size() < B.size()) cout<<"LESS"<<endl;
	else {
		REP(i, A.size()) {
			if(A[i] > B[i]) {
				d = 1;
				break;
			} else if(A[i] < B[i]) {
				d = 2;
				break;
			}
		}

	switch(d) {
		case 0:{
			cout<<"EQUAL"<<endl;
			break;
		}
		case 1: {
			cout<<"GREATER"<<endl;
			break;
		}
		case 2:
		{
			cout<<"LESS"<<endl;
			break;
		}
	}
	}
}

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

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0)break;
    vector<int> p(n);
    int sum=0;
    rep(i,n){
      cin >> p[i];
      sum += p[i];
    }
    int min,max;
    min=*min_element(p.begin(),p.end());
    max=*max_element(p.begin(),p.end());
    sum -= (max+min);
    int avg = sum / (n-2);
    cout << avg << endl;
  }
  return 0;
}



Measured memory_bytes: 3036
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
string s;
cin>>s;
ll ans=0;
for(int i=0;i<3;i++){
    if(s.at(i)=='1'){
        ans++;
    }
}
cout<<ans<<endl;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <limits>
const int mod = 1e9 + 7;
#define INF 1000000000000000
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
long long gcd(long long a, long long b) {
    if (a < b)
        swap(a, b);
    long long r = a % b;
    if (r == 0)
        return b;
    else
        return gcd(b, r);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, ret;
    cin >> n;
    vector<ll> v(n);
    rep(i, n){
        cin>>v[i];
    }
    ret=v[0];
    rep(i, n-1){
        ret=gcd(v[i+1], ret);
    }
    cout<<ret;
}

Measured memory_bytes: 1024
#include <stdio.h>

int
main(void)
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a < b && b < c) {
    printf("Yes\n");
  } 
  else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    vector<int> a(m),p(m);
    for(int i=0;i<m;i++){
        int b;cin >> a[i] >> b;
        for(int j=0;j<b;j++){
            int c;cin >> c;
            c--;
            p[i]+=(1<<c);
        }
    }
    vector<int> dp(1<<n,inf);
    dp[0]=0;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<m;j++){
            chmin(dp[i|p[j]],dp[i]+a[j]);
        }
    }
    if(dp[(1<<n)-1]==inf){
        cout << -1 << endl;
        return 0;
    }
    cout << dp[(1<<n)-1] << endl;
}

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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
	while(x!=parent[x]){
		parent[x] = parent[parent[x]];
		x = parent[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(rx != ry){
		if(Size[rx] > Size[ry]){
			parent[ry] = parent[rx];
			Size[rx] += Size[ry];
		}
		else{
			parent[rx] = parent[ry];
			Size[ry] += Size[rx];
		}
	}
}
*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc=1;
	//cin >> tc;
	while(tc--){
		int n;
		cin >> n;
		ll a[n],pre[n+1]={0};
		for (int i=0;i<n;i++) {
			cin >> a[i];
			pre[i+1] = pre[i] + a[i];
			pre[i+1] %= INF;
		}
		ll ans = 0;
		for (int i=0;i<n-1;i++) {
			ll z = (pre[n] - pre[i+1] + INF)%INF;
			//cout << z << endl;
			z = (z * a[i])%INF;
			//cout << z << endl;
			ans = (ans + z)%INF;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 6760
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int n;
  double m, sum;
  for(;;){
    cin >> n;
    if (n == 0) { break; }
    sum = 0.0;
    m = 0.0;
    vector<int> v;
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      v.push_back(tmp);
      m += tmp;
    }
    m /= n;
    for(int i : v){
      sum += (i - m) * (i - m);
    }
    printf("%1.6f\n" , sqrt(sum / n));
  }
  return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	string S;
	cin >> S;
	N = S.length();
	vl A, B, C, D;
	vl sumA(N + 1), sumB(N + 1), sumC(N + 1), sumD(N + 1);
	sumA[0] = 0; sumB[0] = 0; sumC[0] = 0; sumD[0] = 0;
	for (i = 0; i < N; i++) {
		if (S[i] == 'A') {
			A.push_back(i);
			sumA[i + 1] = sumA[i] + 1; sumB[i + 1] = sumB[i]; sumC[i + 1] = sumC[i]; sumD[i + 1] = sumD[i];
		}
		else if (S[i] == 'B') {
			B.push_back(i);
			sumA[i + 1] = sumA[i]; sumB[i + 1] = sumB[i] + 1; sumC[i + 1] = sumC[i]; sumD[i + 1] = sumD[i];
		}
		else if (S[i] == 'C') {
			C.push_back(i);
			sumA[i + 1] = sumA[i]; sumB[i + 1] = sumB[i]; sumC[i + 1] = sumC[i] + 1; sumD[i + 1] = sumD[i];
		}
		else if (S[i] == '?') {
			D.push_back(i);
			sumA[i + 1] = sumA[i]; sumB[i + 1] = sumB[i]; sumC[i + 1] = sumC[i]; sumD[i + 1] = sumD[i] + 1;
		}
	}
	//3^Qをあらかじめ前計算
	vl Q(N + 1); Q[0] = 1;
	for (i = 0; i < N; i++) {
		Q[i + 1] = (Q[i] * 3) % MOD;
	}
	//元からあるBをBとして用いた
	for (i = 0; i < B.size(); i++) {
		ll aa = sumA[B[i]];
		ll da = sumD[B[i]];
		ll cc = sumC[N] - sumC[B[i] + 1];
		ll dc = sumD[N] - sumD[B[i] + 1];
		//qaは3^(da-1)のこと
		ll a;
		if (da == 0) a = aa % MOD;
		else a = (aa * Q[da] + da * Q[da - 1]) % MOD;
		ll c;
		if (dc == 0) c = cc % MOD;
		else c = (cc * Q[dc] + dc * Q[dc - 1]) % MOD;
		ans = (ans + a * c) % MOD;
		//cout << ans << endl;
	}
	//?をBとして用いた
	for (i = 0; i < D.size(); i++) {
		ll aa = sumA[D[i]];
		ll da = sumD[D[i]];
		ll cc = sumC[N] - sumC[D[i] + 1];
		ll dc = sumD[N] - sumD[D[i] + 1];
		//qaは3^(da-1)のこと
		ll a;
		if (da == 0) a = aa % MOD;
		else a = (aa * Q[da] + da * Q[da-1]) % MOD;
		ll c;
		if (dc == 0) c = cc % MOD;
		else c = (cc * Q[dc] + dc * Q[dc-1]) % MOD;
		ans = (ans + a * c) % MOD;
		//cout << ans << endl;
	}
	cout << ans;
}
	


Measured memory_bytes: 5368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define ll long long int
#define pb push_back
#define llu unsigned long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>

using namespace std;
ll max(ll x,ll y)
{
	if(x>y)
		return x;
	return y;
}
ll min(ll x,ll y)
{
	if(x<y)
		return x;
	return y;
}
int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0;
    int base = 1; 
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) 
	{ 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
    return dec_value; 
} 
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin.ignore(numeric_limits<streamsize>::max(),'\n');
    //const unsigned ll M=1000000007;
    ll k, n, i, j, ans = 0, r;
	cin >> k;
	r = 7; 
	ans = 1;
	vector<bool> used(k + 1, false);
	if (k == 1) ans = 1;
	else if (k == 7) ans = 1;
	else 
	{
		while (r != 0) 
		{
			if (used[r]) 
			{
				ans = -1;
				break;
			}
			used[r] = true;
			r = (r * 10 + 7) % k;
			ans++;
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    string r;
    for (const char& c : x) {
        if (c == 'T' && !r.empty() && r.back() == 'S') {
            r.pop_back();
        } else {
            r.push_back(c);
        }
    }

    cout << r.size() << endl;

    return 0;
}

Measured memory_bytes: 776
#include <stdio.h>
#include <valarray>
#include <iostream>
using namespace std;
int N,M,T;
struct Matrix {
    valarray<int> a;
    int N;
    Matrix(int N0) : a(N0*N0), N(N0){ a=0; }
    int& access(int i,int j)
    {
        return a[i*N+j];
    }
    const int& access(int i,int j)const
    {
        return this->a[i*N+j];
    }
    Matrix(const Matrix & other):a(other.N*other.N),N(other.N)
    {
        a=other.a;
    }
    Matrix operator*(const Matrix& B)const
    {
        Matrix C(N);
        for (int i=0; i<N; ++i)
            for (int j=0; j<N; ++j)
                C.a[i*N+j]
                = (a[slice(i*N,N,1)]*B.a[slice(j,N,N)]).sum()%M;
        return C;
    }
    Matrix expt(int n)const
    {
        if (n == 0) {
            Matrix I(N);
            for (int i=0; i<N; ++i) I.a[i*N+i] = 1;
            return I;
        }
        if (n == 1) return *this;
        if (n % 2) return expt(n-1)*(*this);
        Matrix B = expt(n/2);
        return B*B;
    }
    void show(void)const
    {
        puts("Matrix:(");
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<N;j++)
            {
                printf("%d ",this->access(i,j));
            }
            puts("");
        }
        puts(")");
    }
    valarray<int> apply(const valarray<int>& vec) const
    {
        valarray<int> result(N);
        for(int i=0;i<N;i++)
        {
            //result[i]=(vec*valarray<int>(a[slice(i*N,N,1)])).sum()%M;
            result[i]=(vec*a[slice(i*N,N,1)]).sum()%M;//valarray[slice]はslice_array型,const valarray[slice]はvalarray型

        }
        return result;
    }
};

Matrix getTrans(int n,int a,int b,int c)
{
    Matrix t(n);
    for(int i=0;i<n;i++)
    {
        if(i>=1)
        {
            t.access(i,i-1)=a;
        }
        t.access(i,i)=b;
        if(i<=n-2)
        {
            t.access(i,i+1)=c;
        }
    }
    return t;
    
}

int main(void)
{
    int A,B,C;
    while(scanf("%d%d%d%d%d%d",&N,&M,&A,&B,&C,&T)==6 &&(N||M||A||B||C||T))
    {
        Matrix trans=getTrans(N,A,B,C);
        valarray<int> init(N);
        for(int i=0;i<N;i++)
        {
            int s;
            scanf("%d",&s);
            init[i]=s;
        }
        //trans.show();
        Matrix powerT=trans.expt(T);
        valarray<int> result=powerT.apply(init);
        for(int i=0;i<N;i++)
        {
            printf("%d",result[i]);
            if(i<=N-2)
            {
                printf(" ");
            }
            else puts("");
        }
    }
    
}

Measured memory_bytes: 1256
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Control.Applicative

data Point = Point Double Double Double deriving Eq

textToDouble :: T.Text -> Double
textToDouble t = (read . T.unpack) t :: Double

degToRad :: Double -> Double
degToRad d = d * pi / 180

advance :: (Double, Double) -> Point -> Point
advance (a, b) (Point x y t) =
    (Point (x + a * sin (degToRad t)) (y + a * cos (degToRad t)) (t + b))

main :: IO ()
main = do
    args <- reverse . map (\[a, b] -> (a, b)) . map (map textToDouble) . map (T.splitOn ",") . T.lines <$> T.getContents
    putStr $ unlines $ map show $ map truncate $ (\(Point x y _) -> [x, y]) $ foldr advance (Point 0 0 0) args

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
#define SORT(v) sort(v.begin(), v.end())
#define REVSORT(v) sort(v.begin(), v.end(), std::greater<int>())

typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	vector<ll>a;
	ll tmp;
	ll sell = 0;
	ll mx = 0;
	bool no2 = true;
	cin >> n;
	rep(i, 0, n){
		cin >> tmp;
		a.PB(tmp);
	}
	if (a[0] != 1){
		sell += a[0] - 1;
		a[0] = 1;
	}
	ll mins = 2;
	rep(i, 1, n){
//		if (a[i] == 2)no2 = false;
/*		if (no2){
			sell+=a[i] / 2;
			if (a[i] % 2 == 0)sell--;
			a[i] = 1;
		}*/
//		else{
			sell += a[i] / mins;
			if (a[i] % mins == 0)sell--;
			if (mins == a[i])mins++;
			a[i] = 1;
	//	}
	}
	cout << sell << endl;



	return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for(int i = 0; i < N; i++) cin >> x.at(i);
  vector<int> y(N);
  for(int i = 0; i < N; i++) y.at(i) = abs(X - x.at(i));
  int q;
  
  if(N == 1){
    cout << y.at(0) << endl;
  }
  else if(N == 2){
    cout << gcd(y.at(0), y.at(1)) << endl;
  }
  else{
    q = gcd(y.at(0), y.at(1));
    for(int i = 2; i < N; i++){
      q = gcd(q, y.at(i));
    }
  cout << q << endl;
  }
      
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int d;
    cin >> d;
    if(d == 25) cout << "Christmas" << endl;
    if(d == 24) cout << "Christmas Eve" << endl;
    if(d == 23) cout << "Christmas Eve Eve" << endl;
    if(d == 22) cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>
#include <set>
#include <utility>
typedef long long ll;

using namespace std;

struct xyz {
	string s;
	int p;
	int n;
};

int main() {
	int n;
	cin >> n;
	
	vector<xyz> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i].s >> v[i].p;
		v[i].n = i + 1;
	}
	
	stable_sort(v.begin(), v.end(), [](const xyz &a, const xyz &b){return a.p > b.p;});
	stable_sort(v.begin(), v.end(), [](const xyz &a, const xyz &b){return a.s < b.s;});

	for(int i = 0; i < n; i++) {
		cout << v[i].n << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	vector<int> v(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += max(0L, long(v[i] - c[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256