akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	REP(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(all(a));
	int res = 0;
	REP(i, n) {
		auto itr = lower_bound(all(a), b[i]) - a.begin();
		if ((itr % 2) != (i % 2)) {
			res++;
		}
	}
	put(res/2);
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  int len = S.size() - 1;
  long long sum = 0;
  for (int bits = 0; bits < (1 << len); bits++) {
    int i0 = 0;
    for (int i = 0; i < len; i++) {
      if ((bits >> i) & 1) {
        string next = S.substr(i0, i - i0 + 1);
        sum += stol(next);
        i0 = i + 1;
      }
    }
    string last = S.substr(i0);
    sum += stol(last);
  }
  
  cout << sum << endl;
  return 0;
}

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


int main(){
   string s; 
   cin >> s;
   int m = 1000;
   rep(i,0,s.size()-2){
      int n = atoi(s.substr(i,3).c_str());
      m = min(m, abs(n - 753));
   }
   cout << m << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

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

    
    vector<Pi>ab(M);

    rep(i,M){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        ab[i]=mp(a,b);

    }
    ll ans=0;
    rep(i,M){
        UnionFind uf(N);
        rep(j,M){
            if(i!=j){
                uf.merge(ab[j].first, ab[j].second);

            }
        }
        ll flag=0;
        rep(i,N){
            rep(j,N){
                if(!uf.issame(i,j) && i!=j){
                    ans++;
                    flag=1;
                    break;
                }
            }
            if(flag==1){
                break;
            }
        }
        
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double x = Math.PI;
        double r = sc.nextDouble();
        
        double m=r*r*x;
        double n=r*2*x;
        
        System.out.printf("%.6f %.6f\n",m,n);
	sc.close();
    }
}


Measured memory_bytes: 28264
def nCr(n, r):
  return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

x, y = map(int, input().split())
mod = 10 ** 9 +7
f = [1]
 
for i in range(10**6):
  f.append(f[-1] * (i+1) % mod)
  
if (x+y) % 3 != 0 or (x+y) // 3 < abs(x-y):
  print(0)
  exit()
  
n = (x+y)//3
r = n // 2 - abs(x-y) // 2
print(nCr(n, r))

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

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

int main(void) {
	long long a, b;
	cin >> a >> b;
	cout << a * b / gcd(a, b);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,p[111111],ans,cnt;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&p[i]);
	for (int i=1;i<=n;i++)
	{
		if (p[i]==i) cnt++;
		else 
		{
			ans=ans+(cnt+1)/2;
			cnt=0;
		}
	}
	ans=ans+(cnt+1)/2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n, q;
  cin >> n >> q;
  vector<vector<int64_t>> C(q, vector<int64_t>(3));
  rep(i, q) {
    cin >> C[i][0] >> C[i][1] >> C[i][2];
  }

  dsu d(n);
  rep(i, q) {
    if (C[i][0] == 0) {
      d.merge(C[i][1], C[i][2]);
    }
    else {
      cout << (int)(d.same(C[i][1], C[i][2])) << endl;
    }
  }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  int k;
  cin >> k >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ans = max(ans, a[0] + k - a[n - 1]);
  for (int i = 1; i < n - 1; ++i) ans = max(ans, a[i + 1] - a[i]);
  cout << k - ans;
  return 0;
}



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

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i=0; i<N; i++) cin >> S.at(i);
    sort(S.begin(), S.end());
    string sum = "";
    for (int i=0; i<N; i++) sum += S.at(i);
    cout << sum << endl;
}

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

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int A = V[0];
            int B = V[1];
            Console.WriteLine(Math.Max(A, B) <= 8 ? "Yay!" : ":(");
        }
    }
}


Measured memory_bytes: 11092
M = ['North','East','West','South','Right','Left']
while 1:
    n = int(input())
    if n == 0:
        break
    D = [1,2,3]
    s = 1
    for i in range(n):
        m = input()
        if m == M[0]:
            D[0],D[1] = D[1],7-D[0]
        elif m == M[1]:
            D[0],D[2] = 7-D[2],D[0]
        elif m == M[2]:
            D[0],D[2] = D[2],7-D[0]
        elif m == M[3]:
            D[0],D[1] = 7-D[1],D[0]
        elif m == M[4]:
            D[1],D[2] = D[2],7-D[1]
        else:
            D[1],D[2] = 7-D[2],D[1]
        s += D[0]
    print (s)



