akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <stack>
#include <cctype>
#include <map>
using namespace std;
bool PathernMatch(char *sWildcard, char *sString)
{
	char *s = NULL;
	char *p = NULL;
	bool bStarChar = false;
	bool bBreak = false;
	do{
		bBreak = false;
		for (s = sString, p = sWildcard; *s; ++s, ++p){
			switch (*p){
			case '?':
				break;
			case '*':
				bStarChar = true;
				sString = s;
				sWildcard = p;
				if (!*++sWildcard)
					return true;
				bBreak = true;
				break;
			default:
				if (*s != *p){
					if (!bStarChar)
						return false;
					sString++;
					bBreak = true;
				}
				break;
			}
			if (bBreak)
				break;
		}
		if (bBreak == false){
			if (*p == '*')
				++p;
			return (!*p);
		}
	} while (true);
}
bool IsMatch(string sString1, string sString2, bool lpUseWildcard = false){
	if (!lpUseWildcard)
		return sString1 == sString2;
	else{
		return PathernMatch(const_cast<char*>(sString1.c_str()), const_cast<char*>(sString2.c_str()));
	}
}
int main(){
	ios::sync_with_stdio(false);
	string sTest;
	string sMatch("*AC*");
	getline(cin, sTest);
	if (IsMatch(sMatch, sTest, true))
		cout << "Yes\n";
	else
		cout << "No\n";
endapp:
	//system("pause > nul");
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N), B(N);
  vector< pair<long long,int> > V;
  for(int i = 0; i < N; ++i){
    cin >> A[i] >> B[i];
    V.emplace_back(A[i]+B[i],i);
  }
  sort(V.rbegin(), V.rend());
  long long ans = 0;
  for(int i = 0; i < N; ++i){
    if(i%2) ans -= B[V[i].second];
    else ans += A[V[i].second];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;


int main() {
    ll n;
    cin >> n;
    vector<ll> d1(n,0);
    vector<ll> d2(n,0);


    for(ll i = 0;i < n;++i){
        cin >> d1[i] >> d2[i];
    }
    for(ll i = 0;i < n - 2;++i){
        if(d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}





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

int main() {
    int n;
    string s;
    cin>>n>>s;
    int mx=0;
    for (int i=1;i<n;i++) {
        string t,u;
        t=s.substr(0,i);
        u=s.substr(i);
        set<char> a,b;
        for (char c:t)
            a.insert(c);
        for (char c:u)
            b.insert(c);
        int cnt=0;
        for (char c:a)
            if (b.count(c))
                cnt++;
        mx=max(mx,cnt);
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;

void main()
{
	auto s = readln.chomp;
	enum dist = "abcdefghijklmnopqrstuvwxyz";
	if (s.equal(dist.retro)) {
		writeln = -1;
		return;
	}
	bool[char] done;
	foreach (c; s) {
		done[c] = true;
	}
	string[] arr;
	auto t = s;
	foreach (c; dist) {
		if (c in done) {
			continue;
		}
		t ~= c;
		break;
	}
	if (s != t)
		arr ~= t;
	foreach (i; 0..s.length) {
		bool[char] done2;
		foreach (c; s[0..i]) {
			done2[c] = true;
		}
		char c = s[i];
		char e = '.';
		foreach (d; dist) {
			if (d <= c) {
				continue;
			}
			if (d in done2) {
				continue;
			}
			e = d;
			break;
		}
		if (e == '.') {
			continue;
		}
		auto u = s[0..i].dup;
		u ~= e;
		arr ~= u.idup;
	}
	// arr.writeln;
	std.algorithm.sort = arr;
	arr.front.writeln;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

E = 0

for i in range(0,N):#0-Nまで
	for j in range(i,i+2):#i+1-iまで

		if B[i] - A[j] > 0:
			E += A[j]
			B[i] = B[i] - A[j]
			A[j] = 0
		if B[i] - A[j] <= 0:
			E += B[i]
			A[j] = A[j] - B[i]
			B[i] = 0
			break
	
print(E)

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

#define fast ios::sync_with_stdio(0); cin.tie(NULL); 
#define fi first
#define se second
#define mp make_pair
#define pi 3.14159265359
#define MOD 1000000007
#define inf 1e18
#define setbits(x) __builtin_popcountll(x)
typedef long long ll;
#define mp make_pair
#define ALL(v) v.begin(), v.end() 
#define F(i,s,n) for(i=s;i<n;++i)
#define pb push_back
#define eb emplace_back
#define tin freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pll pair<ll,ll>
ll max(ll a,ll b)
{
    return a*(a>=b)+b*(b>a);
}
string smax(string a,string b)
{
    if(a.size()>b.size())return a;
    return b;
}
/*----------------------------------------------------------*/
string a,b;

void solve()
{
    cin>>a>>b;
    ll n=a.size(),m=b.size();
    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<n+1;++i)
    {
        for(ll j=1;j<m+1;++j)
        {
            if(a[i-1]==b[j-1])dp[i][j]=1+dp[i-1][j-1];
            dp[i][j]=max(dp[i][j],dp[i][j-1]);
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            //cout<<dp[i][j]<<" ";
        }//cout<<endl;
    }
    ll i=n,j=m;
    string s=" ";
    while(i!=0&&j!=0)
    {
        if(dp[i][j]==1+dp[i-1][j-1]&&a[i-1]==b[j-1])
        {
           // cout<<a[i-1]<<endl;
            --i;--j;s=a[i]+s;
            //<<" "<<s<<endl;
        }
        else if(dp[i][j]==dp[i-1][j])--i;
        else --j;
    }cout<<s;
}

int main()
{
    //tin
    fast
    ll tc=1;//cin>>tc;
   for(ll i=1;i<=tc;++i)
   {
    //cout<<"Case #"<<i<<": ";
    solve();
    if(i!=tc)cout<<"\n";
   }
return 0;
}
//End-Cases 
//Precomputation
//Segmentation Fault
//Complexity
//Break it up
//Sub Problems


Measured memory_bytes: 74064
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<int>v(n);
    for(auto & e:  v) cin >> e;
    sort(all(v));
    int m = v.back();
    int sum  =0;
    rep(i,n-1)sum += v[i];
    cout << (sum > m ? "Yes":"No") << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pa pair<int,int>
#define F first
#define S second
#define Max 9999
#define d n%3
typedef long long ll;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b<c?a*b:c)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cassert>
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }

vector<LL> num[127];
void rec(int cur = 0, int I = 0, int sum = 0, LL prod = 1) {
    if (cur == 14) {
	num[sum].push_back(prod);
    } else {
	for (int i=I; i<=9; i++) rec(cur+1, i, sum + i, prod * (i+1));
    }
}

char S[33];
LL dp[15][127][3786][3];

int main() {
    rec();
    int sz = 0;
    REP (i, 127) {
	vector<LL> &a = num[i];
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
//	amax<int>(sz, a.size());
//	if (a.size()) eprintf("%d %lld %lu\n", i, a[0], a.size());
//	else eprintf("%d -1\n", i);
    }

    scanf("%s", S);
    int n = strlen(S);
    dp[0][0][0][0] = 1;

    REP (i, n) REP (sum, 9*(i+1)+1) REP (prod, num[sum].size()) REP (b, 3) if (dp[i][sum][prod][b]) {
	REP (c, 10) {
	    int nsum = sum + c;
	    int nprod = lower_bound(num[nsum].begin(), num[nsum].end(), num[sum][prod] * (c+1)) - num[nsum].begin();
	    assert(num[nsum][nprod] == num[sum][prod] * (c+1));
	    int nb = b;
	    if (b == 0 && c < S[i] - '0') nb = 1;
	    if (b == 0 && c > S[i] - '0') nb = 2;
	    dp[i+1][nsum][nprod][nb] += dp[i][sum][prod][b];
//	    eprintf("%d %d %lld %d : %lld\n", i+1, nsum, num[nsum][nprod], nb, dp[i+1][nsum][nprod][nb]);
	}
    }

    LL ans = 0;
    int sum = 0;
    LL P = 1;
    REP (i, n) {
	int c = S[i] - '0';
	sum += c;
	P *= c + 1;
    }


    REP (s, 127) REP (p, num[s].size()) REP (b, 3) {
	if (s < sum ||
		(s == sum && num[s][p] < P) ||
		(s == sum && num[s][p] == P && b == 1))
	    ans += dp[n][s][p][b];
    }

    printf("%lld\n", ans);



    return 0;
}

Measured memory_bytes: 121232
import java.util.BitSet;
import java.util.Scanner;

class Solver {
    void solve(Scanner sc) {
        String S = sc.next();
        BitSet n = new BitSet(S.length());
        BitSet u = new BitSet(S.length());
        u.set(0);
        for (int i = 1; i < S.length(); i++) {
            boolean eq = S.charAt(i - 1) != S.charAt(i);
            n.set(i, n.get(i - 1) == eq);
            u.set(i, u.get(i - 1) == eq);
        }

        System.out.println(Math.min(n.cardinality(), u.cardinality()));
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

Measured memory_bytes: 24976
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< long long > v(n);
    for( auto &i : v ) cin >> i;
    long long ans = 0;
    for( int i =0; i < n; ++ i )
        for( int j = i + 1; j < n; ++ j )
            ans += v[i] * v[j];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll GCD(ll a, ll b)
{
    return b ? GCD(b, a%b) : a;
}


int main()
{
    ll n, x; cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    rep(i, n)
    {
        ans = GCD(ans, abs(x - a[i]));
    }

    cout << ans << endl;
}

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

int main(){

  string str;
  int joi,ioi,j;
  while(cin >> str){

    joi = ioi = j = 0;

    for(int i=1;i<str.size()-1;i++){
      if( str.substr(j,i-j+2) == "JOI" ) joi++;
      else if( str.substr(j,i-j+2) == "IOI" ) ioi++;
      j = i;
    }

    cout << joi << endl << ioi << endl;

  }
}

Measured memory_bytes: 1216
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a > b) {
                int t = a;
                a = b;
                b = t;
            }
            if (a <= c && c <= b)
                out.println("Yes");
            else
                out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		int XSum = 0;
		for(int i = 0; i < Integer.toString(X).length(); i++) {
			XSum += Integer.parseInt(Integer.toString(X).substring(i, i + 1));
		}
		System.out.println(X % XSum == 0 ? "Yes" : "No");
		scan.close();

	}

}


Measured memory_bytes: 22996
//  A bug is never just a mistake. It represents something bigger. An error of thinking that makes you who you are.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 500009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


int main(){
		
	ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    string left = "";
    string right = "";
    bool rev = 0;
    int q;
    cin>>q;
    rep(i,0,q){
    	int t;
    	cin>>t;
    	if(t==1){
    		rev ^= 1;
    	}
    	else{
    		int f;
    		char c;
    		cin>>f>>c;
    			if(f==1){
    				if(!rev){
    					left = c + left;
    				}
    				else{
    					right = right + c;
    				}

    			}
    			else{
    				if(!rev){
    					right = right + c;
    				}
    				else{
    					left = c + left;
    				}
    			}


    	}
	}
	if(rev){
		reverse(left.begin(),left.end());
		reverse(right.begin(),right.end());
		reverse(s.begin(),s.end());
		cout<<right<<s<<left<<"\n";
	}
	else{
		cout<<left<<s<<right<<"\n";
	}

}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;
int main(void)
{
    int N;
    LL M;
    cin>>N>>M;
    LL ans = 0;
    for(LL i = 1;i *i <= M; ++i){
    	if(M %i != 0) continue;
        if(M / i >= N) ans = max(ans,i);
        if(i >= N) {
        	ans = max(ans,M/i);
        }
    }
    cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func gcd(A int, B int) int {

	if B == 0 {
		return A
	}
	return gcd(B, A%B)
}

func lcm(A int, B int) int {

	return A * B / gcd(A, B)
}
func main() {
	// Code for A - Multiple of 2 and N
	var N int
	fmt.Scanf("%d", &N)

	fmt.Println(lcm(2, N))
}


Measured memory_bytes: 1832
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    print(6-A-B)
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
i,j,n,x,y,a,b,map[30][30];main(){char c,t;for(;scanf("%d",&n),n;puts(n?"No":"Yes")){for(i=0;i<30;i++)for(j=0;j<30;j++)map[i][j]=0;for(j=n;j--;map[x][y]=1)scanf("%d%d",&x,&y);scanf("%d",&j);getchar();for(a=b=10;j--;){i=c=0;while((t=getchar())!='\n')if(t>='0' &&t<='9')i=i*10+t-'0';else if(t>'A' && t<'Z')c=t;for(;i--;){c-'N'||b++;c-'E'||a++;c-'S'||b--;c-'W'||a--;if(map[a][b]==1)map[a][b]=0,n--;}}}exit(0);}

Measured memory_bytes: 0
# coding: utf-8
def main():
    inputs_list = input().split()
    N = int(inputs_list[0])
    K = int(inputs_list[1])
    S = int(inputs_list[2])

    ans = []
    for i in range(K):
        ans.append(S)
    for j in range(N - K):
        if S < 10 ** 9:
            ans.append(S + 1)
        elif S == 10 ** 9:
            ans.append(1)

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 15000
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vector<int> last(26, -1);
    int satisfy = 0;
    vector<int> ans;
    rep(i, 365) {
        int an=1;
        rep(j, 26) {
            int sa = satisfy;
            vector<int> la = last;
            sa += s[i][j];
            la[j] = i;
            int decrease = 0;
            rep(k, 26) decrease += c[k] * (i - last[k]);
            sa -= decrease;
            if (chmax(satisfy, sa))
                an = j;
        }
        ans.push_back(an);
    }
	rep(i,365)
        cout << ans[i]+1 << endl;
}

Measured memory_bytes: 3684
n,m=map(int,input().split())
#r=[[] for i in range(n+1)]
r=[set() for i in range(n+1)]
for i in range(m):
    ai,bi=map(int,input().split())
    if not bi in r[ai]:
#        r[ai].append(bi)
#        r[bi].append(ai)
        r[ai].add(bi)
        r[bi].add(ai)
yn=""
for i in range(2,n):
    if (i in r[1]) and (i in r[n]):
        print("POSSIBLE")
        yn="POSSIBLE"
        break
if yn=="":
    print("IMPOSSIBLE")

Measured memory_bytes: 67740
#include <iostream>
#include <map>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
	if (a < 0) a = -a;
	if (b < 0) b = -b;
	while (a != 0) {
		long long tmp = b % a;
		b = a;
		a = tmp;
	}
	return b;
}

long long pow_mod(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = (res * a) % MOD;
		n >>= 1;
		a = (a * a) % MOD;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	int zero = 0;
	map<pair<ll,ll>, P> mp;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			zero++;
			continue;
		}
		ll gcd_ab = gcd(a, b);
		a /= gcd_ab; b /= gcd_ab;
		if (b < 0) a = -a, b = -b;
		else if (b == 0 && a < 0) a = -a;
		if (a <= 0) mp[{b, -a}].first++;
		else mp[{a, b}].second++;
	}
	ll ans = 1;
	for (auto e : mp) {
		ll x = e.second.first, y = e.second.second;
		ans *= (pow_mod(2,x) + pow_mod(2,y) - 1 + MOD)%MOD;
		ans %= MOD;
	}
	ans = (ans - 1 + MOD) % MOD;
	ans = (ans + zero) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15936
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC111A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            Console.WriteLine(new string(input.Select(x => x == '1' ? '9' : x == '9' ? '1' : x).ToArray()));
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) {
        cout << "error" << endl;
    }
    else {
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

#define CNST_DAY 365
#define NUM_CONTEST 26

int main(void){

    int i,j,k,d,n;
    int D,c[NUM_CONTEST+1]={},s[CNST_DAY+1][NUM_CONTEST+1]={},last[NUM_CONTEST+1]={},t[CNST_DAY+1]={};
    long v[CNST_DAY+1]={};

    int smax[CNST_DAY+1]={},maxcon[CNST_DAY+1]={};

    //入力
    scanf("%d",&D);
    for(d=1;d<=NUM_CONTEST;d++){
        scanf("%d",&c[d]);
    }
    for(d=1;d<=D;d++){
        for(i=1;i<=NUM_CONTEST;i++){
            scanf("%d",&s[d][i]);
        }
    }
    
    //スコア計算
    for(d=1;d<=D;d++){
        smax[d]=s[d][1];
        maxcon[d]=1;
        for(i=2;i<=NUM_CONTEST;i++){
            if(s[d][i]>smax[d]){
                smax[d]=s[d][i];
                maxcon[d]=i;
            }
        }
    }
    for(d=1;d<=D;d++){
        //その日一番大きい満足度が得られるコンテストを開く(満足度の低下を無視したもの)
        //t[d]=maxcon[d];
        t[d]=rand()%26+1;

        //開催するコンテストt[d]を決めた後
        last[t[d]]=d;
        v[d]=v[d-1]+s[d][t[d]];
        for(i=1;i<=NUM_CONTEST;i++){
            v[d]-=c[i]*(d-last[i]);
        }
    }

    //出力
    for(d=1;d<=D;d++){
        //printf("%ld\n",v[d]);
        printf("%d\n",t[d]);
    }

    return 0;
}

Measured memory_bytes: 1776
#include<iostream>
#include<vector>

int n, m, q;
int ans;
std::vector<int> a, b, c, d;

void dfs(std::vector<int> A, int cnt){
    if(cnt == n){
        int tmp = 0;
        for(int i = 0; i < q; i++){
            if(A[b[i]] - A[a[i]] == c[i]){
                tmp += d[i];
            }
        }
        ans = std::max(ans, tmp);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A, cnt+1);
        A.back()++;
    }
}

