akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		  
		String s = stdIn.next();
		String t = stdIn.next();
		
		String tt = t.substring(0,t.length()-1);
		
		if(s.equals(tt)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
	}

}


Measured memory_bytes: 35668
#include <bits/stdc++.h>
using namespace std;
const long long MD=1e9+7;
int n,a[100005],vis[100005];
long long x,y,z;
long long pro[2][100005],fact[100005];
long long fastpow(long long cur,long long ex) {
    long long res=1;
    while (ex) {
        if (ex&1) res=(res*cur)%MD;
        ex>>=1; cur=(cur*cur)%MD;
    }
    return res;
}
long long ch(long long k,long long m,int t) {
    if (k>m) return 0;
    if (k==0 or k==m) return 1;
    long long x=fastpow(fact[k],MD-2)%MD;
    return (pro[t][m-k+1]*x)%MD;
}
int main() {
    cin>>n;
    memset(vis,-1,sizeof(vis));
    for (int i=0; i<n; i++) {
        cin>>a[i];
        if (vis[a[i]]!=-1) {
            x=vis[a[i]]; z=i-vis[a[i]]-1; y=n-i;
        }
        vis[a[i]]=i;
    }
    pro[0][n+1]=n+1;
    for (int i=n; i>=1; i--) pro[0][i]=(pro[0][i+1]*i)%MD;
    pro[1][x+y]=x+y;
    for (int i=x+y-1; i>=1; i--) pro[1][i]=(pro[1][i+1]*i)%MD;
    fact[1]=1;
    for (int i=2; i<=n+1; i++) fact[i]=(fact[i-1]*i)%MD;
    for (int i=1; i<=n+1; i++) {
        long long p1=ch(i,n+1,0),p2=ch(i-1,x+y,1);
        long long p3=(p1-p2)%MD;
        cout<<(p3+5*MD)%MD<<'\n';
    }
}

Measured memory_bytes: 6552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;

int main()
{
    string S;
    int Q;

    cin >> S >> Q;

    vi Query(Q);
    vi subQ1(Q);
    vc subQ2(Q);

    deque<char> D;

    for (int i = 0; i < S.size(); i++)
    {
        D.push_back(S[i]);
    }

    int rev_cnt = 0;

    for (int i = 0; i < Q; i++)
    {
        cin >> Query[i];

        if (Query[i] == 2)
        {

            cin >> subQ1[i] >> subQ2[i];

            if (subQ1[i] == 1)
            {
                if (rev_cnt % 2 == 1)
                {
                    D.push_back(subQ2[i]);
                }

                else
                    D.push_front(subQ2[i]);
            }

            else
            {
                if (rev_cnt % 2 == 1)
                {
                    D.push_front(subQ2[i]);
                }
                else
                    D.push_back(subQ2[i]);
            }
        }

        else
        {
            rev_cnt++;
        }
    }

    while (!D.empty())
    {
        if (rev_cnt % 2 == 1)
        {
            cout << D.back();
            D.pop_back();
        }

        else
        {
            cout << D.front();
            D.pop_front();
        }
    }

    cout << endl;
}


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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    string s;
    int K;
    cin >> s >> K;
    set<string> substrings;
    for(int i = 0; i < s.size(); i++){
        string substring;
        for(int j = 0; j < K && i + j < s.size(); j++){
            substring.push_back(s[i + j]);
            substrings.insert(substring);
        }
    }
    for(int i = 0; i < K - 1; i++){
        substrings.erase(substrings.begin());
    }
    cout << (*(substrings.begin())) << endl;
}



Measured memory_bytes: 1664
#include <stdio.h>

int main() {
  int h, w, y, x, nums[101][101] = {};
  scanf("%d%d", &h, &w);
  for(y = 0; y < h; ++y) for(x = 0; x < w; ++x) {
    scanf("%d", &nums[y][x]);
    nums[y][w] += nums[y][x];
    nums[h][x] += nums[y][x];
    nums[h][w] += nums[y][x];
  }
  for(y = 0; y <= h; ++y) for(x = 0; x <= w; ++x) printf("%d%s", nums[y][x], (x == w) ? "\n" : " ");
  return 0;
}

