akhauriyash/Code-Regression huggingface dataset:
w = gets.chomp.to_i
n = gets.chomp.to_i

change = []

for i in (0...n)
        change[i] = gets.chomp.split(",")
        change[i][0] = change[i][0].to_i - 1
        change[i][1] = change[i][1].to_i - 1
end


data = []
for i in (0...w)
        data[i] = i + 1
end


for i in (0...n)
        data[change[i][0]], data[change[i][1]] = data[change[i][1]], data[change[i][0]]
end

puts data



Measured memory_bytes: 8892
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

class PROCESS {
public:
	string name;
	int time;
};

PROCESS p[100000];
int headIndex = 0;
int lastIndex = 0;

void enqueue(PROCESS np) {
	p[lastIndex++] = np;
	if (lastIndex >= 100000)
		lastIndex = 0;
}

PROCESS dequeue() {
	PROCESS result = p[headIndex++];
	if (headIndex >= 100000)
		headIndex = 0;
	return result;
}

bool isEmpty() {
	return lastIndex == headIndex;
}

int main() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		PROCESS p;
		cin >> p.name >> p.time;
		enqueue(p);
	}
	int ctime = 0;
	while (!isEmpty()) {
		PROCESS p = dequeue();
		if (p.time <= q) {
			ctime += p.time;
			cout << p.name << " " << ctime << endl;
			;
		} else {
			p.time -= q;
			ctime += q;
			enqueue(p);
		}
	}

	return 0;
}

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

ostream& operator<<(ostream& os, const P& p) {
    os << p.first << ' ' << p.second;
    return os;
}

int main() {

    int N;
    cin >> N;
    vector<int> a(N*3+1);
    rep(i, N*3) cin >> a[i];

    ll p[N+1], b[N+1];

    priority_queue<int, vector<int>, greater<int>> que1;
    priority_queue<int> que2;

    ll sum=0;
    int id=0;
    for (int i=0; i<N; ++i) {
        que1.push(a[i]);
        sum += a[i];
    }
    p[id++] = sum;

    for (int i=N; i<2*N; ++i) {
        sum += a[i];
        que1.push(a[i]);
        int t = que1.top(); que1.pop();
        p[id++] = sum - t;
        sum -= t;
    }

    id=0;
    ll sum2=0;
    for (int i=N*3-1; i>=2*N; --i) {
        que2.push(a[i]);
        sum2 += a[i];
    }

    b[id++] = sum2;
    for (int i=2*N-1; i>=N; --i) {
        sum2 += a[i];
        que2.push(a[i]);
        int t = que2.top(); que2.pop();
        b[id++] = sum2 - t;
        sum2 -= t;
    }

    reverse(b, b+N+1);

    ll ma = -(1LL<< 50);
    rep(i, N+1) {
        ma = max(ma, p[i]-b[i]);
    }

    cout << ma << endl;

}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef vector<vi> vii;
const int mxN=405,INF=1e18+7;
//did u check when n=1?
//is mxN correct?
int n,v[mxN],pref[mxN];
int dp[mxN][mxN];

int solve(int l,int r){
    if(l==r)return dp[l][r]=0;
    if(dp[l][r]!=-1)return dp[l][r];
    int ans=INF;
    for(int i=l;i<r;i++){
        ans=min(ans,solve(l,i)+solve(i+1,r)+pref[r+1]-pref[l]);
    }
    return dp[l][r]=ans;
}
int32_t main(){
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
        pref[i+1]=pref[i]+v[i];
    }
    cout<<solve(0,n-1);
    

}   
//dp[l][r]=menor custo pra transformar l->r em um slime
///z

Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] D=new int[N];
		for(int i=0; i<N; i++) {
			D[i]=sc.nextInt()*2;
		}
		int M=sc.nextInt();
		int[] T=new int[M];
		for(int i=0; i<M; i++) {
			T[i]=sc.nextInt()*2;
		}
		Arrays.sort(D);
		for(int i=0; i<M; i++) {
			int index=lowerBound(D,T[i]);
			if(index==-1) {
				pl("NO");
				System.exit(0);
			}
			else if(D[index]==T[i]) {
				D[index]--;
			}
			else if(D[index]!=T[i]) {
				pl("NO");
				System.exit(0);
			}
		}
		pl("YES");
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static final int lowerBound(final int[] arr, final int value) {
		int low = 0;
		int high = arr.length;
		int mid;
		while (low < high) {
			mid = ((high - low) >>> 1) + low;    //(low + high) / 2 (オーバーフロー対策)
			if (arr[mid] < value) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		if(low<arr.length) {
			return low;
		}
		else {
			return -1;
		}
	}
}


