akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  map<pii, int> l;
  rep3(i, 1, n + 1) {
    string s = to_string(i);
    l[pii(s[0] - '0', s[sz(s) - 1] - '0')]++;
  }
  ll ans = 0;
  rep3(i, 1, 10) rep3(j, 1, 10) ans += 1LL * l[pii(i, j)] * l[pii(j, i)];
  cout << ans << endl;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
l = []
for i in range(N):
  l.append(L + i)
l.sort()
if 0 in l:
  print(sum(l))
else:
  if l[0] > 0:
    l.pop(0)
    print(sum(l))
  else:
    l.pop(-1)
    print(sum(l))


Measured memory_bytes: 2940
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Test_200().doIt();
	}
	class Test_200{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int ans = (b - a) % 2;
			if(a <= 0 && b >= 0)System.out.println("Zero");
			else if(a > 0 && b > 0)System.out.println("Positive");
			else if(ans == 0)System.out.println("Negative");
			else System.out.println("Positive");
		}
	}
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000+7;
long long A,B,C,D;
long long dp[1100][1100];

long long ncr[1100][1100];

long long bpow(long long a,long long b,const long long mod){
	return (b?bpow(a*a%mod,b/2,mod)*(b&1?a:1):1)%mod;
}

long long invv[1111];

long long dfs(int g,int r){
	if( g == 0 ) return r == 0;
	if( dp[g][r] != -1 ) return dp[g][r];
	long long ans = dfs(g-1,r);
	
	
	if( A <= g and g <= B ){
		long long sub = 1;
		for(int i = 1 ; i <= D ; i++){
			if( i * g > r ) break;
			
			sub = sub * ncr[r-(i-1)*g][g];
			sub %= mod;
			sub *= invv[i];
			sub %= mod;
			if( i >= C ){
				ans += dfs(g-1,r-i*g) * sub;
				ans %= mod;
			}
		}
	}
	//cout << g << " " << r << ": " << ans << endl;
	return dp[g][r] = ans;	
}
void solve(long long N){
	memset(dp,-1,sizeof(dp));
	cout << dfs(N,N) << endl;
}

int main(){
	for(int i = 0 ; i < 1010 ; i++)
		invv[i] = bpow(i,mod-2,mod);
	ncr[0][0] = 1;
	for(int i = 0 ; i < 1050 ; i++){
		for(int j = 0 ; j < 1050 ; j++){
			ncr[i][j] %= mod;
			ncr[i+1][j] += ncr[i][j];
			ncr[i+1][j+1] += ncr[i][j];
			
		}
	}
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&C);
	scanf("%lld",&D);
	solve(N);
	return 0;
}


Measured memory_bytes: 18816
s = list(input())

if s.count(s[0]) == 4:
    print("No")
else:
    for i in s[1:]:
        if s[0] == i:
            s.remove(i)
            s.remove(i)
            break

    if len(s) == 4:
        print("No")

    if len(s) == 2:
        if s[0] == s[1]:
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input

    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}

ll a[4];
int main(void){

    for(int i=1;i<=3;i++)   cin >> a[i];
    ll ans=1e18+8;
    do{
        ll res=abs(a[2]-a[3])+abs(a[2]-a[1]);
        ans=min(ans,res);
    }while(next_permutation(a+1,a+1+3));
    cout << ans <<endl;
    return 0;
}


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


int main(void){
  string S;
  cin >> S;
  int count =0;
  int i_start = 0, i_end = S.size() - 1;
  while(i_end - i_start >= 1){
  	if(S.at(i_start) != S.at(i_end)) count++;
  	i_start++;
    i_end--;
  }
  cout << count << endl;


}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  string s;
  cin >> s;

  set<char> chs;
  each (ch, s) {
    chs.insert(ch);
  }

  ll ans = 1e18;
  each (ch, chs) {
    ll c = 0;
    string ss = s;
    while (true) {
      ll same = 0;
      for (ll i = 0; i < ss.size(); ++i) {
        if (ss[i] == ch) same++;
      }
      if (ss.size() == same) break;

      string as = ss;
      for (ll i = 1; i < as.size(); ++i) {
        if (as[i] == ch) as[i-1] = ch;
      }

      string bs = as;
      for (ll i = bs.size()-1; i >= 0; --i) {
        if (bs[i] != ch) {
          bs.erase(i, 1);
          break;
        }
      }

      for (ll i = 0; i < bs.size(); ++i) {
        if (bs[i] == ss[i] || bs[i] == ss[i+1]) continue;
        bs = as;
        break;
      }

      ++c;
      ss = bs;
    }

    ans = min(ans, c);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		long num = sc.nextInt();
		long ans = 1;

		for(long count = num; count > 1; count--) {
			ans = ans * count;
		}

		System.out.println(ans);
		ans = 0;
	}

}

