akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


const ll INF = 1e18;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

struct Edge{
    int to;
    ll cost;
};

bool operator<(const Edge& lhs, const Edge& rhs){
    if(lhs.cost != rhs.cost)
        return lhs.cost < rhs.cost;
    else{
        return lhs.to > rhs.to;
    }
}


void dijkstra(vector<vector<Edge>> &edge, vector<ll> &mini)
{
    int n = edge.size();
    mini.resize(n, INF);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push(make_pair(0, 0));


    while (!pq.empty())
    {
        auto t = pq.top();
        pq.pop();
        ll cost = t.first;
        int node = t.second;
        if (mini[node] <= cost)
            continue;

        mini[node] = cost;
        for (auto e : edge[node]) {
            if(mini[e.to] == INF)
                pq.push(make_pair(cost + e.cost, e.to));
        }  
    }
}

      


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

    vector<vector<Edge>> edges(n);

    REP(i, m){
        int l, r, c;
        cin >> l >> r >> c;
        l--, r--;
        edges[l].push_back({r, c});
    }

    REP(i, n-1){
        edges[i+1].push_back({i, 0});
    }
    vector<ll> mini;
    dijkstra(edges, mini);


    cout << (mini[n-1]==INF?-1:mini[n-1]) << endl;

    return 0;
    
}

