akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(4100000)

def Dfs(G, v, n, visited):
    all_visited = True
  
    for i in range(n):
      if visited[i] == False:
        all_visited = False
 
    if all_visited:
        return 1
 
    ret = 0
 
    for i in range(n):
        if not G[v][i]:
            continue
        if visited[i]:
            continue
        visited[i] = True
        ret += Dfs(G, i, n, visited)
        visited[i] = False
 
    return ret

 
def main():
    input =  sys.stdin.readline
    n, m = map(int, input().split())
    e = [list(map(int, input().split())) for i in range(m)]
    g = [[False for j in range(n)] for i in range(n)]
    for i, j in e:
        g[i-1][j-1] = True
        g[j-1][i-1] = True
    visited = [False for i in range(n)]
    visited[0] = True
    
    print(Dfs(g, 0, n, visited))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,a[101],t,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
scanf("%d",&a[i]);
  }
  for(j=i-1;j>=0;j--){

    if(j==0){printf("%d",a[j]);
      printf("\n");}
    else printf("%d ",a[j]);

  }
  return 0;
}

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

using namespace std;

int main() {

	long long n;
	cin >> n;

	string s = "";

	while (n > 0) {
		long long j = n % 26;
		if (j == 0) { j = 26; n--; }
		s.push_back((char)('a' - 1 + j));
		if (n == 26) { break; }
		n /= 26;

	}

	reverse(s.begin(), s.end());

	cout << s << endl;

	return 0;

}

Measured memory_bytes: 3620
s=int(input())
cnt=[]
flag=0
cnt.append(s)
i=0

while flag==0:
  i+=1
  if s%2==0:
    s=int(s/2)
    m=len(cnt)
    cnt.append(s)
    
    n=len(set(cnt))
    if m==n:
      ans=i
      break
  else:
    s=3*s+1
    m=len(cnt)
    cnt.append(s)
    
    n=len(set(cnt))
    if m==n:
      ans=i
      break
  
print(ans+1)    
  
  

Measured memory_bytes: 3064
import sys
input = lambda: sys.stdin.readline().rstrip()

# SegmentTree
class SegmentTree:
  def __init__(self,n,p,unit,f):
    self.num=2**((n-1).bit_length())
    self.seg=[unit]*(2*self.num)
    for i in range(n):self.seg[i+self.num]=p[i]
    for i in range(self.num-1,0,-1):
      self.seg[i]=f(self.seg[i<<1],self.seg[(i<<1)+1])
    self.f=f
    self.unit=unit
  def update(self,i,x):
    i+=self.num
    self.seg[i]=x
    while i:
      i>>=1
      self.seg[i]=self.f(self.seg[i<<1],self.seg[(i<<1)+1])
  def query(self,l,r):
    ansl=ansr=self.unit
    l+=self.num
    r+=self.num-1
    if l==r:
      return self.seg[l]
    f=self.f
    while l<r:
      if l&1:
        ansl=f(ansl,self.seg[l])
        l+=1
      if ~r&1:
        ansr=f(self.seg[r],ansr)
        r-=1
      l>>=1
      r>>=1
    if l==r:
      ansl=f(ansl,self.seg[l])
    return f(ansl,ansr)


n,q=map(int,input().split())
a=list(map(int,input().split()))
f=lambda x,y: max(x,y)
seg=SegmentTree(n,a,0,f)
for _ in range(q):
  t,a,b=map(int,input().split())
  if t==1:
    seg.update(a-1,b)
  if t==2:
    print(seg.query(a-1,b))
  if t==3:
    ng=a-1
    ok=n+1
    while ng+1!=ok:
      mid=(ng+ok)//2
      if seg.query(ng,mid)>=b:ok=mid
      else:ng=mid
    print(ok)


Measured memory_bytes: 99272
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

S = input()
T = input()

ans = 0
for s, t in zip(S, T):
    if s != t:
        ans += 1

print(ans)


Measured memory_bytes: 68856
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define lld long long

int main(){
    int n;
    cin >> n;
    if(n%2 == 0){
        cout << n/2 << endl;
    } else {
        cout << n/2+1 << endl;
    }
}

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

struct SegmentTree {
  struct Node {
    int node, lazy;
    Node() {}
    Node(int node, int lazy) : node(node), lazy(lazy) {}

    Node operator*(const Node &r) const {
      return Node(min(node, r.node), -1);
    }
  };

  Node e = Node(INT_MAX, -1);
  size_t n;
  vector<Node> seg;

