akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

void solve() {
  int n;
  std::cin >> n;
  int p;
  int cnt = 0;
  int min = 999999;
  for (int i = 0; i < n; i++) {
    std::cin >> p;
    if (p < min) {
      min = p;
      cnt++;
    }
  }
  std::cout << cnt;
}


int main() {
  solve();
  return 0;
}

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

int main() {
    string a, b;
    cin >> a >> b;
    if (a.length() > b.length()) {
        cout << "GREATER" << endl;
    } else if (a.length() < b.length()) {
        cout << "LESS" << endl;
    } else {
        if (a < b) {
            cout << "LESS" << endl;
        } else if (a > b) {
            cout << "GREATER" << endl;
        } else {
            cout << "EQUAL" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int a, b, c; cin >> a >> b >> c;
	int res = 0;
	if (a == b && a == c && a % 2 == 0) cout << "-1\n";
	else{
		while(1){
			if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) break;
			a /= 2; int a1 = a;
			b /= 2; int b1 = b;
			c /= 2; int c1 = c;
			a = b1 + c1;
			b = a1 + c1;
			c = a1 + b1;
			res++;
		}
		cout << res << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
    int a, b, o;
    char c;
    scanf ("%d %c %d",&a,&c,&b);

    if(c=='+')
    {
        o=a+b;
    }

    else if(c=='-')
    {
        o=a-b;
    }

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

    return 0;

}


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int p = sc.nextInt();
        String s = sc.next();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = s.charAt(i) - '0';
        long ret = 0;
        if (p == 2 || p == 5) {
            for (int i = 0; i < n; i++) {
                if (a[i] % p == 0) ret += (i + 1);
            }
        } else {
            Map<Long, Long> map = new HashMap<>();
            long pow = 1; long cur = 0;
            for (int i = n - 1; i >= 0; i--) {
                cur = (cur + pow * a[i]) % p;
                if (cur == 0) ret++;
                ret += map.getOrDefault(cur, 0L);
                map.put(cur, map.getOrDefault(cur, 0L) + 1);
                pow = (pow * 10) % p;
            }
        }
        out.println(ret);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 53896
#include <iostream>

using namespace std;

string ToMCXI(int v) {
	char c[5] = "ixcm";
	int k[4] = {1, 10, 100, 1000};
	string ret = "";
	for (int i = 3; i >= 0; --i) {
		int d = v / k[i] % 10;
		if (d > 1) ret += (char)(d + '0');
		if (d > 0) ret += c[i];
	}
	return ret;
}
int FromMCXI(string mcxi) {
	int ret = 0;
	for (int i = 0; i < mcxi.size(); ++i) {
		if ('0' <= mcxi[i] && mcxi[i] <= '9') {
			if (i == mcxi.size()-1) ret += mcxi[i]-'0';
			else {
				int mul = 1;
				switch (mcxi[i+1]) {
				case 'm': mul = 1000; break;
				case 'c': mul = 100; break;
				case 'x': mul = 10; break;
				case 'i': mul = 1; break;
				}
				ret += mul * (mcxi[i]-'0');
			}
			++i;
		}
		else {
			int mul = 1;
			switch (mcxi[i]) {
			case 'm': mul = 1000; break;
			case 'c': mul = 100; break;
			case 'x': mul = 10; break;
			case 'i': mul = 1; break;
			}
			ret += mul;
		}
	}
	return ret;
}
int main() {
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		string s1, s2; cin >> s1 >> s2;
		int v = FromMCXI(s1) + FromMCXI(s2);
		cout << ToMCXI(v) << endl;
	}
}

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

signed main(){
    int n; cin>>n;
    vector<string> s(n);
    vector<vector<int>> a(n,vector<int>(26,0));
    rep(i,n){
        cin>>s.at(i);
        rep(j,s.at(i).size()){
            a.at(i).at(s.at(i).at(j)-'a')++;
        }
    }
    string ans="";
    rep(i,26){
        int m=INT_MAX;
        rep(j,n){
            m=min(m,a.at(j).at(i));
        }
        rep(j,m){
            char c='a'+i;
            ans+=c;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){
	string S;
	cin >> S;
	int cnt = 0;
	int pos = 0;
	int neg = 0;
	int id;
	rep(i, S.size()) {
		if ( S[i] == '1' ) pos++;
		else neg++;
	}
	cnt = min(pos, neg) * 2;
	cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int l, a, b, c, d, maxd;
	int fj, fm;
	
	scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
	
	if (a % c != 0){
		fj = a / c + 1;
	}
	else {
		fj = a / c;
	}
	
	if (b % d != 0){
		fm = b / d + 1;
	}
	else {
		fm = b / d;
	}
	
	if (fj < fm){
		maxd = l - fm;
	}
	else {
		maxd = l - fj;
	}
	printf("%d\n", maxd);
	
	return (0);
}

Measured memory_bytes: 596
grp = [[1,3,5,7,8,10,12],[4,6,9,11],[2]]

indata = raw_input().split()

def search(no):
    index = 0
    for g in grp:
        for i in g:
            if no == str(i):
                return index
        index = index + 1
    return None
            
first = search(indata[0])

second = search(indata[1])
if first == second:
    print "Yes"
else:
    print "No"


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#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 REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

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

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N, M;
vector<int> G[100010];
int used[100010];

void f(int v, vector<int>& w) {
  for (int& nv : G[v]) {
    if (used[nv]) continue;
    used[nv] = 1;
    w.PB(nv);
    f(nv, w);
    return;
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  REP(i, M) {
    int A, B;
    cin >> A >> B;
    A--; B--;
    G[A].PB(B);
    G[B].PB(A);
  }
  vector<int> v, w;
  used[0] = used[G[0][0]] = 1;
  v.PB(0);
  w.PB(G[0][0]);
  f(0, v);
  f(G[0][0], w);
  REV(v);
  REP(i, w.size()) v.PB(w[i]);
  cout << v.size() << endl;
  REP(i, v.size()) cout << v[i]+1 << " \n"[i+1==v.size()];

  return 0;
}

Measured memory_bytes: 9328
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def main():
    # Fenwick Tree
    N = bit = None

    def init(n):
        nonlocal N, bit
        N = n
        bit = [0] * (N + 1)  # 1-origin

    def bit_add(pos, val):
        assert pos > 0
        x = pos
        while x <= N:
            bit[x] += val
            x += x & -x  # (x & -x) = rightmost 1 = block width

    def bit_sum(pos):
        ret = 0
        x = pos
        while x > 0:
            ret += bit[x]
            x -= x & -x
        return ret

    # parse input
    N, Q = map(int, input().split())
    init(N)
    AS = list(map(int, input().split()))
    for i, a in enumerate(AS):
        bit_add(i + 1, a)

    for _q in range(Q):
        a, b, c = map(int, input().split())
        if a == 0:
            bit_add(b + 1, c)
        else:
            print(bit_sum(c) - bit_sum(b))


# tests
T1 = """
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
15
7
25
6
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


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

#define FOR(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)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  cout << n*800 - n/15*200 << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int data[5];
	int i,j,k,l,m;
	for(i=0;i<5;i++) {
		scanf("%d",&data[i]);
	}
	for(i=0;i<4;i++) {
		for(j=i+1;j<5;j++) {
			if(data[i]<data[j]) {
				k=data[i];
				data[i]=data[j];
				data[j]=k;
			}
		}
	}
	for(i=0;i<5;i++) {
		printf("%d",data[i]);
		if(i!=4) {
			printf(" ");
		}
		else {
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M, K;
ll dp[110][10];

void solve() {
	cin >> N >> M >> K; K--;
	if(M == 0) {
		cout << 1 << "\n"; return;
	}
	M--;
	dp[0][0] = 1;
	rep(i, 0, N) {
		rep(j, 0, M + 1) {
			rep(bit, 0, (1 << M)) {
				bool ok = true;
				rep(l, 0, M - 1) {
					if((bit & (1 << l)) && (bit & (1 << (l + 1)))) ok = false;
				}
				if(!ok) continue;
				if(bit & (1 << j)) ADD(dp[i + 1][j + 1], dp[i][j]);
				else if(bit & (1 << (j - 1))) ADD(dp[i + 1][j - 1], dp[i][j]);
				else ADD(dp[i + 1][j], dp[i][j]);
			}
		}
	}
	cout << dp[N][K] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
   int W, H, C, w, h, r;
   scanf("%d %d %d", &W, &H, &C);
   w = W; h = H;
   if ( H > W ) {
       r = W;
       W = H;
       H = r;
   }
   r = W % H;
   while ( r ) {
       W = H;
       H = r;
       r = W % H;
   }
   printf("%d\n", ( h / H ) * ( w / H) * C);
   return 0;
}

Measured memory_bytes: 1844
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int n; cin>>n;
	int ans=0;
	int b[12];
	b[0]=1;
	FOR(i,1,12) b[i]=b[i-1]*3;
	FOR(i,3,10){
		FOR(j,0,b[i]){
			int t=0;
			int f3=0,f5=0,f7=0;
			FOR(k,0,i){
				t*=10;
				t+=((j/b[k])%3*2+3);
				if((j/b[k])%3*2+3==3) f3=1;
				if((j/b[k])%3*2+3==5) f5=1;
				if((j/b[k])%3*2+3==7) f7=1;
			}
			if(t<=n&&f3&&f5&&f7){
				ans++;
				//co(t);
			}
		}
	}
	co(ans);
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(3 * n);

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

    sort(a.begin(), a.end(), greater<int> ());

    int64_t ans = 0;
    for(i = 1; i < 2 * n + 1; i += 2) {
        ans += a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
 
#define ascent(i, a, b) for(int (i) = (a); (i) < (b); (i) ++)

using namespace std;

int main() {
  int n;
  while(true) {
    cin >> n;
    if(n == 0) break;

    int a, b;
    int pa = 0, pb = 0; 
    while(n) {
      cin >> a >> b;
      if(a > b) {
	pa += a + b;
      }
      else if(a < b) {
	pb += a + b;
      }
      else {
	pa += a;
	pb += b;
      }
      n --;
    }

    cout << pa << " " << pb << endl;
  }
      
  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n,mx;
    int m[2][105];
    cin>>n;
    for(int i=0;i<2;i++)
        for(int j =0;j<n;j++)
            cin>>m[i][j];


    mx=-50;

    for(int i =0;i<n;i++)
    {

        int sum =0;
        for (int j=0;j<=i;j++)
            sum+=m[0][j];

        for (int j=i;j<n;j++)
            sum +=m[1][j];

        if (mx<sum)
            mx=sum;
    }

    cout<<mx<<endl;
    
    return 0;
}


Measured memory_bytes: 256
<?php
// メモ化テーブル
$case = 0;
while (TRUE) {
	$dp = array();
	$W = trim(fgets(STDIN));
	if ($W == 0) {
		break;
	}
	$case++;
	$N = trim(fgets(STDIN));
	$items = array();
	for ($i = 0; $i < $N; $i++) {
		list($v, $w) = explode(',', trim(fgets(STDIN)));
		$items[] = array('value' => $v, 'weight' => $w);
	}
	$res = rec(0, $W, 0);
	echo "Case {$case}:\n";
	echo $res[0] . "\n";
	echo $res[1] . "\n";
}

// i 番目以降の重さの総和が w 以下となるように選ぶやりかた
function rec($i, $w, $total) {
	global $dp, $N, $items;
	if (isset($dp[$i][$w])) {
		return $dp[$i][$w];
	}
	$res = null;
	if ($i == $N) {
		// もう宝物は残っていない
		$res =  array(0, $total);
	} elseif ($w < $items[$i]['weight']) {
		// この品物は入らないので、入れずに次を調べる
		$res = rec($i + 1, $w, $total);
	} else {
		// 入れる場合と入れない場合を両方試す
		$v1 = rec($i + 1, $w, $total);
		$v2 = rec($i + 1, $w - $items[$i]['weight'], $total + $items[$i]['weight']);
		$v2[0] += $items[$i]['value'];
		if ($v1[0] < $v2[0]) {
			$res = $v2;
		} else {
			$res = $v1;
		}
	}
	return $dp[$i][$w] = $res;
}

Measured memory_bytes: 148680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    int n;
    cin >> n;
    vector<vector<int>> be(n,vector<int>(n,0));
    vector<vector<int>> af(n,vector<int>(n,0));
    rep(i,n){
        string tmp;
        cin >> tmp;
        rep(j,n){
            be[i][j] = tmp[j]-'a';
        }
    }
    int ans = 0;
    int a=0;
    rep(b,n){
        rep(x,n){
            rep(y,n){
                af[(x+a)%n][(y+b)%n] = be[x][y];
            }
        }
        for(int x=1;x<n;x++){
            for(int y=0;y<x;y++){
                if(af[x][y] != af[y][x]){
                    goto wrong;
                }
            }
        }
        ans++;
        wrong:;
    }
    cout << ans*n << endl;
}



Measured memory_bytes: 1024
line1 = [int(n) for n in input().split()]
line2 = [int(n) for n in input().split()]
D = 0
res = 0
for i in range(line1[0]):
    if D <= int(line1[1]):
        res += 1
    else:
        break
    D = D + int(line2[i])
if D <= int(line1[1]):
    res += 1
print(res)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(void){
	int n;
	scanf("%d", &n );
	double x[n];
	char u[n][4];
	double ans = 0.0;
	for(int i=0;i<n;i++){
		scanf("%lf %s", &x[i], &u[i]);
		if( strcmp("JPY", u[i])==0 )	ans += x[i];
		else	ans += x[i] * 380000.0;
      	//printf("%lf", ans);
      	//printf("%lf %s %d\n", x[i], u[i], strcmp("JPY", u[i]) );
    }
	printf("%lf", ans);
	return 0;
}

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

int main(){
    
    vector<int> num(3);
    for(int i=0; i<3; i++){
        cin >> num.at(i);
    }

    sort(num.begin(),num.end());
    int ans=0;

    if((num.at(2)-num.at(0))%2 && (num.at(2)-num.at(1))%2){
        ans+=num.at(2)-num.at(1)+(num.at(1)-num.at(0))/2;
    }
    else if((num.at(2)-num.at(0))%2==0 && (num.at(2)-num.at(1))%2==0){
        ans+=(2*num.at(2)-num.at(1)-num.at(0))/2;
    }
    else{
        num.at(1)++;
        num.at(2)++;
        ans++;
        if((num.at(2)-num.at(0))%2 && (num.at(2)-num.at(1))%2){
        ans+=num.at(2)-num.at(1)+(num.at(1)-num.at(0))/2;
        }
        else if((num.at(2)-num.at(0))%2==0 && (num.at(2)-num.at(1))%2==0){
            ans+=(2*num.at(2)-num.at(1)-num.at(0))/2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,i,j,cc=0,mx=-1;
    cin>>n;
    map<ll,ll>check;
    cc=1;
    check[n]=1;
    while(1){
        if(n%2==0){
            n/=2;
        }
        else n=3*n+1;
        cc++;
        if(check[n]==1)break;
        check[n]=1;
    }
    cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N, A, B;

vector<int>built(int left,int right,int l){
	if (l == 1)return {left,right};
	vector<int>ret;
	int rec;
	int left_, right_, fl;
	left_ = 0;
	right_ = 0;
	fl = 0;
	for (int i = 0; i < 22; i++) {
		int msk = 1 << i;
		if (fl == 0) {
			if ((msk&left) != (msk&right)) { rec = i; fl = 1; }
			else { left_ += ((msk&left) ? msk : 0); right_ += ((msk&right) ? msk : 0); }
		}
		else { left_ += ((msk&left) ? (msk / 2) : 0); right_ += ((msk&right) ? (msk/2LL) : 0); }
	}
	int mid;
	mid = ((left_%2 == 0)?left_+1:left_-1);
	auto ret1 = built(left_,mid,l-1);
	auto ret2 = built(mid, right_,l-1);

	fore(x, ret1) {
		int x_ = 0;
		for (int i = 0; i < 22; i++) {
			int msk = (1LL << i);
			if(i < rec)x_ += ((msk&x) ? msk : 0);
			else if (i == rec)x_ += ((msk&left) ? msk : 0);
			else x_ += (((msk / 2) & x) ? msk:0);
		}
		ret.pb(x_);
	}
	fore(x, ret2) {
		int x_ = 0;
		for (int i = 0; i < 22; i++) {
			int msk = (1 << i);
			if (i < rec)x_ += ((msk&x) ? msk : 0);
			else if (i == rec)x_ += ((msk&right) ? msk : 0);
			else x_ += (((msk/2)&x) ? msk:0);
		}
		ret.pb(x_);
	}
	return ret;
}

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

	cin >> N >> A >> B;
	int cnta = 0;
	int cntb = 0;
	for (ll i = 0; i < 25; i++) {
		if (A&(1LL<<i))cnta++;
		if (B&(1LL<<i))cntb++;
	}

	if (cnta % 2 == cntb % 2) {
		puts("NO");
		return 0;
	}

	auto ans = built(A,B,N);
	puts("YES");
	fore(x, ans)cout << x << " ";
	cout << endl;


	return 0;
}

Measured memory_bytes: 1756
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <numeric>

using namespace std;

typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(0);
    lo x;
    cin >> x;
    for(lo i = -118 ; i <= 119 ; i++){
        for(lo j = -119 ; j <= 118 ; j++){
            if(pow(i, 5) - pow(j, 5) == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    u64 A; cin >> A;
    string B; cin >> B;
    B.erase(1, 1);
    u64 b = stoull(B);
    u64 ans = (A * b) / 100;
    cout << ans << endl;

    return 0;
}

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

int main() {
    string s,t, u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    if(s == u) cout << a - 1 << " " << b << endl;
    else cout << a << " " << b - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){int A,B,C,X,Y,p;cin >> A >> B >> C >> X >> Y;
int a = X-Y;
cout << min(min(A*X+B*Y,2*C*min(X,Y)+ (a > 0 ? A * a : B * (Y - X))),2 * C * ( a > 0 ? X : Y));
}

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

using namespace std;

int getmin(double x[],int n)
{
    int m = 0;
    double min1 = x[0];
    for(int i = 1; i < n; i++)
        if(min1 >= x[i])
        {
            min1 = x[i];
            m = i;
        }
    return m;
}


int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int t,a,x[1001];
        double xx[1001];

        scanf("%d%d",&t,&a);
        for(int i = 0; i < n; i++)
        {
            scanf("%d",&x[i]);
            xx[i] = fabs(t - x[i] * 0.006 - a);
    
        }
        printf("%d\n",getmin(xx,n)+1);

    }
    return 0;
}


Measured memory_bytes: 256
import math
import bisect
import copy
#import time

#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input()))
l=[]
for i in range(int(input())):
	l.append(input())
d={}
d['AC']=0

d['WA']=0
d['TLE']=0
d['RE']=0
for i in range(len(l)):
	d[l[i]]+=1
for u,v in d.items():
	print(u,'x',v)


Measured memory_bytes: 79300
"""
セグメント木で行きたいところだけど、集合の管理が必要になるため、時間がかかりすぎてしまう。
と思いきや、文字の種類は26種類しかないので、問題ない。
"""
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter
    class BIT:
        def __init__(self,n):
            self.size = n
            self.tree = [Counter([]) for _ in range(n+1)]
        
        def change(self,i,x,y):
            while i <= self.size:
                if x in self.tree[i]:
                    self.tree[i][x] -= 1
                if y not in self.tree[i]:
                    self.tree[i][y] = 1
                else:
                    self.tree[i][y] += 1
                i += i&-i
    
        def sum(self,i):
            s = Counter([])
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            cnt = 0
            return s


    N = int(input())
    S = list(input())
    Q = int(input())
    bit = BIT(N)
    for i in range(N):
        bit.change(i+1," ",S[i])

    for _ in range(Q):
        q,a,b = input().split()
        if q == "1":
            x = S[int(a)-1]
            S[int(a)-1] = b
            bit.change(int(a),x,b)
        else:
            a = int(a)
            b = int(b)
            count = bit.sum(b) - bit.sum(a-1)
            ans = 0
            for v in count.values():
                if v > 0:
                    ans += 1
            print(ans)
main()


Measured memory_bytes: 312204
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int, int>
#define pll pair<ll , ll>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define N 200005
#define INF 1000000000000000
const int nax = 305;
double ev[nax][nax][nax];
double p[nax][nax][nax];

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

    int cnt1=0 ,cnt2=0 ,cnt3 =0;
    for(int i=0;i<n;i++)
    {
        int t;cin>>t;
        if(t==1)cnt1++;
        else if(t==2)cnt2++;
        else cnt3++;

    }

    // cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;

    p[cnt1][cnt2][cnt3] = 1;
    
    for(int i = n;i>=0;i--)
    {
        for(int j =n;j>=0;j--)
        {
            for(int k = n ; k>=0;k--)
            {
                if(i+j+k > n)continue;
                if(i==0&&j==0&&k==0)continue;
                double pwaste = (double)(n - (i+j+k))/n;
                double rep = (pwaste/(1-pwaste))+1;

                ev[k][j][i] += rep*p[k][j][i];

                if(k!=0)
                {
                    p[k-1][j][i] += p[k][j][i]*(double)(k)/(i+j+k);
                    ev[k-1][j][i] += ev[k][j][i]*(double)(k)/(i+j+k);;
                }
                if(j!=0)
                {
                    p[k+1][j-1][i] += p[k][j][i]*(double)(j)/(i+j+k);
                    ev[k+1][j-1][i] += ev[k][j][i]*(double)(j)/(i+j+k);;
                }
                if(i!=0)
                {
                    p[k][j+1][i-1] += p[k][j][i]*(double)(i)/(i+j+k);
                    ev[k][j+1][i-1] += ev[k][j][i]*(double)(i)/(i+j+k);;
                }

            }
        }
    }

    cout<<setprecision(15);
    cout<<ev[0][0][0]<<endl;
    return 0;
} 

Measured memory_bytes: 438656
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    if n == 2 {
        if a[0] == a[1] {
            println!("YES");
        } else {
            println!("NO");
        }
        return;
    }

    for i in 0..n {
        if graph[i].len() >= 2 {
            let ans = dfs(i, i, &graph, &a);
            if ans.is_none() || ans.unwrap() > 0 {
                println!("NO");
            } else {
                println!("YES");
            }
            return;
        }
    }
}

fn dfs(v: usize, p: usize, graph: &Vec<Vec<usize>>, a: &Vec<u64>) -> Option<u64> {
    if graph[v].len() == 1 {
        return Some(a[v]);
    }

    let mut children = vec![];
    for &next in graph[v].iter() {
        if p == next {
            continue;
        }
        match dfs(next, v, graph, a) {
            Some(c) => {
                children.push(c);
            }
            None => {
                return None;
            }
        }
    }

    let v = a[v];
    let sum = children.iter().sum::<u64>();
    if sum > 2 * v {
        return None;
    }

    let upload = 2 * v - sum;
    if sum < upload || (sum - upload) % 2 != 0 {
        return None;
    }
    let matching = (sum - upload) / 2;
    children.sort();
    children.reverse();
    if children.len() > 0 && children[0] > matching + upload {
        return None;
    }
    Some(upload)
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 33788
#include<iostream>
#include<string>
using namespace std;
#define ll long long

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll c=n/(a+b);
  ll d=n%(a+b);
  if(a<d){
    d=a;
  }
  cout << c*a+d << endl;
}


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

using namespace std;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

class UnitnFind
{
	vector<int> parent;
	vector<int> rank;
public:
	UnitnFind(int n){
		parent.resize(n);
		rank.resize(n);
		REP(i, n){
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x){
		if(parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unit(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] < rank[y]){
			parent[x] = y;
		}
		else{
			parent[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

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

	int N, M;
	cin >> N >> M;
	VI A(N);
	REP(i, N) cin >> A[i];
	UnitnFind uf(N + 1);
	REP(i, M){
		int p, q;
		cin >> p >> q;
		uf.unit(p, q);
	}
	int ret = 0;
	REP(i, N){
		if(uf.same(i + 1, A[i])) ret++;
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1408
import math

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

length = len(n_list)
count = 0
for i in range(length):
	for j in range(i+1, length):
		for k in range(j+1, length):
			if n_list[i] != n_list[j] and n_list[i] != n_list[k] and n_list[j] != n_list[k]:
				if abs(n_list[i]-n_list[j]) < n_list[k] and n_list[k] < n_list[i]+n_list[j]:
					count += 1
    
print(count) 

Measured memory_bytes: 73976
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            int input = int.Parse(Console.ReadLine());

            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Reverse(x);
            Console.WriteLine(string.Join(" ",x));

        }
    }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll R, C, K;
  cin >> R >> C >> K;
  vector<vector<vector<ll>>> dp(R + 1, vector<vector<ll>>(C + 1, vector<ll>(4, 0)));
  vector<vector<ll>> maze(R, vector<ll>(C, 0));
  for (ll i = 0; i < K; ++i) {
    ll r, c, v;
    cin >> r >> c >> v;
    r -= 1;c -= 1;
    maze.at(r).at(c) = v;
  }
  for (ll i = 0; i <= R; ++i) {
    for (ll j = 0; j <= C; ++j) {
      for (ll k = 0; k <= 3; ++k) {
        if (j != C) {
          dp.at(i).at(j + 1).at(k) = max(dp.at(i).at(j + 1).at(k), dp.at(i).at(j).at(k));
          if (k != 3 && i != R) {
            dp.at(i).at(j + 1).at(k + 1) = max(dp.at(i).at(j + 1).at(k), dp.at(i).at(j).at(k) + maze.at(i).at(j));
          }
        }
        if (i != R && j != C && k != 3) {
          // cout << dp.at(i + 1).at(j).at(0) << "\n";
          dp.at(i + 1).at(j).at(0) = max(dp.at(i + 1).at(j).at(0), dp.at(i).at(j).at(k) + maze.at(i).at(j));
        }
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < 4; ++i) {
    ans = max(ans, dp.at(R).at(C).at(i));
  }
  cout << ans << "\n";
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
int n;
int digit[12];
void rec(int depth, int biggest) {
    if(depth == n+1) {
        string s;
        rep1(i,n) s = s + (char)('a' + digit[i]);
        cout << s << '\n';
        return;
    }
    for(int i = 0; i <= biggest+1; ++i) {
        digit[depth] = i;
        rec(depth+1, max(biggest, i));
    }
    return;
}

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    cin >> n;
    rec(1, -1);

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n,d; cin>>n>>d;
	int x[n][d]; rep(i,n)rep(j,d) cin>>x[i][j];
	int cnt=0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int sum=0;
			for(int k=0;k<d;k++){
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			for(int k=1;k<1000;k++){
				if(sum==k*k) {
					cnt++;
					break;
				}
			}
			// cout<<sum<<endl;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

VV(pii) G;
vector<LL> dist;

void dfs(int u, LL d){
	if(dist[u] >= 0){ return; }
	dist[u] = d;
	for(cauto p : G[u]){
		dfs(p.first, d + p.second);
	}
}

void mainmain(){
	int n;
	scanf("%d", &n);
	G.resize(n + 1);
	for(int i = 0; i < n - 1; ++i){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		G[a].emplace_back(b, c);
		G[b].emplace_back(a, c);
	}
	int q, k;
	scanf("%d%d", &q, &k);
	dist.assign(n + 1, -1);
	dfs(k, 0);
	for(int i = 0; i < q; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		LL ans = dist[x] + dist[y];
		printf("%lld\n", ans);
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

using namespace std;
int const MAX = 55;

int n[2];
int deck[2][MAX];
int sum[2][MAX];
 
int dp[MAX][MAX][MAX][MAX][2][4];
bool used[MAX][MAX][MAX][MAX][2][4];

int rec(int l1, int r1, int l2, int r2, int which, int pass) {

  auto& ret = dp[l1][r1][l2][r2][which][pass];

  if(used[l1][r1][l2][r2][which][pass]) return ret;
  used[l1][r1][l2][r2][which][pass] = 1;

  if(pass == 3) {
    return ret = 0;
  }

  // pass
  ret = -rec(r2, r2, r1, r1, !which, pass + 1)
        + (sum[which][r1] - sum[which][l1])
        - (sum[!which][r2] - sum[!which][l2]);

  if(r1 == n[which])
    return ret;

  if(deck[which][r1] != -1)
    ret = max(ret, -rec(l2, r2, l1, r1 + 1, !which, 0));
  else
    ret = max(ret, -rec(r2, r2, l1, r1 + 1, !which, 0));

  return ret;
}
 
int main() {

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

  for(int i=0; i<2; i++)
    for(int j=0; j<n[i]; j++)
      cin >> deck[i][j];

  for(int i=0; i<2; i++) {
    sum[i][0] = 0;
    for(int j=0; j<n[i]; j++) {
      int point = deck[i][j];
      if(point == -1) point = 0;
      sum[i][j + 1] = sum[i][j] + point;
    }
  }

  cout << rec(0, 0, 0, 0, 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 110068
#include<bits/stdc++.h>
#define fi(i,a,b) for(ll i = a; i < b; i++)
#define fd(i,a,b) for(ll i = a; i >= b; i--)
#define cfi(container,it) for(auto it = container.begin(); it != container.end(); it++)
#define cfd(container,it) for(auto it = container.rbegin(); it != container.rend(); it++)
#define vi vector<int>
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back

using namespace std;
using ll = long long;
const int MOD = (int) 1e9 + 7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;

	vi l(n);
	fi(i, 0, n) {
		cin>>l[i];
	}	

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

	ll ans = 0;
	fi(i, 0, n) {
		fi(j, i + 1, n) {
			if(l[i] == l[j])
				continue;

			fi(k, j + 1, n) {

				if(l[k] == l[i] || l[k] == l[j])
					continue;

				if(l[i] + l[j] > l[k]) {
					ans++;
				}
			}
		}
	}

	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 3660