Measured memory_bytes: 5620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

static const int N_MAX = 100000;
int n;
int m;
vector<pair<int, int>> graph[N_MAX];
int x[N_MAX];
int visited[N_MAX];

bool bfs(int i)
{
    queue<int> q;
    visited[i] = 1;
    x[i] = 0;
    q.push(i);
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (const auto& e : graph[v])
        {
            if (!visited[e.first])
            {
                x[e.first] = x[v] + e.second;
                visited[e.first] = 1;
                q.push(e.first);
            }
        }
    }
    return true;
}

void dfs(int i)
{
    visited[i] = 1;
    for (const auto& e : graph[i])
    {
        if (!visited[e.first])
        {
            x[e.first] = x[i] + e.second;
            dfs(e.first);
        }
    }
}

int main(int argc, char *argv[])
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; ++i)
    {
        int l, r, d;
        scanf("%d %d %d", &l, &r, &d);
        l--;
        r--;
        graph[l].push_back({r, d});
        graph[r].push_back({l, -d});
    }
    for (int i = 0; i < n; i++)
    {
        x[i] = 0;
        visited[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        if (!visited[i])
            bfs(i);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < graph[i].size(); ++j)
        {
            if (x[graph[i][j].first] - x[i]  != graph[i][j].second)
            {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
}


Measured memory_bytes: 9728
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	char s[3];
	int c = 0;
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
		if (s[i] == '1')
			c++;
	}
	cout << c << endl;
}

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


/**
 * AIZU ONLINE JUDGE
 * 3137
 *  2020/5/3
 */
public class Main {


    boolean main() throws IOException {

        Scanner sc = new Scanner(systemin);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int sum = a+b+c+d;

        int s1 = Math.abs(sum - (a+b)*2);
        int s2 = Math.abs(sum-(a+c)*2);
        int s3 = Math.abs(sum-(a+d)*2);
        int min = Math.min(s1, Math.min(s2, s3));


        System.out.printf("%d\n", min);

        sc.close();
        return false;
    }



    PrintStream log;
    PrintStream result = System.out;
    BufferedReader systemin;

    static Main instance = new Main();

    Main() {
        systemin = new BufferedReader(new InputStreamReader(System.in));
        log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    }

    public static void main(String[] args) throws IOException {

        instance.main();

        instance.systemin.close();
    }


}




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

int main(){
	ll n, city[5], mn;
	cin >> n;
	rep(i, 5){
		cin >> city[i];
		if(i == 0 || mn > city[i]) mn = city[i];
	}
	if(mn < n)cout << ((n+mn-1)/mn) + 4 << endl;
	else cout << 5 << endl;
	
	return 0;
}

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