  SegmentTree(size_t size) : n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n - 1, e) {}

  inline void lazy_evaluate(int k) {
    if (seg[k].lazy != -1) {
      seg[k].node = seg[k].lazy;
      if (k < n - 1) {
        seg[2 * k + 1].lazy = seg[k].lazy;
        seg[2 * k + 2].lazy = seg[k].lazy;
      }
      seg[k].lazy = -1;
    }
  }

  inline void update_node(int k) {
    seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
  }

  void update(int l, int r, int x, int k, int a, int b) {
    lazy_evaluate(k);

    if (r <= a || b <= l) return;
    if (l <= a && b <= r) {
      seg[k].lazy = x;
      lazy_evaluate(k);
      return;
    }

    update(l, r, x, 2 * k + 1, a, (a + b) / 2);
    update(l, r, x, 2 * k + 2, (a + b) / 2, b);
    update_node(k);
  }

  Node query(int l, int r, int k, int a, int b) {
    lazy_evaluate(k);
    if (r <= a || b <= l) return e;
    if (l <= a && b <= r) return seg[k];

    return query(l, r, 2 * k + 1, a, (a + b) / 2) * query(l, r, 2 * k + 2, (a + b) / 2, b);
  }

  void update(int l, int r, int x) {
    update(l, r, x, 0, 0, n);
  }

  int query(int l, int r) {
    return query(l, r, 0, 0, n).node;
  }
};

int main() {
  int n, q;
  cin >> n >> q;

  SegmentTree seg(n);

  while (q--) {
    int c;
    cin >> c;

    if (c) {
      int l, r;
      cin >> l >> r;
      cout << seg.query(l, r + 1) << endl;
    } else {
      int l, r, x;
      cin >> l >> r >> x;
      seg.update(l, r + 1, x);
    }
  }
}

Measured memory_bytes: 4952
#include<bits/stdc++.h>
using namespace std;
int main(){
	int letter[26]={0};
	char ch[100010];
	scanf("%s",ch);
	for(int i=0;i<strlen(ch);i++) letter[ch[i]-'a']++;
	for(int i=0;i<26;i++){
		if(letter[i]==0){
			cout<<(char)('a'+i)<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int i;
	int N;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);

	printf("%d\n", ((N+1)*N)/2);

	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,v,p; cin>>n>>m>>v>>p;
    vll a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    ll l=-1, r=n-1; //Right OK
    while(r-l>1){
        ll mid = (l+r)/2;

        ll rest = m*(v-mid-p);
        ll cand = a[mid]+m;
        bool ng=false;
        for(int i=mid+1; i<n-p+1; i++){
            rest -= cand-a[i];
            if (cand<a[i]){
                ng = true;
                break;
            }
        }
        if (rest>0) ng = true;
        if (ng){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout<<n-l-1<<endl;
    return 0;
}


Measured memory_bytes: 1024
# ABC 109: B – Shiritori
n = int(input())
w = [input() for _ in range(n)]

is_satisfied = 'Yes'

if len(w) != len(set(w)):
    is_satisfied = 'No'
else:
    for i in range(1, len(w)):
        if w[i][0] != w[i - 1][-1]:
            is_satisfied = 'No'
            break

print(is_satisfied)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int R = sc.nextInt();

            int result = R;

            if (N < 10) {
                result += 100 * (10 - N);
            }

            System.out.println(result);

        }
    }

}

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

int main() {
  string s1s2s3;
  cin >> s1s2s3;
  int s1 = stoi(s1s2s3.substr(0,1));
  int s2 = stoi(s1s2s3.substr(1,1));
  int s3 = stoi(s1s2s3.substr(2,1));
  cout <<  s1+s2+s3 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] x = new int[n][2];
        int[][] xpos = new int[n][2];
        int[][] ypos = new int[n][2];
        for(int i=0; i<n; i++){
            x[i][0] = sc.nextInt();
            x[i][1] = sc.nextInt();
            xpos[i][0] = i;
            xpos[i][1] = x[i][0];
            ypos[i][0] = i;
            ypos[i][1] = x[i][1];
        }
        
        Arrays.sort(xpos, (a, b) -> Integer.compare(a[1], b[1]));
        Arrays.sort(ypos, (a, b) -> Integer.compare(a[1], b[1]));

        int[][] xroad = new int[n*2-2][3];
        for(int i=0; i<n-1; i++){
            xroad[i*2][0] = xpos[i][0];
            xroad[i*2][1] = xpos[i+1][0];
            xroad[i*2][2] = xpos[i+1][1] - xpos [i][1];
            xroad[i*2+1][0] = ypos[i][0];
            xroad[i*2+1][1] = ypos[i+1][0];
            xroad[i*2+1][2] = ypos[i+1][1] - ypos [i][1];
        }

        Arrays.sort(xroad, (a, b) -> Integer.compare(a[2], b[2]));

        UnionFindTree uft = new UnionFindTree(n);
        long ans = 0;

        for(int i=0; i<n*2-2; i++){
            int[] thisroad = xroad[i];
            if(!uft.same(thisroad[0], thisroad[1])){
                ans += thisroad[2];
                uft.unite(thisroad[0], thisroad[1]);
            }
        }

        System.out.println(ans);

    }    
}