Measured memory_bytes: 26176
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

     
int main() {
  int n, m;  cin >> n >> m;
  vector<int> w(n);
  vector<int> v(n);
  rep (i, n) {
    cin >> v[i] >> w[i];
  }
  vector<vector<int>> dp(n, vector<int>(m+1, 0));

  for (int i=w[0]; i<m+1; ++i) {
    dp[0][i] = i / w[0] * v[0];
  }
  for (int i=0; i<n-1; ++i) rep (j, m+1) {
    if (j < w[i+1]) dp[i+1][j] = dp[i][j];
    else {
      dp[i+1][j] = max({dp[i][j - w[i+1]] + v[i+1], dp[i+1][j - w[i+1]] + v[i+1], dp[i][j]});
    }
  }

  cout << *max_element(dp[n-1].begin(), dp[n-1].end()) << endl;
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(){
  string N; cin >> N;
  int k=N.size();
  if(k==1){
    cout << N << endl;
    return 0;
  }
  for(int i=1;i<k;i++){
    if(N[i]!='9'){
      cout << 9*(k-1)+ctoi(N[0])-1 << endl;
      return 0;
    }
  }
  cout << 9*(k-1)+ctoi(N[0]) << endl;
}
  
  

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

int main() {
  int h, a; cin >> h >> a;
  cout << (h + a - 1) / a << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define N 300005
#define mod 998244353
#define ll long long
using namespace std;
ll fac[N],inv[N],k,f[N];
int n,a,b;

ll calc(int n,int m){
	if(m>n||m<0)return 0;
	return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main(){
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=N;++i)
	fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=2;i<=N;++i)
	inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=N;++i)
	inv[i]=1ll*inv[i-1]*inv[i]%mod;
	scanf("%d%d%d%lld",&n,&a,&b,&k);
	if(k==0)return puts("1"),0;
	ll ans=0;
	for(int i=0;i<=n;++i){
		if((k-a*i)%b==0&&(k-a*i>=0)){
			int t=(k-a*i)/b;
			f[i]=(calc(n,i)*calc(n,t))%mod;
			ans=(ans+f[i])%mod;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7168
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = 0;
    int x = 0;
    int y = 0;
    
    for (int i=0; i<n; i++){
      int t1 = sc.nextInt();
      int x1 = sc.nextInt();
      int y1 = sc.nextInt();
      int dt = t1 - t;
      int dx = x1 - x;
      int dy = y1 - y;
      int dist = Math.abs(dx) + Math.abs(dy);
      if (dist>dt || (dt-dist)%2==1){
        System.out.println("No");
        return;
      }

      t = t1;
      x = x1;
      y = y1;
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 87232
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void dump(T)(T[][] g) {
    for (int i = 0; i < g.length; i++) {
        for (int j = 0; j < g[i].length; j++) {
            stderr.write(" ", g[i][j]);
        }
        stderr.writeln();
    }
}

void main() {
    auto nmq = readints;
    int n = nmq[0], m = nmq[1], Q = nmq[2];

    auto g = new int[][](n + 1, n + 1);
    for (int i = 0; i < m; i++) {
        auto lr = readints;
        g[lr[0]][lr[1]]++;
    }
    debug dump(g);

    for (int r = n; r > 0; r--) {
        for (int c = 1; c <= n; c++) {
            g[r][c] += g[r][c - 1];
        }
        if (r < n) {
            for (int c = 1; c <= n; c++) {
                g[r][c] += g[r + 1][c];
            }
        }
    }

    debug { stderr.writeln("-- prepared --"); dump(g); }

    for (int i = 0; i < Q; i++) {
        auto pq = readints;
        int p = pq[0], q = pq[1];

        writeln(g[p][q]);
    }
}


Measured memory_bytes: 9340
#include <stdio.h>

int main(){
    long long int a,b,c,d,ans1,ans2,ans3,ans4;
    int i = 0;
    scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
    ans1 = a * c;
    ans2 = b * d;
    ans3 = a * d;
    ans4 = b * c;
    if(ans1 >= ans2 && ans1 >= ans3 && ans1 >= ans4){
        printf("%lld\n", ans1);
    }else if(ans2 >= ans1 && ans2 >= ans3 && ans2 >= ans4){
        printf("%lld\n", ans2);
    }else if(ans3 >= ans2 && ans3 >= ans1 && ans3 >= ans4){
        printf("%lld\n", ans3);
    }else if(ans4 >= ans2 && ans4 >= ans3 && ans4 >= ans1){
        printf("%lld\n", ans4);
    }
}

Measured memory_bytes: 1712
MOD = 10**9 + 7

class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % MOD
            self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

N, K = map(int, input().split())
comb = Combination(N + K + 10)

for i in range(1, K + 1):
    ans = comb.ncr(N - K + 1, i) * comb.nhr(i, K - i) % MOD
    print(ans)


Measured memory_bytes: 3828
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(void)
{
  for(;;){
    int n,a,s,g;
    cin >> n >> a >> s >> g;
    if(!n) return 0;
    vector<pair<string,pair<int,int> > >e(a);
    REP(i,a) cin >> e[i].second.first >> e[i].second.second >> e[i].first;
    vector<vector<int> > wf(n,vector<int>(n,1048576));
    REP(i,a) wf[e[i].second.first][e[i].second.second]=1;
    REP(i,n) wf[i][i]=0;
    REP(k,n) REP(i,n) REP(j,n) wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
    if(wf[s][g]>100){
      cout << "NO" << endl;
      continue;
    }
    vector<vector<pair<string,pair<int,int> > > > us(n,vector<pair<string,pair<int,int> > >());
    REP(i,a) if(wf[e[i].second.second][g]<100) us[e[i].second.first].push_back(e[i]);
    REP(i,n) SORT(us[i]);
    REP(i,n){
      if(us[i].size()<2) continue;
      auto j=us[i].begin();
      for(;j+1!=us[i].end();++j){
	string l=j->first,r=(j+1)->first;
	int len=min(l.size(),r.size());
	if(string(l.begin(),l.begin()+len)<string(r.begin(),r.begin()+len)) break;
      }
      us[i]=vector<pair<string,pair<int,int> > >(us[i].begin(),j+1);
    }
    vector<string> sf(n,"");
    REP(i,n){
      if(us[i].size()<1) continue;
      sf[i]=us[i].back().first;
    }
    vector<vector<pair<int,int> > > ll(n,vector<pair<int,int> >());
    REP(i,n){
      for(auto j:us[i]) ll[i].push_back(make_pair(j.first.size(),j.second.second));
    }
    string sp(256,'z'+1);
    vector<set<int> > re(300,set<int>());
    re[0].insert(s);
    int anslen=256;
    REP(i,250){
      for(int pos:re[i]){
	if(pos==g){
	  anslen=i;
	  break;
	}
	for(pair<int,int> mov:ll[pos]){
	  bool flag=true;
	  int j;
	  for(j=0;j<mov.first;++j){
	    if(sf[pos][j]>sp[i+j]){
	      flag=false;
	      break;
	    }else if(sf[pos][j]<sp[i+j]){
	      break;
	    }
	  }
	  if(!flag) continue;
	  if(j!=mov.first) REP(k,6) re[i+j+k+1].clear();
	  sp.replace(i,mov.first,sf[pos],0,mov.first);
	  re[i+mov.first].insert(mov.second);
	}
      }
      if(anslen<256) break;
    }
    if(anslen<256) cout << string(sp.begin(),sp.begin()+anslen) << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 3276
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 998244353; //1000000007;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void A();

int main()
{
	A();
	fflush(stdout);
	return 0;
}

static void A()
{
	int N;
	get(N);

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

	bool even = true;
	int ans = 0;
	while (even) {
		for (int i = 0; i < N; i++) {
			if (ai[i] && ai[i] % 2 == 0) {
				ai[i] /= 2;
			}
			else {
				even = false;
			}
		}
		if (even) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 2000010;
const Int MOD = 1000000007;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
Int COM(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    COMinit();
    int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
    cout << (COM(c1 + r1, c1) + MOD - COM(1 + c2 + r1, 1 + c2)
             + MOD - COM(1 + c1 + r2, c1) + COM(2 + c2 + r2, 1 + c2)) % MOD << endl;
    return 0;
}


Measured memory_bytes: 47104
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
       Scanner scan = new Scanner(System.in);
       int A = scan.nextInt();
       int B = scan.nextInt();
       int add = A + B ;
       int sub = A - B ;
       int mul = A * B ;
       int max;
       if (add <= sub){
            max = Math.max(sub, mul);
        } else {
            max = Math.max(add, mul);
        }
       System.out.println(max);
       
    }
    
}


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

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

    int h[N*2][3];
    int dp[N*2][3];

    for (int i=0; i<N;i++) {
        for (int j=0; j<3;j++) {
            cin >> h[i][j];
            dp[i][j]=0;
        }
    }

    for (int i=0; i<2*N; i++) {
        for (int j=0; j<3;j++) {
            dp[i][j]=0;
        }
    }

    for (int i=0; i<N;i++) {
        for (int j=0; j<3;j++) {
            for (int k=0; k<3;k++) {
                if (j==k) continue;

                if (dp[i + 1][k] < dp[i][j] + h[i][k])
                {
                    dp[i + 1][k] = dp[i][j] + h[i][k];
                }
            }
        }
    }

    int max = 0;
    for (int j=0; j<3; j++) {
        if (max < dp[N][j])
        {
            max = dp[N][j];
        }
    }
    cout << max << endl;
} 


Measured memory_bytes: 4864
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % MOD;
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];

	ll mi = 1e10;
	ll ans;
	for (ll n = -100; n <= 100; n++) {
		ll sum = 0;
		rep(i, N) sum += pow(n - a[i], 2);
		mi = min(mi, sum);
	}

	cout << mi << endl;
}

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

string next(string s) {
  if (s.size() == 0) return "-1";
  if (s[s.size() - 1] == 'z') return next(s.substr(0, s.size() - 1));
  bool used[26] = {false};
  for (int i = 0; i < s.size(); i++) used[s[i] - 'a'] = true;
  for (int i = s[s.size() - 1] - 'a'; i < 26; i++) if (!used[i]) {
    s[s.size() - 1] = 'a' + i;
    return s;
  }
  return next(s.substr(0, s.size() - 1));
}

int main () {
  string s;
  cin >> s;
  bool used[26] = {false};
  for (auto &c : s) used[c - 'a'] = true;
  if (s.size() < 26) {
    cout << s;
    for (int i = 0; i < 26; i++) if (!used[i]) {
      cout << (char)('a' + i) << endl;
      return 0;
    }
  } else {
    cout << next(s) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/* Dictionary */
#include <stdio.h>
#include <string.h>

#define M 1046527
//#define NIL (-1)
#define L 14

char H[M][L];


int getChar(char ch) {
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}


long long getKey(char str[]) {
    long long sum=0, p=1, i;
    for(i=0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1));}

int find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for(i=0;; i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for(i=0;; i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for(i=0; i<M; i++){ H[i][0] = '\0'; }
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s %s", com, str);

        if(com[0] == 'i') {
            insert(str);
        } else {
            if(find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16084
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
   int n, num = 1, fl = 0, z = 0; cin >> n;
   while(n--) {
     int x; cin >> x;
     if(x == 0) {
       cout << "0\n"; return;
     }
     if((INF/x) < num) {
       fl = 1;
     }
     num *= x;
   }
   if(num > INF || fl) num = -1;
   cout << num << '\n';
}

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

  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
      solve();
  }
}    


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define int long long 
#define N 200005

int h[N],mx[N];


int32_t main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n;i++) mx[i]=-1;
    while(m--){
        int u,v;
        cin>>u>>v;
        mx[u]=max(mx[u],h[v]);
        mx[v]=max(mx[v],h[u]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(h[i]>mx[i]) cnt++;
    }
    cout<<cnt<<endl;
    
}

Measured memory_bytes: 5160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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 S>
vector<int> Z_Algorithm(const S &s) {
    vector<int> prefix(s.size());

    prefix[0] = s.size();
    int i = 1, j = 0;
    while (i < s.size()) {
        while (i+j < s.size() && s[j] == s[i+j]) ++j;
        prefix[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < s.size() && k+prefix[k] < j) prefix[i+k] = prefix[k], ++k;
        i += k; j -= k;
    }

    return prefix;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];

    vector<ll> P(3*N);
    rep(i,N) P[i] = B[i%N]^B[(i+1)%N];
    rep(i,2*N) P[i+N] = A[i%N]^A[(i+1)%N];

    auto prefix = Z_Algorithm<vector<ll>>(P);
    vector<pll> ans;
    rep(i,N) {
        if (prefix[i+N] >= N) {
            ans.emplace_back(i,A[i]^B[0]);
        }
    }

    for (auto i : ans) cout << i.first << " " << i.second << ln;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n+1);
  for(int i=0; i<n-1; i++){
    int a;
    cin >> a;
    vec[a]++;
  }
  
  for(int i=1; i<=n; i++){
    cout << vec[i] << endl;
  }
}
  

Measured memory_bytes: 4052
import sys
input = sys.stdin.readline

N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]

A.sort()

Il = []
L = 1
R = 10**9

for i in range(N):
    l, r = A[i]
    L = max(L, l)
    R = min(R, r)
    Il.append(max(0, R - L + 1))

Ir = []
L = 1
R = 10**9

for i in range(N)[::-1]:
    l, r = A[i]
    L = max(L, l)
    R = min(R, r)
    Ir.append(max(0, R - L + 1))

Ir = Ir[::-1]
res = 0

for i in range(N - 1):
    res = max(res, Il[i] + Ir[i + 1])

A.sort(key=lambda x:x[1] - x[0])

maxrange = A[-1][1] - A[-1][0] + 1

L = 1
R = 10**9

for i in range(N - 1):
    l, r = A[i]
    L = max(L, l)
    R = min(R, r)

res = max(res, maxrange + max(0,R - L + 1))

print(res)

Measured memory_bytes: 29144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  int N = in();
  int M = in();
  int A[128];

  int odd = 0, os[128];
  for (int i = 0; i < M; ++i) {
    A[i] = in();
    if (A[i] % 2 == 1) {
      os[odd++] = i;
    }
  }

  if (odd >= 3) {
    puts("Impossible");
    return 0;
  }

  for (int i = 0; i < odd; ++i) {
    if (os[i] != 0 || os[i] != M - 1) {
      if (A[0] % 2 == 0) {
        swap(A[0], A[os[i]]);
      } else {
        swap(A[M - 1], A[os[i]]);
      }
    }
  }

  vector<int> B;
  B.push_back(A[0] - 1);
  for (int i = 1; i < M; ++i) {
    if (A[i] % 2 == 0) {
      B.push_back(A[i]);
    } else {
      B.push_back(2);
      B.push_back(A[i] - 1);
    }
  }

  int cnt = 0, sum = 0;
  vector<int> C;
  for (const int b : B) {
    if (b > 0) {
      ++cnt;
      sum += b;
      C.push_back(b);
    }
  }
  if (sum < N) {
    ++cnt;
    C.push_back(N - sum);
  }

  for (int i = 0; i < M; ++i) {
    printf("%d%c", A[i], i==M-1 ? '\n' : ' ');
  }
  printf("%d\n", cnt);
  for (int i = 0; i < (int)C.size(); ++i) {
    printf("%d%c", C[i], i==C.size()-1 ? '\n' : ' ');
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> mypair;
#define eps 1e-6
#define equals(a,b) (fabs( (a) - (b) )< EPS )
#define EPS eps
typedef struct point{
	double x,y;
	point(){};
	point(double x ,double y):x(x),y(y){};
	point operator + (point &p){ return point(x+p.x,y+p.y);	}
	point operator - (point &p){ return point(x-p.x,y-p.y);	}
	point operator * (point &p){ return point(x*p.x-y*p.y,x*p.y+y*p.x) ;}
	point operator * (double a){ return point(x*a,y*a);	}
	point operator / (double a){ return point(x/a,y/a);	}
	
	double abs() { return sqrt(norm()); }
	double norm() { return x*x+y*y; }
	
	bool operator < (const point &p) const { return x!=p.x ? x<p.x : y<p.y; }
	bool operator == (const point &p) const { return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS; }
}point;

double cross(point a,point b){ return a.x*b.y - a.y*b.x ; }//ﾂ外ﾂ静・zﾂ青ｬﾂ閉ｪ)ﾂ　aﾂ×b
bool isparallel(point a,point b){ return equals(cross(a,b),0.0); }
double dot(point a,point b){ return a.x*b.x+a.y*b.y ; } //ﾂ禿ﾂ静渉　aﾂ・b
point make(){ 
	double x,y; cin>>x>>y;
       	return point(x,y);
}
int dfs(int now,int m,int ans,vector<vector<point > > &ang,vector<bool>&used){
	if(now == m-1)return ans;
	if(!used[now]) return dfs(now+1,m,ans,ang,used);
	used[now] = false;
	int tmp = ans;
       for(int i = 0;i< m;i++) if(used[i]){
	used[i] = false;
	int count = 1;
	vector<int> convert;
	convert.push_back(i);
	point tmpang = ang[now][i] ;
		for(int j = now+1;j<m;j++){
			if(used[j] )for(int k = j+1;k<m;k++){
				if(used[k]){
					if(isparallel(tmpang,ang[j][k])){
					used[j] =false;
					used[k] = false;
					convert.push_back(j);
					convert.push_back(k);
					count++;
					break;	
					}		
				}	
			}
		}
		
		//	cout<<endl<<"debug"<<now<<' '<<i<<' '<<count<<' '<<count*(count-1)/2<<endl;
		tmp = max(tmp,dfs(now+1,m,ans+(count*(count-1))/2,ang,used));
		for(int j=0;j<convert.size();j++){
			used[convert[j]]  = true;
		//	cout<<convert[j]<<' ';
       		}
	}
	used[now] = true;
	return tmp;	
}

int main(){
	int m;
	cin>>m;
	vector<point> p(m);
	for(int i=0;i<m;i++){
	p[i] = make();
	}
	vector<vector<point> > ang(m,vector<point> (m) );
	for(int i=0;i<m;i++){

		for(int j=0;j<m;j++){
			ang[i][j] = p[i]-p[j];
		}
	}
	vector<bool> used(m,true);
	cout<<dfs(0,m,0,ang,used)<<endl;

	return 0;
}



Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef int T;
const T MOD = 100000;
inline void add(T& x, T y){ x = (x + y); while(x >= MOD){ x -= MOD; } }

int main(){
    const string JOI = "JOI";
    int H, W;
    while(cin >> H >> W){
        string flag[20];
        REP(y, H) cin >> flag[y];

        static T dp[1 << 20][2][2] = {}; // JO flag, last is J, satisfy
        REP(s, 1 << W) REP(i, 2) REP(j, 2) dp[s][i][j] = 0;
        dp[0][0][0] = 1;
        for(int y = 0; y < H; y++)
        for(int x = 0; x < W; x++){
            static T next[1 << 20][2][2] = {};
            REP(s, 1 << W) REP(i, 2) REP(j, 2) next[s][i][j] = 0;

            for(int s = 0; s < (1 << W); s++)
            for(int lastJ = 0; lastJ < 2; lastJ++)
            for(int satis = 0; satis < 2; satis++){
                if(dp[s][lastJ][satis] == 0) continue;
                //printf("x:%d y:%d s:%d lastJ:%d satis:%d dp:%d\n", x, y, s, lastJ, satis, dp[s][lastJ][satis]);
                for(char c : JOI){
                    if(flag[y][x] != '?' && flag[y][x] != c) continue;
                    int ns = s & ~(1 << x);
                    if(c == 'J'){
                        //printf("J: next[%d][%d][%d] <- %d\n", ns, 1, satis, dp[s][lastJ][satis]);
                        add(next[ns][1][satis], dp[s][lastJ][satis]);
                    }else if(c == 'O'){
                        if(x > 0 && lastJ) ns |= (1 << (x - 1));
                        //printf("O: next[%d][%d][%d] <- %d\n", ns, 0, satis, dp[s][lastJ][satis]);
                        add(next[ns][0][satis], dp[s][lastJ][satis]);
                    }else if(c == 'I'){
                        int nsatis = satis;
                        if(s >> x & 1) nsatis = 1;
                        //printf("I: next[%d][%d][%d] <- %d\n", ns, 0, nsatis, dp[s][lastJ][satis]);
                        add(next[ns][0][nsatis], dp[s][lastJ][satis]);
                    }
                }
            }

            REP(s, 1 << W) REP(lastJ, 2) REP(satis, 2) dp[s][lastJ][satis] = next[s][lastJ][satis];
        }
        T ans = 0;
        for(int s = 0; s < (1 << W); s++)
        for(int lastJ = 0; lastJ < 2; lastJ++){
            add(ans, dp[s][lastJ][1]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 33984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int hoge;
  cin >> hoge;
  int ans[10050] = {0};

  for (int x = 1; x * x <= 10050; ++x)
  {
    for (int y = 1; y * y <= 10050; ++y)
    {
      for (int z = 1; z * z <= 10050; ++z)
      {
        int a = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x;
        if (a <= 10010)
          ans[a]++;
      }
    }
  }

  for (int i = 1; i <= hoge; ++i)
    cout << ans[i] << endl;
  // cout << i << " " << ans[i] << endl;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int a,b;
int main(){
    cin>>a>>b;
    if(a==b)rep(i,a)cout<<a;
    else if(a>b)rep(i,a)cout<<b;
    else rep(i,b)cout<<a;
    cout<<endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        for (int i = 0; i < k; i++) {
            if (i % 2 == 0) {
                if (a % 2 == 1) {
                    a--;
                }
                a /= 2;
                b += a;
            } else {
                if (b % 2 == 1) {
                    b--;
                }
                b /= 2;
                a += b;
            }
        }

        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,x,t; cin>>n>>x>>t;
  int y=n/x;
  if(n%x!=0)y++;
  cout<<y*t<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
char t, start[100005];
bool flag = false;
int Q, t1, t2;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> start;
	list<char> L(start, start + strlen(start));
	cin >> Q;
	while (Q--)
	{
		cin >> t1;
		if (t1 == 1)
		{
			flag = !flag;
		}
		else
		{
			cin >> t2 >> t;
			if (flag)
			{
				if (t2 == 1)
				{
					L.push_back(t);
				}
				else
				{
					L.push_front(t);
				}
			}
			else
			{
				if (t2 == 1)
				{
					L.push_front(t);
				}
				else
				{
					L.push_back(t);
				}
			}
		}
	}
	if (flag)
	{
		for (list<char>::reverse_iterator rit = L.rbegin(); rit != L.rend(); ++rit)
			cout << *rit;
		cout << '\n';
	}
	else
	{
		for (list<char>::iterator it = L.begin(); it != L.end(); ++it)
		{
			cout << *it;
		}
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, rr;
	cin >> nn >> rr;
	if(nn >= 10)
	{
		cout << rr << endl;
	}
	else
	{
		cout << rr + 100 * (10 - nn) << endl;
	}
	return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,cnt=0;
    cin>>n>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%n==0)
        {
            cnt=1;
            break;
        }
    }
    if(cnt==1)
    cout<<"OK\n";
    else
        cout<<"NG\n";
}


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

int main(){
    string b,ans="";
    cin >> b;
    for(int i = 0;i < b.size();i ++){
        if(b[i]=='A') ans += 'T';
        else if(b[i]=='T') ans += 'A';
        else if(b[i]=='G') ans += 'C';
        else if(b[i]=='C') ans += 'G';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
void my_push(int);
int my_pop(void);
 
  int count=0;
  int stack[100];
 
int main(void){
 
  int x;
  int a,b;
  char s[100];
 
  while(1){
    if(scanf("%s", s) == EOF)
      break;
    
    if ( s[0] == '+' ){
      a = my_pop();
      b = my_pop();
      my_push(b + a);
    }
    else if ( s[0] == '-' ){
      a = my_pop();
      b = my_pop();
      my_push(b - a);
    }
    else if ( s[0] == '*' ){
      a = my_pop();
      b = my_pop();
      my_push(b * a);
    }
    else {
      x = atoi(s);
      my_push(x);
    }
  }
  printf("%d\n",stack[0]);
  return 0;
}

void my_push(int x){
  
  stack[count++] = x;  
}

int my_pop(void){
  
  return stack[--count];
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
vt<ll> v;
int n;
tuple<ll,int> area_max(){
  int index = 0; ll max_v = -LLINF;
  rep(i,n){
    if(v[i] >= max_v){
      index = i;
      max_v = v[i];
    }
  }
  return tuple<ll,int>{max_v,index};
}
tuple<ll,int> area_min(){
  int index = 0; ll min_v = LLINF;
  rep(i,n){
    if(v[i] <= min_v){
      index = i;
      min_v = v[i];
    }
  }
  return tuple<ll,int>{min_v,index};
}
vector<tii> ans;
int main(){
  cin >> n;
  rep(i,n) {ll in;cin >> in; v.pb(in);}
  int a,b; ll minv,maxv;
  tie(maxv,a) = area_max();
  tie(minv,b) = area_min();
  //絶対値の大きい方を採用する
  if(llabs(maxv) > llabs(minv)){
    rep(i,n){
      ll add; int index;
      tie(add,index) = area_max();
      ans.pb(tii{index,i});
      v[i] += add;
    }
  }else{
    rep(i,n){
      ll add; int index;
      tie(add,index) = area_min();
      ans.pb(tii{index,i});
      v[i] += add;
    }
  }
  if(v[0] > 0){
  for(int i = 0; i < n-1; i++){
    if(v[i+1] - v[i] > 0) continue;
    ll add; int in;
    tie(add,in) = area_max();
    ans.pb(tii{in,i+1});
    v[i+1] += add;
  }
  }else{
  for(int i = n-1; i > 0; i--){
    if(v[i] - v[i-1] > 0) continue;
    ll add; int in;
    tie(add,in) = area_min();
    ans.pb(tii{in,i-1});
    v[i-1] += add;
  }
  }
  cout << ans.size() << endl;
  for(auto i: ans){
    int a,b; tie(a,b) = i;
    cout <<a+1 << " " << b+1 << endl;
  }
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

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

    ll ans = 0;
    for (ll i = K; i <= N + 1; ++i) {
        ll M = (i * (2 * N - i + 1) / 2);
        ll m = (i * (i - 1) /2);
        ans += M - m + 1;
        ans %= mod;
    }
    cout << ans << endl;
}

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

const int N = 100005, M = 200005, inf = 1000000000;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, m, fa[N], val[N], d[N], e[M];
vector<pair<int, int> > g[N];
bool flag = true;

int findroot (int u) {
	if (fa[u] == u) return u;
	int r = findroot(fa[u]);
	val[u] ^= val[fa[u]], fa[u] = r;
	return r;
}
bool merge (int u, int v) {
	int ru = findroot(u), rv = findroot(v);
	if (ru == rv) return false;
	fa[ru] = rv, val[ru] = val[u] ^ val[v] ^ 1;
	return true;
}
int main () {
	read(n), read(m);
	for (int i = 1; i <= n; i++) read(d[i]);
	for (int i = 1; i <= m; i++) {
		int u, v;
		read(u), read(v), e[i] = inf;
		g[u].push_back(make_pair(i, v));
		g[v].push_back(make_pair(i, u));
	}

	for (int i = 1; i <= n; i++) fa[i] = i, val[i] = 0;
	for (int i = 1; i <= n; i++) {
		bool tmp = false;
		pair<int, int> pos;
		for (int j = 0; j < g[i].size(); j++) {
			if (d[g[i][j].second] <= d[i]) {
				tmp = true;
				if (!pos.first || make_pair(d[g[i][j].second], g[i][j].second) < make_pair(d[pos.second], pos.second)) pos = g[i][j];
			}
		}
		if (!tmp) flag = false;
		if (merge(i, pos.second)) {
			e[pos.first] = d[i];
			findroot(i), findroot(pos.second);
		}
	}

	if (flag) {
		for (int i = 1; i <= n; i++) findroot(i), putchar(val[i] ? 'B' : 'W');
		putchar('\n');
		for (int i = 1; i <= m; i++) write(e[i]), putchar('\n');
	}
	else puts("-1");
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n,k;
    cin>>n>>k;
    long long w[n],p[n];
    for(int i=0;i<n;i++){
        cin>>w[i];
        cin>>p[i];
    }
    long long dp[n][k+1]{0};
    for(long long i=1;i<=k;i++)
        if(w[n-1]<=i)
            dp[n-1][i] = p[n-1];
    for(long long i=n-2;i>=0;i--){
        for(long long j=1;j<=k;j++){
            long long p1=0,p2=0;
            if(w[i]<=j)
                p1 = p[i]+dp[i+1][j-w[i]];
            p2 = dp[i+1][j];
            dp[i][j] = max(p1,p2);
            //cout<<dp[i][j]<<"\n";
        }
    }
//    for(int i=n-1;i>=0;i--){
//        for(int j=1;j<=k;j++)
//            cout<<dp[i][k]<<" ";
//    }
    cout<<dp[0][k]<<"\n";
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
ll const MAX = 30;
ll const DAYS = 3650;

int main() {
  vector<ll> dp(MAX+1, 0);
  dp[0] = 1;

  repI(i, 1, MAX+1) {
    dp[i] += dp[i-1];
    if (i > 1) dp[i] += dp[i-2];
    if (i > 2) dp[i] += dp[i-3];
  }
  ll n;

  while(cin >> n && n) {
    cout << dp[n] / DAYS + (dp[n] % DAYS != 0) << endl;;

  }
  return 0;
}



Measured memory_bytes: 2980
n,m=map(int,input().split())
l=[]
for i in range(m):
    a=list(input().split())
    a.append(i)
    l.append(a)

l.sort(key=lambda x:(x[0],x[2]))

f=""
q=""
a=0
w=0

for i in range(m):
    if l[i][0] != f:
        ww=0
    if l[i][1] == "AC":
        if l[i][0] != q:
            a+=1
            w+=ww
            q=l[i][0]
    else:
        ww+=1
    
    f=l[i][0]

print(a,w)

Measured memory_bytes: 37016