akhauriyash/Code-Regression huggingface dataset:
import numpy as np
N = input()
N = int(N)
A = np.hstack([int(a) for a in input().split()])
B = np.hstack([int(a) for a in input().split()])
C = np.hstack([int(a) for a in input().split()])

score = 0
for i in range(N-1):
  score += B[A[i]-1]
  if A[i+1] - A[i] == 1:
    score += C[A[i]-1]

score += B[A[N-1]-1]
print(score)

Measured memory_bytes: 12472
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int n,k,z;
bool vis[100005];
int res[100005];
int a[100005];
  vector<int>v[100005];

int solve(int i)
{
    if(vis[i])
    return res[i];
    else
    {
        vis[i]=true;
        for(auto x:v[i])
        {
            if(solve(x)==0)
            res[i]=1;
        }
    }
    return res[i];
}
int main()
{
  float d,t,s;
  cin>>d>>t>>s;
  float p=d/s;
  if(p<=t)
  cout<<"Yes\n";
  else
  cout<<"No\n";
}

Measured memory_bytes: 6056
#include <bits/stdc++.h>
#define fr(i,a,b) for(int i=a;i<b;i++)
#define ll long long 
#define vec vector<ll int>
#define pb push_back
using namespace std;

int main() 
{
  string str1,str2;
  int count{0};
  cin>>str1;
  cin>>str2;
  fr(i,0,str1.size())
    if(str1[i]==str2[i])
      count+=1;
  if(count==str1.size())
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int boss=1e5;
int n,m,vis[boss+10];
vector<int> lj[boss+10];
int dfs(int u,int fa) {
	if (lj[u].size()>2) return u;
	for (int i:lj[u]) if (i!=fa) return dfs(i,u);
	return u;
}
int main() {
	int i,u,v;
	scanf("%d",&n);
	for (i=1; i<n; i++) {
		scanf("%d%d",&u,&v);
		u++;
		v++;
		lj[u].push_back(v);
		lj[v].push_back(u);
	}
	for (i=1; i<=n; i++) if (lj[i].size()==1) vis[dfs(i,0)]=1,m++;
	for (i=1; i<=n; i++) if (vis[i]) m--;

	printf("%d",max(m,1));
	return 0;
}

Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
#define MAX 161
using namespace std;

bool dp[MAX][MAX][2];
 
int main()
{
  int T;
  while(cin >> T)
    {
      while(T--)
	{
	  rep(i,MAX)rep(j,MAX)rep(l,2)dp[i][j][l] = false;
	  int N;
	  cin >> N;
	  int input[N];
	  rep(i,N) cin >> input[i];
       
	  if(N <= 2)
	    {
	      cout << input[N-1] << endl;
	      continue;
	    }
       
	  int ans = input[N-1];
 
	  REP(cur,1,N-1)
	    {
	      dp[input[cur-1]][input[cur]][cur&1] = true;
	      int R = input[cur+1];
	      rep(L,MAX)
		{
		  rep(M,MAX)
		    {
		      if(!dp[L][M][cur&1])continue;
		      //cout << cur << " cur(" << L << "," << M << "," << R << ")\n";
		      if(M == 0)
			{
			  if(cur+2 < N)
			    {
			      dp[M][R][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";
			    }
			  else       ans = max(ans,R);
			}
		      else
			{
			  if(cur+2 < N)
			    {
			      dp[M][R][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";
			      dp[M-1][R+L][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M-1 << "," << R+L << "," << input[cur+2] << ")\n";
			    }
			  else 
			    {
			      ans = max(ans,R+L);
			      //cout << cur << " ans : " << R << "+" << L << "=" << R+L <<  " (" << L << "," << M << "," << R << ")" <<  endl;
			    }
			}
		    }
		}
	      rep(i,MAX)rep(j,MAX)dp[i][j][cur&1] = false;
	    }
	  
	  cout << ans << endl;      
	}
    }
  return 0;
}

Measured memory_bytes: 1208
use std::collections::HashSet;
use std::iter::FromIterator;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let set:HashSet<char> = HashSet::from_iter(s.chars());
    if set.len() == s.len() {
        println!("yes");
    } else {
        println!("no");
    }
}


Measured memory_bytes: 2188
def search(x, K, Q, A):
    cand = []
    i = 0
    while i < len(A):
        tmp = []
        while i < len(A):
            if A[i] >= x:
                tmp.append(A[i])
                i += 1
            else:
                i += 1
                break
        if len(tmp) >= K:
            tmp.sort()
            L = len(tmp) - K + 1
            cand.extend(tmp[:L])

    if len(cand) < Q:
        return - 1
    else:
        return sorted(cand)[Q-1]


def main():
    N, K, Q = map(int, input().split())
    A = list(map(int, input().split()))

    if Q == 1:
        return 0

    res = 10**18
    for i, x in enumerate(A):
        rest = A[:i] + A[i + 1:]
        y = search(x, K, Q - 1, rest)
        if y == -1:
            continue
        res = min(res, y - x)
    return res


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3316
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc119/tasks/abc119_c
//ポイント：動かすイメージじゃなくて別の場所に作っていくイメージ
//参考：https://atcoder.jp/contests/abc119/tasks/abc119_c

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

int N,A,B,C;
int L[8];

int ans = 0;

//合体させてから伸縮させることを考える

//i: i-1本目までを使うかどうか調べ済み　であることを示す
//a: その時点での A に採用した竹の長さの総和
//b: その時点での B に採用した竹の長さの総和
//c: その時点での C に採用した竹の長さの総和

//A,B,CそれぞれにL[i]を割り振る。使わないL[i]があっても良い。
//この時、割振り方の数は4^N通り
//これら全てに対してabs(目標とするA,B,Cの長さとの差分)を取る　それが伸縮に必要なMPの値となる
int rec(int i, int a, int b, int c) {
    if (i == N) {
    	// A, B, C いずれも竹は 1 本は必ず使ってないとダメ
    	//a,b,cのうちどれかが0 = 一本使ってないやつがあるのでだめ
        if (!a || !b || !c) return INF_INT;
        // 合体してできた a, b, c を A, B, C にするコスト
        //伸縮はここでのみ行う（この関数の他の箇所は全て合体をするための機能になっている）
        return abs(a - A) + abs(b - B) + abs(c - C);
    }
    
    // A, B, C を使う場合。
    // (a ? 10 : 0) とかは、
    //最初の 1 本目は合体コストなし、
    //2 本目からはコスト 10 かかることを意味する

    //Aの材料にL[i]を選定する場合
    int res = rec(i+1, a + L[i], b, c) + (a ? 10 : 0);

    //Bの材料にL[i]を選定する場合
    res = min(res,rec(i+1, a, b + L[i], c) + (b ? 10 : 0));

    //Cの材料にL[i]を選定する場合
    res = min(res,rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));

    //竹L[i]をA,B,Cどれにも採用しない場合
    res = min(res,rec(i+1, a, b, c));
    
    //上記の4パターンのうち最も消費MPが少ないものを返す
    return res;
}

void solve(){
	ans = rec(0, 0, 0, 0);
}
 
int main(){
    cin >> N >> A >> B >> C;
    for(int i=0;i<N;i++) cin >> L[i];
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def ev(n):
    return 0.5*(n+1)


def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p_ev = list(map(ev, p))

    s = np.cumsum(p_ev)
    s = np.insert(s, 0, 0)

    ans = []

    for i in range(n - k+1):
        ans.append(s[i + k] - s[i])

    print(max(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 50460
using System;


class Program
{
    static void Main(string[] args)
    {
        String[] tmp = Console.ReadLine().Split(' ');



        try
        {
            int A = int.Parse(tmp[0]);
            int B = int.Parse(tmp[1]);
            String[] S = Console.ReadLine().Split('-');
            String S_a = S[0];
            String S_b = S[1];
            int check = int.Parse(S_a);
            check = int.Parse(S_b);

            if (S_a.Length == A) Console.WriteLine("Yes");
            else Console.WriteLine("No");

        }
        catch (Exception e)
        {
            Console.WriteLine("No");
        }
        //System.Threading.Thread.Sleep(5000);
    }
}


Measured memory_bytes: 11092
nl=list(map(int,input().split()))
if nl[1]<=0<=nl[1]+nl[0]-1:
    k=(nl[1]+(nl[1]+nl[0]-1))*nl[0]/2
else:
    if abs(nl[1])<abs(nl[1]+nl[0]-1):
        k=(nl[1]+1+(nl[1]+nl[0]-1))*(nl[0]-1)/2
    else:
         k=(nl[1]+(nl[1]+nl[0]-2))*(nl[0]-1)/2
print(int(k))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAXC 100000
int main()
{
	int n;cin>>n;int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int dp[n+1];
	dp[0] = a[0];
	dp[1] = abs(a[1]-a[0]);
	dp[2] = min(dp[1]+a[2], abs(a[2]-a[0]));
	for(int i=3;i<n;i++){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
}

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


int main(){
  ll a,b,k;
  cin >>a>>b>>k;
//高橋くんの分のみで
  int x = 0 ;
  if (a>=k){
    cout <<a-k<<" "<<b<<endl;
    return 0;
  }
  if (a<k){
    if ((k-a)>b){
      cout <<x<<" "<<x<<endl;
      return 0;
    }
    cout <<x<<" "<<b-(k-a)<<endl;
  }
  return 0;
}


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

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

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

	std::vector<ll> a(n);
	REP(i, n) std::cin >> a[i];

	std::vector<ll> c(n + 1, 0);
	REP(i, n) {
		c[i + 1] = c[i] + a[i];
	}

	std::vector<ll> l(n), r(n);
	{ // l
		int p = 0;
		ll sum = 0;
		FOR(i, 2, n - 1) {
			while (p < i && std::abs(c[i] - (sum + a[p]) * 2) < std::abs(c[i] - sum * 2)) {
				sum += a[p++];
			}
			l[i] = p;
		}
	}
	{ // r
		int p = n - 1;
		ll sum = 0;
		RFOR(i, 2, n - 1) {
			ll all = c[n] - c[i];
			while (p >= i && std::abs(all - (sum + a[p]) * 2) < std::abs(all - sum * 2)) {
				sum += a[p--];
			}
			r[i] = p + 1;
		}
	}

	ll ans = (1 << 30);
	FOR(i, 2, n - 1) {
		ll P = c[l[i]];
		ll Q = c[i] - c[l[i]];
		ll R = c[r[i]] - c[i];
		ll S = c[n] - c[r[i]];
		ans = std::min(ans, std::max({ P,Q,R,S }) - std::min({ P,Q,R,S }));
	}
	std::cout << ans << std::endl;
	return 0;
}

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

/*
提出前に確認!
- setとmultisetを間違えない
*/

int mod = 1e9 + 7;

int	main(void)
{
	vector<long long> fac(2e6 + 2, 1);
	for (int i = 2; i < 2e6 + 2; i++) fac[i] = fac[i - 1] * i % mod;
	vector<long long> inv(1e6 + 2, 1);
	for (int i = 2; i < 1e6 + 2; i++) inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
	vector<long long> finv(1e6 + 2, 1);
	for (int i = 2; i < 1e6 + 2; i++) finv[i] = finv[i - 1] * inv[i] % mod;
	int s;
	cin >> s;
	long long ans = 0;
	for (int i = 1; 3 * i <= s; i++)
	{
		ans += (fac[s - 3 * i + i - 1] * finv[s - 3 * i] % mod) * finv[i - 1] % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 34224
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[][][] room = new int[4][3][10];
        for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<10;k++){
                    room[i][j][k] = 0;
                }
            }
        }
        for(int i=0;i<n;i++){
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            room[b-1][f-1][r-1] = room[b-1][f-1][r-1] + v;
        }
        sc.close();

        for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<10;k++){
                    if(k<9){
                        System.out.print(" " + room[i][j][k]);
                    }else{
                        System.out.println(" " + room[i][j][k]);
                    }
                }
            }
            if(i<3){
                System.out.println("####################");
            }
        }
    }
}




