akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    n, m = map(int, input().split())
    edges = list(readlines(m))

    graph = [set() for _ in range(n+1)]
    for a, b in edges:
        graph[a].add(b)
        graph[b].add(a)

    ans = 0
    for a, b in edges:
        queue = deque()
        queue.append(a)
        explored = set()
        explored.add(a)
        while queue:
            u = queue.popleft()
            for v in graph[u]:
                if (u, v) == (a, b) or v in explored:
                    continue
                explored.add(v)
                queue.append(v)

        ans += 0 if len(explored) == n else 1

    print(ans)
            

main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  
  int sum=0;
  for(int i=0;i<N-1;i++){
    sum+=vec[i];
  }
  
  bool res=false;
  
  
  if(sum>vec[N-1]){
    res=true;
  }
  
  if(res){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 200000;

int n;
int a[N + 5], b[N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i <= n; ++i) read(a[i]), b[i] = a[i] - i;
    std::sort(b + 1, b + n + 1);

    ll ans = 0;
    int x = b[(n + 1) / 2];
    for(int i = 1; i <= n; ++i) ans += abs(a[i] - (x + i));
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1792
N, W = map(int, input().split())
w, v = [None] * N, [None] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
wmin = w[0]
_w = [[], [], [], []]
for i in range(N):
    _w[w[i] - wmin].append(v[i])
for i in range(4):
    _w[i].sort(reverse = 1)
    for j in range(1, len(_w[i])):
        _w[i][j] += _w[i][j-1]
    _w[i].insert(0, 0)
ans = 0
for c0 in range(len(_w[0])):
    for c1 in range(len(_w[1])):
        for c2 in range(len(_w[2])):
            for c3 in range(len(_w[3])):
                if wmin * (c0 + c1 + c2 + c3) + c1 + 2 * c2 + 3 * c3 <= W:
                    ans = max(ans, _w[0][c0] + _w[1][c1] + _w[2][c2] + _w[3][c3])
print(ans)


Measured memory_bytes: 3064
import math

A,B,H,M=map(int,input().split(" "))
time_in_mins=H*60+M
time_in_hours=H+M/60
angle=0
angle_of_hour=time_in_hours*30
angle_of_min=time_in_mins*6
while angle_of_hour>360:
    angle_of_hour=angle_of_hour-360
while angle_of_min>360:
    angle_of_min=angle_of_min-360
if abs(angle_of_min-angle_of_hour)>=180:
    angle=360-abs(angle_of_min-angle_of_hour)
else:
    angle=abs(angle_of_min-angle_of_hour)
a_2=A*A
b_2=B*B
a_b=A*B
angle_revised=angle*(math.pi)/180
C=math.sqrt(a_2+b_2-2*a_b*(math.cos(angle_revised)))
print(C)





Measured memory_bytes: 9496
using System;
using System.Linq;
class GFG
{
    public static void Main()
    {
        //var input = Console.ReadLine().Split(' ');

        //var x = int.Parse(input[0]);
        //var a = int.Parse(input[1]);
        //var b = int.Parse(input[2]);

        //var n = int.Parse(Console.ReadLine());
        // var ss = str.ToCharArray().OrderBy(x => x).ToArray();
        var s1 = Console.ReadLine();
        // var s2 = Console.ReadLine();

        Pallindrom(s1);
    }

    static void Pallindrom(string n)
    {

        int l = 0;
        int r = n.Length - 1;

        while (l <= r)
        {
            if (n[l] != n[r])
            {
                Console.Write("No");
                return;
            }
            l++;
            r--;
        }
        Console.Write("Yes");
    }



}




Measured memory_bytes: 13140
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  vector<int> arr(N),Csum(N+1,0);
  REP(i,0,N)cin>>arr[i];
  REP(i,0,N)Csum[i+1]=Csum[i]+arr[i];
  sort(ALL(Csum));
  int prev=-INF,ans=0,cum=0;
  REP(i,0,N+1){
    if(prev==Csum[i]){
      cum++;
      ans+=cum;
    }
    else {
      cum=0;
      prev=Csum[i];
    }
  }
  print(ans);

}


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

