akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<string,int> P;

map<string, int> m;
map<string, int>::iterator it;
vector<P> ans;
int n;

int main(){
	cin >> n;
	rep(i,n){
		string str;
		int cnt;
		cin >> str >> cnt;
		m[str] += cnt;
	}
	for(int i = 1; i <= 5; i++){
		for(it = m.begin(); it != m.end(); it++){
			if((*it).first.size() == i) ans.push_back(P((*it).first,(*it).second));
		}
	}
	rep(i,ans.size()){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

Measured memory_bytes: 1232
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n;
vi in;
int dp[310][310];
int f(int l,int r){
	if(dp[l][r]+inf)return dp[l][r];
	if(r-l<2)return dp[l][r]=0;
	if(r-l==2&&abs(in[l]-in[r-1])<2)return dp[l][r]=2;
	int out=-inf;
	loop(i,l+1,r-1)out=max(out,f(l,i)+f(i,r));
	
//	loop(i,l,r-1)if(abs(in[i]-in[i+1])<2){
//		out=max(out,f(l,i)+2+f(i+2,r));
//	}
	int t=f(l+1,r-1);
	if(t==r-l-2){
		if(abs(in[l]-in[r-1])<2)out=max(out,r-l);
	}
	out=max(out,f(l+1,r));
	out=max(out,f(l,r-1));
	return dp[l][r]=out;
}
int main(){
	while(cin>>n,n){
		in=vi(n);
		rep(i,n)cin>>in[i];
		rep(i,310)rep(j,310)dp[i][j]=-inf;
		cout<<f(0,n)<<endl;;
	}
}



Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
    char s;
    cin >> s;
    if (s >= 'A' && s <= 'Z') cout << "A";
    else cout << "a";
}

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

using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

bool pallan(string s){
    ll i=0,j=s.size()-1;
    while(i<j){
        if(s[i]!=s[j])
            return false;
        i++;
        j--;
    }
    return true;
}

int main() {
    fio;
    
    ll n,m;cin>>n;
    ll dp[128][128];
    memset(dp,0,sizeof(dp));
    ll ans=0;
    for(ll i=1;i<=n;i++){
        string t=to_string(i);
        dp[t[0]][t[t.size()-1]]++;
    }
    
    for(ll i='1';i<='9';i++){
        for(ll j='1';j<='9';j++){
            ans += (dp[i][j]*dp[j][i]);
        }
    }
    
    cout<<ans<<endl;
    
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll t, x;

	cin >> t >> x;

	cout << (double)t / (double)x << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  set<long long> st;
  for (long long d = 1; d * d <= n; d++) {
    if (n % d) continue;
    long long x = d, y = n / d;
    if (x != y) {
      if (x > 2) {
        long long xx = x - 1;
        if (!st.count(xx) && n / xx == n % xx) {
          ans += xx;
          st.insert(xx);
        }
      } 
      if (y > 2) {
        long long xx = y - 1;
        if (!st.count(xx) && n / xx == n % xx) {
          ans += xx;
          st.insert(xx);
        }
      }
    } else {
      if (x > 2) {
        long long xx = x - 1;
        if (!st.count(xx) && n / xx == n % xx) {
          ans += xx;
          st.insert(xx);
        }
      } 
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  auto check=[](ll num){
    ll sn=sqrt(num);
    if(sn*sn==num)return 1;
    sn++;
    if(sn*sn==num)return 1;
    return 0;
  };
  ll n;cin>>n;
  ll d;cin>>d;
  vector<vector<ll>>nd(n,vector<ll>(d));
  rep(i,n){
    rep(j,d)cin>>nd[i][j];
  }
  ll res=0;
  rep(i,n)repi(j,i+1,n){
    ll td=0;
    rep(k,d){
      td+=(nd[i][k]-nd[j][k])*(nd[i][k]-nd[j][k]);
    }
    if(check(td))res++;
  }
  cout<<res<<endl;

  return 0;

}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  int v[n];
  REP(i,n){
    cin >> v[i];
  }
  int count[100001] = {0};
  int max1 = 0;
  int max2 = 0;
  int val1 = 0;
  int val2 = 0;
  for(int i=0;i<n;i+=2){
    int cnt = ++count[v[i]];
    if(cnt > max1){
      val1 = v[i];
      max1 = cnt;
    }else if(cnt > max2){
      val2 = v[i];
      max2 = cnt;
    }
  }
  int max3 = 0;
  int max4 = 0;
  int val3 = 0;
  int val4 = 0;
  int countOdd[100001] = {0};
  for(int i=1;i<n;i+=2){
    int cnt = ++countOdd[v[i]];
    if(cnt > max3){
      val3 = v[i];
      max3 = cnt;
    }else if(cnt > max4){
      val4 = v[i];
      max4 = cnt;
    }
  }
  
  if(val1 == val3){
    cout << min(n-max1-max4,n-max2-max3) << endl;
  }else{
    cout << n - max1 - max3 << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 4800
from itertools import permutations
from math import sqrt

N = int(input())
x = [0]*N; y = [0]*N;
array = []
for i in range(N):
    x[i], y[i] = map(int, input().split())
    array.append(i)

root = list(permutations(array, N))

ans = 0
for i in range(len(root)):
    go = list(root[i])
    total = 0
    for j in range(1, N):
        total += sqrt(abs(x[go[j]]-x[go[j-1]])**2 + 
                abs(y[go[j]]-y[go[j-1]])**2)
    ans += total
print(ans/len(root))


Measured memory_bytes: 7996
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

const int MOD = 1e9+7;
const int MAXN = 10005;
string k;
int n, d;
int dp[MAXN][2][105];

void Add(int& x, int y)
{
    x += y;
    if(x >= MOD) x -= MOD;
}

int DP(int len, bool tight, int modResult)
{
    if(len == n) return (modResult == 0);
    if(dp[len][tight][modResult] != -1) return dp[len][tight][modResult];
    dp[len][tight][modResult] = 0;

    int limit = (tight) ? (k[len]-'0') : 9;

    for(int i = 0; i <= limit; ++i)
    {
        bool nextTight = tight && (i == limit);
        int nextModResult = (((modResult-i) % d) + d) % d;
        Add(dp[len][tight][modResult], DP(len+1, nextTight, nextModResult));
    }

    return dp[len][tight][modResult];
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    cin >> k >> d;
    n = k.size();
    memset(dp, -1, sizeof(dp));
    int ans = DP(0, true, 0) - 1;
    if(ans < 0) ans += MOD;
    cout << ans << "\n";
    return 0; 
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
 vector<long long int>arr(n);
  for(long long int i=0;i<n;i++)
    cin>>arr[i];
  sort(arr.begin(),arr.end(),greater<long long int>());
  long long int ans=0;
  ans=arr[0];
  int c=0;
  int j=1;
  for(long long int i=2;i<n;i++)
  {
    if(c!=2)
    {
      c++;
      ans=ans+arr[j];
    }
    else
    {
      j++;
      c=0;
      i--;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

  ll ans,t;
  cin >> ans;
  for(int i=1; i<n; i++){
    cin >> t;
    ans = lcm(ans, t);
  }

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

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

#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
// const ll MOD = 998244353;
const double PI=3.14159265358979323846;

int n, k;

int op(int a, int b) {
    return max(a, b);
}
int e() {
    return 0;
}
segtree<int, op, e> seg(300010);

int main() {
    cin >> n >> k;
    vector<int> A(n);
    rp(i, 0, n) {
        cin >> A[i];
    }
    int res = 0;
    for(int i = n-1; i >= 0; i--) {
        seg.set(A[i], seg.prod( max(0, A[i] - k), min(A[i] + k, 300000) + 1 ) + 1 );
    }
    cout << seg.all_prod() << endl;
    return 0;

    return 0;
}


Measured memory_bytes: 8560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba") {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

int n, m;
const int dx[2] = {-1, 1};
int bit_power[15];

struct cup_state {
    vector<int> tray[3];
    int move_cnt = 0;
    void print(){
        cout << "cup_state :" << this << endl;
        for (auto i = 0; i < 3; i++) {
            cout << "[" << i << "] : ";
            for (int j : tray[i]) {
                cout << j << " ";
            }
            cout << endl;
        }
        cout << "move_cnt=" << move_cnt << endl;
    };
    int to_bit(){
        int res = 0;
        for (auto i = 0; i < 3; i++) {
            for (auto j = 0; j < tray[i].size(); j++) {
//                res += i << ((tray[i][j] - 1) * 2);
                res += i * bit_power[tray[i][j] - 1];
            }
        }
        return res;
    }
};

int bfs(cup_state init) {
    vector<bool> d((int)pow(3, 15), false);
    queue<cup_state> q;
    q.push(init);
    d[init.to_bit()] = true;
    while (not q.empty()) {
        cup_state p = q.front();
        q.pop();
//        p.print();
        for (auto i = 0; i < 3; i++) {
            if (p.tray[i].empty()) continue;
            if (i != 1 and p.tray[i].size() == n) {
//                cout << p.move_cnt << endl;
                return p.move_cnt;
            }
            if(p.move_cnt >= m) continue;
            for (int j : dx) {
                cup_state tmp = p;
//                cout << "tray : " << i << endl;
                int tmp_cup = p.tray[i][p.tray[i].size() - 1];
                if(tmp_cup == 1 and i != 1) continue;
//                cout << "tmp_cup : " << tmp_cup << endl;
                int tray_index = i + j;
                if (tray_index < 0 or tray_index >= 3) continue;
                if (not p.tray[tray_index].empty()
                    and tmp_cup < p.tray[tray_index][p.tray[tray_index].size() - 1]) continue;
//                cout << "next_tray : " << tray_index << endl;
                tmp.tray[tray_index].push_back(tmp_cup);
                tmp.tray[i].pop_back();
                tmp.move_cnt = p.move_cnt + 1;
//                tmp.print();
                if(not d[tmp.to_bit()]) {
                    q.push(tmp);
                    d[tmp.to_bit()] = true;
                }
            }
        }
    }
    return -1;
}
int main(){
    int p = 1;
    for (int & i : bit_power) {
        i = p;
        p *= 3;
    }

    while(true) {
        cin >> n >> m;
        if(n == 0 and m == 0) break;

        cup_state init = cup_state();
        for (auto &i : init.tray) {
            i = vector<int>(0);
            int size, tmp;
            cin >> size;
            for (auto j = 0; j < size; j++) {
                cin >> tmp;
                i.push_back(tmp);
            }
        }

        int ans = bfs(init);
        cout << ((ans <= m) ? ans : -1) << endl;
    }

    return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    vector<string> vs;
    int k;
    cin >> s >> k;
    int n = s.length();
    REP(i, n)FOR(j, 1, k)
        vs.push_back(s.substr(i, j));
    sort(ALL(vs));
    unique(ALL(vs));
    cout << vs[k - 1] << endl;

    return 0;
}


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

string s;
ll roc = 0;
map<char, ll> m1;
map<pair<char, ll>, ll> m2;

ll exp();
bool decass();

ll exp() {
	if(s[roc] >= '0' && s[roc] <= '9') {
		ll roc_buf = roc;
		while(s[roc] >= '0' && s[roc] <= '9') ++roc;
		ll num = stoi(s.substr(roc_buf, roc - roc_buf));
		return num;
	} else {
		char name = s[roc];
		ll size = m1[name];
		++roc;
		++roc;
		ll num = exp();
		++roc;
		if(num == INF * INF) return INF * INF;
		if(num >= size || size < 0) return INF * INF;
		if(m2.count(pair<char, ll>(name, num)) == 0) return INF * INF;
		else return m2[pair<char, ll>(name, num)];
	}
}

bool decass() {
	if(m1.count(s[roc]) == 0) {
		char name = s[roc];
		++roc;
		++roc;
		ll roc_buf = roc;
		while(s[roc] >= '0' && s[roc] <= '9') ++roc;
		ll num = stoi(s.substr(roc_buf, roc - roc_buf));
		m1[name] = num;
		return true;
	} else {
		char name = s[roc];
		ll size = m1[name];
		++roc;
		++roc;
		ll index = exp();
		if(index == INF * INF) return false;
		if(index >= size || index < 0) return false;
		++roc;
		++roc;
		ll num = exp();
		if(num == INF * INF) return false;
		m2[pair<char, ll>(name, index)] = num;
		return true;
	}
}

int main(void) {
	while(true) {
		ll cnt = 0;
		ll res = 0;
		m1.erase(ALL(m1));
		m2.erase(ALL(m2));
		while(true) {
			cin>>s;
			roc = 0;
			if(s == ".") break;
			if(res == 0 && !decass()) res = cnt + 1;
			++cnt;
		}
		if(cnt == 0) break;
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3188
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String string = sc.next();
		int con = 0;
		String pre = "";
		int took = 1;
		int len = string.length();

		while(string.length() > 0) {
			took = 1;
			//着目箇所評価
			if (pre.length() == 2) {
				took = 1;
				pre = string.substring(0,1);
			}else {
				if (string.substring(0,1).equals(pre) == false) {
					took = 1;
					pre = string.substring(0,1);
				}else {
					if (string.length() == 1) {
						break;
					}
					took = 2;
					pre = string.substring(0,2);
				}
			}
			con++;
			string = string.substring(took,string.length());
		}

		System.out.println(con);

	}
}


Measured memory_bytes: 57544
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    vector<int> p(n);

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

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

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



Measured memory_bytes: 888
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr<<#x<<'='<<x<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();int f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n;
int main() {
	read(n);
	cout<<(n-2)*180<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  unsigned X;
  std::cin >> X;
  
  unsigned t = 0;
  
  while (t < X) {
    if (t * (t + 1) >= 2 * X) {
      break;
    }
    
    ++t;
  }
  
  std::cout << t << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    cout << a[n/2] - a[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        k: usize,
        teleporters: [Usize1; n],
    }

    let max_d = 60;
    let mut next = vec![vec![0; n]; max_d + 1];

    for r in 0..n {
        next[0][r] = teleporters[r];
    }

    for p in 0..max_d {
        for r in 0..n {
            next[p + 1][r] = next[p][next[p][r]];
        }
    }

    let mut cur = 0;
    for i in (0..=max_d).rev() {
        if k & (1usize << i) != 0 {
            cur = next[i][cur];
        }
    }

    println!("{}", cur+1);
}

Measured memory_bytes: 100424
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		int c = 0;
		int v = 0;
		while(c<N) {
			v++;
			int t = v;
			int d = 0;
			while(t%100 == 0) {
				t = t/100;
				d++;
			}
			if (d == D)  c++;
		}
		System.out.println(v);
	}
}


Measured memory_bytes: 24916
#include <list>
#include <cstdio>
#include <string>
#include <iostream>

#pragma warning(disable: 4996)

using namespace std;

int main()
{
	int n, v;

	string c;

	list<int> l;

	scanf("%d", &n);

	for (int i = 0; i < n;)
	{
		cin >> c;

		if (c[0] == 'i')
		{
			scanf("%d", &v);

			l.push_front(v);
		}
		else if (c.size() == 11)
		{
			l.pop_front();
		}
		else if (c.size() == 10)
		{
			l.pop_back();
		}
		else
		{
			scanf("%d", &v);

			list<int>::iterator it = l.begin();

			while (it != l.end())
			{
				if (*it == v)
				{
					l.erase(it); break;
				}

				it++;
			}
		}

		i++;
	}

	list<int>::iterator it = l.begin();

	while (it != l.end())
	{
		if (it == l.begin())
		{
			printf("%d", *it);
		}
		else
		{
			printf(" %d", *it);
		}

		it++;
	}

	printf("\n");

	return 0;
}

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

int main() {
    string s[3];
    for(int i = 0; i < 3; ++i) cin >> s[i];
    
    int nums[3] = {0};
    char turn = 'a';
    char ans = 'x';
    while(ans == 'x') {
        if(turn == 'a') turn = s[0][nums[0]], ++nums[0];
        else if(turn == 'b') turn = s[1][nums[1]], ++nums[1];
        else if(turn == 'c') turn = s[2][nums[2]], ++nums[2];
        for(int j = 0; j < 3; ++j) {
            if(nums[j] >= s[j].size() && turn == 'a' + j) {
                ans = 'A' + j;
            }
        }
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let n = s.len();
    let k = read::<i64>();

    if s.iter().collect::<HashSet<_>>().len() == 1 {
        println!("{}", s.len() as i64 * k / 2);
        return;
    }
    let mut single_ans = 0;
    let mut prev_swaped = false;
    for i in 1..n {
        if s[i - 1] == s[i] {
            if prev_swaped {
                prev_swaped = false;
            } else {
                prev_swaped = true;
                single_ans += 1;
            }
        } else {
            prev_swaped = false;
        }
    }

    if s[0] != s[n - 1] {
        println!("{}", single_ans * k);
        return;
    }

    let mut seek_count = 0;
    let mut first = 0;
    for i in 0..n {
        if s[i] != s[0] {
            first = i;
            break;
        }
        seek_count += 1;
    }
    let mut last = 0;
    for i in (0..n).rev() {
        if s[i] != s[0] {
            last = i + 1;
            break;
        }
        seek_count += 1;
    }

    let mut single_ans2 = 0;
    let mut prev_swaped = false;
    for i in first + 1..last {
        if s[i - 1] == s[i] {
            if prev_swaped {
                prev_swaped = false;
            } else {
                prev_swaped = true;
                single_ans2 += 1;
            }
        } else {
            prev_swaped = false;
        }
    }

    let ans = single_ans + single_ans2 * (k - 1) + (seek_count / 2) * (k - 1);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

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

    long long a[N];

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

    long long dp[N+1][K+1]={};

    for (int i = 0; i < K+1; ++i) { 
        if (a[0]>=i){
            dp[1][i]=1;
        }
    }

    long long s[K+1]={};
    long long M,L;

    M=a[0];
    for (int j = 2; j < N+1; ++j) { 
        M+=a[j-1];
        dp[j][0]=1;
        s[0]=dp[j-1][0];
        
        L=K+1;
        if (L>M+1){L=M+1;}
        for (int i = 1; i < L; ++i) {
            s[i]=s[i-1]+dp[j-1][i];
        }

        for (int i = 1; i < L; ++i) { 
            dp[j][i]=s[i];
            if (i>a[j-1]){
                dp[j][i]-=s[i-a[j-1]-1];
            }
            
            if (dp[j][i]>1000000007){dp[j][i]=dp[j][i]%1000000007;}
        }
    }


    cout << dp[N][K] << endl;
    return 0;

}

Measured memory_bytes: 79872
import numpy as np
S=str(input())
X=[]
c=1
for i in range(1,len(S)):
  if S[i]==S[i-1]:
    c +=1
  elif S[i]!=S[i-1]:
    X +=[c]
    c=1
  if i==len(S)-1:
    X +=[c]
if len(S)==1:
  X=[1]
if len(X)>=3:
  X=np.cumsum(X)
  t=float('inf')
  for i in range(len(X)-1):
    u=max(X[i],len(S)-X[i])
    t=min(u,t)
  answer=t
elif len(X)==1:
  answer=X[0]
elif len(X)==2:
  answer=max(X)
print(answer)

Measured memory_bytes: 14172
#include <stdio.h>          // printf(), scanf()
#include <math.h>           // fabs()

#define equals(a, b) (fabs(a) - fabs(b) < EPS)
static const double EPS = 1e-10;

int
main(int argc, char** argv)
{
	double a1x, a1y, a2x, a2y;
	double b1x, b1y, b2x, b2y;
	int n;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &a1x, &a1y, &a2x, &a2y, &b1x, &b1y, &b2x, &b2y);
		double dax = a2x - a1x, day = a2y - a1y;
		double dbx = b2x - b1x, dby = b2y - b1y;
		double cross = dax * dby - day * dbx;
		if (equals(cross, 0.0))
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    int x, y, z;
};

array<int, 15> dp[14348907];

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

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int x, y, z;
        cin >> x >> y >> z;

        p[i] = { x, y, z };
    }

    int l = (int)pow(3, n);

    vector<ll> r(n + 1, 1LL << 60);
    for (int k = 0; k < l; k++) {
        array<int, 15> u;
        int a = k, b = 0, c = 1;
        ll s = 0;
        if (k == 0) {
            for (int i = 0; i < n; i++) {
                u[i] = min(abs(p[i].x), abs(p[i].y));
            }
        } else {
            for (int i = 0; i < n; i++, c *= 3) {
                int t = a % 3; a /= 3;
                if (t == 0) continue;
                if (b++ == 0) {
                    u = dp[k - t * c];
                    if (t == 1) {
                        for (int j = 0; j < n; j++) {
                            u[j] = min(u[j], abs(p[i].x - p[j].x));
                        }
                    } else {
                        for (int j = 0; j < n; j++) {
                            u[j] = min(u[j], abs(p[i].y - p[j].y));
                        }
                    }
                }
            }
        }
        dp[k] = u;
        for (int i = 0; i < n; i++) {
            s += (ll)u[i] * p[i].z;
        }
        r[b] = min(r[b], s);
    }

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

    return 0;
}

Measured memory_bytes: 844864
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX_N 100005

using namespace std;

int n,K;
int a[MAX_N];

int main()
{
	scanf("%d%d",&n,&K);
	printf("%d\n",(int)ceil((n-1.0)/(K-1.0)));
}


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

int main(){
  int N; cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];
  
  sort(d.begin(), d.end(), greater<int>());
  
  int ans = 1;
  int temp = d[0];
  
  rep(i, N){
    if(temp > d[i]){
      ans++;
      temp = d[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vi A(N);
  cin >> A;

  vi csum(N+1,0);
  rep(i,N){
    csum[i+1] = csum[i] + A[i];
  }

  vvi dp(N, vi(N, INF));
  rep(i,N) dp[i][i] = 0;

  rep(i,1,N){
    rep(j,N-i){
      rep(k,j,j+i){
        chmin(dp[j][j+i],dp[j][k]+dp[k+1][j+i]);
      }
      dp[j][j+i] += csum[i+j+1]-csum[j];
    }
  }
  cout << dp[0][N-1] << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n, m;
//ll a[maxn];
vector<int> G[maxn];
vector<int> vis;

void dfs(int x)
{
  vis[x] = 1;
  for(int& y: G[x])if(!vis[y]) dfs(y);
}

//check T
void solve()
{
  //cin >> n; rep(i, 0, n) cin >> a[i];
  cin >> n >> m;
  int x, y, z;
  rep(i, 0, m)
  {
    cin >> x >> y >> z;
    G[x].pb(y);
    G[y].pb(x);
  }
  vis.assign(n+1, 0);
  int cc = 0;
  rep(i, 1, n+1) if(!vis[i])
  {
    dfs(i);
    cc++;
  }
  cout << cc << endl;
  
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  rep(tc, 1, T+1)
  {
    //cout << "Case #" << tc << ": ";
    solve();
  }
  return 0;
}


Measured memory_bytes: 11648
n,m = list(map(int, input().split()))
l_max = 1
r_min = n
for i in range(m):
    l,r = list(map(int, input().split()))
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r
print(r_min-l_max+1 if r_min>=l_max else 0)

Measured memory_bytes: 3060
# coding=utf-8
 
###
### for atcorder program
###
 
import sys
import math
 
# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338
 
    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []
 
        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist
 
    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)
 
    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)
 
    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
 
mymath = mymath()
 
### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()
 
output = output()
 
### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
 
#R = float(input())
#A.append(list(map(int,input().split())))
 
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]
 
#abc list
#abc = [chr(ord('a') + i) for i in range(26)]
 
### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")  

def get_input():
  N = []
  while True:
    try:
      N.append(input())
      #N.append(int(input()))
    except EOFError:
      break
  return N


N = int(input())
W = []

a = 0
b = 0

for i in range(N):
  W.append([x for x in input().split()])
  
for aw, bw in W:
  if aw == bw:
    a += 1
    b += 1
  elif aw > bw:
    a += 3
  else:
    b += 3
    
print(a,b,sep=' ')


Measured memory_bytes: 5816
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);	
	int n, m; cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << '\n';





}




Measured memory_bytes: 256
n = input('')

if n[-1] == '0':
    print('pon')
if n[-1] == '1':
    print('pon')
if n[-1] == '2':
    print('hon')
if n[-1] == '3':
    print('bon')
if n[-1] == '4':
    print('hon')
if n[-1] == '5':
    print('hon')
if n[-1] == '6':
    print('pon')
if n[-1] == '7':
    print('hon')
if n[-1] == '8':
    print('pon')
if n[-1] == '9':
    print('hon')

Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <ctype.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int flag=0;
  if(s[0]!='A') flag=1;
  int x=0,flag1=0;
  for(int i=2;i<n-1;i++){
    if(s[i]=='C'){
      if(flag1){
        flag=1;
      }else{
        flag1=1;
        x=i;
      }
    }
  }
  if(x==0) flag=1;
  for(int i=1;i<n;i++){
    if(i==x) continue;
    if(isupper(s[i])) flag=1;
  }
  if(flag) cout<<"WA"<<endl;
  else cout<<"AC"<<endl;
  return 0;
}