Measured memory_bytes: 61532
#include<bits/stdc++.h>
using namespace std;
#define int long long
int Max[20],v1[20],v2[20],a[20],delta,d,fac[20],ans,tot;
void dfs(int x,int y,int z){
	if (x>tot){
		ans+=(y==d)*z;
		return;
	}
	if (y+Max[x]<d||y-Max[x]>d)return;
	for (int i=-9;i<=9;i++)dfs(x+1,y+i*a[x],z*(x==1?v1[i+9]:v2[i+9]));
}
signed main(){
	scanf("%lld",&delta);
	delta=-delta;
	fac[0]=1;
	for (int i=1;i<=18;i++)fac[i]=fac[i-1]*10;
	for (int i=1;i<=9;i++)
		for (int j=0;j<=9;j++)v1[i-j+9]++;
	for (int i=0;i<=9;i++)
		for (int j=0;j<=9;j++)v2[i-j+9]++;
	for (int len=2;len<=18;len++){
		tot=0;
		for (int i=len-1,j=0;i>j;i--,j++)
			a[++tot]=fac[i]-fac[j];
		int Gcd=0;
		for (int i=1;i<=tot;i++)Gcd=__gcd(Gcd,a[i]);
		if (delta%Gcd!=0)continue;
		for (int i=1;i<=tot;i++)a[i]/=Gcd;
		for (int i=tot;i;i--)Max[i]=Max[i+1]+9*a[i];
		d=delta/Gcd;
		dfs(1,0,(len&1)?10:1);
	}
	printf("%lld\n",ans);
}
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
vector<ll>vc;
void dfs(int dep, ll pre) {
	if (dep == 0) {
		vc.push_back(pre);
		return;
	}
	int p = pre % 10;
	for (int i = max(0, p - 1); i <= min(9, p + 1); i++) {
		dfs(dep - 1, pre * 10 + i);
	}
}
int main() {
	int num = 1;
	while (1) {
		for (int i = 1; i <= 9 && (int)vc.size() < 100000; i++) {
			dfs(num - 1, i);
		}
		if ((int)vc.size() >= 100000)break;
		num++;
	}
	sort(vc.begin(), vc.end());
	int n;
	cin >> n;
	printf("%lld\n", vc[n - 1]);
	return 0;
}