int main() {
	string w,a="Yes";
	cin>>w;
	int hist['z'+1];
	fill(hist+'a',hist+'z'+1,0);
	for(int i=0;i<w.size();i++){
		if(hist[w[i]])	hist[w[i]]--;
		else	hist[w[i]]++;
	}
	for(int i='a';i<='z';i++){
		if(hist[i]){
			a="No";
			break;
		}
	}
	
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
n,c = map(int,input().split())
stc = [list(map(int,input().split())) for i in range(n)]
stc.sort()


R = [[stc[0][1],stc[0][2]]]
for s,t,c in stc[1:]:
    for i in range(len(R)):
        tr,cr = R[i][0],R[i][1]
        if c == cr and tr <=s:
            R[i] = [t,c]
            break
        if c!=cr and tr <s:
            R[i] = [t,c]
            break
    else:
        R.append([t,c])

print(len(R))

Measured memory_bytes: 28276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

ll n;
vi A;

ll cost(ll l, ll r, ll E) {
    ll sm_1 = 0;
    rep(i,l,r+1) {
        sm_1 += A[i];
    }
    return sm_1;
}

ll memo[410][410];

ll dp(ll l, ll r) {
    if(l == r) return 0;
    if(memo[l][r] != -1) return memo[l][r];
    ll ans = dp(l,l)+dp(l+1,r) + cost(l,r,l);
    rep(i,l,r) {
        ans = min(ans, dp(l,i) + dp(i+1,r) + cost(l,r,i));
    }
    return memo[l][r] = ans;
}

int main() {
    cin.sync_with_stdio(false);
    cin >> n;
    A = vi(n);
    rep(i,0,n) cin >> A[i];
    memset(memo,-1,sizeof(memo));
    cout << dp(0,n-1) << endl;
    return 0;
}


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

using namespace std;

int main(int argc,char* argv[]){
  int a,b,tmp,figure=0;
  cin >> a >> b;
  tmp = b-a;
  for(int i=1;i<tmp;i++) figure += i;
  cout << figure-a << endl;
  return 0;
}


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

int main(){
    string str;
    while(getline(cin, str)){
        rep(i,str.size()){
            if(str[i] >= 'a' && str[i] <= 'z') printf("%c", str[i] - 32);
            else if(str[i] >= 'A' && str[i] <= 'Z') printf("%c", str[i] + 32);
            else cout << str[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 1176
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(s,n) for(int i = s; i < n; i++)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	char str[101];

	while(cin >> str){
		int j = 0;
		while(str[j]){
			if(str[j] == '@'){
				range(0, str[j + 1] - '0'){
					printf("%c",str[j + 2]);
				}
				j += 3;
			}else{
				printf("%c",str[j]);
				j++;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1124
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, k = ns()
    pos = []
    for _ in range(n):
        x, y = ns()
        pos.append((x, y))

    ans = INF
    for tmp in itertools.combinations_with_replacement(pos, 4):
        xl = max(tmp, key=lambda t: t[0])[0]
        xs = min(tmp, key=lambda t: t[0])[0]
        yl = max(tmp, key=lambda t: t[1])[1]
        ys = min(tmp, key=lambda t: t[1])[1]

        cnt = 0
        for xi, yi in pos:
            if xs <= xi <= xl and ys <= yi <= yl:
                cnt += 1
        if cnt >= k:
            ans = min(ans, (xl - xs) * (yl - ys))

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        string L;
        cin >> L;
        ll N = len(L);

        ll ans = 0;
        ll cnt1 = 0;
        rep(i, 0, N) {
                if (L[i] == '1') {
                        ll r = N - i - 1;
                        ll t1 = modc(2, '^', cnt1);
                        ll t2 = modc(3, '^', r);
                        ans = modc(ans, '+', modc(t1, '*', t2));
                        ++cnt1;
                }
        }
        ans = modc(ans, '+', modc(2, '^', cnt1));

        cout << ans << endl;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
#define pi 3.1415926535897
int gcd(int a, int b) {
	if (b != 0) return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n, k; cin >> n >> k;
	vector<int> v;
	rep(i, n){
		int a; cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	int sum = 0;
	rep(i, k){
		sum += v[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 3616
from fractions import gcd 

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

def lcm(a,b):
   return a*b//gcd(a,b)

lcm_number=1

for i in range(N):
   lcm_number=lcm(lcm_number,A[i])

count=0
for i in range(N):
   count+=lcm_number//A[i]

print(count%(10**9+7))

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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;

  // 解答
  cout << (N < 1000 ? "ABC" : "ABD") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int n = sc.nextInt();
        int[][] xya = new int[n][3];
        for (int i = 0; i < n; i++) {
            xya[i][0] = sc.nextInt();
            xya[i][1] = sc.nextInt();
            xya[i][2] = sc.nextInt();
        }

        int ans = solve(w, h, n, xya);
        System.out.println(ans);
    }

    static int solve(int w, int h, int n, int[][] xya) {

        int xMAX = w;
        int xMIN = 0;
        int yMAX = h;
        int yMIN = 0;
        for (int i = 0; i < n; i++) {
            int ptn = xya[i][2];

            // @formatter:off
            switch (ptn) {
                case 1: xMIN = Math.max(xya[i][0], xMIN); break;
                case 2: xMAX = Math.min(xya[i][0], xMAX); break;
                case 3: yMIN = Math.max(xya[i][1], yMIN); break;
                case 4: yMAX = Math.min(xya[i][1], yMAX); break;
            }
            // @formatter:on
        }
        int x = Math.max((xMAX - xMIN), 0);
        int y = Math.max((yMAX - yMIN), 0);

        return x * y;
    }
}


Measured memory_bytes: 21972
/*
AizuOnline A0067
Surface Area of Quadrangular Pyramid 
*/
#include <stdio.h>
#include <float.h>
#include <math.h>

main()
{

  int x,h;
  double dx,dh;
  double V;
  
  while(EOF != scanf(" %d",&x) &&
	EOF != scanf(" %d",&h) &&
	(x || h))
    {
      dx=(double)x;
      dh=(double)h;

      V = dx*dx+sqrt(dx*dx/4.0+dh*dh)*dx*2;
      printf("%f\n",V);
    }

return(0);
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var s = int.Parse(Console.ReadLine());
        var hash = new HashSet<int>();

        int current = s;
        hash.Add(s);
        int m = 2;
        while (true)
        {
            int next;
            if (current % 2 == 0)
            {
                next = current / 2;
            }
            else
            {
                next = 3 * current + 1;
            }
            if (hash.Contains(next))
            {
                break;
            }
            else
            {
                hash.Add(next);
            }
            current = next;
            m++;
        }

        Console.WriteLine(m);
    }

}



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

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

int main()
{
    int n;
    scanf("%d", &n);

    int inp[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &inp[i]);

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

    return 0;
}


Measured memory_bytes: 256
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        # 根への距離を管理
        self.weight = [0] * (n + 1)

    # 検索
    def find(self, x):  # xの親を返す
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            # 親の値を更新(アルゴリズムの高速化)
            self.par[x] = y
            return y  # 親

    # 併合
    # (xからyへの重みがw) = (y - x = W)
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # 既に同集合の場合
        if rx == ry:
            if self.diff(x, y) != w:
                print("No")
                exit()
        # 木の高さで処理を変えるのは高速化(木を低くする)のため
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w + self.weight[x] - self.weight[y]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


import sys
sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
lrd = []
for i in range(M):
    l, r, d = map(int, input().split())
    lrd.append([l, r, d])
w_union_find = WeightedUnionFind(N)
for i in range(M):
    l, r, d = lrd[i]
    w_union_find.union(l, r, d)
print("Yes")


Measured memory_bytes: 44872
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using tllll=tuple<ll,ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/

pll mov(int y, int x, int v){
	vi dx={0,1,1,0,-1,-1},dy={1,0,-1,-1,-1,0,1,1,0,-1,0,1};
	return pll(y+dy[v+(abs(x)%2*6)],x+dx[v]);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll sx,sy,gx,gy,n,lx,ly;
	cin>>sx>>sy>>gx>>gy>>n;
	vvb w(203,vb(203,false));
	rep(i,n){
		int x,y;
		cin>>x>>y;
		w[y+101][x+101]=true;
	}
	cin>>lx>>ly;
	rep(i,203){
		w[ly+102][i]=true;
		w[100-ly][i]=true;
		w[i][lx+102]=true;
		w[i][100-lx]=true;
	}
	vector<vvi> dist(203,vvi(203,vi(6,INF)));

	deque<tllll> q;
	q.emplace_back(sy,sx,0,0);
	while(!q.empty()){
		int y,x,t,d;
		tie(y,x,t,d)=q.front();
		q.pop_front();
		if(dist[y+101][x+101][t]!=INF)continue;
		dist[y+101][x+101][t]=d;
		
		rep(v,6){ //iは方向
			int ny,nx;
			tie(ny,nx) = mov(y,x,v);
			if(w[ny+101][nx+101]) continue;
			if(v==abs(x*y*t)%6){
				q.emplace_front(ny,nx,(t+1)%6,d);
			}else{
				q.emplace_back(ny,nx,(t+1)%6,d+1);
			}
			q.emplace_back(y,x,(t+1)%6,d+1);
		}
	}

	int ans=min(dist[gy+101][gx+101]);
	if(ans==INF) puta(-1);
	else puta(ans);
	return 0;
}


Measured memory_bytes: 7836
def main():
    N = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(N - 1)]

    to = [[] for _ in range(N)]
    for a, b in ab:
        to[a - 1].append(b - 1)
        to[b - 1].append(a - 1)

    c1 = list(range(1, N + 1, 3))
    c2 = list(range(2, N + 1, 3))
    c3 = list(range(3, N + 1, 3))

    color = [0] * N

    for root in range(N):
        if len(to[root]) == 1:
            break

    queue = set([root])
    color[root] = 1
    while queue:
        v = queue.pop()
        color_v = color[v]
        for i in to[v]:
            if color[i] == 0:
                color[i] = 3 - color_v
                queue.add(i)

    ans = [0] * N
    order = sorted(range(N), key=lambda x: color[x])
    if color.count(1) <= N / 3:
        for i in order:
            if c3:
                ans[i] = c3.pop(-1)
            elif c1:
                ans[i] = c1.pop(-1)
            else:
                ans[i] = c2.pop(-1)
    elif color.count(2) <= N / 3:
        for i in reversed(order):
            if c3:
                ans[i] = c3.pop(-1)
            elif c1:
                ans[i] = c1.pop(-1)
            else:
                ans[i] = c2.pop(-1)
    else:
        for i in range(N):
            if (color[i] == 1) and c1:
                ans[i] = c1.pop(-1)
            elif (color[i] == 2) and c2:
                ans[i] = c2.pop(-1)
            else:
                ans[i] = c3.pop(-1)

    print(*ans)


main()


Measured memory_bytes: 97220
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m,q;
  cin >> n >> m >> q;
  vi a(q), b(q), c(q), d(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  int ans = 0;
  for(int i1 = 1; i1 <= m; i1++){
    for(int i2 = i1; i2 <= m; i2++){
      for(int i3 = i2; i3 <= m; i3++){
        for(int i4 = i3; i4 <= m; i4++){
          for(int i5 = i4; i5 <= m; i5++){
            for(int i6 = i5; i6 <= m; i6++){
              for(int i7 = i6; i7 <= m; i7++){
                for(int i8 = i7; i8 <= m; i8++){
                  for(int i9 = i8; i9 <= m; i9++){
                    for(int i10 = i9; i10 <= m; i10++){
                      vi check{i1,i2,i3,i4,i5,i6,i7,i8,i9,i10};
                      int total = 0;
                      rep(i, q){
                        if(check[b[i] - 1] - check[a[i] - 1] == c[i]) total += d[i];
                      }
                      ans = ans < total ? total : ans;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
vi sq;
vi sqa;
bool w[100100];
int main()
{
	while(1)
	{
		int n,k;
		int ans=0;
		cin >> n >> k;
		sqa.clear();
		sq.clear();
		memset(w,false,sizeof(w));
		if(n==0&&k==0)break;
		bool flag=false;
		for(int i=0;i<k;i++)
		{
			int c;
			cin >> c;
			if(c==0)
			{
				flag=true;
				continue;
			}
			w[c]=true;
		}
		int cnt=0;
		for(int i=1;i<=n;i++)
		{
			if(w[i])
			{
				cnt++;
			}
			else
			{
				sq.pb(cnt);
				cnt=0;
			}
		}
		sq.pb(cnt);
		if(!(flag))
		{
			for(int i=0;i<sz(sq);i++)
			{
				ans=max(ans,sq[i]);
			}
			cout << ans << endl;
		}
		else
		{
			for(int i=0;i<sz(sq)-1;i++)
			{
				sqa.pb(sq[i]+sq[i+1]);
			}
			sort(sqa.begin(),sqa.end(),greater<int>());
			cout << sqa[0]+1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1536
N, M, X = list(map(int, input().split()))
CA = [list(map(int, input().split())) for _ in range(N)]

inf = 10 ** 20
mi = inf

for i in range(1 << N):
  L = [0] * M
  c = 0
  for j in range(N):
    t = i & (1 << j)
    if t == 0: continue
    c += CA[j][0]
    for k in range(M):
      L[k] += CA[j][k + 1]
  for j in L:
    if j < X: break
  else:
    mi = min(mi, c)

if mi == inf:
  print(-1)
else:
  print(mi)

Measured memory_bytes: 68556
# https://beta.atcoder.jp/contests/abc074/tasks/abc074_b


def solve():
    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))

    total = 0
    for i in range(N):
        total += min(abs(K - x[i]), abs(0 - x[i])) * 2
    print(total)


if __name__ == '__main__':
    solve()


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

ll counter(ll from,ll to,ll mod){
  return to/mod-from/mod+(from%mod==0);
}

int main(){
  ll  s;
  cin>>s;
  ll ten[19];
  ten[0]=1;
  for(int i=1;i<19;i++){
    ten[i]=ten[i-1]*10;
  }
  ll lb=1;
  ll ub=s+1;
  ll cnt=0;
  bool isloop=true;
  //lb-1madenis-1moji
  while(isloop){
    if(ub-lb<=1){
      isloop=false;
    }
    ll mid=(lb+ub)/2;
    //mid made kazoeru
    cnt=0;
    int size;
    for(int i=0;i<19;i++){
      if(mid<ten[i+1]){
	size=i;
	break;
      }
      //ten[i+1]-1 to ten[i]
      ll cnt3=counter(ten[i],ten[i+1]-1,3);
      ll cnt5=counter(ten[i],ten[i+1]-1,5);
      ll cnt15=counter(ten[i],ten[i+1]-1,15);
      ll non=cnt3+cnt5-cnt15;
      cnt+=(ten[i+1]-ten[i]-non)*(i+1)+(cnt3+cnt5)*4;
    }
    ll cnt3=counter(ten[size],mid,3);
    ll cnt5=counter(ten[size],mid,5);
    ll cnt15=counter(ten[size],mid,15);
    ll non=cnt3+cnt5-cnt15;
    cnt+=(mid-ten[size]+1-non)*(size+1)+(cnt3+cnt5)*4;
    if(cnt<=s){
      lb=mid;
    }
    else{
      ub=mid;
    }

  }
  
  string res="";
  for(ll i=lb;res.size()<100;i++){
    if(i%3==0 && i%5==0){
      res+="FizzBuzz";
    }
    else if(i%3==0){
      res+="Fizz";
    }
    else if(i%5==0){
      res+="Buzz";
    }
    else{
      res+=to_string(i);
    }
  }
  int hoge=0;
  ll i=lb;
  if(i%3==0 || i%5==0){
    if(i%3==0){
      hoge+=4;
    }
    if(i%5==0){
      hoge+=4;
    }
  }
  else{
    hoge+=to_string(i).size();
  }
  
  cout<<res.substr(s-(cnt-hoge)-1,20)<<endl;
  return 0;
}

Measured memory_bytes: 3268
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    for(int i = A; i <= B; i++) {
        if( i%K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
n = int(raw_input())
#stable = 1

class Card():
    __slots__ = ('suit', 'value')

#mergeSort
A = [Card() for _ in xrange(n)]
#quickSort
B = [Card() for _ in xrange(n)]

s = set()
for i in xrange(n):
    a = raw_input().split()
    A[i].suit = a[0]
    B[i].suit = a[0]
    A[i].value = int(a[1])
    B[i].value = int(a[1])
    s.add(int(a[1]))

def partition(A, p, r):
    x = A[r].value
    i = p-1
    for j in xrange(p,r):
        if A[j].value <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[i+1]
    A[i+1] = A[r]
    A[r] = tmp
    return i+1

def quickSort(A,p,r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q, r)
    return 0

quickSort(B, 0, n-1)

for i in s:
    if [d.suit for d in A if d.value == i] != [d.suit for d in B if d.value == i]:
        print('Not stable')
        break
else:
    print('Stable')

for i in xrange(n):
    print B[i].suit, B[i].value

Measured memory_bytes: 84896
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n, i;
    cin >> n >> i;
    cout << n + 1 - i << endl;
}


Measured memory_bytes: 3584
n, m = gets.split.map(&:to_i)

MOD = 1_000_000_007

as = Array.new(n + 3, 0)
m.times do
  a = gets.to_i
  as[a] = -1
end

as[0] = 1

0.upto(n) do |i|
  next if as[i] == -1
  
  if as[i + 1] != -1
    as[i + 1] += as[i]
    as[i + 1] %= MOD
  end

  if as[i + 2] != -1
    as[i + 2] += as[i]
    as[i + 2] %= MOD
  end
end

if as[n] != -1
  p as[n]
else
  p 0
end



Measured memory_bytes: 2812
N, C, K = map(int, input().split())
a = []
for i in range(N):
    a.append(int(input()))

a.sort()
ans = 1
count = 0
pre = a[0]
for i in range(N):
    if count == 0:
        pre = a[i]
    if count >= C or a[i]-pre > K:
        count = 0
        ans += 1
        pre = a[i]
    count += 1
print(ans)


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

A = [0]*4

for _ in range(n):
    n = input()
    if n == "AC":
        A[0] += 1
    elif n == "WA":
        A[1] += 1
    elif n == "TLE":
        A[2] += 1
    else:
        A[3] += 1

print("AC x", A[0])
print("WA x", A[1])
print("TLE x", A[2])
print("RE x", A[3])

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int lli;

string charset[10][5] = {
	{},
	{".", ",", "!", "?", " "},
	{"a", "b", "c"},
	{"d", "e", "f"},
	{"g", "h", "i"},
	{"j", "k", "l"},
	{"m", "n", "o"},
	{"p", "q", "r", "s"},
	{"t", "u", "v"},
	{"w", "x", "y", "z"}
};
int loop[10] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};

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

	int N;
	cin >> N;
	vector<string> ansvec;
	for (int n = 0; n < N; n++){
		string s;
		cin >> s;

		int i = 0;
		int push = -1;
		string ans = "";
		while (i < s.length()){
			int num = stoi(s.substr(i, 1));
			if (num != 0){
				int thisnum = num;
				while (num != 0){
					push++;
					i++;
					num = stoi(s.substr(i, 1));
				}
				ans += charset[thisnum][push % loop[thisnum]];
				push = -1;
			}
			i++;
		}
		ansvec.push_back(ans);
	}

	for (auto it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it << endl;
	}
	return 0;
}

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

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    //vector<vector<int>> G(n);
    //rep(i,n) G(i)
    int ans[n];
    memset(ans,0,sizeof(ans));

    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(i<=x){
                if(j<=x) ans[j-i]++;
                else if(j>x && j<y){
                    int temp=min((x-i)+1+(y-j),j-i);
                    ans[temp]++;
                }
                else{
                    ans[x-i+1+j-y]++;
                }
            }
            else if(i>x && i<y){
                int temp=min(j-i,i-x+1+abs(j-y));
                ans[temp]++;
            }
            else{
                if(j<n){
                    ans[j-i]++;
                }
                else continue;
            }
        }
    }

    rep(i,n){
        if(i==0) continue;
        cout << ans[i] << endl;
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, n) for (ll i=0;i<(n); i++)
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; }
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
//using ll=long long;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;

const long double PI=3.14159265358979323846;

ll k, cnt;
ll ans;
map<ll, string> m;
queue<string> q;

template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}



int main(){
  cin>>k;

  rep(i, 9){
    q.push(to_string(i+1));
  }
  string s;
  cnt = 0;
  while(true){
    s = q.front();
    //cout << s<<" "<<cnt<<endl;
    cnt++;
    //if(cnt>100000) break;
    if(cnt>100000) break;
    m[cnt] = s;
    q.pop();
    char t = s.back();
    //cout << t<<endl;
    if (t=='0'){
      q.push(s+"0");
      q.push(s+"1");
    }
    else if (t=='9'){
      q.push(s+"8");
      q.push(s+"9");
    }
    else{
      // cout <<"#"<<int(t-'0')<<" "<<t<<endl;
      q.push(s+to_string(int(t-'0')-1));
      q.push(s+to_string(int(t-'0')));
      q.push(s+to_string(int(t-'0')+1));
    }

  }
  cout << m[k] << endl;
}


Measured memory_bytes: 22016
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  int ans=-1000000000,M=1000000000,i;
  for(i=0; i<n; i++) {
    int x;
    scanf("%d",&x);
    if(i && x-M>ans) ans=x-M;
    if(M>x) M=x;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

void dfs(ll prev, ll cur, VVI& g, VI& add) {
	REP(i, g[cur].size()) if(g[cur][i]!=prev) {
		ll ni = g[cur][i];
		add[ni]+=add[cur];
		dfs(cur, ni, g, add);
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,Q,a,b,p,x;
	while(cin>>N>>Q) {
		VVI g(N);
		REP(i, N-1) {
			cin>>a>>b;
			a--;b--;
			g[a].PB(b);
			g[b].PB(a);
		}
		VI add(N);
		REP(i, Q) {
			cin>>p>>x;
			p--;
			add[p]+=x;
		}
		dfs(-1, 0, g, add);
		
		cout<<add<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 30592
#include <stdio.h>
#include <ctype.h>

int main(void) {
	
	char c;
	
	for(;;){	
		
		scanf("%c",&c);
		if (islower(c) != 0) 
			printf("%c",toupper(c));
		else if (isupper(c) != 0) 
			printf("%c",tolower(c));
		else if (c == '\n') 
			break;
		else if (islower(c) == 0)
			printf("%c",c);
		else{break;}
	}
	
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
 
int main() {
  string S; cin >>S;
  bool hantei=true;
  int count=0;
  if(S[0]!='A')hantei=false;
  if(S[1]<97||S[1]>127)hantei=false;
  if(S[S.size()-1]<97||S[S.size()-1]>122)hantei=false;
  rep2(i,2,S.size()-1){
      int a;
      a=S[i];
      if(S[i]<97||S[i]>122){
        if(S[i]=='C'&&count==0){
          count++;
        }else{
          hantei=false;
        }
      }
  }
  if(count!=1)hantei=false;
  if(hantei){
    cout<<"AC"<<endl;
  }else{
    cout<<"WA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256