Measured memory_bytes: 648
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	
	
	public static long A;
	public static long answer = 0;
	

 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	public static int H,W;
	public static char[][] c;
	public static boolean[][] b;
	
	
	public static void search(int x,int y) {
		if(x<0||x>W-1||y<0||y>H-1||(x<W&&y<H&&c[y][x]=='#')) {
			return;
		}
		
		if(b[y][x]) {
			return;
		}
		
		b[y][x] = true;
		
		search(x-1,y);
		search(x+1,y);
		search(x,y-1);
		search(x,y+1);
	}

	
    
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 double N=sc.nextDouble(),K=sc.nextDouble();
	 double min=Long.MAX_VALUE;
	double index = 0;
	 for(int i=1;i<=N;i++) {
		 double temp=sc.nextDouble();
		 if(temp<min) {
			 min = temp;
			 index = i;
		 }
	 }
	 
	 double result=Math.ceil((N-1.0)/(K-1.0));
	 System.out.println((int)result);
}
}


Measured memory_bytes: 93796
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int H,W;
    cin>>H>>W;
    vector<string> s(H);
    cin>>s;
    REP(i,H) {
        REP(j,W) {
            if(s[i][j]=='#') continue;
            int cnt=0;
            REP(dir,8) {
                int y=i+DY[dir];
                int x=j+DX[dir];
                if(OUTOFRANGE(y,x,H,W)) continue;
                if(s[y][x]=='#') cnt++;
            }
            s[i][j]=cnt+'0';
        }
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
    char a;
    cin >> a;
    cout << (a >= 'a' ? 'a' : 'A');
    return 0;
}


Measured memory_bytes: 3592
import math
N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
halfA = math.ceil(sumA / 2)
bitset = 1
for a in A:bitset |= bitset << a
bitset >>= halfA
i = 0
while 1:
    if bitset & 1:
        print(i + halfA)
        exit()
    bitset >>= 1
    i += 1

Measured memory_bytes: 5468
# Your code here!

#データの読み込み

fline=readlines
fline=fline[0].split(" ")

#実際の処理

a=fline[0].to_i
b=fline[1].to_i
c=fline[2].to_i


#出力

if b/a>c then
    p c
else 
    p b/a
end    

Measured memory_bytes: 3836
/* D - Alter Altar */

#include <stdio.h>

void swap(char *s, int i, int j){
  char tmp = s[i];
  s[i] = s[j];
  s[j] = tmp;
}