class UnionFindTree{
    int[] par;
    int[] rank;

    public UnionFindTree(int size){
        par = new int[size];
        rank = new int[size];
        for(int i=0; i<size; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

    public int find(int x){
        if(par[x] == x){
            return x;
        }else {
            return par[x] = find(par[x]);
        }
    }

    public void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    public boolean same(int x, int y){
        return find(x) == find(y);
    }
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

#include <boost/range/algorithm.hpp> // boost::sort(arr)


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

  int n, m;
  cin >> n >> m;
  vector<tuple<long long, int, int>> pref_year_city;
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    pref_year_city.emplace_back(p, y, i);
  }
  boost::sort(pref_year_city);
  unordered_map<int, long long> city_pref_cnt;
  int cnt = 0;
  int prev_p = 0;
  for(auto & pyc : pref_year_city) {
    if (get<0>(pyc) == prev_p) {
      ++cnt;
    } else {
      cnt = 1;
    }
    prev_p = get<0>(pyc);
    city_pref_cnt[get<2>(pyc)] = get<0>(pyc) * 1000000 + cnt;
  }
  rep(i, m) {
    cout << setfill('0') << setw(12) << city_pref_cnt[i] << endl;
  }
}


Measured memory_bytes: 8944
#include <iostream>

int main(){
    int n = 0;
    int x = 0;
    int decimal;

    std::cin >> n;
    decimal = (n * 100) % 108;

    if(decimal == 0){
        std::cout << (n * 100)/108 << std::endl;
    }
    else if(decimal != 0){
        x = ((n * 100 - decimal) / 108) + 1;
        if((x * 108 - n * 100) < 100){
            std::cout << x << std::endl;
        }
        else if(x * 108 != n * 100){
            std::cout << ":(" << std::endl;
        }
    }

    return 0;

}

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

#define mp make_pair
#define pb push_back
#define F first
#define S second

using namespace std;

int n;
vector < pair <int, int> > ans;

int main(){
	cin >> n;
	if(n % 2 == 0){
		for(int i = 1; i <= n; i++){
			for(int j = i + 1; j <= n; j++){
				if(i + j != n + 1) ans.pb(mp(i , j));
			}
		}
	}
	else{
		for(int i = 1; i <= n; i++){
			for(int j = 1; j < i; j++){
				if(n - j != i){
					ans.pb(mp(i , j));
				}
			}
		}
	}
	cout << ans.size() << "\n";
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i].F << " " << ans[i].S << "\n";
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long K;

int main()
{
    while (cin >> K) {
        vector<long long> res(50, 49);
        long long p = K / 50;
        long long q = K % 50;
        
        for (int i = 0; i < q; ++i) {
            for (int j = 0; j < i; ++j) res[j]--;
            res[i] += 50;
            for (int j = i+1; j < 50; ++j) res[j]--;
        }
        
        for (int i = 0; i < 50; ++i) res[i] += p;
        
        cout << 50 << endl;
        for (int i = 0; i < 50; ++i) {
            cout << res[i];
            if (i != 49) cout << " ";
        }
        cout << endl;
    }
}















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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int M, N; cin >> N >> M;
    rep(i,M){
        int Ai; cin >> Ai;
        N -= Ai;
    }
    if(N<0) cout << -1 << endl;
    else cout << N << endl;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

int main() {
	int N;
	cin >> N;
	int sum = 0;
	int last;
	REP(i, 1, N+5) {
		sum += i;
		if (sum > N) {
			last = i;
			break;
		}
	}
	REP(i, 1, last+1) {
		if (sum - i == N) continue;
		cout << i << endl;
	}
	return 0;
}

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

Ss = input().rstrip()

lenS = len(Ss)

dp = [[0]*(13) for _ in range(lenS+1)]
dp[0][0] = 1
for i, S in enumerate(Ss):
    for j in range(13):
        dp[i][j] %= MOD
    if S != '?':
        S = int(S)
        for j in range(13):
            j2 = (j*10+S) % 13
            dp[i+1][j2] += dp[i][j]
    else:
        for S in range(10):
            for j in range(13):
                j2 = (j*10+S) % 13
                dp[i+1][j2] += dp[i][j]

ans = dp[lenS][5] % MOD
print(ans)


Measured memory_bytes: 61916
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
# define MOD 1000000000+7
# define INF 1e9
# define LINF 1e18
typedef long long ll;

using namespace std;
int gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
 

bool broken[100000] = {false};
int dp[100010] = {};

int unko[200000] = {}, geri[200000] = {};

int main() {
	/*
		int n = 0, m = 0;
		cin >> n >> m;

		for (int i = 0; i < m; i++) {
			int temp;
			cin >> temp;
			broken[temp] = true;
		}

		dp[0] = 1;

		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j <= min(i + 2, n); j++) {

				if (broken[j] == false) {
					dp[j] += dp[i];
					dp[j] %= MOD;
				}

			}
		}

		cout << dp[n] << endl;

		return 0;
		*/

	int n, m, k;
	int ans = 0;
	cin >> n >> m;
	vector<vector<int>> s(m);
	vector<int> p(m);

	for (int i = 0; i < m; i++) {
		cin >> k;
		s[i].resize(k);//s[i]の大きさを変えてあげる

		for (int j = 0; j < k; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}

	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}

	for (int bit = 0; bit < (1 << n); bit++) {//2^n列挙

		vector<int> on;

		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {//bitの0bと1をiシフトした数の0bのANDをとる
				on.push_back(i);
			}
		}

		bool ok = true;

		for (int i = 0; i < m; i++) {
			int oncnt = 0;

			for (int j = 0; j < s[i].size(); j++) {
				for (int k = 0; k < on.size(); k++) {
					if (s[i][j] == on[k]) {

						oncnt++;
					}
				}
			}

			if (oncnt % 2 != p[i]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans++;
		}
	}

	cout << ans << endl;

}




Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

def main():
    N = int(input())
    T = math.ceil((2*N)**0.5)
    rem = T*(T+1)//2 - N
    if rem > T:
      rem = T*(T-1)//2 - N
      T -= 1
    