int main(void){
    std::cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for(int i = 0; i < q; i++){
        std::cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    std::vector<int> A = {1};
    dfs(A, 0);
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3636
import Control.Monad
import Control.Applicative
import Data.List

solve :: ([Int],[Int]) -> Int -> Int
solve (al,bl) h =
  solve' maxal bl' h 
  where
    maxal = maximum al
    bl' = (filter (>maxal) . sortBy (flip compare)) bl

solve' a b h 
  | h <= 0 = 0
  | null b = div h a + if (mod h a) == 0 then 0 else 1
  | otherwise =
    1 + solve' a (tail b) (h - head b)

main ::IO()
main = do
  [n,h] <- map read . words <$> getLine :: IO [Int]
  l <- replicateM n $ (\(x:y:[]) -> (read x, read y)) . words <$> getLine ::IO [(Int,Int)]
  print $ solve (unzip l) h


Measured memory_bytes: 153980
package main
 
import (
	"fmt"
)
 
func main() {
	var n, x, t int
	fmt.Scanf("%d %d %d", &n, &x, &t)

	ans := n / x
    if n % x != 0{
      ans++
    }
	ans *= t
	fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1836
n=int(input())
s=input()
a = [str(c) for c in s]
ans=0
r=0
g=0
b=0
er=0
for i in range(n):
    if a[i]=='R':
        r+=1
        ans=ans+g*b
    elif a[i]=='G':
        g+=1
        ans=ans+r*b
    else:
        b+=1
        ans=ans+g*r
for i in range(n-1):
    for j in range(i+1,n):
        k=j+(j-i)
        if k<n:
            if a[i]!=a[j] and a[j]!=a[k] and a[k]!=a[i]:
                er+=1
print(ans-er)

Measured memory_bytes: 9256
#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>;

#define INF 1001001001

struct Edge {
  int from;
  int to;
  int cost;
};

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<Edge> G;
  rep(i,m) {
    int s, t, d;
    cin >> s >> t >> d;
    G.push_back(Edge({s,t,d}));
  }

  vector<int> d(n,INF);
  d[r] = 0;
  int vcnt = 0;
  while (true) {
    bool update = false;
    rep(i,m) {
      Edge e = G[i];
      if (d[e.from] == INF || d[e.to] <= d[e.from] + e.cost) continue;
      d[e.to] = d[e.from] + e.cost;
      update = true;
    }
    if (!update) break;
    if (++vcnt == n) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  rep(i,n) {
    if (d[i]==INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3160
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const ll mod=998244353;
inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}
const int N=3e3+10;
ll dp[N][N];
int a[N],n,s;
void add(ll &x,ll y)
{
    x=(x+y)%mod;
}
int main()
{
    n=read(),s=read();
    rep(i,1,n) a[i]=read();
    dp[0][0]=1;
    rep(i,1,n)
    {
        for(int j=0;j<=s;++j) dp[i][j]=dp[i-1][j]*2%mod;
 
        for(int j=s;j>=a[i];--j){
            add(dp[i][j],dp[i-1][j-a[i]]);
        }
    }
    printf("%lld\n",dp[n][s]);
}

Measured memory_bytes: 74252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;

		if (B%A == 0) {
			ans = A+B;
		} else {
			ans = B-A;
		}

		System.out.println( ans );
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#define abs(x) ((x) < 0 ? -(x) : (x))
using namespace std;

long long x, y;

int main()
{
	scanf("%lld%lld", &x, &y);
	if(abs(x - y) < 2){
		printf("Brown\n");
	}
	else{
		printf("Alice\n");
	}
}

Measured memory_bytes: 128
n=int(input())
p=list(map(int,input().split()))
count=0

newp=sorted(p)
for i in range(len(newp)):
  ans1=p[i]
  ans2=newp[i]
  if ans1!=ans2:
    count+=1
    
if count==2 or newp==p:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b;
	while(cin>>a>>b,a||b){
		vector<int>in(a);
		rep(i,a)cin>>in[i];
		sort(all(in));
		int sum=0;
		int co=0;
		for(int i=a-1;i>=0;i--){
			co++;
			if(co==b){
				co=0;
				continue;
			}
			sum+=in[i];
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1216
#include<cstdio>


int check(char a[],char b[],int n,int m){
  if(n>m) return 1;
  if(n<m) return 2;

  for(int i=0;i<n;i++){
    if(a[i]>b[i]) return 1;
    if(a[i]<b[i]) return 2;
  }
  return 0;
}


int main(void){
  char a[200],b[200],c,d;

  int i=0;
  while((c=getchar())!='\n'){
    a[i]=c;
    i++;
  }

  int j=0;
  while((d=getchar())!='\n'){
    b[j]=d;
    j++;
  }
  int ans = check(a,b,i,j);

  if(ans==0)
    printf("EQUAL\n");
  else if(ans==1)
    printf("GREATER\n");
  else if(ans==2)
    printf("LESS\n");

  return 0;
}



Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

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

    int e;
    while(cin>>e,e){
        int res=INF;
        for(int y=0;y*y<=e;y++){
            for(int z=0;z*z*z<=e;z++){
                int x=e-y*y-z*z*z;
                if(x<0)continue;
                res=min(res,x+y+z);
            }
        }
        cout<<res<<endl;
    }
}

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

int main() {
    int x = 0;
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'I') {
            x++;
        }
        if (S.at(i) == 'D') {
            x--;
        }
        ans = max(ans, x);
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

typedef struct
{
  double x, y;
} Point;

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    Point A, B, C;
    scanf("%lf %lf %lf %lf %lf %lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y);

    double a = sqrt((B.x-C.x)*(B.x-C.x) + (B.y-C.y)*(B.y-C.y));
    double b = sqrt((C.x-A.x)*(C.x-A.x) + (C.y-A.y)*(C.y-A.y));
    double c = sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));

    double angleA = acos((b*b+c*c-a*a) / (2*b*c));
    double angleB = acos((c*c+a*a-b*b) / (2*c*a));
    double angleC = acos((a*a+b*b-c*c) / (2*a*b));

    double sin2A = sin(2 * angleA);
    double sin2B = sin(2 * angleB);
    double sin2C = sin(2 * angleC);

    double x = (A.x*sin2A + B.x*sin2B + C.x*sin2C) / (sin2A+sin2B+sin2C);
    double y = (A.y*sin2A + B.y*sin2B + C.y*sin2C) / (sin2A+sin2B+sin2C);
    double r = (a / (2 * sin(angleA)));

    printf("%.3f %.3f %.3f\n", round(x*1000.0)/1000.0, round(y*1000.0)/1000.0, round(r*1000.0)/1000.0);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

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

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

int N;
vector<int> R;
vector<int> W;
int memo[1010][1010];

int rec(int pos, int rest){
  if (pos == N){
    return rest;
  }

  if (memo[pos][rest] != -1){
    return memo[pos][rest];
  }

  int &res = memo[pos][rest] = rest;

  if (rest - R[pos] >= 0){
    res = min(res, rec(pos + 1, rest - R[pos]));
  }

  if (rest - R[pos] - W[pos] >= 0){
    res = min(res, rec(pos + 1, rest - R[pos] - W[pos]));
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);

  while (cin >> N && N){
    R = vector<int>(N);
    W = vector<int>(N);
    REP(i, N){
      cin >> R[i] >> W[i];
    }

    REP(i, N) REP(j, N - 1){
      if (R[j] < R[j + 1]){
        swap(R[j], R[j + 1]);
        swap(W[j], W[j + 1]);
      }
    }

    if (R[0] * 2 <= accumulate(ALL(R), 0)){
      cout << accumulate(ALL(R), 0) + accumulate(ALL(W), 0) << endl;
    } else {
      memset(memo, -1, sizeof(memo));
      cout << accumulate(ALL(R), 0) + accumulate(ALL(W), 0) + rec(1, R[0]) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x1, x2, x3, x4;
  cin >> n;

  x1 = n/1000;
  x2 = (n%1000)/100;
  x3 = (n%100)/10;
  x4 = n%10;
  
  if ( ( x1 == x2 ) && ( x1 == x3 ) ||
       ( x2 == x3 ) && ( x2 == x4 ) ) {
	cout << "Yes" << endl;
  } else {
	cout << "No" << endl;
  }
}

Measured memory_bytes: 3488
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

N = int(input())
s = input()
ans = 'red' if N < 3200 else s
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)




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

	vector<ll> v(100010, 0);
	rep(i, n) {
		ll a;
		cin >> a;
		v[a]++;
	}

	ll ans = 0;
	rep(i, 100010) {
		ans+= v[i] * i;
	}

	int q;
	cin >> q;

	rep(i, q) {
		int b;
		ll c;
		cin >> b >> c;
		v[c] = v[c] + v[b];

		ans = ans + (c - b) *  v[b];

		v[b] = 0;

		cout <<  ans << endl;

	}






	return 0;
}


Measured memory_bytes: 3552
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int s, int d, Weight w = 1) { g[s].emplace_back(s, d, w); }


//???????§????????????????(???????????????)
//Dijkstra O((E+V)logV)
//dist: ?§????????????????????????§??????????????¢
//?????????: ??????????????¨????????????(??????-1)
vector<int> dijkstra(const Graph &g, int s, Array &dist) {
	int n = g.size();
	assert(s < n);
	enum { WHITE, GRAY, BLACK };
	vector<int> color(n, WHITE); color[s] = GRAY;
	vector<int> prev(n, -1);
	dist.assign(n, INF); dist[s] = 0;
	using State = tuple<Weight, int, int>; //?§????????????????????????¢ ??? ???
	priority_queue<State, vector<State>, greater<State>> pq; pq.emplace(0, s, -1);
	while (pq.size()) {
		Weight d; int v, u; tie(d, v, u) = pq.top(); pq.pop();
		if (dist[v] < d)continue;
		color[v] = BLACK; prev[v] = u;
		for (auto &e : g[v]) {
			if (color[e.d] == BLACK)continue;
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				pq.emplace(dist[e.d], e.d, v);
				color[e.d] = GRAY;
			}
		}
	}
	return prev;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, R, Q; cin >> N >> M >> R >> Q;
	Graph g(N + R);
	rep(i, 0, N) {
		add_arc(g, N + i%R, i, 0);
	}
	rep(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		add_arc(g, b, a, c);
	}
	Matrix d(R, Array(N));
	rep(i, 0, R) {
		dijkstra(g, N + i, d[i]);
	}
	Weight ans = 0;
	rep(i, 0, Q) {
		int x, y, z; cin >> x >> y >> z;
		x--, y--;
		Weight c = 0;
		rep(j, 0, R) {
			chmax(c, z - (d[j][x] + d[j][y]));
		}
		ans += c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 24044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i - 1] != s[i])
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 512
function Main(input) {
	tmp = input.split(" ");
	s = parseInt(tmp[0], 10);
	w = parseInt(tmp[1], 10);
  if (s <= w) {
  	console.log('unsafe')
  } else {
  	console.log('safe')
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29628
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N;
    string S, T, A = "";
    cin >> N >> S >> T;
    for (int i = 0; i < N; i++) {
        A += S.at(i);
        A += T.at(i);
    }
    cout << A << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, k;
    cin >> n >> k;

    int s = (n - 1) * (n - 2) / 2;
    if(s < k){
        cout << -1 << endl;
        return 0;
    }

    int x = s - k;
    int m = n - 1 + x;
    cout << m << endl;
    rep(i, n - 1){
        cout << 1 << " " << i + 2 << endl;
    }

    for(int v = 2; v <= n; v++){
        if(x == 0){
            break;
        }
        for(int u = v + 1; u <= n; u++){
            if(x == 0){
                break;
            }
            cout << v << " " << u << endl;
            x--;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import sys

N = int(input())
S = input()

West = S.count("W")
ans = sys.maxsize
tmp_W = 0

for i in range(0, N):
    tmp_ans = tmp_W

    if(S[i] == "W"):
        tmp_W += 1

    tmp_ans += N - i - 1 - West + tmp_W

    if(tmp_ans < ans):
        ans = tmp_ans

print(ans)

Measured memory_bytes: 3704
import java.util.*;
public class Main{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        //入力
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        int[][] a = new int[n][m];
        int[] b = new int[m];
        
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = Integer.parseInt(sc.next());
            }
        }
        for(int i=0; i<m; i++){
            b[i] = Integer.parseInt(sc.next());
        }
        
        //出力
        for(int i=0; i<n; i++){
            int sum = 0;
            for(int j=0; j<m; j++){
                sum += a[i][j] * b[j];
            }
            System.out.println(sum);
        }
    }
}



Measured memory_bytes: 39060
#include<iostream>
#include<vector>

using namespace std;

int main()
{
    long N,K,Q;
    cin>>N>>K>>Q;
    vector<int>A(Q),test(N,K-Q);
    for(int i=0;i<Q;i++){
        cin>>A[i];
    }
    for(int i=0;i<Q;i++){
        test[A[i]-1]++;
    }
    for(int i=0;i<N;i++){
        if(test[i]>0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }

}

Measured memory_bytes: 1408
import math
n = int(input())
A = []

def partition(A,p,r):

    x = A[r-1][1]
    i = p-1

    for j in range(p,r-1):
        if A[j][1] <= x:
            i += 1
            tmp = A[j]
            A[j] = A[i]
            A[i] = tmp
    tmp = A[i+1]
    A[i+1] = A[r-1]
    A[r-1] = tmp

    return i+1


def QuickSort(A,p,r):
    if p<r:
        q = partition(A,p,r)
        QuickSort(A,p,q)
        QuickSort(A,q+1,r)


def merge(A, left, mid, right):

  L = A[left:mid]
  L.append((1,math.inf))
  R = A[mid:right]
  R.append((1,math.inf))
  i = 0
  j = 0
  for k in range(left,right):

    if L[i][1] <= R[j][1]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1


def mergeSort(A,left,right):
    if left +1 < right:
        mid = (left+right) // 2
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)



for i in range(n):
   color,number =input().split()
   A.append((color,int(number)))

A_merge = A.copy()
A_quick = A.copy()

mergeSort(A_merge,0,n)
QuickSort(A_quick,0,n)


if A_quick==A_merge: print("Stable")
else: print("Not stable")

for x in A_quick:
    print("%s %d" %(x[0],x[1]))


Measured memory_bytes: 18412
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    Set<Integer> set = new HashSet<>();
    for(int i = 0; i < N; i++){
      int M = Integer.parseInt(sc.nextLine());
      set.add(M);
    }
    System.out.println(set.size());
  }
}

Measured memory_bytes: 21972
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        if(n%k == 0){
            System.out.println(0);
        }else{
            System.out.println(1);
        }
    }

}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <boost/function.hpp>
#include <cmath>
using namespace std;
typedef long long int llint;
typedef unsigned long long int ullint;
std::string YesNo[] = {"No","Yes"};
#define loop(i,N) for(int i=0; i<(N); i++)
#define sort_all(v) std::sort(v.begin(),v.end())
#define sum_all(v) std::accumulate(v.begin(),v.end(),0) // For int. For float, 0 -> 0.0
template<typename T>
auto input(int N) {
    std::vector<T> v(N);
    loop(i,N) std::cin >> v[i];
    return std::move(v);
}

