akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main()
{
    int n, count;
   unsigned long long int factorial=1;
   while(scanf("%d",&n)==1)
{
     if ( n== 0)
     printf("1\n");
     else
     {
         factorial=1;

         for(count=1;count<=n;++count)
     { factorial*=count;}
      printf("%llu\n",factorial);
      }

      }
      return 0;
       }

Measured memory_bytes: 1024
N=int(input())#問題の数
T=list(map(int,input().split()))#問題を解くのにかかる時間
M=int(input())#ドリンクの種類の数
for i in range(1,M+1):
    tmp=list(map(int,input().split()))
    tmp2=T[tmp[0]-1]
    T[tmp[0]-1]=tmp[1]
    print(sum(T))
    T[tmp[0]-1]=tmp2

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  string ss;cin>>ss;int n = ss.length();
  string s;
  rep(i,n){
    if(i < n-1 && ss[i] == 'B' && ss[i+1] == 'C'){
      s += 'D';i++;
    }
    else s += ss[i];
  }
  int ans = 0, a = 0;
  rep(i,s.length()){
    if(s[i] == 'A')a++;
    else if(s[i] == 'D'){
      ans += a;
    }else{
      a = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 900
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	bool F = true;
	cin >> N;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		if (A[i] % 2 == 0) {
			if (A[i] % 3 != 0 && A[i] % 5 != 0)F = false;
		}
	}
	if (F)cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char x = S.charAt(0);
        if ('A' <= x && x <= 'Z') {
            System.out.println('A');
        } else {
            System.out.println('a');
        }
    }
}



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