    for i in range(T):
        if i+1 != rem:
            print(i+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3408
// IDE used VSCode with gcc plug-in
/*
Event: Codeforces Global Round 7
Author: miitbh1
*/
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <climits>
#include <iomanip>
#include <iostream>
#include <algorithm>


#define rep(i, n) for(int i=0; i<n; i++)
#define repA(i, a, n) for(int i=a; i<n; i++)
#define repD(i, a, n) for(int i=a; i>=n; i--)
#define trav(it, ctr) for(auto it=ctr.begin(); it!=ctr.end(); it++)
#define p(x) cout<<x<<"\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pp(x, y) cout<<x<<" "<<y<<"\n"
#define btc __builtin_popcount
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef priority_queue<int> pq;
typedef pair<int, int> ii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
using ll=long long int;
int N=100001, M=1e9+7;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, a="", b="";
    cin>>s;
    int n=s.length();
    bool f1=true, f2=true, f3=true;
    rep(i, n/2){
    	if(s[i]!=s[n-i-1]){
    		f1=false;
    		break;
    	}
    }
    rep(i, (n-1)/2){
    	a+=string{s[i]};
    }
    repA(i, (n+3)/2 -1, n){
    	b+=string{s[i]};
    }
    n=a.length();
    rep(i, n/2){
    	if(a[i]!=a[n-i-1]){
    		f2=false;
    		break;
    	}
    }
    n=b.length();
    rep(i, n/2){
    	if(b[i]!=b[n-i-1]){
    		f3=false;
    		break;
    	}
    }
    if(f1 and f2 and f3)p("Yes");
    else p("No");
    return 0;
}

Measured memory_bytes: 256
def ms_number(n):
    count = 1
    msnumber_list = [6]
    while msnumber_list[-1] < n:
        msnumber_list.append(7 * count + 1)
        msnumber_list.append(7 * count + 6)
        count += 1

    return msnumber_list[:-1]


def ms_prime(n, msnumber_list):
    msprime_list = []
    msprime_flag = [0 for i in range(n + 1)]