Measured memory_bytes: 256
//Created by: Aditya Singh
//Bleed Blue
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define unm unordered_map<int,int>
#define pb emplace_back
#define nt _int128
#define PI 3.1415926535897932384626433
#define inf 1e18

const int N = 100005;

int ar[N][3], dp[N][3], n;

int solve(int i, int ch)
{
    if (i == n)
        return 0;
    if (ch >= 0 && dp[i][ch] != -1)
        return dp[i][ch];
    int s = 0;
    for (int j = 0; j < 3; j++)
    {
        if (j == ch)
            continue;
        s = max(s, ar[i][j] + solve(i + 1, j));
    }
    return dp[i][ch] = s;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        int i, j, k, m, ans = 0, cnt = 0, sum = 0;
        cin >> n;
        memset(dp, -1, sizeof(dp));
        for (i = 0; i < n; i++)
            for (j = 0; j < 3; j++)
                cin >> ar[i][j];
        cout << solve(0, -1);
    }
    return 0;
}

Measured memory_bytes: 16024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s=new String[3];
        sc.nextInt();
        for(int i=0;i<3;i++){
            s[i]=sc.next();
        }
        char[] c=new char[3];
        int output=0;
        int tmp=0;
        for(int i=0;i<s[0].length();i++){
            for(int j=0;j<3;j++){
                c[j]=s[j].charAt(i);
            }
            tmp=2;
            if(c[0]==c[1])tmp-=1;
            if(c[0]==c[2])tmp-=1;
            if(c[1]==c[2])tmp=tmp==0?0:tmp-1;
            output+=tmp;
        }
        System.out.println(output);

    }

}