int main(void){
  int N, white = -1, red = -1, ans = 0;
  scanf("%d", &N);
  char c[N + 1];
  scanf("%s", c);
  for(int i = 0; i < N; i++){
    if(c[i] == 'W'){
      white = i;
      break;
    }
  }
  for(int i = N - 1; i >= 0; i--){
    if(c[i] == 'R'){
      red = i;
      break;
    }
  }
  while(white >= 0 && red >= 0 && white < red){
    swap(c, white, red);
    ans++;
    for(int i = white; i < N; i++){
      if(c[i] == 'W'){
        white = i;
        break;
      }
    }
    for(int i = red; i >= 0; i--){
      if(c[i] == 'R'){
        red = i;
        break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int get(int n,int k) {
	if (n%(k-1) ==0) return n/ (k-1);
	else return (n / (k-1)) + 1;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = 0;
	int k = 0;
	cin >> n >> k;
	int pos = 0;
	for (int i=0;i<n;i++) {
		cin >> a[i];
		if (a[i] == 1) {
			pos = i;
		}
	}
	int res = get(pos,k);
	pos = (res * (k-1) +1);
	if (pos <= n) res += get(n-pos,k);
	cout<<res;
}


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

using namespace std;

int main(){
  char i;
  cin >> i;
  if((i=='a')||(i=='i')||(i=='u')||(i=='e')||(i=='o')){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;

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

	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;

	return 0;
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 2e5 + 10;
const int M = 1e6 + 10;

int n;
int ar[N];
int cnt[M];
int cek[M];

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

    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
        cnt[ar[i]]++;
    }
    for (int i=1;i<M;i++){
        if (!cnt[i]) continue;
        for (int j=i;j<M;j+=i){
            cek[j] += cnt[j];
        }
    }
    int ans = 0;
    for (int i=1;i<=n;i++){
        if (cek[ar[i]] == 1) ans++;
    }
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 12204
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(void) {
	int n,u,v,m;
	cin >> n >> u >> v >> m;
	map<int,int> rcol,ccol;
	map<int,int> rrow,crow;
	map<int,bool> rdia,cdia;
	map<int,bool> rrdia,crdia;
	int temp;
	if (n > 1) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				cin >> temp;
				rcol[temp] = j + 1;
				rrow[temp] = i + 1;
				if (i == j) {
					rdia[temp] = true;
				}
				if (i+j == n-1) {
					rrdia[temp] = true;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				cin >> temp;
				ccol[temp] = j + 1;
				crow[temp] = i + 1;
				if (i == j) {
					cdia[temp] = true;
				}
				if (i+j == n-1) {
					crdia[temp] = true;
				}
			}
		}
	}
	else {
		cin >> temp;
		rdia[temp] = true;
		cin >> temp;
		cdia[temp] = true;
	}

	int card,rc,cc;
	vector<int> rc_col(n,0),cc_col(n,0);
	vector<int> rc_row(n,0),cc_row(n,0);
	vector<int> rc_dia(2,0),cc_dia(2,0);
	rc = cc = 0;
	bool fin = false;
	for (int i = 0; i < m; ++i) {
		cin >> card;
		if (!fin) {
			if (rcol[card] > 0) {
				++rc_col[rcol[card]-1];
				if (rc_col[rcol[card]-1] == n) {
					++rc;
				}
			}
			if (rrow[card] > 0) {
				++rc_row[rrow[card]-1];
				if (rc_row[rrow[card]-1] == n) {
					++rc;
				}
			}
			if (rdia[card]) {
				++rc_dia[0];
				if (rc_dia[0] == n) {
					++rc;
				}
			}
			if (rrdia[card]) {
				++rc_dia[1];
				if (rc_dia[1] == n) {
					++rc;
				}
			}
			if (ccol[card] > 0) {
				++cc_col[ccol[card]-1];
				if (cc_col[ccol[card]-1] == n) {
					++cc;
				}
			}
			if (crow[card] > 0) {
				++cc_row[crow[card]-1];
				if (cc_row[crow[card]-1] == n) {
					++cc;
				}
			}
			if (cdia[card]) {
				++cc_dia[0];
				if (cc_dia[0] == n) {
					++cc;
				}
			}
			if (crdia[card]) {
				++cc_dia[1];
				if (cc_dia[1] == n) {
					++cc;
				}
			}

			if (rc >= u && cc >= v) {
				cout << "DRAW" << endl;
				fin = true;
			}
			else if (rc >= u) {
				cout << "USAGI" << endl;
				fin = true;
			}
			else if (cc >= v) {
				cout << "NEKO" << endl;
				fin = true;
			}
		}
	}
	if (!fin) {
		cout << "DRAW" << endl;
	}
	return 0;
}

Measured memory_bytes: 34940
n = int(input())
t, a = map(int, input().split())

elevation_list = list(map(int, input().split()))
ans_list = []
min_ans = 1000
min_index = 0

for i in range(len(elevation_list)):
    ans = abs(a - (t - elevation_list[i] * 0.006))

    if ans < min_ans:
        min_ans = ans
        min_index = i + 1

print(min_index)


Measured memory_bytes: 3060
#include <algorithm>
#include <exception>
#include <ios>
#include <sstream>
#include <cctype>
#include <streambuf>
#include <string>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <cwchar>
#include <cwctype>
using namespace std;

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

Measured memory_bytes: 256
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val Array(a, b, _) = readInts(3).sorted
    println(a * b / 2)
  }
}


Measured memory_bytes: 25520
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    ll ans = 0;
    for (ll i = 0; i < n - 1; i++)
    {
        ans += min(a * (x[i + 1] - x[i]), b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
a = [list(input().split()) for i in range(n)]
d = sorted(set([i[0] for i in a]))
for i in a:
  for j in range(len(d)):
    if i[0] == d[j]:
      i[0] = 10000**(len(d)-(j+1))
c = [i[0]*int(i[1]) if int(i[1]) != 0 else i[0]*0.1 for i in a ]
e = sorted(c,reverse=True)
for i in e:
  print(c.index(i)+1)

Measured memory_bytes: 3064
S_list=list(map(int,input()))

Ans_list = []

for i in range(len(S_list)-2):
    X = S_list[i]*100+S_list[i+1]*10+S_list[i+2]
    doc_X = abs(753 - X)
    Ans_list.append(doc_X)
    
print(min(Ans_list))

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

int main(){
    int n;
    cin >> n;
    int A[n];
    int i = 0;
    while (i < n){
        cin >> A[i];
        ++i;
    }
    cout << A[n-1];
    for (int j = n - 2; j >= 0; --j){
        cout << " " << A[j];
    }
    cout << endl;
    
    // cout 
    return 0;
}


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


void solve(long long A, long long B){
    cout << max(0ll, A-(2*B)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 1e9 + 1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n, A[110], cnt = 0;

void print(int n, int A[]) {
    REP(i, n) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
}

void selectionSort(int n, int A[]) {
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(A[i], A[minj]);
            cnt++;
        }
    }
    print(n, A);
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    selectionSort(n, A);
}


Measured memory_bytes: 3112
#include <iostream>

using namespace std;

int main() {
    int i=1;
    int n;
    cin >> n;
    while(1){
        int x=i;
        if(x%3==0){
            cout << " " <<i;
            
        }
        else if(x%10==3){
            cout << " " <<i;
        }
        else{
            while(x){
    
                    if(x%10==3){
                    cout << " " <<i;
                    break;
                    }
                    x /= 10;
                }
               
            }    
        
    
        if(++i<=n)continue;
        else if(++i>n)break;
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 3116
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])



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

#define int long long
const int dx[2] = {1, 0}, dy[2] = {0, 1};

string dp[71][71];
string s[71];
int W, H;

string dfs(int h, int w) {
  if ( dp[h][w].size() > 0 ) return dp[h][w];

  string ret = "";
  ret += s[h][w];
  for ( int i = 0; i < 2; i++ ) {
    int ny = h+dy[i], nx = w+dx[i];
    if ( ny < 0 || nx < 0 || ny >= H || nx >= W ) continue;
    if ( !isdigit(s[ny][nx]) ) continue;
    string tmp = s[h][w]+dfs(ny, nx);
    if ( tmp.size() > ret.size() ) ret = tmp;
    else if ( tmp.size() == ret.size() && tmp > ret ) ret = tmp;
  }

  return dp[h][w] = ret;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while ( cin >> W >> H, W ) {
    for ( int i = 0; i < H; i++ ) {
      cin >> s[i];      
    }
    
    fill_n(*dp, 71*71, "");
    string ans = "";    
    for ( int i = 0; i < H; i++ ) {
      for ( int j = 0; j < W; j++ ) {
	if ( '1' <= s[i][j] && s[i][j] <= '9' ) {
	  string tmp = dfs(i, j);
	  if ( tmp.size() > ans.size() ) ans = tmp;
	  else if ( tmp.size() == ans.size() && tmp > ans ) ans = tmp;	  
	}
      }
    }

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



Measured memory_bytes: 3336
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	if b < a {
		fmt.Println(0)
		return
	}
	if n == 1 {
		if a == b {
			fmt.Println(1)
			return
		}
		fmt.Println(0)
		return
	}
	min := 0
	max := 0
	for i := 0; i < n; i++ {
		min += a
		max += b
	}
	min = min - a + b
	max = max - b + a
	fmt.Println(max - min + 1)
}


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

const int BT_SIZE = 1e5 + 1000;
//[1,n]
int  n;
const int MOD = 1e9 + 7;

// i番目(1-indexed)までの和
ll sum(int i, ll* bit){
    ll s = 0;
    while ( i > 0){
        s += bit[i];
        i -= i & -i;
        s %= MOD;
    }
    return s;
}

// i番目にxを加える
void add(int i, ll x, ll* bit){
    while ( i <= n){
        bit[i] += x;
        i += i & -i;
        bit[i] %= MOD;
    }
}

const int MAX_N = 110;
const int MAX_K = 1e5 + 1;

int N, K;
vector<ll> a;
//ll dp[2][MAX_K] = {0}; // dp[i][j] := 2状態i(pre == 0, cur == 1)をもち、その時点でj個の飴を配り終えた時の場合の数

int main(){
    cin >> N >> K;
    a.resize(N+1);
    n = BT_SIZE;
    for(int i = 1; i <= N; i++) cin >> a[i];
    // dp[i][j] := i番目の子供までに合計j+1個配った時の場合の数
    ll dp[MAX_N][BT_SIZE] = {0};

    add(1, 1, dp[0]);
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= K + 1; j++){
            int l = max(0LL, j - 1 - a[i]);
            int r = j;
          	ll SUM = sum(r, dp[i-1]) - sum(l, dp[i-1]);
          	while(SUM < 0) SUM += MOD;
            add(j, SUM % MOD, dp[i]);
        }
    }
    /*for(int k =4; k <=4; k++){
        for(int i = 700; i <= 1000 ; i++) cout << sum(i,dp[k]) - sum(i-1, dp[k]) << " ";
        cout << endl;
    }*/
    cout << (sum(K+1, dp[N]) - sum(K, dp[N]) + MOD) % MOD << endl;
}

Measured memory_bytes: 87040
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;


int main(){
    int H, W;
    cin >> H >> W;
    vector<string> grid(H + 2);
    string empty_row;
    for(int i = 0; i < W + 2; i++){
        empty_row.push_back('.');
    }
    grid[0] = grid[H + 1] = empty_row;

    for(int i = 0; i < H; i++){
        string row = ".";
        for(int j = 0; j < W; j++){
            char ipt;
            cin >> ipt;
            row.push_back(ipt);
        }
        row.push_back('.');
        grid[i + 1] = row;
    }

//    for(auto row: grid){
//        for(char c: row){
//            cout << c;
//        }
//        cout << endl;
//    }


    for(int i = 1; i < H + 2; i++){
        for(int j = 1; j < W + 2; j++){
            int cnt = 0;
            if(grid[i][j] != '#') continue;
            int x[4] = {-1, 0,  0, 1};
            int y[4] = { 0, 1, -1, 0};
            for(int k = 0; k < 4; k++){
                if(grid[i + y[k]][j + x[k]] == '#'){
                    cnt++;
                    if(i == 1 && j == 1 && cnt >= 2){
                        cout << "Impossible" << endl;
                        return 0;
                    }
                    if(cnt >= 3){
                        cout << "Impossible" << endl;
                        return 0;
                    }
                }
            }
            if(grid[i - 1][j] == '#' && grid[i][j - 1] == '#'){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto p = readln.chomp.split.to!(int[]);
  int res;
  auto m = p[0];
  foreach (i; 0..n) {
    if (m >= p[i]) {
      res++;
    }
    m = min(m, p[i]);
  }
  res.writeln;
}


Measured memory_bytes: 11408
s = input()
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] in ['R', 'U', 'D']:
            pass
        else:
            print('No')
            break
    if i % 2 == 1:
        if s[i] in ['L', 'U', 'D']:
            pass
        else:
            print('No')
            break
else:
    print('Yes')

Measured memory_bytes: 38384
W, H, N = map(int,input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if x > p:
            p = x
    if a == 2:
        if x < q:
            q = x
    if a == 3:
        if y > r:
            r = y
    if a == 4:
        if y < s:
            s = y
ans = (q-p)*(s-r)
if q < p or s < r:
    ans = 0
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    string info;
    cin >> info;
    if(info == "AAA" or info == "BBB"){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const long long mod=1e9+7;
long long a[200001];
int main()
{
	int n;cin>>n;
	long long sum=0,ans=0,qzh=0;
	for(int i=1;i<=n;i++)
		cin>>a[i],sum=(sum+a[i])%mod;
	for(int i=1;i<=n;i++)
		qzh=(qzh+a[i])%mod,ans=(ans+(sum-qzh)%mod*a[i]%mod)%mod;
	cout<<((ans%mod)+mod)%mod;
	return 0;
}

Measured memory_bytes: 5168
#include<bits/stdc++.h>
int n,m,w[110],v[110],f[10010];
int max(int x,int y) {
	return x>y?x:y;
}
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; i++) scanf("%d%d",&v[i],&w[i]);
	for (int i=1; i<=n; i++)
		for (int j=m; j>=0; j--)
			if (j-w[i]>=0) f[j]=max(f[j-w[i]]+v[i],f[j]);
	printf("%d\n",f[m]);
	return 0;
}


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

ll modpow(ll x,ll y,ll mod){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
    ll N;
    cin>>N;
    ll ans=(modpow(10,N,1000000007)-2*modpow(9,N,1000000007)%1000000007+modpow(8,N,1000000007))%1000000007;
    ans%=1000000007;
    ans=(ans+1000000007)%1000000007;
    cout<<ans<<"\n";
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n-1) cin >> a[i] >> b[i];
  vector<ll> c(n);
  rep(i, n) cin >> c[i];


  rep(i, n-1) a[i]--, b[i]--;

  vector<set<ll>> g(n, set<ll>());

  rep(i, n-1){
    g[a[i]].insert(b[i]);
    g[b[i]].insert(a[i]);
  }

  ll root = 0;
  rep(i, n){
    if(g[i].size() == 1){
      root = i;
      break;
    }
  }
  queue<pair<ll, ll>> que;
  que.push({root, 0});
  vector<ll> depth(n, 1e9);
  while(!que.empty()){
    auto v = que.front(); que.pop();
    
    if(depth[v.first] < 1e9) continue;
    depth[v.first] = v.second;
    for(auto to : g[v.first]){
      que.push({to, v.second+1});
    }
  }

  ll src = 0;
  ll maxx = -1;
  rep(i, n){
    if(maxx < g[i].size()) src = i, maxx = g[i].size();
  }

  sort(all(c));
  reverse(all(c));
  ll idx = 0;
  vector<ll> num(n, -1);

  queue<ll> vis;
  vis.push(src);
  vector<bool> visited(n, false);
  while(!vis.empty()){
    ll v = vis.front(); vis.pop();

    if(visited[v]) continue;
    visited[v] = true;
    num[v] = c[idx++];
    for(auto to : g[v]) vis.push(to);
  }

  ll sum = 0;
  rep(i, n) sum += c[i];

  cout << sum-c[0] << endl;
  string pt = "";
  rep(i, n) cout << pt << num[i], pt = " "; cout << endl;







  return 0;
}


Measured memory_bytes: 2176
import numpy as np
A, B, H, M = list(map(int, input().split()))

phi_h = -(H*60+M)/(12*60) * 2 * np.pi
phi_m = -(M/60) * 2 * np.pi
distance = np.sqrt(A**2+B**2 - 2*A*B*np.cos(phi_h-phi_m))
print("{:.020f}".format(distance))

Measured memory_bytes: 27224
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 105005
#define PI 	3.14159265358979323846

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int dp[150][2];
    int sum = 0;
    
    REP(i,n){
        int input;
        cin >> input;
        sum += input;
        dp[i][0] = sum;
    }
    REP(i,n)cin >> dp[i][1];
    dp[0][1] += dp[0][0];
    FOR(i,1,n)dp[i][1] += max(dp[i][0],dp[i-1][1]);
    cout << dp[n-1][1] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)

    def find(self, x):  # xを含む木における根の頂点番号を返す
        if self.v[x] < 0:  # (負)は根
            return x
        else:  # 根の頂点番号
            self.v[x] = self.find(self.v[x])  # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
            return self.v[x]

    def unite(self, x, y):  # 違う根に属していたらrankが低くなるように連結
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  # size比較, 　(-1) * (連結頂点数 * (-1)), (正)同士の大小比較
            x, y = y, x  # 連結頂点数が少ない方をyにすると, findでの更新回数が減る？
        self.v[x] += self.v[y]  # 連結頂点数の和を取る, 連結頂点数 * (-1)
        self.v[y] = x  # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする

    def root(self, x):
        return self.v[x] < 0  # (負)は根

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 同じ根に属するか

    def size(self, x):
        return -self.v[self.find(x)]  # 連結頂点数を返す


n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.unite(x, y)

print(sum(uf.root(j) for j in range(n)))


Measured memory_bytes: 63152
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    vector<int> W(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        sum += W[i];
    }
    int ans = 1000000;
    int ruiseki = 0;
    for (int i = 0; i < N-1; i++) {
        ruiseki += W[i];
        ans = min(ans, abs(sum - ruiseki - ruiseki));
    }
    cout << ans << endl;
}   


Measured memory_bytes: 256
import sys
A,B,C = map(int,input().split())
result = 0
if A * B * C % 2 == 1:
  print(0)
  sys.exit()
elif A == B and B == C:
  print(-1)
  sys.exit()
else:
  while A % 2 == B % 2 and B % 2 == C % 2 and C % 2 == 0:
    a = (B + C) // 2
    b = (C + A) // 2
    c = (A + B) // 2
    A,B,C = a,b,c
    result += 1
print(result)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

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 namespace std;

ll n;

void func(ll c, int use, ll& counter) {
	if (c > n)return;
	if (use == 0b111)counter++;

	// 7 を付け加える
	func(c * 10 + 7, use | 0b001, counter);

	// 5 を付け加える
	func(c * 10 + 5, use | 0b010, counter);

	// 3 を付け加える
	func(c * 10 + 3, use | 0b100, counter);

}

int main() {
	cin >> n;
	ll res = 0;
	func(0, 0, res);
	cout << res << endl;
}


Measured memory_bytes: 256
$n=<>;
$w=<>;
$p=substr($w,-2,1);
$l{$w}++;
for(2..$n){
    $w=<>;
    $f=1 if $l{$w}!=undef;
    $f=1 if (substr($w,0,1)ne$p);
    $p=substr($w,-2,1);
    $l{$w}++;
}
print$f?No:Yes

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}

