akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++){
        for (int k = 0; k < B.size(); k++){
            for (int j = 0; j < B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main(){
    int n;
    cin >> n;
    P p[n];
    rep(i, n){
        cin >> p[i].second >> p[i].first;
    }
    sort(p, p + n);
    int t = 0;
    rep(i, n){
        t += p[i].second;
        if(t > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main()
{
    int n,c=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)
    {
        int t=a[i];
        int s=a[i+1];
        if(t==s)
        {
            c++;
            i++;
        }
    }
    cout<<c<<endl;
    return 0;
}


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

int main(){
  int n;
  while(1){
    cin>>n;
    if(!n)break;
    int a,b;
    int apoint=0,bpoint=0;
    rep(i,n){
      cin>>a>>b;
      if(a==b){
	apoint+=a;
	bpoint+=b;
      }else if(a>b){
	apoint+=(a+b);
      }else{
	bpoint+=(a+b);
      }
    }
    cout<<apoint<<" "<<bpoint<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> ans(m, 0);
    rep(i, n){
        int k;
        cin >> k;
        vector<int> a(k);
        rep(i, k){
            cin >> a.at(i);
            ans[a.at(i)-1]++;
        }
    }
    int cnt=0;
    rep(i, m)if(ans[i] == n)cnt++;
    cout << cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  ll left=0,right=0,ans=0;
  ll sum=0,xsum=0;
  while(left!=n){
    while(right<n && (sum+a[right]==(xsum^a[right]))){
      sum+=a[right];
      xsum^=a[right];
      right++;
    }
    ans+=right-left;
    sum-=a[left];
    xsum^=a[left];
    left++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int x=sc.nextInt();
      int k=sc.nextInt();
      for (int i=k-x+1; i<k+x; i++)
      {
        System.out.print(i+" ");
      }
      System.out.println();
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <string>

using namespace std;

int main(){
    string N;
    cin >> N;
    if (N[0] == N[1] && N[1] == N[2] ||
        N[1] == N[2] && N[2] == N[3]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
a=[]
4.times {a << gets.to_i}
count=0

(a[0]+1).times do |i|
  (a[1]+1).times do |j|
  	sum=0
    sum+=500*i+100*j
    if a[3] == sum
	  count+=1
    elsif a[3] > sum
      count+=1 if a[3] <= sum + 50 * a[2]
    end
  end
end
puts count

Measured memory_bytes: 1788
#include<stdio.h>
#define MOJI 1200

int main()
{
  char str[MOJI];
  int i, count=0;

  while(1){
    scanf("%c", &str[count]);

    if('A' <= str[count] && str[count] <= 'Z'){
      str[count] += 'a' - 'A';
    }
    else if('a' <= str[count] && str[count] <= 'z'){
      str[count] -= 'a' - 'A';
    }

    if(str[count] == '\n')break;
    count++;
  }

  for(i=0; i < count ;i++)
    printf("%c",str[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for(int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }
        sc.close();
        Arrays.sort(A);
        long[] K = new long[N];
        int index = 0;
        int index_k = 0;
        while(index < N-1){
            if(A[index] == A[index+1]){
                K[index_k++] = A[index];
                index += 2;
            }else{
                index++;
            }
        }
        Arrays.sort(K);
        long result = K[N-1] * K[N-2];
        System.out.println(result);

    }

}

Measured memory_bytes: 48460
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LIMIT 500


int compare_int(const void *a,const void *b){
  if(*(int*)a > *(int*)b) return 1;
  return -1;
}

int N, K;
int A[LIMIT];
int amari[LIMIT];

int ok(int d){
  for (int i = 0; i < LIMIT; i++) {
    amari[i] = 1e9+1;
  }
  for (int i = 0; i < N; i++) {
    amari[i] = A[i]%d;
  }

  qsort(amari, LIMIT, sizeof(int), compare_int);

  int sum[N+1];
  sum[0] = 0;
  for (int i = 1; i <= N; i++) {
    sum[i] = sum[i-1]+amari[i-1];
  }

  for (int i = 0; i <= N; i++) {
    if(sum[i] == ((N-i)*d-sum[N]+sum[i]) && sum[i] <= K) return 1;
  }

  return 0;
}


int main(void){
  scanf("%d%d", &N, &K);

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

  int ans = 1;
  for (int i = 1; i < sqrt(sum); i++) {
    if(sum%i) continue;
    if(ok(sum/i)){
      ans = sum/i;
      break;
    }
    if(ok(i)) ans = i;
  }

  printf("%d\n", ans);


  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(){
      string s;
      while(getline(cin,s)){
            for(int i=0;i<25;i++)while(s.find("the")==-1&&s.find("this")==-1&&s.find("that")==-1)for(int j=0;j<s.size();j++)if(s[j]>='a'&&s[j]<='z')s[j]!='z'?s[j]++:s[j]='a';
            cout<<s<<endl;
      }
}

Measured memory_bytes: 1176
#include <iostream>
using namespace std;
using ll=long long;

int main(){
    int N;
    cin >> N;
    ll ans = 0;
    for(ll i = 0; i < N; ++i){
        ll tmp1;
        cin >> tmp1;
        ans += tmp1 - 1;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int x; cin >> x;
  cout << (x >= 30 ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vll ans(11000, 0);

    for(ll x = 1; x <= 100; x++) {
        for(ll y = 1; y <= 100; y++) {
            for(ll z = 1; z <= 100; z++) {
                ll n = x*x + y*y + z*z + x*y + y*z + z*x;
                if(n <= 10000) ans[n]++;
            }
        }
    }
    for(ll i = 1; i <= N; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 3724
#include <stdio.h>
#define DIV 1000000007
int main(){
  char c;
  long long int dp[5]={0,1,0,0,0};

  while((c=getchar())!='\n')
    if(c=='?')
      for(int j=4;j>0;j--)
	dp[j]=(dp[j]*3+dp[j-1])%DIV;
    else
      dp[c-'A'+2]=(dp[c-'A'+2]+dp[c-'A'+1])%DIV;

  printf("%lld\n",dp[4]);

  return 0;
}


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

bool compair_by_second(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.second != b.second) {
        return a.second < b.second;
    }
    else {
        return a.first < b.first;
    }
}


bool compair_by_first(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.first != b.first) {
        return a.first < b.first;
    }
    else {
        return a.second < b.second;
    }
}

int main()
{
    ll N;
    cin >> N;
    vector<pair<ll,ll>> P(N);
    
    ll A;
    map<ll,ll> M;
    set<ll> S;
    REP(i,0,N) {
        cin >> A;
        P[i] = make_pair(i, A);
        ++M[A];
        S.insert(A);
    }
    
    ll sum = 0;
    FORR(s,S) sum += M[s] * (M[s] - 1) / 2;

    ll num, cnt, ans;
    REP(i,0,N) {
        num = P[i].second;
        cnt = M[num];
        ans = sum - cnt * (cnt - 1) / 2 + (cnt - 1) * (cnt - 2) / 2;
        _PR(ans);
    }

        

    return 0;
}

/*



*/

Measured memory_bytes: 18560
def is_month(x):
  if 1 <= x <= 12:
    return True
  else:
    return False

S = input()
first, latter = is_month(int(S[:2])), is_month(int(S[2:]))
if first and latter:
  ans = "AMBIGUOUS"
elif not first and not latter:
  ans = "NA"
elif first:
  ans = "MMYY"
else:
  ans = "YYMM"
print(ans)

Measured memory_bytes: 9112
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#define fi first
#define se second
#define db double
#define pb push_back
#define PI acos(-1.0)
#define ll long long int
#define pii pair<int,int>
#define sz(a) (int)(a).size()
#define bug printf("!!!!!!\n");
#define ull unsigned long long int
#define Fill(x,y) memset(x,y,sizeof(x))
using namespace std;
const db eps = 1e-6;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18;
const int mod = 1e9+7;
const int maxn = 1e6+5;
int n, m;
struct node {
    int to, next, w;
    bool operator < (const node& a) const {
        return w > a.w;
    }
} e[maxn<<1];
int cnt, head[maxn];
void add(int u, int v, int w) {
    e[cnt] = node{v, head[u], w};
    head[u] = cnt++;
}
bool vis[maxn];
int dis[maxn];
void dij(int st, int ed) {
    priority_queue<node> q;
    Fill(dis,inf); Fill(vis,0);
    dis[st] = 0;
    q.push(node{st, 0, 0});
    while (!q.empty()) {
        node u = q.top();
        q.pop();
        if(vis[u.to]) continue;
        vis[u.to] = 1;

        for (int i = head[u.to]; ~i; i = e[i].next) {
            int to = e[i].to;
            if (dis[to] > dis[u.to] + e[i].w) {
                dis[to] = dis[u.to] + e[i].w;
                q.push(node{to, 0, dis[to]});
            }
        }
    }
    printf("%d\n", dis[ed] == inf?-1:dis[ed]/2);
}
map<int, int>mp[maxn];
void init() {
    cnt = 0; Fill(head, -1);
    for (int i = 1 ; i <= n ; i ++) mp[i].clear();
}
int getid(int x, int y) {
    if (!mp[x][y]) mp[x][y] = ++n;
    return mp[x][y];
}
void solve() {
    while(~scanf("%d%d", &n, &m)) {
        init(); int ed = n;
        for (int i = 1 ; i <= m ; i ++) {
            int u, v, c;
            scanf("%d%d%d", &u, &v, &c);
            int uc = getid(u, c);
            int vc = getid(v, c);
            add(uc, vc, 0); add(vc, uc, 0);
            add(u, uc, 1); add(uc, u, 1);
            add(v, vc, 1); add(vc, v, 1);
        }
        dij(1, ed);
    }
}
int main() {
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "r", stdin);
#endif
    //  freopen("out.txt","w",stdout);
    int t = 1, cas = 1;
    //scanf("%d",&t);
    while(t--){
        //printf("Case #%d: ", cas++);
        solve();
        //printf("\n");
    }
}


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

int main()
{
	int n;
	while(cin>>n)
	{
		int ans=n%10;
		if(ans==2||ans==4||ans==5||ans==7||ans==9)
		cout<<"hon"<<endl;
		else if(ans==0||ans==1||ans==6||ans==8)
		cout<<"pon"<<endl;
		else
		cout<<"bon"<<endl;
	}
	
return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
int main (void){
    int A;
    int B;
    int K;
    scanf("%d %d",&A,&B);


    if(abs(A-B)%2 == 0  ){
       K =(A+B)/2;
        printf("%d",K);
         
    }else{
        printf("IMPOSSIBLE\n");
    }
return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int deg[26];				// Îx æª¶ÈçvXAÅãÌ¶Èç}CiX
vector<int> edge[26];	// æªÌ¶©çÅãÌ¶ÖÌGbW
bool vis[26];				// KâtO

bool dfs (int curr )
{
	vis[curr] = true;
	rep (i, edge[curr].size() )
		if (!vis[edge[curr][i]] )
			dfs (edge[curr][i] );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Kobutanukitsuneko", "r", stdin );
	int n;
	while (cin >> n && n ){
		rep (i, 26 ) deg[i] = 0, edge[i].clear(), vis[i] = true;
		int a, b;
		rep (i, n ){
			string word = ""; 
			cin >> word;
			a = word[0] - 'a', b = word[word.length()-1] - 'a';
			deg[a]++, deg[b]--;
			vis[a] = false, vis[b] = false;
			edge[a].push_back (b );
		} // end rep
		dfs (a );

		bool found = true;
		rep (i, 26 ){
			if (deg[i] != 0 || !vis[i] ){
				found = false;
				break;
			} // end if
		} // end rep

		if (found ){
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		} // end if
	} // end while
		
	return 0;
}

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

int main(void){
    long long K, A, B;
    cin >> K >> A >> B;
    long long r=1, i=0, m=0;
    for(i=0; i<K; i++){
        if(m == 1){
          	r += B;
          	m--;
        }
        else if(r < A) r++;
        else if(A >= B-1) r++;
        else if(i > K-2) r++;
        else{
            r -= A;
            m++;
        }
    }
    cout << r << endl;
}

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

using namespace std;
using ll = long long;

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

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

    ll sum = 0;
    for (int i = 0; i < 60; i++) {
        ll count = 0;
        for (int j = 0; j < N; j++) {
            if ((A[j] >> i) & 1) count++;
        }
        ll bits = ((N - count) * count);
        for (int j = 0; j < i; j++) bits = (bits * 2) % 1000000007;
        sum = (sum + bits) % 1000000007;
    }

    cout << sum << endl;
}


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

int main(void){
    ll N ,M;
    cin >> N >> M;
    ll A,B;
    P drink[N];
    rep(i,N){
        cin >> A >> B;
        drink[i] = {A,B};
    }
    sort(drink,drink+N);
    //rep(i,N) cout << drink[i].first << " " <<  drink[i].second << endl;
    
    ll rest = M;
    ll ans = 0;
    rep(i,N){
        if(rest - drink[i].second > 0){
            ans += (drink[i].first * drink[i].second);
            rest = rest-drink[i].second;
           // cout << ans << " " << rest<<endl;
        }else{
            ans += (rest * drink[i].first);
            break;
        }
    }
    
    cout << ans << endl;

}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] l = new long[n + 1];
		l[0] = 2;
		l[1] = 1;
		for(int i = 2 ; i <= n ; i++) {
			l[i] = l[i - 1] + l[i - 2];
		}
		System.out.println(l[n]);
	}
}

Measured memory_bytes: 23124
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        long N = scan.nextInt();
        long answer = 0;
        if(N % 2 == 0) {
            answer = N / 2 * (N - 1);
        } else {
            answer = (N-1) / 2 * N;
        }
        os.println(answer);
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    //vector<int> val;
public:
    UF(int n) : num(n) {
        par.resize(n);
        siz.resize(n);
        //val.resize(n);
        int i;
        for (i = 0; i < n; i++) {
            par[i] = i; siz[i] = 1;
            //val[i]=0;
        }
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (siz[x] < siz[y]) {
            par[x] = y;
            siz[y] = siz[x] + siz[y];
            //val[y]=val[x]+val[y];
        }
        else {
            par[y] = x;
            siz[x] = siz[x] + siz[y];
            //val[x]=val[x]+val[y];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
        //int ngroup( int& ans ) {
        int count = 0;
        int i;
        for (i = 0; i < num; i++) {
            if (par[i] == i) {
                count++;
                //ans += (val[i]? siz[i]: siz[i]-1);
            }
        }
        return count;
    }
};

void solve()
{
    int n,m;
    scanf("%d%d", &n, &m);
    vector<int> a(m),b(m);
    int i,j;
    for(i=0; i<m; i++) {
        scanf("%d%d", &a[i], &b[i]); a[i]--; b[i]--;
    }

    int ans=0;
    for(i=0; i<m; i++) {
        UF uf(n);
        for(j=0; j<m; j++) {
            if(i==j) continue;
            uf.unite(a[j],b[j]);
        }
        if(uf.ngroup()!=1) ans++;
    }
    printf("%d\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#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
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,K;
  cin >> N >> K;
  priority_queue<P> suzu;
  for(int i=0; i<N; i++){
    int t,d;
    cin >> t >> d;
    suzu.emplace(d,t);
  }
  ll ans = 0;
  set<int> used;
  ll now = 0;
  ll cnt = 0;
  ll sum = 0;
  priority_queue<int,vector<int>,greater<int>> in;
  for(int i=0; i<K; i++){
    int cost,v;
    tie(cost,v) = suzu.top();
    suzu.pop();
    if(used.count(v)){
      in.emplace(cost);
    }else{
      used.emplace(v);
      cnt++;
    }
    now += cost;
  }
  ans = now + cnt*cnt;
  while(suzu.size() && in.size()){
    int cost,v;
    tie(cost,v) = suzu.top();
    suzu.pop();
    if(used.count(v)) continue;
    used.emplace(v);
    now -= in.top();
    in.pop();
    cnt++;
    now += cost;
    chmax(ans,now+cnt*cnt);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 7112
#include <bits/stdc++.h>
 
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;
 
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  cout << min(B / A, C) << endl;
}

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

using namespace std;

#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const int inf = 1e9; 

const double PI =  3.14159265;

int main(){
	IO;
	string s;
	cin>>s;
	(s[2]==s[3]&&s[4]==s[5])?cout<<"Yes":cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

using namespace std;

#define MOD 1000000007
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ALL(x) ((x).begin(), (x).end())
#define sync(); ios_base::sync_with_stdio(0);

inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main() {
  sync();

  string s;
  cin >> s;
  ll k;
  cin >> k;

  ll n = s.length();
  
  for(ll i = 0; i < n; i++){
    if(s[i] == 'a'){

    }else{
      if('z'-s[i]+1 <= k){
		k -= ('z' - s[i] + 1);

	s[i] = 'a';
      }
    }
  }
  dump(s);
  dump(k);
  for(ll i = 0; i < k % 26; i++){
    if(s[n-1] == 'z'){
      s[n-1] = 'a';
    }else{
      s[n-1]++;
    }
  }
  cout << s << endl;
  return 0;
  

}


Measured memory_bytes: 592
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, K; cin >> A >> B >> K;
    vector<int> v;
    RREP(i, max(A, B), 1) {
        if(A % i == 0 && B % i == 0) K--;
        if (K == 0) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
#define X first
#define Y second
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
const int maxn=5e5+10;
const ll Inf=1e10;

ll ans;
ll n,k;
set<int>st;

//正向遍历一遍选择最小需要工作的天数，逆向遍历求解最大工作的天数，这样两者之间的交集就一定是需要工作的天数

int main(){

	int n,k,c;
	cin>>n>>k>>c;
	int res1[maxn],res2[maxn];
	string a;
	cin>>a;
	int pos=0;
	for(int i=0;i<n&&pos<k;i++){
		if(a[i]=='o'){
			res1[pos++]=i;
			i+=c;
		}
	}
	pos=k-1;
	for(int i=n-1;i>=0&&pos>=0;i--){
		if(a[i]=='o'){
			res2[pos--]=i;
			i-=c;
		}
	}
	for(int i=0;i<k;i++){
		if(res1[i]==res2[i]){
			cout<<res1[i]+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4612
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
	long n=s.nextLong();
	long ans=0;
	if(n%2==1)
	System.out.println("0");
	else
	{	n=n/2;
	    for(int i=1;n>=(long)Math.pow(5,i);i++)
	{ans+=(n/(long)Math.pow(5,i));}
	    System.out.println(ans);}}
	}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// cmdG

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

    string st, yui;
    cin >> st >> yui;

    string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    for (int i = st.size() - yui.size(); i >= 0; i--) {
        bool ok = true;
        string tmp;
        for (int j = 0; j < i; j++) {
            if (st[j] == '?') {
                tmp.pb('a');
            } else {
                tmp.pb(st[j]);
            }
        }
        for (int j = 0; j < yui.size(); j++) {
            if (!(st[i+j] == yui[j] || st[i+j] == '?')) {
                ok = false;
                break;
            } else {
                tmp.pb(yui[j]);
            }
        }
        for (int j = i + yui.size(); j < st.size(); j++) {
            if (st[j] == '?') {
                tmp.pb('a');
            } else {
                tmp.pb(st[j]);
            }
        }
        if (ok) {
            ans = (ans > tmp) ? tmp : ans;
        }
    }

    if (ans == "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") {
        cout << "UNRESTORABLE" << endl;
    } else {
        cout << ans << endl;
    }


    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <numeric>
#include <algorithm>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

vector<int> aa;

typedef long long ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
    {
        //        aa.push_back(b);
        return a;
    }
    else
        return gcd(b, (a % b));
}

vector<pair<ll, int>> factorize(ll n)
{
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i)
    {
        if (n % i)
            continue;
        res.emplace_back(i, 0);
        while (n % i == 0)
        {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1)
        res.emplace_back(n, 1);
    return res;
}

int main()
{
  

    ll a, b;
    cin >> a;
    cin >> b;

    ll n = gcd(a, b);
    auto f = factorize(n);
    int ans = f.size() + 1;

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f

const int N = 1e5;

int dp[N+5];
int arr[N+5];

int main(){

	ios_base::sync_with_stdio(0);
	int n, k; cin >>n >>k;
	for(int i = 1; i<=n; i++) cin >>arr[i];
	arr[0] = arr[1];
	
	dp[0] = dp[1] = 0;
	for(int i = 2; i<=n; i++){
		int temp = INF;
		for(int j = 1; j<=k; j++){
			if(i-j > 0){ 						
				temp = min(temp, dp[i-j] + abs(arr[i] - arr[i-j]));
			} 
			else break;
		}
		dp[i] = temp;
	}
	
	cout <<dp[n] <<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int numbers[] = new int[n];
        int total = 0;
        int count = 0;
        int min = n + 1;
        for(int i = 0; i < n; i++){
            numbers[i] = Integer.parseInt(sc.next());
            total += numbers[i];
        }
        for(int i = 0 ; i < n; i++){
            count += numbers[i];
            int temp = Math.abs(total - (count * 2) );
            if(temp < min) min = temp;
        }
        System.out.println(min);
        
    }
    
}

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

void print_array( std::vector<int> A ){
  for( int i = 0; i < A.size(); i++ )
  {
      std::cout << A[i];
      if( i != A.size()-1 ) std::cout << " ";
  }
  std::cout << std::endl;
}

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

  std::vector<int> A( N );
  for( int i = 0; i < N; i++ ){
    std::cin >> A[i];
  }

  //挿入ソート
  print_array( A );
  for( int i = 1; i < N; i++ ){
    int v = A[i];
    int j = i - 1;
    while( j >= 0 && v < A[j] ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    print_array( A );
  }
}



Measured memory_bytes: 3140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//0入力するまで続けて、標準偏差を出力する
public class Main {

    public static void main(String[] args) throws IOException {
        // TODO 自動生成されたメソッド・スタブ
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
        while (!((line = br.readLine()).equals("0"))) {
            int students = Integer.parseInt(line);
            String[] inputScore = br.readLine().split(" ");
            int[] data = new int[students];
            double sum = 0;
            double average = 0;
            double squaresum = 0;

            for (int i = 0; i < students; i++) {
                sum += Integer.parseInt(inputScore[i]);
//                System.out.println(Integer.parseInt(inputScore[i]));
//                System.out.println(sum);
            }
            average = sum / students;

            for (int i = 0; i < students; i++) {
                squaresum += Math.pow(Integer.parseInt(inputScore[i]) - average, 2);
            }

            double varience = squaresum / students;
            System.out.println(Math.sqrt(varience));
        }

    }

}


Measured memory_bytes: 25408
#include <iostream>

int main(int argc, char const* argv[])
{
	int h,w;
	std::cin >> h >> w;
	while (!(h==0&&h==w)) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i==0||i==h-1||j==0||j==w-1) {
					std::cout << "#" ;
				} else {
					std::cout << "." ;
				}
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
		std::cin >> h >> w;
	}

	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

int n, k;

bool probaj(int mid, vi &v)
{
    int potrebno = 0;
    for(int i = 0; i < n; ++i)
    {
        if(v[i]<=mid)
            continue;
        potrebno += v[i] / mid;
    }
    return potrebno <= k;
}

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

    cin >> n >> k;

    int maksi = -1e9;
    vi v(n);
    for(auto &z : v)
    {
        cin >> z;
        maksi = max(maksi,z);
    }
    int l = 1, r = maksi;
    int ans = r;

    while(l<=r)
    {
        int mid = l + (r-l)/2;

        if(probaj(mid,v))
        {
            ans = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }

    cout << ans << '\n';
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int a,b,c,k,sum=0;
	cin>>a>>b>>c>>k;
	if(k<=a)
	sum=k;
	else if(k>a&&k<=(a+b))
	sum=a;
	else sum=a-(k-a-b);
	cout<<sum; 
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;

class Main{
	Scanner scan = new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	public Main(){
		int d=a/b;
		int r=a%b;
                double f=(double)a/(double)b;
		System.out.printf("%d %d %.5f", d, r, f);
	}
	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 26296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string,int> mp;
int g[13][13];
int ct[13][2];
int get(int x,int y,int h,int w){
	int res = 0;
	vector<int> v;
	vector<int> v2;
	int tx = x,ty = y; 
	for(int i=0;i<h;i++){
		if(tx>>i & 1) v.push_back(i);
	}
	for(int i=0;i<w;i++){
		if(ty>>i & 1) v2.push_back(i);
	}
	int l1 = v.size();
	int l2 = v2.size();
	for(int i=0;i<l1;i++){
		for(int j=0;j<l2;j++){
			if(g[v[i]][v2[j]]==2) res--;
		}
	}
	for(int i=0;i<l1;i++){
		res += ct[v[i]][0];
	}
	for(int i=0;i<l2;i++){
		res += ct[v2[i]][1];
	}
	return res;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int h,w,k;
	cin>>h>>w>>k;
	string s;
	int sum = 0;
	for(int i=0;i<h;i++){
		cin>>s;
		for(int j=0;j<w;j++){
			if(s[j]=='.') g[i][j] = 1;
			else g[i][j] = 2;
			if(g[i][j]==2) sum++;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(g[i][j]==2) ct[i][0]++;
		}
	}
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
			if(g[j][i]==2) ct[i][1]++;
		}
	}
	if(sum<k){
		cout<<0<<endl;
		return 0;
	}
	int ans = 0;
	for(int i=0;i<(1<<h);i++){
		for(int j=0;j<(1<<w);j++){
			if(sum - get(i,j,h,w)==k) ans++;
		}
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
using namespace std;

#define N 1000
#define EPS 1e-9

int arr[N];

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

	int n, k, ans;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	ans = 0;
	for (int i = 0; k; --k, ++i)
		ans += arr[i];
	cout << ans << '\n';

}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <set>

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	set<int> mochi;

	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin >> tmp;
		mochi.insert(tmp);
	}

	cout << mochi.size() << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=50,M=1e9+7;
lli base[N][N],ans[N][N];
lli n,k;
void mul1()
{
    lli ret[n][n];
    memset(ret, 0LL, sizeof(ret)); 
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                ret[i][j]=(ret[i][j]+ans[i][k]*base[k][j])%M;
            }
        }
    }
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) ans[i][j]=ret[i][j];
}
void mul2()
{
    lli ret[n][n];
    memset(ret, 0LL, sizeof(ret));
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                ret[i][j]=(ret[i][j]+base[i][k]*base[k][j])%M;
            }
        }
    }
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) base[i][j]=ret[i][j];
}

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    cin>>n>>k;
    lli i,j,tot=0;
    
    for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>base[i][j];
    
    for(i=0;i<n;i++) ans[i][i]=1;
    
    while(k)
    {
        if(k%2==1)
            mul1(); //ans=ans*base
        mul2();     //base=base*base
        k/=2;
    }
    
    for(i=0;i<n;i++) for(j=0;j<n;j++) tot=(tot+ans[i][j])%M;
    
    cout<<tot;
    return 0;
}

Measured memory_bytes: 384
#include <string>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll x,n;
    cin >> n >> x;
    vector<ll> l(n);
    for(ll i = 0;i < n;i++){
        cin >> l[i];
    }
    ll cnt = 1;
    ll pi = 0;
    for(ll i = 0;i < n;i++){
        pi += l[i];
        if(x >= pi){
            cnt++;
        }
    }
    cout << cnt;
}

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

typedef long long LL;
const int N = 505;
const LL inf = 0x3f3f3f3f3f3f3f3f;

LL dp[2][N][N], sum1[N][N], sum2[N][N], ans = inf;
int n;

void down(LL &x, LL y) { x = std::min(x, y); }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < i; ++j)
			std::cin >> sum1[i][j];
		for (int j = i + 1; j <= n; ++j)
			std::cin >> sum2[j][i];
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j < i; ++j)
			sum1[i][j] += sum1[i][j - 1], sum2[i][j] += sum2[i][j - 1];
	dp[1][1][0] = 0;
	for (int i = 2; i <= n; ++i) {
		int now = i & 1, lst = now ^ 1;
		std::memset(dp[now], 0x3f, sizeof dp[0]);
		for (int j = 1; j < i; ++j)
			for (int k = 0; k < j; ++k) if (dp[lst][j][k] < inf) {
				down(dp[now][j][k], dp[lst][j][k] + sum1[i][k - 1] + sum2[i][i - 1] - sum2[i][j - 1]);
				down(dp[now][i][j], dp[lst][j][k] + sum1[i][j - 1]);
			}
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < i; ++j)
			down(ans, dp[n & 1][i][j]);
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 8192
/*   _ _ _                     
    | | | | ___  ___           
    | | | || . ||  _|          
    |_____||_  ||_|  _____     
             |_|    |_____|  */
// Time : 19/10/18
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
int main(){
#ifdef Wqr_
    freopen("in.txt","r",stdin);
#endif
    //std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    string in;
    cin >> in;
    bool flag = 1;
    for(int i = 0; i < in.length(); i++){
        if (i % 2) {
            if(in[i] != 'L' && in[i] != 'U' && in[i] != 'D') flag = 0;
        } else {
            if (in[i] != 'R' && in[i] != 'U' && in[i] != 'D') flag = 0;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
# reffer to http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2968766#1
class Node(object):
  def __init__(self, num, prv = None, nxt = None):
    self.num = num
    self.prv = None
    self.nxt = None

class DoublyLinkedList(object):
  def __init__(self):
    self.start = self.last = None

  def insert(self, num):
    new_elem = Node(num)

    if self.start is None:
      # 最初と最後にnew_elemをセット
      self.start = self.last = new_elem
    else:
      # 前に追加していくのでnew_elemの次にself.startをセット
      new_elem.nxt = self.start
      self.start.prv = new_elem
      self.start = new_elem

  def delete_num(self, target):
    it = self.start
    while it is not None:
      if it.num == target:
        # nodeが1つしか無いかのチェック
        if it.prv is None and it.nxt is None:
          self.start = self.last = new_elem
        else:
          # 先頭かどうかのチェック
          if it.prv is not None:
            it.prv.nxt = it.nxt
          else:
            self.start = self.start.nxt

          # 最後かどうかのチェック
          if it.nxt is not None:
            it.nxt.prv = it.prv
          else:
            self.last = self.last.prv

        break

      # 対象nodeを次に回す
      it = it.nxt

  def delete_start(self):
    if self.start is self.last:
      self.start = self.last = None
    else:
      self.start.nxt.prv = None
      self.start = self.start.nxt

  def delete_last(self):
    if self.start is self.last:
      self.start = self.last = None
    else:
      self.last.prv.nxt = None
      self.last = self.last.prv

  def get_content(self):
    ret = []
    it = self.start

    while it is not None:
      ret.append(it.num)
      it = it.nxt

    return ' '.join(ret)

def _main():
  from sys import stdin

  n = int(input())

  lst = DoublyLinkedList()

  for _ in range(n):
    cmd = stdin.readline().strip().split()
    if cmd[0] == 'insert':
      lst.insert(cmd[1])
    elif cmd[0] == 'delete':
      lst.delete_num(cmd[1])
    elif cmd[0] == 'deleteFirst':
      lst.delete_start()
    elif cmd[0] == 'deleteLast':
      lst.delete_last()


  print(lst.get_content())

if __name__ == '__main__':
  _main()


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

using namespace std;

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<ll> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

  int ans = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L[i] + L[j] > L[k] && L[i] != L[j] && L[j] != L[k]) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
N,M=list(map(int,input().split()));
SC=[list(map(int,input().split())) for i in range(M)]



for i in range(10**N):
  s=str(i)
  if(len(s)==N):
    
    OK=True
    for j in range(M):
      OK&=(s[SC[j][0]-1]==str(SC[j][1]))
      
    if(OK):
      print(s)
      exit()
      
print(-1)
    

Measured memory_bytes: 3060