typedef llint dtype;

int main(void)
{
    int N;
    cin >> N;
    auto A = input<dtype>(N);
    loop(i,N) A[i] -= i+1;
    sort_all(A);
    dtype ans, lower=0, upper=0;
    if(N % 2) {
        for(auto i=0;i<N/2;i++) lower += A[i];
        for(auto i=N/2+1;i<N;i++) upper += A[i];
        ans = upper - lower;
    } else {
        for(auto i=0;i<N/2;i++) lower += A[i];
        for(auto i=N/2;i<N;i++) upper += A[i];
        ans = upper - lower;
    }

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

Measured memory_bytes: 1792
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    char n; cin>>n; 
    if (n>'Z') cout << "a" << endl;
    else cout << "A" << endl;
}

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


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end

template<unsigned mod=1000000007>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=1000000007>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
using Mint=mint<>;

Mint dp[1010000],sum[1010000];

int main(){
   int n; scanf("%d",&n);
   dp[0]=sum[0]=n; dp[1]=Mint(1LL*n*n); sum[1]=dp[0]+dp[1];
   rep(i,2,n){
      dp[i]=dp[i-1]+Mint(n-1)*Mint(n-1)+sum[i-3]+Mint(n+1-i);
      sum[i]=sum[i-1]+dp[i];
   }
   printf("%d\n",dp[n-1].val);
   return 0;
}

Measured memory_bytes: 8192
N, M = map(int, input().split())
SC = [tuple(map(int, input().split())) for _ in range(M)]
for i in range(10 ** N):
    i, ok = str(i), True
    if len(i) == N:
        for s, c in SC:
            if i[s - 1] != str(c):
                ok = False
        if ok:
            print(i)
            exit()

print(-1)


Measured memory_bytes: 3060