akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    def segfunc(a, b):
        if b == 0:
            return a
        else:
            return segfunc(b, a % b)

    def init(arr):
        # 0-index/上段の分ズラす
        for i in range(n):
            seg[i+num-1]=arr[i]
        # 上段の分を右から埋めていく
        for i in range(num-2,-1,-1) :
            seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
        
    def update(k,x):
        # 元の配列のindex→seg木上のindex
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
        
    def query(p,q):
        # 不当な区間
        if q<=p:
            return ide_ele
        p += num-1
        q += num-2
        res=ide_ele
        # 最下段から区間を見て更新していく
        # 見ている区間が覆う区間はその時点で見る必要はなく
        # 半分しか覆っていない区間は更新する
        # 上段に上がる際に区間外が混ざらないようにする
        while q-p>1:
            if p&1 == 0:
                res = segfunc(res,seg[p])
            if q&1 == 1:
                res = segfunc(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = segfunc(res,seg[p])
        else:
            res = segfunc(segfunc(res,seg[p]),seg[q])
        return res

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

    # 単位元
    ide_ele = 0

    # num:n以上の最小の2のべき乗
    # n:5~8のときnum=8なので3が入ってほしいから-1
    num =2**((n-1).bit_length())

    # セグ木初期化
    seg=[ide_ele]*2*num
    init(A)

    res = 0
    for i in range(n):
        res = max(res, segfunc(query(0, i), query(i+1, n)))
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 101280
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    int N;
    cin >> N;
    int a[N];
    int num = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] % 2 == 1) {
            num++;
        }
    }
    if (num % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    Vi a(n);
    rp(i,n) cin >> a[i];
    ll sum=0;
    rp(i,n){
        if(i&1) sum-=a[i];
        else sum+=a[i];
    }
    rp(i,n){
        princ(sum);
        sum=-sum;
        sum+=a[i]*2;
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3960
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(m);
    REP(i,m) cin >> s[i];
    int ans = 0, mi = 0, x = 0;
    REP(j,n){
        REP(i,m){
            if (s[i][j] == 'W') x--;
            else x++;
        }
        if (x < mi){
            mi = x;
            ans = j+1;
        }
    }

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

    return 0;
}

Measured memory_bytes: 4472
#include <bits/stdc++.h>
#define N 500020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int ins[N];
int p[N], q[N];
int to[N<<1], nxt[N<<1], head[N], cnt;
void insert(int x, int y) {
  // printf("%d(%d) --> %d(%d)\n", x, q[x], y, q[y]);
  ++ ins[x];
  to[++ cnt] = x;
  nxt[cnt] = head[y];
  head[y] = cnt;
}

// 单点加，查询区间max
namespace sgt {
  int mx[N<<2];
  void update(int x, int k, int L, int R, int v) {
    if (L == R) {
      mx[x] = max(mx[x], v);
      return;
    }
    int mid = L + R >> 1;
    if (k <= mid) update(x << 1, k, L, mid, v);
    else update(x<<1|1, k, mid + 1, R, v);
    mx[x] = max(mx[x << 1], mx[x<<1|1]);
  }
  int query(int x, int l, int r, int L, int R) {
    if (l > r) return 0;
    if (l == L && r == R)
      return mx[x];
    int mid = L + R >> 1;
    if (r <= mid) return query(x << 1, l, r, L, mid);
    else if (l > mid) return query(x<<1|1, l, r, mid + 1, R);
    return max(query(x << 1, l, mid, L, mid), query(x<<1|1, mid + 1, r, mid + 1, R));
  }
}

typedef pair<int, int> pii;
priority_queue<pii, vector<pii>, greater<pii>> que;

int main(int argc, char const *argv[]) {
  int n = read(), k = read();
  for (int i = 1; i <= n; ++ i) {
    q[p[i] = read()] = i;
  }
  // for (int i = 1; i <= n; ++ i) {
  //   printf("%d ", q[i]);
  // } puts("");
  for (int i = 1; i <= n; ++ i) {
    // int ql = max(1, q[i] - k + 1);
    int ql = q[i] + 1;
    int qr = min(n, q[i] + k - 1);
    int mn = sgt::query(1, ql, qr, 1, n);
    if (mn) {
      insert(i, mn);
    }
    sgt::update(1, q[i], 1, n, i);
  }
  for (int i = 1; i <= n; ++ i) {
    if (!ins[i]) {
      que.push({ q[i], i });
    }
  }
  vector<int> res;
  while (!que.empty()) {
    int x = que.top().second;
    que.pop();
    for (int i = head[x]; i; i = nxt[i]) {
      if (!-- ins[to[i]]) {
        que.push({ q[to[i]], to[i] });
      }
    }
    res.push_back(x);
  }
  // for (int i = 0; i < n; ++ i) {
  //   printf("%d\n", q[res[i]]);
  // } puts("====");
  for (size_t i = 0; i < res.size(); ++ i) {
    p[q[res[i]]] = i + 1;
  }
  for (int i = 1; i <= n; ++ i) {
    printf("%d\n", p[i]);
  }
  return 0;
}
/*
先求原序列的逆序q（q[p[i]]=i）

发现原序列中的操作在逆序中即为交换两个相邻的差值>=k的元素。

不难发现逆序中的最小字典序即为原序列的最小字典序。（猜的

发现所有差值<k的元素的相对位置不会发生变化。

例如第 3 个样例，逆序为

6 7 5 1 2 8 3 4
+
^-+
^-^-+
      +
      ^-+
^-^-------+
    ^-^-^---+
^---^---^---^-+

（图为每个点不能越过的元素的限制）

直接求拓扑序即可。

但是直接做是 n^2 的，于是只要将每个点与前面最后一个限制连线即可。

6 7 5 1 2 8 3 4
+
^-+
  ^-+
      +
      ^-+
  ^-------+
    ^-------+
^-------------+

总复杂度 O(nlogn)
*/

Measured memory_bytes: 30960
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>











ll n;



void solve()
{
	cin>>n;
	for(ll i=1;;i++)
	{
		if(i*i>n)
		{
			cout<<(i-1)*(i-1)<<"\n";
			return;
		}
	}
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

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

using namespace std;

using ll = long long;

int main()
{
    ll n, k;
    cin >> n >> k;
    n = n%k;
    ll ans = min(n, abs(n - k));
    cout << ans << endl;
    return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;


VI v[12];


int main() {

	int n;
	cin >> n;

	vector<pair<string, pair<int, int>>> v;

	REP(i, n) {
		string s;
		int a;
		cin >> s >> a;
		v.push_back({ s,{100 - a,i + 1} });
	}
	sort(ALL(v));

	REP(i, n) {
		cout << v[i].second.second << endl;
	}

}

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

using namespace std;

const int N=2e5+50;
typedef long long ll; 

ll n;
ll k;
ll a[N],b[N];//b[N]为模拟一个循环数组 
map<ll,ll> mp;//用于查找循环节 

int main()
{
//	freopen("input.txt","r",stdin);
	
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	ll loc=1;//loc为当前国王所处位置
	b[1]=1; 
	for(ll i=1;i<=n+10;i++)//寻找r 
	{
		loc=a[loc];
		b[i+1]=loc;
	 }
 	ll pre,l,r;//pre为前缀，l、r为第一个循环节的左右下标
 	for(ll i=1;i<=n+10;i++)//确认r的位置 
 	{
 		mp[b[i]]++;
 		if(mp[b[i]]>1) 
 		{
 			r=i-1;
 			break;
		 }
	}
	for(ll i=1;i<=n+10;i++)
	{
		if(b[i]==b[r+1]) 
		{
			l=i;
			break;
		}
	 } 
//	for(ll i=1;i<=n+10;i++) cout<<b[i]<<" "<<endl;
	pre=l-1;
	ll c=r-l+1;
	if(k<=pre-1) cout<<b[k+1];
	else 
	{
		k-=pre;
		k%=c;
		cout<<b[l+k];
	}

	
	return 0;
}

Measured memory_bytes: 18724
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

s = input().rstrip()

li = ['0'] * len(s)
for i in range(len(s)):
    li[i] = s[i]

ans = 0
for i in range(1, len(s)):
    if li[i-1] != li[i]:
        continue
    else:
        if li[i] == '1':
            li[i] = '0'
        else:
            li[i] = '1'
        ans += 1
print(ans)


Measured memory_bytes: 70772
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BAcCepted solver = new BAcCepted();
        solver.solve(1, in, out);
        out.close();
    }

    static class BAcCepted {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            out.println(s.chars().filter(Character::isUpperCase).count() == 2
                    && s.substring(2, s.length() - 1).chars().anyMatch(c -> c == 'C')
                    && s.charAt(0) == 'A' ? "AC" : "WA");
        }

    }
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % MOD, N / 2);
  else return Pow(A * A % MOD, N / 2) * A % MOD;
}