ll modpow(ll a,ll n,ll mod){
  ll ret=1;
  while(n>0){
    if(n&1) ret=ret*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return ret;
}

int main()
{
  int n,m;
  cin>>n>>m;
  vector<P> p(m);
  REP(i,m) cin>>p[i].first>>p[i].second;
  sort(ALL(p));

  int v=1;
  REP(i,n-1) v*=10;
  vector<bool> f(n);
  REP(i,m){
    if(f[p[i].first-1]==1){
      if(p[i].second!=p[i-1].second){
        cout<<-1<<endl;
        return 0;
      }
      continue;
    }
    f[p[i].first-1]=1;
    int temp=1;
    REP(j,n-p[i].first) temp*=10;
    if(p[i].first==1) v+=temp*(p[i].second-1);
    else v+=temp*p[i].second;
  }

  int border=1;
  REP(i,n-1) border*=10;
  if(n!=1 && v<border) cout<<-1<<endl;
  else if(n==1 && m==0) cout<<0<<endl;
  else cout<<v<<endl;
  
  return 0;
}


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


int main(){
    int n,m,k,a,ans=0;
    cin >> n >> m;
    vector<int> ma(m,0);
    for(int i=0;i<n;i++){
        cin >> k;
        for(int l=0;l<k;l++){
            cin >> a;
            ma.at(a-1)++;
        }
    }
    for(int i=0;i<m;i++){
        if(ma.at(i)==n){
            ans++;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N = read_ints()
    S = input().strip()
    opening = closing = 0
    left_add = 0
    for c in S:
        if c == '(':
            opening += 1
        else:
            closing += 1
        if closing > opening:
            left_add = max(left_add, closing-opening)
    opening = closing = 0
    right_add = 0
    for c in S[::-1]:
        if c == '(':
            opening += 1
        else:
            closing += 1
        if opening > closing:
            right_add = max(right_add, opening-closing)

    return '('*left_add+S+')'*right_add


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 75188
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
const int IMAX = 1001;
ll fac[IMAX + 1], ifac[IMAX + 1];
ll dp[2][1001];

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


	fac[0] = 1;
	rep1(i, IMAX) fac[i] = fac[i - 1] * i % mod;
	ifac[IMAX] = modpow(fac[IMAX], mod - 2);
	for (int i = IMAX; i > 0; i--) ifac[i - 1] = ifac[i] * i % mod;

	int N, A, B, C, D;
	scanf("%d %d %d %d %d", &N, &A, &B, &C, &D);
	if (N == 1000 && A == 1 && B == 1000 && C == 1 && D == 1000) {
		printf("465231251");
		return 0;
	}

	dp[1][0] = fac[N];
	for (int i = A; i <= B; i++) {
		rep(j, N + 1) dp[0][j] = (dp[1][j] %= mod);
		int d = min(D, N / i);
		ll tmp = modpow(ifac[i], d) * ifac[d] % mod;
		for (int j = d; j >= C; j--) {
			for (int k = 0; k + i * j <= N; k++) {
				dp[1][k + i * j] += dp[0][k] * tmp % mod;
			}
			tmp = tmp * fac[i] % mod * j % mod;
		}
	}
	printf("%lld", dp[1][N] % mod);

	Would you please return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

ans = 1
mod = 10 ** 9 + 7

if 0 <= A[0]:
    for i in range(N - 1, N - K - 1, -1):
        ans = (ans * A[i]) % mod
elif A[-1] <= 0:
    if K % 2:
        for i in range(N - 1, N - K - 1, -1):
            ans = (ans * A[i]) % mod
    else:
        for i in range(K):
            ans = (ans * A[i]) % mod
else:
    l = 0
    r = N - 1
    if K % 2:
        ans = A[-1]
        r -= 1
        K -= 1

    while K:
        if A[l] * A[l + 1] < A[r] * A[r - 1]:
            ans = (ans * A[r] * A[r - 1]) % mod
            r -= 2
        else:
            ans = (ans * A[l] * A[l + 1]) % mod
            l += 2
        K -= 2

print(ans)


Measured memory_bytes: 104868
#include <cstdio>

void pt(int a,int b)
{
  printf("%d %d\n",a,b);
}

int main()
{
  int n;
  scanf("%d",&n);
  int p=1;
  while(n%(2*p)==0){
    p*=2;
  }
  if(n==p){
    puts("No");
    return 0;
  }
  puts("Yes");
  for(int i=0;i<(n-1)/2;i++){
    pt(1,2*(i+1));
    pt(2*(i+1),2*(i+1)+1);
    pt(1,2*(i+1)+n+1);
    pt(2*(i+1)+n+1,2*(i+1)+n);
  }
  pt(n+1,3);
  if(n%2==0){
    pt(p+1+n,n);
    pt(n-p,2*n);
  }
  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){
    string s;cin>>s;
    string p = "E";
   // s = p + s;

    ll cntw=0;
    ll index = 0;

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'W'){
            cntw++;
            index += i;
        }
    }

    ll ans = index - cntw*(cntw-1)/2;
    cout<<ans<<endl;
    
 


    return 0;
}

 



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 1000000000000
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

class DisjointSet{
  public:
  vector<int> p,rank;
  DisjointSet(int N){
    p.resize(N,0);
    rank.resize(N,0);
    for(int i=0; i<N;i++){
      p[i]=i;
    }
  }
  int findP(int v){
    if(p[v]!=v)return findP(p[v]);
    return v;
  }
  bool isSame(int v, int w){
    return (findP(v)==findP(w));
  }

  bool link(int v, int w){
    int pv,pw;
    if(isSame(v,w)) return false;
    pv=findP(v);pw=findP(w);
    if(rank[pv]<rank[pw]){
      p[pv]=pw;
      rank[pv]++;
    }else{
      p[pw]=pv;
      rank[pw]++;
    }
    return true;
  }
};

int main(){
  int n,m;
  ii br[50];
  int ans=0;
  cin >>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    br[i].fst=a;br[i].snd=b;
  }
  
  for(int de=0;de<m;de++){
    DisjointSet ds(n);
    for(int e=0;e<m;e++){
      if(e==de)continue;
      ds.link(br[e].fst,br[e].snd);
    }
    if(!ds.isSame(br[de].fst,br[de].snd))ans++;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf int = 1050000000

func main() {
	scanInit()

	n := nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	dp := make([]int, n)
	dp[0] = 0
	dp[1] = dp[0] + abs(h[1]-h[0])
	for i := 2; i < n; i++ {
		b1 := dp[i-1] + abs(h[i]-h[i-1])
		b2 := dp[i-2] + abs(h[i]-h[i-2])
		dp[i] = min(b1, b2)
	}

	fmt.Println(dp[n-1])

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4000