akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    if len(A)==len(set(A)):
        print('YES')
    else:
        print('NO')




if __name__ == "__main__":
    main()

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

int main() {
  ll n, m;
  cin >> n >> m;

  vector<bool> cleared(n + 1);
  vector<ll> pena(n + 1);
  for (ll i = 1; i <= n; i++) {
    cleared[i] = false;
    pena[i] = 0;
  }
  
  ll correct = 0;
  ll penalty = 0;
  ll p;
  string s;

  for (ll i = 0; i < m; i++) {
    cin >> p >> s;
    if (!cleared[p] && s == "WA") {
      pena[p]++;
    }
    if (!cleared[p] && s == "AC") {
      correct++;
      penalty += pena[p];
      cleared[p] = true;
    }
  }

  cout << correct << " " << penalty << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	for(int n;scanf("%d",&n),n;){
		int m;	scanf("%d ",&m);
		int cnt=0,len=0;
		bool f=false;
		for(char bf='@';m--;){
			char c=getchar();
			if     (bf=='I' && c=='I')	len=0,f=false;
			else if(bf=='O' && c=='O')	len=0,f=false;
			else if(bf=='I' && c=='O')	f=true;
			else if(bf=='O' && c=='I' && f){
				len++;
				if(n<=len)	cnt++;
			}
			bf=c;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0
using System;

public class Hello
{
    public static void Main()
    {
        var a1 = "maerd";
        var a2 = "esare";
        var a3 = "resare";
        var a4 = "remaerd";
        var s2 = Console.ReadLine().Trim();
        var w = s2.ToCharArray();
        Array.Reverse(w);
        var s = new string(w);
        var sL = s.Length;
        var p = 0;
        while (true)
        {
            if (p + 5 > sL) { Console.WriteLine("NO"); break; }
            var w5 = s.Substring(p, 5);
            if (p + 5 == sL && (w5 == a1 | w5 == a2)) { Console.WriteLine("YES"); break; }
            if (p + 6 == sL && s.Substring(p, 6) == a3) { Console.WriteLine("YES"); break; }
            if (p + 7 == sL && s.Substring(p, 7) == a4) { Console.WriteLine("YES"); break; }
            if (w5 == a1 | w5 == a2) { p += 5; goto next; }
            if (p + 6 < sL && s.Substring(p, 6) == a3) { p += 6; goto next; }
            if (p + 7 < sL && s.Substring(p, 7) == a4) { p += 7; goto next; }
            { Console.WriteLine("NO"); break; }
            next:;
        }
    }
}


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

int main() {
  string s;
  cin >> s;
  int x = s.size();
  int cnt = 0;
  
  for(int i=0;i<(x/2);i++){
    if(s.at(i) != s.at(x-i-1)) cnt++;
  }
  cout << cnt << endl;        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main()
{
    int x , n , p , ans = 100000; 
    bool isp[102] = {};
    
    cin >> x >> n;
    
    for(int i=0 ;i<n ;i++ ){
        cin >> p;
        isp[p] = true;
    }
    
    for(int i=101 ;i>=0 ;i-- ){
        if(isp[i] == false){
            if( abs(x - i) <= abs(x - ans)){
                ans = i;
            }
        }
    }
    
    cout << ans << endl;
    
    return (0);
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

typedef pair<int,int> P;
vector<P> G[810];
int to[810],cost[810];

P dfs(int p,int v){
    P r(0,v);
    for(auto&& e:G[v]){
        if(e.first!=p){
            P t = dfs(v,e.first);
            if(G[e.first].size()!=1) t.first += e.second;
            if(r.first<t.first)r=t;
        }
    }
    return r;
}

int diameter(){
    P r = dfs(-1,1);
    P t = dfs(-1,r.second);
    return t.first;
}

int main(){
    int n;
    while(cin>>n,n){
        int ans = 0;
        for(int i=0;i<n-1;i++){
            cin >> to[i];
        }
        for(int i=0;i<n-1;i++){
            cin >> cost[i];
            ans += 3*cost[i];
        }
        for(int i=0;i<n-1;i++){
            G[i+2].push_back({to[i],cost[i]});
            G[to[i]].push_back({i+2,cost[i]});
        }
        for(int i=1;i<=n;i++){
            if(G[i].size()==1)ans-=2*G[i][0].second;
        }
        int d = diameter();
        ans -= d;
        cout << ans << endl;
      	for(int i=0;i<=n;i++)G[i].clear();
    }
    return 0;
}


Measured memory_bytes: 3256
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

def resolve():
    Q = I()
    lr = [LI() for _ in range(Q)]

    r_max = max([i[1] for i in lr])
    primes = set(sieve(r_max))

    acc = [0]*(r_max+2)
    for i in range(r_max+1):
        if i in primes and (i+1)//2 in primes:
            acc[i+1] = acc[i] + 1
        else:
            acc[i+1] = acc[i]

    for i in lr:
        print(acc[i[1]+1]-acc[i[0]])

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 23692
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    
    int ans = 0;
    
    for(int i = 0; i <= n; i++){
        int t = i;
        int cnt = 0;
        while(t > 0){
            cnt += t % 6;
            t /= 6;
        }
        t = n - i;
        while(t > 0){
            cnt += t % 9;
            t /= 9;
        }
        if(i == 0){
            ans = cnt;
        }else{
            ans = min(ans, cnt);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

ll calcS(ll n, ll b){
	return n/b  + n%b;
}

int main(void){
	string s;
	cin>>s;
	if(s.size()==2){
		if(s[0]==s[1]){
			cout<<"1 2"<<endl;
		}else{
			cout<<"-1 -1"<<endl;
		}
		return 0;
	}
	rep(i,s.size()-2){
		if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i+2] == s[i]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<"-1 -1"<<endl;
	return 0;
}


Measured memory_bytes: 512
from collections import deque
import copy
H, W = map(int, input().split())
maze = [list(input()) for i in range(H)]
S = []
for i in range(H):
  for j in range(W):
    if maze[i][j] == ".":
      maze[i][j] = float("inf")
      S.append([i, j])
    else:
      maze[i][j] = -1
def bfs(H, W, maze, S):
  ans = 0
  for sy, sx in S:
    maze1 = copy.deepcopy(maze)
    maze1[sy][sx] = 0
    q = deque()
    q.append([sy,sx])
    while len(q)>0:
      y, x = q.popleft()
      for i, j in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
        nexty = y+i
        nextx = x+j
        if nexty < 0 or nexty>=H or nextx < 0 or nextx>=W:
          continue
        if maze1[nexty][nextx] != -1:
          if maze1[nexty][nextx] > maze1[y][x]+1:
            maze1[nexty][nextx] = maze1[y][x] + 1
            q.append([nexty, nextx])
            ans = max(ans, maze1[nexty][nextx])
  print(ans)
bfs(H, W, maze, S)


Measured memory_bytes: 3444
#include <stdio.h> //partition
#define N 100005
  
int A[N];
 
int Partition(int *,int,int);
 
int main()
{
  int n,i,x;
      
  scanf("%d",&n);
      
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
     
  x=Partition(A,0,n-1);
      
  for(i=0;i<x;i++)
    {
      printf("%d ",A[i]);
    }
  printf("[%d] ",A[x]);
      
  for(i=x+1;i<n-1;i++)
    {
      printf("%d ",A[i]);
    }
  printf("%d\n",A[n-1]);
      
  return 0;
}
 
int Partition(int A[],int p,int r)
{
  int x,i,j,tmp;
      
  x=A[r];
  i = p-1;
      
  for(j=p;j<r;j++)
    {
      if (A[j] <= x)
	{
	  i=i+1;
	  tmp=A[j];
	  A[j]=A[i];
	  A[i]=tmp;
        }
    }
  
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
      
  return i+1;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int c[501], s[501], f[501];
    cin >> n;
    for (int i = 0; i < n - 1; i++)
        cin >> c[i] >> s[i] >> f[i];

    for (int i = 0; i < n - 1; i++)
    {
        int time = s[i] + c[i]; // 2番目の駅
        for (int j = i + 1; j < n - 1; j++)
        {
            time = max(time, s[j]);
            time = ((time + f[j] - 1) / f[j]) * f[j];
            time += c[j];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var l = Input().Select(long.Parse).ToArray();
		Array.Sort(l);
		Array.Reverse(l);
		long wa = 0;
		for(int i = 0; i < l.Length; i++)
		{
			for(int j = i+1; j < l.Length; j++)
			{
				if(l[i] == l[j])
					continue;
				for(int k = j+1; k < l.Length; k++)
				{
					if(l[j] == l[k] || l[k] == l[i] || l[k] + l[j] <= l[i])
						continue;
					wa++;
				}
			}
		}
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 28240
from collections import Counter
N = int(input())
mod = 10 ** 9 + 7

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

primes = []
for i in range(1, N + 1):
    primes += prime_factorize(i)

ans = 1
for v in Counter(primes).values():
    ans *= (v + 1)
    ans %= mod
print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

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

// const int kMaxN;

string a, b, c;
string ans;

int main() {
  cin >> a;
  cin >> b;
  cin >> c;
  // cout << a << endl;
  // cout << a[0]+b[1] << endl;

  ans = a[0];
  ans += b[1];
  ans += c[2];

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            final int K = Integer.parseInt(reader.readLine());
            System.out.println(K / 2 * (K - K / 2));
        }
    }
}


Measured memory_bytes: 21076
import sys
input = sys.stdin.readline

N=int(input())

EDGE=[list(map(int,input().split())) for i in range(N-1)]

E=[[] for i in range(N+1)]

for x,y,w in EDGE:
    E[x].append([y,w])
    E[y].append([x,w])

from collections import deque
QUE = deque([1])

check=[-1]*(N+1)
check[1]=0

while QUE:
    now=QUE.pop()

    for to,w in E[now]:
        if check[to]!=-1:
            continue
        check[to]=(check[now]+w)%2
        QUE.append(to)

for c in check[1:]:
    print(c)

Measured memory_bytes: 94172
import numpy as np

def acinput():
    return list(map(int,input().split(" ")))


N=int(input())

a=[]
for i in range(N):
    a.append(int(input()))

idx=np.argsort(a)

for i in range(N):
    if i==idx[-1]:
        print(a[idx[-2]])
    else:
        print(a[idx[-1]])



Measured memory_bytes: 24868
input()=chomp(readline())
n,m=parse.(split(input()))
a=fill('0',n,n)
for i=1:n,(j,c)=enumerate(input())
    a[i,j]=c
end
b=fill('0',m,m)
for i=1:m,(j,c)=enumerate(input())
    b[i,j]=c
end
println(any(b==a[i+1:i+m,j+1:j+m]for i=0:n-m,j=0:n-m)?"Yes":"No")

Measured memory_bytes: 130764
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int price = scan.nextInt();
		
		int count = 0;
		for(int x = 0; x <= a; x++){
			for(int y = 0; y <= b; y++){
				for(int z = 0; z <= c; z++){
					if(500 * x + 100 * y + 50 * z == price)count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, x;
  cin >> N;
  x = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r, d;
  cin >> l >> r;
    d = r + 1 - l;
    x += d;
  }
  cout << x << endl;
}

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

int main() {
	long long		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	str;
	
	cin >> n >> k;
	
	vector<int> h(n);
	
	for(i=0;i<n;i++) {
		cin >> h[i];
	}
	
	sort(h.begin(), h.end());
	reverse(h.begin(), h.end());
	
	for(i=k;i<n;i++) {
		ans += h[i];
	}
	cout << ans << endl;


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    cout << N/3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int ring[3]; rep(i, 3) cin >> ring[i];
  sort(ring, ring+3);
  int result = ring[0] + ring[1];
  cout << result << endl;
  return 0;
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int N, M;
	cin >> N >> M;

	if(N % 2 == 1){
		int left = N / 2;
		int right = (N + 1) / 2;
		rep(i, M){
			cout << left << " " << right << endl;
			left--;
			right++;
		}
	}
	else{
		vector<bool> match(N+1, false);
		int left = 1;
		int right = N - 1;
		bool flg = false;
		rep(i,M){
			/*
			if(!flg && right - left <= N/2){
				right--;
				flg = true;
			}
			cout << left << " " << right << endl;
			*/
			
			int ci = right - left;
			if(!match[ci] && !match[N - ci] && ci != N - ci){
				match[ci] = true;
				match[N - ci] = true;
				cout << left << " " << right << endl;
			}
			else{
				right--;
				ci = right - left;
				match[ci] = true;
				match[N - ci] = true;
				cout << left << " " << right << endl;
			}
			
			left++;
			right--;
		}
	}

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3656
a = gets.chomp.to_i
b = []
b = gets.chomp.split("")
#puts a
#puts b.join("")
s = 0
t = 0
cnt = 3 * 10**5
for i in 1..a-1 #1文字目
    if b[i] != "W"
          t = t+1
    end
end
if (s + t) <= cnt
    cnt = (s + t)
end
#puts t
for i in 1..a-1 #2文字目から
    if b[i] != "W"
    t = t -1
    end
    if b[i-1] != "E"
        s = s + 1
    end
    #puts s + t
    if (s + t) <= cnt
        cnt = (s + t)
    end
end
puts cnt

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

using namespace std;

int main() {
    int n, m;
    int road[50][50] ={};

    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        road[a-1][b-1]++;
        road[b-1][a-1]++;
    }

    for (int i = 0; i < n; i++) {
        int num_road = 0;
        for (int j = 0; j < n; j++) {
            num_road += road[i][j];
        }
        cout << num_road << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

const int hw_max = 1000 + 5;
char graph[hw_max][hw_max];
int sign[hw_max][hw_max];
int h, w, n, ans;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
struct node
{
    int x;
    int y;
    int time;
} start;

void BFS(node op, char ed)
{
    queue <node> process;
    process.push(op);
    sign[op.x][op.y] = 1;
    while(!process.empty())
    {
        node now = process.front();
        process.pop();
        for(int i = 0; i < 4; i ++)
        {
            node next = now;
            next.x += dx[i];
            next.y += dy[i];
            next.time ++;
            if(next.x >= 0 && next.x < h && next.y >= 0 && next.y < w && graph[next.x][next.y] != 'X' && !sign[next.x][next.y])
            {
                if(graph[next.x][next.y] == ed)
                {
                    ans += next.time;
                    next.time = 0;
                    start = next;
                        return;
                }
                else
                {
                    process.push(next);
                    sign[next.x][next.y] = 1;
                }
            }
        }
    }
}

int main()
{
    while(~scanf("%d %d %d", & h, & w, & n))
    {
        getchar();
        for(int i = 0; i < h; i ++)
        {
            for(int j = 0; j < w; j ++)
            {
                   scanf("%c", & graph[i][j]);
                   if(graph[i][j] == 'S')
                   {
                    start.x = i;
                    start.y = j;
                    start.time = 0;
                   }
            }
            getchar();
        }
        ans = 0;
        for(int i = 1; i <= n; i ++)
        {
            memset(sign, 0, sizeof(sign));
            BFS(start, '0' + i);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

int main(){
    int N, M; cin >> N >> M;
    ll X; cin >> X;
    vector<vector<ll>> a(N, vector<ll>());
    vector<ll> c;
    rep(i,N){
        ll C; cin >> C;
        c.push_back(C);
        rep(j,M){
            ll A; cin >> A;
            a[i].push_back(A);
        }
    }

    ll ans = INF;
    rep(i,pow(2,N)){
        ll total = 0;
        vector<ll> tmp(M, 0);
        rep(j,N){
            int bit = (i >> j);
            if ((bit & 1) == 1){
                total += c[j];
                rep(k,M){
                    tmp[k] += a[j][k];
                }
            }
        }
        bool isOK = true;
        rep(j,M){
            if (tmp[j] < X) isOK = false;
        }
        if (isOK){
            ans = min(ans, total);
        }
    }

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;



}

Measured memory_bytes: 4112
n = int(input())
lst = [input() for _ in range(n)]

dic = dict()
res = 0
for i in range(n):
    sorted_string = "".join(sorted(lst[i]))
    if sorted_string in dic:
        dic[sorted_string] += 1
        res += dic[sorted_string]
    else:
        dic[sorted_string] = 0
    
print(res)

Measured memory_bytes: 24980
//ITP1_4_A
#include<iostream>
using namespace std;

int main()
{
	int a,b;
	
	cin>>a>>b;
	
	cout<<a/b<<" "<<a%b<<" ";
	cout.setf(ios::fixed,ios::floatfield);
	cout<<(double)a/b<<endl;
	
	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
const int maxn = 100010;
vector <int> vt[maxn];
vector <int> ans,tt;
int temp,lt;
bool nr[maxn],vis[maxn],vis2[maxn];
int dfs(int st){
    ans.push_back(st);
    vis2[st] = 1;
    if(st == temp)
        return 1;
    for(int i = 0;i < vt[st].size(); i++){
        if(vis2[vt[st][i]]){
            continue;
        }
        if(dfs(vt[st][i])){
            return 1;
        }
    }
    ans.pop_back();
    return 0;
}
int  dfs2(int st){
    if(nr[st]){
        lt--;
    }
    int flag=1;
    vis[st] = 1;
    vis2[st] = 1;
    ans.push_back(st);
    for(int i = 0;i < vt[st].size();i++){
        if(vis[vt[st][i]] == 0){
            flag = 0;
            if(vis2[vt[st][i]] == 0 && dfs2(vt[st][i])){
                return 1;
            }
        }
    }
    if(flag == 1 && lt == 0){
        return 1;
    }
    if (nr[st])
        lt ++;
    vis[st] = 0;
    ans.pop_back();
    return 0;
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,x,y;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        vt[x].push_back(y);
        vt[y].push_back(x);
    }
    for(int i = 0;i <= n; i++)
        if (vt[i].size() == 1){
            tt.push_back(i);
        }
    if(tt.size() >= 2){
        temp = tt[1];
        dfs(tt[0]);
    }else{
        for(int i = 1; i <= n; i++){
            memset(nr,0,sizeof(nr));
            memset(vis2,0,sizeof (vis2));
            for(int j = 0; j < vt[i].size(); j++)
                nr[vt[i][j]] = 1;
            lt = vt[i].size();
            if(dfs2(i)){
                break;
            }
        }
    }
    cout << ans.size() << endl;
    for(int i = 0;i < ans.size();i++)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 10104
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	VI a(5);
	rep(i, 5)cin >> a[i];
	SORT(a); REVE(a);
	rep(i, 5) {
		cout << a[i];
		printf(i == 4 ? "\n" : " ");
	}
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 素因数分解：nの素因数分解を{素数, 指数}の形で昇順に返す
vector<pair<long long int, long long int>> primeFactorize(long long int n){
    vector<pair<long long int, long long int>> ret;
    for(long long int i=2; i*i<=n; i++){
        if(n%i != 0) continue;
        long long int ex = 0;
        while(n%i == 0){ ex++; n /= i; }
        ret.push_back({i, ex});
    }
    if(n != 1) ret.push_back({n, 1});
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli a, b; cin >> a >> b;

    // aとbの公約数は、gcd(a, b)の約数に等しい
    lli div = __gcd(a, b);

    // 互いに素である必要があるため、素因数分解する
    auto pFac = primeFactorize(div);

    // 素因数の個数と"1"を含めた総数を出力
    cout << pFac.size()+1ll << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll MOD=1000000007;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> scores(N);
    for ( ll i = 0; i < N; ++ i ){
        cin >> scores[i];
    }

    // ll ans = scores[0] % MOD;

    // {
    //     ll a = scores[0] % MOD;
    //     ll b = scores[1] % MOD;
    //     for ( ll i = 0; i < 4; ++ i ){
    //         a *= scores[i];
    //         a %= MOD;
    //         b *= scores[i+1];
    //         b%=MOD;
    //         cout << "a=" << a << ",b=" << b << endl;
    //     }
    //     cout << a << endl;
    // }
    // for ( ll i = 1; i < K; ++ i ){
    //     ans *= scores[i];
    //     ans %= MOD;
    // }
    // for (ll i = K; i < N; ++ i ){
    //     auto before = ans;
    //     ans *= modinv(scores[i-K], MOD);
    //     ans %= MOD;
    //     ans *= scores[i];
    //     ans %= MOD;
    //     cout << before << ":" << ans;
    //     cout << ((before<ans)?"Yes":"No") << endl;

    // }

    for ( ll i = K; i < N; ++ i){
        bool isT = scores[i-K] < scores[i];
        cout << (isT?"Yes":"No") << endl;
    }


    return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
int main() {
  int N,K,count=0;
  cin >> N >> K;
  for(int i=1; i<=N; i+=2){
    count+=1;
  }
  if(count>=K){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  vector<vector<char>> S(N, vector<char>(N, '0'));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) { cin >> S[i][j]; }
  }
  uint32_t ans = 0;
  for (int x = 0; x < N; x++) {
    //「右にxずらし」で盤面が対称になるかどうかチェック
    bool flag = true;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        int a = (i + x) % N;
        int b = (j - x + N) % N;
        if (S[i][j] != S[b][a]) {
          flag = false;
          break;
        }
      }
      if (!flag) break;
    }
    if (flag) ans += N;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if(Math.abs(n - m) >= 2) {
			System.out.println(0);
		} else if(Math.abs(n - m) >= 1) {
			int max = Math.max(n, m);
			int min = Math.min(n, m);
			long sum = 1;
			for(long i = 1 ; i <= max ; i++) {
				sum = sum * i % 1000000007;
			}
			for(long i = 1 ; i <= min ; i++) {
				sum = sum * i % 1000000007;
			}
			System.out.println(sum);
		} else {
			long sum = 1;
			for(long i = 1 ; i <= n ; i++) {
				sum = sum * i % 1000000007;
			}
			for(long i = 1 ; i <= n ; i++) {
				sum = sum * i % 1000000007;
			}
			sum = sum * 2 % 1000000007;;
			System.out.println(sum);
		}
	}
}


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

int main(void){
  int n, sz, cnt;
  int a, b, c;
  string s;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s;
    sz = s.size();
    cnt = 0;
    stack<int> st;
    for(int j = sz - 1; j >= 0; j--) st.push(s[j] - '0');
    while(true){
      a = st.top();st.pop();
      if(st.empty()) break;
      b = st.top();st.pop();
      c = a + b;
      while(c){
	st.push(c % 10);
	c /= 10;
      }
      cnt++;
    }
    if(cnt % 2) cout << "Fabre wins." << endl;
    else cout << "Audrey wins." << endl;
  }
  return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int q;
  cin >> q;
  
  multiset<ll> left, right;
  ll nowmin = 0, sumb = 0;
  
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      ll a, b;
      cin >> a >> b;
      sumb += b;
      if (i == 0) {
        left.insert(a);
        right.insert(a);
      }
      else {
        auto it1 = left.end(), it2 = right.begin();
        it1--;
        if (*it1 <= a && a <= *it2) {
          left.insert(a);
          right.insert(a);
        }
        else if (a < *it1) {
          nowmin += *it1 - a;
          left.insert(a);
          left.insert(a);
          right.insert(*it1);
          left.erase(it1);
        }
        else {
          nowmin += a - *it2;
          right.insert(a);
          right.insert(a);
          left.insert(*it2);
          right.erase(it2);
        }
      }
    }
    else {
      auto it1 = left.end();
      it1--;
      cout << *it1 << " " << nowmin + sumb << '\n';
    }
  }
}

Measured memory_bytes: 22296
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	int X,A,B;
	scanf("%d%d%d", &X , &A, &B);


	if ((X * 100 + A * 10 + B) % 4 == 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}

}

Measured memory_bytes: 128
# ABC104C - All Green
def ans(g, i, L):
    # Assume the case using question no.i
    if i == 0:  # base case
        return float("inf")

    n = min(g // (i * 100), L[i][0])  # n:count
    s = n * i * 100  # s:score

    # add bonus if available
    if n == L[i][0]:
        s += L[i][1]

    # make up for the shortage
    if s < g:
        n += ans(g - s, i - 1, L)

    # compare to other cases without question no.i recursively
    return min(n, ans(g, i - 1, L))


def main():
    d, g = list(map(int, input().rstrip().split()))
    arr = [0] + [list(map(int, input().rstrip().split())) for _ in range(d)]
    print(ans(g, d, arr))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int len;
    cin>>s;
    len=s.size();
    for(int i=0;i<len;i++)
        if(s[i]=='C')
            for(int j=i+1;j<len;j++)
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
from math import factorial


def combinations_count(n):
    if n < 2:
        return 0
    return factorial(n) // (factorial(n - 2) * factorial(2))


if __name__ == "__main__":
    n, m = map(int, input().split())
    print(combinations_count(n) + combinations_count(m))


Measured memory_bytes: 3060
using System;

namespace abc131_d
{
    class Program
    {
        static void Main(string[] args)
        {
            // 仕事の個数
            var n = int.Parse(Console.ReadLine());
            // それぞれにかかる時間と締め切り
            var t = new t[n];
            for (var i = 0; i < n; i++)
            {
                var items = Console.ReadLine().Split(' ');
                t[i] = new t
                {
                    a = int.Parse(items[0]),
                    b = int.Parse(items[1])
                };
            }

            // 締め切りが同じ仕事が複数ある場合、どの仕事を優先しても結果は変わらない(結局やらなくてはならないので)
            // 締め切り：1 56 57 57 100
            // →どちらの57を先にやっても構わない。
            //  逆に、57を始める前に、それよりも締め切りが早いやつを全部片づけておかないとやばい
            // →1が間に合う→56も間に合う→57も間に合う→100も間に合う
            //  逆に、1と56だけで考えて間に合わなかったら、どうあがいても間に合わない
            Array.Sort(t);
            var time = 0;
            for (int i = 0; i < t.Length; i++)
            {
                var limit = t[i].b;
                time += t[i].a;
                if (limit < time)
                {
                    time = 0;
                    break;
                }
            }

            var answer = time > 0 ? "Yes" : "No";
            Console.WriteLine($"{answer}");
        }
    }

    struct t : IComparable<t>
    {
        public int a;
        public int b;

        public int CompareTo(t other)
        {
            return b.CompareTo(other.b);
        }
    }
}


Measured memory_bytes: 19116
S = input()
S0 ="01"
S1 ="10"
n0 = 0
n1 = 0
for i in range(len(S)):
    if(S[i]!=S0[i%2]):
        n0+=1
    if(S[i]!=S1[i%2]):
        n1+=1
print(min(n0,n1))


Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
    int N, A, B;
    int i, tmp, digitSum, total;
    scanf("%d %d %d", &N, &A, &B);
    total = 0;
    for (i=0; i<=N; i++)
    {
        tmp = i;
        digitSum = 0;
        while (tmp>0) {
            digitSum += tmp%10;
            tmp /= 10;
        }
        if (digitSum >= A && digitSum <= B) {
            total += i;
        }
    }
    printf("%d\n", total);
    return 0;
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

//S[0]から始まる文字列の長さを求める関数
int string_len(char* str){
    int len=0;
    while(str[len]!=0){
        len++;
    }
    return len;
}

int main(void){
    char S[100001];
    scanf("%s",S);

    //文字列の長さ
    int N=string_len(S);

    //0101...にマッチしている数
    int b=0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            if(S[i]=='0') b++;
        }
        else{
            if(S[i]=='1') b++;
        }
    }

    //1010...にマッチしている数
    int w=0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            if(S[i]=='1') w++;
        }
        else{
            if(S[i]=='0') w++;
        }
    }

    int ans;
    if(b>=w) ans=N-b;
    else ans=N-w;
    
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


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

  size_t n;
  int64_t t;
  cin >> n >> t;
  vector<int64_t> xs(n);
  cin >> xs;

  int64_t acc = t;
  int64_t lst = 0;

  for(const auto x: xs)
  {
    if(lst + t < x)
      acc += t;
    else
      acc += x - lst;

    lst = x;
  }

  cout << acc;
  return EXIT_SUCCESS;
}



Measured memory_bytes: 1792
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    foreach (i; 1 .. 10) {
        foreach (j; 1 .. 10) {
            writefln("%dx%d=%d", i, j, i * j);
        }
    }
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}

vector<vi> adj;

void dfs(int v, int par, vi & d) {
  if(par != -1) {
    d[v] = d[par] + 1;
  }
  for(auto x: adj[v]) {
    if(x == par) continue;
    dfs(x, v, d);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n, u, v; cin>>n>>u>>v;
  adj.resize(n+1, vi(0));
  rep(i,0,n-1) {
    int x, y; cin>>x>>y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  vi d1(n+1), d2(n+1);
  dfs(u, -1, d1);
  dfs(v, -1, d2);
  int ans = 0;
  int m = -1;
  debug(d1, d2);
  rep(i,1,n+1) {
    if(d1[i] < d2[i]) {
      int s = 0;
      if(d1[i] % 2 != d2[i]%2) {
        s = 2*(d2[i]-1);
      }
      else {
        s = d2[i] - 1 + d2[i];
      }
      if(s>m) {
        m = s;
        ans = d2[i] - 1;
      }
    }
    /*
    else if(d1[i] == d2[i]) {
      if(2*d1[i] > m) {
        m = 2*d1[i];
        ans = d1[i];
      }
    }*/
    /*
    else {
      int s = 0;
      if(d1[i] % 2 != d2[i] % 2) {
        s = 2*d1[i];
        if(s > m) {
          m = d1[i];
          ans = d1[i];
        }
      }
      else {
        s = d1[i] + d1[i] - 1;
        if(s>m) {
          m = d1[i];
          ans = d1[i];
        }
      }
    }*/
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 10368
s = input()
t = input()
ans = ""
po = False

for i in range(len(s)-len(t)+1):
    if s[i] in [t[0],"?"]:
        if all([s[i + j] in [t[j], "?"]for j in range(len(t))]):
            if not po:
                ans = (s[:i] + t + s[i + len(t):]).replace("?","a")
                po = True
            temp = (s[:i] + t + s[i + len(t):]).replace("?","a")
            if temp < ans:
                ans = temp
            


if ans:
    print(ans.replace("?", "a"))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
L,R=map(int,input().split())
if L//2019<R//2019 or L%2019==0 or R%2019==0:
    print(0)
#     print("s1")
elif (L//673<R//673 and L//3<R//3) or (L%3==0 and R%673==0) or (L%673==0 and R%3==0):
    print(0)
#     print("s2")
else:
    l=list(range(L,R+1))
    arr=[]
    for i in range(len(l)):
        for j in range(len(l)):
            if i < j:
                arr.append(l[i]*l[j]%2019)
    print(min(arr))

Measured memory_bytes: 6800
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define MAXN 201
#define MAXM 100010



ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



mod dp[MAXN][MAXM];
int n, x;
int s[MAXN];

int main() {
	cout << fixed << setprecision(12);	
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s, s + n);
	dp[n][x] = 1;
	for (int i = n - 1; i >= 0; i--) {
		memcpy(dp[i], dp[i + 1], sizeof(dp[i]));
		for (int j = 0; j < MAXM; j++) {
			dp[i][j] *= i;
		}
		for (int j = 0; j < s[i]; j++) {
			for (int l = j; l < MAXM; l += s[i]) {
				dp[i][j] += dp[i + 1][l];
			}
		}
	}
	mod ret(0);
	for (int i = 0; i < MAXM; i++) {
		ret += dp[0][i] * i;
	}
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 160680
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			int n = in.nextInt();
			if(n==0) break;
			int a[] = new int[n];
			for(int i=0; i<n; i++) a[i] = in.nextInt();
			System.out.println(solve(a));
		}
	}
	
	static int solve(int[] a){
		int n = a.length;
		int total = 0;
		int ret = 1<<29;
		for(int i=0; i<n; i++) total += a[i];
		for(int mask=0; mask<(1<<n); mask++){
			int sum = 0;
			for(int i=0; i<n; i++)if((mask & (1<<i)) > 0) sum += a[i];
			if(Math.abs(total - 2*sum) < ret)
				ret = Math.abs(total - 2*sum);
		}
		
		return ret;
	}
}

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

int main(void) {
	const char *SEP = " ";
	int n, d1, d2, cnt, result;
	char input_str[12 * 200000];
	char *num_str;
	int i;

	fgets(input_str, sizeof(input_str), stdin);
	num_str = strtok(input_str, SEP);
	n = atoi(num_str);

	result = 0;
	cnt = 0;
	for ( i = 0; i < n; i++ ) {
		fgets(input_str, sizeof(input_str), stdin);
		num_str = strtok(input_str, SEP);
		d1 = atoi(num_str);
		
		num_str = strtok(NULL, SEP);
		d2 = atoi(num_str);

		if ( d1 == d2 ) {
			cnt++;
			if ( 3 <= cnt ) {
				result = 1;
			}
		}
		else {
			cnt = 0;
		}
	}

	if ( result ) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 1600
#include<bits/stdc++.h>
using namespace std;
int main() {
  struct Town {int I, P, Y; string ID;};
  int N, M;
  cin >> N >> M;
  vector<Town> T(M);
  for(auto i=0; i<M; ++i) {
    T[i].I = i+1;
    cin >> T[i].P >> T[i].Y;
    T[i].ID = "000000000000";
  }
  sort(begin(T), end(T), [](auto l, auto r) {return l.Y<r.Y;});
  map<int, int> cnt;
  for(auto& i: T) {
    auto x = ++cnt[i.P];
    for(auto j=0; j<6; ++j) {
      i.ID[j] = '0'+(x%10);
      x /= 10;
      i.ID[6+j] = '0'+(i.P%10);
      i.P /= 10;
    }
    reverse(begin(i.ID), end(i.ID));
  }
  sort(begin(T), end(T), [](auto l, auto r) {return l.I<r.I;});
  for(auto& i: T) cout << i.ID << endl;
}


Measured memory_bytes: 13184