akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        const double btcRate = 380000.0;

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var dict = new Dictionary<string, double>();
            dict["JPY"] = 0;
            dict["BTC"] = 0;

            var tmp = new string[2];
            for (var i = 0; i < n; i++)
            {
                tmp = Console.ReadLine().Split();
                dict[tmp[1]] += double.Parse(tmp[0]);
            }

            var total = dict["JPY"] + dict["BTC"] * btcRate;

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13152
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string.h>
#define sf(n) scanf("%d",&n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define ll long long
#define mod 1000000007
#define INF 400000
using namespace std;
int main(){
    string x;
    cin>>x;
    int l=x.length();
    int num1=0,num2=0;
    char k='0';
    for(int i=0;i<l;i++){
        if(x[i]==k){
            num1++;
        }
        else{
            num2++;
        }
        k='0'+'1'-k;
    }
    printf("%d\n",min(num1,num2));
}


Measured memory_bytes: 512
//確定するものから決める. iが大きい方から決める.
#include <iostream>
#define int long long
using namespace std;

int n;
int a[100000], b[100000];

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i] >> b[i];
	
	int cnt = 0;
	for (i = n - 1; i >= 0; i--) {
		int r = (a[i] + cnt) % b[i];
		if (r == 0) r = b[i];
		cnt += b[i] - r;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std ;
long long int power(long long int a,long long int n,long long int m) ;
 long long int power(long long int a,long long int n,long long int m)
{  if(n==0)
   return 1 ;
   long long int x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
int main()
{ long long int n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,m1 ;
  string s  ;
  cin>>s ;
  if(s[0]=='7'||s[1]=='7'||s[2]=='7')
    cout<<"Yes" ;
  else cout<<"No" ;
  return 0 ; }


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

int main()
{
    int a, b;
    cin >> a >> b;
    int s = 0;
    if(b / 100 == 1) s = 1000 * a + b;
    else if(b / 10 != 0) s = 100 * a + b;
    else s = 10 * a + b;
    string ans = "No";
    for(int i = 1; i * i <= s; i++) {
        if(i * i == s) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        Heap piorityQueue = new Heap();
        while(true)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            switch (inputs[0])
            {
                case "insert": piorityQueue.Insert(int.Parse(inputs[1])); break;
                case "extract": Console.WriteLine(piorityQueue.ExtractMax()); break;
                case "end": return;
            }
        }
    }
}

class Heap
{
    private const int MaxSize = 2000000;
    public int Count {get; set;} // = 0;
    private int[] elements;
    public int this[int i]
    {
        get {return elements[i];}
        set {elements[i] = value;}
    }
    public Heap() : this(MaxSize) {}
    public Heap(int size)
    {
        elements = new int[size];
        Count = 0;
    }
    public Heap(int[] array)
    {
        Count = array.Length;
        elements = new int[Count];
        for (int i = 0; i < Count; i++)
        {
            elements[i] = array[i];
        }
    }
    private int LeftOf(int i)
    {
        int val = 2 * (i + 1) - 1;
        return val < Count ? val : -1;
    }
    private int RightOf(int i)
    {
        int val = 2 * (i + 1);
        return val < Count ? val : -1;
    }
    private int ParentOf(int i)
    {
        int val = (i + 1) / 2 - 1;
        return val >= 0 ? val : -1;
    }
    public void BuildMaxHeap()
    {
        for (int i = Count / 2 - 1; i >= 0 ; i--)
        {
            Modify(i);
        }
    }
    private void Modify(int i)
    {
        int l = LeftOf(i);
        int r = RightOf(i);
        int largest = i;
        if(l != -1 && elements[l] > elements[i]) largest = l;
        if(r != -1 && elements[r] > elements[largest]) largest = r;
        if(largest != i)
        {
            Swap(i, largest);
            Modify(largest);
        }
    }
    private void Swap(int i, int j)
    {
        int tmp = elements[i];
        elements[i] = elements[j];
        elements[j] = tmp;
    }
    public void Display()
    {
        for (int i = 0; i < Count; i++)
        {
            Console.Write(" " + elements[i]);
        }
        Console.WriteLine();
    }

    public void Insert(int val)
    {
        int i = Count++;
        elements[i] = val;
        while(i > 0 && elements[ParentOf(i)] < elements[i])
        {
            Swap(ParentOf(i), i);
            i = ParentOf(i);
        }
    }
    public int ExtractMax()
    {
        if(Count <= 0) return -1;
        int tmp = elements[0];
        elements[0] = elements[--Count];
        Modify(0);
        return tmp;
    }
}

Measured memory_bytes: 23428
#include <iostream>
#include <string>
#include <vector>
#define rep(i, j) for (long long i = 0; i < j; i++)

using namespace std;

signed main()
{
    int a;
    string str;
    cin >> a;
    cin >> str;
    if (a >= 3200) {
        cout << str << endl;
    } else {
        cout << "red" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<stack>
#include<algorithm>
#include<climits>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define vll vector<ll>
#define mii map<ll, ll>
#define debug(x) cerr << #x << " is " << x << "\n";
#define debug1(x, y) cerr << #x << " is " << x << "\n" << #y << " is " << y << "\n";
#define w(x) ll x; cin >> x; while(x--)
#define endl "\n"
#define f first 
#define s second 
#define fo(n) for(ll i = 0LL; i < n; ++i) 
#define setbits(n) __builtin_popcount(n)
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(x.begin(), x.end())
#define pb push_back
#define mk make_pair
#define PERMUTE next_permutation
#define RESET(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
using namespace std;

const int MAX = 1e5 + 1;
vector<int> adj[MAX];
vector<int> dp(MAX, 0);
vector<int> inDegree(MAX, 0);
vector<bool> visited(MAX, false);

void dfs(int u) {
    visited[u] = true;
    for(int v: adj[u]) {
        dp[v] = max(dp[u] + 1, dp[v]);
        inDegree[v]--;
        if(!inDegree[v]) {
            dfs(v);
        }
    }
}

int main(){
    fast
    int n, m, ans = 0;
    cin >> n >> m;
    fo(m) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        inDegree[v]++;
    }
    for(int i = 1; i <= n; ++i) {
        if(!visited[i] && inDegree[i] == 0) 
            dfs(i);
    }
    for(int i = 1; i <= n; ++i)
        ans = max(ans, dp[i]);
    cout << ans << endl;

    return 0;
}

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

int main()
{
  string a;
  cin >> a;
  if (a == "MON"){
    cout << 6 << endl;
  }
  if (a == "TUE"){
    cout << 5 << endl;
  }
  if (a == "WED"){
    cout << 4 << endl;
  }
  if (a == "THU"){
    cout << 3 << endl;
  }
  if (a == "FRI"){
    cout << 2 << endl;
  }
  if (a == "SAT"){
    cout << 1 << endl;
  }
  if (a == "SUN"){
    cout << 7 << endl;
  }
}

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

using namespace std;
int n,l,pos,a,b;

int main()
{
	scanf("%d%d%d",&n,&l,&a);
	for(int i=2;i<=n;i++)
	{
		b=a;scanf("%d",&a);
		if(a+b>=l) pos=i-1; 
	}
	if(!pos) return puts("Impossible"),0;
	puts("Possible");
	for(int i=1;i<=pos-1;i++) printf("%d\n",i);
	for(int i=n-1;i>=pos;i--) printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 768
a,b,c = map(int,input().split())
if a<=b<=c:
    print(f"{a} {b} {c}")
elif a<=c<=b:
    print(f"{a} {c} {b}")
elif b<=a<=c:
    print(f"{b} {a} {c}")
elif b<=c<=a:
    print(f"{b} {c} {a}")
elif c<=a<=b:
    print(f"{c} {a} {b}")
elif c<=b<=a:
    print(f"{c} {b} {a}")


Measured memory_bytes: 5608
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
#define MAX 50
int h,w,s;
int t[MAX][MAX],u[MAX][MAX];
int calc(int ay,int ax,int by,int bx){
  return u[by][bx]-u[ay-1][bx]-u[by][ax-1]+u[ay-1][ax-1];
}
P dp[MAX][MAX][MAX][MAX];

P rec(int ay,int ax,int by,int bx){
  if(dp[ay][ax][by][bx].first!=-1)return dp[ay][ax][by][bx];
  int sum=u[h][w]-calc(ay,ax,by,bx);
  if(sum>s)return P(-1,1e8);
  P res=P(1,s-sum);
  for(int i=ay;i<by;i++){
    P a=rec(ay,ax,i,bx),b=rec(i+1,ax,by,bx);
    if(a.first==-1||b.first==-1)continue;
    res=max(res,P(a.first+b.first,min(a.second,b.second)));
  }
  for(int j=ax;j<bx;j++){
    P a=rec(ay,ax,by,j),b=rec(ay,j+1,by,bx);
    if(a.first==-1||b.first==-1)continue;
    res=max(res,P(a.first+b.first,min(a.second,b.second)));
  }
  return dp[ay][ax][by][bx]=res;
}

int main(){
  while(1){
    cin>>h>>w>>s;
    if(h==0&&w==0&&s==0)break;
    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
	cin>>t[i][j];
	u[i][j]=t[i][j]+u[i-1][j]+u[i][j-1]-u[i-1][j-1];
	for(int k=1;k<=h;k++)
	  for(int l=1;l<=w;l++)
	    dp[i][j][k][l].first=-1;
      }
    }
    P ans=rec(1,1,h,w);
    cout<<ans.first<<' '<<ans.second<<endl;
  }
  return 0;
}

Measured memory_bytes: 50016
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,Q = map(int,readline().split())
m = map(int,read().split())
ABC = list(zip(m,m,m))

INF = 10 ** 18
cyclic_cost = [INF] * N
for a,b,c in ABC:
    if cyclic_cost[a] > c + 1:
        cyclic_cost[a] = c + 1
    if cyclic_cost[b] > c + 2:
        cyclic_cost[b] = c + 2

cyclic_cost += cyclic_cost # 2周分
x = INF
for i in range(N+N):
    x += 2
    if x < cyclic_cost[i]:
        cyclic_cost[i] = x
    x = cyclic_cost[i]
cyclic_cost = [x if x < y else y for x,y in zip(cyclic_cost, cyclic_cost[N:])]

ABC += [(i,i+1,c) for i,c in enumerate(cyclic_cost)]
ABC[-1] = (N-1,0,cyclic_cost[-1])

class UnionFind:
    def __init__(self,N):
        self.root = list(range(N))
        self.size = [1] * (N)
        
    def find_root(self,x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x
    
    def merge(self,x,y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return False
        sx,sy = self.size[x],self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy
        return True

ABC.sort(key = itemgetter(2))

uf = UnionFind(N)
merge = uf.merge
answer = 0
for a,b,c in ABC:
    if merge(a,b):
        answer += c

print(answer)

Measured memory_bytes: 91160
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<62);

using namespace std;
vi v, ind;
bool comp(int a, int b){
	return v[a] < v[b];
}
int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
	cin >> n;
	v.resize(n);
	f(i, n) ind.pb(i);
	f(i, n) cin >> v[i];
	sort(all(ind), comp);
	f(i, n) cout << ind[i] + 1 << " ";
	cout << endl;
    return 0;
}


Measured memory_bytes: 2548
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			String[] tmpArray = str.split(" ");
			
			int y = Integer.parseInt(tmpArray[0]);
			int m = Integer.parseInt(tmpArray[1]);
			int d = Integer.parseInt(tmpArray[2]);
			
			int ymd = y*10000 + m * 100 + d;
			
			if(ymd >= 19890108){
				System.out.printf("heisei %d %d %d\n", y - 1988, m, d);
			}

			else if(ymd >= 19261225){
				System.out.printf("showa %d %d %d\n", y - 1925, m, d);
			}

			else if(ymd >= 19120730){
				System.out.printf("taisho %d %d %d\n", y - 1911, m, d);
			}

			else if(ymd >= 18680908){
				System.out.printf("meiji %d %d %d\n", y - 1867, m, d);
			}
			else {
				System.out.printf("pre-meiji\n");
			}


		}
	}

}

