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;


vll x;
vpair e[100005];
void dfs(int v, int d) {
    x[v] = d;
    for (auto u : e[v]) {
        if (x[u.fi] != LINF) continue;
        dfs(u.fi, d+u.se);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    x.resize(n, LINF);
    vint l(m), r(m), d(m);
    rep(i, m) {
        cin >> l[i] >> r[i] >> d[i];
        --l[i];
        --r[i];
        e[l[i]].emplace_back(r[i], d[i]);
        e[r[i]].emplace_back(l[i], -d[i]);
    }

    rep(i, n) {
        if (x[i] == LINF) dfs(i, 0);
    }
    
    bool c = true;
    rep(i, m) {
        if (x[r[i]] - x[l[i]] != d[i]) c = false;
    }

    yns(c);
    return 0;
}

Measured memory_bytes: 14720
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

const int N = 1e5 + 10;
int a[N];

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

LL max(LL a , LL b)
{
	if(a > b) return a;
	else return b;
}

int main()
{
	int n , k;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d %d",&n , &k);
	LL Max = 0;
	for(int i = 1 ; i <= n ; i++) {scanf("%I64d",&a[i]) ; Max = max(Max , a[i]);}
	sort(a + 1 , a + 1 + n);
	if(Max < k){
		printf("IMPOSSIBLE\n");
		return 0;
	}
	else{
		LL ggcd = a[1];
		for(int i = 2 ; i <= n ; i++){
			ggcd = gcd(a[i] , ggcd);	
		}
		if(k % ggcd == 0) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	double x,y;
	double a,b,c,d,e,f;

	while(scanf("%lf %lf %lf %lf %lf %lf", &a,&b,&c,&d,&e,&f) != EOF){
		if(e == 0 && d*b != 0){
			x = (f/d);
			y = (c/b)-(a*f)/(b*d);
		}else if(b == 0 && a*e != 0){
			x = (c/a);
			y = (f/e)-(c*d)/(a*e);
		}else if(a == 0 && b*d != 0){
			y = (c/b);
			x = (f/d)-(c*e)/(b*d);
		}else if(d == 0 && a*e != 0){
			y = (f/e);
			x = (c/a)-(b*f)/(a*e);
		}else{
			x = (e*c - b*f)/(a*e - b*d);
			y = (f/e) - (d/e)*x;
		}

		if(x<0.0005 && x>-0.0005) x = 0;
		if(y<0.0005 && y>-0.0005) y = 0;

		printf("%.3lf %.3lf\n", x,y);
	}

	return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
#define int long long
using namespace std; 
void chmax(int &a, int b) { a = max(a, b); }
int INF = 1e+15;
int n, q;
int w[100], v[100];
int dp[300001];
signed main() {
	int i, j;
	cin >> n >> q;
	for (i = 0; i < n; i++) cin >> w[i] >> v[i];
	for (i = 0; i <= q; i++) dp[i] = -INF;
	dp[0] = 0;
	
	for (i = 0; i < n; i++) {
		for (j = q; j >= 0; j--) {
			chmax(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	
	int ans = 0;
	for (i = 0; i <= q; i++) chmax(ans, dp[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
s = input()

# s[0:i+1] == s[i+1:2*(i+1)]
for i in reversed(range(len(s))):
    if 2 * i < len(s):
        # print("{} {}".format(s[:i], s[i:2 * i]))
        if s[:i] == s[i:2 * i]:
            print(2*i)
            exit()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

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);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("../input.txt", "r", stdin);
        freopen("../output.txt", "w", stdout);
    #endif*/
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n;
        cin>>n;
        vvl vec(n, vl(3));
        rep(i, n){
            rep(j, 3)   cin>>vec[i][j];
        }
        vvl dp(n, vl(3, 0));
        rep(i, 3)   dp[0][i] = vec[0][i];
        rep1(i, n){
            rep(j, 3){
                dp[i][j] = max3(dp[i][j], dp[i-1][(j+1)%3]+vec[i][j], dp[i-1][(j+2)%3]+vec[i][j]);
                // cout<<dp[i][j]<<" ";
            }
            // cout<<endl;
        }
        cout<<max3(dp[n-1][0], dp[n-1][1], dp[n-1][2]);
    }
}

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


int main(){
  int n, m; cin >> n >> m;
  int mat[n][m];
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin >> mat[i][j];
    }
  }

  int vec[m];
  for(int i=0; i<m; i++){
    cin >> vec[i];
  }

  int c=0;
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      c += mat[i][j]*vec[j];
    }
    cout << c << endl;
    c = 0;
  }

  return 0;
}

Measured memory_bytes: 3144
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(a);
        for (int i = 0; i < n; i++) {
            System.out.println(b[i] == a[n-1] ? a[n-2] : a[n-1]);
        }
        sc.close();

    }

}