Measured memory_bytes: 9972
while 1:
    a,op,b = input().split()
    if op == "?":
        break
    a = int(a)
    b = int(b)
    if op == "+":
        print("{:d}".format(a+b))
    elif op == "-":
        print("{:d}".format(a-b))
    elif op == "*":
        print("{:d}".format(a*b))
    elif op == "/":
        print("{:d}".format(a//b))


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;

int main() {
	int n;
	scanf("%d" , &n);
	int arr[n];
	for (int i = 0 ; i < n ; i++){
		scanf("%d" , &arr[i]);
		if (arr[i] &1) return printf("first\n") , 0;
	}
	printf("second\n");

}



Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;
template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using Vb = V<bool>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using VVb = V<Vb>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int cDiv(const ll x, const ll y) { return (x+y-1) / y; } // ceil(x/y)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
// struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = 1<<30;
// const ll INFll = 1ll<<60;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


Vl a;

void solve2(ll k, ll n, ll l) {
  if (n == 0) return;
  ll d = l / (a[n-1] + 1);
  ll r = l % (a[n-1] + 1);
  cout << (d+1) << ' ';
  if (r == 0) return;
  solve2(k, n-1, r-1);
}

void solve(ll k, ll n) {
  if (k % 2 == 0) {
    cout << (k/2) << ' ';
    rep(i, n-1) cout << k << ' ';
    return;
  }

  ll m = 0;
  while (n-m >= a[m]) ++m;
  rep(i, n-m) cout << (k+1)/2 << ' ';
  
  solve2(k, m, (a[m]-n+m-1)/2);
}


int main() {
  ll k, n; cin >> k >> n;

  a.assign(n+2, 0);
  rep(i, n+1) {
    a[i+1] = k * (a[i]+1);
    if (a[i+1] > n) break;
  }

  solve(k, n);
  cout << '\n';
}


Measured memory_bytes: 5616
<?php
$input = trim(fgets(STDIN));
while( 0 != $input ) {
    
    $list = str_split($input);
    $sum = 0;
    
    foreach ($list as $i) {
        $sum += (int)$i;
    }
    
    echo $sum . "\n";
    $input = trim(fgets(STDIN));
}

Measured memory_bytes: 15380
#include<iostream>
#include<string>
#include<algorithm>

int main(){
  std::string s;
  std::cin >> s;
  int length[20]={};
  int i=0;
  for(auto& e : s){
    if(e=='A'||e=='T'||e=='G'||e=='C')
      length[i]++;
    else
      i++;
  }
  int max=0;
  for(int j=0;j<20;j++){
    max = std::max(length[j],max);
  }
  std::cout<<max<<std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  string s;
  cin >> s;
  char before;
  before = s[0];
  bool isSame = true;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != before) isSame = false;
  }

  if (isSame) cout << "No" << endl;
  else cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
 
using namespace std;

int main(){
  ll X;
  cin >> X;
  ll num = 100;
  for(int i=1;i<4000;i++){
    num = num * 1.01;
    if(X<=num){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


// 編集距離（レーベンシュタイン距離）
#define MAX_LENGTH_S1 (1000)
#define MAX_LENGTH_S2 (1000)

int edit_dist(const string S1, const string S2) {
	int len1 = S1.size();
	int len2 = S2.size();
	// dp[i][j]:S1[i]までとS2[j]までの最長共通部分列
	vector<vector<int>> dp(len1 + 1, vector<int>(len2 + 1));
	dp[0][0] = 0;
	for (int i = 1; i <= len1; i++) dp[i][0] = i;
	for (int i = 1; i <= len2; i++) dp[0][i] = i;
	for (int i = 0; i < len1; i++) {
		for (int j = 0; j < len2; j++) {
			dp[i + 1][j + 1] = min(dp[i][j] + (S1[i] != S2[j]), min(dp[i][j + 1] + 1, dp[i + 1][j] + 1));
		}
	}
	int edit_dist = dp[len1][len2];
	return edit_dist;
}

int main() {

	string S1, S2;
	cin >> S1 >> S2;

	cout << edit_dist(S1,S2) << endl;

	return 0;
}



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

int main() {
	vector<char> vec1(3);
	vector<char> vec2(3);

	for (int i = 0; i < 3; i++)
		cin >> vec1.at(i);

	for (int i = 0; i < 3; i++)
		cin >> vec2.at(i);

	reverse(vec2.begin(), vec2.end());

	if (vec1 == vec2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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

using namespace std;

int w;
int a;
int b;

void solve()
{
    int x,y,z;
    x=min(a,b);
    y=max(a,b);
    z=x+w;
    if(z<y)
        printf("%d\n",y-z);
    else
        printf("%d\n",0);
}

int main()
{
    while(cin>>w>>a>>b)
        {
            solve();
        }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
#define MODSIZE 1000000007
priority_queue<int, vector<int>, greater<int> > PQ; // 昇順PQ
// priority_queue<int> PQ;

int main(){
  ll a;
  long double b;

  cin >> a >> b;

  ll ans = a*b;

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

  return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
int main(){
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    map<char,int> m;
    rep(i,h) {
        string s;
        cin >> s;
        rep(j,w) {
            m[s[j]];
            m[s[j]]++;
        }
    }
    int num4=0, num2=0, num1=0;
    if(h%2==0 && w%2 ==0) {
        num4 = w/2*h/2;
    } else if(w%2 == 0) {
        num4 = (w/2)*(h-1)/2;
        num2 = w/2;
    } else if(h%2 == 0) {
        num4 = (w-1)/2*h/2;
        num2 = h/2;
    } else {
        num4 = (w-1)/2*(h-1)/2;
        num2 = (h-1)/2 + (w-1)/2;
        num1 = 1;
    }
    for(auto itr = m.begin(); itr != m.end(); itr++) {
        int n = (*itr).second;
        num4 -= n/4;
        n%=4;
        num2 -= n/2;
        n%=2;
        if(num4 < 0) {
            num2 -= -num4*2;
            num4 = 0;
        }
        num1 -= n;
        if(num1 < 0 || num2 < 0 || num4 < 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int N;
string s;
int t[200005];

int main(){
  cin>>N>>s;
  
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      t[0]=i;
      t[1]=j;
      
      for(int k=2;k<N+N;k++){
        if( (s[(k-1)%N]=='o') ^ t[k-1] )t[k]=t[k-2];
        else t[k]=1-t[k-2];
      }

      bool flg=true;
      for(int k=0;k<N;k++)
        if(t[k]!=t[k+N])flg=false;
      
      if(flg){
        for(int k=0;k<N;k++)cout<<(t[k]==0?'S':'W');
        cout<<endl;
        return 0;
      }
      
    }
  }
  cout<<-1<<endl;
  return 0;
}


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

int main()
{
	string s;
	cin >> s;
	if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3])
		cout << "Bad";
	else
		cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace @try
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sp = Console.ReadLine().Split(' ');
            int x = int.Parse(sp[0]);
            int y = int.Parse(sp[1]);
            Console.WriteLine("{0} {1}", x * y, (x + y) * 2);
        }
    }
}

Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
using namespace std;
long long F[100][10];
long long P[100][11];
int main(void) {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> P[i][j];
    }
  }

  long long ans = -9223372036854775808;
  // 営業中の時間帯bit1
  // 営業なしはなしなので下限値は1
  for (unsigned int op = 1; op < (1<<10); op++) {
    long long profit = 0;
    for (int store_num = 0; store_num < N; store_num++) {
      unsigned int op_count = 0;
      for (unsigned int time_zone = 0; time_zone < 10; time_zone++) {
        // お姉ちゃんが店を開かない場合は営業利益を計算しない
        if ((op & (1<<time_zone)) == 0) continue;

        if (F[store_num][time_zone]==1) op_count++;
      }
      profit += P[store_num][op_count];
    }
    ans = max(ans, profit);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main()
{
  char s[4],r[4];
  cin>>s>>r;
  int answer=0;
  for(int i=0;i<3;i++)
  {
    if(s[i]==r[i])
      answer++;
  }
  cout<<answer;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a, b, c, number, i;

int main(){

	cin >> a >> b >> c;

	i = a;
	number = 0;

	while (i <= b){

		if (c % i == 0){
			number++;
		}
		i++;
	}
	cout << number << endl;
	return 0;
}






Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


vector<int> operator * (const vector<int> &a, const vector<int> &b) {
    vector<int> res(a.size());
    for (int i = 0; i < res.size(); ++i) res[i] = a[b[i]];
    return res;
}

vector<int> power(const vector<int> &a, long long N) {
    vector<int> res(a.size());
    iota(res.begin(), res.end(), 0);
    if (N == 0) return res;
    res = power(a, N/2);
    res = res * res;
    if (N & 1) res = res * a;
    return res;
}

int N, M;
long long K;
vector<long long> x, a;

int main() {
    cin >> N;
    x.resize(N);
    for (int i = 0; i < N; ++i) cin >> x[i];
    for (int i = N-1; i >= 1; --i) x[i] -= x[i-1];
    cin >> M >> K;

    vector<int> p(N);
    iota(p.begin(), p.end(), 0);
    a.resize(M);
    for (int i = 0; i < M; ++i) {
        cin >> a[i], --a[i];
        swap(p[a[i]], p[a[i]+1]);
    }

    //COUT(p);
    
    p = power(p, K);
    vector<long long> res(N);
    for (int i = 0; i < N; ++i) res[i] = x[p[i]];
    for (int i = 1; i < N; ++i) res[i] += res[i-1];
    for (int i = 0; i < N; ++i) {
        cout << fixed << setprecision(10) << (double)(res[i]) << endl;
    }
}


Measured memory_bytes: 26112
#include<bits/stdc++.h>
#define F first
#define S second
#define LL long long
#define MP make_pair
#define PB push_back
#define I insert

const LL mod=1000000007, N=200005;
using namespace std;

LL n, m, i, j, k, l, r, t, ans;

int main(){
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

	return 0;
}
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE ___ KAPANADZE




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[100],x = 0,y = 0;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a + n,greater<int>());
	for(int i = 0;i < n;i++){
		if(i % 2 == 0) x += a[i];
		else y += a[i];
	}
	cout << x - y << endl;
	return 0;
}

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

#define DAY_TIME 86400

//??¢??°(00:00:00??????????§???°?????????)
int timeToNum(char* text) {
	int ans=0;
	//h
	ans += (text[0] - '0') * 60 * 60 * 10;
	ans += (text[1] - '0') * 60 * 60;
	//m
	ans += (text[3] - '0') * 60 * 10;
	ans += (text[4] - '0') * 60;
	//s
	ans += (text[6] - '0') * 10;
	ans += (text[7] - '0');

	return ans;
}

//?????????????????????
int imosu[DAY_TIME];

//??????????????¨??????
int N;

//??????????????¨??°?????????
char timeS[100];
char timeE[100];

//??????
int ans;

int main() {
	while (true) {
		//?????????
		for(int i=0;i<DAY_TIME;i++)imosu[i]=0;
		ans=0;

		//??\?????¨???????????¶
		cin>>N;
		if(N==0)break;

		for(int i=0;i<N;i++){
			//??\???
			cin >> timeS;
			cin >> timeE;
			
			//???????????????????????????
			imosu[timeToNum(timeS)]++;
			imosu[timeToNum(timeE)]--;
		}

		//????????????????????????????????????
		for (int i = 0; i < DAY_TIME-1; i++) {
			imosu[i+1]+=imosu[i];
			ans=max(ans,imosu[i+1]);
		}
		//?????§????????????
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353
#define N 210

int n;

ll power(ll x,ll y) {
	if (!y) return 1;
	ll ret=power(x,y>>1)%mod;
	ret=ret*ret%mod;
	if (y&1) ret=ret*x%mod;
	return ret%mod;
}

int x[N],y[N],A,B,cnt;
ll ans,C;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	ans=power(2,n);
	ans=(ans-1+mod)%mod;
	ans=(ans-n+mod)%mod;
	ans=(ans-(ll)(n-1)*n/2+mod)%mod;
	
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
		{
			A=y[i]-y[j];
			B=x[j]-x[i];
			C=-x[i]*A-y[i]*B;
			cnt=2;
			for (int k=1;k<=n;k++)
			{
				if (k==i || k==j) continue;
				if (A*x[k]+B*y[k]+C!=0) continue;
				if (k<j) break;
				cnt++;
			}
			ans=(ans-power(2,cnt)+mod)%mod;
			ans=(ans+1)%mod;
			ans=(ans+cnt)%mod;
			ans=(ans+(ll)(cnt-1)*cnt/2)%mod;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
 
using namespace std;
 
int main(void) {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<vector<bool> > g(N, vector<bool>(N, false));
 
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    g[a - 1][b - 1] = g[b - 1][a - 1] = 1;
  }
 
  vector<int> v(N);
  iota(v.begin(), v.end(), 1);
 
  do {
    //始点が1でない時
    if (v[0] != 1)
      continue;
 
    bool flag = true;
    for (int i = 1; i < N; i++) {
      //通れるパスがなかった時
      if (!g[v[i - 1] - 1][v[i] - 1]) {
        flag = false;
        break;
      }
    }
 
    if (flag)
      ans++;
 
  } while (next_permutation(v.begin(), v.end()));
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long a[3*n];
    for(int i = 0;i<3*n;i++){
        cin >> a[i];
    }
    sort(a,a+3*n,greater<long long>());
    long long ans = 0;
    for(int i = 0;i<n;i++){
        ans = ans + a[2*i+1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
/*In the name of Allah*/
#include<bits/stdc++.h>

#include<cstdio>
#include<vector>
#include<utility>
#include<string>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <string>

#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <string.h>

#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace __gnu_cxx;
using namespace std;
typedef long long ll;
typedef long double ld;

#define pi acos(-1)
#define s(a) scanf("%d",&a)
#define p(a) printf("%d",a)

#define csp(a) cout<<a<<' '
#define cnl(a) cout<<a<<'\n'
#define nl cout<<'\n';
#define sp cout<<' ';


#define REP(i, a, b) for (int i = (a); i < (b); ++i)

#define rep(i, n) REP(i, 0, (n))


#define REPE(i,a,b) for (int i = (a); i <= (b) ; ++i)
#define repe(i,n) REPE(i, 1, (n))


#define optimize() ios_base::sync_with_stdio(0)
int main(){ optimize();

ll s,sum=0; cin>>s; 
    
 for(ll i=1;i<=s;++i)
{if(i%3!=0 && i%5!=0 && i%15!=0)
 sum+=i;

} cout<<sum;


return 0;}

Measured memory_bytes: 3616
import itertools

n,m = map(int,input().split())#頂点の数、辺の数

graph = [[False for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a][b] = True
    graph[b][a] = True

ans = 0
for i in itertools.permutations(range(n)):
    if i[0] != 0:
        continue
    visited = [0]*n
    visited[0] += 1
    for j in range(n):
        if j == n-1:
            if 0 not in visited:
                ans += 1
            break
        if graph[i[j]][i[j+1]] == True:
            visited[i[j+1]] += 1
        
            
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
int main()
{
    int w, h, x, y;
    scanf("%d%d%d%d", &w, &h, &x, &y);
    printf("%lf %d\n", double(w) * double(h) / 2, 2*x == w && 2*y == h);
}

Measured memory_bytes: 128
n = int(input())

x = []
y = []
# left >= rightの場合、
# keft < right う

for _ in range(n):
    s = input()
    b = c = 0

    # sの中でペアにならない括弧を計算
    for t in s:
        if t == '(':
            b += 1
        else:
            if b == 0:
                c += 1
            else:
                b -= 1
    if b >= c:
        x.append((c, b))
    else:
        y.append((-b, c))
x.sort()
y.sort()
now = 0
for a, b in x:
    now -= a
    if now < 0:
        print('No')
        exit()
    now += b
for a, b in y:
    now -= b
    if now < 0:
        print('No')
        exit()
    now -= a

if now == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 173608
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main(){
      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
  {
  	cin>>a[i];
  }
  int g=a[0];
  for(i=1;i<n;i++)
  {
  	g=gcd(g,a[i]);
  }
  cout<<g<<"\n";
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[20],v[100],deta;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i]>>v[i];
    for(int i=0;i<n-1;i++)for(int j=0;j<n-1;j++)
    {
        if(v[j]<v[j+1]||(v[j]==v[j+1]&&a[j]>a[j+1]))
        {
            deta=v[j];
            v[j]=v[j+1];
            v[j+1]=deta;
            deta=a[j];
            a[j]=a[j+1];
            a[j+1]=deta;
        }
    }
    cout<<a[0]<<" "<<v[0]<<endl;
    return 0;
}

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

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
	int n;
	scanf("%d", &n);
	return n;
}

ll Lin() {
	ll n;
	scanf("%lld", &n);
	return n;
}

double Din() {
	double n;
	scanf("%lf", &n);
	return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 3e3 + 5;

string s, t;

int dp[N][N];
pii par[N][N];

int lcs(int n, int m) {
	if (n == -1 || m == -1) return 0;
	if (dp[n][m] != -1) return dp[n][m];
	if (s[n] == t[m]) {
		par[n][m] = {n - 1, m - 1};
		return dp[n][m] = 1 + lcs(n - 1, m - 1);
	}
	int l = lcs(n, m - 1), u = lcs(n - 1, m);
	if (l > u) {
		par[n][m] = {n, m - 1};
		return dp[n][m] = l;
	}
	else {
		par[n][m] = {n - 1, m};
		return dp[n][m] = u;
	}
}

void path(int n, int m) {
	if (n == -1 || m == -1) return;
	path(par[n][m].ff, par[n][m].ss);
	if (s[n] == t[m]) printf("%c", s[n]);
}


int solve() {
	cin >> s >> t;
	fill(dp, -1);
	int n = s.size(), m = t.size();
	lcs(n - 1, m - 1);
	path(n - 1, m - 1);
	printf("\n");
	return 0;
}

int main() {
	int test = 1, tc = 0;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 106624
package main
import (
  "fmt"
)

func main() {
  var r, g, b int
  fmt.Scan(&r, &g, &b)
  res := r * 100 + g * 10 + b
  if res % 4 == 0 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}



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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	ll n,a,b;cin>>n>>a>>b;
	if(a%2==b%2){
		cout<<abs(b-a)/2<<endl;
		return 0;
	}
	ll x[]{1,n};
	ll ans=LLONG_MAX;
	rep(i,2){
		if(abs(a-x[i])>abs(b-x[i]))swap(a,b);
		ll Min=abs(a-x[i]);
		ll c=(b<x[i]?b+Min:b-Min);
		if((c-x[i])%2==0){
			ans=min(ans,abs(c-x[i])/2+Min);
		}
		else{
			ans=min(ans,abs(c-x[i])/2+Min+1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;

const int maxn=100010;
int n,m,a[maxn],b[maxn],ac,pe;
char c[5];

int main()
{
	int i,p;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
	{
		scanf("%d%s",&p,c+1);
		if (a[p])
			continue;
		if (c[1]=='A')
		{
			ac++;
			pe+=b[p];
			a[p]=1;
		}
		else
			b[p]++;
	}
	printf("%d %d\n",ac,pe);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int N, Q;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
int main() {
    /*cin >> N >> Q;
    LazySegmentTree seg( vector<ll>(N, 0) );
    for(int i=0; i<Q; i++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t, x; cin >> s >> t >> x;
            seg.add(s-1, t, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << seg.getsum(s-1, t) << endl;
        }
    }*/

    ll n,d,a;cin>>n>>d>>a;
    d*=2;
    vector<P> xh(n);
    rep(i,n){
        ll xx, hh;cin>>xx>>hh;
        xh[i]={xx,(hh+a-1)/a};
    }
    sort(xh.begin(),xh.end());
    vector<ll> x(n),h(n);
    rep(i,n){x[i]=xh[i].first,h[i]=xh[i].second;}
    LazySegmentTree seg(h);
    ll ans = 0;
    for(int i=0; i<n; i++){
        ll left = i;
        ll right = upper_bound(x.begin(),x.end(),x[i]+d)-x.begin();
        ll rem = max(0LL,seg.getsum(i,i+1));
        ans += rem;
        seg.add(left,right,-rem);

    }
    cout<<ans;

}

Measured memory_bytes: 16256
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int n,m;
struct node{
	int a,b;
}_[100001];
ll ans;
bool cmp(node _1,node _2){
	return _1.a<_2.a;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&_[i].a,&_[i].b);
	sort(_+1,_+n+1,cmp);
	int i;
	for (i=1;m>=_[i].b;i++){
		ans+=(ll)_[i].b*(ll)_[i].a;
		m-=_[i].b;
	}
	ans+=m*(ll)_[i].a;
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  vector<ll> sums(N+1);
  sums[0]=0;
  for(int i=1;i<=N;i++){
    sums[i] = sums[i-1] + A[i-1];
  }
  unordered_map <ll,ll> mp;
  rep(i,N+1) mp[(sums[i])%M]++;
  ll ans = 0;
  for(auto m:mp){
    ans += m.second*(m.second-1)/2;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    double l;
    cin >> l;
    double ans = (l*l*l)/27;
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(A),
    get_number(B),
    X is max(max(A + B, A - B), A * B),
    writeln(X).


Measured memory_bytes: 8184
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i];
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,ar[N],sum,a,b,c;


int main()
{
	fast;
	cin>>a>>b>>c;
	cout<<a*b/2;
}

Measured memory_bytes: 256
#16:40
n = int(input())
a = list(map(int,input().split()))
a = [0] + a
for i in range(n):
  if a[i+1] < a[i]:
    print('No')
    break
  elif a[i+1] > a[i]:
    a[i+1] -= 1
else:
  print('Yes')

Measured memory_bytes: 15020
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
vector<int> v;

bool like(int a){
    return v[v[a]] == a;
}

int main() {
    int n;
    cin >> n;
    v.push_back(0);
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);

    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(like(i)) cnt++;
    }
    cout << cnt / 2 << endl;
}


Measured memory_bytes: 892
#include <stdio.h>

int main(void) {
  char na[9][16];
  int a[9], b[9], c[9], d[9], i;

  for (i = 0; i < 9; i++)
    scanf("%s %d %d", na[i], &a[i], &b[i]);
  for (i = 0; i < 9; i++) {
    c[i] = a[i] + b[i];
    d[i] = a[i] * 200 + b[i] * 300;
  }

  for (i = 0; i < 9; i++)
    printf("%s %d %d\n", na[i], c[i], d[i]);

  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	ll N,H,W;
	cin >> N >> H >> W;
	vector<ll> A(N), B(N);
	REP(i,N){
		cin >> A[i] >> B[i];
	}
	
	ll ret = 0;
	REP(i,N){
		if((A[i] >= H) && (B[i] >= W)) ret++;
	}
	
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
def m2():
    n = int(input())
    s = str(input())
    ALL = [str(i) for i in range(10)]
    ans = 0
    for a in ALL:
        for b in ALL:
            for c in ALL:
                flag = 0
                for i in range(n):
                    if s[i] == a and flag == 0:
                        flag = 1
                        continue
                    if s[i] == b and flag == 1:
                        flag = 2
                        continue
                    if s[i] == c and flag == 2:
                        flag = 3
                    if flag == 3:
                        ans += 1
                        break
    return ans

print(m2())

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

int main(){
	int n,m;
	cin>>n>>m;
	int p[m];
	string s[m];
	bool a[n]={false};
	int ac=0;
	int wa[n]={};
	int wanum=0;
	rep(i,m){
		cin>>p[i]>>s[i];
		if(!a[p[i]-1]){
			if(s[i]=="AC"){
				a[p[i]-1]=true;
				ac++;
			}else{
				wa[p[i]-1]++;
			}
		}
	}
	rep(i,n){
		if(a[i])wanum+=wa[i];
	}
	puts(ac);
	puts(wanum);
	
}

Measured memory_bytes: 6528
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main() {
	long long N, K;
	scanf("%ld%ld", &N, &K);
	N = N % K;
	N = min(N, abs(N - K));
	printf("%ld", N);
}

Measured memory_bytes: 3828
import java.util.*;

public class Main {
    public static void main(String args[]) {
        int N, T;
        int min = 9999;
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        T = scanner.nextInt();
        for (int i = 1; i <= N; i++) {
            int c = scanner.nextInt();
            int t = scanner.nextInt();
            if (t <= T) {
                if (c < min) {
                    min = c;
                }
            }
        }
        if (min == 9999) {
            System.out.println("TLE");
        } else {
            System.out.println(min);
        }
    }
}

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

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

    int n;
    cin>>n;
    unsigned long long int sum=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3620
n, m = [int(i) for i in input().split()]
py = []
for j in range(m):
    py.append([j]+[int(i) for i in input().split()])
py.sort(key=lambda x:x[2])
b = [1] * n
c=[]
for i in py:
    c.append([str(i[1]).zfill(6) + str(b[i[1]-1]).zfill(6), i[0]])
    b[i[1]-1] += 1
c.sort(key=lambda x:x[1])
for i in c:
    print(i[0])

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    int h, w; std::cin >> h >> w;
    int n; std::cin >> n;
    vi a(n); rep(i, n) std::cin >> a[i];
    bool right = true;
    int cur = 0;
    vvi grid(h, vi(w));
    rep(i, h) {
        if (right) rep(j, w) {
            grid[i][j] = cur+1;
            a[cur]--;
            if (a[cur] == 0) cur++;
        } else drep(j, w) {
            grid[i][j] = cur+1;
            a[cur]--;
            if (a[cur] == 0) cur++;
        }
        right ^= 1;
    }
    rep(i, h) rep(j, w) {
        std::cout << grid[i][j] << (j+1 < w ? " " : "\n");
    }
}


Measured memory_bytes: 384
import sys
H,W,K=map(int,input().split())
if W==1:
    print(1)
    sys.exit()
L=[1,1,2,3,5,8,13,21,34]
mod=10**9+7
dp=[[0]*W for i in range(H+1)]
dp[0][0]=1
for i in range(H):
    for j in range(W):
        if j==0:
            dp[i+1][j]+=dp[i][j]*L[W-1]
            dp[i+1][j]+=dp[i][j+1]*L[W-2]
            dp[i+1][j]%=mod
        elif j==W-1:
            dp[i+1][j]+=dp[i][j]*L[W-1]
            dp[i+1][j]+=dp[i][j-1]*L[W-2]
            dp[i+1][j]%=mod
        else:
            dp[i+1][j]+=dp[i][j-1]*L[j-1]*L[W-j-1]
            dp[i+1][j]+=dp[i][j]*L[j]*L[W-j-1]
            dp[i+1][j]+=dp[i][j+1]*L[j]*L[W-j-2]
            dp[i+1][j]%=mod
print(dp[H][K-1])

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

using namespace std;

int N;
int a[101010];

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

  int res = 0;
  for (int i = 1; i <= N; i++) {
    if (i == a[a[i]]) res++;
  }

  cout << res / 2 << endl;

  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char str[23];
int dp[2][1<<20];
int main(){
	while(1){
		scanf("%s",str);
		if(str[0]=='#')break;
		int n=strlen(str);
		for(int i=0;i<(1<<n);i++)dp[0][i]=dp[1][i]=0;
		dp[0][0]=1;
		for(int i=0;i<25;i++){
			int t=i%2;
			for(int j=0;j<(1<<n);j++)dp[!t][j]=0;
			for(int j=0;j<(1<<n);j++){
				if(!dp[t][j])continue;
				int flag=1;
				for(int k=0;k<n;k++){
					if(!(j&(1<<(n-1-k)))&&str[k]-'a'+i==25){
						flag=0;
						break;
					}
					if(str[k]-'a'+i==24){
						dp[!t][j+(1<<(n-1-k))]=1;
					}
				}
				if(flag)dp[!t][j]=1;
			}
		}
		int ret=0;
		for(int i=0;i<(1<<n);i++)ret+=dp[1][i];
		printf("%d\n",ret);
		if(ret<=10){
			for(int i=0;i<(1<<n);i++){
				if(dp[1][i]){
					for(int j=0;j<n;j++)if(i&(1<<j))str[n-1-j]++;
					printf("%s\n",str);
					for(int j=0;j<n;j++)if(i&(1<<j))str[n-1-j]--;
				}
			}
		}else{
			int cnt=0;
			for(int i=0;i<(1<<n);i++){
				if(dp[1][i]){
					cnt++;
					if(cnt>5&&cnt<=ret-5)continue;
					for(int j=0;j<n;j++)if(i&(1<<j))str[n-1-j]++;
					printf("%s\n",str);
					for(int j=0;j<n;j++)if(i&(1<<j))str[n-1-j]--;
				}
			}
		}
	}
}

Measured memory_bytes: 9168
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

//int solve(int n,int s)
//{
//	if(n<=0 || 10<n)
//		return 0;
//	
//	vi c(n),k(10);
//	rep(i,n)
//		c[i]=i+1;
//	rep(i,10)
//		k[i]=i;
//	int res=0;
//	do{
//		if(inner_product(allof(c),k.begin(),0)==s)
//			res++;
//		reverse(n+allof(k));
//	}while(next_permutation(allof(k)));
//	return res;
//}

int memo[1<<10][331];

void gen_answer()
{
	rep(i,10)
		memo[1<<i][i]=1;
	repi(i,1,1<<10){
		int use=__builtin_popcount(i);
		rep(j,10){
			if(i&(1<<j))
				continue;
			int term=(use+1)*j;
			rep(k,331-term)
				memo[i|(1<<j)][k+term]+=memo[i][k];
		}
	}
}

int solve(int n,int s)
{
	if(n<=0 || 10<n)
		return 0;
	if(s<0 || 330<s)
		return 0;
	
	int res=0;
	rep(i,1<<10){
		if(__builtin_popcount(i)==n)
			res+=memo[i][s];
	}
	return res;
}

int main()
{
	gen_answer();
	for(int n,s;cin>>n>>s;)
		//cout<<solve(n,s)<<endl;
		//printf("%d %d: %d\n",n,s,solve(n,s));
		printf("%d\n",solve(n,s));
	
	return 0;
}

Measured memory_bytes: 0
import numpy as np
from inspect import signature

N, W = map(int, input().split())
w = [0]
v = [0]
for i in range(N):
    tw, tv = map(int, input().split())
    w.append(tw)
    v.append(tv)
w = np.array(w)
v = np.array(v)

dp = np.zeros((N+1,W+1),dtype=np.int)

for i in range(1,N+1):
    dp[i][:w[i]] = dp[i-1][:w[i]]
    dp[i][w[i]:] = np.maximum(dp[i-1][:W+1-w[i]]+v[i],dp[i-1][w[i]:])

# dp = np.zeros((n+1,w+1),dtype=np.int)
print(dp[N][W])

Measured memory_bytes: 92696
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t; cin>>s>>t;
  ll slen=s.length(),tlen=t.length();
  bool isok=false;
  ll qlen=0;
  for(ll i=slen-1;i>=tlen-1;--i) {
    qlen=0;
    for(ll ii=0;ii<tlen;++ii) if(s[i-ii]==t[tlen-1-ii]||s[i-ii]=='?') qlen++;
    if(qlen==tlen) {
      isok=true;
      for(ll j=0;j<tlen;++j) s[i-j]=t[tlen-1-j];
      for(ll l=0;l<slen;++l) if(s[l]=='?') s[l]='a';
      break;
    }
  }
  if(isok) print(s);else print("UNRESTORABLE");
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val l = sc.nextInt()

    val tastes = (1..n).map { l + it - 1 }
    val zm = tastes.minBy { Math.abs(it) }
    val result = tastes.sum() - zm!!
    print(result)
}


Measured memory_bytes: 29860