Measured memory_bytes: 1400
/*
   ЗАПУСКАЕМ СТЕНУ ИЗ КРЕМА
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    map <int, int> a;
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        a[x]++;
    }
    int cur = 0;
    ll ans = 0;
    for (auto c : a)
    {
        if (c.second >= 4)
        {
            ans = max(ans, c.first * (ll) c.first);
	    	cur = max(cur, c.first);
        }
        else
        {
            if (c.second >= 2)
            {
                ans = max(ans, cur * (ll) c.first);
                cur = max(cur, c.first);
            }
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

int gcd(int u, int v) {
  int r;
  while (v != 0) {
    r = u % v;
    u = v;
    v = r;
  }
  return u;
}

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

  int r = M / N, res = -1;
  while(true) {
    if (M % r == 0) {
      res = r;
      break;
    }
    r--;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

i64 H, W, D, Q; cin >> H >> W >> D;
// dist[a]= (i, j, dist). 座標，a%Dからの距離．
VVI dist(H*W+1);
rep(i, 0, H) rep(j, 0, W){
    int a; cin >> a;
    dist[a] = VI{i+1, j+1, 0}; 
}
rep(a, D+1, H*W + 1){
    int x = dist[a][0], y = dist[a][1];
    int px = dist[a - D][0], py = dist[a - D][1];
    dist[a][2] = dist[a - D][2] + abs(x - px) + abs(y - py);
}


cin >> Q;
rep(_, 0, Q){
    int l, r; cin >> l >> r;
    cout << abs(dist[r][2] - dist[l][2]) << "\n";
}

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,a,n) for(int i=a;i<n;i++)
typedef complex<double> P;
struct seg{P p1,p2;};
double eps=1e-10;
bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;
  if(a.imag()<-eps)return -1;
  if(a.real()<-eps)return 2;
  if(abs(b)+eps<abs(c))return -2;
  return 0;
}
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}
bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}
double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}
int main(){
  double a,b,c,d;
  int n,ve,al;
  while(cin>>n>>ve>>al,n){
    P p[n][5];
    seg D[n][5];
    r(i,n){
      cin>>a>>b>>c>>d;
      r(j,5)p[i][j]=P(a-d*sin(M_PI/180*(72*j+c)),b+d*cos(M_PI/180*(72*j+c)));
      r(j,5)D[i][j].p1=p[i][j%5],D[i][j].p2=p[i][(j+2)%5];
    }
    double w[n][n];
    r(i,n)r(j,n)w[i][j]=i==j?0:1000000000;
    r(i,n)R(j,i+1,n){
      double t=1000000000;
      r(k,5)r(l,5)t=min(t,dist(D[i][k].p1,D[i][k].p2,D[j][l].p1,D[j][l].p2));
      w[i][j]=w[j][i]=t;
    }
    r(k,n)r(i,n)r(j,n)w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
    printf("%.11f\n",w[ve-1][al-1]);
  }
}

Measured memory_bytes: 3720
S=input()
n=len(S)
s1=S[0:(n-1)//2]
s2=S[(n+1)//2:n]

if s1!=s2:
    print("No")
    exit()

s3=s1[0:(n-1)//2]
s4=s1[0:(n+1)//2]
if s3!=s4:
    print("No")
    exit()

s5=s2[0:(n-1)//2]
s6=s2[0:(n+1)//2]
if s5!=s6:
    print("No")
    exit()

print("Yes")

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    string s; cin >> s;
    int N = s.size();
    // dp[i][j] : i 文字目まで見た時に 13 で割って j 余るものの個数
    int dp[100010][13] = {};
    dp[0][0] = 1;
    rep(i, N) {
        rep(j, 13) {
            if(s[i] == '?') {
                rep(k, 10) {
                    int tmp = (10*j + k)%13;
                    dp[i+1][tmp] += dp[i][j];
                    dp[i+1][tmp] %= MOD;
                }
            } else {
                int tmp = (10*j + (s[i]-'0'))%13;
                dp[i+1][tmp] += dp[i][j];
                dp[i+1][tmp] %= MOD;
            }
        }
    }

    cout << dp[N][5] << '\n';
    return 0;
}

Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
int main(){ 
  int a,b,c,i = 3,d = 1;
  cin >> a >> b >> c;
  if (a == b){
    i -= d;
  }
  if (a == c){
    i -= d;
  }
  if (b == c){
    i -= d;
  }
  if (a == b && b == c){
    i += d;
  }
  cout  << i << '\n';
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    S = input()
    A = []
    if S[0]=='1':
        nw = 1
    else:
        nw = -1
    for i in range(1,N):
        if S[i]=='1' and nw<0:
            A.append(nw)
            nw = 1
        elif S[i]=='0' and nw>0:
            A.append(nw)
            nw = -1
        else:
            nw += 2*(S[i]=='1')-1
    A.append(nw)
    if len(A)==1:
        print(N)
        exit()
    B = [0]*(len(A)+1)
    for i in range(len(A)):
        B[i+1] = B[i]+abs(A[i])
    if A[0]<0:
        fm = 0
    else:
        fm = 1
    ret = 0
    for i in range(fm, len(A), 2):
        ret = max(ret, B[min(i+2*K,len(B)-1)]-B[max(i-1,0)])
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13756
S=input()
n=len(S)
S1=S[0:(n-1)//2]
S2=S[(n+3)//2-1:]

if S1==S2 and S1[0:(n-1)//2]==S1[(n-1)//2::-1] and S2[0:(n-1)//2]==S2[(n-1)//2::-1]:
  print('Yes')
else:
  print('No')
  

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

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0; i<3; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        boolean res = false;
        if(a[0] != a[1] && a[1] != a[2]) {
            res = true;
        } else if (a[0] == a[1] && a[1] == a[2]) {
            res = true;
        }
        System.out.println(res ? "No" : "Yes");



    }



}


Measured memory_bytes: 23764
k = int(input())
a = [0]*k
a[0] = 7%k
for i in range(1, k):
    a[i] = (a[i-1] * 10 + 7)%k
for i in range(k):
    if a[i] == 0:
        print(i+1)
        exit()
print(-1)


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

int main() {
  int n;
  string s;
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (s == "AC") {
      ac++;
    } else if (s == "WA") {
      wa++;
    } else if (s == "TLE") {
      tle++;
    } else {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N, M;
    cin >> N >> M;
    vector<LL> X(M);
    REP(i,M)cin>>X[i];

    if(N >= M){
        cout << 0 << endl;
        return 0;
    }

    sort(X.begin(), X.end());

    vector<LL> dist(M-1);
    LL sum = 0;
    REP(i,M-1){
        dist[i] = abs(X[i+1] - X[i]);
        sum += dist[i];
    }

    sort(dist.begin(), dist.end(), greater<LL>());

    REP(i,N-1){
        sum -= dist[i];
    }

    cout << sum << endl;
    return 0;

    


}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  cout<<(N-1)*N/2-N/2<<endl;
  if(N%2==0){
    for(int i=0;i<N;i++)
      for(int j=i+1;j<N;j++)
        if(i+j+1!=N)cout<<i+1<<' '<<j+1<<endl;
  }else{
    for(int i=0;i<N;i++)
      for(int j=i+1;j<N;j++)
        if(i+j+2!=N)cout<<i+1<<' '<<j+1<<endl;
  }
}

Measured memory_bytes: 3644
N, M, X = map(int, input().split())
import numpy as np
books = [list(map(int, input().split())) for _ in range(N)]

ans = 10**18
for i in range(1<<N):
    algo = np.array([0]*M)
    cost = 0
    for j in range(N):
        if (i>>j)&1:
            c, *al = books[j]
            al = np.array(al)
            algo += al
            cost += c
    if np.all(algo>=X):
        ans = min(ans, cost)

if ans!=10**18:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 27524
from collections import deque

n, queries = map(int, input().split())

stack_dict = []
for i in range(n):
    stack_dict.append(deque())

for i in range(queries):
    q, t, *x = map(int, input().split())
    if q == 0:
        stack_dict[t].append(x[0])
    elif q == 1:
        if stack_dict[t]:
            print(stack_dict[t][-1])
    elif q == 2:
        if stack_dict[t]:
            stack_dict[t].pop()


Measured memory_bytes: 14532
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
  tmp = toIntAll(tmp);
	var k = parseInt(tmp[0], 10);
	var x = parseInt(tmp[1], 10);

  var down = x-(k-1);
  var up = x+(k-1);

  if(down < -1000000) down = -1000000;
  if(1000000 < up) up = 1000000;

  var array = [];
  for (var i = 0; i < up-down+1; i++) {
    array[i] = down + i;
  }

  var result = outputDelimiterSpace(array);
	//出力
	console.log('%s',result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function toIntAll(input){
  var out = []
  for(var i=0; i<input.length; i++){
    out[i] = parseInt(input[i]);
  }
  return out;
}

//配列を空白区切りの文字列に結合（最後に改行） -> string
function outputDelimiterSpace(words){
  var out = words.join(' ');
  out += '\n';
  return out;
}


Measured memory_bytes: 21064
#include <cassert>
#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>
*/