Measured memory_bytes: 91232
#include<stdio.h>
main()
{
    int n , m;
    scanf("%d%d",&n,&m);
    int c=0,i,j;
    for(i=0;i<=(n-1);i++)
    {
      for(j=0;j<=n-2;j++)
      {
          c=c+1;
      }
    }
    int k=0;
    for(i=0;i<=(m-1);i++)
    {
        for(j=0;j<=m-2;j++)
        {
         k=k+1;
        }
    }
    int t;
    t=(c+k)/2;
    printf("%d",t);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int ans;
	scanf("%d%d%d",&a,&b,&c);
	if(b < a){
		if(b+c <=a){
			ans = 0;
		}
		else
		ans = c - (a-b);
	}
	else
	ans = c;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int max(int a, int b){
	return a>b?a:b;
}
int main(void){
	int a,b,c,sum;
	cin >> a >> b >> c;
	sum = a+b+c - max(max(a,b),c);
	cout << sum << endl;
	return 0;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,c;
	char b,n,m;
	int sum;
	while(scanf("%d",&a)!=EOF)
	{
		scanf("%c",&m);
		scanf("%c",&b);
		scanf("%c",&n);
		scanf("%d",&c);
		if(b==43)
		{
			sum=a+c;
			printf("%d\n",sum);
		}
		else
		{
			sum=a-c;
			printf("%d\n",sum);
		}
 
	}
	return  0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <algorithm>
#include <utility>
#define INF INT_MAX / 2
using namespace std;

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

int main(void) {
	
	string c[] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

	int t;
	cin >> t;
	for(int i=0;i<t;i++){
		int cnt = 0;
		string s;
		cin >> s;
		for(int i=0;i<s.size();i++){
			if(s[i] == '0'){
				if(cnt == 0)continue;
				int n = s[i-1]-'1';
				cout << c[n][(cnt-1)%(c[n].size())];
				cnt = 0;
			}else cnt++;
		}
		cout << endl;
	}

}

// command shift d duplicate
// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));

Measured memory_bytes: 1208
sx, sy, tx, ty = map(int, input().split())

dx = abs(tx - sx)
dy = abs(ty - sy)

ans = ''

ans += 'R' * dx
ans += 'U' * dy

ans += 'L' * dx
ans += 'D' * dy

ans += 'D'
ans += 'R' * (dx + 1)
ans += 'U' * (dy + 1)
ans += 'L'

ans += 'U'
ans += 'L' * (dx + 1)
ans += 'D' * (dy + 1)
ans += 'R'

print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
int n,a[101][3]={0},sum=0,m,z;
cin>>n;
cin>>m;
for(int i=0;i<m;i++){
  int k;
  cin>>k;
  a[k-1][0]=1;
}
cin>>m;
for(int i=0;i<m;i++){
  int k;
  cin>>k;
  a[k-1][1]=1;
}
cin>>m;
for(int i=0;i<m;i++){
  int k;
  cin>>k;
  a[k-1][2]=1;
}
for(int i=0;i<n;i++){
  if(a[i][0]!=1&&a[i][2]==1){
    sum++;
  }
  else if(a[i][1]==1&&a[i][2]==1){
   sum++; 
  }
}
cout<<sum<<'\n';
  return 0;
  
}

Measured memory_bytes: 3120
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

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


int main(){
	typedef pair<int,int> pii;
	
	A:;
	
	int h,w;
	cin>>h>>w;
	
	if(h==0 && w==0)return 0;
	
	pii input = pii(h*h + w*w, h);
	
	
	pii mini = pii(200*200 + 200*200, 200);
	int minx = -1;
	int miny = -1;
	
	reps(i,1,151){
		reps(j,i+1,151){
			pii dat = pii(i*i + j*j, i);
			
			if(dat<=input)continue;
			
			if(dat<mini){
				mini = dat;
				minx = j;
				miny = i;
			}
		}
	}
	
	printf("%d %d\n",miny,minx);
	
	goto A;
}

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

int main() {
	string a, b, c; cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front()) {
		puts("YES");
	}
	else puts("NO");
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans = max(ans, abs(A[i]-A[j]))
    
    print(ans)
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <stack>
#include <algorithm>
#define MAX 1400
using namespace std;

struct Rectangle {
    int height;
    int pos;
};

int getLargestRectangle(int size,int buffer[]) {
    stack<Rectangle> S;
    int maxv=0;
    buffer[size]=0;

    for(int i=0;i<=size;i++) {
        Rectangle rect;
        rect.height=buffer[i];
        rect.pos=i;
        if(S.empty()||S.top().height<rect.height)
            S.push(rect);
        else if(S.top().height>rect.height) {
            int target=i;
            while(!S.empty()&&S.top().height>=rect.height) {
                Rectangle pre=S.top();S.pop();
                int area=pre.height*(i-pre.pos);
                maxv=max(maxv,area);
                target=pre.pos;
            }
            rect.pos=target;
            S.push(rect);
        }
    }
    return maxv;
}

int H,W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle() {
    for(int j=0;j<W;j++)
        for(int i=0;i<H;i++)
            if(buffer[i][j])
                T[i][j]=0;
            else
                T[i][j]=(i>0)?T[i-1][j]+1:1;

    int maxv=0;
    for(int i=0;i<H;i++)
        maxv=max(maxv,getLargestRectangle(W,T[i]));

    return maxv;
}

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

    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
            scanf("%d",&buffer[i][j]);

    cout<<getLargestRectangle()<<endl;
}