    for i in msnumber_list:
        if msprime_flag[i] == 0:
            msprime_list.append(i)
            for j in msnumber_list:
                if i * j > n:
                    break
                msprime_flag[i * j] = 1

    return msprime_list


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


msnumber_list = ms_number(300000)
msprime_list = ms_prime(300000, msnumber_list)

answer = []
input_list = []

while True:
    n = int(input())
    if n == 1:
        break

    input_list.append(n)
    divisors = make_divisors(n)

    answer.append([d for d in divisors if d in msprime_list])


for i in range(len(input_list)):
    print(str(input_list[i]) + ": ", end="")
    print(*answer[i])


Measured memory_bytes: 11808
#include <iostream>
#include <cstdio>
#define N 3005

using namespace std;

int n;
int a[N];
int head[N], nex[N << 1], to[N << 1], te;

inline void read(int &x) {
	x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
}
inline void ade(int u, int v) {
	nex[++te] = head[u], head[u] = te, to[te] = v;
}

bool dfs(int u) {
	bool flag = false;
	for(int i = head[u]; i; i = nex[i]) {
		int v = to[i];
		if(a[v] >= a[u]) continue;
		flag |= !dfs(v);
	}
	return flag;
}

int main() {
	read(n);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = 1, u, v; i < n; ++i) {
		read(u), read(v);
		ade(u, v), ade(v, u);
	}
	for(int i = 1; i <= n; ++i)
		if(dfs(i)) printf("%d ", i);
	putchar('\n');
	return 0;
}

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

int main () {
  string str;
  cin >> str;
  int count = 0;
  for(int i = 0; i < 3; i++) {
    if(str[i] == '1') count++;
  }
  cout << count << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  
  int a,n,c;
  double x,b;
  
  scanf("%d",&n);
  if(n%1000!=0){
    b=n/1000+1;
  }
  else{
    b=n/1000;
  }
  c=b*1000;
  printf("%d",c-n);
 
  return 0;
}

Measured memory_bytes: 1680
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long subsolve(int N, long long C, vector<long long> X, vector<long long> V) {
	vector<long long> VS(N + 1);
	for (int i = N - 1; i >= 0; --i) {
		VS[i] = VS[i + 1] + V[i];
	}
	long long ans = 0, opt = 0, TS = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(ans, opt - (C - X[i]) * 2 + VS[i]);
		TS += V[i];
		opt = max(opt, TS - X[i]);
	}
	ans = max(ans, opt);
	return ans;
}
int main() {
	int N; long long C;
	cin >> N >> C;
	vector<long long> X(N), V(N);
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> V[i];
	}
	long long ans1 = subsolve(N, C, X, V);
	for (int i = 0; i < N; ++i) X[i] = C - X[i];
	reverse(X.begin(), X.end());
	reverse(V.begin(), V.end());
	long long ans2 = subsolve(N, C, X, V);
	cout << max(ans1, ans2) << endl;
	return 0;
}

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