// 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 <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>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
// #define MOD 1000000007
ll h,w,k;
const ll MOD = 1000000007LL;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>h>>w>>k;
  k--;
  vector< vector<ll> > dp(h+1,vector<ll> (w));
  dp[0][0]=1;
  rep(k,h)rep(j,w)rep(l,1LL<<(w-1)){
    std::vector<bool> row(w-1);
    rep(i,w-1) row[i] = (l&(1LL<<i));
    bool ok = true;
    rep(i,w-2) ok = ok && !(row[i] and row[i+1]);
    if(!ok) continue;

    ll n = j;
    if(j < w-1 and row[j]) n = j+1;
    if(j-1 >= 0 and row[j-1]) n = j-1;

    dp[k+1][n] += dp[k][j];
    dp[k+1][n] %= MOD;
  }

  cout<<dp[h][k]<<endl;

}

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


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

int main() {
	int n;
	cin >> n;
	int a[100];
	int b[100];
	int count = 0;
	for (int i = 0; i < n; i++) {
		a[i] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			count++;
		}
	}
	if (count >= n-2) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 384
import sys
animals, legs = [int(i) for i in input().split()]

cranes = 2
turtle = 4

for i in range(0, animals + 1):
    for j in range(0, animals + 1):
        number = (2*i) + (4*j)
        if i + j == animals and number == legs:
            print("Yes")
            sys.exit()

print("No")