Measured memory_bytes: 18520
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#include <random>
#include <map>
#pragma warning(disable : 4996)

#define MAX_N 100

int main(void) {
	int n;
	char s[MAX_N + 1];
	scanf("%d", &n);
	scanf("%s", &s[0]);
	int x = 0;
	int max = x;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'I') ++x;
		if (s[i] == 'D') --x;
		if (x > max) {
			max = x;
		}
	}
	printf("%d", max);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
vecll tot(51, 0);
vecll p(51, 0);
ll rec(int i, ll k) {
  if (k == 0) return 0;
  if (i == 0) return 1;
  if (k == 1) return 0;
  // cout << i << " " << k << " " << (tot[i] + 1) / 2 << endl;
  if (k >= (tot[i] + 1) / 2) {
    return p[i - 1] + 1 + rec(i - 1, k - (tot[i] + 1) / 2);
  } else {
    return rec(i - 1, k - 1);
  }
}
int main() {
  init();
  int n;
  ll x;
  cin >> n >> x;
  tot[0] = p[0] = 1;
  REP(i, 50) {
    tot[i + 1] = 2 * tot[i] + 3;
    p[i + 1] = 2 * p[i] + 1;
  }
  // REP(i, 51) { cout << p[i] << endl; }
  // cout << tot[50] << end  l;
  // cout << p[50] << endl;
  cout << rec(n, x) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i=0;i<N;i++) {
    cin >> h.at(i);
  }
  
  if (N > 1) {
    int count=0,min=101,change=0;
    for (int i=1;i<N;i++) {
      if (h.at(i-1) >= h.at(i)) {
        count += h.at(i-1) - h.at(i);
      }
      if (h.at(i-1) < h.at(i)) {
        if (min > h.at(i-1)) {
          change++;
          min = h.at(i-1);
        }
      }
    }
    if (h.at(N-1) > min) {
      count += h.at(N-1) - min;
    }
    if (h.at(N-1) < min) {
      min = h.at(N-1);
    }
      
    cout << count+min << endl;
  }
  
  if (N==1) {
    cout << h.at(0) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;
typedef long long ll;
int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = LLONG_MAX;
    for (int i = 0; i <= 2*max(X, Y); i+=2) {
        ll tmp = i*C;
        tmp += max((ll)0, X-i/2)*A + max((ll)0, Y-i/2)*B;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
# -*- coding:utf-8 -*-
import sys


class Node(object):
    __slots__ = ["value", "left", "right"]

    def __init__(self, value, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right


class BinTree(object):
    def __init__(self):
        self._tree = None

    def insert(self, value):
        parent = None
        current = self._tree

        while current is not None:
            parent = current
            if value < current.value:
                current = current.left
            else:
                current = current.right

        if parent is None:
            self._tree = Node(value)
        elif value < parent.value:
            parent.left = Node(value)
        else:
            parent.right = Node(value)

    def find(self, value):
        current = self._tree

        while current is not None:
            if value == current.value:
                return True
            elif value < current.value:
                current = current.left
            else:
                current = current.right

        return False

    def preoder_walk(self):
        def preoder(node):
            result = []
            if node is None:
                pass
            else:
                result.append(node.value)
                result.extend(preoder(node.left))
                result.extend(preoder(node.right))
            return result

        return preoder(self._tree)

    def inorder_walk(self):
        def inorder(node):
            result = []
            if node is None:
                pass
            else:
                result.extend(inorder(node.left))
                result.append(node.value)
                result.extend(inorder(node.right))
            return result

        return inorder(self._tree)


def print_tree(tree):
    print(" " + " ".join([str(val) for val in tree.inorder_walk()]))
    print(" " + " ".join([str(val) for val in tree.preoder_walk()]))


def print_yes_no(boolean):
    if boolean:
        print("yes")
    else:
        print("no")


def main(commands):
    tree = BinTree()
    for com in commands:
        if com[0] == "insert":
            tree.insert(int(com[1]))
        elif com[0] == "print":
            print_tree(tree)
        elif com[0] == "find":
            print_yes_no(tree.find(int(com[1])))
        else:
            raise ValueError


if __name__ == "__main__":
    n = int(input())
    commands = [com.split() for com in sys.stdin.readlines()]
    main(commands)

Measured memory_bytes: 217432
s = input()
if 1<=int(s[:2]) <= 12 and 1<=int(s[2:]) <= 12:
    print('AMBIGUOUS')
elif 1 <= int(s[:2]) <= 12:
    print('MMYY')
elif 1 <= int(s[2:]) <= 12:
    print('YYMM')
else:
    print('NA')

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

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;

int N;
V<int> A, D = {-1, 0, 1};
int64_t f(int i, int64_t p) {
	// cout << i << " " << p << endl;
	if (i == N)
		return p%2 == 0;

	int64_t ways = 0;
	for (int d : D) {
		ways += f(i+1, p*(A[i]+d));
	}
	return ways;
}


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

	cin >> N;
	A.resize(N);
	READALL(A);

	cout << f(0, 1) << endl;
	
}

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

using namespace std;

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

  int p, q, r;
  cin >> p >> q >> r;
  int ans = min({p + q, q + r, p + r});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	k := nextInt()
	odd := 0
	even := 0
	for i := 1; i <= k; i++ {
		if i%2 == 0 {
			even++
		} else {
			odd++
		}
	}
	fmt.Println(even * odd)
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[i].b
}

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-

import sys
import os
import math


lst = sys.stdin.readlines()
#print(lst)

for s in lst:
    cnt = 0
    target_val = int(s)
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a + b + c + d == target_val:
                        cnt += 1
    print(cnt)

Measured memory_bytes: 7544
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;

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

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

	int c=0;
	for(int i=0; i<n-2; i++){
		if(p[i]<p[i+1] && p[i+1]<p[i+2])
			c++;
		if(p[i]>p[i+1] && p[i+1]>p[i+2])
			c++;
	}

	cout << c << endl;
}

