akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector<bool> flag(n);
		for(int i = 0; i < n; ++i)
		{
			flag[i] = true;
		}
		int count = 0;
		int pos = 0;
		while(count < n)
		{
			int step = m;
			while(step > 0)
			{
				if(flag[pos])
				{
					--step;
				}
				++pos;
				pos %= n;
			}
			flag[(pos - 1 + n) % n] = false;
			++count;
		}
		cout << (pos - 1 + n) % n + 1 << endl;
	}
}

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

Measured memory_bytes: 1196
a,b,k = list(map(int,input().split()))

newk = k-a
if newk >= 0:
  a = 0
  b = b-newk
  if b <= 0:
    print(str(0) + " " +str(0))
  else:
    print(str(0) + " " + str(b))
else:
  a = a-k
  print(str(a) + " " +str(b))




Measured memory_bytes: 2940
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	s = input()
	t = ['Sunny', 'Cloudy', 'Rainy']
	print(t[(t.index(s)+1)%3])

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


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

#define all(v) begin(v), end(v)
#define endl '\n';
#define int long long
#define pii pair<int, int>

int32_t main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);

    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int &x: a) {
        cin >> x;
    }
    sort(all(a));
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> h(n),a(m),b(m);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    for(int i=0;i<m;i++){
        cin >> a[i];
        cin >> b[i];
    }
    vector<bool> flag(n,true);
    for(int i=0;i<m;i++){
        if(h[a[i]-1]>h[b[i]-1]){
            flag[b[i]-1] = false;
        }else if(h[a[i]-1]<h[b[i]-1]){
            flag[a[i]-1] = false;
        }else{
            flag[b[i]-1] = false;
            flag[a[i]-1] = false;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++) ans += flag[i];
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;


int main() {
    
    string s;
    cin>>s;
    bool ans=true;
    string k=s;
    reverse(k.begin(),k.end());

    if(s!=k){
        ans=false;
    }
    int l=s.size();
    string sub= s.substr(0,(l-1)/2);

    string sub2=sub;
    reverse(sub2.begin(),sub2.end());
    if(sub!=sub2){
        ans=false;
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  int n = s.size();
  
  lint ans = 0;
  for (int bit = 0; bit < (1 << (n - 1)); bit++) {
    lint add = (int)(s[0] - '0');
    for (int i = 0; i < n - 1; i++) {
      if (bit & (1 << i)) {
        ans += add;
        add = (int)(s[i + 1] - '0');
      } else {
        add *= 10;
        add += (int)(s[i + 1] - '0');
      }
    }

    ans += add;
  }

  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
a, b = 0, 0

while l:
  m1 = max(l)
  a += m1
  l.remove(m1)
  if l:
    m2 = max(l)
    l.remove(m2)
print( 2 * a - s )



Measured memory_bytes: 9092
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N, i, key, j, k = 0, minj;
  int *data;

  scanf("%d", &N);

  data = (int *)malloc(N * sizeof(int));

  for(i = 0; i < N; i++) scanf("%d", &data[i]);

  for(i = 0; i < N; i++){
   
    minj = i;
    
    for(j = i; j < N; j++){
      if(data[j] < data[minj]){
	minj = j;
      }
    }
     key = data[minj];
    data[minj] = data[i];
    data[i] = key;
    if(data[i] != data[minj]) k++; 
  }
  for(i = 0; i < N - 1; i++) printf("%d ", data[i]);
  printf("%d\n", data[i]);
  printf("%d\n", k);
 
  return 0;
}

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

using namespace std;

int main(){
    string card_array;
    int shuffle;
    int n_shuffle;
    while(true){
        cin >> card_array;
        if(card_array == "-") break;
        
        cin >> n_shuffle;

        for(int i = 0; i < n_shuffle;i++){
            cin >> shuffle;
            string drawn = card_array.substr(0,shuffle);
            card_array.erase(0,shuffle);
            card_array = card_array + drawn;
        }
        cout << card_array << "\n";
    }
    
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, s = 0;
  cin >> n;
  vector<ll> a(n);

  rep(i, n) cin >> a[i], s ^= a[i];
  rep(i, n) a[i] ^= s;
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 4784
# mod mでの二項係数を求める
class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

n,p = map(int, input().split())
al = list(map(int, input().split()))
bicoeff = BiCoeff(10**5,10**9+7)

odd = 0
even = 0
for a in al:
    if a%2==0:
        even += 1
    else:
        odd += 1

r1 = 2**even
r2 = 0
for k in range(odd+1):
    if k%2==p:
        r2 += bicoeff.calc(odd, k)
print(r1*r2)



Measured memory_bytes: 14836
#include <iostream>
#include <vector>
using namespace std;
void selectionSort(vector<int> &A, int N) {
  int minj, cnt = 0;
  for(int i = 0; i < N; ++i) {
	minj = i;
	for(int j = i; j < N; ++j) {
	  if(A[j] < A[minj]) minj = j;
	}
	swap(A[i], A[minj]);
	if(i != minj) cnt++;
  }
  /*-- print --*/
  for(int k = 0; k < N; ++k) {
	cout << A[k];
	cout << (k < N - 1 ? " " : "\n");
  }
  cout << cnt << endl;
}
int main() {
  int N;
  cin >> N;
  vector<int> v1(N);
  for(int i = 0; i < N; ++i) {
	cin >> v1[i];
  }
  selectionSort(v1, N);
  return 0;
}

Measured memory_bytes: 3104
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
#define lim 1000000
bool primes[lim];
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int a, d, n;
        cin >> a >> d >> n;
        if(a == 0) return;

        int cnt = 0;
        int val = a;
        while(true){
            if(primes[val]){
                cnt++;
            }
            if(cnt >= n) break;
            val += d;
        }

        cout << val << endl;
        solve();
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for(int i = 2; i < lim; ++i){
        primes[i] = true;
    }
    for(int i = 2; i < lim; ++i){
        if(primes[i]){
            for(int j = i * 2; j < lim; j += i){
                primes[j] = false;
            }
        }
    }
    Solve().solve();


    return 0;
}



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

int main() {
  long long k;
  cin>>k;
  if(k&1 == 0){
    cout<<-1<<endl;
    return 0;
  } 
  long long val= 7%k;
  map<long long, int> mp;
  int idx = 1;
  while(++mp[val] == 1){
    if(not val) return cout<<idx<<endl, 0;
    idx++;
    val = ( val* 10+7)%k;
    //val += 7;
    //val%=k;
    /*string s = to_string(sum);
    bool f = true;
    for(auto c : s) f &= c == '7';
    if(f){
      cout<<sum<<endl;
      return 0;
    }
    sum += k;*/
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 65964
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
int n, k;
ll dp[N], sum[N];
int l[N], r[N];

inline void solve()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; ++i)
        scanf("%d%d", &l[i], &r[i]);
    dp[1] = sum[1] = 1;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 1; j <= k; ++j)
            dp[i] += (sum[max(0, i - l[j])] - sum[max(0, i - r[j] - 1)]) % mod, dp[i] %= mod, dp[i] += mod, dp[i] %= mod;
        sum[i] = (sum[i - 1] + dp[i]) % mod;
    }
    cout << dp[n];
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
    {
        solve();
        // if (Test)
        //     putchar('\n');
    }
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 6908
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;

int diff(string a, string b){
	int len = min( a.length(), b.length() );
	rep(i,len){
		if( a[i] == '?' && b[i] != 'a' && b[i] != 'z' ) return 0;
		if( b[i] == '?' && a[i] != 'a' && a[i] != 'z' ) return 0;
		if( a[i] < b[i] ) return 1;
		if( a[i] > b[i] ) return 2;
	}
	if( a.length() == b.length() ){
		return 0;
	}else{
		return 1 + (a.length() > b.length());
	}
}

int main(){
	//ios_base::sync_with_stdio(0);
	int N, ans=0;
	string S[10005], T;

	cin >> N;
	rep(i,N) cin >> S[i];
	cin >> T;

	int cnt[5]={};
	rep(i,N) cnt[ diff(S[i], T) ]++;

	//cout << cnt[0] << " ";
	//cout << cnt[1] << " ";
	//cout << cnt[2] << " ";
	//cout << endl;
	for(int i=cnt[1]+1; i<=N-cnt[2]+1; i++){
		if(i>cnt[1]+1) cout << " ";
		cout << i;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(i,p,n) for(int i=p;i<n;i++)
#define fr1(i,p,n) for(int i=p;i>=n;i--)
#define FAST ios::sync_with_stdio(0);
#define sz(v) (int)v.size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define precise cout << std::setprecision(12) << std::fixed;
#define endl "\n"
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FAST
    int t=1;
    //cin>>t;
    while(t--)
    {
        char ch;
        cin>>ch;
        if(ch>='A' && ch<='Z') cout<<"A"<<endl;
        else cout<<"a"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define lld long double
    #define all(x) x.begin(),x.end() 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
        
    #define XOX 
    
    typedef vector<int> vi;
    // typedef pair<int,int> pi; 

    const long double pi =6.28318530717958623200;
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ DEB $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    long double r;
    void solve()
    {
        cin>>r;
        lld ans=pi*r;
        cout<<ans<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        deci(10);
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void chmax(int &a, int b) { if (a < b) a = b; }

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

    int res = 0;
    vector<vector<int> > dp(N+1, vector<int>(N+1, 0));
    for (int i = N-1; i >= 0; --i) {
        for (int j = N-1; j > i; --j) {
            if (S[i] == S[j]) chmax(dp[i][j], dp[i+1][j+1] + 1);
            chmax(res, min(dp[i][j], j-i));
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 98304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll  n, i, j=0;
    string a, b;
    cin>>a>>b;
    for(i=0; i<a.size(); i++){
        if(a[i]==b[i])j++;
    }
    cout<<j<<endl;
    return 0;
}



Measured memory_bytes: 256
/**

サイコロの各面には図のとおりに 1 から 6 のラベルが割りあてられています。

入力としてサイコロの各面のラベルに対応する数字と、転がす命令の列が与えられるので、サイコロの上面の数字を出力してください。シミュレーションの初期状態は、図のとおりのラベルの位置でサイコロが置かれているものとします。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		// 6桁の数字を受け取る配列diceを作る
		int[] dice = new int[6];
		int intUemen = 0;
		int intMaemen = 0;
		int intKekka = 0;
		// 6個入力された数字を受け取る
		for (int i = 0; i < 6; i++) {
			dice[i] = sc.nextInt();
		}
		//質問の数を受け取る
		int situ = sc.nextInt();
		//質問の数だけ処理を繰り返す
		for (int i = 0; i < situ; i++) {
			//上面と正面の数を受け取る
			intUemen = sc.nextInt();
			intMaemen = sc.nextInt();

			//上面と正面、それぞれの数が一致した場合intKekkaに数を入れる。
			if (intUemen == dice[0]) {
				if (intMaemen == dice[1]) {
					intKekka = dice[2];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[4];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[1];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[3];
				}
			} else if (intUemen == dice[1]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[3];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[2];
				}
			} else if (intUemen == dice[2]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[1];
				} else if (intMaemen == dice[1]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[4];
				}
			} else if (intUemen == dice[3]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[4];
				} else if (intMaemen == dice[1]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[1];
				}
			} else if (intUemen == dice[4]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[2];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[3];
				}
			} else if (intUemen == dice[5]) {
				if (intMaemen == dice[1]) {
					intKekka = dice[3];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[1];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[4];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[2];
				}
			}
			//結果表示
			System.out.println(intKekka);
		}
	}
}

Measured memory_bytes: 17196
INF = 10 ** 18
N = 393  # フレーズの最大長さ

# phraseの個数
n = int(input())
phrss = [list(map(int, input().split())) for _ in range(n)]
m = int(input())
mldys = [int(input()) for _ in range(m)]

max_mldy = max(mldys)

# mp[i]: 長さiのフレーズの最大の得点
# フレーズごとにforループを回すと遅いから先に長さごとの得点を計算しておく
mp = [-INF] * (N + 1)
for phrase in phrss:
    shortest, longest, point = phrase
    for length in range(shortest, longest + 1):
        mp[length] = max(point, mp[length])

# dp[i]: 長さiのメロディの最大得点
dp = [-INF] * (N + 1)
dp[0] = 0

# DP表更新
for i in range(N + 1):
    for j in range(1, i + 1):
        dp[i] = max(dp[i - j] + mp[j], dp[i])

# OUTPUT
# 答えリスト作成
ans = []
for melody in mldys:
    ans.append(dp[melody])

# メロディにぴったりフレーズを当てはめられるかどうか調べる
# 負の答えがあれば不可能
can = True
for ai in ans:
    if ai < 0:
        can = False

# 答え出力 不可能なら-1を出力
if can:
    for ai in ans:
        print(ai)
else:
    print(-1)



Measured memory_bytes: 5688
def factorial_cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
X=[0] *N
for idx in range(N):
    X[idx]=factorial_cor(N-1-idx)

Pp = 1
for idx in range(N - 1):
    count = 0
    for idy in range(idx):
        if (P[idx] > P[idy]):
            count+=1
    Pp += ((P[idx] - count - 1) if (P[idx] - count - 1) >= 0 else 0) * X[idx]
Qp = 1
for idx in range(N - 1):
    count = 0
    for idy in range(idx):
        if (Q[idx] > Q[idy]):
            count+=1
    Qp += ((Q[idx] - count - 1) if (Q[idx] - count - 1) >= 0 else 0) * X[idx]

print(abs(Pp-Qp))


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

namespace AtCoder{
    public static class AtCoder{
        public static void Main(){
            long n = long.Parse(Console.ReadLine());
            var l = new string[n];
            long ans = 0;
            for(long i = 0; i < n; i++){
                var s = Console.ReadLine();
                l[i] = s;
            }
            Array.Sort(l);
            string tmp = string.Empty;
            for(long i = 0; i < n; i++){
                if(tmp != l[i]){ans++;}
                tmp = l[i];
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 38644
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int n;
    cin>>n;
    int ans=0;
    if(n&1)
    {
      cout<<0<<endl;
    }
    else
    {
      n/=10;
      ans+=n;
      while(n)
      {
        ans+=n/5;
        n/=5;
      }
      cout<<ans<<endl;
    }
    

  }
  //time("");
  return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, X: int, Y: int):
    X = X - 1
    Y = Y - 1

    counter = collections.defaultdict(int)
    for i in range(N):
        for j in range(i+1, N):
            k = min(j - i, abs(Y-j) + abs(X-i) + 1)
            counter[k] += 1
    for i in range(1, N):
        print(counter[i])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)

if __name__ == '__main__':
    main()


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

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

struct Edge {
    int from, to;
    i64 cost;
    Edge() {}
    Edge(int t, i64 c) : from(-1), to(t), cost(c) {}
    Edge(int f, int t, i64 c) : from(f), to(t), cost(c) {}

    bool operator<(const Edge& r) const {
        return cost < r.cost;
    }
    bool operator>(const Edge& r) const {
        return cost > r.cost;
    }
};

using Vertex = vector<Edge>;
using Graph  = vector<Vertex>;

// 無向
void link(Graph& g, int from, int to, int cost = 1) {
    g[from].push_back(Edge(from, to, cost));
    g[to].push_back(Edge(to, from, cost));
    return;
}

// 有向
void connect(Graph& g, int from, int to, int cost = 1) {
    g[from].push_back(Edge(from, to, cost));
    return;
}

vector<i64> dijkstra(const Graph& g, int start) {
    const auto inf = numeric_limits<i64>::max();
    vector<i64> dist(g.size(), inf);

    using Pi = pair<i64, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[start] = 0;
    que.push(make_pair(0, 0));
    while (!que.empty()) {
        const auto e    = que.top();
        const auto cost = e.first;
        const auto from = e.second;
        que.pop();
        if (dist[from] < cost) continue;

        for (const auto& e : g[from]) {
            const auto next_cost = e.cost + cost;
            if (chmin(dist[e.to], next_cost)) {
                que.push(make_pair(next_cost, e.to));
            }
        }
    }

    return dist;
}

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

signed main() {
    int N;
    cin >> N;
    Graph G(N);
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int v, c;
            cin >> v >> c;
            connect(G, u, v, c);
        }
    }
    auto dist = dijkstra(G, 0);
    rep(i, 0, N) {
        cout << i << " " << dist[i] << "\n";
    }
}



Measured memory_bytes: 3176
D(n){
	int r,m;
	r=n/(-10);
	m=n-r*(-10);
	if(m<0){
		m+=10;
		r++;
	}
	if(r)
		D(r);
	printf("%d",m);
}
main(n){
	for(;scanf("%d",&n),n;){
		D(n);
		puts("");
	}
	exit(0);
}

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

long long gcd(long long a,long long b){
	if(a==0 || b==0){
		return max(a,b);
	}
	else if(a==1 || b==1){
		return 1;
	}
	
	long long q;
	bool pro =true;
	while(pro){
		q=a%b;
		if(q==0){
			return min(a,b);
		}
		else{
			a=b;
			b=q;
			if(a%b==0){
				return q;
				pro=false;
			}
		}
	}
}


int main() {
	int N;
	cin>>N;
	if(N==2){
		int a,b;
		cin >> a>>b;
		cout<<max(a,b)<<endl;
	}
	else{
		vector<long long> an(N);
		for(int i=0;i<N;i++){
			cin >> an.at(i);
		}
		vector<long long> li(N);
		vector<long long> ri(N);
		li.at(0)=an.at(0);
		ri.at(N-1)=an.at(N-1);
		
		for(int i=1;i<N;i++){
			li.at(i)=gcd(li.at(i-1),an.at(i));
		}
		for(int i=N-2;i>=0;i=i-1){
			ri.at(i)=gcd(ri.at(i+1),an.at(i));
		}
		
		long long m=ri.at(1);
		for(int i=1;i<N-1;i++){
			long long mi=gcd(ri.at(i+1),li.at(i-1));
			if(mi>m){
				m=mi;
			}
		}
		if(li.at(N-2)>m){
			m=li.at(N-2);
		}
		
		cout << m << endl;
	}
}


Measured memory_bytes: 2560
N, M = list(map(int,input().split()))
in_ = []
for i in range(M):
    a, b = map(int, input().split())
    in_.append([a, b])

class UnionFind():

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:  return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:  return

        if self.parents[x] > self.parents[y]:  x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):  return -self.parents[self.find(x)]

    def same(self, x, y):  return self.find(x) == self.find(y)
        
uf = UnionFind(N)
cnt = N * (N - 1) // 2
ans = [0 for _ in range(M)]

for i in range(M):
    ans[-i - 1] = cnt
    a, b = in_[-i - 1][0] - 1, in_[-i - 1][1] - 1
    if uf.same(a, b):  continue
    cnt -= (uf.size(a) * uf.size(b))
    uf.union(a, b)

for i in range(M):  print(ans[i])

Measured memory_bytes: 94076
s = list(input())
if s[0] == "A" and s[2:-1].count("C") == 1:
    s.remove("A")
    s.remove("C")
    for i in range(len(s)):
        if s[i].islower():
            continue
        else:
            print("WA")
            exit()
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> G[maxn],order;
int n,known[maxn],val[maxn],l[maxn],r[maxn],k,used[maxn],known_parity[maxn][2],shit,par[maxn],ans[maxn];
void dfs(int v)
{
	used[v] = 1;
	l[v] = -1e9;
	r[v] = 1e9;
	for(int i = 0;i < G[v].size(); ++i)
	{
		int to = G[v][i];
		if(used[to])
		{
			continue;
		}
		dfs(to);
		par[to] = v;
		if(known_parity[to][0])
		{
			known_parity[v][1] = 1;
		}
		if(known_parity[to][1])
		{
			known_parity[v][0] = 1;
		}
		l[v] = max(l[v],l[to] - 1);
		r[v] = min(r[v],r[to] + 1);
	}
	if(known[v] == 1)
	{
		l[v] = max(l[v],val[v]);
		r[v] = min(r[v],val[v]);
		known_parity[v][val[v] % 2] = 1;
	}
	if(known_parity[v][0] == 1 && known_parity[v][1] == 1)
	{
		shit = 1;
	}
	if(l[v] > r[v])
	{
		shit = 1;
	}
	order.push_back(v);
}
int solve_val(int v,int par)
{
	if(par == 0)
	{
		return l[v];
	}
	l[v] = max(l[v],ans[par] - 1);
	r[v] = max(r[v],ans[par] + 1);
	while(l[v] % 2 == ans[par] % 2)
	{
		++l[v];
	}
	return l[v];
}
int main(int argc, char const *argv[])
{
	cin>>n;
	for(int i = 0;i < n - 1; ++i)
	{
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cin>>k;
	for(int i = 1;i <= k; ++i)
	{
		int a,b;
		cin>>a>>b;
		known[a] = 1;
		val[a] = b;
	}
	dfs(1);
	if(shit)
	{
		cout<<"No\n";
		return 0;
	}
	reverse(order.begin(),order.end());
	printf("Yes\n");
	for(int i = 0;i < order.size(); ++i)
	{
		int v = order[i];
		ans[v] = solve_val(v,par[v]);
	}
	for(int i = 1;i <= n; ++i)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 15096
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,b;
  if(scanf("%d%d",&a,&b)==-1){
    exit(1);
  }
  if(a>12){
    printf("0\n");
    return 0;
  }
  if(b>31){
    printf("0\n");
    return 0;
  }
  if(a==2 && b>28){
    printf("0\n");
    return 0;
  }
  if((a==4 || a==6 || a==9 ||a==11) && b>30){
    printf("0\n");
    return 0;
  }
  if(a>b){
    printf("%d\n",a-1);
  }
  else{
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	N, D := getStdinInt2()
	ans := 0
	for i := 0; i < N; i++ {
		X, Y := getStdinInt2()
		if dis(X, Y) <= float64(D) {
			ans++
		}
	}
	fmt.Printf("%d\n", ans)
}

func dis(x, y int) float64 {
	return math.Sqrt((float64)(x*x + y*y))
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 15252
// https://atcoder.jp/contests/abc141/tasks/abc141_e
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using I = int;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    I N;
    string S;
    cin >> N >> S;
    I len = S.length(), maxv = 0;
    REPR(d, len) {
        I cnt = 0;
        REP(i, len - d) {
            if (S[i] == S[i + d]) {
                cnt++;
            } else {
                cnt = 0;
            }
            maxv = max(maxv, min(cnt, d));
        }
        if (d == maxv)
            break;
    }
    cout << maxv << endl;

    return 0;
}


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

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

const int MAX_H = 20;
const int MAX_W = 20;
const int MAX_M = 16;

int H, W;
string M[MAX_H];
bool vis[MAX_M][4][MAX_H][MAX_W];

bool run( int x, int y, int dir, int mem ) {
  
  if(vis[mem][dir][y][x]) return 0;
  vis[mem][dir][y][x] = 1;
  
  switch(M[y][x]) {
  case '<': dir = 0; break;
  case '>': dir = 2; break;
  case '^': dir = 1; break;
  case 'v': dir = 3; break;
  case '_': dir = ( mem ? 0 : 2 ); break;
  case '|': dir = ( mem ? 1 : 3 ); break;
  case '.': break;
  case '@': return 1;
  case '+': mem = ( mem + 1 ) % 16; break;
  case '-': mem = ( mem + 15 ) % 16; break;
  case '?':
    for(int i=0; i<4; i++) {
      if(run((x+dx[i]+W)%W, (y+dy[i]+H)%H, i, mem)) return 1;
    }
    return 0;
  default:
    if(isdigit(M[y][x])) {
      mem = M[y][x]-'0';
    }
  }
  return run((x+dx[dir]+W)%W, (y+dy[dir]+H)%H, dir, mem);
}

int main() {
  
  cin >> H >> W;
  cin.ignore();
  
  for(int i=0; i<H; i++) getline(cin, M[i]);
  
  if(run(0, 0, 2, 0)) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include<iomanip>
#include<vector>
#include<numeric>
#include<algorithm>
#define int long long
const int inf=1145141919;
const int mod=1000000007;
using namespace std;
template<class T>void chmax(T &x,const T &y){
	x=max(x,y);
}
template<class T>void chmin(T &x,const T &y){
	x=min(x,y);
}
int N,M,K;
signed main(){
	int i;
	cin>>N>>M>>K;
	if(K==0){
		cout<<"Yes"<<endl;
		return 0;
	}
	int u=N*M-K*2;
	for(i=0;i<=N;i++){
		int x=N-i*2;
		if(x!=0&&u%x==0&&(u/x)<=M&&(u/x)>=-M&&(u/x)%2==M%2){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
// 2019/04/27
// AtCoder Beginner Contest 098 - A
// (stdin: type Ctrl + D after input)

"use strict";
 
function Main(in_input){
    // Modify Input
    var in_lines = in_input.split("\n");
    var in_line1 = in_lines[0].split(" ");
    var a = parseInt(in_line1[0], 10);
    var b = parseInt(in_line1[1], 10);

    // Calc Answer
    var c_max = Math.max(a+b, a-b, a*b) + 0;

    // Output
    console.log(c_max);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  
  cin >> N;
  int ans = 1;
  int min;
  cin >> min;
  for(int i = 1; i < N; i++){
    int a;
    cin >> a;
    if(a < min){
      min = a;
      ans++;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in();
    vec a(n),b(n);
    rep(i,n){
        a[i]=b[i]=in();
    }
    sort(All(b));
    rep(i,n){
        if(a[i]==b[n-1]){
            cout<<b[n-2]<<endl;
        }else{
            cout<<b[n-1]<<endl;
        }
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void mmax(T &m, const T q) { if (m < q) m = q; }
template<typename T> void mmin(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    lint D;
    cin >> D;
    lint N;
    cin >> N;
    int i = 0;
    REP(_, N)
    {
        i++;
        if (i % 100 == 0) i++;
    }
    cout << i;
    REP(_, D) cout << "00";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long
#define wtcl return
using namespace std;

inline ll read()
{
	ll s = 0, f = 1;
	char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	return s * f ;
}
inline void out(ll x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) out(x/10);
	putchar(x%10+'0');
}

int main()
{
	int a,b,t;
	cin>>a>>b>>t;
	int ans = t/a*b;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s, t;
    cin >> s >> t;
    ll sl = s.length();
    ll tl = t.length();
    map<char, vector<ll>> smap;
    ll ans = 0;
    
    rep(i, sl) {
        smap[s[i]].push_back(i);
    }
    
    rep(i, tl) {
        if (sz(smap[t[i]]) == 0) {
            cout << -1 << endl;
            return 0;
        }
        
        ll idx = ans % sl;
        ll hit = lower_bound(all(smap[t[i]]), idx) - smap[t[i]].begin();
        
        if (hit >= sz(smap[t[i]])) {
            ans += sl - idx + smap[t[i]][0] + 1;
        }
        else {
            ans += smap[t[i]][hit] - idx + 1;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1736
package main

import (
	"fmt"
	"sort"
)

type Arm struct {
	position int
	length   int
}

type Arms []Arm

func (x Arms) Len() int {
	return len(x)
}

func (x Arms) Swap(i, j int) {
	x[i], x[j] = x[j], x[i]
}

func (x Arms) Less(i, j int) bool {
	return x[i].position < x[j].position
}

func isCross(a, b Arm) bool {
	rightA := a.position + a.length
	leftB := b.position - b.length
	return rightA > leftB
}

func main() {
	var n int
	var x []Arm

	fmt.Scan(&n)
	x = make([]Arm, n)
	for i := 0; i < n; i++ {
		var position, length int
		fmt.Scan(&position)
		fmt.Scan(&length)
		x[i].position = position
		x[i].length = length
	}

	sort.Sort(Arms(x))

	var remains int = n
	var target Arm = x[0]
	for i := 1; i < n; i++ {
		if isCross(target, x[i]) {
			remains--
			if target.position+target.length > x[i].position+x[i].length {
				target = x[i]
			}
		} else {
			target = x[i]
		}
	}

	fmt.Println(remains)
}

func scanNums(len int) (nums []int) {
	var num int
	var i int
	for i = 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 5504
#include <iostream>
#include <cstring>
#include <cmath> 
#include <algorithm>

using namespace std;

const int maxn=1e3+10,mod=1e9+7;
int n,m,va;
char c;
unsigned long long map[maxn][maxn],f[maxn][maxn];

int main()
{
	//memset(f,1,sizeof(f));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>c;
			if(c=='#')
			{
				map[i][j]=-1;
			}
		}
	}
	f[1][1]=1;
	for(int i=1;i<=n;i++)
    {
	    for(int j=1;j<=m;j++)
	    {
	    	if(map[i][j]==-1)
			{
				f[i][j]=0;
			} 
			else
			{
				f[i][j]=max(f[i][j],f[i-1][j]+f[i][j-1]);
				f[i][j]%=mod;
			}
	    }
    }
//    for(int i=1;i<=n;i++)
//    {
//    	for(int j=1;j<=m;j++)
//    	{
//    		cout<<f[i][j]<<" ";
//		}
//    	cout<<endl;
//	}
	cout<<endl; 
	cout<<f[n][m]%mod<<endl;
    return 0;
}

Measured memory_bytes: 16128