int main() {
  int a1,a2,a3,b1,b2,b3,c1,ans;
  scanf("%d%d",&a1,&b1);
  scanf("%d%d",&a2,&b2);
    scanf("%d",&c1);
  a3=a2-a1;
  b3=b2-b1;
  if(b3<0){
    --a3;
    b3=60+b3;
    ans=60*a3+b3-c1;
  }
  else{
    ans=60*a3+b3-c1;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 int main(){
   int n,k;
   cin>>n>>k;
   vector<int>h(n);
   int ans=0;
   for(int i=0;i<n;i++){
	cin>>h[i];
     if(h[i]>=k){
       ans++;
     }
   }
   
   cout<<ans<<endl;
   
 }

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    
    vector<int> vec(n);
    for(int i=0;i<n;++i){
        cin>>vec[i];
    }
    if(k>=n) {
        cout<<0<<endl;
        return 0;
    }
    sort(vec.begin(),vec.end());
    long long ans = 0;
    for(int i=0;i<n-k;++i){
        ans += vec[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int sum[101],n,mx,cou;
int main(){
    while(cin>>n){
        sum[n]++;
    }
    for(int i=0;i<100;i++)mx=max(mx,sum[i]);
    for(int i=0;i<100;i++){
        if(mx==sum[i]){
            cout<<i<<endl;
    }
    }
return 0;
}

Measured memory_bytes: 1160
# N = gets.chomp.to_i
# A, B, C = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars

a_exists = false
b_exists = false
S.each do |c|
  if c == 'A'
    a_exists = true
  else
    b_exists = true
  end
end

if a_exists && b_exists
  print "Yes\n"
else
  print "No\n"
end


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

bool dp[4001][16001];
int x,y,tx,ty,ax[4001],ay[4001];

void dfsx(int t,int n){
	if(dp[t][n+8000])return;
	if(t<tx){
		dfsx(t+1,n+ax[t]);
		dfsx(t+1,n-ax[t]);
	}
	dp[t][n+8000]=1;
}

void dfsy(int t,int n){
	if(dp[t][n+8000])return;
	if(t<ty){
		dfsy(t+1,n+ay[t]);
		dfsy(t+1,n-ay[t]);
	}
	dp[t][n+8000]=1;
}

int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s>>x>>y;
	bool fx=1;
	for(int i=0;i<s.length();++i){
		if(s[i]=='F'){
			if(fx)++ax[tx];
			else ++ay[ty];
		}else{
			if(fx)fx=0,++tx;
			else fx=1,++ty;
		}
	}
	if(s[s.length()-1]=='F'){
		if(fx)++tx;
		else ++ty;
	}
	dfsx(1,ax[0]);
	bool xx=dp[tx][8000+x]==1?1:0;
	memset(dp,0,sizeof(dp));
	dfsy(0,0);
	bool yy=dp[ty][8000+y]==1?1:0;
	if(xx&&yy)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 62976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	
	void prog()
	{
		cin = new Scanner();

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

		Console.WriteLine("{0} {1}", a * b, 2 * (a + b));
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 9124
#!/bin/env python

def main():
    s = raw_input().strip()
    retval = ""
    for c in s:
        if c == '1':
            retval += '9'
        elif c == '9':
            retval += '1'
        else:
            retval += c
    print retval

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int cnt[11];
    for (int i = 0; i < 11; i++) {
        cnt[i] = 0;
    }
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;
    if (cnt[5] == 2 && cnt[7] == 1) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
# include <set>
# include <iomanip>
# include <functional>
# include <queue>
#include<map>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}


int main() {
	int ko, naga;
	cin >> ko >> naga;
	string manji[108];
	for (int i = 0; i < ko; i++) {
		cin >> manji[i];
	}
	sort(manji, manji + ko);
	for (int i = 0; i < ko; i++) {
		cout << manji[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

result = 0
for i in range(n):
    beated_l = min(a[i],b[i])
    beated_r = min(a[i+1],b[i]-beated_l)
    result += beated_l + beated_r
    a[i+1] -= beated_r
print(result)

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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  int N, X;
  cin >> N >> X;
  int m[N];
  for (int i = 0; i < N; ++i)cin >> m[i];

  for (int i = 0; i < N; ++i)X -= m[i];

  sort(m, m+N);

  cout << X / m[0] + N << endl;
  return 0;
}


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

long long gcd(long long a, long long b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

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

int main(){
	long long a,b,c,d; cin >> a >> b >> c >> d;
	long long l = (b/lcm(c,d) - (a-1)/lcm(c,d));
	cout << (b - a + 1) - ((b/c - (a-1)/c) + (b/d - (a-1)/d) - l)<< endl;
}

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

int main(){
	long long n,k;
	cin>>n>>k;
	long long a[n+1],b[n+1];
	memset(b,0,sizeof(b));
	vector<long long> v;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int kk=1;
	long long ss=0;
	while(b[kk]==0){
		b[kk]=1;
		kk=a[kk];
		ss++;
	}
	memset(b,0,sizeof(b));
	while(b[kk]==0){
		b[kk]=1;
		v.push_back(kk);
		kk=a[kk];
	}
	if(k<ss-v.size()){
		int kk=1;
		while(k){
			k--;
			kk=a[kk];
		}
		cout<<kk<<endl;
		return 0;
	}
	k=(k-ss+(long long)v.size())%v.size();
	cout<<v[k]<<endl;
	return 0;
}


Measured memory_bytes: 8228
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;

  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vector<ll> mins = a;
  vector<ll> maxs = b;

  sort(ALL(a));
  sort(ALL(b));

  ll ans;
  ll lb, ub;
  if (n % 2 == 1) {
    lb = a[(n-1)/2];
    ub = b[(n-1)/2];
    ans = ub - lb + 1;
  } else {
    lb = a[(n/2)-1] + a[(n/2)];
    ub = b[(n/2)-1] + b[(n/2)];
    ans = ub - lb + 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int L;
string C;
int num[62];
//string R="Atcod3rIsGreatAtcod3rIsGreatAtcod3rIsGreatAtcod3rIsGreatAtcod3rIsGreatAtcod3rIsGreatAtcod3rIsGreatAtcod3rIsGreatAtcod3rIsG";
string R;
int dpdp[130][130];
string ret;

int edit(string& AA,string& BB) {
	int x,y,ma=0;
	FOR(x,130) FOR(y,130) dpdp[x][y]=1<<20;
	dpdp[0][0]=0;
	
	FOR(x,AA.size()+1) FOR(y,BB.size()+1) {
		dpdp[x+1][y+1]=min(dpdp[x+1][y+1],dpdp[x][y]+1);
		dpdp[x+1][y]=min(dpdp[x+1][y],dpdp[x][y]+1);
		dpdp[x][y+1]=min(dpdp[x][y+1],dpdp[x][y]+1);
		if(x<AA.size() && y<BB.size()) {
			if(AA[x]==BB[y]) dpdp[x+1][y+1]=min(dpdp[x+1][y+1],dpdp[x][y]);
		}
	}
	return dpdp[AA.size()][BB.size()];
}

int ask(string S) {
	static int num=0;
	num++;
	//assert(num<=849);
	cout<<"? "<<S<<endl;
	
	int x;
	if(R.size()) {
		x=edit(R,S);
	}
	else {
		cin>>x;
	}
	//cerr<<num<<" "<<R<<" "<<S<<" "<<x<<endl;
	if(x==0) {
		cerr<<num<<endl;
		cout<<"! "<<S<<endl;
		exit(0);
	}
	return x;
}

string hoge(string A,string B) {
	int pos=0;
	FORR(b,B) {
		while(1) {
			string C=A.substr(0,pos)+b+A.substr(pos);
			int r=ask(C);
			pos++;
			if(r==L-C.size()) {
				A=C;
				break;
			}
		}
	}
	return A;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	
	FOR(i,26) C+='a'+i;
	FOR(i,26) C+='A'+i;
	FOR(i,10) C+='0'+i;
	vector<pair<int,string>> cand;
	FOR(i,62) {
		num[i]=128-ask(string(128,C[i]));
		L+=num[i];
		if(num[i]) cand.push_back({num[i],string(num[i],C[i])});
	}
	
	
	while(cand.size()>1) {
		sort(ALL(cand));
		reverse(ALL(cand));
		string A=hoge(cand[cand.size()-1].second,cand[cand.size()-2].second);
		cand.pop_back();
		cand.pop_back();
		cand.push_back({A.size(),A});
		
	}
	
	ask(cand[0].second);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N, K; cin >> N >> K;
    int D[N]; rep(i, N) cin >> D[i];
    
    int ans = 0;

    for(int i = 0; i <= K; i++){
        //i回以下pushする
        vector<int> hand;
        if(K-i >= N){
            rep(j, N) hand.push_back(D[j]);
            sort(hand.begin(), hand.end());
            int acc = 0;
            for(int j = i; j < hand.size(); j++) acc += hand[j];
            if(acc > ans) ans = acc;
        }
        else{
            for(int j = 0; j <= K-i; j++){
                vector<int> hand2;
                //右からj回, 左からK-j-i回取り出す
                rep(k, K-j-i) hand2.push_back(D[k]);
                rep(k, j) hand2.push_back(D[N-1 - k]);

                sort(hand2.begin(), hand2.end());
                int acc = 0;
                int start = i;
                //cout << start << endl;
                while(start > 0 && start <= hand2.size() && hand2[start-1] > 0) start--;
                for(int k = start; k < hand2.size(); k++) acc += hand2[k];
                if(acc > ans) ans = acc;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(w>=x+r&&0<=x-r&&h>=y+r&&0<=y-r)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
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; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n;
	cin >> n;
	int a[110];
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = Inf;
	for (int B = 1; B <= 100; B++) {
		int tmp = 0;
		for (i = 0; i < n; i++) {
			tmp += pow(B - a[i], 2);
		}
		ans = min(ans, tmp);
	}
	cout << ans;
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

ll gcd(ll A, ll B) {
	if (A < B) return gcd(B, A);
	else if (B == 0) return A;
	else return gcd(B, A % B);
}


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


	int N;
	cin >> N;
	ll T[101];
	rep1(i, N) cin >> T[i];
	
	ll kotae = 1;
	rep1(i, N) {
		ll kari = gcd(kotae, T[i]);
		kotae /= kari;
		kotae *= T[i];
	}

	co(kotae);

	Would you please return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    int cnt = 0, mini = 1e9;
    for (int i = 0; i < n; i++) {
        if (mini > p[i]) cnt++;
        mini = min(mini, p[i]);
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 1024
# ABC090C - Flip, Flip, and Flip...... (ARC091C)
def main():
    n, m = sorted(list(map(int, input().rstrip().split())))
    if (n, m) == (1, 1):  # special case
        print(1)
    elif n == 1:
        print(m - 2)
    elif n == 2:
        print(0)
    else:
        print((n - 2) * (m - 2))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>

int n;
int v[101];
long long dp[101][21];

long long calc(int i,int j){
	if(j>20||j<0)return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	if(i==n-1&&j==v[n-1])return 1;
	else if(i==n-1&&j!=v[n-1])return 0;

	long long ans=0;
	ans+=calc(i+1,j+v[i]);
	ans+=calc(i+1,j-v[i]);
	return dp[i][j]=ans;
}

int main(){
	memset(dp,-1,sizeof(dp));
	std::cin>>n;
	for(int i=0;i<n;i++)std::cin>>v[i];
	std::cout<<calc(1,v[0])<<std::endl;;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    string s1,s2;
    s1=s.substr(0,2);
    s2=s.substr(2,2);
    int num1,num2;
    num1=stoi(s1);
    num2=stoi(s2);
    if(num1>12||num1==0){
        if(num2>12||num2==0){
            cout<<"NA"<<endl;
        }
        else{
            cout<<"YYMM"<<endl;
        }
    }
    else{
        if(num2>12||num2==0){
            cout<<"MMYY"<<endl;
        }
        else{
            cout<<"AMBIGUOUS"<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int n;  cin >> n;
    int cnt = 0, ans = 0;
    for (int i = 1; i <= n; i+=2) {
        cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0)
                cnt++;
        }
        if (cnt == 8)
            ans++;
    }

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

Measured memory_bytes: 256
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(args: Array<String>) {
    val c = Array(3) { readInts() }
    val a2 = c[1][0] - c[0][0]
    val a3 = c[2][0] - c[0][0]
    val ans = c[1][1] - c[0][1] == a2
        && c[1][2] - c[0][2] == a2
        && c[2][1] - c[0][1] == a3
        && c[2][2] - c[0][2] == a3
    println(if (ans) "Yes" else "No")
}


Measured memory_bytes: 38232
N=int(input())
s=[]
for i in range(N):
    s.append(int(input()))
a=[0]
ans=sum(s)
if ans%10==0:
    for i in s:
        if (ans-i)%10 != 0:
            a.append(ans-i)
    ans=max(a)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int K, N; cin >> K >> N;
    int a[N], d=0;
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N-1; i++){
        chmax(d, a[i+1]-a[i]);
    }
    chmax(d, a[0]+K-a[N-1]);
    cout << K-d << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int a,b;
	cin>>a>>b;
	cout<<(a+b-3)/(a-1)<<endl;
	return 0;
}


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

#define P pair<int,int>
#define vv vector<vector<int>>
#define v vector<int>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;

int main()
{
  vector<long long> arr;
  int n;
  cin >>n;
  rep(i,n)
  {
    long long x;
    cin>>x;
    arr.push_back(x);
  }

  rep(i,n)
  {
    if(arr[i]==0)
    {
      printf("0\n");
      return 0;
    }
  }

  long long ans=1;
  rep(i,n)
  {
    if(arr[i]<=1000000000000000000/ans)
    {
      ans*=arr[i];
    }
    else{
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n",ans);

}


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

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

	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}

	int a = 0;
	int b = 0;
	int c = 0;
	long long ans = 1;

	for (int i = 0; i < n; i++) {
		int x = 0;
		if (vec.at(i) == a) {
			a++;
			x++;
		}
		if (vec.at(i) == b) {
			if (x == 0) b++;
			x++;
		}
		if (vec.at(i) == c) {
			if (x == 0) c++;
			x++;
		}
		ans *= x;
		ans %= 1000000007;
      // cout << x << ":" << ans << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,a,b;
  cin>>n>>a>>b;
  int64_t x,y;
  x=n/(a+b);
  y=n%(a+b);
  if(y==0) cout<<x*a;
  else if(y<=a) cout<<x*a+y;
  else cout<<x*a+a;
}
  

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

P=[tuple(map(int,input().split())) for _ in [0]*N]

xM,yM,xm,ym=-3*10**9,-3*10**9,-3*10**9,-3*10**9
xM_list,xm_list,yM_list,ym_list=[],[],[],[]

for i in range(N):
    x,y=P[i]
    nr=(x+y,x-y,-x+y,-x-y)
    
    if xM<nr[0]:
        xM=nr[0]
        xM_list=[P[i]]
    elif xM==nr[0]:
        xM_list.append(P[i])
    if xm<nr[1]:
        xm=nr[1]
        xm_list=[P[i]]
    elif xm==nr[1]:
        xm_list.append(P[i])
    if yM<nr[2]:
        yM=nr[2]
        yM_list=[P[i]]
    elif yM==nr[2]:
        yM_list.append(P[i])
    if ym<nr[3]:
        ym=nr[3]
        ym_list=[P[i]]
    elif ym==nr[3]:
        ym_list.append(P[i])

xm_list.sort(lambda x:x[1])
xM_list.sort(lambda x:x[1])
ym_list.sort(lambda x:x[0])
yM_list.sort(lambda x:x[0])

# print(xm_list,xM_list,ym_list,yM_list)
goodP=[]

if len(xm_list)>1:
    goodP.append(xm_list[-1])
    goodP.append(xm_list[0])
else:
    goodP.append(xm_list[0])
if len(xM_list)>1:
    goodP.append(xM_list[-1])
    goodP.append(xM_list[0])
else:
    goodP.append(xM_list[0])
if len(ym_list)>1:
    goodP.append(ym_list[-1])
    goodP.append(ym_list[0])
else:
    goodP.append(ym_list[0])
if len(yM_list)>1:
    goodP.append(yM_list[-1])
    goodP.append(yM_list[0])
else:
    goodP.append(yM_list[0])

res=[]
for i in range(len(goodP)):
    for j in range(len(goodP)):
        if not i<j:
            continue
        res.append(abs(goodP[i][0]-goodP[j][0])+abs(goodP[i][1]-goodP[j][1]))
print(max(res))

Measured memory_bytes: 131960
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <math.h> 

using namespace std;
int H,K;
vector< vector< int > > vett;



long long int solve(int i, int j,vector<vector<long long int>> & DP){
	if(i==0 && j==0)
		return 1;
	if(i < 0 || j < 0 || vett[i][j] == 1)
		return 0;
	
	if(DP[i][j] != -1)
		return DP[i][j];
		
	DP[i][j] = (solve(i-1,j,DP) + solve(i,j-1,DP)) % ( (long int)pow(10,9) + 7 );
	return DP[i][j];
}


int main(int argc, char** argv) {
	cin >> H >> K;
	vett.resize(H);
	
	for(int i=0; i < H; i++){
		vett[i].resize(K);
		for(int j=0;j< K;j++){
			char p;
			cin >> p;
			vett[i][j] = (p == '#') ? 1 : 0;
		}
	}

	vector< vector<long long int > > DP(H, vector<long long int>(K,-1));
	
	cout << solve(H-1,K-1,DP) ;	
	
	
	
	return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, t; cin >> n >> t;
    V<pair<ll,ll>> v(n);
    REP(i, n){
        ll a, b; cin >> a >> b;
        v[i] = {a, b};
    }
    sort(all(v));
    ll res = 0;
    V<> dp(t + 5000, 0);
    REP(i, n) RREP(j, t) chmax(dp[j+v[i].first], dp[j] + v[i].second);
    REP(j, t + 5000) chmax(res, dp[j]);
    cout << res << '\n';
}

Measured memory_bytes: 3728
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;

signed main(){
  vector<int> ch(4,0);
  int a,b;
  cin>>a>>b;
  a--;
  b--;
  ch[a]++;
  ch[b]++;
  cin>>a>>b;
  a--;
  b--;
  ch[a]++;
  ch[b]++;
  cin>>a>>b;
  a--;
  b--;
  ch[a]++;
  ch[b]++;
  sort(ch.begin(),ch.end());
  if(ch[0]==ch[1]&&ch[0]==1&&ch[2]==ch[3]&&ch[2]==2)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
/*
[dp] S - Digit Sum
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 1e5;
const int MAX_D = 100;
const ll MOD = 1e9 + 7;

string K;
int N;
int D;
ll dp[MAX_N + 1][2][MAX_D];

ll solve() {
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < D; k++) {
                int lim = (j == 1) ? 9 : (K[i] - '0');
                for (int l = 0; l <= lim; l++) {
                    (dp[i + 1][j || (l < lim)][(k + l) % D] += dp[i][j][k]) %=
                        MOD;
                }
            }
        }
    }

    return (dp[N][0][0] + dp[N][1][0] + MOD - 1) % MOD;
}

int main() {
    cin >> K;
    cin >> D;
    N = K.length();

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 16640
#include<cstdio>
#include<algorithm>

const int N_MAX = 100000;
int a[N_MAX];

int max(int a, int b) { return a > b ? a : b; }

int main() {
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	std::sort(a, a+n);
	int b[2];
	b[0] = a[0];
	b[1] = a[n-1];
	long long ans = a[n-1] -a[0];
	for(int i=1;i < n-i-1;i++) {
		ans += b[i%2] - a[i];
		b[i%2] = a[i];
		ans += a[n-i-1] - b[(i+1)%2];
		b[(i+1)%2] = a[n-i-1];
	}
	if(n%2) {
		if(b[0] < b[1]) ans += max(b[1] - a[n/2], a[n/2] - b[0]);
		else ans += max(b[0] - a[n/2], a[n/2] - b[1]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 512
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

vector<int> solve(int a, int b, int n);
int add_bit(int a, int p, int b);
int delete_bit(int a, int p);

int main() {
	fast_cin();
	int n, a, b;
	cin >> n >> a >> b;
	int ctr = 0;
	for (int i = 0; i < n; ++i) {
		ctr += (a & (1 << i)) != (b & (1 << i));
	}
	if (ctr % 2 == 0) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	vector<int> ans = solve(a, b, n);
	for (auto &i : ans) {
		cout << i << ' ';
	}
	cout << endl;
}

vector<int> solve(int a, int b, int n) {
	if (n == 1) {
		return {a, b};
	}
	int x = 0;
	while ((a & (1 << x)) == (b & (1 << x))) {
		++x;
	}
	int u = delete_bit(a, x);
	int v = delete_bit(b, x);
	int c = u ^ 1;
	vector<int> l = solve(u, c, n - 1);
	vector<int> r = solve(c, v, n - 1);
	for (auto &i : l) {
		i = add_bit(i, x, (a >> x) & 1);
	}
	for (auto &i : r) {
		i = add_bit(i, x, (b >> x) & 1);
		l.pb(i);
	}
	return l;
}

int add_bit(int a, int p, int b) {
	return ((((a >> p) << 1) | b) << p) | (a & ((1 << p) - 1));
}

int delete_bit(int a, int p) {
	return ((a >> (p + 1)) << p) | (a & ((1 << p) - 1));
}

Measured memory_bytes: 1648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    int n,k;cin>>n>>k;
    VI p(n),c(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>c[i];
    rep(i,n)p[i]--;
    ll ans=-INFTY;
    rep(si,n){//siは開始位置
        int x=si;
        VI s;//siを開始としたサイクルの要素
        ll tot=0;//サイクルの和
        while(true){
            x=p[x];//遷移
            s.push_back(c[x]);
            tot+=c[x];
            if(x==si)break;//戻ってきたらサイクルの終わり
        }
        int l=s.size();
        ll t=0;
    rep(i,l){
        t+=s[i];
        if(i+1>k)break;
        ll now=t;
        if(tot>0){
            ll e=(k-(i+1))/l;//何回回せるか
            now+=tot*e;
        }
            chmax(ans,now);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3816
a,b = input().split()
a = int(a)
#print(b)
ans = a*int(b[0])
ans2 = a*int(b[2:])
#print(ans)
#print(ans2)
if len(str(ans2))>2:
    ans = ans + int(str(ans2)[:-2])
print(ans)



Measured memory_bytes: 61828
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
vector<int> u, d, f; // d はその頂点の発見時刻、f はその頂点の完了時刻
vector<bool> seen;

void dfs(vector<vector<int>> &g, int v, int& ptr) {
	seen[v] = true;
	ptr++;
	d[v] = ptr;
	for(auto next_v: g[v]) {
		if(seen[next_v]) continue;
		dfs(g, next_v, ptr);
	}
	ptr++;
	f[v] = ptr;
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	u.resize(n);
	d.resize(n);
	f.resize(n);
	seen.assign(n, false);
	rep(i, n) {
		cin >> u[i];
		int k;
		cin >> k;
		rep(j, k) {
			int tmp;
			cin >> tmp;
			tmp--;
			g[i].push_back(tmp);
		}
	}
	int ptr = 0;
	rep(i, n) {
		if(seen[i]) continue;
		dfs(g, i, ptr);
	}
	rep(i, n) {
		printf("%d %d %d\n", u[i], d[i], f[i]);
	}
	return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	double a,b; cin >> a >> b;
	double ans=a*b/(a+b);
	printf("%.7f\n",ans );
}

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

#define INF (1<<30)

#define Rep0(i, n)  for (int i=0; i<n; i++)
#define Rep1(i, n)  for (int i=1; i<=n; i++)

int main() {
    string s1, s2;
    cin >>s1 >>s2;
    int n1=s1.size();
    int n2=s2.size();
    vector<vector<int>> DP(n1+1, vector<int> (n2+1, INF));
    Rep0(i, n1+1)
        DP.at(i).at(0)=i;
    Rep0(j, n2+1)
        DP.at(0).at(j)=j;
    Rep1(i, n1)
        Rep1(j, n2) {
            int cost=1;
            if (s1.at(i-1)==s2.at(j-1))
                cost=0;
            DP.at(i).at(j)=DP.at(i-1).at(j-1)+cost;
            DP.at(i).at(j)=min(DP.at(i).at(j), DP.at(i-1).at(j)+1);
            DP.at(i).at(j)=min(DP.at(i).at(j), DP.at(i).at(j-1)+1);
        }
    cout <<DP.at(n1).at(n2) <<endl;
    return 0;
}


Measured memory_bytes: 6904
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=100005;

ll a[MAX_N];

int main(){
  ll N,K,mindif=LINF;
  cin >> N >> K ;
  rep(i,N) scanf("%lld",&a[i]);
  sort(a,a+N);
  if(N==1){
    if(a[0]==K) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  rep(i,N-1) if(a[i+1]-a[i]!=0) mindif=min(mindif,a[i+1]-a[i]);
  rep(i,N){
    if(a[i]>=K && (a[i]-K)%mindif==0){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

int main(){
    int d, t, s; cin >> d >> t >> s;

    if(d - t * s > 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 3588
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll n, x;
  while (true) {
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    ll ans = 0;
    for (int i = 1; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        for (int k = j + 1; k < n + 1; k++) {
          if (i + j + k == x) ans++;
        }
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;

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

	int tmp = N;
	int tot2 = 0;
	while (tmp != 0) {
		tot2 += tmp % 10;
		tmp /= 10;
	}

	//string s = to_string(N);

	//cout << "s " << s << endl;

	//int tot = 0;
	//for (int i = 0; i < s.size(); i++)
	//	tot += atoi( s[i].c_str());
	//cout <<"tot" << tot2 << endl;

	if (N % tot2 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	//cin >> N;

		return 0;
}

Measured memory_bytes: 384
N,M=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)
cs,bs=M.times.map{gets.split.map(&:to_i)}.transpose
card=Hash.new{0}
as.each do |e|
  card[e]+=1
end
M.times do |i|
  card[bs[i]]+=cs[i]
end

cnt=0
pos=-1
key=card.keys.sort.reverse
last=0
while cnt<=N
  pos+=1
  count=card[key[pos]]
  last+=count*key[pos]
  cnt += count
end
last-=(cnt-N)*key[pos]
puts last


Measured memory_bytes: 34824
import sys
from bisect import bisect_right, bisect_left

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    col = [1] * N
    col[0] = -A[0]
    for a in A[1:]:
        index = bisect_right(col, -a)
        col[index] = -a
        #print(col, index)
    ans = bisect_right(col, 0)
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 11804
//文字のカウント
#include<iostream>
#include<string>
using namespace std;

int main(){
    string str;
    int ab[26]={};
    int i;
    while(getline(cin,str)){
        for(i=0; i<str.size(); i++){
            if(str[i]>='a'&&str[i]<='z'){
                ab[str[i]-'a']++;
            }else if(str[i]>='A'&&str[i]<='Z'){
                ab[str[i]-'A']++;
            }
        }
    }
    for(i=0;i<26;i++){
        cout << (char)('a'+i) << " : " << ab[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int n;
    string s;
    cin>>n>>s;
    set<int> st;
    vector<bool> used(10,false);
    for(int i=0;i<n;i++){
	int num = s[i]-'0';
	if( !used[num] ){
	    used[num] = true;
	    vector<bool> rest(10,false);
	    int sum = 100*num;
	    for(int j=i+1;j<n;j++){
		int n2 = s[j]-'0';
		if( !rest[n2] ){
		    rest[n2] = true;
		    sum += 10*n2;
		    for(int k = j+1;k<n;k++){
			int n3 = s[k] -'0';
			st.insert( sum + n3 );
		    }
		    sum -= 10*n2;
		}
	    }
	}
    }
    
    cout<<st.size()<<endl;
  //  for(auto i:st)cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 384
class Dice:

    def __init__(self):
        # 初期値がない場合
        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        # 初期値が指定される場合
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        
        
def main():
    import random

    t1,s1,e1,w1,n1,b1 = map(int, input().split())
    t2,s2,e2,w2,n2,b2 = map(int, input().split())

    dice1 = Dice(t1,s1,e1,w1,n1,b1)
    dice2 = Dice(t2,s2,e2,w2,n2,b2)

    flag = 0

    for _ in range(10000):

        if (dice1.t, dice1.s, dice1.e, dice1.w, dice1.n, dice1.b) == (dice2.t, dice2.s, dice2.e, dice2.w, dice2.n, dice2.b):
            flag = 1
            break
        else:
            seed = random.randint(0, 3)
            dice2.rot(seed)

    if flag == 1:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()



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

const int mod = 998244353;
int n, k;
pair<int, int> seg[10];
long long pre[200002];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	for(int i = 0; i < k; i++)
		cin >> seg[i].first >> seg[i].second;
	sort(seg, seg + k);
	pre[1] = 1, pre[2] = -1;
	for(int i = 1; i <= n; i++){
		if(i)
			pre[i] = ((pre[i] + pre[i - 1]) % mod + mod) % mod;
		for(int j = 0; j < k; j++){
			int down = min(n + 1, i + seg[j].first);
			int up = min(n + 1, i + seg[j].second + 1);
			pre[down] = ((pre[down] + pre[i]) % mod + mod) % mod;
			pre[up] = ((pre[up] - pre[i]) % mod + mod) % mod;
		}
	}
	cout << pre[n] << '\n';
	return 0;
}

Measured memory_bytes: 5160
s = int(input())
vals = []
vals += [s]
n=1
while True:
    if vals[n-1]%2==0:
        val = vals[n-1]/2
    else:
        val = vals[n-1]*3+1
        
    if val in vals:
        print(len(vals)+1)
        break
    else:
        vals += [val]
        n += 1

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**5)
readline = sys.stdin.readline
writelines = sys.stdout.writelines
write = sys.stdout.write

N, M = map(int, readline().split())
*A, = map(int, readline().split())

A.sort(reverse=1)
CS = [0,2,5,5,4,5,6,3,7,6]

INV = (None, 0)
EMP = ([], 0)

memo = [[-1]*(N+1) for i in range(M+1)]
mM = memo[M]
mM[0] = EMP
for i in range(1, N+1):
    mM[i] = INV
def dfs(rest, i):
    mi = memo[i]
    if mi[rest] != -1:
        return mi[rest]
    v = A[i]; cost = CS[v]
    r = None
    cnt = 0
    k = 0
    kc = 0
    for k in range((rest // cost) + 1):
        r0, c0 = dfs(rest-k*cost, i+1)
        if r0 is not None:
            cnt0 = k + c0
            if r is None or cnt <= cnt0:
                r = r0
                cnt = cnt0
                kc = k
    if r is None:
        mi[rest] = INV
        return INV
    mi[rest] = res = [kc] + r, cnt
    return res
res, _ = dfs(N, 0)
ans = []
for i in range(M):
    ans.append(str(A[i]) * res[i])
writelines(ans)
write("\n")

Measured memory_bytes: 56668
import fractions as f

n = int(input())   
l = [[0 for i in range(n+1)] for j in range(n+1)]


cnt =0
for a in range(1,n+1):
    for b in range(1,n+1):
        
        if a > b : 
            q, w = b, a
        else:
            q ,w = a, b

        x = l[q][w]

        if x == 0:
            x = f.gcd(q, w)
            #print("qwx=",q,w,x)
            l[q][w] = x
        
        
            
        for c in range(1,n+1):
            e = x
            
            #print("a,b,c = ",a,b,c)
            if e > c : e, c = c, e

            y = l[e][c]
            if y == 0:
                y = f.gcd(e, c)
                #print("xcy=",x,c,y)
                l[e][c] = y

            cnt += y
            #print(a,b,e,y)

print (cnt)
#print(l)
#print(l[2][2])



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

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

    int a[3000] = { 0 };
    for( int i = 0; i < N; ++i )
        cin >> a[i];

    long int m = 0;
    for( int i = 0; i < N; ++i )
        m += a[i];

/*
    long int f, ans = 0;
    for( int i = m; -1 < i; --i ){
        f = 0;
        for( int j = 0; j < N; ++j ){
            f += i % a[j];
        }
        cout << i << " : " << f << endl;
        if( ans < f ) ans = f;
    }
*/
    cout << m-N << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    string s;
    cin>>s;
    rep(i,0,3)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            return;
        }

    }
    cout<<"No"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define min(a, b) a < b ? a : b
#define max(a, b) a > b ? a : b

#define MAXN 100000

int main(void)
{
	long long i;
	long long N;
	//int ok;
	long long sumn = 0, suma = 0, k;

	//scanf("%lld", &N);

	long long A[MAXN];
	long long d[MAXN];

	scanf("%lld", &N);

	for (i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		suma += A[i];
	}

	sumn = N * (N + 1) / 2;
	if ((suma % sumn) != 0) {
		//ok = 0;
		printf("NO\n");
	} else {
		k = suma / sumn;
		for (i = 0; i < N; i++) {
			d[i] = A[(i + 1) % N] - A[i] - k;
		}
		for (i = 0; i < N; i++) {
			/*if (d[i] % N == 0 && d[i] <= 0) {
				ok = 1;
			} else {
				ok = 0;
				break;
			}*/
			//ok = 1;
			if (d[i] % N != 0 || d[i] > 0) {
				//ok = 0;
				//break;
				printf("NO\n");
				return (0);
			}
		}
		printf("YES\n");
	}
	/*if (ok) {
		
	} else {
		printf("NO\n");
	}*/
	return (0);
}

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

int main(){
  int n,tmp;
  int alice=0,bob=0;
  cin >> n;
  vector<int> vec(n);
  
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(vec.at(i) < vec.at(j)){
		tmp = vec.at(i);
        vec.at(i) = vec.at(j);
        vec.at(j) = tmp;
      }
    }
  }
  
  for(int i=0; i<n; i += 2){
    alice += vec.at(i);
  }
  
  for(int i=1; i<n; i += 2){
    bob += vec.at(i);
  }
  
  cout << alice - bob << endl;
}

Measured memory_bytes: 256