akhauriyash/Code-Regression huggingface dataset:
open Printf
open Scanf

let (++) = Int64.add
let (--) = Int64.sub
let ( ** ) = Int64.mul
let (//) = Int64.div
let (%%) = Int64.rem
let landl = Int64.logand
let lorl = Int64.logor
let lnotl = Int64.lognot
let lxorl = Int64.logxor
let lsll = Int64.shift_left
let lsrl = Int64.shift_right_logical
let long = Int64.of_int
let succl = Int64.succ
let predl = Int64.pred

let read_int _ = scanf " %d " (fun x -> x)
let read_long _ = scanf " %Ld " (fun x -> x)
let read_str _ = scanf " %s " (fun x -> x)
let read_double _ = scanf " %f " (fun x -> x)

let m = 1_000_000_007L

let rec gcd a b = if b = 0L then a else gcd b (a %% b)

let rec mod_pow a = function
  | 0L -> 1L
  | b -> (if b %% 2L = 0L then 1L else a) ** mod_pow (a ** a %% m) (b//2L) %% m


let foldi init f arr =
  let rec foldi' i v =
    if Array.length arr <= i
    then v
    else let v' = f v i arr.(i) in
      foldi' (i+1) v' in
  foldi' 0 init

let () =
  let n,k = scanf " %d %d " (fun x y -> x,y) in
  let h = Array.init n read_int in
  Array.sort compare h;
  let res = foldi max_int (fun c i v ->
      if i+k-1 < Array.length h
      then min (h.(i+k-1) - h.(i)) c
      else c) h in
  printf "%d\n" res


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

#define sum12 = 195;
#define sum3 = 200;

int main(void){
    int n,p, year,month,day,sum=0;
    
    cin >> n ;
    for(int i = 0;i<n;i++){
        sum = 0;
        cin >> year >> month >> day;
        
        if(year%3==0){
            sum = 21-day + (10-month)*20;
        } else{
            if(month % 2 == 0) {
                sum += 20-day;
                sum += (10 - month)/2*39;
                
            }
            
            else{
                
                sum += 20-day;
                sum += (9-month)/2 *39 + 20;
                
            }
        }
    
    
        if(year % 3 == 0){
            p = 999-year;
            sum += 200 * p/3 + (p-p/3) * 195;            
            
        }else if(year % 3 == 1){
            year--;
            p = 999 -year;
            sum += 200 * p/3 + (p-p/3 )* 195 -195;
        } else{
            year -= 2;
            p = 999-year;
         sum += 200 * p/3 + (p-p/3) * 195 - 390;    
        }
        
               // cout << year << " : " << sum << endl;
            
        
        cout << sum << endl;
            
    }
        
    
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int h, w, n, a[10000];
	queue<int> que;
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 0; j < a[i]; j++) {
			que.push(i+1);
		}
	}

	int ans[100][100];

	bool left = 0; // 0:right 1:left
	int pw = 0;
	for (int i = 0; i < h; i++) {
		pw = left ? w-1 : 0;
		for (int j = 0; j < w; j++) {
			int num = que.front(); que.pop();
			ans[i][pw] = num;
			left ? pw-- : pw++;
		}
		left = !left;
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << ans[i][j] << ' ';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mx 100000
using namespace std;
 
int main() {
	FIO;
	string s1,s2;
	cin>>s1>>s2;
	int l1=s1.length();
	int l2=s2.length();
	vector<vector<int>> dp(l1+1,vector<int>(l2+1,0));
	for(int i=1;i<=l1;i++){
		for(int j=1;j<=l2;j++){
			if(s1[i-1]==s2[j-1]) dp[i][j]=1+dp[i-1][j-1];
			else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
	}
	string str="";
	int i=l1,j=l2;
	while(i>0 && j>0){
		if(dp[i][j]!=max(dp[i-1][j],dp[i][j-1])){
			str+=s1[i-1];
			i--;
			j--;
		}
		else if(dp[i][j]==dp[i-1][j]){
			i--;
		}
		else{
			j--;
		}
	}
	reverse(str.begin(),str.end());
	cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 35584
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)
#define INF 1e15
#define int long long

struct Edge{
	int a,b,c;
};

struct Node{
	int p,c;
};
bool operator < (Node a,Node b){
	return a.c > b.c;
}
vector<int> dijkstra(int s, vector< vector<Edge> > g){
	vector<int> dist(g.size(), INF);
	priority_queue<Node> Q;
	Q.push({s,0});
	while( Q.size() ){
		auto q = Q.top(); Q.pop();
		if( dist[q.p] != INF ) continue;
		dist[q.p] = q.c;
		for( auto e : g[q.p] ){
			Q.push({e.b, q.c + e.c});
		}
	}
	return dist;
}

int visited[100010];
int order[100010];
int currentTime = 0;
set< pair<int,int> > bad;

int dfs(int x, int p, Edge e, const vector< vector<Edge> > &g){
	visited[x] = ++currentTime;
	int ans = currentTime;
	
	for( auto &&e : g[x] ){
		if( p == e.b ) continue;

		if( visited[e.b] != 0 ){
			ans = min(ans, visited[e.b]);
		}else{
			ans = min(ans, dfs(e.b, x, e, g));
		}
	}
	if( p != -1 && ans > visited[p] ){
		bad.insert({x,p});
		bad.insert({p,x});
	}
	return ans;
}

signed main(){
	int n,m;
	cin >> n >> m;
	vector<Edge> es;
	vector< vector<Edge> > g(n),rg(n);
	for(int i = 0 ; i < m ; i++){
		int a,b,c;
		cin >> a >> b;
		c = 1;
		es.push_back({a,b,c});
		g[a].push_back({a,b,c});
		g[b].push_back({b,a,c});
	}
	dfs(0,-1, {}, g);

	vector< pair<int,int> > a;
	for( auto e : es ){
		if( bad.count({e.a, e.b}) ){
			a.push_back({min(e.a,e.b),max(e.a,e.b)});
		}
	}
	sort(a.begin(),a.end());
	for( auto p : a ){
		cout << p.first << " " << p.second << endl;
	}
}

Measured memory_bytes: 9016
def solve():
    s=input()
    t=input()
    ans=len(t)
    for i in range(0,len(s)-len(t)+1) :
        diff=0
        for j in range(0,len(t)) :
            diff+= 1 if s[i+j]!=t[j] else 0
            if diff>ans :
                break
        ans=min(ans,diff)
    return ans

print(solve())


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

int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

//入力
int A,B,C,D;

int main(){
  cin >> A >> B >> C >> D;
  while(1){
    C=C-B;
    if(C<=0){
      cout << "Yes" << endl;
      return 0;
    }
    A=A-D;
    if(A<=0){
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
N,K=map(int,input().split())
A=list(map(int,input().split()))

score=1
for i in range(K):
    score+=A[i]

for i in range(K,N):
    pre=score
    score-=A[i-K]
    score+=A[i]
    if score>pre:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 31628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int R = scan.nextInt();
        int G = scan.nextInt();
        int B = scan.nextInt();
        int N = scan.nextInt();
        int answer = 0;
        int max_r = N / R;
        int max_g = N / G;
        int max_b = N / B;
        for (int r = 0; r <= max_r; r++) {
            for (int g = 0; g <= max_g; g++) {
                if (N < r * R + g * G) {
                    continue;
                }
                int remain = N - r * R - g * G;
                if (remain % B != 0) {
                    continue;
                }
                if (remain / B <= max_b) {
                    answer += 1;
                }
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21332
// atcoder/abc048/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

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

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string a, b, c;
  while (cin >> a >> b >> c) {
    cout << a.front() << b.front() << c.front() << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(o) {cerr<<#o<<" "<<o<<endl;}
#define DUMPC(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//??¨????????????????????????
//n??\????????£??´??°????´???°???????????°???????????????is_prime[]???????´?
void eratos(int n, bool is_prime[]) {
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i*i <= n; i++)
		if (is_prime[i]) {
			int j = i + i;
			while (j <= n) {
				is_prime[j] = false;
				j = j + i;
			}
		}
}

signed main() {
	bool is_prime[50001];
	eratos(50001, is_prime);
	for (int n; cin >> n&&n;) {
		int ans = 0;
		FOR(i, 2, n / 2 + 1) {
			if (is_prime[i] && is_prime[n - i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, a, b) for (int i = a; i < (b); ++i)
#define FOR(i, n) for (int i = n; i >= 0; --i)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF (1LL << 50)
using namespace std;
//struct Edge{int from, to, cost;};
const int limit = 100010;
using edge = struct{int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

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

    REP(i, n-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        edge e1 = {b,c};
        edge e2 = {a,c};
        tree[a].push_back(e1);
        tree[b].push_back(e2);
    }

    int q,k;
    cin >> q >> k;
    k--;

    dfs(k, -1, 0);

    REP(i,q){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;

}

Measured memory_bytes: 14336
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {

		Scanner scanner = new Scanner( System.in );

		ArrayList<Integer> nums = new ArrayList<Integer>();

		while ( true ) {
			String inputText = scanner.nextLine();


			int x = Integer.parseInt( inputText );
			if ( x == 0) {
				break;
			}
			nums.add( x );
		}

		for ( int i = 0; i < nums.size(); i++ ) {
			System.out.println("Case " + (i + 1) + ": " + nums.get( i ) );
		}

		scanner.close();
	}
}

Measured memory_bytes: 62320
x,y = map(int,input().split())
ax = abs(x)
ay = abs(y)
if ax == ay and x != y:
    a = 1
elif x > y and 0 < y:
    a = ax - ay + 2
elif x > y and y == 0:
    a = ax - ay + 1
elif x > y and 0 > y:
    if ay > ax and x >= 0:
        a = ay - ax + 1
    elif ay > ax and x < 0:
        a = ay - ax + 2
    elif ax > ay:
        a = ax - ay + 1
elif y > x and x < 0 and ay > ax:
    a = ay - ax + 1
elif y > x and x < 0 and y > 0 and ax > ay:
    a = ax - ay + 1
else:
    a = y-x
print(a)

Measured memory_bytes: 9120
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

#define MAX_N 100
#define MAX_M 100

/*
 * define global variables here.
 */
long A, B, C;

void solve();
void setup();

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

void setup() {
  // make io faster.
  cin.tie(0);
  ios::sync_with_stdio(false);

  /*
   * initialize global variables here.
   */
  cin >> A >> B >> C;
}

void solve() {
  if (A % 2 == 0 ||
      B % 2 == 0 ||
      C % 2 == 0) {
    cout << 0 << '\n';
    return;
  }
  vector<long> v = {A, B, C};
  sort(v.begin(), v.end());
  cout << v[1] * v[0] << '\n';
  return;
}


Measured memory_bytes: 256
d = {}
N, d['A'], d['B'], d['C'] = map(int, input().split())
S = [input() for _ in range(N)]

if sum(d.values()) == 0:
    print('No')
elif sum(d.values()) == 1:
    ans = []
    for s in S:
        if d[s[0]] == d[s[1]] == 0:
            print('No')
            exit()
        elif d[s[0]] > d[s[1]]:
            d[s[0]] -= 1
            d[s[1]] += 1
            ans.append(s[1])
        else:
            d[s[0]] += 1
            d[s[1]] -= 1
            ans.append(s[0])
    print('Yes')
    print(*ans, sep='\n')
else:
    ans = []
    for i, s in enumerate(S):
        if d[s[0]] == d[s[1]] == 0:
            print('No')
            exit()
        elif d[s[0]] > d[s[1]]:
            d[s[0]] -= 1
            d[s[1]] += 1
            ans.append(s[1])
        elif d[s[0]] < d[s[1]]:
            d[s[0]] += 1
            d[s[1]] -= 1
            ans.append(s[0])
        elif d[s[0]] == d[s[1]] == 1 and i != N-1 and S[i] != S[i+1]:
            if s[0] in S[i+1]:
                d[s[0]] += 1
                d[s[1]] -= 1
                ans.append(s[0])
            else:
                d[s[0]] -= 1
                d[s[1]] += 1
                ans.append(s[1])
        else:
            d[s[0]] -= 1
            d[s[1]] += 1
            ans.append(s[1])
    print('Yes')
    print(*ans, sep='\n')


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

namespace Contest01
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            char s1 = S[0];
            char s2 = S[1];
            char s3 = S[2];

            char t1 = T[0];
            char t2 = T[1];
            char t3 = T[2];

            int sum = 0;

            if (s1 == t1)
            {
                sum = sum + 1;
            }
            if (s2 == t2)
            {
                sum = sum + 1;
            }
            if (s3 == t3)
            {
                sum = sum + 1;
            }
            Console.WriteLine(sum);
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		for(int i=0;i<N;i++){
			int min = (int)1e9;
			int idx = -1;
			for(int j=0;j<M;j++){
				if(Dist(A[i],B[i],C[j],D[j]) < min){
					min = Dist(A[i],B[i],C[j],D[j]);
					idx = j;
				}
			}
			Console.WriteLine(idx+1);
		}
		
		
		
	}
	
	static int Dist(int x1, int y1, int x2, int y2){
		return Math.Abs(x1-x2) + Math.Abs(y1-y2);
	}
	
	int N,M;
	int[] A,B,C,D;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[N]; B = new int[N];
		for(int i=0;i<N;i++){
			d = ria();
			A[i] = d[0];
			B[i] = d[1];
		}
		
		C = new int[M]; D = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			C[i] = d[0];
			D[i] = d[1];
		}

	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main(void) {
    int n, ans = 0, count[100003] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        count[a]++;
        count[a + 1]++;
        count[a + 2]++;
    }
    for (int i = 0; i <= 100002; i++) ans = max(ans, count[i]);
    cout << ans << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var d = new Dictionary<long, long>();

            for(var i = 1; i <= n; i++){
                var a = long.Parse(Console.ReadLine());
                d.Add(i, a);
            }

            var flag = false;
            var count = 0;
            var key = 1L;
            while(true){
                if(d.ContainsKey(key)){
                    count++;
                    var item = d[key];
                    if(item == 2){
                        flag = true;
                        break;
                    }
                    d.Remove(key);
                    key = item;
                }else{
                    break;
                }
            }

            Console.WriteLine(flag ? count : -1);
        }
    }
}


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

using namespace std;

int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    string ans = "Yes";
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i]){
            ans="No";
            break;
        }
    }
    if(t.length()-s.length() != 1)
        ans = "No";

    cout<<ans<<endl;

}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>

#define L 100005

char b[10][20] = {
    "",
    "',.!?",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};
char s[L], a[L];

int main() {
    for (int i = 1; i < 10; ++i) {
        int tn = strlen(b[i]);
        for (int j = 0; j < tn; ++j)
            b[i][j + tn] = b[i][j] - 'a' + 'A';
        b[i][tn + tn] = '\0';
    }
    while (EOF != scanf("%s", s)) {
        int n = strlen(s), an = 0;
        for (int i = 0; i < n; ++i) {
            int j = i + 1;
            while (j < n && s[j] == s[i]) ++j;
            int v = s[i] - '0';
            a[an++] = b[v][(j - i - 1) % strlen(b[v])];
            if (s[j] == '0') {
                ++j;
                while (j < n && s[j] == '0') {
                    a[an++] = ' ';
                    ++j;
                }
            }
            i = j - 1;
        }
        a[an] = '\0';
        puts(a);
    }
    return 0;
}

Measured memory_bytes: 0
//#include<bits/stdc++.h>
#include<cstdio>
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 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(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;
}

int daishou[200002];

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


	int N = getint();
	int A[200001];
	rep1(i, N) A[getint()] = i;

	ll kotae = 0;
	for (int i = N; i > 0; i--) {
		int a = A[i];
		int l = daishou[a - 1];
		int r = daishou[a + 1];
		if (l && r) {
			daishou[l] = r;
			daishou[r] = l;
			kotae += (ll)(a - l + 1) * (r - a + 1) * i;
		}
		else if (l) {
			daishou[l] = a;
			daishou[a] = l; 
			kotae += (ll)(a - l + 1) * i;
		}
		else if (r) {
			daishou[r] = a;
			daishou[a] = r;
			kotae += (ll)(r - a + 1) * i;
		}
		else {
			daishou[a] = a;
			kotae += i;
		}
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int ans = 0;
string s;
int main()
{
	cin >> s;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == 'C')
		{
			ans++;
		}
		if(s[i] == 'F' && ans)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

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

const int maxn = 100005;
int a[maxn], n;

inline int gcd(int a, int b) {
	return !b ? a : gcd(b, a % b);
}

int solve() {
	int flag1 = 0, cnt1 = 0, cnt0 = 0;
	rep (i, 1, n)
		if (a[i] & 1) {
			flag1 |= (a[i] == 1);
			cnt1++;
		}
		else cnt0++;
	if (cnt0 & 1) return 1;
	if (cnt1 != 1) return 0;
	if (flag1) return cnt0 & 1;
	rep (i, 1, n)
		if (a[i] & 1) a[i]--;
	int g = a[1];
	rep (i, 2, n)
		g = gcd(g, a[i]);
	rep (i, 1, n)
		a[i] /= g;
	return solve() ^ 1;
}

int main() {
	scanf("%d", &n);
	rep (i, 1, n) scanf("%d", &a[i]);
	puts(solve() ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
int p,q,r,i;
int dfs(){
  int t[2]={},c=0,m=0,w=0,k=0,a=0,pp=0;
  t[0]=t[1]=-100;
  if(s[i]=='(')i++;
  for(;i<s.size();i++){pp=0;
    if(s[i]=='(')t[c++]=dfs(),a++,pp++;
    else if(s[i]>='0'&&s[i]<='2')t[c++]=s[i]-'0',a++;
    else if(s[i]=='P')t[c++]=p,a++;
    else if(s[i]=='Q')t[c++]=q,a++;
    else if(s[i]=='R')t[c++]=r,a++;
    else if(s[i]=='-')m++;
    else if(s[i]=='+')w++,a=0;
    else if(s[i]=='*')k++,a=0;
    if(m%2&&a){
     t[c-1]=abs(t[c-1]-2);
     a=m=0;
   }
    if(s[i]==')'&&!pp){
      if(c==1)return t[0];
      if(w)return max(t[0],t[1]);
      if(k)return min(t[0],t[1]);
    }
  }
  return t[0];
}
int main(){
  while(cin>>s,s!="."){
      int res=0;
      r(x,3)r(y,3)r(z,3){
	p=x;q=y;r=z;i=0;
	if(dfs()==2)res++;
      }
      cout<<res<<endl;
  }
}

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

int N;
int pop_cnt;
int p_mod_org, m_mod_org;
string X;
vector<int> p_mod, m_mod;
vector<int> F;

int my_popcount(int bits) {
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void input_init(void) {
	cin >> N >> X;
	pop_cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (X[i] == '1')
			++pop_cnt;
	}
//	F.resize(N, 0);
	F.resize(N, 1);				// Koba-debug
}

void calcu(int i) {
	int num = 0;
	if (X[i] == '0')
		num = (p_mod_org + p_mod[N - 1 - i]) % (pop_cnt + 1);
	else {
		if (pop_cnt - 1 != 0)
			num = (m_mod_org + (pop_cnt - 1) - m_mod[N - 1 - i]) % (pop_cnt - 1);
		else {
			F[i] = 0;			// Koba-debug
			return;
		}
	}

//	++(F[i]);
	if (num == 0)
		return;
	while (num != 0) {
		++(F[i]);
		int b = my_popcount(num);
		num = num % b;
	}
}

void solve(void) {
	p_mod.resize(N, 0);
	p_mod[0] = 1;
	for (int i = 1; i < N; ++i)
		p_mod[i] = (2 * p_mod[i - 1]) % (pop_cnt + 1);
	m_mod.resize(N, 0);
	if (pop_cnt - 1 > 0) {
		m_mod[0] = 1 % (pop_cnt - 1);
		for (int i = 1; i < N; ++i)
			m_mod[i] = (2 * m_mod[i - 1]) % (pop_cnt - 1);
	}
	p_mod_org = m_mod_org = 0;
	for (int i = 0; i < N; ++i) {
		if (X[i] == '1') {
			p_mod_org = (p_mod_org + p_mod[N - 1 - i]) % (pop_cnt + 1);
			if (pop_cnt - 1 != 0)
				m_mod_org = (m_mod_org + m_mod[N - 1 - i]) % (pop_cnt - 1);
		}
	}
	for (int i = 0; i < N; ++i)
		calcu(i);
}

int main(void) {
	input_init();
	if (pop_cnt != 0)
		solve();
	for (int i = 0; i < N; ++i)
		cout << F[i] << '\n';
	return 0;
}


Measured memory_bytes: 5940
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

int main () {
	string str;
	cin >> str;
	For (i, 0, str.size() - 9)
		putchar (str[i]);
	putchar ('\n');
    return 0;
}


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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    for (int i=A; i<=B; i++){
        if ((B-K+1 <= i) | (i <= A+K-1)){
            cout << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;
bool k[100001]={};
int a[100001]={};
int main() {
	bool k[100001]={};

	k[2]=true;
	k[3]=true;
	for(int i=5;i<100001;i+=2){
		bool m=true;
		for(int j=3;j<=min(i-1,400);j+=2){
			if(i%j==0){
				m=false;
				break;
			}
		}
		k[i]=m;
	}
	for(int i=1;i<100001;i++){
		a[i]=a[i-1];
		if(k[i]&&k[(i+1)/2])a[i]++;
	}

	int q;
	int l,r;
	cin>>q;
	for(int i=0;i<q;++i){
		cin>>l>>r;
		cout<<(a[r]-a[l-1])<<endl;
	}
	return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;


#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}



// substr(start, len)

int main(){
  int N, sum = 0;
  cin >> N;

  vector<int> x(N);

  rep(i, 0, N){ 
    cin >> x[i];
  }
  int a = accumulate(all(x), 0);
  
  if(a % N == 0){
    a /= N;
    rep(i, 0, N){
      sum += pow(x[i] - a, 2);
    }
    cout << sum << endl;
    return 0;
  }else{
    double p = (double)a / N;
    int sum_f = 0, sum_c = 0, p_f, p_c;
    p_f = floor(p);
    p_c = ceil(p);
    rep(i, 0, N){
      sum_f += pow(x[i] - p_f, 2);
      sum_c += pow(x[i] - p_c, 2);
    }
    if(sum_f < sum_c){
      cout << sum_f << endl;
    }else{
      cout << sum_c << endl;
    }
  }
  

// CHECK if it's possible to overflow!!
}

Measured memory_bytes: 256
n = int(input())
P = [int(i) for i in input().split()]

ans = 0
for i in range(1, n - 1):
    if P[i] != max(P[i - 1], P[i], P[i + 1]) and P[i] != min(P[i - 1], P[i], P[i + 1]):
        ans += 1
        
print(ans)

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

using namespace std;

const int MAX_V=1001;
struct edge{
  int from,to;
  string cost;
};
edge es[MAX_V];
string d[MAX_V];
int V,E;
string INF;
bool bellman_ford(int s,int g){
  for(int i=0;i<V;i++)d[i]=INF;
  d[s]="";
  int cnt=0;
  while(1){
    bool update=false;
    bool gupdate=false;
    for(int i=0;i<E;i++){
      edge &e=es[i];
      if(d[e.from]!=INF&&d[e.to]>e.cost+d[e.from]){
	d[e.to]=e.cost+d[e.from];
	update=true;
	if(e.to==g)gupdate=true;
      }
    }
    if(!update)break;
    cnt++;
    // S[ðXVµÂÃ¯éÌÂHª¶Ý
    if(cnt>=V&&gupdate)return false;
    else if(cnt>=10*V)return true;
  }
  return true;
}
int N,A,S,G;

int main(){
  for(int i=0;i<1000;i++)INF+='z';
  while(cin>>N>>A>>S>>G&&(N|A|S|G)){
    E=A;V=N;
    for(int i=0;i<A;i++){
      edge e;
      cin>>e.to>>e.from>>e.cost;
      es[i]=e;
    }
    bool res=bellman_ford(G,S);
    if(!res||d[S]==INF)cout<<"NO"<<endl;
    else cout<<d[S]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1752
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
ll val[105],v[105],dp[100025];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,V;ll ans = 0;scanf("%d%d",&n,&V);
    for(int i = 1;i<=n;++i) scanf("%lld%lld",&v[i],&val[i]);
    for(int i = 1;i<=n;++i)
    {
        for(int j = V;j>=v[i];j--)
            dp[j] = max(dp[j],dp[j-v[i]]+val[i]);
    }
    for(int i = 1;i<=V;++i) ans = max(ans,dp[i]);
    printf("%lld\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;
    if (A > B){
        cout << 2*A - 1 << endl;
    }
    else if (A == B){
        cout << A + B << endl;
    }
    else {
        cout << 2*B - 1 << endl;
    }
}

Measured memory_bytes: 256
import math
import sys

def f(s):
    return -2 \
        if s=='#' else -1


def dfs(s_x,s_y):
    tmp=[[s[i][j] for j in range(w)] for i in range(h)]
    tmp[s_x][s_y]=0
    que=[[s_x,s_y]]
    que_next=[]
    level=-1
    while que!=[]:
        level+=1
        for p in que:

            px,py=p[0],p[1]

            for q in [[px+1,py],[px-1,py],[px,py+1],[px,py-1]]:
                qx,qy=q[0],q[1]
                if (qx>=0 and qx<h) and (qy>=0 and qy<w) and tmp[qx][qy]==-1:
                    tmp[qx][qy]=0
                    que_next.append(q)


        que=[que_next[i] for i in range(len(que_next))]
        que_next=[]
    return level



h,w=map(int,input().split())
s=[[] for i in range(h)]
for i in range(h):
    p=input()
    s[i]=[f(p[j]) for j in range(w)]

ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]==-1:
            ans=max(ans,dfs(i,j))

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string S, T;
    cin >> S >> T;

    int ans = 0;
    rep(i, S.length()) {
        if (S[i] != T[i]) ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3796
#include<stdio.h>
int main(void)
{
	int r, D, x, w[10];
	scanf("%d%d%d", &r, &D, &x);

	for (int i = 0; i < 10; i++) {
		if (i == 0) {
			w[i] = r * x - D;
			printf("%d\n", w[i]);
		}
		else {
			w[i] = r * w[i - 1] - D;
			printf("%d\n", w[i]);
		}

		
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <numeric>
using namespace std;

int main() {
    int N, K; cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; i++) cin >> h[i];
	sort(h.begin(), h.end(), greater<int>());

	int res = 1000000000;
	for(int i = 0; i < N - K + 1; i++){
		res = min(res, h[i] - h[i + K - 1]);
	}
	cout << res << endl;
}

Measured memory_bytes: 640
from sys import stdin
input = stdin.readline


def main():
  N, M = list(map(int, input().split()))
  s = []
  c = []
  for i in range(M):
    ss, cc = map(int, input().split())
    s.append(ss)
    c.append(cc)

  # print(10**(N-1), 10**N)
  # print(s, c)
  if N == 1:
    left = 0
  else:
    left = 10**(N-1)
  for i in range(left, 10**N):
    flag = True
    for j in range(M):
      if str(i)[s[j]-1] != str(c[j]):
        flag = False
    if flag:
      print(i)
      return

  print(-1)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 66112
def calcGaps(n):
    gaps = [1]
    while 3 * gaps[-1] + 1 < n:
        gaps.append(3 * gaps[-1] + 1)
    return gaps[::-1]


def insertionSort(a, n, gap, cnt):
    for i in range(gap, n):
        v = a[i]
        j = i - gap
        while j >= 0 and a[j] > v:
            a[j + gap] = a[j]
            j = j - gap
            cnt += 1
        a[j + gap] = v
    return a, cnt


def shellSort(a, n):
    cnt = 0
    Gaps = calcGaps(n)
    for gap in Gaps:
        a, cnt = insertionSort(a, n, gap, cnt)
    print(len(Gaps))
    print(*Gaps)
    print(cnt)
    print(*a, sep='\n')


n = int(input())
A = [int(input()) for _ in range(n)]

shellSort(A, n)


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

#define ll long long
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


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

    vector<int> P(N);
    rep(i,N) cin >> P[i];
    
    int key = P[0];
    int ans = N;
    rep(i,N)
    {
        if( key < P[i] )
        {
            ans--;
        }
        key = min(key, P[i]);
    }

    cout << ans << endl;
            

}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
      	int a=x;
      int b=y;
      int c=z;
      int aux=a,aux1=c;
      a=b;
      b=aux;
      c=a;
      a=aux1;
		System.out.println((a+" "+b+" "+c));
	}
}


Measured memory_bytes: 21972
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let s = get!(String; n).into_iter().map(|e| e.chars().collect::<Vec<_>>()).collect::<Vec<_>>();
    let mut count = 0;
    for a in 0..n {
        let mut flag = false;
        for i in 0..n {
            for j in 0..n {
                if s[(i+a)%n][j] != s[(j+a)%n][i] {
                    flag = true;
                }
            }
        }
        if !flag {
            count += 1;
        }
    }
    println!("{}", count*n);
}


Measured memory_bytes: 8572
#include<cstdio>
#include<algorithm>
using namespace std;
int N,Ans=2e9,R[300005],L[300005];
char S[300005];
int main()
{
	scanf("%d",&N);
	scanf("%s",S+1);
	for (int i=1;i<=N;i++){
		R[i]=R[i-1];
		if (S[i]=='W') R[i]++;
	}
	for (int i=N;i;i--){
		L[i]=L[i+1];
		if (S[i]=='E') L[i]++;
	}
	for (int i=1;i<=N;i++) Ans=min(Ans,L[i+1]+R[i-1]);
	printf("%d\n",Ans);
	return 0;
}

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

int main(void){
  int x, y;

  while(1){
    cin >> x >> y;
    if( x == 0 && y == 0){
      break;
    }else{
      if( x <= y ){
	cout << x << " " << y << endl;
      }else{
	cout << y << " " << x << endl;
      }
    }
  }
  return 0;
}

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

int main() {
long long int n,l,a[100],d=0;
cin >> n;
for(int p=0;p<n;p++)
    {
        cin >> a[p];
    }
 for(int i=0;i<n;i++)
    {
         for(int j=i+1;j<n;j++)
            {
                 for(int k=j+1;k<n;k++)
                    {
                        if((a[i]!=a[j]) && (a[j]!=a[k]) && (a[i]!=a[k]))
                            {
                                if((a[i]+a[j]>a[k]) && (a[i]+a[k]>a[j]) && (a[k]+a[j]>a[i]))
                                    {
                                        d++;
                                    }
                            }
                    }
            }
    }
        
      
           cout << d; 
        return 0;
        
}


Measured memory_bytes: 3636
def abc093b():
    a, b, k = map(int, input().split())
    if b - a + 1 <= 2 * k:
        return [i for i in range(a, b + 1)]
    else:
        return [i for i in range(a, a + k)] + [i for i in range(b - k + 1, b + 1)]


for num in abc093b():
    print(num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

const int INF = (1 << 31) - 1;

//?????¶???????????°???????????¨(RMQ & RUQ)??????????????¨??????????°????
struct SegTree {
    int N;
    vector<int> dat, lazy;
    SegTree() {}
    SegTree(int n) {
        N = 1;
        while(N < n) N *= 2;
        dat.resize(2 * N, INF);//change!!
        lazy.resize(2 * N, -1);//change!!
    }
    //?????¶??????
    void lazy_evaluate(int k, int l, int r){
        if(lazy[k] != -1){//?????¶????????????
            dat[k] = lazy[k];
            if(k < N - 1){//k????????§???????????????????????¬
                lazy[k * 2 + 1] = lazy[k];
                lazy[k * 2 + 2] = lazy[k];
            }
            lazy[k] = -1;
        }
    }
    int marge(int x, int y){
        return min(x, y);//change!!
    }
    //replace x [a, b)
    void update(int a, int b, int x){ update(a, b, 0, 0, N, x); }
    void update(int a, int b, int k, int l, int r, int x){
        lazy_evaluate(k, l, r);        
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            lazy[k] = x;
            lazy_evaluate(k, l, r);
        }else{
            int m = (l + r) / 2;
            update(a, b, k * 2 + 1, l, m, x);
            update(a, b, k * 2 + 2, m, r, x);
            dat[k] = marge(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    // min [a, b)
    int query(int a, int b){ return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        lazy_evaluate(k, l, r);
        if(r <= a or b <= l) return INF;//change!!
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        int x = query(a, b, k * 2 + 1, l, m);
        int y = query(a, b, k * 2 + 2, m, r);
        return marge(x, y);
    }
};


signed main(){
    int n, q;
    cin >> n >> q;
    SegTree sg(n);
    rep(i, 0, q){
        int k, s, t, x;
        cin >> k;
        if(k == 0){
            cin >> s >> t >> x;
            sg.update(s, t + 1, x);
        }else{
            cin >> s;
            cout << sg.query(s, s + 1) << endl;
            //  rep(j, 0, n){
            //     cout << sg.dat[sg.N - 1 +  j] << " ";
            // }
            // rep(j, 0, sg.N * 2){
            //     cout << sg.dat[j] << " ";
            // }
            // cout << endl;
        }
    }
}

Measured memory_bytes: 7044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long answer = 0;

        for (long i = 1; i <= n; i++)
        {
            if (i % 3 != 0 && i % 5 != 0)
            {
                answer += i;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27388
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint INF = 1e15;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
struct Node {
  lint dist = INF;
  vector<int> nbr;
  vector<lint> cost;
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  REP(i, N) V.emplace_back();
  REP(i, M) {
    int a, b; lint c;
    cin >> a >> b >> c;
    a--; b--;
    V[a].nbr.push_back(b);
    V[a].cost.push_back(-c);
  }
  V[0].dist = 0;
  REP(k, N*2) REP(i, N) REP(j, V[i].nbr.size()) {
    if(k >= N && V[i].dist + V[i].cost[j] < V[V[i].nbr[j]].dist) {
      V[V[i].nbr[j]].dist = -INF;
    } else if(V[i].dist + V[i].cost[j] < V[V[i].nbr[j]].dist) {
      V[V[i].nbr[j]].dist = V[i].dist + V[i].cost[j];
    }
  }
  if(V[N-1].dist == -INF) cout << "inf" << endl;
  else cout << -V[N-1].dist << endl;
}

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

int main() {
	int w, h, x, y, r;

	cin >> w >> h >> x >> y >> r;

	//about x
	//w-x=r:touch
	//w-x>r:in
	//w-x<r:out

	//about y:
	//h-y=r:touch
	//h-y>r:in
	//h-y<r:out  

	if (x - r >= 0 && y - r >= 0 && w - x >= r&&h - y >= r) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;




}

   

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

int main(void)
{
  int n, i;
  ll a[100000];
  int count;
  ll ans = 0;
  ll max = -1000000000;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] < 0)
      count++;
    if (llabs(max) > llabs(a[i]))
        max = a[i];
    ans += llabs(a[i]);
  }
  if (count % 2 == 0)
    printf("%lld\n", ans);
  else
    printf("%lld\n", ans-2*llabs(max));
}


Measured memory_bytes: 896