typedef long long int ll;
int main(){

int i, n, a, b, c, value, cont = 0;
vector<int> vec;
cin >> n;

while(n--){
    cin >> value;
    vec.push_back(value);
}

for( i = 1; i < vec.size() - 1; ++i)
    if(vec[i] < vec[i+1] && vec[i] > vec[i-1] || vec[i] > vec[i+1] && vec[i] < vec[i-1])
        cont++;

cout << cont << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vc vector<char> 
#define vvc vector<vector<char> > 
#define vpi vector<pair<int,int> >
#define ll long long 
#define sz(a) int(a.size())
#define forn(i,n) for(int i = 0 ; i < int(n) ; i++)
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define len(s) s.length()
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define modulo 998244353ll
#define mod 1000000007ll
#define MAXN  1000001 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b){if(a==0 || b == 0) return max(a,b);if(a == 1 || b == 1)return 1;return gcd(max(a,b)%min(a,b),min(a,b));}


void solve()
{
    int n;
    cin>>n;
    ll ans = 0;
    ans += 1ll*power(10,n);
    ans %= mod;
    ans -= 2ll*power(9,n);
    ans += 1ll*power(8,n);
    if(ans > mod)
    ans %= mod;
    while(ans < 0)
    ans += mod;
    ans %= mod;
    cout<<ans<<endl;
}


int main()
{
    fast();
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<array>
#include<list>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>
#include<memory>

using namespace std;

using ll = unsigned long long;

using vec = vector<int>;
using mat = vector<vec>;


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

	if (N == 1)
	{
		cout << "Yes" << endl;
		cout << "2" << endl;
		cout << "1 1" << endl;
		cout << "1 1" << endl;
		return 0;
	}

	int SNum = 3;

	for (SNum = 3;; ++SNum)
	{
		if (SNum*(SNum - 1) / 2 == N)
		{
			break;
		}

		if (SNum*(SNum + 1) / 2 > 100000)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	cout << SNum << endl;

	mat E(SNum, vec(SNum));

	int id = 1;

	for (int i = 0; i < SNum; ++i)
	{
		for (int j = i+1; j < SNum; ++j)
		{
			if (i == j)continue;

			E[i][j] = id;
			E[j][i] = id;
			id++;
		}
	}

	for (int i = 0; i < SNum; ++i)
	{
		cout << SNum - 1 << " ";
		for (int j = 0; j < SNum; ++j)
		{
			if (i == j)continue;
			cout << E[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
    int n1, n2,i,j;
    int c=0;
    int s[100000];
    int t[100000];

    cin>>n1;
    for(i=0;i<n1;i++) cin>>s[i];
  	cin>>n2;
    for(j=0;j<n2;j++) cin>>t[j];

    for(i=0;i<n2;i++){
        for(j=0;j<n1;j++){
            if(t[i]==s[j]){
                c++;
                break;
            }

        }
    }

    cout<<c<<endl;

}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
int Q;
long long sumL = 0, sumR = 0;
multiset <int> L, R;
long long addB;
 
void update(int x) {
    if(L.empty()) {
        sumL += x;
        L.insert(x);
        return;
    }
    int naxL = *(L.rbegin());
 
    if(x >= naxL) {
        R.insert(x);
        sumR += x;
    } else {
        L.insert(x);
        sumL += x;
    }
 
    if(L.size() + 1 < R.size()) {
        int val = *R.begin();
        L.insert(val);
        R.erase(R.find(val));
        sumL += val;
        sumR -= val;
    } else if(R.size() + 1 < L.size()) {
        int val = *L.rbegin();
        R.insert(val);
        L.erase(L.find(val));
        sumR += val;
        sumL -= val;
    }
}
 
void get() {
    int val;
    if(L.size() + 1 == R.size())
        val = *R.begin();
    else
        val = *L.rbegin();
 
    long long ans = addB + L.size() * 1LL * val - sumL + sumR - R.size() * 1LL * val;
    cout << val << " " << ans << "\n";
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin >> Q;
    while(Q --> 0) {
        int type;
        cin >> type;
        if(type == 1) {
            int a, b;
            cin >> a >> b;
            addB += b;
            update(a);
        } else {
            get();
        }
    }
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "Yes" : "No" ) << '\n' ;
#define mxn 100005
using namespace std;

void solve(){
     int d,t,s;
     cin >> d >> t >> s;
     output(s*t >= d);
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3644
import math
i = list(map(int, input().split()))
a = i[0]
#print('a=',a)
b = i[1]
#print('b=',b)
h = i[2]
#print('h=',h)
m = i[3]
#print('m=',m)
#長針の角度を求める
ma = m*6
#print('ma=',ma)
#短針の角度を求める
ha = h*30+0.5*m
#print('ha=',ha)
#角度の差の絶対値
ang = ha -ma
#print(ang)
#長針と短針の角度が同じなら長針ー短針をすればいい。
e = math.cos(math.radians(ang))
d = a*a + b*b -2*a*b* e
#print(d)
c = math.sqrt(d)
print(c)
  
#print('あくまでテスト',math.sqrt(9+16-2*3*4*math.cos(math.radians(80))))


Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,m,ans;
    cin>>n>>m;
    rep(i,sqrt(m)){
      if(m%(i+1)==0&&i+1<=m/n) ans=max(ans,i+1);
      if(m%(i+1)==0&&m/(i+1)<=m/n) ans=max(ans,m/(i+1));
    }
    cout<<ans;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,a;
  cin>>n>>a;
  VL x(n);
  rep(i,n)cin>>x[i];

  ll dp[n+5][n+5][n*55];
  rep(i,n+5)rep(j,n+5)rep(k,n*55)dp[i][j][k]=0;
  dp[0][0][0]=1;

  rep(i,n){
    rep(j,n){
      rep(k,n*51){
        //if(dp[i][j][k]){
          dp[i+1][j][k]+=dp[i][j][k];
          dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
        //}
      }
    }
  }
  
  ll ans=0;
  reps(i,n)ans+=dp[n][i][i*a];
  out(ans);

  
  return 0;
}



Measured memory_bytes: 65280
import java.io.*;
class Main{


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

	BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	while(true){
	    String s = sc.readLine();
	    if(s.equals("END OF INPUT"))break;
	    String[] sr = s.split(" ");
	    for(int i=0;i<sr.length;i++){
		System.out.print(sr[i].length());
	    }
	    System.out.println("");
	}
    }


}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

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

int main() {
  int64_t K;
  string S;
  cin >> K;
  cin >> S;

  if(K < S.size()){
    cout << S.substr(0,K) << "..." << endl;
  }else{
    cout << S << endl;
  }
  
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	vector<int> div;

	int X;
	cin >> X;

	rep(i, 1, sqrt(X) + 1)
	{
		if (X%i == 0)
		{
			div.push_back(i);
			if (X / i != i)div.push_back(X / i);
		}
	}

	for (auto d : div)
	{
		rep(i, -10000, 10000)
		{
			int A = i;
			int B = i - d;
			if (A*A*A*A + A * A*A*B + A * A*B*B + A * B*B*B + B * B*B*B == X / d)
			{
				cout << A << " " << B;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3680
#include <iostream>

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

long long w, weight[101], value[101];
long long dp[101][100001] = {0};

using namespace std;

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

  for(int i = 0; i < N; i++) cin >> weight[i] >> value[i];

  for(int i = 0; i < N; i++){
    for(int sum_w = 0; sum_w <= w; sum_w++){
      if(sum_w - weight[i] >= 0){
        chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
      }
      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
    }
  }

  cout<<dp[N][w]<<endl;
  
  return 0;
}

Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  
   
   int S,W;
   cin>>S>>W;
   if(W >= S)
   {
     cout<<"unsafe"<<endl;
   }
   else
   {
     cout<<"safe"<<endl;
   }
   
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

a,b,c,x,y = list(map(int,input().split()))

min_cost = 5000 * 100000 * 2
#abピザを2i枚買う時残り必要な額を計算する

for i in range(100001):
    zan_a = max(x-i,0)
    zan_b = max(y-i,0)
    min_cost = min((a*zan_a+b*zan_b+c*i*2),min_cost)
print(min_cost)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

class Dice{
	int mn[6];	
	
	public:
		void set(int num, int val){
			mn[num] = val;
		}
	
		void rot(char dir){
			int buf, old[6];
			memcpy(old, mn, sizeof(mn));
			switch(dir){
				case 'E':
				mn[0] = old[3];
				mn[2] = old[0];
				mn[5] = old[2];
				mn[3] = old[5];
				break;
				case 'W':
				mn[3] = old[0];
				mn[0] = old[2];
				mn[2] = old[5];
				mn[5] = old[3];
				break;
				case 'S':
				mn[0] = old[4];
				mn[1] = old[0];
				mn[5] = old[1];
				mn[4] = old[5];
				break;
				case 'N':
				mn[4] = old[0];
				mn[0] = old[1];
				mn[1] = old[5];
				mn[5] = old[4];
				break;
				case 'R':
				mn[1] = old[2];
				mn[2] = old[4];
				mn[4] = old[3];
				mn[3] = old[1];
				break;
				case 'L':
				mn[2] = old[1];
				mn[4] = old[2];
				mn[3] = old[4];
				mn[1] = old[3];
				break;
			}
		}
		
		int get(int num){
			return mn[num];
		}
		
		int serch(int val){
			int i;
			for(i = 0; 6 > i; i++){
				if(mn[i] == val) return i;
			}
			return -1;
		}
		
		void Aset(int up, int front){
			int i, su = serch(up);
			if(su == 3 || su == 2){
				while(get(0) != up){
					rot('E');
				}
			}
			else {
				while(get(0) != up){
					rot('S');
				}
			}
			while(get(1) != front){
				rot('R');
			}
		}
};


int main() {
	int b, i, n;
	Dice dice;
	
	for(i = 0; 6 > i; i++){
		scanf("%d", &b);
		dice.set(i,b);
	}
	scanf("%d", &n);
	for(i = 0; n > i; i++){
		int cm[2];
		scanf("%d%d", &cm[0], &cm[1]);
		
		dice.Aset(cm[0], cm[1]);
		printf("%d\n", dice.get(2));
	}
	return 0;
}


Measured memory_bytes: 2760
#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;
  cin >> n;
  if(n % 3 == 0){
    cout << n / 3 << endl;
  }else{
    n /= 3;
    cout << max(n, 0) << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long t = sc.nextLong();
        long prev = 0;
        long ans = 0;
        for(int i = 0 ; i < n; i++){
            long next = sc.nextLong();
            ans += Math.min(t,next-prev);
            prev = next;
        }
        System.out.println(ans+t);
    }
}


Measured memory_bytes: 63496
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll bit[200010], num;

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

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

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	while (true)
	{
		string s[2], t[2], c[2][210];
		bool cst = false, all = true;
		cin >> s[0];
		if (s[0][0] == '.' && s[0].length() == 1)
		{
			break;
		}
		cin >> s[1];
		if (s[0].length() == s[1].length())
		{
			for (int i = 0; i < s[0].length(); i++)
			{
				if (s[0][i] != s[1][i])
				{
					all = false;
				}
			}
		}
		else
		{
			all = false;
		}

		if (all)
		{
			cout << "IDENTICAL" << endl;
			continue;
		}
		int o[2] = { -1, -1 };
		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j < s[i].length(); j++)
			{
				if (s[i][j] == '"' && cst)
				{
					cst = false;
					t[i] += s[i][j];
				}
				else if (s[i][j] == '"')
				{
					cst = true;
					o[i]++;
					t[i] += s[i][j];
				}
				else if (cst)
				{
					c[i][o[i]] += s[i][j];
				}
				else
				{
					t[i] += s[i][j];
				}
			}
		}
		if (t[0].length() != t[1].length())
		{
			cout << "DIFFERENT" << endl;
			continue;
		}
		bool jud = true;
		for (int i = 0; i < t[0].length(); i++)
		{
			if (t[0][i] != t[1][i])
			{
				jud = false;
			}
		}
		int dif = 0;
		for (int i = 0; i <= o[0]; i++)
		{
			if (c[0][i].length() != c[1][i].length())
			{
				dif++;
				continue;
			}
			bool J = true;
			for (int j = 0; j < c[0][i].length(); j++)
			{
				if (c[0][i][j] != c[1][i][j])
				{
					J = false;
				}
			}
			if (!J)
			{
				dif++;
			}
		}

		if (!jud || dif > 1)
		{
			cout << "DIFFERENT" << endl;
			continue;
		}
		if (dif == 1)
		{
			cout << "CLOSE" << endl;
		}
	}
	int www;
	cin >> www;
}



Measured memory_bytes: 3236
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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 REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

int h, w;
int n_white;
char m[50][50];

void init()
{
}

int movable()
{
    int ret = INF;
    queue<IP> q;
    q.push(mp(0, mp(0, 0)));
    while(!q.empty()){
        int d, x, y;
        d = q.front().fi;
        x = q.front().se.fi;
        y = q.front().se.se;
        q.pop();
        if(m[x][y] != '.') continue;
        if(x == h-1 && y == w-1){
            ret = min(ret, d);
        }
        m[x][y] = '-';
        REP(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
            if(m[nx][ny] != '.') continue;
            q.push(mp(d+1, mp(nx, ny)));
        }
    }
    if(ret == INF) ret = -1;
    else ret = n_white - ret;
    return ret;
}

void solve()
{
    cout << movable() << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    REP(i, h){
        REP(j, w){
            cin >> m[i][j];
            if(m[i][j] == '.') n_white++;
        }
    }
    n_white--;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
$cnt = 0;
for ($i = 0; $i < $n - 1; $i++) {
    if ($h[$i + 1] <= $h[$i]) $cnt++;
    else $cnt = 0;
    $ans = max($cnt, $ans);
}
echo $ans . PHP_EOL;

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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int N;
  set< int > g[100000];
  cin >> N;
  queue< pair< int, int > > que;
  for(int i = 0; i < 2 * N - 2; i++) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    if(g[A].count(B)) que.emplace(A, B);
    g[A].emplace(B);
    g[B].emplace(A);
  }
  UnionFind tree(N);
  while(!que.empty()) {
    int a, b;
    tie(a, b) = que.front();
    que.pop();
    a = tree.find(a), b = tree.find(b);
    if(a == b) continue;
    if(g[a].size() > g[b].size()) swap(a, b);
    tree.unite(b, a);
    g[a].erase(b);
    g[b].erase(a);
    for(int to : g[a]) {
      g[to].erase(a);
      if(g[to].count(b)) que.emplace(to, b);
      else g[to].emplace(b), g[b].emplace(to);
    }
    g[a].clear();
  }
  if(tree.size(0) == N) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 24064