akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> topo_sort(const vector<vector<int> > &G){
	int n = G.size();
	vector<int> ans(n);
	vector<int> num(n);
	for(int i = 0; i < n; i++){
		for(int to : G[i]) num[to]++;
	}
	queue<int> que;
	for(int i = 0; i < n; i++){
		if(num[i] == 0) que.push(i);
	}
	while(que.size()){
		int now = que.front(); que.pop();
		for(auto to : G[now]){
			num[to]--;
			if(num[to] == 0) que.push(to), ans[to] = now + 1;
		}
	}
	return ans;
}

signed main(){
	int N, M; scanf("%d%d", &N, &M);
	int E = N - 1 + M;
	vector<vector<int> > G(N);
	for(int i = 0; i < E; i++){
		int u, v; scanf("%d%d", &u, &v);
		--u; --v;
		G[u].push_back(v);
	}
	vector<int> ans = topo_sort(G);
	for(int i = 0; i < N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 9484
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long[] as = new long[s.length()];
		long[] cs = new long[s.length()];
		long[] hleft = new long[s.length()];
		long[] hright = new long[s.length()];
		long[] pow = new long[s.length()+1];
		long MOD = 1000000007;
		as[0] = 0;
		for(int i=1;i<s.length();++i){
			as[i] += as[i-1];
			hleft[i] += hleft[i-1];
			char a = s.charAt(i-1);
			if(a=='A') as[i]++;
			if(a=='?') hleft[i]++;
		}
		cs[s.length()-1] = 0;
		for(int i=s.length()-2;i>=0;--i){
			cs[i] += cs[i+1];
			hright[i] += hright[i+1];
			char c = s.charAt(i+1);
			if(c=='C') cs[i]++;
			if(c=='?') hright[i]++;
		}
		pow[0] = 1;
		for(int i=1;i<s.length();++i){
			pow[i] = pow[i-1]*3;
			pow[i] %= MOD;
		}

		long ans = 0;
		for(int i=1;i<s.length()-1;++i){
			char b = s.charAt(i);
			if(b=='B'||b=='?'){
				long left = as[i] * pow[(int)hleft[i]];
				if(hleft[i]!=0) left += hleft[i] * pow[(int)hleft[i]-1];
				left %= MOD;
				long right = cs[i] * pow[(int)hright[i]];
				if(hright[i]!=0) right += hright[i] * pow[(int)hright[i]-1];
				right %= MOD;
				ans += left * right;
				ans %= MOD;
			}
		}

		System.out.println(ans);
		return;
	}
}

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

int main() {
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    double x = fabs(x1 - x2);
    double y = fabs(y1 - y2);

    //cout << sqrt(x*x + y*y) << endl;
    double ans = sqrt(x*x + y*y);
    printf("%lf12", ans); 
}


Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;