Measured memory_bytes: 256
from collections import deque


def solve(n, a_list, b_list):

    # create graph
    g = {i: dict() for i in range(n)}
    for i in range(n - 1):
        a, b = a_list[i] - 1, b_list[i] - 1
        g[a][b] = -1
        g[b][a] = -1

    k = max([len(g[a]) for a in range(n)])

    used_color = [-1] * n
    used_color[0] = k - 1
    # BFS
    queue = deque([0])
    while len(queue) > 0:
        p = queue.popleft()
        c = used_color[p]
        for q in g[p].keys():
            if used_color[q] != -1:
                continue
            c += 1
            c %= k
            # print(p, q, c)
            g[p][q] = c
            g[q][p] = c
            used_color[q] = c
            queue.append(q)

    res_list = [0] * (n - 1)
    for i in range(n - 1):
        res_list[i] = g[a_list[i] - 1][b_list[i] - 1] + 1

    return k, res_list


def main():
    n = int(input())
    a_list = [0] * (n - 1)
    b_list = [0] * (n - 1)
    for i in range(n - 1):
        a, b = map(int, input().split())
        a_list[i] = a
        b_list[i] = b

    k, res_list = solve(n, a_list, b_list)
    print(k)
    for i in range(n - 1):
        print(res_list[i])


def test():
    print(solve(3, [1, 2], [2, 3]))
    print(solve(8, [1, 2, 2, 2, 4, 5, 6], [2, 3, 4, 5, 7, 6, 8]))


if __name__ == "__main__":
    # test()
    main()


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

long long s[400][30]; 
const int Shurui=26;//今回は26種類
int Date;//今回は1年間なので365日
double Seigenjikan=1.8;//実行時間