ll N, M;
vector<vector<ll>> G;
vector<ll> colors;
//頂点vから辺をちょうど3本たどる
bool is_bipartite(ll v, ll color = 0) {
    colors[v] = color;
    for (auto nv : G[v]) {
        if (colors[nv] == color) return false;
        else if (colors[nv] == -1 && !(is_bipartite(nv, 1-color))) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> N >> M;
    G.resize(N);
    colors.assign(N, -1);
    for (int i = 0; i < M; i++) {
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if (is_bipartite(0)) {
        ll B, W = 0;
        for (int i = 0; i < N; i++) {
            W += colors[i];
        }
        B = N-W;
        cout << B*W-M << endl;
    }
    else cout << N*(N-1)/2-M << endl;
}


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

//const int INF = 1000000;

int main() {
  
  string S;
  int a;
  
  cin >> S;
  
  a = S.size();
  
  cout << S.at(0) << a - 2 << S.at(a - 1) << endl;
  
}

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

int main(){
  int N;
  cin >> N;
  int W[100],d;
  int sum=0,sum2=0;
  
  for(int i=0;i<N;i++){
    cin >> W[i];
    sum+=W[i];
  }
  d = sum;
  
  for(int i=0;i<N;i++){
    sum2+=W[i];
    
    d = min(d, abs(sum-sum2*2));
  }
  
  cout<<d<<endl;

}

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

int main() {
    string S;
    cin >> S;
    set<char> t;

    rep(i,S.size()) {
        if(t.count(S.at(i))) {
            cout << "no" << endl;
            return 0;
        }
        t.insert(S.at(i));
    }

    cout << "yes" << endl;
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun a b -> a = b in
  let (ans,_) = Array.fold_left 
  	(fun (ans, now) b -> 
    	if b && (now = 2) then (ans+1,0) 
        else if b then (ans, now+1) 
        else (ans, 0)) (0,0) arr in
  Printf.printf "%s\n" (if ans > 0 then "Yes" else "No")

Measured memory_bytes: 3764
#include <stdio.h>

int main(void)
{
	int w, n, a, b, t, i;
	int length[30], width[30];
	
	scanf("%d %d", &w, &n);
	
	for (i = 0; i < 30; i++){
		length[i] = i + 1;
	}
	
	for (i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		t = length[a - 1];
		length[a - 1] = length[b - 1];
		length[b - 1] = t;
	}
	
	for (i = 0; i < w; i++){
		printf("%d\n", length[i]);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

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); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=998244353;

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

signed main(){
	int n,k;
	vector<tuple<int,int,int>> ans;
	cin >> n >> k;
	if(k * 2 > n + 1){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0;i < n;i += 2){
		ans.emplace_back(k + i,k + 2 * n - 1 - i / 2,k + 3 * n - 1 - (n - 1) / 2 + i / 2);
	}
	for(int i = 1;i < n;i += 2){
		ans.emplace_back(k + i,k + n + n / 2 - 1 - i / 2,k + 2 * n + i / 2);
	}
	for(int i = 0;i < n;i++){
		cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << endl;
	}
}

Measured memory_bytes: 4976
import math
N, K = map(int,input().split())
MOD = 10**9 + 7

def nCr(n,r):
    if n <= 0 or r <= 0:
        return 1
    elif n-r < 0:
        return 0
    else:
        return (math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))%MOD

for i in range(1,K+1):
    ans = 1
    b = K-i
    ans *= nCr(K-1,i-1)
    ans *= nCr(N-K+1,i)
    print(ans%MOD)


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

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

    int Y;
    cin >> Y;

    // s.f. 10000, 5000, 1000
    for(int i = 0; i < N+1; i++) {
        for(int j = 0; j < N+1-i; j++) {
            int k = N - i - j;
            int sum = k * 1000 + j * 5000 + i * 10000;
            if(sum == Y){
                cout << i << " " << j << " " << k;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Text.RegularExpressions;
using static System.Console;

namespace CsTest
{
    class Program
    {
        static void Main()
        {
            var input1 = ReadLine();
            var input2 = ReadLine();

            for (int i = 0; i < input2.Length; i++)
            {
                Write(input1[i]);
                Write(input2[i]);
            }
            if (input1.Length == input2.Length) WriteLine();
            else WriteLine(input1[input1.Length - 1]);
        }
    }

    public class AtCoder
    {
        public static string[] ReadStringArray() => ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        public static int[] ReadInt32Array() => ReadStringArray().Select(s => int.Parse(s)).ToArray();
        public static long[] ReadInt64Array() => ReadStringArray().Select(s => long.Parse(s)).ToArray();
    }
}

Measured memory_bytes: 11092
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e5 + 20 , inf = 1e9 + 20 ;
int n , x[N] , y[N] ;
char d[N] ;

inline ld get (ld k) {
	ld xmn = inf , xmx = -inf , ymn = inf , ymx = -inf ;

	for (int i = 0 ; i < n ; i ++) {
		ld nx = x[i] + ((d[i] == 'R') - (d[i] == 'L')) * k ;
		ld ny = y[i] + ((d[i] == 'U') - (d[i] == 'D')) * k ;

		xmn = min(xmn , nx) , xmx = max(xmx , nx) ;
		ymn = min(ymn , ny) , ymx = max(ymx , ny) ;
	}

	return (xmx - xmn) * (ymx - ymn) ;
}

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

	cin >> n ;
	
	for (int i = 0 ; i < n ; i ++) cin >> x[i] >> y[i] >> d[i] ;

	ld low = 0 , high = 2e8 + 20 ;

	for (int _ = 0 ; _ < 200 ; _ ++) {
		ld f1 = (2 * low + high) / 3 , f2 = (low + 2 * high) / 3 ;

		if (get(f1) < get(f2)) high = f2 ;
		else low = f1 ;
	}

	cout << fixed << setprecision(10) << get(low) << '\n' ;
}


Measured memory_bytes: 1152
#include<iostream>

using namespace std;


int main(void) {
    int N;
    int x[100010], y[100010], t[100010];

    cin >> N;
    t[0] = x[0] = y[0] = 0;
    for (int i=1; i < N+1; i++) cin >> t[i] >> x[i] >> y[i];

    bool can = true;
    for (int i = 0; i < N; i++) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);

        if (dt < dist) {
            can = false;
        }
        if (dist % 2 != dt % 2) {
            can = false;
        }
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 1408
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

k = ni()
que = deque()
for i in range(1, 10):
    que.append(i)
ct = 0
for i in range(k):
    x = que.popleft()
    if x % 10 != 0:
        que.append(10*x+x%10-1)
    que.append(10*x+x%10)
    if x % 10 != 9:
        que.append(10*x+x%10+1)
print(x)

Measured memory_bytes: 13972
//次のアルファベット

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;int k;cin>>s>>k;
    int n = s.size();
    rep(i,0,n){
        int a=26-(s[i]-'a');
        if(a<=k&&s[i]!='a'){
            k-=a;
            s[i]='a';
        }
    }
    s[s.size()-1]=((s[s.size()-1]-'a')+k)%26+'a';
    cout<<s<<nnn;
    return 0;
}

Measured memory_bytes: 3756
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	int n,m,dis;
	cin >> n >> m;
	vector< pair<int,int> > a(m);
	for(int i=0; i<m; i++){
		cin >> a[i].first >> a[i].second;
	}
	/*int key,temp;
	for(int i=0; i<m; i++){
		key=i;
		for(int j=i+1; j<m; j++){
			if(a[key]>a[j])key=j;
			else if(a[key]==a[j]&&b[key]>b[j])key=j;
		}
		temp=a[i];a[i]=a[key];a[key]=temp;
		temp=b[i];b[i]=b[key];b[key]=temp;
	}*/
	sort(a.begin(),a.end());
	int ans=0;dis=n+1;
	for(int i=m-1; i>=0; i--){
		if(dis<=a[i].second)continue;
		ans++;dis=a[i].first+1;
	}
	cout << ans << endl;
	return 0;
}

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

signed main() {
    int sum = 0, ma = 0;
    for (int i = 0; i < 5; i++) {
        int a;
        cin >> a;
        if (a % 10) ma = max(ma, 10 - a % 10);
        sum += (a + 9) / 10 * 10;
    }
    cout << sum - ma << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
 int a, b, c, d;
  cin >> a;
  
  if(a<1000) co("ABC");
  else co("ABD");
  
  return 0;
}


Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<limits>
#include<iomanip>
#include<set>
#include<tuple>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1000000000 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int n,cnt=0;
	cin >> n;
	VI a(n);
	rep(i, n) cin >> a[i];

	for (int i = 1; i < n - 1; i++) {
		if (a[i - 1] == a[i] && a[i] == a[i + 1]) {
			a[i] = -1;
			cnt++;
		}
	}

	for (int i = 1; i < n; i++) {
		if (a[i - 1] == a[i] || a[i] == a[i + 1]) {
			a[i] = -1;
			cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

h,w=LI()

h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0})
dp=[10**6]*(h*w)
dp[1]=0
g[1]=0

for j in range(h*w-h):
    r,c=j//w,j%w
    if j==1 or (1<=r<=h-2 and 1<=c<=w-2):
        pass
    else:
        continue

    dp[j+1]=min(dp[j]+1 if (g[j],g[j+1])==(0,1) else dp[j],dp[j+1])
    dp[j+w]=min(dp[j]+1 if (g[j],g[j+w])==(0,1) else dp[j],dp[j+w])


print(dp[(h-2)*w+w-2])


Measured memory_bytes: 43244
def read(): return list(map(int, input().split()))


def calc(h, w):
    S = h * w

    ret = 1145141919
    for x in range(1, w + 1):
        s1 = h * x
        if h % 2 == 0:
            s2 = (h // 2) * (w - x)
        elif (w - x) % 2 == 0:
            s2 = ((w - x) // 2) * h
        else:
            t2 = h * ((w - x) // 2)
            t3 = S - s1 - t2

            s2 = (w - x) * (h // 2)
            s3 = S - s1 - s2

            ret = min(ret, max(s1, t2, t3) - min(s1, t2, t3), max(s1, s2, s3) - min(s1, s2, s3))
            continue

        s3 = S - s1 - s2

        smax = max(s1, s2, s3)
        smin = min(s1, s2, s3)

        ret = min(ret, smax - smin)

    return ret


def main():
    h, w = read()
    if h % 3 == 0 or w % 3 == 0:
        print(0)
        return

    ans = calc(h, w)
    h, w = w, h
    ans = min(ans, calc(h, w))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n;
int w[200];
int sum[200],ans;
int cut (int x){
    int a,b;
    a = sum[x];
    b = sum[n]-sum[x];
    int res = abs(a-b);
    return res;
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>w[i];
    for(int i=1;i<=n;i++)sum[i]=sum[i-1]+w[i];

    ans = INT_MAX;
    for(int i=1;i<=n;i++){
        ans = min(ans,cut(i));
    }
    cout<<ans<<newl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S;
  cin >> S;
  S = "0"+S;
  int N = S.size();
  vector<vector<ll> > dp(N, vector<ll>(2));
  int t = int(S[N-1]-'0');
  dp[0][0] = t;
  dp[0][1] = (10-t);
  REP(i, 1, N) {
    int t = int(S[N-1-i]-'0');
    if(t == 9) {
      dp[i][0] = dp[i-1][0]+t;
      dp[i][1] = min(dp[i-1][0]+(10-t), dp[i-1][1]);
    } else if(t == 0) {
      dp[i][0] = min(dp[i-1][0], dp[i-1][1]+(t+1));
      dp[i][1] = dp[i-1][1]+(10-(t+1));
    } else {
      dp[i][0] = min(dp[i-1][0]+t, dp[i-1][1]+(t+1));
      dp[i][1] = min(dp[i-1][0]+(10-t), dp[i-1][1]+(10-(t+1)));
    }
  }
  cout << min(dp[N-1][0], dp[N-1][1]) << endl;
  return 0;
}


Measured memory_bytes: 55856
//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 200005

int par[maxn],size[maxn],col[maxn],wt[maxn],got[maxn],done[maxn];
vector<pair<int,int> >store1;
vector<int>v;
vector<pair<int,int> >store[maxn];
map<int,int>assign;
ll fact[maxn],ifact[maxn];
vector<int>component[maxn];

ll bpow(ll x,ll n)
{
	ll ans=1;
	while(n>0)
	{
	    if(n&1) ans*=x;
	    x*=x;
	    ans%=mod;
	    x%=mod;
	    n/=2;
	}
	return ans;
}
int find(int x)
{
	if(par[x]==x)
	return x;
	return par[x]=find(par[x]);
}
void merge(int x,int y)
{
	int xp=find(x);
	int yp=find(y);
	if(xp==yp)
	return;
	if(size[xp]<size[yp])
	{
		par[xp]=yp;
		size[yp]+=size[xp];
		for(auto it:component[xp])
		component[yp].pb(it);
	}
	else
	{
		par[yp]=xp;
		size[xp]+=size[yp];
		for(auto it:component[yp])
		component[xp].pb(it);
	}
}
int main()
{
	boost1;boost2;
	int i,j,n,m,x,y,X,Y,id1,id2,col1,col2,ctr=0,id,lightest_id,lightest_wt,weight;
	ll ans=1;
	cin>>n>>X>>Y;
	for(i=1;i<=n;i++)
	{
		par[i]=i;
		size[i]=1;
		component[i].pb(i);
	}
	for(i=1;i<=n;i++)
	{
		cin>>col[i]>>wt[i];
		store1.pb({wt[i],i});
		v.pb(col[i]);
	}
	ctr=0;
	sort(all(v));
	for(i=0;i<v.size();i++)
	{
		if(!assign[v[i]])
		{
			ctr++;
			assign[v[i]]=ctr;
		}
	}
	for(i=1;i<=n;i++)
	col[i]=assign[col[i]];
	for(i=1;i<=n;i++)
	store[col[i]].pb({wt[i],i});
	for(i=1;i<=ctr;i++)
	sort(all(store[i]));
	for(i=1;i<=ctr;i++)
	{
		if(store[i].size()<=1)
		continue;
		lightest_id=store[i][0].S;
		lightest_wt=store[i][0].F;
		for(j=1;j<store[i].size();j++)
		{
			id=store[i][j].S;
			weight=store[i][j].F;
			if(weight+lightest_wt<=X)
			merge(id,lightest_id);
		}
	}
	sort(all(store1));
	id1=store1[0].S;
	col1=col[id1];
	id2=-1;
	for(i=1;i<store1.size();i++)
	{
		if(col[store1[i].S]!=col1)
		{
			id2=store1[i].S;
			col2=col[id2];
			break;
		}
	}
	if(id2!=-1)
	{
		for(i=1;i<=n;i++)
		{
			if(col[id1]!=col[i] && wt[id1]+wt[i]<=Y)
			merge(id1,i);
			if(col[id2]!=col[i] && wt[id2]+wt[i]<=Y)
			merge(id2,i);
		}
	}
	fact[0]=1;
	ifact[0]=1;
	for(i=1;i<maxn;i++)
	{
		fact[i]=(i*fact[i-1])%mod;
		ifact[i]=bpow(fact[i],mod-2);
	}
	for(i=1;i<=n;i++)
	{
		if(find(i)!=i)
		continue;
		ans=(ans*fact[size[i]])%mod;
		for(auto it:component[i])
		got[col[it]]++;
		for(auto it:component[i])
		{
			if(done[col[it]])
			continue;
			done[col[it]]=1;
			ans=(ans*bpow(fact[got[col[it]]],mod-2))%mod;
		}
		for(auto it:component[i])
		{
			got[col[it]]=0;
			done[col[it]]=0;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 38772
import math


def main():
    N, D = map(int, input().split())
    X = []
    for i in range(N):
        X.append(list(map(int, input().split())))

    ans = 0
    for i in range(1, N):
        for j in range(i):
            d2 = 0
            for k in range(D):
                d2 += abs(X[i][k] - X[j][k]) ** 2
            d = math.sqrt(d2)
            if d.is_integer():
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
k = int(input())
a = [None]*1000001
a[1]=7%k
n=0

if a[1]==0:
    print("1")
    n=1

for i in range(2,k+1):
    a[i]=(a[i-1]*10+7)%k
    if a[i]==0 and n==0:
        print("{}".format(i))
        n=1
if n==0:
    print("-1")


Measured memory_bytes: 48536
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define mod 1000000007
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans=0,maxi=0;
	maxi=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<maxi)
		{
			ans+=(maxi-a[i]);
		}
		else
		{
			maxi=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i = 0 ; i < n ; i++)
int main()
{ 
	int n;
	cin >> n;
	int a[n+1][3];
	memset(a, 0 , sizeof(a));
	forn(i,n)cin >> a[i][0]>> a[i][1]>> a[i][2];
	for(int i = 1 ; i <= n ; i++)
	{
		a[i][0] += max(a[i-1][1], a[i-1][2]);
		a[i][1] += max(a[i-1][0], a[i-1][2]);
		a[i][2] += max(a[i-1][0], a[i-1][1]);
	}
	cout<<max(a[n][0], max(a[n][1], a[n][2]));
return 0;
}




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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const ll inf = 1e17;
const ll mod = 1e9 + 7;
const int N = 200005;

void solve(){
	int n;
	cin >> n;
	multiset<int> st;
	vi v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	sort(v.rbegin(), v.rend());
	st.insert(v[0]);
	ll ans = 0;
	for(int i = 1; i < n; i++){
		int el = *st.rbegin();
		ans += el;
		st.erase(std::prev(st.end()));
		int put = min(el, v[i]);
		st.insert(put);
		st.insert(put);
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 13516
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ansl = 0;
	int left = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') {
			left++;
		} else {
			if (left == 0) {
				ansl++;
			} else {
				left--;
			}
		}
	}
	int ansr = left;
	rep(i,ansl) cout << '(';
	cout << s;
	rep(i,ansr) cout << ')';
	cout << endl;
}

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

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;

int main()
{
	map<int, int > mp;
	int N;
	cin >> N;
	
	for (int i = 0; i<N; i++)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	
	for (std::map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
	{
		if (it->second > 1) 
		{
			cout << "NO" <<endl;
			return 0;
		}
	}
	cout <<"YES" <<endl;
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 9600
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <cassert>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<ll> l(k), r(k); rep(i, k)cin >> l[i] >> r[i];
	vector<ll> imos(500100);
	ll now = 1;
	ll MOD = 998244353;
	rep(pos, n - 1)
	{
		now += imos[pos];
		now %= MOD;
		rep(i, k)
		{
			imos[pos + l[i]] += now;
			imos[pos + l[i]] %= MOD;
			imos[pos + r[i] + 1] += MOD;
			imos[pos + r[i] + 1] -= now;
			imos[pos + r[i] + 1] %= MOD;
		}
	}
	/*rep(i, n)
	{
		imos[i + 1] += imos[i];
		imos[i + 1] %= MOD;
	}*/
	cout << imos[n - 1] << endl;
}

Measured memory_bytes: 7148
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[] darmas;
	static int[][] memo;
	static int max(int i, int j) {
		if(memo[i][j] == -1) {
			int n = j - i;
			if(n == 1) {
				memo[i][j] = 0;
			}
			else if(n == 2) {
				assert(j-1 == i+1);
				memo[i][j] = (Math.abs(darmas[i] - darmas[i+1]) <= 1) ? 2 : 0;
			}
			else {
				int lmax = 0;
				if(n >= 4) {
					lmax = max(i+1, j-1);
					lmax += (lmax == n-2) ? ( Math.abs(darmas[i] - darmas[j-1]) <= 1 ? 2 : 0) : 0;
				}
				for(int k = i + 1; k + 1 < j; k++) {
					int top = max(i,k);
					int bot = max(k, j);
					if(lmax < top + bot) {
						lmax = top + bot;
					}
				}
				memo[i][j] = lmax;
			}
		}
		return memo[i][j];
	}

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			for(int n = sc.nextInt(); n!= 0; n = sc.nextInt()) {
				darmas = new int[n];
				memo = new int[n][n+1];
				for(int i = 0; i < n; i++) {
					darmas[i] = sc.nextInt();
					Arrays.fill(memo[i], -1);
				}
				System.out.println(max(0, n));
			}
		}
	}
}



Measured memory_bytes: 59232
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"


#define MAX LLONG_MAX

#define MIN LLONG_MIN

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  stack<char> st;
  //p1(s.length());
  
  for01(0,s.length())
  {
    if(s[i] == 'B' && !st.empty())
      st.pop();
    else
    {
      if(s[i] != 'B')
      	st.push(s[i]);
    }
  }
  
  
  
  stack<char> s2;
  ll l = st.size();
  for01(0, l)
  {
    s2.push(st.top());
    st.pop();
  }
  
  //p1(st.size());
  
  l = s2.size();
  for01(0,l)
  { 
    cout << s2.top();
    s2.pop();
  }
  
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
int main(){
	int a;
	cin>>a;
	if(a<1200){
		cout<<"ABC"<<endl;
	}
	else if(1200<=a&&a<2800){
		cout<<"ARC"<<endl;
	}
	else{
		cout<<"AGC"<<endl;
	}
}

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

int main(){
  int i,j,minj,N,A[100],tmp,cnt=0;

  scanf("%d",&N);

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

  for(i=0; i<N; i++){
    minj = i;
    for(j=i; j<N; j++){
      if(A[j]<A[minj]){
        minj = j;
      }
    }
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    if(tmp != A[i])cnt++;
  }

  for(i=0; i<N; i++){
    if(i!=0) printf(" %d",A[i]);
    else printf("%d",A[i]);
  }

  printf("\n%d\n",cnt);

  return 0;
}



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


int main() {

   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);

   int n, p;
   cin >> n >> p;
   cout << ((n * 3) + p) / 2 << endl;


   return 0;
}

Measured memory_bytes: 256
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

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

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


#line 2 "tmp.cpp"

bool check1(deque<int> &path, vector<vi> &g, set<int> &s) {
  for (const auto v : g[path[0]]) {
    if (s.find(v) == s.end()) {
      path.push_front(v);
      s.insert(v);
      return false;
    }
  }
  return true;
}

bool check2(deque<int> &path, vector<vi> &g, set<int> &s) {
  for (const auto v : g[path[path.size() - 1]]) {
    if (s.find(v) == s.end()) {
      path.push_back(v);
      s.insert(v);
      return false;
    }
  }
  return true;
}

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

  int n, m;
  cin >> n >> m;
  vector<vi> g(n);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  deque<int> path;
  set<int> set;
  path.push_back(0);
  path.push_back(g[0][0]);
  set.insert(0);
  set.insert(g[0][0]);

  while (true) {
    if (check1(path, g, set) && check2(path, g, set))
      break;
  }

  int s = path.size();
  cout << s << endl;
  REP(i, s) { cout << path[i] + 1 << (i == s - 1 ? "\n" : " "); }

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int a, b;
  cin>>a>>b;
  cout<<a*b<<'\n';
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int a, b, m, t;
  cin >> a >> b >> m;
  vector<int> va, vb;
  
  for(int i = 0; i < a; i++) {
    cin >> t;
    va.push_back(t);
  }
  int ma = *min_element(va.begin(), va.end());
 
  for(int i = 0; i < b; i++) {
    cin >> t;
    vb.push_back(t);
  }
  int mb = *min_element(vb.begin(), vb.end());
  int result = ma + mb;
  
  for(int i = 0; i < m; i++) {
    cin >> a >> b >> t;
    result = min(result, va[a-1] + vb[b-1] - t);
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
    char c[3][3];
    for (int i=0; i<3; i++)
        for (int j=0; j<3; j++)
            cin >> c[j][i];
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

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

using namespace std;

int n, m, A, B;
int maxd, cnt;
int st[maxn];
vector<int> G[maxn];

void dfs(int u)
{
	st[u] = 1;
	for (auto v : G[u])
	{
		if (st[v] == 2)
		{
			if (A) B = v;
			else A = v;
		}
		else if (!st[v]) dfs(v);
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i ++ )
	{
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v), G[v].push_back(u);
	}
	
	for (int i = 1; i <= n; i ++ )
	{
		int ddd = G[i].size();
		if (ddd % 2) { puts("No"); return 0; }
		if (ddd > maxd) maxd = ddd, cnt = 1;
		else if (ddd == maxd) cnt ++ ;
	}
	
	if (maxd >= 6) puts("Yes");
	else if (maxd == 4)
	{
		if (cnt >= 3)
		{
			puts("Yes");
			return 0;
		}
		else if (cnt == 1)
		{
			puts("No");
			return 0;
		}
		else
		{
			for (int i = 1; i <= n; i ++ )	
				if (G[i].size() == 4) st[i] = 2;
			for (int i = 1; i <= n; i ++ )
				if (!st[i])
				{
					A = B = 0;
					dfs(i);
					if (A == B)
					{
						puts("Yes");
						return 0;
					}
				}
			
			puts("No");
		}
	}
	else puts("No");
	
	return 0;
}

Measured memory_bytes: 6912
//     nohomo    //
//  Brankonymous //
//     nohomo    //

#include <bits/stdc++.h>

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define mod 1000000007
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

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


Measured memory_bytes: 256
N,M = map(int,input().split())
A = set([int(input()) for i in range(M)])
MOD = 10**9+7

if 0 in A:
    print(0)
    exit()

dp = [0]*(N+1)
dp[0] = 1
for i in range(N):
    if i+1 not in A:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    if i+2 <= N and i+2 not in A:
        dp[i+2] += dp[i]
        dp[i+2] %= MOD
print(dp[-1])

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

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

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

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

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

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    vector<int> p(n);
    UnionFind uf(n+1);
    rep(i, n) cin>>p[i];
    rep(i, m) {
        int x,y;cin>>x>>y;
        uf.merge(x,y);
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        if(uf.issame(i+1, p[i])) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2176
N,M=map(int,input().split())
A=list(map(int,input().split()))
L=sum(A)/(4*M)
j=0
A1=sorted(A,reverse=True)
for i in range(M):
    if A1[i]>=L:
        j+=0
    else:
        j+=1
if j==0:
    print("Yes")
else:
    print("No")


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

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}

int main() {
    int n;
	cin >> n;
	for (int i = 11; i <= 55555; i += 10) {
		if (isprime(i) == true) {
			if (i != 11) cout << " ";
			cout << i; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int[] s = new int[m];
        int[] c = new int[m];
        for (int i = 0; i < m; i++) {
            s[i] = in.nextInt();
            c[i] = in.nextInt();
        }
        int limit = 1;
        for (int i = 0; i < n; i++) {
            limit *= 10;
        }
        for (int i = 0; i < limit; i++) {
            String is = String.valueOf(i);
            if (is.length() != n) {
                continue;
            }
            boolean ok = true;
            for (int j = 0; j < m; j++) {
                if (is.charAt(s[j] - 1) != c[j] + 48) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll ans = 0;
    ll r,g,b,n;
    cin >> r >> g >> b >> n;
    for (ll i=0;i<=n/r;i++){
        for (ll j=0;j<=n/g;j++){
            ll tmp = n - r*i - g*j;
            if(tmp >= 0 and tmp%b == 0){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256