ll N, K;
ll DP[int(1e5+5)];

int main(){
  N = 3;
  cin >> K;
  for (ll i = K; i >= 1; i--){
    DP[i] = Pow(K / i, N);

    ll sum = 0;
    for (ll j = 2 * i; j <= K; j += i){
      sum += DP[j]; sum %= MOD;
    }
    DP[i] -= sum; DP[i] %= MOD;
    if (DP[i] < 0) DP[i] += MOD;
  }

  ll ans = 0;
  for (ll i = 1; i <= K; i++){
    ans += i * DP[i]; ans %= MOD; 
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int N;

multimap<int, int> m;

int main() {
    cin >> N;
    REP (i, N) {
        int A, B;
        cin >> A >> B;
        m.insert(MP(B, A));
    }
    LL t = 0;
    for (auto& itr : m) {
        t += itr.second;
        if (t > itr.first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 9600
#include<cstdio>
#include<map>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
  ll en=1e9;
  ll n,t;
  cin>>n>>t;
  int sum=0;
  string s;
  bool h=true;
  cin>>s;
  rep(i,s.size())if(isdigit(s[i])){
    ll a=s[i]-'0';
    ll w=1;
    rep(j,a){
      w*=n;
      if(w>en){
	h=false;
	break;
      }
    }
    sum+=w;
    if(sum>en){
      h=false;
    }
    if(!h)break;
  }
  if(sum*t>en)h=false;
  if(!h)cout<<"TLE"<<endl;
  else cout<<sum*t<<endl;
}

Measured memory_bytes: 1200
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  string s;
  cin >> s;
  int sum;
  for(int i=0; i<8; i++){
    sum = s[0] - '0';
    for(int j=0; j<3; j++){
      if(i & 1<<j){
        sum -= s[j+1] - '0';
      }else{
        sum += s[j+1] - '0';
      }
    }
    if(sum == 7){
      string ans = "";
      ans += to_string(s[0] - '0');
      ans += (i & 1 ? "-" : "+");
      ans += to_string(s[1] - '0');
      ans += (i & 1<<1 ? "-" : "+");
      ans += to_string(s[2] - '0');
      ans += (i & 1<<2 ? "-" : "+");
      ans += to_string(s[3] - '0');
      ans += "=7";
      cout << ans << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var w = Console.ReadLine().Split().Select(x => int.Parse(x.ToString())).First();
            for (int i = 0; i < s.Length; i++)
            {
                if ((i + w) % w == 0)
                {
                    Console.Write(s[i]);
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 11220
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline ll getK() {
	ll A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll A[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	ll N = getint(), K =getK();
	rep(i, N) {
		int a = getint();
		A[a] += getint();
	}

	ll kazu = 0;
	int kotae = 1;
	for (; kotae <= 100000; kotae++) {
		kazu += A[kotae];
		if (kazu >= K) break;
	}

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

int main() {
    int val[1001], W, N, v, w, caseNo = 1;
    char c;
    while (cin >> W, W) {
        memset(val, -1, sizeof val);
        val[0] = 0;
        cin >> N;
        for (int i=0; i<N; ++i) {
            cin >> v >> c >> w;
            for (int j=W; j>=0; --j) {
                if (0 <= val[j] && j + w <= W) {
                    val[j + w] = max(val[j + w], val[j] + v);
                }
            }
        }
        int maxv = 0, maxw = 0;
        for (int i=0; i<=W; ++i) {
            if (maxv < val[i]) {
                maxv = val[i];
                maxw = i;
            }
        }
        cout << "Case " << caseNo << ":" << endl;
        cout << maxv << endl;
        cout << maxw << endl;
        ++ caseNo;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#define WHITE 0
#define GRAY 1 
#define BLACK 2
typedef struct{
    int u;
    int k;
    int a[100];
    int color;
    int d;
    int f;
}rist;

void dfs(void);
void visit(int);
int n,time;
rist G[100];
int main(){
    int i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&G[i].u,&G[i].k);
        for(j=0;j<G[i].k;j++){
            scanf("%d",&G[i].a[j]);
        }
    }

    dfs();

    for(i=0;i<n;i++){
        printf("%d %d %d\n",G[i].u,G[i].d,G[i].f);
    }
    return 0;
}

void dfs(){
    int i;
    for(i=0;i<n;i++){
        G[i].color=WHITE;
    }
    time=0;
    for(i=0;i<n;i++){
        if(G[i].color==WHITE) visit(i);
    }
}

void visit(int u){
    int i,j;
    G[u].color=GRAY;
    G[u].d=++time;
    for(i=0;i<G[u].k;i++){
        for(j=0;j<n;j++){
            if(G[u].a[i]==G[j].u) if(G[j].color==WHITE) visit(j);
        }
    }
    G[u].color=BLACK;
    G[u].f=++time;
}


Measured memory_bytes: 2040
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
string s;
ll dp[100005][15];
int n;
int main(){
	cin >> s; n = s.size();
	dp[0][0] = 1;
	rep(i,n){
		rep(j,13){
			if(s[i] != '?') dp[i+1][(j*10+s[i]-'0')%13] += dp[i][j];
			else rep(x,10) dp[i+1][(j*10+x)%13] += dp[i][j];
		}
		rep(j,13) dp[i+1][j]%=mod;
	}
	cout << (dp[n][5]%mod+mod)%mod << endl;
}

Measured memory_bytes: 12160
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= min(b, a + k - 1); ++i) cout << i << endl;
	for (int i = max(b - k + 1, a + k); i <= b; i++) cout << i << endl;

	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

void solve(int x1,int y1,int x2,int y2){
    rep(i,0,y2-y1)cout<<"U";
    rep(i,0,x2-x1)cout<<"R";
    rep(i,0,y2-y1)cout<<"D";
    rep(i,0,x2-x1+1)cout<<"L";
    rep(i,0,y2-y1+1)cout<<"U";
    rep(i,0,x2-x1+1)cout<<"R";
    cout<<"D";
    cout<<"R";
    rep(i,0,y2-y1+1)cout<<"D";
    rep(i,0,x2-x1+1)cout<<"L";
    cout<<"U"<<endl;
}

int main(){
    
    int sx,sy,tx,ty;
    
    cin>>sx>>sy>>tx>>ty;
    solve(sx,sy,tx,ty);    
    
    return 0;
}
 

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string S, T;
	cin >> S >> T;

	string ans;
	T.pop_back();
	if (S == T) ans = "Yes";
	else ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner (System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int [] d = new int [n];
		int i, j;
		int temp;
		int calorie;
		int max = 0;

		for (i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}

		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				if (d[i] < d[j]) {
					temp = d[i];
					d[i] = d[j];
					d[j] = temp;
				}
			}
		}

		for (i = 0; i < n; i++) {
			int sum = 0;
			for (j = 0; j < i; j++) {
				sum += d[j];
				calorie = (c + sum) / (a + i * b);
				if (max < calorie) {
					max = calorie;
				}
			}
		}
		
		System.out.println(max);

	}

}

Measured memory_bytes: 18212
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 10;
int A[maxn];
int B[maxn];
int n, m, k;
signed main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		cin >> A[i];
		A[i] += A[i - 1];
	}
	for (int i = 1; i <= m; i++) {
		cin >> B[i];
		B[i] += B[i - 1];
	}
	int ans = -1;
	for (int i = 0; i <= n; i++) {
		int left = k - A[i];
		if (left < 0) continue;

		int pos = upper_bound(B, B + m + 1, left) - B - 1;
		ans = max(ans, pos + i);
	}
	cout << ans << endl;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M> class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept
      : a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
// }}}
// {{{ Decompose Prime
std::map<ll, ll> decomposePrime(ll n) {
  std::map<ll, ll> m;
  ll x = 2;
  while (x * x <= n) {
    if (n % x == 0) {
      m[x]++;
      n /= x;
    } else {
      x++;
    }
  }
  if (n > 1)
    m[n]++;
  return m;
}
// }}}

ll mpow(ll x, ll y, ll m) {
  if (y == 0)
    return 1;
  else if (y % 2 == 1)
    return x * mpow(x, y - 1, m) % m;
  else
    return mpow(x * x % m, y / 2, m) % m;
}

const ll M = 1000000007;
using mint = modint<1000000007>;
vector<ll> nPrimes(1000001, 0); // {prime -> # of the prime}, LCM

signed main() {
#if 1
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) { cin >> a[i]; }
#else
  ll N = 10000;
  vector<ll> a(N);
  rep(i, N) { a[i] = i * 100; }
#endif
  rep(i, N) {
    auto m = decomposePrime(a[i]);
    for (auto e : m) {
      chmax(nPrimes[e.first], e.second);
    }
  }

  mint L(1);
  rep(i, nPrimes.size()) { L *= mint(mpow(i, nPrimes[i], M)); }

  mint ans(0);
  rep(i, N) {
    mint t = L / mint(a[i]);
    ans += t;
  }
  cout << ans.value() << endl;
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
struct Istream {
	template <class T> 
	Istream &operator >>(T &x) {
		static char ch;static bool neg;
		for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
		for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
		x=neg?-x:x;
		return *this;
	}
	template <class T>
	operator T() {
		static T x;
		*this>>x;
		return x;
	}
}is;
struct Ostream {
	template <class T>
	Ostream &operator <<(T x) {
		x<0 && (putchar('-'),x=-x);
		static char stack[233];static int top;
		for(top=0;x;stack[++top]=x%10+'0',x/=10);
		for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
		return *this;
	}
	Ostream &operator <<(char ch) {
		putchar(ch);
		return *this;
	}
}os;
const int MAXN=2e5+11;
template <class T> inline bool Tension(T &a,T const &b) { return a>b?a=b,1:0; }
template <class T> inline T abs(T const &x) { return x<0?-x:x; }
int main() {
	int n=is;
	static long long preSum[MAXN];
	for(int i=1;i<=n;++i) {
		preSum[i]=preSum[i-1]+(int)is;
	}
	long long Ans=LLONG_MAX;
	for(int i=1;i<=n-1;++i) {
		Tension(Ans,abs(2*preSum[i]-preSum[n]));
	}
	os<<Ans<<'\n';
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	ll T;
	cin >> T;
	vector<ll> t(N);
	REP(i, N) cin >> t[i];
	ll sum = T;
	REP(i, N - 1) {
		sum += min(T, t[i + 1] - t[i]);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
    static void Main(string[] args)
    {
        // 入力
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int X = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');

        // Xも含めて、座標をリスト化する
        List<int> list = new List<int>() { X };
        for(int i=0; i<N; i++)
        {
            list.Add(int.Parse(input[i]));
        }

        list.Sort();

        // 各座標間の距離
        List<int> gcdList = new List<int>();
        for(int i=1; i<list.Count; i++)
        {
            int dis = list[i] - list[i - 1];
            gcdList.Add(dis);
        }

        // gcdリスト全ての数の最大公約数を求める
        int gcd = gcdList[0];
        for (int i = 1; i < gcdList.Count; i++ )
        {
            gcd = calculationGCD(gcd, gcdList[i]);
        }

        Console.WriteLine(gcd);
        //if (ret)
        //    Console.WriteLine("Yes");
        //else
        //    Console.WriteLine("No");
    }

    static int calculationGCD(int a, int b)
    {
        if(a%b == 0)
        {
            return b;
        }
        else
        {
            return calculationGCD(b, a % b);
        }
    }

}

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

int h, w;
char s[101][101];

int dp[101][101];
const int INF = 1e9;

int rec(int r, int c) {
    int &res = dp[r][c];
    if (res != -1) return res;
    if (r == h - 1 && c == w - 1) res = 0;
    else {
        res = INF;
        if (r + 1 < h) {
            int tmp = rec(r + 1, c);
            if (s[r][c] == '.' && s[r + 1][c] == '#') ++tmp;
            res = min(res, tmp);
        }
        if (c + 1 < w) {
            int tmp = rec(r, c + 1);
            if (s[r][c] == '.' && s[r][c + 1] == '#') ++tmp;
            res = min(res, tmp);
        }
    }
    return res;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) cin >> s[i];
    memset(dp, -1, sizeof dp);
    int ans = rec(0, 0) + (int)(s[0][0] == '#');
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int n;
  while(scanf("%d",&n)!=EOF)
    printf("3C%02d\n",(n-1)%39+1);
}

Measured memory_bytes: 3140
n = int(input())
s_list = []
for _ in range(n):
    s_list.append(''.join(sorted(input())))

s_list = sorted(s_list)

count = 0
total = 0
s_prev = s_list[0]
for s in s_list[1:]:
    if s_prev == s:
        count += 1
    else:
        if count > 0:
            total += count * (count + 1) // 2
            count = 0
    s_prev = s

if count > 0:
    total += count * (count + 1) // 2

print(total)

Measured memory_bytes: 11408
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>

using namespace std;

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


int main(){

  ios_base::sync_with_stdio(false);

  int N = 0;
  cin>>N;

  int a = floor(N/15);
  int ret = N*800-a*200;
  cout<<ret<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<double> a(n);for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
    a[i]=1/a[i];
  }
  double sum=0;
  for(int i=0;i<n;i++)sum+=a[i];
  cout<<1/sum<<endl;
}


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

using namespace std;

long MOD = 1000000007;

class Edge{
public:
  int from, to, cost;
};

vector < vector < Edge > > edge;
vector <bool> visited;
int deep_cost=0, deep_index=0;
vector < int > diameter_path;

void dfs(int now, int d, vector<int> path){
  if(d>deep_cost){
    deep_cost=d;
    deep_index=now;
    diameter_path=path;
  }
  for(int i=0; i<edge[now].size(); i++){
    if(!visited[edge[now][i].to]){
      visited[edge[now][i].to]=true;
      //cout<<now<<" -> "<<edge[now][i].to<<endl;//
      path.push_back(edge[now][i].to);
      dfs(edge[now][i].to, d+edge[now][i].cost, path);
    }
  }
}

vector<long> v;
vector<long> c;
long sum = 0;
long cnt = 0;
void dfs2(int now){
    for(int i=0; i<edge[now].size(); i++){
        if(!visited[edge[now][i].to]){
            visited[edge[now][i].to]=true;
            v[edge[now][i].to] = c[cnt];
            sum += c[cnt++];
            dfs2(edge[now][i].to);
        }
    }
}



int main(){
    long N;
    long from, to;
    vector < int > p;

    cin>>N;//点数, 枝数
    edge.resize(N);
    for(int i=0; i<N-1; i++){
        cin>>from>>to;
        //入力される値の範囲, 添字と同じ？
        edge[from-1].push_back((Edge){from-1, to-1, 1});
        edge[to-1].push_back((Edge){to-1, from-1, 1});//無向
    }

    c.resize(N);
    for(int i=0; i<N; i++){
        cin>>c[i];
    }
    sort(c.begin(), c.end(), greater<int>());

    int start=0;
    visited.resize(N);
    for(int i=0; i<N; i++){
        visited[i]=false;
    }
    visited[start]=true;
    p.push_back(start);
    dfs(start, 0, p);

    int a=deep_cost; //deep_index;
    for(int i=0; i<N; i++){
        visited[i]=false;
    }
    visited[deep_index]=true;
    p.clear();
    p.push_back(deep_index);
    diameter_path.clear();
    deep_cost=0;
    dfs(deep_index, 0, p);


    v.resize(N);
    for(int i=0; i<N; i++){
        visited[i]=false;
        v[i] = 0;
    }
    start = diameter_path[0];
    visited[start]=true;
    v[start] = c[cnt];
    cnt++;
    dfs2(start);

    cout<<sum<<endl;
    for(int i=0; i<N; i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;


    return 0;
}

Measured memory_bytes: 441440
#include <stdio.h>

int main (void)
{
  int n , max =0 , ans = 0;
  scanf("%d",&n);
  char s[100];
  scanf("%s",s);
  
  for(int i = 0; i < n; i ++){
    if(s[i]=='I'){
      ans++;
      if(max<ans){
        max = ans;
      }}
    if(s[i]=='D'){  
        ans--;
    }}
  printf("%d",max);
  
  return 0;
}
      

Measured memory_bytes: 128
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
B = sorted([[A[i][0]-A[i][1],A[i][0]+A[i][1]] for i in range(N)],key=lambda x:x[1])
cur = 1
C = [B[0]]
while cur<N:
    if B[cur][0]>=C[-1][1]:
        C.append(B[cur])
    cur += 1
print(len(C))

Measured memory_bytes: 80984
def solve():
  N = int(input())
  S = input()
  stones = []
  look = S[0]
  cnt = 0

  if S[0] == '.': stones.append(0)
  for s in S:
    if look == s: cnt += 1
    else:
      stones.append(cnt)
      cnt = 1
      look = s
  stones.append(cnt)
  if S[N - 1] == '#': stones.append(0)

  count = sum(stones[1::2])
  ans = count

  for i in range(0, len(stones), 2):
    count = count + stones[i] - stones[i + 1]
    if ans > count: ans = count
  return ans

print(solve())


Measured memory_bytes: 5864
from collections import defaultdict
U = 10 ** 5
root = [None] * (2*U+1)
N = int(input())
XY = [[int(x) for x in input().split()] for _ in range(N)]

def find_root(x):
  y = root[x]
  if y is None:
    root[x] = x
    return x
  if x == y:
    return y
  z = find_root(y)
  root[x] = z
  return z

def merge(x,y):
  rx = find_root(x)
  ry = find_root(y)
  if rx == ry:
    return
  root[ry] = rx
  return

for x,y in XY:
  merge(x,U+y)

pts_cnt = defaultdict(int)
x_cnt = defaultdict(int)
y_cnt = defaultdict(int)

for x in range(U+1):
  if root[x] is None:
    continue
  x_cnt[find_root(x)] += 1

for y in range(U+1,U+U+1):
  if root[y] is None:
    continue
  y_cnt[find_root(y)] += 1

for x,y in XY:
  pts_cnt[find_root(x)] += 1

answer = 0
for k,v in pts_cnt.items():
  answer += x_cnt[k] * y_cnt[k] - v

print(answer)

Measured memory_bytes: 25060
import numpy as np
H, W = map(int, input().split())
grid = np.array([list(input()) for _ in range(H)])
grid_1 = grid[~np.all(grid == '.', axis = 1), :]
grid_2 = grid_1[:, ~np.all(grid == '.', axis = 0)]
for i in range(grid_2.shape[0]):
    print(''.join(grid_2[i]))

Measured memory_bytes: 12552
import java.util.*;
public class Main {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
	       String[] ary = sc.nextLine().split("[ ,\\.]");
	       int i=0,j;
	       for(String o : ary) {
		   j=o.length();
		   if(j>2&&j<7){
		   if(i==0)
		       i=1;
		   else
		       System.out.print(" ");
		   System.out.print(o);
		   }
	       }
	       System.out.println();
   }
}

Measured memory_bytes: 0
N, K = map(int, input().split())
S = list(input())

flag = True
for i in range(1, N):
    if K != 0:
        if flag:
            if S[i-1] != S[i]:
                flag = False
        if not flag:
            S[i] = 'L' if S[i] == 'R' else 'R'
            if i < N - 1:
                if S[i] == S[i+1]:
                    flag = True
                    K -= 1

ans = 0
if N > 1:
    if S[0] == 'R' and S[1] == 'R':
        ans += 1
    for i in range(1, N - 1):
        if S[i] == 'R' and S[i + 1] == 'R':
            ans += 1
        elif S[i] == 'L' and S[i - 1] == 'L':
            ans += 1
    if S[-1] == 'L' and S[-2] == 'L':
        ans += 1

print(ans)


Measured memory_bytes: 4084
def binarySearch(numList, key):
    right = len(A)
    left = 0
    
    while left < right:
        mid = (right + left) // 2
        
        if A[mid] == key:
            return True
        elif A[mid] > key:
            right = mid
        else:
            left = mid + 1
    return False
    
sum = 0
lenA = int(input())
A = list(map(int, input().split())) 
lenB = int(input())
B = list(map(int, input().split())) 
cnt = 0

for i in range(len(B)):
    if binarySearch(A, B[i]):
        cnt += 1
print(cnt)
    


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

const long MAXN=200100;
int n,a[MAXN];
long long ans=0;

int main() {
	cin>>n;register int i;
	for(i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(i=2;i<=n;++i) {
		if(a[i-1]>a[i]) {
			ans+=(long long)a[i-1]-(long long)a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;

	int sz=s.size(), t=0, ten=1;
	map<int,int> mp;
	mp[0]=1;
	for(int i=1; i<=sz; ++i){
		int a=stoi(s.substr(sz-i,1));
		a = a*ten%2019;
		t = (t+a)%2019;
		++mp[t];
		ten = ten*10%2019;
	}

	int ans=0;
	for(auto i: mp){
		ans += i.second*(i.second-1)/2;
	}
	
	cout << ans << endl;
}

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

int main(void)
{
 
  ll a, b, r, x, tmp;
  cin >> a;
  cin >> b;
 
  x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最小公倍数を出力 */
  cout << x/b;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long a,b;
    cin >> a >> b;
    long long ans;

    int max_pq=max(a,b);
    int min_pq=min(a,b);
    int amari,sho;

   while(max_pq%min_pq!=0){
       sho = max_pq / min_pq;
       amari = max_pq % min_pq;
       if(amari==0){
           break;
       }else{
           max_pq = max(amari,min_pq);
           min_pq = min(amari,min_pq);
       }
   }

    ans = a * b / min_pq;
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

a = input()
komoji = [chr(i) for i in range(97, 97+26)]
if  a in komoji:
    print("a")
else:
    print("A")

Measured memory_bytes: 9112
#include <numeric>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; for (auto& e : a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; for (auto& e : a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; for (auto& r : a) { for (auto& e : r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; for (auto& e : a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

#define forn(a, e) for (int a = 0; a < (int)e; a++)
#define forr(a, s, e) for (int a = s; a < (int)e; a++)

using i64 = long long;

template<typename T>
using Pair = array<T, 2>;

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

    string s;
    while (cin >> s) {
        vector<vector<int>> dp(s.size() + 1, vector<int>(3, -1));
        int n = s.size();
        dp[0][0] = 1;
        for (int i = 1; i < n; i++) {
            if (dp[i - 1][0] != -1) {
                if (s[i] != s[i - 1]) {
                    dp[i][0] = max(dp[i - 1][0] + 1, dp[i][0]);
                } else {
                    dp[i + 1][1] = max(dp[i - 1][0] + 1, dp[i + 1][1]);
                }
                dp[i][1] = max(dp[i][1], dp[i - 1][0]);
            }
            if (dp[i - 1][1] != -1) {
                dp[i][2] = max(dp[i][2], dp[i - 1][1] + 1);
            }
            if (dp[i - 1][2] != -1) {
                if (s.substr(i - 3, 2) != s.substr(i - 1, 2)) {
                    dp[i][1] = max(dp[i][1], dp[i - 1][2]);
                }
                if (s[i - 1] != s[i]) {
                    dp[i][0] = max(dp[i - 1][2] + 1, dp[i][0]);
                } else {
                    dp[i + 1][1] = max(dp[i - 1][2] + 1, dp[i + 1][1]);
                }
            }
        }
        logvv(dp);
        cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    }
}


Measured memory_bytes: 11412
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int min = 1000000010;
		int ans = 0;
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			if(min>b[i]){
				ans = a[i] + b[i];
				min = b[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 66420
/*input
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

struct x
{
	map<char, ll> freq;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    ll ans = 0;
    string s; cin >> s;
    vector<x> suf(n);
    suf[n - 1].freq[s[n - 1]]++;
    for(int i = n - 2; i > -1; i--)
    {
    	suf[i].freq['R'] = suf[i + 1].freq['R'] + (s[i] == 'R');
    	suf[i].freq['G'] = suf[i + 1].freq['G'] + (s[i] == 'G');
    	suf[i].freq['B'] = suf[i + 1].freq['B'] + (s[i] == 'B');
    }
    for(int i = 0; i < n; i++) for(int j = i + 1; j < n - 1; j++)
    {
    	if(s[i] == s[j]) continue;
    	char need;
    	if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) need = 'B';
    	else if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) need = 'G';
    	else need = 'R';
    	ans += suf[j + 1].freq[need];
    	if(2 * j - i < n && s[2 * j - i] == need) ans--;
    }
    cout << ans;

    return 0;
}

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

a = list(map(int, input().split()))

min_signs = 0

for num in a:
    if num < 0:
        min_signs += 1

a = list(map(abs, a))

if min_signs % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - 2 * min(a))


Measured memory_bytes: 14332
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


template <class T, class U>
ll euclid_gcd(T a, U b){
    if(a < b)return euclid_gcd(b,a);
    ll r;
    while((r = a%b)){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i]/= 2;
    }
    ll ans = 0;
    ll lcm = 1;
    bool ok = true;
    rep(i,n){
        ll g = euclid_gcd(lcm, a[i]);
        lcm *= a[i] / g;
    }
    rep(i,n){
        ll t = lcm / a[i];
        if(t % 2 == 0)ok = false;
    }
    if(ok){
        ans = m/lcm;
        ans = (ans + 1) / 2;
    }
    
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

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

int main(){

	int n;
	ll a[100];
	a[0] = 2;
	a[1] = 1;
	cin >> n;

	for (int i = 2; i <= n; i++) {
		a[i] = a[i - 1] + a[i - 2];
	}

	cout << a[n] << endl;

	return 0;
}

Measured memory_bytes: 256