Measured memory_bytes: 22996
import math

n = int(input())
mod = 10**9+7

def eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

if n==1:
    print(1)
    exit()

era = eratosthenes(n)

dict = {}
for i in range(n):
    num = i+1
    while num!=1:
        for j in era:
            while num%j==0:
                num/=j
                if j in dict:
                    dict[j]+=1
                else:
                    dict[j]=1

ans = 1
for i in dict:
    ans = ans*(dict[i]+1)%mod

print(ans)


Measured memory_bytes: 3064
N, M = map(int,input().split())
reachable = False
from_start = []
to_end = []

for i in range(M):
    a,b = map(int,input().split())
    if a == 1:
        from_start.append(b)
    elif b == N:
        to_end.append(a)

if len(set(from_start).intersection(set(to_end))) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 21828
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  long long int ans=0;
  for(int i=1; i<=n; i++){
    long long int high=n;
    long long int low=1;
    long long int mid;
    while(high>=low){
      mid=(high+low)/2;
      if(i*mid<n){
        low=mid+1;
      }else{
        high=mid-1;
      }
    }
    if(i*mid<n){
      ans+=mid;
    }else{
      ans+=mid-1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 10);
  for (int i = 1; i <= 360; i++) {
    if ((n * i) % 360 == 0) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main() {
ll x;
cin>>x;
ll y=0;
ll m=100;
while(m<x){
    m*=1.01;
    y++;
}
cout<<y<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    int n; cin >> n;
    int arr[n];
    auto isTri = [](int a, int b, int c){
        return a+b > c && a+c > b && b+c > a;
    };
    for(int &i: arr) cin >> i;
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(arr[i] == arr[j]) continue;
            for(int k = j+1; k < n; k++){
                if(arr[i] == arr[k] || arr[j] == arr[k]) continue;
                if(isTri(arr[i], arr[j], arr[k]))
                    ans++;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3620
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        now_gcd = gcd(a,b)
        for c in range(1,k+1):
            ans += gcd(now_gcd, c)

print(ans)

Measured memory_bytes: 74956
#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin >> x;
    if (x == 1)
        cout << 0 << endl;
    else
        cout << 1 << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf 1000000000000000000
const int sz = 200006;
ll n,k;
vector<ll>h, dp;
int main() {
	io
	cin>>n>>k;
	vector<ll>w(n), v(n);
	for(int i = 0; i<n; i++) cin>>w[i]>>v[i];
	vector<vector<ll>>dp(n+1, vector<ll>(k+1));
	for(int i = 0; i<=n; i++) {
		for(int j = 0; j<=k; j++) {
			if(i == 0 || j == 0) dp[i][j] = 0;
			else if(w[i-1]<=j) {
				dp[i][j] = max(dp[i-1][j-w[i-1]]+v[i-1], dp[i-1][j]);
			}
			else dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][k];
}




Measured memory_bytes: 80256
#!/usr/bin/ruby
#encoding: utf-8

n,m,x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

# compute ncost
ncost = 0
(0..m-1).each do |i|
  if x < a[i] and a[i] < n then
    ncost += 1
  end
end

# compute zcost
zcost = 0
(0..m-1).each do |i|
  if 0 < a[i] and a[i] < x then
    zcost += 1
  end
end

puts [ncost,zcost].min


Measured memory_bytes: 1788
#include <cstdio>

typedef long long ll;
ll min(ll a, ll b) {return a < b ? a : b;}

int main()
{
    // freopen("a.in", "r", stdin);

    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    printf("%lld\n", n / (a + b) * a + min(n % (a + b), a));

    return 0;
}

Measured memory_bytes: 128
from sys import stdin
data = stdin.readlines()

x = int(data[0].split()[0])
n = int(data[0].split()[1])
if n >= 1:
    p = [int(s) for s in data[1].split()]
else:
    p = []

if x in p:
    for i in range(1,100):
        if x-i in p:
            if x+i in p:
                continue
            else:
                print(x+i)
                break
        else:
            print(x-i)
            break
else:
    print(x)

Measured memory_bytes: 9088