Measured memory_bytes: 24528
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy

MODULO = pow(10, 9) + 7


def solve(values, h, w):
    dp = [[0] * (1 + w) for _ in range(1 + h)]
    dp[1][1] = 1
    for i in range(h):
        for j in range(w):
            if i + j != 0 and values[i][j] == ".":
                LOG.debug((i, j, values[i][j]))
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MODULO
    LOG.debug("\n".join(map(str, dp)))
    return dp[h][w]


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    H, W = map(int, input().split())
    values = []
    for _ in range(H):
        values.append(input())
    result = solve(values, H, W)
    print(result)


def configure_log():
    "Configure the log output"
    log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)


Measured memory_bytes: 69392
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

int d[256][256];

void solve(ll N, ll M, ll R, vector<ll> r, vector<ll> A, vector<ll> B, vector<ll> C) {
  REP(i,N) REP(j,N) d[i][j] = 1e9;
  REP(i,N) d[i][i] = 0;
  REP(i,M) {
    const int s = A[i] - 1;
    const int t = B[i] - 1;
    const int c = C[i];
    chmin(d[s][t], c);
    chmin(d[t][s], c);
  }
  REP(k,N) REP(i,N) REP(j,N) chmin(d[i][j], d[i][k] + d[k][j]);
  REP(i,R) r[i]--;
  sort(ALL(r));
  int res = 1e9;
  do {
    int sum = 0;
    REP(i,R-1) sum += d[r[i]][r[i+1]];
    chmin(res, sum);
  } while (next_permutation(ALL(r)));
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll M;
	ll R;
	ll N;
	scanf("%lld", &N);
	scanf("%lld", &M);
	vector<ll> A(M-1+1);
	vector<ll> C(M-1+1);
	vector<ll> B(M-1+1);
	scanf("%lld", &R);
	vector<ll> r(R-1+1);
	for (int i = 0 ; i <= R-1 ; i++) {
	  scanf("%lld", &r[i]);
	}
	for (int i = 0 ; i <= M-1 ; i++) {
	  scanf("%lld", &A[i]);
	  scanf("%lld", &B[i]);
	  scanf("%lld", &C[i]);
	}
	solve(N, M, R, r, A, B, C);
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;
int a[200005];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum=0;
    cin>>n;
    f(i,0,n) {
        cin>>a[i];
        sum+=a[i];   
    }
    sum%=mod;
    int ans=0;
    f(i,0,n) {
        sum-=a[i];
        sum+=mod;
        sum%=mod;
        ans=(ans+a[i]*sum)%mod;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 5216
n = int(input())
w = list()
f = input()
w.append(f)
cnt = 0
for i in range(1, n):
    x = input()
    a = w[i-1]
    if a[-1] == x[0]:
        if x not in w:
            cnt += 1
            w.append(x)
            if cnt == n-1:
                print("Yes")
                break
        else:
            print("No")
            break
    else:
        print("No")
        break

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

string s;
int n;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    n = s.size();
    rep(i, n) {
        if (s[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}



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

int main(void) {
  int N, Q; cin >> N >> Q;
  string S; cin >> S;
  vector<int> L(Q);
  vector<int> R(Q);
  vector<int> A(N);
  
  for (int i=0; i<Q; i++) {
    cin >> L[i] >> R[i];
  }
  
  int cnt = 0;
  A[0] = 0;
  for (int i=1; i<N; i++) {
    if (S[i] == 'C' && S[i-1] == 'A') cnt++;
    A[i] = cnt;
  }
  
  for (int i=0; i<Q; i++) {
    cout << A[R[i]-1] - A[L[i]-1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4552
tri=0
sh=0
rec=0
dul=0

while True:
    L=input().split( )
    E=[int(L[i]) for i in range(3)]
    mx=max(E)
    sm=sum(E)
    quad_sum=E[0]**2+E[1]**2+E[2]**2

    if mx*2>=sm:
        print(tri,rec,sh,dul)
        break
    else:
        tri+=1
        if mx**2*2>quad_sum:
            dul+=1
        elif mx**2*2==quad_sum:
            rec+=1
        else:
            sh+=1



Measured memory_bytes: 5604
import math
import itertools
import statistics
import collections

n = int(input())
#a = list(map(int, input().split()))
d = []
for i in range(n):
    d.append(int(input()))

d.sort(reverse=True)
count = 1
for i in range(n-1):
    if d[i]>d[i+1]:
        count +=1

#print(d)
print(count)

Measured memory_bytes: 5264
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    int ret = 0;
    for(size_t i=0;i<s.size();i++){
        if(s[i] == t[i]) ret++;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

struct data {
    int id;
    int pref;
    int year;
    int ord;
};
bool year_asc(const data& left, const data& right) {
    return left.year < right.year;
}
bool id_asc(const data& left, const data& right) {
    return left.id < right.id;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<data> datas;
    rep(i, m) {
        int p, y;
        cin >> p >> y;
        data d = {i, p, y};
        datas.pb(d);
    }
    sort(datas.begin(), datas.end(), year_asc);

    vi nums(n, 0);
    rep(i, m) datas[i].ord = ++nums[datas[i].pref - 1];
    sort(datas.begin(), datas.end(), id_asc);
    for (auto d: datas) {
        cout << setfill('0') << right << setw(6) << d.pref;
        cout << setfill('0') << right << setw(6) << d.ord << endl;
    }
}


Measured memory_bytes: 3440
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] L = new int[N];
        
        int max = 0;
        int maxIndex = 0;
        for(int i = 0; i < N; i++){
            L[i] = sc.nextInt();
            
            if( max < L[i]){
                max = L[i];
                maxIndex = i;
            }
        }
        
        int sum = 0;
        for(int i = 0; i < N; i++){
            if( i != maxIndex ) sum += L[i];
        }

        System.out.println( max < sum ? "Yes" : "No" );
        
    }
}


Measured memory_bytes: 22736
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N,M;
int C[1010];
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		C[x-1]++;
		C[y-1]++;
	}
	FOR(i,N) cout<<C[i]<<endl;
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll r, g, b, n;
    cin >> r >> g >> b >> n;
    ll ans = 0;
    rep(i, 3001) {
        rep(j, 3001) {
            ll rem = n - r * i - g * j;
            if ((rem < 0) || (rem % b != 0)) continue;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)

#全体の数列について答えを求めるnC2=n(n-1)/2
ALL=0
for i in c.values():
  if i>1:
    ALL += i*(i-1)//2

#各要素が影響する分を求める
for i in A:
  if c[i]>2:
    print(ALL-c[i]+1)
  elif c[i]==2:
    print(ALL-1)
  else:
    print(ALL)

Measured memory_bytes: 33932
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

 map<int,int> ds;	//上下级关系
 //map<int, int> ranks;

int FindSup(int root)
{
	if (ds[root] == root)
		return root;
	ds[root] = FindSup(ds[root]);
	return ds[root];
}

void Union(int root1, int root2)
{
	int x = FindSup(root1);
	int y = FindSup(root2);
	if (x == y)
		return;
	if (x> y)
		ds[y] = x;
	else
		ds[x] = y;
	/*else
	{
		ds[x] = y;
		ranks[y]++;
	}*/
}

int main()
{
	int N, M, cnt = 0;
	int x, y;
	scanf("%d %d", &N, &M);

	for (int i = 1; i <= N; i++)
	{
		ds[i] = i;
		//ranks[i] = 0;
	}	

	for (int i = 0; i < M; i++)
	{	
		scanf("%d %d", &x, &y);
		if (FindSup(x) != FindSup(y))
		{
			Union(x, y);
			cnt++;
		}	
	}
	cnt = N - 1 - cnt;
	if (cnt < 0)
		cnt = 0;
	printf("%d", cnt);
	 
	 return 0;
}

Measured memory_bytes: 8480
/*

Author: @karngyan
Team: BlundersPride

*/

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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair

const ll N = 1e5 + 10;
const ll INF = 1e15;
ll n , k;
ll h[N];
ll dp[N];

ll go(ll i)
{
	if(i <= k)
		return abs(h[i] - h[1]);

	ll &ans = dp[i];
	if(ans != INF)
		return ans;

	for(ll j = 1; j<=k ; j++)
	{
		ans = min( ans , go(i-j) + abs(h[i] - h[i-j]));
	}
	return ans;
}
signed main()
{

	fast;
	// memset(dp , -1 , sizeof dp);
////////////////////////////////////////////////////////////////////////////////////////////

	cin >> n >> k;
	rep(i,1,n+1)
	{
		cin >> h[i];
		dp[i] = INF;
	}
	cout<<go(n)<<endl;






////////////////////////////////////////////////////////////////////////////////////////////

	
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define INF (int)1e9
#define fora(i,a,b) for(ll i=a;i<b;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp(x,y) make_pair(x,y)
#define mii map<int,int>
using namespace std;

  long long int cal(long long int N,long long int po,long long int MOD){


      if(N==0 || N==1) return N%MOD;

      if(po==0) return 1;

       if(MOD==1) return 0;

      long long int ans=1;

        while(po){

            if(po%2){

               ans=(ans*N)%MOD;
            }

            N=(N*N)%MOD;
            po/=2;
        }
    return ans;
  }
  
long modPow(long a, long x, long p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long modInverse(long a, long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
long modBinomial(long n, long k, long p) {
// calculates C(n,k) mod p (assuming p is prime).

    long numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    long denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
int main()
{   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n,a,b,sum=0;
    cin>>n>>a>>b;
    sum+=cal(2,n,1000000007)-1;
    //cout<<sum<<"&";
    sum+=-modBinomial(n, a,1000000007 )-modBinomial(n, b,1000000007 );
    if(sum<-1000000007)
    cout<<sum+2*1000000007;
    else if(sum<0)
    cout<<sum+1000000007;
    else
    cout<<sum%1000000007;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}
 
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}


int dp[2020][2020];

signed main(){
	IOS();
	int H,W;
	cin>>H>>W;
	string s[H];
	rep(i,0,H){
		cin>>s[i];
	}
	rep(i,0,H){
		int cnt = 0;
		rep(j,0,W){
			dp[i][j] += cnt;
			if(s[i][j]=='.')cnt++;
			else cnt = 0;
		}
		cnt = 0;
		rrep(j,0,W){
			dp[i][j] += cnt;
			if(s[i][j]=='.')cnt++;
			else cnt = 0;
		}
	}
	rep(j,0,W){
		int cnt = 0;
		rep(i,0,H){
			dp[i][j] += cnt;
			if(s[i][j]=='.')cnt++;
			else cnt = 0;
		}
		cnt = 0;
		rrep(i,0,H){
			dp[i][j] += cnt;
			if(s[i][j]=='.')cnt++;
			else cnt = 0;
		}
	}
	int ma = 0;
	pint id;
	rep(i,0,H)rep(j,0,W)if(s[i][j]=='.')if(chmax(ma,dp[i][j]+1))id={i+1,j+1};
	cout<<ma<<endl;
}

Measured memory_bytes: 36096
n = int(input())
s = [0]*n

ans = 0
initb = 0
lasta = 0
add = 0
juuhuku = 0
flag = 0

for i in range(n):
    s[i] = input()
    st = s[i]

    if st[0] == "B":
        initb += 1

        if st[len(st)-1] == "A":
            lasta += 1
            juuhuku += 1
        else:
            flag += 1

    elif st[len(st)-1] == "A":
        lasta += 1
        flag += 1

    for j in range(len(st)):

        if st[j] == "A":

            if j == len(st) - 1:
                break
            if st[j+1] == "B":
                ans += 1

if initb <= lasta:
    add = initb
else:
    add = lasta

if juuhuku > 0:

    if flag > 0:
        ans = ans + add 
    else:
        ans = ans + add -1

else:
    ans = ans + add

print(ans)

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int INF = 1e9 + 5;
#define ll long long
#define EMPTY (-1)
int main() {
	int N, W;
	cin>>N>>W;
	vector<ll> w(N), v(N);
	for(int i=0;i < N; i++) {
		cin>>w[i]>>v[i];
	}
	vector<ll> dp(W+1, EMPTY);
	dp[0] = 0;
	for(int i=0;i<N;i++) {
		for(int j=W; j>=0; j--) {
			if(j-w[i]>=0 && dp[j-w[i]] != EMPTY)
				dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
		}
	}
	ll ans = 0;
	for(int i=0;i<=W;i++) {
		ans = max(ans, dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(ll i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
int main()
{
    int n;
    cin>>n;
    int a[n];
    ll x;
    loop(n){
        cin>>a[i];
        if(i)
            x^=a[i];
        else
            x=a[i];
    }
    if(!x)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/// 20
/// 15 7 13 15 15 15 15 13 19
/*

*/


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(S: str):
    ab = int(S[:2])
    db = int(S[2:])

    yymm = False
    if (0 <= ab <= 99) and (1 <= db <= 12):
        yymm = True
    mmyy = False
    if (0 <= db <= 99) and (1 <= ab <= 12):
        mmyy = True

    if yymm and mmyy:
        return 'AMBIGUOUS'
    if not (yymm or mmyy):
        return 'NA'

    if yymm:
        return 'YYMM'

    return 'MMYY'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = (next(tokens))  # type: int
    result = solve(S)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5632
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	A, B := sc.nextInt(), sc.nextInt()
	diff := A - 2*B
	if diff > 0 {
		fmt.Println(diff)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 640
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;


int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  rep(i,n) cout << s[i] << t[i];
  cout << endl;
}


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

using namespace std;

#define pb push_back

typedef long long ll;

const int maxs = 100010;
const int maxn = 41;
const int lim = 10;
const int mod = 1000000007;

int N, arr[4], state_cnt = 0, to[maxs][lim+1], fail_state[maxs], end_state[maxs];
int root = 0;
ll dp[maxn][maxs];

void insert(vector<int> &haiku)
{
	int cur_state = root;	
	for(int i=0; i<haiku.size(); i++){
		if(!to[cur_state][haiku[i]]){
			++state_cnt;
			to[cur_state][haiku[i]] = state_cnt;
		}
		cur_state = to[cur_state][haiku[i]];
	}
	end_state[cur_state] = 1;
}

void generate(vector<int> &haiku, int cnt, int sum)
{
	if(haiku.size() > N)
		return;
	if(sum == arr[cnt]){
		cnt++;
		sum = 0;
	}
	if(cnt>3){
		insert(haiku);
		return;	
	}	
	for(int i=1; i+sum<=arr[cnt]; i++){
		haiku.pb(i);
		generate(haiku, cnt, sum+i);
		haiku.pop_back();
	}
}

void ahoc()
{
	queue<int> q;
	for(int i=1; i<=lim; i++){
		if(to[root][i]){
			fail_state[to[root][i]] = root;
			q.push(to[root][i]);	
		}	
	}
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int i=1; i<=lim; i++){	
			if(!to[u][i])
				continue;
			int v = fail_state[u];
			while(v && !to[v][i])
				v = fail_state[v];			
			fail_state[to[u][i]] = to[v][i];		
			end_state[to[u][i]] |= end_state[to[v][i]];
			q.push(to[u][i]);
		}
	}
}

ll solve(int cur, int state)
{
	if(cur > N)
		return 1;
	if(dp[cur][state] != -1)
		return dp[cur][state];
	ll ret = 0;	
	for(int i=1; i<=lim; i++){
		int u = state;
		while(u && !to[u][i])
			u = fail_state[u];
		u = to[u][i];
		if(!end_state[u])
			ret = (ret + solve(cur+1, u))%mod;	
	}	
	return dp[cur][state] = ret;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	scanf("%d%d%d%d", &N, &arr[1], &arr[2], &arr[3]);
	vector<int> haiku;	
	generate(haiku, 1, 0);
	ahoc();
	ll ans = 1;
	for(int i=1; i<=N; i++)
		ans = (ans*10)%mod;
	ans = (ans - solve(1, 0) + mod)%mod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 34048
import math

def combination(n,r):
    return int(math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))

if __name__=="__main__":
    N,K=map(int,input().split())
    a=1000000007
    result=0

    if N==K:
        for i in range(K):
            if i==0:
                print(1)
            else:
                print(0)
    else:
        for i in range(1,K+1):
            if N-K+1-i<0:
                print(0)
            else:
                result=int(combination(N-K+1,i)*combination(K-1,i-1))
                print(result%a)

Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main(){
  int n, a[200000];
  cin >> n;
  int m1 = -1, m2 = -1;
  for(int i=0; i<n; i++){
    cin >> a[i];
  	if (a[i] > m1) {
		m2 = m1;
      	m1 = a[i];
    }else if(a[i] > m2){
      	m2 = a[i];
    }
  }
  for(int i=0; i<n; i++){
    if(a[i] == m1)cout << m2 << endl;
    else cout << m1 << endl;
  }
  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int H, W, K;

int main()
{
  int N;
  cin >> N;
  map<int, int> a;

  REP(i, 1, N + 1)
  {
    map<int, int> tmp = prime_factor(i);
    for (auto p:tmp){
      a[p.first] += p.second;
    }
  }

  
  ll ans = 0;
  for(auto p:a){
    if(p.second>=74){
      ans++;
    }
    for(auto q:a){
      if(q.first!=p.first){
        if(p.second>=14&&q.second>=4){
          ans++;
        }
        if(p.second>=24&&q.second>=2){
          ans++;
        }
        if(p.first<q.first){
          for(auto k:a){
            if(k.first!=q.first&&k.first!=p.first){
              if(p.second>=4&&q.second>=4&&k.second>=2){
                ans++;
                
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
	int n;
	while(cin >> n, n) {
		vi v(n);
		rep(i, n) cin >> v[i];
		sort(all(v));
		int s = accumulate(v.begin() + 1, v.end() - 1, 0);
		cout << s / (n - 2) << endl;
	}
}

Measured memory_bytes: 3104
N,A,B = [int(x) for x in input().split(" ")]

if(A > B) or (N == 1 and A != B):
	print("0")
else:
	Smin = A * (N - 1) + B
	Smax = B * (N - 1) + A

	print(Smax - Smin + 1)

Measured memory_bytes: 2940
using System;

class Program
{
    static void Main(string[] args)
    {
        var num = Convert.ToInt32(Console.ReadLine());
        var haveOne = Convert.ToInt32(Console.ReadLine());
        if (num % 500 == 0) Console.WriteLine("Yes");
        else if (num - num / 500 * 500 <= haveOne) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

struct UnionFind{
  vint d;
  UnionFind(int x = 0) : d(x,-1){}

  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

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

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

  int  size(int x){return -d[find(x)];}
};

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vint deg(100005);
  vvint to(100005,vint(0));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }

  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);    
  }

  rep(i,n){
    int ans = uf.size(i) - 1 - deg[i];
    for(int p:to[i]){
      if(uf.same(i,p)) ans--;
    }
    printf("%d%c",ans,i==n-1?'\n':' ');
  }
  return 0;
}

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

int main(){
    int n; cin>>n;
    vector<int> b(n-1);

    for(int i=0; i<n-1; i++) cin>>b[i];

    ll ans = 0;

    //最初と最後の項は与えられた数列と一緒

    ans += b[0];

    ans += b[n-2];

    for(int i=1; i<n-1; i++)ans += min(b[i],b[i-1]);

    cout<<ans<<endl;

    return 0;
    
}

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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char a[3];
  for(int i=0;i<4;i++){
  scanf("%c",&a[i]);
  }
  if (a[0]==a[1]&&a[2]==a[3]&&a[0]!=a[2]){
    printf("Yes");
  }
  else if(a[0]==a[2]&&a[1]==a[3]&&a[0]!=a[1]){
    printf("Yes");
  }
  else if(a[0]==a[3]&&a[2]==a[1]&&a[0]!=a[2]){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 3552