Measured memory_bytes: 30132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int a, b, c, d;

signed main() {
	cin >> a >> b >> c >> d;
	cout << (a - c)*(b - d) << endl;
	ggr
}

Measured memory_bytes: 256
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e5 + 5;
unordered_map<int,int> mp;
int n,m;


int main(){
	n=D();
	for(int i=0;i<n;++i)
		++mp[D()];
	for(auto i:mp)
		if(i.first <= i.second)
			m+=i.first;
	printf("%d",n-m);
	

}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}


















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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  int cnt=0;
  for(char i:s) if(i=='o') cnt++;
  cout<<700+cnt*100<<endl;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as V
import Data.List (sortBy)

main :: IO ()
main = do
  (n : m : v : p : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  as <- V.fromList . sortBy (flip compare) . map unsafeSignedDecimal . T.words <$> T.getLine :: IO (V.Vector Int)
  let
    search :: (Int, Int) -> Int
    search (i, j) | j == succ i = j
                  | c k         = search (k, j)
                  | otherwise   = search (i, k)
      where
        k = (i + j) `div` 2
    c :: Int -> Bool
    c k | b0 = True
        | b1 = False
        | b2 = False
        | otherwise = True
      where
        b0 = k < p
        b1 = as V.! k + m < as V.! (pred p)
        b2 = m * (pred p + n - k) + sum (map (\i -> as V.! k + m - as V.! pred i) [p..k]) < m * v
  print $ search (0, n)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 16764
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    ll N;
    cin >> N;
    ll ans = 1;
    if (N == 1) {
        cout << ans << endl;
        return;
    }
    vector<int> tbl(N+1,1);
    FOR(i,2,N+1) {
        auto ni = i;
        while (ni <= (N+1)) {
            tbl[ni]++;
            ni += i;
        }
        ans += ll(i) * ll(tbl[i]);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 42308
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

string num;
int ans;
int count;
int main()
{
  while(cin >>num){
    ans = 0;
    if(num[0] == '0')
      break;
    for(int i = 0;i < num.size();i++){
      ans +=num[i]-'0';
  }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define ll long long
#define il inline
#define RG register
using namespace std;
il int gi(){ RG int x=0,q=1; RG char ch=getchar(); while( ( ch<'0' || ch>'9' ) && ch!='-' ) ch=getchar();
  if( ch=='-' ) q=-1,ch=getchar(); while(ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; }

char s[200010];
ll ans,n,cnt[27];

il void init(){
  scanf("%s",s); n=strlen(s);
}

il void work(){
  for(RG int i=n-1;i>=0;i--){
    RG int sum=0;
    for(RG int j=0;j<26;j++)
      if(j!=s[i]-'a') sum+=cnt[j];
    ans+=sum;
    cnt[s[i]-'a']++;
  }
  printf("%lld\n",ans+1);
}

int main(){ init(); work(); return 0; }

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if ( A >= B * 2 ){
    cout << A - B * 2 << endl;
  }
  else if ( A < B * 2 ){
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static double[][] a;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		a=new double[n][];
		double xp=0,yp=0;
		for(int i = 0;i<n;i++) {
			a[i]=sc.Da;
			xp+=a[i][0];
			yp+=a[i][1];
		}
		xp/=n;
		yp/=n;
		double p=0.1,d=0;
		while(true){
			int g=0;
			d=(a[0][0]-xp)*(a[0][0]-xp)+(a[0][1]-yp)*(a[0][1]-yp);
			for(int i = 1;i<n;i++) {
				var f=(a[i][0]-xp)*(a[i][0]-xp)+(a[i][1]-yp)*(a[i][1]-yp);
				if(d<f){d=f;g=i;}
			}
			xp+=(a[g][0]-xp)*p;
			yp+=(a[g][1]-yp)*p;
			if(Abs((a[g][0]-xp)*p)+Abs((a[g][1]-yp)*p)<1e-11){break;}
			p*=0.999;
		}
		Console.WriteLine("{0}",Sqrt(d));
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

c = [[0 for i in range(w)] for j in range(h)]

p = [0,0]
for i in range(n):
    for j in range(a[i]):
        c[p[0]][p[1]]=str(i+1)
        if p[0]%2==0:
            if p[1]==w-1:
                p[0]+=1
            else:
                p[1]+=1
        else:
            if p[1]==0:
                p[0]+=1
            else:
                p[1]-=1

for i in range(h):
    print(' '.join(c[i]))

Measured memory_bytes: 41200
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int N = cin.ReadInt;
            int[]A = cin.ReadIntArray(N);
            int ans = A.Select(Divide2).Min();
            WriteLine(ans);
        }

        public int Divide2(int X){
            int y = 0;
            while(X%2 == 0){
                X = X/2;
                y++;
            }
            return y;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator =' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11476
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << ": " << x << endl
typedef pair<int, int> P;
// sort by P.first (asd)
bool comPair(const P &firstElof, const P &secondElof) {
    return firstElof.second < secondElof.second;
}

int main() {
    int n, i, j, k;
    bool check = false;
    vector<int> vec;
    cin >> n;
    int sum = 0;
    for (i = 0; i < n; i++) {
        cin >> k;
        sum += k;
        vec.emplace_back(k);
    }
    vector<int> ans(n);
    ans[0] = sum;
    for (i = 1; i < n; i += 2) {
        ans[0] -= 2 * vec[i];
    }
    for (i = 0; i < n; i++) {
        ans[i + 1] = vec[i] * 2 - ans[i];
    }
    for (i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2168
#include<iostream>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int N;
int d[300];
long dp[2][301][601];
long fac[601],invfac[601],inv[301];
main()
{
	cin>>N;
	fac[0]=1;
	for(int i=1;i<=2*N;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=0;i<=2*N;i++)invfac[i]=power(fac[i],mod-2);
	for(int i=1;i<=N;i++)inv[i]=power(i,mod-2);
	bool isroop=true;
	for(int i=0;i<N;i++)
	{
		cin>>d[i];
		if(d[i]!=2)isroop=false;
	}
	if(isroop)
	{
		cout<<fac[N-1]*inv[2]%mod<<endl;
		return 0;
	}
	int now=0;
	dp[now][0][0]=1;
	long pd=1;
	for(int i=0;i<N;i++)
	{
		pd=pd*invfac[d[i]-1]%mod;
		for(int j=0;j<=N;j++)for(int k=0;k<=2*N;k++)dp[1-now][j][k]=0;
		for(int j=0;j<N;j++)for(int k=0;k<=2*N;k++)
		{
			if(dp[now][j][k]==0)continue;
			(dp[1-now][j][k]+=dp[now][j][k])%=mod;
			if(d[i]>=2)(dp[1-now][j+1][k+d[i]-2]+=dp[now][j][k]*(d[i]-1))%=mod;
		}
		now=1-now;
	}
	long ans=0;
	for(int i=3;i<N;i++)for(int j=1;j<=2*N;j++)
	{
		(ans+=dp[now][i][j]*fac[N-1-i]%mod*fac[i-1]%mod*pd%mod*j%mod*inv[2])%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}
int V,E;

using Weight=int;
struct Edge{
  int src,dst;
  Weight weight;
  Edge():src(0),dst(0),weight(0){}
  Edge(int s,int d,Weight w=0):src(s),dst(d),weight(w){}
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;

Graph g(100005);
Graph rg(100005);
vector<int> vs;
vector<bool> used(100005);
vector<int> cmp(100005);

void dfs(int v){
  used[v]=true;
  rep(i,g[v].size()){
    if(!used[g[v][i].dst])dfs(g[v][i].dst);
  }
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  rep(i,rg[v].size()){
    if(!used[rg[v][i].dst])rdfs(rg[v][i].dst,k);
  }
}

int scc(){
  fill(all(used),0);
  vs.clear();
  rep(i,V){
    if(!used[i])dfs(i);
  }
  fill(all(used),0);
  int k=0;
  for(int i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]])rdfs(vs[i],k++);
  }
  return k;
}


signed main(){
  cin>>V>>E;
  rep(i,E){
    int s,t;
    cin>>s>>t;
    g[s].emplace_back(s,t,0);
    rg[t].emplace_back(t,s,0);
  }
  int q;
  cin>>q;

  int num=scc();
  while(q--){
    int u,v;
    cin>>u>>v;
    cout<<(cmp[u]==cmp[v]?1:0)<<endl;
  }
  return 0;
}



Measured memory_bytes: 10420
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		//out.println(solve());
		out.flush();
	}

	static void solve(){
		int N = sc.nextInt();
		if(N==1) out.println("Hello World");
		else out.println(sc.nextInt()+sc.nextInt());
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 20948
#include<stdio.h>

#define A_MAX 25 //A店25*200=5000
#define B_MAX 16 //B店16*300=4800
#define C_MAX 10 //C店10*500=5000

#define A_PRICE 380 //A店のそば粉1袋の金額
#define B_PRICE 550 //B店のそば粉1袋の金額
#define C_PRICE 850 //C店のそば粉1袋の金額

#define A_QUANT 200 //A店の1袋辺りの内容量
#define B_QUANT 300 //B店の1袋辺りの内容量
#define C_QUANT 500 //C店の1袋辺りの内容量

void simulation(int input, int *result); //購入金額をシミュレートする関数

main()
{
	int n = 0, result = 0;
	while(scanf("%d", &n), n != 0)
	{
		simulation(n, &result);
		printf("%d\n", result);
		result = 0;
	}
	return 0;
}
void simulation(int input, int *result)
{
	int a = 0, b = 0, c = 0; //制御変数
	int price = 0; //価格を代入する変数
	
	int a_low = 0, a_high = 0; //a_low:割引される袋数,a_high:割引されない袋数
	int b_low = 0, b_high = 0; //b_low:割引される袋数,b_high:割引されない袋数
	int c_low = 0, c_high = 0; //c_low:割引される袋数,c_high:割引されない袋数
	
	for(a = 0; a <= A_MAX; a++)
	{
		for(b = 0; b <= B_MAX; b++)
		{
			for(c = 0; c <= C_MAX; c++)
			{
				if(((a * A_QUANT) + (b * B_QUANT) + (c * C_QUANT)) == input)
				{
					//printf("a = %d b = %d c = %d\n", a, b, c);
					
					a_high = a % 5, a_low = a - a_high;
					b_high = b % 4, b_low = b - b_high;
					c_high = c % 3, c_low = c - c_high;
					
					price = (((A_PRICE * a_low) * 0.8) + (A_PRICE * a_high)) + (((B_PRICE * b_low) * 0.85) + (B_PRICE * b_high)) + (((C_PRICE * c_low) * 0.88) + (C_PRICE * c_high));
					//printf("price = %d\n", price);
					if(*result == 0)
					{
						*result = price;
					}
					if(*result > price)
					{
						*result = price;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int n, k;
int a[505];

int try_d(int d) {
    // printf("try %d\n", d);
    int sub = 0;
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int j = 0; j < n; j++) {
        int lower = a[j] / d * d;
        int higher = a[j] % d == 0 ? a[j] : (a[j] / d + 1) * d;
        // printf("lower = %d, higher = %d\n", lower, higher);
        sub += (a[j] - lower);
        if (higher > a[j]) {
            // printf("pq.push %d\n", higher - a[j]);
            pq.push(higher - a[j]);
        }
    }
    int ret = 0;
    while (sub > 0) {
        sub -= d;
        ret += pq.top();
        pq.pop();
    }
    // printf("d = %d, diff = %d\n", d, ret);
    return ret;
}

int main() {
    cin >> n >> k;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ans = 1;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (try_d(i) <= k) { ans = max(ans, i); }
            if (try_d(sum / i) <= k) { ans = max(ans, sum / i); }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a; cin >> a;
  cout << (a < 1200 ? "ABC" : "ARC") << '\n';
}


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

int main()
{
	std::map<std::string, int> word_frequency;
	std::string word;
	while (std::cin >> word) {
		word_frequency[word]++;
	}

	std::string most_frequent_word;
	std::string longest_word;
	int max_frequency = 0;
	for (std::map<std::string, int>::iterator i = word_frequency.begin(); i != word_frequency.end(); ++i) {
		if (i->second > max_frequency) {
			most_frequent_word = i->first;
			max_frequency = i->second;
		}
		if (i->first.size() > longest_word.size()) {
			longest_word = i->first;
		}
	}

	std::cout << most_frequent_word << ' ' << longest_word << std::endl;

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string str;
  int count = 0;
  int max_count = 0;

  cin >> str;

  for(int i = 0; i < (int)str.size(); ++i){
    char ch = str[i];
    if(ch == 'R') {
      count += 1;
    }
    else {
      if(count > max_count){
        max_count = count;
      }
      count = 0;
    }
}

if(count > max_count){
        max_count = count;
      }

  cout << max_count << endl;
}

Measured memory_bytes: 3592
M, D = map(int, input().split())
ans = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d1, d10 = d%10, d//10
        if d1 >1 and d10 > 1 and d1*d10 == m:
            ans += 1
print(ans)

Measured memory_bytes: 39664
import java.util.Arrays;
import java.util.Scanner;
 
import javax.naming.spi.DirStateFactory.Result;
 
import org.omg.CORBA.PUBLIC_MEMBER;
 
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static int[] first = splitInt(sc.nextLine(), " ");
	public static int[][] array2 = new int[2][first[1]];
	public static int[] array = new int[2];
	public static int result;
	
	public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	}
	public static String[] array4 = new String[2];
	public static int[] array5 = new int[2];
	public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	}
}


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

using namespace std;

int main() {
	int K;
	cin >> K;
	vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout << a[K - 1];
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
last = a[0]
direction = 0
ans = 1

# 増加か減少かで分ける 切れ目で+1する
for a in a[1:]:
    if direction == 0:
        if last < a:
            direction = 1
        elif last > a:
            direction = -1
        last = a
        continue
    if direction == 1:
        if last <= a:
            last = a
            continue
        else:
            last = a
            direction = 0
            ans += 1
            continue
    if direction == -1:
        if last >= a:
            last = a
            continue
        else:
            last = a
            direction = 0
            ans += 1
            continue
print(ans)

Measured memory_bytes: 14252
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-04-29(Wed)
   note   
**********************************************************************/

#include <bits/stdc++.h>
using namespace std;

int main() {
  int r; 
  cin >> r;
  int ans = 3 * r * r;
  cout << ans << endl;
}

Measured memory_bytes: 256
<?php
while (true) {
    list($h, $w) = sscanf(trim(fgets(STDIN)), "%d %d");
    if ($h == 0 && $w == 0) { break; }
    
    for ($i=1; $i<=$h; $i++) {
        
        for ($j=1; $j<=$w; $j++) {
            if ($i==1 || $i==$h) {
                echo "#";
            } else {
                if ($j==1 || $j==$w) {
                    echo "#";
                } else {
                    echo ".";
                }
            }
            
        }
        echo "\n";
    }
    echo "\n";
}


Measured memory_bytes: 9220
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
// cf IO: I64d
// atcoder IO: ｌｌｄ
const int Maxn=305;
int a[Maxn][Maxn];
int n,m;
bool can[Maxn];
int cnt[Maxn];
int check(int &res){
	memset(cnt,0,sizeof(cnt));
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			if (can[a[i][j]]){
				cnt[a[i][j]]++;
				break;
			}
		}
	}
	int rr=0,ii;
	for (int i=1;i<=m;i++){
		if (cnt[i]>rr){
			rr=cnt[i];
			ii=i;
		}
	}
	res=min(res,rr);
	//cout<<rr<<endl;
	return ii;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	} 
	for (int i=1;i<=m;i++){
		can[i]=true;
	}
	int ans=1e9;
	for (int i=1;i<m;i++){
		int Mx=check(ans);
		can[Mx]=false;
	}
	if(ans==1e9) cout<<1<<endl;
	else 
	printf("%d\n",ans);
	return 0;
}

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


const int N=1e5 +10 ;
int phi[N];
int pr[N];
const int mod=1e9+7;
long long mod_expo(long long a, long long b)
{
	long long now=a;
	long long ans=1;
	while(b)
	{
		if(b&1) 
		{
			ans*=now;
		}
		b>>=1;
		now*=now;
		now%=mod;
		ans%=mod;

	}
	return ans;
}
int main()
{
	for(int i=1;i<N;i++) phi[i]=i,pr[i]=1;
	
	for(int i=2;i<N;i++) 
		if(pr[i])
		for(int j=i;j<N;j+=i)
			phi[j]-=phi[j]/i,pr[j]=0;
	int ans=0;	
	int n,k;
	cin>>n>>k;
	for(int d=1;d<=k;d++)
	{
		ans+=(1ll*mod_expo(k/d,n)*phi[d])%mod;
		// cout<<phi[d]<<endl;
		ans%=mod;
	}		
	cout<<ans;


	return 0;
}


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

#define ioso ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define kholo freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
#define laglo cerr << "Ti : " << clock() * 1.0 / CLOCKS_PER_SEC  << endl;
#define endl '\n';
#define ll long long

int main() {
	ioso;// kholo;
	ll q;
	string s;
	cin >> s;

	cin >> q;
	int sum = 0;
	vector<int> ad,c;
	vector<string> cd;
	int cnt = 0;
	int a;
	for(int i=0;i<q;i++) {
		cin >> a;
		if(a==1) cnt++;
		else {
			int f;  cin >> f;
			c.push_back(f);
			string g; cin >> g;
			cd.push_back(g);
		}
		ad.push_back(a);

	}

	vector<string> fron;
	vector<string> pise;
	if(cnt&1) reverse(s.begin(), s.end());

	ll tw_cnt=0;
	for(int i=0;i<q;i++) {
		a = ad[i];
		if(a==1) {
			sum+=a;
		}
		else {
			int f = c[tw_cnt];
			string k = cd[tw_cnt];
			if(cnt&1) {
			if(!(sum&1)) {
				if(f==1) {
				//	s += k; 
					fron.push_back(k);
				}
				else {
				//	k += s;
				//	s = k;
					pise.push_back(k);
				}
			}
			else {
				if(f==2) {
				//	s += k; 
					fron.push_back(k);
				}
				else {
				//	k += s;
				//	s = k;
					pise.push_back(k);
				}
			}
			tw_cnt++;
			}
			else {
				if((sum&1)) {
				if(f==1) {
				//	s += k; 
					fron.push_back(k);
				}
				else {
				//	k += s;
				//	s = k;
					pise.push_back(k);
				}
			}
			else {
				if(f==2) {
				//	s += k; 
					fron.push_back(k);
				}
				else {
				//	k += s;
				//	s = k;
					pise.push_back(k);
				}
			}
			tw_cnt++;
			}
			
		}
	}
		reverse(pise.begin(), pise.end());
		ll siz = pise.size();
		for (int i = 0; i < siz; ++i)
		{
			/* code */
			cout << pise[i];
		}
		cout << s;
		siz = fron.size();
		for (int i = 0; i < siz; ++i)
		{
			/* code */
			cout << fron[i];
		}
		cout << endl;
	
	//laglo;
}

Measured memory_bytes: 16568
IDENTIFICATION DIVISION.
PROGRAM-ID. B-String-R.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 S      PIC X(100).
01 T      PIC X(100).
01 SS     PIC X(200).
01 S-LEN  PIC 9(3).
01 I      PIC 9(3).
 
01 OUT-COST PIC ZZ9.
 
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT S.
  ACCEPT T.

  UNSTRING S DELIMITED BY ' '
    INTO S COUNT S-LEN. 
  STRING S S DELIMITED BY ' '
    INTO SS.

  PERFORM VARYING I FROM 1 BY 1
    UNTIL (I > S-LEN)
       OR (T(1:S-LEN) = SS(I:S-LEN))
  END-PERFORM.

  IF (I > S-LEN)
    DISPLAY 'No'
  ELSE
    DISPLAY 'Yes'
  END-IF.
 
MAIN-EXIT.
  STOP RUN.

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

int n, x, y;
int ans[2005];

int solve() {
  scanf("%d %d %d", &n, &x, &y);
  --x, --y;

  for (int i = 0; i < n; ++i) ans[i] = 0;

  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      ++ans[min(j - i, min(abs(x-i) + abs(y-j) + 1, abs(y-i) + abs(x-j) + 1))];
    }
  }

  for (int i = 1; i < n; ++i) printf("%d\n", ans[i]);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

LMAX = 1
RMIN = n

for i in range(m):
    l, r = map(int, input().split())
    LMAX = max(LMAX, l)
    RMIN = min(RMIN, r)

if LMAX <= RMIN:
    print(RMIN - LMAX + 1)
else:
    print(0)

Measured memory_bytes: 43752
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int fac[500005], ifac[500005];

int power(int x, int t)
{
	int ret = 1;
	while(t > 0) {
		if(t & 1) ret = 1LL * ret * x % MOD;
		x = 1LL * x * x % MOD;
		t >>= 1;
	}
	return ret;
}

int main()
{
	fac[0] = 1;
	rep1(i, 500000) fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[500000] = power(fac[500000], MOD - 2);
	for(int i = 500000; i >= 1; i --) ifac[i - 1] = 1LL * ifac[i] * i % MOD;
	
	int n, m;
	scanf("%d%d", &n, &m);
	
	int ret = 0;
	for(int i = 0; i <= min(n, m); i ++) {
		int ca = 1LL * fac[m] * ifac[m - i] % MOD;
		ca = 1LL * fac[n] * ifac[i] % MOD * ifac[n - i] % MOD * ca % MOD;
		ca = 1LL * power(m + 1, n - i) * power(n + 1, m - i) % MOD * ca % MOD;
		if(i & 1) ret = (ret - ca + MOD) % MOD;
		else ret = (ret + ca) % MOD;
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        // cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    vector<vector<int>> g(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    queue<pii> q;
    q.push({0, s});
    vector<int> dist1(n, INF), dist2(n, INF);
    dist1[s] = dist2[t] = 0;
    while (!q.empty()) {
        int v = q.front().second; q.pop();
        FORE(w, g[v]) {
            if (chmin(dist1[w], dist1[v] + 1)) {
                q.push({dist1[w], w});
            }
        }
    }
    q.push({0, t});
    while (!q.empty()) {
        int v = q.front().second; q.pop();
        FORE(w, g[v]) {
            if (chmin(dist2[w], dist2[v] + 1)) {
                q.push({dist2[w], w});
            }
        }
    }
    int D = dist1[t];

    map<int, int> cnt;
    REP(v, n) cnt[dist2[v]]++;

    int ans = 0;
    REP(v, n) {
        int tmp = cnt[D - dist1[v] - 2];
        FORE(w, g[v]) {
            if (dist2[w] == D - dist1[v] - 2) {
                tmp--;
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 12300
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b>=10)
	{
		cout<<"error"<<endl;
	}else{
		cout<<a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;
int LR[2200][2200]={0},RL[2200][2200]={0},UD[2200][2200]={0},DU[2200][2200]={0};
int main(){
    ll h,w,ans=0,tmp=0;
    cin>>h>>w;
    string s[h];
    rep(i,0,h)cin>>s[i];

    rep(i,0,h)if(s[i][0]=='.')LR[i][0]=1;
    rep(i,0,w)if(s[0][i]=='.')UD[0][i]=1;
    
    rep(i,0,h){
        rep(j,1,w){
            if(s[i][j]=='.')LR[i][j]=LR[i][j-1]+1;
            else LR[i][j]=0;
        }
        irep(j,w-1,0){
            if(s[i][j]=='.')RL[i][j]=RL[i][j+1]+1;
            else RL[i][j]=0;
        }
    }

    rep(i,0,w){
        rep(j,1,h){
            if(s[j][i]=='.')UD[j][i]=UD[j-1][i]+1;
            else UD[j][i]=0;
        }
        irep(j,h-1,0){
            if(s[j][i]=='.')DU[j][i]=DU[j+1][i]+1;
            else DU[j][i]=0;
        }
    }

     rep(i,0,h){
        rep(j,0,w){
            tmp=0;
            if(s[i][j]=='.')tmp=LR[i][j]+RL[i][j]+UD[i][j]+DU[i][j]-3;
            ans=max(ans,tmp);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 78208