int main(){
	int N,ans=0; cin >> N;
	int a;
	for(int i=0; i<N; i++){
		cin >> a;
		while(a%2==0){
			ans+=1;
			a/=2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def GCD_calc(A,B):
    if(A>=B):
        big = A
        small = B
    else:
        big = B
        small = A
    r=big%small
    if r == 0:
        return small
    else:
        return GCD_calc(small,r)

a,b = map(int,input().split())
print(GCD_calc(a,b))



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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(M);
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
  }
  int r = N;
  for (int i = 0; i < M; i++) {
    r -= vec.at(i);
  }
  if ( r >= 0) {
    cout << r << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3672
package main

import (
        "fmt"
        "math"
)

func main() {
        var n int
        fmt.Scanf("%d", &n)

        // -- kashikoi --
        floor := float64(n) / 1.08
        //ceil := float64(n+1) / 1.08
        //fmt.Printf("%.2f <---> %.2f\n", floor, ceil)

        if x := math.Ceil(floor); int(x*1.08) == n {
                fmt.Println(x)
        } else {
                fmt.Println(":(")
        }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
   // cin>>TESTS;
    while(TESTS--){
       int n,m;
       cin>>n>>m;
       if(n==m)cout<<"Yes"<<endl;
       else cout<<"No"<<endl;   
    }
}











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

int main() {
  int n;
  cin >> n;
  bool res = false;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == n) {
        res = true;
      }
    }
  }
  if (res) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  
  public static void main(String [] args){
    Scanner inp = new Scanner(System.in);
    int r = inp.nextInt();
    int g = inp.nextInt();
    int b = inp.nextInt();
    if((10 * g + b) % 4 == 0)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}



Measured memory_bytes: 23636
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor
int main(){
    string N;
    cin >> N;
    llong ans = 0;
    for(int i=0; i<N.size(); i++){
        ans = ans + (N[i]-'0');
    }
    if(ans%9==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

//数値から文字列に変換
string num2string(llong num){
    ostringstream oss;
    oss << num;

    return oss.str();
}

Measured memory_bytes: 3500
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  def solve(sc: Scanner): String = {
    val n = sc.nextInt()
    (180 * (n - 2)).toString
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


Measured memory_bytes: 27424
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n =sc.nextLong();
		int f = (int)Math.floor((double)100*sc.nextDouble());
		long temp = n*f;
		temp/=(long)100;
		System.out.println(temp);
	}
}


Measured memory_bytes: 37340
N = input()
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

point = 0

for i in range(N):
  no_food = A[i]
  point += B[no_food - 1]
  if i != 0:
    if no_food - A[i - 1] == 1:
      point += C[no_food - 2]

print point

Measured memory_bytes: 2568
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll r=0;
  ll g=0;
  ll b=0;
  
  rep(i,n){
    if(s[i]=='R')r++;
    if(s[i]=='G')g++;
    if(s[i]=='B')b++;
  }
  
  ll ans = r*g*b;
  
  repo(j,n-1){
    ll sa;
    if(j<=n-1-j) sa=j;
    else sa=n-1-j;
    repo(x,sa+1){
      if(s[j-x]!=s[j] && s[j]!=s[j+x] && s[j-x]!=s[j+x])ans--;
    }
  }
  
  
  
  cout << ans << endl;

}

Measured memory_bytes: 3600
l = list(map(int,input().split(" ")))
k = l[0]
x = l[1]

c_min = x - k + 1
c_max = x + k - 1

if c_min < -1000000:
    c_min = -1000000
if c_max > 1000000:
    c_max = 1000000

l_ans = []
for i in range(c_min,c_max+1):
    l_ans.append(i)

print(" ".join(map(str,l_ans)))

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

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

  int n;
  cin >> n;

  double ans = 0, a;
  rep (i,0,n){
    cin >> a;
    ans += 1 / a;
  }
  ans = 1 / ans;
  cout << fixed << setprecision(12) << ans << endl;
}


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



  
int main(){
  
  int n,m,q;
  cin>>n>>m>>q;
  
  vector<int> data(11);
  
  vector<vector<int>> checkdata(q,vector<int>(4));
  
  for (int i=0;i<q;i++){
    int x,y,z,w;
    cin>>x>>y>>z>>w;
    checkdata.at(i).at(0)=x;
    checkdata.at(i).at(1)=y;
    checkdata.at(i).at(2)=z;
    checkdata.at(i).at(3)=w;
  }
    
  
  
  int answer=0;
  
  for (int a=1;a<=m;a++){
    for (int b=a;b<=m;b++){
      for (int c=b;c<=m;c++){
         for (int d=c;d<=m;d++){
            for (int e=d;e<=m;e++){
               for (int f=e;f<=m;f++){
                  for (int g=f;g<=m;g++){
                     for (int h=g;h<=m;h++){
                        for (int i=h;i<=m;i++){
                          for (int j=i;j<=m;j++){                               
                            data.at(1)=a;
                            data.at(2)=b;
                            data.at(3)=c;
                            data.at(4)=d;
                            data.at(5)=e;
                            data.at(6)=f;
                            data.at(7)=g;
                            data.at(8)=h;
                            data.at(9)=i;
                            data.at(10)=j;   
                            
                            
                            int score=0;
                            
                            for (int r=0;r<q;r++){
                              int tmp1,tmp2,tmp3,tmp4;
                              tmp1=checkdata.at(r).at(0);
                              tmp2=checkdata.at(r).at(1);
                              tmp3=checkdata.at(r).at(2);
                              tmp4=checkdata.at(r).at(3);
                              if (data.at(tmp2)-data.at(tmp1)==tmp3){
                                score+=tmp4;
                              }
                            }
                            
                            

              
                          
                            answer=max(answer,score);
                              
                          }
                        }
                     }
                  }
               }
            }
         }
      }
    }
  }
  
  cout<<answer<<endl;
  

  
  
}

    












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

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = 0; i < K; i++)
    {
        if (i % 2 == 0)
        {
            if (A % 2 == 1)
            {
                A--;
            }
            A /= 2;
            B += A;
        }
        else
        {
            if (B % 2 == 1)
            {
                B--;
            }
            B /= 2;
            A += B;
        }
    }
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int a=N-999;
	if(N<=999)
	{
		cout<<"ABC";
		return 0;
	}
	else
	{
		cout<<"ABD";
		return 0;
	}
 } 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadInts();
            if (nm[0] == nm[1])
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
int n;
int a[MAXN+5], b[MAXN+5], cnt[2][MAXN+5], ida, idb, tpa, tpb;
int main()
{
	cin>>n;
	n >>= 1;
	for(int i=1; i<=n; i++)
		cin>>a[i]>>b[i];
	for(int i=1; i<=n; i++)
	{
		cnt[0][a[i]]++;
		cnt[1][b[i]]++;
		if(cnt[0][a[i]] > tpa)
			tpa = cnt[0][a[i]], ida = a[i];
		if(cnt[1][b[i]] > tpb)
			tpb = cnt[1][b[i]], idb = b[i];
	}
	if(ida != idb)
	{
		cout<<n-tpa + n-tpb<<endl;
		return 0;
	}
	int maxa=0, maxb=0;
	for(int i=1; i<=n; i++)
	{
		if(a[i] != ida)
		{
			maxa = max(cnt[0][a[i]], maxa);
		}
		if(b[i] != idb)
		{
			maxb = max(cnt[1][b[i]], maxb);
		}
	}
	cout<<min(n-tpa+n-maxb, n-tpb+n-maxa);
}
	