Measured memory_bytes: 9176
#include <iostream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.archery", "r", stdin );

	int n;
	while (1){
		cin >> n;
		if (n == 0 ){
			break;
		} // end if
		int i;
		int res = 0;
		int ya = 0;
		for (i = 0; i < n/4; ++i){
			cin >> ya;
			res += ya;
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
data_i=sorted(data.items(),key=lambda x:x[1])
count=0
set_a=list(set(a))
if k<len(set_a):
    for i in range(len(set_a)-k):
        count+=data_i[i][1]
    print(count)
else:
    print(0)


Measured memory_bytes: 52788
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  double ans = 1.0;
  double bunbo = 0.0;
  REP(i,n) bunbo += 1.0/a[i];
  cout << fixed << setprecision(10);
  cout << 1.0 / bunbo << endl;
}



Measured memory_bytes: 256
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    S = input()
    T = input()

    min_len = len(T)
    for i, s in enumerate(S[:len(S)-len(T)+1]):
        sub = S[i:i+len(T)]
        # print(sub)
        count = 0
        for j, t in enumerate(T):
            if sub == T:
                break
            if sub[j] == t:
                continue
            sub = sub[:j] + t + sub[j+1:]
            count += 1

        min_len = min(min_len, count)

    return min_len


def main():
    print(solve())


if __name__ == "__main__":
    main()


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

using pii = pair<int,int>;

int main() {
	int n;
  cin >> n;
  map<pii,int> freq;
  pii points[n];
  for (int i = 0; i < n; i++)
    cin >> points[i].first >> points[i].second;
  	for (int i = 0; i < n; i++) {
    	for (int j = 0; j < n; j++) {
        	int p = points[i].first - points[j].first; 
        	int q = points[i].second - points[j].second;
          	if (p || q)
            	freq[pii(p,q)]++;
        }
    }
  	int ans = n;
  for (pair<pii,int> pp : freq)
    ans = min(ans,n-pp.second);
  	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

ll gcd(ll a, ll b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    while(b){
        ll tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

long long pow(long long n, long long x, long long MOD=(long long)(1e9)+7){
    long long res = 1LL;
    while(x){
        if(x%2==1) res = (res*n) % MOD;
        x = x>>1;
        n= (n*n) % MOD;
    }
    return res%MOD;
}

vector<pair<long long, long long>> factoring(long long N) {
    long long n = N;
    vector<pair<long long, long long>> res;
    for(int i=2; i*i<=N; i++) {
        if(n%i!=0) continue;
        pair<long long, long long> p = make_pair(i, 0);
        while(n%i==0){
            p.second++;
            n /= i;
        }
        res.push_back(p);
    }
    if(n>1) res.push_back(P(n, 1));
    return res;
}
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N);
    REP(i, N) cin>>A[i];
    vector<vector<P>> C(N);
    REP(i, N) C[i] = factoring(A[i]);
    ll d = A[0];
    ll mul = 1;
    vector<ll> m(1e6+500);
    REP(i, N) {
        for(const auto &p: C[i]){
            if(m[p.first] < p.second) m[p.first] = p.second;
        }
        //if(mul%A[i] != 0){
            //d = gcd(mul, A[i]);
            //mul *= A[i]/d;
        //}
    }
    REP(i, 1e6+500){
        if(m[i]==0) continue;
        mul = (mul * pow(i, m[i]))%MOD;
    }
    ll res = 0;
    REP(i, N){
        res = (res + mul * pow(A[i], MOD-2))%MOD;
    }
    cout << res%MOD << endl;
    return 0;
}

Measured memory_bytes: 9856
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> p(n);
    vector<int> val2index(n);
    for(int i=0; i<n; i++){
        cin>>p[i];
        p[i]--;
        val2index[p[i]] = i;
    }

    /*
    int sum = 0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            vector<int> v;
            for(int k=i; k<=j; k++){
                v.emplace_back(p[k]+1);
            }
            sort(v.begin(), v.end(), greater<int>());
            sum += v[1];
        }
    }
    cout << sum << endl;
    */
    
    set<int> st;
    st.insert(-1);
    st.insert(n);
    st.insert(val2index[n-1]);
 
    ll ans = 0;
    for(int i=n-2; i>=0; i--){
        st.insert(val2index[i]);
 
        auto mid = st.find(val2index[i]);
        auto ub = mid; ub++;

        if(*ub != n){
            auto lb = mid; lb--;
            auto uub = ub; uub++;
            ans += (ll)(*uub - *ub) * (*mid - *lb) * (i + 1);
        }

        auto lb = mid; lb--;
        if(*lb != -1){
            auto ub = mid; ub++;
            auto llb = lb; llb--;
            ans += (ll)(*lb - *llb) * (*ub - *mid) * (i + 1);
        }
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    string s;
    list<char> list;
    int q,r=0,t,f;
    char c;
    in(s,q);
    rep(i,s.length()){
        list.push_back(s[i]);
    }
    rep(i,q){
        in(t);
        if(t==1){
            r++;
        }else{
            in(f,c);
            if((r+f)%2==0){
                list.push_back(c);
            }else{
                list.push_front(c);
            }
        }
    }
    if(r%2==1)reverse(all(list));
    for(auto it:list){
        printf("%c",it);
    }
    printf("\n");
}


Measured memory_bytes: 13160
#include <iostream>
using namespace std;
int main(){
  int a,b;
  string s;
  cin >> a >> b;
  cin >>s;
  bool flag=true;
  for(int i=0;i<a+b+1;i++){
    if(i==a && s[i]!='-'){
      flag = false;
    }
    else if(i!=a && s[i]=='-'){
      flag = false;
    }
  }
  cout << ((flag)?"Yes":"No");
  return 0;
}

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

    rep(i, 9) {
        int p = pow(10,i);
        f += (N / p) % 10 ;
    }

    if(N % f) //ハーシャッド数でないとき
    cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 4056
/// >>In The Name Of God
/// >>ALIREZANA

#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define smin(x,y) (x) = min(x,y)
#define smax(x,y) (x) = max(x,y)
#define all(x) (x).begin(),(x).end()
#define _ ios_base::sync_with_stdio(0)\
                ,cin.tie(0),cout.tie(0);

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

const int M = 12;
vi adj[M];
int p[M], t[M], l[M], ans;

int main()
{_
    int n, m;   cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int x, y;  cin >> x;
        while(x--)
            cin >> y, adj[y-1].pb(i);
    }
    for(int i = 0; i < m; i++)
        cin >> p[i];

    for(int mask = 0; mask < (1<<n); mask++)
    {
        memset(t, 0, sizeof t);
        memset(l, 0, sizeof l);
        for(int i = 0; i < n; i++)
            if(mask & (1<<i))   t[i] = 1;

        for(int i = 0; i < n; i++) if(t[i])
        {
            for(auto x : adj[i])
                l[x] = 1-l[x];
        }
        bool q = 1;
        for(int i = 0; i < m; i++)
            if(l[i] != p[i])
                q = 0;
        if(q)
            ans ++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  double a,b;
  scanf("%lf",&a);
  scanf("%lf",&b);
  if(a>b){
    printf("GREATER\n");
  }else if(a<b){
    printf("LESS\n");
  }else if(a==b){
    printf("EQUAL\n");
  }
  return 0;
}


Measured memory_bytes: 128
/*
	AOJ 0510 JOI yo 2005 2006 1 Score
*/

//ミスを防ぐためにまずは基本のIncludeをすべて格納する

#include<fstream>
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#define INF (1<<21)
using namespace std;
typedef pair<int,int> P;

//ここまで基本型、多少の変更はあるけどまあいける

int main()
{
	int a[4],b[4];
	int asum,bsum;


	cin >>a[0]>>a[1]>>a[2]>>a[3];
	cin >>b[0]>>b[1]>>b[2]>>b[3];

	asum=a[0]+a[1]+a[2]+a[3];
	bsum=b[0]+b[1]+b[2]+b[3];

	int high;

	high=asum;
	if (bsum>asum) {high = bsum;}
	
	cout<<high<<endl;

	return 0;
}

Measured memory_bytes: 1160
s = input()
alph_list = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
res = [0] * 26
for i in range(len(s)):
    for j in range(26):
        if s[i] == alph_list[j]:
            res[j] = 1
for i in range(26):
    if res[i] == 0:
        print(alph_list[i])
        break
    elif i == 25:
        print("None")

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

int main() {
  int N;
  cin >> N;
  
  if (N == 1) cout << "Hello World" << endl;
  if (N == 2) {
    int A, B;
    cin >> A >> B;
    cout << A+B << endl;
  }
  
}

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

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

  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for(int i = 0; i < N; ++i) cin >> H.at(i);

  sort(H.rbegin(), H.rend());

  for(int i = 0; i < min(K, N); ++i) {
    H.at(i) = 0;
  }

  long long sum = 0;
  for(int i = 0; i < H.size(); ++i) {
    sum += H.at(i);
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
n = int(input())
h = list(map(int,input().split()))

for i in range(n-1):
    if h[n-1-i] < h[n-1-i-1]:
        h[n-1-i-1] -= 1
for i in range(1,n):
    if h[i] < h[i-1]:
        print('No')
        exit()

print('Yes')
        

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

int a[100005], cnt[100005];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        cnt[a[i]]++;
    }
    bool ok = 1;
    if(n%2 == 0){
        for(int i=n-1;i>=1;i-=2){
            if(cnt[i] != 2) ok = 0;
        }
    }
    else{
        for(int i=n-1;i>=1;i-=2){
            if(cnt[i] != 2) ok = 0;
        }
        if(cnt[0] != 1) ok = 0;
    }
    if(!ok){
        printf("0\n");
        return 0;
    }
    ll ans = 1;
    for(int i=n-1;i>=1;i-=2){
        ans *= 2;
        ans %= mod;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 4556
#include<bits/stdc++.h>
using namespace std;
long long vis[200005],dis[200005];
vector<long long>adj[200005];
void bfs(long long node)
{
    queue<long long>q;
    q.push(node);
    vis[node]=1;
    dis[node]=0;
    while(!q.empty())
    {
        long long c=q.front();
        q.pop();
        for(auto j:adj[c])
        {
            if(!vis[j])
            {
                q.push(j);
                dis[j]=dis[c]+1;
                vis[j]=1;
            }
        }
    }
}
int main()
{
    long long T,i,j,n,m,a,b;

        cin>>n>>m;
        for(j=0;j<m;j++)
        {
            cin>>a>>b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        bfs(1);
        if(dis[n]==2)
            cout<<"POSSIBLE"<<endl;
        else
            cout<<"IMPOSSIBLE"<<endl;

}


Measured memory_bytes: 19720
#include<iostream>
#include<iomanip>

using namespace std;

#define rep(i, a, n) for (int i = (a); i < (n); i++)

void Main(){
  string a,b,c;
  cin>>a>>b>>c;
  a[a.size()-1]==b[0] && b[b.size()-1]==c[0] ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int N;
int A[105];
long double sum = 0.0;

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = 1; i <= N; i++) {
		sum += 1.0L / double(A[i]);
	}

	long double ans = 1.0L / sum;

	cout <<setprecision(12)<<fixed<< ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
constexpr int DIGIT = 55;
ll N, K;
string s;
vector<vector<ll>> bitcount(DIGIT, vector<ll>(2, 0)), dp(DIGIT + 1, vector<ll>(2, -1));

ll rec(ll e, bool tight, ll sum) {
	if (e == s.size())return sum;
	if (dp[e][tight] != -1)return dp[e][tight];
	sum <<= 1;

	bool bit = s[e] == '1';
	ll res = 0;
	if (tight) {
		if (s[e] == '1') {
			res = max(res, rec(e + 1, true, sum + bitcount[e][0]));
		}
		res = max(res, rec(e + 1, !bit, sum + bitcount[e][1]));
	}
	else {
		res = rec(e + 1, false, sum + max(bitcount[e][0], bitcount[e][1]));
	}
	return dp[e][tight] = res;
}

ll solve_dp() {
	dp[0][0] = 0;
	rep(e, DIGIT) {
		if (dp[e][1] != -1)
			dp[e + 1][1] = max(dp[e + 1][1], dp[e][1] * 2 + max(bitcount[e][0], bitcount[e][1]));
		if (dp[e][0] != -1 && s[e] == '1')
			dp[e + 1][1] = max(dp[e + 1][1], dp[e][0] * 2 + bitcount[e][1]);
		if (dp[e][0] != -1)
			dp[e + 1][0] = max(dp[e + 1][0], dp[e][0] * 2 + bitcount[e][s[e] == '0']);
	}
	return max(dp[DIGIT][0], dp[DIGIT][1]);
}

string binary(ll K) {
	string s = "";
	rep(i, DIGIT) {
		s += (K & 1 ? "1" : "0");
		K >>= 1;
	}
	reverse(s.begin(), s.end());
	return s;
}

int main()
{
	cin >> N >> K;
	s = binary(K);
	vector<ll> A(N);
	rep(i, N)cin >> A[i];

	for (auto a : A)rep(i, DIGIT) {
		bitcount[i][a & 1ll]++;
		a >>= 1ll;
	}
	reverse(bitcount.begin(), bitcount.end());

	cout << solve_dp() << endl;
	//rec(0, true, 0);
	//cout << max(dp.back()[0], dp.back()[1]) << endl;
	return 0;
}


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


int main(){
    int A, B, M,minSUM = 1001000, mina =1001000, minb = 1001000;
    cin >> A >> B >> M;
    int a[A+1],b[B+1],x[M+1],y[M+1],c[M+1];
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    rep(i,M) cin >> x[i] >> y[i] >> c[i];
    rep(i,M){
        if(minSUM > a[x[i]-1] + b[y[i]-1] - c[i]){
            minSUM = a[x[i]-1] + b[y[i]-1] - c[i];
        }
    }
    rep(i,A){
        if(mina > a[i]){
            mina = a[i];
        }
    }
    rep(i,B){
        if(minb > b[i]){
            minb = b[i];
        }
    }
    cout << min(minSUM,mina+minb) << endl;
    return 0;
}


    

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


int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ll n, a, b;
	cin >> n >> a >> b;
	if(n == 1 and a == b) cout << 1;
	else if(n == 1) cout << 0;
	else if(a > b) cout << 0;
	else cout << (n-2)*(b-a)+1;



}

Measured memory_bytes: 3632
MOD = 10**9 + 7
l = input()
dp = [1, 0] # bounded, unbounded
ndp = [0, 0]

for c in l:
    ndp1 = dp[1] * 3
    if c == '1':
        ndp0 = dp[0] * 2
        ndp1 += dp[0]
    else:
        ndp0 = dp[0]
    dp = ndp0 % MOD, ndp1 % MOD
print(sum(dp) % MOD)


Measured memory_bytes: 41068
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, ans = 0;
int main() {
	cin >> n;
	vector<ll> a(n), b(n);
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	REP(i, 30) {
		ll now = 0, nv = 1ll << i, mod = 1ll << (i + 1);
		vector<ll> bb = b;
		REP(j, n)bb[j] %= mod;
		sort(ALL(bb));
		bb.push_back(INF);
		REP(j, n) {
			auto a1 = lower_bound(ALL(bb), nv - (a[j] % mod));
			auto a2 = lower_bound(ALL(bb), nv * 2 - (a[j] % mod));
			auto a3 = lower_bound(ALL(bb), nv * 3 - (a[j] % mod));
			auto a4 = lower_bound(ALL(bb), nv * 4 - (a[j] % mod));
			now += (a2 - bb.begin()) - (a1 - bb.begin());
			now += (a4 - bb.begin()) - (a3 - bb.begin());
		}
		if (now % 2 == 1)ans += nv;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8144
import sys

# N: コマ数
# M: 地点数

N,M,*X = map(int, open(0).read().split())

# コマ数が地点数以上の場合、各地点にコマを配置できる
# よって 0 回の移動で目的を達成できる
if N >= M:
    print(0)
    sys.exit()

X.sort()
ans = []
for i in range(M-1):
    ans.append(abs(X[i+1] - X[i]))

print(X[-1] - X[0] - sum(sorted(ans)[::-1][:N-1]))

Measured memory_bytes: 20096
#include <iostream>

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

    std::string s;
    std::cin >> s;

    std::cout << s;
    s[s.size() - 1] == 's' ?   std::cout <<  "es" : std::cout <<  's';
    std::cout << '\n';
}

Measured memory_bytes: 3664
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a[3];
	scanf("%d%d", &a[0], &a[1]);
	printf("%s\n", (a[0] % 3 == 0 || a[1] % 3 == 0 || (a[1] + a[0]) % 3 == 0) ? "Possible" : "Impossible");
	
	Please AC;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 2000010

void countingSort(int, int);
static int a[N], b[N], c[N];

int main()
{
  int n;
  int i, j, k;

  scanf("%d", &n);
  j=0;
  for(i=1; i<=n; i++)
    {
      scanf("%d", &a[i]);
      if(j<a[i])j=a[i];
    }

  //sort
  countingSort(j, n);

  //print
  for(i=1; i<n; i++)printf("%d ", b[i]);
  printf("%d\n", b[n]);
  return 0;
}

//sort
void countingSort(int max, int n)
{
  int i, j, k;

  for(i=0; i<=max; i++)c[i]=0;
  for(i=1; i<=n; i++)c[a[i]]++;

  for(i=1; i<=max; i++)
    {
      if(i!=0)c[i]+=c[i-1];
    }

  for(i=n; i>=1; i--)
    {
      b[c[a[i]]]=a[i];
      c[a[i]]--;
    }
}

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

int func(int a, int  b){
  if(b == 0) return a;
  return func(b,a%b);
}

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

Measured memory_bytes: 256
#H×Wのマス目入力の周りに"."を付け加える関数
def pixel_input(H,W,border="."):
    pixel = [[border]*(W+2)] + \
    [[border] + list(input()) + [border] for _ in range(H)] + \
    [[border]*(W+2)]
    return pixel

#マス目型2次元配列を出力する関数
def pixel_print(pixel):
    for i in range(len(pixel)):
        print("".join(pixel[i]))

#数値の標準入力関数（1次元配列の場合は引数なし、2次元配列の場合は引数に行の数）
#switchを1にすると2次元配列のときに各行を配列として読み込まない
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]
          
#問題を解く
H,W=ipt()
pixel_print(pixel_input(H,W,"#"))

Measured memory_bytes: 3064