int main() {
  clock_t start = clock();
  cin >>Date;
  vector<int>c(Shurui);
  vector<int>last(Date,0);//前回の日にち
  vector<int>t(Date,0);//開催する順番
  for(int i=0;i<Date;i++)t[i]=i%Shurui;//とりあえずの値
  long long wa=0;
  for(int i=0;i<Shurui;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<Date;i++){
    for(int j=0;j<Shurui;j++){
      cin>>s[i][j];
    }
  }
  long long kotae=0;
  long long hikukazu=0;
  long long atai=0;
  for(int i=0;i<Date;i++){
    atai=LLONG_MAX;
    for(int j=0;j<Shurui;j++){
      if(s[i][j]-c[j]*(i+1-last[j])<atai){
        t[i]=j;
        atai=s[i][j]-c[j]*(i+1-last[j]);
      }
    }
  }
  for(int i=0;i<Date;i++){
    atai=0;
    atai=s[i][t[i]];
    hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
    last[t[i]]=i+1;
    kotae+=atai-hikukazu;
  }  
  clock_t end = clock();
  double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  while(time<Seigenjikan){
    int d=rand()%Date;
    int q=rand()%Shurui;
    int old=t[d];
    t[d]=q;
    long long new_kotae=0;
    hikukazu=0;
    for(int i=0;i<Date;i++){
      atai=0;
      atai=s[i][t[i]];
      hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
      last[t[i]]=i+1;
      new_kotae+=atai-hikukazu;
    }
    if(new_kotae<kotae){
      t[d]=old;
    }else{
      kotae=new_kotae;
    }
    end = clock();
    time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  }
  for(int i=0;i<Date;i++){
    cout<<t[i]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>

int main(void) {
  int n, x;
  scanf("%d %d", &n, &x);
  int l[n];
  int d = 0, ans = 1;
  for ( int i = 1; i <= n; i++ ) {
    scanf("%d", &l[i]);
    d += l[i];
    if ( d <= x ) ans++;
  }

  printf("%d", ans);
  
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int):
    one = N % 10
    if one == 3:
        print("bon")
    elif one in [2,4,5,7,9]:
        print("hon")
    else:
        print("pon")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <stdio.h>

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

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

  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0)printf(" ");
      printf("%d",adj[i][j]);
    
    }
    printf("\n");
  }

  return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}

int main(){
    ll n,q;cin>>n>>q;
    ll s[n],t[n],x[n];
    vector<pll> v;
    rep(i,0,n){
        cin>>s[i]>>t[i]>>x[i];
        s[i]-=x[i];
        t[i]-=x[i];
        v.push_back(make_pair(s[i],i));
    }
    sort(v.begin(),v.end());
    vector<ll> d(q);rep(i,0,q)cin>>d[i];
    ll u;
    for(int i=0;;i++){
        if(i*i>q){
            u=i-1;
            break;
        }
    }
    ll y=u;
    if(u*u!=q)y++;
    ll ans[y];
    ll anss[q];
    //cout<<u<<" "<<y<<endl;return 0;
    fill(ans,ans+y,inf);
    fill(anss,anss+q,inf);
    
    rep(i,0,n){
        ll now=v[i].first,num=v[i].second;
      //cout<<num<<" "<<x[num]<<endl;
      
        ll e=lower_bound(d.begin(),d.end(),s[num])-d.begin();
        ll f=lower_bound(d.begin(),d.end(),t[num])-d.begin();
        if(e==f)continue;
        ll se=e/u,sf=(f-1)/u;
        //cout<<e<<" "<<f<<endl;
      //cout<<se+1<<" "<<sf<<endl;
        rep(j,se+1,sf)ans[j]=min(ans[j],x[num]);
        rep(j,e,min(f,u*(se+1)))anss[j]=min(anss[j],x[num]);
        rep(j,max(e,sf*u),f)anss[j]=min(anss[j],x[num]);
      
    }
  //rep(i,0,n)cout<<ans2[i]<<endl;
    rep(i,0,q){
        ll t=i/u;
        ll h=min(ans[t],anss[i]);
        if(h==inf)h=-1;
        cout<<h<<endl;
    }
}



Measured memory_bytes: 12780
#include <iostream>
#include <climits>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

    ll N, M, X, mi = 999999999999;
	cin >>N>>M>>X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));
    rep(i, N) {
        cin >> C.at(i);
        rep(j, M) {
            cin >> A.at(i).at(j);
        }
    }
  

    
    for (int bit = 0; bit < (1 << N); ++bit)
    {
        ll man = 0;
        vector<ll> R(M);
        for (ll i = 0; i < N; ++i) {
            if (bit & (1 << i)) { 
                rep(j, M) {
                    R.at(j) += A.at(i).at(j);
                }
                man += C.at(i);
            }
        }
        int han = 0;
        rep(j, M) {
            if (R.at(j) < X) {
                han = 1;
            }
        }
        if (han == 0) {
            mi = min(mi, man);
        }

    }
    if (mi == 999999999999) {
        mi = -1;
    }
    cout << mi << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N; cin >> N;
  int x; cin >> x;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  ll ans=0;
  rep(i,N-1){
    ll sum=a[i]+a[i+1];
    if(sum>x){
      a[i+1]=max(0ll,a[i+1]-(sum-x));
      ans+=sum-x;
    }
  }
  cout << ans << endl;
  
}

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