Measured memory_bytes: 1408
#include<stdio.h>
int main(){
  int n,i,j,num=0,count,check;
  scanf("%d",&n);
  for(i=105;i<=n;i=i+2){
    count=1;
    int x=i;
    for(j=3;j<=13;j=j+2){
      check=1;
      while(x%j==0 && x!=0){
        check++;
        x/=j;
      }
      count*=check;
    }
    if(count==8)
      num++;
  }
  printf("%d\n",num);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
bool eq(double x,double y){
  double z=x-y;
  if(z<0.000000001)return true;
  else return false;
}
double S3( double x1, double y1, double x2,double y2, double x3, double y3 ){

  double sum = 0;
  sum = ( x1*y2 - x2*y1 ) + ( x2*y3 - x3*y2 ) + ( x3*y1 - x1*y3 );
  sum = abs(sum);
  sum /= 2;

  return sum;
}
int n;
double xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;

int check(double x,double y){
  double a = S3(xp1,yp1,xp2,yp2,x,y);
  double b = S3(xp2,yp2,xp3,yp3,x,y);
  double c = S3(xp3,yp3,xp1,yp1,x,y);
  double d = S3(xp1,yp1,xp2,yp2,xp3,yp3);
  if(eq(a+b+c,d)){
    return 1;
  }else{
    return -1;
  }
}

int main(){
  cin>>n;
  while(n--){
    cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
    if(check(xk,yk)==check(xs,ys))cout<<"NG"<<endl;
    else cout<<"OK"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f;

int n, m;

int main()
{
	//File("");
    n = gi(), m = gi();
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
	return 0;
}


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

int n,x;
int m[50];
bool dp[1000001];

bool isprime(int num){
  if(num<=1) return 0;
  for(int i=2;i*i<=num;i++){
    if(num%i==0) return 0;
  }
  return 1;
}


int main(){
  while(cin>>n>>x && (n||x)){
    for(int i=0;i<n;i++) cin>>m[i];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<n;i++){
      for(int j=0;j<=x;j++){
	if(dp[j] && j+m[i]<=x) dp[j+m[i]]=1;
      }
    }
    int ans=0;
    for(int i=x;i>=0;i--) {
      if(dp[i] && isprime(i) ){
	ans=i;
	break;
      }
    }
    if(ans==0) cout<<"NA"<<endl;
    else cout<<ans<<endl;
	
  }
  
  return 0;
}

Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <map>
#include <string>

#define PI 3.14159265359	

using namespace std;

int main(){
	int sum;
	string s;
	while (1){
		cin >> s;
		if (s == "0") break;
		sum = 0;
		for (int i = 0; i < s.size(); i++){
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


int main(){
   std::ios::sync_with_stdio(false);
   cin.tie(0);
int a,b,c,d;
cin>>a>>b>>c>>d;

if(a+b<c+d)
    cout<<"Right"<<endl;
else if(a+b>c+d)
    cout<<"Left"<<endl;
else
    cout<<"Balanced"<<endl;

 return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>

using namespace std;

typedef pair<int, int> pi;
typedef long long ll;
const int MAX_N = 15;

struct Dice{
  int l, r, f, b, d, u;
  int x, y;

  Dice(int _l, int _r, int _f, int _b, int _d, int _u, int _x, int _y){
    l = _l; r = _r; f = _f; b = _b; d = _d; u = _u; x = _x; y = _y;
  }

  void Left(){
    int tmp = u;
    u = r;
    r = d;
    d = l;
    l = tmp;
    x -= 1;
  }

  void Right(){
    int tmp = u;
    u = l;
    l = d;
    d = r;
    r = tmp;
    x += 1;
  }

  void Front(){
    int tmp = f;
    f = u;
    u = b;
    b = d;
    d = tmp;
    y -= 1;
  }

  void Back(){
    int tmp = u;
    u = f;
    f = d;
    d = b;
    b = tmp;
    y += 1;
  }

  void Role(char c){
    if(c == 'L') Left();
    else if(c == 'R') Right();
    else if(c == 'F') Front();
    else Back();
  }

  pi cord(){
    return pi(x, y);
  }

  void print(){
    cout << l << " " << r << " " << f << " " << b << " " << d << " " << u << endl;
  }
};

int N;
map<pi, int>Scores[16];
map<pi, int>Map;
int dp[1<<MAX_N];

int dfs(int S)
{

  int &res = dp[S];
  if(res > 0){
    return res;
  }

  if(S == (1<<N)-1){
    return 0;
  }
  
  for(int u=0;u<N;++u){
    if(!(S >> u & 1)){
      int score = 0;
      int nS = S | 1 << u;
      for(auto mass: Scores[u]){
	pi cord = mass.first;
	if((Map[cord] & nS) == Map[cord]) score += mass.second;
      }
      res = max(res, dfs(nS) + score);      
    }
  }
  return res;
}

int main()
{
  while(cin >> N, N){
    memset(dp, 0, sizeof(dp));
    for(int i=0;i<N;i++) Scores[i].clear();
    Map.clear();
    for(int i=0;i<N;i++){
      int x, y, l, r, f, b, d, u;
      string rot;
      cin >> x >> y >> l >> r >> f >> b >> d >> u >> rot;
      Dice dice(l, r, f, b, d, u, x, y);
      pi cord = dice.cord();      
      Scores[i][cord] =  dice.d;
      if(Map.find(cord) == Map.end())
	Map[cord] = 0;
      Map[cord] = Map[cord] | (1<<i);
      for(auto c: rot){
	dice.Role(c);
	//	dice.print();
	cord = dice.cord();	
	Scores[i][cord] =  dice.d;
	if(Map.find(cord) == Map.end())
	  Map[cord] = 0;
	Map[cord] = Map[cord] | (1<<i);	
      }


      //      int sum = 0;
      /*      for(auto x: Scores[i]){
	cout << x.first.first << " "<< x.first.second << " " << x.second << endl;
	//	sum += x.second;
      }

      for(auto x: Map){
	cout << x.first.first << " "<< x.first.second << " " << x.second << endl;	
      }
      */
      //      cout << sum  << endl;
    }
    
    cout << dfs(0) << endl;
  }
  return 0;
}

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

int main(void)
{
    char z,x;
    int a,b,c;
    cin>>a>>z>>b>>x>>c;
    cout<<2018<<'/'<<setfill('0')<<setw(2)<<b<<'/'<<setfill('0')<<setw(2)<<c;
    return 0;
}


Measured memory_bytes: 256
#include <chrono>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using namespace std::chrono;

int get_size(const vector<vector<bool>>& g, int start = 0) {
  vector<bool> used(g.size(), false);
  queue<int> q;
  q.push(start);
  used[start] = true;
  int cmp_size = 1;

  while (!q.empty()) {
    int u = q.front();
    q.pop();

    for (size_t v = 0; v < g.size(); ++v) {
      if (g[u][v] && !used[v]) {
        used[v] = true;
        ++cmp_size;
        q.push(v);
      }
    }
  }
  return cmp_size;
}

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  vector<vector<bool>> g(n, vector<bool>(n, false));
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u][v] = g[v][u] = true;
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (!g[i][j])
        continue;

      g[i][j] = g[j][i] = false;

      ans += get_size(g) != n;

      g[i][j] = g[j][i] = true;
    }
  }

  cout << ans << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0011&lang=jp
#include <stdio.h>
#include <stdlib.h>

void* smalloc ( size_t size )
{
    void* pntr = malloc( size );
    if ( pntr == NULL )
    {
        fputs( "malloc failed.\n", stderr );
        exit( EXIT_FAILURE );
    }
    return pntr;
}

int main ( void )
{
    int row, col, i, amida[2], tmp;
    int* result;

    scanf( "%d", &row );
    scanf( "%d", &col );

    result = (int*)smalloc( sizeof(int) * row );

    for ( i = 0; i < row; i++ )
    {
        result[i] = i + 1;
    }

    for ( i = 0; i < col; i++ )
    {
        scanf( "%d,%d", &amida[0], &amida[1] );
        tmp = result[amida[0] - 1];
        result[amida[0] - 1] = result[amida[1] - 1];
        result[amida[1] - 1] = tmp;
    }

    for ( i = 0; i < row; i++ )
    {
        printf( "%d\n", result[i] );
    }

    free(result);
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n, T;
    cin>>n>>T;

    int ans = INF;
    rep(i, n) {
        int c, t;
        cin>>c>>t;
        
        if (t <= T) chmin(ans, c);
    }
    if (ans == INF) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}

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

const bool DEBUG = false;

long long L;

void input() { cin >> L; }

int main(int argc, char const *argv[]) {
  input();
  cout << setprecision(20) << pow(L / 3.0, 3.0) << endl;
  return 0;
}

Measured memory_bytes: 256
B=list(map(int,input().split()))
B = B+list(map(int,input().split()))
B = B+list(map(int,input().split()))
A = [0 for i in range(9)]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(9):
        if B[j] == b:
            A[j] = 1
if A[0]==A[3] and A[3] == A[6] and A[0] == 1:
    print("Yes")
elif A[0]==A[1] and A[1] == A[2] and A[0] == 1:
    print("Yes")
elif A[0]==A[4] and A[4] == A[8] and A[0] == 1:
    print("Yes")
elif A[1]==A[4] and A[4] == A[7] and A[1] == 1:
    print("Yes")
elif A[2]==A[5] and A[5] == A[8] and A[2] == 1:
    print("Yes")
elif A[3]==A[4] and A[4] == A[5] and A[5] == 1:
    print("Yes")
elif A[7]==A[6] and A[7] == A[8] and A[8] == 1:
    print("Yes")
elif A[2]==A[4] and A[4] == A[6] and A[2] == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int N,W;
int main() {
	ll a,b;
	cin >> a >> b;
	ll z = (a+b)/2;
	if((a+b)%2){
		cout << "IMPOSSIBLE";
	}else{
		cout << z << endl;
	}
}

Measured memory_bytes: 256
// 0514 Quality Checking (????????????)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0514
// by Equim on 16-12-21

#include <cstdio>

int main()
{
    while (true)
    {
        // INPUT
        int a, b, c, Cases;
        scanf("%d%d%d", &a, &b, &c);
        if (a == 0)
            break;
        scanf("%d", &Cases);
        
        int Result[a + b + c + 1];
        for (int i = 1; i <= a + b + c; i++)
        {
            Result[i] = 2;
        }
        
        int RawData[Cases][4];
        for (int i = 0; i < Cases; i++)
        {
            scanf("%d%d%d%d", &RawData[i][0], &RawData[i][1], &RawData[i][2], &RawData[i][3]);
        }
        
        int Unqualified, QualifiedCount;
        bool HasNewChecked = false;
        
        
        // PROCESS
        do
        {
            HasNewChecked = false;
            
            for (int i = 0; i < Cases; i++)
            {
                if (RawData[i][0] + RawData[i][1] + RawData[i][2] == 0)
                    continue;
                
                if (RawData[i][3] == 1)
                {
                    for (int j = 0; j <= 2; j++)
                    {
                        Result[RawData[i][j]] = 1;
                        RawData[i][j] = 0;
                    }
                    HasNewChecked = true;
                }
                else
                {
                    Unqualified = 0;
                    QualifiedCount = 0;
                    for (int j = 0; j <= 2; j++)
                    {
                        if (Result[RawData[i][j]] == 1 || RawData[i][j] == 0)
                        {
                            RawData[i][j] = 0;
                            QualifiedCount++;
                        }
                        else
                            Unqualified = j;
                    }
                    if (QualifiedCount == 2)
                    {
                        Result[RawData[i][Unqualified]] = 0;
                        RawData[i][Unqualified] = 0;
                        HasNewChecked = true;
                    }
                }
            }
        } while (HasNewChecked);

        
        // OUTPUT
        for (int i = 1; i < a + b + c + 1; i++)
        {
            printf("%d\n", Result[i]);
        }
    }
    return 0;
}

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

int main(){
    while(true){
        ll n,m;
        cin>>n>>m;
        if(n==0&&m==0)return 0;
        ll s=0;
        rep(i,3){
            ll num;
            cin>>num;
            rep(j,num){
                ll p;
                cin>>p;
                p--;
                s+=(i<<(p*2));
            }
        }
        ll c2=0;
        rep(i,n){
            c2+=(2<<(i*2));
        }
        queue<pair<ll,ll>> que;
        que.push(make_pair(s,0));
        set<ll> used;
        used.insert(s);
        bool flag=true;
        while(que.size()){
            pair<ll,ll> pa=que.front();
            que.pop();
            ll state=pa.first;
            ll number=pa.second;
            if(state==0 || state==c2){
                cout<<number<<endl;
                flag=false;
                break;
            }
            for(ll i=0;i<2;i++){
                for(ll j=i+1;j<3;j++){
                    if(i==0&&j==2)continue;
                    ll m1=-1;
                    ll m2=-1;
                    rep(k,n){
                        if(~(state>>(k*2) ^ i) & 1 && ~(state>>(k*2) ^ i) & 1<<1){
                            m1=k;
                        }
                        if(~(state>>(k*2) ^ j) & 1 && ~(state>>(k*2) ^ j) & 1<<1){
                            m2=k;
                        }
                    }
                    if(m1>m2&&number<m){
                        ll ns=state;
                        ns=ns-(i<<(m1*2))+(j<<(m1*2));
                        if(used.find(ns)!=used.end())continue;
                        que.push(make_pair(ns,number+1));
                        used.insert(ns);
                    }else if(m1<m2&&number<m){
                        ll ns=state;
                        ns=ns-(j<<(m2*2))+(i<<(m2)*2);
                        if(used.find(ns)!=used.end())continue;
                        que.push(make_pair(ns,number+1));
                        used.insert(ns);
                    }
                }
            }
        }
        if(flag)cout<<-1<<endl;
    }
}



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

int main(){
  int N; cin>>N;
  vector<int> sc(N,0);
  rep(i,N*(N-1)/2){
    int a,b,c,d; cin>>a>>b>>c>>d;
    
    if(c>d) sc[a-1]+=3;
    else if(c<d) sc[b-1]+=3;
    else{ ++sc[a-1]; ++sc[b-1]; }
  }
  rep(i,N){
    int x=1;
    rep(j,N) if(j!=i && sc[i]<sc[j]) ++x;
    cout<<x<<endl;
  }
  return 0;
}
      

Measured memory_bytes: 3072
#include<iostream>
#include<cstring>
using namespace std;
int h, u, n, c, a, winner, p, usa, neko, usanana, usanana2, nekonana, nekonana2, usax[1145140], usay[1145140], nekox[1145140], nekoy[1145140], usabx[1000], usaby[1000], nekobx[1000], nekoby[1000];
int main() {
	memset(usax, 114514, sizeof(usax));
	memset(usay, 114514, sizeof(usay));
	memset(nekox, 114514, sizeof(nekox));
	memset(nekoy, 114514, sizeof(nekoy));
	cin >> h >> u >> n >> c;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < h; j++) {
			cin >> usa;
			usax[usa] = j;
			usay[usa] = i;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < h; j++) {
			cin >> neko;
			nekox[neko] = j;
			nekoy[neko] = i;
		}
	}
	winner = 3;
	usa = 0;
	neko = 0;
	for (int i = 0; i < c; i++) {
		cin >> a;
		if (h == 1) {
			if (usax[a] < 114514) {
				usa++;
			}
			if (nekox[a] < 114514) {
				neko++;
			}
		}
		else {
			p = 0;
			if (usax[a] < 114514) {
				usabx[usax[a]]++;
				if (usabx[usax[a]] == h) {
					usa += 1;
				}
			}
			if (usay[a] < 114514) {
				usaby[usay[a]]++;
				if (usaby[usay[a]] == h) {
					usa += 1;
				}
			}
			if (usax[a] < 114514) {
				if (usax[a] == usay[a]) {
					usanana++;
				}
				if (usax[a] == h - 1 - usay[a]) {
					usanana2++;
				}
				if (usanana == h) {
					usa += 1;
					usanana++;
				}
				if (usanana2 == h) {
					usa += 1;
					usanana2++;
				}
			}
			if (nekox[a] < 114514) {
				nekobx[nekox[a]]++;
				if (nekobx[nekox[a]] == h) {
					neko += 1;
				}
			}
			if (nekoy[a] < 114514) {
				nekoby[nekoy[a]]++;
				if (nekoby[nekoy[a]] == h) {
					neko += 1;
				}
			}
			if (nekox[a] < 114514) {
				if (nekox[a] == nekoy[a]) {
					nekonana++;
				}
				if (nekox[a] == h - 1 - nekoy[a]) {
					nekonana2++;
				}
				if (nekonana == h) {
					neko += 1;
					nekonana++;
				}
				if (nekonana2 == h) {
					neko += 1;
					nekonana2++;
				}
			}
		}
		if (winner == 3) {
			if (usa >= u && neko >= n) {
				winner = 2;
			}
			else if (usa >= u) {
				winner = 0;
			}
			else if (neko >= n) {
				winner = 1;
			}
		}
	}
	if (winner == 0) {
		cout << "USAGI" << endl;
	}
	else if (winner == 1) {
		cout << "NEKO" << endl;
	}
	else {
		cout << "DRAW" << endl;
	}
	return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

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

int main() {
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;

    return 0;
}

Measured memory_bytes: 3572
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;

/** Problem0258 : Kitchen Garden **/
int main()
{
	int n, h[101];

	while (cin>>n, n) {
		memset(h, 0, sizeof(h));
		rep(i, n+1)
			cin >> h[i];
		
		rep(i, n+1) {
			vector<int> t;
			rep(j, n+1) {
				if (i!=j) {
					t.push_back(h[j]);
				}
			}
			
			int d= t[1] - t[0];
			REP(j, 2, n) {
				if (t[j]-t[j-1]!=d) {
					goto next;
				}
			}
			cout << h[i] << endl;
			break;
		next:;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
typedef pair<int, int> P;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
void solve() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep (i, h) {
		cin >> s[i];
	}	
	int ans = 0;
	//BFSを用いて解く
	//全てのマスをスタート位置として設定して探索を行う
	//BFSを使用することで、現在マスの隣接マスを探索し終わってから
	//隣接マスの隣接マスの探索を開始することができる
	rep (si, h) {
		rep (sj, w) {
			if (s[si][sj] == '#') continue;
			//スタート位置毎に距離盤面を初期化する
			vector<vector<int>> dist(h, vector<int>(w, INF));
			queue<P> q;
			auto update = [&](int i, int j, int x) {
				if (dist[i][j] != INF) return;
				dist[i][j] = x;
				q.push(P(i, j)); //.emplace(i, j)
			};
			update(si, sj, 0);
			while(!q.empty()) {
				int i = q.front().first;
				int j = q.front().second; q.pop();
				//隣接マス(上下左右4方向)を探索する
				rep (dir, 4) {
					int ni = i+di[dir], nj = j+dj[dir];
					//盤面から外に出たor壁の場合は探索打ち切り
					if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
					if (s[ni][nj] == '#') continue;
					//今のマスから距離を1加算して隣接マスをキューに入れていく
					update(ni, nj, dist[i][j] + 1);
				}
			}
			//スタート位置毎に盤面の中で最大の移動回数を記録していく
			rep (i, h) {
				rep (j, w) {
					if (dist[i][j] == INF) continue;
					ans = max(ans, dist[i][j]);
				}
			}
		}
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
z = $stdin.read.split("\n")
def f(arr, n)
  (arr.slice(arr.size - n, n) + arr.slice(0, arr.size - n)).join
end
s = z[0].split("")
t = z[1]
i = 0
result = false
loop do
  if f(s, i) == t
    result = true
    break
  end
  if i == s.size - 1
    break
  end
  i+=1
end
if result
  puts 'Yes'
else
  puts 'No'
end

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }

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

  ll n, x; cin >> n >> x;
  vector<ll> a(n);
  ll tmp;
  rep(i, n) {
    cin >> tmp;
    a[i] = abs(tmp-x);
  }

  ll ans = a[n-1];
  rep(i, n-1) {
    ans = gcd(a[i], ans);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		ArrayList<Integer> liList = new ArrayList<Integer>();

		for(int i = 1; i <= N; i++) {
			liList.add(sc.nextInt());
		}

		Collections.sort(liList, Comparator.reverseOrder());

		int result = 0;
		for(int i = 0; i < K; i++) {
			result += liList.get(i);
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<tll,vector<tll>,greater<tll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  ll n,k;
  cin>>n>>k;
  vll ans(k+1,0);
  for(int i=k;i>0;i--){
    ll cu=k/i;
    ll no=0;
    ll ccu=1;
    while(ccu*i<=k){
      no+=ans[ccu*i];
      no%=MOD;
      ccu++;
    }
    (ans[i]=modpow(cu,n,MOD)-no)%=MOD;
    if(ans[i]<0) ans[i]+=MOD;
  }
  ll res=0;
  for(int i=k;i>0;i--){
    res+=ans[i]*i;
    res%=MOD;
  }
  COUT(res);
}

Measured memory_bytes: 4052
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
if(A + B + C + D == 7):
    print(str(A) + '+' +str(B) + '+' + str(C) + '+' + str(D) + '=7')
elif(A - B + C + D == 7):
    print(str(A) + '-' +str(B) + '+' + str(C) + '+' + str(D) + '=7')
elif(A + B - C + D == 7):
    print(str(A) + '+' +str(B) + '-' + str(C) + '+' + str(D) + '=7')
elif(A + B + C - D == 7):
    print(str(A) + '+' +str(B) + '+' + str(C) + '-' + str(D) + '=7')
elif(A - B - C + D == 7):
    print(str(A) + '-' +str(B) + '-' + str(C) + '+' + str(D) + '=7')
elif(A - B + C - D == 7):
    print(str(A) + '-' +str(B) + '+' + str(C) + '-' + str(D) + '=7')
elif(A + B - C - D == 7):
    print(str(A) + '+' +str(B) + '-' + str(C) + '-' + str(D) + '=7')
elif(A - B - C - D == 7):
    print(str(A) + '-' +str(B) + '-' + str(C) + '-' + str(D) + '=7')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K, Q;
  cin >> N >> K >> Q;
  int score[N];
  fill(score, score + N, K - Q);
  while (Q--) {
    int A;
    cin >> A;
    score[--A]++;
  }
  for (int i = 0; i < N; i++) cout << (score[i] > 0 ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 4068
N = int(input())
A = list(map(int, input().split()))
hold = 0
m = 1000
for i in range(N-1):
    if A[i] < A[i+1]:
        hold += m // A[i]
        m = m % A[i]
    elif hold > 0:
        m += hold*A[i]
        hold = 0
    else:
        pass
if hold != 0:
    m += A[N-1]*hold
print(m)

Measured memory_bytes: 61744
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  long long N,K;
  cin>>N>>K;
  long long A[200001];
  long long light[200001];
  for(int j=0;j<K;j++){
  for(int i=1;i<=N;i++){
    light[i]=0;
  }
  for(int i=1;i<=N;i++){
    cin>>A[i];
    if(i-A[i]>1) light[i-A[i]]++;
    if(i-A[i]<=1) light[1]++;
    if(i+A[i]+1<=N) light[i+A[i]+1]--;
  }
  for(int i=2;i<=N;i++){
    light[i]+=light[i-1];
  }
    int judge=0;
    for(int i=1;i<=N;i++){
      A[i]=light[i];
      if(A[i]==N) judge++;
    }
    if(judge==N) break;
  }
  for(int i=1;i<=N;i++){
    if(i!=N) cout<<A[i]<<' ';
    else cout<<A[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 6692
class Edge
  attr_reader :s, :e, :z

  def initialize(s, e, z)
    @s = s
    @e = e
    @z = z
  end
end

class Graph
  def initialize(n,edges)
    @city = n
    @dist = Array.new(n).map{Array.new(n,Float::INFINITY)}
    edges.each do |edge|
      @dist[edge.s][edge.e] = @dist[edge.e][edge.s] = [@dist[edge.e][edge.s], edge.z].min
    end
  end

  def warshall_floyd
    @city.times do |k|
      @city.times do |i|
        @city.times do |j|
          @dist[i][j] = [@dist[i][j], @dist[i][k] + @dist[j][k]].min if(@dist[i][j] > @dist[i][k] + @dist[k][j])
        end
      end
    end
    @dist
  end
end


n, m, r = gets.chomp.split(" ").map(&:to_i)
input = gets.chomp.split(" ").map{|i| i.to_i.pred}
query = input.permutation(r)

edges = []

m.times do
  s, e, z = gets.chomp.split(" ").map(&:to_i)
  edges << Edge.new(s.pred, e.pred, z)
end

graph = Graph.new(n,edges)
dist = graph.warshall_floyd

score = []
query.each do |route|
  score << route.each_cons(2).map{|a,b| dist[a][b]}.inject(&:+)
end
p score.min

Measured memory_bytes: 5176
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = - np.array(readline().split(), dtype=np.int32)

a.sort()
b.sort()
c.sort()

cnt_a = np.searchsorted(a, b, side='left')
cnt_c = np.searchsorted(c, -b, side='left')
 
answer = (cnt_a * cnt_c).sum()
print(answer)


Measured memory_bytes: 20064
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int n, o;
	cin >> n;
	if (n % 2 == 1) {
		cout << n / 2 + 1 << endl;
	}
	else {
		cout << n / 2 << endl;
	}
	return 0;
}

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

int main() {
  int N,K;
  int result = 0;
  cin >> N >> K;
  vector<int> vec(N);
  
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
  }
  for (int j=0; j<N; j++) {
    if (vec.at(j) >= K) {
      result++;
    }
  }
  cout << result << endl;
  
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
  	if((a + b) % 2 == 1) {
      	cout << ((a + b) / 2 + 1) << endl;
    }else{
      	cout << (a + b) / 2 << endl;
    }
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		char X = args[0][0];
		char Y = args[1][0];

		Console.WriteLine((X < Y) ? "<" : (X > Y) ? ">" : "=");
	}
}





Measured memory_bytes: 13140
#include <bits/stdc++.h>
#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 pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll h,w,n,a,b;

int main(){
	cin >> h >> w >> n;
	
	map<P, int> mp;
	REP(q,0,n){
		cin >> a >> b; a--; b--;
		REP(i,max(0LL,b-2),min(w-3,b)+1){
			REP(j,max(0LL,a-2),min(h-3,a)+1){
				mp[P(i,j)]++;
			}
		}
	}
	
	ll pos[20]={};
	for(auto s:mp){
		pos[s.second]++;
		pos[0]++;
	}
	
	pos[0]=(h-2)*(w-2)-pos[0];
	REP(i,0,10) cout << pos[i] << endl;
	return 0;
}



Measured memory_bytes: 56448