public class Program
{
	public static void Main()
	{
		int[] candies = Console.ReadLine().Split().Select(int.Parse)
			.OrderBy(i => i).ToArray();
		Console.WriteLine(candies[0] + candies[1] == candies[2]
			? "Yes" : "No");
	}
}

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

typedef long long ll;

int main(){
    int n;
    ll T;
    cin >> n >> T;

    ll ans = 0;
    ll before, after;  
    cin >> before;
    
    for(int i = 1; i < n; i++){
        cin >> after;
        ans += min(after-before, T);
        before = after;
    }

    ans += T;

    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

map<int, int> fact(ll N) {
    map<int, int> res;
    if (N <= 1) return res;
    for (int i = 2; (ll)i * i <= N; ++i) {
        if (N % i) continue;
        while (N % i == 0) {
            N /= i;
            res[i]++;
        }
    }
    if (N != 1) res[N]++;
    return res;
}

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

    auto mp = fact(N);

    int ans = 0;
    for (auto &p: mp) {
        int sum = 0, res = 0;
        for (int i = 1; i <= p.second; ++i) {
            sum += i;
            if (p.second < sum) break;
            res++;
        }
        ans += res;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
	ll x; cin >> x;
	ll ans = 1;
	for (int i = 2; i <= sqrt(x); ++i){
		ll j = 1;
		while (pow(i, j) <= x) j++;
		ans = max((ll)pow(i, j - 1), ans);
	}cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<vector<int>> A(N,vector<int>(N-1));
  rep(y,N){
    rep(x,N-1){
      cin >> A[y][x];
      A[y][x]--;
    }
  }
  int ans = 0;
  vector<int> itr(N,0);

  int cnt=0;
  for(;;){
    ans++;
    vector<bool> moved(N,false);
    bool ok = false;
    for(int y=0;y<N;y++){
      //bool ok = false;
      if(itr[y]==N-1) continue;
      int vs = A[y][itr[y]];
      //if(y==vs) continue;
      if(y == A[vs][itr[vs]] && !moved[y] && !moved[vs] && itr[y]!=N-1 && itr[vs]!=N-1){
        //cout << y << " " << vs << endl;
        cnt+=2;
        ok = true;
        moved[y] = moved[vs] = true;
        itr[vs]++;
        itr[y]++;
      }
    }
    if(!ok){
      cout << -1 << endl;
      return 0;
    }
    if(cnt == N*(N-1)) break;
    //cout << "-----" << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6272
from itertools import combinations

[N],*li = [list(map(int,i.split())) for i in open(0)]
li = li[0]
count = 0
for k in combinations(li,3):
    k = sorted(list(k))
    if k[2]<k[0]+k[1] and k[0]!=k[1] and k[1]!= k[2]:
        count += 1
print(count)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll mod_pow(ll a,ll b,ll p){ //(a^b)%p
	ll res=1;
	a%=p;

	while(b>0){
		if(b&1==1) res=((res%p)*(a%p))%p;
		a=(a%p*a%p)%p;
		b>>=1;
	}
	return res;
}

//mod_inv=mod_pow(denominator,MOD-2,MOD);

int32_t main(){
	fastio();
	int n;
	cin >> n;
	int a[n];
	map<int,int>f;
	map<int,int>s[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
		int k = a[i];
		for(int j = 2; j * j <= k; j++){
			if(k % j == 0){
				int cnt = 0;
				while(k%j==0){
					k = k/j;
					cnt++;
				}
				f[j] = max(f[j],cnt);
				s[i][j] = cnt;
			}
		}
		if( k > 1) f[k] = max(f[k] , 1ll),s[i][k] = 1;
	}


	int lc = 1;
	for(auto j:f){
		lc = lc * mod_pow(j.ff,j.ss,mod);
		lc %= mod;
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		int k = lc * mod_pow(a[i], mod - 2, mod);
		k %= mod;
		ans += k;
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 7168
N=gets.to_i
h=gets.split(" ").map(&:to_i)
c=Array.new(N,0)
c[0],c[1]=0,(h[1]-h[0]).abs
for i in 2..N-1
	c[i]=[c[i-2]+(h[i-2]-h[i]).abs,c[i-1]+(h[i-1]-h[i]).abs].min
end
puts c[N-1]

Measured memory_bytes: 11396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,mx=0;
    cin >> n;
    long long i,arr[10000];
    for(i=sqrt(n)+1;i>0;i--)
    {
        if(n%i==0)
        {
            mx=i;
            break;
        }
    }
    cout << mx-1 + n/mx-1 << endl;
    return 0;
}


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

#define int long long

#define all(v) v.begin(), v.end()
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << (x) << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  int n, m;
  std::cin >> n >> m;

  std::vector<std::vector<bool>> A(n, std::vector<bool>(n, false));
  int a, b;
  REP(i, m) {
    std::cin >> a >> b;
    A[a-1][b-1] = true;
    A[b-1][a-1] = true;
  }

  std::vector<int> vec(n);
  REP(i, n) {
    vec.at(i) = i;
  }

  ASORT(vec);
  int sum = 0;
  do {
    bool flag = false;
    if (vec[0] != 0) {
      continue;
    }
    REP (i, n-1) {
      // check(vec.at(i)+1);
      // check(vec.at(i+1)+1);
      if (!A.at(vec.at(i)).at(vec.at(i+1))) {
        // cout("abort");
        flag = true;
        break;
      }
    }
    if (flag) {
      continue;
    }
    sum++;
    // cout("");
  } while (next_permutation(all(vec)));

  cout(sum);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef pair<ll,P> lP;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  ll x,y,z,k,a[1010],b[1010],c[1010],ans,S,X,Y,Z,cnt=0;
  cin>>x>>y>>z>>k;
  fr(i,x) cin>>a[i];
  fr(i,y) cin>>b[i];
  fr(i,z) cin>>c[i];
  sort(a,a+x);
  sort(b,b+y);
  sort(c,c+z);
  reverse(a,a+x);
  reverse(b,b+y);
  reverse(c,c+z);
  ans=a[0]+b[0]+c[0];
  ifr(i,x) a[i]=a[0]-a[i];
  ifr(i,y) b[i]=b[0]-b[i];
  ifr(i,z) c[i]=c[0]-c[i];
  priority_queue<PP,vector<PP>,greater<PP>> pq;
  pq.push(mp(mp(0,0),mp(0,0)));
  map<lP,bool> lPb;
  while(cnt<k){
    PP pp=pq.top();
    pq.pop();
    if(lPb[mp(pp.ft.sd,pp.sd)]) continue;
    cout<<ans-pp.ft.ft<<endl;
    cnt++;
    lPb[mp(pp.ft.sd,pp.sd)]=1;
    S=pp.ft.ft;X=pp.ft.sd;Y=pp.sd.ft;Z=pp.sd.sd;
    if(X<x-1) pq.push(mp(mp(a[X+1]+b[Y]+c[Z],X+1),mp(Y,Z)));
    if(Y<y-1) pq.push(mp(mp(a[X]+b[Y+1]+c[Z],X),mp(Y+1,Z)));
    if(Z<z-1) pq.push(mp(mp(a[X]+b[Y]+c[Z+1],X),mp(Y,Z+1)));
  }
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];

        for(int i=0;i<N;i++){
            x[i] = sc.nextInt();
        }
        int sum = 0;
        for(int i=0;i<N;i++){
            if((K-x[i])>x[i]){
                sum = sum + 2*x[i];
            } else {
                sum = sum + 2 *(K-x[i]);
            }
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    rep(i, n)cin >> a[i][0] >> a[i][1] >> a[i][2];
    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    for(int i = 1; i <= n; i++){
        rep(j, 3)rep(k, 3){
            if(j == k)continue;
            dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i-1][j]);
        }
    }
    int ans = 0;
    rep(i, 3)ans = max(ans, dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 13972
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cctype>
using namespace std;
#define N 105
int n , m;
struct query
{
    int id , x , y;
}q[N * N];
bool g[N][N] , f[N][N];
bool Q(int x , int y)
{
    for (int i = 1 ; i <= n ; ++ i)
        if (g[x][i] && f[y][i] || g[y][i] && f[x][i])
            return 1;
    return 0;
}
bool check(int V)
{
    int i , j , k, x , y;
    memset(f , 0 , sizeof(f));
    memset(g , 0 , sizeof(g));
    for (i = 1 ; i <= n ; ++ i)
        g[i][i] = 1;
    for (i = 1 ; i <= V ; ++ i)
        if (q[i].id <= 2)
        {
            x = q[i].x , y = q[i].y;
            g[x][y] = 1;
            if (q[i].id == 2)
                g[y][x] = 1;
        }
    for (k = 1 ; k <= n ; ++ k)
        for (i = 1 ; i <= n ; ++ i) if (g[i][k])
            for (j = 1 ; j <= n ; ++ j) if (g[k][j])
                g[i][j] = 1;
    for (i = 1 ; i <= V ; ++ i)
        if (q[i].id == 4)
        {
            x = q[i].x , y = q[i].y;
           /* for (j = 1 ; j <= n ; ++ j) if (g[j][x])
                for (k = 1 ; k <= n ; ++ k) if (g[k][y])
                    f[j][k] = f[k][j] = 1;*/
            for (j = 1 ; j <= n ; ++ j) if (g[j][x])
                f[j][y] = 1;
            for (j = 1 ; j <= n ; ++ j) if (g[j][y])
                f[j][x] = 1;
        }
    for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) f[i][j] |= f[j][i];
    for (i = 1 ; i <= V ; ++ i)
    {
        x = q[i].x , y = q[i].y;
        if (q[i].id == 3) // x != y
        {//      x , y = empty           x == y
            if (g[x][y] && g[y][x])
                return 0;
            if (Q(x , x) && Q(y , y))
                return 0;
        }
        else if (q[i].id == 5) // x ins y != empty
        {    //x = empty   y = empty   x ins y == empty
            if (Q(x , x) || Q(y , y) || Q(x , y) || Q(y , x))
                return 0;
        }
    }
    return 1;
}

int main()
{
    while (scanf("%d%d",&n,&m))
    {
    	if(n == 0 && m == 0) break;
        for (int i = 1 ; i <= m ; ++ i)
           scanf("%d%d%d",&q[i].id, &q[i].x , &q[i].y);

        int top = 1 , bot = m , mid;
        while (top < bot)
        {
            mid = top + bot + 1 >> 1;
            if (check(mid))
                top = mid;
            else
                bot = mid - 1;
        }
        printf("%d\n" , top);
    }
    return 0;
}

Measured memory_bytes: 1156
from collections import Counter
import sys

n = int(input())
arr = list(map(int, input().split()))

# 全て0ならYes
if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

# 3つずつ循環していなければNo
if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(arr)

# 2種類の場合
if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()

# 3種類の場合
elif len(c) == 3:
    result = list(c.values())
    if result[0] == result[1] == result[2]:
        ans1 = True
    else:
        ans1 = False
else:
    print("No")
    sys.exit()

result = list(c.keys())
ans2 = result[0] == result[1] ^ result[2] and result[1] == result[0] ^ result[2] and result[2] == result[0] ^ result[1]

print("Yes" if ans1 and ans2 else "No")

Measured memory_bytes: 20716
#include <algorithm>
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  int64_t n;
  cin >> n;
  int64_t ans = n;
  for (int64_t a = 1; a * a <= n; ++a) {
    if (n % a != 0) continue;
    int64_t b = n / a;
    ans = min(ans, a - 1 + b - 1);
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
  vector<int> v(4);
  for (int i = 0; i < 6; i++) {
    int a;
    cin >> a;
    v.at(a - 1)++;
  }
  bool flag = true;
  for (int i = 0; i < v.size(); i++) {
    if (v.at(i) >= 3) flag = false;
  }
  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  map<char, vi> mps, mpt;
  rep(i, n) {
    mps[s[i]].push_back(i);
    mpt[t[i]].push_back(i);
  }
  set<vi> sts, stt;
  for(auto v : mps) sts.insert(v.second);
  for(auto v : mpt) stt.insert(v.second);
  cout << (sts == stt ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4588
#include <stdio.h>
int main (){

  int m,f,r;

  while(1){

    scanf("%d%d%d",&m,&f,&r);

    if(m==-1 && f==-1 && r==-1)break;

    if(m==-1 || f==-1 || m+f<30 ) printf("F\n");
    else if(m+f<50){
      if(r>=50)printf("C\n");
      else printf("D\n");
    }else if(m+f<65)printf("C\n");
    else if(m+f<80)printf("B\n");
    else printf("A\n");

  }

  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 60;

const int nMax = 105;
const int vMax = 100005;

int N, W;
int w[nMax], v[nMax];
ll dp[nMax][vMax];

ll solve() {
    for (int i = 0; i < nMax; i++) {
        for (int j = 0; j < vMax; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < vMax; j++) {
            if (j < v[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }

    ll M = 0;
    for (int j = 0; j < vMax; j++) {
        if (dp[N][j] <= W && M < j) {
            M = j;
        }
    }
    return M;
}

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 82304